Button: Add separate event handler for dropping portraits.
[gemrb.git] / gemrb / GUIScripts / bg2 / LevelUp.py
blob64f3939bc4cb91bf8308f0c4a02c3641cb80fc47
1 # -*-python-*-
2 # GemRB - Infinity Engine Emulator
3 # Copyright (C) 2003-2004 The GemRB Project
5 # This program is free software; you can redistribute it and/or
6 # modify it under the terms of the GNU General Public License
7 # as published by the Free Software Foundation; either version 2
8 # of the License, or (at your option) any later version.
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
15 # You should have received a copy of the GNU General Public License
16 # along with this program; if not, write to the Free Software
17 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20 # LevelUp.py - scripts to control the level up functionality and windows
21 import GemRB
22 from GUIDefines import *
23 from ie_stats import *
24 from ie_restype import RES_2DA
25 from GUICommon import HasTOB, GetLearnablePriestSpells, GetMageSpells, HasSpell, AddClassAbilities, GameIsBG2
26 from GUIREC import GetStatOverview, UpdateRecordsWindow, GetActorClassTitle, GSNN
27 from GUICommonWindows import *
28 from LUCommon import *
29 from LUSpellSelection import *
30 if HasTOB():
31 from LUHLASelection import *
32 from LUProfsSelection import *
33 from LUSkillsSelection import *
34 from Actor import *
36 LevelUpWindow = None
37 DoneButton = 0
38 TextAreaControl = 0
39 InfoCounter = 1
40 NewProfPoints = 0
41 NewSkillPoints = 0
42 LevelDiff = 0
43 Level = 0
44 Classes = 0
45 NumClasses = 0
46 DualSwap = 0
47 KitName = 0
48 IsDual = 0
49 IsMulti = 0
50 pc = 0
51 ClassName = 0
52 actor = 0
54 # old values (so we don't add too much)
55 OldHPMax = 0 # << old maximum hitpoints
56 OldSaves = [0]*5 # << old saves
57 OldThaco = 0 # << old thac0 value
58 OldLore = 0 # << old lore value
59 OldDSpells = [0]*7 # << old divine spells per level
60 OldWSpells = [0]*9 # << old wizard spells per level
61 NewDSpells = [0]*7 # << new divine spells per level
62 NewWSpells = [0]*9 # << new wizard spells per level
63 DeltaDSpells = 0 # << total new divine spells
64 DeltaWSpells = 0 # << total new wizard spells
66 def OpenLevelUpWindow():
67 """Sets up the level up window."""
69 global LevelUpWindow, TextAreaControl, NewProfPoints, actor
70 global DoneButton
71 global NewSkillPoints, KitName, LevelDiff, RaceTable
72 global ClassTable, Level, Classes, NumClasses, DualSwap, ClassSkillsTable, IsMulti
73 global OldHPMax, OldSaves, OldLore, OldThaco, DeltaDSpells, DeltaWSpells
74 global NewDSpells, NewWSpells, OldDSpells, OldWSpells, pc, HLACount, ClassName, IsDual
76 LevelUpWindow = GemRB.LoadWindowObject (3)
78 InfoButton = LevelUpWindow.GetControl (125)
79 InfoButton.SetText (13707)
80 InfoButton.SetEvent (IE_GUI_BUTTON_ON_PRESS, "LevelUpInfoPress")
82 DoneButton = LevelUpWindow.GetControl (0)
83 DoneButton.SetText (11962)
84 DoneButton.SetEvent (IE_GUI_BUTTON_ON_PRESS, "LevelUpDonePress")
85 DoneButton.SetState (IE_GUI_BUTTON_DISABLED)
86 DoneButton.SetFlags (IE_GUI_BUTTON_DEFAULT, OP_OR)
88 # hide "Character Generation"
89 Label = LevelUpWindow.CreateLabel (0x1000007e, 0,0,0,0,"NUMBER","",1)
91 # name
92 pc = GemRB.GameGetSelectedPCSingle ()
93 actor = Actor(pc)
94 Label = LevelUpWindow.GetControl (0x10000000+90)
95 Label.SetText (GemRB.GetPlayerName (pc))
97 # some current values
98 OldHPMax = GemRB.GetPlayerStat (pc, IE_MAXHITPOINTS, 1)
99 OldThaco = GemRB.GetPlayerStat (pc, IE_TOHIT, 1)
100 OldLore = GemRB.GetPlayerStat (pc, IE_LORE, 1)
101 for i in range (5):
102 OldSaves[i] = GemRB.GetPlayerStat (pc, IE_SAVEVSDEATH+i, 1)
104 # class
105 Label = LevelUpWindow.GetControl (0x10000000+106)
106 Label.SetText (GetActorClassTitle (pc))
107 print "Title:",GetActorClassTitle (pc),"\tActor Title:",actor.ClassTitle()
109 Class = GemRB.GetPlayerStat (pc, IE_CLASS)
110 print "Class:",Class,"\tActor Class:",actor.classid
111 ClassIndex = ClassTable.FindValue (5, Class)
112 SkillTable = GemRB.LoadTableObject("skills")
114 # kit
115 ClassName = ClassTable.GetRowName(ClassIndex)
116 Kit = GetKitIndex (pc)
117 print "Kit:", Kit, "\tActor Kit:",actor.KitIndex()
118 print "ClassName:",ClassName,"\tActor ClassNames:",actor.ClassNames()
120 # need this for checking gnomes
121 RaceName = GemRB.GetPlayerStat (pc, IE_RACE, 1)
122 RaceName = RaceTable.FindValue (3, RaceName)
123 RaceName = RaceTable.GetRowName (RaceName)
125 # figure our our proficiency table and index
126 if Kit == 0:
127 KitName = ClassName
128 else:
129 #rowname is just a number, the kitname is the first data column
130 KitName = KitListTable.GetValue(Kit, 0)
132 # our multiclass variables
133 IsMulti = IsMultiClassed (pc, 1)
134 Classes = [IsMulti[1], IsMulti[2], IsMulti[3]]
135 NumClasses = IsMulti[0] # 2 or 3 if IsMulti; 0 otherwise
136 IsMulti = NumClasses > 1
137 IsDual = 0
138 DualSwap = 0
140 # not multi, check dual
141 if not IsMulti:
142 # check if we're dual classed
143 IsDual = IsDualClassed (pc, 1)
144 Classes = [IsDual[2], IsDual[1]] # make sure the new class is first
146 # either dual or single only care about 1 class
147 NumClasses = 1
149 # not dual, must be single
150 if IsDual[0] == 0:
151 Classes = [Class]
152 else: # make sure Classes[1] is a class, not a kit
153 if IsDual[0] == 1: # kit
154 Classes[1] = KitListTable.GetValue (IsDual[1], 7)
155 else: # class
156 Classes[1] = ClassTable.GetValue (Classes[1], 5)
158 # store a boolean for IsDual
159 IsDual = IsDual[0] > 0
161 print "NumClasses:",NumClasses,"\tActor NumClasses:",actor.NumClasses()
163 Level = [0]*3
164 LevelDiff = [0]*3
166 # reorganize the leves if we're dc so the one we want to use is in Level[0]
167 # and the old one is in Level[1] (used to regain old class abilities)
168 if IsDual:
169 # convert the classes from indicies to class id's
170 DualSwap = IsDualSwap (pc)
171 ClassName = ClassTable.GetRowName (Classes[0])
172 KitName = ClassName # for simplicity throughout the code
173 Classes[0] = ClassTable.GetValue (Classes[0], 5)
174 # Class[1] is taken care of above
176 # we need the old level as well
177 if DualSwap:
178 Level[1] = GemRB.GetPlayerStat (pc, IE_LEVEL)
179 else:
180 Level[1] = GemRB.GetPlayerStat (pc, IE_LEVEL2)
182 print "Classes:",Classes,"\tActor Classes:",actor.Classes()
183 print "IsDual:",IsDual>0,"\tActor IsDual",actor.isdual
185 hp = 0
186 HaveCleric = 0
187 DeltaWSpells = 0
188 DeltaDSpells = 0
190 # get a bunch of different things each level
191 for i in range(NumClasses):
192 # print "Class:",Classes[i]
193 # we don't care about the current level, but about the to-be-achieved one
194 # get the next level
195 Level[i] = GetNextLevelFromExp (GemRB.GetPlayerStat (pc, IE_XP)/NumClasses, Classes[i])
196 TmpIndex = ClassTable.FindValue (5, Classes[i])
197 TmpName = ClassTable.GetRowName (TmpIndex)
199 # print "Name:",TmpName
201 # find the level diff for each classes (3 max, obviously)
202 if i == 0:
203 if DualSwap:
204 LevelDiff[i] = Level[i] - GemRB.GetPlayerStat (pc, IE_LEVEL2)
205 else:
206 LevelDiff[i] = Level[i] - GemRB.GetPlayerStat (pc, IE_LEVEL)
207 elif i == 1:
208 LevelDiff[i] = Level[i] - GemRB.GetPlayerStat (pc, IE_LEVEL2)
209 elif i == 2:
210 LevelDiff[i] = Level[i] - GemRB.GetPlayerStat (pc, IE_LEVEL3)
212 # print "Level (",i,"):",Level[i]
213 # print "Level Diff (",i,"):",LevelDiff[i]
215 # save our current and next spell amounts
216 StartLevel = Level[i] - LevelDiff[i]
217 DruidTable = ClassSkillsTable.GetValue (Classes[i], 0, 0)
218 ClericTable = ClassSkillsTable.GetValue (Classes[i], 1, 0)
219 MageTable = ClassSkillsTable.GetValue (Classes[i], 2, 0)
221 # see if we have mage spells
222 if MageTable != "*":
223 # we get 1 extra spell per level if we're a specialist
224 Specialist = 0
225 if KitListTable.GetValue (Kit, 7) == 1: # see if we're a kitted mage
226 Specialist = 1
227 MageTable = GemRB.LoadTableObject (MageTable)
228 # loop through each spell level and save the amount possible to cast (current)
229 for j in range (MageTable.GetColumnCount ()):
230 NewWSpells[j] = MageTable.GetValue (str(Level[i]), str(j+1), 1)
231 OldWSpells[j] = MageTable.GetValue (str(StartLevel), str(j+1), 1)
232 if NewWSpells[j] > 0: # don't want specialist to get 1 in levels they should have 0
233 NewWSpells[j] += Specialist
234 if OldWSpells[j] > 0:
235 OldWSpells[j] += Specialist
236 DeltaWSpells = sum(NewWSpells)-sum(OldWSpells)
237 elif ClericTable != "*":
238 # check for cleric spells
239 ClericTable = GemRB.LoadTableObject (ClericTable)
240 HaveCleric = 1
241 # same as above
242 for j in range (ClericTable.GetColumnCount ()):
243 NewDSpells[j] = ClericTable.GetValue (str(Level[i]), str(j+1), 1)
244 OldDSpells[j] = ClericTable.GetValue (str(StartLevel), str(j+1), 1)
245 DeltaDSpells = sum(NewDSpells)-sum(OldDSpells)
246 elif DruidTable != "*":
247 # clerics have precedence in multis (ranger/cleric)
248 if HaveCleric == 0:
249 #use MXSPLPRS if we can't find the resource (SoA fix)
250 if not GemRB.HasResource (DruidTable, RES_2DA):
251 DruidTable = "MXSPLPRS"
253 # check druid spells
254 DruidTable = GemRB.LoadTableObject (DruidTable)
255 # same as above
256 for j in range (DruidTable.GetColumnCount ()):
257 NewDSpells[j] = DruidTable.GetValue (str(Level[i]), str(j+1), 1)
258 OldDSpells[j] = DruidTable.GetValue (str(StartLevel), str(j+1), 1)
259 DeltaDSpells = sum(NewDSpells)-sum(OldDSpells)
261 # setup class bonuses for this class
262 if IsMulti or IsDual or Kit == 0:
263 ABTable = ClassSkillsTable.GetValue (TmpName, "ABILITIES")
264 else: # single-classed with a kit
265 ABTable = KitListTable.GetValue (str(Kit), "ABILITIES")
267 # add the abilites if we aren't a mage and have a table to ref
268 if ABTable != "*" and ABTable[:6] != "CLABMA":
269 AddClassAbilities (pc, ABTable, Level[i], LevelDiff[i])
271 print "Actor CurrentLevels:",actor.Levels()
272 print "Levels:",Level,"Actor NextLevels:",actor.NextLevels()
273 print "LevelDiffs:",LevelDiff,"Actor LevelDiffs:",actor.LevelDiffs()
275 #update our saves, thaco, hp and lore
276 SetupSavingThrows (pc, Level)
277 SetupThaco (pc, Level)
278 SetupLore (pc, LevelDiff)
279 SetupHP (pc, Level, LevelDiff)
281 # use total levels for HLAs
282 HLACount = 0
283 if HasTOB(): # make sure SoA doesn't try to get it
284 HLATable = GemRB.LoadTableObject("lunumab")
285 # we need to check each level against a multi value (this is kinda screwy)
286 if actor.multiclass:
287 print "Actor HLA Names:",["MULTI"+str(actor.NumClasses())+name \
288 for name in actor.ClassNames()]
289 else:
290 print "Actor HLA Names:",actor.ClassNames()
292 for i in range (NumClasses):
293 if IsMulti:
294 # get the row name for lookup ex. MULTI2FIGHTER, MULTI3THIEF
295 MultiName = ClassTable.FindValue (5, Classes[i])
296 MultiName = ClassTable.GetRowName (MultiName)
297 MultiName = "MULTI" + str(NumClasses) + MultiName
298 else:
299 MultiName = ClassName
301 # if we can't learn for this class, we can't learn at all
302 FirstLevel = HLATable.GetValue (MultiName, "FIRST_LEVEL", 1)
303 if Level[i] < FirstLevel:
304 HLACount = 0
305 break
307 if (Level[i] - LevelDiff[i]) < FirstLevel:
308 # count only from FirstLevel up
309 HLACount += (Level[i] - FirstLevel + 1)
310 else:
311 HLACount += LevelDiff[i]
313 # set values required by the hla level up code
314 HLACount = HLACount / HLATable.GetValue (ClassName, "RATE", 1)
315 GemRB.SetVar ("HLACount", HLACount)
316 HLAButton = LevelUpWindow.GetControl (126)
317 if HLACount:
318 HLAButton.SetText (4954)
319 HLAButton.SetEvent (IE_GUI_BUTTON_ON_PRESS, "LevelUpHLAPress")
320 else:
321 HLAButton.SetFlags (IE_GUI_BUTTON_DISABLED, OP_OR)
323 # setup our profs
324 Level1 = []
325 for i in range (len (Level)):
326 Level1.append (Level[i]-LevelDiff[i])
327 SetupProfsWindow (pc, LUPROFS_TYPE_LEVELUP, LevelUpWindow, RedrawSkills, Level1, Level)
328 NewProfPoints = GemRB.GetVar ("ProfsPointsLeft")
330 #we autohide the skills and let SetupSkillsWindow show them if needbe
331 for i in range (4):
332 HideSkills (i)
333 SetupSkillsWindow (pc, LUSKILLS_TYPE_LEVELUP, LevelUpWindow, RedrawSkills, Level1, Level)
334 NewSkillPoints = GemRB.GetVar ("SkillPointsLeft")
336 TextAreaControl = LevelUpWindow.GetControl(110)
337 TextAreaControl.SetText(GetLevelUpNews())
339 RedrawSkills()
340 GemRB.SetRepeatClickFlags (GEM_RK_DISABLE, OP_NAND)
341 LevelUpWindow.ShowModal (MODAL_SHADOW_GRAY)
343 # if we have a sorcerer who can learn spells, we need to do spell selection
344 if (Classes[0] == 19) and (DeltaWSpells > 0): # open our sorc spell selection window
345 OpenSpellsWindow (pc, "SPLSRCKN", Level[0], LevelDiff[0])
347 def HideSkills(i):
348 """Hides the given skill label from view."""
349 global LevelUpWindow
351 Label = LevelUpWindow.GetControl (0x10000000+32+i)
352 Label.SetText ("")
353 Button1 = LevelUpWindow.GetControl(i*2+17)
354 Button1.SetState(IE_GUI_BUTTON_DISABLED)
355 Button1.SetFlags(IE_GUI_BUTTON_NO_IMAGE,OP_OR)
356 Button2 = LevelUpWindow.GetControl(i*2+18)
357 Button2.SetState(IE_GUI_BUTTON_DISABLED)
358 Button2.SetFlags(IE_GUI_BUTTON_NO_IMAGE,OP_OR)
359 Label = LevelUpWindow.GetControl(0x10000000+43+i)
360 Label.SetText("")
362 def RedrawSkills():
363 """Redraws the entire window.
365 Called whenever a state changes, such as a proficiency or skill being
366 added or taken away."""
368 global DoneButton, LevelUpWindow, HLACount
370 # we need to disable the HLA button if we don't have any HLAs left
371 HLACount = GemRB.GetVar ("HLACount")
372 if HLACount == 0:
373 # turn the HLA button off
374 HLAButton = LevelUpWindow.GetControl (126)
375 HLAButton.SetState(IE_GUI_BUTTON_DISABLED)
377 # enable the done button if they've allocated all points
378 # sorcerer spell selection (if applicable) comes after hitting the done button
379 ProfPointsLeft = GemRB.GetVar ("ProfsPointsLeft")
380 SkillPointsLeft = GemRB.GetVar ("SkillPointsLeft")
381 if ProfPointsLeft == 0 and SkillPointsLeft == 0 and HLACount == 0:
382 DoneButton.SetState (IE_GUI_BUTTON_ENABLED)
383 else:
384 DoneButton.SetState (IE_GUI_BUTTON_DISABLED)
385 return
387 def GetLevelUpNews():
388 """Returns a string containing improvements gain on level up.
390 These include: HP, spells per level, and lore, among others."""
392 News = GemRB.GetString (5259) + '\n\n'
394 # display if our class has been reactivated
395 if IsDual:
396 if (Level[0] - LevelDiff[0]) <= Level[1] and Level[0] > Level[1]:
397 News = GemRB.GetString (5261) + '\n\n'
399 # 5271 - Additional weapon proficiencies
400 if NewProfPoints > 0:
401 News += GemRB.GetString (5271) + ": " + str(NewProfPoints) + '\n\n'
403 # temps to compare all our new saves against (we get the best of our saving throws)
404 LOHGain = 0
405 BackstabMult = 0
407 for i in range(NumClasses):
408 # get the class name
409 TmpClassName = ClassTable.FindValue (5, Classes[i])
410 TmpClassName = ClassTable.GetRowName (TmpClassName)
412 # backstab
413 # NOTE: Stalkers and assassins should get the correct mods at the correct levels based
414 # on AP_SPCL332 in their respective CLAB files.
415 # APND: Stalkers appear to get the correct mod at the correct levels; however, because they start
416 # at backstab multi x1, they are x1 too many at their respective levels.
417 if Classes[i] == 4 and GemRB.GetPlayerStat (pc, IE_BACKSTABDAMAGEMULTIPLIER, 1) > 1: # we have a thief who can backstab (2 at level 1)
418 # save the backstab multiplier if we have a thief
419 BackstabTable = GemRB.LoadTableObject ("BACKSTAB")
420 BackstabMult = BackstabTable.GetValue (0, Level[i])
422 # lay on hands
423 if (ClassSkillsTable.GetValue (Classes[i], 6) != "*"):
424 # inquisitors and undead hunters don't get lay on hands out the chute, whereas cavaliers
425 # and unkitted paladins do; therefore, we check for the existence of lay on hands to ensure
426 # the character should get the new value; LoH is defined in GA_SPCL211 if anyone wants to
427 # make a pally kit with LoH
428 if (HasSpell (pc, IE_SPELL_TYPE_INNATE, 0, "SPCL211") >= 0):
429 LOHTable = GemRB.LoadTableObject ("layhands")
430 LOHGain = LOHTable.GetValue (0, Level[i]) - LOHTable.GetValue (0, Level[i]-LevelDiff[i])
432 # saving throws
433 # 5277 death
434 # 5278 wand
435 # 5279 polymorph
436 # 5282 breath
437 # 5292 spell
438 # include in news if the save is updated
439 Changed = 0
440 for i in range (5):
441 CurrentSave = GemRB.GetPlayerStat (pc, IE_SAVEVSDEATH+i, 1)
442 SaveString = 5277+i
443 if i == 3:
444 SaveString = 5282
445 elif i == 4:
446 SaveString = 5292
448 if CurrentSave < OldSaves[i]:
449 News += GemRB.GetString (SaveString) + ": " + str(OldSaves[i]-CurrentSave) + '\n'
450 Changed = 1
451 if Changed:
452 News += '\n'
454 # 5305 - THAC0 Reduced by
455 # only output if there is a change in thaco
456 NewThaco = GemRB.GetPlayerStat (pc, IE_TOHIT, 1)
457 if (NewThaco < OldThaco):
458 News += GemRB.GetString (5305) + ": " + str(OldThaco-NewThaco) + '\n\n'
460 # new spell slots
461 # 5373 - Additional Priest Spells
462 # 5374 - Additional Mage Spells
463 # 61269 - Level <LEVEL> Spells
464 if DeltaDSpells > 0: # new divine spells
465 News += GemRB.GetString (5373) + '\n'
466 for i in range (len (NewDSpells)):
467 # only display classes with new spells
468 if (NewDSpells[i]-OldDSpells[i]) == 0:
469 continue
470 GemRB.SetToken("level", str(i+1))
471 News += GemRB.GetString(61269)+": " + str(NewDSpells[i]-OldDSpells[i]) + '\n'
472 News += '\n'
473 if DeltaWSpells > 0: # new wizard spells
474 News += GemRB.GetString (5374) + '\n'
475 for i in range (len (NewWSpells)):
476 # only display classes with new spells
477 if (NewWSpells[i]-OldWSpells[i]) == 0:
478 continue
479 GemRB.SetToken("level", str(i+1))
480 News += GemRB.GetString(61269)+": " + str(NewWSpells[i]-OldWSpells[i]) + '\n'
481 News += '\n'
483 # 5375 - Backstab Multiplier Increased by
484 # this auto-updates... we just need to inform of the update
485 BSGain = BackstabMult - GemRB.GetPlayerStat (pc, IE_BACKSTABDAMAGEMULTIPLIER, 1)
486 if (BSGain > 0):
487 News += GemRB.GetString (5375) + ": " + str(BSGain) + '\n\n'
489 # 5376 - Lay on Hands increased
490 if LOHGain > 0:
491 News += GemRB.GetString (5376) + ": " + str(LOHGain) + '\n\n'
493 # 5293 - HP increased by
494 if (OldHPMax != GemRB.GetPlayerStat (pc, IE_MAXHITPOINTS, 1)):
495 News += GemRB.GetString (5293) + ": " + str(GemRB.GetPlayerStat (pc, IE_MAXHITPOINTS, 1) - OldHPMax) + '\n'
497 # 5377 - Lore Increased by
498 # add the lore gain if we haven't done so already
499 NewLore = GemRB.GetPlayerStat (pc, IE_LORE, 1)
500 if NewLore > OldLore:
501 News += GemRB.GetString (5377) + ": " + str(NewLore-OldLore) + '\n\n'
503 # 5378 - Additional Skill Points
504 # ranger and bard skill(point) gain is not mentioned here in the original
505 if NewSkillPoints > 0:
506 News += GemRB.GetString (5378) + ": " + str(NewSkillPoints) + '\n'
508 return News
510 def LevelUpInfoPress():
511 """Displays new abilites gained on level up.
513 Alternates between overall and modified stats."""
515 global LevelUpWindow, TextAreaControl, InfoCounter, LevelDiff
517 if InfoCounter % 2:
518 # call GetStatOverview with the new levels, so the future overview is shown
519 # TODO: show only xp, levels, thac0, #att, lore, reputation, backstab, saving throws
520 TextAreaControl.SetText(GetStatOverview(pc, LevelDiff))
521 else:
522 TextAreaControl.SetText(GetLevelUpNews())
523 InfoCounter += 1
524 return
526 # save the results
527 def LevelUpDonePress():
528 """Updates the PC with the new choices.
530 Closes the window when finished."""
532 global SkillTable
534 # proficiencies
535 ProfsSave (pc)
537 # skills
538 SkillsSave (pc)
540 # level
541 if DualSwap: # swap the IE_LEVELs around if a backward dual
542 GemRB.SetPlayerStat (pc, IE_LEVEL2, Level[0])
543 GemRB.SetPlayerStat (pc, IE_LEVEL, Level[1])
544 else:
545 GemRB.SetPlayerStat (pc, IE_LEVEL, Level[0])
546 GemRB.SetPlayerStat (pc, IE_LEVEL2, Level[1])
547 GemRB.SetPlayerStat (pc, IE_LEVEL3, Level[2])
549 print "Levels:",Level[0],"/",Level[1],"/",Level[2]
551 # save our number of memorizable spells per level
552 if DeltaWSpells > 0:
553 # loop through each wizard spell level
554 for i in range(len(NewWSpells)):
555 if NewWSpells[i] > 0: # we have new spells, so update
556 GemRB.SetMemorizableSpellsCount(pc, NewWSpells[i], IE_SPELL_TYPE_WIZARD, i)
558 # save our number of memorizable priest spells
559 if DeltaDSpells > 0: # druids and clerics count
560 for i in range (len(NewDSpells)):
561 # get each update
562 if NewDSpells[i] > 0:
563 GemRB.SetMemorizableSpellsCount (pc, NewDSpells[i], IE_SPELL_TYPE_PRIEST, i)
565 # learn all the spells we're given, but don't have, up to our given casting level
566 if GemRB.GetMemorizableSpellsCount (pc, IE_SPELL_TYPE_PRIEST, i, 1) > 0: # we can memorize spells of this level
567 for j in range(NumClasses): # loop through each class
568 IsDruid = ClassSkillsTable.GetValue (Classes[j], 0, 0)
569 IsCleric = ClassSkillsTable.GetValue (Classes[j], 1, 0)
570 if IsCleric == "*" and IsDruid == "*": # no divine spells (so mage/cleric multis don't screw up)
571 continue
572 elif IsCleric == "*": # druid spells
573 ClassFlag = 0x8000
574 else: # cleric spells
575 ClassFlag = 0x4000
577 Learnable = GetLearnablePriestSpells(ClassFlag, GemRB.GetPlayerStat (pc, IE_ALIGNMENT), i+1)
578 for k in range(len(Learnable)): # loop through all the learnable spells
579 if HasSpell (pc, IE_SPELL_TYPE_PRIEST, i, Learnable[k]) < 0: # only write it if we don't yet know it
580 GemRB.LearnSpell(pc, Learnable[k])
582 # hlas
583 # level, xp and other stuff by the core?
585 # 5261 - Regained abilities from inactive class
586 if IsDual: # we're dual classed
587 print "activation?"
588 if (Level[0] - LevelDiff[0]) <= Level[1] and Level[0] > Level[1]: # our new classes now surpasses our old class
589 print "reactivating base class"
590 ReactivateBaseClass ()
592 if LevelUpWindow:
593 LevelUpWindow.Unload()
594 UpdatePortraitWindow ()
595 UpdateRecordsWindow()
597 GemRB.SetRepeatClickFlags (GEM_RK_DISABLE, OP_OR)
598 return
600 def LevelUpHLAPress ():
601 """Opens the HLA selection window."""
603 # we can turn the button off and temporarily set HLACount to 0
604 # because there is no cancel button on the HLA window; therefore,
605 # it's guaranteed to come back as 0
606 TmpCount = GemRB.GetVar ("HLACount")
607 GemRB.SetVar ("HLACount", 0)
608 RedrawSkills ()
609 GemRB.SetVar ("HLACount", TmpCount)
611 OpenHLAWindow (pc, NumClasses, Classes, Level)
612 return