Initial commit: Plants turn-based battle game
This commit is contained in:
@@ -0,0 +1,37 @@
|
||||
from __future__ import annotations
|
||||
|
||||
TYPE_RADIANT = "radiant"
|
||||
TYPE_NOCTURNAL = "nocturnal"
|
||||
TYPE_ICE = "ice"
|
||||
TYPE_GARDEN = "garden"
|
||||
TYPE_WILDFLOWER = "wildflower"
|
||||
|
||||
ALL_TYPES = (TYPE_RADIANT, TYPE_NOCTURNAL, TYPE_ICE, TYPE_GARDEN, TYPE_WILDFLOWER)
|
||||
|
||||
# type_beats[X] = the type that X is strong against
|
||||
TYPE_BEATS = {
|
||||
TYPE_RADIANT: TYPE_NOCTURNAL,
|
||||
TYPE_NOCTURNAL: TYPE_ICE,
|
||||
TYPE_ICE: TYPE_GARDEN,
|
||||
TYPE_GARDEN: TYPE_WILDFLOWER,
|
||||
TYPE_WILDFLOWER: TYPE_RADIANT,
|
||||
}
|
||||
|
||||
TYPE_ADVANTAGE_MULT = 1.4 # hitting a type you're strong against
|
||||
TYPE_DISADVANTAGE_MULT = 0.7 # hitting a type that's strong against you
|
||||
|
||||
|
||||
def type_multiplier(attacker_type: str, defender_type: str) -> float:
|
||||
"""Damage multiplier between two plant types. Only affects damage."""
|
||||
if TYPE_BEATS.get(attacker_type) == defender_type:
|
||||
return TYPE_ADVANTAGE_MULT
|
||||
if TYPE_BEATS.get(defender_type) == attacker_type:
|
||||
return TYPE_DISADVANTAGE_MULT
|
||||
return 1.0
|
||||
|
||||
|
||||
def type_relations(ptype: str):
|
||||
"""Return (strong_against, weak_against) for a type."""
|
||||
strong = TYPE_BEATS.get(ptype)
|
||||
weak = next((k for k, v in TYPE_BEATS.items() if v == ptype), None)
|
||||
return strong, weak
|
||||
Reference in New Issue
Block a user