Ejemplo n.º 1
0
        public void RemoveCharacter(Character character)
        {
            lock (_characters)
                _characters.Remove(character);

            Send(string.Format("{0}|-{1}", Packet.Movement, character.Id));
        }
Ejemplo n.º 2
0
        public static void Update(Character character)
        {
            StatsRepository.Update(character.Stats);
             AlignmentRepository.Update(character.Alignment);

             const string query =
                 "UPDATE characters SET skin=@skin, level=@level, " +
                 "pdvNow=@pdvNow, exp=@exp, mapId=@mapId, cellId=@cellId, direction=@direction, channels=@channels, " +
                 "statsPoints=@statsPoints, spellsPoints=@spellsPoints, kamas=@kamas WHERE id=@id";

             Base.Repository.ExecuteQuery(query, GameDbManager.GetDatabaseConnection(),
                 (command) =>
                 {
                     command.Parameters.Add(new MySqlParameter("@id", character.Id));
                     command.Parameters.Add(new MySqlParameter("@skin", character.Skin));
                     command.Parameters.Add(new MySqlParameter("@level", character.Level));
                     command.Parameters.Add(new MySqlParameter("@pdvNow", character.PdvNow));
                     command.Parameters.Add(new MySqlParameter("@exp", character.Exp));
                     command.Parameters.Add(new MySqlParameter("@mapId", character.Map.Id));
                     command.Parameters.Add(new MySqlParameter("@cellId", character.MapCell));
                     command.Parameters.Add(new MySqlParameter("@direction", character.Direction));
                     command.Parameters.Add(new MySqlParameter("@channels",
                         string.Format("{0}", string.Join("", character.Channels))));
                     command.Parameters.Add(new MySqlParameter("@statsPoints", character.StatsPoints));
                     command.Parameters.Add(new MySqlParameter("@spellsPoints", character.SpellPoints));
                     command.Parameters.Add(new MySqlParameter("@kamas", character.Kamas));
                 });
        }
Ejemplo n.º 3
0
 public static InventoryItem ExistItem(InventoryItem item, Character character, StatsManager.Position position = StatsManager.Position.None, int quantity = 1)
 {
     return DatabaseProvider.InventoryItems.Find(
         x =>
             x.ItemInfos == item.ItemInfos &&
             string.Join(",", x.Stats).Equals(string.Join(",", item.Stats)) &&
             x.Character == character && x.ItemPosition == position && x.Quantity >= quantity);
 }
Ejemplo n.º 4
0
        public Exchange(Character firstTrader, Character secondTrader)
        {
            FirstTrader = firstTrader;
            SecondTrader = secondTrader;

            _firstTraderItems = new List<InventoryItem>();
            _secondTraderItems = new List<InventoryItem>();

            _timer = DateTime.Now;
        }
Ejemplo n.º 5
0
        public static void Create(Character character, int accountId)
        {
            const string query =
                 "INSERT INTO characters SET id=@id, name=@name, classe=@classe, sex=@sex, color1=@color1, color2=@color2," +
                 "color3=@color3, skin=@skin, level=@level, alignmentId=@alignmentId, statsId=@statsId, " +
                 "pdvNow=@pdvNow, mapId=@mapId, cellId=@cellId, direction=@direction, channels=@channels, statsPoints=@statsPoints, " +
                 "spellsPoints=@spellsPoints, kamas=@kamas";

             Base.Repository.ExecuteQuery(query, GameDbManager.GetDatabaseConnection(),
                 (command) =>
                 {
                     command.Parameters.Add(new MySqlParameter("@id", character.Id));
                     command.Parameters.Add(new MySqlParameter("@name", character.Name));
                     command.Parameters.Add(new MySqlParameter("@classe", (int) character.Classe));
                     command.Parameters.Add(new MySqlParameter("@sex", character.Sex));
                     command.Parameters.Add(new MySqlParameter("@color1", character.Color1));
                     command.Parameters.Add(new MySqlParameter("@color2", character.Color2));
                     command.Parameters.Add(new MySqlParameter("@color3", character.Color3));
                     command.Parameters.Add(new MySqlParameter("@skin", character.Skin));
                     command.Parameters.Add(new MySqlParameter("@level", character.Level));
                     command.Parameters.Add(new MySqlParameter("@alignmentId", character.Alignment.Id));
                     command.Parameters.Add(new MySqlParameter("@statsId", character.Stats.Id));
                     command.Parameters.Add(new MySqlParameter("@pdvNow", character.PdvNow));
                     command.Parameters.Add(new MySqlParameter("@mapId", character.Map.Id));
                     command.Parameters.Add(new MySqlParameter("@cellId", character.MapCell));
                     command.Parameters.Add(new MySqlParameter("@direction", character.Direction));
                     command.Parameters.Add(new MySqlParameter("@channels", string.Join("", character.Channels)));
                     command.Parameters.Add(new MySqlParameter("@statsPoints", character.StatsPoints));
                     command.Parameters.Add(new MySqlParameter("@spellsPoints", character.SpellPoints));
                     command.Parameters.Add(new MySqlParameter("@kamas", character.Kamas));
                 });

             Logs.LogWritter(Constant.GameFolder, string.Format("Création du personnage {0}", character.Name));

             const string query2 =
                 "INSERT INTO characters SET accountId=@accountId, gameserverId=@gameServer, characterId=@id";

             Base.Repository.ExecuteQuery(query2, RealmDbManager.GetDatabaseConnection(),
                 (command) =>
                 {
                     command.Parameters.Add(new MySqlParameter("@accountId", accountId));
                     command.Parameters.Add(new MySqlParameter("@gameServer", DatabaseProvider.ServerId));
                     command.Parameters.Add(new MySqlParameter("@id", character.Id));
                 });

             lock (DatabaseProvider.Characters)
                 DatabaseProvider.Characters.Add(character);

             lock (DatabaseProvider.AccountCharacters)
                 DatabaseProvider.AccountCharacters.Add(new AccountCharacters
                 {
                     Account = DatabaseProvider.Accounts.Find(x => x.Id == accountId),
                     Character = character
                 });
        }
Ejemplo n.º 6
0
        public static bool VerifyIfCharacterMeetItemCondition(Character character, string conditionString)
        {
            if (conditionString.Equals(string.Empty))
                return true;

            if (!conditionString.Contains("&") && !conditionString.Contains("|"))
            {
                conditionString = conditionString.Replace("(", "").Replace(")", "");

                return ParseItemConditionWithoutSpliter(character, conditionString);
            }

            if (!conditionString.Contains("&") && conditionString.Contains("|"))
            {
                return ParseItemConditionWithOrSpliter(character, conditionString);
            }

            return ParseItemConditionWithAndSpliter(character, conditionString);
        }
Ejemplo n.º 7
0
        public bool Accepted(Character character, GameClient client, GameClient receiverClient)
        {
            if (DateTime.Now < _timer.AddMilliseconds(TimeInvtervalToAccept))
                return false;

            if (character == FirstTrader)
            {
                _firstValidated = _firstValidated == false;

                LockExchangeCases(client, receiverClient, FirstTrader, _firstValidated);
            }
            else
            {
                _secondValidated = _secondValidated == false;

                LockExchangeCases(client, receiverClient, SecondTrader, _secondValidated);
            }

            return _firstValidated && _secondValidated;
        }
Ejemplo n.º 8
0
        private void EchangeItem(GameClient firstTraderClient, GameClient secondTraderClient, InventoryItem item,
            Character trader)
        {
            var existItemSecondTrader = InventoryItem.ExistItem(item, SecondTrader);
            var existItemFirstTrader = InventoryItem.ExistItem(item, FirstTrader);

            if (FirstTrader == trader)
            {
                RemoveTraderItem(existItemFirstTrader, firstTraderClient, item);
                CreateTraderItem(SecondTrader, existItemSecondTrader, secondTraderClient, item);
            }
            else
            {
                RemoveTraderItem(existItemSecondTrader, secondTraderClient, item);
                CreateTraderItem(FirstTrader, existItemFirstTrader, firstTraderClient, item);
            }
        }
Ejemplo n.º 9
0
        private void CreateTraderItem(Character trader, InventoryItem existItemTrader, GameClient traderClient,
            InventoryItem item)
        {
            if (existItemTrader != null)
            {
                existItemTrader.Quantity += item.Quantity;

                traderClient.SendPackets(string.Format("{0}{1}|{2}", Packet.ObjectQuantity, existItemTrader.Id,
                    existItemTrader.Quantity));

                InventoryItemRepository.Update(existItemTrader);
            }
            else
            {
                var newItem = item.Copy(quantity: item.Quantity);

                newItem.Character = trader;

                traderClient.SendPackets(string.Format("{0}{1}", Packet.ObjectAdd, newItem.ItemInfo()));

                InventoryItemRepository.Create(newItem, true);
            }
        }
Ejemplo n.º 10
0
        public void RemoveItem(Character character, InventoryItem item, int quantity, GameClient client,
            GameClient receiverClient)
        {
            _timer = DateTime.Now;

            UnLockExchangeCases(client, receiverClient);

            InventoryItem existItem;

            if (character == FirstTrader)
            {
                existItem =
                    _firstTraderItems.Find(
                        x =>
                            x.Character == item.Character && x.ItemPosition == item.ItemPosition &&
                            x.ItemInfos == item.ItemInfos && x.Stats == item.Stats);
            }
            else
            {
                existItem =
                    _secondTraderItems.Find(
                        x =>
                            x.Character == item.Character && x.ItemPosition == item.ItemPosition &&
                            x.ItemInfos == item.ItemInfos && x.Stats == item.Stats);
            }

            if (existItem == null) return;

            if (existItem.Quantity >= quantity)
                existItem.Quantity -= quantity;

            if (existItem.Quantity == 0)
            {
                client.SendPackets(string.Format("{0}-{1}", Packet.ExchangeObjectLocalObjectMove, item.Id));

                receiverClient.SendPackets(string.Format("{0}-{1}", Packet.ExchangeObjectDistantObjectMove, item.Id));

                if (FirstTrader == character)
                    _firstTraderItems.Remove(existItem);
                else
                    _secondTraderItems.Remove(existItem);
            }
            else
            {
                client.SendPackets(string.Format("{0}+{1}|{2}", Packet.ExchangeObjectLocalObjectMove, item.Id,
                    existItem.Quantity));

                receiverClient.SendPackets(string.Format("{0}+{1}", Packet.ExchangeObjectDistantObjectMove,
                    item.ToExchangeFormat(existItem.Quantity)));
            }
        }
Ejemplo n.º 11
0
        public void AddKamas(Character character, int kamas, GameClient client, GameClient receiverClient)
        {
            _timer = DateTime.Now;

            UnLockExchangeCases(client, receiverClient);

            if (FirstTrader == character)
                FirstKamas = kamas;
            else
                SecondKamas = kamas;

            client.SendPackets(string.Format("{0}{1}", Packet.ExchangeObjectLocalKamasMove, kamas));
            receiverClient.SendPackets(string.Format("{0}{1}", Packet.ExchangeObjectDistantKamasMove, kamas));
        }
Ejemplo n.º 12
0
        public void Calculate(Character character)
        {
            var items = DatabaseProvider.InventoryItems.FindAll(x => x.Character == character && x.IsEquiped());

            foreach (var stats in from inventoryItem in items
                from stats in inventoryItem.Stats
                select stats)
            {
                ParseStats(stats);
            }

            foreach (var itemSetBonus in from set in character.GetSets()
                let numberOfItemsEquipedInSet = character.GetAllItemsEquipedInSet(set).Count
                where set.BonusesDictionary.ContainsKey(numberOfItemsEquipedInSet)
                from itemSetBonus in set.BonusesDictionary[numberOfItemsEquipedInSet]
                select itemSetBonus)
            {
                ParseStats(itemSetBonus);
            }
        }
Ejemplo n.º 13
0
        private void AddCharacter(string data)
        {
            var charactersNumber =
                DatabaseProvider.AccountCharacters.FindAll(x => x.Account.Id == _client.Account.Id).Count;

            if (charactersNumber >= int.Parse(Config.Get("Player_Max_Per_Account")))
            {
                _client.SendPackets(Packet.CreateCharacterFullErrors);
                return;
            }

            var datas = data.Split('|');

            var name = datas[0];

            var classe = int.Parse(datas[1]);

            var sex = int.Parse(datas[2]);

            var color1 = int.Parse(datas[3]);

            var color2 = int.Parse(datas[4]);

            var color3 = int.Parse(datas[5]);

            if (classe == (int) Character.Class.Pandawa &&
                bool.Parse(Config.Get("Subscription")) &&
                _client.Account.IsNotSubscribed())
                return;

            if (DatabaseProvider.Characters.All(x => x.Name != name) && name.Length >= 3 && name.Length <= 20)
            {
                var reg = new Regex("^[a-zA-Z-]+$");

                if (reg.IsMatch(name) && name.Count(c => c == '-') < 3)
                {
                    if (classe >= 1 && classe <= 12 && (sex == 1 || sex == 0))
                    {
                        var newCharacter = new Character
                        {
                            Id =
                                DatabaseProvider.Characters.Count > 0
                                    ? DatabaseProvider.Characters.OrderByDescending(x => x.Id).First().Id + 1
                                    : 1,
                            Name = name,
                            Classe = (Character.Class) classe,
                            Sex = sex,
                            Color1 = color1,
                            Color2 = color2,
                            Color3 = color3,
                            Level = int.Parse(Config.Get("Starting_level")),
                            Skin = int.Parse(classe + "" + sex),
                            PdvNow =
                                (int.Parse(Config.Get("Starting_level")) - 1)*Character.GainHpPerLvl + Character.BaseHp,
                            PdvMax =
                                (int.Parse(Config.Get("Starting_level")) - 1)*Character.GainHpPerLvl + Character.BaseHp,
                        };

                        newCharacter.GenerateInfos(_client.Account.GmLevel);

                        CharacterRepository.Create(newCharacter, _client.Account.Id);

                        _client.SendPackets(Packet.CreationSuccess);

                        _client.SendPackets(Packet.GameBegin);

                        SendCharactersList("");
                    }
                    else
                    {
                        _client.SendPackets(Packet.CreateCharacterFullErrors);
                    }
                }
                else
                {
                    _client.SendPackets(Packet.CreateCharacterBadName);
                }
            }
            else
            {
                _client.SendPackets(Packet.NameAlredyExists);
            }
        }
Ejemplo n.º 14
0
        public void Generate(Character character, int quantity = 1)
        {
            var item = new InventoryItem
            {
                Id = DatabaseProvider.InventoryItems.Count > 0
                    ? DatabaseProvider.InventoryItems.OrderByDescending(x => x.Id).First().Id + 1
                    : 1,
                Character = character,
                ItemInfos = this,
                ItemPosition = StatsManager.Position.None,
                Stats = ItemStats.GenerateRandomStats(Stats).ToList(),
                Quantity = quantity
            };

            var existItem = InventoryItem.ExistItem(item, item.Character, item.ItemPosition);

            if (existItem != null)
            {
                existItem.Quantity += 1;
                InventoryItemRepository.Update(existItem);
            }
            else
                InventoryItemRepository.Create(item, true);
        }
Ejemplo n.º 15
0
 public ServerMessage(Character character)
 {
     _character = character;
 }
Ejemplo n.º 16
0
        private static bool ParseItemConditionWithAndSpliter(Character character, string conditionString)
        {
            var conditions = conditionString.Split('&');

            return conditions.All(condition => Parse(condition, character) == true);
        }
Ejemplo n.º 17
0
        private static bool Parse(string condition, Character character)
        {
            if (condition.Contains("("))
                return ParseItemConditionWithOrSpliter(character, condition);

            var header = condition.Substring(0, 2);

            var balance = condition.Substring(2, 1);

            var value = int.Parse(condition.Substring(3));

            int characterStatsValue;

            bool avaliable;

            switch (header.Substring(0, 1))
            {
                case "C":

                    switch (header.Substring(1, 1))
                    {
                        case "a":
                            characterStatsValue = character.Stats.Agility.Base;
                            break;

                        case "i":
                            characterStatsValue = character.Stats.Intelligence.Base;
                            break;

                        case "c":
                            characterStatsValue = character.Stats.Chance.Base;
                            break;

                        case "s":
                            characterStatsValue = character.Stats.Strength.Base;
                            break;

                        case "v":
                            characterStatsValue = character.Stats.Vitality.Base;
                            break;

                        case "w":
                            characterStatsValue = character.Stats.Wisdom.Base;
                            break;

                        case "A":
                            characterStatsValue = character.Stats.Agility.GetTotal();
                            break;

                        case "I":
                            characterStatsValue = character.Stats.Intelligence.GetTotal();
                            break;

                        case "C":
                            characterStatsValue = character.Stats.Chance.GetTotal();
                            break;

                        case "S":
                            characterStatsValue = character.Stats.Strength.GetTotal();
                            break;

                        case "V":
                            characterStatsValue = character.Stats.Vitality.GetTotal();
                            break;

                        case "W":
                            characterStatsValue = character.Stats.Wisdom.GetTotal();
                            break;

                        default:
                            return true;
                    }

                    break;

                case "P":

                    switch (header.Substring(1, 1))
                    {
                        case "G":
                            characterStatsValue = (int) character.Classe;
                            break;
                        case "L":
                            characterStatsValue = character.Level;
                            break;
                        case "K":
                            characterStatsValue = character.Kamas;
                            break;
                        case "S":
                            characterStatsValue = character.Sex;
                            break;
                        case "X":
                            characterStatsValue = DatabaseProvider.AccountCharacters.Find(x => x.Character == character).Account.GmLevel;
                            break;
                        case "W":
                            characterStatsValue = character.GetMaxWeight();
                            break;
                        case "s":
                            characterStatsValue = character.Alignment.Type;
                            break;
                        case "a":
                            characterStatsValue = character.Alignment.Level;
                            break;
                        case "P":
                            characterStatsValue = character.Alignment.Grade;
                            break;

                        default:
                            return true;
                    }

                    break;

                default:
                    return true;
            }

            if (balance == "") return false;

            switch (balance)
            {

                case "<":
                    avaliable = (characterStatsValue < value ? true : false);
                    break;

                case ">":
                    avaliable = (characterStatsValue > value ? true : false);
                    break;

                case "=":
                case "~":
                    avaliable = (characterStatsValue == value ? true : false);
                    break;

                case "!":
                    avaliable = (characterStatsValue != value ? true : false);
                    break;

                default:
                    return true;
            }

            return avaliable;
        }
Ejemplo n.º 18
0
 private static bool ParseItemConditionWithoutSpliter(Character character, string conditionString)
 {
     return Parse(conditionString, character);
 }
Ejemplo n.º 19
0
        private static bool ParseItemConditionWithOrSpliter(Character character, string conditionString)
        {
            conditionString = conditionString.Replace("(", "").Replace(")", "");

            var conditions = conditionString.Split('|');

            return conditions.Any(condition => Parse(condition, character) == true);
        }
Ejemplo n.º 20
0
        private void LockExchangeCases(GameClient client, GameClient receiverClient, Character character, bool validated)
        {
            client.SendPackets(string.Format("{0}{1}{2}", Packet.ExchangeReady, validated ? "1" : "0",
                    character.Id));

            receiverClient.SendPackets(string.Format("{0}{1}{2}", Packet.ExchangeReady, validated ? "1" : "0",
                character.Id));
        }
Ejemplo n.º 21
0
 public void AddCharacter(Character character)
 {
     lock (_characters)
         _characters.Add(character);
 }
Ejemplo n.º 22
0
        public void AddItem(Character character, InventoryItem item, int quantity, GameClient client,
            GameClient receiverClient)
        {
            _timer = DateTime.Now;

            UnLockExchangeCases(client, receiverClient); // Update exchange board

            InventoryItem existItem;

            if (FirstTrader == character)
            {
                existItem =
                    _firstTraderItems.Find(
                        x =>
                            x.Character == item.Character && x.ItemPosition == item.ItemPosition &&
                            x.ItemInfos == item.ItemInfos && x.Stats == item.Stats);
            }
            else
            {
                existItem =
                    _secondTraderItems.Find(
                        x =>
                            x.Character == item.Character && x.ItemPosition == item.ItemPosition &&
                            x.ItemInfos == item.ItemInfos && x.Stats == item.Stats);
            }

            if (existItem != null)
            {
                existItem.Quantity += quantity;

                client.SendPackets(string.Format("{0}+{1}|{2}", Packet.ExchangeObjectLocalObjectMove, item.Id,
                    existItem.Quantity));

                receiverClient.SendPackets(string.Format("{0}+{1}", Packet.ExchangeObjectDistantObjectMove,
                    item.ToExchangeFormat(existItem.Quantity)));
            }
            else
            {
                var newItem = item.Copy(quantity: quantity);

                if (character == FirstTrader)
                    _firstTraderItems.Add(newItem);
                else
                    _secondTraderItems.Add(newItem);

                client.SendPackets(string.Format("{0}+{1}|{2}", Packet.ExchangeObjectLocalObjectMove, item.Id,
                    newItem.Quantity));

                receiverClient.SendPackets(string.Format("{0}+{1}", Packet.ExchangeObjectDistantObjectMove,
                    item.ToExchangeFormat(newItem.Quantity)));
            }
        }
Ejemplo n.º 23
0
 public static void CreateExchangeSession(Character senderCharacter, Character receiverCharacter)
 {
     lock (Exchanges)
         Exchanges.Add(new Exchange (senderCharacter, receiverCharacter));
 }