Initial commit: Plants turn-based battle game
This commit is contained in:
@@ -0,0 +1,73 @@
|
||||
from __future__ import annotations
|
||||
|
||||
from dataclasses import dataclass, field
|
||||
from typing import List
|
||||
|
||||
from .skills import S_ATTACKED_THIS_TURN, Skill
|
||||
|
||||
TEAM_PLAYER = 0
|
||||
TEAM_ENEMY = 1
|
||||
|
||||
ROLE_ATTACKER = "attacker"
|
||||
ROLE_SUPPORT = "support"
|
||||
ROLE_TANK = "tank"
|
||||
ROLES = (ROLE_ATTACKER, ROLE_SUPPORT, ROLE_TANK)
|
||||
|
||||
# Shared presentation for roles: human name, accent color, and icon file.
|
||||
ROLE_NAMES = {
|
||||
ROLE_ATTACKER: "Attacker",
|
||||
ROLE_SUPPORT: "Support",
|
||||
ROLE_TANK: "Tank",
|
||||
}
|
||||
ROLE_ICONS = {
|
||||
ROLE_ATTACKER: "attacker_icon",
|
||||
ROLE_SUPPORT: "supporter_icon",
|
||||
ROLE_TANK: "tank_icon",
|
||||
}
|
||||
ROLE_COLORS = {
|
||||
ROLE_ATTACKER: (235, 130, 90),
|
||||
ROLE_SUPPORT: (120, 155, 235),
|
||||
ROLE_TANK: (235, 200, 90),
|
||||
}
|
||||
|
||||
|
||||
@dataclass
|
||||
class Unit:
|
||||
name: str
|
||||
team: int
|
||||
plant_type: str
|
||||
max_hp: int
|
||||
attack: int
|
||||
speed: int
|
||||
defense: int
|
||||
skills: List[Skill]
|
||||
role: str = ""
|
||||
crit: float = 0.10
|
||||
passive: str = ""
|
||||
passive_value: int = 0
|
||||
sort_order: int = 0
|
||||
runes: List = field(default_factory=list) # (effect_key, pct_fraction) per equipped rune
|
||||
|
||||
hp: int = field(init=False)
|
||||
alive: bool = field(init=False)
|
||||
status: dict = field(default_factory=dict)
|
||||
acted: bool = field(default=False)
|
||||
next_at: float = field(default=0.0)
|
||||
level: int = field(default=1)
|
||||
stage: int = field(default=1)
|
||||
first_skill_used: bool = field(default=False) # primrose
|
||||
used_once: bool = field(default=False) # generic "first time" flags
|
||||
injected_index: int = field(default=-1, init=False)
|
||||
injected_name: str = field(default="", init=False)
|
||||
|
||||
def __post_init__(self) -> None:
|
||||
self.hp = self.max_hp
|
||||
self.alive = True
|
||||
self.status = {}
|
||||
|
||||
def reset_turn_flags(self) -> None:
|
||||
self.acted = False
|
||||
self.status.pop(S_ATTACKED_THIS_TURN, None)
|
||||
|
||||
def __repr__(self) -> str:
|
||||
return self.name
|
||||
Reference in New Issue
Block a user