using System.Collections.Generic; using UnityEngine; namespace NecromancerTome { /// /// Дальний питомец после одержимости (указание 23.10.2026, #35: «Если питомец далеко от хозяина и хозяин вышел из режима /// одержимости, то питомец должен сразу быть отозван. Скажем, если больше 100 блоков, то отзовём, если меньше, то /// возвращается своим ходом»). Отзыв - тот же, что книгой (RecallPet: подсказка «… отозван», книга назад, если призыв её /// тратит). Далеко ушедший питомец иначе остаётся в выгруженном участке, и PetFollowPatch снимает с него владение. /// public static class PetFarRecall { /// Порог в блоках; 0 - выключено (питомец всегда идёт своим ходом, как раньше). public static float Distance = 100f; /// true - питомец отозван (дальше ничего с ним не делать). public static bool TryRecall(EntityPlayer _owner, EntityAlive _pet) { if (Distance <= 0f || _owner == null || _pet == null || _pet.IsDead()) { return false; } float d = Vector3.Distance(_owner.position, _pet.position); string cls = EntityClass.list.TryGetValue(_pet.entityClass, out EntityClass ec) ? ec.entityClassName : null; if (d <= Distance || cls == null || !Patch_ItemActionSpawnEntity_Spawn_PetLimit.LimitedPets.TryGetValue(cls, out Patch_ItemActionSpawnEntity_Spawn_PetLimit.PetInfo info) || info.RecalledKey == null) { return false; } Debug.Log("[NecromancerTome] PetFarRecall: " + cls + " " + _pet.entityId + " в " + Mathf.RoundToInt(d) + " блоках от хозяина - отозван"); Patch_ItemActionSpawnEntity_Spawn_PetLimit.RecallPet(_owner, _pet.entityId, info.RecalledKey, info.ConsumesBook ? info.SummonItemName : null); return true; } } public class ConsoleCmdNecroPetFar : ConsoleCmdAbstract { public override bool IsExecuteOnClient => true; public override bool AllowedInMainMenu => false; public override string[] getCommands() { return new string[] { "necropetfar" }; } public override string getDescription() { return "Necromancer's Tome: recall a far pet when leaving possession - distance."; } public override string getHelp() { return "necropetfar - status\n" + "necropetfar - recall the pet if it is farther than this from you\n" + "necropetfar off - never recall, the pet always walks back"; } public override void Execute(List _params, CommandSenderInfo _senderInfo) { SdtdConsole con = SingletonMonoBehaviour.Instance; if (_params.Count >= 1) { if (_params[0] == "off") { PetFarRecall.Distance = 0f; } else if (float.TryParse(_params[0], System.Globalization.NumberStyles.Float, System.Globalization.CultureInfo.InvariantCulture, out float v) && v >= 0f) { PetFarRecall.Distance = v; } } con.Output("necropetfar: " + (PetFarRecall.Distance > 0f ? "recall farther than " + PetFarRecall.Distance + " blocks" : "off - the pet always walks back")); } } }