Skip to content

Commit

Permalink
Merge pull request #95 from LPSim/issue-88
Browse files Browse the repository at this point in the history
resolve #88
  • Loading branch information
zyr17 authored Feb 18, 2024
2 parents 86b7d6b + db9b65c commit 7091887
Show file tree
Hide file tree
Showing 89 changed files with 502 additions and 654 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -172,3 +172,4 @@ prof
ZZZ
Z2
*DS_Store
update.md
2 changes: 1 addition & 1 deletion http_room_serve.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"""


from src.lpsim.network.http_room_server import HTTPRoomServer
from lpsim.network.http_room_server import HTTPRoomServer


if __name__ == "__main__":
Expand Down
6 changes: 3 additions & 3 deletions http_test_serve.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from src.lpsim.server.event_handler import OmnipotentGuideEventHandler_3_3
from src.lpsim.network import HTTPServer
from src.lpsim.server.match import MatchConfig, Match
from lpsim.server.event_handler import OmnipotentGuideEventHandler_3_3
from lpsim.network import HTTPServer
from lpsim.server.match import MatchConfig, Match
from tests.utils_for_test import get_random_state
import logging

Expand Down
4 changes: 2 additions & 2 deletions ipynb/parse_name_type.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
"metadata": {},
"outputs": [],
"source": [
"from src.lpsim.server import Cards, Summons, Characters, CharacterStatus, TeamStatus\n",
"from src.lpsim.server.consts import IconType\n",
"from lpsim.server import Cards, Summons, Characters, CharacterStatus, TeamStatus\n",
"from lpsim.server.consts import IconType\n",
"from typing import get_type_hints\n",
"import time\n",
"import pydantic\n",
Expand Down
27 changes: 12 additions & 15 deletions src/lpsim/server/action.py
Original file line number Diff line number Diff line change
Expand Up @@ -402,29 +402,15 @@ class MakeDamageAction(ActionBase):
Action for making damage. Heal treats as negative damage. Elemental
applies to the character (e.g. Kokomi) treats as zero damage.
It can also contain character change and object creation (caused by
elemental reaction or skill effects). They will be executed right after
making damage, and gives corresponding events.
Args:
damage_value_list (List[DamageValue]): The damage values to make.
do_character_change (bool): Whether to change character after making
damage.
character_change_idx (List[int]): The character indices of the
character who will be changed to for each player. If it is -1,
this damage will not explicitly change the character. It should
not be a defeated character.
create_objects (List[CreateObjectAction]): The objects to create after
making damage.
"""

type: Literal[ActionTypes.MAKE_DAMAGE] = ActionTypes.MAKE_DAMAGE
record_level: int = 10
damage_value_list: List[DamageValue]
create_objects: List[CreateObjectAction] = []

# character change
character_change_idx: List[int] = [-1, -1]

def __init__(self, *argv, **kwargs):
super().__init__(*argv, **kwargs)
Expand Down Expand Up @@ -466,10 +452,21 @@ class GenerateRerollDiceRequestAction(ActionBase):

class SkipPlayerActionAction(ActionBase):
"""
Action for skipping current player action.
Action for skipping current player action. As skipping will cause action end, its
variables are the same as ActionEndAction.
"""

type: Literal[ActionTypes.SKIP_PLAYER_ACTION] = ActionTypes.SKIP_PLAYER_ACTION
action_label: int # Refer to PlayerActionLabels
do_combat_action: bool
position: ObjectPosition

def get_action_end_action(self):
return ActionEndAction(
action_label=self.action_label,
do_combat_action=self.do_combat_action,
position=self.position,
)


# 25
Expand Down
26 changes: 15 additions & 11 deletions src/lpsim/server/character/anemo/jean_3_3.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,12 @@

from ...modifiable_values import DamageIncreaseValue, DamageValue

from ...action import ActionTypes, Actions, ChangeObjectUsageAction, MakeDamageAction
from ...action import (
Actions,
ChangeObjectUsageAction,
MakeDamageAction,
SwitchCharacterAction,
)
from ...struct import Cost

from ...consts import (
Expand Down Expand Up @@ -100,17 +105,18 @@ class GaleBlade(ElementalSkillBase):
cost: Cost = Cost(elemental_dice_color=DieColor.ANEMO, elemental_dice_number=3)

def get_actions(self, match: Any) -> List[Actions]:
ret = super().get_actions(match)
next_idx = match.player_tables[
1 - self.position.player_idx
].next_character_idx()
if next_idx is None:
return ret
# change character
attack_action = ret[0]
assert attack_action.type == ActionTypes.MAKE_DAMAGE
attack_action.character_change_idx[1 - self.position.player_idx] = next_idx
return ret
return super().get_actions(match)
return [
self.attack_opposite_active(match, self.damage, self.damage_type),
SwitchCharacterAction(
player_idx=1 - self.position.player_idx, character_idx=next_idx
),
self.charge_self(1),
]


class DandelionBreeze(ElementalBurstBase):
Expand All @@ -127,9 +133,6 @@ def get_actions(self, match: Any) -> List[Actions]:
characters = match.player_tables[self.position.player_idx].characters
heal_action = MakeDamageAction(
damage_value_list=[],
create_objects=[
self.create_summon("Dandelion Field", {"version": self.version})
],
)
for character in characters:
if character.is_alive:
Expand All @@ -144,6 +147,7 @@ def get_actions(self, match: Any) -> List[Actions]:
)
)
ret.append(heal_action)
ret.append(self.create_summon("Dandelion Field", {"version": self.version}))
return ret


Expand Down
34 changes: 18 additions & 16 deletions src/lpsim/server/character/anemo/kaedehara_kazuha_3_8.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,29 +48,34 @@ class Chihayaburu(ElementalSkillBase):
cost: Cost = Cost(elemental_dice_color=DieColor.ANEMO, elemental_dice_number=3)

def get_actions(self, match: Any) -> List[Actions]:
ret: List[Actions] = []
# make damage
ret.append(
return [
self.attack_opposite_active(
match,
self.damage,
self.damage_type,
[self.create_character_status("Midare Ranzan: New")],
)
)
),
self.create_character_status("Midare Ranzan: New"),
self.charge_self(1),
]

def event_handler_SKILL_END(
self, event: SkillEndEventArguments, match: Any
) -> List[SwitchCharacterAction]:
if event.action.position.id != self.id:
# not using this skill, do nothing
return []
# switch character
next_character = match.player_tables[
self.position.player_idx
].next_character_idx()
if next_character is not None:
ret.append(
return [
SwitchCharacterAction(
player_idx=self.position.player_idx,
character_idx=next_character,
)
)
ret.append(self.charge_self(1))
return ret
]
return []


class KazuhaSlash(ElementalBurstBase):
Expand All @@ -82,12 +87,9 @@ class KazuhaSlash(ElementalBurstBase):
)

def get_actions(self, match: Any) -> List[Actions]:
return super().get_actions(
match,
[
self.create_summon("Autumn Whirlwind"),
],
)
return super().get_actions(match) + [
self.create_summon("Autumn Whirlwind"),
]


# Talents
Expand Down
18 changes: 6 additions & 12 deletions src/lpsim/server/character/anemo/maguu_kenki_3_3.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,9 @@ def get_actions(self, match: Any) -> List[Actions]:
"""
gather two actions
"""
return super(BB_3_4, self).get_actions(
match,
[
self.create_summon("Shadowsword: Lone Gale"),
],
)
return super(BB_3_4, self).get_actions(match) + [
self.create_summon("Shadowsword: Lone Gale"),
]


class FrostyAssault(FA_3_4):
Expand All @@ -34,12 +31,9 @@ def get_actions(self, match: Any) -> List[Actions]:
"""
gather two actions
"""
return super(FA_3_4, self).get_actions(
match,
[
self.create_summon("Shadowsword: Galloping Frost"),
],
)
return super(FA_3_4, self).get_actions(match) + [
self.create_summon("Shadowsword: Galloping Frost"),
]


class MaguuKenki_3_3(MK_3_4):
Expand Down
23 changes: 12 additions & 11 deletions src/lpsim/server/character/anemo/sucrose_3_3.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

from ...modifiable_values import DamageIncreaseValue

from ...action import ActionTypes, Actions
from ...action import Actions, SwitchCharacterAction
from ...struct import Cost

from ...consts import (
Expand Down Expand Up @@ -91,17 +91,18 @@ class AstableAnemohypostasisCreation6308(ElementalSkillBase):
cost: Cost = Cost(elemental_dice_color=DieColor.ANEMO, elemental_dice_number=3)

def get_actions(self, match: Any) -> List[Actions]:
ret = super().get_actions(match)
prev_idx = match.player_tables[
1 - self.position.player_idx
].previous_character_idx()
if prev_idx is None:
return ret
# change character
attack_action = ret[0]
assert attack_action.type == ActionTypes.MAKE_DAMAGE
attack_action.character_change_idx[1 - self.position.player_idx] = prev_idx
return ret
return super().get_actions(match)
return [
self.attack_opposite_active(match, self.damage, self.damage_type),
SwitchCharacterAction(
player_idx=1 - self.position.player_idx, character_idx=prev_idx
),
self.charge_self(1),
]


class ForbiddenCreationIsomer75TypeII(ElementalBurstBase):
Expand All @@ -116,9 +117,9 @@ class ForbiddenCreationIsomer75TypeII(ElementalBurstBase):

def get_actions(self, match: Any) -> List[Actions]:
args = {"talent_activated": self.is_talent_equipped(match)}
return super().get_actions(
match, [self.create_summon("Large Wind Spirit", args)]
)
return super().get_actions(match) + [
self.create_summon("Large Wind Spirit", args)
]


# Talents
Expand Down
40 changes: 25 additions & 15 deletions src/lpsim/server/character/anemo/venti_3_7.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,12 @@

from ...event import RoundEndEventArguments

from ...action import ActionTypes, Actions, ChangeObjectUsageAction, MakeDamageAction
from ...action import (
Actions,
ChangeObjectUsageAction,
MakeDamageAction,
SwitchCharacterAction,
)
from ...struct import Cost

from ...consts import (
Expand Down Expand Up @@ -37,11 +42,14 @@ class Stormeye_3_7(SwirlChangeSummonBase):

def event_handler_ROUND_END(
self, event: RoundEndEventArguments, match: Any
) -> List[MakeDamageAction | ChangeObjectUsageAction]:
) -> List[MakeDamageAction | ChangeObjectUsageAction | SwitchCharacterAction]:
"""
Need to change enemy active
"""
ret = super().event_handler_ROUND_END(event, match)
ret: List[
MakeDamageAction | ChangeObjectUsageAction | SwitchCharacterAction
] = []
ret += super().event_handler_ROUND_END(event, match)
our_active = match.player_tables[self.position.player_idx].active_character_idx
target_characters = match.player_tables[1 - self.position.player_idx].characters
target_idx = our_active
Expand All @@ -53,9 +61,16 @@ def event_handler_ROUND_END(
break
else:
raise AssertionError("No character alive")
attack_action = ret[0]
assert attack_action.type == ActionTypes.MAKE_DAMAGE
attack_action.character_change_idx[1 - self.position.player_idx] = target_idx
if (
target_idx
!= match.player_tables[1 - self.position.player_idx].active_character_idx
):
ret.append(
SwitchCharacterAction(
player_idx=1 - self.position.player_idx,
character_idx=target_idx,
)
)
return ret


Expand All @@ -79,14 +94,9 @@ def get_actions(self, match: Any) -> List[Actions]:
talent_activated = False
if self.is_talent_equipped(match):
talent_activated = True
return super().get_actions(
match,
[
self.create_team_status(
"Stormzone", {"talent_activated": talent_activated}
)
],
)
return super().get_actions(match) + [
self.create_team_status("Stormzone", {"talent_activated": talent_activated})
]


class WindsGrandOde(ElementalBurstBase):
Expand All @@ -102,7 +112,7 @@ def get_actions(self, match: Any) -> List[Actions]:
Attack and create object
"""
# create summon first, so it can change element immediately.
return super().get_actions(match, [self.create_summon("Stormeye")])
return super().get_actions(match) + [self.create_summon("Stormeye")]


# Talents
Expand Down
9 changes: 3 additions & 6 deletions src/lpsim/server/character/anemo/wanderer_4_1.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,12 +97,9 @@ def get_actions(self, match: Any) -> List[Actions]:
"""
Attack and create object
"""
return super().get_actions(
match,
[
self.create_character_status("Windfavored"),
],
)
return super().get_actions(match) + [
self.create_character_status("Windfavored"),
]


class KyougenFiveCeremonialPlays(ElementalBurstBase):
Expand Down
9 changes: 3 additions & 6 deletions src/lpsim/server/character/anemo/xiao_3_7.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,9 @@ def get_actions(self, match: Any) -> List[Actions]:
args = {}
if self.is_talent_equipped(match):
args["skill_cost_decrease_usage"] = 2
return super().get_actions(
match,
[
self.create_character_status("Yaksha's Mask", args),
],
)
return super().get_actions(match) + [
self.create_character_status("Yaksha's Mask", args),
]


# Talents
Expand Down
Loading

0 comments on commit 7091887

Please sign in to comment.