iwd: more gcw syncing with bg2 - actonpc and dragging
[gemrb.git] / gemrb / GUIScripts / bg2 / CharGenEnd.py
blob8bdff6bb4f679dd25f8d895e5a0cf90e6505f29f
1 # -*-python-*-
2 # GemRB - Infinity Engine Emulator
3 # Copyright (C) 2003-2004 The GemRB Project
5 # This program is free software; you can redistribute it and/or
6 # modify it under the terms of the GNU General Public License
7 # as published by the Free Software Foundation; either version 2
8 # of the License, or (at your option) any later version.
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
15 # You should have received a copy of the GNU General Public License
16 # along with this program; if not, write to the Free Software
17 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19 # character generation end
20 import GemRB
21 import GUICommon
22 import LUCommon
23 from ie_stats import *
24 from ie_slots import *
25 from ie_spells import *
27 def OnLoad():
28 # Lay on hands, turn undead and backstab multiplier get set by the core
29 # set my character up
30 MyChar = GemRB.GetVar ("Slot")
31 Class = GemRB.GetPlayerStat (MyChar, IE_CLASS)
32 ClassIndex = GUICommon.ClassTable.FindValue (5, Class)
33 ClassName = GUICommon.ClassTable.GetRowName (ClassIndex)
34 IsMulti = GUICommon.IsMultiClassed (MyChar, 1)
35 Levels = [GemRB.GetPlayerStat (MyChar, IE_LEVEL), GemRB.GetPlayerStat (MyChar, IE_LEVEL2), \
36 GemRB.GetPlayerStat (MyChar, IE_LEVEL3)]
38 # weapon proficiencies
39 # set the base number of attacks; effects will add the proficiency bonus
40 # 2 means 1 attack, because this is the number of attacks in 2 rounds
41 GemRB.SetPlayerStat (MyChar, IE_NUMBEROFATTACKS, 2)
43 #lore, thac0, hp, and saves
44 GemRB.SetPlayerStat (MyChar, IE_MAXHITPOINTS, 0)
45 GemRB.SetPlayerStat (MyChar, IE_HITPOINTS, 0)
46 LUCommon.SetupSavingThrows (MyChar)
47 LUCommon.SetupThaco (MyChar)
48 LUCommon.SetupLore (MyChar)
49 LUCommon.SetupHP (MyChar)
51 # mage spells
52 TableName = GUICommon.ClassSkillsTable.GetValue (Class, 2, 0)
53 if TableName != "*":
54 index = 0
55 if IsMulti[0]>1:
56 #find out which class gets mage spells
57 for i in range (IsMulti[0]):
58 if GUICommon.ClassSkillsTable.GetValue (IsMulti[i+1], 2, 0) != "*":
59 index = i
60 break
61 GUICommon.SetupSpellLevels(MyChar, TableName, IE_SPELL_TYPE_WIZARD, Levels[index])
63 # apply class/kit abilities
64 KitIndex = GUICommon.GetKitIndex (MyChar)
65 if IsMulti[0]>1:
66 #get the class abilites for each class
67 for i in range (IsMulti[0]):
68 TmpClassName = GUICommon.ClassTable.GetRowName (GUICommon.ClassTable.FindValue (5, IsMulti[i+1]) )
69 ABTable = GUICommon.ClassSkillsTable.GetValue (TmpClassName, "ABILITIES")
70 if ABTable != "*" and ABTable[:6] != "CLABMA":
71 GUICommon.AddClassAbilities (MyChar, ABTable, Levels[i], Levels[i])
72 else:
73 if KitIndex:
74 ABTable = GUICommon.KitListTable.GetValue (str(KitIndex), "ABILITIES")
75 else:
76 ABTable = GUICommon.ClassSkillsTable.GetValue (ClassName, "ABILITIES")
77 if ABTable != "*" and ABTable[:6] != "CLABMA": # mage kits specify ability tables which don't exist
78 GUICommon.AddClassAbilities (MyChar, ABTable, Levels[0], Levels[0])
80 # apply starting (alignment dictated) abilities
81 # pc, table, new level, level diff, alignment
82 AlignmentTable = GemRB.LoadTable ("aligns")
83 AlignmentAbbrev = AlignmentTable.FindValue (3, GemRB.GetPlayerStat (MyChar, IE_ALIGNMENT))
84 GUICommon.AddClassAbilities (MyChar, "abstart", 6,6, AlignmentAbbrev)
86 # setup starting gold (uses a roll dictated by class
87 TmpTable = GemRB.LoadTable ("strtgold")
88 temp = GemRB.Roll (TmpTable.GetValue (Class, 1),TmpTable.GetValue (Class, 0), TmpTable.GetValue (Class, 2))
89 GemRB.SetPlayerStat (MyChar, IE_GOLD, temp * TmpTable.GetValue (Class, 3))
91 # save the appearance
92 GUICommon.SetColorStat (MyChar, IE_HAIR_COLOR, GemRB.GetVar ("HairColor") )
93 GUICommon.SetColorStat (MyChar, IE_SKIN_COLOR, GemRB.GetVar ("SkinColor") )
94 GUICommon.SetColorStat (MyChar, IE_MAJOR_COLOR, GemRB.GetVar ("MajorColor") )
95 GUICommon.SetColorStat (MyChar, IE_MINOR_COLOR, GemRB.GetVar ("MinorColor") )
96 #GUICommon.SetColorStat (MyChar, IE_METAL_COLOR, 0x1B )
97 #GUICommon.SetColorStat (MyChar, IE_LEATHER_COLOR, 0x16 )
98 #GUICommon.SetColorStat (MyChar, IE_ARMOR_COLOR, 0x17 )
99 GemRB.SetPlayerStat (MyChar, IE_EA, 2 )
101 # save the name and starting xp (can level right away in game)
102 GemRB.SetPlayerName (MyChar, GemRB.GetToken ("CHARNAME"), 0)
104 # does all the rest
105 LargePortrait = GemRB.GetToken ("LargePortrait")
106 SmallPortrait = GemRB.GetToken ("SmallPortrait")
107 GemRB.FillPlayerInfo (MyChar, LargePortrait, SmallPortrait)
109 # add the starting inventory for tob
110 if GUICommon.GameIsTOB():
111 # get the kit (or use class if no kit) to load the start table
112 if KitIndex == 0:
113 EquipmentColName = ClassName
114 # sorcerers are missing from the table, use the mage equipment instead
115 if EquipmentColName == "SORCERER":
116 EquipmentColName = "MAGE"
117 else:
118 EquipmentColName = GUICommon.KitListTable.GetValue (KitIndex, 0)
120 EquipmentTable = GemRB.LoadTable ("25stweap")
122 # a map of slots in the table to the real slots
123 # SLOT_BAG is invalid, so use the inventory (first occurence)
124 # SLOT_INVENTORY: use -1 instead, that's what CreateItem expects
125 RealSlots = [ SLOT_ARMOUR, SLOT_SHIELD, SLOT_HELM, -1, SLOT_RING, \
126 SLOT_RING, SLOT_CLOAK, SLOT_BOOT, SLOT_AMULET, SLOT_GLOVE, \
127 SLOT_BELT, SLOT_QUIVER, SLOT_QUIVER, SLOT_QUIVER, \
128 SLOT_ITEM, SLOT_ITEM, SLOT_ITEM, SLOT_WEAPON, SLOT_WEAPON, SLOT_WEAPON ]
129 inventory_exclusion = 0
131 #loop over rows - item slots
132 for slot in range(0, EquipmentTable.GetRowCount ()):
133 slotname = EquipmentTable.GetRowName (slot)
134 item_resref = EquipmentTable.GetValue (slotname, EquipmentColName)
136 # no item - go to next
137 if item_resref == "*":
138 continue
140 # the table has typos for kitted bard's armor
141 if item_resref == "LEATH14":
142 item_resref = "LEAT14"
144 # get empty slots of the requested type
145 realslot = GemRB.GetSlots (MyChar, RealSlots[slot], -1)
146 if RealSlots[slot] == SLOT_WEAPON:
147 # exclude the shield slot, so the offhand stays empty
148 realslot = realslot[1:]
150 if realslot == (): # fallback to the inventory
151 realslot = GemRB.GetSlots (MyChar, -1, -1)
153 if realslot == (): # this shouldn't happen!
154 print "Eeek! No free slots for", item_resref
155 continue
157 # if an item contains a comma, the rest of the value is the stack
158 if "," in item_resref:
159 item_resref = item_resref.split(",")
160 count = int(item_resref[1])
161 item_resref = item_resref[0]
162 else:
163 count = 0
165 targetslot = realslot[0]
166 SlotType = GemRB.GetSlotType (targetslot, MyChar)
167 i = 1
168 item = GemRB.GetItem (item_resref)
170 if inventory_exclusion & item['Exclusion']:
171 # oops, too many magic items to equip, so just dump it to the inventory
172 targetslot = GemRB.GetSlots (MyChar, -1, -1)[0]
173 SlotType = -1
174 else:
175 # if there are no free slots, CreateItem will create the item on the ground
176 while not GemRB.CanUseItemType (SlotType["Type"], item_resref, MyChar) \
177 and i < len(realslot):
178 targetslot = realslot[i]
179 SlotType = GemRB.GetSlotType (targetslot, MyChar)
180 i = i + 1
182 GemRB.CreateItem(MyChar, item_resref, targetslot, count, 0, 0)
183 GemRB.ChangeItemFlag (MyChar, targetslot, IE_INV_ITEM_IDENTIFIED, OP_OR)
184 inventory_exclusion |= item['Exclusion']
186 playmode = GemRB.GetVar ("PlayMode")
187 if playmode >=0:
188 if GemRB.GetVar("GUIEnhancements"):
189 GemRB.SaveCharacter ( GemRB.GetVar ("Slot"), "gembak" )
190 #LETS PLAY!!
191 GemRB.EnterGame()
192 GemRB.ExecuteString ("EquipMostDamagingMelee()", MyChar)
193 else:
194 #leaving multi player pregen
195 if CharGenWindow:
196 CharGenWindow.Unload ()
197 #when export is done, go to start
198 if GUICommon.HasTOB():
199 GemRB.SetToken ("NextScript","Start2")
200 else:
201 GemRB.SetToken ("NextScript","Start")
202 GemRB.SetNextScript ("ExportFile") #export
203 return