-
Notifications
You must be signed in to change notification settings - Fork 81
/
Copy pathnb01EmgrPhase0.py
333 lines (282 loc) · 14.3 KB
/
nb01EmgrPhase0.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
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
# -*- coding: utf-8 -*-
""" *==LICENSE==*
CyanWorlds.com Engine - MMOG client, server and tools
Copyright (C) 2011 Cyan Worlds, Inc.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
Additional permissions under GNU GPL version 3 section 7
If you modify this Program, or any covered work, by linking or
combining it with any of RAD Game Tools Bink SDK, Autodesk 3ds Max SDK,
NVIDIA PhysX SDK, Microsoft DirectX SDK, OpenSSL library, Independent
JPEG Group JPEG library, Microsoft Windows Media SDK, or Apple QuickTime SDK
(or a modified version of those libraries),
containing parts covered by the terms of the Bink SDK EULA, 3ds Max EULA,
PhysX SDK EULA, DirectX SDK EULA, OpenSSL and SSLeay licenses, IJG
JPEG Library README, Windows Media SDK EULA, or QuickTime SDK EULA, the
licensors of this Program grant you additional
permission to convey the resulting work. Corresponding Source for a
non-source form of such a combination shall include the source code for
the parts of OpenSSL and IJG JPEG Library used as well as that of the covered
work.
You can contact Cyan Worlds, Inc. by email [email protected]
or by snail mail at:
Cyan Worlds, Inc.
14617 N Newport Hwy
Mead, WA 99021
*==LICENSE==* """
from Plasma import *
from PlasmaTypes import *
import random
# These are helper functions for the special state variables that need custom code.
def Ayhoheek5Man1State(VARname, NewSDLValue):
PtDebugPrint("nb01EmgrPhase0.Ayhoheek5Man1State(): Attempting to set '{}' to a value of {}".format(VARname, NewSDLValue))
nb01Ayhoheek5Man1StateMaxINT = 2
if NewSDLValue > nb01Ayhoheek5Man1StateMaxINT:
PtDebugPrint("ERROR: nb01EmgrPhase0.Ayhoheek5Man1State:\tERROR: Variable '{}'' expected range from 0-{}. Received value of {}.".format(VARname, nb01Ayhoheek5Man1StateMaxINT, NewSDLValue))
return
elif NewSDLValue == 0:
PtDebugPrint("DEBUG: nb01EmgrPhase0.Ayhoheek5Man1State:\tPaging out 5 Man Heek table completely.")
PtPageOutNode("nb01Ayhoheek5Man1State")
PtPageOutNode("nb01Ayhoheek5Man1Dead")
elif NewSDLValue == 1:
PtDebugPrint("DEBUG: nb01EmgrPhase0.Ayhoheek5Man1State:\tPaging in broken 5 Man Heek table.")
PtPageInNode("nb01Ayhoheek5Man1Dead")
PtPageOutNode("nb01Ayhoheek5Man1State")
elif NewSDLValue == 2:
PtDebugPrint("DEBUG: nb01EmgrPhase0.Ayhoheek5Man1State:\tPaging in functional 5 Man Heek table.")
PtPageInNode("nb01Ayhoheek5Man1State")
PtPageOutNode("nb01Ayhoheek5Man1Dead")
else:
PtDebugPrint("ERROR: nb01EmgrPhase0.Ayhoheek5Man1State:\tERROR: Invalid value ({}) for variable '{}'.".format(NewSDLValue, VARname))
return
class nb01EmgrPhase0(ptResponder):
# State options for Neighborhood decoration randomization
HoodDecorations = {
"nb01ClockVis": (0, 1),
"nb01GardenFungusVis": (0, 1),
"nb01DestructionCracksVis": (0, 1),
"nb01LanternsVis": (0, 1),
"nb01LampOption01Vis": (0, 1),
"nb01OldImager01Vis": (0, 1),
"nb01OldImager02Vis": (0, 1),
"nb01WaterfallTorchesVis": (0, 1),
"nb01ResidenceAdditionsVis": (0, 1),
"nb01StainedWindowOption": (0, 1, 2)
}
# These booleans will page in/out the page sharing their name.
SimplePagingVars = [
"nb01LinkBookGarrisonVis",
]
# This maps a state variable to a helper function which
# will be called on updates to that variable.
# Calling convention is func(varName, newValue)
SpecialPagingVars = {
'nb01Ayhoheek5Man1State': Ayhoheek5Man1State,
}
# Link Room Pedestal randomization options
Pedestals = {
"Left": {
# ----
#"sdlState": "nb01LinkBookGarrisonVis",
#"sdlGlass": "nb01StainedWindowOption",
#"Books" : {
# 1: {"Name": "Gahreesen", "Glasses": (1, 2)},
#}
# ----
# The Gahreesen Stained Glass doesn't observe the proper on/off rules
# So we won't try to regulate the Left position
},
"Center": {
"sdlState": "nb01LinkBookEderToggle",
"sdlGlass": "nb01StainedGlassEders",
"Books" : {
#1: Kemo -- deprecated
2: {"Name": "EderDelin", "Glasses": (1, 2, 3)},
3: {"Name": "EderTsogal", "Glasses": (4, 5, 6)},
}
},
"Right": {
"sdlState": "nb01LinkBookGZVis",
"sdlGlass": "nb01StainedGlassGZ",
"Books" : {
1: {"Name": "GreatZero", "Glasses": (1, 2, 3)},
}
}
}
def __init__(self):
ptResponder.__init__(self)
random.seed()
self.id = 5222
self.version = 7
PtDebugPrint("__init__nb01EmgrPhase0 v.{}".format(self.version))
self.PedestalSDL = []
self._pedestalSDLValues = {}
self._ageVault = None
self._updateAgeSDL = False
# Store these in a list for convenience
for position in self.Pedestals:
if self.Pedestals[position]:
self.PedestalSDL.append(self.Pedestals[position]["sdlState"])
self.PedestalSDL.append(self.Pedestals[position]["sdlGlass"])
def OnServerInitComplete(self):
ageSDL = PtGetAgeSDL()
if not ageSDL:
PtDebugPrint("nb01EmgrPhase0.OnServerInitComplete:\tNo ageSDL. We're done here.")
return
for sdlVar in self.PedestalSDL:
ageSDL.setFlags(sdlVar, 1, 1)
ageSDL.sendToClients(sdlVar)
ageSDL.setNotify(self.key, sdlVar, 0.0)
self._pedestalSDLValues[sdlVar] = ageSDL[sdlVar][0]
PtDebugPrint("nb01EmgrPhase0.OnServerInitComplete(): Pedestal SDL variable {} = {}".format(sdlVar, self._pedestalSDLValues[sdlVar]))
for sdlVar in self.SimplePagingVars:
ageSDL.setFlags(sdlVar, 1, 1)
ageSDL.sendToClients(sdlVar)
ageSDL.setNotify(self.key, sdlVar, 0.0)
self.IManageSimplePagingVar(sdlVar)
for sdlVar in self.SpecialPagingVars:
ageSDL.setFlags(sdlVar, 1, 1)
ageSDL.sendToClients(sdlVar)
ageSDL.setNotify(self.key, sdlVar, 0.0)
self.SpecialPagingVars[sdlVar](sdlVar, ageSDL[sdlVar][0])
# Set up the linking room pedestals.
if self.sceneobject.isLocallyOwned():
PtDebugPrint("nb01EmgrPhase0.OnServerInitComplete(): Check all pedestal books and stained glasses for sanity.")
for position in self.Pedestals:
if self.Pedestals[position]:
self.IManageLinkPedestal(position)
# Age State Randomization
# This used to be in the Nexus, but that would never affect server-generated hoods
if self.sceneobject.isLocallyOwned():
self._RandomizeNeighborhood()
# Save the AgeVaultSDL if we need to...
self._SaveSDL()
def OnSDLNotify(self, VARname, SDLname, PlayerID, tag):
ageSDL = PtGetAgeSDL()
PtDebugPrint("nb01EmgrPhase0.OnSDLNotify():\tVARname: {}, SDLname: {}, tag: {}, value: {}".format(VARname, SDLname, tag, ageSDL[VARname][0]))
if VARname in self.SimplePagingVars:
self.IManageSimplePagingVar(VARname)
elif VARname in self.SpecialPagingVars.keys():
NewSDLValue = ageSDL[VARname][0]
self.SpecialPagingVars[VARname](VARname, NewSDLValue)
elif VARname in self.PedestalSDL:
self._pedestalSDLValues[VARname] = ageSDL[VARname][0]
PtDebugPrint("nb01EmgrPhase0.OnSDLNotify():\t{} = {}".format(VARname, self._pedestalSDLValues[VARname]))
else:
PtDebugPrint("ERROR: nb01EmgrPhase0.OnSDLNotify():\tVariable '{}' was not recognized.".format(VARname))
return
def IManageLinkPedestal(self, position):
"""Manage Pedestal link books and stained glass"""
PtDebugPrint("nb01EmgrPhase0.IManageLinkPedestal(): PedestalPosition = {}".format(position))
if position in self.Pedestals:
pedInfo = self.Pedestals[position]
state = self._pedestalSDLValues[pedInfo["sdlState"]]
if state:
if state in pedInfo["Books"]:
# We have this book...
book = pedInfo["Books"][state]
if self._pedestalSDLValues[pedInfo["sdlGlass"]] not in book["Glasses"]:
# ...but the glass is wrong.
self.IPickPedestalGlass(position, book)
else:
# This is not a valid book for this pedestal. Get a new one.
self.IPickPedestalBook(position)
else:
# No book, clear the glass if it's set.
self.IPickPedestalGlass(position, 0)
else:
PtDebugPrint("nb01EmgrPhase0.IManageLinkPedestal(): No pedestal named '{}'. Ignoring.".format(position))
def IPickPedestalBook(self, position):
if position in self.Pedestals:
# Select a random book from this pedestal's list.
newBookChoice = random.choice(list(self.Pedestals[position]["Books"].keys()))
self._UpdateVaultSDL(self.Pedestals[position]["sdlState"], newBookChoice)
newBook = self.Pedestals[position]["Books"][newBookChoice]
PtDebugPrint("nb01EmgrPhase0.IPickPedestalBook():\tSelecting {} as new book for pedestal.".format(newBook["Name"]))
# Update the stained glass to match.
self.IPickPedestalGlass(position, newBook)
else:
PtDebugPrint("nb01EmgrPhase0.IPickPedestalBook(): No pedestal named '{}'. Ignoring.".format(position))
def IPickPedestalGlass(self, position, bookInfo):
if position in self.Pedestals:
newGlass = 0
if bookInfo:
# Select a random glass from this book's list.
newGlass = bookInfo["Glasses"][random.randint(0, len(bookInfo["Glasses"]) - 1)]
PtDebugPrint("nb01EmgrPhase0.IPickPedestalGlass():\tSelecting stained glass #{} to match book for {}.".format(newGlass, bookInfo["Name"]))
else:
PtDebugPrint("nb01EmgrPhase0.IPickPedestalGlass():\tNo book. Clearing stained glass.")
self._UpdateVaultSDL(self.Pedestals[position]["sdlGlass"], newGlass)
else:
PtDebugPrint("nb01EmgrPhase0.IPickPedestalGlass(): No pedestal named '{}'. Ignoring.".format(position))
def _SaveSDL(self):
if self._updateAgeSDL:
self._ageVault.updateAgeSDL(self._ageSDL)
del self._ageSDL
self._updateAgeSDL = False
def _UpdateSimpleStateVar(self, ageSDL, sdlName, value, overwrite=True):
if isinstance(ageSDL, ptSDLStateDataRecord):
var = ageSDL.findVar(sdlName)
if var is None:
PtDebugPrint("nb01EmgrPhase0._UpdateSimpleStateVar(): '{}' not found!".format(sdlName))
return
elif isinstance(ageSDL, ptSimpleStateVariable):
var = ageSDL
else:
raise TypeError("ageSDL must be a ptSDLStateDataRecord or a ptSimpleStateVariable")
if not overwrite and var.isUsed():
PtDebugPrint("nb01EmgrPhase0._UpdateSimpleStateVar(): Skipping update of '{}'".format(sdlName), level=kDebugDumpLevel)
return
if var.getType() == PtSDLVarType.kBool:
var.setBool(value)
elif var.getType() in (PtSDLVarType.kInt, PtSDLVarType.kByte):
var.setInt(value)
elif var.getType() == PtSDLVarType.kString32:
var.setString(value)
else:
PtDebugPrint("nb01EmgrPhase0._UpdateSimpleStateVar(): '{}' has an unknown type!".format(sdlName))
return
PtDebugPrint("nb01EmgrPhase0._UpdateSimpleStateVar(): '{}' = {}".format(sdlName, value))
self._updateAgeSDL = True
def _UpdateVaultSDL(self, sdlVar, value, overwrite=True):
if not self._ageVault:
self._ageVault = ptAgeVault()
if not self._ageVault:
PtDebugPrint("nb01EmgrPhase0._UpdateVaultSDL():\tNo AgeVault?!")
return
self._ageSDL = self._ageVault.getAgeSDL()
if not self._ageSDL:
PtDebugPrint("nb01EmgrPhase0._UpdateVaultSDL():\tVaultSDL is null?!")
return
if sdlVar and value:
self._UpdateSimpleStateVar(self._ageSDL, sdlVar, value, overwrite)
def _RandomizeNeighborhood(self):
"""Does initial state scrambling for the Neighborhood.
This makes all hoods have a slightly different appearance (hopefully)"""
PtDebugPrint("nb01EmgrPhase0._RandomizeNeighborhood(): ---Attempting to Randomize SDL---")
for name, values in self.HoodDecorations.items():
self._UpdateVaultSDL(name, random.choice(values), overwrite=False)
PtDebugPrint("nb01EmgrPhase0._RandomizeNeighborhood(): ---SDL Randomized!---")
def IManageSimplePagingVar(self, VARname):
"""Load or unload a page based on the value of the specified SDL"""
ageSDL = PtGetAgeSDL()
try:
if ageSDL[VARname][0] == 1: # Are we paging things in?
PtDebugPrint("DEBUG: nb01EmgrPhase0.IManageSimplePagingVar:\tPaging in {}".format(VARname))
PtPageInNode(VARname)
elif ageSDL[VARname][0] == 0: # Are we paging things out?
PtDebugPrint("DEBUG: nb01EmgrPhase0.IManageSimplePagingVar:\tPaging out {}".format(VARname))
PtPageOutNode(VARname)
else:
PtDebugPrint("ERROR: nb01EmgrPhase0.IManageSimplePagingVar:\tVariable '{}' had unexpected value of {} (should be a boolean).".format(VARname, ageSDL[VARname][0]))
except:
PtDebugPrint("ERROR: nb01EmgrPhase0.IManageSimplePagingVar:\tError managing variable '{}'".format(VARname))
return