-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
23 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,26 @@ | ||
from enum import Enum | ||
|
||
from typing import TYPE_CHECKING | ||
if TYPE_CHECKING: | ||
from ..character import Character | ||
|
||
class ReactionType(Enum): | ||
NOTHING = 0 | ||
DODGE = 1 | ||
FIGHT_BACK = 2 | ||
|
||
class ReactionStrategy: | ||
def reply(self, character: "Character", attacker: "Character") -> ReactionType: | ||
def reply(self, character: Character, attacker: Character) -> ReactionType: | ||
raise NotImplementedError() | ||
|
||
class NothingReactionStrategy(ReactionStrategy): | ||
def reply(self, character: "Character", attacker: "Character") -> ReactionType: | ||
def reply(self, character: Character, attacker: Character) -> ReactionType: | ||
return ReactionType.NOTHING | ||
|
||
class DodgeReactionStrategy(ReactionStrategy): | ||
def reply(self, character: "Character", attacker: "Character") -> ReactionType: | ||
def reply(self, character: Character, attacker: Character) -> ReactionType: | ||
return ReactionType.DODGE | ||
|
||
class FightBackReactionStrategy(ReactionStrategy): | ||
def reply(self, character: "Character", attacker: "Character") -> ReactionType: | ||
def reply(self, character: Character, attacker: Character) -> ReactionType: | ||
return ReactionType.FIGHT_BACK |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,25 @@ | ||
import random | ||
from typing import List | ||
|
||
from typing import TYPE_CHECKING | ||
if TYPE_CHECKING: | ||
from ..character import Character | ||
|
||
class TargetSelectionStrategy: | ||
def select_target(self, character: "Character", characters: List["Character"]) -> "Character": | ||
def select_target(self, character: Character, characters: List[Character]) -> Character: | ||
raise NotImplementedError() | ||
|
||
class RandomTargetSelectionStrategy(TargetSelectionStrategy): | ||
def select_target(self, character: "Character", characters: List["Character"]) -> "Character": | ||
def select_target(self, character: Character, characters: List[Character]) -> Character: | ||
target_candidates = [target for target in characters if target.side != character.side and target.hp > 0] | ||
return random.choice(target_candidates) | ||
|
||
class MinimumHpTargetSelectionStrategy(TargetSelectionStrategy): | ||
def select_target(self, character: "Character", characters: List["Character"]) -> "Character": | ||
def select_target(self, character: Character, characters: List[Character]) -> Character: | ||
target_candidates = [target for target in characters if target.side != character.side and target.hp > 0] | ||
return min(target_candidates, key=lambda target: target.hp) | ||
|
||
class MaximumHpTargetSelectionStrategy(TargetSelectionStrategy): | ||
def select_target(self, character: "Character", characters: List["Character"]) -> "Character": | ||
def select_target(self, character: Character, characters: List[Character]) -> Character: | ||
target_candidates = [target for target in characters if target.side != character.side and target.hp > 0] | ||
return max(target_candidates, key=lambda target: target.hp) |