/
GUICG2.py
180 lines (158 loc) · 5.47 KB
/
GUICG2.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
# GemRB - Infinity Engine Emulator
# Copyright (C) 2003 The GemRB Project
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#
#
#character generation, class (GUICG2)
import GemRB
import GUICommon
import CommonTables
import LUCommon
from ie_stats import *
from GUIDefines import *
ClassWindow = 0
TextAreaControl = 0
DoneButton = 0
MyChar = 0
def OnLoad():
global ClassWindow, TextAreaControl, DoneButton, MyChar
GemRB.LoadWindowPack("GUICG", 640, 480)
ClassWindow = GemRB.LoadWindow(2)
MyChar = GemRB.GetVar ("Slot")
Race = CommonTables.Races.FindValue (3, GemRB.GetPlayerStat (MyChar, IE_RACE) )
RaceName = CommonTables.Races.GetRowName(Race)
ClassCount = CommonTables.Classes.GetRowCount()+1
j = 0
#radiobutton groups must be set up before doing anything else to them
for i in range(1,ClassCount):
ClassName = CommonTables.Classes.GetRowName (i-1)
if CommonTables.Classes.GetValue (ClassName, "MULTI"):
continue
if j>7:
Button = ClassWindow.GetControl(j+7)
else:
Button = ClassWindow.GetControl(j+2)
Button.SetFlags(IE_GUI_BUTTON_RADIOBUTTON, OP_OR)
Button.SetState(IE_GUI_BUTTON_DISABLED)
j = j+1
j = 0
GemRB.SetVar("MAGESCHOOL",0)
HasMulti = 0
for i in range(1,ClassCount):
ClassName = CommonTables.Classes.GetRowName(i-1)
Allowed = CommonTables.Classes.GetValue(ClassName, RaceName)
if CommonTables.Classes.GetValue (ClassName, "MULTI"):
if Allowed!=0:
HasMulti = 1
continue
if j>7:
Button = ClassWindow.GetControl(j+7)
else:
Button = ClassWindow.GetControl(j+2)
j = j+1
t = CommonTables.Classes.GetValue(ClassName, "NAME_REF")
Button.SetText(t )
if Allowed==0:
continue
if Allowed==2:
GemRB.SetVar("MAGESCHOOL",5) #illusionist
Button.SetState(IE_GUI_BUTTON_ENABLED)
Button.SetEvent(IE_GUI_BUTTON_ON_PRESS, ClassPress)
Button.SetVarAssoc("Class", i)
MultiClassButton = ClassWindow.GetControl(10)
MultiClassButton.SetText(11993)
if HasMulti == 0:
MultiClassButton.SetState(IE_GUI_BUTTON_DISABLED)
BackButton = ClassWindow.GetControl(14)
BackButton.SetText(15416)
BackButton.SetFlags (IE_GUI_BUTTON_CANCEL, OP_OR)
DoneButton = ClassWindow.GetControl(0)
DoneButton.SetText(11973)
DoneButton.SetFlags (IE_GUI_BUTTON_DEFAULT, OP_OR)
TextAreaControl = ClassWindow.GetControl(13)
ClassName = GUICommon.GetClassRowName (GemRB.GetVar ("Class")-1, "index")
if ClassName == "":
TextAreaControl.SetText(17242)
DoneButton.SetState(IE_GUI_BUTTON_DISABLED)
else:
TextAreaControl.SetText (CommonTables.Classes.GetValue (ClassName, "DESC_REF"))
DoneButton.SetState(IE_GUI_BUTTON_ENABLED)
MultiClassButton.SetEvent(IE_GUI_BUTTON_ON_PRESS, MultiClassPress)
DoneButton.SetEvent(IE_GUI_BUTTON_ON_PRESS, NextPress)
BackButton.SetEvent(IE_GUI_BUTTON_ON_PRESS, BackPress)
ClassWindow.SetVisible(WINDOW_VISIBLE)
return
def BackPress():
if ClassWindow:
ClassWindow.Unload()
GemRB.SetNextScript("CharGen3")
GemRB.SetVar("Class",0) #scrapping the class value
return
def SetClass():
# find the class from the class table
ClassIndex = GemRB.GetVar ("Class") - 1
ClassName = GUICommon.GetClassRowName (ClassIndex, "index")
Class = CommonTables.Classes.GetValue (ClassName, "ID")
GemRB.SetPlayerStat (MyChar, IE_CLASS, Class)
KitIndex = GemRB.GetVar ("Class Kit")
MageSchool = GemRB.GetVar ("MAGESCHOOL")
#multiclassed gnomes
if MageSchool and not KitIndex:
SchoolTable = GemRB.LoadTable ("magesch")
KitIndex = CommonTables.KitList.FindValue (6, SchoolTable.GetValue (MageSchool, 3) )
KitValue = (0x4000 + KitIndex)
GemRB.SetPlayerStat (MyChar, IE_KIT, KitValue)
# protect against barbarians; this stat will be overwritten later
GemRB.SetPlayerStat (MyChar, IE_HITPOINTS, ClassIndex)
#assign the correct XP
if GUICommon.GameIsTOB():
GemRB.SetPlayerStat (MyChar, IE_XP, CommonTables.ClassSkills.GetValue (ClassName, "STARTXP2"))
else:
GemRB.SetPlayerStat (MyChar, IE_XP, CommonTables.ClassSkills.GetValue (ClassName, "STARTXP"))
#create an array to get all the classes from
NumClasses = 1
IsMulti = GUICommon.IsMultiClassed (MyChar, 1)
if IsMulti[0] > 1:
NumClasses = IsMulti[0]
Classes = [IsMulti[1], IsMulti[2], IsMulti[3]]
else:
Classes = [GemRB.GetPlayerStat (MyChar, IE_CLASS)]
#loop through each class and update it's level
xp = GemRB.GetPlayerStat (MyChar, IE_XP)/NumClasses
for i in range (NumClasses):
CurrentLevel = LUCommon.GetNextLevelFromExp (xp, Classes[i])
if i == 0:
GemRB.SetPlayerStat (MyChar, IE_LEVEL, CurrentLevel)
elif i <= 2:
GemRB.SetPlayerStat (MyChar, IE_LEVEL2+i-1, CurrentLevel)
def MultiClassPress():
GemRB.SetVar("Class Kit",0)
if ClassWindow:
ClassWindow.Unload()
GemRB.SetNextScript("GUICG10")
return
def ClassPress():
SetClass()
if ClassWindow:
ClassWindow.Unload()
GemRB.SetNextScript("GUICG22")
return
def NextPress ():
SetClass()
if ClassWindow:
ClassWindow.Unload()
GemRB.SetNextScript("CharGen4") #alignment
return