6 Commits

Author SHA1 Message Date
YouHaveTrouble ee06338f22 bump version 2025-12-22 17:33:09 +01:00
YouHaveTrouble cc2849737c autoformatted locale 2025-12-22 17:29:21 +01:00
YouHaveTrouble e3f74c2e21 update to newest tmodloader version 2025-12-22 17:28:31 +01:00
YouHaveTrouble cc6d8d6dc2 version bump 2023-01-28 22:03:41 +01:00
YouHaveTrouble e300c3cddb Nerf katana teleport 2023-01-28 22:02:59 +01:00
YouHaveTrouble 8a9730f61f add discord link 2022-12-21 00:24:00 +01:00
15 changed files with 319 additions and 240 deletions
+13 -10
View File
@@ -2,23 +2,26 @@ using Terraria;
using Terraria.ModLoader; using Terraria.ModLoader;
using YHTMod.Projectiles.Weapons; using YHTMod.Projectiles.Weapons;
namespace YHTMod.Buffs; namespace YHTMod.Buffs;
public class ToclafaneMinionBuff : ModBuff { public class ToclafaneMinionBuff : ModBuff
{
public override void SetStaticDefaults() { public override void SetStaticDefaults()
DisplayName.SetDefault("Summon Toclafane"); {
Description.SetDefault("It came from a parallel world to fight for its Master.");
Main.buffNoSave[Type] = true; Main.buffNoSave[Type] = true;
Main.buffNoTimeDisplay[Type] = true; Main.buffNoTimeDisplay[Type] = true;
} }
public override void Update(Player player, ref int buffIndex) { public override void Update(Player player, ref int buffIndex)
if (player.ownedProjectileCounts[ModContent.ProjectileType<ToclafaneMinion>()] > 0) { {
if (player.ownedProjectileCounts[ModContent.ProjectileType<ToclafaneMinion>()] > 0)
{
player.buffTime[buffIndex] = 18000; player.buffTime[buffIndex] = 18000;
} else { }
else
{
player.DelBuff(buffIndex); player.DelBuff(buffIndex);
buffIndex--; buffIndex--;
} }
} }
} }
+11 -11
View File
@@ -1,32 +1,32 @@
using Terraria; using Terraria;
using Terraria.GameContent.ItemDropRules; using Terraria.GameContent.ItemDropRules;
using Terraria.ID; using Terraria.ID;
using Terraria.ModLoader; using Terraria.ModLoader;
using YHTMod.Items; using YHTMod.Items;
using YHTMod.Items.ArcaneMissle; using YHTMod.Items.ArcaneMissile;
namespace YHTMod.Changes; namespace YHTMod.Changes;
public class NpcLoot : GlobalNPC public class NpcLoot : GlobalNPC
{ {
public override void ModifyNPCLoot(NPC npc, NPCLoot npcLoot) { public override void ModifyNPCLoot(NPC npc, NPCLoot npcLoot)
int id = npc.type; {
var id = npc.type;
if (NPCID.Sets.CountsAsCritter[id]) {
if (NPCID.Sets.CountsAsCritter[id])
{
npcLoot.Add(ItemDropRule.Common(ModContent.ItemType<MithrilPebbleOfPigSmiting>(), 400)); npcLoot.Add(ItemDropRule.Common(ModContent.ItemType<MithrilPebbleOfPigSmiting>(), 400));
} }
switch (id) { switch (id)
{
case NPCID.Plantera: case NPCID.Plantera:
npcLoot.Add(ItemDropRule.Common(ItemID.ChlorophyteOre, 1, 60, 80)); npcLoot.Add(ItemDropRule.Common(ItemID.ChlorophyteOre, 1, 60, 80));
break; break;
case NPCID.Tim: case NPCID.Tim:
npcLoot.Add(ItemDropRule.Common(ModContent.ItemType<ArcaneMissle>())); npcLoot.Add(ItemDropRule.Common(ModContent.ItemType<ArcaneMissile>()));
break; break;
} }
} }
} }
@@ -3,20 +3,17 @@ using Terraria.GameContent.Creative;
using Terraria.ID; using Terraria.ID;
using Terraria.ModLoader; using Terraria.ModLoader;
namespace YHTMod.Items.ArcaneMissle; namespace YHTMod.Items.ArcaneMissile;
public class ArcaneMissle : ModItem { public class ArcaneMissile : ModItem
{
public override void SetStaticDefaults() { public override void SetStaticDefaults()
DisplayName.SetDefault("Arcane Missle"); {
Tooltip.SetDefault(
"Magical projectile crits shoot a homing arcane missle\n" +
"Arcane missles cannot crit"
);
CreativeItemSacrificesCatalog.Instance.SacrificeCountNeededByItemId[Type] = 1; CreativeItemSacrificesCatalog.Instance.SacrificeCountNeededByItemId[Type] = 1;
} }
public override void SetDefaults() { public override void SetDefaults()
{
Item.width = 64; Item.width = 64;
Item.height = 64; Item.height = 64;
Item.accessory = true; Item.accessory = true;
@@ -27,10 +24,10 @@ public class ArcaneMissle : ModItem {
Item.noUseGraphic = true; Item.noUseGraphic = true;
} }
public override void UpdateAccessory(Player player, bool hideVisual) { public override void UpdateAccessory(Player player, bool hideVisual)
{
player.GetModPlayer<YhtPlayer>().arcaneMissle = Item.damage; player.GetModPlayer<YhtPlayer>().arcaneMissle = Item.damage;
base.UpdateAccessory(player, hideVisual); base.UpdateAccessory(player, hideVisual);
} }
} }

Before

Width:  |  Height:  |  Size: 3.4 KiB

After

Width:  |  Height:  |  Size: 3.4 KiB

@@ -1,28 +1,31 @@
using System;
using Terraria; using Terraria;
using Terraria.ID; using Terraria.ID;
using Terraria.ModLoader; using Terraria.ModLoader;
namespace YHTMod.Items.ArcaneMissle; namespace YHTMod.Items.ArcaneMissile;
public class ArcaneMissleBehavior : GlobalNPC { public class ArcaneMissileBehavior : GlobalNPC
{
public override void OnHitByProjectile(NPC npc, Projectile projectile, int damage, float knockback, bool crit) { public override void OnHitByProjectile(NPC npc, Projectile projectile, NPC.HitInfo hitInfo, int damage)
if (!crit) { {
base.OnHitByProjectile(npc, projectile, damage, knockback, false); if (!hitInfo.Crit)
{
base.OnHitByProjectile(npc, projectile, hitInfo, damage);
return; return;
} }
if (Main.netMode == NetmodeID.Server) { if (Main.netMode == NetmodeID.Server)
{
return; return;
} }
Player player = Main.LocalPlayer; var player = Main.LocalPlayer;
if (player.GetModPlayer<YhtPlayer>().arcaneMissle != 0 && projectile.DamageType == DamageClass.Magic) { if (player.GetModPlayer<YhtPlayer>().arcaneMissle != 0 && projectile.DamageType == DamageClass.Magic)
// player just crit with magic weapon while having arcane missle accessory {
Projectile proj = Projectile.NewProjectileDirect( // player just crit with magic weapon while having arcane missile accessory
projectile.GetSource_FromThis("arcaneMissle"), var proj = Projectile.NewProjectileDirect(
projectile.GetSource_FromThis("arcaneMissile"),
Main.LocalPlayer.position, Main.LocalPlayer.position,
npc.position.DirectionFrom(Main.LocalPlayer.position), npc.position.DirectionFrom(Main.LocalPlayer.position),
ProjectileID.MagicMissile, ProjectileID.MagicMissile,
@@ -37,11 +40,11 @@ public class ArcaneMissleBehavior : GlobalNPC {
proj.tileCollide = false; proj.tileCollide = false;
proj.DamageType = DamageClass.Magic; proj.DamageType = DamageClass.Magic;
proj.aiStyle = ProjAIStyleID.MagicMissile; proj.aiStyle = ProjAIStyleID.MagicMissile;
// Prevent crits for the missles // Prevent crits for the missiles
proj.CritChance = Int32.MinValue; proj.CritChance = int.MinValue;
} }
base.OnHitByProjectile(npc, projectile, damage, knockback, true); base.OnHitByProjectile(npc, projectile, hitInfo, damage);
} }
} }
-1
View File
@@ -7,7 +7,6 @@ namespace YHTMod.Items;
public class CopperSwordOnAStick : ModItem { public class CopperSwordOnAStick : ModItem {
public override void SetStaticDefaults() { public override void SetStaticDefaults() {
DisplayName.SetDefault("Copper Sword On A Stick");
CreativeItemSacrificesCatalog.Instance.SacrificeCountNeededByItemId[Type] = 1; CreativeItemSacrificesCatalog.Instance.SacrificeCountNeededByItemId[Type] = 1;
} }
+34 -30
View File
@@ -6,47 +6,51 @@ using Terraria.ModLoader;
namespace YHTMod.Items; namespace YHTMod.Items;
public class KatanaRedo : GlobalItem { public class KatanaRedo : GlobalItem
{
public override void ModifyTooltips(Item item, List<TooltipLine> tooltips) public override void ModifyTooltips(Item item, List<TooltipLine> tooltips)
{ {
if (item.type != ItemID.Katana) return; if (item.type != ItemID.Katana) return;
tooltips.Insert(5, new TooltipLine(YHTMod.GetInstance(), "flavor" , "Nothing personel kid.")); tooltips.Insert(5, new TooltipLine(YHTMod.GetInstance(), "flavor", "Nothing personel kid."));
tooltips.Insert(6, new TooltipLine(YHTMod.GetInstance(), "usage" , "Right click to teleport behind them.")); tooltips.Insert(6, new TooltipLine(YHTMod.GetInstance(), "usage", "Right click to teleport behind them."));
} }
public override bool AltFunctionUse(Item item, Player player) { public override bool AltFunctionUse(Item item, Player player)
if (item.type != ItemID.Katana) { {
return base.AltFunctionUse(item, player); return item.type == ItemID.Katana || base.AltFunctionUse(item, player);
}
return true;
} }
public override bool? UseItem(Item item, Player player) { public override bool? UseItem(Item item, Player player)
{
if (item.type != ItemID.Katana || player.altFunctionUse != 2) return null; if (item.type != ItemID.Katana || player.altFunctionUse != 2) return null;
for (int i = 0; i < Main.maxNPCs; i++) { var yhtPlayer = player.GetModPlayer<YhtPlayer>();
NPC npc = Main.npc[i];
if (yhtPlayer.katanaTeleportCooldown > 0) return null;
yhtPlayer.katanaTeleportCooldown = 300;
for (var i = 0; i < Main.maxNPCs; i++)
{
var npc = Main.npc[i];
if (!npc.CanBeChasedBy()) continue; if (!npc.CanBeChasedBy()) continue;
float between = Vector2.Distance(npc.Center, player.Center); var between = Vector2.Distance(npc.Center, player.Center);
bool inRange = between < 650; var inRange = between < 650;
bool lineOfSight = Collision.CanHitLine(player.position, player.width, player.height, npc.position, var lineOfSight = Collision.CanHitLine(player.position, player.width, player.height, npc.position,
npc.width, npc.height); npc.width, npc.height);
if (inRange && lineOfSight) { if (!inRange || !lineOfSight) continue;
Vector2 tpPos = npc.position; var tpPos = npc.position;
tpPos.X += -(npc.direction * npc.width + (player.width*2)); tpPos.X += -(npc.direction * npc.width + (player.width * 2));
if (Collision.TileCollision(tpPos, Vector2.Zero, player.width, player.height) != Vector2.Zero) return true; if (Collision.TileCollision(tpPos, Vector2.Zero, player.width, player.height) != Vector2.Zero) return true;
player.Teleport(tpPos, TeleportationStyleID.RodOfDiscord); player.Teleport(tpPos, TeleportationStyleID.RodOfDiscord);
player.velocity = Vector2.Zero; player.velocity = Vector2.Zero;
player.NinjaDodge(); player.NinjaDodge();
return true; return true;
}
} }
return null; return null;
} }
} }
-14
View File
@@ -7,20 +7,6 @@ namespace YHTMod.Items;
public class MithrilPebbleOfPigSmiting : ModItem { public class MithrilPebbleOfPigSmiting : ModItem {
public override void SetStaticDefaults() { public override void SetStaticDefaults() {
DisplayName.SetDefault("Mithril Pebble of Pig Smiting");
Tooltip.SetDefault(
"For you see long ago this pebble was forged in the fiery pits of Tartarus. By the grand blacksmith of Lucifer himself. In a time before the world began there were\n" +
"pigs that roamed the world of aincrad. They took what they pleased and did what they wanted. The humans tried to survive but the pigs were too powerful. Then a man stood against the hogs!\n" +
"His name... Well its not a Him its a Her...HER name...was...Akane! Lucifer crafted this mighty weapon for Akane. Amd she threw it Over and Over, Again and Again. She freed\n" +
"the humans but the pigs wouldn't give up! In a mighty battle Akane fell to the Hogs Hero, Becon! Like Bacon but with a 'E' instead of a 'A'. ANYWAY Becon used his Cleaver to strike\n" +
"down Akane. And the pebble fell. One of the hogs tried to pick it up but that hog died as soon as he touched the stone. Another Hero picked up the pebble. It was Akanes Apprentice. Sophie.\n" +
"The hogs ran from the battlefield as Sophie threw the pebble. Striking many of them down. But there were too many. After returning home Sophie trained hard and set off to find Becon.\n" +
"She killed hog after hog looking for him. One little piggy spilled and told her when he was. She made Becon, Into Bacon. Battle after battle the Hogs Became weaker. With time so did Sophie.\n" +
"She died because she ate too much Pork. And the Pebble was passed too Marjosa. He made a decision. Instead of killing them all. He made them walk on four legs. He would eat them and keep them\n" +
"locked up where they cant escape. Some Hogs rebelled but most of them went with it. Accepting defeat. Then as Marjosa was Hunting wild Hogs. 3 appeared at once. Taking him by surprise.\n" +
"They hit him with there sharp horns. Marjosa hit the with the Mighty Pebble killing them all but he was weak and far from anyone who could offer help. And Thus, Marjosa\n" +
"Guardian of the Pebble fell to his knees and passed from this world. Leaving behind the mighty weapon. For he knew. One day its power would be required once more.\n" +
"But the Legacy of the pebble lives on.");
CreativeItemSacrificesCatalog.Instance.SacrificeCountNeededByItemId[Type] = 1; CreativeItemSacrificesCatalog.Instance.SacrificeCountNeededByItemId[Type] = 1;
} }
-2
View File
@@ -12,8 +12,6 @@ namespace YHTMod.Items;
public class ToclafaneStaff : ModItem { public class ToclafaneStaff : ModItem {
public override void SetStaticDefaults() { public override void SetStaticDefaults() {
DisplayName.SetDefault("Toclafane Staff");
Tooltip.SetDefault("Summons a toclafane to remove population for you");
ItemID.Sets.GamepadWholeScreenUseRange[Item.type] = true; // This lets the player target anywhere on the whole screen while using a controller. ItemID.Sets.GamepadWholeScreenUseRange[Item.type] = true; // This lets the player target anywhere on the whole screen while using a controller.
ItemID.Sets.LockOnIgnoresCollision[Item.type] = true; ItemID.Sets.LockOnIgnoresCollision[Item.type] = true;
CreativeItemSacrificesCatalog.Instance.SacrificeCountNeededByItemId[Type] = 1; CreativeItemSacrificesCatalog.Instance.SacrificeCountNeededByItemId[Type] = 1;
+58
View File
@@ -0,0 +1,58 @@
Buffs: {
ToclafaneMinionBuff: {
DisplayName: Summon Toclafane
Description: It came from a parallel world to fight for its Master.
}
}
Items: {
ArcaneMissile: {
DisplayName: Arcane Missile
Tooltip:
'''
Magical projectile crits shoot a homing arcane missile
Arcane missiles cannot crit
'''
}
CopperSwordOnAStick: {
DisplayName: Copper Sword On A Stick
Tooltip: ""
}
MithrilPebbleOfPigSmiting: {
DisplayName: Mithril Pebble Of Pig Smiting
Tooltip:
'''
For you see long ago this pebble was forged in the fiery pits of Tartarus. By the grand blacksmith of Lucifer himself.
In a time before the world began there were pigs that roamed the world of Aincrad. They took what they pleased and did
what they wanted. The humans tried to survive but the pigs were too powerful. Then a man stood against the hogs! His
name... Well its not a Him its a Her...HER name...was...Akane! Lucifer crafted this mighty weapon for Akane. And she
threw it Over and Over, Again and Again. She freed the humans but the pigs wouldn't give up! In a mighty battle Akane
fell to the Hogs Hero, Becon! Like Bacon but with a 'E' instead of a 'A'. ANYWAY Becon used his Cleaver to strike down
Akane. And the pebble fell. One of the hogs tried to pick it up but that hog died as soon as he touched the stone.
Another Hero picked up the pebble. It was Akane's Apprentice. Sophie. The hogs ran from the battlefield as Sophie threw
the pebble. Striking many of them down. But there were too many. After returning home Sophie trained hard and set off
to find Becon. She killed hog after hog looking for him. One little piggy spilled and told her when he was. She made
Becon, Into Bacon. Battle after battle the Hogs Became weaker. With time so did Sophie. She died because she ate too
much Pork. And the Pebble was passed too Marjosa. He made a decision. Instead of killing them all. He made them walk
on four legs. He would eat them and keep them locked up where they cant escape. Some Hogs rebelled but most of them
went with it. Accepting defeat. Then as Marjosa was Hunting wild Hogs. 3 appeared at once. Taking him by surprise.
They hit him with there sharp horns. Marjosa hit the with the Mighty Pebble killing them all but he was weak and far
from anyone who could offer help. And Thus, Marjosa Guardian of the Pebble fell to his knees and passed from this
world. Leaving behind the mighty weapon. For he knew. One day its power would be required once more.
But the Legacy of the pebble lives on.
'''
}
ToclafaneStaff: {
DisplayName: Toclafane Staff
Tooltip: Summons a toclafane to remove population for you
}
}
Projectiles: {
CopperSwordOnAStickProjectile.DisplayName: Copper Sword On A Stick
MithrilPebbleOfPigSmitingProjectile.DisplayName: Mithril Pebble Of Pig Smiting
ToclafaneMinion.DisplayName: Toclafane Minion
}
@@ -24,7 +24,7 @@ class MithrilPebbleOfPigSmitingProjectile : ModProjectile {
base.AI(); base.AI();
DrawOriginOffsetX = 0; DrawOriginOffsetX = 0;
DrawOffsetX = 0; DrawOffsetX = 0;
int dust = Dust.NewDust(Projectile.Center, 1, 1, DustID.Mythril, 0f, 0f, 0, default(Color), 1f); var dust = Dust.NewDust(Projectile.Center, 1, 1, DustID.Mythril, 0f, 0f, 0, default(Color), 1f);
Main.dust[dust].noGravity = true; Main.dust[dust].noGravity = true;
Main.dust[dust].velocity *= 0.3f; Main.dust[dust].velocity *= 0.3f;
} }
+162 -139
View File
@@ -7,13 +7,13 @@ using YHTMod.Buffs;
namespace YHTMod.Projectiles.Weapons; namespace YHTMod.Projectiles.Weapons;
public class ToclafaneMinion : ModProjectile { public class ToclafaneMinion : ModProjectile
{
private int _shootCooldown = 0;
private AttackMode _attackMode = AttackMode.Ranged;
private int shootCooldown = 0; public override void SetStaticDefaults()
private AttackMode attackMode = AttackMode.RANGED; {
public override void SetStaticDefaults() {
DisplayName.SetDefault("Toclafane Minion");
// Sets the amount of frames this minion has on its spritesheet // Sets the amount of frames this minion has on its spritesheet
Main.projFrames[Projectile.type] = 8; Main.projFrames[Projectile.type] = 8;
// This is necessary for right-click targeting // This is necessary for right-click targeting
@@ -23,7 +23,8 @@ public class ToclafaneMinion : ModProjectile {
ProjectileID.Sets.MinionSacrificable[Projectile.type] = true; ProjectileID.Sets.MinionSacrificable[Projectile.type] = true;
} }
public sealed override void SetDefaults() { public sealed override void SetDefaults()
{
Projectile.width = 32; Projectile.width = 32;
Projectile.height = 32; Projectile.height = 32;
Projectile.scale = 0.65f; Projectile.scale = 0.65f;
@@ -36,24 +37,29 @@ public class ToclafaneMinion : ModProjectile {
Projectile.penetrate = -1; Projectile.penetrate = -1;
} }
public override bool? CanCutTiles() { public override bool? CanCutTiles()
{
return false; return false;
} }
public override bool MinionContactDamage() { public override bool MinionContactDamage()
{
return true; return true;
} }
public override void AI() { public override void AI()
Player player = Main.player[Projectile.owner]; {
var player = Main.player[Projectile.owner];
#region Active check #region Active check
if (player.dead || !player.active) { if (player.dead || !player.active)
{
player.ClearBuff(ModContent.BuffType<ToclafaneMinionBuff>()); player.ClearBuff(ModContent.BuffType<ToclafaneMinionBuff>());
} }
if (player.HasBuff(ModContent.BuffType<ToclafaneMinionBuff>())) { if (player.HasBuff(ModContent.BuffType<ToclafaneMinionBuff>()))
{
Projectile.timeLeft = 2; Projectile.timeLeft = 2;
} }
@@ -61,13 +67,14 @@ public class ToclafaneMinion : ModProjectile {
#region General behavior #region General behavior
if (shootCooldown > 0) { if (_shootCooldown > 0)
shootCooldown = shootCooldown - 1; {
_shootCooldown = _shootCooldown - 1;
} }
attackMode = AttackMode.RANGED; _attackMode = AttackMode.Ranged;
Vector2 idlePosition = player.Center; var 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;
@@ -76,9 +83,10 @@ 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
Vector2 vectorToIdlePosition = idlePosition - Projectile.Center; var vectorToIdlePosition = idlePosition - Projectile.Center;
float distanceToIdlePosition = vectorToIdlePosition.Length(); var 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
Projectile.position = idlePosition; Projectile.position = idlePosition;
@@ -87,18 +95,18 @@ 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
float overlapVelocity = 0.04f; const float overlapVelocity = 0.04f;
for (int i = 0; i < Main.maxProjectiles; i++) { for (var i = 0; i < Main.maxProjectiles; i++)
{
// Fix overlap with other minions // Fix overlap with other minions
Projectile other = Main.projectile[i]; var 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) { Math.Abs(Projectile.position.Y - other.position.Y) < Projectile.width)) continue;
if (Projectile.position.X < other.position.X) Projectile.velocity.X -= overlapVelocity; if (Projectile.position.X < other.position.X) Projectile.velocity.X -= overlapVelocity;
else Projectile.velocity.X += overlapVelocity; else Projectile.velocity.X += overlapVelocity;
if (Projectile.position.Y < other.position.Y) Projectile.velocity.Y -= overlapVelocity; if (Projectile.position.Y < other.position.Y) Projectile.velocity.Y -= overlapVelocity;
else Projectile.velocity.Y += overlapVelocity; else Projectile.velocity.Y += overlapVelocity;
}
} }
#endregion #endregion
@@ -106,40 +114,42 @@ public class ToclafaneMinion : ModProjectile {
#region Find target #region Find target
// Starting search distance // Starting search distance
float distanceFromTarget = 700f; var distanceFromTarget = 700f;
Vector2 targetCenter = Projectile.position; var targetCenter = Projectile.position;
bool foundTarget = false; var 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)
NPC npc = Main.npc[player.MinionAttackTargetNPC]; {
float between = Vector2.Distance(npc.Center, Projectile.Center); var npc = Main.npc[player.MinionAttackTargetNPC];
var 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;
targetCenter = npc.Center; targetCenter = npc.Center;
foundTarget = true; foundTarget = true;
} }
} }
if (!foundTarget) { if (!foundTarget)
for (int i = 0; i < Main.maxNPCs; i++) { {
NPC npc = Main.npc[i]; for (var i = 0; i < Main.maxNPCs; i++)
if (npc.CanBeChasedBy()) { {
float between = Vector2.Distance(npc.Center, Projectile.Center); var npc = Main.npc[i];
bool closest = Vector2.Distance(Projectile.Center, targetCenter) > between; if (!npc.CanBeChasedBy()) continue;
bool inRange = between < distanceFromTarget; var between = Vector2.Distance(npc.Center, Projectile.Center);
bool lineOfSight = Collision.CanHitLine(Projectile.position, Projectile.width, var closest = Vector2.Distance(Projectile.Center, targetCenter) > between;
Projectile.height, npc.position, npc.width, npc.height); var inRange = between < distanceFromTarget;
// Additional check for this specific minion behavior, otherwise it will stop attacking once it dashed through an enemy while flying though tiles afterwards var lineOfSight = Collision.CanHitLine(Projectile.position, Projectile.width,
// The number depends on various parameters seen in the movement code below. Test different ones out until it works alright Projectile.height, npc.position, npc.width, npc.height);
bool closeThroughWall = between < 100f; // Additional check for this specific minion behavior, otherwise it will stop attacking once it dashed through an enemy while flying though tiles afterwards
if (((closest && inRange) || !foundTarget) && (lineOfSight || closeThroughWall)) { // The number depends on various parameters seen in the movement code below. Test different ones out until it works alright
distanceFromTarget = between; var closeThroughWall = between < 100f;
targetCenter = npc.Center; if (((!closest || !inRange) && foundTarget) || (!lineOfSight && !closeThroughWall)) continue;
foundTarget = true; distanceFromTarget = between;
} targetCenter = npc.Center;
} foundTarget = true;
} }
} }
@@ -150,46 +160,56 @@ public class ToclafaneMinion : ModProjectile {
#region Movement #region Movement
// Default movement parameters (here for attacking) // Default movement parameters (here for attacking)
float speed = 8f; var speed = 8f;
float inertia = 20f; var inertia = 20f;
if (foundTarget) { if (foundTarget)
Vector2 direction = targetCenter - Projectile.Center; {
var 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)
direction *= speed; direction *= speed;
Projectile.velocity = (Projectile.velocity * (inertia - 1) + direction) / inertia; Projectile.velocity = (Projectile.velocity * (inertia - 1) + direction) / inertia;
} }
if (distanceFromTarget <= 120f) { switch (distanceFromTarget)
attackMode = AttackMode.MELEE; {
} case <= 120f:
_attackMode = AttackMode.Melee;
if (distanceFromTarget > 120f && shootCooldown == 0) { break;
shootCooldown = 60; // 1 second between shots case > 120f when _shootCooldown == 0:
Projectile laser = Projectile.NewProjectileDirect(player.GetSource_FromThis(), Projectile.Center, {
direction, ProjectileID.DeathLaser, 30, Projectile.knockBack, Projectile.owner); _shootCooldown = 60; // 1 second between shots
laser.friendly = true; var laser = Projectile.NewProjectileDirect(player.GetSource_FromThis(), Projectile.Center,
laser.hostile = false; direction, ProjectileID.DeathLaser, 30, Projectile.knockBack, Projectile.owner);
laser.penetrate = 5; laser.friendly = true;
attackMode = AttackMode.RANGED; laser.hostile = false;
laser.penetrate = 5;
_attackMode = AttackMode.Ranged;
break;
}
} }
} }
else { else
{
// Minion doesn't have a target: return to player and idle // Minion doesn't have a target: return to player and idle
if (distanceToIdlePosition > 600f) { if (distanceToIdlePosition > 600f)
{
// Speed up the minion if it's away from the player // Speed up the minion if it's away from the player
speed = 12f; speed = 12f;
inertia = 60f; inertia = 60f;
} }
else { else
{
// Slow down the minion if closer to the player // Slow down the minion if closer to the player
speed = 4f; speed = 4f;
inertia = 80f; inertia = 80f;
} }
if (distanceToIdlePosition > 20f) { if (distanceToIdlePosition > 20f)
{
// The immediate range around the player (when it passively floats about) // The immediate range around the player (when it passively floats about)
// This is a simple movement formula using the two parameters and its desired direction to create a "homing" movement // This is a simple movement formula using the two parameters and its desired direction to create a "homing" movement
@@ -197,7 +217,8 @@ public class ToclafaneMinion : ModProjectile {
vectorToIdlePosition *= speed; vectorToIdlePosition *= speed;
Projectile.velocity = (Projectile.velocity * (inertia - 1) + vectorToIdlePosition) / inertia; Projectile.velocity = (Projectile.velocity * (inertia - 1) + vectorToIdlePosition) / inertia;
} }
else if (Projectile.velocity == Vector2.Zero) { else if (Projectile.velocity == Vector2.Zero)
{
// If there is a case where it's not moving at all, give it a little "poke" // If there is a case where it's not moving at all, give it a little "poke"
Projectile.velocity.X = -0.15f; Projectile.velocity.X = -0.15f;
Projectile.velocity.Y = -0.05f; Projectile.velocity.Y = -0.05f;
@@ -211,66 +232,67 @@ public class ToclafaneMinion : ModProjectile {
// So it will lean slightly towards the direction it's moving // So it will lean slightly towards the direction it's moving
Projectile.rotation = Projectile.velocity.X * 0.05f; Projectile.rotation = Projectile.velocity.X * 0.05f;
int frameSpeed = 8; const int frameSpeed = 8;
Projectile.frameCounter++; Projectile.frameCounter++;
if (Projectile.frameCounter >= frameSpeed) { if (Projectile.frameCounter >= frameSpeed)
{
Projectile.frameCounter = 0; Projectile.frameCounter = 0;
if (attackMode == AttackMode.MELEE) { switch (_attackMode)
switch (Projectile.frame) { {
case 0: case AttackMode.Melee:
Projectile.frame++; switch (Projectile.frame)
break; {
case 1: case 0:
Projectile.frame++; case 1:
break; case 2:
case 2: Projectile.frame++;
Projectile.frame++; break;
break; case 3:
case 3: Projectile.frame = 0;
Projectile.frame = 0; break;
break; case 4:
case 4: Projectile.frame = 1;
Projectile.frame = 1; break;
break; case 5:
case 5: Projectile.frame = 2;
Projectile.frame = 2; break;
break; case 6:
case 6: Projectile.frame = 3;
Projectile.frame = 3; break;
break; case 7:
case 7: Projectile.frame = 4;
Projectile.frame = 4; break;
break; }
}
}
if (attackMode == AttackMode.RANGED) { break;
switch (Projectile.frame) { case AttackMode.Ranged:
case 0: switch (Projectile.frame)
Projectile.frame = 5; {
break; case 0:
case 1: Projectile.frame = 5;
Projectile.frame = 6; break;
break; case 1:
case 2: Projectile.frame = 6;
Projectile.frame = 7; break;
break; case 2:
case 3: Projectile.frame = 7;
Projectile.frame = 4; break;
break; case 3:
case 4: Projectile.frame = 4;
Projectile.frame++; break;
break; case 4:
case 5: case 5:
Projectile.frame++; case 6:
break; Projectile.frame++;
case 6: break;
Projectile.frame++; case 7:
break; Projectile.frame = 4;
case 7: break;
Projectile.frame = 4; }
break;
} break;
default:
break;
} }
} }
@@ -279,8 +301,9 @@ public class ToclafaneMinion : ModProjectile {
#endregion #endregion
} }
enum AttackMode { private enum AttackMode
MELEE, {
RANGED Melee,
Ranged,
} }
} }
+6
View File
@@ -1,3 +1,4 @@
using System;
using Terraria.ModLoader; using Terraria.ModLoader;
namespace YHTMod; namespace YHTMod;
@@ -5,6 +6,11 @@ namespace YHTMod;
public class YhtPlayer : ModPlayer { public class YhtPlayer : ModPlayer {
public int arcaneMissle = 0; public int arcaneMissle = 0;
public int katanaTeleportCooldown = 0;
public override void PreUpdate() {
this.katanaTeleportCooldown = Math.Max(this.katanaTeleportCooldown - 1, 0);
}
public override void ResetEffects() { public override void ResetEffects() {
+1 -1
View File
@@ -1,3 +1,3 @@
displayName = YHT Mod displayName = YHT Mod
author = YouHaveTrouble author = YouHaveTrouble
version = 1.1.0 version = 1.1.2
+2
View File
@@ -4,6 +4,8 @@ Steam workshop: https://steamcommunity.com/sharedfiles/filedetails/?id=289735007
Mod wiki: https://github.com/YouHaveTrouble/YHTMod/wiki Mod wiki: https://github.com/YouHaveTrouble/YHTMod/wiki
Discussion discord: [![Discord](https://img.shields.io/discord/821565102108573706?style=flat-square&color=%237289da&label=Discord)](https://discord.gg/j8KK5dGBps)
Code: YouHaveTrouble Code: YouHaveTrouble
Sprites: YouHaveTrouble, Patrxon Sprites: YouHaveTrouble, Patrxon