+ Basic Greed Pot Implementation
This commit is contained in:
1 parent
63c619fbc7
commit
b9eeb72260
4 files changed
+321
No files matched your search
@@ -0,0 +1,18 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using CalamityMod.Tiles;
|
||||
using Terraria.ModLoader;
|
||||
|
||||
namespace CalamityMod.Items.Placeables
|
||||
{
|
||||
public class GreedPot : ModItem
|
||||
{
|
||||
public new string LocalizationCategory => "Items.Placeables";
|
||||
|
||||
public override void SetDefaults() => Item.DefaultToPlaceableTile(ModContent.TileType<GreedPotTile>());
|
||||
|
||||
}
|
||||
}
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 457 B |
@@ -0,0 +1,303 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Net;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using CalamityMod.DataStructures;
|
||||
using CalamityMod.Items.Placeables.Ores;
|
||||
using Microsoft.Xna.Framework;
|
||||
using Microsoft.Xna.Framework.Graphics;
|
||||
using Terraria;
|
||||
using Terraria.DataStructures;
|
||||
using Terraria.GameContent;
|
||||
using Terraria.ID;
|
||||
using Terraria.ModLoader;
|
||||
using Terraria.ObjectData;
|
||||
|
||||
namespace CalamityMod.Tiles
|
||||
{
|
||||
public class GreedPotTile : ModTile
|
||||
{
|
||||
public override void SetStaticDefaults()
|
||||
{
|
||||
Main.tileFrameImportant[Type] = true;
|
||||
Main.tileNoFail[Type] = true;
|
||||
Main.tileObsidianKill[Type] = true;
|
||||
|
||||
TileObjectData.newTile.CopyFrom(TileObjectData.Style3x3);
|
||||
|
||||
ModTileEntity te = ModContent.GetInstance<GreedPotTE>();
|
||||
TileObjectData.newTile.HookPostPlaceMyPlayer = new PlacementHook(te.Hook_AfterPlacement, -1, 0, true);
|
||||
|
||||
TileObjectData.addTile(Type);
|
||||
|
||||
DustType = DustID.Iron;
|
||||
|
||||
AddMapEntry(new Color(250, 142, 4));
|
||||
}
|
||||
|
||||
public override void MouseOver(int i, int j)
|
||||
{
|
||||
List<int> availableOres = GreedTransmutation.GreedChain.Where(p => p.Value.Availability.Invoke()).Select(p => p.Key).ToList();
|
||||
|
||||
Player player = Main.LocalPlayer;
|
||||
player.noThrow = 2;
|
||||
player.cursorItemIconEnabled = true;
|
||||
player.cursorItemIconID = availableOres[(int)((Main.GlobalTimeWrappedHourly * 2) % availableOres.Count)];
|
||||
}
|
||||
|
||||
public override void AnimateIndividualTile(int type, int i, int j, ref int frameXOffset, ref int frameYOffset)
|
||||
{
|
||||
if (TileEntity.TryGet<GreedPotTE>(new(i, j), out var greedPotTE))
|
||||
{
|
||||
frameXOffset = 18 * 3 * greedPotTE.MyFrame;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public class GreedPotTE : ModTileEntity
|
||||
{
|
||||
internal bool Activated = false;
|
||||
internal ushort TimeSinceActivation = 0;
|
||||
private ushort FrameTime = 0;
|
||||
private byte CurrentFrame = 0;
|
||||
public int MyFrame => (int)CurrentFrame;
|
||||
|
||||
private const byte FullActiveFrame = 4;
|
||||
private const byte FrameRate = 3;
|
||||
private const byte FrameTotal = 8;
|
||||
|
||||
public override bool IsTileValidForEntity(int x, int y)
|
||||
{
|
||||
Tile tile = Main.tile[x, y];
|
||||
|
||||
int style = 0, alt = 0;
|
||||
TileObjectData.GetTileInfo(tile, ref style, ref alt);
|
||||
TileObjectData data = TileObjectData.GetTileData(tile.TileType, style, alt);
|
||||
|
||||
int sheetSquare = 16 + data.CoordinatePadding;
|
||||
int FrameX = tile.TileFrameX / sheetSquare % data.Width;
|
||||
int FrameY = tile.TileFrameY / sheetSquare % data.Height;
|
||||
|
||||
return tile.HasTile && tile.TileType == ModContent.TileType<GreedPotTile>() && FrameX == 0 && FrameY == 0;
|
||||
}
|
||||
|
||||
public override int Hook_AfterPlacement(int i, int j, int type, int style, int direction, int alternate)
|
||||
{
|
||||
if (Main.netMode == NetmodeID.MultiplayerClient)
|
||||
{
|
||||
NetMessage.SendTileSquare(Main.myPlayer, i, j, 3, 3);
|
||||
NetMessage.SendData(MessageID.TileEntityPlacement, -1, -1, null, i, j, Type);
|
||||
return -1;
|
||||
}
|
||||
return Place(i, j);
|
||||
}
|
||||
|
||||
public override void OnNetPlace() => NetMessage.SendData(MessageID.TileEntitySharing, -1, -1, null, ID, Position.X, Position.Y);
|
||||
|
||||
public override void Update()
|
||||
{
|
||||
if(Activated)
|
||||
{
|
||||
if(CurrentFrame != 3)
|
||||
{
|
||||
FrameTime++;
|
||||
if(FrameTime % FrameRate == 0)
|
||||
{
|
||||
FrameTime = 0;
|
||||
CurrentFrame = (byte)((CurrentFrame + 1) % FrameTotal);
|
||||
}
|
||||
}
|
||||
|
||||
if (TimeSinceActivation >= 150)
|
||||
{
|
||||
Activated = false;
|
||||
TimeSinceActivation = 0;
|
||||
return;
|
||||
}
|
||||
|
||||
TimeSinceActivation++;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (CurrentFrame != 0)
|
||||
{
|
||||
FrameTime++;
|
||||
if (FrameTime % FrameRate == 0)
|
||||
{
|
||||
FrameTime = 0;
|
||||
CurrentFrame = (byte)((CurrentFrame + 1) % FrameTotal);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public override void NetSend(BinaryWriter writer)
|
||||
{
|
||||
writer.Write(Activated);
|
||||
writer.Write(FrameTime);
|
||||
writer.Write(TimeSinceActivation);
|
||||
writer.Write(CurrentFrame);
|
||||
}
|
||||
public override void NetReceive(BinaryReader reader)
|
||||
{
|
||||
Activated = reader.ReadBoolean();
|
||||
FrameTime = reader.ReadUInt16();
|
||||
TimeSinceActivation = reader.ReadUInt16();
|
||||
CurrentFrame = reader.ReadByte();
|
||||
}
|
||||
}
|
||||
|
||||
public class GreedTransmutation : ModProjectile
|
||||
{
|
||||
public override string Texture => "CalamityMod/Projectiles/InvisibleProj";
|
||||
|
||||
public override void SetStaticDefaults()
|
||||
{
|
||||
static bool twoMechsDowned() =>
|
||||
NPC.downedMechBoss1 && NPC.downedMechBoss2 && !NPC.downedMechBoss3 ||
|
||||
NPC.downedMechBoss2 && NPC.downedMechBoss3 && !NPC.downedMechBoss1 ||
|
||||
NPC.downedMechBoss3 && NPC.downedMechBoss1 && !NPC.downedMechBoss2 ||
|
||||
NPC.downedMechBoss1 && NPC.downedMechBoss2 && NPC.downedMechBoss3;
|
||||
|
||||
GreedChain = new()
|
||||
{
|
||||
{ ItemID.CopperOre, (ItemID.IronOre, () => true) },
|
||||
{ ItemID.IronOre, (ItemID.SilverOre, () => true) },
|
||||
{ ItemID.SilverOre, (ItemID.GoldOre, () => true) },
|
||||
{ ItemID.TinOre, (ItemID.LeadOre, () => true) },
|
||||
{ ItemID.LeadOre, (ItemID.TungstenOre, () => true) },
|
||||
{ ItemID.TungstenOre, (ItemID.PlatinumOre, () => true) },
|
||||
{ ItemID.GoldOre, (ModContent.ItemType<AerialiteOre>(), () => DownedBossSystem.downedHiveMind || DownedBossSystem.downedPerforator) },
|
||||
{ ItemID.PlatinumOre, (ModContent.ItemType<AerialiteOre>(), () => DownedBossSystem.downedHiveMind || DownedBossSystem.downedPerforator) },
|
||||
{ ModContent.ItemType<AerialiteOre>(), (ItemID.PalladiumOre, () => Main.hardMode) },
|
||||
{ ItemID.CobaltOre, (ItemID.MythrilOre, () => CalamityServerConfig.Instance.EarlyHardmodeProgressionRework ? NPC.downedMechBossAny : Main.hardMode) },
|
||||
{ ItemID.MythrilOre, (ItemID.AdamantiteOre, () => CalamityServerConfig.Instance.EarlyHardmodeProgressionRework ? twoMechsDowned() : Main.hardMode) },
|
||||
{ ItemID.PalladiumOre, (ItemID.OrichalcumOre, () => CalamityServerConfig.Instance.EarlyHardmodeProgressionRework ? NPC.downedMechBossAny : Main.hardMode) },
|
||||
{ ItemID.OrichalcumOre, (ItemID.TitaniumOre, () => CalamityServerConfig.Instance.EarlyHardmodeProgressionRework ? twoMechsDowned() : Main.hardMode) },
|
||||
{ ItemID.AdamantiteOre, (ModContent.ItemType<HallowedOre>(), () => CalamityServerConfig.Instance.EarlyHardmodeProgressionRework ? NPC.downedMechBoss1 && NPC.downedMechBoss2 && NPC.downedMechBoss3 : NPC.downedMechBossAny) },
|
||||
{ ItemID.TitaniumOre, (ModContent.ItemType<HallowedOre>(), () => CalamityServerConfig.Instance.EarlyHardmodeProgressionRework ? NPC.downedMechBoss1 && NPC.downedMechBoss2 && NPC.downedMechBoss3 : NPC.downedMechBossAny) },
|
||||
{ ModContent.ItemType<HallowedOre>(), (ItemID.ChlorophyteOre, () => NPC.downedMechBoss1 && NPC.downedMechBoss2 && NPC.downedMechBoss3) },
|
||||
{ ItemID.ChlorophyteOre, (ModContent.ItemType<PerennialOre>(), () => NPC.downedPlantBoss) },
|
||||
{ ModContent.ItemType<PerennialOre>(), (ModContent.ItemType<ScoriaOre>(), () => NPC.downedGolemBoss) },
|
||||
{ ModContent.ItemType<ScoriaOre>(), (ItemID.LunarOre, () => NPC.downedMoonlord) },
|
||||
{ ItemID.LunarOre, (ModContent.ItemType<ExodiumCluster>(), () => NPC.downedMoonlord) },
|
||||
{ ModContent.ItemType<ExodiumCluster>(), (ModContent.ItemType<UelibloomOre>(), () => DownedBossSystem.downedProvidence) },
|
||||
{ ModContent.ItemType<UelibloomOre>(), (ModContent.ItemType<AuricOre>(), () => DownedBossSystem.downedYharon) },
|
||||
};
|
||||
}
|
||||
|
||||
internal static Dictionary<int, (int Result, Func<bool> Availability)> GreedChain;
|
||||
|
||||
private int InputItemType => (int)Projectile.ai[0];
|
||||
private int SuccessOutputItemType => (int)Projectile.ai[1];
|
||||
|
||||
private Vector2 PotPosition = Vector2.Zero;
|
||||
private Vector2 StartPosition = Vector2.Zero;
|
||||
|
||||
BezierCurve path = null;
|
||||
|
||||
public override void SetDefaults()
|
||||
{
|
||||
Projectile.width = 24;
|
||||
Projectile.height = 24;
|
||||
Projectile.friendly = true;
|
||||
Projectile.ignoreWater = true;
|
||||
Projectile.tileCollide = false;
|
||||
Projectile.penetrate = 1;
|
||||
Projectile.timeLeft = 120;
|
||||
}
|
||||
|
||||
public override void OnSpawn(IEntitySource source)
|
||||
{
|
||||
StartPosition = Projectile.Center;
|
||||
PotPosition = Projectile.velocity;
|
||||
Projectile.velocity = Vector2.Zero;
|
||||
Projectile.netUpdate = true;
|
||||
}
|
||||
|
||||
|
||||
public override void AI()
|
||||
{
|
||||
if(path == null)
|
||||
{
|
||||
Vector2 startPoint = StartPosition;
|
||||
Vector2 endPoint = PotPosition - Vector2.UnitY * 64;
|
||||
|
||||
Vector2 direction = endPoint - startPoint;
|
||||
float curveIntensity = Main.rand.NextFloat(0.2f, 0.4f);
|
||||
Vector2 perpindicular = direction.RotatedBy(MathHelper.PiOver2);
|
||||
if (direction.X > 0)
|
||||
curveIntensity *= -1;
|
||||
|
||||
Vector2 controlPoint1 = startPoint + (direction * 0.25f) + (perpindicular * curveIntensity);
|
||||
Vector2 controlPoint2 = startPoint + (direction * 0.75f) + (perpindicular * curveIntensity);
|
||||
|
||||
path = new BezierCurve(startPoint, controlPoint1, controlPoint2, endPoint);
|
||||
}
|
||||
|
||||
float lerp = 1 - MathHelper.Clamp(((Projectile.timeLeft - 60) / 60f), 0f, 1f);
|
||||
|
||||
Projectile.Center = path.Evaluate(CalamityUtils.CircOutEasing(lerp, 1));
|
||||
|
||||
if (Projectile.timeLeft == 1)
|
||||
{
|
||||
int i = Item.NewItem(Projectile.GetItemSource_DropAsItem(), Projectile.Center, Main.rand.NextBool(3) ? SuccessOutputItemType : ItemID.StoneBlock);
|
||||
Main.item[i].GetGlobalItem<GreedTransmutationGlobalItem>().FromGreedPot = true;
|
||||
}
|
||||
}
|
||||
|
||||
public override bool PreDraw(ref Color lightColor)
|
||||
{
|
||||
//Anim Plan
|
||||
//Moving to Pos: 0 -> 60
|
||||
//Darken: 70 -> 80
|
||||
//Transform: 90 -> 100
|
||||
//Undarken: 110 -> 120
|
||||
Texture2D tex = TextureAssets.Item[InputItemType].Value;
|
||||
Main.spriteBatch.Draw(tex, Projectile.Center - Main.screenPosition + (Vector2.UnitY * MathF.Sin(Main.GlobalTimeWrappedHourly + Projectile.ai[2]) * 8), null, lightColor, Projectile.rotation, tex.Size() * 0.5f, 1f, 0, 0);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public class GreedTransmutationGlobalItem : GlobalItem
|
||||
{
|
||||
public override bool InstancePerEntity => true;
|
||||
|
||||
internal bool FromGreedPot = false;
|
||||
|
||||
public override bool? UseItem(Item item, Player player)
|
||||
{
|
||||
if (Main.LocalPlayer.whoAmI != player.whoAmI)
|
||||
return null;
|
||||
|
||||
if (!GreedTransmutation.GreedChain.TryGetValue(item.type, out var transmutation))
|
||||
return null;
|
||||
|
||||
if (!transmutation.Availability())
|
||||
return null;
|
||||
|
||||
Point mouseTile = Main.MouseWorld.ToTileCoordinates();
|
||||
|
||||
GreedPotTE greedPotTE = CalamityUtils.FindTileEntity<GreedPotTE>(mouseTile.X, mouseTile.Y, 3, 3, 18);
|
||||
if (greedPotTE == null)
|
||||
return null;
|
||||
|
||||
if (!player.IsInTileInteractionRange(mouseTile.X, mouseTile.Y, TileReachCheckSettings.Simple))
|
||||
return null;
|
||||
|
||||
Projectile.NewProjectile(Projectile.GetSource_NaturalSpawn(), Main.LocalPlayer.Center, greedPotTE.Position.ToWorldCoordinates(24, 24) + Main.rand.NextVector2Circular(12, 32), ModContent.ProjectileType<GreedTransmutation>(), 0, 0, Main.LocalPlayer.whoAmI, item.type, transmutation.Result, Main.rand.Next(120));
|
||||
greedPotTE.Activated = true;
|
||||
greedPotTE.TimeSinceActivation = 0;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public override bool CanStackInWorld(Item destination, Item source)
|
||||
{
|
||||
return !destination.GetGlobalItem<GreedTransmutationGlobalItem>().FromGreedPot || !source.GetGlobalItem<GreedTransmutationGlobalItem>().FromGreedPot;
|
||||
}
|
||||
}
|
||||
}
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 2.4 KiB |
Reference in new issue
Block a user