示例#1
0
        public override bool ShouldExecute()
        {
            //Modified
            prog = entity.GetBehavior <EntityBehaviorProgram>();

            if (prog?.dormant != false || !(entity.LeftHandItemSlot.Itemstack?.Collectible is ItemArrow))
            {
                return(false);
            }
            long ellapsedMs = entity.World.ElapsedMilliseconds;

            if (ellapsedMs - lastCheckOrAttackMs < fullClip || cooldownUntilMs > ellapsedMs)
            {
                return(false);
            }

            Vec3d pos = entity.ServerPos.XYZ.Add(0, entity.CollisionBox.Y2 / 2, 0).Ahead((entity.CollisionBox.X2 - entity.CollisionBox.X1) / 2, 0, entity.ServerPos.Yaw);

            targetEntity = entityUtil.GetNearestEntity(pos, maxDist > maxVerDist ? maxDist : maxVerDist, (e) => {
                if (!e.Alive || !e.IsInteractable || e.EntityId == this.entity.EntityId)
                {
                    return(false);
                }

                for (int i = 0; i < seekEntityCodesExact.Length; i++)
                {
                    if (e.Code.Path == seekEntityCodesExact[i])
                    {
                        if (hasDirectContact(e))
                        {
                            return(true);
                        }
                    }
                }


                for (int i = 0; i < seekEntityCodesBeginsWith.Length; i++)
                {
                    if (e.Code.Path.StartsWithFast(seekEntityCodesBeginsWith[i]) && hasDirectContact(e))
                    {
                        return(true);
                    }
                }

                return(false);
            });

            lastCheckOrAttackMs = entity.World.ElapsedMilliseconds;
            nextShotMs          = 0;
            shotsFired          = 0;

            return(targetEntity != null);
        }
示例#2
0
        public override bool ShouldExecute()
        {
            // React immediately on hurt, otherwise only 1/10 chance of execution
            prog = entity.GetBehavior <EntityBehaviorProgram>();
            if (prog?.dormant != false)
            {
                return(false);
            }
            if (rand.NextDouble() > 0.1f && (whenInEmotionState == null || !entity.HasEmotionState(whenInEmotionState)))
            {
                return(false);
            }

            if (whenInEmotionState != null && !entity.HasEmotionState(whenInEmotionState))
            {
                return(false);
            }
            if (whenNotInEmotionState != null && entity.HasEmotionState(whenNotInEmotionState))
            {
                return(false);
            }
            if (lastSearchTotalMs + 4000 > entity.World.ElapsedMilliseconds)
            {
                return(false);
            }
            if (whenInEmotionState == null && rand.NextDouble() > 0.5f)
            {
                return(false);
            }


            if (jumpAnimOn && entity.World.ElapsedMilliseconds - finishedMs > 2000)
            {
                entity.AnimManager.StopAnimation("jump");
            }

            if (cooldownUntilMs > entity.World.ElapsedMilliseconds)
            {
                return(false);
            }

            if (belowTempThreshold > -99)
            {
                ClimateCondition conds = entity.World.BlockAccessor.GetClimateAt(entity.Pos.AsBlockPos, EnumGetClimateMode.NowValues);
                lowTempMode = conds != null && conds.Temperature <= belowTempThreshold;
            }

            float range = lowTempMode ? belowTempSeekingRange : seekingRange;


            lastSearchTotalMs = entity.World.ElapsedMilliseconds;

            Vec3d ownPos = entity.ServerPos.XYZ;

            targetEntity = (EntityAgent)partitionUtil.GetNearestEntity(entity.ServerPos.XYZ, range, (e) => {
                if (!e.Alive || !e.IsInteractable || e.EntityId == this.entity.EntityId)
                {
                    return(false);
                }

                for (int i = 0; i < seekEntityCodesExact.Length; i++)
                {
                    if (e.Code.Path == seekEntityCodesExact[i])
                    {
                        if (e.Code.Path == "player")
                        {
                            float rangeMul = e.Stats.GetBlended("animalSeekingRange");

                            IPlayer player = entity.World.PlayerByUid(((EntityPlayer)e).PlayerUID);
                            return
                            ((rangeMul == 1 || e.ServerPos.DistanceTo(ownPos) < range * rangeMul) &&
                             (player == null || (player.WorldData.CurrentGameMode != EnumGameMode.Creative && player.WorldData.CurrentGameMode != EnumGameMode.Spectator && (player as IServerPlayer).ConnectionState == EnumClientState.Playing))
                            );
                        }
                        return(true);
                    }
                }


                for (int i = 0; i < seekEntityCodesBeginsWith.Length; i++)
                {
                    if (e.Code.Path.StartsWithFast(seekEntityCodesBeginsWith[i]))
                    {
                        return(true);
                    }
                }

                return(false);
            });



            if (targetEntity != null)
            {
                if (alarmHerd && entity.HerdId > 0)
                {
                    entity.World.GetNearestEntity(entity.ServerPos.XYZ, range, range, (e) =>
                    {
                        EntityAgent agent = e as EntityAgent;
                        if (e.EntityId != entity.EntityId && agent != null && agent.Alive && agent.HerdId == entity.HerdId)
                        {
                            agent.Notify("seekEntity", targetEntity);
                        }

                        return(false);
                    });
                }

                targetPos = targetEntity.ServerPos.XYZ;

                if (entity.ServerPos.SquareDistanceTo(targetPos) <= MinDistanceToTarget())
                {
                    return(false);
                }

                return(true);
            }

            return(false);
        }