NYCRO HELP ME BRO (Fixed Compiling)
This commit is contained in:
1 parent
50a14a454e
commit
3d15aaa89c
3 files changed
+61
-55
No files matched your search
@@ -18,7 +18,7 @@ using static Terraria.ModLoader.ModContent;
|
||||
|
||||
namespace CalamityMod.NPCs.SunkenSea
|
||||
{
|
||||
public class Probesnout : SunkenSeaNPC, IPathFinder
|
||||
public class Probesnout : SunkenSeaNPC
|
||||
{
|
||||
#region Members
|
||||
|
||||
@@ -94,7 +94,11 @@ namespace CalamityMod.NPCs.SunkenSea
|
||||
|
||||
private Action _previousBehavior;
|
||||
|
||||
public PathfindingTask Path { get; set; }
|
||||
private int HuntCooldown
|
||||
{
|
||||
get => (int)NPC.ai[3];
|
||||
set => NPC.ai[3] = value;
|
||||
}
|
||||
|
||||
public Vector2 Position => NPC.Center;
|
||||
|
||||
@@ -128,6 +132,12 @@ namespace CalamityMod.NPCs.SunkenSea
|
||||
NPC.spriteDirection = Main.rand.NextBool().ToDirectionInt();
|
||||
NPC.GravityMultiplier *= 2f;
|
||||
NPC.MaxFallSpeedMultiplier *= 2f;
|
||||
pathfinding = new PathfindingManager(NPC)
|
||||
{
|
||||
Acceleration = 0.4f,
|
||||
MaxSpeed = 8f,
|
||||
MinimalPointDistance = 60f,
|
||||
};
|
||||
}
|
||||
|
||||
public override void AI()
|
||||
@@ -181,14 +191,7 @@ namespace CalamityMod.NPCs.SunkenSea
|
||||
private void IdlingBehavior()
|
||||
{
|
||||
// At random, the mob will choose a random nearby point and pathfind there.
|
||||
PathfindingTask parameters = null;
|
||||
if (Main.rand.NextBool(150))
|
||||
{
|
||||
_randomPathPoint = NPC.Center + Main.rand.NextVector2Unit() * 300f;
|
||||
NPC.netUpdate = true;
|
||||
parameters = new PathfindingTask(NPC.Center, _randomPathPoint, SunkenSeaTileValidity);
|
||||
}
|
||||
this.DoPathfinding(parameters);
|
||||
pathfinding.DoPathfinding(new(NPC.Center, NPC.Center + Main.rand.NextVector2Unit() * Main.rand.NextFloat(500f, 3000f), SunkenSeaTileValidity));
|
||||
}
|
||||
|
||||
private void FleeingBehavior()
|
||||
@@ -216,12 +219,11 @@ namespace CalamityMod.NPCs.SunkenSea
|
||||
}
|
||||
while (!Main.tile[(NPC.Center + _randomPathPoint).ToTileCoordinates()].IsTileSolid());
|
||||
NPC.netUpdate = true;
|
||||
this.DoPathfinding(new PathfindingTask(NPC.Center, NPC.Center + _randomPathPoint, SunkenSeaTileValidity));
|
||||
pathfinding.DoPathfinding(new(NPC.Center, NPC.Center + _randomPathPoint, SunkenSeaTileValidity));
|
||||
}
|
||||
else
|
||||
{
|
||||
NPC.velocity += NPC.DirectionFrom(CurrentPredator.Center) * Acceleration;
|
||||
Path = null;
|
||||
|
||||
// Cap the speed if MaxSpeed has been surpassed.
|
||||
if (NPC.velocity.LengthSquared() > MaxSpeed * MaxSpeed)
|
||||
@@ -238,8 +240,14 @@ namespace CalamityMod.NPCs.SunkenSea
|
||||
return;
|
||||
}
|
||||
|
||||
bool huntReady = HuntCooldown == 0;
|
||||
if (huntReady)
|
||||
HuntCooldown = Main.rand.Next(13, 30);
|
||||
|
||||
// With sight, just go straight at him. Without it, try to pathfind over them.
|
||||
this.DoPathfinding(new PathfindingTask(NPC.Center, CurrentPrey.Center, SunkenSeaTileValidity), continuouslyUpdatePath: true);
|
||||
pathfinding.DoPathfinding(new(NPC.Center, CurrentPrey.Center, SunkenSeaTileValidity), forceNewTask: huntReady);
|
||||
|
||||
HuntCooldown--;
|
||||
}
|
||||
|
||||
private void EatingBehavior()
|
||||
@@ -257,7 +265,7 @@ namespace CalamityMod.NPCs.SunkenSea
|
||||
}
|
||||
}
|
||||
else
|
||||
this.DoPathfinding(new PathfindingTask(NPC.Center, SpongeFoundPosition, SunkenSeaTileValidity));
|
||||
pathfinding.DoPathfinding(new(NPC.Center, SpongeFoundPosition, SunkenSeaTileValidity));
|
||||
}
|
||||
|
||||
private void OutsideWaterBehavior()
|
||||
@@ -386,7 +394,7 @@ namespace CalamityMod.NPCs.SunkenSea
|
||||
{
|
||||
base.SetDefaults();
|
||||
|
||||
// BannerItem = ItemType<ProbesnoutBanner>();
|
||||
BannerItem = ItemType<ProbesnoutBanner>();
|
||||
|
||||
NPC.lifeMax = 5;
|
||||
|
||||
|
||||
+25
-37
@@ -18,7 +18,7 @@ using static Terraria.ModLoader.ModContent;
|
||||
|
||||
namespace CalamityMod.NPCs.SunkenSea
|
||||
{
|
||||
public class Sharkoon : SunkenSeaNPC, IPathFinder
|
||||
public class Sharkoon : SunkenSeaNPC
|
||||
{
|
||||
#region Fields & Properties
|
||||
|
||||
@@ -133,6 +133,12 @@ namespace CalamityMod.NPCs.SunkenSea
|
||||
|
||||
private Action _previousBehavior;
|
||||
|
||||
private int HuntCooldown
|
||||
{
|
||||
get => (int)NPC.ai[3];
|
||||
set => NPC.ai[3] = value;
|
||||
}
|
||||
|
||||
#region SunkenSeaNPC Implementation
|
||||
|
||||
protected override List<int> PreyIDs =>
|
||||
@@ -157,20 +163,6 @@ namespace CalamityMod.NPCs.SunkenSea
|
||||
|
||||
#endregion
|
||||
|
||||
#region IPathFinder Implementation
|
||||
|
||||
public PathfindingTask Path { get; set; }
|
||||
|
||||
public Vector2 Position => NPC.Center;
|
||||
|
||||
public Vector2 Velocity { get => NPC.velocity; set => NPC.velocity = value; }
|
||||
|
||||
public float Acceleration { get; set; } = 0.25f;
|
||||
|
||||
public float MaxSpeed { get; set; } = 6f;
|
||||
|
||||
#endregion
|
||||
|
||||
#endregion
|
||||
|
||||
#region SetDefaults
|
||||
@@ -227,6 +219,11 @@ namespace CalamityMod.NPCs.SunkenSea
|
||||
NPC.spriteDirection = Main.rand.NextBool().ToDirectionInt();
|
||||
NPC.GravityMultiplier *= 2f;
|
||||
NPC.MaxFallSpeedMultiplier *= 2f;
|
||||
pathfinding = new PathfindingManager(NPC)
|
||||
{
|
||||
Acceleration = 0.25f,
|
||||
MaxSpeed = 6f,
|
||||
};
|
||||
}
|
||||
|
||||
public override void AI()
|
||||
@@ -261,14 +258,7 @@ namespace CalamityMod.NPCs.SunkenSea
|
||||
private void IdlingBehavior()
|
||||
{
|
||||
// At random, the mob will choose a random nearby point and pathfind there.
|
||||
PathfindingTask task = null;
|
||||
if (Main.rand.NextBool(IdleRandomMovementUnlikeliness))
|
||||
{
|
||||
_randomPathPoint = NPC.Center + Main.rand.NextVector2Unit() * Main.rand.NextFloat(IdleMinPathDistance, IdleMaxPathDistance);
|
||||
NPC.netUpdate = true;
|
||||
task = new PathfindingTask(NPC.Center, _randomPathPoint, SunkenSeaTileValidity);
|
||||
}
|
||||
this.DoPathfinding(task);
|
||||
pathfinding.DoPathfinding(new(NPC.Center, NPC.Center + Main.rand.NextVector2Unit() * 2000f, SunkenSeaTileValidity));
|
||||
}
|
||||
|
||||
private void HuntingBehavior()
|
||||
@@ -280,15 +270,14 @@ namespace CalamityMod.NPCs.SunkenSea
|
||||
return;
|
||||
}
|
||||
|
||||
bool huntReady = HuntCooldown == 0;
|
||||
if (huntReady)
|
||||
HuntCooldown = Main.rand.Next(13, 30);
|
||||
|
||||
// With sight, just go straight at him. Without it, try to pathfind over them.
|
||||
if (!NPC.HasSight(CurrentPrey.Center))
|
||||
this.DoPathfinding(new PathfindingTask(NPC.Center, CurrentPrey.Center, SunkenSeaTileValidity));
|
||||
else
|
||||
{
|
||||
NPC.velocity += NPC.DirectionTo(CurrentPrey.Center) * Acceleration;
|
||||
if (NPC.velocity.LengthSquared() > MaxSpeed * MaxSpeed)
|
||||
NPC.velocity = Vector2.Normalize(NPC.velocity) * MaxSpeed;
|
||||
}
|
||||
pathfinding.DoPathfinding(new(NPC.Center, CurrentPrey.Center, SunkenSeaTileValidity), forceNewTask: huntReady);
|
||||
|
||||
HuntCooldown--;
|
||||
}
|
||||
|
||||
private void FleeingBehavior()
|
||||
@@ -307,18 +296,19 @@ namespace CalamityMod.NPCs.SunkenSea
|
||||
// Try to manuever if there are any obstacles.
|
||||
if (!Main.tile[(NPC.Center + NPC.DirectionFrom(_avoidedEntity.Center) * FleeTileAnticipationDistance).ToTileCoordinates()].IsTileSolid())
|
||||
{
|
||||
NPC.velocity += NPC.DirectionFrom(_avoidedEntity.Center) * Acceleration;
|
||||
NPC.velocity += NPC.DirectionFrom(_avoidedEntity.Center) * pathfinding.Acceleration;
|
||||
pathfinding.ClearResults();
|
||||
|
||||
// Cap the speed if MaxSpeed has been surpassed.
|
||||
if (NPC.velocity.LengthSquared() > MaxSpeed * MaxSpeed)
|
||||
NPC.velocity = Vector2.Normalize(NPC.velocity) * MaxSpeed;
|
||||
if (NPC.velocity.LengthSquared() > pathfinding.MaxSpeed * pathfinding.MaxSpeed)
|
||||
NPC.velocity = Vector2.Normalize(NPC.velocity) * pathfinding.MaxSpeed;
|
||||
}
|
||||
else
|
||||
{
|
||||
float distanceFromAvoided = Vector2.Distance(NPC.Center, _avoidedEntity.Center);
|
||||
_randomPathPoint = NPC.Center + Main.rand.NextVector2Unit() * Utils.Remap(distanceFromAvoided, 0f, 960f, 80f, 3200f);
|
||||
NPC.netUpdate = true;
|
||||
this.DoPathfinding(new PathfindingTask(NPC.Center, _randomPathPoint, SunkenSeaTileValidity));
|
||||
pathfinding.DoPathfinding(new(NPC.Center, _randomPathPoint, SunkenSeaTileValidity));
|
||||
}
|
||||
|
||||
// If it's capable of exploding and the predator's within distance, kaboom.
|
||||
@@ -397,8 +387,6 @@ namespace CalamityMod.NPCs.SunkenSea
|
||||
// When it gets outside of water, it'll try to gravitate downards towards the water.
|
||||
if (newBehavior == OutsideWaterBehavior)
|
||||
NPC.noGravity = false;
|
||||
|
||||
Path = null;
|
||||
}
|
||||
|
||||
protected override void OnPreyDetection(NPC prey)
|
||||
|
||||
@@ -35,6 +35,8 @@ namespace CalamityMod
|
||||
#region Pathfinding Manager
|
||||
public class PathfindingManager
|
||||
{
|
||||
public List<Vector2> Path { get => lastSuccessfulTask?.Result ?? []; }
|
||||
|
||||
/// <summary>
|
||||
/// The entity which this PathfindingManager manages. This cannot be changed after creation.
|
||||
/// </summary>
|
||||
@@ -44,13 +46,15 @@ namespace CalamityMod
|
||||
/// The acceleration this PathfindingManager will impart to its Entity when making it follow a found path.<br />
|
||||
/// This has no impact on the Entity's other behaviors, AI, etc.
|
||||
/// </summary>
|
||||
internal float Acceleration { get; set; }
|
||||
internal float Acceleration { get; set; } = 0.2f;
|
||||
|
||||
/// <summary>
|
||||
/// The maximum speed this PathfindingManager allow its Entity to move at when making it follow a found path.<br />
|
||||
/// This has no impact on the Entity's other behaviors, AI, etc.
|
||||
/// </summary>
|
||||
internal float MaxSpeed { get; set; }
|
||||
internal float MaxSpeed { get; set; } = 4f;
|
||||
|
||||
internal float MinimalPointDistance { get; set; } = 48f;
|
||||
|
||||
/// <summary>
|
||||
/// The last completed pathfinding task that this manager has performed.<br />
|
||||
@@ -183,7 +187,7 @@ namespace CalamityMod
|
||||
entity.velocity = entity.velocity.SafeNormalize(Vector2.UnitY) * MaxSpeed;
|
||||
|
||||
// If the entity is within 48 pixels of its target point, consider the point reached.
|
||||
if (Vector2.DistanceSquared(entity.Center, nextPoint) < 48f * 48f)
|
||||
if (Vector2.DistanceSquared(entity.Center, nextPoint) < MinimalPointDistance * MinimalPointDistance)
|
||||
return true;
|
||||
|
||||
// Otherwise, continue following.
|
||||
@@ -218,6 +222,12 @@ namespace CalamityMod
|
||||
DefaultIdleBehavior();
|
||||
}
|
||||
|
||||
public void ClearResults()
|
||||
{
|
||||
currentTask = null;
|
||||
lastSuccessfulTask = null;
|
||||
}
|
||||
|
||||
#region Pathfinding Task
|
||||
/// <summary>
|
||||
/// Represents a task for calculating a complex path.<br/>
|
||||
|
||||
Reference in new issue
Block a user