Initial commit: Plants turn-based battle game
This commit is contained in:
@@ -0,0 +1,44 @@
|
||||
from __future__ import annotations
|
||||
|
||||
MAX_LEVEL = 50
|
||||
STAGE_MULT = [1.0, 1.25, 1.55, 1.9, 2.3]
|
||||
GROWTH = {"attack": 0.06, "defense": 0.06, "health": 0.05, "speed": 0.04}
|
||||
EVOLVE_STAGE_AT_LEVEL = {2: 10, 3: 20, 4: 30, 5: 40} # evolve to stage 2/3/4/5 at these levels
|
||||
EVOLVE_COST = {2: 2, 3: 4, 4: 6, 5: 8} # duplicates consumed to evolve
|
||||
|
||||
|
||||
def compute_stats(base_stats, level: int = 1, stage: int = 1):
|
||||
"""base_stats = (attack, speed, defense, health); returns leveled stats."""
|
||||
mult = STAGE_MULT[max(0, min(len(STAGE_MULT) - 1, stage - 1))]
|
||||
atk, spd, dfn, hp = base_stats
|
||||
|
||||
def scale(v, growth):
|
||||
return int(v * mult * (1 + growth * (level - 1)))
|
||||
|
||||
return (scale(atk, GROWTH["attack"]),
|
||||
scale(spd, GROWTH["speed"]),
|
||||
scale(dfn, GROWTH["defense"]),
|
||||
scale(hp, GROWTH["health"]))
|
||||
|
||||
|
||||
def xp_to_next(level: int) -> int:
|
||||
return 40 * level
|
||||
|
||||
|
||||
def stage_for_level(level: int) -> int:
|
||||
stage = 1
|
||||
for s in (2, 3, 4, 5):
|
||||
if level >= EVOLVE_STAGE_AT_LEVEL[s]:
|
||||
stage = s
|
||||
return stage
|
||||
|
||||
|
||||
def can_evolve(level: int, stage: int, duplicates: int) -> bool:
|
||||
target = stage + 1
|
||||
if target not in EVOLVE_STAGE_AT_LEVEL:
|
||||
return False
|
||||
return level >= EVOLVE_STAGE_AT_LEVEL[target] and duplicates >= EVOLVE_COST[target]
|
||||
|
||||
|
||||
def evolve_cost(stage: int) -> int:
|
||||
return EVOLVE_COST.get(stage + 1, 0) if stage + 1 in EVOLVE_COST else 0
|
||||
Reference in New Issue
Block a user