예제 #1
0
        public override void Perform(Creature creature, float deltaTime)
        {
            //Debugger.Log("attack prio : " + prio);

            ProfilingUtils.BeginSample("CreatureAction::Perform (AttackEcoTarget)");

            if (Time.time > this.timeNextSwim)
            {
                this.timeNextSwim = Time.time + this.swimInterval;

                Vector3 position = Player.main.transform.position;

                Vector3 targetDirection = -MainCamera.camera.transform.forward;

                base.swimBehaviour.Attack(position, targetDirection, this.swimVelocity);
            }

            if (this.resetAggressionOnTime && Time.time > this.timeStartAttack + this.maxAttackDuration)
            {
                this.StopAttack();
            }

            ProfilingUtils.EndSample(null);
        }
예제 #2
0
        public static bool Prefix(Creature __instance, float deltaTime, Animator ___traitsAnimator, ref CreatureAction ___lastAction,
                                  CreatureAction ___prevBestAction, float ___flinch, float ___flinchFadeRate, List <CreatureAction> ___actions, ref int ___indexLastActionChecked,
                                  ref int ___animAggressive, ref int ___animScared, ref int ___animTired, ref int ___animHappy, ref int ___animFlinch)
        {
            TechType techType   = CraftData.GetTechType(__instance.gameObject);
            string   myTechType = techType.AsString(true);

            if (!(myTechType == "ghostleviathan" || myTechType == "ghostleviathanjuvenile") || !PassiveGhostLeviathansPatcher.Config.isGhostPassive)
            {
                return(true);
            }

            int myIndexLast = ___indexLastActionChecked;

            CreatureAction ChooseBestAction()
            {
                if (___actions.Count == 0)
                {
                    return(null);
                }
                if (__instance.liveMixin && !__instance.liveMixin.IsAlive())
                {
                    SwimBehaviour component = __instance.GetComponentInParent <SwimBehaviour>();
                    if (component)
                    {
                        component.Idle();
                    }
                    return(null);
                }
                ProfilingUtils.BeginSample("Creature.ChooseBestAction");
                float          mynum            = 0f;
                CreatureAction mycreatureAction = null;

                if (___prevBestAction != null)
                {
                    mycreatureAction = ___prevBestAction;
                    ProfilingUtils.BeginSample("bestAction.Evaluate");
                    mynum = mycreatureAction.Evaluate(__instance);
                    ProfilingUtils.EndSample(null);
                }
                myIndexLast++;
                if (myIndexLast >= ___actions.Count)
                {
                    myIndexLast = 0;
                }
                CreatureAction creatureAction2 = ___actions[myIndexLast];

                ProfilingUtils.BeginSample("current.Evaluate");
                float num2 = creatureAction2.Evaluate(__instance);

                ProfilingUtils.EndSample(null);
                if (num2 > mynum && !Utils.NearlyEqual(num2, 0f, 1E-45f))
                {
                    mycreatureAction = creatureAction2;
                }
                ProfilingUtils.EndSample(null);
                return(mycreatureAction);
            }

            ___indexLastActionChecked = myIndexLast;

            ProfilingUtils.BeginSample("CreatureBehavior::Update");
            ProfilingUtils.BeginSample("choose action");
            CreatureAction creatureAction = ChooseBestAction();

            if (___prevBestAction != creatureAction)
            {
                if (___prevBestAction)
                {
                    ___prevBestAction.StopPerform(__instance);
                }
                if (creatureAction)
                {
                    //Logger.Log(creatureAction.ToString());
                    creatureAction.StartPerform(__instance);
                }
                ___prevBestAction = creatureAction;
            }
            ProfilingUtils.EndSample(null);
            if (creatureAction)
            {
                ProfilingUtils.BeginSample("perform action");
                creatureAction.Perform(__instance, deltaTime);
                ProfilingUtils.EndSample(null);
            }
            float num = DayNightUtils.Evaluate(1f, __instance.activity);

            __instance.Tired.Value = Mathf.Lerp(__instance.Tired.Value, 1f - num, 0.1f * deltaTime);
            ProfilingUtils.BeginSample("update traits");
            __instance.Curiosity.UpdateTrait(deltaTime);
            __instance.Friendliness.UpdateTrait(deltaTime);
            __instance.Hunger.UpdateTrait(deltaTime);
            __instance.Aggression.UpdateTrait(deltaTime);
            __instance.Scared.UpdateTrait(deltaTime);
            __instance.Tired.UpdateTrait(deltaTime);
            __instance.Happy.UpdateTrait(deltaTime);
            ___flinch = Mathf.Lerp(___flinch, 0f, ___flinchFadeRate * deltaTime);
            ProfilingUtils.EndSample(null);
            if (___traitsAnimator && ___traitsAnimator.isActiveAndEnabled)
            {
                ___traitsAnimator.SetFloat(___animAggressive, __instance.Aggression.Value);
                ___traitsAnimator.SetFloat(___animScared, __instance.Scared.Value);
                ___traitsAnimator.SetFloat(___animTired, __instance.Tired.Value);
                ___traitsAnimator.SetFloat(___animHappy, __instance.Happy.Value);
                ___traitsAnimator.SetFloat(___animFlinch, ___flinch);
            }
            ProfilingUtils.EndSample(null);
            return(false);
        }
예제 #3
0
        public static bool Prefix(MoveTowardsTarget __instance)
        {
            float aggressionMultiplier;
            int   aggressionRadius;

            if (CraftData.GetTechType(__instance.gameObject) == TechType.Crash)
            {
                return(true); // Explody ambush fish just runs normal method
            }

            if (Player.main.precursorOutOfWater || !Player.main.IsUnderwater() || PrecursorMoonPoolTrigger.inMoonpool || (Ocean.main.GetDepthOf(Player.main.gameObject) < 5))
            {
                return(true);
            }

            Vehicle veh = Player.main.currentMountedVehicle;

            if (veh != null)
            {
                if (veh.precursorOutOfWater)
                {
                    return(true);
                }
            }

            //BR// Adjust aggression levels
            if (Config.DEATHRUN.Equals(DeathRun.config.creatureAggression) || Config.EXORBITANT.Equals(DeathRun.config.creatureAggression))
            {
                if (DayNightCycle.main.timePassedAsFloat > DeathRun.FULL_AGGRESSION)
                {
                    aggressionMultiplier = 4;
                    aggressionRadius     = 6;
                }
                else if (DayNightCycle.main.timePassedAsFloat > DeathRun.MORE_AGGRESSION)
                {
                    aggressionMultiplier = 2;
                    aggressionRadius     = 3;
                }
                else
                {
                    return(true);
                }
            }
            else if (Config.HARD.Equals(DeathRun.config.creatureAggression) && (DayNightCycle.main.timePassedAsFloat > DeathRun.MORE_AGGRESSION))
            {
                aggressionMultiplier = 2;
                aggressionRadius     = 3;
            }
            else
            {
                return(true); // Just run normal method
            }

            ProfilingUtils.BeginSample("UpdateCurrentTarget");
            if (EcoRegionManager.main != null && (Mathf.Approximately(__instance.requiredAggression, 0f) || __instance.creature.Aggression.Value * aggressionMultiplier >= __instance.requiredAggression))
            {
                IEcoTarget ecoTarget = EcoRegionManager.main.FindNearestTarget(__instance.targetType, __instance.transform.position, __instance.isTargetValidFilter, aggressionRadius);

                if (ecoTarget != null)
                {
                    __instance.currentTarget = ecoTarget;
                }
                else
                {
                    __instance.currentTarget = null;
                }
            }
            ProfilingUtils.EndSample(null);
            return(false);
        }
예제 #4
0
        public static void PostFix(EcoRegion __instance, EcoTargetType type, Vector3 wsPos, EcoRegion.TargetFilter isTargetValid, ref float bestDist, ref IEcoTarget best)
        {
            if (DeathRun.crashFishSemaphore)
            {
                return;
            }

            ProfilingUtils.BeginSample("EcoRegion.FindNearestTarget");
            __instance.timeStamp = Time.time;
            System.Collections.Generic.HashSet <IEcoTarget> hashSet;
            if (!__instance.ecoTargets.TryGetValue((int)type, out hashSet))
            {
                ProfilingUtils.EndSample(null);
                return;
            }
            float num = float.MaxValue;

            foreach (IEcoTarget ecoTarget in hashSet)
            {
                if (ecoTarget != null && !ecoTarget.Equals(null))
                {
                    float sqrMagnitude = (wsPos - ecoTarget.GetPosition()).sqrMagnitude;

                    if (((ecoTarget.GetGameObject() == Player.main.gameObject) && !Player.main.IsInside() && Player.main.IsUnderwater() && !Player.main.precursorOutOfWater) ||
                        (ecoTarget.GetGameObject().GetComponent <Vehicle>() && (ecoTarget.GetGameObject().GetComponent <Vehicle>() == Player.main.currentMountedVehicle)) && !Player.main.currentMountedVehicle.precursorOutOfWater)
                    {
                        bool feeding = false;
                        if (ecoTarget.GetGameObject() == Player.main.gameObject)
                        {
                            Pickupable held = Inventory.main.GetHeld();
                            if (held != null && (held.GetTechType() == TechType.Peeper))
                            {
                                feeding = true;
                            }
                        }

                        float depth = Ocean.main.GetDepthOf(ecoTarget.GetGameObject());
                        if ((depth > 5) && !feeding)
                        {
                            if (Config.DEATHRUN.Equals(DeathRun.config.creatureAggression) || Config.EXORBITANT.Equals(DeathRun.config.creatureAggression))
                            {
                                if (DayNightCycle.main.timePassedAsFloat >= DeathRun.FULL_AGGRESSION)
                                {
                                    sqrMagnitude = 1; //BR// Player appears very close! (i.e. attractive target)
                                }
                                else if (DayNightCycle.main.timePassedAsFloat >= DeathRun.MORE_AGGRESSION)
                                {
                                    sqrMagnitude /= 4;
                                }
                                else
                                {
                                    sqrMagnitude /= 2;
                                }
                            }
                            else if (Config.HARD.Equals(DeathRun.config.creatureAggression))
                            {
                                if (DayNightCycle.main.timePassedAsFloat >= DeathRun.FULL_AGGRESSION)
                                {
                                    sqrMagnitude /= 3; //BR// Player appears closer! (i.e. attractive target)
                                }
                                else if (DayNightCycle.main.timePassedAsFloat >= DeathRun.MORE_AGGRESSION)
                                {
                                    sqrMagnitude /= 2;
                                }
                            }
                        }
                    }

                    if (sqrMagnitude < num && (isTargetValid == null || isTargetValid(ecoTarget)))
                    {
                        best = ecoTarget;
                        num  = sqrMagnitude;
                    }
                }
            }
            if (best != null)
            {
                bestDist = Mathf.Sqrt(num);
            }
            ProfilingUtils.EndSample(null);
        }