- UID
- 24770
- 阅读权限
- 40
- 回帖
- 142
- 喵币
- 0
- 有爱
- 18
- DKP
- 565
- 金币
- 20297
- 在线时间
- 236 小时
- 注册时间
- 2020-4-12
- 最后登录
- 2025-9-20
声望: 660   虚弱: 0

Lv.4(锻造者)

|
发表于 2024-11-19 10:26:17
|
显示全部楼层
-- 定义常量
local ITEM_ENTRY = 30001
local TRANSFER_TABLE = "_zhuanzhi"
local MAX_SKILL_LEVEL = 34000
local PROFESSION_SKILLS = {171, 164, 333, 202, 182, 165, 186, 197, 356, 393, 185, 129}
-- 安全执行数据库查询函数
local function safeQuery(db, query,...)
local result = db:Query(query,...)
if not result then
print("数据库查询错误: ".. db:GetLastError())
-- 这里可以根据实际情况决定如何处理错误,比如向玩家发送错误消息等
end
return result
end
-- 处理角色信息更新的函数
local function updateCharacterInfo(db, targetGuid, player)
local race = player:GetRace()
local class = player:GetClass()
local gender = player:GetGender()
local skin = player:GetSkin()
local face = player:GetFace()
local hairStyle = player:GetHairStyle()
local hairColor = player:GetHairColor()
local facialHair = player:GetFacialHair()
safeQuery(db, "UPDATE characters set race =?, class =?, gender =?, skin =?, face =?, hair_style =?, hair_color =?, facial_hair =? where guid =?",
race, class, gender, skin, face, hairStyle, hairColor, facialHair, targetGuid)
end
-- 清理角色技能的函数
local function clearCharacterSkills(db, targetGuid)
safeQuery(db, "delete from character_spell where guid =? and spell <?", targetGuid, MAX_SKILL_LEVEL)
local skills = safeQuery(db, "select * from character_skills where guid =?", targetGuid)
if skills then
local skillId = skills:GetUInt32(1)
for _, v in pairs(PROFESSION_SKILLS) do
if skillId ~= v then
safeQuery(db, "delete from character_skills where guid =? and skill =?", targetGuid, skillId)
end
end
end
end
-- 主要的Lua函数
local function lushi(event, player, item, target)
local accountId = player:GetAccountId()
local db = CharDB()
-- 清空转账表中该账号的数据
safeQuery(db, "delete from ".. TRANSFER_TABLE.. " where AC =?", accountId)
player:GossipClearMenu()
local characterGuids = safeQuery(db, "select guid from characters where account =?", accountId)
local menuIndex = 1
if characterGuids then
for row in characterGuids:Iterator() do
local guid = row:GetUInt32(0)
local characterInfo = safeQuery(db, "select * from characters where guid =?", guid)
if characterInfo then
safeQuery(db, "INSERT INTO ".. TRANSFER_TABLE.. " VALUES(?,?,?)", menuIndex, guid, accountId)
menuIndex = menuIndex + 1
end
end
end
-- 添加转职说明到菜单
player:GossipMenuAddItem(0, "自助转职说明:", 0, 21)
player:GossipMenuAddItem(0, "1.转职会清空职业技能和所有图纸。", 0, 22)
player:GossipMenuAddItem(0, "2.转职会保留专业熟练度和所有被动收益", 0, 23)
player:GossipMenuAddItem(0, "3.转职后不匹配的装备通过邮箱返还", 0, 24)
player:GossipMenuAddItem(0, "4.转职不限制种族,职业,次数", 0, 24)
player:GossipMenuAddItem(0, "5.转职后克隆当前角色的职业和外观", 0, 24)
player:GossipMenuAddItem(0, "6.使用步骤:比如我现在是兽人战士,我想转职成矮人骑士,先建立一个矮人骑士,将这个转职凭证邮寄给矮人骑士,矮人骑士使用这个凭证后选择兽人战士,那么兽人战士就将转职成矮人骑士", 0, 24)
player:GossipMenuAddItem(0, " >我已知晓,点击转职<", 0, 0)
player:GossipSendMenu(1, item)
end
local function ResetMap_Select(event, player, item, sender, intid, code)
local accountId = player:GetAccountId()
local db = CharDB()
local characterGuids = safeQuery(db, "select guid from characters where account =?", accountId)
if intid == 0 then
player:GossipMenuAddItem(0, "点击下方角色名字选项即可完成转职 不要选当前角色为转职对象,无效!", 0, 20)
local characterCount = 0
if characterGuids then
characterCount = characterGuids:GetRowCount()
for i = 1, characterCount do
local guid = characterGuids:GetUInt32(i - 1) -- 注意这里的索引从0开始
local characterInfo = safeQuery(db, "select * from characters where guid =?", guid)
if characterInfo then
player:GossipMenuAddItem(0, "第".. i.."个角色>>>".. characterInfo:GetString(2), 0, i)
end
end
end
player:GossipSendMenu(1, item)
else
local currentGuid = player:GetGUIDLow()
local currentCharacterInfo = safeQuery(db, "select * from characters where guid =?", currentGuid)
if currentCharacterInfo then
local targetCharacterRow = safeQuery(db, "select * from ".. TRANSFER_TABLE.. " where ID =? and AC =?", intid, accountId)
if targetCharacterRow then
local targetGuid = targetCharacterRow:GetUInt32(1)
updateCharacterInfo(db, targetGuid, player)
clearCharacterSkills(db, targetGuid)
SendWorldMessage("转职已完成,小退查看。")
player:GossipComplete()
end
end
end
end
-- 注册事件
RegisterItemGossipEvent(ITEM_ENTRY, 1, lushi)
RegisterItemGossipEvent(ITEM_ENTRY, 2, ResetMap_Select)
试试这个 AI 优化的!!! |
|