import sqlite3
import os
import getpass
def insert_ImprintData(db_path,ImprintId):
# 连接到SQLite数据库
conn = sqlite3.connect(db_path)
cursor = conn.cursor()
try:
# 检查ImprintId是否已经存在
cursor.execute("SELECT COUNT(*) FROM ImprintData WHERE ImprintId = ?", (int(ImprintId),))
count = cursor.fetchone()[0]
if count > 0:
print(f"ImprintId {ImprintId} 已经存在,不插入记录")
return 0
# 查询ImprintData表中的最大Id
cursor.execute("SELECT MAX(Id) FROM ImprintData")
max_id_result = cursor.fetchone()[0]
if max_id_result is None:
next_id = 1
else:
next_id = max_id_result + 1
# 插入记录
record = (
next_id, 0, ImprintId, 1, 0, b'\x00' * 8, b'\x00', b'\x00', 0, 0, 0
)
cursor.execute('''
INSERT INTO ImprintData (Id, OwnerId, ImprintId, Level, IsNew, Addition, DeBuffs, DeBuffAgrs, IsIdentify, State, BagSlotIndex)
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
''', record)
# 提交事务
conn.commit()
print(f"纹章{ImprintId}记录插入成功")
except Exception as e:
print(f"发生错误: {e}")
finally:
# 关闭游标和连接
cursor.close()
conn.close()
def insert_item_data(db_path,ItemId,num):
# 连接到SQLite数据库
conn = sqlite3.connect(db_path)
cursor = conn.cursor()
try:
# 检查ItemId 有没有19
cursor.execute(f"SELECT COUNT(*) FROM ItemData WHERE ItemId = {ItemId}")
count = cursor.fetchone()[0]
if count == 0:
# 查询ItemData的Id最大值
cursor.execute("SELECT MAX(Id) FROM ItemData")
max_id = cursor.fetchone()[0]
if max_id is None:
new_id = 1
else:
new_id = max_id + 1
# 插入数据
cursor.execute(f"INSERT INTO ItemData (Id, ItemId, Count, IsNew) VALUES (?, ?, ?, ?)", (new_id, ItemId, num, 0))
print(f"插入数据: {new_id}, {ItemId}, {num}, 0")
else:
print(f"ItemId {ItemId} 已经存在")
# 提交事务
conn.commit()
except Exception as e:
print(f"发生错误: {e}")
finally:
# 关闭游标和连接
cursor.close()
conn.close()
def update_UnitData(db_path):
conn = sqlite3.connect(db_file)
cursor = conn.cursor()
try:
# 检查LevelProperty是否为0x000000000000000000000000000000000000000000000000000000000000000000000000
zero_level_property = b'\x00' * 36
cursor.execute("SELECT InstanceId FROM UnitData WHERE LevelProperty = ?", (zero_level_property,))
results = cursor.fetchall()
if results:
level_property_value = b'0x000643334343434353063306430606060653533343264306530000000000000000000000'
for instance_id in results:
cursor.execute("UPDATE UnitData SET LevelProperty = ? WHERE InstanceId = ?", (level_property_value, instance_id[0]))
# 提交事务
conn.commit()
print("等级属性更新成功")
else:
print("没有需要更新的等级属性")
# 更新表UnitData_dg_tmp中所有对象的SkillAddition, SpeedAddition, 和 Shield字段的值为100
update_query = """
UPDATE UnitData
SET SkillAddition = CASE WHEN SkillAddition < 100 THEN 100 ELSE SkillAddition END,
SpeedAddition = CASE WHEN SpeedAddition < 100 THEN 100 ELSE SpeedAddition END,
MoraleAddition = CASE WHEN MoraleAddition < 100 THEN 100 ELSE MoraleAddition END,
Shield = CASE WHEN Shield < 100 THEN 100 ELSE Shield END,
BaseSkillLevel = CASE WHEN BaseSkillLevel < 3 THEN 3 ELSE BaseSkillLevel END,
AdvanceSkillLevel = CASE WHEN AdvanceSkillLevel < 3 THEN 3 ELSE AdvanceSkillLevel END,
AttackFarther = CASE WHEN AttackFarther < 1 THEN 1 ELSE AttackFarther END,
ActionPointAddition = CASE WHEN ActionPointAddition < 1 THEN 1 ELSE ActionPointAddition END,
SlotAddition = CASE WHEN SlotAddition < 1 THEN 1 ELSE SlotAddition END;
"""
# 执行更新查询
cursor.execute(update_query)
# 提交事务
conn.commit()
print("UnitData人物列表更新完成")
except sqlite3.Error as e:
print(f"发生错误: {e}")
finally:
# 关闭游标和连接
cursor.close()
conn.close()
def has_single_unit(db_path):
# 连接到SQLite数据库
conn = sqlite3.connect(db_path)
cursor = conn.cursor()
try:
# 查询UnitData表中的记录数
cursor.execute("SELECT COUNT(*) FROM UnitData")
count = cursor.fetchone()[0]
# 检查记录数是否为1
if count == 1:
return True
else:
return False
except Exception as e:
print(f"发生错误: {e}")
return False
finally:
# 关闭游标和连接
cursor.close()
conn.close()
# 如果直接运行此脚本,则调用主函数
if __name__ == "__main__":
username = getpass.getuser()
db_file = rf'C:\Users\{username}\AppData\LocalLow\qikemei\The Book Of Warriors\iiiiilllll111iiiii1112'
imprint_id_list=['75', '249', '608', '53', '20', '602', '113', '607', '611', '247', '253', '18', '19', '917', '610', '232', '605', '71']
# 检查表UnitData中是否只有一个对象
if has_single_unit(db_file):
insert_item_data(db_file,19,3)#世界树果实
insert_item_data(db_file,16,3)#技能石
insert_item_data(db_file,13,1)#BOSS石头人
insert_item_data(db_file,23,1)#BOSS火龙
insert_item_data(db_file,24,3)#BOSS毒虫
insert_item_data(db_file,25,1)#BOSS跳鼠
insert_item_data(db_file,8,9)#BOSS跳鼠
insert_item_data(db_file,10,30)#勇者密匣
insert_item_data(db_file,18,30)#神秘树枝
insert_item_data(db_file,6,30)#升级果实
for imprint_id in imprint_id_list:
insert_ImprintData(db_file, imprint_id)
# insert_ImprintData(db_file,'75')
print("UnitData人物列表中只有一个对象")
else:
print("UnitData人物列表中有多个对象或没有对象")
update_UnitData(db_file)
import os
import getpass
def insert_ImprintData(db_path,ImprintId):
# 连接到SQLite数据库
conn = sqlite3.connect(db_path)
cursor = conn.cursor()
try:
# 检查ImprintId是否已经存在
cursor.execute("SELECT COUNT(*) FROM ImprintData WHERE ImprintId = ?", (int(ImprintId),))
count = cursor.fetchone()[0]
if count > 0:
print(f"ImprintId {ImprintId} 已经存在,不插入记录")
return 0
# 查询ImprintData表中的最大Id
cursor.execute("SELECT MAX(Id) FROM ImprintData")
max_id_result = cursor.fetchone()[0]
if max_id_result is None:
next_id = 1
else:
next_id = max_id_result + 1
# 插入记录
record = (
next_id, 0, ImprintId, 1, 0, b'\x00' * 8, b'\x00', b'\x00', 0, 0, 0
)
cursor.execute('''
INSERT INTO ImprintData (Id, OwnerId, ImprintId, Level, IsNew, Addition, DeBuffs, DeBuffAgrs, IsIdentify, State, BagSlotIndex)
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
''', record)
# 提交事务
conn.commit()
print(f"纹章{ImprintId}记录插入成功")
except Exception as e:
print(f"发生错误: {e}")
finally:
# 关闭游标和连接
cursor.close()
conn.close()
def insert_item_data(db_path,ItemId,num):
# 连接到SQLite数据库
conn = sqlite3.connect(db_path)
cursor = conn.cursor()
try:
# 检查ItemId 有没有19
cursor.execute(f"SELECT COUNT(*) FROM ItemData WHERE ItemId = {ItemId}")
count = cursor.fetchone()[0]
if count == 0:
# 查询ItemData的Id最大值
cursor.execute("SELECT MAX(Id) FROM ItemData")
max_id = cursor.fetchone()[0]
if max_id is None:
new_id = 1
else:
new_id = max_id + 1
# 插入数据
cursor.execute(f"INSERT INTO ItemData (Id, ItemId, Count, IsNew) VALUES (?, ?, ?, ?)", (new_id, ItemId, num, 0))
print(f"插入数据: {new_id}, {ItemId}, {num}, 0")
else:
print(f"ItemId {ItemId} 已经存在")
# 提交事务
conn.commit()
except Exception as e:
print(f"发生错误: {e}")
finally:
# 关闭游标和连接
cursor.close()
conn.close()
def update_UnitData(db_path):
conn = sqlite3.connect(db_file)
cursor = conn.cursor()
try:
# 检查LevelProperty是否为0x000000000000000000000000000000000000000000000000000000000000000000000000
zero_level_property = b'\x00' * 36
cursor.execute("SELECT InstanceId FROM UnitData WHERE LevelProperty = ?", (zero_level_property,))
results = cursor.fetchall()
if results:
level_property_value = b'0x000643334343434353063306430606060653533343264306530000000000000000000000'
for instance_id in results:
cursor.execute("UPDATE UnitData SET LevelProperty = ? WHERE InstanceId = ?", (level_property_value, instance_id[0]))
# 提交事务
conn.commit()
print("等级属性更新成功")
else:
print("没有需要更新的等级属性")
# 更新表UnitData_dg_tmp中所有对象的SkillAddition, SpeedAddition, 和 Shield字段的值为100
update_query = """
UPDATE UnitData
SET SkillAddition = CASE WHEN SkillAddition < 100 THEN 100 ELSE SkillAddition END,
SpeedAddition = CASE WHEN SpeedAddition < 100 THEN 100 ELSE SpeedAddition END,
MoraleAddition = CASE WHEN MoraleAddition < 100 THEN 100 ELSE MoraleAddition END,
Shield = CASE WHEN Shield < 100 THEN 100 ELSE Shield END,
BaseSkillLevel = CASE WHEN BaseSkillLevel < 3 THEN 3 ELSE BaseSkillLevel END,
AdvanceSkillLevel = CASE WHEN AdvanceSkillLevel < 3 THEN 3 ELSE AdvanceSkillLevel END,
AttackFarther = CASE WHEN AttackFarther < 1 THEN 1 ELSE AttackFarther END,
ActionPointAddition = CASE WHEN ActionPointAddition < 1 THEN 1 ELSE ActionPointAddition END,
SlotAddition = CASE WHEN SlotAddition < 1 THEN 1 ELSE SlotAddition END;
"""
# 执行更新查询
cursor.execute(update_query)
# 提交事务
conn.commit()
print("UnitData人物列表更新完成")
except sqlite3.Error as e:
print(f"发生错误: {e}")
finally:
# 关闭游标和连接
cursor.close()
conn.close()
def has_single_unit(db_path):
# 连接到SQLite数据库
conn = sqlite3.connect(db_path)
cursor = conn.cursor()
try:
# 查询UnitData表中的记录数
cursor.execute("SELECT COUNT(*) FROM UnitData")
count = cursor.fetchone()[0]
# 检查记录数是否为1
if count == 1:
return True
else:
return False
except Exception as e:
print(f"发生错误: {e}")
return False
finally:
# 关闭游标和连接
cursor.close()
conn.close()
# 如果直接运行此脚本,则调用主函数
if __name__ == "__main__":
username = getpass.getuser()
db_file = rf'C:\Users\{username}\AppData\LocalLow\qikemei\The Book Of Warriors\iiiiilllll111iiiii1112'
imprint_id_list=['75', '249', '608', '53', '20', '602', '113', '607', '611', '247', '253', '18', '19', '917', '610', '232', '605', '71']
# 检查表UnitData中是否只有一个对象
if has_single_unit(db_file):
insert_item_data(db_file,19,3)#世界树果实
insert_item_data(db_file,16,3)#技能石
insert_item_data(db_file,13,1)#BOSS石头人
insert_item_data(db_file,23,1)#BOSS火龙
insert_item_data(db_file,24,3)#BOSS毒虫
insert_item_data(db_file,25,1)#BOSS跳鼠
insert_item_data(db_file,8,9)#BOSS跳鼠
insert_item_data(db_file,10,30)#勇者密匣
insert_item_data(db_file,18,30)#神秘树枝
insert_item_data(db_file,6,30)#升级果实
for imprint_id in imprint_id_list:
insert_ImprintData(db_file, imprint_id)
# insert_ImprintData(db_file,'75')
print("UnitData人物列表中只有一个对象")
else:
print("UnitData人物列表中有多个对象或没有对象")
update_UnitData(db_file)