public static CharacterDatabaseData Load(DataRow row)
        {
            CharacterDatabaseData ch = new CharacterDatabaseData();

            if (ch.LoadFromDatabase(row) == false)
            {
                return(null);
            }

            return(ch);
        }
		public static CharacterDatabaseData Load(DataRow row) {
			CharacterDatabaseData ch = new CharacterDatabaseData();
			if (ch.LoadFromDatabase(row) == false) {
				return null;
			}

			return ch;
		}
Exemple #3
0
        public static ECharacterCreationResult Create(Account account, string name, byte slot, byte str, byte agi, byte vit, byte int_, byte dex, byte luk, short hairColor, short hairStyle, out Character newChar)
        {
            newChar = null;

            if (name.Length > 24)
            {
                name = name.Substring(0, 24);
            }
            //name = name.Replace('\032', ' ').Replace('\t', ' ').Replace('\x0A', ' ').Replace('\x0D', ' ');

            if (
                (slot >= Global.MAX_SLOTS) ||
                (str + agi + vit + int_ + dex + luk != 6 * 5) ||
                (str < 1 || str > 9 || agi < 1 || agi > 9 || vit < 1 || vit > 9 || int_ < 1 || int_ > 9 || dex < 1 || dex > 9 || luk < 1 || luk > 9) ||
                (str + int_ != 10 || agi + luk != 10 || vit + dex != 10)
                )
            {
                return(ECharacterCreationResult.CharCreationDenied);                // invalid input
            }

            // Check for max character count on this account
            if (account.Chars.Count >= Global.MAX_SLOTS)
            {
                return(ECharacterCreationResult.CharCreationDenied);                // character account limit exceeded
            }
            // Check for existing char with this name
            if (Core.Database.Query("SELECT charID FROM `char` WHERE `name` = '{0}'", name.MysqlEscape()).Rows.Count > 0)
            {
                return(ECharacterCreationResult.CharnameAlreadyExists);
            }
            // Check for existing char on this slot
            foreach (Character tmpChar in account.Chars.Values)
            {
                if (tmpChar.Status.Slot == slot)
                {
                    return(ECharacterCreationResult.CharCreationDenied);
                }
            }

            // TODO: this has to be in CharacterDatabaseStatus, nor?
            //		 CharacterDatabaseData represents the character in the character server
            //		 so..
            newChar                  = new Character(DatabaseID.Zero, false);
            newChar.Parent           = account;
            newChar.Status.Name      = name;
            newChar.Status.Slot      = slot;
            newChar.Status.Zeny      = Config.StartZeny;
            newChar.Status.Str       = str;
            newChar.Status.Agi       = agi;
            newChar.Status.Dex       = dex;
            newChar.Status.Vit       = vit;
            newChar.Status.Int       = int_;
            newChar.Status.Luk       = luk;
            newChar.Status.HPMax     = newChar.Status.HP = (40 * (100 + vit) / 100);
            newChar.Status.SPMax     = newChar.Status.SP = (11 * (100 + int_) / 100);
            newChar.Status.HairStyle = hairStyle;
            newChar.Status.HairColor = hairColor;
            newChar.Status.SavePoint = new Location(Mapcache.GetID(Config.StartMap), Config.StartMapX, Config.StartMapY);
            newChar.Status.Location  = new Location(newChar.Status.SavePoint.Map.ID, newChar.Status.SavePoint.Point.X, newChar.Status.SavePoint.Point.Y);

            // Save it
            CharacterDatabaseData status = newChar.Status;
            string query =
                string.Format(
                    "INSERT INTO `char` (" +
                    "`accountID`, `slot`, `name`, `zeny`, `str`, `agi`, `vit`, `int`, `dex`, `luk`, `hpMax`, `hp`," +
                    "`spMax`, `sp`, `hair`, `hairColor`, `lastMap`, `lastX`, `lastY`, `saveMap`, `saveX`, `saveY`" +
                    ") VALUES (" +
                    "{0}, {1}, '{2}', '{3}', '{4}', '{5}', '{6}', '{7}', '{8}', '{9}', '{10}', '{11}'," +
                    "'{12}', '{13}', '{14}', '{15}', '{16}', '{17}', '{18}', '{19}', '{20}', '{21}'" +
                    ")"
                    ,
                    account.WorldID.ID, slot, name.MysqlEscape(), status.Zeny, status.Str, status.Agi, status.Vit,
                    status.Int, status.Dex, status.Luk, status.HPMax, status.HP, status.SPMax, status.SP,
                    status.HairStyle, status.HairColor, status.Location.Map, status.Location.Point.X, status.Location.Point.Y,
                    status.SavePoint.Map, status.SavePoint.Point.X, status.SavePoint.Point.X
                    );

            Core.Database.Query(query);
            uint charID = (uint)Core.Database.GetLastInsertID();

            if (charID == 0)
            {
                // Failed to add character?
                return(ECharacterCreationResult.CharCreationDenied);
            }
            // save Serial/CharID
            newChar.UpdateDatabaseID(charID, EDatabaseType.Char);
            newChar.WorldID = new WorldID(charID, EDatabaseType.Char);
            // Add it to account dictionary
            account.Chars.Add(newChar.WorldID, newChar);

            return(ECharacterCreationResult.Success);
        }