forked from Pizzaandy/EternalEncounterBuilder
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patheternalevents.py
196 lines (162 loc) · 5.62 KB
/
eternalevents.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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
import chevron
from textwrap import dedent
# bruh
camelcase = lambda test_str: test_str[:1].lower() + test_str[1:] if test_str else ''
# (alias, total_args, optional_args)
event_to_ebl = {}
ebl_to_event = {}
class EternalEvent:
ev_template = dedent("""\
eventCall = {
eventDef = "{{name}}";
args = {
num = {{count}};
{{#items}}
item[{{index}}] = {
{{var}} = {{{value}}}
}
{{/items}}
}
}
""")
decl_template = dedent("""\
{
{{varname}} = {{{value}}}
}""")
def stringify(self):
items = [
{
"index": index,
"value": (f'"{val[1]}";' if isinstance(val[1], str)
and val[1] not in ["NULL", "true", "false"]
else f'{val[1]};'),
"var": var[1]
}
for index, (val, var) in enumerate(zip(vars(self).items(), self.args))
]
#print(items)
name = camelcase(type(self).__name__)
for item in items:
if item["var"].startswith("decl"):
varname = item["var"].replace("decl:", "")
item["var"] = "decl"
item["value"] = (
chevron.render(
template=self.decl_template,
data={"varname": varname, "value": item["value"]}))
return chevron.render(
template=self.ev_template,
data={"name": name, "items": items, "count": len(items)})
# metaprogramming time
def __init_subclass__(cls, alias="", **kwargs):
super().__init_subclass__(**kwargs)
# initialize fields
args = []
optional_args = 0
for attr, value in cls.__dict__.items():
if not attr.startswith("__"):
if value[-1] == "*":
value = value.replace("*", "")
optional_args += 1
args.append((attr, value))
cls.args = args
# add event class aliases to dicts
default_alias = camelcase(cls.__name__)
aliases = alias if alias else [camelcase(cls.__name__)]
if not isinstance(aliases, list):
aliases = [aliases]
event_to_ebl[cls.__name__] = (aliases[0], len(args), optional_args)
for item in aliases:
ebl_to_event[item] = (cls.__name__, len(args))
ebl_to_event[default_alias] = (cls.__name__, len(args))
def __init__(self, *args):
for init_arg, (cls_name, cls_args) in zip(args, self.args):
setattr(self, cls_name, init_arg)
def __str__(cls):
return cls.stringify()
class MaintainAICount(EternalEvent, alias=["maintainAI", "maintain"]):
spawnType = "eEncounterSpawnType_t"
desired_count = "int"
max_spawn_count = "int"
min_spawn_delay = "float"
min_ai_for_respawn = "int"
spawnGroup = "entity"
group_level = "string"
max_spawn_delay = "float"
class StaggeredAISpawn(EternalEvent):
spawnType = "eEncounterSpawnType_t"
spawn_count = "int"
spawnGroup = "entity*"
group_label = "string*"
minSpawnStagger = "float"
maxSpawnStagger = "float"
class StopMaintainingAICount(EternalEvent, alias=["stopMaintainAI", "stopMaintain"]):
spawnType = "eEncounterSpawnType_t"
group_label = "string*"
class SpawnAI(EternalEvent):
spawnType = "eEncounterSpawnType_t"
spawn_count = "int"
spawnGroup = "entity"
group_label = "string"
class SpawnSingleAI(EternalEvent, alias="spawn"):
spawnType = "eEncounterSpawnType_t"
spawnTarget = "entity"
group_label = "string*"
class SetMusicState(EternalEvent):
target = "entity"
stateDecl = "decl:soundstate"
designComment = "string"
class MakeAIAwareOfPlayer(EternalEvent, alias="alertAI"):
allActive = "bool"
onSpawn = "bool"
groupLabel = "string*"
restorePerception = "bool"
class ActivateTarget(EternalEvent, alias="activate"):
targetEntity = "entity"
command = "string"
class SetFactionRelation(EternalEvent):
instigatorSpawnType = "eEncounterSpawnType_t"
groupLabel = "string*"
targetSpawnType = "eEncounterSpawnType_t"
relation = "socialEmotion_t"
class ClearFactionOverrides(EternalEvent):
pass
class ForceChargeOnAllAI(EternalEvent):
pass
class WaitMulitpleConditions(EternalEvent):
condition_count = "int"
logic_operator = "encounterLogicOperator_t"
disableAIHighlight = "bool"
class Wait(EternalEvent):
seconds = "float"
disableAIHighlight = "bool"
class WaitAIHealthLevel(EternalEvent, alias="AIHealthLevel"):
aiType = "eEncounterSpawnType_t"
desired_remaing_ai_count = "int"
group_label = "char*"
disableAIHighlight = "bool"
class WaitAIRemaining(EternalEvent, alias="AIRemaining"):
aiType = "eEncounterSpawnType_t"
desired_count = "int"
group_label = "string"
class WaitMaintainComplete(EternalEvent, alias="maintainComplete"):
aiType = "eEncounterSpawnType_t"
remaining_spawn_couunt = "int"
group_label = "string"
class WaitForEventFlag(EternalEvent, alias="Flag"):
eventFlag = "eEncounterEventFlags_t"
userFlag = "string*"
testIfAlreadyRaised = "bool"
disableAIHighlight = "bool"
class DamageAI(EternalEvent):
damageType = "decl:damage"
aiType = "eEncounterSpawnType_t"
group_label = "string*"
class DesignerComment(EternalEvent, alias="print"):
designerComment = "string*"
printToConsole = "bool"
#events = []
#for line in lines:
#if line.startswith("Wave"):
#mylist = get_event_args(SpawnAI)
#print(mylist