Merge branch 'events'.
[gemrb.git] / gemrb / GUIScripts / LevelUp.py
blob9d5c65f49c1f8e584d6a03a777c3de9e72537c4a
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 import GUICommon
26 import GUICommonWindows
27 import GUIREC
28 import LUSpellSelection
29 import LUCommon
30 if GUICommon.HasTOB():
31 import LUHLASelection
32 from LUHLASelection import HLASelectPress, HLADonePress #HACK
33 import LUProfsSelection
34 import LUSkillsSelection
35 import Actor
37 LevelUpWindow = None
38 DoneButton = 0
39 TextAreaControl = 0
40 InfoCounter = 1
41 NewProfPoints = 0
42 NewSkillPoints = 0
43 LevelDiff = 0
44 Level = 0
45 Classes = 0
46 NumClasses = 0
47 DualSwap = 0
48 KitName = 0
49 IsDual = 0
50 IsMulti = 0
51 pc = 0
52 ClassName = 0
53 actor = 0
55 # old values (so we don't add too much)
56 OldHPMax = 0 # << old maximum hitpoints
57 OldSaves = [0]*5 # << old saves
58 OldThaco = 0 # << old thac0 value
59 OldLore = 0 # << old lore value
60 OldDSpells = [0]*7 # << old divine spells per level
61 OldWSpells = [0]*9 # << old wizard spells per level
62 NewDSpells = [0]*7 # << new divine spells per level
63 NewWSpells = [0]*9 # << new wizard spells per level
64 DeltaDSpells = 0 # << total new divine spells
65 DeltaWSpells = 0 # << total new wizard spells
67 def OpenLevelUpWindow():
68 """Sets up the level up window."""
70 global LevelUpWindow, TextAreaControl, NewProfPoints, actor
71 global DoneButton
72 global NewSkillPoints, KitName, LevelDiff, RaceTable
73 global ClassTable, Level, Classes, NumClasses, DualSwap, ClassSkillsTable, IsMulti
74 global OldHPMax, OldSaves, OldLore, OldThaco, DeltaDSpells, DeltaWSpells
75 global NewDSpells, NewWSpells, OldDSpells, OldWSpells, pc, HLACount, ClassName, IsDual
77 LevelUpWindow = GemRB.LoadWindow (3)
79 if GUICommon.GameIsBG2():
80 InfoButton = LevelUpWindow.GetControl (125)
81 InfoButton.SetText (13707)
82 InfoButton.SetEventByName (IE_GUI_BUTTON_ON_PRESS, "LevelUpInfoPress")
84 DoneButton = LevelUpWindow.GetControl (0)
85 DoneButton.SetText (11962)
86 DoneButton.SetEventByName (IE_GUI_BUTTON_ON_PRESS, "LevelUpDonePress")
87 DoneButton.SetState (IE_GUI_BUTTON_DISABLED)
88 DoneButton.SetFlags (IE_GUI_BUTTON_DEFAULT, OP_OR)
90 # hide "Character Generation"
91 Label = LevelUpWindow.CreateLabel (0x1000007e, 0,0,0,0,"NUMBER","",1)
93 # name
94 pc = GemRB.GameGetSelectedPCSingle ()
95 actor = Actor.Actor(pc)
96 Label = LevelUpWindow.GetControl (0x10000000+90)
97 Label.SetText (GemRB.GetPlayerName (pc))
99 if GUICommon.GameIsBG1() or GUICommon.GameIsIWD1():
100 # armorclass
101 Label = LevelUpWindow.GetControl (0x10000057)
102 ac = GemRB.GetPlayerStat (pc, IE_ARMORCLASS)
103 #This is a temporary solution, the core engine should set the stat correctly!
104 ac += GemRB.GetAbilityBonus (IE_DEX, 2, GemRB.GetPlayerStat (pc, IE_DEX) )
105 Label.SetText (str (ac))
106 Label.SetTooltip (17183)
108 # hp now
109 Label = LevelUpWindow.GetControl (0x10000058)
110 Label.SetText (str (GemRB.GetPlayerStat (pc, IE_HITPOINTS)))
111 Label.SetTooltip (17184)
113 # hp max
114 Label = LevelUpWindow.GetControl (0x10000059)
115 Label.SetText (str (GemRB.GetPlayerStat (pc, IE_MAXHITPOINTS)))
116 Label.SetTooltip (17378)
118 # some current values
119 OldHPMax = GemRB.GetPlayerStat (pc, IE_MAXHITPOINTS, 1)
120 OldThaco = GemRB.GetPlayerStat (pc, IE_TOHIT, 1)
121 OldLore = GemRB.GetPlayerStat (pc, IE_LORE, 1)
122 for i in range (5):
123 OldSaves[i] = GemRB.GetPlayerStat (pc, IE_SAVEVSDEATH+i, 1)
125 # class
126 Label = LevelUpWindow.GetControl (0x10000000+106)
127 Label.SetText (GUIREC.GetActorClassTitle (pc))
128 print "Title:",GUIREC.GetActorClassTitle (pc),"\tActor Title:",actor.ClassTitle()
130 Class = GemRB.GetPlayerStat (pc, IE_CLASS)
131 print "Class:",Class,"\tActor Class:",actor.classid
132 ClassIndex = GUICommon.ClassTable.FindValue (5, Class)
133 SkillTable = GemRB.LoadTable("skills")
135 # kit
136 ClassName = GUICommon.ClassTable.GetRowName(ClassIndex)
137 Kit = GUICommon.GetKitIndex (pc)
138 print "Kit:", Kit, "\tActor Kit:",actor.KitIndex()
139 print "ClassName:",ClassName,"\tActor ClassNames:",actor.ClassNames()
141 # need this for checking gnomes
142 RaceName = GemRB.GetPlayerStat (pc, IE_RACE, 1)
143 RaceName = GUICommon.RaceTable.FindValue (3, RaceName)
144 RaceName = GUICommon.RaceTable.GetRowName (RaceName)
146 # figure our our proficiency table and index
147 if Kit == 0:
148 KitName = ClassName
149 else:
150 #rowname is just a number, the kitname is the first data column
151 KitName = GUICommon.KitListTable.GetValue(Kit, 0)
153 # our multiclass variables
154 IsMulti = GUICommon.IsMultiClassed (pc, 1)
155 Classes = [IsMulti[1], IsMulti[2], IsMulti[3]]
156 NumClasses = IsMulti[0] # 2 or 3 if IsMulti; 0 otherwise
157 IsMulti = NumClasses > 1
158 IsDual = 0
159 DualSwap = 0
161 # not multi, check dual
162 if not IsMulti:
163 # check if we're dual classed
164 IsDual = GUICommon.IsDualClassed (pc, 1)
165 Classes = [IsDual[2], IsDual[1]] # make sure the new class is first
167 # either dual or single only care about 1 class
168 NumClasses = 1
170 # not dual, must be single
171 if IsDual[0] == 0:
172 Classes = [Class]
173 else: # make sure Classes[1] is a class, not a kit
174 if IsDual[0] == 1: # kit
175 Classes[1] = GUICommon.KitListTable.GetValue (IsDual[1], 7)
176 else: # class
177 Classes[1] = GUICommon.ClassTable.GetValue (Classes[1], 5)
179 # store a boolean for IsDual
180 IsDual = IsDual[0] > 0
182 print "NumClasses:",NumClasses,"\tActor NumClasses:",actor.NumClasses()
184 Level = [0]*3
185 LevelDiff = [0]*3
187 # reorganize the leves if we're dc so the one we want to use is in Level[0]
188 # and the old one is in Level[1] (used to regain old class abilities)
189 if IsDual:
190 # convert the classes from indicies to class id's
191 DualSwap = GUICommon.IsDualSwap (pc)
192 ClassName = GUICommon.ClassTable.GetRowName (Classes[0])
193 KitName = ClassName # for simplicity throughout the code
194 Classes[0] = GUICommon.ClassTable.GetValue (Classes[0], 5)
195 # Class[1] is taken care of above
197 # we need the old level as well
198 if DualSwap:
199 Level[1] = GemRB.GetPlayerStat (pc, IE_LEVEL)
200 else:
201 Level[1] = GemRB.GetPlayerStat (pc, IE_LEVEL2)
203 print "Classes:",Classes,"\tActor Classes:",actor.Classes()
204 print "IsDual:",IsDual>0,"\tActor IsDual",actor.isdual
206 hp = 0
207 HaveCleric = 0
208 DeltaWSpells = 0
209 DeltaDSpells = 0
211 # get a bunch of different things each level
212 for i in range(NumClasses):
213 # print "Class:",Classes[i]
214 # we don't care about the current level, but about the to-be-achieved one
215 # get the next level
216 Level[i] = LUCommon.GetNextLevelFromExp (GemRB.GetPlayerStat (pc, IE_XP)/NumClasses, Classes[i])
217 TmpIndex = GUICommon.ClassTable.FindValue (5, Classes[i])
218 TmpName = GUICommon.ClassTable.GetRowName (TmpIndex)
220 # print "Name:",TmpName
222 # find the level diff for each classes (3 max, obviously)
223 if i == 0:
224 if DualSwap:
225 LevelDiff[i] = Level[i] - GemRB.GetPlayerStat (pc, IE_LEVEL2)
226 else:
227 LevelDiff[i] = Level[i] - GemRB.GetPlayerStat (pc, IE_LEVEL)
228 elif i == 1:
229 LevelDiff[i] = Level[i] - GemRB.GetPlayerStat (pc, IE_LEVEL2)
230 elif i == 2:
231 LevelDiff[i] = Level[i] - GemRB.GetPlayerStat (pc, IE_LEVEL3)
233 # print "Level (",i,"):",Level[i]
234 # print "Level Diff (",i,"):",LevelDiff[i]
236 # save our current and next spell amounts
237 StartLevel = Level[i] - LevelDiff[i]
238 DruidTable = GUICommon.ClassSkillsTable.GetValue (Classes[i], 0, 0)
239 ClericTable = GUICommon.ClassSkillsTable.GetValue (Classes[i], 1, 0)
240 MageTable = GUICommon.ClassSkillsTable.GetValue (Classes[i], 2, 0)
242 # see if we have mage spells
243 if MageTable != "*":
244 # we get 1 extra spell per level if we're a specialist
245 Specialist = 0
246 if GUICommon.KitListTable.GetValue (Kit, 7) == 1: # see if we're a kitted mage
247 Specialist = 1
248 MageTable = GemRB.LoadTable (MageTable)
249 # loop through each spell level and save the amount possible to cast (current)
250 for j in range (MageTable.GetColumnCount ()):
251 NewWSpells[j] = MageTable.GetValue (str(Level[i]), str(j+1), 1)
252 OldWSpells[j] = MageTable.GetValue (str(StartLevel), str(j+1), 1)
253 if NewWSpells[j] > 0: # don't want specialist to get 1 in levels they should have 0
254 NewWSpells[j] += Specialist
255 if OldWSpells[j] > 0:
256 OldWSpells[j] += Specialist
257 DeltaWSpells = sum(NewWSpells)-sum(OldWSpells)
258 elif ClericTable != "*":
259 # check for cleric spells
260 if not GemRB.HasResource(ClericTable, RES_2DA, 1):
261 ClericTable = "MXSPLPRS" # iwd1 doesn't have a DRUIDSPELL column in the table
262 ClericTable = GemRB.LoadTable (ClericTable)
263 HaveCleric = 1
264 # same as above
265 for j in range (ClericTable.GetColumnCount ()):
266 NewDSpells[j] = ClericTable.GetValue (str(Level[i]), str(j+1), 1)
267 OldDSpells[j] = ClericTable.GetValue (str(StartLevel), str(j+1), 1)
268 DeltaDSpells = sum(NewDSpells)-sum(OldDSpells)
269 elif DruidTable != "*":
270 # clerics have precedence in multis (ranger/cleric)
271 if HaveCleric == 0:
272 #use MXSPLPRS if we can't find the resource (SoA fix)
273 if not GemRB.HasResource (DruidTable, RES_2DA):
274 DruidTable = "MXSPLPRS"
276 # check druid spells
277 DruidTable = GemRB.LoadTable (DruidTable)
278 # same as above
279 for j in range (DruidTable.GetColumnCount ()):
280 NewDSpells[j] = DruidTable.GetValue (str(Level[i]), str(j+1), 1)
281 OldDSpells[j] = DruidTable.GetValue (str(StartLevel), str(j+1), 1)
282 DeltaDSpells = sum(NewDSpells)-sum(OldDSpells)
284 # setup class bonuses for this class
285 if IsMulti or IsDual or Kit == 0:
286 ABTable = GUICommon.ClassSkillsTable.GetValue (TmpName, "ABILITIES")
287 else: # single-classed with a kit
288 ABTable = GUICommon.KitListTable.GetValue (str(Kit), "ABILITIES")
290 # add the abilites if we aren't a mage and have a table to ref
291 if ABTable != "*" and ABTable[:6] != "CLABMA":
292 GUICommon.AddClassAbilities (pc, ABTable, Level[i], LevelDiff[i])
294 print "Actor CurrentLevels:",actor.Levels()
295 print "Levels:",Level,"Actor NextLevels:",actor.NextLevels()
296 print "LevelDiffs:",LevelDiff,"Actor LevelDiffs:",actor.LevelDiffs()
298 #update our saves, thaco, hp and lore
299 LUCommon.SetupSavingThrows (pc, Level)
300 LUCommon.SetupThaco (pc, Level)
301 LUCommon.SetupLore (pc, LevelDiff)
302 LUCommon.SetupHP (pc, Level, LevelDiff)
304 # use total levels for HLAs
305 HLACount = 0
306 if GUICommon.HasTOB(): # make sure SoA doesn't try to get it
307 HLATable = GemRB.LoadTable("lunumab")
308 # we need to check each level against a multi value (this is kinda screwy)
309 if actor.multiclass:
310 print "Actor HLA Names:",["MULTI"+str(actor.NumClasses())+name \
311 for name in actor.ClassNames()]
312 else:
313 print "Actor HLA Names:",actor.ClassNames()
315 for i in range (NumClasses):
316 if IsMulti:
317 # get the row name for lookup ex. MULTI2FIGHTER, MULTI3THIEF
318 MultiName = GUICommon.ClassTable.FindValue (5, Classes[i])
319 MultiName = GUICommon.ClassTable.GetRowName (MultiName)
320 MultiName = "MULTI" + str(NumClasses) + MultiName
321 else:
322 MultiName = ClassName
324 # if we can't learn for this class, we can't learn at all
325 FirstLevel = HLATable.GetValue (MultiName, "FIRST_LEVEL", 1)
326 if Level[i] < FirstLevel:
327 HLACount = 0
328 break
330 if (Level[i] - LevelDiff[i]) < FirstLevel:
331 # count only from FirstLevel up
332 HLACount += (Level[i] - FirstLevel + 1)
333 else:
334 HLACount += LevelDiff[i]
336 # set values required by the hla level up code
337 HLACount = HLACount / HLATable.GetValue (ClassName, "RATE", 1)
338 GemRB.SetVar ("HLACount", HLACount)
339 if GUICommon.GameIsBG2():
340 HLAButton = LevelUpWindow.GetControl (126)
341 if HLACount:
342 HLAButton.SetText (4954)
343 HLAButton.SetEventByName (IE_GUI_BUTTON_ON_PRESS, "LevelUpHLAPress")
344 else:
345 HLAButton.SetFlags (IE_GUI_BUTTON_DISABLED, OP_OR)
347 # setup our profs
348 Level1 = []
349 for i in range (len (Level)):
350 Level1.append (Level[i]-LevelDiff[i])
351 if GUICommon.GameIsBG2():
352 LUProfsSelection.SetupProfsWindow (pc, LUProfsSelection.LUPROFS_TYPE_LEVELUP, LevelUpWindow, RedrawSkills, Level1, Level)
353 else:
354 LUProfsSelection.SetupProfsWindow (pc, LUProfsSelection.LUPROFS_TYPE_LEVELUP, LevelUpWindow, RedrawSkills, Level1, Level, 0, False, 0)
355 NewProfPoints = GemRB.GetVar ("ProfsPointsLeft")
357 #we autohide the skills and let SetupSkillsWindow show them if needbe
358 for i in range (4):
359 HideSkills (i)
360 if GUICommon.GameIsBG2():
361 LUSkillsSelection.SetupSkillsWindow (pc, LUSkillsSelection.LUSKILLS_TYPE_LEVELUP, LevelUpWindow, RedrawSkills, Level1, Level)
362 else:
363 LUSkillsSelection.SetupSkillsWindow (pc, LUSkillsSelection.LUSKILLS_TYPE_LEVELUP, LevelUpWindow, RedrawSkills, Level1, Level, 0, False)
364 NewSkillPoints = GemRB.GetVar ("SkillPointsLeft")
366 if GUICommon.GameIsBG2():
367 TextAreaControl = LevelUpWindow.GetControl(110)
368 TextAreaControl.SetText(GetLevelUpNews())
369 else:
370 TextAreaControl = LevelUpWindow.GetControl(42)
371 TextAreaControl.SetText(GUIREC.GetStatOverview(pc, LevelDiff))
373 RedrawSkills()
374 GemRB.SetRepeatClickFlags (GEM_RK_DISABLE, OP_NAND)
375 LevelUpWindow.ShowModal (MODAL_SHADOW_GRAY)
377 # if we have a sorcerer who can learn spells, we need to do spell selection
378 if (Classes[0] == 19) and (DeltaWSpells > 0): # open our sorc spell selection window
379 LUSpellSelection.OpenSpellsWindow (pc, "SPLSRCKN", Level[0], LevelDiff[0])
381 def HideSkills(i):
382 """Hides the given skill label from view."""
383 global LevelUpWindow
385 Label = LevelUpWindow.GetControl (0x10000000+32+i)
386 Label.SetText ("")
387 Button1 = LevelUpWindow.GetControl(i*2+17)
388 Button1.SetState(IE_GUI_BUTTON_DISABLED)
389 Button1.SetFlags(IE_GUI_BUTTON_NO_IMAGE,OP_OR)
390 Button2 = LevelUpWindow.GetControl(i*2+18)
391 Button2.SetState(IE_GUI_BUTTON_DISABLED)
392 Button2.SetFlags(IE_GUI_BUTTON_NO_IMAGE,OP_OR)
393 Label = LevelUpWindow.GetControl(0x10000000+43+i)
394 Label.SetText("")
396 def RedrawSkills():
397 """Redraws the entire window.
399 Called whenever a state changes, such as a proficiency or skill being
400 added or taken away."""
402 global DoneButton, LevelUpWindow, HLACount
404 # we need to disable the HLA button if we don't have any HLAs left
405 HLACount = GemRB.GetVar ("HLACount")
406 if GUICommon.GameIsBG2() and HLACount == 0:
407 # turn the HLA button off
408 HLAButton = LevelUpWindow.GetControl (126)
409 HLAButton.SetState(IE_GUI_BUTTON_DISABLED)
411 # enable the done button if they've allocated all points
412 # sorcerer spell selection (if applicable) comes after hitting the done button
413 ProfPointsLeft = GemRB.GetVar ("ProfsPointsLeft")
414 SkillPointsLeft = GemRB.GetVar ("SkillPointsLeft")
415 if ProfPointsLeft == 0 and SkillPointsLeft == 0 and HLACount == 0:
416 DoneButton.SetState (IE_GUI_BUTTON_ENABLED)
417 else:
418 DoneButton.SetState (IE_GUI_BUTTON_DISABLED)
419 return
421 def GetLevelUpNews():
422 """Returns a string containing improvements gain on level up.
424 These include: HP, spells per level, and lore, among others."""
426 News = GemRB.GetString (5259) + '\n\n'
428 # display if our class has been reactivated
429 if IsDual:
430 if (Level[0] - LevelDiff[0]) <= Level[1] and Level[0] > Level[1]:
431 News = GemRB.GetString (5261) + '\n\n'
433 # 5271 - Additional weapon proficiencies
434 if NewProfPoints > 0:
435 News += GemRB.GetString (5271) + ": " + str(NewProfPoints) + '\n\n'
437 # temps to compare all our new saves against (we get the best of our saving throws)
438 LOHGain = 0
439 BackstabMult = 0
441 for i in range(NumClasses):
442 # get the class name
443 TmpClassName = GUICommon.ClassTable.FindValue (5, Classes[i])
444 TmpClassName = GUICommon.ClassTable.GetRowName (TmpClassName)
446 # backstab
447 # NOTE: Stalkers and assassins should get the correct mods at the correct levels based
448 # on AP_SPCL332 in their respective CLAB files.
449 # APND: Stalkers appear to get the correct mod at the correct levels; however, because they start
450 # at backstab multi x1, they are x1 too many at their respective levels.
451 if Classes[i] == 4 and GemRB.GetPlayerStat (pc, IE_BACKSTABDAMAGEMULTIPLIER, 1) > 1: # we have a thief who can backstab (2 at level 1)
452 # save the backstab multiplier if we have a thief
453 BackstabTable = GemRB.LoadTable ("BACKSTAB")
454 BackstabMult = BackstabTable.GetValue (0, Level[i])
456 # lay on hands
457 if (GUICommon.ClassSkillsTable.GetValue (Classes[i], 6) != "*"):
458 # inquisitors and undead hunters don't get lay on hands out the chute, whereas cavaliers
459 # and unkitted paladins do; therefore, we check for the existence of lay on hands to ensure
460 # the character should get the new value; LoH is defined in GA_SPCL211 if anyone wants to
461 # make a pally kit with LoH
462 if (GUICommon.HasSpell (pc, IE_SPELL_TYPE_INNATE, 0, "SPCL211") >= 0):
463 LOHTable = GemRB.LoadTable ("layhands")
464 LOHGain = LOHTable.GetValue (0, Level[i]) - LOHTable.GetValue (0, Level[i]-LevelDiff[i])
466 # saving throws
467 # 5277 death
468 # 5278 wand
469 # 5279 polymorph
470 # 5282 breath
471 # 5292 spell
472 # include in news if the save is updated
473 Changed = 0
474 for i in range (5):
475 CurrentSave = GemRB.GetPlayerStat (pc, IE_SAVEVSDEATH+i, 1)
476 SaveString = 5277+i
477 if i == 3:
478 SaveString = 5282
479 elif i == 4:
480 SaveString = 5292
482 if CurrentSave < OldSaves[i]:
483 News += GemRB.GetString (SaveString) + ": " + str(OldSaves[i]-CurrentSave) + '\n'
484 Changed = 1
485 if Changed:
486 News += '\n'
488 # 5305 - THAC0 Reduced by
489 # only output if there is a change in thaco
490 NewThaco = GemRB.GetPlayerStat (pc, IE_TOHIT, 1)
491 if (NewThaco < OldThaco):
492 News += GemRB.GetString (5305) + ": " + str(OldThaco-NewThaco) + '\n\n'
494 # new spell slots
495 # 5373 - Additional Priest Spells
496 # 5374 - Additional Mage Spells
497 # 61269 - Level <LEVEL> Spells
498 if DeltaDSpells > 0: # new divine spells
499 News += GemRB.GetString (5373) + '\n'
500 for i in range (len (NewDSpells)):
501 # only display classes with new spells
502 if (NewDSpells[i]-OldDSpells[i]) == 0:
503 continue
504 GemRB.SetToken("level", str(i+1))
505 News += GemRB.GetString(61269)+": " + str(NewDSpells[i]-OldDSpells[i]) + '\n'
506 News += '\n'
507 if DeltaWSpells > 0: # new wizard spells
508 News += GemRB.GetString (5374) + '\n'
509 for i in range (len (NewWSpells)):
510 # only display classes with new spells
511 if (NewWSpells[i]-OldWSpells[i]) == 0:
512 continue
513 GemRB.SetToken("level", str(i+1))
514 News += GemRB.GetString(61269)+": " + str(NewWSpells[i]-OldWSpells[i]) + '\n'
515 News += '\n'
517 # 5375 - Backstab Multiplier Increased by
518 # this auto-updates... we just need to inform of the update
519 BSGain = BackstabMult - GemRB.GetPlayerStat (pc, IE_BACKSTABDAMAGEMULTIPLIER, 1)
520 if (BSGain > 0):
521 News += GemRB.GetString (5375) + ": " + str(BSGain) + '\n\n'
523 # 5376 - Lay on Hands increased
524 if LOHGain > 0:
525 News += GemRB.GetString (5376) + ": " + str(LOHGain) + '\n\n'
527 # 5293 - HP increased by
528 if (OldHPMax != GemRB.GetPlayerStat (pc, IE_MAXHITPOINTS, 1)):
529 News += GemRB.GetString (5293) + ": " + str(GemRB.GetPlayerStat (pc, IE_MAXHITPOINTS, 1) - OldHPMax) + '\n'
531 # 5377 - Lore Increased by
532 # add the lore gain if we haven't done so already
533 NewLore = GemRB.GetPlayerStat (pc, IE_LORE, 1)
534 if NewLore > OldLore:
535 News += GemRB.GetString (5377) + ": " + str(NewLore-OldLore) + '\n\n'
537 # 5378 - Additional Skill Points
538 # ranger and bard skill(point) gain is not mentioned here in the original
539 if NewSkillPoints > 0:
540 News += GemRB.GetString (5378) + ": " + str(NewSkillPoints) + '\n'
542 return News
544 def LevelUpInfoPress():
545 """Displays new abilites gained on level up.
547 Alternates between overall and modified stats."""
549 global LevelUpWindow, TextAreaControl, InfoCounter, LevelDiff
551 if InfoCounter % 2:
552 # call GetStatOverview with the new levels, so the future overview is shown
553 # TODO: show only xp, levels, thac0, #att, lore, reputation, backstab, saving throws
554 TextAreaControl.SetText(GUIREC.GetStatOverview(pc, LevelDiff))
555 else:
556 TextAreaControl.SetText(GetLevelUpNews())
557 InfoCounter += 1
558 return
560 # save the results
561 def LevelUpDonePress():
562 """Updates the PC with the new choices.
564 Closes the window when finished."""
566 global SkillTable
568 # proficiencies
569 LUProfsSelection.ProfsSave (pc)
571 # skills
572 LUSkillsSelection.SkillsSave (pc)
574 # level
575 if DualSwap: # swap the IE_LEVELs around if a backward dual
576 GemRB.SetPlayerStat (pc, IE_LEVEL2, Level[0])
577 GemRB.SetPlayerStat (pc, IE_LEVEL, Level[1])
578 else:
579 GemRB.SetPlayerStat (pc, IE_LEVEL, Level[0])
580 GemRB.SetPlayerStat (pc, IE_LEVEL2, Level[1])
581 GemRB.SetPlayerStat (pc, IE_LEVEL3, Level[2])
583 print "Levels:",Level[0],"/",Level[1],"/",Level[2]
585 # save our number of memorizable spells per level
586 if DeltaWSpells > 0:
587 # loop through each wizard spell level
588 for i in range(len(NewWSpells)):
589 if NewWSpells[i] > 0: # we have new spells, so update
590 GemRB.SetMemorizableSpellsCount(pc, NewWSpells[i], IE_SPELL_TYPE_WIZARD, i)
592 # save our number of memorizable priest spells
593 if DeltaDSpells > 0: # druids and clerics count
594 for i in range (len(NewDSpells)):
595 # get each update
596 if NewDSpells[i] > 0:
597 GemRB.SetMemorizableSpellsCount (pc, NewDSpells[i], IE_SPELL_TYPE_PRIEST, i)
599 # learn all the spells we're given, but don't have, up to our given casting level
600 if GemRB.GetMemorizableSpellsCount (pc, IE_SPELL_TYPE_PRIEST, i, 1) > 0: # we can memorize spells of this level
601 for j in range(NumClasses): # loop through each class
602 IsDruid = GUICommon.ClassSkillsTable.GetValue (Classes[j], 0, 0)
603 IsCleric = GUICommon.ClassSkillsTable.GetValue (Classes[j], 1, 0)
604 if IsCleric == "*" and IsDruid == "*": # no divine spells (so mage/cleric multis don't screw up)
605 continue
606 elif IsCleric == "*": # druid spells
607 ClassFlag = 0x8000
608 else: # cleric spells
609 ClassFlag = 0x4000
611 Learnable = GUICommon.GetLearnablePriestSpells(ClassFlag, GemRB.GetPlayerStat (pc, IE_ALIGNMENT), i+1)
612 for k in range(len(Learnable)): # loop through all the learnable spells
613 if GUICommon.HasSpell (pc, IE_SPELL_TYPE_PRIEST, i, Learnable[k]) < 0: # only write it if we don't yet know it
614 GemRB.LearnSpell(pc, Learnable[k])
616 # hlas
617 # level, xp and other stuff by the core?
619 # 5261 - Regained abilities from inactive class
620 if IsDual: # we're dual classed
621 print "activation?"
622 if (Level[0] - LevelDiff[0]) <= Level[1] and Level[0] > Level[1]: # our new classes now surpasses our old class
623 print "reactivating base class"
624 LUCommon.ReactivateBaseClass ()
626 if LevelUpWindow:
627 LevelUpWindow.Unload()
628 GUICommonWindows.UpdatePortraitWindow ()
629 GUIREC.UpdateRecordsWindow()
631 GemRB.SetRepeatClickFlags (GEM_RK_DISABLE, OP_OR)
632 return
634 def LevelUpHLAPress ():
635 """Opens the HLA selection window."""
637 # we can turn the button off and temporarily set HLACount to 0
638 # because there is no cancel button on the HLA window; therefore,
639 # it's guaranteed to come back as 0
640 TmpCount = GemRB.GetVar ("HLACount")
641 GemRB.SetVar ("HLACount", 0)
642 RedrawSkills ()
643 GemRB.SetVar ("HLACount", TmpCount)
645 LUHLASelection.OpenHLAWindow (pc, NumClasses, Classes, Level)
646 return