public static bool CreateCharacter(ClientManager MyClient, XHERO MyHero) { bool result = false; if (conn.State == ConnectionState.Open) { String timeStamp = GetTimestamp(DateTime.Now); MySqlCommand cmd = new MySqlCommand(); cmd.Connection = conn; cmd.CommandText = "INSERT INTO u_hero(id_idx, hero_order, serial, name, hero_type, now_zone_idx, init_pos_layer, revive_zone_idx, baselevel, speed_move, str, dex, aim, luck, res_fire, res_water, res_earth, res_wind, res_devil, hc, hd, ap, dp, hp, mp, regdate, avatar_head, last_logout_time, skill_point)VALUES(@ID, @HERO_ORDER, @SERIAL, @NAME, @HERO_TYPE, @NOW_ZONE_IDX, @INIT_POS_LAYER, @REVIVE_ZONE_IDX, @BASELEVEL, @SPEEDMOVE, @STR, @DEX, @AIM, @LUCK, @RES_FIRE, @RES_WATER, @RES_EARTH, @RES_WIND, @RES_DEVIL, @HC, @HD, @AP, @DP, @HP, @MP, @REGDATE, @AVATAR_HEAD, @LAST_LOGOUT_TIME, @SKILL_POINT);"; cmd.Parameters.AddWithValue("@ID", MyClient.data.id_idx); cmd.Parameters.AddWithValue("@HERO_ORDER", MyHero.hero_order); cmd.Parameters.AddWithValue("@SERIAL", timeStamp); cmd.Parameters.AddWithValue("@NAME", MyHero.name); cmd.Parameters.AddWithValue("@HERO_TYPE", MyHero.hero_type); cmd.Parameters.AddWithValue("@NOW_ZONE_IDX", 130); // mapa inicial cmd.Parameters.AddWithValue("@INIT_POS_LAYER", 255); // layer inicial cmd.Parameters.AddWithValue("@REVIVE_ZONE_IDX", 130); // mapa inicial - revive cmd.Parameters.AddWithValue("@BASELEVEL", 1); // lv inicial cmd.Parameters.AddWithValue("@SPEEDMOVE", 4); // velocidade char inicial cmd.Parameters.AddWithValue("@STR", MyHero.Energia); // energia cmd.Parameters.AddWithValue("@DEX", MyHero.Agilidade); // agilidade cmd.Parameters.AddWithValue("@AIM", MyHero.Exatidao); // exaltidao cmd.Parameters.AddWithValue("@LUCK", MyHero.Sorte); // sorte cmd.Parameters.AddWithValue("@RES_FIRE", 0); cmd.Parameters.AddWithValue("@RES_WATER", 0); cmd.Parameters.AddWithValue("@RES_EARTH", 0); cmd.Parameters.AddWithValue("@RES_WIND", 0); cmd.Parameters.AddWithValue("@RES_DEVIL", 0); cmd.Parameters.AddWithValue("@HC", 1); cmd.Parameters.AddWithValue("@HD", 1); cmd.Parameters.AddWithValue("@AP", 3); cmd.Parameters.AddWithValue("@DP", 3); cmd.Parameters.AddWithValue("@HP", 16); // hp auto calcule by ZoneServer cmd.Parameters.AddWithValue("@MP", 14); // mp auto calcule by ZoneServer DateTime localDate = DateTime.Now; string time = localDate.ToString("yyyy-MM-dd HH:mm:ss"); //Console.WriteLine("Time: " + time); cmd.Parameters.AddWithValue("@REGDATE", time); // horario atual do servidor cmd.Parameters.AddWithValue("@AVATAR_HEAD", MyHero.avatar_head); // avatar head cmd.Parameters.AddWithValue("@LAST_LOGOUT_TIME", 0); // 0 cmd.Parameters.AddWithValue("@SKILL_POINT", 0); // skill points iniciais MySqlDataReader reader = cmd.ExecuteReader(); if (reader.RecordsAffected > 0) { result = true; } else { result = false; } reader.Close(); } return(result); }
private static void ProcessCreateHeroReceive(ClientManager MyClient, byte[] PacketData) { using (MemoryStream ms = new MemoryStream(PacketData)) { using (BinaryReader br = new BinaryReader(ms, Encoding.UTF8)) { br.ReadInt32(); // id_idx br.ReadByte(); // byte null br.ReadByte(); // packet type byte Hero_Type = br.ReadByte(); short Energia = br.ReadInt16(); short Agilidade = br.ReadInt16(); short Exatidao = br.ReadInt16(); short Sorte = br.ReadInt16(); short unknow = br.ReadInt16(); short unknow2 = br.ReadInt16(); byte hero_order = br.ReadByte(); string heroname = ""; char c; while ((c = br.ReadChar()) != (char)0x00) { heroname += c; } // verificar se os tributos recebidos estão dentro do limite suportado // verificar o tamanho do nome do personagem, se passar de 12 descarta XHERO MyHero = new XHERO(); MyHero.avatar_head = (int)unknow2; MyHero.hero_type = (int)Hero_Type; MyHero.name = heroname; MyHero.hero_order = hero_order; MyHero.Agilidade = Agilidade; MyHero.Energia = Energia; MyHero.Exatidao = Exatidao; MyHero.Sorte = Sorte; if (!Database.gamedata.CharacterNameExists(heroname)) { if (Database.gamedata.CreateCharacter(MyClient, MyHero)) { SendData.SendResponseCreateHero(MyClient, 0); // create success } else { SendData.SendResponseCreateHero(MyClient, 2); // create failed } } else { SendData.SendResponseCreateHero(MyClient, 1); // username exist } } } }
public void LoadMyItems(XHERO hero) { try { if (conn.State == ConnectionState.Open) { MySqlCommand cmd = new MySqlCommand(); cmd.Connection = conn; cmd.CommandText = "select * from u_item WHERE id_idx = @id and hero_order = @order;"; cmd.Parameters.AddWithValue("@id", hero.zs_data.ID_IDX); cmd.Parameters.AddWithValue("@order", hero.zs_data.HERO_ORDER); MySqlDataReader reader = cmd.ExecuteReader(); if (reader.HasRows) { while (reader.Read()) { CItem item = new CItem(hero); item.id = reader.GetUInt32(3); item.socket_type = reader.GetByte(4); item.socket_num = reader.GetByte(5); item.count = reader.GetUInt16(6); item.opt = reader.GetByte(7); item.opt_level = reader.GetByte(8); item.duration = reader.GetUInt32(9); item.last_check_time = reader.GetDateTime(10); item.synergy = reader.GetByte(11); item.synergy_level = reader.GetByte(12); hero.AddItem(item); Console.WriteLine("item adicionado!"); } } else { reader.Close(); } reader.Close(); } } catch { } }
public static List <XHERO> GetAllHeroesFromID(int id_idx) { List <XHERO> Heroes = new List <XHERO>(); //Console.WriteLine("Gettind characters!"); if (conn.State == ConnectionState.Open) { MySqlCommand cmd = new MySqlCommand(); cmd.Connection = conn; cmd.CommandText = "select hero_order, serial, class, name, hero_type, baselevel, avatar_head, status, status_time from u_hero WHERE id_idx = @id ORDER BY hero_order asc;"; cmd.Parameters.AddWithValue("@id", id_idx); MySqlDataReader reader = cmd.ExecuteReader(); //Console.WriteLine("Columns:" + reader.FieldCount); while (reader.Read()) { XHERO temp = new XHERO(); temp.id_idx = id_idx; temp.hero_order = reader.GetInt32(0); temp.serial = reader.GetInt64(1); temp.hero_class = reader.GetInt32(2); temp.name = reader.GetString(3); temp.hero_type = reader.GetInt32(4); temp.baselevel = reader.GetInt32(5); temp.avatar_head = reader.GetInt32(6); temp.status = reader.GetInt32(7); DateTime status_time = reader.GetDateTime(reader.GetOrdinal("status_time")); temp.status_time = (int)ClientFunctions.GetTotalSecondsFromDateTime(status_time); // Console.WriteLine("Status_time: " + ClientFunctions.GetTotalSecondsFromDateTime(status_time)); //Console.WriteLine("Status_time: " + status_time.ToString("yyyy - MM - dd HH: mm:ss")); Heroes.Add(temp); } reader.Close(); } return(Heroes); }
public void LoadMixSkill(XHERO hero) { try { if (conn.State == ConnectionState.Open) { MySqlCommand cmd = new MySqlCommand(); cmd.Connection = conn; cmd.CommandText = "select * from u_MixSkill WHERE HeroIdx = @id and HeroOrder = @order;"; cmd.Parameters.AddWithValue("@id", hero.zs_data.ID_IDX); cmd.Parameters.AddWithValue("@order", hero.zs_data.HERO_ORDER); MySqlDataReader reader = cmd.ExecuteReader(); if (reader.HasRows) { while (reader.Read()) { hero.mixSkill.MixSkill1 = reader.GetUInt16(2); hero.mixSkill.MixSkill2 = reader.GetUInt16(3); hero.mixSkill.MixSkill3 = reader.GetUInt16(4); hero.mixSkill.MixSkill4 = reader.GetUInt16(5); hero.mixSkill.MixSkill5 = reader.GetUInt16(6); hero.mixSkill.MixSkill6 = reader.GetUInt16(7); hero.mixSkill.MixSkill7 = reader.GetUInt16(8); hero.mixSkill.MixSkill8 = reader.GetUInt16(9); hero.mixSkill.MixSkill9 = reader.GetUInt16(10); hero.mixSkill.MixSkill10 = reader.GetUInt16(11); Console.WriteLine("MixSkill setado!"); } } else { reader.Close(); } reader.Close(); } } catch { } }
public void LoadMySkills(XHERO hero) { try { if (conn.State == ConnectionState.Open) { MySqlCommand cmd = new MySqlCommand(); cmd.Connection = conn; cmd.CommandText = "select * from u_heroskill WHERE heroIndex = @id and heroSocketNum = @order;"; cmd.Parameters.AddWithValue("@id", hero.zs_data.ID_IDX); cmd.Parameters.AddWithValue("@order", hero.zs_data.HERO_ORDER); MySqlDataReader reader = cmd.ExecuteReader(); if (reader.HasRows) { while (reader.Read()) { CSkill skill = new CSkill(hero); skill.skillID = reader.GetByte(2); skill.skillLevel = reader.GetByte(3); skill.skillPoint = reader.GetUInt16(4); skill.learningDate = reader.GetDateTime(5); hero.AddSkill(skill); Console.WriteLine("skill adicionada!"); } } else { reader.Close(); } reader.Close(); } } catch { } }
public void LoadMyQuests(XHERO hero) { try { if (conn.State == ConnectionState.Open) { MySqlCommand cmd = new MySqlCommand(); cmd.Connection = conn; cmd.CommandText = "select * from u_QuestLog WHERE id_idx = @id and hero_order = @order;"; cmd.Parameters.AddWithValue("@id", hero.zs_data.ID_IDX); cmd.Parameters.AddWithValue("@order", hero.zs_data.HERO_ORDER); MySqlDataReader reader = cmd.ExecuteReader(); if (reader.HasRows) { while (reader.Read()) { CQuest quest = new CQuest(hero); quest.quest_index = reader.GetUInt16(2); quest.quest_state = reader.GetByte(3); hero.AddQuest(quest); } } else { reader.Close(); } reader.Close(); } } catch { return; } }
public void LoadMyHenchs(XHERO hero) { try { if (conn.State == ConnectionState.Open) { MySqlCommand cmd = new MySqlCommand(); cmd.Connection = conn; cmd.CommandText = "SELECT * FROM u_hench_0 WHERE id_idx = @ID AND hero_order = @HERO_ORDER UNION SELECT * FROM u_hench_1 WHERE id_idx = @ID AND hero_order = @HERO_ORDER UNION SELECT * FROM u_hench_2 WHERE id_idx = @ID AND hero_order = @HERO_ORDER UNION SELECT * FROM u_hench_3 WHERE id_idx = @ID AND hero_order = @HERO_ORDER UNION SELECT * FROM u_hench_4 WHERE id_idx = @ID AND hero_order = @HERO_ORDER UNION SELECT * FROM u_hench_5 WHERE id_idx = @ID AND hero_order = @HERO_ORDER UNION SELECT * FROM u_hench_6 WHERE id_idx = @ID AND hero_order = @HERO_ORDER UNION SELECT * FROM u_hench_7 WHERE id_idx = @ID AND hero_order = @HERO_ORDER UNION SELECT * FROM u_hench_8 WHERE id_idx = @ID AND hero_order = @HERO_ORDER UNION SELECT * FROM u_hench_9 WHERE id_idx = @ID AND hero_order = @HERO_ORDER order by hench_order asc;"; cmd.Parameters.AddWithValue("@ID", hero.zs_data.ID_IDX); cmd.Parameters.AddWithValue("@HERO_ORDER", hero.zs_data.HERO_ORDER); MySqlDataReader reader = cmd.ExecuteReader(); if (reader.HasRows) { while (reader.Read()) { XHENCH_INFO hench = new XHENCH_INFO(hero); hench.position = reader.GetByte(3); hench.hench_order = reader.GetByte(4); hench.HenchID = reader.GetUInt16(5); hench.HenchName = reader.GetString(6); hench.sex = reader.GetByte(7); hench.IsDead = reader.GetBoolean(8); hench.mixnum = (byte)reader.GetInt16(9); hench.hench_lv = reader.GetUInt16(10); hench.hench_lvmax = reader.GetUInt16(11); hench.hench_exp = reader.GetInt64(12); long back = (long)Init.game.sdata.lvUserInfo[hench.hench_lv].LvUpExp; // back lv long next = 500; hench.hench_exp_backlevel = back; hench.hench_exp_nextlevel = next; hench.str = reader.GetUInt16(16); hench.dex = reader.GetUInt16(17); hench.aim = reader.GetUInt16(18); hench.luck = reader.GetUInt16(19); hench.ap = reader.GetUInt16(20); hench.dp = reader.GetUInt16(21); hench.hc = reader.GetUInt16(22); hench.hd = reader.GetUInt16(23); hench.hp = reader.GetUInt32(24); hench.mp = reader.GetUInt32(25); hench.max_hp = 65535; // example hench.max_mp = 65535; // example hench.growthtype = (byte)reader.GetInt16(31); hench.race_val = reader.GetUInt16(32); hench.enchant_grade = (byte)reader.GetInt16(35); hench.item_slot_total = (byte)reader.GetInt16(36); hench.item0_idx = reader.GetUInt16(37); hench.item0_duration = reader.GetUInt32(39); hench.item1_idx = reader.GetUInt16(40); hench.item1_duration = reader.GetUInt32(42); hench.item2_idx = reader.GetUInt16(43); hench.item2_duration = reader.GetUInt32(45); hench.duration = reader.GetInt32(46); if (hench.position == 0) { hero.AddBattleHench(new XBATTLE_HENCH(hench)); } else { hero.AddHench(hench); } } } else { reader.Close(); } reader.Close(); } } catch (Exception e) { Console.WriteLine("Hench load filed!" + e.Message); } }
public void LoadMyHero(XHERO hero) { try { if (conn.State == ConnectionState.Open) { Console.WriteLine("[DATABASE] Pegando dados do personagem!"); MySqlCommand cmd = new MySqlCommand(); cmd.Connection = conn; cmd.CommandText = "select * from u_hero WHERE id_idx = @ID AND hero_order = @ORDER;"; cmd.Parameters.AddWithValue("@ID", hero.zs_data.ID_IDX); cmd.Parameters.AddWithValue("@ORDER", hero.zs_data.HERO_ORDER); MySqlDataReader reader = cmd.ExecuteReader(); if (reader.HasRows) { while (reader.Read()) { hero.id_idx = reader.GetUInt32(0); hero.hero_order = reader.GetByte(1); hero.serial = reader.GetInt64(2); hero.Class = reader.GetByte(3); hero.name = reader.GetString(4); hero.hero_type = reader.GetByte(5); hero.now_zone_idx = reader.GetUInt16(6); hero.now_zone_x = reader.GetByte(7); hero.now_zone_y = reader.GetByte(8); hero.init_pos_layer = reader.GetUInt16(9); hero.revive_zone_idx = reader.GetUInt16(10); hero.baselevel = reader.GetUInt16(11); hero.gold = reader.GetUInt32(12); hero.attr = reader.GetUInt32(13); hero.exp = reader.GetInt64(14); hero.speed_move = reader.GetByte(15); hero.speed_attack = reader.GetUInt16(16); hero.speed_skill = reader.GetUInt16(17); hero.str = reader.GetUInt32(18); hero.dex = reader.GetUInt32(19); hero.aim = reader.GetUInt32(20); hero.luck = reader.GetUInt32(21); hero.ap = reader.GetUInt16(22); hero.dp = reader.GetUInt16(23); hero.hc = reader.GetUInt16(24); hero.hd = reader.GetUInt16(25); hero.hp = reader.GetUInt32(26); hero.mp = reader.GetUInt32(27); hero.maxhp = reader.GetUInt32(28); hero.maxmp = reader.GetUInt32(29); hero.abil_freepoint = reader.GetUInt32(30); hero.res_fire = reader.GetUInt16(31); hero.res_water = reader.GetUInt16(32); hero.res_earth = reader.GetUInt16(33); hero.res_wind = reader.GetUInt16(34); hero.res_devil = reader.GetUInt16(35); hero.ign_att_cnt = reader.GetByte(36); hero.regdate = reader.GetDateTime(37); hero.avatar_head = reader.GetUInt16(38); hero.avatar_body = reader.GetUInt16(39); hero.avatar_foot = reader.GetUInt16(40); hero.return_time = reader.GetUInt32(41); hero.status = reader.GetByte(42); hero.status_time = reader.GetDateTime(43); hero.nickname = reader.GetUInt16(44); hero.last_logout_time = reader.GetDateTime(45); hero.skill_point = reader.GetUInt32(46); hero.login = reader.GetByte(47); } } reader.Close(); } } catch { } }