diff --git a/_DPS_/FileConfig.json b/_DPS_/FileConfig.json index 6034a7f..c6a6a70 100644 --- a/_DPS_/FileConfig.json +++ b/_DPS_/FileConfig.json @@ -137,6 +137,11 @@ "Script": [ "誉名录/誉名录.nut" ] + }, + "换装系统": { + "Script": [ + "换装系统/换装系统.nut" + ] } } } \ No newline at end of file diff --git a/_DPS_/_BuiltProject/换装系统/换装系统.nut b/_DPS_/_BuiltProject/换装系统/换装系统.nut new file mode 100644 index 0000000..0b8e9ba --- /dev/null +++ b/_DPS_/_BuiltProject/换装系统/换装系统.nut @@ -0,0 +1,211 @@ +/* +文件名:换装系统.nut +路径:_DPS_/_BuiltProject/换装系统/换装系统.nut +创建日期:2026-03-02 04:16 +文件用途: +*/ + +class OutfitSystem { + + MysqlObject = null; + + ItemSlot = [ + [0, 13], //护肩 + [0, 14], //下装 + [0, 15], //鞋子 + [0, 12], //上衣 + [0, 16], //腰带 + [0, 10], //武器 + [0, 18], //手镯 + [0, 20], //辅助装备 + [-1, -1], //耳环 + [0, 11], //称号 + [0, 17], //项链 + [0, 19], //戒指 + [0, 21], //魔法石 + [-1, -1], //武器装扮 + [1, 9], //光环 + [1, 1], //头部 + [1, 6], //胸部 + [1, 7], //腰部 + [1, 0], //帽子 + [1, 3], //上衣 + [1, 4], //下装 + [1, 2], //脸部 + [1, 8], //皮肤 + [1, 5], //鞋 + [2, 22] //宠物 + ]; + + + constructor() { + + MysqlObject = Mysql(Str_Ptr("127.0.0.1"), 3306, Str_Ptr("taiwan_cain"), Str_Ptr("game"), Str_Ptr("uu5!^%jg")); + MysqlObject.Exec_Sql(format("SET NAMES %s", "latin1")); + + local check_table_sql = "SELECT COUNT(*) FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'OutfitSystem';" + local Ret = MysqlObject.Select(check_table_sql, ["int"]); + if (Ret.len() == 0 || Ret[0][0] == 0) { + local sql = "CREATE TABLE OutfitSystem (cid VARCHAR(128) NOT NULL COMMENT '角色CID', info VARCHAR(512) NOT NULL COMMENT '信息字符串', PRIMARY KEY (cid)) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT '角色换装信息表';"; + MysqlObject.Exec_Sql(sql); + } + + //记录装备 + ClientSocketPackFuncMap.rawset(21015001, function(SUser, Jso) { + local Slot = Jso.Slot; + local EquipInfo = Json.Encode(Jso.EquipInfo); + local SetKey = format("%d_%d", SUser.GetCID(), Slot); + MysqlObject.Exec_Sql(format("INSERT INTO OutfitSystem (cid, info) VALUES ('%s', '%s') ON DUPLICATE KEY UPDATE info = '%s';", SetKey, EquipInfo, EquipInfo)); + }.bindenv(this)); + + //清空装备 + ClientSocketPackFuncMap.rawset(21015005, function(SUser, Jso) { + local Slot = Jso.Slot; + local SetKey = format("%d_%d", SUser.GetCID(), Slot); + MysqlObject.Exec_Sql(format("DELETE FROM OutfitSystem WHERE cid = '%s';", SetKey)); + }.bindenv(this)); + + //查询配置 + ClientSocketPackFuncMap.rawset(21015003, function(SUser, Jso) { + local Slot = Jso.Slot; + local SetKey = format("%d_%d", SUser.GetCID(), Slot); + local Ret = MysqlObject.Select(format("SELECT info FROM OutfitSystem WHERE cid = '%s';", SetKey), ["string"]); + if (Ret.len() == 0) { + SUser.SendJso({ + op = 21015004, + Slot = Slot, + EquipInfo = null + }); + } else { + SUser.SendJso({ + op = 21015004, + Slot = Slot, + EquipInfo = Json.Decode(Ret[0][0]) + }); + } + + }.bindenv(this)); + + //换装请求 + Gm_InputFunc_Handle["HZ"] <- function(SUser, CmdString) { + local count = -1; + local pos = 0; + local handler = []; + do { + local start = pos; + pos = CmdString.find(" ", pos + 1); + if (pos != null) { + handler.append(CmdString.slice(start + 1, pos)); + } else + handler.append(CmdString.slice(start + 1)); + count = count + 1 + } while (pos != null) + + //得到空格数量 + if (count != 1) return; + local Slot = handler[1].tointeger() - 1; + local SetKey = format("%d_%d", SUser.GetCID(), Slot); + local Ret = MysqlObject.Select(format("SELECT info FROM OutfitSystem WHERE cid = '%s';", SetKey), ["string"]); + if (Ret.len() != 0) { + local EquipInfoList = Json.Decode(Ret[0][0]); + local ChangeFlag = true; + foreach(_Index, EquipInfo in EquipInfoList) { + local EquipIndex = EquipInfo[0]; + //没有装备 + if (EquipIndex == 0) continue; + //耳环和武器装扮 + if (ItemSlot[_Index][0] == -1) continue; + //寻找符合的装备 + local Flag = ChanageEquip(SUser, ItemSlot[_Index], EquipInfo); + if(!Flag) ChangeFlag = false; + } + + Sq_CallFunc(S_Ptr("0x0867ba5c"), "int", ["pointer", "int", "int", "int"], SUser.C_Object, 0, 2, 0); + Sq_CallFunc(S_Ptr("0x0867ba5c"), "int", ["pointer", "int", "int", "int"], SUser.C_Object, 1, 2, 1); + Sq_CallFunc(S_Ptr("0x0867ba5c"), "int", ["pointer", "int", "int", "int"], SUser.C_Object, 7, 2, 7); + SUser.SendItemSpace(7); + SUser.SendItemSpace(1); + SUser.SendItemSpace(0); + + if(ChangeFlag) { + SUser.SendNotiPacketMessage("换装成功!", 8); + } + } else { + + } + }.bindenv(this); + } + + function ChanageEquip(SUser, SlotInfo, EquipInfo) { + local InvenObj = SUser.GetInven(); + local EquipIndex = EquipInfo[0]; + local Upgrade = EquipInfo[1]; + local Amplification = EquipInfo[2]; + local Forging = EquipInfo[3]; + local Enchanting = EquipInfo[4]; + local StartIndex = 0; + local EndIndex = 0; + local FindType = 0; + + //装备 + if (SlotInfo[0] == 0) { + StartIndex = 3; + EndIndex = 56; + FindType = 1; + } + //时装 + else if (SlotInfo[0] == 1) { + StartIndex = 0; + EndIndex = 104; + FindType = 2; + } + //宠物 + else if (SlotInfo[0] == 2) { + StartIndex = 0; + EndIndex = 104; + FindType = 3; + } + + for (local i = StartIndex; i< EndIndex; i++) { + local Inven_Item = InvenObj.GetSlot(FindType, i); + if (Inven_Item) { + local Index = Inven_Item.GetIndex(); + if (Index == EquipIndex) { + //对比属性 + local EquipUpgrade = Inven_Item.GetUpgrade(); + local EquipAmplification = Inven_Item.GetAmplification(); + local EquipForging = Inven_Item.GetForging(); + local EquipEnchanting = Inven_Item.GetEnchanting(); + if (EquipUpgrade == Upgrade && EquipAmplification == Amplification && EquipForging == Forging && EquipEnchanting == Enchanting) { + //对比成功 + if (SlotInfo[0] == 2) { + Sq_CallFunc(S_Ptr("0x08500688"), "int", ["pointer", "int", "int", "int", "int"], InvenObj.C_Object, 3, i, 0, 22); + return true; + } else { + //装备和时装 + Sq_CallFunc(S_Ptr("0x0865EED2"), "int", ["pointer", "int", "short", "int"], SUser.C_Object, SlotInfo[0], i, SlotInfo[1]); + return true; + } + } + } + } + } + } +} + + +Timer.SetTimeOut(function() { + getroottable()._OutfitSystem_ <- OutfitSystem(); + print("换装系统 - 已加载"); + + + /* + 对于宠物的更换 走的不是装备的变更逻辑 + //move item + Sq_CallFunc(S_Ptr("0x08500688"), "int", ["pointer", "int", "int", "int", "int"], InvenObj.C_Object, 3, 0, 0, 22); + //刷新宠物 + Sq_CallFunc(S_Ptr("0x0867ba5c"), "int", ["pointer", "int", "int", "int"], SUser.C_Object, 1, 2, 1); + //刷新宠物背包 + SUser.SendItemSpace(7); + */ +}, 1); \ No newline at end of file