Exemplo n.º 1
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);
     }
 }
    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);
    }