Skip to content

Commit

Permalink
feat(#267): Added poke to Fight descision
Browse files Browse the repository at this point in the history
  • Loading branch information
lxgr-linux committed Nov 20, 2024
1 parent 7eee240 commit 821fe71
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 11 deletions.
2 changes: 1 addition & 1 deletion pokete_classes/deck.py
Original file line number Diff line number Diff line change
Expand Up @@ -274,4 +274,4 @@ def control(self, inp):
)


deck: Deck | None = None
deck: Deck
12 changes: 8 additions & 4 deletions pokete_classes/fight/fight_decision.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,19 @@ class Result(Enum):
class FightDecision:
def __init__(
self, result: Result, attack: Attack | None = None,
item: InvItem | None = None
item: InvItem | None = None, poke: int | None = None
):
self.result: Result = result
self.attack_value: Attack | None = attack
self.item_value: InvItem | None = item
self.poke: int | None = poke

def to_dict(self) -> FightDecisionData:
result: FightDecisionData = {
"result": self.result.value,
"attack": None if self.attack_value is None else self.attack_value.index,
"item": None if self.item_value is None else self.item_value.name,
"poke": self.poke
}
return result

Expand All @@ -46,13 +48,15 @@ def from_dict(
attack = _poke.attack_obs[_poke.attacks.index(_d["attack"])]
return cls.attack(attack)
case Result.ITEM.value:
assert _d["item"] is not None
assert _d["item"] in _player["items"].keys()
item = getattr(invitems, _d["item"])
return cls.item(item)
case Result.RUN_AWAY.value:
return cls.run_away()
case Result.CHOOSE_POKE.value:
return cls.run_away()
assert _d["poke"] is not None
return cls.choose_poke(_d["poke"])
case _:
assert False

Expand All @@ -70,5 +74,5 @@ def item(cls, item: InvItem) -> "FightDecision":
return cls(Result.ITEM, item=item)

@classmethod
def choose_poke(cls) -> "FightDecision":
return cls(Result.CHOOSE_POKE)
def choose_poke(cls, poke: int) -> "FightDecision":
return cls(Result.CHOOSE_POKE, poke=poke)
6 changes: 4 additions & 2 deletions pokete_classes/fight/fightmap/fightmap.py
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,9 @@ def fast_change(self, arr, setob):
self.show()
time.sleep(SPEED_OF_TIME * 0.1)

def get_figure_attack(self, ctx: Context, player, enem) -> FightDecision:
def get_figure_attack(
self, ctx: Context, player: Provider, enem: Provider
) -> FightDecision:
"""Chooses the players attack
ARGS:
player: The players provider
Expand Down Expand Up @@ -248,7 +250,7 @@ def get_figure_attack(self, ctx: Context, player, enem) -> FightDecision:
if not self.choose_poke(ctx, player):
self.show(init=True)
continue
return FightDecision.choose_poke()
return FightDecision.choose_poke(player.play_index)
loops.std(ctx)
self.show()

Expand Down
8 changes: 6 additions & 2 deletions pokete_classes/fight/providers.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,15 @@ class Provider(ABC):
ARGS:
pokes: The Poketes the Provider holds"""

def __init__(self, pokes: list[Poke], escapable:bool, xp_multiplier:int):
def __init__(self,
pokes: list[Poke], escapable:bool, xp_multiplier:int,
inv: dict[str, int] | None = None
):
self.pokes = pokes
self.escapable = escapable
self.xp_multiplier = xp_multiplier
self.play_index = 0
self.inv: dict[str, int] = {} if inv is None else inv

def heal(self):
"""Heals all poketes"""
Expand All @@ -44,7 +48,7 @@ def index_conf(self):
i for i, poke in enumerate(self.pokes) if poke.hp > 0
)

def remove_item(self, name:str):
def remove_item(self, name:str, amount:int=1):
"""Removes and item from the providers inventory
Accept for the player implementation that shouldnt do anything"""
return
Expand Down
1 change: 1 addition & 0 deletions pokete_classes/multiplayer/msg/fight/fight_decision.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ class FightDecisionData(TypedDict):
result: int
attack: str | None
item: str | None
poke: int | None


class FightDecision(bs_rpc.Body):
Expand Down
2 changes: 1 addition & 1 deletion pokete_classes/multiplayer/remote_fight/figure_wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def __init__(self,
self.outgoing = outgoing
self.incomming = incomming
self.figure = figure
super().__init__(figure.pokes, figure.escapable, figure.xp_multiplier)
super().__init__(figure.pokes, figure.escapable, figure.xp_multiplier, figure.inv)

@property
def caught_pokes(self):
Expand Down
2 changes: 1 addition & 1 deletion pokete_classes/multiplayer/remote_fight/provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def __init__(self, name: str,
super().__init__(
[Poke(
poke["name"], _xp=poke["xp"], _hp=poke["hp"], _ap=poke["ap"], _attacks=poke["attacks"], _effects=poke["effects"], player=False, shiny=poke["shiny"], nature=poke["nature"], stats=poke["stats"]
) for poke in self.player["pokes"]], False, 4)
) for poke in self.player["pokes"]], False, 4, self.player["items"])

def greet(self, fightmap: FightMap):
fightmap.outp.outp(f"Fight started with {self.name}, good luck!")
Expand Down

0 comments on commit 821fe71

Please sign in to comment.