Example #1
0
        public bool LoadCharacters()
        {
            if (!Authenticated)
            {
                return(false);
            }
            Characters = new Dictionary <byte, WorldCharacter>();
            try
            {
                DataTable charData = null;
                using (DatabaseClient dbClient = Program.DatabaseManager.GetClient())
                {
                    charData = dbClient.ReadDataTable("SELECT * FROM Characters WHERE AccountID='" + this.AccountID + "'");
                }

                if (charData != null)
                {
                    foreach (DataRow row in charData.Rows)
                    {
                        Database.Storage.Character ch = new Database.Storage.Character();
                        ch.PositionInfo.ReadFromDatabase(row);
                        ch.LookInfo.ReadFromDatabase(row);
                        ch.CharacterStats.ReadFromDatabase(row);
                        ch.Slot           = (byte)row["Slot"];
                        ch.CharLevel      = (byte)row["Level"];
                        ch.AccountID      = this.AccountID;
                        ch.Name           = (string)row["Name"];
                        ch.ID             = GetDataTypes.GetInt(row["CharID"]);
                        ch.Job            = (byte)row["Job"];
                        ch.Money          = GetDataTypes.GetLong(row["Money"].ToString());
                        ch.Exp            = long.Parse(row["Exp"].ToString());
                        ch.HP             = int.Parse(row["CurHP"].ToString());
                        ch.HPStones       = 10;
                        ch.MasterJoin     = DateTime.Parse(row["MasterJoin"].ToString());
                        ch.SP             = int.Parse(row["CurSP"].ToString());
                        ch.SPStones       = 10;
                        ch.StatPoints     = (byte)row["StatPoints"];
                        ch.UsablePoints   = (byte)row["UsablePoints"];
                        ch.Fame           = 0; // TODO
                        ch.GameSettings   = Database.DataStore.ReadMethods.GetGameSettings(ch.ID, Program.DatabaseManager);
                        ch.ClientSettings = Database.DataStore.ReadMethods.GetClientSettings(ch.ID, Program.DatabaseManager);
                        ch.Shortcuts      = Database.DataStore.ReadMethods.GetShortcuts(ch.ID, Program.DatabaseManager);
                        ch.QuickBar       = Database.DataStore.ReadMethods.GetQuickBar(ch.ID, Program.DatabaseManager);
                        ch.QuickBarState  = Database.DataStore.ReadMethods.GetQuickBarState(ch.ID, Program.DatabaseManager);
                        ch.ReviveCoper    = GetDataTypes.GetLong(row["MasterReciveMoney"]);
                        if (row.IsNull("GroupID"))
                        {
                            ch.GroupId = -1;
                        }
                        else
                        {
                            ch.GroupId = long.Parse(row["GroupID"].ToString());
                        }

                        if (ch.GroupId == -1 || row.IsNull("IsGroupMaster"))
                        {
                            ch.IsGroupMaster = false;
                        }
                        else
                        {
                            ch.IsGroupMaster = ReadMethods.EnumToBool(row["IsGroupMaster"].ToString());
                        }

                        Characters.Add(ch.Slot, new WorldCharacter(ch, this));
                    }
                }
            }
            catch (Exception ex)
            {
                Log.WriteLine(LogLevel.Exception, "Error loading characters from {0}: {1}", Username, ex.InnerException.ToString());
                return(false);
            }
            return(true);
        }
Example #2
0
        public WorldCharacter CreateCharacter(string name, byte slot, byte hair, byte color, byte face, Job job, bool ismale)
        {
            if (Characters.ContainsKey(slot) || slot > 5)
                return null;
            //TODO: check if hair etc are actual beginner ones! (premium hack)
            //NOTE: Check the SHN's for this -> Moved to database
            BaseStatsEntry stats = DataProvider.Instance.JobBasestats[job];
            if (stats == null)
            {
                //NOTE be serious.. please
                // Log.WriteLine(LogLevel.Warn, "Houston, we have a problem! Jobstats not found for job {0}", job.ToString());
                Log.WriteLine(LogLevel.Error, "Jobstats not found for job {0}", job.ToString());
                return null;
            }
            Database.Storage.LookInfo newLook = new Database.Storage.LookInfo();
            Database.Storage.PositionInfo newPos = new Database.Storage.PositionInfo();
            Database.Storage.Character newchar = new Database.Storage.Character();
            newchar.AccountID = this.AccountID;
            newchar.CharLevel = 1;
            newchar.Name = name;
            newLook.Face = face;
            newLook.Hair = hair;
            newLook.HairColor = color;
            newchar.Job = (byte)job;
            newLook.Male = ismale;
            newchar.Slot = slot;
            newPos.XPos = 7636;
            newPos.YPos = 4610;
            newchar.HP = (short)stats.MaxHP;
            newchar.SP = (short)stats.MaxSP;
            newchar.HPStones = (short)stats.MaxHPStones;
            newchar.SPStones = (short)stats.MaxSPStones;
            newchar.LookInfo = newLook;
            newchar.PositionInfo = newPos;
            int charID = newchar.ID;
             DatabaseClient client = Program.DatabaseManager.GetClient();

             string query =
                 "INSERT INTO `characters` " +
                 "(`AccountID`,`Name`,`MasterJoin`,`Slot`,`Job`,`Male`,`Hair`,`HairColor`,`Face`," +
                 " `QuickBar`, `QuickBarState`, `ShortCuts`, `GameSettings`, `ClientSettings`) " +
                 "VALUES " +
                     "('" + newchar.AccountID +
                     "', '" + newchar.Name +
                     "', '" + DateTime.Now.ToDBString() +
                        "', " +		newchar.Slot +
                        ", " +		newchar.Job  +
                        ", " +		Convert.ToByte(newchar.LookInfo.Male) +
                        ", " +		newchar.LookInfo.Hair +
                        ", " +		newchar.LookInfo.HairColor +
                        ", " +		newchar.LookInfo.Face +
                        ", " +      "0" +
                        ", " +      "0" +
                        ", " +      "0" +
                        ", " +      "0" +
                        ", " +      "0" +
                        ")";
                client.ExecuteQuery(query);

            WorldCharacter tadaa = new WorldCharacter(newchar,this);
            ushort begineqp = GetBeginnerEquip(job);

            if (begineqp > 0)
            {
                sbyte eqp_slot = (sbyte)((job == Job.Archer) ? -10 : -12); //, (job == Job.Archer) ? (byte)12 : (byte)10, begineqp)
                Equip eqp = new Equip((uint)newchar.ID, begineqp, eqp_slot);
                tadaa.Inventory.AddToEquipped(eqp);
                client.ExecuteQuery("INSERT INTO equips (owner,slot,EquipID) VALUES ('"+tadaa.ID+"','"+eqp_slot+"','"+eqp.EquipID+"')");
            }
            Characters.Add(slot, tadaa);
            return tadaa;
        }
Example #3
0
        public WorldCharacter CreateCharacter(string name, byte slot, byte hair, byte color, byte face, Job job, bool ismale)
        {
            if (Characters.ContainsKey(slot) || slot > 5)
            {
                return(null);
            }
            //TODO: check if hair etc are actual beginner ones! (premium hack)
            //NOTE: Check the SHN's for this -> Moved to database
            BaseStatsEntry stats = DataProvider.Instance.JobBasestats[job];

            if (stats == null)
            {
                //NOTE be serious.. please
                // Log.WriteLine(LogLevel.Warn, "Houston, we have a problem! Jobstats not found for job {0}", job.ToString());
                Log.WriteLine(LogLevel.Error, "Jobstats not found for job {0}", job.ToString());
                return(null);
            }
            Database.Storage.LookInfo     newLook = new Database.Storage.LookInfo();
            Database.Storage.PositionInfo newPos  = new Database.Storage.PositionInfo();
            Database.Storage.Character    newchar = new Database.Storage.Character();
            newchar.AccountID    = this.AccountID;
            newchar.CharLevel    = 1;
            newchar.Name         = name;
            newLook.Face         = face;
            newLook.Hair         = hair;
            newLook.HairColor    = color;
            newchar.Job          = (byte)job;
            newLook.Male         = ismale;
            newchar.Slot         = slot;
            newPos.XPos          = 7636;
            newPos.YPos          = 4610;
            newchar.HP           = (short)stats.MaxHP;
            newchar.SP           = (short)stats.MaxSP;
            newchar.HPStones     = (short)stats.MaxHPStones;
            newchar.SPStones     = (short)stats.MaxSPStones;
            newchar.LookInfo     = newLook;
            newchar.PositionInfo = newPos;
            int            charID = newchar.ID;
            DatabaseClient client = Program.DatabaseManager.GetClient();

            string query =
                "INSERT INTO `characters` " +
                "(`AccountID`,`Name`,`MasterJoin`,`Slot`,`Job`,`Male`,`Hair`,`HairColor`,`Face`," +
                " `QuickBar`, `QuickBarState`, `ShortCuts`, `GameSettings`, `ClientSettings`) " +
                "VALUES " +
                "('" + newchar.AccountID +
                "', '" + newchar.Name +
                "', '" + DateTime.Now.ToDBString() +
                "', " + newchar.Slot +
                ", " + newchar.Job +
                ", " + Convert.ToByte(newchar.LookInfo.Male) +
                ", " + newchar.LookInfo.Hair +
                ", " + newchar.LookInfo.HairColor +
                ", " + newchar.LookInfo.Face +
                ", " + "0" +
                ", " + "0" +
                ", " + "0" +
                ", " + "0" +
                ", " + "0" +
                ")";

            client.ExecuteQuery(query);

            WorldCharacter tadaa    = new WorldCharacter(newchar, this);
            ushort         begineqp = GetBeginnerEquip(job);

            if (begineqp > 0)
            {
                sbyte eqp_slot = (sbyte)((job == Job.Archer) ? -10 : -12); //, (job == Job.Archer) ? (byte)12 : (byte)10, begineqp)
                Equip eqp      = new Equip((uint)newchar.ID, begineqp, eqp_slot);
                tadaa.Inventory.AddToEquipped(eqp);
                client.ExecuteQuery("INSERT INTO equips (owner,slot,EquipID) VALUES ('" + tadaa.ID + "','" + eqp_slot + "','" + eqp.EquipID + "')");
            }
            Characters.Add(slot, tadaa);
            return(tadaa);
        }
Example #4
0
        public bool LoadCharacters()
        {
            if (!Authenticated) return false;
            Characters = new Dictionary<byte, WorldCharacter>();
            try
            {
                DataTable charData = null;
                using (DatabaseClient dbClient = Program.DatabaseManager.GetClient())
                {
                    charData = dbClient.ReadDataTable("SELECT * FROM Characters WHERE AccountID='" + this.AccountID + "'");
                }

                if (charData != null)
                {
                    foreach (DataRow row in charData.Rows)
                    {

                        Database.Storage.Character ch = new Database.Storage.Character();
                        ch.PositionInfo.ReadFromDatabase(row);
                        ch.LookInfo.ReadFromDatabase(row);
                        ch.CharacterStats.ReadFromDatabase(row);
                        ch.Slot = (byte)row["Slot"];
                        ch.CharLevel = (byte)row["Level"];
                        ch.AccountID = this.AccountID;
                        ch.Name = (string)row["Name"];
                        ch.ID = GetDataTypes.GetInt(row["CharID"]);
                        ch.Job = (byte)row["Job"];
                        ch.Money = GetDataTypes.GetLong(row["Money"].ToString());
                        ch.Exp = long.Parse(row["Exp"].ToString());
                        ch.HP = int.Parse(row["CurHP"].ToString());
                        ch.HPStones = 10;
                        ch.MasterJoin = DateTime.Parse(row["MasterJoin"].ToString());
                        ch.SP = int.Parse(row["CurSP"].ToString());
                        ch.SPStones = 10;
                        ch.StatPoints = (byte)row["StatPoints"];
                        ch.UsablePoints = (byte)row["UsablePoints"];
                        ch.Fame = 0;	// TODO
                        ch.GameSettings = Database.DataStore.ReadMethods.GetGameSettings(ch.ID, Program.DatabaseManager);
                        ch.ClientSettings = Database.DataStore.ReadMethods.GetClientSettings(ch.ID, Program.DatabaseManager);
                        ch.Shortcuts = Database.DataStore.ReadMethods.GetShortcuts(ch.ID, Program.DatabaseManager);
                        ch.QuickBar = Database.DataStore.ReadMethods.GetQuickBar(ch.ID, Program.DatabaseManager);
                        ch.QuickBarState = Database.DataStore.ReadMethods.GetQuickBarState(ch.ID, Program.DatabaseManager);
                        ch.ReviveCoper = GetDataTypes.GetLong(row["MasterReciveMoney"]);
                        if (row.IsNull("GroupID"))
                            ch.GroupId = -1;
                        else
                            ch.GroupId = long.Parse(row["GroupID"].ToString());

                        if (ch.GroupId == -1 || row.IsNull("IsGroupMaster"))
                            ch.IsGroupMaster = false;
                        else
                            ch.IsGroupMaster = ReadMethods.EnumToBool(row["IsGroupMaster"].ToString());

                        Characters.Add(ch.Slot, new WorldCharacter(ch, this));
                    }
                }
            }
            catch (Exception ex)
            {
                Log.WriteLine(LogLevel.Exception, "Error loading characters from {0}: {1}", Username, ex.InnerException.ToString());
                return false;
            }
            return true;
        }