Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: #82 object trigger order #115

Merged
merged 1 commit into from
Mar 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/lpsim/server/character/character_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -751,9 +751,9 @@ def damage_taken(self) -> int:

def get_object_lists(self) -> List[ObjectBase]:
"""
Get all objects of the character, order is passive skill, weapon,
artifact, talent, status. For status, order is their index in status
list, i.e. generated time.
Get all objects of the character, order is character itself, skills, and other
objects. Order of other objects, including equipment and status, are based on
when they are attached, regardless of their types.
"""
result: List[ObjectBase] = [self]
for skill in self.skills:
Expand Down
48 changes: 30 additions & 18 deletions src/lpsim/server/match.py
Original file line number Diff line number Diff line change
Expand Up @@ -1094,11 +1094,15 @@ def get_object_list(self) -> List[ObjectBase]:
Get all objects in the match by `self.table.get_object_lists`.
The order of objects should follow the game rule. The rules are:
1. objects of `self.current_player` goes first
2. objects belongs to character goes first
2.1. active character first, otherwise the default order.
2.2. for one character, order is weapon, artifact, talent, status.
2.3. for status, order is their index in status list, i.e.
generated time.
2. objects belongs to character and team status goes first
2.1. active character first, then next, next ... until all alive
characters are included.
2.2. for one character, order is character self, its skills, other objects
attached to the character.
2.3. status and equipment have no priority, just based on the time when they
are attached to the character.
2.4. specifically, team status has lower priority of active character and
its attached objects, but higher priority of other characters.
3. for other objects, order is: summon, support, hand, dice, deck.
3.1. all other objects in same region are sorted by their index in
the list.
Expand Down Expand Up @@ -1491,20 +1495,28 @@ def _respond_switch_character(self, response: SwitchCharacterResponse):
)
cost_value = self._modify_cost_value(cost_value, "REAL")
actions.append(SwitchCharacterAction.from_response(response))
actions.append(
ActionEndAction(
action_label=PlayerActionLabels.SWITCH.value,
position=ObjectPosition(
player_idx=response.player_idx,
character_idx=response.request.active_character_idx,
area=ObjectPositionType.CHARACTER,
id=self.player_tables[response.player_idx]
.characters[response.request.active_character_idx]
.id,
),
do_combat_action=True,
)
end_action = ActionEndAction(
action_label=PlayerActionLabels.SWITCH.value,
position=ObjectPosition(
player_idx=response.player_idx,
character_idx=response.request.active_character_idx,
area=ObjectPositionType.CHARACTER,
id=self.player_tables[response.player_idx]
.characters[response.request.active_character_idx]
.id,
),
do_combat_action=True,
)
# as after switching character, the active character may change, so
# we need to update combat action value before switching.
combat_action_value = CombatActionValue(
position=end_action.position,
action_label=end_action.action_label,
do_combat_action=end_action.do_combat_action,
)
self._modify_value(value=combat_action_value, mode="REAL")
end_action.do_combat_action = combat_action_value.do_combat_action
actions.append(end_action)
self.event_controller.stack_actions(actions)
self.requests = [
x for x in self.requests if x.player_idx != response.player_idx
Expand Down
14 changes: 9 additions & 5 deletions src/lpsim/server/player_table.py
Original file line number Diff line number Diff line change
Expand Up @@ -197,12 +197,15 @@ def get_object_lists(self) -> List[ObjectBase]:
Get all objects in the table.
The order of objects should follow the game rule. The rules are:
1. objects of `self.current_player` goes first
2. objects belongs to character goes first
2. objects belongs to character and team status goes first
2.1. active character first, then next, next ... until all alive
characters are included.
2.2. for one character, order is weapon, artifact, talent, status.
2.3. for status, order is their index in status list, i.e.
generated time.
2.2. for one character, order is character self, its skills, other objects
attached to the character.
2.3. status and equipment have no priority, just based on the time when they
are attached to the character.
2.4. specifically, team status has lower priority of active character and
its attached objects, but higher priority of other characters.
3. for other objects, order is: summon, support, hand, dice, deck.
3.1. all other objects in same region are sorted by their index in
the list.
Expand All @@ -215,7 +218,8 @@ def get_object_lists(self) -> List[ObjectBase]:
target = (start_character_idx + i) % len(self.characters)
if self.characters[target].is_alive:
result += self.characters[target].get_object_lists()
result += self.team_status
if i == 0:
result += self.team_status
result += self.summons
result += self.supports
if self.using_hand is not None:
Expand Down
4 changes: 3 additions & 1 deletion src/lpsim/server/status/team_status/event_cards.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,9 @@ class LeaveItToMe_3_3(UsageTeamStatus):
def value_modifier_COMBAT_ACTION(
self, value: CombatActionValue, match: Any, mode: Literal["TEST", "REAL"]
) -> CombatActionValue:
assert self.usage > 0
if self.usage <= 0:
# no usage, do nothing
return value
if not self.position.check_position_valid(
value.position,
match,
Expand Down
Loading