コード例 #1
0
        /// <summary>
        /// Returns whether the EntityAIBase should begin execution.
        /// </summary>
        public override bool ShouldExecute()
        {
            TargetEntity = TheEntity.GetAttackTarget();

            if (TargetEntity == null)
            {
                return(false);
            }

            if (TargetEntity.GetDistanceSqToEntity(TheEntity) > (double)(Field_48331_g * Field_48331_g))
            {
                return(false);
            }

            Vec3D vec3d = RandomPositionGenerator.Func_48620_a(TheEntity, 16, 7, Vec3D.CreateVector(TargetEntity.PosX, TargetEntity.PosY, TargetEntity.PosZ));

            if (vec3d == null)
            {
                return(false);
            }
            else
            {
                MovePosX = vec3d.XCoord;
                MovePosY = vec3d.YCoord;
                MovePosZ = vec3d.ZCoord;
                return(true);
            }
        }
コード例 #2
0
        /// <summary>
        /// Returns whether the EntityAIBase should begin execution.
        /// </summary>
        public override bool ShouldExecute()
        {
            if (Entity.GetAge() >= 100)
            {
                return(false);
            }

            if (Entity.GetRNG().Next(120) != 0)
            {
                return(false);
            }

            Vec3D vec3d = RandomPositionGenerator.Func_48622_a(Entity, 10, 7);

            if (vec3d == null)
            {
                return(false);
            }
            else
            {
                Field_46098_b = vec3d.XCoord;
                Field_46099_c = vec3d.YCoord;
                Field_46097_d = vec3d.ZCoord;
                return(true);
            }
        }
コード例 #3
0
    public override void Start()
    {
        // if no pathing blocks, just randomly pick something.
        if (this.position == Vector3.zero)
        {
            int maxDistance = 30;

            if (this.theEntity.IsAlert)
            {
                this.position = RandomPositionGenerator.CalcAway(this.theEntity, 0, maxDistance, maxDistance, this.theEntity.LastTargetPos);
            }
            else
            {
                this.position = RandomPositionGenerator.Calc(this.theEntity, maxDistance, maxDistance);
            }
        }

        this.time = 0f;

        EntityUtilities.ChangeHandholdItem(this.theEntity.entityId, EntityUtilities.Need.Reset);

        // Turn off the entity jumping, and turn on breaking blocks, to allow for better pathing.
        if (this.theEntity is EntityAliveSDX)
        {
            (theEntity as EntityAliveSDX).canJump = false;
            (theEntity as EntityAliveSDX).moveHelper.CanBreakBlocks = true;
        }

        // Path finding has to be set for Breaking Blocks so it can path through doors
        PathFinderThread.Instance.FindPath(this.theEntity, this.position, this.theEntity.GetMoveSpeed(), true, this);


        return;
    }
コード例 #4
0
    public static void BackupHelper(int EntityID, Vector3 awayFrom, int distance)
    {
        EntityAlive myEntity = GameManager.Instance.World.GetEntity(EntityID) as EntityAlive;

        if (myEntity == null)
        {
            return;
        }

        if (myEntity.moveHelper == null)
        {
            return;
        }

        Vector3 dirV   = myEntity.position - awayFrom;
        Vector3 vector = Vector3.zero;

        // If you are blocked, try to go to another side.
        vector = RandomPositionGenerator.CalcAway(myEntity, distance, distance, distance, awayFrom);
        myEntity.moveHelper.SetMoveTo(vector, false);

        // Move away at a hard coded speed of -4 to make them go backwards
        myEntity.speedForward = -4f;// Mathf.SmoothStep(myEntity.speedForward, -0.25f, 2 * Time.deltaTime);

        // Keep them facing the spot
        // myEntity.SetLookPosition( awayFrom );
        //myEntity.RotateTo(awayFrom.x, awayFrom.y, awayFrom.z, 30f, 30f);
    }
コード例 #5
0
 public DestroyBoxSystem(IGameContext context, IBoxFactory boxFactory,
                         RandomPositionGenerator positionGenerator) : base(context)
 {
     _context           = context;
     _boxFactory        = boxFactory;
     _positionGenerator = positionGenerator;
 }
コード例 #6
0
 public InitWorldSystem(IGameContext context, MonsterFactory monsterFactory,
                        IBoxFactory boxFactory, RandomPositionGenerator randomPositionGenerator)
 {
     _boxFactory              = boxFactory;
     _monsterFactory          = monsterFactory;
     _context                 = context;
     _randomPositionGenerator = randomPositionGenerator;
 }
コード例 #7
0
 public CreateNewCreatureSystem(IGameContext context, MonsterFactory factory, RandomPositionGenerator randomPositionGenerator, Grid grid)
 {
     _factory     = factory;
     _grid        = grid;
     _attackGroup = context.GetGroup(GameMatcher.AllOf(
                                         GameMatcher.Creator,
                                         GameMatcher.Calldown,
                                         GameMatcher.InitialCalldown,
                                         GameMatcher.Target));
     _randomPositionGenerator = randomPositionGenerator;
 }
コード例 #8
0
        /// <summary>
        /// Execute a one shot task or start executing a continuous task
        /// </summary>
        public override void StartExecuting()
        {
            InsidePosX = -1;

            if (EntityObj.GetDistanceSq(DoorInfo.GetInsidePosX(), DoorInfo.PosY, DoorInfo.GetInsidePosZ()) > 256D)
            {
                Vec3D vec3d = RandomPositionGenerator.Func_48620_a(EntityObj, 14, 3, Vec3D.CreateVector((double)DoorInfo.GetInsidePosX() + 0.5D, DoorInfo.GetInsidePosY(), (double)DoorInfo.GetInsidePosZ() + 0.5D));

                if (vec3d != null)
                {
                    EntityObj.GetNavigator().Func_48666_a(vec3d.XCoord, vec3d.YCoord, vec3d.ZCoord, 0.3F);
                }
            }
            else
            {
                EntityObj.GetNavigator().Func_48666_a((double)DoorInfo.GetInsidePosX() + 0.5D, DoorInfo.GetInsidePosY(), (double)DoorInfo.GetInsidePosZ() + 0.5D, 0.3F);
            }
        }
コード例 #9
0
    public override void Start()
    {
        // if no pathing blocks, just randomly pick something.

        Vector3 newPosition = EntityUtilities.GetNewPositon(this.theEntity.entityId);

        if (newPosition == Vector3.zero)
        {
            this.position = RandomPositionGenerator.CalcAway(this.theEntity, 10, 30, 10, this.theEntity.position);
        }

        //Give them more time to path find.The CanContinue() stops at 30f, so we'll set it at -90, rather than 0.
        this.time = -90f;

        // Path finding has to be set for Breaking Blocks so it can path through doors
        PathFinderThread.Instance.FindPath(this.theEntity, this.position, this.theEntity.GetMoveSpeed(), true, this);
        return;
    }
コード例 #10
0
        /// <summary>
        /// Returns whether the EntityAIBase should begin execution.
        /// </summary>
        public override bool ShouldExecute()
        {
            if (Field_48316_a.GetAITarget() == null)
            {
                return(false);
            }

            Vec3D vec3d = RandomPositionGenerator.Func_48622_a(Field_48316_a, 5, 4);

            if (vec3d == null)
            {
                return(false);
            }
            else
            {
                Field_48315_c = vec3d.XCoord;
                Field_48312_d = vec3d.YCoord;
                Field_48313_e = vec3d.ZCoord;
                return(true);
            }
        }
コード例 #11
0
        /// <summary>
        /// Returns whether the EntityAIBase should begin execution.
        /// </summary>
        public override bool ShouldExecute()
        {
            if (TheEntity.IsWithinHomeDistanceCurrentPosition())
            {
                return(false);
            }

            ChunkCoordinates chunkcoordinates = TheEntity.GetHomePosition();
            Vec3D            vec3d            = RandomPositionGenerator.Func_48620_a(TheEntity, 16, 7, Vec3D.CreateVector(chunkcoordinates.PosX, chunkcoordinates.PosY, chunkcoordinates.PosZ));

            if (vec3d == null)
            {
                return(false);
            }
            else
            {
                MovePosX = vec3d.XCoord;
                MovePosY = vec3d.YCoord;
                MovePosZ = vec3d.ZCoord;
                return(true);
            }
        }
コード例 #12
0
    public override void Start()
    {
        // if no pathing blocks, just randomly pick something.
        if (this.position == Vector3.zero)
        {
            Vector3 vector = Vector3.zero;
            int     num2   = 30;

            if (this.theEntity.IsAlert)
            {
                vector = RandomPositionGenerator.CalcAway(this.theEntity, 0, num2, num2, this.theEntity.LastTargetPos);
            }
            else
            {
                vector = RandomPositionGenerator.Calc(this.theEntity, num2, num2);
            }

            this.position = vector;
            this.time     = 0f;
        }
        else
        {
            this.time = -60f;
        }
        //Vector3 temp = Ent
        //EntityUtilities.GetNewPositon(this.theEntity.entityId);
        //if (temp != Vector3.zero)
        //{
        //    this.position = temp;
        //    //Give them more time to path find.The CanContinue() stops at 30f, so we'll set it at -90, rather than 0.
        //    this.time = 90f;
        //}
        //   EntityUtilities.ChangeHandholdItem(this.theEntity.entityId, EntityUtilities.Need.Melee);
        // Path finding has to be set for Breaking Blocks so it can path through doors
        PathFinderThread.Instance.FindPath(this.theEntity, this.position, this.theEntity.GetMoveSpeed(), true, this);
        return;
    }
コード例 #13
0
        public MainPage()
        {
            BindingContext = this;

            //Initialize collection that holds the locations bound to the Map

            _locations = new ObservableCollection <LocationModel>();

            Random randomPositionGenerator = new Random();

            for (int i = 0; i < _pinCount; i++)
            {
                //Create new location
                LocationModel locationModel = new LocationModel();
                locationModel.Address     = $"Address {i}";
                locationModel.Description = $"Location {i}";
                locationModel.Position    = RandomPositionGenerator.Next();

                //Add Location to the collection
                _locations.Add(locationModel);
            }

            InitializeComponent();
        }
コード例 #14
0
    // flocking logic
    private void flockTasks()
    {
        if (GamePrefs.GetBool(EnumGamePrefs.DebugStopEnemiesMoving) ||
            GameStats.GetInt(EnumGameStats.GameState) == 2)
        {
            return;
        }
        if (world.IsRemote())
        {
            return;
        }
        if (IsDead())
        {
            return;
        }
        if (masterEntity == null && !hasFlock && maxToSpawn > 0)
        {
            SpawnFlock();
        }
        else if (masterEntity == null && hasFlock && oldmasterID > 0)
        {
            FindOldMaster();
        }
        GetEntitySenses().ClearIfExpired();
        if (AttackTimeout > 0)
        {
            AttackTimeout--;
        }
        if (AttackTimeout <= 0)
        {
            var a            = Waypoint - position;
            var sqrMagnitude = a.sqrMagnitude;
            if (sqrMagnitude < 1f || sqrMagnitude > 6400f)
            {
                if (!isWithinHomeDistanceCurrentPosition() && GetMasterEntity() == null && !isHunting)
                {
                    // uses vanilla code to stay near "home position" if its a "master"
                    Vector3 ye = RandomPositionGenerator.CalcTowards(this, 2 * base.getMaximumHomeDistance(), 2 * base.getMaximumHomeDistance(), 2 * base.getMaximumHomeDistance(), base.getHomePosition().position.ToVector3());

                    if (!ye.Equals(Vector3.zero))
                    {
                        // going home
                        Waypoint    = ye;
                        HasWaypoint = true;
                    }
                }
                else
                {
                    HasWaypoint = false;


                    if (!HasWaypoint)
                    {
                        if (base.GetRevengeTarget() != null &&
                            (base.GetRevengeTarget().GetDistanceSq(this) < 6400f && Random.value <= 0.5f || isHunting))
                        {
                            // if it's targeting an enemy. Notice that if it's hunting I just want it to get it done.
                            Waypoint = base.GetRevengeTarget().GetPosition() + Vector3.up;
                        }
                        else
                        {
                            if (GetMasterEntity() == null)
                            {
                                // if it finds a target block nearby, it will go for it. Not attack it, just go near it
                                // this will make them "destroy" crops for example, if we make them target crop blocks.
                                if (FindLandSpot())
                                {
                                    // going for landing spot
                                    Waypoint = landPosition +
                                               new Vector3((float)((rand.NextDouble() * 2.0 - 1.0) * 3.0),
                                                           (float)((rand.NextDouble() * 2.0 - 1.0) * 3.0),
                                                           (float)((rand.NextDouble() * 2.0 - 1.0) * 3.0));
                                }
                                else
                                {
                                    // chooses a random waypoint - vanilla code
                                    Waypoint = GetPosition() +
                                               new Vector3((float)((rand.NextDouble() * 2.0 - 1.0) * 16.0),
                                                           (float)((rand.NextDouble() * 2.0 - 1.0) * 16.0),
                                                           (float)((rand.NextDouble() * 2.0 - 1.0) * 16.0));
                                    // maximum Y. Just to avoid them going too high (out of sight, out of heart)
                                    var maxY = world.GetHeight((int)Waypoint.x, (int)Waypoint.z) + maxHeight;
                                    if (Waypoint.y > maxY)
                                    {
                                        Waypoint.y = maxY;
                                    }
                                }
                            }
                            else
                            {
                                // if the master has a landing spot, it goes to random position near the landing spot, otherwise just follows master
                                if ((GetMasterEntity() as EntityZombieFlyingSDX).GetLandingSpot() == Vector3.zero)
                                {
                                    Waypoint = GetMasterEntity().GetPosition() + Vector3.up;
                                }
                                else
                                {
                                    Waypoint = (GetMasterEntity() as EntityZombieFlyingSDX).GetLandingSpot() +
                                               new Vector3((float)((rand.NextDouble() * 2.0 - 1.0) * 3.0),
                                                           (float)((rand.NextDouble() * 2.0 - 1.0) * 3.0),
                                                           (float)((rand.NextDouble() * 2.0 - 1.0) * 3.0));
                                }
                                // }
                            }
                        }
                    }

                    var num = 255;

                    AdjustWayPoint();
                    // if waypoint is not in the air, change it up
                    //                    while (world.GetBlock(new Vector3i(Waypoint)).type != BlockValue.Air.type && num > 0)
                    //                  {
                    //                    Waypoint.y = Waypoint.y + 1f;
                    //                  num--;
                    //            }
                }

                Waypoint.y = Mathf.Min(Waypoint.y, 250f);
            }

            if (CourseCheck-- <= 0)
            {
                CourseCheck += rand.Next(5) + 2;
                if (isCourseTraversable(Waypoint, out sqrMagnitude))
                {
                    motion += a / sqrMagnitude * 0.1f;
                }
                else
                {
                    Waypoint = GetPosition();
                }
            }
        }



        float intendedRotation;

        intendedRotation = (float)Math.Atan2(motion.x, motion.z) * 180f / 3.14159274f;
        rotation.y       = UpdateRotation(rotation.y, intendedRotation, 10f);
    }
コード例 #15
0
 protected void LegacyTask()
 {
     if (!GamePrefs.GetBool(EnumGamePrefs.DebugStopEnemiesMoving))
     {
         if (GameStats.GetInt(EnumGameStats.GameState) != 2)
         {
             base.GetEntitySenses().ClearIfExpired();
             if (this.MV > 0)
             {
                 this.MV--;
             }
             if (this.MV <= 0)
             {
                 Vector3 vector       = this.HV - this.position;
                 float   sqrMagnitude = vector.sqrMagnitude;
                 if (sqrMagnitude < 1f || sqrMagnitude > 2304f)
                 {
                     if (!base.isWithinHomeDistanceCurrentPosition())
                     {
                         Vector3 hv = RandomPositionGenerator.CalcTowards(this, 2 * base.getMaximumHomeDistance(), 2 * base.getMaximumHomeDistance(), 2 * base.getMaximumHomeDistance(), base.getHomePosition().position.ToVector3());
                         if (!hv.Equals(Vector3.zero))
                         {
                             this.HV = hv;
                             this.AV = true;
                         }
                     }
                     else
                     {
                         this.AV = false;
                         if (base.GetRevengeTarget() != null && base.GetRevengeTarget().GetDistanceSq(this) < 2304f && Random.value <= 0.5f)
                         {
                             this.HV = base.GetRevengeTarget().GetPosition() + Vector3.up;
                         }
                         else
                         {
                             this.HV = base.GetPosition() + new Vector3((float)((this.rand.NextDouble() * 2.0 - 1.0) * 16.0), (float)((this.rand.NextDouble() * 2.0 - 1.0) * 16.0), (float)((this.rand.NextDouble() * 2.0 - 1.0) * 16.0));
                         }
                     }
                     this.HV.y = Mathf.Min(this.HV.y, 250f);
                 }
                 if (this.LV-- <= 0)
                 {
                     this.LV += this.rand.Next(5) + 2;
                     if (this.isCourseTraversable(this.HV, out sqrMagnitude))
                     {
                         this.motion += vector / sqrMagnitude * 0.1f;
                     }
                     else
                     {
                         this.HV = base.GetPosition();
                     }
                 }
             }
             if (base.GetRevengeTarget() != null && base.GetRevengeTarget().IsDead())
             {
                 base.SetRevengeTarget(null);
             }
             if (base.GetRevengeTarget() == null || this.EV-- <= 0)
             {
                 EntityPlayer closestPlayer = this.world.GetClosestPlayer(this, 48f, false);
                 if (base.CanSee(closestPlayer))
                 {
                     base.SetRevengeTarget(closestPlayer);
                 }
                 if (base.GetRevengeTarget() != null)
                 {
                     this.EV = 20;
                 }
             }
             float distanceSq;
             if (!this.AV && base.GetRevengeTarget() != null && (distanceSq = base.GetRevengeTarget().GetDistanceSq(this)) < 2304f)
             {
                 float num  = base.GetRevengeTarget().position.x - this.position.x;
                 float num2 = base.GetRevengeTarget().position.z - this.position.z;
                 this.rotation.y = Mathf.Atan2(num, num2) * 180f / 3.14159274f;
                 if (this.MV <= 0 && distanceSq < 2.8f && this.position.y >= base.GetRevengeTarget().position.y&& this.position.y <= base.GetRevengeTarget().getHeadPosition().y&& base.Attack(false))
                 {
                     this.MV = base.GetAttackTimeoutTicks();
                     base.Attack(true);
                 }
             }
             else
             {
                 this.rotation.y = (float)Math.Atan2((double)this.motion.x, (double)this.motion.z) * 180f / 3.14159274f;
             }
             return;
         }
     }
 }
コード例 #16
0
        public static bool CanContinue(EAIApproachAndAttackTarget __instance)
        {
            bool result = true;

            if (__instance.entityTarget == null)
            {
                return(result);
            }

            // If it's a zombie, don't do anything extra
            if (!EntityUtilities.IsHuman(__instance.theEntity.entityId))
            {
                return(result);
            }


            // Non zombies should continue to attack
            if (__instance.entityTarget.IsDead())
            {
                DisplayLog("Target is Dead. Leaving the Body.", __instance.theEntity);
                __instance.theEntity.IsEating = false;
                __instance.theEntity.SetAttackTarget(null, 0);
                return(false);
            }

            // Don't execute the approach and attack if there's a ranged ai task, and they are still 4 blocks away
            if (EntityUtilities.HasTask(__instance.theEntity.entityId, "Ranged"))
            {
                float distanceSq = __instance.entityTarget.GetDistanceSq(__instance.theEntity);
                DisplayLog(" Ranged Entity: Distance between " + __instance.entityTarget.EntityName + " : " + distanceSq, __instance.theEntity);
                // Let the entity move closer, without walking a few steps and trying to fire, which can make the entity stutter as it tries to keep up with a retreating enemey.
                if (distanceSq > 50 && distanceSq < 60)
                {
                    return(result);
                }

                // Hold your ground
                if (distanceSq > 10f && distanceSq < 60)
                {
                    DisplayLog("I am ranged, so I will not move forward.", __instance.theEntity);
                    __instance.theEntity.SetLookPosition(__instance.entityTarget.position);
                    __instance.theEntity.RotateTo(__instance.entityTarget, 45, 45);
                    __instance.theEntity.navigator.clearPath();
                    __instance.theEntity.moveHelper.Stop();

                    return(false);
                }

                // Back away!
                if (distanceSq > 4 && distanceSq < 10)
                {
                    DisplayLog(" Ranged Entity: They are coming too close to me! I am backing away", __instance.theEntity);

                    Vector3 dirV   = __instance.theEntity.position - __instance.entityTarget.position;
                    Vector3 vector = RandomPositionGenerator.CalcPositionInDirection(__instance.theEntity, __instance.theEntity.position, dirV, 40f, 80f);
                    __instance.theEntity.moveHelper.SetMoveTo(vector, false);
                    __instance.theEntity.SetLookPosition(__instance.entityTarget.position);
                    __instance.theEntity.RotateTo(__instance.entityTarget, 45, 45);
                    return(false);
                }
                if (distanceSq < 5)
                {
                    DisplayLog("They are too close. Let's fight!", __instance.theEntity);
                    return(true);
                }
            }

            return(result);
        }
コード例 #17
0
    // flocking logic
    private void flockTasks()
    {
        if (GamePrefs.GetBool(EnumGamePrefs.DebugStopEnemiesMoving) || GameStats.GetInt(EnumGameStats.GameState) == 2)
        {
            return;
        }
        if (this.world.IsRemote())
        {
            return;
        }
        if (this.IsDead())
        {
            return;
        }
        if (masterEntity == null && !hasFlock && maxToSpawn > 0)
        {
            SpawnFlock();
        }
        else if (masterEntity == null && hasFlock && oldmasterID > 0)
        {
            FindOldMaster();
        }
        base.GetEntitySenses().ClearIfExpired();
        if (this.AttackTimeout > 0)
        {
            this.AttackTimeout--;
        }
        if (this.AttackTimeout <= 0)
        {
            Vector3 a            = this.Waypoint - this.position;
            float   sqrMagnitude = a.sqrMagnitude;
            if (sqrMagnitude < 1f || sqrMagnitude > 6400f)
            {
                if (!base.isWithinHomeDistanceCurrentPosition() && this.GetMasterEntity() == null && !isHunting)
                {
                    // uses vanilla code to stay near "home position" if its a "master"
                    Vector3 ye = RandomPositionGenerator.CalcTowards(this, 2 * base.getMaximumHomeDistance(), 2 * base.getMaximumHomeDistance(), 2 * base.getMaximumHomeDistance(), base.getHomePosition().position.ToVector3());
                    if (!ye.Equals(Vector3.zero))
                    {
                        if (debug)
                        {
                            Debug.Log("Going Home");
                        }
                        this.Waypoint    = ye;
                        this.HasWaypoint = true;
                    }
                }
                else
                {
                    this.HasWaypoint = false;
                    if (base.GetRevengeTarget() != null && ((base.GetRevengeTarget().GetDistanceSq(this) < 6400f && UnityEngine.Random.value <= 0.5f) || isHunting))
                    {
                        // if it's targeting an enemy. Notice that if it's hunting I just want it to get it done.
                        this.Waypoint = base.GetRevengeTarget().GetPosition() + Vector3.up;
                    }
                    else
                    {
                        if (this.GetMasterEntity() == null)
                        {
                            // if it finds a target block nearby, it will go for it. Not attack it, just go near it
                            // this will make them "destroy" crops for example, if we make them target crop blocks.
                            if (FindLandSpot())
                            {
                                // going for landing spot
                                this.Waypoint = landPosition + new Vector3((float)((this.rand.RandomDouble * 2.0 - 1.0) * 3.0), (float)((this.rand.RandomDouble * 2.0 - 1.0) * 3.0), (float)((this.rand.RandomDouble * 2.0 - 1.0) * 3.0));
                            }
                            else
                            {
                                // chooses a random waypoint - vanilla code
                                this.Waypoint = base.GetPosition() + new Vector3((float)((this.rand.RandomDouble * 2.0 - 1.0) * 16.0), (float)((this.rand.RandomDouble * 2.0 - 1.0) * 16.0), (float)((this.rand.RandomDouble * 2.0 - 1.0) * 16.0));
                                // maximum Y. Just to avoid them going too high (out of sight, out of heart)
                                int maxY = this.world.GetHeight((int)this.Waypoint.x, (int)this.Waypoint.z) + maxHeight;
                                if (this.Waypoint.y > maxY)
                                {
                                    this.Waypoint.y = maxY;
                                    if (debug)
                                    {
                                        Debug.Log("Prevented it from going higher");
                                    }
                                }
                            }
                        }
                        else
                        {
                            if ((this.GetMasterEntity() as EntityZombieFlockSDX).GetRevengeTarget() != null)
                            {
                                // attacks the same target as master
                                this.SetRevengeTarget((this.GetMasterEntity() as EntityZombieFlockSDX).GetRevengeTarget());
                                this.Waypoint = (this.GetMasterEntity() as EntityZombieFlockSDX).GetRevengeTarget().GetPosition() + Vector3.up;
                            }
                            else
                            {
                                // if the master has a landing spot, it goes to random position near the landing spot, otherwise just follows master
                                if ((this.GetMasterEntity() as EntityZombieFlockSDX).GetLandingSpot() == Vector3.zero)
                                {
                                    this.Waypoint = this.GetMasterEntity().GetPosition() + Vector3.up;
                                }
                                else
                                {
                                    this.Waypoint = (this.GetMasterEntity() as EntityZombieFlockSDX).GetLandingSpot() + new Vector3((float)((this.rand.RandomDouble * 2.0 - 1.0) * 3.0), (float)((this.rand.RandomDouble * 2.0 - 1.0) * 3.0), (float)((this.rand.RandomDouble * 2.0 - 1.0) * 3.0));
                                }
                            }
                        }
                    }
                    int num = 255;
                    // if waypoint is not in the air, change it up
                    while (this.world.GetBlock(new Vector3i(this.Waypoint)).type != BlockValue.Air.type && num > 0)
                    {
                        this.Waypoint.y = this.Waypoint.y + 1f;
                        num--;
                    }
                }
                this.Waypoint.y = Mathf.Min(this.Waypoint.y, 250f);
            }
            if (this.CourseCheck-- <= 0)
            {
                this.CourseCheck += this.rand.RandomRange(5) + 2;
                //if (base.isCourseTraversable(this.Waypoint, out sqrMagnitude))
                //{
                //    this.motion += a / sqrMagnitude * 0.1f;
                //}
                //else
                //{
                this.Waypoint = base.GetPosition();
                //}
            }
        }
        if (base.GetRevengeTarget() != null)
        {
            if (!retaliateAttack && !targetPlayers && !isHunting)
            {
                base.SetRevengeTarget(null);
            }
            else if (base.GetRevengeTarget().IsDead())
            {
                base.SetRevengeTarget(null);
                isHunting = false;
            }
        }
        // if it's a parent and has no target, then it will look for one.
        if ((base.GetRevengeTarget() == null) && this.GetMasterEntity() == null)
        {
            if (this.TargetInterval-- <= 0)
            {
                isHunting = false;
                if (targetPlayers)
                {
                    // if it's an agressive animal, will look for a player to attack
                    FindClosestPlayer();
                }
                if ((base.GetRevengeTarget() == null))
                {
                    if (naturalEnemies != null)
                    {
                        if (naturalEnemies.Length > 0)
                        {
                            // if it has natural enemies, will look for one to attack
                            FindNaturalEnemy();
                        }
                    }
                }
                if (base.GetRevengeTarget() != null)
                {
                    this.TargetInterval = 20;
                }
            }
        }
        float intendedRotation;

        if (!this.HasWaypoint)
        {
            if (base.GetRevengeTarget() != null)
            {
                float distanceSq;
                if ((distanceSq = base.GetRevengeTarget().GetDistanceSq(this)) < 6400f)
                {
                    float y = base.GetRevengeTarget().position.x - this.position.x;
                    float x = base.GetRevengeTarget().position.z - this.position.z;
                    if (distanceSq < 5f)
                    {
                        intendedRotation = Mathf.Atan2(y, x) * 180f / 3.14159274f;
                    }
                    else
                    {
                        intendedRotation = (float)Math.Atan2((double)this.motion.x, (double)this.motion.z) * 180f / 3.14159274f;
                        if (this.motion.magnitude < 0.25f)
                        {
                            this.motion = this.motion.normalized * 0.25f;
                        }
                    }
                    if (this.AttackTimeout <= 0)
                    {
                        if (distanceSq < 2.8f)
                        {
                            if (this.position.y >= base.GetRevengeTarget().position.y)
                            {
                                if (!isHunting)
                                {
                                    if (this.position.y <= base.GetRevengeTarget().getHeadPosition().y - 0.25f)
                                    {
                                        if (base.Attack(false))
                                        {
                                            this.AttackTimeout = base.GetAttackTimeoutTicks();
                                            base.Attack(true);
                                        }
                                    }
                                }
                                else
                                {
                                    // just marks the "target" to unload, as if it had captured it.
                                    if (UnityEngine.Random.value <= 0.5f)
                                    {
                                        if (debug)
                                        {
                                            Debug.Log("Eating the target!!!");
                                        }
                                        base.GetRevengeTarget().MarkToUnload();
                                        // stops hunting to look for another suitable target after a bit
                                        isHunting = false;
                                        base.SetRevengeTarget(null);
                                        this.TargetInterval = 50;
                                    }
                                }
                            }
                        }
                    }
                    this.rotation.y = EntityAlive.UpdateRotation(this.rotation.y, intendedRotation, 10f);
                    return;
                }
            }
        }
        intendedRotation = (float)Math.Atan2((double)this.motion.x, (double)this.motion.z) * 180f / 3.14159274f;
        this.rotation.y  = EntityAlive.UpdateRotation(this.rotation.y, intendedRotation, 10f);
    }
コード例 #18
0
        private void PositionMainDraw(int rankedPlayers, MatchInfo[] matches, Queue <string> codes)
        {
            var playersCount = matches.Length;
            var vsRanked     = new Stack <int>();
            var taken        = new List <int>();

            PositionInMatch(matches, 0, codes.Dequeue());
            PositionInMatch(matches, playersCount - 1, codes.Dequeue());
            taken.Add(0);
            taken.Add(playersCount - 1);
            vsRanked.Push(1);
            vsRanked.Push(matches.Length - 2);

            var randomizer = default(RandomPositionGenerator);

            if (rankedPlayers > 2)
            {
                var p1 = playersCount / 4;
                var p2 = (playersCount - 1) - playersCount / 4;
                randomizer = new RandomPositionGenerator(new[] { p1, p2 });
                taken.Add(randomizer.Take());
                PositionInMatch(matches, taken.Last(), codes.Dequeue());

                taken.Add(randomizer.Take());
                PositionInMatch(matches, taken.Last(), codes.Dequeue());

                vsRanked.Push(p1 + 1);
                vsRanked.Push(p2 - 1);
            }

            if (rankedPlayers > 4)
            {
                var p = new[]
                {
                    playersCount / 2 - 1,
                    playersCount / 2,
                    playersCount / 4 - 1,
                    (playersCount) - playersCount / 4,
                };
                randomizer = new RandomPositionGenerator(p);

                taken.Add(randomizer.Take());
                PositionInMatch(matches, taken.Last(), codes.Dequeue());
                taken.Add(randomizer.Take());
                PositionInMatch(matches, taken.Last(), codes.Dequeue());
                taken.Add(randomizer.Take());
                PositionInMatch(matches, taken.Last(), codes.Dequeue());
                taken.Add(randomizer.Take());
                PositionInMatch(matches, taken.Last(), codes.Dequeue());


                vsRanked.Push(p[0] - 1);
                vsRanked.Push(p[1] + 1);
                vsRanked.Push(p[2] - 1);
                vsRanked.Push(p[3] + 1);
            }



            var positions = Enumerable.Range(0, playersCount).Except(vsRanked).Except(taken).ToList();

            randomizer = new RandomPositionGenerator(positions.ToArray());

            while (randomizer.CanTake())
            {
                PositionInMatch(matches, randomizer.Take(), codes.Dequeue());
            }

            if (rankedPlayers > 4)
            {
                positions = new List <int>();
                positions.Add(vsRanked.Pop());
                positions.Add(vsRanked.Pop());
                positions.Add(vsRanked.Pop());
                positions.Add(vsRanked.Pop());
                randomizer = new RandomPositionGenerator(positions.ToArray());
                while (randomizer.CanTake())
                {
                    PositionInMatch(matches, randomizer.Take(), codes.Dequeue());
                }
            }

            if (rankedPlayers > 2)
            {
                positions = new List <int>();
                positions.Add(vsRanked.Pop());
                positions.Add(vsRanked.Pop());
                randomizer = new RandomPositionGenerator(positions.ToArray());
                while (randomizer.CanTake())
                {
                    PositionInMatch(matches, randomizer.Take(), codes.Dequeue());
                }
            }

            PositionInMatch(matches, vsRanked.Pop(), codes.Dequeue());
            PositionInMatch(matches, vsRanked.Pop(), codes.Dequeue());
        }
コード例 #19
0
        public PositioningItem[] Rank(int actualPlayersCount)
        {
            var playersCount = CalculatePlayersCount(actualPlayersCount);
            
                        var codes = new Queue<string>();
            for (var i = 0; i < actualPlayersCount ; i++)
            {
                codes.Enqueue("Q" + (i + 1));
            }


            if (actualPlayersCount < playersCount)
            {
                for (var i = 0; i < (playersCount - actualPlayersCount); i++)
                {
                    codes.Enqueue("BYE");
                }
            }

            var items = new List<PositioningItem>(playersCount);
            var skip = playersCount / 8;
            var first = new List<int>();
            var second = new List<int>();
            var third = new List<int>();

            for (var i = 0; i < playersCount; i += skip)
            {
                items[i] = new PositioningItem() { Index = i, Code = codes.Dequeue() };
                first.Add(i);
                second.Add(i + 2);
                second.Add(i + 4);
                third.Add(i + 3);
                third.Add(i + 5);
            }
            var oddPlaces = new List<int>();
            for (var i = skip - 1; i < playersCount; i += skip)
            {
                oddPlaces.Add(i);
            }
            first.AddRange(oddPlaces);

            var randomizer = new RandomPositionGenerator(oddPlaces.ToArray());
            while (randomizer.CanTake())
            {
                var i = randomizer.Take();
                items[i] = new PositioningItem() { Index = i, Code = codes.Dequeue() };
            }

            randomizer = new RandomPositionGenerator(second.ToArray());
            while (randomizer.CanTake())
            {
                var i = randomizer.Take();
                items[i] = new PositioningItem() { Index = i, Code = codes.Dequeue() };
            }

            randomizer = new RandomPositionGenerator(third.ToArray());
            while (randomizer.CanTake())
            {
                var i = randomizer.Take();
                items[i] = new PositioningItem() { Index = i, Code = codes.Dequeue() };
            }

            var available = Enumerable.Range(0, playersCount).Except(first).Except(second).Except(third);
            randomizer = new RandomPositionGenerator(available.ToArray());
            while (randomizer.CanTake())
            {
                var i = randomizer.Take();
                items[i] = new PositioningItem() { Index = i, Code = codes.Dequeue() };
            }

            
            

            //for (int i = 0; i < playersCount; i++)
            //{
            //    var item = new PositioningItem() {Index = i};
            //    if (i%2 == 0)
            //    {
            //        item.Code = codes.Dequeue();
            //    }
            //    items.Add(item);
            //}



            //var empty = items.Where(i => string.IsNullOrEmpty(i.Code));
            //var randomizer = new RandomPositionGenerator(empty.Select(i=>i.Index).ToArray());
            //while (randomizer.CanTake())
            //{
            //    items[randomizer.Take()].Code = codes.Dequeue();
            //}

            return items.ToArray();
        }
コード例 #20
0
        private void PositionQualifyingDraw(MatchInfo[] matches, int playersCount, int actualPlayersCount, Queue <string> codes)
        {
            var skip    = playersCount / 8;
            var first   = new List <int>();
            var second  = new List <int>();
            var third   = new List <int>();
            var against = new Stack <int>();

            for (var i = 0; i < playersCount; i += skip)
            {
                PositionInMatch(matches, i, codes.Dequeue());
                against.Push(i + 1);
                if (skip > 1)
                {
                    first.Add(i);
                }
                if (skip > 4)
                {
                    for (var j = 2; j < skip; j *= 2)
                    {
                        second.Add(i + j);
                        third.Add(i + j + 1);
                    }
                }
            }
            var oddPlaces = new List <int>();

            if (codes.Count > 0)
            {
                if (skip > 2)
                {
                    for (var i = skip - 1; i < playersCount; i += skip)
                    {
                        oddPlaces.Add(i);
                        against.Push(i - 1);
                    }
                    first.AddRange(oddPlaces);
                    var randomizer = new RandomPositionGenerator(oddPlaces.ToArray());
                    while (randomizer.CanTake())
                    {
                        PositionInMatch(matches, randomizer.Take(), codes.Dequeue());
                    }


                    randomizer = new RandomPositionGenerator(second.ToArray());
                    while (randomizer.CanTake())
                    {
                        PositionInMatch(matches, randomizer.Take(), codes.Dequeue());
                    }

                    randomizer = new RandomPositionGenerator(third.ToArray());
                    while (randomizer.CanTake())
                    {
                        PositionInMatch(matches, randomizer.Take(), codes.Dequeue());
                    }
                }

                var available = Enumerable.Range(0, playersCount).Except(first).Except(second).Except(third);
                if (available.Any() && codes.Count > 0)
                {
                    var remainderQueue = new Queue <string>();
                    var code           = codes.Dequeue();
                    while (against.Count > 0 && code != "BYE")
                    {
                        against.Pop();
                        remainderQueue.Enqueue(code);
                        code = codes.Dequeue();
                    }
                    if (against.Count > 0)
                    {
                        available = available.Except(against);
                    }
                    if (available.Any() && remainderQueue.Count > 0)
                    {
                        var randomizer = new RandomPositionGenerator(available.ToArray());
                        while (randomizer.CanTake())
                        {
                            PositionInMatch(matches, randomizer.Take(), remainderQueue.Dequeue());
                        }
                    }

                    while (against.Count > 0)
                    {
                        PositionInMatch(matches, against.Pop(), "BYE");
                    }
                }
            }
        }
コード例 #21
0
 private void RankPlayers(List<CompetitionPosition> positions, int[] randomPositions, List<Player> players, List<int> availablePositions,
                                List<int> rankedPositions)
 {
     var randomizer = new RandomPositionGenerator(randomPositions);
     while (players.Count > 0 && randomizer.CanTake())
     {
         var position = randomizer.Take();
         RankPlayer(positions, position, players, availablePositions, rankedPositions);
     }
 }
コード例 #22
0
        public PositioningItem[] Rank(int actualPlayersCount, int qPlayers)
        {
            var playersCount = PlayersCountCalculator.CalculatePlayersCount(actualPlayersCount);
            var rankedPlayers = playersCount/4;
            

            var items = new List<PositioningItem>(playersCount);
            for (int i = 0; i < playersCount; i++)
            {
                items.Add(new PositioningItem() { Index = i });
            }

            var codes = new Queue<string>();
            for (var i = 0; i < actualPlayersCount - qPlayers; i++)
            {
                codes.Enqueue("MD" + (i + 1));
            }

            for (int i = 0; i < qPlayers; i++)
            {
                codes.Enqueue("Q" + (i + 1));
            }

            if (actualPlayersCount < playersCount)
            {
                for (var i = 0; i < (playersCount - actualPlayersCount); i++)
                {
                    codes.Enqueue("BYE");
                }
            }

            var vsRanked = new Stack<int>();

            items[0].Code = codes.Dequeue();
            items.Last().Code = codes.Dequeue();
            vsRanked.Push(1);
            vsRanked.Push(items.Count - 2);

            var randomizer = default(RandomPositionGenerator);
            if (rankedPlayers > 2)
            {
                var p1 = items.Count / 4;
                var p2 = (items.Count - 1) - items.Count / 4;
                randomizer = new RandomPositionGenerator(new[] { p1, p2 });
                items[randomizer.Take()].Code = codes.Dequeue();
                items[randomizer.Take()].Code = codes.Dequeue();
                vsRanked.Push(p1 + 1);
                vsRanked.Push(p2 - 1);
            }

            if (rankedPlayers > 4)
            {
                var p = new[]
                            {
                                items.Count / 2-1,
                                items.Count/2,
                                items.Count / 4-1,
                                (items.Count) - items.Count/4,

                            };
                randomizer = new RandomPositionGenerator(p);
                items[randomizer.Take()].Code = codes.Dequeue();
                items[randomizer.Take()].Code = codes.Dequeue();
                items[randomizer.Take()].Code = codes.Dequeue();
                items[randomizer.Take()].Code = codes.Dequeue();

                vsRanked.Push(p[0] - 1);
                vsRanked.Push(p[1] + 1);
                vsRanked.Push(p[2] - 1);
                vsRanked.Push(p[3] + 1);
            }


            var emptySlots = items.Where(item => string.IsNullOrEmpty(item.Code));
            var positions = emptySlots.Select(i => i.Index).Except(vsRanked).ToList();
            randomizer = new RandomPositionGenerator(positions.ToArray());

            while (randomizer.CanTake())
            {
                items[randomizer.Take()].Code = codes.Dequeue();
            }
            if (rankedPlayers > 4)
            {
                positions = new List<int>();
                positions.Add(vsRanked.Pop());
                positions.Add(vsRanked.Pop());
                positions.Add(vsRanked.Pop());
                positions.Add(vsRanked.Pop());
                randomizer = new RandomPositionGenerator(positions.ToArray());
                while (randomizer.CanTake())
                {
                    items[randomizer.Take()].Code = codes.Dequeue();
                }
            }

            if (rankedPlayers > 2)
            {
                positions = new List<int>();
                positions.Add(vsRanked.Pop());
                positions.Add(vsRanked.Pop());
                randomizer = new RandomPositionGenerator(positions.ToArray());
                while (randomizer.CanTake())
                {
                    items[randomizer.Take()].Code = codes.Dequeue();
                }
            }

            items[vsRanked.Pop()].Code = codes.Dequeue();
            items[vsRanked.Pop()].Code = codes.Dequeue();

            return items.ToArray();
        }