Пример #1
0
        /// <inheritdoc />
        public void ChangeFace(IPlayerEntity player, uint objectId, uint faceId, bool useCoupon)
        {
            if (!useCoupon)
            {
                if (player.PlayerData.Gold < _worldServerConfiguration.Customization.ChangeFaceCost)
                {
                    _textPacketFactory.SendDefinedText(player, DefineText.TID_GAME_LACKMONEY);
                }
                else
                {
                    player.VisualAppearance.FaceId = (int)faceId;
                    _playerDataSystem.DecreaseGold(player, (int)_worldServerConfiguration.Customization.ChangeFaceCost);
                    _customizationPacketFactory.SendChangeFace(player, faceId);
                }
            }
            else
            {
                Item couponItem = player.Inventory.GetItemById(DefineItem.II_SYS_SYS_SCR_FACEOFFFREE);

                if (couponItem == null)
                {
                    _textPacketFactory.SendDefinedText(player, DefineText.TID_GAME_WARNNING_COUPON);
                    return;
                }

                _inventorySystem.DeleteItem(player, couponItem, 1);

                _customizationPacketFactory.SendChangeFace(player, faceId);
            }
        }
Пример #2
0
        /// <inheritdoc />
        public void BuyItem(IPlayerEntity player, NpcShopItemInfo shopItemInfo, int quantity)
        {
            var npc = player.FindEntity <INpcEntity>(x => x.Object.Name == player.PlayerData.CurrentShopName);

            if (npc == null)
            {
                _logger.LogError($"ShopSystem: Cannot find NPC: {player.PlayerData.CurrentShopName}");
                return;
            }

            if (!npc.NpcData.HasShop)
            {
                _logger.LogError($"ShopSystem: NPC {npc.Object.Name} doesn't have a shop.");
                return;
            }

            if (shopItemInfo.Tab < 0 || shopItemInfo.Tab >= ShopData.DefaultTabCount)
            {
                _logger.LogError($"Attempt to buy an item from {npc.Object.Name} shop tab that is out of range.");
                return;
            }

            ItemContainerComponent shopTab = npc.Shop.ElementAt(shopItemInfo.Tab);

            if (shopItemInfo.Slot < 0 || shopItemInfo.Slot > shopTab.MaxCapacity - 1)
            {
                _logger.LogError($"ShopSystem: Item slot index was out of tab bounds. Slot: {shopItemInfo.Slot}");
                return;
            }

            Item shopItem = shopTab.GetItemAtSlot(shopItemInfo.Slot);

            if (shopItem.Id != shopItemInfo.ItemId)
            {
                _logger.LogError($"ShopSystem: Shop item id doens't match the item id that {player.Object.Name} is trying to buy.");
                return;
            }

            if (player.PlayerData.Gold < shopItem.Data.Cost)
            {
                _logger.LogTrace($"ShopSystem: {player.Object.Name} doens't have enough gold to buy item {shopItem.Data.Name} at {shopItem.Data.Cost}.");
                _textPacketFactory.SendDefinedText(player, DefineText.TID_GAME_LACKMONEY);
                return;
            }

            int itemsCreatedCount = _inventorySystem.CreateItem(player, shopItem, quantity);

            if (itemsCreatedCount > 0)
            {
                _playerDataSystem.DecreaseGold(player, shopItem.Data.Cost * itemsCreatedCount);
            }
        }