本帖最后由 iManw 于 2018-10-17 22:10 编辑
from Utils import *
skill_types = [
['SkillName', 'string'],
['SkillDesc', 'string'],
['SkillLevel', 'tinyint'],
['SkillID', 'short'],
['SkillAnim', 'tinyint'],
['SkillIcon', 'int'],
['ReqLevel', 'short'],
['Country', 'tinyint'],
['AttackFighter', 'tinyint'],
['DefenseFighter', 'tinyint'],
['Patrolrogue', 'tinyint'],
['Shootrogue', 'tinyint'],
['AttackMage', 'tinyint'],
['DefenseMage', 'tinyint'],
['Grow', 'tinyint'],
['SkillPoint', 'tinyint'],
['TypeShow', 'tinyint'],
['TypeAttack', 'tinyint'],
['TypeEffect', 'tinyint'],
['TypeDetail', 'short'],
['NeedWeapon1', 'tinyint'],
['NeedWeapon2', 'tinyint'],
['NeedWeapon3', 'tinyint'],
['NeedWeapon4', 'tinyint'],
['NeedWeapon5', 'tinyint'],
['NeedWeapon6', 'tinyint'],
['NeedWeapon7', 'tinyint'],
['NeedWeapon8', 'tinyint'],
['NeedWeapon9', 'tinyint'],
['NeedWeapon10', 'tinyint'],
['NeedWeapon11', 'tinyint'],
['NeedWeapon12', 'tinyint'],
['NeedWeapon13', 'tinyint'],
['NeedWeapon14', 'tinyint'],
['NeedWeapon15', 'tinyint'],
['Shield', 'tinyint'],
['SP', 'short'],
['MP', 'short'],
['ReadyTime', 'tinyint'],
['ResetTime', 'short'],
['AttackRange', 'tinyint'],
['StateType', 'tinyint'],
['AttrType', 'tinyint'],
['Disable', 'short'],
['PrevSkillID', 'short'],
['SuccessType', 'tinyint'],
['SuccessValue', 'tinyint'],
['TargetType', 'tinyint'],
['ApplyRange', 'tinyint'],
['MultiAttack', 'tinyint'],
['KeepTime', 'short'],
['Weapon1', 'tinyint'],
['Weapon2', 'tinyint'],
['Weaponvalue', 'tinyint'],
['Bag', 'tinyint'],
['Arrow', 'short'],
['DamageType', 'tinyint'],
['DamageHP', 'short'],
['DamageSP', 'short'],
['DamageMP', 'short'],
['TimeDamageType', 'tinyint'],
['TimeDamageHP', 'short'],
['TimeDamageSP', 'short'],
['TimeDamageMP', 'short'],
['AddDamageHP', 'short'],
['AddDamageSP', 'short'],
['AddDamageMP', 'short'],
['AbilityType1', 'tinyint'],
['AbilityValue1', 'short'],
['AbilityType2', 'tinyint'],
['AbilityValue2', 'short'],
['AbilityType3', 'tinyint'],
['AbilityValue3', 'short'],
['HealHP', 'short'],
['HealSP', 'short'],
['HealMP', 'short'],
['TimeHealHP', 'short'],
['TimeHealSP', 'short'],
['TimeHealMP', 'short'],
['DefenseType', 'tinyint'],
['DefenseValue', 'tinyint'],
['LimitHP', 'tinyint'],
['FixRange', 'tinyint'],
['ChangeType', 'short'],
['ChangeLevel', 'short'],
]
def MainSkill(outFmt):
if (outFmt.export_complete):
return CombineSkill("Skill")
if (outFmt.csv_import or outFmt.csv_complete):
return ExtractSkill("Skill", outFmt)
def MainNPCSkill(outFmt):
if (outFmt.export_complete):
return CombineSkill("NpcSkill")
if (outFmt.csv_import or outFmt.csv_complete):
return ExtractSkill("NpcSkill", outFmt)
def CombineSkill(type):
csvIn = work_dir + type + ".complete.csv"
try:
csvf = csv.DictReader(open(csvIn))
except IOError:
sys.exit(MsgFileReadError % csvIn)
foutName = work_dir + type + ".SData"
try:
fout = open(foutName, mode='wb')
except IOError:
sys.exit(MsgFileWriteError % foutName)
recs = []
for row in csvf:
recs.append(row)
print "skill_rows: " + str(len(recs))
# Write Total.
record_total = struct.pack('I', (len(recs) / 3))
fout.write(record_total)
for i in recs:
pack_fields(fout, skill_types, i)
return True
def ExtractSkill(type, outFmt):
# Open SData File.
skillSData = feed_dir + type + ".SData"
try:
input = open(skillSData, mode='rb')
except IOError:
sys.exit(MsgFileReadError % skillSData)
header = get_data_headers(skill_types)
if (outFmt.csv_import):
filename = work_dir + type + ".import.csv"
header.pop(1) # Remove SkillDesc
header.pop(3) # Remove SkillAnim
header.pop(3) # Remove SkillIcon
if (outFmt.csv_complete):
filename = work_dir + type + ".complete.csv"
print("Creating " + filename)
# Open File for output.
try:
fout = open(filename, mode='wb')
except IOError:
sys.exit(MsgFileWriteError % filename)
fout_csv = csv.writer(fout)
fout_csv.writerow(header)
fout_csv = csv.DictWriter(fout, header)
record_total = unpack_field(input, 'int')
i = 0
j = 0
while True:
rec = unpack_fields(input, skill_types, {})
if (rec["SkillLevel"] == 1):
i += 1
j = 0
j += 1
if (outFmt.csv_import):
rec["SkillID"] = i
cs_rec = copyKeys(rec, header)
fout_csv.writerow(cs_rec)
if (i == record_total and j == 3):
break
return True