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 static void Postfix(Chunk _chunk) { if (!Configuration.CheckFeatureStatus(AdvFeatureClass, Feature)) { return; } // Allow us to throttle which chunks get caves or not by creating a list of world positions. SphereCache.GenerateCaveChunks(); SphereII_CaveTunneler.AddCaveToChunk(_chunk); }
private void BtnOk_OnPressed(XUiController _sender, OnPressEventArgs _onPressEventArgs) { string text = this.txtPassword.Text; float code = 0f; StringParsers.TryParseFloat(text, out code); myEntity.Buffs.AddCustomVar("PathingCode", code); SphereCache.RemovePaths(myEntity.entityId); EntityUtilities.GetNewPositon(myEntity.entityId); EntityUtilities.SetCurrentOrder(myEntity.entityId, EntityUtilities.Orders.Wander); GameManager.ShowTooltip(base.xui.playerUI.entityPlayer, "Pathing Code Set"); base.xui.playerUI.windowManager.Close(base.WindowGroup.ID); }
public override void OnUpdateLive() { // Wake them up if they are sleeping, since the trigger sleeper makes them go idle again. if (!this.sleepingOrWakingUp && isAlwaysAwake) { this.IsSleeping = true; ConditionalTriggerSleeperWakeUp(); } emodel.avatarController.SetBool("IsBusy", false); Buffs.RemoveBuff("buffnewbiecoat", false); Stats.Health.MaxModifier = Stats.Health.Max; // Set CanFall and IsOnGround if (this.emodel != null && this.emodel.avatarController != null) { this.emodel.avatarController.SetBool("CanFall", !this.emodel.IsRagdollActive && this.bodyDamage.CurrentStun == EnumEntityStunType.None && !this.isSwimming); this.emodel.avatarController.SetBool("IsOnGround", this.onGround || this.isSwimming); } if (SingletonMonoBehaviour <ConnectionManager> .Instance.IsServer) { //If blocked, check to see if its a door. if (moveHelper.IsBlocked) { Vector3i blockPos = moveHelper.HitInfo.hit.blockPos; BlockValue block = world.GetBlock(blockPos); if (Block.list[block.type].HasTag(BlockTags.Door) && !BlockDoor.IsDoorOpen(block.meta)) { bool canOpenDoor = true; TileEntitySecureDoor tileEntitySecureDoor = GameManager.Instance.World.GetTileEntity(0, blockPos) as TileEntitySecureDoor; if (tileEntitySecureDoor != null) { if (tileEntitySecureDoor.IsLocked() && tileEntitySecureDoor.GetOwner() == "") { canOpenDoor = false; } } //TileEntityPowered poweredDoor = GameManager.Instance.World.GetTileEntity(0, blockPos) as TileEntityPowered; //if (poweredDoor != null) //{ // if (poweredDoor.IsLocked() && poweredDoor.GetOwner() == "") // canOpenDoor = false; //} if (canOpenDoor) { DisplayLog("I am blocked by a door. Trying to open..."); SphereCache.AddDoor(entityId, blockPos); EntityUtilities.OpenDoor(entityId, blockPos); // We were blocked, so let's clear it. moveHelper.ClearBlocked(); } } } } // Check to see if we've opened a door, and close it behind you. Vector3i doorPos = SphereCache.GetDoor(entityId); if (doorPos != Vector3i.zero) { DisplayLog("I've opened a door recently. I'll see if I can close it."); BlockValue block = world.GetBlock(doorPos); if (Block.list[block.type].HasTag(BlockTags.Door) && BlockDoor.IsDoorOpen(block.meta)) { float CloseDistance = 3; // If it's a multidim, increase tha radius a bit if (Block.list[block.type].isMultiBlock) { Vector3i vector3i = StringParsers.ParseVector3i(Block.list[block.type].Properties.Values["MultiBlockDim"], 0, -1, false); if (CloseDistance > vector3i.x) { CloseDistance = vector3i.x + 1; } } if ((GetDistanceSq(doorPos.ToVector3()) > CloseDistance)) { DisplayLog("I am going to close the door now."); EntityUtilities.CloseDoor(entityId, doorPos); SphereCache.RemoveDoor(entityId, doorPos); } } } // Makes the NPC always face its attack or revent target. EntityAlive target = EntityUtilities.GetAttackOrReventTarget(entityId) as EntityAlive; if (target != null) { // makes the npc look at its attack target if (this.emodel != null && this.emodel.avatarController != null) { this.emodel.SetLookAt(target.getHeadPosition()); } SetLookPosition(target.getHeadPosition()); RotateTo(target, 45, 45); if (EntityUtilities.HasTask(this.entityId, "Ranged")) { if (EntityUtilities.CheckAIRange(this.entityId, target.entityId)) { EntityUtilities.ChangeHandholdItem(this.entityId, EntityUtilities.Need.Ranged); } else { EntityUtilities.ChangeHandholdItem(this.entityId, EntityUtilities.Need.Melee); } } else { EntityUtilities.ChangeHandholdItem(this.entityId, EntityUtilities.Need.Melee); } } // Non-player entities don't fire all the buffs or stats, so we'll manually fire the water tick, // Stats.Water.Tick(0.5f, 0, false); // then fire the updatestats over time, which is protected from a IsPlayer check in the base onUpdateLive(). //Stats.UpdateStatsOverTime(0.5f); updateTime = Time.time + 2f; base.OnUpdateLive(); // Allow EntityAliveSDX to get buffs from blocks if (!this.isEntityRemote) { updateBlockRadiusEffects(); } // No NPC info, don't continue if (NPCInfo == null) { return; } // If the Tile Entity Trader isn't set, set it now. Sometimes this fails, and won't allow interaction. if (TileEntityTrader == null) { TileEntityTrader = new TileEntityTrader(null); TileEntityTrader.entityId = entityId; TileEntityTrader.TraderData.TraderID = NPCInfo.TraderID; } // If there is no attack target, don't bother checking this. if (target == null) { if (this is EntityAliveFarmingAnimalSDX) { return; } List <global::Entity> entitiesInBounds = GameManager.Instance.World.GetEntitiesInBounds(this, new Bounds(position, Vector3.one * 5f)); if (entitiesInBounds.Count > 0) { for (int i = 0; i < entitiesInBounds.Count; i++) { if (entitiesInBounds[i] is EntityPlayerLocal || entitiesInBounds[i] is EntityPlayer) { // Check your faction relation. If you hate each other, don't stop and talk. FactionManager.Relationship myRelationship = FactionManager.Instance.GetRelationshipTier(this, entitiesInBounds[i] as EntityPlayerLocal); if (myRelationship == FactionManager.Relationship.Hate) { break; } if (GetDistance(entitiesInBounds[i]) < 1 && this.moveHelper != null) { DisplayLog("The entity is too close to me. Moving away: " + entitiesInBounds[i].ToString()); EntityUtilities.BackupHelper(entityId, entitiesInBounds[i].position, 3); break; } // Turn to face the player, and stop the movement. emodel.avatarController.SetBool("IsBusy", true); SetLookPosition(entitiesInBounds[i].getHeadPosition()); RotateTo(entitiesInBounds[i], 90f, 90f); EntityUtilities.Stop(this.entityId); break; } } } } }
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()); }
public override void OnUpdateLive() { if (SingletonMonoBehaviour <ConnectionManager> .Instance.IsServer) { //If blocked, check to see if its a door. if (moveHelper.IsBlocked) { Vector3i blockPos = moveHelper.HitInfo.hit.blockPos; BlockValue block = world.GetBlock(blockPos); if (Block.list[block.type].HasTag(BlockTags.Door) && !BlockDoor.IsDoorOpen(block.meta)) { bool canOpenDoor = true; TileEntitySecureDoor tileEntitySecureDoor = GameManager.Instance.World.GetTileEntity(0, blockPos) as TileEntitySecureDoor; if (tileEntitySecureDoor != null) { if (tileEntitySecureDoor.IsLocked() && tileEntitySecureDoor.GetOwner() == "") { canOpenDoor = false; } } //TileEntityPowered poweredDoor = GameManager.Instance.World.GetTileEntity(0, blockPos) as TileEntityPowered; //if (poweredDoor != null) //{ // if (poweredDoor.IsLocked() && poweredDoor.GetOwner() == "") // canOpenDoor = false; //} if (canOpenDoor) { DisplayLog("I am blocked by a door. Trying to open..."); SphereCache.AddDoor(entityId, blockPos); EntityUtilities.OpenDoor(entityId, blockPos); // We were blocked, so let's clear it. moveHelper.ClearBlocked(); } } } } // Check to see if we've opened a door, and close it behind you. Vector3i doorPos = SphereCache.GetDoor(entityId); if (doorPos != Vector3i.zero) { DisplayLog("I've opened a door recently. I'll see if I can close it."); BlockValue block = world.GetBlock(doorPos); if (Block.list[block.type].HasTag(BlockTags.Door) && BlockDoor.IsDoorOpen(block.meta)) { float CloseDistance = 3; // If it's a multidim, increase tha radius a bit if (Block.list[block.type].isMultiBlock) { Vector3i vector3i = StringParsers.ParseVector3i(Block.list[block.type].Properties.Values["MultiBlockDim"], 0, -1, false); if (CloseDistance > vector3i.x) { CloseDistance = vector3i.x + 1; } } if ((GetDistanceSq(doorPos.ToVector3()) > CloseDistance)) { DisplayLog("I am going to close the door now."); EntityUtilities.CloseDoor(entityId, doorPos); SphereCache.RemoveDoor(entityId, doorPos); } } } // Makes the NPC always face its attack or revent target. EntityAlive target = EntityUtilities.GetAttackOrReventTarget(entityId) as EntityAlive; if (target != null) { // makes the npc look at its attack target if (this.emodel != null && this.emodel.avatarController != null) { this.emodel.SetLookAt(target.getHeadPosition()); } SetLookPosition(target.getHeadPosition()); RotateTo(target, 45, 45); } Buffs.RemoveBuff("buffnewbiecoat", false); Stats.Health.MaxModifier = Stats.Health.Max; // Set CanFall and IsOnGround if (this.emodel != null && this.emodel.avatarController != null) { this.emodel.avatarController.SetBool("CanFall", !this.emodel.IsRagdollActive && this.bodyDamage.CurrentStun == EnumEntityStunType.None && !this.isSwimming); this.emodel.avatarController.SetBool("IsOnGround", this.onGround || this.isSwimming); } // Non-player entities don't fire all the buffs or stats, so we'll manually fire the water tick, Stats.Water.Tick(0.5f, 0, false); // then fire the updatestats over time, which is protected from a IsPlayer check in the base onUpdateLive(). Stats.UpdateStatsOverTime(0.5f); base.OnUpdateLive(); }
public override void OnUpdateLive() { //If blocked, check to see if its a door. if (moveHelper.IsBlocked) { Vector3i blockPos = moveHelper.HitInfo.hit.blockPos; BlockValue block = world.GetBlock(blockPos); if (Block.list[block.type].HasTag(BlockTags.Door) && !BlockDoor.IsDoorOpen(block.meta)) { bool canOpenDoor = true; TileEntitySecureDoor tileEntitySecureDoor = GameManager.Instance.World.GetTileEntity(0, blockPos) as TileEntitySecureDoor; if (tileEntitySecureDoor != null) { if (tileEntitySecureDoor.IsLocked() && tileEntitySecureDoor.GetOwner() == "") { canOpenDoor = false; } } //TileEntityPowered poweredDoor = GameManager.Instance.World.GetTileEntity(0, blockPos) as TileEntityPowered; //if (poweredDoor != null) //{ // if (poweredDoor.IsLocked() && poweredDoor.GetOwner() == "") // canOpenDoor = false; //} if (canOpenDoor) { DisplayLog("I am blocked by a door. Trying to open..."); SphereCache.AddDoor(entityId, blockPos); EntityUtilities.OpenDoor(entityId, blockPos); // We were blocked, so let's clear it. moveHelper.ClearBlocked(); } } } // Check to see if we've opened a door, and close it behind you. Vector3i doorPos = SphereCache.GetDoor(entityId); if (doorPos != Vector3i.zero) { DisplayLog("I've opened a door recently. I'll see if I can close it."); BlockValue block = world.GetBlock(doorPos); if (Block.list[block.type].HasTag(BlockTags.Door) && BlockDoor.IsDoorOpen(block.meta)) { float CloseDistance = 3; // If it's a multidim, increase tha radius a bit if (Block.list[block.type].isMultiBlock) { Vector3i vector3i = StringParsers.ParseVector3i(Block.list[block.type].Properties.Values["MultiBlockDim"], 0, -1, false); if (CloseDistance > vector3i.x) { CloseDistance = vector3i.x + 1; } } if ((GetDistanceSq(doorPos.ToVector3()) > CloseDistance)) { DisplayLog("I am going to close the door now."); EntityUtilities.CloseDoor(entityId, doorPos); SphereCache.RemoveDoor(entityId, doorPos); } } } // Makes the NPC always face its attack or revent target. EntityAlive target = EntityUtilities.GetAttackOrReventTarget(entityId) as EntityAlive; if (target != null) { SetLookPosition(attackTarget.position); RotateTo(attackTarget, 45, 45); } Buffs.RemoveBuff("buffnewbiecoat", false); Stats.Health.MaxModifier = Stats.Health.Max; // Non-player entities don't fire all the buffs or stats, so we'll manually fire the water tick, Stats.Water.Tick(0.5f, 0, false); // then fire the updatestats over time, which is protected from a IsPlayer check in the base onUpdateLive(). Stats.UpdateStatsOverTime(0.5f); updateTime = Time.time - 2f; base.OnUpdateLive(); // No NPC info, don't continue if (NPCInfo == null) { return; } // If the Tile Entity Trader isn't set, set it now. Sometimes this fails, and won't allow interaction. if (TileEntityTrader == null) { TileEntityTrader = new TileEntityTrader(null); TileEntityTrader.entityId = entityId; TileEntityTrader.TraderData.TraderID = NPCInfo.TraderID; } // Check if there's a player within 10 meters of us. If not, resume wandering. emodel.avatarController.SetBool("IsBusy", false); if (!SingletonMonoBehaviour <ConnectionManager> .Instance.IsServer) { return; } if (target == null) { if (this is EntityAliveFarmingAnimalSDX) { return; } List <global::Entity> entitiesInBounds = GameManager.Instance.World.GetEntitiesInBounds(this, new Bounds(position, Vector3.one * 5f)); if (entitiesInBounds.Count > 0) { for (int i = 0; i < entitiesInBounds.Count; i++) { if (entitiesInBounds[i] is EntityPlayerLocal) { // Check your faction relation. If you hate each other, don't stop and talk. FactionManager.Relationship myRelationship = FactionManager.Instance.GetRelationshipTier(this, entitiesInBounds[i] as EntityPlayerLocal); if (myRelationship == FactionManager.Relationship.Hate) { break; } if (GetDistance(entitiesInBounds[i]) < 2) { DisplayLog("The entity is too close to me. Moving away: " + entitiesInBounds[i].ToString()); EntityUtilities.BackupHelper(entityId, entitiesInBounds[i].position, 5); //moveHelper.SetMoveTo((entitiesInBounds[i] as EntityPlayerLocal).GetLookVector(), false); break; } // Turn to face the player, and stop the movement. emodel.avatarController.SetBool("IsBusy", true); SetLookPosition(entitiesInBounds[i].getHeadPosition()); RotateTo(entitiesInBounds[i], 90f, 90f); navigator.clearPath(); moveHelper.Stop(); // this stops the walking jitter this.speedForward = 0; break; } } } } }