The Gift updated visual effect
Fixed it being able to affect multiple NPCs at once Fixed HealingPlus particle drawing position and cleaned up its code
This commit is contained in:
1 parent
95ff066a8a
commit
8fc95ed775
3 files changed
+31
-22
No files matched your search
+29
-12
@@ -3,6 +3,7 @@ using CalamityMod.NPCs;
|
||||
using CalamityMod.Particles;
|
||||
using Microsoft.Xna.Framework;
|
||||
using Terraria;
|
||||
using Terraria.Audio;
|
||||
using Terraria.GameContent;
|
||||
using Terraria.ID;
|
||||
using Terraria.Localization;
|
||||
@@ -14,7 +15,7 @@ namespace CalamityMod.Items.Tools
|
||||
{
|
||||
public new string LocalizationCategory => "Items.Tools";
|
||||
public override string Texture => "Terraria/Images/Item_601"; //Placeholder
|
||||
|
||||
public static readonly SoundStyle BadBuzzer = new SoundStyle("CalamityMod/Sounds/Custom/BadGiftBuzzer") with { Volume = 0.85f };
|
||||
public override void SetDefaults()
|
||||
{
|
||||
Item.width = Item.height = 20;
|
||||
@@ -44,26 +45,42 @@ namespace CalamityMod.Items.Tools
|
||||
{
|
||||
// Don't run this code for NPCs that aren't affected by happiness
|
||||
// Also don't run this if The Gift has already been used on this NPC; they all will hold grudges against you :)
|
||||
if (!n.isLikeATownNPC || NPCID.Sets.NoTownNPCHappiness[n.type] || NPCID.Sets.IsTownPet[n.type] ||
|
||||
n.GetGlobalNPC<CalamityGlobalTownNPC>().TheGiftStatus.HasValue)
|
||||
if (!n.isLikeATownNPC || NPCID.Sets.NoTownNPCHappiness[n.type] || NPCID.Sets.IsTownPet[n.type] || n.GetGlobalNPC<CalamityGlobalTownNPC>().TheGiftStatus.HasValue)
|
||||
continue;
|
||||
|
||||
if (Item.Hitbox.Intersects(n.Hitbox))
|
||||
{
|
||||
bool positive = Main.rand.NextBool();
|
||||
Color c = positive ? Color.Green : Color.Red;
|
||||
SoundEngine.PlaySound(positive ? SoundID.ResearchComplete : BadBuzzer, n.Center);
|
||||
n.GetGlobalNPC<CalamityGlobalTownNPC>().TheGiftStatus = positive;
|
||||
n.GetGlobalNPC<CalamityGlobalTownNPC>().TheGiftReset = 0.0;
|
||||
|
||||
// Visual effect to demonstrate that something happened
|
||||
for (int i = 0; i < 6; i++)
|
||||
{
|
||||
Vector2 spawnPos = n.Center + Main.rand.NextVector2Circular(30f, 30f);
|
||||
HealingPlus s = new(spawnPos, 0.5f, (spawnPos - n.Center).SafeNormalize(Vector2.Zero) * 0.65f, c, c * 0.2f, 25)
|
||||
{
|
||||
Rotation = positive ? 0f : MathHelper.PiOver4
|
||||
};
|
||||
GeneralParticleHandler.SpawnParticle(s);
|
||||
}
|
||||
for (int j = 0; j < 4; j++)
|
||||
{
|
||||
Vector2 spawnPos = n.Center + Main.rand.NextVector2Circular(50f, 50f);
|
||||
Vector2 arrVel = -Vector2.UnitY * 0.6f * positive.ToDirectionInt();
|
||||
StatChangeArrow arr = new(spawnPos, arrVel, -MathHelper.PiOver2 * positive.ToDirectionInt(), c, c * 0.1f, 0.7f, 40);
|
||||
GeneralParticleHandler.SpawnParticle(arr);
|
||||
}
|
||||
|
||||
Item.active = false;
|
||||
Item.type = ItemID.None;
|
||||
Item.stack = 0;
|
||||
if (Main.dedServ)
|
||||
NetMessage.SendData(MessageID.SyncItem, -1, -1, null, Item.whoAmI);
|
||||
|
||||
bool positive = Main.rand.NextBool();
|
||||
Color c = positive ? Color.Green : Color.Red;
|
||||
n.GetGlobalNPC<CalamityGlobalTownNPC>().TheGiftStatus = positive;
|
||||
n.GetGlobalNPC<CalamityGlobalTownNPC>().TheGiftReset = 0.0;
|
||||
|
||||
// Placeholder visual effect
|
||||
HealingPlus s = new(n.Center, 2f, Vector2.Zero, c, c, 40);
|
||||
GeneralParticleHandler.SpawnParticle(s);
|
||||
// Make sure it can't apply to multiple NPCs at once
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,11 +12,8 @@ namespace CalamityMod.Particles
|
||||
public override bool UseCustomDraw => true;
|
||||
public override bool SetLifetime => true;
|
||||
|
||||
public Player Owner;
|
||||
public Color StartColor;
|
||||
public Color EndColor;
|
||||
public Vector2 OverridePosition;
|
||||
public float Opacity;
|
||||
|
||||
public HealingPlus(Vector2 position, float scale, Vector2 velocity, Color colorStart, Color colorEnd, int lifetime)
|
||||
{
|
||||
@@ -34,20 +31,15 @@ namespace CalamityMod.Particles
|
||||
{
|
||||
Color = Color.Lerp(StartColor, EndColor, LifetimeCompletion);
|
||||
Lighting.AddLight(Position, Color.ToVector3() * 0.2f);
|
||||
Opacity -= 0.5f;
|
||||
}
|
||||
|
||||
public override void CustomDraw(SpriteBatch spriteBatch)
|
||||
{
|
||||
Texture2D tex = ModContent.Request<Texture2D>(Texture).Value;
|
||||
|
||||
Vector2 Size = new Vector2(Scale);
|
||||
Vector2 origin = new Vector2(tex.Width, tex.Height) * 0.5f;
|
||||
|
||||
Vector2 origin = new Vector2(tex.Width, tex.Height);
|
||||
|
||||
Vector2 PositionAdjust = new Vector2(-16, -40);
|
||||
|
||||
spriteBatch.Draw(tex, Position - Main.screenPosition - PositionAdjust, null, Color, Rotation, origin, Size, SpriteEffects.None, 0);
|
||||
spriteBatch.Draw(tex, Position - Main.screenPosition, null, Color, Rotation, origin, Size, SpriteEffects.None, 0);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Binary file not shown.
Reference in new issue
Block a user