Esempio n. 1
0
        /// <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);
        }