Ejemplo n.º 1
0
        /// <summary>
        /// Положить предмет в багажник
        /// </summary>
        public bool PutInTrunk(Client player, Vehicle vehicle, InventoryItem item, int count)
        {
            if (!EnoughItems(player, item, count))
            {
                return(false);
            }
            var vehicleCarring = VehicleManager.GetCarrying((VehicleHash)vehicle.model);
            var vehicleInfo    = _vehicleInfoManager.GetInfoByHandle(player, vehicle);
            var trunk          = vehicleInfo.GetTrunk();

            if (!_inventoryHelper.CanCarry(trunk, item, count, vehicleCarring))
            {
                API.sendColoredNotificationToPlayer(player, "Превышена грузоподъемность транспорта", 0, 6);
                return(false);
            }
            var playerInfo = _playerInfoManager.GetInfo(player);

            playerInfo.Inventory.First(ItemPredicate(item)).DecreaseCount(count);
            var itemInTrunk = trunk.FirstOrDefault(ItemPredicate(item));

            if (itemInTrunk == null)
            {
                item.Count = count;
                trunk.Add(item);
            }
            else
            {
                itemInTrunk.Count += count;
            }
            vehicleInfo.SetTrunk(trunk);
            _vehicleInfoManager.SetInfo(player, vehicleInfo);
            _playerInfoManager.RefreshUI(player, playerInfo);
            _inventoryManager.EquipWeapon(player);
            return(true);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Покупка оружия
        /// </summary>
        private void BuyWeapon(Client player, object[] args)
        {
            var goodItem   = JsonConvert.DeserializeObject <WeaponGood>(args[0].ToString());
            var playerInfo = _playerInfoManager.GetInfo(player);
            var district   = (int)args[1];

            if (!HasMoney(player, playerInfo, goodItem.Price) || district != Validator.INVALID_ID && !HasLicense(player, playerInfo))
            {
                return;
            }
            var item = CreateWeaponItem(playerInfo, goodItem);

            if (!_inventoryHelper.CanCarry(playerInfo.Inventory, item, item.Count))
            {
                API.sendColoredNotificationToPlayer(player, "Превышена грузоподъемность персонажа", 0, 6);
                return;
            }
            playerInfo.Inventory.Add(item);
            playerInfo.Balance -= goodItem.Price;
            _playerInfoManager.RefreshUI(player, playerInfo);
            if (!player.hasData(WorkData.IS_POLICEMAN))
            {
                _inventoryManager.EquipWeapon(player);
            }
            API.sendNotificationToPlayer(player, $"Приобретено ~b~\"{goodItem.Name}\"");
            if (district != Validator.INVALID_ID)
            {
                _clanManager.ReplenishClanBalance(district, goodItem.Price);
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Забрать из хранилища
        /// </summary>
        private void TakeItem(Client player, PlayerInfo playerInfo, long id, int count)
        {
            var item = playerInfo.Inventory.First(e => e.Id == id);

            if (!_inventoryHelper.CanCarry(playerInfo.Inventory, item, count))
            {
                API.sendColoredNotificationToPlayer(player, "Превышена грузоподъемность персонажа", 0, 6);
                return;
            }
            if (item.CountInHouse < count)
            {
                API.sendNotificationToPlayer(player, "~r~Попытка переместить неверное количество");
                return;
            }
            item.CountInHouse -= count;
            item.Count        += count;
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Добавляет покупку в инвентарь
        /// </summary>
        private bool AddItemToInventory(PlayerInfo playerInfo, InventoryType type, int count)
        {
            var item = playerInfo.Inventory.FirstOrDefault(e => e.Type == type) ?? CreateItem(playerInfo.AccountId, type, count);

            if (!_inventoryHelper.CanCarry(playerInfo.Inventory, item, count))
            {
                return(false);
            }
            if (playerInfo.Inventory.Any(e => e.Type == type))
            {
                item.Count += count;
            }
            else
            {
                playerInfo.Inventory.Add(item);
            }
            return(true);
        }