コード例 #1
0
ファイル: Spells.py プロジェクト: jdm/gemrb
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 ()
コード例 #2
0
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)
コード例 #3
0
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
コード例 #4
0
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