示例#1
0
        protected override void ServerOnEat(ItemEatData data)
        {
            ItemBottleEmpty.ServerSpawnEmptyBottle(data.Character);

            // 100% chance to get food poisoning
            data.Character.ServerAddStatusEffect <StatusEffectNausea>(intensity: 0.5); // 5 minutes

            base.ServerOnEat(data);
        }
示例#2
0
        protected override void ServerOnEat(ItemEatData data)
        {
            var character = data.Character;

            ItemBottleEmpty.ServerSpawnEmptyBottle(character);

            // 100% chance to get food poisoning unless you have artificial stomach
            if (!character.SharedHasPerk(StatName.PerkEatSpoiledFood))
            {
                character.ServerAddStatusEffect <StatusEffectNausea>(intensity: 0.5); // 5 minutes
            }

            base.ServerOnEat(data);
        }
示例#3
0
 protected override void ServerOnEat(ItemEatData data)
 {
     ItemBottleEmpty.ServerSpawnEmptyBottle(data.Character);
     base.ServerOnEat(data);
 }
        private static int SharedTryConsumeWaterBottles(
            WateringCanRefillActionState state,
            ICharacter character,
            int waterAmount,
            int waterCapacity)
        {
            IItemsServerService serverItemsService = null;
            IItemsClientService clientItemsService = null;

            var isServer = IsServer;

            if (isServer)
            {
                serverItemsService = Server.Items;
            }
            else
            {
                clientItemsService = Client.Items;
            }

            var totalUsedBottlesCount = 0;
            var maxBottlesToConsume   = MaxBottlesToConsumePerRefill;

            foreach (var itemBottle in state.ItemsToConsumeForRefill)
            {
                // check if character owns this item
                if (!character.ProtoCharacter
                    .SharedEnumerateAllContainers(character, includeEquipmentContainer: false)
                    .Any(c => c.Items.Contains(itemBottle)))
                {
                    throw new Exception("The character doesn't own " + itemBottle + " - cannot use it to reload");
                }

                int itemBottleCountToSubstract;

                var itemBottleCount = itemBottle.Count;
                if (itemBottleCount == 0)
                {
                    continue;
                }

                if (itemBottleCount > maxBottlesToConsume)
                {
                    itemBottleCount = (ushort)maxBottlesToConsume;
                }

                if (waterAmount + itemBottleCount * BottleWaterAmount
                    >= waterCapacity)
                {
                    // there are more than enough item count in that item stack to fully refill the watering can
                    itemBottleCountToSubstract =
                        (int)Math.Ceiling((waterCapacity - waterAmount) / (double)BottleWaterAmount);
                    waterAmount = waterCapacity;
                }
                else
                {
                    // consume full item stack
                    itemBottleCountToSubstract = itemBottleCount;
                    waterAmount += itemBottleCount * BottleWaterAmount;
                }

                if (itemBottleCountToSubstract > 0)
                {
                    maxBottlesToConsume   -= itemBottleCountToSubstract;
                    totalUsedBottlesCount += itemBottleCountToSubstract;

                    // reduce item count
                    var itemBottleNewCount = itemBottle.Count - itemBottleCountToSubstract;
                    if (isServer)
                    {
                        serverItemsService.SetCount(
                            itemBottle,
                            itemBottleNewCount,
                            byCharacter: character,
                            // reloading is also processed on Client-side separately, so no need to send updates
                            isSendingUpdatesToPlayer: false);

                        // spawn empty bottles
                        ItemBottleEmpty.ServerSpawnEmptyBottle(character, (ushort)itemBottleCountToSubstract);
                    }
                    else // if (IsClient)
                    {
                        clientItemsService.SetCount(itemBottle, itemBottleNewCount);
                    }
                }

                if (waterAmount >= waterCapacity)
                {
                    // fully refilled
                    break;
                }

                if (maxBottlesToConsume <= 0)
                {
                    // amount of bottles to consume exceeded
                    break;
                }
            }

            if (IsClient)
            {
                NotificationSystem.ClientShowItemsNotification(
                    new Dictionary <IProtoItem, int>()
                {
                    { GetProtoEntity <ItemBottleWater>(), -totalUsedBottlesCount }
                });
            }

            return(waterAmount);
        }
示例#5
0
        private static int ServerTryConsumeWaterBottles(
            ICharacter character,
            int waterAmount,
            int waterCapacity,
            List <IItem> bottlesToConsume)
        {
            var serverItemsService    = Server.Items;
            var totalUsedBottlesCount = 0;
            var maxBottlesToConsume   = MaxBottlesToConsumePerRefill;

            foreach (var itemBottle in bottlesToConsume)
            {
                // check if character owns this item
                if (!character.ProtoCharacter
                    .SharedEnumerateAllContainers(character, includeEquipmentContainer: false)
                    .Any(c => c.Items.Contains(itemBottle)))
                {
                    throw new Exception("The character doesn't own " + itemBottle + " - cannot use it to reload");
                }

                int itemBottleCountToSubstract;

                var itemBottleCount = itemBottle.Count;
                if (itemBottleCount == 0)
                {
                    continue;
                }

                if (itemBottleCount > maxBottlesToConsume)
                {
                    itemBottleCount = (ushort)maxBottlesToConsume;
                }

                if (waterAmount + itemBottleCount * BottleWaterAmount
                    >= waterCapacity)
                {
                    // there are more than enough item count in that item stack to fully refill the watering can
                    itemBottleCountToSubstract =
                        (int)Math.Ceiling((waterCapacity - waterAmount) / (double)BottleWaterAmount);
                    waterAmount = waterCapacity;
                }
                else
                {
                    // consume full item stack
                    itemBottleCountToSubstract = itemBottleCount;
                    waterAmount += itemBottleCount * BottleWaterAmount;
                }

                if (itemBottleCountToSubstract > 0)
                {
                    maxBottlesToConsume   -= itemBottleCountToSubstract;
                    totalUsedBottlesCount += itemBottleCountToSubstract;

                    // reduce item count
                    var itemBottleNewCount = itemBottle.Count - itemBottleCountToSubstract;
                    serverItemsService.SetCount(
                        itemBottle,
                        itemBottleNewCount,
                        byCharacter: character,
                        isSendingUpdatesToPlayer: true);

                    // spawn empty bottles
                    ItemBottleEmpty.ServerSpawnEmptyBottle(character, (ushort)itemBottleCountToSubstract);
                }

                if (waterAmount >= waterCapacity)
                {
                    // fully refilled
                    break;
                }

                if (maxBottlesToConsume <= 0)
                {
                    // amount of bottles to consume exceeded
                    break;
                }
            }

            NotificationSystem.ServerSendItemsNotification(
                character,
                new Dictionary <IProtoItem, int>()
            {
                { GetProtoEntity <ItemBottleWater>(), -totalUsedBottlesCount }
            });

            return(waterAmount);
        }