Beispiel #1
0
        public static void HandleUseCharacter(Int32 id, DataBuffer buffer)
        {
            // Make sure the user exists.
            if (!Data.Players.ContainsKey(id))
            {
                return;
            }

            var slot = buffer.ReadInt32();

            HandleData.HandleUseCharacter(id, slot);
        }
Beispiel #2
0
        public static void HandleAddCharacter(Int32 id, DataBuffer buffer)
        {
            var legal  = new Regex("^[a-zA-Z0-9]*$");
            var name   = buffer.ReadString().Trim();
            var classn = buffer.ReadInt32();
            var gender = buffer.ReadByte();

            // Make sure this player exists.
            if (!Data.Players.ContainsKey(id))
            {
                return;
            }

            // Make sure the name is at least X characters long.
            if (name.Length < Data.Settings.MinUsernameChar)
            {
                Send.AlertMessage(id, String.Format("Character name must be at least {0} characters in length.", Data.Settings.MinUsernameChar));
                return;
            }

            // Make sure they only entered regular characters.
            if (!legal.IsMatch(name))
            {
                Send.AlertMessage(id, "Invalid name, only letters and numbers are allowed in names.");
                return;
            }

            // Check if the name is already in use or not.
            if (Data.Characters.Contains(name))
            {
                Send.AlertMessage(id, "A character with this name already exists!");
                return;
            }

            // Check if there's a slot left to use!
            var slot = -1;

            for (var i = 0; slot < Data.Players[id].Characters.Length; i++)
            {
                if (Data.Players[id].Characters[i].Name.Length < 1)
                {
                    slot = i;
                    break;
                }
            }
            if (slot < 0)
            {
                Send.AlertMessage(id, "Unable to create character.");
                return;
            }

            // We've come this far, we can add this character!
            Data.Characters.Add(name);
            Data.Players[id].Characters[slot].Name      = name;
            Data.Players[id].Characters[slot].Gender    = (Byte)gender;
            Data.Players[id].Characters[slot].Class     = classn;
            Data.Players[id].Characters[slot].Sprite    = gender == (Int32)Enumerations.Gender.Male ? Data.Classes[classn].MaleSprite : Data.Classes[classn].FemaleSprite;
            Data.Players[id].Characters[slot].Level     = 1;
            Data.Players[id].Characters[slot].Map       = Data.Settings.StartMap;
            Data.Players[id].Characters[slot].X         = Data.Settings.StartX;
            Data.Players[id].Characters[slot].Y         = Data.Settings.StartY;
            Data.Players[id].Characters[slot].Direction = (Int32)Enumerations.Direction.Down;
            for (var i = 0; i < (Int32)Enumerations.Stats.Stat_Count; i++)
            {
                Data.Players[id].Characters[slot].Statistic[i] = Data.Classes[classn].Statistic[i];
            }

            // Save our data!
            Data.SaveCharacterList();
            Data.SavePlayer(id);

            // Notify our user!
            Logger.Write(String.Format("ID: {0} has created a character named '{1}'.", id, name));
            HandleData.HandleUseCharacter(id, slot);
        }