Пример #1
0
        public async Task AddItemToAsync_ShouldCreateAnItemInDatabase_ThenReturnsAFullyLoadedItem()
        {
            const int itemId         = 25;
            const int characterId    = 10;
            var       itemTemplateId = Guid.NewGuid();
            var       itemData       = new ItemData();
            var       itemTemplate   = new ItemTemplate();
            var       request        = new CreateItemRequest {
                ItemData = itemData, ItemTemplateId = itemTemplateId
            };
            var createdItem = new Item {
                Id = itemId
            };
            var fullyLoadedItem = new Item();

            _unitOfWorkFactory.GetUnitOfWork().ItemTemplates.GetAsync(itemTemplateId)
            .Returns(itemTemplate);
            _itemFactory.CreateItem(ItemOwnerType.Character, characterId, itemTemplate, itemData)
            .Returns(createdItem);
            _unitOfWorkFactory.GetUnitOfWork().Items.GetWithAllDataAsync(itemId)
            .Returns(fullyLoadedItem);

            var actualItem = await _service.AddItemToAsync(ItemOwnerType.Character, characterId, request);

            Received.InOrder(() =>
            {
                _unitOfWorkFactory.GetUnitOfWork().Items.Add(createdItem);
                _unitOfWorkFactory.GetUnitOfWork().SaveChangesAsync();
            });
            actualItem.Should().BeSameAs(fullyLoadedItem);
        }
Пример #2
0
        /// <inheritdoc />
        public void Initialize(IPlayerEntity player)
        {
            IEnumerable <DbItem> items = _database.Items.Where(x => x.CharacterId == player.PlayerData.Id && !x.IsDeleted);

            if (items != null)
            {
                foreach (DbItem databaseItem in items)
                {
                    Item item = _itemFactory.CreateItem(databaseItem);

                    player.Inventory.SetItemAtIndex(item, item.Slot);
                }
            }
        }
Пример #3
0
        public async Task <DougResponse> Shop(Command command)
        {
            var items = new List <Item>
            {
                _itemFactory.CreateItem(ItemFactory.CoffeeCup),
                _itemFactory.CreateItem(ItemFactory.Apple),
                _itemFactory.CreateItem(ItemFactory.Bread),
                _itemFactory.CreateItem(ItemFactory.McdoFries)
            };

            await _slack.SendEphemeralBlocks(new ShopMenu(items).Blocks, command.UserId, command.ChannelId);

            return(NoResponse);
        }
Пример #4
0
        public void MoveStackableItemsTest(bool shouldSourceDeleteItem)
        {
            Service.Initialize(_player);

            int  sourceSlot      = GetRandomSlotInUse();
            int  destinationSlot = GetRandomSlotInUse();
            Item sourceItem      = _player.Inventory.GetItemAtSlot(sourceSlot);
            Item destinationItem = _player.Inventory.GetItemAtSlot(destinationSlot);

            if (sourceItem == null)
            {
                Assert.Throws <InvalidOperationException>(() => Service.MoveItem(_player, (byte)sourceSlot, (byte)destinationSlot));
                return;
            }

            const int itemPackMax             = 1000;
            const int sourceItemQuantity      = 500;
            var       destinationItemQuantity = shouldSourceDeleteItem ? 100 : 600;

            sourceItem = _itemFactory.CreateItem(1, 0, ElementType.None, 0);
            sourceItem.Data.PackMax = itemPackMax;
            sourceItem.Quantity     = sourceItemQuantity;
            sourceItem.Slot         = sourceSlot;
            _player.Inventory.SetItemAtSlot(sourceItem, sourceSlot);

            destinationItem = _itemFactory.CreateItem(1, 0, ElementType.None, 0);
            destinationItem.Data.PackMax = itemPackMax;
            destinationItem.Quantity     = destinationItemQuantity;
            destinationItem.Slot         = destinationSlot;
            _player.Inventory.SetItemAtSlot(destinationItem, destinationSlot);

            Service.MoveItem(_player, (byte)sourceSlot, (byte)destinationSlot);

            if (shouldSourceDeleteItem)
            {
                Assert.Null(_player.Inventory.GetItemAtSlot(sourceSlot));
                Assert.NotNull(destinationItem);
                Assert.Equal(sourceItemQuantity + destinationItemQuantity, destinationItem.Quantity);
                _inventoryPacketFactoryMock.Verify(x => x.SendItemUpdate(_player, UpdateItemType.UI_NUM, destinationItem.UniqueId, destinationItem.Quantity), Times.Once());
            }
            else
            {
                Assert.Equal(destinationItemQuantity - sourceItemQuantity, sourceItem.Quantity);
                Assert.Equal(itemPackMax, destinationItem.Quantity);
                _inventoryPacketFactoryMock.Verify(x => x.SendItemUpdate(_player, UpdateItemType.UI_NUM, sourceItem.UniqueId, sourceItem.Quantity), Times.Once());
                _inventoryPacketFactoryMock.Verify(x => x.SendItemUpdate(_player, UpdateItemType.UI_NUM, destinationItem.UniqueId, destinationItem.Quantity), Times.Once());
            }
        }
Пример #5
0
        /// <inheritdoc />
        public IMapLayer CreateLayer(IMapInstance parentMapInstance, int layerId)
        {
            var mapLayer = ActivatorUtilities.CreateInstance <MapLayer>(_serviceProvider, parentMapInstance, layerId);

            foreach (IMapRegion region in parentMapInstance.Regions)
            {
                if (region is IMapRespawnRegion respawnRegion)
                {
                    if (respawnRegion.ObjectType == WorldObjectType.Mover)
                    {
                        for (int i = 0; i < respawnRegion.Count; i++)
                        {
                            IMonsterEntity monster = _monsterFactory.CreateMonster(parentMapInstance, mapLayer, respawnRegion.ModelId, respawnRegion);

                            mapLayer.AddEntity(monster);
                        }
                    }
                    else if (respawnRegion.ObjectType == WorldObjectType.Item)
                    {
                        var item = _itemFactory.CreateItem(respawnRegion.ModelId, 0, 0, 0);

                        for (int i = 0; i < respawnRegion.Count; ++i)
                        {
                            IItemEntity itemEntity = _itemFactory.CreateItemEntity(parentMapInstance, mapLayer, item);
                            itemEntity.Object.Position = respawnRegion.GetRandomPosition();
                            itemEntity.Region          = respawnRegion;

                            mapLayer.AddEntity(itemEntity);
                        }
                    }
                }
            }

            return(mapLayer);
        }
Пример #6
0
 //Method for creating any method with the passed amount, list and factory.
 private void GenerateItems(int pItemCount, List<Item> pItemList, IItemFactory pFactory)
 {
     for (int index = 0; index < pItemCount; index++)
     {
         Item item = pFactory.CreateItem();
         pItemList.Add(item);
     }
 }
Пример #7
0
 private void AddEquipment(string itemId, IItemFactory itemFactory)
 {
     if (!string.IsNullOrEmpty(itemId))
     {
         var item = (EquipmentItem)itemFactory.CreateItem(itemId);
         Equipment.TryAdd(item.Slot, item);
     }
 }
Пример #8
0
    public string AddItemToHero(string itemName, string heroName, long strengthBonus, long agilityBonus, long intelligenceBonus, long hitpointsBonus, long damageBonus)
    {
        var hero = this.heroes[heroName];
        var item = itemFactory.CreateItem(itemName, strengthBonus, agilityBonus, intelligenceBonus, hitpointsBonus, damageBonus);

        hero.AddItem(item);

        return(string.Format(Constants.ItemCreateMessage, itemName, heroName));
    }
Пример #9
0
        public string RegisterBag(string username, IEnumerable <string> bagItems)
        {
            var passenger = this.airport.GetPassenger(username);

            var items = bagItems.Select(i => itemFactory.CreateItem(i)).ToArray();
            var bag   = new Bag(passenger, items);

            passenger.Bags.Add(bag);

            return($"Registered bag with {string.Join(", ", bagItems)} for {username}");
        }
Пример #10
0
            public ItemData Clone(IItemFactory <I, I> itemFactory, ProjectItemElement initialItemElementForFactory)
            {
                // setting the factory's item element to the original item element that produced the item
                // otherwise you get weird things like items that appear to have been produced by update elements
                itemFactory.ItemElement = OriginatingItemElement;
                var clonedItem = itemFactory.CreateItem(Item, OriginatingItemElement.ContainingProject.FullPath);

                itemFactory.ItemElement = initialItemElementForFactory;

                return(new ItemData(clonedItem, OriginatingItemElement, ElementOrder, ConditionResult));
            }
Пример #11
0
        /// <inheritdoc />
        public IMonsterEntity CreateMonster(IMapInstance currentMap, IMapLayer currentMapLayer, int moverId, IMapRespawnRegion region, bool respawn = false)
        {
            if (!_gameResources.Movers.TryGetValue(moverId, out MoverData moverData))
            {
                throw new ArgumentException($"Cannot find mover with id '{moverId}' in game resources.", nameof(moverId));
            }

            var monster = new MonsterEntity
            {
                Object = new ObjectComponent
                {
                    ModelId     = moverId,
                    Name        = moverData.Name,
                    Level       = moverData.Level,
                    Type        = WorldObjectType.Mover,
                    Size        = ObjectComponent.DefaultObjectSize,
                    MovingFlags = ObjectState.OBJSTA_STAND,
                    Position    = region.GetRandomPosition(),
                    Angle       = RandomHelper.FloatRandom(0, 360f),
                    Spawned     = true,
                    AbleRespawn = respawn,
                    CurrentMap  = currentMap,
                    LayerId     = currentMapLayer.Id
                },
                Timers = new TimerComponent
                {
                    NextMoveTime = Time.TimeInSeconds() + RandomHelper.LongRandom(8, 20)
                }
            };

            monster.Moves = new MovableComponent
            {
                Speed = moverData.Speed
            };

            monster.Data   = moverData;
            monster.Region = region;
            monster.Attributes[DefineAttributes.HP]  = moverData.AddHp;
            monster.Attributes[DefineAttributes.MP]  = moverData.AddMp;
            monster.Attributes[DefineAttributes.STR] = moverData.Strength;
            monster.Attributes[DefineAttributes.STA] = moverData.Stamina;
            monster.Attributes[DefineAttributes.DEX] = moverData.Dexterity;
            monster.Attributes[DefineAttributes.INT] = moverData.Intelligence;
            monster.Behavior = _behaviorManager.GetBehavior(BehaviorType.Monster, monster, moverId);
            monster.Hand     = _itemFactory.CreateItem(11, 0, ElementType.None, 0);

            if (moverData.Class == MoverClassType.RANK_BOSS)
            {
                monster.Object.Size *= 2;
            }

            return(monster);
        }
Пример #12
0
        public override string Use(int itemPos, User user, string channel)
        {
            base.Use(itemPos, user, channel);

            var items = new List <Item>
            {
                _itemFactory.CreateItem(FarmersArmor.ItemId),
                _itemFactory.CreateItem(FarmersBoots.ItemId),
                _itemFactory.CreateItem(FarmersGloves.ItemId),
                _itemFactory.CreateItem(WoodenShield.ItemId),
                _itemFactory.CreateItem(ShortSword.ItemId),
            };

            _inventoryRepository.AddItems(user, items);

            user.LoadItems(_itemFactory);
            user.InventoryItems.Sort((item1, item2) => item1.InventoryPosition.CompareTo(item2.InventoryPosition));

            var itemNames = string.Join(", ", items.Select(item => item.Name));

            _slack.SendEphemeralMessage(string.Format(DougMessages.YouObtained, $"*{itemNames}*"), user.Id, channel).Wait();

            return(string.Empty);
        }
Пример #13
0
        /// <inheritdoc />
        public void Execute(IPlayerEntity player, object[] parameters)
        {
            _logger.LogTrace($"{player.Object.Name} wants to create an item");

            if (parameters.Length <= 0)
            {
                throw new ArgumentException($"Create item command must have at least one parameter.", nameof(parameters));
            }

            if (!player.Inventory.HasAvailableSlots())
            {
                _textPacketFactory.SendDefinedText(player, DefineText.TID_GAME_LACKSPACE);
                return;
            }
            int         quantity      = parameters.Length >= 2 ? Convert.ToInt32(parameters[1]) : 1;
            byte        refine        = parameters.Length >= 3 ? Convert.ToByte(parameters[2]) : (byte)0;
            ElementType element       = parameters.Length >= 4 ? (ElementType)Enum.Parse(typeof(ElementType), parameters[3].ToString(), true) : default;
            byte        elementRefine = parameters.Length >= 5 ? Convert.ToByte(parameters[4]) : (byte)0;

            string itemInput = parameters[0].ToString();
            Item   itemToCreate;

            if (!int.TryParse(itemInput, out int itemId))
            {
                itemToCreate = _itemFactory.CreateItem(itemInput, refine, element, elementRefine, player.PlayerData.Id);
            }
            else
            {
                itemToCreate = _itemFactory.CreateItem(itemId, refine, element, elementRefine, player.PlayerData.Id);
            }

            if (itemToCreate != null)
            {
                _inventorySystem.CreateItem(player, itemToCreate, quantity, player.PlayerData.Id);
            }
        }
Пример #14
0
        public void Item_Factory_Create_Correct_Item()
        {
            Item item = _itemFactory.CreateItem(759);

            Check.That(item).IsNotNull();
            Check.That(item.Vnum).Is(759);
            Check.That(item.Name).Is("Archmage Wand");
            Check.That(item.BagType).Is(BagType.EQUIPMENT);
            Check.That(item.Type).Is(0);
            Check.That(item.SubType).Is(9);
            Check.That(item.Data).CountIs(20);
            Check.That(item.Data).HasElementAt(0).WhichIs <short>(73);
            Check.That(item.Data).HasElementAt(1).WhichIs <short>(318);
            Check.That(item.Data).HasElementAt(2).WhichIs <short>(366);
            Check.That(item.Data).HasElementAt(3).WhichIs <short>(70);
        }
Пример #15
0
        public void Buy(Interaction interaction)
        {
            var user = _userRepository.GetUser(interaction.UserId);
            var item = _itemFactory.CreateItem(interaction.Value);

            if (!user.HasEnoughCreditsForAmount(item.Price))
            {
                var message = user.NotEnoughCreditsForAmountResponse(item.Price);
                _slack.SendEphemeralMessage(message, user.Id, interaction.ChannelId);
                return;
            }

            _userRepository.RemoveCredits(user.Id, item.Price);

            _inventoryRepository.AddItem(user, item.Id);
        }
Пример #16
0
        /// <inheritdoc />
        public void DropItem(IWorldEntity entity, ItemDescriptor item, IWorldEntity owner, int quantity = 1)
        {
            Item        droppedItem = _itemFactory.CreateItem(item.Id, item.Refine, item.Element, item.ElementRefine);
            IItemEntity newItem     = _itemFactory.CreateItemEntity(entity.Object.CurrentMap, entity.Object.CurrentLayer, droppedItem, owner);

            newItem.Drop.Item.Quantity = quantity;
            newItem.Object.Position    = Vector3.GetRandomPositionInCircle(entity.Object.Position, DropCircleRadius);

            if (newItem.Drop.HasOwner)
            {
                newItem.Drop.OwnershipTime = Time.TimeInSeconds() + _worldServerConfiguration.Drops.OwnershipTime;
                newItem.Drop.DespawnTime   = Time.TimeInSeconds() + _worldServerConfiguration.Drops.DespawnTime;
            }

            owner.Object.CurrentLayer.AddEntity(newItem);
        }
        public string RegisterBag(string username, IEnumerable <string> bagItems)
        {
            var passenger = this.airport.GetPassenger(username);
            var items     = new List <IItem>();

            foreach (var bagItem in bagItems)
            {
                var item = itemFactory.CreateItem(bagItem);
                items.Add(item);
            }
            var bag = new Bag(passenger, items);

            passenger.Bags.Add(bag);

            return($"Registered bag with {string.Join(", ", bagItems)} for {username}");
        }
Пример #18
0
        public override string Use(int itemPos, User user, string channel)
        {
            base.Use(itemPos, user, channel);

            var loot = _randomService.RandomFromWeightedTable(_dropTable);

            var item = _itemFactory.CreateItem(loot.Id);

            _inventoryRepository.AddItems(user, Enumerable.Repeat(item, loot.Quantity));

            user.LoadItems(_itemFactory);
            user.InventoryItems.Sort((item1, item2) => item1.InventoryPosition.CompareTo(item2.InventoryPosition));

            _slack.BroadcastMessage(string.Format(DougMessages.LootboxAnnouncement, _userService.Mention(user), Name, $"{loot.Quantity}x *{item.Name}*"), channel).Wait();

            return(string.Empty);
        }
Пример #19
0
        public DougResponse Buy(User user, string itemId)
        {
            var item = _itemFactory.CreateItem(itemId);

            var price = _governmentService.GetPriceWithTaxes(item);

            if (!user.HasEnoughCreditsForAmount(price))
            {
                return(new DougResponse(user.NotEnoughCreditsForAmountResponse(price)));
            }

            _creditsRepository.RemoveCredits(user.Id, price);

            _inventoryRepository.AddItem(user, item);

            _governmentService.CollectSalesTaxes(item);

            return(new DougResponse());
        }
Пример #20
0
        public async Task ExecuteAsync(
            NhbkAction action,
            ActionContext context,
            INotificationSession notificationSession
            )
        {
            if (action.Type != ActionType)
            {
                throw new InvalidActionTypeException(action.Type, ActionType);
            }
            if (action.Data == null)
            {
                throw new InvalidActionDataException(action.Type);
            }
            if (!action.Data.TemplateId.HasValue)
            {
                throw new InvalidActionDataException(action.Type);
            }

            var itemTemplate = await context.UnitOfWork.ItemTemplates.GetAsync(action.Data.TemplateId.Value);

            if (itemTemplate == null)
            {
                throw new ItemTemplateNotFoundException(action.Data.TemplateId.Value);
            }

            var itemData = new ItemData();

            if (!string.IsNullOrEmpty(action.Data.ItemName))
            {
                itemData.Name = action.Data.ItemName;
            }
            if (action.Data.Quantity.HasValue)
            {
                itemData.Quantity = action.Data.Quantity.Value;
            }

            var item = _itemFactory.CreateItem(ItemOwnerType.Character, context.SourceCharacter.Id, itemTemplate, itemData);

            context.UnitOfWork.Items.Add(item);

            notificationSession.NotifyCharacterAddItem(context.SourceCharacter.Id, item, true);
        }
        public List <IItem> GetItems()
        {
            List <IItem> res = new List <IItem>();

            IItemServiceProxy          s   = this.serviceProxyFactory.CreateItemServiceProxy();
            IResult <List <IItemDTO> > dto = s.GetItems();

            if (dto.IsSuccessful)
            {
                IItemFactory f = this.objectFactory.CreateItemFactory();
                foreach (IItemDTO d in dto.Result)
                {
                    IResult <IItem> item = f.CreateItem(d);
                    res.Add(item.Result);
                }
            }

            return(res);
        }
Пример #22
0
        public ShopMenu(Shop shop, User user, IItemFactory itemFactory, IGovernmentService governmentService)
        {
            var items = shop.ShopItems.Select(itm => itemFactory.CreateItem(itm.ItemId));

            _governmentService = governmentService;
            Blocks             = new List <Block>
            {
                ShopHeader(),
                new Section(new MarkdownText($"*{shop.Name}* \n {shop.Description}")),
                new Divider()
            };

            Blocks.AddRange(items.Aggregate(new List <Block>(), (list, item) => list.Concat(ShopItemSection(item, shop.Id)).ToList()));
            Blocks.Add(new Divider());

            Blocks.Add(new Context(new List <string> {
                string.Format(DougMessages.Balance, user.Credits)
            }));
        }
Пример #23
0
        /// <summary>
        /// Attempts to split this item into two based on the amount provided.
        /// </summary>
        /// <param name="itemFactory">A reference to the item factory in use.</param>
        /// <param name="amount">The amount of the item to split.</param>
        /// <returns>True if the operation was successful, false otherwise, along with the item produced, if any.</returns>
        public (bool success, IItem itemProduced) Split(IItemFactory itemFactory, byte amount)
        {
            itemFactory.ThrowIfNull(nameof(itemFactory));

            if (!this.IsCumulative || this.Amount <= amount)
            {
                return(false, null);
            }

            this.Amount -= amount;

            var remainder = itemFactory.CreateItem(new ItemCreationArguments()
            {
                TypeId = this.Type.TypeId
            });

            remainder.Amount = amount;

            return(true, remainder);
        }
Пример #24
0
        private async Task AddMonsterLootToUser(User user, Monster monster, string channel)
        {
            var droppedItems = _randomService.RandomTableDrop(monster.DropTable, user.ExtraDropChance()).Select(drop => _itemFactory.CreateItem(drop.Id)).ToList();

            if (droppedItems.Any())
            {
                _inventoryRepository.AddItems(user, droppedItems);
                var itemsMessage = string.Join(", ", droppedItems.Select(item => $"*{item.Name}*"));
                await _slack.BroadcastMessage(string.Format(DougMessages.UserObtained, _userService.Mention(user), itemsMessage), channel);
            }
        }
Пример #25
0
        public GroundItem CreateGroundItem(long id, int vnum, int amount)
        {
            Item item = _itemFactory.CreateItem(vnum);

            return(new GroundItem(id, item, amount));
        }
Пример #26
0
        /// <inheritdoc />
        public INpcEntity CreateNpc(IMapContext mapContext, NpcDyoElement element)
        {
            int npcModelId = element.Index;

            if (!_gameResources.Movers.TryGetValue(npcModelId, out MoverData moverData))
            {
                throw new ArgumentException($"Cannot find mover with id '{npcModelId}' in game resources.", nameof(npcModelId));
            }

            var npc = new NpcEntity
            {
                Object = new ObjectComponent
                {
                    MapId      = mapContext.Id,
                    CurrentMap = mapContext as IMapInstance,
                    ModelId    = npcModelId,
                    Name       = element.CharacterKey,
                    Angle      = element.Angle,
                    Position   = element.Position.Clone(),
                    Size       = (short)(ObjectComponent.DefaultObjectSize * element.Scale.X),
                    Spawned    = true,
                    Type       = WorldObjectType.Mover,
                    Level      = 1
                },
                Data = moverData
            };

            npc.Behavior             = _behaviorManager.GetBehavior(BehaviorType.Npc, npc, npc.Object.ModelId);
            npc.Timers.LastSpeakTime = RandomHelper.Random(10, 15);
            npc.Quests = _gameResources.Quests.Values.Where(x => !string.IsNullOrEmpty(x.StartCharacter) && x.StartCharacter.Equals(npc.Object.Name, StringComparison.OrdinalIgnoreCase)).ToList();
            npc.Hand   = _itemFactory.CreateItem(11, 0, ElementType.None, 0);

            if (_gameResources.Npcs.TryGetValue(npc.Object.Name, out NpcData npcData))
            {
                npc.NpcData = npcData;
            }

            if (npc.NpcData != null && npc.NpcData.HasShop)
            {
                ShopData npcShopData = npc.NpcData.Shop;
                npc.Shop = new ItemContainerComponent[npcShopData.Items.Length];

                for (var i = 0; i < npcShopData.Items.Length; i++)
                {
                    npc.Shop[i] = new ItemContainerComponent(100);

                    for (var j = 0; j < npcShopData.Items[i].Count && j < npc.Shop[i].MaxCapacity; j++)
                    {
                        ItemDescriptor item     = npcShopData.Items[i][j];
                        Item           shopItem = _itemFactory.CreateItem(item.Id, item.Refine, item.Element, item.ElementRefine);

                        shopItem.Slot     = j;
                        shopItem.Quantity = shopItem.Data.PackMax;

                        npc.Shop[i].SetItemAtIndex(shopItem, j);
                    }
                }
            }

            return(npc);
        }
 public I CreateItem(I source, string definingProject)
 {
     SetItemElement();
     return(_wrappedItemFactory.CreateItem(source, definingProject));
 }
 public void TestMethod1()
 {
     var             kernel = IoC.IoCKernel.Kernel;
     IItemFactory    f      = kernel.Get <IItemFactory>();
     IResult <IItem> item   = f.CreateItem(3);
 }
Пример #29
0
 public void CreateItem(IItemFactory itemFactory)
 {
     Item = itemFactory.CreateItem(ItemId);
 }
Пример #30
0
        /// <inheritdoc />
        public IPlayerEntity CreatePlayer(DbCharacter character)
        {
            int playerModelId = character.Gender == 0 ? 11 : 12; // TODO: remove these magic numbers

            if (!_gameResources.Movers.TryGetValue(playerModelId, out MoverData moverData))
            {
                throw new ArgumentException($"Cannot find mover with id '{playerModelId}' in game resources.", nameof(playerModelId));
            }

            var player = _playerFactory(_serviceProvider, null) as PlayerEntity;

            IMapInstance map = _mapManager.GetMap(character.MapId);

            if (map == null)
            {
                throw new InvalidOperationException($"Cannot find map with id '{character.MapId}'.");
            }

            IMapLayer mapLayer = map.GetMapLayer(character.MapLayerId) ?? map.DefaultMapLayer;

            player.Object = new ObjectComponent
            {
                ModelId     = playerModelId,
                Type        = WorldObjectType.Mover,
                MapId       = character.MapId,
                CurrentMap  = map,
                LayerId     = mapLayer.Id,
                Position    = new Vector3(character.PosX, character.PosY, character.PosZ),
                Angle       = character.Angle,
                Size        = ObjectComponent.DefaultObjectSize,
                Name        = character.Name,
                Spawned     = false,
                Level       = character.Level,
                MovingFlags = ObjectState.OBJSTA_STAND
            };
            player.VisualAppearance = new VisualAppearenceComponent
            {
                Gender    = character.Gender,
                SkinSetId = character.SkinSetId,
                HairId    = character.HairId,
                HairColor = character.HairColor,
                FaceId    = character.FaceId,
            };
            player.PlayerData = new PlayerDataComponent
            {
                Id         = character.Id,
                Gender     = character.Gender.ToString().ToEnum <GenderType>(),
                Slot       = character.Slot,
                Gold       = character.Gold,
                Authority  = (AuthorityType)character.User.Authority,
                Experience = character.Experience,
                JobData    = _gameResources.Jobs[(DefineJob.Job)character.JobId]
            };
            player.Moves = new MovableComponent
            {
                Speed        = _gameResources.Movers[player.Object.ModelId]?.Speed ?? 0.1f,
                LastMoveTime = Time.GetElapsedTime(),
                NextMoveTime = Time.GetElapsedTime() + 10
            };

            player.Data = moverData;

            player.Attributes[DefineAttributes.HP]  = character.Hp;
            player.Attributes[DefineAttributes.MP]  = character.Mp;
            player.Attributes[DefineAttributes.FP]  = character.Fp;
            player.Attributes[DefineAttributes.STR] = character.Strength;
            player.Attributes[DefineAttributes.STA] = character.Stamina;
            player.Attributes[DefineAttributes.DEX] = character.Dexterity;
            player.Attributes[DefineAttributes.INT] = character.Intelligence;

            player.Statistics          = new StatisticsComponent(character);
            player.Timers.NextHealTime = Time.TimeInSeconds() + RecoverySystem.NextIdleHealStand;

            player.Behavior = _behaviorManager.GetDefaultBehavior(BehaviorType.Player, player);
            player.Hand     = _itemFactory.CreateItem(11, 0, ElementType.None, 0);

            var gameServices = _serviceProvider.GetRequiredService <IEnumerable <IGameSystemLifeCycle> >().OrderBy(x => x.Order);

            foreach (IGameSystemLifeCycle service in gameServices)
            {
                service.Initialize(player);
            }

            mapLayer.AddEntity(player);

            return(player);
        }