Skip to content

Commit

Permalink
fix some bug about damge_excute, finish wj
Browse files Browse the repository at this point in the history
  • Loading branch information
flick-ai committed Jun 5, 2024
1 parent 199cc0f commit 92f8f8f
Show file tree
Hide file tree
Showing 20 changed files with 121 additions and 57 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def on_end(self, game: 'GeniusGame'):

def update_listener_list(self):
self.listeners = [
(EventType.FINAL_EXECUTE, ZoneType.CHARACTER_ZONE, self.on_damage),
(EventType.EXECUTE_DAMAGE, ZoneType.CHARACTER_ZONE, self.on_damage),
(EventType.FINAL_END, ZoneType.CHARACTER_ZONE, self.on_end)
]

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def on_end(self, game: 'GeniusGame'):

def update_listener_list(self):
self.listeners = [
(EventType.FINAL_EXECUTE, ZoneType.CHARACTER_ZONE, self.on_damage),
(EventType.EXECUTE_DAMAGE, ZoneType.CHARACTER_ZONE, self.on_damage),
(EventType.FINAL_END, ZoneType.CHARACTER_ZONE, self.on_end)
]

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,23 @@ class HeartofKhvarenasBrillianceEntity(Artifact):
def __init__(self, game: 'GeniusGame', from_player: 'GeniusPlayer', from_character = None, artifact_card = None):
super().__init__(game, from_player, from_character, artifact_card)
self.usage_round = -1
self.is_excute = False

def after_damage(self, game:'GeniusGame'):
if self.usage_round != game.round:
if game.current_damage.damage_to == self.from_character:
if self.from_character.is_active:
self.from_player.get_card(num=1)
self.usage_round = game.round
self.is_excute = True

def on_excute(self, game: 'GeniusGame'):
if self.is_excute:
if self.from_character.is_active and self.from_character.is_alive:
self.from_player.get_card(num=1)
self.is_excute = False

def update_listener_list(self):
self.listeners = [
(EventType.FINAL_EXECUTE, ZoneType.CHARACTER_ZONE, self.after_damage),
(EventType.EXECUTE_DAMAGE, ZoneType.CHARACTER_ZONE, self.after_damage),
(EventType.FINAL_EXECUTE, ZoneType.CHARACTER_ZONE, self.on_excute)
]


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ class MarechausseeHunterEntity(Artifact):
def __init__(self, game: 'GeniusGame', from_player: 'GeniusPlayer', from_character = None, artifact_card = None):
super().__init__(game, from_player, from_character, artifact_card)
self.round_usage = 0
self.is_excute = False

def excute(self, game):
if self.round_usage == 0 or self.round_usage == 3:
Expand All @@ -26,10 +27,15 @@ def excute(self, game):
self.from_player.get_card(num=1)
return

def on_excute(self, game:'GeniusGame'):
if self.is_excute:
if self.from_character.is_alive:
self.excute(game)
self.is_excute = False

def after_damage(self, game:'GeniusGame'):
if game.current_damage.damage_to == self.from_character:
self.excute(game)
self.is_excute = True

def after_heal(self, game:'GeniusGame'):
if game.current_heal.heal_to_character == self.from_character:
Expand All @@ -40,9 +46,10 @@ def on_end(self, game: 'GeniusGame'):

def update_listener_list(self):
self.listeners = [
(EventType.FINAL_EXECUTE, ZoneType.CHARACTER_ZONE, self.after_damage),
(EventType.EXECUTE_DAMAGE, ZoneType.CHARACTER_ZONE, self.after_damage),
(EventType.AFTER_HEAL, ZoneType.CHARACTER_ZONE, self.after_heal),
(EventType.FINAL_END, ZoneType.CHARACTER_ZONE, self.on_end)
(EventType.FINAL_END, ZoneType.CHARACTER_ZONE, self.on_end),
(EventType.FINAL_EXECUTE, ZoneType.CHARACTER_ZONE, self.on_excute)
]


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ class VeteransVisageEntity(Artifact):
def __init__(self, game: 'GeniusGame', from_player: 'GeniusPlayer', from_character = None, artifact_card = None):
super().__init__(game, from_player, from_character, artifact_card)
self.round_usage = 0
self.is_excute = False

def excute(self, game):
if self.round_usage == 0:
Expand All @@ -25,10 +26,16 @@ def excute(self, game):
self.round_usage += 1
self.from_player.get_card(num=1)
return

def on_excute(self, game):
if self.is_excute:
if self.from_character.is_alive:
self.is_excute = False
self.excute(game)

def after_damage(self, game:'GeniusGame'):
if game.current_damage.damage_to == self.from_character:
self.excute(game)
self.is_excute = True

def after_heal(self, game:'GeniusGame'):
if game.current_heal.heal_to_character == self.from_character:
Expand All @@ -39,9 +46,10 @@ def on_end(self, game: 'GeniusGame'):

def update_listener_list(self):
self.listeners = [
(EventType.FINAL_EXECUTE, ZoneType.CHARACTER_ZONE, self.after_damage),
(EventType.EXECUTE_DAMAGE, ZoneType.CHARACTER_ZONE, self.after_damage),
(EventType.AFTER_HEAL, ZoneType.CHARACTER_ZONE, self.after_heal),
(EventType.FINAL_END, ZoneType.CHARACTER_ZONE, self.on_end)
(EventType.FINAL_END, ZoneType.CHARACTER_ZONE, self.on_end),
(EventType.FINAL_EXECUTE, ZoneType.CHARACTER_ZONE, self.on_excute),
]


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,23 +14,30 @@ class VourukashasGlowEntity(Artifact):
def __init__(self, game: 'GeniusGame', from_player: 'GeniusPlayer', from_character = None, artifact_card = None):
super().__init__(game, from_player, from_character, artifact_card)
self.usage_round = -1
self.is_excute = False

def after_damage(self, game:'GeniusGame'):
if self.usage_round != game.round:
if game.current_damage.damage_to == self.from_character:
if self.from_character.is_active:
self.from_player.get_card(num=1)
self.usage_round = game.round

self.is_excute = True

def on_excute(self, game):
if self.is_excute:
if self.from_character.is_active and self.from_character.is_alive:
self.from_player.get_card(num=1)
self.usage_round = game.round
self.is_excute = False

def on_end(self, game: 'GeniusGame'):
if game.active_player_index == self.from_player.index:
if self.usage_round == game.round:
self.from_character.heal(1, game)

def update_listener_list(self):
self.listeners = [
(EventType.FINAL_EXECUTE, ZoneType.CHARACTER_ZONE, self.after_damage),
(EventType.END_PHASE, ZoneType.CHARACTER_ZONE, self.on_end)
(EventType.EXECUTE_DAMAGE, ZoneType.CHARACTER_ZONE, self.after_damage),
(EventType.END_PHASE, ZoneType.CHARACTER_ZONE, self.on_end),
(EventType.FINAL_EXECUTE, ZoneType.CHARACTER_ZONE, self.on_excute)
]


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ def update_listener_list(self):
self.listeners = [
(EventType.DAMAGE_ADD, ZoneType.CHARACTER_ZONE, self.on_damage_add),
(EventType.AFTER_USE_SKILL, ZoneType.CHARACTER_ZONE, self.on_after_skill),
(EventType.FINAL_EXECUTE, ZoneType.CHARACTER_ZONE, self.after_damage),
(EventType.EXECUTE_DAMAGE, ZoneType.CHARACTER_ZONE, self.after_damage),
]


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ def update_listener_list(self):
self.listeners = [
(EventType.DAMAGE_ADD, ZoneType.CHARACTER_ZONE, self.on_damage_add),
(EventType.FINAL_END, ZoneType.CHARACTER_ZONE, self.on_end),
(EventType.FINAL_EXECUTE, ZoneType.CHARACTER_ZONE, self.after_damage),
(EventType.EXECUTE_DAMAGE, ZoneType.CHARACTER_ZONE, self.after_damage),
(EventType.AFTER_HEAL, ZoneType.CHARACTER_ZONE, self.after_heal),
(EventType.CALCULATE_DICE, ZoneType.CHARACTER_ZONE, self.on_calculate_dice),
(EventType.ON_USE_SKILL, ZoneType.CHARACTER_ZONE, self.on_skill),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ def update_listener_list(self):
self.listeners = [
(EventType.DAMAGE_ADD, ZoneType.CHARACTER_ZONE, self.on_damage_add),
(EventType.FINAL_END, ZoneType.CHARACTER_ZONE, self.on_end),
(EventType.FINAL_EXECUTE, ZoneType.CHARACTER_ZONE, self.after_damage),
(EventType.EXECUTE_DAMAGE, ZoneType.CHARACTER_ZONE, self.after_damage),
(EventType.AFTER_HEAL, ZoneType.CHARACTER_ZONE, self.after_heal),
(EventType.CALCULATE_DICE, ZoneType.CHARACTER_ZONE, self.on_calculate_dice),
(EventType.ON_USE_SKILL, ZoneType.CHARACTER_ZONE, self.on_skill),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ def update_listener_list(self):
self.listeners = [
(EventType.DAMAGE_ADD, ZoneType.CHARACTER_ZONE, self.on_damage_add),
(EventType.FINAL_END, ZoneType.CHARACTER_ZONE, self.on_end),
(EventType.FINAL_EXECUTE, ZoneType.CHARACTER_ZONE, self.after_damage),
(EventType.EXECUTE_DAMAGE, ZoneType.CHARACTER_ZONE, self.after_damage),
(EventType.AFTER_HEAL, ZoneType.CHARACTER_ZONE, self.after_heal),
]

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def find_target(self, game:'GeniusGame'):
else:
return []

def on_discard(self, game: GeniusGame):
def on_discard(self, game: 'GeniusGame'):
target_card_name = self.base_name + str(self.cost_num - 1)
target_card = eval(target_card_name)()
game.active_player.card_zone.insert_randomly(target_card, num=0)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ def on_use(self, game:'GeniusGame'):

def update_listener_list(self):
self.listeners = [
(EventType.FINAL_EXECUTE, ZoneType.ACTIVE_ZONE, self.on_damage),
(EventType.EXECUTE_DAMAGE, ZoneType.ACTIVE_ZONE, self.on_damage),
(EventType.AFTER_HEAL, ZoneType.ACTIVE_ZONE, self.on_heal),
(EventType.CALCULATE_DICE, ZoneType.ACTIVE_ZONE, self.on_calculate),
(EventType.ON_PLAY_CARD, ZoneType.ACTIVE_ZONE, self.on_use),
Expand Down
46 changes: 38 additions & 8 deletions genius_invocation/card/action/event/events/WaterandJustice.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from genius_invocation.card.action.base import ActionCard
from genius_invocation.utils import *
from genius_invocation.event.damage import Damage
if TYPE_CHECKING:
from genius_invocation.game.game import GeniusGame

Expand All @@ -15,19 +16,48 @@ def __init__(self) -> None:
super().__init__()

def calculate_target_point(self,sum_point: int, max_points: List[int]):
# 重新平均分配生命值
target_point = []
# 计算重新平均分配生命值
need_character = len(max_points)
target_point = [0 for i in range(need_character)]
target_idx = [i for i in range(need_character)]

while sum_point > 0:
for idx in target_idx:
target_point[idx] += 1
sum_point -= 1
if sum_point == 0:
break
if max_points[idx] == target_point[idx]:
target_idx.remove(idx)

return target_point


def on_played(self, game: 'GeniusGame'):
sum_point = 0
max_points = []
target_idx = []
for player in game.active_player.character_list:
if player.is_alive:
sum_point += player.health_point
max_points.append(player.max_health_point)
target_idx.append(player.idx)
character_list = [get_my_active_character(game)].extend(get_my_standby_character(game))
for character in character_list:
sum_point += character.health_point
max_points.append(character.max_health_point)
target_point = self.calculate_target_point(sum_point, max_points)

# 进行对应操作
for idx, character in enumerate(character_list):
if target_point > character.health_point:
character.heal(heal=target_point[idx]-character.health_point, game=game)
elif target_point < character.health_point:
damage = Damage.create_damage(
game=game,
damage_type=SkillType.OTHER,
main_damage_element=ElementType.PIERCING,
main_damage=character.health_point-target_point[idx],
piercing_damage=0,
damage_from=None,
damage_to=character
)
game.add_damage(damage)
game.resolve_damage()

character.heal(heal=1, game=game)

11 changes: 9 additions & 2 deletions genius_invocation/card/action/event/foods/Rainbow_Macarons.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,23 @@ def __init__(self, game: 'GeniusGame', from_player: 'GeniusPlayer', from_charact
super().__init__(game, from_player, from_character)
self.from_character.heal(heal=1,game=game)
self.current_usage = 3
self.is_heal = False

def on_damage(self, game: 'GeniusGame'):
if game.current_damage.damage_to == self.from_character:
def on_excute(self, game: 'GeniusGame'):
if self.is_heal:
self.is_heal = False
self.from_character.heal(heal=1, game=game)
self.current_usage -= 1
if self.current_usage <=0:
self.on_destroy(game)

def on_damage(self, game: 'GeniusGame'):
if game.current_damage.damage_to == self.from_character:
self.is_heal = True

def update_listener_list(self):
self.listeners = [
(EventType.EXECUTE_DAMAGE, ZoneType.CHARACTER_ZONE, self.on_damage),
(EventType.FINAL_EXECUTE, ZoneType.CHARACTER_ZONE, self.on_damage),
]

Expand Down
24 changes: 10 additions & 14 deletions genius_invocation/card/action/support/item/Kusava.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,30 +17,26 @@ def __init__(self, game: 'GeniusGame', from_player: 'GeniusPlayer', from_charact
self.memories_and_dreams = 0

def get_max_count_card(self, game: 'GeniusGame'):
max_count = 0
max_idx = []
card_list = []
for idx, action_card in enumerate(self.from_player.hand_zone.card):
if action_card.card_type == ActionCardType.EQUIPMENT_TALENT:
count = sum([i['cost_num'] for i in action_card.cost])
else:
count = action_card.cost_num

if count > max_count:
max_idx = []
max_count = count
max_idx.append(idx)
if count == max_count:
max_idx.append(idx)
return idx
card_list.append((idx, count))
max_count_card = sorted(card_list, key=lambda x:x[-1])
if len(max_count_card) == 0:
return []
elif len(max_count_card) == 1:
return [max_count_card[0]]
else:
max_count_idx = [i[0] for i in max_count_card[0:2]]
return max_count_idx

def on_begin(self, game:'GeniusGame'):
if game.active_player_index == self.from_player.index:
max_count_idx = self.get_max_count_card(game)
if len(max_count_idx) == 0:
return
if len(max_count_idx) > 2:
max_count_idx = max_count_idx[0:2]

for idx in max_count_idx:
self.from_player.hand_zone.discard_card(idx)
self.memories_and_dreams = min(self.max_count, self.memories_and_dreams + 1)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from genius_invocation.entity.support import Support
from genius_invocation.entity.status import Combat_Status
from genius_invocation.event.damage import Damage
from genius_invocation.card.action.base import ActionCard


if TYPE_CHECKING:
Expand Down
4 changes: 2 additions & 2 deletions genius_invocation/event/events.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ def __init__(self, need_character=False) -> None:


def append_action(self, action, character_index=None) -> ListenerNode:
if character_index:
if character_index is not None:
node = ListenerNode(action, self.character_tails[character_index].before, self.character_tails[character_index])
self.character_tails[character_index].before.next = node
self.character_tails[character_index].before = node
Expand All @@ -63,7 +63,7 @@ def append_action(self, action, character_index=None) -> ListenerNode:
return node

def __call__(self, game: 'GeniusGame', character_index=None) -> None:
if not character_index:
if character_index is None:
listener = self.head.next
tail_before = self.tail.before
while listener != self.tail:
Expand Down
4 changes: 2 additions & 2 deletions genius_invocation/game/player.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ def __init__(self, game: 'GeniusGame', deck, idx) -> None:
# 初始化牌库、起始5张手牌、骰子区
self.card_zone: CardZone = CardZone(game, self, deck['action_card']) # 牌库区
self.hand_zone: HandZone = HandZone(game, self) # 手牌区
arcanes = self.card_zone.find_card(ActionCardType.EVENT_ARCANE_LEGEND, num=-1)
self.hand_zone.add(self.card_zone.get_card(num=5-len(arcanes))+arcanes)
arcanes = self.card_zone.find_card(ActionCardType.EVENT_ARCANE_LEGEND, num=-1, invoke=False)
self.hand_zone.add(self.card_zone.get_card(num=5-len(arcanes), invoke=False)+arcanes)
self.dice_zone: DiceZone = DiceZone(game, self)

# 环境中的基本状态
Expand Down
Loading

0 comments on commit 92f8f8f

Please sign in to comment.