Files
CalamityModPublic/Items/DifficultyItems/Malice.cs
T
2021-08-18 17:32:42 -04:00

103 lines
4.0 KiB
C#

using CalamityMod.CalPlayer;
using CalamityMod.Events;
using CalamityMod.World;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Terraria;
using Terraria.DataStructures;
using Terraria.ID;
using Terraria.ModLoader;
namespace CalamityMod.Items.DifficultyItems
{
public class Malice : ModItem
{
public int frameCounter = 0;
public int frame = 0;
public override void SetStaticDefaults()
{
DisplayName.SetDefault("Malice");
Tooltip.SetDefault("Enrages every boss and allows them to drop special items.\n" +
"Nurse no longer heals while a boss is alive.\n" +
"Effect can be toggled on and off.");
}
public override void SetDefaults()
{
item.rare = ItemRarityID.Purple;
item.width = 82;
item.height = 66;
item.useAnimation = 45;
item.useTime = 45;
item.useStyle = ItemUseStyleID.HoldingUp;
item.UseSound = SoundID.Item119;
item.consumable = false;
}
public override void UseStyle(Player player)
{
player.itemLocation += new Vector2(-32f * player.direction, player.gravDir).RotatedBy(player.itemRotation);
}
public override bool PreDrawInInventory(SpriteBatch spriteBatch, Vector2 position, Rectangle frameI, Color drawColor, Color itemColor, Vector2 origin, float scale)
{
Texture2D texture = ModContent.GetTexture("CalamityMod/Items/DifficultyItems/Malice_Animated");
spriteBatch.Draw(texture, position, item.GetCurrentFrame(ref frame, ref frameCounter, 8, 8), Color.White, 0f, origin, scale, SpriteEffects.None, 0);
return false;
}
public override bool PreDrawInWorld(SpriteBatch spriteBatch, Color lightColor, Color alphaColor, ref float rotation, ref float scale, int whoAmI)
{
Texture2D texture = ModContent.GetTexture("CalamityMod/Items/DifficultyItems/Malice_Animated");
spriteBatch.Draw(texture, item.position - Main.screenPosition, item.GetCurrentFrame(ref frame, ref frameCounter, 8, 8), lightColor, 0f, Vector2.Zero, 1f, SpriteEffects.None, 0);
return false;
}
public override bool UseItem(Player player)
{
if (player.itemAnimation > 0 && player.itemTime == 0)
{
// This world syncing code should only be run by one entity- the server, to prevent a race condition
// with the packets.
if (Main.netMode == NetmodeID.MultiplayerClient)
return true;
if (CalamityPlayer.areThereAnyDamnBosses || CalamityWorld.DoGSecondStageCountdown > 0 || BossRushEvent.BossRushActive)
{
string key = "Mods.CalamityMod.ChangingTheRules";
Color messageColor = Color.Crimson;
CalamityUtils.DisplayLocalizedText(key, messageColor);
return true;
}
if (!CalamityWorld.malice)
{
CalamityWorld.malice = true;
string key = "Mods.CalamityMod.MaliceText";
Color messageColor = Color.Crimson;
CalamityUtils.DisplayLocalizedText(key, messageColor);
}
else
{
CalamityWorld.malice = false;
string key = "Mods.CalamityMod.MaliceText2";
Color messageColor = Color.Crimson;
CalamityUtils.DisplayLocalizedText(key, messageColor);
}
CalamityWorld.DoGSecondStageCountdown = 0;
CalamityNetcode.SyncWorld();
return true;
}
return true;
}
public override void AddRecipes()
{
ModRecipe recipe = new ModRecipe(mod);
recipe.AddTile(TileID.DemonAltar);
recipe.SetResult(this);
recipe.AddRecipe();
}
}
}