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)
Beispiel #2
0
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)