Example #1
0
        private void ServerRemote_Eat(IItem item)
        {
            var character = ServerRemoteContext.Character;

            this.ServerValidateItemForRemoteCall(item, character);

            var stats = PlayerCharacter.GetPublicState(character).CurrentStatsExtended;

            var freshness = FoodSpoilageSystem.SharedGetFreshnessEnum(item);

            // check that the player has perk to eat a spoiled food
            if (freshness == FoodFreshness.Red &&
                character.SharedHasPerk(StatName.PerkEatSpoiledFood))
            {
                freshness = FoodFreshness.Yellow;
            }

            var itemEatData = new ItemEatData(item, character, stats, freshness);

            if (!this.SharedCanEat(itemEatData))
            {
                return;
            }

            this.ServerOnEat(itemEatData);
            Logger.Important(character + " consumed " + item);

            this.ServerNotifyItemUsed(character, item);
            // decrease item count
            Server.Items.SetCount(item, (ushort)(item.Count - 1));
        }
Example #2
0
        protected override bool ClientItemUseFinish(ClientItemData data)
        {
            var character = Client.Characters.CurrentPlayerCharacter;
            var item      = data.Item;
            var stats     = PlayerCharacter.GetPublicState(character).CurrentStatsExtended;

            if (!this.SharedCanEat(
                    new ItemEatData(item,
                                    character,
                                    stats,
                                    FoodSpoilageSystem.SharedGetFreshnessEnum(item))))
            {
                return(false);
            }

            this.CallServer(_ => _.ServerRemote_Eat(item));
            return(true);
        }