Files
CalamityModPublic/Tiles/BaseTiles/BaseBossRelic.cs
T

139 lines
5.8 KiB
C#

using System;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using ReLogic.Content;
using Terraria;
using Terraria.DataStructures;
using Terraria.Enums;
using Terraria.ID;
using Terraria.Localization;
using Terraria.ModLoader;
using Terraria.ObjectData;
namespace CalamityMod.Tiles.BaseTiles
{
public abstract class BaseBossRelic : ModTile
{
public const int FrameWidth = 18 * 3;
public const int FrameHeight = 18 * 4;
public const int HorizontalFrames = 1;
public const int VerticalFrames = 1;
public Asset<Texture2D> RelicTexture;
// Every relic has its own extra floating part, should be 50x50. Optional: Expand this sheet if you want to add more, stacked vertically
// If you do not go the optional way, and you extend from this class, you can override this to point to a different texture
public abstract string RelicTextureName
{
get;
}
public abstract int AssociatedItem
{
get;
}
// All relics use the same pedestal texture, this one is copied from vanilla
public override string Texture => "CalamityMod/Tiles/BaseTiles/RelicPedestal";
public override void Load()
{
if (!Main.dedServ)
{
// Cache the extra texture displayed on the pedestal
RelicTexture = ModContent.Request<Texture2D>(RelicTextureName);
}
}
public override void Unload()
{
// Unload the extra texture displayed on the pedestal
RelicTexture = null;
}
public override void SetStaticDefaults()
{
RegisterItemDrop(AssociatedItem);
Main.tileShine[Type] = 400; // Responsible for golden particles
Main.tileFrameImportant[Type] = true; // Any multitile requires this
TileID.Sets.InteractibleByNPCs[Type] = true; // Town NPCs will palm their hand at this tile
TileObjectData.newTile.CopyFrom(TileObjectData.Style3x4); // Relics are 3x4
TileObjectData.newTile.LavaDeath = false; // Does not break when lava touches it
TileObjectData.newTile.DrawYOffset = 2; // So the tile sinks into the ground
TileObjectData.newTile.Direction = TileObjectDirection.PlaceLeft; // Player faces to the left
TileObjectData.newTile.StyleHorizontal = false;
// Register an alternate tile data with flipped direction
TileObjectData.newAlternate.CopyFrom(TileObjectData.newTile); // Copy everything from above, saves us some code
TileObjectData.newAlternate.Direction = TileObjectDirection.PlaceRight; // Player faces to the right
TileObjectData.addAlternate(1);
// Register the tile data itself
TileObjectData.addTile(Type);
// Register map name and color
// "MapObject.Relic" refers to the translation key for the vanilla "Relic" text
AddMapEntry(new Color(233, 207, 94), Language.GetText("MapObject.Relic"));
}
public override bool CreateDust(int i, int j, ref int type)
{
return false;
}
public override void DrawEffects(int i, int j, SpriteBatch spriteBatch, ref TileDrawInfo drawData)
{
// Since this tile does not have the hovering part on its sheet, we have to animate it ourselves
// Therefore we register the top-left of the tile as a "special point"
// This allows us to draw things in SpecialDraw
if (drawData.tileFrameX % FrameWidth == 0 && drawData.tileFrameY % FrameHeight == 0)
{
Main.instance.TilesRenderer.AddSpecialPoint(i, j, Terraria.GameContent.Drawing.TileDrawing.TileCounterType.CustomNonSolid);
}
}
public override void SpecialDraw(int i, int j, SpriteBatch spriteBatch)
{
// Take the tile, check if it actually exists.
Point p = new Point(i, j);
Tile tile = Main.tile[p.X, p.Y];
if (!tile.HasTile)
return;
// Get the initial draw parameters.
Texture2D texture = RelicTexture.Value;
int frameY = tile.TileFrameX / FrameWidth; // Picks the frame on the sheet based on the placeStyle of the item.
Rectangle frame = texture.Frame(HorizontalFrames, VerticalFrames, 0, frameY);
Vector2 origin = frame.Size() / 2f;
Vector2 worldPos = p.ToWorldCoordinates(24f, 64f);
Color color = Lighting.GetColor(p.X, p.Y);
bool direction = tile.TileFrameY / FrameHeight != 0; // This is related to the alternate tile data we registered before.
SpriteEffects effects = direction ? SpriteEffects.FlipHorizontally : SpriteEffects.None;
// Some math magic to make it smoothly move up and down over time.
const float TwoPi = (float)Math.PI * 2f;
float offset = (float)Math.Sin(Main.GlobalTimeWrappedHourly * TwoPi / 5f);
Vector2 drawPos = worldPos - Main.screenPosition + new Vector2(0f, -40f) + new Vector2(0f, offset * 4f);
// Draw the main texture.
spriteBatch.Draw(texture, drawPos, frame, color, 0f, origin, 1f, effects, 0f);
// Draw the periodic glow effect.
float scale = (float)Math.Sin(Main.GlobalTimeWrappedHourly * TwoPi / 2f) * 0.3f + 0.7f;
Color effectColor = color;
effectColor.A = 0;
effectColor = effectColor * 0.1f * scale;
float offset2 = 6f + offset * 2f;
float oneSixth = 1f / 6f;
for (float k = 0f; k < 1f; k += oneSixth)
spriteBatch.Draw(texture, drawPos + (TwoPi * k).ToRotationVector2() * offset2, frame, effectColor, 0f, origin, 1f, effects, 0f);
}
}
}