diff --git a/NPCs/SunkenSea/Probesnout.cs b/NPCs/SunkenSea/Probesnout.cs index 8ed2f1a5e1..e3edf4ffab 100644 --- a/NPCs/SunkenSea/Probesnout.cs +++ b/NPCs/SunkenSea/Probesnout.cs @@ -309,14 +309,16 @@ namespace CalamityMod.NPCs.SunkenSea #region Syncing - protected override void SendMoreExtraAI(BinaryWriter writer) + public override void SendExtraAI(BinaryWriter writer) { + base.SendExtraAI(writer); writer.Write7BitEncodedInt(AnimationFrames); writer.Write7BitEncodedInt(TimePerAnimationFrame); } - protected override void ReceiveMoreExtraAI(BinaryReader reader) + public override void ReceiveExtraAI(BinaryReader reader) { + base.ReceiveExtraAI(reader); AnimationFrames = reader.Read7BitEncodedInt(); TimePerAnimationFrame = reader.Read7BitEncodedInt(); } diff --git a/NPCs/SunkenSea/Sharkoon.cs b/NPCs/SunkenSea/Sharkoon.cs index ef16163d7f..ca84579a17 100644 --- a/NPCs/SunkenSea/Sharkoon.cs +++ b/NPCs/SunkenSea/Sharkoon.cs @@ -614,8 +614,9 @@ namespace CalamityMod.NPCs.SunkenSea #region Syncing - protected override void SendMoreExtraAI(BinaryWriter writer) + public override void SendExtraAI(BinaryWriter writer) { + base.SendExtraAI(writer); writer.Write7BitEncodedInt(AnimationFrames); writer.Write7BitEncodedInt(TimePerAnimationFrame); writer.Write(AnimationLoop); @@ -623,8 +624,9 @@ namespace CalamityMod.NPCs.SunkenSea writer.Write7BitEncodedInt(RandomIdleMovementUnlikeliness); } - protected override void ReceiveMoreExtraAI(BinaryReader reader) + public override void ReceiveExtraAI(BinaryReader reader) { + base.ReceiveExtraAI(reader); AnimationFrames = reader.Read7BitEncodedInt(); TimePerAnimationFrame = reader.Read7BitEncodedInt(); AnimationLoop = reader.ReadBoolean(); diff --git a/NPCs/SunkenSea/SunkenSeaNPC.cs b/NPCs/SunkenSea/SunkenSeaNPC.cs index d252cdd63a..a17d9794e5 100644 --- a/NPCs/SunkenSea/SunkenSeaNPC.cs +++ b/NPCs/SunkenSea/SunkenSeaNPC.cs @@ -21,50 +21,8 @@ namespace CalamityMod.NPCs.SunkenSea /// public abstract class SunkenSeaNPC : ModNPC { - #region Biome Designation - - [Flags] - protected enum BiomeFlags : byte - { - None = 0, - UndergroundDesert = 1, - TimelessShores = 2, - RadiantReefs = 4, - PolypForest = 8, - GleamingBurrows = 16, - BasaltGully = 32, - } - - protected abstract BiomeFlags BiomeDesignation { get; } - - protected readonly Dictionary SpawnCondition, int BiomeType)> BiomeCorrespondentValues = new() - { - { BiomeFlags.UndergroundDesert, (spawnInfo => spawnInfo.Player.ZoneDesert, -1 /* None needed. */) }, - { BiomeFlags.TimelessShores, (spawnInfo => spawnInfo.Player.Calamity().ZoneTimelessShores, GetInstance().Type) }, - { BiomeFlags.RadiantReefs, (spawnInfo => spawnInfo.Player.Calamity().ZoneRadiantReefs, GetInstance().Type) }, - { BiomeFlags.PolypForest, (spawnInfo => spawnInfo.Player.Calamity().ZonePolypForest, GetInstance().Type) }, - { BiomeFlags.GleamingBurrows, (spawnInfo => spawnInfo.Player.Calamity().ZoneGleamingBurrows, GetInstance().Type) }, - { BiomeFlags.BasaltGully, (spawnInfo => spawnInfo.Player.Calamity().ZoneBasaltGully, GetInstance().Type) }, - }; - - protected List> BiomeSpawnConditions { get; private set; } = new(); - - #endregion - #region Fields & Properties - /// - /// A list which stores the NPC's IDs that this creature hunts. - /// - protected abstract List HuntNPCs { get; } - - /// - /// A list which stores the NPC's IDs that this creature avoids. - /// - protected abstract List AvoidNPCs { get; } - - protected abstract float SpawningChance { get; } - /// /// Since a lot of these NPCs change behaviors a lot, this abstract class provides an property to store and trigger behaviors.
/// Automatically resets and to not cause errors. @@ -74,11 +32,14 @@ namespace CalamityMod.NPCs.SunkenSea get => _currentBehavior; set { - PreviousBehavior = _currentBehavior; + OnBehaviorChange(value); + PathfindingPoints = null; PathPointIndex = 0; - OnBehaviorChange(value); + + PreviousBehavior = _currentBehavior; _currentBehavior = value; + NetUpdate(); } } @@ -89,6 +50,34 @@ namespace CalamityMod.NPCs.SunkenSea ///
protected Action PreviousBehavior { get; private set; } + /// + /// A lot of these Sunken Sea creatures use the pathfinding algorithm,
+ /// so this abstract class provides a so you can store the paths.
+ /// Defaults to . + ///
+ protected List PathfindingPoints { get; set; } + + /// + /// The probablity that this Sunken Sea NPC spawns given the conditions. + /// + protected abstract float SpawningChance { get; } + + protected int PathPointIndex { get; set; } + + private bool _hasSpawned; + + #region Targetting + + /// + /// A list which stores the NPC's IDs that this creature hunts. + /// + protected abstract List HuntNPCs { get; } + + /// + /// A list which stores the NPC's IDs that this creature avoids. + /// + protected abstract List AvoidNPCs { get; } + /// /// The current NPC that this creature has detected as prey. /// @@ -142,11 +131,6 @@ namespace CalamityMod.NPCs.SunkenSea /// protected Entity NearestEntity { get; private set; } - /// - /// Whether or not the creature has detected anything at all. - /// - protected bool HasAnyTargets => CurrentPrey != null || CurrentPredator != null || CurrentPlayer != null; - /// /// The distance detection radius.
/// Defaults to 300 pixels. @@ -182,19 +166,56 @@ namespace CalamityMod.NPCs.SunkenSea /// Defaults to 3 seconds. ///
protected virtual float PermanenceSenseTime => CalamityUtils.SecondsToFrames(3f); - private int _permanenceSenseTimer; /// - /// A lot of these Sunken Sea creatures use the pathfinding algorithm,
- /// so this abstract class provides a so you can store the paths.
- /// Defaults to . + /// Whether or not the creature has detected anything at all. ///
- protected List PathfindingPoints { get; set; } + protected bool HasAnyTargets => CurrentPrey != null || CurrentPredator != null || CurrentPlayer != null; - protected int PathPointIndex { get; set; } + #endregion - private bool _hasSpawned; + #region Biome Designation + + /// + /// The flags corresponding for the possible spawns for a Sunken Sea NPC. + /// + [Flags] + protected enum BiomeFlags : byte + { + None = 0, + UndergroundDesert = 1, + TimelessShores = 2, + RadiantReefs = 4, + PolypForest = 8, + GleamingBurrows = 16, + BasaltGully = 32, + } + + /// + /// The biomes that this Sunken Sea NPC belongs to. + /// + protected abstract BiomeFlags BiomeDesignation { get; } + + /// + /// Each biome has a correspoding spawn condition boolean value and a biome type. + /// + protected readonly Dictionary SpawnCondition, int BiomeType)> BiomeCorrespondentValues = new() + { + { BiomeFlags.UndergroundDesert, (spawnInfo => spawnInfo.Player.ZoneDesert, -1 /* None needed. */) }, + { BiomeFlags.TimelessShores, (spawnInfo => spawnInfo.Player.Calamity().ZoneTimelessShores, GetInstance().Type) }, + { BiomeFlags.RadiantReefs, (spawnInfo => spawnInfo.Player.Calamity().ZoneRadiantReefs, GetInstance().Type) }, + { BiomeFlags.PolypForest, (spawnInfo => spawnInfo.Player.Calamity().ZonePolypForest, GetInstance().Type) }, + { BiomeFlags.GleamingBurrows, (spawnInfo => spawnInfo.Player.Calamity().ZoneGleamingBurrows, GetInstance().Type) }, + { BiomeFlags.BasaltGully, (spawnInfo => spawnInfo.Player.Calamity().ZoneBasaltGully, GetInstance().Type) }, + }; + + /// + /// The spawn conditions for each biome that this Sunken Sea NPC belongs to. + /// + protected List> BiomeSpawnConditions { get; private set; } = new(); + + #endregion #endregion @@ -432,7 +453,7 @@ namespace CalamityMod.NPCs.SunkenSea NPC.netSpam = netSpam; } - public sealed override void SendExtraAI(BinaryWriter writer) + public override void SendExtraAI(BinaryWriter writer) { writer.Write7BitEncodedInt(CurrentPrey.whoAmI); writer.Write7BitEncodedInt(CurrentPredator.whoAmI); @@ -450,11 +471,9 @@ namespace CalamityMod.NPCs.SunkenSea writer.Write7BitEncodedInt(PathPointIndex); writer.Write(_hasSpawned); - - SendMoreExtraAI(writer); } - public sealed override void ReceiveExtraAI(BinaryReader reader) + public override void ReceiveExtraAI(BinaryReader reader) { CurrentPrey.whoAmI = reader.Read7BitEncodedInt(); CurrentPredator.whoAmI = reader.Read7BitEncodedInt(); @@ -472,22 +491,8 @@ namespace CalamityMod.NPCs.SunkenSea PathPointIndex = reader.Read7BitEncodedInt(); _hasSpawned = reader.ReadBoolean(); - - ReceiveMoreExtraAI(reader); } - /// - /// Same function as , but since that one already sends information and to avoid accidents,
- /// is and instead this is available. - ///
- protected virtual void SendMoreExtraAI(BinaryWriter writer) { } - - /// - /// Same function as , but since that one already sends information and to avoid accidents,
- /// is and instead this is available. - ///
- protected virtual void ReceiveMoreExtraAI(BinaryReader reader) { } - #endregion } }