protected bool TryEat(GameObject preyGameObject, bool holdingByPlayer = false)
        {
            bool          result        = false;
            BehaviourType behaviourType = BehaviourData.GetBehaviourType(preyGameObject);

            if (this.CanEat(behaviourType, holdingByPlayer))
            {
                base.SendMessage("OnFishEat", preyGameObject, SendMessageOptions.DontRequireReceiver);
                float num = 1f;
                if (behaviourType == BehaviourType.MediumFish)
                {
                    num = 1.5f;
                }
                if (behaviourType == BehaviourType.Shark)
                {
                    num = 3f;
                }
                if (preyGameObject.GetComponent <Creature>() != null)
                {
                    UnityEngine.Object.Destroy(preyGameObject);
                }
                this.creature.Hunger.Add(-this.eatHungerDecrement * num);
                this.creature.Happy.Add(this.eatHappyIncrement * num);
                Peeper component = preyGameObject.GetComponent <Peeper>();
                if (component != null && component.isHero)
                {
                    InfectedMixin component2 = base.GetComponent <InfectedMixin>();
                    if (component2 != null)
                    {
                        component2.Heal(0.5f);
                    }
                }
                result = true;
            }
            return(result);
        }
Пример #2
0
        public static void Postfix(GameObject target, AggressiveWhenSeeTarget __instance, ref bool __result)
        {
            if (target == null)
            {
                __result = false;
                return;
            }
            if (target == __instance.creature.friend)
            {
                __result = false;
                return;
            }
            if (target == Player.main.gameObject && !Player.main.CanBeAttacked())
            {
                __result = false;
                return;
            }
            if (__instance.ignoreSameKind && CraftData.GetTechType(target) == __instance.myTechType)
            {
                __result = false;
                return;
            }
            if (__instance.targetShouldBeInfected)
            {
                InfectedMixin component = target.GetComponent <InfectedMixin>();
                if (component == null || component.GetInfectedAmount() < 0.33f)
                {
                    __result = false;
                    return;
                }
            }

            float dist = Vector3.Distance(target.transform.position, __instance.transform.position);

            if (dist > __instance.maxRangeScalar)
            {
                if (((target != Player.main.gameObject) && !target.GetComponent <Vehicle>()) || (dist > __instance.maxRangeScalar * 4))
                {
                    __result = false;
                    return;
                }

                if (target == Player.main.gameObject)
                {
                    if (Player.main.precursorOutOfWater || PrecursorMoonPoolTrigger.inMoonpool)
                    {
                        __result = false;
                        return;
                    }
                }

                if (target.GetComponent <Vehicle>() != null)
                {
                    if ((target.GetComponent <Vehicle>() != Player.main.currentMountedVehicle) || target.GetComponent <Vehicle>().precursorOutOfWater || PrecursorMoonPoolTrigger.inMoonpool)
                    {
                        __result = false;
                        return;
                    }
                }
            }
            if (!Mathf.Approximately(__instance.minimumVelocity, 0f))
            {
                Rigidbody componentInChildren = target.GetComponentInChildren <Rigidbody>();
                if (componentInChildren != null && componentInChildren.velocity.magnitude <= __instance.minimumVelocity)
                {
                    __result = false;
                    return;
                }
            }

            if ((((target != Player.main.gameObject) || Player.main.IsInside() || Player.main.precursorOutOfWater || PrecursorMoonPoolTrigger.inMoonpool) && (!target.GetComponent <Vehicle>() || (target.GetComponent <Vehicle>() != Player.main.currentMountedVehicle) || target.GetComponent <Vehicle>().precursorOutOfWater)) || // Must be player or vehicle
                (Ocean.main.GetDepthOf(target) <= 5) ||                                                                                                                                                                                                                                                                              // Keeps reapers from eating us up on land
                (!Config.EXORBITANT.Equals(DeathRun.config.creatureAggression) && !Config.DEATHRUN.Equals(DeathRun.config.creatureAggression)) ||                                                                                                                                                                                    // Only on maximum aggression mode
                (DayNightCycle.main.timePassedAsFloat < DeathRun.MORE_AGGRESSION) ||                                                                                                                                                                                                                                                 // Not at very beginning of game
                (CraftData.GetTechType(__instance.gameObject) == TechType.Crash))                                                                                                                                                                                                                                                    // Not the explody fish (more fun from ambush!)
            {
                __result = __instance.creature.GetCanSeeObject(target);
            }
            else
            {
                if (!Config.EXORBITANT.Equals(DeathRun.config.creatureAggression))
                {
                    __result = true; //BR// Can definitely see player "even through terrain"
                }
                else
                {
                    //BR// For DeathRun setting, we don't check "field of view", only that line-of-sight doesn't pass through terrain.
                    __result = !Physics.Linecast(__instance.transform.position, target.transform.position, Voxeland.GetTerrainLayerMask());
                }
            }
        }