mirror of
https://github.com/YouHaveTrouble/YHTMod.git
synced 2026-05-11 21:56:54 +00:00
more specific types
This commit is contained in:
@@ -65,7 +65,7 @@ public class ToclafaneMinion : ModProjectile {
|
|||||||
|
|
||||||
_attackMode = AttackMode.Ranged;
|
_attackMode = AttackMode.Ranged;
|
||||||
|
|
||||||
var idlePosition = player.Center;
|
Vector2 idlePosition = player.Center;
|
||||||
idlePosition.Y -= 48f;
|
idlePosition.Y -= 48f;
|
||||||
|
|
||||||
float minionPositionOffsetX = (10 + Projectile.minionPos * 40) * -player.direction;
|
float minionPositionOffsetX = (10 + Projectile.minionPos * 40) * -player.direction;
|
||||||
@@ -74,8 +74,8 @@ public class ToclafaneMinion : ModProjectile {
|
|||||||
// All of this code below this line is adapted from Spazmamini code (ID 388, aiStyle 66)
|
// All of this code below this line is adapted from Spazmamini code (ID 388, aiStyle 66)
|
||||||
|
|
||||||
// Teleport to player if distance is too big
|
// Teleport to player if distance is too big
|
||||||
var vectorToIdlePosition = idlePosition - Projectile.Center;
|
Vector2 vectorToIdlePosition = idlePosition - Projectile.Center;
|
||||||
var distanceToIdlePosition = vectorToIdlePosition.Length();
|
float distanceToIdlePosition = vectorToIdlePosition.Length();
|
||||||
if (Main.myPlayer == player.whoAmI && distanceToIdlePosition > 2000f) {
|
if (Main.myPlayer == player.whoAmI && distanceToIdlePosition > 2000f) {
|
||||||
// Whenever you deal with non-regular events that change the behavior or position drastically, make sure to only run the code on the owner of the projectile,
|
// Whenever you deal with non-regular events that change the behavior or position drastically, make sure to only run the code on the owner of the projectile,
|
||||||
// and then set netUpdate to true
|
// and then set netUpdate to true
|
||||||
@@ -86,9 +86,9 @@ public class ToclafaneMinion : ModProjectile {
|
|||||||
|
|
||||||
// If your minion is flying, you want to do this independently of any conditions
|
// If your minion is flying, you want to do this independently of any conditions
|
||||||
const float overlapVelocity = 0.04f;
|
const float overlapVelocity = 0.04f;
|
||||||
for (var i = 0; i < Main.maxProjectiles; i++) {
|
for (int i = 0; i < Main.maxProjectiles; i++) {
|
||||||
// Fix overlap with other minions
|
// Fix overlap with other minions
|
||||||
var other = Main.projectile[i];
|
Projectile other = Main.projectile[i];
|
||||||
if (i == Projectile.whoAmI || !other.active || other.owner != Projectile.owner ||
|
if (i == Projectile.whoAmI || !other.active || other.owner != Projectile.owner ||
|
||||||
!(Math.Abs(Projectile.position.X - other.position.X) +
|
!(Math.Abs(Projectile.position.X - other.position.X) +
|
||||||
Math.Abs(Projectile.position.Y - other.position.Y) < Projectile.width)) continue;
|
Math.Abs(Projectile.position.Y - other.position.Y) < Projectile.width)) continue;
|
||||||
@@ -103,14 +103,14 @@ public class ToclafaneMinion : ModProjectile {
|
|||||||
#region Find target
|
#region Find target
|
||||||
|
|
||||||
// Starting search distance
|
// Starting search distance
|
||||||
var distanceFromTarget = 700f;
|
float distanceFromTarget = 700f;
|
||||||
var targetCenter = Projectile.position;
|
Vector2 targetCenter = Projectile.position;
|
||||||
var foundTarget = false;
|
bool foundTarget = false;
|
||||||
|
|
||||||
// This code is required if your minion weapon has the targeting feature
|
// This code is required if your minion weapon has the targeting feature
|
||||||
if (player.HasMinionAttackTargetNPC) {
|
if (player.HasMinionAttackTargetNPC) {
|
||||||
var npc = Main.npc[player.MinionAttackTargetNPC];
|
NPC npc = Main.npc[player.MinionAttackTargetNPC];
|
||||||
var between = Vector2.Distance(npc.Center, Projectile.Center);
|
float between = Vector2.Distance(npc.Center, Projectile.Center);
|
||||||
// Reasonable distance away so it doesn't target across multiple screens
|
// Reasonable distance away so it doesn't target across multiple screens
|
||||||
if (between < 2000f) {
|
if (between < 2000f) {
|
||||||
distanceFromTarget = between;
|
distanceFromTarget = between;
|
||||||
@@ -120,17 +120,17 @@ public class ToclafaneMinion : ModProjectile {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!foundTarget) {
|
if (!foundTarget) {
|
||||||
for (var i = 0; i < Main.maxNPCs; i++) {
|
for (int i = 0; i < Main.maxNPCs; i++) {
|
||||||
var npc = Main.npc[i];
|
NPC npc = Main.npc[i];
|
||||||
if (!npc.CanBeChasedBy()) continue;
|
if (!npc.CanBeChasedBy()) continue;
|
||||||
var between = Vector2.Distance(npc.Center, Projectile.Center);
|
float between = Vector2.Distance(npc.Center, Projectile.Center);
|
||||||
var closest = Vector2.Distance(Projectile.Center, targetCenter) > between;
|
bool closest = Vector2.Distance(Projectile.Center, targetCenter) > between;
|
||||||
var inRange = between < distanceFromTarget;
|
bool inRange = between < distanceFromTarget;
|
||||||
var lineOfSight = Collision.CanHitLine(Projectile.position, Projectile.width,
|
bool lineOfSight = Collision.CanHitLine(Projectile.position, Projectile.width,
|
||||||
Projectile.height, npc.position, npc.width, npc.height);
|
Projectile.height, npc.position, npc.width, npc.height);
|
||||||
// Additional check for this specific minion behavior, otherwise it will stop attacking once it dashed through an enemy while flying though tiles afterwards
|
// Additional check for this specific minion behavior, otherwise it will stop attacking once it dashed through an enemy while flying though tiles afterwards
|
||||||
// The number depends on various parameters seen in the movement code below. Test different ones out until it works alright
|
// The number depends on various parameters seen in the movement code below. Test different ones out until it works alright
|
||||||
var closeThroughWall = between < 100f;
|
bool closeThroughWall = between < 100f;
|
||||||
if (((!closest || !inRange) && foundTarget) || (!lineOfSight && !closeThroughWall)) continue;
|
if (((!closest || !inRange) && foundTarget) || (!lineOfSight && !closeThroughWall)) continue;
|
||||||
distanceFromTarget = between;
|
distanceFromTarget = between;
|
||||||
targetCenter = npc.Center;
|
targetCenter = npc.Center;
|
||||||
@@ -145,11 +145,11 @@ public class ToclafaneMinion : ModProjectile {
|
|||||||
#region Movement
|
#region Movement
|
||||||
|
|
||||||
// Default movement parameters (here for attacking)
|
// Default movement parameters (here for attacking)
|
||||||
var speed = 8f;
|
float speed = 8f;
|
||||||
var inertia = 20f;
|
float inertia = 20f;
|
||||||
|
|
||||||
if (foundTarget) {
|
if (foundTarget) {
|
||||||
var direction = targetCenter - Projectile.Center;
|
Vector2 direction = targetCenter - Projectile.Center;
|
||||||
direction.Normalize();
|
direction.Normalize();
|
||||||
if (distanceFromTarget > 40f) {
|
if (distanceFromTarget > 40f) {
|
||||||
// The immediate range around the target (so it doesn't latch onto it when close)
|
// The immediate range around the target (so it doesn't latch onto it when close)
|
||||||
@@ -163,7 +163,7 @@ public class ToclafaneMinion : ModProjectile {
|
|||||||
break;
|
break;
|
||||||
case > 120f when _shootCooldown == 0: {
|
case > 120f when _shootCooldown == 0: {
|
||||||
_shootCooldown = 60; // 1 second between shots
|
_shootCooldown = 60; // 1 second between shots
|
||||||
var laser = Projectile.NewProjectileDirect(player.GetSource_FromThis(), Projectile.Center,
|
Projectile laser = Projectile.NewProjectileDirect(player.GetSource_FromThis(), Projectile.Center,
|
||||||
direction, ProjectileID.DeathLaser, 30, Projectile.knockBack, Projectile.owner);
|
direction, ProjectileID.DeathLaser, 30, Projectile.knockBack, Projectile.owner);
|
||||||
laser.friendly = true;
|
laser.friendly = true;
|
||||||
laser.hostile = false;
|
laser.hostile = false;
|
||||||
|
|||||||
Reference in New Issue
Block a user