diff --git a/Changelogs/Github/v0.1.2.MD b/Changelogs/Github/v0.1.2.MD new file mode 100644 index 0000000..d7baf93 --- /dev/null +++ b/Changelogs/Github/v0.1.2.MD @@ -0,0 +1,5 @@ +# Release Notes v0.1.2 + +- Fixed "Rename Pet" menu having incorrect text. +- Fixed pets getting stuck. (*Hopefully*) +- Increased pet sleeping time. \ No newline at end of file diff --git a/Changelogs/Workshop/v0.1.2.MD b/Changelogs/Workshop/v0.1.2.MD new file mode 100644 index 0000000..9558082 --- /dev/null +++ b/Changelogs/Workshop/v0.1.2.MD @@ -0,0 +1,5 @@ +[h1]Release Notes v0.1.2[/h1] + +- Fixed "Rename Pet" menu having incorrect text. +- Fixed pets getting stuck. (*Hopefully*) +- Increased pet sleeping time. \ No newline at end of file diff --git a/Components/CPetStuckChecker.cs b/Components/CPetStuckChecker.cs new file mode 100644 index 0000000..fc62867 --- /dev/null +++ b/Components/CPetStuckChecker.cs @@ -0,0 +1,11 @@ +using KitchenMods; +using UnityEngine; + +namespace Pets.Components +{ + public struct CPetStuckChecker : IModComponent + { + public long LastCheck; + public Vector3 LastPosition; + } +} \ No newline at end of file diff --git a/Mod.cs b/Mod.cs index 0683f1a..593ff88 100644 --- a/Mod.cs +++ b/Mod.cs @@ -20,7 +20,7 @@ namespace Pets { public const string MOD_GUID = "com.starfluxgames.pets"; public const string MOD_NAME = "Pets"; - public const string MOD_VERSION = "0.1.1"; + public const string MOD_VERSION = "0.1.2"; public const string MOD_AUTHOR = "StarFluxGames"; public const string MOD_GAMEVERSION = ">=1.1.8"; diff --git a/Systems/Activities/PetSleepActivity.cs b/Systems/Activities/PetSleepActivity.cs index b0ad14c..448dbe8 100644 --- a/Systems/Activities/PetSleepActivity.cs +++ b/Systems/Activities/PetSleepActivity.cs @@ -76,7 +76,7 @@ namespace Pets.Systems.Activities { InteractingWith = TargetEntity, StartTime = DateTimeOffset.Now.ToUnixTimeSeconds(), - TimeToFinish = Random.Range(5, 15), + TimeToFinish = Random.Range(15, 25), IsWaitingForDestination = true }); diff --git a/Systems/Activities/StopInteraction.cs b/Systems/Activities/StopInteraction.cs index c8ad700..920b318 100644 --- a/Systems/Activities/StopInteraction.cs +++ b/Systems/Activities/StopInteraction.cs @@ -33,6 +33,12 @@ namespace Pets.Systems.Activities if (!Require(pet, out CMoveToLocation cMoveToLocation)) continue; if (!Require(pet, out CPosition cPosition)) continue; if (!Require(pet, out CCurrentSpeed cCurrentSpeed)) continue; + if (cPetInteractingWith.InteractingWith == Entity.Null) + { + EntityManager.RemoveComponent(pet); + continue; + } + if (cPetInteractingWith.IsWaitingForDestination) { if (Vector3.Distance(cPosition, cMoveToLocation.Location) < 0.1f && cCurrentSpeed.speed < Mod.MinimumSpeedThreshold) diff --git a/Systems/PetActivitySystem.cs b/Systems/PetActivitySystem.cs index 06dbcef..a45d22a 100644 --- a/Systems/PetActivitySystem.cs +++ b/Systems/PetActivitySystem.cs @@ -2,6 +2,7 @@ using System.Collections.Generic; using System.Linq; using Kitchen; using KitchenData; +using KitchenLib.Utils; using Pets.Components; using Pets.Components.Status; using Pets.Customs.Types; @@ -84,27 +85,84 @@ namespace Pets.Systems return entitiesInRange; } - - protected bool CanGetTo(Vector3 startingPosition, Vector3 targetPosition, Vector3 targetOffset, out Vector3 targetDestination) - { + + private GameObject point1; + private GameObject point2; + + protected bool CanGetTo(Vector3 startingPosition, Vector3 targetPosition, Vector3 targetOffset, out Vector3 targetDestination, bool ShowDebugSpheres = false) + { + if (!ShowDebugSpheres) + Mod.Logger.LogInfo(""); + + + if (ShowDebugSpheres) + { + if (point1 != null) + GameObject.Destroy(point1); + if (point2 != null) + GameObject.Destroy(point2); + + point1 = GameObject.CreatePrimitive(PrimitiveType.Sphere); + point2 = GameObject.CreatePrimitive(PrimitiveType.Sphere); + + point1.transform.position = startingPosition; + point2.transform.position = targetPosition + targetOffset; + + point1.transform.localScale = Vector3.one * 0.5f; + point2.transform.localScale = Vector3.one * 0.5f; + + GameObject.Destroy(point1.GetComponent()); + GameObject.Destroy(point2.GetComponent()); + } + targetDestination = Vector3.zero; CLayoutRoomTile tile1 = GetTile(targetPosition); CLayoutRoomTile tile2 = GetTile(targetPosition + targetOffset); - if (tile1.RoomID != tile2.RoomID) return false; - + + if (tile1.RoomID == 0 || tile2.RoomID == 0) + { + if (ShowDebugSpheres) + { + point1.GetComponent().material = MaterialUtils.GetExistingMaterial("AppleRed"); + point2.GetComponent().material = MaterialUtils.GetExistingMaterial("AppleRed"); + } + return false; + } + + if (tile1.RoomID != tile2.RoomID) + { + if (ShowDebugSpheres) + { + point1.GetComponent().material = MaterialUtils.GetExistingMaterial("AppleRed"); + point2.GetComponent().material = MaterialUtils.GetExistingMaterial("AppleRed"); + } + return false; + } + NavMesh.CalculatePath(startingPosition, targetPosition + targetOffset, NavMesh.AllAreas, Path); if (Path.status == NavMeshPathStatus.PathComplete) targetDestination = targetPosition + targetOffset; - - return Path.status == NavMeshPathStatus.PathComplete; + + if (Path.status != NavMeshPathStatus.PathComplete) + { + if (ShowDebugSpheres) + { + point1.GetComponent().material = MaterialUtils.GetExistingMaterial("AppleRed"); + point2.GetComponent().material = MaterialUtils.GetExistingMaterial("AppleRed"); + } + return false; + } + + point1.GetComponent().material = MaterialUtils.GetExistingMaterial("AppleGreen"); + point2.GetComponent().material = MaterialUtils.GetExistingMaterial("AppleGreen"); + return true; } protected bool GetOffsetPosition(Vector3 forward, Vector2 offset, out Vector2 success) { success = Vector2.zero; float rotation = Mathf.Atan2(forward.x, forward.z) * Mathf.Rad2Deg; - Mod.Logger.LogInfo("GetOffsetPosition " + rotation); if (rotation == 0) success = offset; if (rotation == 90) diff --git a/Systems/PetStuckCheck.cs b/Systems/PetStuckCheck.cs new file mode 100644 index 0000000..ed03016 --- /dev/null +++ b/Systems/PetStuckCheck.cs @@ -0,0 +1,94 @@ +using System; +using Kitchen; +using KitchenMods; +using Pets.Components; +using Pets.Components.Status; +using Unity.Collections; +using Unity.Entities; +using UnityEngine; + +namespace Pets.Systems +{ + public class PetStuckCheck : GameSystemBase, IModSystem + { + private EntityQuery _pets; + protected override void Initialise() + { + base.Initialise(); + _pets = GetEntityQuery(new QueryHelper().All(typeof(CPet))); + } + + protected override void OnUpdate() + { + using NativeArray pets = _pets.ToEntityArray(Allocator.Temp); + + for (int i = 0; i < pets.Length; i++) + { + Entity pet = pets[i]; + if (!Require(pet, out CPet cPet)) continue; + if (!Require(pet, out CPosition cPosition)) continue; + if (!Require(pet, out CMoveToLocation cMoveToLocation)) continue; + if (!Require(pet, out CCurrentSpeed cCurrentSpeed)) continue; + + if (Vector3.Distance(cMoveToLocation.Location, cPosition) > 0) + { + if (Require(pet, out CPetStuckChecker cPetStuckChecker)) + { + long currentTime = DateTimeOffset.Now.ToUnixTimeSeconds(); + if ((currentTime - cPetStuckChecker.LastCheck) < 5) continue; + if (!(Vector3.Distance(cPosition, cPetStuckChecker.LastPosition) < 0.1f)) + { + EntityManager.AddComponentData(pet, new CPetStuckChecker + { + LastCheck = currentTime, + LastPosition = cPosition.Position + }); + } + else + { + if (!Require(pet, out CDefaultState cDefaultState)) continue; + cPet.State = cDefaultState.State; + EntityManager.SetComponentData(pet, cPet); + + if (Has(pet)) + EntityManager.RemoveComponent(pet); + + if (Has(pet)) + EntityManager.RemoveComponent(pet); + + if (Has(pet)) + EntityManager.AddComponentData(pet, new CCurrentSpeed + { + speed = 0 + }); + + if (Require(pet, out CPetInteractingWith cPetInteractingWith)) + { + if (cPetInteractingWith.InteractingWith != Entity.Null) + { + EntityManager.RemoveComponent(cPetInteractingWith.InteractingWith); + EntityManager.RemoveComponent(pet); + } + } + + EntityManager.RemoveComponent(pet); + } + } + else + { + EntityManager.AddComponentData(pet, new CPetStuckChecker + { + LastCheck = DateTimeOffset.Now.ToUnixTimeSeconds(), + LastPosition = cPosition.Position + }); + } + } + else + { + if (Has(pet)) + EntityManager.RemoveComponent(pet); + } + } + } + } +} \ No newline at end of file diff --git a/Views/PetView.cs b/Views/PetView.cs index e508ee2..d51bc3e 100644 --- a/Views/PetView.cs +++ b/Views/PetView.cs @@ -155,7 +155,7 @@ namespace Pets.Views if (Data.RequestingInputSource == InputSourceIdentifier.Identifier) { - TextInputView.RequestTextInput(base.Localisation["INPUT_TITLE_RENAME_RESTAURANT"], "", 24, HandleNewName); + TextInputView.RequestTextInput("Rename Pet", "", 24, HandleNewName); } }