Sunken Sea NPC Re-Ordering.
This commit is contained in:
1 parent
caf73071c9
commit
e46036d0d7
3 files changed
+87
-78
No files matched your search
@@ -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();
|
||||
}
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -21,50 +21,8 @@ namespace CalamityMod.NPCs.SunkenSea
|
||||
/// </summary>
|
||||
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<BiomeFlags, (Func<NPCSpawnInfo, bool> SpawnCondition, int BiomeType)> BiomeCorrespondentValues = new()
|
||||
{
|
||||
{ BiomeFlags.UndergroundDesert, (spawnInfo => spawnInfo.Player.ZoneDesert, -1 /* None needed. */) },
|
||||
{ BiomeFlags.TimelessShores, (spawnInfo => spawnInfo.Player.Calamity().ZoneTimelessShores, GetInstance<TimelessShoresBiome>().Type) },
|
||||
{ BiomeFlags.RadiantReefs, (spawnInfo => spawnInfo.Player.Calamity().ZoneRadiantReefs, GetInstance<RadiantReefsBiome>().Type) },
|
||||
{ BiomeFlags.PolypForest, (spawnInfo => spawnInfo.Player.Calamity().ZonePolypForest, GetInstance<PolypForestBiome>().Type) },
|
||||
{ BiomeFlags.GleamingBurrows, (spawnInfo => spawnInfo.Player.Calamity().ZoneGleamingBurrows, GetInstance<GleamingBurrowsBiome>().Type) },
|
||||
{ BiomeFlags.BasaltGully, (spawnInfo => spawnInfo.Player.Calamity().ZoneBasaltGully, GetInstance<BasaltGullyBiome>().Type) },
|
||||
};
|
||||
|
||||
protected List<Func<NPCSpawnInfo, bool>> BiomeSpawnConditions { get; private set; } = new();
|
||||
|
||||
#endregion
|
||||
|
||||
#region Fields & Properties
|
||||
|
||||
/// <summary>
|
||||
/// A list which stores the NPC's IDs that this creature hunts.
|
||||
/// </summary>
|
||||
protected abstract List<int> HuntNPCs { get; }
|
||||
|
||||
/// <summary>
|
||||
/// A list which stores the NPC's IDs that this creature avoids.
|
||||
/// </summary>
|
||||
protected abstract List<int> AvoidNPCs { get; }
|
||||
|
||||
protected abstract float SpawningChance { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Since a lot of these NPCs change behaviors a lot, this abstract class provides an <see cref="Action"/> property to store and trigger behaviors.<br/>
|
||||
/// Automatically resets <see cref="PathfindingPoints"/> and <see cref="PathTimer"/> 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
|
||||
/// </summary>
|
||||
protected Action PreviousBehavior { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// A lot of these Sunken Sea creatures use the <see cref="CalamityUtils.AStar"/> pathfinding algorithm,<br/>
|
||||
/// so this abstract class provides a <see cref="List{T}"/> so you can store the paths.<br/>
|
||||
/// Defaults to <see langword="null"/>.
|
||||
/// </summary>
|
||||
protected List<Vector2> PathfindingPoints { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The probablity that this Sunken Sea NPC spawns given the conditions.
|
||||
/// </summary>
|
||||
protected abstract float SpawningChance { get; }
|
||||
|
||||
protected int PathPointIndex { get; set; }
|
||||
|
||||
private bool _hasSpawned;
|
||||
|
||||
#region Targetting
|
||||
|
||||
/// <summary>
|
||||
/// A list which stores the NPC's IDs that this creature hunts.
|
||||
/// </summary>
|
||||
protected abstract List<int> HuntNPCs { get; }
|
||||
|
||||
/// <summary>
|
||||
/// A list which stores the NPC's IDs that this creature avoids.
|
||||
/// </summary>
|
||||
protected abstract List<int> AvoidNPCs { get; }
|
||||
|
||||
/// <summary>
|
||||
/// The current NPC that this creature has detected as prey.
|
||||
/// </summary>
|
||||
@@ -142,11 +131,6 @@ namespace CalamityMod.NPCs.SunkenSea
|
||||
/// </summary>
|
||||
protected Entity NearestEntity { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Whether or not the creature has detected anything at all.
|
||||
/// </summary>
|
||||
protected bool HasAnyTargets => CurrentPrey != null || CurrentPredator != null || CurrentPlayer != null;
|
||||
|
||||
/// <summary>
|
||||
/// The distance detection radius.<br/>
|
||||
/// Defaults to 300 pixels.
|
||||
@@ -182,19 +166,56 @@ namespace CalamityMod.NPCs.SunkenSea
|
||||
/// Defaults to 3 seconds.
|
||||
/// </summary>
|
||||
protected virtual float PermanenceSenseTime => CalamityUtils.SecondsToFrames(3f);
|
||||
|
||||
private int _permanenceSenseTimer;
|
||||
|
||||
/// <summary>
|
||||
/// A lot of these Sunken Sea creatures use the <see cref="CalamityUtils.AStar"/> pathfinding algorithm,<br/>
|
||||
/// so this abstract class provides a <see cref="List{T}"/> so you can store the paths.<br/>
|
||||
/// Defaults to <see langword="null"/>.
|
||||
/// Whether or not the creature has detected anything at all.
|
||||
/// </summary>
|
||||
protected List<Vector2> PathfindingPoints { get; set; }
|
||||
protected bool HasAnyTargets => CurrentPrey != null || CurrentPredator != null || CurrentPlayer != null;
|
||||
|
||||
protected int PathPointIndex { get; set; }
|
||||
#endregion
|
||||
|
||||
private bool _hasSpawned;
|
||||
#region Biome Designation
|
||||
|
||||
/// <summary>
|
||||
/// The flags corresponding for the possible spawns for a Sunken Sea NPC.
|
||||
/// </summary>
|
||||
[Flags]
|
||||
protected enum BiomeFlags : byte
|
||||
{
|
||||
None = 0,
|
||||
UndergroundDesert = 1,
|
||||
TimelessShores = 2,
|
||||
RadiantReefs = 4,
|
||||
PolypForest = 8,
|
||||
GleamingBurrows = 16,
|
||||
BasaltGully = 32,
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The biomes that this Sunken Sea NPC belongs to.
|
||||
/// </summary>
|
||||
protected abstract BiomeFlags BiomeDesignation { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Each biome has a correspoding spawn condition boolean value and a biome type.
|
||||
/// </summary>
|
||||
protected readonly Dictionary<BiomeFlags, (Func<NPCSpawnInfo, bool> SpawnCondition, int BiomeType)> BiomeCorrespondentValues = new()
|
||||
{
|
||||
{ BiomeFlags.UndergroundDesert, (spawnInfo => spawnInfo.Player.ZoneDesert, -1 /* None needed. */) },
|
||||
{ BiomeFlags.TimelessShores, (spawnInfo => spawnInfo.Player.Calamity().ZoneTimelessShores, GetInstance<TimelessShoresBiome>().Type) },
|
||||
{ BiomeFlags.RadiantReefs, (spawnInfo => spawnInfo.Player.Calamity().ZoneRadiantReefs, GetInstance<RadiantReefsBiome>().Type) },
|
||||
{ BiomeFlags.PolypForest, (spawnInfo => spawnInfo.Player.Calamity().ZonePolypForest, GetInstance<PolypForestBiome>().Type) },
|
||||
{ BiomeFlags.GleamingBurrows, (spawnInfo => spawnInfo.Player.Calamity().ZoneGleamingBurrows, GetInstance<GleamingBurrowsBiome>().Type) },
|
||||
{ BiomeFlags.BasaltGully, (spawnInfo => spawnInfo.Player.Calamity().ZoneBasaltGully, GetInstance<BasaltGullyBiome>().Type) },
|
||||
};
|
||||
|
||||
/// <summary>
|
||||
/// The spawn conditions for each biome that this Sunken Sea NPC belongs to.
|
||||
/// </summary>
|
||||
protected List<Func<NPCSpawnInfo, bool>> 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);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Same function as <see cref="SendExtraAI(BinaryWriter)"/>, but since that one already sends information and to avoid accidents,<br/>
|
||||
/// <see cref="SendExtraAI(BinaryWriter)"/> is <see langword="sealed"/> and instead this is available.
|
||||
/// </summary>
|
||||
protected virtual void SendMoreExtraAI(BinaryWriter writer) { }
|
||||
|
||||
/// <summary>
|
||||
/// Same function as <see cref="ReceiveExtraAI(BinaryReader)"/>, but since that one already sends information and to avoid accidents,<br/>
|
||||
/// <see cref="ReceiveExtraAI(BinaryReader)"/> is <see langword="sealed"/> and instead this is available.
|
||||
/// </summary>
|
||||
protected virtual void ReceiveMoreExtraAI(BinaryReader reader) { }
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user