[go: up one dir, main page]

Menu

[r9]: / kscraft / trunk / SC.py  Maximize  Restore  History

Download this file

201 lines (181 with data), 7.6 kB

  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
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
# SC.py: Dark Age of Camelot Spellcrafting Calculator (main Window)
# See http://www.ugcs.caltech.edu/~jlamanna/daoc/sccalc/index.html for updates
# Copyright (C) 2003, James Lamanna (jlamanna@ugcs.caltech.edu)
# 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
from Item import *
from constants import *
import string
import sys
def formatCost(cost):
plat = (cost / 10000000) % 1000
gold = (cost / 10000) % 1000
silver = (cost / 100) % 100
copper = cost % 100
str = ''
if plat > 0:
str += '%dp ' % plat
if gold > 0 or plat > 0:
str += '%dg ' % gold
if silver > 0 or gold > 0 or plat > 0:
str += '%ds ' % silver
str += '%dc' % copper
return str
def getGemName(item, slot):
gemstate = item.getAttr('ActiveState')
gemtype = item.getSlotAttr(gemstate, slot, 'Type')
realm = item.getAttr('Realm')
if gemtype == 'Unused': return ''
gemlist = eval('%sList' % gemtype, globals(), globals())
amountlist = eval('%sValues' % gemtype, globals(), globals())
amountindex = amountlist.index(item.getSlotAttr(gemstate, slot, 'Amount'))
effect = item.getSlotAttr(gemstate, slot, 'Effect')
gemname = GemNames[amountindex]
gemend = GemSubName[gemtype]
if type(gemlist) == types.ListType:
effectindex = map(lambda(x):x[0], gemlist).index(effect)
gemmiddle = gemlist[effectindex][1]
else:
effectindex = map(lambda(x):x[0], gemlist[realm]).index(effect)
gemmiddle = gemlist[realm][effectindex][1]
gemname += ' ' + gemmiddle + ' ' + gemend
return string.strip(gemname)
def getGemNameParts(gemname):
#returns level, liquid prefix and dust suffix
if gemname == '':
return ['','','']
gemwords = string.split(gemname, ' ', 3)
if gemwords[0] not in GemNames:
sys.stderr.write("Could not find " + gemwords[1] + " gem\r\n")
return ['','','']
# Prefix (two words distinguish some borked gems)
if gemwords[1] not in GemLiquids:
dbg = "Could not find liquid " + gemwords[1] + "\r\n"
gemwords[1] += " " + gemwords[2]
if gemwords[1] not in GemLiquids:
dbg = dbg + "Could not find liquid " + gemwords[1] + "\r\n"
sys.stderr.write(dbg)
return ['','','']
# Suffix (may include second prefix word) to distinguish dust
gemwords[2] = " ".join(gemwords[2:])
if gemwords[2] not in GemDusts:
dbg = "Could not find dust " + gemwords[2] + "\r\n"
gemwords[2] = gemwords[3]
if gemwords[2] not in GemDusts:
dbg = "Could not find dust " + gemwords[2] + "\r\n"
sys.stderr.write(dbg)
return ['','','']
if len(gemwords) > 3:
gemwords.pop()
return gemwords
def getGemMaterials(item, slot, realm):
gemstate = item.getAttr('ActiveState')
gemname = getGemName(item, slot)
ret = { 'Gems' : { }, 'Dusts' : { }, 'Liquids' : { } }
gemlevel, gemliquid, gemdust = getGemNameParts(gemname)
if gemlevel == '': return ret
gemtype = item.getSlotAttr(gemstate, slot, 'Type')
gemindex = GemNames.index(gemlevel)
if gemliquid == 'Brilliant' or gemliquid == 'Finesse':
ret['Gems'][MaterialGems[gemindex]] = 3
ret['Dusts'][GemDusts[gemdust]] = (gemindex * 5) + 1
ret['Liquids'][GemLiquids[gemliquid][0]] = (gemindex * 6) + 2
ret['Liquids'][GemLiquids[gemliquid][1]] = (gemindex * 6) + 2
ret['Liquids'][GemLiquids[gemliquid][2]] = (gemindex * 6) + 2
elif gemtype == 'Focus' or gemtype == 'Resist':
ret['Gems'][MaterialGems[gemindex]] = 1
ret['Dusts'][GemDusts[gemdust]] = (gemindex * 5) + 1
ret['Liquids'][GemLiquids[gemliquid]] = gemindex + 1
else:
ret['Gems'][MaterialGems[gemindex]] = 1
ret['Dusts'][GemDusts[gemdust]] = (gemindex * 4) + 1
ret['Liquids'][GemLiquids[gemliquid]] = gemindex + 1
return ret
def getItemImbue(item):
itemlevel = item.getAttr('Level')
if item.getAttr('ItemQuality') == '':
item.loadAttr('ItemQuality', '94')
if itemlevel == '':
itemimbue = 0
else:
itemimbue = ImbuePts[int(itemlevel)-1]\
[int(item.getAttr('ItemQuality'))-94]
return itemimbue
def calcImbue(item):
itemtype = item.getAttr('ActiveState')
if itemtype == 'drop': return 0
mvals = []
for i in range(0, 4):
type = item.getSlotAttr(itemtype, i, 'Type')
amount = item.getSlotAttr(itemtype, i, 'Amount')
if amount == '':
mval = 0.0
elif type == 'Focus':
mval = 1.0
elif type == 'Unused':
mval = 0.0
elif type == 'Stat':
mval = ((int(amount) - 1) / 3.0) * 2 + 1
elif type == 'Resist' or type == 'Power':
mval = (int(amount) - 1) * 2
if mval == 0: mval = 1.0
elif type == 'Hits':
mval = int(amount) / 4.0
elif type == 'Skill':
mval = (int(amount) - 1) * 5.0
if mval == 0: mval = 1.0
mvals.append(mval)
maximbue = max(mvals)
mvals.remove(maximbue)
totalimbue = ((maximbue * 2 + sum(mvals)) / 2.0)
return totalimbue
def computeOverchargeSuccess(imbue, itemimbue, item, crafterskill):
success = -OCStartPercentages[int(imbue-itemimbue)]
for i in range(0, 4):
if item.getSlotAttr(activestate, i, 'Type') == 'Unused':
success += GemQualOCModifiers['94']
else:
success += GemQualOCModifiers[item.getSlotAttr(activestate, i, 'Qua')]
success += ItemQualOCModifiers[item.getAttr('ItemQuality')]
success += (crafterSkill - 500) / 10
if crafterSkill <= 50: success -= 450
return success
def computeGemCost(item, i):
itemtype = item.getAttr('ActiveState')
gemtype = re.sub(' ', '', item.getSlotAttr(itemtype, i, 'Type'))
if item.getSlotAttr(itemtype, i, 'Amount') == '':
amount = 0
else:
amount = int(item.getSlotAttr(itemtype, i, 'Amount'))
if amount == '' or gemtype == 'Unused' or amount == 0 or itemtype == 'drop':
cost = 0
remakecost = 0
costindex = 0
return (0, 1)
gemname = getGemName(item, i)
gemlevel, gemliquid, gemdust = getGemNameParts(gemname)
if gemlevel == '':
return (0, 1)
costindex = eval('%sValues' % gemtype, globals(), globals()).index(str(amount))
cost = GemCosts[costindex]
remakecost = RemakeCosts[costindex] * int(item.getSlotAttr(itemtype, i, 'Remakes'))
if gemliquid == 'Brilliant' or gemliquid == 'Finesse':
cost += 60 * costindex
cost = cost * 3
if remakecost > 0:
remakecost += 180 * costindex
elif gemtype == 'Resist' or gemtype == 'Focus':
cost += 60 * costindex
if remakecost > 0:
remakecost += 60 * costindex
return (cost + remakecost, costindex+1)
# vim: set ts=4 sw=4 et: