-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgreat.py
116 lines (98 loc) · 4.22 KB
/
great.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
from __future__ import annotations
from typing import List, NoReturn, ForwardRef, Tuple
from openciv.engine.managers.i18n import T_TranslationOrStr
from openciv.engine.exceptions.great_exception import GreatPersonTreeNotLoaded
from openciv.engine.saving import SaveAble
from openciv.engine.managers.log import LogManager
from openciv.gameplay.effect import Effects
from openciv.gameplay.resource import Resource
from openciv.gameplay.resources.core.mechanics._base import BaseGreatMechanicResource
class Great(SaveAble):
def __init__(
self,
key: str,
name: T_TranslationOrStr,
description: T_TranslationOrStr,
resource_type_required: Resource | None | Tuple | BaseGreatMechanicResource | List = None,
cost: float = 0.0,
*args,
**kwargs,
):
super().__init__(*args, **kwargs)
self.key: str = key
self.name: T_TranslationOrStr = name
self.description: T_TranslationOrStr = description
self.cost: float = cost
self.bought: bool = False
self.on_map: bool = False
self.effects: Effects = Effects()
self.resource_type_required: Resource | None | Tuple | BaseGreatMechanicResource | List = resource_type_required
self._setup_saveable()
class GreatsTree(SaveAble):
def __init__(
self,
key: str,
name: T_TranslationOrStr,
description: T_TranslationOrStr,
greats: List[Great] = [],
points: float = 0.0,
*args,
**kwargs,
):
super().__init__(*args, **kwargs)
self.key: str = key
self.greats: List[Great] = greats
self.points: float = points
self.name: T_TranslationOrStr = name
self.description: T_TranslationOrStr = description
self.effects_on_finish: Effects = Effects()
self._setup_saveable()
def buy_great(self, great: Great) -> Great:
self.points -= great.points
LogManager.get_instance().gameplay.debug(f"Bought Great {great.__class__.__name__} for {great.points} points")
return great
def add_great(self, great: Great) -> NoReturn:
self.greats.append(great)
LogManager.get_instance().gameplay.debug(f"Added Great {great.__class__.__name__} to {self.name}")
def remove_great(self, great: Great) -> NoReturn:
self.greats.remove(great)
LogManager.get_instance().gameplay.debug(f"Removed Great {great.__class__.__name__} from {self.name}")
def __add__(self, b: int | float | Great) -> ForwardRef("GreatsTree"):
if isinstance(b, Great):
self.add_great(b)
return self
LogManager.get_instance().gameplay.debug(f"Adding {b.__class__.__name__} points to {self.name}")
self.points += float(b)
return self
def __radd__(self, b: int | float | Great) -> ForwardRef("GreatsTree"):
return self.__add__(b)
def __sub__(self, b: int | float | Great) -> ForwardRef("GreatsTree"):
if isinstance(b, Great):
self.remove_great(b)
return self
LogManager.get_instance().gameplay.debug(f"Subtracting {b} points from {self.name}")
self.points -= float(b)
return self
def __rsub__(self, b: int | float | Great) -> ForwardRef("GreatsTree"):
return self.__sub__(b)
class Greats:
def __init__(self, loaded_great_trees: List[GreatsTree] = []):
self.loaded_trees: List[GreatsTree] = loaded_great_trees
def _check_tree_exists(self, tree: str, exception_on_fail: bool = True):
if tree not in self.categories:
if exception_on_fail:
raise GreatPersonTreeNotLoaded(f"Great Person Tree {tree} not loaded")
return False
return True
def addTree(self, tree: str):
self._check_tree_exists(tree, True)
self.loaded_trees.append(tree)
def addPoint(self, tree: str, amount: int | float):
self._check_tree_exists(tree, True)
self.loaded_trees[tree] += amount
def decreasePoints(self, tree: str, amount: int | float):
self._check_tree_exists(tree, True)
self.loaded_trees[tree] -= amount
def setPoints(self, tree: str, amount: int | float):
self._check_tree_exists(tree, True)
self.loaded_trees[tree] = amount