Add self-defense
This commit is contained in:
1 parent
ae3a23329a
commit
6f35ec5fbb
2 files changed
+50
-13
No files matched your search
@@ -1,5 +1,6 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading;
|
||||
using CalamityMod.Items.Accessories;
|
||||
using CalamityMod.Items.Fishing;
|
||||
using CalamityMod.Items.Fishing.FishingRods;
|
||||
@@ -12,6 +13,7 @@ using CalamityMod.Items.SummonItems.TownPets;
|
||||
using CalamityMod.Items.Tools;
|
||||
using CalamityMod.Items.Weapons.Ranged;
|
||||
using CalamityMod.Items.Weapons.Rogue;
|
||||
using CalamityMod.Particles;
|
||||
using CalamityMod.Projectiles.Typeless;
|
||||
using CalamityMod.World;
|
||||
using Microsoft.Xna.Framework;
|
||||
@@ -172,11 +174,14 @@ namespace CalamityMod.NPCs.TownNPCs
|
||||
|
||||
public override void FindFrame(int frameHeight)
|
||||
{
|
||||
if (NPC.ai[0] == 12f)
|
||||
if (NPC.ai[0] == 12f) // Attacking
|
||||
{
|
||||
NPC.spriteDirection = NPC.direction;
|
||||
|
||||
NPC.frameCounter = 0;
|
||||
NPC.frame.Y = frameHeight * 9;
|
||||
}
|
||||
|
||||
else if (NPC.velocity.Y == 0f)
|
||||
{
|
||||
if (!NPC.IsABestiaryIconDummy)
|
||||
@@ -203,6 +208,7 @@ namespace CalamityMod.NPCs.TownNPCs
|
||||
if (NPC.frame.Y / frameHeight >= Main.npcFrameCount[Type] - 1)
|
||||
NPC.frame.Y = frameHeight;
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
NPC.frameCounter = 0.0;
|
||||
@@ -328,8 +334,8 @@ namespace CalamityMod.NPCs.TownNPCs
|
||||
|
||||
public override void TownNPCAttackStrength(ref int damage, ref float knockback)
|
||||
{
|
||||
damage = 25;
|
||||
knockback = 3f;
|
||||
damage = 10;
|
||||
knockback = 1f;
|
||||
}
|
||||
|
||||
public override void TownNPCAttackProj(ref int projType, ref int attackDelay)
|
||||
@@ -351,14 +357,23 @@ namespace CalamityMod.NPCs.TownNPCs
|
||||
randExtraCooldown = 10;
|
||||
}
|
||||
|
||||
public override void DrawTownAttackGun(ref Texture2D item, ref Rectangle itemFrame, ref float scale, ref int horizontalHoldoutOffset)
|
||||
public override void PostDraw(SpriteBatch spriteBatch, Vector2 screenPos, Color drawColor)
|
||||
{
|
||||
item = TextureAssets.Item[ModContent.ItemType<ElephantKiller>()].Value;
|
||||
itemFrame = new Rectangle(0, 0, item.Width, item.Height);
|
||||
horizontalHoldoutOffset = -21;
|
||||
// Manually draw gun frame when attacking
|
||||
if (NPC.ai[0] == 12f && !NPC.IsABestiaryIconDummy)
|
||||
{
|
||||
Texture2D gunTex = TextureAssets.Item[ModContent.ItemType<ElephantKiller>()].Value;
|
||||
int holdoutOffset = -21;
|
||||
Vector2 origin = NPC.spriteDirection == -1 ? new Vector2(gunTex.Width + holdoutOffset, gunTex.Height / 2f) : new Vector2(-holdoutOffset, gunTex.Height / 2f);
|
||||
Vector2 drawPos = NPC.Center - screenPos + new Vector2(0f, 8f);
|
||||
float rotation = NPC.ai[2] * ((float)Math.PI / 2f) * NPC.spriteDirection;
|
||||
|
||||
spriteBatch.Draw(gunTex, drawPos, null, drawColor, rotation, origin, NPC.scale, NPC.spriteDirection == 1 ? SpriteEffects.None : SpriteEffects.FlipHorizontally, 0f);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public class ShadySalesmanSpawnSystem : ModSystem
|
||||
{
|
||||
private static bool CanSpawnTonight = true;
|
||||
|
||||
@@ -3,31 +3,35 @@ using System.Collections.Generic;
|
||||
using CalamityMod.Items.Accessories;
|
||||
using CalamityMod.Items.Fishing;
|
||||
using CalamityMod.Items.Fishing.FishingRods;
|
||||
using CalamityMod.NPCs.TownNPCs;
|
||||
using CalamityMod.Particles;
|
||||
using Microsoft.Xna.Framework;
|
||||
using Terraria;
|
||||
using Terraria.DataStructures;
|
||||
using Terraria.ID;
|
||||
using Terraria.ModLoader;
|
||||
|
||||
namespace CalamityMod.Projectiles.Typeless
|
||||
{
|
||||
public class ShadySalesmanGunshot : ModProjectile
|
||||
public class ShadySalesmanGunshot : ModProjectile, ILocalizedModType
|
||||
{
|
||||
public override string Texture => "CalamityMod/Projectiles/InvisibleProj";
|
||||
|
||||
public override void SetDefaults()
|
||||
{
|
||||
Projectile.width = 4;
|
||||
Projectile.height = 4;
|
||||
Projectile.width = 12;
|
||||
Projectile.height = 12;
|
||||
Projectile.friendly = true;
|
||||
Projectile.hostile = false;
|
||||
Projectile.penetrate = 1;
|
||||
Projectile.penetrate = 3;
|
||||
Projectile.timeLeft = 600;
|
||||
Projectile.tileCollide = true;
|
||||
Projectile.ignoreWater = true;
|
||||
Projectile.extraUpdates = 1;
|
||||
Projectile.extraUpdates = 10;
|
||||
Projectile.DamageType = DamageClass.Ranged;
|
||||
Projectile.extraUpdates = 8;
|
||||
Projectile.localNPCHitCooldown = -1;
|
||||
Projectile.usesLocalNPCImmunity = true;
|
||||
|
||||
}
|
||||
|
||||
public override void AI()
|
||||
@@ -35,6 +39,24 @@ namespace CalamityMod.Projectiles.Typeless
|
||||
Lighting.AddLight(Projectile.Center, Color.Khaki.ToVector3() * 0.2f);
|
||||
}
|
||||
|
||||
public override void OnSpawn(IEntitySource source)
|
||||
{
|
||||
// Shift the projectile up to about the center of the salesman and override its speed
|
||||
if (source is EntitySource_Parent parentSource && parentSource.Entity is NPC npc && npc.type == ModContent.NPCType<ShadySalesman>())
|
||||
{
|
||||
Projectile.position.Y -= 4f;
|
||||
|
||||
float rotation = npc.ai[2];
|
||||
Vector2 barrelDirection = rotation.ToRotationVector2();
|
||||
|
||||
if (npc.spriteDirection == -1)
|
||||
barrelDirection.X *= -1;
|
||||
|
||||
float speed = Projectile.velocity.Length();
|
||||
Projectile.velocity = barrelDirection * speed;
|
||||
}
|
||||
}
|
||||
|
||||
public override void OnHitNPC(NPC target, NPC.HitInfo hit, int damageDone)
|
||||
{
|
||||
SpawnImpactEffects(target.Center);
|
||||
|
||||
Reference in new issue
Block a user