using protobuf; using system; using system.runtime.interopservices; using system.collections.generic; using system.io; using system.linq; using system.collections.concurrent; using system.text; using system.threading.tasks; namespace mrhassan.network.gamepackets { public sealed class coatstorage { public coatstorage() { } public bool read(byte[] packet) { using (var memorystream = new memorystream(packet)) { info = serializer.deserializewithlengthprefix<coatstorageproto>(memorystream, prefixstyle.fixed32); } return true; } public void handle(client.gamestate client) { switch (info.actionid) { case action.combine: { conqueritem itemininventory = null; conqueritem iteminsystem = null; if (client.inventory.trygetitem((uint)info.itemid, out itemininventory)) { if (client.entity.storageitems.trygetvalue((uint)info.itemguid, out iteminsystem)) { iteminsystem.minutes += itemininventory.minutes; database.conqueritemtable.updateminutes(iteminsystem); if (iteminsystem.minutes != 0) { uint num; if (datetime.now >= iteminsystem.timestamp.addminutes(iteminsystem.minutes)) { database.conqueritemtable.deleteitem(iteminsystem.uid); } else { timespan span = new timespan(iteminsystem.timestamp.addminutes(iteminsystem.minutes).ticks); timespan span2 = new timespan(datetime.now.ticks); num = (uint)(span.totalseconds - span2.totalseconds); iteminsystem.timeleftinminutes = num; } } client.inventory.remove(itemininventory, game.enums.itemuse.remove); var proto = new coatstorageproto(); proto.actionid = action.combine; proto.itemguid = info.itemguid; proto.itemid = (int)iteminsystem.id; proto.additem(iteminsystem, 1); client.send(finalizeprotobuf(proto)); } } break; } case action.equipcheck: Conqueritem myitem; if (client.inventory.trygetitem(info.itemguid, out myitem)) { var packet = finalizeprotobuf(new coatstorageproto() { actionid = info.actionid, itemguid = info.itemguid, }); client.send(packet); } break; case action.addtowardrobe: { if (!canequip(info, client)) { if (client.inventory.trygetitem(info.itemguid, out myitem)) { if (!client.entity.storageitems.containskey(myitem.uid)) client.entity.storageitems.add(myitem.uid, myitem); myitem.inwardrobe = true; database.conqueritemtable.updatewardrobe(myitem.inwardrobe, myitem.uid); client.inventory.remove(myitem, game.enums.itemuse.none); } break; } if (client.entity.storageitems.trygetvalue(info.itemguid, out myitem)) { foreach (var i in client.entity.storageitems.values) { if (i.position == (byte)packethandler.getpositionfromid(myitem.id)) { if (client.equipment.trygetitem((byte)i.position) != null) client.equipment.remove((byte)i.position, true); i.position = 0; database.conqueritemtable.updatelocation(i, client); } } myitem.position = (byte)packethandler.getpositionfromid(myitem.id); if (!client.equipment.add(myitem)) { client.equipment.remove((byte)myitem.position, true); } var iu = new itemusage(true); iu.id = itemusage.unknown5; iu.uid = myitem.uid; iu.dwparam = myitem.position; client.send(iu.toarray()); clientequip equips = new clientequip(); equips.doequips(client); client.send(equips.toarray()); database.conqueritemtable.updatelocation(myitem, client); client.equipment.updateentitypacket(); client.send(finalizeprotobuf(new coatstorageproto() { actionid = info.actionid, itemguid = info.itemguid, itemid = (int)myitem.id })); } else if (client.inventory.trygetitem(info.itemguid, out myitem)) { client.entity.storageitems.add(myitem.uid, myitem); myitem.inwardrobe = true; database.conqueritemtable.updatewardrobe(myitem.inwardrobe, myitem.uid); client.inventory.remove(myitem, game.enums.itemuse.none); client.send(finalizeprotobuf(new coatstorageproto() { actionid = info.actionid, itemguid = info.itemguid, itemid = (int)myitem.id })); foreach (var i in client.entity.storageitems.values) { if (i.position != 0 && i.position == (byte)packethandler.getpositionfromid(myitem.id)) { if (client.equipment.trygetitem((byte)i.position) != null) client.equipment.remove((byte)i.position, true); i.position = 0; database.conqueritemtable.updatelocation(i, client); } } myitem.position = (byte)packethandler.getpositionfromid(myitem.id); if (!client.equipment.add(myitem)) { client.equipment.remove((byte)myitem.position, true); } var iu = new itemusage(true); iu.id = itemusage.unknown5; iu.uid = myitem.uid; iu.dwparam = myitem.position; client.send(iu.toarray()); clientequip equips = new clientequip(); equips.doequips(client); client.send(equips.toarray()); database.conqueritemtable.updatelocation(myitem, client); client.equipment.updateentitypacket(); } break; } case action.takeoff: If (client.entity.storageitems.trygetvalue(info.itemguid, out myitem)) { client.send(finalizeprotobuf(new coatstorageproto() { actionid = info.actionid, itemguid = info.itemguid, itemid = (int)myitem.id })); var pos = (byte)packethandler.getpositionfromid(myitem.id); client.equipment.remove(pos, true); clientequip equips = new clientequip(); equips.doequips(client); if (pos == 17) equips.steedarmor = 0; else equips.garment = 0; client.send(equips.toarray()); client.equipment.updateentitypacket(); } break; case action.retrieve: If (client.entity.storageitems.trygetvalue(info.itemguid, out myitem) && client.inventory.count < 40) { var pos = (byte)packethandler.getpositionfromid(myitem.id); client.entity.storageitems.remove(myitem.uid); myitem.inwardrobe = false; database.conqueritemtable.updatewardrobe(myitem.inwardrobe, myitem.uid); client.send(finalizeprotobuf(new coatstorageproto() { actionid = info.actionid, itemguid = info.itemguid, itemid = (int)myitem.id })); client.inventory.add(myitem, game.enums.itemuse.move); clientequip equips = new clientequip(); equips.doequips(client); if (pos == 17) equips.steedarmor = 0; else equips.garment = 0; client.send(equips.toarray()); client.equipment.updateentitypacket(); } break; } new titlestorage().checktitles(client); } private bool canequip(coatstorageproto info, client.gamestate client) { conqueritem myitem; if (client.inventory.trygetitem(info.itemguid, out myitem) || client.entity.storageitems.trygetvalue(info.itemguid, out myitem) || client.equipment.trygetitem(info.itemguid, out myitem)) { var dbinfo = database.conqueriteminformation.baseinformations.containskey(myitem.id) ? Database.conqueriteminformation.baseinformations[myitem.id] : Null; if (dbinfo == null) return false; bool issteedarmor = packethandler.getpositionfromid(myitem.id) == packethandler.positions.steedarmor; bool canequipsteedarmor = issteedarmor && client.entity.subclasses.classes.containskey(9) && client.entity.subclasses.classes[9].phase >= database.conqueriteminformation.baseinformations[myitem.id].proficiency; if (!issteedarmor) { var charsex = (client.entity.body == 1003 || client.entity.body == 1004) ? "male" : "female"; if ((dbinfo.gender == 1 ? Charsex != "male" : Dbinfo.gender == 0 ? False : Charsex != "female")) { return false; } } else if (issteedarmor && !canequipsteedarmor) return false; } else return false; return true; } private byte[] finalizeprotobuf(coatstorageproto coatstorageproto) { using (var memorystream = new memorystream()) { serializer.serializewithlengthprefix(memorystream, coatstorageproto, prefixstyle.fixed32); var pkt = new byte[8 + memorystream.length]; memorystream.toarray().copyto(pkt, 0); writer.write((ushort)memorystream.length, 0, pkt); writer.write((ushort)3300, 2, pkt); return pkt; } } public void login(client.gamestate client) { var pkt = new coatstorageproto(); foreach (var item in client.entity.storageitems.values) { pkt.additem(item, client.entity.storageitems.values.where(i => i.id == item.id).count()); client.send(finalizeprotobuf(pkt)); if (item.position != 0) { client.equipment.add(item); var iu = new itemusage(true); iu.id = itemusage.unknown5; iu.uid = item.uid; iu.dwparam = item.position; client.send(iu.toarray()); clientequip equips = new clientequip(); equips.doequips(client); client.send(equips.toarray()); database.conqueritemtable.updatelocation(item, client); client.equipment.updateentitypacket(); } } var currentgarment = client.equipment.trygetitem((byte)packethandler.positions.garment); if (currentgarment != null && !client.entity.storageitems.containskey(currentgarment.uid)) { client.entity.storageitems.add(currentgarment.uid, currentgarment); pkt.additem(currentgarment, client.entity.storageitems.values.where(i => i.id == currentgarment.id).count()); pkt.item.equipped = true; client.send(finalizeprotobuf(pkt)); } var currentmountarmor = client.equipment.trygetitem((byte)packethandler.positions.steedarmor); if (currentmountarmor != null && !client.entity.storageitems.containskey(currentmountarmor.uid)) { client.entity.storageitems.add(currentmountarmor.uid, currentmountarmor); pkt.additem(currentmountarmor, client.entity.storageitems.values.where(i => i.id == currentmountarmor.id).count()); pkt.item.equipped = true; client.send(finalizeprotobuf(pkt)); } } public coatstorageproto info; public enum action : Int { /// <summary> /// load items in storage ... /// </summary> login = 0, equipcheck = 1, retrieve = 2, combine = 4, addtowardrobe = 5, takeoff = 6, dwparam = 7, } } [protocontract] public class coatstorageproto { [protomember(1, isrequired = true)] public coatstorage.action actionid; [protomember(2, isrequired = true)] public uint itemguid; [protomember(3, isrequired = true)] public int itemid; [protomember(4, isrequired = true)] public int junk; [protomember(5, isrequired = true)] public itemstorage item; public void additem(conqueritem item, int stack) { item = new itemstorage(); item.itemuid = item.uid; item.itemid = (int)item.id; item.maximumdurability = item.minimumdurability = item.maximdurability; item.stack = stack; item.firstsocket = (int)item.socketone; item.secondsocket = (int)item.sockettwo; item.plus = item.plus; item.protection = item.bless; item.bound = item.bound; item.health = item.enchant; item.socketprogress = (int)item.socketprogress; item.effect = item.effect; item.color = item.color; item.craftprogress = (int)item.plusprogress; item.locked = item.lock == 1 ? True : False; item.suspicious = false; item.inscribed = false; item.dwparam7 = 0; item.equipped = item.position != 0; item.dwparam15 = 0; item.time = 0; item.subtime = 0; } } [protocontract] public class itemstorage { [protomember(1, isrequired = true)] public uint itemuid; [protomember(2, isrequired = true)] public int itemid; [protomember(3, isrequired = true)] public int socketprogress; [protomember(4, isrequired = true)] public int firstsocket; [protomember(5, isrequired = true)] public int secondsocket; [protomember(6, isrequired = true)] public game.enums.itemeffect effect; [protomember(7, isrequired = true)] public int dwparam7; [protomember(8, isrequired = true)] public int plus; [protomember(9, isrequired = true)] public int protection; [protomember(10, isrequired = true)] public bool bound; [protomember(11, isrequired = true)] public int health; [protomember(12, isrequired = true)] public bool equipped; [protomember(13, isrequired = true)] public bool suspicious; [protomember(14, isrequired = true)] public bool locked; [protomember(15, isrequired = true)] public int dwparam15; [protomember(16, isrequired = true)] public game.enums.color color; [protomember(17, isrequired = true)] public int craftprogress; /// <summary> /// inscribed in guild arsenal /// this class is for wardrobe items which are garments or mount armors so this filed is always false /// </summary> [protomember(18, isrequired = true)] public bool inscribed; /// <summary> /// time left in seconds ! /// </summary> [protomember(19, isrequired = true)] public int time; /// <summary> /// time left in minutes (if item not activated only) /// </summary> [protomember(20, isrequired = true)] public int subtime; [protomember(21, isrequired = true)] public int stack; [protomember(22, isrequired = true)] public int minimumdurability; [protomember(23, isrequired = true)] public int maximumdurability; } public static class storage { private static string path = constants.dataholderpath + "storage.ini"; public static void read(out storageinfo storageinfo) { storageinfo = new storageinfo(); var reader = new inifile(path); { storageinfo.count = reader.readint32("storage", "storagetypecount", 0); storageinfo.storages = new storageinfo.storage[storageinfo.count]; for (int i = 0; i < storageinfo.count; i++) { var mysection = (i + 1).tostring(); storageinfo.storages[i] = new storageinfo.storage(); storageinfo.storages[i].type = reader.readint32(mysection, "type", 0); storageinfo.storages[i].unitcount = reader.readint32(mysection, "unitcount", 0); storageinfo.storages[i].viewtype = reader.readint32(mysection, "viewtype", 0); storageinfo.storages[i].units = new storageinfo.storage.unit[storageinfo.storages[i].unitcount]; for (int u = 0; u < storageinfo.storages[i].unitcount; u++) { var unitsection = mysection + "-" + (u + 1).tostring(); storageinfo.storages[i].units[u] = new storageinfo.storage.unit(); storageinfo.storages[i].units[u].id = reader.readint32(unitsection, "id", 0); storageinfo.storages[i].units[u].anisection = reader.readstring(unitsection, "anisection"); storageinfo.storages[i].units[u].getwaytype3 = reader.readint32(unitsection, "getwaytype3", 0); storageinfo.storages[i].units[u].getwaytext3 = reader.readstring(unitsection, "getwaytext3"); storageinfo.storages[i].units[u].param = reader.readstring(unitsection, "param"); storageinfo.storages[i].units[u].intro = reader.readstring(unitsection, "intro"); } } } //console.writeline("storages loaded"); } } [structlayout(layoutkind.sequential)] public class storageinfo { public int count; public storage[] storages; public class storage { public int type; public int unitcount; public int viewtype; public unit[] units; public class unit { public int id; public string anisection; public int getwaytype3; public string getwaytext3; public string param; public string intro; } } public storage getstoragebytype(int type) { foreach (var storage in storages) if (storage != null && storage.type == type) return storage; return null; } public storage.unit getunitbyid(int id, storage _storage = null) { if (_storage != null) { foreach (var unit in _storage.units) if (unit.id == id) return unit; } else { foreach (var storage in storages) if (storage != null) foreach (var unit in storage.units) if (unit.id == id) return unit; } return null; } } public sealed class storagemanager { public static storageinfo info; public static void load() { try { storage.read(out info); } catch (exception e) { console.writeline(e); } } public static t wing<t>(int _type, int _id) { object value = null; int trash = 0; if (typeof(t) == typeof(bool)) { value = int.tryparse(info.getunitbyid(_id, info.getstoragebytype(_type)).param, out trash); } else if (typeof(t) == typeof(int)) { var mytype = _type.tostring(); var myid = _id.tostring(); while (myid.length < 4) myid = "0" + myid; value = int.parse(mytype + myid); } else throw new exception("unknow type : " + typeof(t).name); return (t)convert.changetype(value, typeof(t)); } public static int gettitlepoints(short _type, short _id) { if (_type == 1 && _id == 1000) return 150; else if (_type == 2018 && _id == 1) return 500; else if (_type == 2001 && _id == 2) return 300; else if (_type == 2002 && _id == 3) return 150; else if (_type == 2003 && _id == 4) return 300; else if (_type == 2004 && _id == 5) return 150; else if (_type == 2005 && _id == 6) return 150; else if (_type == 2006 && _id == 7) return 150; else if (_type == 2020 && _id == 2020) return 300; else if (_type == 2021 && _id == 2021) return 200; else if (_type == 2022 && _id == 2022) return 100; else if (_type == 2023 && _id == 2023) return 300; else if (_type == 2024 && _id == 2024) return 200; else if (_type == 2025 && _id == 2025) return 100; else if (_type == 2028 && _id == 2028) return 150; else if (_type == 2029 && _id == 2029) return 300; else if (_type == 2030 && _id == 2030) return 100; else if (_type == 2031 && _id == 2031) return 200; else if (_type == 6009 && _id == 6009) return 300; else if (_type == 6007 && _id == 6007) return 300; else if (_type == 6008 && _id == 6008) return 300; else if (_type == 2026 && _id == 2026) return 100; else if (_type == 2027 && _id == 2027) return 300; else if (_type == 2032 && _id == 2032) return 300; else if (_type == 2033 && _id == 2033) return 300; else if (_type == 6011 && _id == 6011) return 300; else if (_type == 2034 && _id == 2034) return 300; else if (_type == 2013 && _id == 14) return 300; else if (_type == 2014 && _id == 15) return 300; else if (_type == 2015 && _id == 16) return 300; else if (_type == 2016 && _id == 17) return 300; else if (_type == 2035 && _id == 2035) return 300; else if (_type == 2036 && _id == 2036) return 300; else if (_type == 2037 && _id == 2037) return 300; else if (_type == 2038 && _id == 2038) return 300; else if (_type == 2039 && _id == 2039) return 300; else if (_type == 2040 && _id == 2040) return 100; else if (_type == 2041 && _id == 2041) return 100; else if (_type == 2044 && _id == 2044) return 100; else if (_type == 2045 && _id == 2045) return 100; else if (_type == 6012 && _id == 6012) return 100; else if (_type == 2050 && _id == 2050) return 100; else if (_type == 2051 && _id == 2051) return 100; else if (_type == 2052 && _id == 2052) return 100; else if (_type == 2053 && _id == 2053) return 150; else if (_type == 2054 && _id == 2054) return 150; else if (_type == 2057 && _id == 2057) return 150; else if (_type == 2056 && _id == 2056) return 100; else if (_type == 2046 && _id == 2046) return 150; else if (_type == 2047 && _id == 2047) return 150; else if (_type == 2048 && _id == 2048) return 150; else if (_type == 2049 && _id == 2049) return 150; else if (_type == 2059 && _id == 2059) return 100; else if (_type == 2060 && _id == 2060) return 150; else if (_type == 2061 && _id == 2061) return 150; else if (_type == 2062 && _id == 2062) return 150; else if (_type == 6013 && _id == 6013) return 100; else if (_type == 6014 && _id == 6014) return 150; else if (_type == 6015 && _id == 6015) return 150; else if (_type == 6016 && _id == 6016) return 150; else if (_type == 6017 && _id == 6017) return 150; else if (_type == 2063 && _id == 2063) return 150; else if (_type == 2064 && _id == 2064) return 150; else if (_type == 2065 && _id == 2065) return 150; return 0; } public static t title<t>(int _type, int _id) { object value = null; int trash = 0; if (typeof(t) == typeof(bool)) { value = !int.tryparse(info.getunitbyid(_id, info.getstoragebytype(_type)).param, out trash); } else if (typeof(t) == typeof(int)) { var mytype = _type.tostring(); var myid = _id.tostring(); while (myid.length < 4) myid = "0" + myid; value = int.parse(mytype + myid); } else throw new exception("unknow type : " + typeof(t).name); return (t)convert.changetype(value, typeof(t)); } } public sealed class titlestorage { public titlestorage() { } public bool read(byte[] packet) { using (var memorystream = new memorystream(packet)) { info = serializer.deserializewithlengthprefix<titlestorageproto>(memorystream, prefixstyle.fixed32); } return true; } private bool collectedrandmonkey(client.gamestate client) { return client.entity.storageitems.values.where(p => monkeysvalues.contains(p.id)).tolist().count > 0 ? True : False; } private bool collectedcelestialfox(client.gamestate client) { return client.entity.storageitems.values.where(p => p.id == 200595).tolist().count > 0 ? True : False; } private bool collectedcelestialfoxfantasy(client.gamestate client) { return client.entity.storageitems.values.where(p => p.id == 200596).tolist().count > 0 ? True : False; } list<uint> monkeysvalues = new list<uint>() { 200553, 200554, 200555, 200556, 200557, 200558, 200559, 200560 }; private bool collected8typesmonkey(client.gamestate client) { list<uint> ids = new list<uint>(); var dict = client.entity.storageitems.values.tolist(); for (int x = 0; x < dict.count; x++) { if (monkeysvalues.contains(dict[x].id) && !ids.contains(dict[x].id)) { ids.add(dict[x].id); } } return ids.count == 8 ? True : False; } private bool collectedmonkey(client.gamestate client, uint id) { return client.entity.storageitems.values.where(p => p.id == id).tolist().count > 0 ? True : False; } public void checktitles(client.gamestate client) { if (client.entity.havealltitles) { getall(client); return; } #region titles and wings equips #region wings #region union emperor if (client.union != null) if (client.union.iskingdom()) if (client.union.isleader(client.entity.uid)) new titlestorage().addtitle(client, 4001, 1000, false); else new titlestorage().removetitle(client, 4001, 1000, false); else new titlestorage().removetitle(client, 4001, 1000, false); else new titlestorage().removetitle(client, 4001, 1000, false); #endregion #region the champion of elite pk tournament if (client.entity.titles.containskey(titlepacket.titles.elitepkchamption_high)) { datetime date = datetime.now; for (int i = datetime.now.day; i < 31; i++) { date = new datetime(datetime.now.year, datetime.now.month, i); if (date.dayofweek == dayofweek.friday) { date = new datetime(datetime.now.year, datetime.now.month, i, 19, 55, 0); break; } } if (date.day == datetime.now.day && date.hour == datetime.now.hour && date.year == datetime.now.year && date.minute == date.minute && datetime.now.dayofweek != dayofweek.friday) { for (int i = 1; i < 31; i++) { date = new datetime(datetime.now.year, datetime.now.month + 1, i); if (date.dayofweek == dayofweek.friday) { date = new datetime(datetime.now.year, datetime.now.month + 1, i, 19, 55, 0); break; } } } timespan timespan = date - datetime.now; int time = (int)(timespan.totalseconds); new titlestorage().addtitle(client, 6001, 20, false, time); } else new titlestorage().removetitle(client, 6001, 20, false); #endregion #region own a 5-star garment if (database.wardrobetable.amountstargarments(client, 5) >= 1) { new titlestorage().addtitle(client, 6003, 22, false); } else new titlestorage().removetitle(client, 6003, 22, false); #endregion #region own a 5-star mount armor if (database.wardrobetable.amountstarmounts(client, 5) >= 1) { new titlestorage().addtitle(client, 6004, 23, false); } else new titlestorage().removetitle(client, 6004, 23, false); #endregion #region prestige score reaches 600,000 if (client.entity.totalperfectionscore >= 600000) { new titlestorage().addtitle(client, 2026, 2026, false); } else new titlestorage().removetitle(client, 2026, 2026, false); #endregion #region stars score reaches 324 if (client.equipment.totalstars >= 324) { new titlestorage().addtitle(client, 6007, 6007, false); } else new titlestorage().removetitle(client, 6007, 6007, false); #endregion #region stars score reaches 216 if (client.equipment.totalstars >= 216) { new titlestorage().addtitle(client, 6008, 6008, false); } else new titlestorage().removetitle(client, 6008, 6008, false); #endregion #endregion #region titles #region union emperor if (client.union != null) if (client.union.iskingdom()) if (client.union.isleader(client.entity.uid)) new titlestorage().addtitle(client, 1, 1000, false); else new titlestorage().removetitle(client, 1, 1000, false); else new titlestorage().removetitle(client, 1, 1000, false); else new titlestorage().removetitle(client, 1, 1000, false); #endregion #region vip if (client.entity.viplevel > 0) { switch (client.entity.viplevel) { case 1: Case 2: Case 3: Case 4: { new titlestorage().addtitle(client, 2030, 2030, false); break; } case 5: Case 6: { new titlestorage().addtitle(client, 2029, 2029, false); break; } case 7: { new titlestorage().addtitle(client, 2031, 2031, false); break; } } } else { new titlestorage().removetitle(client, 2030, 2030, false); new titlestorage().removetitle(client, 2029, 2029, false); new titlestorage().removetitle(client, 2031, 2031, false); } #endregion #region collectedrandmonkey if (collectedrandmonkey(client)) { new titlestorage().addtitle(client, 2013, 14, false); } else { new titlestorage().removetitle(client, 2013, 14, false); } #endregion #region collect 8 kinds of permanent saint monkeys (can be activated via the wardrobe after the event) if (collected8typesmonkey(client)) { new titlestorage().addtitle(client, 2016, 17, false); } else { new titlestorage().removetitle(client, 2016, 17, false); } #endregion #region collect a permanent solar monkey if (collectedmonkey(client, 200559)) { new titlestorage().addtitle(client, 2014, 15, false); } else { new titlestorage().removetitle(client, 2014, 15, false); } #endregion #region collect a permanent lunar monkey if (collectedmonkey(client, 200560)) { new titlestorage().addtitle(client, 2015, 16, false); } else { new titlestorage().removetitle(client, 2015, 16, false); } #endregion #region tulip if (client.entity.myflowers != null && client.entity.myflowers.ranktuilps == 1) { new titlestorage().addtitle(client, 6005, 6005, false); } else { new titlestorage().removetitle(client, 6005, 6005, false); } #endregion #region the total score of chi study reaches 1.600 points if (client.chidata.dragonpoints == 400 && client.chidata.phoenixpoints == 400 && client.chidata.tigerpoints == 400 && client.chidata.turtlepoints == 400) { new titlestorage().addtitle(client, 2018, 1, false); } else { new titlestorage().removetitle(client, 2018, 1, false); } #endregion #region prestige score reaches 400,000 if (client.entity.totalperfectionscore >= 400000) { new titlestorage().addtitle(client, 2027, 2027, false); } else { new titlestorage().removetitle(client, 2027, 2027, false); } #endregion #region the total score of jiang hu training reaches 81,000 points(title) if (client.entity.myjiang != null && client.entity.myjiang.inner_strength >= 81000) { new titlestorage().addtitle(client, 2004, 5, false); } else { new titlestorage().removetitle(client, 2004, 5, false); } #endregion #region complete 320 achievement if (client.entity.myachievement.count(client.entity.uid) >= 320) { new titlestorage().addtitle(client, 2001, 2, false); } else { new titlestorage().removetitle(client, 2001, 2, false); } #endregion #region own 5 garments of 4-star or 5-star if (database.wardrobetable.amountstargarments(client, 4) >= 5) { new titlestorage().addtitle(client, 2005, 6, false); } else { new titlestorage().removetitle(client, 2005, 6, false); } #endregion #region own 5 mount of 4-star or 5-star if (database.wardrobetable.amountstarmounts(client, 4) >= 5) { new titlestorage().addtitle(client, 2006, 7, false); } else { new titlestorage().removetitle(client, 2006, 7, false); } #endregion #region celestialfox(200595) if (collectedcelestialfox(client)) { new titlestorage().addtitle(client, 2050, 2050, false); } else { new titlestorage().removetitle(client, 2050, 2050, false); } #endregion #region celestialfox(fantasy)(200596) if (collectedcelestialfoxfantasy(client)) { new titlestorage().addtitle(client, 2051, 2051, false); } else { new titlestorage().removetitle(client, 2051, 2051, false); } #endregion #endregion #endregion #region gm /*if (client.account.state == database.accounttable.accountstate.gamemaster) { foreach (var title in database.wardrobetable.titles.values) { addtitle(client, (short)title.type, (short)title.id); } }*/ #endregion } public void login(client.gamestate client, bool crossed = false, string val = "") { if (!crossed) { checktitles(client); using (var cmd = new database.mysqlcommand(database.mysqlcommandtype.select).select("entities").where("uid", client.account.entityid)) using (var reader = new database.mysqlreader(cmd)) { if (reader.read()) { if (reader.readstring("wardrobe") != "") { if (reader.readstring("wardrobe").contains("~")) { var wing = reader.readstring("wardrobe").split('~')[0]; int type = convert.toint32(wing.split('-')[0]); int id = convert.toint32(wing.split('-')[1]); if (client.entity.wings.containskey((uint)type) && client.entity.wings.containsvalue((uint)id)) { var pkt = new titlestorageproto() { actionid = action.update, points = client.entity.utitlepoints, type = type, id = id, value = new titlevalue() { type = type, id = id, equipped = true } }; client.send(finalizeprotobuf(pkt)); client.entity.equippedwing = storagemanager.wing<int>(type, id); client.entity.nowequippedwing.clear(); client.entity.nowequippedwing.add(type + "~" + id); } var title = reader.readstring("wardrobe").split('~')[1]; int type2 = convert.toint32(title.split('-')[0]); int id2 = convert.toint32(title.split('-')[1]); if (client.entity.wtitles.containskey((uint)type2) && client.entity.wtitles.containsvalue((uint)id2)) { var pkt = new titlestorageproto() { actionid = action.update, points = client.entity.utitlepoints, type = type2, id = id2, value = new titlevalue() { type = type2, id = id2, equipped = true } }; client.send(finalizeprotobuf(pkt)); client.entity.equippedtitle = storagemanager.title<int>(type2, id2); client.entity.nowequippedtitle.clear(); client.entity.nowequippedtitle.add(type2 + "~" + id2); } } } } } } else { if (val != "") { if (val.contains("~")) { checktitles(client); var wing = val.split('~')[0]; int type = convert.toint32(wing.split('-')[0]); int id = convert.toint32(wing.split('-')[1]); var pkt = new titlestorageproto() { actionid = action.update, points = client.entity.utitlepoints, type = type, id = id, value = new titlevalue() { type = type, id = id, equipped = true } }; client.send(finalizeprotobuf(pkt)); client.entity.equippedwing = storagemanager.wing<int>(type, id); client.entity.nowequippedwing.clear(); client.entity.nowequippedwing.add(type + "~" + id); var title = val.split('~')[1]; int type2 = convert.toint32(title.split('-')[0]); int id2 = convert.toint32(title.split('-')[1]); pkt.type = type2; pkt.id = id2; pkt.value.type = type2; pkt.value.id = id2; client.send(finalizeprotobuf(pkt)); client.entity.equippedtitle = storagemanager.title<int>(type2, id2); client.entity.nowequippedtitle.clear(); client.entity.nowequippedtitle.add(type2 + "~" + id2); } } } } public void handle(client.gamestate client) { switch (info.actionid) { case action.unequip: { if (storagemanager.wing<bool>(info.type, info.id)) { client.entity.equippedwing = 0; client.entity.nowequippedwing.clear(); } else if (storagemanager.title<bool>(info.type, info.id)) { client.entity.equippedtitle = 0; client.entity.nowequippedtitle.clear(); } client.send(finalizeprotobuf(info)); break; } case action.equip: { if (client.entity.utitlepoints < storagemanager.gettitlepoints((short)info.type, (short)info.id)) break; if (storagemanager.wing<bool>(info.type, info.id)) { client.entity.equippedwing = storagemanager.wing<int>(info.type, info.id); client.entity.nowequippedwing.clear(); client.entity.nowequippedwing.add(info.type + "~" + info.id); } else if (storagemanager.title<bool>(info.type, info.id)) { client.entity.equippedtitle = storagemanager.title<int>(info.type, info.id); client.entity.nowequippedtitle.clear(); client.entity.nowequippedtitle.add(info.type + "~" + info.id); } info = new titlestorageproto() { actionid = action.equip, points = client.entity.utitlepoints, type = info.type, id = info.id, }; client.send(finalizeprotobuf(info)); break; } } new titlestorage().checktitles(client); } public void getall(client.gamestate client) { foreach (var title in database.wardrobetable.titles.values) { addtitle(client, (short)title.type, (short)title.id, false); } client.entity.havealltitles = true; } public void addtitle(client.gamestate client, short _type, short _id, bool equipped = false, int timeinseconds = 0) { if (storagemanager.wing<bool>(_type, _id)) { if (!client.entity.wings.containsvalue((uint)_id)) client.entity.wings.add((uint)_type, (uint)_id); else return; } else { if (!client.entity.wtitles.containsvalue((uint)_id)) client.entity.wtitles.add((uint)_type, (uint)_id); else return; } client.entity.utitlepoints += storagemanager.gettitlepoints(_type, _id); var pkt = new titlestorageproto() { actionid = action.update, points = client.entity.utitlepoints, value = new titlevalue() { type = _type, id = _id, equipped = equipped, time = timeinseconds, } }; client.send(finalizeprotobuf(pkt)); if (equipped) { if (storagemanager.wing<bool>(_type, _id)) { client.entity.equippedwing = storagemanager.wing<int>(_type, _id); client.entity.nowequippedwing.clear(); client.entity.nowequippedwing.add(_type + "~" + _id); } else if (storagemanager.title<bool>(_type, _id)) { client.entity.equippedtitle = storagemanager.title<int>(_type, _id); client.entity.nowequippedtitle.clear(); client.entity.nowequippedtitle.add(_type + "~" + _id); } } } public void removetitle(client.gamestate client, short _type, short _id, bool equipped = false) { if (storagemanager.wing<bool>(_type, _id)) { if (client.entity.wings.containsvalue((uint)_id)) { client.entity.wings.remove((uint)_type); if (client.entity.equippedwing == storagemanager.wing<int>(_type, _id)) { client.entity.equippedwing = 0; client.entity.nowequippedwing.clear(); var pkt = new titlestorageproto() { actionid = action.unequip, id = _id, type = _type, points = client.entity.utitlepoints, value = new titlevalue() { type = _type, id = _id, equipped = false } }; client.send(finalizeprotobuf(pkt)); } client.entity.utitlepoints -= storagemanager.gettitlepoints(_type, _id); var pkt2 = new titlestorageproto() { actionid = action.removetitle, id = _id, type = _type, points = client.entity.utitlepoints, value = new titlevalue() { type = _type, id = _id, equipped = false } }; client.send(finalizeprotobuf(pkt2)); } else return; } else { if (client.entity.wtitles.containsvalue((uint)_id)) { client.entity.wtitles.remove((uint)_type); if (client.entity.equippedtitle == storagemanager.title<int>(_type, _id)) { client.entity.equippedtitle = 0; client.entity.nowequippedtitle.clear(); var pkt = new titlestorageproto() { actionid = action.unequip, id = _id, type = _type, points = client.entity.utitlepoints, value = new titlevalue() { type = _type, id = _id, equipped = false } }; client.send(finalizeprotobuf(pkt)); } client.entity.utitlepoints -= storagemanager.gettitlepoints(_type, _id); var pkt2 = new titlestorageproto() { actionid = action.removetitle, id = _id, type = _type, points = client.entity.utitlepoints, value = new titlevalue() { type = _type, id = _id, equipped = false } }; client.send(finalizeprotobuf(pkt2)); } else return; } } public byte[] finalizeprotobuf(titlestorageproto titlestorageproto) { using (var memorystream = new memorystream()) { serializer.serializewithlengthprefix(memorystream, titlestorageproto, prefixstyle.fixed32); var pkt = new byte[8 + memorystream.length]; memorystream.toarray().copyto(pkt, 0); writer.write((ushort)memorystream.length, 0, pkt); writer.write((ushort)3301, 2, pkt); return pkt; } } public titlestorageproto info; [flags] public enum action : Int { update = 0, usetitle = 1, removetitle = 3, equip = 4, unequip = 5, } } [protocontract] public class titlestorageproto { [protomember(1, isrequired = true)] public titlestorage.action actionid; [protomember(2, isrequired = true)] public int points; [protomember(3, isrequired = true)] public int type; [protomember(4, isrequired = true)] public int id; [protomember(5, isrequired = true)] public titlevalue value; } [protocontract] public class titlevalue { [protomember(1, isrequired = true)] public int type; [protomember(2, isrequired = true)] public int id; [protomember(3, isrequired = true)] public bool equipped; [protomember(4, isrequired = true)] public int time; } }