def SetupSpellsWindow(chargen=0): if chargen: MyChar = GemRB.GetVar ("Slot") Class = GemRB.GetPlayerStat (MyChar, IE_CLASS) ClassName = GUICommon.GetClassRowName (Class, "class") Level = LevelDiff = 1 else: MyChar = GemRB.GameGetSelectedPCSingle () ClassIndex = GemRB.GetVar ("LUClass") ClassName = GUICommon.GetClassRowName (ClassIndex, "index") LevelDiff = GemRB.GetVar ("LevelDiff") Level = GemRB.GetPlayerStat (MyChar, IE_CLASSLEVELSUM)#FIXME +1? SpellTableName = CommonTables.ClassSkills.GetValue (ClassName, "MAGESPELL") # mxsplbon.2da is handled in core and does not affect learning # sorcerer types need this hack to not get too many spells # for them the castable and known count progress differently if SpellTableName == "MXSPLSOR": SpellTableName = "SPLSRCKN" elif SpellTableName == "MXSPLBRD": SpellTableName = "SPLBRDKN" # learn priest spells if any and setup spell levels # but first nullify any previous spells if chargen: for row in range(CommonTables.ClassSkills.GetRowCount()): rowname = CommonTables.ClassSkills.GetRowName (row) SpellBookType = CommonTables.ClassSkills.GetValue (rowname, "SPLTYPE") if SpellBookType != "*": Spellbook.RemoveKnownSpells (MyChar, SpellBookType, 1,9, 0) Spellbook.RemoveKnownSpells (MyChar, IE_IWD2_SPELL_DOMAIN, 1,9, 0) IDLUCommon.LearnAnySpells (MyChar, ClassName, chargen) # make sure we have a correct table if SpellTableName == "*": if chargen: GemRB.SetNextScript ("CharGen7") else: import GUIREC GUIREC.FinishLevelUp () return # FIXME: this way will only work for chargen, where there aren't any multikits # extract LUClass kit if any and use that IFF it is a mage kit # this value is only used for detecting specialists! KitValue = GemRB.GetPlayerStat (MyChar, IE_KIT) SpellBookType = CommonTables.ClassSkills.GetValue (ClassName, "SPLTYPE") LUSpellSelection.OpenSpellsWindow (MyChar, SpellTableName, Level, LevelDiff, KitValue, chargen, True, SpellBookType) if not chargen: import GUIREC GUIREC.FinishLevelUp ()
def SetupSpellsWindow(chargen=0): if chargen: MyChar = GemRB.GetVar("Slot") Class = GemRB.GetPlayerStat(MyChar, IE_CLASS) ClassName = GUICommon.GetClassRowName(Class, "class") Level = 0 LevelDiff = 1 KitValue = GemRB.GetPlayerStat(MyChar, IE_KIT) else: MyChar = GemRB.GameGetSelectedPCSingle() ClassIndex = GemRB.GetVar("LUClass") ClassName = GUICommon.GetClassRowName(ClassIndex, "index") LevelDiff = GemRB.GetVar("LevelDiff") Level = GemRB.GetPlayerStat(MyChar, IE_CLASSLEVELSUM) # this is only used for detecting specialists! KitValue = GemRB.GetVar("LUKit") SpellTableName = CommonTables.ClassSkills.GetValue(ClassName, "MAGESPELL") # mxsplbon.2da is handled in core and does not affect learning # sorcerer types need this change to not get too many spells # for them the castable and known count progress differently # TODO: create an extra clsskills column to hold this data if SpellTableName == "MXSPLSOR": SpellTableName = "SPLSRCKN" elif SpellTableName == "MXSPLBRD": SpellTableName = "SPLBRDKN" # charbase has domain slots reserved, so nuke them if chargen: Spellbook.UnsetupSpellLevels(MyChar, "MXSPLCLR", IE_IWD2_SPELL_DOMAIN, 1) # learn priest spells if any and setup spell levels # but first nullify any previous spells if chargen: for row in range(CommonTables.ClassSkills.GetRowCount()): rowname = CommonTables.ClassSkills.GetRowName(row) SpellBookType = CommonTables.ClassSkills.GetValue( rowname, "SPLTYPE") if SpellBookType != "*": Spellbook.RemoveKnownSpells(MyChar, SpellBookType, 1, 9, 0) Spellbook.RemoveKnownSpells(MyChar, IE_IWD2_SPELL_DOMAIN, 1, 9, 0) IDLUCommon.LearnAnySpells(MyChar, ClassName, chargen) # make sure we have a correct table and that we're eligible BookType = CommonTables.ClassSkills.GetValue(ClassName, "BOOKTYPE") canLearn = chargen or Spellbook.IsSorcererBook(BookType) # bard / sorcerer if SpellTableName == "*" or not canLearn: if chargen: GemRB.SetNextScript("CharGen7") else: import GUIREC GUIREC.FinishLevelUp() return SpellBookType = CommonTables.ClassSkills.GetValue(ClassName, "SPLTYPE") LUSpellSelection.OpenSpellsWindow(MyChar, SpellTableName, Level + LevelDiff, LevelDiff, KitValue, chargen, True, SpellBookType)
def CanLevelUp(actor): """Returns true if the actor can level up.""" # get our class and placements for Multi'd and Dual'd characters Class = GUICommon.GetClassRowName (actor) Multi = GUICommon.IsMultiClassed (actor, 1) Dual = GUICommon.IsDualClassed (actor, 1) # get all the levels and overall xp here xp = GemRB.GetPlayerStat (actor, IE_XP) Levels = [GemRB.GetPlayerStat (actor, IE_LEVEL), GemRB.GetPlayerStat (actor, IE_LEVEL2),\ GemRB.GetPlayerStat (actor, IE_LEVEL3)] if GemRB.GetPlayerStat(actor, IE_LEVELDRAIN)>0: return 0 if GameCheck.IsIWD2(): import GUIREC levelsum = GemRB.GetPlayerStat (actor, IE_CLASSLEVELSUM) next = GUIREC.GetNextLevelExp(levelsum, GUIREC.GetECL(actor)) return next <= xp if Multi[0] > 1: # multiclassed xp = xp/Multi[0] # divide the xp evenly between the classes for i in range (Multi[0]): # if any class can level, return 1 TmpClassName = GUICommon.GetClassRowName (Multi[i+1], "class") tmpNext = int(GetNextLevelExp (Levels[i], TmpClassName)) if (tmpNext != 0 or Levels[i] == 0) and tmpNext <= xp: return 1 # didn't find a class that could level return 0 elif Dual[0] > 0: # dual classed # get the class we can level if Dual[0] == 3: ClassID = CommonTables.KitList.GetValue (Dual[2], 7) Class = GUICommon.GetClassRowName (ClassID, "class") else: Class = GUICommon.GetClassRowName(Dual[2], "index") if GUICommon.IsDualSwap(actor): Levels = [Levels[1], Levels[0], Levels[2]] # check the class that can be level (single or dual) tmpNext = int(GetNextLevelExp (Levels[0], Class) ) return ((tmpNext != 0 or Levels[0] == 0) and tmpNext <= xp)
def CloseCustomizeWindow (): import GUIREC global CustomizeWindow if CustomizeWindow: CustomizeWindow.Unload () CustomizeWindow = None GUIREC.UpdateRecordsWindow () return
def ReviewPress(): global PartyFormationWindow, ReviewWindow ReviewWindow = GemRB.LoadWindow(8, "GUISP") DoneButton = ReviewWindow.GetControl(1) DoneButton.SetText(11973) DoneButton.MakeDefault() DoneButton.MakeEscape() DoneButton.SetEvent(IE_GUI_BUTTON_ON_PRESS, ReviewDonePress) LeftTextArea = ReviewWindow.GetControl(2) RightTextArea = ReviewWindow.GetControl(3) MyChar = GemRB.GetVar("Slot") import GUIREC GUIREC.DisplayGeneral(MyChar, LeftTextArea) GUIREC.DisplaySkills(MyChar, RightTextArea) ReviewWindow.ShowModal(MODAL_SHADOW_GRAY) return
def ReviewPress (): global PartyFormationWindow, ReviewWindow PartyFormationWindow.SetVisible (WINDOW_INVISIBLE) ReviewWindow = GemRB.LoadWindow (8) DoneButton = ReviewWindow.GetControl (1) DoneButton.SetText (11973) DoneButton.SetFlags (IE_GUI_BUTTON_DEFAULT, OP_OR) DoneButton.SetFlags (IE_GUI_BUTTON_CANCEL, OP_OR) DoneButton.SetEvent (IE_GUI_BUTTON_ON_PRESS, ReviewDonePress) LeftTextArea = ReviewWindow.GetControl (2) RightTextArea = ReviewWindow.GetControl (3) MyChar = GemRB.GetVar ("Slot") import GUIREC GUIREC.DisplayGeneral (MyChar, LeftTextArea) GUIREC.DisplaySkills (MyChar, RightTextArea) ReviewWindow.SetVisible (WINDOW_VISIBLE) return
def LevelUpInfoPress(): """Displays new abilites gained on level up. Alternates between overall and modified stats.""" import GUIREC global LevelUpWindow, TextAreaControl, InfoCounter, LevelDiff if InfoCounter % 2: # call GetStatOverview with the new levels, so the future overview is shown TextAreaControl.SetText(GUIREC.GetStatOverview(pc, LevelDiff)) else: TextAreaControl.SetText(GetLevelUpNews()) InfoCounter += 1 return
def LevelUpInfoPress(): """Displays new abilites gained on level up. Alternates between overall and modified stats.""" import GUIREC global LevelUpWindow, TextAreaControl, InfoCounter, LevelDiff if InfoCounter % 2: # call GetStatOverview with the new levels, so the future overview is shown # TODO: show only xp, levels, thac0, #att, lore, reputation, backstab, saving throws TextAreaControl.SetText(GUIREC.GetStatOverview(pc, LevelDiff)) else: TextAreaControl.SetText(GetLevelUpNews()) InfoCounter += 1 return
def DoSingleAction (): i = GemRB.GetVar ('ItemButton') print i OpenFloatMenuWindow () if i == 0: GUIMA.OpenMapWindow () elif i == 1: GUIJRNL.OpenJournalWindow () elif i == 2: GUIINV.OpenInventoryWindow () elif i == 3: GUIREC.OpenRecordsWindow () elif i == 4: # FIXME: Or priest scroll .... GUIMG.OpenMageWindow ()
def DoSingleAction(): i = GemRB.GetVar('ItemButton') OpenFloatMenuWindow() if i == 0: GUIMA.OpenMapWindow() elif i == 1: GUIJRNL.OpenJournalWindow() elif i == 2: GUIINV.OpenInventoryWindow() elif i == 3: GUIREC.OpenRecordsWindow() elif i == 4: pc = GemRB.GameGetFirstSelectedPC() ClassName = GUICommon.GetClassRowName(pc) if CommonTables.ClassSkills.GetValue(ClassName, "CLERICSPELL") == "*": GUIMG.OpenSpellWindow() else: GUIPR.OpenPriestWindow()
def ReviewPress(): global PartyFormationWindow, ReviewWindow PartyFormationWindow.SetVisible(WINDOW_INVISIBLE) ReviewWindow = GemRB.LoadWindow(8) DoneButton = ReviewWindow.GetControl(1) DoneButton.SetText(11973) DoneButton.SetFlags(IE_GUI_BUTTON_DEFAULT, OP_OR) DoneButton.SetFlags(IE_GUI_BUTTON_CANCEL, OP_OR) DoneButton.SetEvent(IE_GUI_BUTTON_ON_PRESS, ReviewDonePress) LeftTextArea = ReviewWindow.GetControl(2) RightTextArea = ReviewWindow.GetControl(3) MyChar = GemRB.GetVar("Slot") LeftTextArea.SetText(GemRB.GetPlayerName(MyChar)) # TODO: mimic original; reuse GUIREC/CharOverview to reduce duplication import GUIREC GUIREC.DisplaySkills(MyChar, RightTextArea) ReviewWindow.SetVisible(WINDOW_VISIBLE) return
def AcceptPress(): if TotPoints: # Setting up the error window TextArea = QuitWindow.GetControl(0) TextArea.SetText(46782) Button = QuitWindow.GetControl(1) Button.SetText("") Button.SetFlags(IE_GUI_BUTTON_NO_IMAGE, OP_SET) Button.SetState(IE_GUI_BUTTON_DISABLED) Button = QuitWindow.GetControl(2) Button.SetText(46783) Button.SetFlags(IE_GUI_BUTTON_DEFAULT, OP_OR) Button.SetEvent(IE_GUI_BUTTON_ON_PRESS, OkButton) NewLifeWindow.SetVisible(WINDOW_GRAYED) #go dark QuitWindow.SetVisible(WINDOW_VISIBLE) return if NewLifeWindow: NewLifeWindow.Unload() if QuitWindow: QuitWindow.Unload() #set my character up if not LevelUp: MyChar = GemRB.CreatePlayer("charbase", 1) Str = Stats[0] if Str <= 18: GemRB.SetPlayerStat(1, IE_STR, Str) GemRB.SetPlayerStat(1, IE_STREXTRA, 0) else: GemRB.SetPlayerStat(1, IE_STR, 18) GemRB.SetPlayerStat(1, IE_STREXTRA, extras[Str - 19]) GemRB.SetPlayerStat(1, IE_INT, Stats[1]) GemRB.SetPlayerStat(1, IE_WIS, Stats[2]) GemRB.SetPlayerStat(1, IE_DEX, Stats[3]) GemRB.SetPlayerStat(1, IE_CON, Stats[4]) GemRB.SetPlayerStat(1, IE_CHR, Stats[5]) if LevelUp: # hp is handled in GUIREC import GUIREC GUIREC.OpenLevelUpWindow() return #don't add con bonus, it will be calculated by the game #interestingly enough, the game adds only one level's con bonus Con = Stats[4] if Con > 14: x = 30 else: x = 20 + (Con - 9) * 2 print "Setting max hp to: ", x GemRB.SetPlayerStat(1, IE_MAXHITPOINTS, x) #adding the remaining constitution bonus to the current hp #if Con>14: # x = x+(Con-14)*3 print "Setting current hp to: ", x GemRB.SetPlayerStat(1, IE_HITPOINTS, x) GemRB.FillPlayerInfo(1) #does all the rest #alter this if needed GemRB.SetRepeatClickFlags(GEM_RK_DISABLE, OP_SET) #LETS PLAY!! GemRB.EnterGame() return
def SpellsDonePress(): """Move to the next assignable level. If there is not another assignable level, then save all the new spells and close the window.""" global SpellBook, SpellLevel, SpellsWindow, MemoBook, Memorization # oops, we were here before, just memorise the spells and exit if sum(MemoBook) > 0: for i in MemoBook: if i: GemRB.MemorizeSpell(pc, SpellBookType, SpellLevel, i - 1, 1) SpellBook = [] MemoBook = [0] * ButtonCount # save all the spells if not Memorization: for i in range(len(Spells[SpellLevel])): if SpellBook[i]: # we need to learn this spell if IWD2: GemRB.LearnSpell(pc, Spells[SpellLevel][i][0], 0, 1 << SpellBookType) else: GemRB.LearnSpell(pc, Spells[SpellLevel][i][0]) # check to see if we need to update again for i in range(SpellLevel + 1, 9): if SpellsSelectPointsLeft[i] > 0: # reset the variables GemRB.SetVar("SpellTopIndex", 0) SpellLevel = i if not (chargen and GameCheck.IsBG1()): SpellBook = [0] * len(Spells[i]) ScrollBar = SpellsWindow.GetControl(NewScrollBarID) UpdateScrollBar(ScrollBar, len(Spells[i])) # show the spells and set the done button to off ShowSpells() DoneButton.SetDisabled(True) return # bg1 lets you memorize spells too (iwd too, but it does it by itself) if chargen and sum(MemoBook) == 0 and \ (GameCheck.IsBG1() or (IWD2 and SpellBookType == IE_IWD2_SPELL_WIZARD)): SpellLevel = 0 # bump it for specialists and iwd2 casters with high stats SpellsSelectPointsLeft[SpellLevel] = 1 + BonusPoints[SpellLevel] # FIXME: setting the proper count here breaks original characters, see #680 #GemRB.SetMemorizableSpellsCount (pc, SpellsSelectPointsLeft[SpellLevel], SpellBookType, SpellLevel) DoneButton.SetDisabled(True) Memorization = 1 ShowKnownSpells() return # close our window and update our records if SpellsWindow and (not chargen or GameCheck.IsBG2() or IWD2): SpellsWindow.Close() SpellsWindow = None # move to the next script if this is chargen if chargen: if GameCheck.IsBG2(): GemRB.SetNextScript("GUICG6") elif GameCheck.IsBG1(): SpellsWindow.Close() # HACK from CharGenCommon import next next() elif IWD2: GemRB.SetNextScript("CharGen7") elif IWD2: import GUIREC GUIREC.FinishLevelUp() return
def OpenLUStatsWindow(Type=1): global NewLifeWindow, QuitWindow, StatTable global TotPoints, AcPoints, HpPoints global TotLabel, AcLabel, HpLabel global TextArea, Stats, StatLabels, StatLowerLimit, StatLimit, LevelUp GemRB.SetRepeatClickFlags(GEM_RK_DOUBLESPEED, OP_SET) LevelUp = Type if LevelUp: import GUICommonWindows import GUIREC GUICommonWindows.OptionsWindow.SetVisible(WINDOW_INVISIBLE) GUICommonWindows.PortraitWindow.SetVisible(WINDOW_INVISIBLE) GUICommonWindows.ActionsWindow.SetVisible(WINDOW_INVISIBLE) GUIREC.RecordsWindow.SetVisible(WINDOW_INVISIBLE) # only TNO gets the main stat boosts pc = GemRB.GameGetFirstSelectedPC() if pc != 1: GUIREC.OpenLevelUpWindow() return else: GemRB.LoadGame(None) #loading the base game StatTable = GemRB.LoadTable("abcomm") GemRB.LoadWindowPack("GUICG") #setting up confirmation window QuitWindow = GemRB.LoadWindow(1) QuitWindow.SetVisible(WINDOW_INVISIBLE) #setting up CG window NewLifeWindow = GemRB.LoadWindow(0) if LevelUp: Str = GemRB.GetPlayerStat(1, IE_STR, 1) Dex = GemRB.GetPlayerStat(1, IE_DEX, 1) Con = GemRB.GetPlayerStat(1, IE_CON, 1) Wis = GemRB.GetPlayerStat(1, IE_WIS, 1) Int = GemRB.GetPlayerStat(1, IE_INT, 1) Cha = GemRB.GetPlayerStat(1, IE_CHR, 1) TotPoints = 1 # FIXME: actually LevelDiff Stats = [Str, Int, Wis, Dex, Con, Cha] StatLowerLimit = list( Stats ) # so we copy the values or the lower limit would increase with them StatLimit = [25] * 6 else: Str = Dex = Con = Wis = Int = Cha = 9 TotPoints = 21 Stats = [Str, Int, Wis, Dex, Con, Cha] # stat label controls for i in range(len(Stats)): StatLabels[i] = NewLifeWindow.GetControl(0x10000018 + i) # individual stat buttons for i in range(len(Stats)): Button = NewLifeWindow.GetControl(i + 2) Button.SetFlags(IE_GUI_BUTTON_NO_IMAGE, OP_SET) Button.SetEvent(IE_GUI_MOUSE_OVER_BUTTON, StatPress[i]) Button = NewLifeWindow.GetControl(8) Button.SetFlags(IE_GUI_BUTTON_RADIOBUTTON, OP_SET) Button.SetState(IE_GUI_BUTTON_LOCKED) Button.SetSprites("", 0, 0, 0, 0, 0) Button.SetText(5025) Button.SetEvent(IE_GUI_MOUSE_OVER_BUTTON, AcPress) Button = NewLifeWindow.GetControl(9) Button.SetFlags(IE_GUI_BUTTON_RADIOBUTTON, OP_SET) Button.SetState(IE_GUI_BUTTON_LOCKED) Button.SetSprites("", 0, 0, 0, 0, 0) Button.SetText(5026) Button.SetEvent(IE_GUI_MOUSE_OVER_BUTTON, HpPress) Button = NewLifeWindow.GetControl(10) Button.SetFlags(IE_GUI_BUTTON_RADIOBUTTON, OP_SET) Button.SetState(IE_GUI_BUTTON_LOCKED) Button.SetSprites("", 0, 0, 0, 0, 0) Button.SetText(5027) Button.SetEvent(IE_GUI_MOUSE_OVER_BUTTON, PointPress) # stat +/- buttons for i in range(len(StatPress)): Button = NewLifeWindow.GetControl(11 + 2 * i) Button.SetEvent(IE_GUI_BUTTON_ON_PRESS, IncreasePress) Button.SetEvent(IE_GUI_MOUSE_OVER_BUTTON, StatPress[i]) Button.SetVarAssoc("Pressed", i) Button = NewLifeWindow.GetControl(12 + 2 * i) Button.SetEvent(IE_GUI_BUTTON_ON_PRESS, DecreasePress) Button.SetEvent(IE_GUI_MOUSE_OVER_BUTTON, StatPress[i]) Button.SetVarAssoc("Pressed", i) NewLifeLabel = NewLifeWindow.GetControl(0x10000023) NewLifeLabel.SetText(1899) TextArea = NewLifeWindow.GetControl(23) TextArea.SetText(18495) TotLabel = NewLifeWindow.GetControl(0x10000020) AcLabel = NewLifeWindow.GetControl(0x1000001E) HpLabel = NewLifeWindow.GetControl(0x1000001F) Label = NewLifeWindow.GetControl(0x10000021) Label.SetText(254) PhotoButton = NewLifeWindow.GetControl(35) PhotoButton.SetState(IE_GUI_BUTTON_LOCKED) PhotoButton.SetFlags(IE_GUI_BUTTON_NO_IMAGE | IE_GUI_BUTTON_PICTURE, OP_SET) PhotoButton.SetEvent(IE_GUI_MOUSE_OVER_BUTTON, OverPhoto) PhotoButton.SetPicture("STPNOC") AcceptButton = NewLifeWindow.GetControl(0) AcceptButton.SetText(4192) AcceptButton.SetEvent(IE_GUI_BUTTON_ON_PRESS, AcceptPress) AcceptButton.SetFlags(IE_GUI_BUTTON_DEFAULT, OP_OR) CancelButton = NewLifeWindow.GetControl(1) CancelButton.SetText(4196) CancelButton.SetEvent(IE_GUI_BUTTON_ON_PRESS, CancelPress) UpdateLabels() NewLifeWindow.SetVisible(WINDOW_VISIBLE) return
def SpellsDonePress(): """Move to the next assignable level. If there is not another assignable level, then save all the new spells and close the window.""" global SpellBook, SpellLevel, SpellsWindow, MemoBook, Memorization # oops, we were here before, just memorise the spells and exit if sum(MemoBook) > 0: for i in MemoBook: if i: GemRB.MemorizeSpell(pc, SpellBookType, SpellLevel, i - 1, 1) SpellBook = [] MemoBook = [0] * ButtonCount # save all the spells if not Memorization: for i in range(len(Spells[SpellLevel])): if SpellBook[i]: # we need to learn this spell if IWD2: GemRB.LearnSpell(pc, Spells[SpellLevel][i][0], 0, 1 << SpellBookType) else: GemRB.LearnSpell(pc, Spells[SpellLevel][i][0]) # check to see if we need to update again for i in range(SpellLevel + 1, 9): if SpellsSelectPointsLeft[i] > 0: # reset the variables GemRB.SetVar("SpellTopIndex", 0) SpellLevel = i if not (chargen and GameCheck.IsBG1()): SpellBook = [0] * len(Spells[i]) if (EnhanceGUI): # setup the scrollbar ScrollBar = SpellsWindow.GetControl(1000) if len(Spells[i]) > (ButtonCount + ExtraSpellButtons()): HideUnhideScrollBar(0) if chargen: ScrollBar.SetVarAssoc( "SpellTopIndex", GUICommon.ceildiv( (len(Spells[i]) - ButtonCount), 6) + 1) else: ScrollBar.SetVarAssoc( "SpellTopIndex", GUICommon.ceildiv( (len(Spells[i]) - ButtonCount - 1), 5) + 1) else: ScrollBar.SetVarAssoc("SpellTopIndex", 0) HideUnhideScrollBar(1) # show the spells and set the done button to off ShowSpells() DoneButton.SetState(IE_GUI_BUTTON_DISABLED) return # bg1 lets you memorize spells too (iwd too, but it does it by itself) if chargen and sum(MemoBook) == 0 and \ (GameCheck.IsBG1() or (IWD2 and SpellBookType != IE_IWD2_SPELL_SORCERER)): SpellLevel = 0 SpellsSelectPointsLeft[SpellLevel] = 1 if KitMask != 0x4000: # specialists get an extra spell per level SpellsSelectPointsLeft[SpellLevel] += 1 DoneButton.SetState(IE_GUI_BUTTON_DISABLED) Memorization = 1 ShowKnownSpells() return # close our window and update our records if SpellsWindow and (not chargen or GameCheck.IsBG2() or IWD2): SpellsWindow.Unload() SpellsWindow = None # move to the next script if this is chargen if chargen: if GameCheck.IsBG2(): GemRB.SetNextScript("GUICG6") elif GameCheck.IsBG1(): # HACK from CharGenCommon import next next() elif IWD2: GemRB.SetNextScript("CharGen7") elif IWD2: import GUIREC GUIREC.FinishLevelUp() return
def CanLevelUp(actor): """Returns true if the actor can level up.""" # get our class and placements for Multi'd and Dual'd characters Class = GUICommon.GetClassRowName (actor) Multi = GUICommon.IsMultiClassed (actor, 1) Dual = GUICommon.IsDualClassed (actor, 1) # get all the levels and overall xp here xp = GemRB.GetPlayerStat (actor, IE_XP) Levels = [GemRB.GetPlayerStat (actor, IE_LEVEL), GemRB.GetPlayerStat (actor, IE_LEVEL2),\ GemRB.GetPlayerStat (actor, IE_LEVEL3)] if GemRB.GetPlayerStat(actor, IE_LEVELDRAIN)>0: return 0 if GameCheck.IsIWD2(): import GUIREC levelsum = GemRB.GetPlayerStat (actor, IE_CLASSLEVELSUM) nextXP = GUIREC.GetNextLevelExp (levelsum, GUIREC.GetECL (actor)) return nextXP <= xp # hardcoded special case to handle TNO, who is usually a single class # but with three separate Levels/XP values and the ability to switch between them # it returns the active class if true SwitcherClass = GUICommon.NamelessOneClass(actor) if SwitcherClass: xp = { "FIGHTER" : GemRB.GetPlayerStat (actor, IE_XP), "MAGE" : GemRB.GetPlayerStat (actor, IE_XP_MAGE), "THIEF" : GemRB.GetPlayerStat (actor, IE_XP_THIEF) } lvls = { "FIGHTER" : Levels[0] , "MAGE": Levels[1], "THIEF": Levels [2] } tmpNext = GetNextLevelExp (lvls[SwitcherClass], SwitcherClass) if (tmpNext != 0 or lvls[SwitcherClass] == 0) and tmpNext <= xp[SwitcherClass]: return 1 #ignore the rest of this function, to avoid false positives #other classes can only be achieved by hacking the game somehow return 0 if Multi[0] > 1: # multiclassed xp = xp // Multi[0] # divide the xp evenly between the classes for i in range (Multi[0]): # if any class can level, return 1 TmpClassName = GUICommon.GetClassRowName (Multi[i+1], "class") tmpNext = GetNextLevelExp (Levels[i], TmpClassName) if (tmpNext != 0 or Levels[i] == 0) and tmpNext <= xp: return 1 # didn't find a class that could level return 0 elif Dual[0] > 0: # dual classed # get the class we can level if Dual[0] == 3: ClassID = CommonTables.KitList.GetValue (Dual[2], 7) Class = GUICommon.GetClassRowName (ClassID, "class") else: Class = GUICommon.GetClassRowName(Dual[2], "index") if GUICommon.IsDualSwap(actor): Levels = [Levels[1], Levels[0], Levels[2]] # check the class that can be level (single or dual) tmpNext = GetNextLevelExp (Levels[0], Class) return ((tmpNext != 0 or Levels[0] == 0) and tmpNext <= xp)
def OpenLevelUpWindow(): """Sets up the level up window.""" import GUIREC global LevelUpWindow, TextAreaControl, NewProfPoints, actor global DoneButton global NewSkillPoints, KitName, LevelDiff global Level, Classes, NumClasses, DualSwap, IsMulti global OldHPMax, OldSaves, OldLore, OldThaco, DeltaDSpells, DeltaWSpells global NewDSpells, NewWSpells, OldDSpells, OldWSpells, pc, HLACount, ClassName, IsDual LevelUpWindow = GemRB.LoadWindow (3) if GameCheck.IsBG2(): InfoButton = LevelUpWindow.GetControl (125) InfoButton.SetText (13707) InfoButton.SetEvent (IE_GUI_BUTTON_ON_PRESS, LevelUpInfoPress) # hide "Character Generation" LevelUpWindow.DeleteControl(0x1000007e) DoneButton = LevelUpWindow.GetControl (0) DoneButton.SetText (11962) DoneButton.SetEvent (IE_GUI_BUTTON_ON_PRESS, LevelUpDonePress) DoneButton.SetState (IE_GUI_BUTTON_DISABLED) DoneButton.MakeDefault() # also disable closing by ESC, so we don't stack upgrades DoneButton.MakeEscape () # name pc = GemRB.GameGetSelectedPCSingle () actor = Actor.Actor(pc) Label = LevelUpWindow.GetControl (0x10000000+90) Label.SetText (GemRB.GetPlayerName (pc)) # some current values OldHPMax = GemRB.GetPlayerStat (pc, IE_MAXHITPOINTS, 1) OldThaco = GemRB.GetPlayerStat (pc, IE_TOHIT, 1) OldLore = GemRB.GetPlayerStat (pc, IE_LORE, 1) for i in range (5): OldSaves[i] = GemRB.GetPlayerStat (pc, IE_SAVEVSDEATH+i, 1) # class Label = LevelUpWindow.GetControl (0x10000000+106) Label.SetText (GUICommon.GetActorClassTitle (pc)) print("Title: " + GUICommon.GetActorClassTitle (pc) + "\tActor Title: " + actor.ClassTitle()) Class = GemRB.GetPlayerStat (pc, IE_CLASS) print("Class: " + str(Class) + "\tActor Class: " + str(actor.classid)) # kit ClassName = GUICommon.GetClassRowName (Class, "class") Kit = GUICommon.GetKitIndex (pc) print("Kit: " + str(Kit) + "\tActor Kit: " + str(actor.KitIndex())) print("ClassName: " + ClassName + "\tActor ClassNames: " + str(actor.ClassNames())) # need this for checking gnomes RaceName = GemRB.GetPlayerStat (pc, IE_RACE, 1) RaceName = CommonTables.Races.FindValue (3, RaceName) RaceName = CommonTables.Races.GetRowName (RaceName) # figure our our proficiency table and index if Kit == 0: KitName = ClassName else: #rowname is just a number, the kitname is the first data column KitName = CommonTables.KitList.GetValue(Kit, 0) # our multiclass variables IsMulti = GUICommon.IsMultiClassed (pc, 1) Classes = [IsMulti[1], IsMulti[2], IsMulti[3]] NumClasses = IsMulti[0] # 2 or 3 if IsMulti; 0 otherwise IsMulti = NumClasses > 1 IsDual = 0 DualSwap = 0 # not multi, check dual if not IsMulti: # check if we're dual classed IsDual = GUICommon.IsDualClassed (pc, 1) Classes = [] # either dual or single only care about 1 class NumClasses = 1 # not dual, must be single if IsDual[0] == 0: Classes = [Class] else: # resolve kits to classes (new class goes first) if IsDual[0] == 3: # 1st kit Classes.append (CommonTables.KitList.GetValue (IsDual[2], 7)) else: # 1st class Classes.append (CommonTables.Classes.GetValue (IsDual[2], 5)) if IsDual[0] == 1: # 2nd kit Classes.append (CommonTables.KitList.GetValue (IsDual[1], 7)) else: # 2nd class Classes.append (CommonTables.Classes.GetValue (IsDual[1], 5)) # store a boolean for IsDual IsDual = IsDual[0] > 0 print("NumClasses: " + str(NumClasses) + "\tActor NumClasses: " + str(actor.NumClasses())) if IsDual: # convert the classes from indicies to class id's DualSwap = GUICommon.IsDualSwap (pc) ClassName = GUICommon.GetClassRowName (Classes[0], "index") KitName = ClassName # for simplicity throughout the code print("Classes: " + str(Classes) + "\tActor Classes: " + str(actor.Classes())) print("IsDual: " + str(IsDual > 0) + "\tActor IsDual: " + str(actor.isdual)) # get the next target levels and difference between levels Level = LUCommon.GetNextLevels(pc, Classes) LevelDiff = LUCommon.GetLevelDiff(pc, Level) # clear some globals, since we may get called multiple times with different classes DeltaWSpells = 0 DeltaDSpells = 0 OldDSpells = [0]*7 OldWSpells = [0]*9 NewDSpells = [0]*7 NewWSpells = [0]*9 # calculate the new spells (results are stored in global variables) GetNewSpells(pc, Classes, Level, LevelDiff, Kit) # this is handled by core # # setup class bonuses for this class # if IsMulti or IsDual or Kit == 0: # ABTable = CommonTables.ClassSkills.GetValue (TmpClassName, "ABILITIES") # else: # single-classed with a kit # ABTable = CommonTables.KitList.GetValue (str(Kit), "ABILITIES") # # # add the abilites if we have a table to ref # if ABTable != "*" and GemRB.HasResource (ABTable, RES_2DA, 1): # GUICommon.AddClassAbilities (pc, ABTable, Level[i], LevelDiff[i]) print("Actor CurrentLevels:" + str(actor.Levels())) print("Levels: " + str(Level) + "\tActor NextLevels: " + str(actor.NextLevels())) print("LevelDiffs: " + str(LevelDiff) + "\tActor LevelDiffs: " + str(actor.LevelDiffs())) #update our saves, thaco, hp and lore LUCommon.SetupSavingThrows (pc, Level) LUCommon.SetupThaco (pc, Level) LUCommon.SetupLore (pc, LevelDiff) LUCommon.SetupHP (pc, Level, LevelDiff) # we set up these labels so late, so they can show the new HP if GameCheck.IsBG1() or GameCheck.IsIWD1(): # armorclass Label = LevelUpWindow.GetControl (0x10000057) Label.SetText (str (GemRB.GetPlayerStat (pc, IE_ARMORCLASS))) Label.SetTooltip (17183) # hp now Label = LevelUpWindow.GetControl (0x10000058) Label.SetText (str (GemRB.GetPlayerStat (pc, IE_HITPOINTS))) Label.SetTooltip (17184) # hp max Label = LevelUpWindow.GetControl (0x10000059) Label.SetText (str (GemRB.GetPlayerStat (pc, IE_MAXHITPOINTS))) Label.SetTooltip (17378) # use total levels for HLAs HLACount = 0 if GameCheck.HasTOB(): # make sure SoA doesn't try to get it HLATable = GemRB.LoadTable("lunumab") # we need to check each level against a multi value (this is kinda screwy) if actor.multiclass: print("Actor HLA Names: " + str(["MULTI" + str(actor.NumClasses()) + name \ for name in actor.ClassNames()])) else: print("Actor HLA Names: " + str(actor.ClassNames())) for i in range (NumClasses): if IsMulti: # get the row name for lookup ex. MULTI2FIGHTER, MULTI3THIEF MultiName = GUICommon.GetClassRowName (Classes[i], "class") MultiName = "MULTI" + str(NumClasses) + MultiName else: MultiName = ClassName # if we can't learn for this class, we can't learn at all FirstLevel = HLATable.GetValue (MultiName, "FIRST_LEVEL", GTV_INT) if Level[i] < FirstLevel: HLACount = 0 break if (Level[i] - LevelDiff[i]) < FirstLevel: # count only from FirstLevel up HLACount += (Level[i] - FirstLevel + 1) else: HLACount += LevelDiff[i] # set values required by the hla level up code HLACount = HLACount // HLATable.GetValue (ClassName, "RATE", GTV_INT) GemRB.SetVar ("HLACount", HLACount) if GameCheck.IsBG2(): HLAButton = LevelUpWindow.GetControl (126) if HLACount: HLAButton.SetText (4954) HLAButton.SetEvent (IE_GUI_BUTTON_ON_PRESS, LevelUpHLAPress) else: HLAButton.SetFlags (IE_GUI_BUTTON_DISABLED, OP_OR) # setup our profs Level1 = [] for i in range (len (Level)): Level1.append (Level[i]-LevelDiff[i]) if GameCheck.IsBG2(): LUProfsSelection.SetupProfsWindow (pc, LUProfsSelection.LUPROFS_TYPE_LEVELUP, LevelUpWindow, RedrawSkills, Level1, Level) else: LUProfsSelection.SetupProfsWindow (pc, LUProfsSelection.LUPROFS_TYPE_LEVELUP, LevelUpWindow, RedrawSkills, Level1, Level, 0, False, 0) NewProfPoints = GemRB.GetVar ("ProfsPointsLeft") #we autohide the skills and let SetupSkillsWindow show them if needbe for i in range (4): HideSkills (i) if GameCheck.IsBG2(): LUSkillsSelection.SetupSkillsWindow (pc, LUSkillsSelection.LUSKILLS_TYPE_LEVELUP, LevelUpWindow, RedrawSkills, Level1, Level) else: LUSkillsSelection.SetupSkillsWindow (pc, LUSkillsSelection.LUSKILLS_TYPE_LEVELUP, LevelUpWindow, RedrawSkills, Level1, Level, 0, False) NewSkillPoints = GemRB.GetVar ("SkillPointsLeft") if GameCheck.IsBG2(): TextAreaControl = LevelUpWindow.GetControl(110) TextAreaControl.SetText(GetLevelUpNews()) else: TextAreaControl = LevelUpWindow.GetControl(42) TextAreaControl.SetText(GUIREC.GetStatOverview(pc, LevelDiff)) RedrawSkills() LevelUpWindow.ShowModal (MODAL_SHADOW_GRAY) # if we have a sorcerer who can learn spells, we need to do spell selection for c in range(NumClasses): if Spellbook.HasSorcererBook (pc, Classes[c]) and DeltaWSpells > 0: LUSpellSelection.OpenSpellsWindow (pc, "SPLSRCKN", Level[c], LevelDiff[c])
def OpenLevelUpWindow(): """Sets up the level up window.""" import GUIREC global LevelUpWindow, TextAreaControl, NewProfPoints, actor global DoneButton global NewSkillPoints, KitName, LevelDiff global Level, Classes, NumClasses, DualSwap, IsMulti global OldHPMax, OldSaves, OldLore, OldThaco, DeltaDSpells, DeltaWSpells global NewDSpells, NewWSpells, OldDSpells, OldWSpells, pc, HLACount, ClassName, IsDual LevelUpWindow = GemRB.LoadWindow(3) if GameCheck.IsBG2(): InfoButton = LevelUpWindow.GetControl(125) InfoButton.SetText(13707) InfoButton.SetEvent(IE_GUI_BUTTON_ON_PRESS, LevelUpInfoPress) DoneButton = LevelUpWindow.GetControl(0) DoneButton.SetText(11962) DoneButton.SetEvent(IE_GUI_BUTTON_ON_PRESS, LevelUpDonePress) DoneButton.SetState(IE_GUI_BUTTON_DISABLED) DoneButton.SetFlags(IE_GUI_BUTTON_DEFAULT, OP_OR) # hide "Character Generation" Label = LevelUpWindow.CreateLabel( 0x1000007e, 0, 0, 0, 0, "NUMBER", "", IE_FONT_ALIGN_CENTER | IE_FONT_SINGLE_LINE) # name pc = GemRB.GameGetSelectedPCSingle() actor = Actor.Actor(pc) Label = LevelUpWindow.GetControl(0x10000000 + 90) Label.SetText(GemRB.GetPlayerName(pc)) if GameCheck.IsBG1() or GameCheck.IsIWD1(): # armorclass Label = LevelUpWindow.GetControl(0x10000057) Label.SetText(str(GemRB.GetPlayerStat(pc, IE_ARMORCLASS))) Label.SetTooltip(17183) # hp now Label = LevelUpWindow.GetControl(0x10000058) Label.SetText(str(GemRB.GetPlayerStat(pc, IE_HITPOINTS))) Label.SetTooltip(17184) # hp max Label = LevelUpWindow.GetControl(0x10000059) Label.SetText(str(GemRB.GetPlayerStat(pc, IE_MAXHITPOINTS))) Label.SetTooltip(17378) # some current values OldHPMax = GemRB.GetPlayerStat(pc, IE_MAXHITPOINTS, 1) OldThaco = GemRB.GetPlayerStat(pc, IE_TOHIT, 1) OldLore = GemRB.GetPlayerStat(pc, IE_LORE, 1) for i in range(5): OldSaves[i] = GemRB.GetPlayerStat(pc, IE_SAVEVSDEATH + i, 1) # class Label = LevelUpWindow.GetControl(0x10000000 + 106) Label.SetText(GUICommon.GetActorClassTitle(pc)) print "Title:", GUICommon.GetActorClassTitle( pc), "\tActor Title:", actor.ClassTitle() Class = GemRB.GetPlayerStat(pc, IE_CLASS) print "Class:", Class, "\tActor Class:", actor.classid SkillTable = GemRB.LoadTable("skills") # kit ClassName = GUICommon.GetClassRowName(Class, "class") Kit = GUICommon.GetKitIndex(pc) print "Kit:", Kit, "\tActor Kit:", actor.KitIndex() print "ClassName:", ClassName, "\tActor ClassNames:", actor.ClassNames() # need this for checking gnomes RaceName = GemRB.GetPlayerStat(pc, IE_RACE, 1) RaceName = CommonTables.Races.FindValue(3, RaceName) RaceName = CommonTables.Races.GetRowName(RaceName) # figure our our proficiency table and index if Kit == 0: KitName = ClassName else: #rowname is just a number, the kitname is the first data column KitName = CommonTables.KitList.GetValue(Kit, 0) # our multiclass variables IsMulti = GUICommon.IsMultiClassed(pc, 1) Classes = [IsMulti[1], IsMulti[2], IsMulti[3]] NumClasses = IsMulti[0] # 2 or 3 if IsMulti; 0 otherwise IsMulti = NumClasses > 1 IsDual = 0 DualSwap = 0 # not multi, check dual if not IsMulti: # check if we're dual classed IsDual = GUICommon.IsDualClassed(pc, 1) Classes = [IsDual[2], IsDual[1]] # make sure the new class is first # either dual or single only care about 1 class NumClasses = 1 # not dual, must be single if IsDual[0] == 0: Classes = [Class] else: # make sure Classes[1] is a class, not a kit if IsDual[0] == 1: # kit Classes[1] = CommonTables.KitList.GetValue(IsDual[1], 7) else: # class TmpClassName = GUICommon.GetClassRowName(Classes[1], "index") Classes[1] = CommonTables.Classes.GetValue(TmpClassName, "ID") # store a boolean for IsDual IsDual = IsDual[0] > 0 print "NumClasses:", NumClasses, "\tActor NumClasses:", actor.NumClasses() Level = [0] * 3 LevelDiff = [0] * 3 # reorganize the leves if we're dc so the one we want to use is in Level[0] # and the old one is in Level[1] (used to regain old class abilities) if IsDual: # convert the classes from indicies to class id's DualSwap = GUICommon.IsDualSwap(pc) ClassName = GUICommon.GetClassRowName(Classes[0], "index") KitName = ClassName # for simplicity throughout the code Classes[0] = CommonTables.Classes.GetValue(ClassName, "ID") # Class[1] is taken care of above # we need the old level as well if DualSwap: Level[1] = GemRB.GetPlayerStat(pc, IE_LEVEL) else: Level[1] = GemRB.GetPlayerStat(pc, IE_LEVEL2) print "Classes:", Classes, "\tActor Classes:", actor.Classes() print "IsDual:", IsDual > 0, "\tActor IsDual", actor.isdual hp = 0 HaveCleric = 0 # clear some globals, since we may get called multiple times with different classes DeltaWSpells = 0 DeltaDSpells = 0 OldDSpells = [0] * 7 OldWSpells = [0] * 9 NewDSpells = [0] * 7 NewWSpells = [0] * 9 # get a bunch of different things each level for i in range(NumClasses): # print "Class:",Classes[i] # we don't care about the current level, but about the to-be-achieved one # get the next level Level[i] = LUCommon.GetNextLevelFromExp( GemRB.GetPlayerStat(pc, IE_XP) / NumClasses, Classes[i]) TmpClassName = GUICommon.GetClassRowName(Classes[i], "class") # find the level diff for each classes (3 max, obviously) if i == 0: if DualSwap: LevelDiff[i] = Level[i] - GemRB.GetPlayerStat(pc, IE_LEVEL2) else: LevelDiff[i] = Level[i] - GemRB.GetPlayerStat(pc, IE_LEVEL) elif i == 1: LevelDiff[i] = Level[i] - GemRB.GetPlayerStat(pc, IE_LEVEL2) elif i == 2: LevelDiff[i] = Level[i] - GemRB.GetPlayerStat(pc, IE_LEVEL3) # print "Level (",i,"):",Level[i] # print "Level Diff (",i,"):",LevelDiff[i] # save our current and next spell amounts StartLevel = Level[i] - LevelDiff[i] DruidTable = CommonTables.ClassSkills.GetValue(TmpClassName, "DRUIDSPELL", GTV_STR) ClericTable = CommonTables.ClassSkills.GetValue( TmpClassName, "CLERICSPELL", GTV_STR) MageTable = CommonTables.ClassSkills.GetValue(TmpClassName, "MAGESPELL", GTV_STR) # see if we have mage spells if MageTable != "*": # we get 1 extra spell per level if we're a specialist Specialist = 0 if CommonTables.KitList.GetValue( Kit, 7) == 1: # see if we're a kitted mage Specialist = 1 if Spellbook.HasSorcererBook(pc, Classes[i]): MageTable = "SPLSRCKN" MageTable = GemRB.LoadTable(MageTable) # loop through each spell level and save the amount possible to cast (current) for j in range(MageTable.GetColumnCount()): NewWSpells[j] = MageTable.GetValue(str(Level[i]), str(j + 1), GTV_INT) OldWSpells[j] = MageTable.GetValue(str(StartLevel), str(j + 1), GTV_INT) if NewWSpells[ j] > 0: # don't want specialist to get 1 in levels they should have 0 NewWSpells[j] += Specialist if OldWSpells[j] > 0: OldWSpells[j] += Specialist DeltaWSpells = sum(NewWSpells) - sum(OldWSpells) elif ClericTable != "*": # check for cleric spells if not GemRB.HasResource(ClericTable, RES_2DA, 1): ClericTable = "MXSPLPRS" # iwd1 doesn't have a DRUIDSPELL column in the table ClericTable = GemRB.LoadTable(ClericTable) HaveCleric = 1 # same as above for j in range(ClericTable.GetColumnCount()): NewDSpells[j] = ClericTable.GetValue(str(Level[i]), str(j + 1), GTV_INT) OldDSpells[j] = ClericTable.GetValue(str(StartLevel), str(j + 1), GTV_INT) DeltaDSpells = sum(NewDSpells) - sum(OldDSpells) elif DruidTable != "*": # clerics have precedence in multis (ranger/cleric) if HaveCleric == 0: #use MXSPLPRS if we can't find the resource (SoA fix) if not GemRB.HasResource(DruidTable, RES_2DA): DruidTable = "MXSPLPRS" # check druid spells DruidTable = GemRB.LoadTable(DruidTable) # same as above for j in range(DruidTable.GetColumnCount()): NewDSpells[j] = DruidTable.GetValue( str(Level[i]), str(j + 1), GTV_INT) OldDSpells[j] = DruidTable.GetValue( str(StartLevel), str(j + 1), GTV_INT) DeltaDSpells = sum(NewDSpells) - sum(OldDSpells) # this is handled by core # # setup class bonuses for this class # if IsMulti or IsDual or Kit == 0: # ABTable = CommonTables.ClassSkills.GetValue (TmpClassName, "ABILITIES") # else: # single-classed with a kit # ABTable = CommonTables.KitList.GetValue (str(Kit), "ABILITIES") # # # add the abilites if we have a table to ref # if ABTable != "*" and GemRB.HasResource (ABTable, RES_2DA, 1): # GUICommon.AddClassAbilities (pc, ABTable, Level[i], LevelDiff[i]) print "Actor CurrentLevels:", actor.Levels() print "Levels:", Level, "Actor NextLevels:", actor.NextLevels() print "LevelDiffs:", LevelDiff, "Actor LevelDiffs:", actor.LevelDiffs() #update our saves, thaco, hp and lore LUCommon.SetupSavingThrows(pc, Level) LUCommon.SetupThaco(pc, Level) LUCommon.SetupLore(pc, LevelDiff) LUCommon.SetupHP(pc, Level, LevelDiff) # use total levels for HLAs HLACount = 0 if GameCheck.HasTOB(): # make sure SoA doesn't try to get it HLATable = GemRB.LoadTable("lunumab") # we need to check each level against a multi value (this is kinda screwy) if actor.multiclass: print "Actor HLA Names:",["MULTI"+str(actor.NumClasses())+name \ for name in actor.ClassNames()] else: print "Actor HLA Names:", actor.ClassNames() for i in range(NumClasses): if IsMulti: # get the row name for lookup ex. MULTI2FIGHTER, MULTI3THIEF MultiName = GUICommon.GetClassRowName(Classes[i], "class") MultiName = "MULTI" + str(NumClasses) + MultiName else: MultiName = ClassName # if we can't learn for this class, we can't learn at all FirstLevel = HLATable.GetValue(MultiName, "FIRST_LEVEL", GTV_INT) if Level[i] < FirstLevel: HLACount = 0 break if (Level[i] - LevelDiff[i]) < FirstLevel: # count only from FirstLevel up HLACount += (Level[i] - FirstLevel + 1) else: HLACount += LevelDiff[i] # set values required by the hla level up code HLACount = HLACount / HLATable.GetValue(ClassName, "RATE", GTV_INT) GemRB.SetVar("HLACount", HLACount) if GameCheck.IsBG2(): HLAButton = LevelUpWindow.GetControl(126) if HLACount: HLAButton.SetText(4954) HLAButton.SetEvent(IE_GUI_BUTTON_ON_PRESS, LevelUpHLAPress) else: HLAButton.SetFlags(IE_GUI_BUTTON_DISABLED, OP_OR) # setup our profs Level1 = [] for i in range(len(Level)): Level1.append(Level[i] - LevelDiff[i]) if GameCheck.IsBG2(): LUProfsSelection.SetupProfsWindow( pc, LUProfsSelection.LUPROFS_TYPE_LEVELUP, LevelUpWindow, RedrawSkills, Level1, Level) else: LUProfsSelection.SetupProfsWindow( pc, LUProfsSelection.LUPROFS_TYPE_LEVELUP, LevelUpWindow, RedrawSkills, Level1, Level, 0, False, 0) NewProfPoints = GemRB.GetVar("ProfsPointsLeft") #we autohide the skills and let SetupSkillsWindow show them if needbe for i in range(4): HideSkills(i) if GameCheck.IsBG2(): LUSkillsSelection.SetupSkillsWindow( pc, LUSkillsSelection.LUSKILLS_TYPE_LEVELUP, LevelUpWindow, RedrawSkills, Level1, Level) else: LUSkillsSelection.SetupSkillsWindow( pc, LUSkillsSelection.LUSKILLS_TYPE_LEVELUP, LevelUpWindow, RedrawSkills, Level1, Level, 0, False) NewSkillPoints = GemRB.GetVar("SkillPointsLeft") if GameCheck.IsBG2(): TextAreaControl = LevelUpWindow.GetControl(110) TextAreaControl.SetText(GetLevelUpNews()) else: TextAreaControl = LevelUpWindow.GetControl(42) TextAreaControl.SetText(GUIREC.GetStatOverview(pc, LevelDiff)) RedrawSkills() GemRB.SetRepeatClickFlags(GEM_RK_DISABLE, OP_NAND) LevelUpWindow.ShowModal(MODAL_SHADOW_GRAY) # if we have a sorcerer who can learn spells, we need to do spell selection for c in range(len(Classes)): if Spellbook.HasSorcererBook(pc, Classes[c]) and DeltaWSpells > 0: LUSpellSelection.OpenSpellsWindow(pc, "SPLSRCKN", Level[c], LevelDiff[c])
def LevelUpDonePress(): """Updates the PC with the new choices. Closes the window when finished.""" import GUICommonWindows import GUIREC global SkillTable # proficiencies LUProfsSelection.ProfsSave(pc) # skills LUSkillsSelection.SkillsSave(pc) # level if DualSwap: # swap the IE_LEVELs around if a backward dual GemRB.SetPlayerStat(pc, IE_LEVEL2, Level[0]) GemRB.SetPlayerStat(pc, IE_LEVEL, Level[1]) else: GemRB.SetPlayerStat(pc, IE_LEVEL, Level[0]) GemRB.SetPlayerStat(pc, IE_LEVEL2, Level[1]) GemRB.SetPlayerStat(pc, IE_LEVEL3, Level[2]) print "Levels:", Level[0], "/", Level[1], "/", Level[2] # save our number of memorizable spells per level if DeltaWSpells > 0: # loop through each wizard spell level for i in range(len(NewWSpells)): if NewWSpells[i] > 0: # we have new spells, so update GemRB.SetMemorizableSpellsCount(pc, NewWSpells[i], IE_SPELL_TYPE_WIZARD, i) # save our number of memorizable priest spells if DeltaDSpells > 0: # druids and clerics count for i in range(len(NewDSpells)): # get each update if NewDSpells[i] > 0: GemRB.SetMemorizableSpellsCount(pc, NewDSpells[i], IE_SPELL_TYPE_PRIEST, i) # learn all the spells we're given, but don't have, up to our given casting level # bonus spells don't count in determining if we can use this level if GemRB.GetMemorizableSpellsCount( pc, IE_SPELL_TYPE_PRIEST, i, 0) > 0: # we can memorize spells of this level for j in range(NumClasses): # loop through each class TmpClassName = GUICommon.GetClassRowName( Classes[j], "class") IsDruid = CommonTables.ClassSkills.GetValue( TmpClassName, "DRUIDSPELL", GTV_STR) IsCleric = CommonTables.ClassSkills.GetValue( TmpClassName, "CLERICSPELL", GTV_STR) if IsCleric == "*" and IsDruid == "*": # no divine spells (so mage/cleric multis don't screw up) continue elif IsCleric == "*": # druid spells ClassFlag = 0x8000 else: # cleric spells ClassFlag = 0x4000 Learnable = Spellbook.GetLearnablePriestSpells( ClassFlag, GemRB.GetPlayerStat(pc, IE_ALIGNMENT), i + 1) for k in range(len(Learnable) ): # loop through all the learnable spells if Spellbook.HasSpell( pc, IE_SPELL_TYPE_PRIEST, i, Learnable[k] ) < 0: # only write it if we don't yet know it GemRB.LearnSpell(pc, Learnable[k]) # hlas # level, xp and other stuff by the core? # 5261 - Regained abilities from inactive class if IsDual: # we're dual classed print "activation?" if (Level[0] - LevelDiff[0]) <= Level[1] and Level[0] > Level[ 1]: # our new classes now surpasses our old class print "reactivating base class" ReactivateBaseClass() if LevelUpWindow: LevelUpWindow.Unload() GUICommonWindows.UpdatePortraitWindow() GUIREC.UpdateRecordsWindow() GemRB.SetRepeatClickFlags(GEM_RK_DISABLE, OP_OR) return
def DCMainDonePress(): """Saves our dualclass changes and closes the window. This de-activates our old class and readjusts the basic actor stats, such as THAC0, spell casting, proficiencies, and so forth, to the new class.""" import GUIREC # save our proficiencies LUProfsSelection.ProfsSave(pc, LUProfsSelection.LUPROFS_TYPE_DUALCLASS) # remove old class abilities KitIndex = GUICommon.GetKitIndex(pc) if KitIndex: ABTable = CommonTables.KitList.GetValue(str(KitIndex), "ABILITIES") else: ABTable = CommonTables.ClassSkills.GetValue(OldClassName, "ABILITIES") if ABTable != "*" and GemRB.HasResource(ABTable, RES_2DA, 1): GUICommon.RemoveClassAbilities(pc, ABTable, GemRB.GetPlayerStat(pc, IE_LEVEL)) # remove old class casting if not NewMageSpells: for i in range(9): GemRB.SetMemorizableSpellsCount(pc, 0, IE_SPELL_TYPE_WIZARD, i) GUICommon.RemoveKnownSpells(pc, IE_SPELL_TYPE_PRIEST, 1, 7, 1) # apply our class abilities ABTable = CommonTables.ClassSkills.GetValue(ClassName, "ABILITIES") if ABTable != "*" and GemRB.HasResource(ABTable, RES_2DA, 1): GUICommon.AddClassAbilities(pc, ABTable) # learn our new priest spells if NewPriestMask: GUICommon.LearnPriestSpells(pc, 1, NewPriestMask) GemRB.SetMemorizableSpellsCount(pc, 1, IE_SPELL_TYPE_PRIEST, 0) # save our thief skills if we have them LUSkillsSelection.SkillsSave(pc) # save our new class and say was multi OldClassId = GemRB.GetPlayerStat(pc, IE_CLASS) MultClassId = (1 << (NewClassId - 1)) | (1 << (OldClassId - 1)) MultClassId = CommonTables.Classes.FindValue(4, MultClassId) MultClassId = CommonTables.Classes.GetValue(MultClassId, 5) GemRB.SetPlayerStat(pc, IE_CLASS, MultClassId) GemRB.SetPlayerStat( pc, IE_MC_FLAGS, CommonTables.Classes.GetValue(OldClassName, "MC_WAS_ID", 1)) # update our levels and xp if GUICommon.IsDualSwap(pc): GemRB.SetPlayerStat(pc, IE_LEVEL2, 1) else: GemRB.SetPlayerStat(pc, IE_LEVEL2, GemRB.GetPlayerStat(pc, IE_LEVEL), 0) GemRB.SetPlayerStat(pc, IE_LEVEL, 1) GemRB.SetPlayerStat(pc, IE_XP, 0) # new thac0 ThacoTable = GemRB.LoadTable("THAC0") GemRB.SetPlayerStat(pc, IE_TOHIT, ThacoTable.GetValue(NewClassId - 1, 0, 1)) # new saves SavesTable = CommonTables.Classes.GetValue( CommonTables.Classes.FindValue(5, NewClassId), 3, 0) SavesTable = GemRB.LoadTable(SavesTable) for i in range(5): GemRB.SetPlayerStat(pc, IE_SAVEVSDEATH + i, SavesTable.GetValue(i, 0)) # close our window if DCMainWindow: DCMainWindow.Unload() GUIREC.UpdateRecordsWindow() return
def DCMainDonePress(): """Saves our dualclass changes and closes the window. This de-activates our old class and readjusts the basic actor stats, such as THAC0, spell casting, proficiencies, and so forth, to the new class.""" import GUIREC global ClassName # save our proficiencies LUProfsSelection.ProfsSave(pc, LUProfsSelection.LUPROFS_TYPE_DUALCLASS) # remove old class abilities KitIndex = GUICommon.GetKitIndex(pc) if KitIndex: ABTable = CommonTables.KitList.GetValue(str(KitIndex), "ABILITIES") else: ABTable = CommonTables.ClassSkills.GetValue(OldClassName, "ABILITIES") if ABTable != "*" and GemRB.HasResource(ABTable, RES_2DA, 1): GUICommon.RemoveClassAbilities(pc, ABTable, GemRB.GetPlayerStat(pc, IE_LEVEL)) # remove old class casting if not NewMageSpells: for i in range(9): GemRB.SetMemorizableSpellsCount(pc, 0, IE_SPELL_TYPE_WIZARD, i) Spellbook.RemoveKnownSpells(pc, IE_SPELL_TYPE_PRIEST, 1, 7, 1) # apply our class abilities ABTable = CommonTables.ClassSkills.GetValue(ClassName, "ABILITIES") if ABTable != "*" and GemRB.HasResource(ABTable, RES_2DA, 1): GUICommon.AddClassAbilities(pc, ABTable) # learn our new priest spells if NewPriestMask: Spellbook.LearnPriestSpells(pc, 1, NewPriestMask) GemRB.SetMemorizableSpellsCount(pc, 1, IE_SPELL_TYPE_PRIEST, 0) # save our thief skills if we have them LUSkillsSelection.SkillsSave(pc) # NOTE: the ordering here is very deliberate, don't touch! # for the dc detection code to work in core, some level and mc bits info has to be there # 3 PCF functions (class, kit, level) all need more info # testcase: dualclassing and checking how the actionbar evolves # mark the actor as dualclassed OldMCFlags = GemRB.GetPlayerStat(pc, IE_MC_FLAGS, 1) NewMCBit = CommonTables.Classes.GetValue(OldClassName, "MC_WAS_ID", GTV_INT) GemRB.SetPlayerStat(pc, IE_MC_FLAGS, OldMCFlags | NewMCBit) # calculate new dc/mc class combo OldClassId = GemRB.GetPlayerStat(pc, IE_CLASS) MultClassId = (1 << (NewClassId - 1)) | (1 << (OldClassId - 1)) MultClassId = CommonTables.Classes.FindValue("MULTI", MultClassId) MultClassId = CommonTables.Classes.GetRowName(MultClassId) MultClassId = CommonTables.Classes.GetValue(MultClassId, "ID") # fake update our levels (no PCF), so the PCF can be ran later on correct values # core only looks at the level difference when determining dc class order DSOverride = {"old": OldClassId, "new": NewClassId, "mc": MultClassId} Level1 = GemRB.GetPlayerStat(pc, IE_LEVEL) if GUICommon.IsDualSwap(pc, DSOverride): GemRB.SetPlayerStat(pc, IE_LEVEL2, 0, 0) else: GemRB.SetPlayerStat(pc, IE_LEVEL2, Level1 - 1, 0) GemRB.SetPlayerStat(pc, IE_LEVEL, 0, 0) # finally set the new class GemRB.SetPlayerStat(pc, IE_CLASS, MultClassId) # update our levels and xp if GUICommon.IsDualSwap(pc, DSOverride): GemRB.SetPlayerStat(pc, IE_LEVEL2, 1) else: GemRB.SetPlayerStat(pc, IE_LEVEL2, Level1, 0) GemRB.SetPlayerStat(pc, IE_LEVEL, 1) GemRB.SetPlayerStat(pc, IE_XP, 0) # END of order matters NOTE # new thac0 ThacoTable = GemRB.LoadTable("THAC0") GemRB.SetPlayerStat(pc, IE_TOHIT, ThacoTable.GetValue(NewClassId - 1, 0, GTV_INT)) # new saves SavesTable = CommonTables.Classes.GetValue(ClassName, "SAVE", GTV_STR) SavesTable = GemRB.LoadTable(SavesTable) for i in range(5): GemRB.SetPlayerStat(pc, IE_SAVEVSDEATH + i, SavesTable.GetValue(i, 0)) # dump any equipped items that are now unusable DumpUnusableItems(pc) # close our window if DCMainWindow: DCMainWindow.Unload() GUIREC.UpdateRecordsWindow() return
def DCMainDonePress(): """Saves our dualclass changes and closes the window. This de-activates our old class and readjusts the basic actor stats, such as THAC0, spell casting, proficiencies, and so forth, to the new class.""" import GUIREC global ClassName # save our proficiencies LUProfsSelection.ProfsSave(pc, LUProfsSelection.LUPROFS_TYPE_DUALCLASS) # remove old class abilities KitIndex = GUICommon.GetKitIndex(pc) if KitIndex: ABTable = CommonTables.KitList.GetValue(str(KitIndex), "ABILITIES") else: ABTable = CommonTables.ClassSkills.GetValue(OldClassName, "ABILITIES") if ABTable != "*" and GemRB.HasResource(ABTable, RES_2DA, 1): GUICommon.RemoveClassAbilities(pc, ABTable, GemRB.GetPlayerStat(pc, IE_LEVEL)) # remove old class casting if not NewMageSpells: for i in range(9): GemRB.SetMemorizableSpellsCount(pc, 0, IE_SPELL_TYPE_WIZARD, i) Spellbook.RemoveKnownSpells(pc, IE_SPELL_TYPE_PRIEST, 1, 7, 1) # apply our class abilities ABTable = CommonTables.ClassSkills.GetValue(ClassName, "ABILITIES") if ABTable != "*" and GemRB.HasResource(ABTable, RES_2DA, 1): GUICommon.AddClassAbilities(pc, ABTable) # learn our new priest spells if NewPriestMask: Spellbook.LearnPriestSpells(pc, 1, NewPriestMask) GemRB.SetMemorizableSpellsCount(pc, 1, IE_SPELL_TYPE_PRIEST, 0) # save our thief skills if we have them LUSkillsSelection.SkillsSave(pc) # save our new class and say was multi OldClassId = GemRB.GetPlayerStat(pc, IE_CLASS) MultClassId = (1 << (NewClassId - 1)) | (1 << (OldClassId - 1)) MultClassId = CommonTables.Classes.FindValue("MULTI", MultClassId) MultClassId = CommonTables.Classes.GetRowName(MultClassId) MultClassId = CommonTables.Classes.GetValue(MultClassId, "ID") GemRB.SetPlayerStat(pc, IE_CLASS, MultClassId) GemRB.SetPlayerStat( pc, IE_MC_FLAGS, CommonTables.Classes.GetValue(OldClassName, "MC_WAS_ID", 1)) # update our levels and xp if GUICommon.IsDualSwap(pc): GemRB.SetPlayerStat(pc, IE_LEVEL2, 1) else: GemRB.SetPlayerStat(pc, IE_LEVEL2, GemRB.GetPlayerStat(pc, IE_LEVEL), 0) GemRB.SetPlayerStat(pc, IE_LEVEL, 1) GemRB.SetPlayerStat(pc, IE_XP, 0) # new thac0 ThacoTable = GemRB.LoadTable("THAC0") GemRB.SetPlayerStat(pc, IE_TOHIT, ThacoTable.GetValue(NewClassId - 1, 0, 1)) # new saves SavesTable = CommonTables.Classes.GetValue(ClassName, "SAVE", 0) SavesTable = GemRB.LoadTable(SavesTable) for i in range(5): GemRB.SetPlayerStat(pc, IE_SAVEVSDEATH + i, SavesTable.GetValue(i, 0)) # dump any equipped items that are now unusable SlotTypes = [ SLOT_ARMOUR, SLOT_SHIELD, SLOT_HELM, SLOT_RING, SLOT_CLOAK, SLOT_BOOT, SLOT_AMULET, SLOT_GLOVE, SLOT_BELT, SLOT_ITEM, SLOT_WEAPON, SLOT_QUIVER ] for type in SlotTypes: Slots = GemRB.GetSlots(pc, type) if not len(Slots): # nothing there continue for slot in Slots: SlotType = GemRB.GetSlotType(slot, pc) CREItem = GemRB.GetSlotItem(pc, slot) if not GemRB.CanUseItemType(SlotType["Type"], CREItem["ItemResRef"], pc): # move it to a free inventory slot by mimicking dragging Item = GemRB.GetItem(CREItem["ItemResRef"]) GemRB.DragItem(pc, slot, Item["ItemIcon"]) GemRB.DropDraggedItem(pc, -3) # close our window if DCMainWindow: DCMainWindow.Unload() GUIREC.UpdateRecordsWindow() return