fire turret
This commit is contained in:
1 parent
7e234d1a3b
commit
c4104e8002
13 files changed
+400
-8
No files matched your search
Binary file not shown.
|
After Width: | Height: | Size: 14 KiB |
@@ -0,0 +1,36 @@
|
||||
using CalamityMod.Tiles.PlayerTurrets;
|
||||
using CalamityMod.Items.Materials;
|
||||
using CalamityMod.Items.Placeables.Plates;
|
||||
using Terraria;
|
||||
using Terraria.ID;
|
||||
using Terraria.ModLoader;
|
||||
|
||||
namespace CalamityMod.Items.Placeables.PlayerTurrets
|
||||
{
|
||||
public class FireTurret : ModItem
|
||||
{
|
||||
public override void SetStaticDefaults()
|
||||
{
|
||||
SacrificeTotal = 1;
|
||||
}
|
||||
|
||||
public override void SetDefaults()
|
||||
{
|
||||
Item.DefaultToPlaceableTile(ModContent.TileType<PlayerFireTurret>());
|
||||
|
||||
Item.value = Item.buyPrice(0, 10, 0, 0);
|
||||
Item.rare = ItemRarityID.Pink;
|
||||
}
|
||||
|
||||
public override void AddRecipes()
|
||||
{
|
||||
CreateRecipe().
|
||||
AddIngredient<MysteriousCircuitry>(14).
|
||||
AddIngredient<DubiousPlating>(20).
|
||||
AddIngredient<Chaosplate>(10).
|
||||
AddIngredient<EssenceofChaos>(12).
|
||||
AddTile(TileID.MythrilAnvil).
|
||||
Register();
|
||||
}
|
||||
}
|
||||
}
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 472 B |
@@ -0,0 +1,83 @@
|
||||
using Microsoft.Xna.Framework;
|
||||
using Microsoft.Xna.Framework.Graphics;
|
||||
using Terraria;
|
||||
using Terraria.ID;
|
||||
using Terraria.ModLoader;
|
||||
using Terraria.Audio;
|
||||
using System;
|
||||
|
||||
namespace CalamityMod.Projectiles.Turret
|
||||
{
|
||||
public class FireShot : ModProjectile
|
||||
{
|
||||
public override string Texture => "CalamityMod/Projectiles/InvisibleProj";
|
||||
|
||||
|
||||
public override void SetStaticDefaults()
|
||||
{
|
||||
DisplayName.SetDefault("Fire Shot");
|
||||
ProjectileID.Sets.TrailCacheLength[Projectile.type] = 16;
|
||||
ProjectileID.Sets.TrailingMode[Projectile.type] = 0;
|
||||
}
|
||||
|
||||
public override void SetDefaults()
|
||||
{
|
||||
Projectile.width = 32;
|
||||
Projectile.height = 32;
|
||||
Projectile.friendly = true;
|
||||
Projectile.tileCollide = false;
|
||||
Projectile.ignoreWater = true;
|
||||
Projectile.alpha = 255;
|
||||
Projectile.penetrate = 4;
|
||||
Projectile.extraUpdates = 1;
|
||||
Projectile.timeLeft = 52;
|
||||
Projectile.usesLocalNPCImmunity = true;
|
||||
Projectile.localNPCHitCooldown = -1;
|
||||
}
|
||||
|
||||
|
||||
public override void AI()
|
||||
{
|
||||
if (Projectile.localAI[0] == 0f)
|
||||
{
|
||||
// play a sound frame 1.
|
||||
var sound = SoundEngine.PlaySound(new SoundStyle("CalamityMod/Sounds/Custom/FlamethrowerTurret") with { Volume = 0.65f }, Projectile.Center);
|
||||
}
|
||||
Projectile.localAI[0]++;
|
||||
Projectile.velocity.Y -= 0.065f;
|
||||
if (Projectile.timeLeft < 16)
|
||||
Projectile.velocity *= 0f;
|
||||
}
|
||||
public override void OnHitNPC(NPC target, int damage, float knockback, bool crit)
|
||||
{
|
||||
target.AddBuff(BuffID.OnFire3, 240);
|
||||
}
|
||||
|
||||
public override bool PreDraw(ref Color lightColor)
|
||||
{
|
||||
float rotation = 0f;
|
||||
Texture2D lightTexture = ModContent.Request<Texture2D>("CalamityMod/ExtraTextures/GreyscaleVortex").Value;
|
||||
for (int i = 0; i < Projectile.oldPos.Length; i++)
|
||||
{
|
||||
float colorInterpolation = (float)Math.Cos((Projectile.timeLeft - 16) / 7f + i / (float)Projectile.oldPos.Length * MathHelper.Pi) * 0.35f + 0.65f;
|
||||
Color color = Color.Lerp(Color.Yellow, Color.OrangeRed, colorInterpolation) * 0.4f;
|
||||
color.A = 7;
|
||||
rotation += 0.2f;
|
||||
Vector2 drawPosition = Projectile.oldPos[i] + lightTexture.Size() * 0.5f - Main.screenPosition + new Vector2(0f, Projectile.gfxOffY) + new Vector2(-186f, -186f);
|
||||
float intensity = 0.6f;
|
||||
intensity *= MathHelper.Lerp(0.15f, 1f, 1f - i / (float)Projectile.oldPos.Length);
|
||||
intensity *= 1.5f * (Projectile.localAI[0] / 40f + 0.0375f); //become bigger the longer the projectile is alive
|
||||
// Become smaller the futher along the old positions we are.
|
||||
if (Projectile.timeLeft < 22)
|
||||
{
|
||||
color.A += 50;
|
||||
}
|
||||
if (Projectile.timeLeft < 16)
|
||||
intensity *= Projectile.timeLeft / 15;
|
||||
Vector2 scale = new Vector2(1f) * intensity;
|
||||
Main.EntitySpriteDraw(lightTexture, drawPosition, null, color, rotation, lightTexture.Size() * 0.5f, scale * 0.25f, SpriteEffects.None, 0);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
using Terraria;
|
||||
using Terraria.ID;
|
||||
using Terraria.ModLoader;
|
||||
|
||||
namespace CalamityMod.Projectiles.Turret
|
||||
{
|
||||
public class FireShotBuffer : ModProjectile
|
||||
{
|
||||
public override string Texture => "CalamityMod/Projectiles/InvisibleProj";
|
||||
|
||||
public override void SetStaticDefaults()
|
||||
{
|
||||
DisplayName.SetDefault("Fire Shot");
|
||||
}
|
||||
|
||||
public override void SetDefaults()
|
||||
{
|
||||
Projectile.width = 6;
|
||||
Projectile.height = 6;
|
||||
Projectile.friendly = true;
|
||||
Projectile.tileCollide = false;
|
||||
Projectile.ignoreWater = true;
|
||||
Projectile.alpha = 255;
|
||||
Projectile.penetrate = 1;
|
||||
Projectile.extraUpdates = 1;
|
||||
Projectile.timeLeft = 1;
|
||||
}
|
||||
|
||||
|
||||
public override void AI()
|
||||
{
|
||||
if (Main.netMode != NetmodeID.MultiplayerClient)
|
||||
{
|
||||
var source = Main.player[Main.myPlayer].GetSource_FromThis();
|
||||
Projectile.NewProjectile(source, Projectile.Center, Projectile.velocity, ModContent.ProjectileType<FireShot>(), Projectile.damage, Projectile.knockBack, Main.myPlayer);
|
||||
Projectile.Kill();
|
||||
}
|
||||
}
|
||||
|
||||
public override bool? CanDamage() => false;
|
||||
}
|
||||
}
|
||||
@@ -39,13 +39,16 @@ namespace CalamityMod.Projectiles.Turret
|
||||
{
|
||||
if (Projectile.localAI[0] == 0f)
|
||||
{
|
||||
Projectile.velocity.Y -= 1f;
|
||||
Projectile.velocity.Y -= 1.5f;
|
||||
// play a sound frame 1.
|
||||
var sound = SoundEngine.PlaySound(new SoundStyle("CalamityMod/Sounds/Custom/PlantyMushMine", 3), Projectile.Center);
|
||||
var sound = SoundEngine.PlaySound(new SoundStyle("CalamityMod/Sounds/Custom/PlantyMushMine", 3) with { Volume = 0.65f }, Projectile.Center);
|
||||
|
||||
Projectile.localAI[0] = 1f;
|
||||
}
|
||||
Projectile.velocity.Y += 0.03f;
|
||||
if (Projectile.velocity.Y < 10f)
|
||||
Projectile.velocity.Y += 0.08f;
|
||||
if (Projectile.velocity.Y > 10f)
|
||||
Projectile.velocity.Y = 10f;
|
||||
Projectile.velocity.X *= 0.995f;
|
||||
}
|
||||
public override void OnHitNPC(NPC target, int damage, float knockback, bool crit)
|
||||
@@ -74,8 +77,8 @@ namespace CalamityMod.Projectiles.Turret
|
||||
Vector2 innerScale = new Vector2(1f) * intensity * 0.7f;
|
||||
outerColor *= intensity;
|
||||
innerColor *= intensity;
|
||||
Main.EntitySpriteDraw(lightTexture, drawPosition, null, outerColor, 0f, lightTexture.Size() * 0.5f, outerScale * 0.60f, SpriteEffects.None, 0);
|
||||
Main.EntitySpriteDraw(lightTexture, drawPosition, null, innerColor, 0f, lightTexture.Size() * 0.5f, innerScale * 0.60f, SpriteEffects.None, 0);
|
||||
Main.EntitySpriteDraw(lightTexture, drawPosition, null, outerColor, 0f, lightTexture.Size() * 0.5f, outerScale * 0.40f, SpriteEffects.None, 0);
|
||||
Main.EntitySpriteDraw(lightTexture, drawPosition, null, innerColor, 0f, lightTexture.Size() * 0.5f, innerScale * 0.40f, SpriteEffects.None, 0);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -11,8 +11,6 @@ namespace CalamityMod.Projectiles.Turret
|
||||
public override void SetStaticDefaults()
|
||||
{
|
||||
DisplayName.SetDefault("Water Shot");
|
||||
ProjectileID.Sets.TrailCacheLength[Projectile.type] = 20;
|
||||
ProjectileID.Sets.TrailingMode[Projectile.type] = 0;
|
||||
}
|
||||
|
||||
public override void SetDefaults()
|
||||
|
||||
Binary file not shown.
@@ -0,0 +1,135 @@
|
||||
using CalamityMod.Projectiles.Turret;
|
||||
using CalamityMod.Tiles.PlayerTurrets;
|
||||
using Microsoft.Xna.Framework;
|
||||
using System.IO;
|
||||
using Terraria;
|
||||
using Terraria.ModLoader;
|
||||
|
||||
namespace CalamityMod.TileEntities
|
||||
{
|
||||
public class TEPlayerFireTurret : TEBaseTurret
|
||||
{
|
||||
// Tile which hosts this tile entity
|
||||
public override int TileType => ModContent.TileType<PlayerFireTurret>();
|
||||
public override int HostTileWidth => PlayerFireTurret.Width;
|
||||
public override int HostTileHeight => PlayerFireTurret.Height;
|
||||
|
||||
// Projectile variables
|
||||
public override int ProjectileType => ModContent.ProjectileType<FireShotBuffer>();
|
||||
public override int ProjectileDamage => 35;
|
||||
public override float ProjectileKnockback => 1f;
|
||||
public override float ShootSpeed => 8f;
|
||||
public override int FiringStartupDelay => 10;
|
||||
public override int FiringUseTime => 6;
|
||||
|
||||
// Projectile spawn location variables
|
||||
public override Vector2 TurretCenterOffset => new Vector2(22f + 4f * Direction, -2f);
|
||||
protected override float ShootForwardsOffset => 24f;
|
||||
|
||||
// Targeting variables
|
||||
public override float MaxRange => 300f;
|
||||
protected override float MaxTargetAngleDeviance => MathHelper.ToRadians(36f);
|
||||
protected override float MaxDeltaAnglePerFrame => MathHelper.ToRadians(5f);
|
||||
protected override float CloseAimThreshold => MathHelper.ToRadians(12f);
|
||||
protected override float CloseAimLerpFactor => 0.08f;
|
||||
|
||||
// Variables specific to this turret subclass
|
||||
private int _npcTargetIndex = -1;
|
||||
public int NPCTargetIndex
|
||||
{
|
||||
get => _npcTargetIndex;
|
||||
set
|
||||
{
|
||||
bool sync = _npcTargetIndex != value;
|
||||
_npcTargetIndex = value;
|
||||
if (sync)
|
||||
SendSyncPacket();
|
||||
}
|
||||
}
|
||||
|
||||
// Lab turrets specifically must be placed on the top left corner of their host tile.
|
||||
// This restriction is not shared by general turrets for flexibility reasons.
|
||||
public override bool IsTileValidForEntity(int x, int y)
|
||||
{
|
||||
Tile tile = Main.tile[x, y];
|
||||
return tile.HasTile && tile.TileType == TileType && tile.TileFrameX == 0 && tile.TileFrameY == 0;
|
||||
}
|
||||
|
||||
protected override Vector2 ChooseTarget(Vector2 targetingCenter)
|
||||
{
|
||||
int indexToSet = NPCTargetIndex;
|
||||
|
||||
// If a npc is already targeted, make sure they still exist and aren't dead.
|
||||
if (indexToSet != -1)
|
||||
{
|
||||
NPC npc = Main.npc[NPCTargetIndex];
|
||||
|
||||
// If they don't exist, or are dead, then unmark them as a target and search for a new one.
|
||||
if (!npc.active)
|
||||
indexToSet = -1;
|
||||
else
|
||||
{
|
||||
// If the existing target npc is close enough, return their position. Otherwise unmark them as a target.
|
||||
Vector2 npcPos = npc.Center;
|
||||
float distSQ = Vector2.DistanceSquared(targetingCenter, npcPos);
|
||||
if (distSQ <= MaxRange * MaxRange)
|
||||
return npcPos;
|
||||
else
|
||||
indexToSet = -1;
|
||||
}
|
||||
}
|
||||
|
||||
// No valid target currently exists. Loop through npcs (efficiently!) to look for the closest new target.
|
||||
Vector2 ret = InvalidTarget;
|
||||
float distSQToBeat = MaxRange * MaxRange;
|
||||
|
||||
for (int i = 0; i < Main.maxNPCs; ++i)
|
||||
{
|
||||
NPC npc = Main.npc[i];
|
||||
if (!npc.active || npc.friendly || npc.CountsAsACritter)
|
||||
continue;
|
||||
|
||||
float distSQ = npc.DistanceSQ(targetingCenter);
|
||||
if (distSQ < distSQToBeat)
|
||||
{
|
||||
distSQToBeat = distSQ;
|
||||
ret = npc.Center;
|
||||
indexToSet = i;
|
||||
}
|
||||
}
|
||||
|
||||
// Set NPCTargetIndex now that we're sure what we're targeting. This triggers a netcode sync if the value is different.
|
||||
NPCTargetIndex = indexToSet;
|
||||
return ret;
|
||||
}
|
||||
|
||||
// Makes turrets track their targeted player correctly client side.
|
||||
// This doesn't improve their actual accuracy, because they only fire server side.
|
||||
// However, it makes them rotate much more smoothly.
|
||||
// Any targeting and rotation data derived from this update will be overridden by the turret's next sync.
|
||||
public override void UpdateClient()
|
||||
{
|
||||
if (NPCTargetIndex != -1)
|
||||
{
|
||||
NPC npc = Main.npc[NPCTargetIndex];
|
||||
if (npc.active)
|
||||
TargetPos = npc.Center;
|
||||
}
|
||||
}
|
||||
|
||||
// This type of turret syncs extra data: its player target index.
|
||||
// This only takes 2 bytes so a junk array is written for the remainder of the space.
|
||||
private const int BytesUsed = 2;
|
||||
private static readonly byte[] JunkData = new byte[] { 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA };
|
||||
protected override void WriteExtraData(BinaryWriter writer)
|
||||
{
|
||||
writer.Write((short)_npcTargetIndex);
|
||||
writer.Write(JunkData);
|
||||
}
|
||||
protected override void ReadExtraData(Mod mod, BinaryReader reader)
|
||||
{
|
||||
_npcTargetIndex = reader.ReadInt16();
|
||||
_ = reader.ReadBytes(NumExtraBytes - BytesUsed);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -29,7 +29,7 @@ namespace CalamityMod.TileEntities
|
||||
// Targeting variables
|
||||
public override float MaxRange => 300f;
|
||||
protected override float MaxTargetAngleDeviance => MathHelper.ToRadians(12f);
|
||||
protected override float MaxDeltaAnglePerFrame => MathHelper.ToRadians(3f);
|
||||
protected override float MaxDeltaAnglePerFrame => MathHelper.ToRadians(5f);
|
||||
protected override float CloseAimThreshold => MathHelper.ToRadians(12f);
|
||||
protected override float CloseAimLerpFactor => 0.08f;
|
||||
|
||||
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 355 B |
@@ -0,0 +1,95 @@
|
||||
using CalamityMod.Items.Placeables.PlayerTurrets;
|
||||
using CalamityMod.TileEntities;
|
||||
using Microsoft.Xna.Framework;
|
||||
using Microsoft.Xna.Framework.Graphics;
|
||||
using Terraria;
|
||||
using Terraria.DataStructures;
|
||||
using Terraria.GameContent.ObjectInteractions;
|
||||
using Terraria.ID;
|
||||
using Terraria.ModLoader;
|
||||
using Terraria.ObjectData;
|
||||
|
||||
namespace CalamityMod.Tiles.PlayerTurrets
|
||||
{
|
||||
public class PlayerFireTurret : ModTile
|
||||
{
|
||||
public const int Width = 3;
|
||||
public const int Height = 2;
|
||||
public const int OriginOffsetX = 1;
|
||||
public const int OriginOffsetY = 1;
|
||||
public const int SheetSquare = 18;
|
||||
|
||||
public override void SetStaticDefaults()
|
||||
{
|
||||
Main.tileLighted[Type] = true;
|
||||
Main.tileFrameImportant[Type] = true;
|
||||
Main.tileNoAttach[Type] = true;
|
||||
Main.tileLavaDeath[Type] = false;
|
||||
Main.tileWaterDeath[Type] = false;
|
||||
|
||||
// No need to set width, height, origin, etc. here, Style3x2 is exactly what we want.
|
||||
TileObjectData.newTile.CopyFrom(TileObjectData.Style3x2);
|
||||
TileObjectData.newTile.LavaDeath = false;
|
||||
|
||||
// When this tile is placed, it places the Draedon Lab Turret tile entity.
|
||||
ModTileEntity te = ModContent.GetInstance<TEPlayerFireTurret>();
|
||||
TileObjectData.newTile.HookPostPlaceMyPlayer = new PlacementHook(te.Hook_AfterPlacement, -1, 0, true);
|
||||
|
||||
TileObjectData.addTile(Type);
|
||||
ModTranslation name = CreateMapEntryName();
|
||||
name.SetDefault("Fire Turret");
|
||||
AddMapEntry(new Color(67, 72, 81), name);
|
||||
HitSound = SoundID.Item14;
|
||||
|
||||
// Has 500% durability.
|
||||
MineResist = 5f;
|
||||
}
|
||||
|
||||
public override bool CanExplode(int i, int j) => false;
|
||||
|
||||
public override bool CreateDust(int i, int j, ref int type)
|
||||
{
|
||||
Dust.NewDust(new Vector2(i, j) * 16f, 16, 16, 226);
|
||||
return false;
|
||||
}
|
||||
|
||||
public override bool HasSmartInteract(int i, int j, SmartInteractScanSettings settings) => true;
|
||||
|
||||
public override void NumDust(int i, int j, bool fail, ref int num) => num = fail ? 1 : 3;
|
||||
|
||||
public override void KillMultiTile(int i, int j, int frameX, int frameY)
|
||||
{
|
||||
Item.NewItem(new EntitySource_TileBreak(i, j), i * 16, j * 16, 32, 32, ModContent.ItemType<FireTurret>(), 1);
|
||||
|
||||
Tile t = Main.tile[i, j];
|
||||
int left = i - t.TileFrameX % (Width * SheetSquare) / SheetSquare;
|
||||
int top = j - t.TileFrameY % (Height * SheetSquare) / SheetSquare;
|
||||
|
||||
TEPlayerFireTurret te = CalamityUtils.FindTileEntity<TEPlayerFireTurret>(i, j, Width, Height, SheetSquare);
|
||||
te?.Kill(left, top);
|
||||
}
|
||||
|
||||
// The turret tile draws a pulse turret on top of itself.
|
||||
public override void PostDraw(int i, int j, SpriteBatch spriteBatch)
|
||||
{
|
||||
Tile t = Main.tile[i, j];
|
||||
if (t.TileFrameX != 36 || t.TileFrameY != 0)
|
||||
return;
|
||||
|
||||
TEPlayerFireTurret te = CalamityUtils.FindTileEntity<TEPlayerFireTurret>(i, j, Width, Height, SheetSquare);
|
||||
if (te is null)
|
||||
return;
|
||||
int drawDirection = te.Direction;
|
||||
Color drawColor = Lighting.GetColor(i, j);
|
||||
|
||||
Texture2D tex = ModContent.Request<Texture2D>("CalamityMod/Tiles/PlayerTurrets/FireTurretHead").Value;
|
||||
Vector2 screenOffset = Main.drawToScreen ? Vector2.Zero : new Vector2(Main.offScreenRange);
|
||||
Vector2 drawOffset = new Vector2(i * 16 - Main.screenPosition.X, j * 16 - Main.screenPosition.Y) + screenOffset;
|
||||
drawOffset.Y -= 2f;
|
||||
drawOffset.X += (drawDirection == -1 ? -10f : 2f) -2f;
|
||||
|
||||
SpriteEffects sfx = drawDirection == -1 ? SpriteEffects.FlipVertically : SpriteEffects.None;
|
||||
spriteBatch.Draw(tex, drawOffset, null, drawColor, te.Angle, tex.Size() * 0.5f, 1f, sfx, 0.0f);
|
||||
}
|
||||
}
|
||||
}
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 340 B |
Reference in new issue
Block a user