Example #1
0
        public void SetUnitEquipment(int unitId, int slot)
        {
            var(data, defUnit) = _units.GetUnit(unitId);
            var currentEquipment = defUnit.Equipment.Values.FirstOrDefault(x => x.Slot == slot && x.Stars == data.EquipmentStars);

            if (currentEquipment == null)
            {
                throw new Exception($"Unit id ={unitId} no equipment id = {slot}");
            }
            if (!_resources.HasItem(currentEquipment.ItemId))
            {
                throw new Exception($"Unable to insert equipment for a unit. no required item in inventory. unit id = {unitId} slot = {slot} item_id = {currentEquipment.ItemId}");
            }
            data.Equipment[slot] = currentEquipment.ItemId;
            _resources.SpendItem(currentEquipment.ItemId, 1);
            LogicLog.SetEquip(unitId, currentEquipment.ItemId, slot, data.EquipmentStars);
        }