internal void EquipItem(int wearType, uint itemHandle) { if (!this.Inventory.ContainsKey(itemHandle)) { ConsoleUtils.Write(ConsoleMsgType.Error, "Trying to access invalid handle in player inventory.\n"); return; } Item i = this.Inventory[itemHandle]; this.Equip[(int)i.WearInfo] = itemHandle; ClientPacketHandler.send_WearChange(this, itemHandle, (short)i.WearInfo, this.Inventory[itemHandle].Enhance); if (Stats.PCCalculate(this)) { ClientPacketHandler.send_UpdateStats(this, false); ClientPacketHandler.send_UpdateStats(this, true); } ClientPacketHandler.send_Property(this, "max_havoc", Globals.MaxHavoc); ClientPacketHandler.send_Property(this, "max_chaos", Globals.MaxChaos); ClientPacketHandler.send_Property(this, "max_stamina", Globals.MaxStamina); ClientPacketHandler.send_PacketResponse(this, 0x00C8); ClientPacketHandler.send_CharacterView(this); }
internal void UnequipItem(int wearType) { uint handle = this.Equip[wearType]; if (handle == 0) { ConsoleUtils.Write(ConsoleMsgType.Error, "Trying to unequip inexistant item."); return; } this.Equip[wearType] = 0; ClientPacketHandler.send_WearChange(this, handle, -1, this.Inventory[handle].Enhance); if (Stats.PCCalculate(this)) { ClientPacketHandler.send_UpdateStats(this, false); ClientPacketHandler.send_UpdateStats(this, true); } ClientPacketHandler.send_Property(this, "max_havoc", Globals.MaxHavoc); ClientPacketHandler.send_Property(this, "max_chaos", Globals.MaxChaos); ClientPacketHandler.send_Property(this, "max_stamina", Globals.MaxStamina); ClientPacketHandler.send_PacketResponse(this, 0x00C9); ClientPacketHandler.send_CharacterView(this); }
/// <summary> /// Sets the character's position /// </summary> /// <param name="jobLv"></param> private void SetPosition(float x, float y, byte layer) { this.Position = new Point(x, y); this.Layer = layer; ClientPacketHandler.send_Property(this, "x", 0, true, this.Position.X.ToString()); ClientPacketHandler.send_Property(this, "y", 0, true, this.Position.Y.ToString()); ClientPacketHandler.send_Property(this, "layer", 0, true, this.Layer.ToString()); }
/// <summary> /// Tries to Level UP character Job /// </summary> internal void JobLevelUp() { int reqJp = 0; switch (JobId2Depth(this.Job)) { case Db.JobDepth.Basic: reqJp = Jp0Table[this.JobLevel]; break; case Db.JobDepth.First: reqJp = Jp1Table[this.JobLevel]; break; case Db.JobDepth.Second: reqJp = Jp2Table[this.JobLevel]; break; case Db.JobDepth.Master: reqJp = Jp3Table[this.JobLevel]; break; } if (reqJp <= 0) // Max level reached { return; } else if (this.JP < reqJp) // Not enough JP { return; } this.JP -= reqJp; this.JobLevel++; ClientPacketHandler.send_Property(this, "jp", this.JP); ClientPacketHandler.send_Property(this, "job_level", this.JobLevel); ClientPacketHandler.send_UpdateStats(this, false); ClientPacketHandler.send_UpdateStats(this, true); ClientPacketHandler.send_Property(this, "max_havoc", this.MaxHavoc); ClientPacketHandler.send_Property(this, "max_chaos", this.MaxChaos); ClientPacketHandler.send_Property(this, "max_stamina", this.MaxStamina); ClientPacketHandler.send_PacketResponse(this, 0x019A, 0, this.Handle); }
/// <summary> /// Loads a character data /// </summary> /// <param name="charName">the name of the character</param> /// <returns>true on success, false otherwise</returns> internal bool LoadCharacter(string charName) { Database db = new Database(Server.UserDbConString); // TODO : Query CleanUP MySqlDataReader reader = db.ReaderQuery( "SELECT `char_id`,`slot`,`sex`,`race`," + "`hair_id`,`face_id`,`body_id`,`hands_id`,`feet_id`," + "`face_detail_id`,`hair_color`,`skin_color`,`x`,`y`,`layer`," + "`save_x`,`save_y`,`level`,`exp`,`job`,`job_level`, `client_info`," + "`jp`" + " FROM `char`" + " WHERE `account_id` = @accId AND `name` = @name AND `delete_date`= 0", new string[] { "accId", "name" }, new object[] { this.AccountId, charName } ); if (!reader.Read()) { // Character not in account ConsoleUtils.Write(ConsoleMsgType.Warning, "User trying to get a character that is not in his account.\n"); return(false); } this.MaxStamina = Globals.MaxStamina; this.MaxChaos = 0; this.MaxHavoc = 0; this.Gold = 0; this.Chaos = 0; this.TP = 0; this.HairColor = (int)reader["hair_color"]; this.HairId = (int)reader["hair_id"]; this.FaceId = (int)reader["face_id"]; this.BodyId = (int)reader["body_id"]; this.HandsId = (int)reader["hands_id"]; this.FeetId = (int)reader["feet_id"]; this.Name = charName; this.Race = (Races)(int)reader["race"]; this.Sex = (int)reader["sex"]; // TODO : FIX this.SkinColor = (uint)(int)reader["skin_color"]; this.CharId = (int)reader["char_id"]; this.Position = new Point((int)reader["x"], (int)reader["y"]); this.Layer = (byte)(int)reader["layer"]; this.ClientInfo = (string)reader["client_info"]; this.LoadQuest(); this.RegionX = RegionMngr.GetRegionX(this.Position.X); this.RegionY = RegionMngr.GetRegionY(this.Position.Y); //==== Character level/job/skills/buffs loading this.Level = (int)reader["level"]; this.Job = (short)reader["job"]; this.JobLevel = (int)reader["job_level"]; this.JP = (long)reader["jp"]; this.LoadInventory(); this.LoadSummons(); this.LoadStats(); this.LoadSkills(); // TODO Most of these packets probably can be placed in their own methods ClientPacketHandler.send_UpdateStats(this, false); ClientPacketHandler.send_UpdateStats(this, true); ClientPacketHandler.send_Property(this, "max_havoc", this.MaxHavoc); ClientPacketHandler.send_Property(this, "max_chaos", this.MaxChaos); ClientPacketHandler.send_Property(this, "max_stamina", this.MaxStamina); ClientPacketHandler.send_LoginResult(this); ClientPacketHandler.send_InventoryList(this); ClientPacketHandler.send_EquipSummon(this); ClientPacketHandler.send_CharacterView(this); ClientPacketHandler.send_UpdateGoldChaos(this); ClientPacketHandler.send_Property(this, "tp", this.TP); ClientPacketHandler.send_Property(this, "chaos", this.Chaos); ClientPacketHandler.send_UpdateLevel(this); ClientPacketHandler.send_UpdateExp(this); ClientPacketHandler.send_Property(this, "job", this.Job); ClientPacketHandler.send_Property(this, "job_level", this.JobLevel); ClientPacketHandler.send_Property(this, "job_0", 0); ClientPacketHandler.send_Property(this, "jlv_0", 0); ClientPacketHandler.send_Property(this, "job_1", 0); ClientPacketHandler.send_Property(this, "jlv_1", 0); ClientPacketHandler.send_Property(this, "job_2", 0); ClientPacketHandler.send_Property(this, "jlv_2", 0); if (this.SkillList.Count > 0) { ClientPacketHandler.send_SkillList(this, this.SkillList.Values.ToArray()); } ClientPacketHandler.send_Packet404(this); ClientPacketHandler.send_Packet1005(this); ClientPacketHandler.send_BeltSlotInfo(this); ClientPacketHandler.send_GameTime(this); ClientPacketHandler.send_Property(this, "huntaholic_point", 0); ClientPacketHandler.send_Property(this, "huntaholic_ent", 12); ClientPacketHandler.send_Property(this, "ap", 0); ClientPacketHandler.send_Packet4700(this); ClientPacketHandler.send_Property(this, "alias", 0, true, ""); ClientPacketHandler.send_Property(this, "ethereal_stone", 0); ClientPacketHandler.send_Property(this, "dk_count", 0); ClientPacketHandler.send_Property(this, "pk_count", 0); ClientPacketHandler.send_Property(this, "immoral", 0); ClientPacketHandler.send_Property(this, "stamina", 0); ClientPacketHandler.send_Property(this, "max_stamina", this.MaxStamina); ClientPacketHandler.send_Property(this, "channel", 1); ClientPacketHandler.send_EntityState(this); if (this.ClientInfo != "") { ClientPacketHandler.send_Property(this, "client_info", 0, true, this.ClientInfo); } ClientPacketHandler.send_QuestList(this); ClientPacketHandler.send_Packet625(this); ClientPacketHandler.send_Packet626(this); ClientPacketHandler.send_Packet627(this); ClientPacketHandler.send_Packet629(this); ClientPacketHandler.send_Packet631(this, 1); ClientPacketHandler.send_Packet631(this, 2); ClientPacketHandler.send_Packet631(this, 3); ClientPacketHandler.send_Packet631(this, 4); ClientPacketHandler.send_Packet631(this, 5); //PacketParser.send_Packet22(sid, 2); //PacketParser.send_Packet22(sid, 3); ClientPacketHandler.send_Property(this, "playtime", 0); ClientPacketHandler.send_Property(this, "playtime_limit1", 1080000); ClientPacketHandler.send_Property(this, "playtime_limit2", 1800000); ClientPacketHandler.send_LocationInfo(this); ClientPacketHandler.send_WeatherInfo(this); ClientPacketHandler.send_Property(this, "playtime", 0); //PacketParser.send_Packet22(sid, 4); //PacketParser.send_Packet08(sid, 1); ///ClientPacketHandler.send_GameTime(this); //PacketParser.send_Packet1101(this, 2); ///ClientPacketHandler.send_LocationInfo(this); ClientPacketHandler.send_Property(this, "stamina_regen", 30); ClientPacketHandler.send_UpdateStats(this, false); ClientPacketHandler.send_UpdateStats(this, true); return(true); }
public static void LevelUp(GameObject obj, int skillId, byte targetLv) { if (!SkillDb.DB.ContainsKey(skillId)) // Skill doesn't exists { return; } if (obj.Type == GameObjectType.Player) { Player player = (Player)obj; short curLevel = 0; bool haveSkill = false; if (player.SkillList.ContainsKey(skillId)) { curLevel = player.SkillList[skillId].Level; haveSkill = true; } int jpCost = SkillDb.DB[skillId].RequiredJp[targetLv]; if (jpCost > player.JP) { return; } player.JP -= jpCost; if (haveSkill) { Database db = new Database(Server.UserDbConString); player.SkillList[skillId].Level = targetLv; db.WriteQuery( "UPDATE `skill` SET `level` = @level WHERE `char_id` = @cid AND `id` = @skid", new string[] { "level", "cid", "skid" }, new object[] { player.SkillList[skillId].Level, player.CharId, skillId } ); } else { Skill skill = new Skill() { Id = skillId, Level = targetLv, TotalCooldown = SkillDb.DB[skillId].CooldownTime }; Database db = new Database(Server.UserDbConString); player.SkillList.Add(skillId, skill); db.WriteQuery( "INSERT INTO `skill` (`char_id`, `id`, `level`) VALUES (@cid, @skid, @level)", new string[] { "level", "cid", "skid" }, new object[] { player.SkillList[skillId].Level, player.CharId, skillId } ); } ClientPacketHandler.send_Property(player, "tp", player.TP); ClientPacketHandler.send_UpdateExp(player); //ClientPacketHandler.send_UpdateStats(this, false); //ClientPacketHandler.send_UpdateStats(this, true); //ClientPacketHandler.send_Property(this, "max_havoc", this.MaxHavoc); //ClientPacketHandler.send_Property(this, "max_chaos", this.MaxChaos); //ClientPacketHandler.send_Property(this, "max_stamina", this.MaxStamina); ClientPacketHandler.send_SkillList(player, new Skill[] { player.SkillList[skillId] }); ClientPacketHandler.send_PacketResponse(player, 0x0192, 0, (uint)skillId); } }