private void ServerRemote_Eat(IItem item) { var character = ServerRemoteContext.Character; this.ServerValidateItemForRemoteCall(item, character); var stats = PlayerCharacter.GetPublicState(character).CurrentStatsExtended; var freshness = ItemFreshnessSystem.SharedGetFreshnessEnum(item); // check that the player has perk to eat a spoiled food if (freshness == ItemFreshness.Red && character.SharedHasPerk(StatName.PerkEatSpoiledFood)) { freshness = ItemFreshness.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)); }
private static bool SharedTryFindItemsOfType( IItemsContainerProvider containers, IProtoItem requiredProtoItem, uint count, out List <IItem> result, double minQualityFraction) { var countToFindRemains = (int)count; result = new List <IItem>(); foreach (var container in containers.ItemsContainers) { foreach (var item in container.Items) { if (item.ProtoItem != requiredProtoItem) { continue; } if (requiredProtoItem is IProtoItemWithDurability && ItemDurabilitySystem.SharedGetDurabilityFraction(item) < minQualityFraction) { // not enough durability continue; } if (requiredProtoItem is IProtoItemWithFreshness && ItemFreshnessSystem.SharedGetFreshnessFraction(item) < minQualityFraction) { // not enough durability continue; } result.Add(item); countToFindRemains -= item.Count; if (countToFindRemains <= 0) { break; } } if (countToFindRemains <= 0) { break; } } return(countToFindRemains <= 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, ItemFreshnessSystem.SharedGetFreshnessEnum(item)))) { return(false); } this.CallServer(_ => _.ServerRemote_Eat(item)); return(true); }
protected virtual void ServerOnEat(ItemEatData data) { var freshnessCoef = ItemFreshnessSystem.SharedGetFreshnessPositiveEffectsCoef(data.Freshness); data.CurrentStats.SharedSetStaminaCurrent(data.CurrentStats.StaminaCurrent + ApplyFreshness(this.StaminaRestore)); data.CurrentStats.ServerSetHealthCurrent(data.CurrentStats.HealthCurrent + ApplyFreshness(this.HealthRestore)); data.CurrentStats.ServerSetFoodCurrent(data.CurrentStats.FoodCurrent + ApplyFreshness(this.FoodRestore)); data.CurrentStats.ServerSetWaterCurrent(data.CurrentStats.WaterCurrent + ApplyFreshness(this.WaterRestore)); // Please note: if player has an artificial stomach than the food freshness cannot be red. if (data.Freshness == ItemFreshness.Red) { // 20% chance to get food poisoning if (RandomHelper.RollWithProbability(0.2)) { data.Character.ServerAddStatusEffect <StatusEffectNausea>(intensity: 0.5); // 5 minutes } } foreach (var effect in this.Effects) { effect.Execute(new EffectActionContext(data.Character)); } float ApplyFreshness(float value) { if (value <= 0) { return(value); } value *= freshnessCoef; return(value); } }
protected override void ServerInitialize(ServerInitializeData data) { base.ServerInitialize(data); ItemFreshnessSystem.ServerInitializeItem(data.PrivateState, data.IsFirstTimeInit); }
protected sealed override void PrepareProtoItem() { base.PrepareProtoItem(); this.FreshnessMaxValue = ItemFreshnessSystem.SharedCalculateFreshnessMaxValue(this); this.PrepareProtoItemWithFreshness(); }
protected override void ServerUpdate(ServerUpdateData data) { ItemFreshnessSystem.ServerUpdateFreshness(data.GameObject, data.DeltaTime); }