public static Vector3 GetNewPositon(int EntityID, bool Random = false) { EntityAlive myEntity = GameManager.Instance.World.GetEntity(EntityID) as EntityAlive; if (myEntity == null) { return(Vector3.zero); } Vector3 result = Vector3.zero; List <Vector3> Paths = SphereCache.GetPaths(EntityID); if (Paths == null || Paths.Count == 0) { // Grab a list of blocks that are configured for this class. // <property name="PathingBlocks" value="PathingCube" /> List <string> Blocks = EntityUtilities.ConfigureEntityClass(EntityID, "PathingBlocks"); if (Blocks.Count == 0) { Blocks.Add("PathingCube"); } //Scan for the blocks in the area List <Vector3> PathingVectors = ModGeneralUtilities.ScanForTileEntityInChunksListHelper(myEntity.position, Blocks, EntityID); if (PathingVectors == null || PathingVectors.Count == 0) { return(result); } //Add to the cache SphereCache.AddPaths(EntityID, PathingVectors); } // Finds the closet block we matched with. Vector3 tMin = new Vector3(); if (Random) { tMin = SphereCache.GetRandomPath(EntityID); } else { tMin = ModGeneralUtilities.FindNearestBlock(myEntity.position, SphereCache.GetPaths(EntityID)); if (tMin == Vector3.zero) { return(tMin); } } // Remove it from the cache. SphereCache.RemovePath(EntityID, tMin); result = GameManager.Instance.World.FindSupportingBlockPos(tMin); // Center the pathing position. result.x = (float)Utils.Fastfloor(result.x) + 0.5f; result.y = (float)Utils.Fastfloor(result.y) + 0.5f; result.z = (float)Utils.Fastfloor(result.z) + 0.5f; return(result); }
public static Vector3 GetNewPositon(int EntityID, int maxBlocks = 30) { EntityAlive myEntity = GameManager.Instance.World.GetEntity(EntityID) as EntityAlive; if (myEntity == null) { return(Vector3.zero); } if (!EntityUtilities.CheckProperty(EntityID, "PathingBlocks")) { return(Vector3.zero); } Vector3 result = Vector3.zero; List <Vector3> Paths = SphereCache.GetPaths(EntityID); if (Paths == null || Paths.Count == 0) { // Grab a list of blocks that are configured for this class. // <property name="PathingBlocks" value="PathingCube" /> List <string> Blocks = EntityUtilities.ConfigureEntityClass(EntityID, "PathingBlocks"); if (Blocks.Count == 0) { // DisplayLog("No Blocks configured. Setting Default", __instance.theEntity); // Blocks.Add("PathingCube"); return(result); } //Scan for the blocks in the area List <Vector3> PathingVectors = ModGeneralUtilities.ScanForBlockInListHelper(myEntity.position, Blocks, maxBlocks); if (PathingVectors.Count == 0) { return(result); } //Add to the cache SphereCache.AddPaths(EntityID, PathingVectors); } Vector3 newposition = SphereCache.GetRandomPath(EntityID); if (newposition == Vector3.zero) { return(result); } // Remove it from the cache. SphereCache.RemovePath(EntityID, newposition); result = GameManager.Instance.World.FindSupportingBlockPos(newposition); //Debug.Log("Position: " + result); // Center the pathing position. result.x = (float)Utils.Fastfloor(result.x) + 0.5f; result.y = (float)Utils.Fastfloor(result.y) + 0.5f; result.z = (float)Utils.Fastfloor(result.z) + 0.5f; return(result); }
public override bool CanExecute() { // if you are supposed to stay put, don't wander. if (EntityUtilities.CanExecuteTask(this.theEntity.entityId, EntityUtilities.Orders.Stay)) { return(false); } // If Pathing blocks does not exist, don't bother trying to do the enhanced wander code if (!EntityUtilities.CheckProperty(this.theEntity.entityId, "PathingBlocks")) { return(base.CanExecute()); } // If there's a target to fight, dont wander around. That's lame, sir. if (EntityUtilities.GetAttackOrReventTarget(this.theEntity.entityId) != null) { return(false); } this.throttle += 0.05f; // If we have Paths available, allow us to look for a new one. if (this.throttle > 10 || SphereCache.GetPaths(this.theEntity.entityId) != null) { Vector3 newPosition = EntityUtilities.GetNewPositon(this.theEntity.entityId); if (newPosition != Vector3.zero) { this.throttle = 11; String strParticleName = "#@modfolder(0-SphereIICore):Resources/PathSmoke.unity3d?P_PathSmoke_X"; if (!ParticleEffect.IsAvailable(strParticleName)) { ParticleEffect.RegisterBundleParticleEffect(strParticleName); } BlockValue myBlock = GameManager.Instance.World.GetBlock(new Vector3i(newPosition)); DisplayLog(" I have a new position I can path too."); // For testing, change the target to this block, so we can see where the NPC intends to go. if (blShowPathFindingBlocks) { DisplayLog(" I have highlighted where I am going: " + newPosition); Vector3 supportBlock = GameManager.Instance.World.FindSupportingBlockPos(newPosition); BlockUtilitiesSDX.addParticles(strParticleName, new Vector3i(supportBlock)); } if (SphereCache.LastBlock.ContainsKey(this.theEntity.entityId)) { if (blShowPathFindingBlocks) { DisplayLog("I am changing the block back to the pathing block"); Vector3 supportBlock = GameManager.Instance.World.FindSupportingBlockPos(this.position); BlockUtilitiesSDX.removeParticles(new Vector3i(supportBlock)); } SphereCache.LastBlock[this.theEntity.entityId] = newPosition; } else { // Store the LastBlock position here, so we know what we can remove next time. SphereCache.LastBlock.Add(this.theEntity.entityId, newPosition); } this.position = newPosition; return(true); } else { // no positions, so reset the time out. this.throttle = 0; } } return(base.CanExecute()); }