Esempio n. 1
0
        private static IPlayer Convert(int classChoiceLevel, int levelCap,
                                       IEquipmentRepository equipmentRepository,
                                       IPlayerFactory playerFactory, PlayerDTO dto)
        {
            PlayerDTO.CharClassDTO cc = dto.CharClass;
            ICharClass             cci;

            if (cc.Type.ID == 0)
            {
                cci = new DeprivedCharClass(classChoiceLevel);
            }
            else
            {
                cci = new CharClassImpl(cc.Type, cc.CoinBonus,
                                        cc.ItemFind, cc.Pets, cc.Prestige,
                                        cc.PreventDeathBonus, cc.SuccessChance,
                                        cc.XpBonus, levelCap, cc.Xp);
            }

            IList <IItem> items = new List <IItem>();

            foreach (var item in dto.Items)
            {
                items.Add(equipmentRepository.getById(item));
            }

            var equipment = new Dictionary <EquipSlot, IEquipment>();

            foreach (var kvp in dto.Equipment)
            {
                equipment.Add(kvp.Key, equipmentRepository.getById(kvp.Value));
            }

            IPlayer player = new Player(dto.ID, dto.Name, cci, dto.Coins,
                                        dto.LastDailyGroupFinder, items, equipment);

            foreach (var o in playerFactory.GetCurrentDefaultObservers())
            {
                player.AddObserver(o);
            }

            return(player);
        }