Esempio n. 1
0
def OnLoad():
    global SkillWindow, DoneButton, MyChar

    SkillWindow = GemRB.LoadWindow(6, "GUICG")
    CharGenCommon.PositionCharGenWin(SkillWindow)

    MyChar = GemRB.GetVar("Slot")

    Levels = [GemRB.GetPlayerStat (MyChar, IE_LEVEL), \
      GemRB.GetPlayerStat (MyChar, IE_LEVEL2), \
      GemRB.GetPlayerStat (MyChar, IE_LEVEL3)]
    LUSkillsSelection.SetupSkillsWindow (MyChar, \
     LUSkillsSelection.LUSKILLS_TYPE_CHARGEN, SkillWindow, RedrawSkills, [0,0,0], Levels)

    # can't be moved earlier as this var will be set in the setup call above
    if not GemRB.GetVar("SkillPointsLeft"):  #skipping
        if SkillWindow:
            SkillWindow.Unload()
        GemRB.SetNextScript("GUICG9")
        return

    BackButton = SkillWindow.GetControl(25)
    BackButton.SetText(15416)
    BackButton.MakeEscape()
    BackButton.SetEvent(IE_GUI_BUTTON_ON_PRESS, BackPress)

    DoneButton = SkillWindow.GetControl(0)
    DoneButton.SetText(11973)
    DoneButton.MakeDefault()
    DoneButton.SetEvent(IE_GUI_BUTTON_ON_PRESS, NextPress)
    DoneButton.SetDisabled(True)

    RedrawSkills()
    SkillWindow.Focus()
    return
Esempio n. 2
0
def OnLoad():
	global SkillWindow, DoneButton

	SkillWindow = GemRB.LoadWindow(6, "GUICG")

	MyChar = GemRB.GetVar ("Slot")

	Levels = [GemRB.GetPlayerStat (MyChar, IE_LEVEL), \
			GemRB.GetPlayerStat (MyChar, IE_LEVEL2), \
			GemRB.GetPlayerStat (MyChar, IE_LEVEL3)]
	LUSkillsSelection.SetupSkillsWindow (MyChar, LUSkillsSelection.LUSKILLS_TYPE_CHARGEN, SkillWindow, RedrawSkills, [0,0,0], Levels,0,False)
	
	BackButton = SkillWindow.GetControl(25)
	BackButton.SetText(15416)
	BackButton.OnPress (lambda: CharGenCommon.back(SkillWindow))

	DoneButton = SkillWindow.GetControl(0)
	DoneButton.SetText(11973)
	DoneButton.MakeDefault()
	DoneButton.OnPress (NextPress)
	DoneButton.SetState(IE_GUI_BUTTON_DISABLED)

	RedrawSkills()
	SkillWindow.ShowModal(MODAL_SHADOW_NONE)
	return
Esempio n. 3
0
def OnLoad():
    global SkillWindow, DoneButton

    if GUICommon.CloseOtherWindow(OnLoad):
        if (SkillWindow):
            SkillWindow.Unload()
            SkillWindow = None
        return

    GemRB.LoadWindowPack("GUICG", 640, 480)
    SkillWindow = GemRB.LoadWindow(6)

    MyChar = GemRB.GetVar("Slot")

    Levels = [GemRB.GetPlayerStat (MyChar, IE_LEVEL), \
      GemRB.GetPlayerStat (MyChar, IE_LEVEL2), \
      GemRB.GetPlayerStat (MyChar, IE_LEVEL3)]
    LUSkillsSelection.SetupSkillsWindow(
        MyChar, LUSkillsSelection.LUSKILLS_TYPE_CHARGEN, SkillWindow,
        RedrawSkills, [0, 0, 0], Levels, 0, False)

    BackButton = SkillWindow.GetControl(25)
    BackButton.SetText(15416)
    BackButton.SetEvent(IE_GUI_BUTTON_ON_PRESS, CharGenCommon.BackPress)

    DoneButton = SkillWindow.GetControl(0)
    DoneButton.SetText(11973)
    DoneButton.SetFlags(IE_GUI_BUTTON_DEFAULT, OP_OR)
    DoneButton.SetEvent(IE_GUI_BUTTON_ON_PRESS, NextPress)
    DoneButton.SetState(IE_GUI_BUTTON_DISABLED)
    GemRB.SetRepeatClickFlags(GEM_RK_DISABLE, OP_NAND)

    RedrawSkills()
    SkillWindow.ShowModal(MODAL_SHADOW_NONE)
    return
Esempio n. 4
0
def OnLoad():
    global SkillWindow, DoneButton, MyChar

    GemRB.LoadWindowPack("GUICG", 640, 480)
    SkillWindow = GemRB.LoadWindow(6)
    MyChar = GemRB.GetVar("Slot")

    Levels = [GemRB.GetPlayerStat (MyChar, IE_LEVEL), \
      GemRB.GetPlayerStat (MyChar, IE_LEVEL2), \
      GemRB.GetPlayerStat (MyChar, IE_LEVEL3)]
    LUSkillsSelection.SetupSkillsWindow (MyChar, \
     LUSkillsSelection.LUSKILLS_TYPE_CHARGEN, SkillWindow, RedrawSkills, [0,0,0], Levels)

    if not GemRB.GetVar("SkillPointsLeft"):  #skipping
        GemRB.SetNextScript("GUICG9")
        return

    BackButton = SkillWindow.GetControl(25)
    BackButton.SetText(15416)
    BackButton.SetFlags(IE_GUI_BUTTON_CANCEL, OP_OR)
    BackButton.SetEvent(IE_GUI_BUTTON_ON_PRESS, BackPress)

    DoneButton = SkillWindow.GetControl(0)
    DoneButton.SetText(11973)
    DoneButton.SetFlags(IE_GUI_BUTTON_DEFAULT, OP_OR)
    DoneButton.SetEvent(IE_GUI_BUTTON_ON_PRESS, NextPress)
    DoneButton.SetState(IE_GUI_BUTTON_DISABLED)
    GemRB.SetRepeatClickFlags(GEM_RK_DISABLE, OP_NAND)

    RedrawSkills()
    SkillWindow.SetVisible(WINDOW_VISIBLE)
    return
Esempio n. 5
0
def DCMainBackPress():
    """Reverts all current changes and reverts back to the previous step."""
    global DCMainStep, DCClass, NewMageSpells
    global NewPriestMask

    if DCMainStep == 2:  # class selected, wait to choose skills
        # disable the skills button and re-enable the class button
        # the class will be reset when the class button is clicked
        DCMainSkillsButton.SetState(IE_GUI_BUTTON_DISABLED)
        DCMainClassButton.SetState(IE_GUI_BUTTON_ENABLED)

        # back a step
        DCMainStep = 1
    elif DCMainStep == 3:  # skills selected
        # re-enable our skills button
        DCMainSkillsButton.SetState(IE_GUI_BUTTON_ENABLED)

        # un-learn our spells and skills
        if NewMageSpells:
            Spellbook.RemoveKnownSpells(pc, IE_SPELL_TYPE_WIZARD, 1, 1, 1)

        LUSkillsSelection.SkillsNullify()
        NewPriestMask = 0
        NewMageSpells = 0

        # go back a step
        DCMainStep = 2
    return
Esempio n. 6
0
def AcceptLevelUp():
	OpenLevelUpWindow()
	#do level up
	pc = GemRB.GameGetSelectedPCSingle ()
	GemRB.SetPlayerStat (pc, IE_SAVEVSDEATH, SavThrows[0])
	GemRB.SetPlayerStat (pc, IE_SAVEVSWANDS, SavThrows[1])
	GemRB.SetPlayerStat (pc, IE_SAVEVSPOLY, SavThrows[2])
	GemRB.SetPlayerStat (pc, IE_SAVEVSBREATH, SavThrows[3])
	GemRB.SetPlayerStat (pc, IE_SAVEVSSPELL, SavThrows[4])
	oldhp = GemRB.GetPlayerStat (pc, IE_MAXHITPOINTS, 1)
	GemRB.SetPlayerStat (pc, IE_MAXHITPOINTS, HPGained+oldhp)
	oldhp = GemRB.GetPlayerStat (pc, IE_HITPOINTS, 1)
	GemRB.SetPlayerStat (pc, IE_HITPOINTS, HPGained+oldhp)
	#increase weapon proficiency if needed
	if WeapProfType!=-1:
		GemRB.SetPlayerStat (pc, WeapProfType, CurrWeapProf + WeapProfGained )
	Specific = GemRB.GetPlayerStat (pc, IE_SPECIFIC)
	if Specific == 1:
		#TODO:
		#the nameless one is dual classed
		#so we have to determine which level to increase
		GemRB.SetPlayerStat (pc, IE_LEVEL, GemRB.GetPlayerStat (pc, IE_LEVEL)+NumOfPrimLevUp)
	else:
		GemRB.SetPlayerStat (pc, IE_LEVEL, GemRB.GetPlayerStat (pc, IE_LEVEL)+NumOfPrimLevUp)
		if avatar_header['SecoLevel'] != 0:
			GemRB.SetPlayerStat (pc, IE_LEVEL2, GemRB.GetPlayerStat (pc, IE_LEVEL2)+NumOfSecoLevUp)
	
	LUSkillsSelection.SkillsSave (pc)
	UpdateRecordsWindow ()
Esempio n. 7
0
def DCSkillsBackPress():
    """Reverts all changes to this points."""

    if DCSkillsWindow:
        DCSkillsWindow.Unload()
    LUSkillsSelection.SkillsNullify()
    DCMainBackPress()
    return
Esempio n. 8
0
def DCSkillsBackPress():
    """Reverts all changes to this points."""

    if DCSkillsWindow:
        DCSkillsWindow.Unload()
    DCMainWindow.ShowModal(MODAL_SHADOW_GRAY)
    LUSkillsSelection.SkillsNullify()
    DCMainBackPress()
    return
Esempio n. 9
0
def AcceptLevelUp():
    #do level up
    pc = GemRB.GameGetSelectedPCSingle()
    GemRB.SetPlayerStat(pc, IE_SAVEVSDEATH, SavThrows[0])
    GemRB.SetPlayerStat(pc, IE_SAVEVSWANDS, SavThrows[1])
    GemRB.SetPlayerStat(pc, IE_SAVEVSPOLY, SavThrows[2])
    GemRB.SetPlayerStat(pc, IE_SAVEVSBREATH, SavThrows[3])
    GemRB.SetPlayerStat(pc, IE_SAVEVSSPELL, SavThrows[4])
    oldhp = GemRB.GetPlayerStat(pc, IE_MAXHITPOINTS, 1)
    GemRB.SetPlayerStat(pc, IE_MAXHITPOINTS, HPGained + oldhp)
    oldhp = GemRB.GetPlayerStat(pc, IE_HITPOINTS, 1)
    GemRB.SetPlayerStat(pc, IE_HITPOINTS, HPGained + oldhp)

    # Weapon Proficiencies
    if WeapProfType != -1:
        # Companion NPC's get points added directly to their chosen weapon
        GemRB.SetPlayerStat(pc, IE_PROFICIENCYBASTARDSWORD + WeapProfType,
                            CurrWeapProf + WeapProfGained)
    else:
        # TNO has points added to the "Unused Slots" dummy proficiency
        freeSlots = GemRB.GetPlayerStat(pc, IE_FREESLOTS)
        GemRB.SetPlayerStat(pc, IE_FREESLOTS, freeSlots + WeapProfGained)

    SwitcherClass = GUICommon.NamelessOneClass(pc)
    if SwitcherClass:
        # Handle saving of TNO class level in the correct CRE stat
        Levels = {
            "FIGHTER": GemRB.GetPlayerStat(pc, IE_LEVEL),
            "MAGE": GemRB.GetPlayerStat(pc, IE_LEVEL2),
            "THIEF": GemRB.GetPlayerStat(pc, IE_LEVEL3)
        }
        LevelStats = {
            "FIGHTER": IE_LEVEL,
            "MAGE": IE_LEVEL2,
            "THIEF": IE_LEVEL3
        }
        GemRB.SetPlayerStat(pc, LevelStats[SwitcherClass],
                            Levels[SwitcherClass] + NumOfPrimLevUp)
    else:
        GemRB.SetPlayerStat(pc, IE_LEVEL,
                            GemRB.GetPlayerStat(pc, IE_LEVEL) + NumOfPrimLevUp)
        if avatar_header['SecoLevel'] != 0:
            GemRB.SetPlayerStat(
                pc, IE_LEVEL2,
                GemRB.GetPlayerStat(pc, IE_LEVEL2) + NumOfSecoLevUp)

    LUSkillsSelection.SkillsSave(pc)

    # Spells
    LevelUp.pc = pc
    LevelUp.Classes = Classes
    LevelUp.NumClasses = NumClasses
    # (we need to override the globals this function uses there since they wouldn't have been set)
    LevelUp.SaveNewSpells()

    LevelUpWindow.Close()
    NewLife.OpenLUStatsWindow(True, sum(LevelDiff))
Esempio n. 10
0
def NextPress():
    if SkillWindow:
        SkillWindow.Unload()
    # save all skills

    LUSkillsSelection.SkillsSave(MyChar)

    GemRB.SetNextScript("GUICG9")  #weapon proficiencies
    return
Esempio n. 11
0
def NextPress():
    if SkillWindow:
        SkillWindow.Unload()
    # save all skills

    LUSkillsSelection.SkillsSave(MyChar)

    GemRB.SetRepeatClickFlags(GEM_RK_DISABLE, OP_OR)
    GemRB.SetNextScript("GUICG9")  #weapon proficiencies
    return
Esempio n. 12
0
def OpenSkillsWindow():
    """Opens the skills selection window.

	This will allow the selection of thief skills for appropriate classes, or
	auto-assign them for classes that recieve skills based on level."""

    global DCSkillsWindow, DCSkillsDoneButton

    DCSkillsWindow = GemRB.LoadWindow(7)
    if GameCheck.IsBG2():
        LUSkillsSelection.SetupSkillsWindow (pc, \
         LUSkillsSelection.LUSKILLS_TYPE_DUALCLASS, DCSkillsWindow, DCSkillsRedraw, classid=NewClassId)
    else:
        LUSkillsSelection.SetupSkillsWindow (pc, \
         LUSkillsSelection.LUSKILLS_TYPE_DUALCLASS, DCSkillsWindow, \
         DCSkillsRedraw, [0,0,0], [1,1,1], NewClassId, False)

    #just go back if we can't assign skills
    if GemRB.GetVar("SkillPointsLeft") <= 0:
        DCSkillsWindow.Close()
        return

    # setup the back and done buttons
    BackButton = DCSkillsWindow.GetControl(24)
    BackButton.SetText(15416)
    BackButton.MakeEscape()
    BackButton.SetEvent(IE_GUI_BUTTON_ON_PRESS, DCSkillsBackPress)

    DCSkillsDoneButton = DCSkillsWindow.GetControl(25)
    DCSkillsDoneButton.SetText(11973)
    DCSkillsDoneButton.MakeDefault()
    DCSkillsDoneButton.SetEvent(IE_GUI_BUTTON_ON_PRESS, DCSkillsDonePress)
    DCSkillsDoneButton.SetState(IE_GUI_BUTTON_DISABLED)

    # setup the default text area
    TextArea = DCSkillsWindow.GetControl(22)
    TextArea.SetText(17248)

    DCSkillsWindow.ShowModal(MODAL_SHADOW_GRAY)
    DCSkillsRedraw()
    return
Esempio n. 13
0
def LevelUpDonePress():
    """Updates the PC with the new choices.

	Closes the window when finished."""
    import GUICommonWindows
    import GUIREC

    # 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])

    # spells
    SaveNewSpells()

    # 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.Close()
    GUICommonWindows.UpdatePortraitWindow()
    return
Esempio n. 14
0
def OnLoad():
	MyChar = GemRB.GetVar ("Slot")

	# nullify our thieving skills
	LUSkillsSelection.SkillsNullify ()
	LUSkillsSelection.SkillsSave (MyChar)

	# nullify our proficiencies
	LUProfsSelection.ProfsNullify ()

	# nully other variables
	GemRB.SetVar ("HatedRace", 0)

	# save our previous stats:
	# 	abilities
	AbilityTable = GemRB.LoadTable ("ability")
	AbilityCount = AbilityTable.GetRowCount ()

	# print our diagnostic as we loop (so as not to duplicate)
	print "CharGen6 output:"

	#remove all known spells and nullify the memorizable counts
	Spellbook.RemoveKnownSpells (MyChar, IE_SPELL_TYPE_WIZARD, 1,9, 1)
	Spellbook.RemoveKnownSpells (MyChar, IE_SPELL_TYPE_PRIEST, 1,7, 1)

	# learn divine spells if appropriate
	ClassName = GUICommon.GetClassRowName (MyChar)
	TableName = CommonTables.ClassSkills.GetValue (ClassName, "CLERICSPELL", 0) # cleric spells

	if TableName == "*": # only druid spells or no spells at all
		TableName = CommonTables.ClassSkills.GetValue (ClassName, "DRUIDSPELL", 0)
		ClassFlag = 0x8000
	elif CommonTables.ClassSkills.GetValue (ClassName, "DRUIDSPELL", 0) != "*": # cleric and druid spells
		ClassFlag = 0
	else: # only cleric spells
		ClassFlag = 0x4000

	if TableName != "*":
		#figure out which class casts spells and use the level of the class
		#to setup the priest spells
		Levels = [GemRB.GetPlayerStat (MyChar, IE_LEVEL), \
				GemRB.GetPlayerStat (MyChar, IE_LEVEL2), \
				GemRB.GetPlayerStat (MyChar, IE_LEVEL3)]
		index = 0
		IsMulti = GUICommon.IsMultiClassed (MyChar, 1)
		if IsMulti[0]>1:
			#loop through each multiclass until we come across the class that gives
			#divine spells; because clerics have a lower id than rangers, they should
			#be looked at first in Cleric/Ranger multi's, which is correct
			foundindex = 0
			for i in range (IsMulti[0]):
				ClassName = GUICommon.GetClassRowName (IsMulti[i+1], "class")
				for table in "CLERICSPELL", "DRUIDSPELL":
					if CommonTables.ClassSkills.GetValue (ClassName, table) != "*":
						index = i
						foundindex = 1
						break
				if foundindex:
					break

		#set our memorizable counts
		Spellbook.SetupSpellLevels (MyChar, TableName, IE_SPELL_TYPE_PRIEST, Levels[index])

		#learn all our priest spells up to the level we can learn
		for level in range (8):
			if GemRB.GetMemorizableSpellsCount (MyChar, IE_SPELL_TYPE_PRIEST, level, 0) <= 0:
				Spellbook.LearnPriestSpells (MyChar, level, ClassFlag)
				break
	CharGenCommon.DisplayOverview (6)
	return
Esempio n. 15
0
def OpenLevelUpWindow ():
	global LevelUpWindow
	global SavThrows
	global HPGained
	global WeapProfType, CurrWeapProf, WeapProfGained
	global NumOfPrimLevUp, NumOfSecoLevUp

	GemRB.HideGUI ()

	if LevelUpWindow != None:
		if LevelUpWindow:
			LevelUpWindow.Unload ()
		LevelUpWindow = None
		GemRB.SetVar ("FloatWindow", -1)

		GemRB.UnhideGUI()
		return

	GemRB.LoadWindowPack ("GUIREC") # since we get called from NewLife
	LevelUpWindow = Window = GemRB.LoadWindow (4)
	GemRB.SetVar ("FloatWindow", LevelUpWindow.ID)

	# Accept
	Button = Window.GetControl (0)
	Button.SetText (4192)
	Button.SetEvent (IE_GUI_BUTTON_ON_PRESS, AcceptLevelUp)

	pc = GemRB.GameGetSelectedPCSingle ()

	# These are used to identify Nameless One
	BioTable = GemRB.LoadTable ("bios")
	Specific = GemRB.GetPlayerStat (pc, IE_SPECIFIC)
	AvatarName = BioTable.GetRowName (Specific+1)

	# These will be used for saving throws
	SavThrUpdated = False
	SavThrows = [0,0,0,0,0]
	SavThrows[0] = GemRB.GetPlayerStat (pc, IE_SAVEVSDEATH)
	SavThrows[1] = GemRB.GetPlayerStat (pc, IE_SAVEVSWANDS)
	SavThrows[2] = GemRB.GetPlayerStat (pc, IE_SAVEVSPOLY)
	SavThrows[3] = GemRB.GetPlayerStat (pc, IE_SAVEVSBREATH)
	SavThrows[4] = GemRB.GetPlayerStat (pc, IE_SAVEVSSPELL)

	HPGained = 0
	ConHPBon = 0
	Thac0Updated = False
	Thac0 = 0
	WeapProfGained = 0

	ClasWeapTable = GemRB.LoadTable ("weapprof")
	WeapProfType = -1
	CurrWeapProf = -1
	#This does not apply to Nameless since he uses unused slots system
	#Nameless is Specific == 1
	if Specific != "1":
		# Searching for the column name where value is 1
		for i in range (5):
			WeapProfName = ClasWeapTable.GetRowName (i)
			value = ClasWeapTable.GetValue (WeapProfName, AvatarName)
			if value == 1:
				WeapProfType = i
				break

	if WeapProfType!=-1:
		CurrWeapProf = GemRB.GetPlayerStat (pc, IE_PROFICIENCYBASTARDSWORD + WeapProfType)

	# Recording this avatar's current proficiency level
	# Since Nameless one is not covered, hammer and club can't occur
	# What is the avatar's class (Which we can use to lookup XP)
	Class = GUICommon.GetClassRowName (pc)

	# name
	Label = Window.GetControl (0x10000000)
	Label.SetText (GemRB.GetPlayerName (pc, 1))

	# class
	Label = Window.GetControl (0x10000001)
	Label.SetText (CommonTables.Classes.GetValue (Class, "NAME_REF"))

	# Armor Class
	Label = Window.GetControl (0x10000023)
	Label.SetText (str (GemRB.GetPlayerStat (pc, IE_ARMORCLASS)))

	# Thief Skills
	# For now we shall set them to the current levels and disable the increment buttons
	# Points Left
	Label = Window.GetControl (0x10000006)
	Label.SetText ('0')
	# Stealth
	Label = Window.GetControl (0x10000008)
	Label.SetText (str (GemRB.GetPlayerStat (pc, IE_STEALTH)) + '%')
	# Detect Traps
	Label = Window.GetControl (0x1000000A)
	Label.SetText (str (GemRB.GetPlayerStat (pc, IE_TRAPS)) + '%')
	# Pick Pockets
	Label = Window.GetControl (0x1000000C)
	Label.SetText (str (GemRB.GetPlayerStat (pc, IE_PICKPOCKET)) + '%')
	# Open Doors
	Label = Window.GetControl (0x1000000E)
	Label.SetText (str (GemRB.GetPlayerStat (pc, IE_LOCKPICKING)) + '%')
	# Plus and Minus buttons
	LUSkillsSelection.SetupSkillsWindow (pc, LUSkillsSelection.LUSKILLS_TYPE_LEVELUP, LevelUpWindow, RedrawSkills, [0,0,0], [1,1,1], 0, False)
	RedrawSkills()

	# Is avatar multi-class?
	if avatar_header['SecoLevel'] == 0:
		# avatar is single class
		# What will be avatar's next level?
		NextLevel = avatar_header['PrimLevel'] + 1
		while avatar_header['XP'] >= GetNextLevelExp (NextLevel, Class):
			NextLevel = NextLevel + 1
		NumOfPrimLevUp = NextLevel - avatar_header['PrimLevel'] # How many levels did we go up?

		# Is avatar Nameless One?
		if Specific == "1":
			# Saving Throws
			# Nameless One gets the best possible throws from all the classes except Priest
			FigSavThrTable = GemRB.LoadTable ("SAVEWAR")
			MagSavThrTable = GemRB.LoadTable ("SAVEWIZ")
			ThiSavThrTable = GemRB.LoadTable ("SAVEROG")
			# For Nameless, we also need to know his levels in every class, so that we pick
			# the right values from the corresponding tables. Also we substract one, so
			# that we may use them as column indices in tables.
			FighterLevel = GemRB.GetPlayerStat (pc, IE_LEVEL) - 1
			MageLevel = GemRB.GetPlayerStat (pc, IE_LEVEL2) - 1
			ThiefLevel = GemRB.GetPlayerStat (pc, IE_LEVEL3) - 1
			# this is the constitution bonus type for this level
			CONType = 1
			# We are leveling up one of those levels. Therefore, one of them has to be updated.
			if avatar_header['PrimClass'] == "FIGHTER":
				FighterLevel = NextLevel - 1
				CONType = 0
			elif avatar_header['PrimClass'] == "MAGE":
				MageLevel = NextLevel - 1
			else:
				ThiefLevel = NextLevel - 1

			ConHPBon = GetConHPBonus (pc, NumOfPrimLevUp, 0, CONType)
			# Now we need to update the saving throws with the best values from those tables.
			# The smaller the number, the better saving throw it is.
			# We also need to check if any of the levels are larger than 21, since
			# after that point the table runs out, and the throws remain the
			# same
			if FighterLevel < 21:
				for i in range (5):
					Throw = FigSavThrTable.GetValue (i, FighterLevel)
					if Throw < SavThrows[i]:
						SavThrows[i] = Throw
						SavThrUpdated = True
			if MageLevel < 21:
				for i in range (5):
					Throw = MagSavThrTable.GetValue (i, MageLevel)
					if Throw < SavThrows[i]:
						SavThrows[i] = Throw
						SavThrUpdated = True
			if ThiefLevel < 21:
				for i in range (5):
					Throw = ThiSavThrTable.GetValue (i, ThiefLevel)
					if Throw < SavThrows[i]:
						SavThrows[i] = Throw
						SavThrUpdated = True
			# Cleaning up
		else:
			#How many weapon procifiencies we get
			for i in range (NumOfPrimLevUp):
				if HasGainedWeapProf (pc, CurrWeapProf + WeapProfGained, avatar_header['PrimLevel'] + i, avatar_header['PrimClass']):
					WeapProfGained += 1

			# Saving Throws
			# Loading the right saving throw table
			SavThrTable = GemRB.LoadTable (CommonTables.Classes.GetValue (Class, "SAVE"))
			# Updating the current saving throws. They are changed only if the
			# new ones are better than current. The smaller the number, the better.
			# We need to substract one from the NextLevel, so that we get right values.
			# We also need to check if NextLevel is larger than 21, since after that point
			# the table runs out, and the throws remain the same 
			if NextLevel < 22:
				for i in range (5):
					Throw = SavThrTable.GetValue (i, NextLevel-1)
					if Throw < SavThrows[i]:
						SavThrows[i] = Throw
						SavThrUpdated = True
			# Cleaning Up

			# Hit Points Gained and Hit Points from Constitution Bonus
			for i in range (NumOfPrimLevUp):
				HPGained = HPGained + GetSingleClassHP (Class, avatar_header['PrimLevel'])

			if avatar_header['PrimClass'] == "FIGHTER":
				CONType = 0
			else:
				CONType = 1
			ConHPBon = GetConHPBonus (pc, NumOfPrimLevUp, 0, CONType)

			# Thac0
			Thac0 = GetThac0 (Class, NextLevel)
			# Is the new thac0 better than old? (The smaller, the better)
			if Thac0 < GemRB.GetPlayerStat (pc, IE_TOHIT, 1):
				Thac0Updated = True

	else:
		# avatar is multi class
		# we have only fighter/X multiclasses, so this
		# part is a bit hardcoded
		PrimNextLevel = 0
		SecoNextLevel = 0
		NumOfPrimLevUp = 0
		NumOfSecoLevUp = 0

		# What will be avatar's next levels?
		PrimNextLevel = avatar_header['PrimLevel']
		while avatar_header['XP'] >= GetNextLevelExp (PrimNextLevel, "FIGHTER"):
			PrimNextLevel = PrimNextLevel + 1
		# How many primary levels did we go up?
		NumOfPrimLevUp = PrimNextLevel - avatar_header['PrimLevel']

		for i in range (NumOfPrimLevUp):
			if HasGainedWeapProf (pc, CurrWeapProf + WeapProfGained, avatar_header['PrimLevel'] + i, avatar_header['PrimClass']):
				WeapProfGained += 1

		# Saving Throws
		FigSavThrTable = GemRB.LoadTable ("SAVEWAR")
		if PrimNextLevel < 22:
			for i in range (5):
				Throw = FigSavThrTable.GetValue (i, PrimNextLevel - 1)
				if Throw < SavThrows[i]:
					SavThrows[i] = Throw
					SavThrUpdated = True
		# Which multi class is it?
		if GemRB.GetPlayerStat (pc, IE_CLASS) == 7:
			# avatar is Fighter/Mage (Dak'kon)
			Class = "MAGE"
			SavThrTable = GemRB.LoadTable ("SAVEWIZ")
		else:
			# avatar is Fighter/Thief (Annah)
			Class = "THIEF"
			SavThrTable = GemRB.LoadTable ("SAVEROG")
		
		SecoNextLevel = avatar_header['SecoLevel']
		while avatar_header['XP'] >= GetNextLevelExp (SecoNextLevel, Class):
			SecoNextLevel = SecoNextLevel + 1
		# How many secondary levels did we go up?
		NumOfSecoLevUp = SecoNextLevel - avatar_header['SecoLevel']
		if SecoNextLevel < 22:
			for i in range (5):
				Throw = SavThrTable.GetValue (i, SecoNextLevel - 1)
				if Throw < SavThrows[i]:
					SavThrows[i] = Throw
					SavThrUpdated = True

		# Hit Points Gained and Hit Points from Constitution Bonus (multiclass)
		for i in range (NumOfPrimLevUp):
			HPGained = HPGained + GetSingleClassHP ("FIGHTER", avatar_header['PrimLevel'])/2

		for i in range (NumOfSecoLevUp):
			HPGained = HPGained + GetSingleClassHP (Class, avatar_header['SecoLevel'])/2
		ConHPBon = GetConHPBonus (pc, NumOfPrimLevUp, NumOfSecoLevUp, 2)

		# Thac0
		# Multi class use the primary class level to determine Thac0
		Thac0 = GetThac0 (Class, PrimNextLevel)
		# Is the new thac0 better than old? (The smaller the better)
		if Thac0 < GemRB.GetPlayerStat (pc, IE_TOHIT, 1):
			Thac0Updated = True


	# Displaying the saving throws
	# Death
	Label = Window.GetControl (0x10000019)
	Label.SetText (str (SavThrows[0]))
	# Wand
	Label = Window.GetControl (0x1000001B)
	Label.SetText (str (SavThrows[1]))
	# Polymorph
	Label = Window.GetControl (0x1000001D)
	Label.SetText (str (SavThrows[2]))
	# Breath
	Label = Window.GetControl (0x1000001F)
	Label.SetText (str (SavThrows[3]))
	# Spell
	Label = Window.GetControl (0x10000021)
	Label.SetText (str (SavThrows[4]))

	FinalCurHP = GemRB.GetPlayerStat (pc, IE_HITPOINTS) + HPGained
	FinalMaxHP = GemRB.GetPlayerStat (pc, IE_MAXHITPOINTS) + HPGained

	# Current HP
	Label = Window.GetControl (0x10000025)
	Label.SetText (str (FinalCurHP))

	# Max HP
	Label = Window.GetControl (0x10000027)
	Label.SetText (str (FinalMaxHP))

	# Displaying level up info
	overview = ""
	if CurrWeapProf!=-1 and WeapProfGained>0:
		overview = overview + GemRB.GetString (38715) + '\n' + '+' + str (WeapProfGained) + '\n'

	overview = overview + str (HPGained) + " " + GemRB.GetString (38713) + '\n'
	overview = overview + str (ConHPBon) + " " + GemRB.GetString (38727) + '\n'

	if SavThrUpdated:
		overview = overview + GemRB.GetString (38719) + '\n'
	if Thac0Updated:
		GemRB.SetPlayerStat (pc, IE_TOHIT, Thac0)
		overview = overview + GemRB.GetString (38718) + '\n'

	Text = Window.GetControl (3)
	Text.SetText (overview)

	GemRB.UnhideGUI ()
	Window.ShowModal (MODAL_SHADOW_GRAY)
Esempio n. 16
0
def OpenLevelUpWindow():
    global LevelUpWindow
    global SavThrows
    global HPGained
    global WeapProfType, CurrWeapProf, WeapProfGained
    global NumOfPrimLevUp, NumOfSecoLevUp

    global LevelDiff, Level, Classes, NumClasses

    LevelUpWindow = Window = GemRB.LoadWindow(
        4, "GUIREC")  # since we get called from NewLife

    # Accept
    Button = Window.GetControl(0)
    Button.SetText(4192)
    Button.SetEvent(IE_GUI_BUTTON_ON_PRESS, AcceptLevelUp)

    pc = GemRB.GameGetSelectedPCSingle()

    # These are used to identify Nameless One
    BioTable = GemRB.LoadTable("bios")
    Specific = GemRB.GetPlayerStat(pc, IE_SPECIFIC)
    AvatarName = BioTable.GetRowName(Specific)

    # These will be used for saving throws
    SavThrUpdated = False
    SavThrows = [0, 0, 0, 0, 0]
    SavThrows[0] = GemRB.GetPlayerStat(pc, IE_SAVEVSDEATH)
    SavThrows[1] = GemRB.GetPlayerStat(pc, IE_SAVEVSWANDS)
    SavThrows[2] = GemRB.GetPlayerStat(pc, IE_SAVEVSPOLY)
    SavThrows[3] = GemRB.GetPlayerStat(pc, IE_SAVEVSBREATH)
    SavThrows[4] = GemRB.GetPlayerStat(pc, IE_SAVEVSSPELL)

    HPGained = 0
    ConHPBon = 0
    Thac0Updated = False
    Thac0 = 0
    WeapProfGained = 0

    WeapProfType = -1
    CurrWeapProf = 0

    # Count the number of existing weapon procifiencies
    if GUICommon.IsNamelessOne(pc):
        # TNO: Count the total amount of unassigned proficiencies
        CurrWeapProf = GemRB.GetPlayerStat(pc, IE_FREESLOTS)
    else:
        # Scan the weapprof table for the characters favoured weapon proficiency (WeapProfType)
        # This does not apply to Nameless since he uses unused slots system
        for i in range(6):
            WeapProfName = CommonTables.WeapProfs.GetRowName(i)
            value = CommonTables.WeapProfs.GetValue(WeapProfName, AvatarName)
            if value == 1:
                WeapProfType = i
                break

    for i in range(6):
        CurrWeapProf += GemRB.GetPlayerStat(pc, IE_PROFICIENCYBASTARDSWORD + i)

    # What is the avatar's class (Which we can use to lookup XP)
    Class = GUICommon.GetClassRowName(pc)

    # name
    Label = Window.GetControl(0x10000000)
    Label.SetText(GemRB.GetPlayerName(pc, 1))

    # class
    Label = Window.GetControl(0x10000001)
    Label.SetText(CommonTables.Classes.GetValue(Class, "NAME_REF"))

    # Armor Class
    Label = Window.GetControl(0x10000023)
    Label.SetText(str(GemRB.GetPlayerStat(pc, IE_ARMORCLASS)))

    # 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

    if not IsMulti:
        NumClasses = 1
        Classes = [GemRB.GetPlayerStat(pc, IE_CLASS)]

    if GUICommon.IsNamelessOne(pc):
        # Override the multiclass info for TNO
        IsMulti = 1
        NumClasses = 3
        # Fighter, Mage, Thief ID
        Classes = [2, 1, 4]

    Level = LUCommon.GetNextLevels(pc, Classes)
    LevelDiff = LUCommon.GetLevelDiff(pc, Level)

    # calculate the new spells (results are stored in global variables in LevelUp)
    LevelUp.GetNewSpells(pc, Classes, Level, LevelDiff)

    # Thief Skills
    Level1 = []
    for i in range(len(Level)):
        Level1.append(Level[i] - LevelDiff[i])
    LUSkillsSelection.SetupSkillsWindow(
        pc, LUSkillsSelection.LUSKILLS_TYPE_LEVELUP, LevelUpWindow,
        RedrawSkills, Level1, Level, 0, False)
    RedrawSkills()

    # Is avatar multi-class?
    if avatar_header['SecoLevel'] == 0:
        # avatar is single class
        # What will be avatar's next level?
        NextLevel = avatar_header['PrimLevel'] + 1
        while avatar_header['XP'] >= GetNextLevelExp(NextLevel, Class):
            NextLevel = NextLevel + 1
        NumOfPrimLevUp = NextLevel - avatar_header[
            'PrimLevel']  # How many levels did we go up?

        #How many weapon procifiencies we get
        for i in range(NumOfPrimLevUp):
            WeapProfGained += GainedWeapProfs(pc,
                                              CurrWeapProf + WeapProfGained,
                                              avatar_header['PrimLevel'] + i,
                                              AvatarName)

        # Hit Points Gained and Hit Points from Constitution Bonus
        for i in range(NumOfPrimLevUp):
            HPGained = HPGained + GetSingleClassHP(Class,
                                                   avatar_header['PrimLevel'])
        if Class == "FIGHTER":
            CONType = 0
        else:
            CONType = 1
        ConHPBon = GetConHPBonus(pc, NumOfPrimLevUp, 0, CONType)

        # Thac0
        Thac0 = GetThac0(Class, NextLevel)
        # Is the new thac0 better than old? (The smaller, the better)
        if Thac0 < GemRB.GetPlayerStat(pc, IE_TOHIT, 1):
            Thac0Updated = True

        # Saving Throws
        if GUICommon.IsNamelessOne(pc):
            # Nameless One always uses the best possible save from each class
            FigSavThrTable = GemRB.LoadTable("SAVEWAR")
            MagSavThrTable = GemRB.LoadTable("SAVEWIZ")
            ThiSavThrTable = GemRB.LoadTable("SAVEROG")

            FighterLevel = GemRB.GetPlayerStat(pc, IE_LEVEL) - 1
            MageLevel = GemRB.GetPlayerStat(pc, IE_LEVEL2) - 1
            ThiefLevel = GemRB.GetPlayerStat(pc, IE_LEVEL3) - 1

            # We are leveling up one of those levels. Therefore, one of them has to be updated.
            if Class == "FIGHTER":
                FighterLevel = NextLevel - 1
            elif Class == "MAGE":
                MageLevel = NextLevel - 1
            else:
                ThiefLevel = NextLevel - 1

            # Now we need to update the saving throws with the best values from those tables.
            # The smaller the number, the better saving throw it is.
            # We also need to check if any of the levels are larger than 21, since
            # after that point the table runs out, and the throws remain the
            # same
            if FighterLevel < 21:
                for i in range(5):
                    Throw = FigSavThrTable.GetValue(i, FighterLevel)
                    if Throw < SavThrows[i]:
                        SavThrows[i] = Throw
                        SavThrUpdated = True
            if MageLevel < 21:
                for i in range(5):
                    Throw = MagSavThrTable.GetValue(i, MageLevel)
                    if Throw < SavThrows[i]:
                        SavThrows[i] = Throw
                        SavThrUpdated = True
            if ThiefLevel < 21:
                for i in range(5):
                    Throw = ThiSavThrTable.GetValue(i, ThiefLevel)
                    if Throw < SavThrows[i]:
                        SavThrows[i] = Throw
                        SavThrUpdated = True
        else:
            SavThrTable = GemRB.LoadTable(
                CommonTables.Classes.GetValue(Class, "SAVE"))
            # Updating the current saving throws. They are changed only if the
            # new ones are better than current. The smaller the number, the better.
            # We need to substract one from the NextLevel, so that we get right values.
            # We also need to check if NextLevel is larger than 21, since after that point
            # the table runs out, and the throws remain the same
            if NextLevel < 22:
                for i in range(5):
                    Throw = SavThrTable.GetValue(i, NextLevel - 1)
                    if Throw < SavThrows[i]:
                        SavThrows[i] = Throw
                        SavThrUpdated = True

    else:
        # avatar is multi class
        # we have only fighter/X multiclasses, so this
        # part is a bit hardcoded
        PrimNextLevel = 0
        SecoNextLevel = 0
        NumOfPrimLevUp = 0
        NumOfSecoLevUp = 0

        # What will be avatar's next levels?
        PrimNextLevel = avatar_header['PrimLevel']
        while avatar_header['XP'] >= GetNextLevelExp(PrimNextLevel, "FIGHTER"):
            PrimNextLevel = PrimNextLevel + 1
        # How many primary levels did we go up?
        NumOfPrimLevUp = PrimNextLevel - avatar_header['PrimLevel']

        for i in range(NumOfPrimLevUp):
            WeapProfGained += GainedWeapProfs(pc,
                                              CurrWeapProf + WeapProfGained,
                                              avatar_header['PrimLevel'] + i,
                                              AvatarName)

        # Saving Throws
        FigSavThrTable = GemRB.LoadTable("SAVEWAR")
        if PrimNextLevel < 22:
            for i in range(5):
                Throw = FigSavThrTable.GetValue(i, PrimNextLevel - 1)
                if Throw < SavThrows[i]:
                    SavThrows[i] = Throw
                    SavThrUpdated = True
        # Which multi class is it?
        if GemRB.GetPlayerStat(pc, IE_CLASS) == 7:
            # avatar is Fighter/Mage (Dak'kon)
            Class = "MAGE"
            SavThrTable = GemRB.LoadTable("SAVEWIZ")
        else:
            # avatar is Fighter/Thief (Annah)
            Class = "THIEF"
            SavThrTable = GemRB.LoadTable("SAVEROG")

        SecoNextLevel = avatar_header['SecoLevel']
        while avatar_header['XP'] >= GetNextLevelExp(SecoNextLevel, Class):
            SecoNextLevel = SecoNextLevel + 1
        # How many secondary levels did we go up?
        NumOfSecoLevUp = SecoNextLevel - avatar_header['SecoLevel']
        if SecoNextLevel < 22:
            for i in range(5):
                Throw = SavThrTable.GetValue(i, SecoNextLevel - 1)
                if Throw < SavThrows[i]:
                    SavThrows[i] = Throw
                    SavThrUpdated = True

        # Hit Points Gained and Hit Points from Constitution Bonus (multiclass)
        for i in range(NumOfPrimLevUp):
            HPGained = HPGained + GetSingleClassHP(
                "FIGHTER", avatar_header['PrimLevel']) / 2

        for i in range(NumOfSecoLevUp):
            HPGained = HPGained + GetSingleClassHP(
                Class, avatar_header['SecoLevel']) / 2
        ConHPBon = GetConHPBonus(pc, NumOfPrimLevUp, NumOfSecoLevUp, 2)

        # Thac0
        # Multi class use the primary class level to determine Thac0
        Thac0 = GetThac0(Class, PrimNextLevel)
        # Is the new thac0 better than old? (The smaller the better)
        if Thac0 < GemRB.GetPlayerStat(pc, IE_TOHIT, 1):
            Thac0Updated = True

    # Displaying the saving throws
    # Death
    Label = Window.GetControl(0x10000019)
    Label.SetText(str(SavThrows[0]))
    # Wand
    Label = Window.GetControl(0x1000001B)
    Label.SetText(str(SavThrows[1]))
    # Polymorph
    Label = Window.GetControl(0x1000001D)
    Label.SetText(str(SavThrows[2]))
    # Breath
    Label = Window.GetControl(0x1000001F)
    Label.SetText(str(SavThrows[3]))
    # Spell
    Label = Window.GetControl(0x10000021)
    Label.SetText(str(SavThrows[4]))

    FinalCurHP = GemRB.GetPlayerStat(pc, IE_HITPOINTS) + HPGained
    FinalMaxHP = GemRB.GetPlayerStat(pc, IE_MAXHITPOINTS) + HPGained

    # Current HP
    Label = Window.GetControl(0x10000025)
    Label.SetText(str(FinalCurHP))

    # Max HP
    Label = Window.GetControl(0x10000027)
    Label.SetText(str(FinalMaxHP))

    # Displaying level up info
    overview = ""
    if CurrWeapProf != -1 and WeapProfGained > 0:
        overview = overview + GemRB.GetString(38715) + '\n' + '+' + str(
            WeapProfGained) + '\n'

    overview = overview + str(HPGained) + " " + GemRB.GetString(38713) + '\n'
    overview = overview + str(ConHPBon) + " " + GemRB.GetString(38727) + '\n'

    if SavThrUpdated:
        overview = overview + GemRB.GetString(38719) + '\n'
    if Thac0Updated:
        GemRB.SetPlayerStat(pc, IE_TOHIT, Thac0)
        overview = overview + GemRB.GetString(38718) + '\n'

    Text = Window.GetControl(3)
    Text.SetText(overview)

    Window.ShowModal(MODAL_SHADOW_GRAY)
Esempio n. 17
0
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()
    return
Esempio n. 18
0
def NextPress():
	SkillWindow.Close()
	MyChar = GemRB.GetVar ("Slot")
	LUSkillsSelection.SkillsSave(MyChar)
	CharGenCommon.next()
Esempio n. 19
0
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])
Esempio n. 20
0
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
Esempio n. 21
0
def NextPress():
    MyChar = GemRB.GetVar("Slot")
    LUSkillsSelection.SkillsSave(MyChar)
    GemRB.SetRepeatClickFlags(GEM_RK_DISABLE, OP_OR)
    CharGenCommon.next()
Esempio n. 22
0
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
Esempio n. 23
0
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
Esempio n. 24
0
def unsetSkill():
    import LUSkillsSelection
    MyChar = GemRB.GetVar("Slot")
    LUSkillsSelection.SkillsNullify()
    LUSkillsSelection.SkillsSave(MyChar)
Esempio n. 25
0
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])