public int GetItemCalories(Item item)
    {
        int num;
        ItemModConsumable component = item.info.GetComponent <ItemModConsumable>();

        if (component == null)
        {
            return(0);
        }
        List <ItemModConsumable.ConsumableEffect> .Enumerator enumerator = component.effects.GetEnumerator();
        try
        {
            while (enumerator.MoveNext())
            {
                ItemModConsumable.ConsumableEffect current = enumerator.Current;
                if (current.type != MetabolismAttribute.Type.Calories || current.amount <= 0f)
                {
                    continue;
                }
                num = Mathf.CeilToInt(current.amount);
                return(num);
            }
            return(0);
        }
        finally
        {
            ((IDisposable)enumerator).Dispose();
        }
        return(num);
    }
示例#2
0
    public virtual void EatNearbyFood()
    {
        if (UnityEngine.Time.time < nextEatTime)
        {
            return;
        }
        float num = StaminaCoreFraction();

        nextEatTime = UnityEngine.Time.time + UnityEngine.Random.Range(2f, 3f) + Mathf.InverseLerp(0.5f, 1f, num) * 4f;
        if (num >= 1f)
        {
            return;
        }
        List <BaseEntity> obj = Facepunch.Pool.GetList <BaseEntity>();

        Vis.Entities(base.transform.position + base.transform.forward * 1.5f, 2f, obj, 67109377);
        obj.Sort((BaseEntity a, BaseEntity b) => (b is DroppedItem).CompareTo(a is DroppedItem));
        foreach (BaseEntity item in obj)
        {
            if (item.isClient)
            {
                continue;
            }
            DroppedItem droppedItem = item as DroppedItem;
            if ((bool)droppedItem && droppedItem.item != null && droppedItem.item.info.category == ItemCategory.Food)
            {
                ItemModConsumable component = droppedItem.item.info.GetComponent <ItemModConsumable>();
                if ((bool)component)
                {
                    ReplenishFromFood(component);
                    droppedItem.item.UseItem();
                    if (droppedItem.item.amount <= 0)
                    {
                        droppedItem.Kill();
                    }
                    break;
                }
            }
            CollectibleEntity collectibleEntity = item as CollectibleEntity;
            if ((bool)collectibleEntity && collectibleEntity.IsFood())
            {
                collectibleEntity.DoPickup(null);
                break;
            }
            GrowableEntity growableEntity = item as GrowableEntity;
            if ((bool)growableEntity && growableEntity.CanPick())
            {
                growableEntity.PickFruit(null);
                break;
            }
        }
        Facepunch.Pool.FreeList(ref obj);
    }
示例#3
0
 public void ReplenishFromFood(ItemModConsumable consumable)
 {
     if ((bool)consumable)
     {
         ClientRPC(null, "Eat");
         lastEatTime = UnityEngine.Time.time;
         float ifType  = consumable.GetIfType(MetabolismAttribute.Type.Calories);
         float ifType2 = consumable.GetIfType(MetabolismAttribute.Type.Hydration);
         float num     = consumable.GetIfType(MetabolismAttribute.Type.Health) + consumable.GetIfType(MetabolismAttribute.Type.HealthOverTime);
         ApplyDungCalories(ifType);
         ReplenishStaminaCore(ifType, ifType2);
         Heal(num * 4f);
     }
 }
示例#4
0
    public int GetItemCalories(Item item)
    {
        ItemModConsumable component = (ItemModConsumable)((Component)item.info).GetComponent <ItemModConsumable>();

        if (Object.op_Equality((Object)component, (Object)null))
        {
            return(0);
        }
        foreach (ItemModConsumable.ConsumableEffect effect in component.effects)
        {
            if (effect.type == MetabolismAttribute.Type.Calories && (double)effect.amount > 0.0)
            {
                return(Mathf.CeilToInt(effect.amount));
            }
        }
        return(0);
    }
示例#5
0
    public int GetBaitCalories()
    {
        int num = 0;

        foreach (Item obj in this.inventory.itemList)
        {
            ItemModConsumable component = (ItemModConsumable)((Component)obj.info).GetComponent <ItemModConsumable>();
            if (!Object.op_Equality((Object)component, (Object)null) && !this.ignoreBait.Contains(obj.info))
            {
                foreach (ItemModConsumable.ConsumableEffect effect in component.effects)
                {
                    if (effect.type == MetabolismAttribute.Type.Calories && (double)effect.amount > 0.0)
                    {
                        num += Mathf.CeilToInt(effect.amount * (float)obj.amount);
                    }
                }
            }
        }
        return(num);
    }
示例#6
0
    private void GiveEffectsTo(BasePlayer player)
    {
        if (!player)
        {
            return;
        }
        ItemModConsumable component = GetOwnerItemDefinition().GetComponent <ItemModConsumable>();

        if (!component)
        {
            Debug.LogWarning("No consumable for medicaltool :" + base.name);
        }
        else
        {
            if (Interface.CallHook("OnHealingItemUse", this, player) != null)
            {
                return;
            }
            BasePlayer ownerPlayer = GetOwnerPlayer();
            if (player != ownerPlayer && player.IsWounded() && canRevive)
            {
                if (Interface.CallHook("OnPlayerRevive", GetOwnerPlayer(), player) != null)
                {
                    return;
                }
                player.StopWounded(ownerPlayer);
            }
            foreach (ItemModConsumable.ConsumableEffect effect in component.effects)
            {
                if (effect.type == MetabolismAttribute.Type.Health)
                {
                    player.health += effect.amount;
                }
                else
                {
                    player.metabolism.ApplyChange(effect.type, effect.amount, effect.time);
                }
            }
        }
    }
示例#7
0
    private void GiveEffectsTo(BasePlayer player)
    {
        if (!Object.op_Implicit((Object)player))
        {
            return;
        }
        ItemModConsumable component = (ItemModConsumable)((Component)this.GetOwnerItemDefinition()).GetComponent <ItemModConsumable>();

        if (!Object.op_Implicit((Object)component))
        {
            Debug.LogWarning((object)("No consumable for medicaltool :" + ((Object)this).get_name()));
        }
        else
        {
            if (Interface.CallHook("OnHealingItemUse", (object)this, (object)player) != null)
            {
                return;
            }
            if (Object.op_Inequality((Object)player, (Object)this.GetOwnerPlayer()) && player.IsWounded() && this.canRevive)
            {
                if (Interface.CallHook("OnPlayerRevive", (object)this.GetOwnerPlayer(), (object)player) != null)
                {
                    return;
                }
                player.StopWounded();
            }
            foreach (ItemModConsumable.ConsumableEffect effect in component.effects)
            {
                if (effect.type == MetabolismAttribute.Type.Health)
                {
                    player.health += effect.amount;
                }
                else
                {
                    player.metabolism.ApplyChange(effect.type, effect.amount, effect.time);
                }
            }
        }
    }
    public int GetBaitCalories()
    {
        int num = 0;

        foreach (Item item in this.inventory.itemList)
        {
            ItemModConsumable component = item.info.GetComponent <ItemModConsumable>();
            if (component == null || this.ignoreBait.Contains(item.info))
            {
                continue;
            }
            foreach (ItemModConsumable.ConsumableEffect effect in component.effects)
            {
                if (effect.type != MetabolismAttribute.Type.Calories || effect.amount <= 0f)
                {
                    continue;
                }
                num += Mathf.CeilToInt(effect.amount * (float)item.amount);
            }
        }
        return(num);
    }
    public void EatNearbyFood()
    {
        if (Time.time < this.nextEatTime)
        {
            return;
        }
        float single = this.StaminaCoreFraction();

        this.nextEatTime = Time.time + UnityEngine.Random.Range(2f, 3f) + Mathf.InverseLerp(0.5f, 1f, single) * 4f;
        if (single >= 1f)
        {
            return;
        }
        List <BaseEntity> list = Pool.GetList <BaseEntity>();

        Vis.Entities <BaseEntity>(base.transform.position + (base.transform.forward * 1.5f), 2f, list, 67109377, QueryTriggerInteraction.Collide);
        list.Sort((BaseEntity a, BaseEntity b) => b is DroppedItem.CompareTo(a is DroppedItem));
        foreach (BaseEntity baseEntity in list)
        {
            if (baseEntity.isClient)
            {
                continue;
            }
            DroppedItem droppedItem = baseEntity as DroppedItem;
            if (droppedItem && droppedItem.item != null && droppedItem.item.info.category == ItemCategory.Food)
            {
                ItemModConsumable component = droppedItem.item.info.GetComponent <ItemModConsumable>();
                if (component)
                {
                    base.ClientRPC(null, "Eat");
                    this.lastEatTime = Time.time;
                    float ifType  = component.GetIfType(MetabolismAttribute.Type.Calories);
                    float ifType1 = component.GetIfType(MetabolismAttribute.Type.Hydration);
                    float single1 = component.GetIfType(MetabolismAttribute.Type.Health) + component.GetIfType(MetabolismAttribute.Type.HealthOverTime);
                    this.ReplenishStaminaCore(ifType, ifType1);
                    this.Heal(single1 * 2f);
                    droppedItem.item.UseItem(1);
                    if (droppedItem.item.amount > 0)
                    {
                        break;
                    }
                    droppedItem.Kill(BaseNetworkable.DestroyMode.None);
                    Pool.FreeList <BaseEntity>(ref list);
                    return;
                }
            }
            CollectibleEntity collectibleEntity = baseEntity as CollectibleEntity;
            if (!collectibleEntity || !collectibleEntity.IsFood())
            {
                PlantEntity plantEntity = baseEntity as PlantEntity;
                if (!plantEntity || !plantEntity.CanPick())
                {
                    continue;
                }
                plantEntity.PickFruit(null);
                Pool.FreeList <BaseEntity>(ref list);
                return;
            }
            else
            {
                collectibleEntity.DoPickup(null);
                Pool.FreeList <BaseEntity>(ref list);
                return;
            }
        }
        Pool.FreeList <BaseEntity>(ref list);
    }
示例#10
0
    public override void DoAction(Item item, BasePlayer player)
    {
        if (item.amount < 1)
        {
            return;
        }
        GameObjectRef consumeEffect = this.GetConsumeEffect();

        if (consumeEffect.isValid)
        {
            Vector3 vector3 = (player.IsDucked() ? new Vector3(0f, 1f, 0f) : new Vector3(0f, 2f, 0f));
            Effect.server.Run(consumeEffect.resourcePath, player, 0, vector3, Vector3.zero, null, false);
        }
        player.metabolism.MarkConsumption();
        ItemModConsumable consumable = this.GetConsumable();

        if (!string.IsNullOrEmpty(consumable.achievementWhenEaten))
        {
            player.GiveAchievement(consumable.achievementWhenEaten);
        }
        float single  = (float)Mathf.Max(consumable.amountToConsume, 1);
        float single1 = (float)Mathf.Min((float)item.amount, single);
        float single2 = single1 / single;
        float single3 = item.conditionNormalized;

        if (consumable.conditionFractionToLose > 0f)
        {
            single3 = consumable.conditionFractionToLose;
        }
        foreach (ItemModConsumable.ConsumableEffect effect in consumable.effects)
        {
            if (player.healthFraction > effect.onlyIfHealthLessThan)
            {
                continue;
            }
            if (effect.type != MetabolismAttribute.Type.Health)
            {
                player.metabolism.ApplyChange(effect.type, effect.amount * single2 * single3, effect.time * single2 * single3);
            }
            else if (effect.amount >= 0f)
            {
                BasePlayer basePlayer = player;
                basePlayer.health = basePlayer.health + effect.amount * single2 * single3;
            }
            else
            {
                player.OnAttacked(new HitInfo(player, player, DamageType.Generic, -effect.amount * single2 * single3, player.transform.position + (player.transform.forward * 1f)));
            }
        }
        if (this.product != null)
        {
            ItemAmountRandom[] itemAmountRandomArray = this.product;
            for (int i = 0; i < (int)itemAmountRandomArray.Length; i++)
            {
                ItemAmountRandom itemAmountRandom = itemAmountRandomArray[i];
                int num = Mathf.RoundToInt((float)itemAmountRandom.RandomAmount() * single3);
                if (num > 0)
                {
                    Item item1 = ItemManager.Create(itemAmountRandom.itemDef, num, (ulong)0);
                    player.GiveItem(item1, BaseEntity.GiveItemReason.Generic);
                }
            }
        }
        if (string.IsNullOrEmpty(this.eatGesture))
        {
            player.SignalBroadcast(BaseEntity.Signal.Gesture, this.eatGesture, null);
        }
        if (consumable.conditionFractionToLose <= 0f)
        {
            item.UseItem((int)single1);
            return;
        }
        item.LoseCondition(consumable.conditionFractionToLose * item.maxCondition);
    }
    public override void DoAction(Item item, BasePlayer player)
    {
        if (item.amount < 1)
        {
            return;
        }
        GameObjectRef consumeEffect = this.GetConsumeEffect();

        if (consumeEffect.isValid)
        {
            Vector3 posLocal = player.IsDucked() ? new Vector3(0.0f, 1f, 0.0f) : new Vector3(0.0f, 2f, 0.0f);
            Effect.server.Run(consumeEffect.resourcePath, (BaseEntity)player, 0U, posLocal, Vector3.get_zero(), (Connection)null, false);
        }
        player.metabolism.MarkConsumption();
        ItemModConsumable consumable = this.GetConsumable();
        float             num1       = (float)Mathf.Max(consumable.amountToConsume, 1);
        float             num2       = Mathf.Min((float)item.amount, num1);
        float             num3       = num2 / num1;
        float             num4       = item.conditionNormalized;

        if ((double)consumable.conditionFractionToLose > 0.0)
        {
            num4 = consumable.conditionFractionToLose;
        }
        foreach (ItemModConsumable.ConsumableEffect effect in consumable.effects)
        {
            if ((double)player.healthFraction <= (double)effect.onlyIfHealthLessThan)
            {
                if (effect.type == MetabolismAttribute.Type.Health)
                {
                    if ((double)effect.amount < 0.0)
                    {
                        player.OnAttacked(new HitInfo((BaseEntity)player, (BaseEntity)player, DamageType.Generic, -effect.amount * num3 * num4, Vector3.op_Addition(((Component)player).get_transform().get_position(), Vector3.op_Multiply(((Component)player).get_transform().get_forward(), 1f))));
                    }
                    else
                    {
                        player.health += effect.amount * num3 * num4;
                    }
                }
                else
                {
                    player.metabolism.ApplyChange(effect.type, effect.amount * num3 * num4, effect.time * num3 * num4);
                }
            }
        }
        if (this.product != null)
        {
            foreach (ItemAmountRandom itemAmountRandom in this.product)
            {
                int iAmount = Mathf.RoundToInt((float)itemAmountRandom.RandomAmount() * num4);
                if (iAmount > 0)
                {
                    Item obj = ItemManager.Create(itemAmountRandom.itemDef, iAmount, 0UL);
                    player.GiveItem(obj, BaseEntity.GiveItemReason.Generic);
                }
            }
        }
        if (string.IsNullOrEmpty(this.eatGesture))
        {
            player.SignalBroadcast(BaseEntity.Signal.Gesture, this.eatGesture, (Connection)null);
        }
        if ((double)consumable.conditionFractionToLose > 0.0)
        {
            item.LoseCondition(consumable.conditionFractionToLose * item.maxCondition);
        }
        else
        {
            item.UseItem((int)num2);
        }
    }
示例#12
0
    public override void DoAction(Item item, BasePlayer player)
    {
        if (item.amount < 1)
        {
            return;
        }
        GameObjectRef gameObjectRef = GetConsumeEffect();

        if (gameObjectRef.isValid)
        {
            Vector3 posLocal = (player.IsDucked() ? new Vector3(0f, 1f, 0f) : new Vector3(0f, 2f, 0f));
            Effect.server.Run(gameObjectRef.resourcePath, player, 0u, posLocal, Vector3.zero);
        }
        player.metabolism.MarkConsumption();
        ItemModConsumable consumable = GetConsumable();

        if (!string.IsNullOrEmpty(consumable.achievementWhenEaten))
        {
            player.GiveAchievement(consumable.achievementWhenEaten);
        }
        float num  = Mathf.Max(consumable.amountToConsume, 1);
        float num2 = Mathf.Min(item.amount, num);
        float num3 = num2 / num;
        float num4 = item.conditionNormalized;

        if (consumable.conditionFractionToLose > 0f)
        {
            num4 = consumable.conditionFractionToLose;
        }
        foreach (ItemModConsumable.ConsumableEffect effect in consumable.effects)
        {
            if (Mathf.Clamp01(player.healthFraction + player.metabolism.pending_health.Fraction()) > effect.onlyIfHealthLessThan)
            {
                continue;
            }
            if (effect.type == MetabolismAttribute.Type.Health)
            {
                if (effect.amount < 0f)
                {
                    player.OnAttacked(new HitInfo(player, player, DamageType.Generic, (0f - effect.amount) * num3 * num4, player.transform.position + player.transform.forward * 1f));
                }
                else
                {
                    player.health += effect.amount * num3 * num4;
                }
            }
            else
            {
                player.metabolism.ApplyChange(effect.type, effect.amount * num3 * num4, effect.time * num3 * num4);
            }
        }
        if (player.modifiers != null && Interface.CallHook("OnPlayerAddModifiers", player, item, consumable) == null)
        {
            player.modifiers.Add(consumable.modifiers);
        }
        if (product != null)
        {
            ItemAmountRandom[] array = product;
            foreach (ItemAmountRandom itemAmountRandom in array)
            {
                int num5 = Mathf.RoundToInt((float)itemAmountRandom.RandomAmount() * num4);
                if (num5 > 0)
                {
                    Item item2 = ItemManager.Create(itemAmountRandom.itemDef, num5, 0uL);
                    player.GiveItem(item2);
                }
            }
        }
        if (string.IsNullOrEmpty(eatGesture))
        {
            player.SignalBroadcast(BaseEntity.Signal.Gesture, eatGesture);
        }
        if (consumable.conditionFractionToLose > 0f)
        {
            item.LoseCondition(consumable.conditionFractionToLose * item.maxCondition);
        }
        else
        {
            item.UseItem((int)num2);
        }
    }