예제 #1
0
        protected override bool ServerIsCompleted(ICharacter character, PlayerTaskStateWithCount state)
        {
            var containers = new CharacterContainersProvider(character, includeEquipmentContainer: true);

            if (this.RequiredCount == 1)
            {
                // only one item is required
                foreach (var protoItem in this.List)
                {
                    if (containers.ContainsItemsOfType(protoItem, requiredCount: 1))
                    {
                        // found at least one item of the required item type
                        state.SetCountCurrent(1, countMax: 1);
                        return(true);
                    }
                }

                state.SetCountCurrent(0, countMax: 1);
                return(false);
            }

            // more than a single item is required
            var availableCount = 0;

            foreach (var protoItem in this.List)
            {
                availableCount += containers.CountItemsOfType(protoItem);
                if (availableCount >= this.RequiredCount)
                {
                    break;
                }
            }

            state.SetCountCurrent(this.IsReversible
                                      ? availableCount
                                      : Math.Max(state.CountCurrent, availableCount),
                                  this.RequiredCount);
            return(state.CountCurrent >= this.RequiredCount);
        }
        public string Execute(
            double durabilityPercent = 100,
            [CurrentCharacterIfNull] ICharacter character = null)
        {
            var durabilityFraction = MathHelper.Clamp(durabilityPercent / 100, min: 0, max: 1);
            var containers         = new CharacterContainersProvider(character, includeEquipmentContainer: true);

            foreach (var container in containers.Containers)
            {
                foreach (var item in Api.Shared.WrapInTempList(container.Items).EnumerateAndDispose())
                {
                    if (item.ProtoItem is IProtoItemWithDurability protoItemWithDurability)
                    {
                        var privateState = item.GetPrivateState <IItemWithDurabilityPrivateState>();
                        var durability   = protoItemWithDurability.DurabilityMax * durabilityFraction;
                        privateState.DurabilityCurrent = (uint)Math.Round(durability, MidpointRounding.AwayFromZero);
                    }
                }
            }

            return($"Durability of all items modified to {durabilityFraction * 100}%");
        }
        public string Execute(
            double chargePercent = 100,
            [CurrentCharacterIfNull] ICharacter character = null)
        {
            var chargeFraction = MathHelper.Clamp(chargePercent / 100, min: 0, max: 1);
            var containers     = new CharacterContainersProvider(character, includeEquipmentContainer: true);

            foreach (var container in containers.Containers)
            {
                foreach (var item in Api.Shared.WrapInTempList(container.Items).EnumerateAndDispose())
                {
                    switch (item.ProtoItem)
                    {
                    case IProtoItemPowerBank protoItemPowerBank:
                    {
                        var itemPrivateState = item.GetPrivateState <ItemPowerBankPrivateState>();
                        var capacity         = protoItemPowerBank.EnergyCapacity;
                        itemPrivateState.EnergyCharge = capacity * chargeFraction;
                        break;
                    }

                    case IProtoItemWithFuel protoItemWithFuel:
                    {
                        var privateState = item.GetPrivateState <ItemWithFuelPrivateState>();
                        var fuel         = protoItemWithFuel.ItemFuelConfig.FuelCapacity * chargeFraction;
                        privateState.FuelAmount = (uint)Math.Round(fuel, MidpointRounding.AwayFromZero);
                        protoItemWithFuel.ItemFuelConfig.SharedOnRefilled(item,
                                                                          privateState.FuelAmount,
                                                                          serverNotifyClients: true);
                        break;
                    }
                    }
                }
            }

            return($"Charge/fuel amount of all items modified to {chargeFraction * 100}%");
        }