diff --git a/CalPlayer/CalamityPlayer.cs b/CalPlayer/CalamityPlayer.cs index a6b0237745..501329fc0a 100644 --- a/CalPlayer/CalamityPlayer.cs +++ b/CalPlayer/CalamityPlayer.cs @@ -130,7 +130,7 @@ namespace CalamityMod.CalPlayer public int CurrentlyViewedFactoryX = -1; public int CurrentlyViewedFactoryY = -1; - public TEDraedonFuelFactory CurrentlyViewedFactory; + public TEPowerCellFactory CurrentlyViewedFactory; public int CurrentlyViewedChargerX = -1; public int CurrentlyViewedChargerY = -1; @@ -235,6 +235,10 @@ namespace CalamityMod.CalPlayer public int danceOfLightCharge = 0; public int shadowPotCooldown = 0; public int dogTextCooldown = 0; + public float auralisStealthCounter = 0f; + public int auralisAuroraCounter = 0; + public int auralisAuroraCooldown = 0; + public int auralisAurora = 0; public int fungalSymbioteTimer = 0; public bool canFireReaverRangedProjectile = false; public bool canFireAtaxiaRangedProjectile = false; @@ -2044,6 +2048,10 @@ namespace CalamityMod.CalPlayer soundCooldown = 0; shadowPotCooldown = 0; dogTextCooldown = 0; + auralisStealthCounter = 0f; + auralisAuroraCounter = 0; + auralisAuroraCooldown = 0; + auralisAurora = 0; fungalSymbioteTimer = 0; rage = 0; adrenaline = 0; @@ -6308,6 +6316,15 @@ namespace CalamityMod.CalPlayer } } + if (auralisAuroraCounter >= 300) + { + damage -= 100; + if (damage < 1) + damage = 1; + auralisAuroraCounter = 0; + auralisAuroraCooldown = CalamityUtils.SecondsToFrames(30f); + } + if (proj.type == ModContent.ProjectileType()) { damage = 0; diff --git a/CalPlayer/CalamityPlayerDrawEffects.cs b/CalPlayer/CalamityPlayerDrawEffects.cs index 51515b794d..562766c82f 100644 --- a/CalPlayer/CalamityPlayerDrawEffects.cs +++ b/CalPlayer/CalamityPlayerDrawEffects.cs @@ -215,7 +215,8 @@ namespace CalamityMod.CalPlayer currentlyHeldItem.type == ModContent.ItemType() || currentlyHeldItem.type == ModContent.ItemType() || currentlyHeldItem.type == ModContent.ItemType() || - currentlyHeldItem.type == ModContent.ItemType()) + currentlyHeldItem.type == ModContent.ItemType() || + currentlyHeldItem.type == ModContent.ItemType()) { Texture2D texture = ModContent.GetTexture("CalamityMod/Items/Weapons/Ranged/DeathwindGlow"); int offsetX = 10; @@ -239,6 +240,11 @@ namespace CalamityMod.CalPlayer texture = ModContent.GetTexture("CalamityMod/Items/Weapons/Ranged/AuroraBlazerGlow"); offsetX = 44; } + else if (currentlyHeldItem.type == ModContent.ItemType()) + { + texture = ModContent.GetTexture("CalamityMod/Items/Weapons/Ranged/AuralisGlow"); + offsetX = 62; + } Vector2 center = Main.itemTexture[currentlyHeldItem.type].Size() * 0.5f; int originOffsetX = (int)center.X - offsetX; @@ -494,6 +500,38 @@ namespace CalamityMod.CalPlayer } }); + public static readonly PlayerLayer AuralisAuroraEffects = new PlayerLayer("CalamityMod", "AuralisAurora", PlayerLayer.Body, drawInfo => + { + Player drawPlayer = drawInfo.drawPlayer; + CalamityPlayer modPlayer = drawPlayer.Calamity(); + if (modPlayer.auralisAuroraCounter < 300 || modPlayer.auralisAuroraCooldown > 0) + return; + float auroraCount = 7; + float opacity = 0.4f; + + float time = Main.GlobalTime % 3f / 3f; + Texture2D auroraTexture = ModContent.GetTexture("CalamityMod/ExtraTextures/AuroraTexture"); + for (int i = 0; i < auroraCount; i++) + { + float incrementOffsetAngle = MathHelper.TwoPi * i / auroraCount; + float xOffset = (float)Math.Sin(time * MathHelper.TwoPi + incrementOffsetAngle * 2f) * 20f; + float yOffset = (float)Math.Sin(time * MathHelper.TwoPi + incrementOffsetAngle * 2f + MathHelper.ToRadians(60f)) * 6f; + float rotation = (float)Math.Sin(incrementOffsetAngle) * MathHelper.Pi / 12f; + Color color = CalamityUtils.ColorSwap(Auralis.blueColor, Auralis.greenColor, 3f); + Vector2 offset = new Vector2(xOffset, yOffset - 14f); + DrawData drawData = new DrawData(auroraTexture, + drawPlayer.Top + offset - Main.screenPosition, + null, + color * opacity, + rotation + MathHelper.PiOver2, + auroraTexture.Size() * 0.5f, + 0.135f, + SpriteEffects.None, + 1); + Main.playerDrawData.Add(drawData); + } + }); + public static readonly PlayerLayer IbanDevRobot = new PlayerLayer("CalamityMod", "IbanDevRobot", PlayerLayer.Body, drawInfo => { Player drawPlayer = drawInfo.drawPlayer; @@ -647,6 +685,7 @@ namespace CalamityMod.CalPlayer list.Add(RoverDriveShield); list.Add(StratusSphereDrawing); list.Add(ProfanedMoonlightDyeEffects); + list.Add(AuralisAuroraEffects); list.Add(IbanDevRobot); list.Add(DyeInvisibilityFix); } diff --git a/CalPlayer/CalamityPlayerMiscEffects.cs b/CalPlayer/CalamityPlayerMiscEffects.cs index 9b4831c42a..28735bfed8 100644 --- a/CalPlayer/CalamityPlayerMiscEffects.cs +++ b/CalPlayer/CalamityPlayerMiscEffects.cs @@ -1032,6 +1032,10 @@ namespace CalamityMod.CalPlayer } else modPlayer.roverDriveTimer = 616; //Doesn't reset to zero to prevent exploits + if (modPlayer.auralisAurora > 0) + modPlayer.auralisAurora--; + if (modPlayer.auralisAuroraCooldown > 0) + modPlayer.auralisAuroraCooldown--; // Silva invincibility effects if (modPlayer.silvaCountdown > 0 && modPlayer.hasSilvaEffect && modPlayer.silvaSet) @@ -2345,6 +2349,80 @@ namespace CalamityMod.CalPlayer } else modPlayer.modStealth = 1f; + + if (player.ActiveItem().type == ModContent.ItemType() && player.StandingStill(0.1f)) + { + if (modPlayer.auralisStealthCounter < 300f) + modPlayer.auralisStealthCounter++; + + bool usingScope = false; + if (!Main.gameMenu && Main.netMode != NetmodeID.Server) + { + if (player.noThrow <= 0 && !player.lastMouseInterface || (Main.zoomX != 0f || Main.zoomY != 0f)) + { + if (PlayerInput.UsingGamepad) + { + if (PlayerInput.GamepadThumbstickRight.Length() != 0f || !Main.SmartCursorEnabled) + { + usingScope = true; + } + } + else if (Main.mouseRight) + usingScope = true; + } + } + + int chargeDuration = CalamityUtils.SecondsToFrames(5f); + int auroraDuration = CalamityUtils.SecondsToFrames(20f); + + if (usingScope && modPlayer.auralisAuroraCounter < chargeDuration + auroraDuration) + modPlayer.auralisAuroraCounter++; + + if (modPlayer.auralisAuroraCounter > chargeDuration + auroraDuration) + { + modPlayer.auralisAuroraCounter = 0; + modPlayer.auralisAuroraCooldown = CalamityUtils.SecondsToFrames(30f); + } + + if (modPlayer.auralisAuroraCounter > 0 && modPlayer.auralisAuroraCounter < chargeDuration && !usingScope) + modPlayer.auralisAuroraCounter--; + + if (modPlayer.auralisAuroraCounter > chargeDuration && modPlayer.auralisAuroraCounter < chargeDuration + auroraDuration && !usingScope) + modPlayer.auralisAuroraCounter = 0; + } + else + { + modPlayer.auralisStealthCounter = 0f; + modPlayer.auralisAuroraCounter = 0; + } + if (modPlayer.auralisAuroraCooldown > 0) + { + if (modPlayer.auralisAuroraCooldown == 1) + { + int dustAmt = 36; + for (int d = 0; d < dustAmt; d++) + { + Vector2 source = Vector2.Normalize(player.velocity) * new Vector2((float)player.width / 2f, (float)player.height) * 1f; //0.75 + source = source.RotatedBy((double)((float)(d - (dustAmt / 2 - 1)) * MathHelper.TwoPi / (float)dustAmt), default) + player.Center; + Vector2 dustVel = source - player.Center; + int blue = Dust.NewDust(source + dustVel, 0, 0, 229, dustVel.X, dustVel.Y, 100, default, 1.2f); + Main.dust[blue].noGravity = true; + Main.dust[blue].noLight = false; + Main.dust[blue].velocity = dustVel; + } + for (int d = 0; d < dustAmt; d++) + { + Vector2 source = Vector2.Normalize(player.velocity) * new Vector2((float)player.width / 2f, (float)player.height) * 0.75f; + source = source.RotatedBy((double)((float)(d - (dustAmt / 2 - 1)) * MathHelper.TwoPi / (float)dustAmt), default) + player.Center; + Vector2 dustVel = source - player.Center; + int green = Dust.NewDust(source + dustVel, 0, 0, 107, dustVel.X, dustVel.Y, 100, default, 1.2f); + Main.dust[green].noGravity = true; + Main.dust[green].noLight = false; + Main.dust[green].velocity = dustVel; + } + } + modPlayer.auralisAuroraCounter = 0; + } } #endregion diff --git a/CalamityLists.cs b/CalamityLists.cs index 8dec0653a1..5b92f9c836 100644 --- a/CalamityLists.cs +++ b/CalamityLists.cs @@ -1525,6 +1525,7 @@ namespace CalamityMod scopedWeaponList = new List() { ModContent.ItemType(), + ModContent.ItemType(), ModContent.ItemType(), ModContent.ItemType(), ModContent.ItemType(), diff --git a/CalamityMod.cs b/CalamityMod.cs index 6784b969c6..f30f4f4a5b 100644 --- a/CalamityMod.cs +++ b/CalamityMod.cs @@ -119,44 +119,44 @@ namespace CalamityMod public static int ghostKillCount = 0; public static int sharkKillCount = 0; - // Textures + // Textures public static Texture2D heartOriginal2; - public static Texture2D heartOriginal; - public static Texture2D rainOriginal; - public static Texture2D manaOriginal; - public static Texture2D carpetOriginal; - public static Texture2D AstralCactusTexture; + public static Texture2D heartOriginal; + public static Texture2D rainOriginal; + public static Texture2D manaOriginal; + public static Texture2D carpetOriginal; + public static Texture2D AstralCactusTexture; public static Texture2D AstralCactusGlowTexture; public static Texture2D AstralSky; // DR data structure public static SortedDictionary DRValues; - // Boss Kill Time data structure - public static SortedDictionary bossKillTimes; + // Boss Kill Time data structure + public static SortedDictionary bossKillTimes; - // Boss velocity scaling data structure - public static SortedDictionary bossVelocityDamageScaleValues; - public const float velocityScaleMin = 0.5f; - public const float bitingEnemeyVelocityScale = 0.8f; + // Boss velocity scaling data structure + public static SortedDictionary bossVelocityDamageScaleValues; + public const float velocityScaleMin = 0.5f; + public const float bitingEnemeyVelocityScale = 0.8f; // TODO -- Calamity should check for other mods existing in exactly one place internal Mod thorium = null; public bool fargosMutant = false; - internal static CalamityMod Instance; + internal static CalamityMod Instance; #region Load public override void Load() { - Instance = this; - heartOriginal2 = Main.heartTexture; - heartOriginal = Main.heart2Texture; - rainOriginal = Main.rainTexture; - manaOriginal = Main.manaTexture; - carpetOriginal = Main.flyingCarpetTexture; + Instance = this; + heartOriginal2 = Main.heartTexture; + heartOriginal = Main.heart2Texture; + rainOriginal = Main.rainTexture; + manaOriginal = Main.manaTexture; + carpetOriginal = Main.flyingCarpetTexture; - NormalityRelocatorHotKey = RegisterHotKey("Normality Relocator", "Z"); + NormalityRelocatorHotKey = RegisterHotKey("Normality Relocator", "Z"); RageHotKey = RegisterHotKey("Rage Mode", "V"); AdrenalineHotKey = RegisterHotKey("Adrenaline Mode", "B"); AegisHotKey = RegisterHotKey("Elysian Guard", "N"); @@ -181,97 +181,97 @@ namespace CalamityMod CalamityLists.LoadLists(); SetupVanillaDR(); - SetupBossKillTimes(); - SetupBossVelocityScalingValues(); + SetupBossKillTimes(); + SetupBossVelocityScalingValues(); SetupThoriumBossDR(thorium); CalamityLocalization.AddLocalizations(); - On.Terraria.Player.TileInteractionsUse += Player_TileInteractionsUse; - On.Terraria.WorldGen.OpenDoor += LabDoorsOpen; - On.Terraria.WorldGen.CloseDoor += LabDoorsClose; + On.Terraria.Player.TileInteractionsUse += Player_TileInteractionsUse; + On.Terraria.WorldGen.OpenDoor += LabDoorsOpen; + On.Terraria.WorldGen.CloseDoor += LabDoorsClose; } - private static bool LabDoorsOpen(On.Terraria.WorldGen.orig_OpenDoor orig, int i, int j, int direction) - { - Tile tile = Main.tile[i, j]; - if (tile.type == ModContent.TileType() || tile.type == ModContent.TileType() || - tile.type == ModContent.TileType() || tile.type == ModContent.TileType()) - { - return false; - } - else - { - return orig(i, j, direction); - } - } + private static bool LabDoorsOpen(On.Terraria.WorldGen.orig_OpenDoor orig, int i, int j, int direction) + { + Tile tile = Main.tile[i, j]; + if (tile.type == ModContent.TileType() || tile.type == ModContent.TileType() || + tile.type == ModContent.TileType() || tile.type == ModContent.TileType()) + { + return false; + } + else + { + return orig(i, j, direction); + } + } - private static bool LabDoorsClose(On.Terraria.WorldGen.orig_CloseDoor orig, int i, int j, bool forced) - { - Tile tile = Main.tile[i, j]; - if (tile.type == ModContent.TileType() || tile.type == ModContent.TileType() || - tile.type == ModContent.TileType() || tile.type == ModContent.TileType()) - { - return false; - } - else - { - return orig(i, j, forced); - } - } + private static bool LabDoorsClose(On.Terraria.WorldGen.orig_CloseDoor orig, int i, int j, bool forced) + { + Tile tile = Main.tile[i, j]; + if (tile.type == ModContent.TileType() || tile.type == ModContent.TileType() || + tile.type == ModContent.TileType() || tile.type == ModContent.TileType()) + { + return false; + } + else + { + return orig(i, j, forced); + } + } - private static void Player_TileInteractionsUse(On.Terraria.Player.orig_TileInteractionsUse orig, Player player, int i, int j) - { - Tile tile = Main.tile[i, j]; - if (tile.type == ModContent.TileType()) - { - DoorSwap(ModContent.TileType(), ModContent.TileType(), i, j); - } - else if (tile.type == ModContent.TileType()) - { - DoorSwap(ModContent.TileType(), ModContent.TileType(), i, j); - } - else if (tile.type == ModContent.TileType()) - { - DoorSwap(ModContent.TileType(), ModContent.TileType(), i, j); - } - else if (tile.type == ModContent.TileType()) - { - DoorSwap(ModContent.TileType(), ModContent.TileType(), i, j); - } - else - { - orig(player, i, j); - } - } + private static void Player_TileInteractionsUse(On.Terraria.Player.orig_TileInteractionsUse orig, Player player, int i, int j) + { + Tile tile = Main.tile[i, j]; + if (tile.type == ModContent.TileType()) + { + DoorSwap(ModContent.TileType(), ModContent.TileType(), i, j); + } + else if (tile.type == ModContent.TileType()) + { + DoorSwap(ModContent.TileType(), ModContent.TileType(), i, j); + } + else if (tile.type == ModContent.TileType()) + { + DoorSwap(ModContent.TileType(), ModContent.TileType(), i, j); + } + else if (tile.type == ModContent.TileType()) + { + DoorSwap(ModContent.TileType(), ModContent.TileType(), i, j); + } + else + { + orig(player, i, j); + } + } - public static void DoorSwap(int type1, int type2, int i, int j, bool forced = false) - { - if (PlayerInput.Triggers.JustPressed.MouseRight || forced) - { - ushort type = (ushort)type1; - short frameY = 0; - for (int dy = -4; dy < 4; dy++) - { - if (Main.tile[i, j + dy].frameY > 0 && frameY == 0) - continue; - if (Main.tile[i, j + dy].type == type2) - { - if (Main.tile[i, j + dy] is null) - { - Main.tile[i, j + dy] = new Tile(); - } - Main.tile[i, j + dy].type = type; - Main.tile[i, j + dy].frameY = frameY; - frameY += 16; - if ((int)frameY / 16 >= 4) - break; - } - } + public static void DoorSwap(int type1, int type2, int i, int j, bool forced = false) + { + if (PlayerInput.Triggers.JustPressed.MouseRight || forced) + { + ushort type = (ushort)type1; + short frameY = 0; + for (int dy = -4; dy < 4; dy++) + { + if (Main.tile[i, j + dy].frameY > 0 && frameY == 0) + continue; + if (Main.tile[i, j + dy].type == type2) + { + if (Main.tile[i, j + dy] is null) + { + Main.tile[i, j + dy] = new Tile(); + } + Main.tile[i, j + dy].type = type; + Main.tile[i, j + dy].frameY = frameY; + frameY += 16; + if ((int)frameY / 16 >= 4) + break; + } + } - Main.PlaySound(SoundID.DoorClosed, i * 16, j * 16, 1, 1f, 0f); - } - } + Main.PlaySound(SoundID.DoorClosed, i * 16, j * 16, 1, 1f, 0f); + } + } private void LoadClient() { @@ -333,8 +333,8 @@ namespace CalamityMod Filters.Scene["CalamityMod:SupremeCalamitas"] = new Filter(new SCalScreenShaderData("FilterMiniTower").UseColor(1.1f, 0.3f, 0.3f).UseOpacity(0.65f), EffectPriority.VeryHigh); SkyManager.Instance["CalamityMod:SupremeCalamitas"] = new SCalSky(); - Filters.Scene["CalamityMod:Signus"] = new Filter(new SignusScreenShaderData("FilterMiniTower").UseColor(0.35f, 0.1f, 0.55f).UseOpacity(0.35f), EffectPriority.VeryHigh); - SkyManager.Instance["CalamityMod:Signus"] = new SignusSky(); + Filters.Scene["CalamityMod:Signus"] = new Filter(new SignusScreenShaderData("FilterMiniTower").UseColor(0.35f, 0.1f, 0.55f).UseOpacity(0.35f), EffectPriority.VeryHigh); + SkyManager.Instance["CalamityMod:Signus"] = new SignusSky(); SkyManager.Instance["CalamityMod:Astral"] = new AstralSky(); SkyManager.Instance["CalamityMod:Cryogen"] = new CryogenSky(); @@ -344,10 +344,10 @@ namespace CalamityMod RipperUI.Reset(); AstralArcanumUI.Load(this); - GameShaders.Hair.BindShader(ModContent.ItemType(), new LegacyHairShaderData().UseLegacyMethod((Player player, Color newColor, ref bool lighting) => Color.Lerp(player.hairColor, new Color(0, 255, 171), ((float)player.Calamity().adrenaline / (float)player.Calamity().adrenalineMax)))); - GameShaders.Hair.BindShader(ModContent.ItemType(), new LegacyHairShaderData().UseLegacyMethod((Player player, Color newColor, ref bool lighting) => Color.Lerp(player.hairColor, new Color(255, 83, 48), ((float)player.Calamity().rage / (float)player.Calamity().rageMax)))); - GameShaders.Hair.BindShader(ModContent.ItemType(), new LegacyHairShaderData().UseLegacyMethod((Player player, Color newColor, ref bool lighting) => Color.Lerp(player.hairColor, new Color(139, 205, 255), ((float)player.wingTime / (float)player.wingTimeMax)))); - GameShaders.Hair.BindShader(ModContent.ItemType(), new LegacyHairShaderData().UseLegacyMethod((Player player, Color newColor, ref bool lighting) => Color.Lerp(player.hairColor, new Color(186, 85, 211), (player.Calamity().rogueStealth / player.Calamity().rogueStealthMax)))); + GameShaders.Hair.BindShader(ModContent.ItemType(), new LegacyHairShaderData().UseLegacyMethod((Player player, Color newColor, ref bool lighting) => Color.Lerp(player.hairColor, new Color(0, 255, 171), ((float)player.Calamity().adrenaline / (float)player.Calamity().adrenalineMax)))); + GameShaders.Hair.BindShader(ModContent.ItemType(), new LegacyHairShaderData().UseLegacyMethod((Player player, Color newColor, ref bool lighting) => Color.Lerp(player.hairColor, new Color(255, 83, 48), ((float)player.Calamity().rage / (float)player.Calamity().rageMax)))); + GameShaders.Hair.BindShader(ModContent.ItemType(), new LegacyHairShaderData().UseLegacyMethod((Player player, Color newColor, ref bool lighting) => Color.Lerp(player.hairColor, new Color(139, 205, 255), ((float)player.wingTime / (float)player.wingTimeMax)))); + GameShaders.Hair.BindShader(ModContent.ItemType(), new LegacyHairShaderData().UseLegacyMethod((Player player, Color newColor, ref bool lighting) => Color.Lerp(player.hairColor, new Color(186, 85, 211), (player.Calamity().rogueStealth / player.Calamity().rogueStealthMax)))); SchematicLoader.LoadEverything(); @@ -377,17 +377,17 @@ namespace CalamityMod DRValues?.Clear(); DRValues = null; - bossKillTimes?.Clear(); - bossKillTimes = null; - bossVelocityDamageScaleValues?.Clear(); - bossVelocityDamageScaleValues = null; + bossKillTimes?.Clear(); + bossKillTimes = null; + bossVelocityDamageScaleValues?.Clear(); + bossVelocityDamageScaleValues = null; CalamityLists.UnloadLists(); thorium = null; fargosMutant = false; - Instance = null; + Instance = null; PopupGUIManager.UnloadGUIs(); InvasionProgressUIManager.UnloadGUIs(); @@ -402,20 +402,20 @@ namespace CalamityMod AstralArcanumUI.Unload(); base.Unload(); - if (!Main.dedServ) - { - Main.heartTexture = heartOriginal2; - Main.heart2Texture = heartOriginal; - Main.rainTexture = rainOriginal; - Main.manaTexture = manaOriginal; - Main.flyingCarpetTexture = carpetOriginal; - } + if (!Main.dedServ) + { + Main.heartTexture = heartOriginal2; + Main.heart2Texture = heartOriginal; + Main.rainTexture = rainOriginal; + Main.manaTexture = manaOriginal; + Main.flyingCarpetTexture = carpetOriginal; + } - heartOriginal2 = null; - heartOriginal = null; - rainOriginal = null; - manaOriginal = null; - carpetOriginal = null; + heartOriginal2 = null; + heartOriginal = null; + rainOriginal = null; + manaOriginal = null; + carpetOriginal = null; } #endregion @@ -429,16 +429,16 @@ namespace CalamityMod #region ConfigCrap internal static void SaveConfig(CalamityConfig cfg) - { - // in-game ModConfig saving from mod code is not supported yet in tmodloader, and subject to change, so we need to be extra careful. - // This code only supports client configs, and doesn't call onchanged. It also doesn't support ReloadRequired or anything else. - MethodInfo saveMethodInfo = typeof(ConfigManager).GetMethod("Save", BindingFlags.Static | BindingFlags.NonPublic); - if (saveMethodInfo != null) - saveMethodInfo.Invoke(null, new object[] { cfg }); - else - Instance.Logger.Warn("In-game SaveConfig failed, code update required"); - } - #endregion + { + // in-game ModConfig saving from mod code is not supported yet in tmodloader, and subject to change, so we need to be extra careful. + // This code only supports client configs, and doesn't call onchanged. It also doesn't support ReloadRequired or anything else. + MethodInfo saveMethodInfo = typeof(ConfigManager).GetMethod("Save", BindingFlags.Static | BindingFlags.NonPublic); + if (saveMethodInfo != null) + saveMethodInfo.Invoke(null, new object[] { cfg }); + else + Instance.Logger.Warn("In-game SaveConfig failed, code update required"); + } + #endregion #region Vanilla Enemy DR private void SetupVanillaDR() @@ -471,7 +471,7 @@ namespace CalamityMod { NPCID.DeadlySphere, 0.4f }, { NPCID.DiabolistRed, 0.2f }, { NPCID.DiabolistWhite, 0.2f }, - { NPCID.DukeFishron, 0.1f }, + { NPCID.DukeFishron, 0.1f }, { NPCID.DungeonGuardian, 0.999999f }, { NPCID.DungeonSpirit, 0.2f }, { NPCID.ElfCopter, 0.15f }, @@ -516,9 +516,9 @@ namespace CalamityMod { NPCID.Paladin, 0.45f }, { NPCID.PirateCaptain, 0.05f }, { NPCID.PirateShipCannon, 0.15f }, - { NPCID.Plantera, 0.15f }, - { NPCID.PlanterasTentacle, 0.1f }, - { NPCID.PossessedArmor, 0.25f }, + { NPCID.Plantera, 0.15f }, + { NPCID.PlanterasTentacle, 0.1f }, + { NPCID.PossessedArmor, 0.25f }, { NPCID.PresentMimic, 0.3f }, { NPCID.PrimeCannon, 0.2f }, { NPCID.PrimeLaser, 0.2f }, @@ -592,220 +592,220 @@ namespace CalamityMod ThoriumDR("Omnicide", 0.3f); ThoriumDR("Abyssion", 0.35f); } - #endregion + #endregion - #region Boss Kill Times - private void SetupBossKillTimes() - { - // 3600 = 1 minute + #region Boss Kill Times + private void SetupBossKillTimes() + { + // 3600 = 1 minute - bossKillTimes = new SortedDictionary { - { NPCID.KingSlime, 3600 }, - { NPCID.EyeofCthulhu, 5400 }, - { NPCID.EaterofWorldsHead, 7200 }, - { NPCID.EaterofWorldsBody, 7200 }, - { NPCID.EaterofWorldsTail, 7200 }, - { NPCID.BrainofCthulhu, 5400 }, - { NPCID.Creeper, 1800 }, - { NPCID.QueenBee, 7200 }, - { NPCID.SkeletronHead, 9000 }, - { NPCID.WallofFlesh, 7200 }, - { NPCID.WallofFleshEye, 7200 }, - { NPCID.Spazmatism, 10800 }, - { NPCID.Retinazer, 10800 }, - { NPCID.TheDestroyer, 10800 }, + bossKillTimes = new SortedDictionary { + { NPCID.KingSlime, 3600 }, + { NPCID.EyeofCthulhu, 5400 }, + { NPCID.EaterofWorldsHead, 7200 }, + { NPCID.EaterofWorldsBody, 7200 }, + { NPCID.EaterofWorldsTail, 7200 }, + { NPCID.BrainofCthulhu, 5400 }, + { NPCID.Creeper, 1800 }, + { NPCID.QueenBee, 7200 }, + { NPCID.SkeletronHead, 9000 }, + { NPCID.WallofFlesh, 7200 }, + { NPCID.WallofFleshEye, 7200 }, + { NPCID.Spazmatism, 10800 }, + { NPCID.Retinazer, 10800 }, + { NPCID.TheDestroyer, 10800 }, { NPCID.TheDestroyerBody, 10800 }, - { NPCID.TheDestroyerTail, 10800 }, - { NPCID.SkeletronPrime, 10800 }, - { NPCID.Plantera, 10800 }, - { NPCID.Golem, 9000 }, - { NPCID.GolemHead, 3600 }, - { NPCID.DukeFishron, 9000 }, - { NPCID.CultistBoss, 9000 }, - { NPCID.MoonLordCore, 14400 }, - { NPCID.MoonLordHand, 7200 }, - { NPCID.MoonLordHead, 7200 }, - { ModContent.NPCType(), 3600 }, - { ModContent.NPCType(), 3600 }, - { ModContent.NPCType(), 3600 }, - { ModContent.NPCType(), 5400 }, - { ModContent.NPCType(), 1800 }, - { ModContent.NPCType(), 5400 }, - { ModContent.NPCType(), 7200 }, - { ModContent.NPCType(), 10800 }, - { ModContent.NPCType(), 3600 }, - { ModContent.NPCType(), 3600 }, - { ModContent.NPCType(), 3600 }, - { ModContent.NPCType(), 3600 }, - { ModContent.NPCType(), 10800 }, - { ModContent.NPCType(), 7200 }, - { ModContent.NPCType(), 7200 }, - { ModContent.NPCType(), 7200 }, - { ModContent.NPCType(), 7200 }, - { ModContent.NPCType(), 10800 }, - { ModContent.NPCType(), 1200 }, - { ModContent.NPCType(), 11400 }, - { ModContent.NPCType(), 10800 }, - { ModContent.NPCType(), 10800 }, - { ModContent.NPCType(), 10800 }, - { ModContent.NPCType(), 7200 }, - { ModContent.NPCType(), 7200 }, - { ModContent.NPCType(), 7200 }, - { ModContent.NPCType(), 10800 }, - { ModContent.NPCType(), 10800 }, - { ModContent.NPCType(), 5400 }, - { ModContent.NPCType(), 7200 }, - { ModContent.NPCType(), 14400 }, - { ModContent.NPCType(), 1200 }, - { ModContent.NPCType(), 1200 }, - { ModContent.NPCType(), 1200 }, - { ModContent.NPCType(), 5400 }, - { ModContent.NPCType(), 5400 }, - { ModContent.NPCType(), 5400 }, - { ModContent.NPCType(), 7200 }, - { ModContent.NPCType(), 10800 }, - { ModContent.NPCType(), 10800 }, - { ModContent.NPCType(), 5400 }, - { ModContent.NPCType(), 5400 }, - { ModContent.NPCType(), 5400 }, - { ModContent.NPCType(), 9000 }, - { ModContent.NPCType(), 9000 }, - { ModContent.NPCType(), 9000 }, - { ModContent.NPCType(), 10800 }, - { ModContent.NPCType(), 18000 } - }; - } - #endregion + { NPCID.TheDestroyerTail, 10800 }, + { NPCID.SkeletronPrime, 10800 }, + { NPCID.Plantera, 10800 }, + { NPCID.Golem, 9000 }, + { NPCID.GolemHead, 3600 }, + { NPCID.DukeFishron, 9000 }, + { NPCID.CultistBoss, 9000 }, + { NPCID.MoonLordCore, 14400 }, + { NPCID.MoonLordHand, 7200 }, + { NPCID.MoonLordHead, 7200 }, + { ModContent.NPCType(), 3600 }, + { ModContent.NPCType(), 3600 }, + { ModContent.NPCType(), 3600 }, + { ModContent.NPCType(), 5400 }, + { ModContent.NPCType(), 1800 }, + { ModContent.NPCType(), 5400 }, + { ModContent.NPCType(), 7200 }, + { ModContent.NPCType(), 10800 }, + { ModContent.NPCType(), 3600 }, + { ModContent.NPCType(), 3600 }, + { ModContent.NPCType(), 3600 }, + { ModContent.NPCType(), 3600 }, + { ModContent.NPCType(), 10800 }, + { ModContent.NPCType(), 7200 }, + { ModContent.NPCType(), 7200 }, + { ModContent.NPCType(), 7200 }, + { ModContent.NPCType(), 7200 }, + { ModContent.NPCType(), 10800 }, + { ModContent.NPCType(), 1200 }, + { ModContent.NPCType(), 11400 }, + { ModContent.NPCType(), 10800 }, + { ModContent.NPCType(), 10800 }, + { ModContent.NPCType(), 10800 }, + { ModContent.NPCType(), 7200 }, + { ModContent.NPCType(), 7200 }, + { ModContent.NPCType(), 7200 }, + { ModContent.NPCType(), 10800 }, + { ModContent.NPCType(), 10800 }, + { ModContent.NPCType(), 5400 }, + { ModContent.NPCType(), 7200 }, + { ModContent.NPCType(), 14400 }, + { ModContent.NPCType(), 1200 }, + { ModContent.NPCType(), 1200 }, + { ModContent.NPCType(), 1200 }, + { ModContent.NPCType(), 5400 }, + { ModContent.NPCType(), 5400 }, + { ModContent.NPCType(), 5400 }, + { ModContent.NPCType(), 7200 }, + { ModContent.NPCType(), 10800 }, + { ModContent.NPCType(), 10800 }, + { ModContent.NPCType(), 5400 }, + { ModContent.NPCType(), 5400 }, + { ModContent.NPCType(), 5400 }, + { ModContent.NPCType(), 9000 }, + { ModContent.NPCType(), 9000 }, + { ModContent.NPCType(), 9000 }, + { ModContent.NPCType(), 10800 }, + { ModContent.NPCType(), 18000 } + }; + } + #endregion - #region Boss Velocity Contact Damage Scale Values - private void SetupBossVelocityScalingValues() - { - bossVelocityDamageScaleValues = new SortedDictionary { - { NPCID.KingSlime, velocityScaleMin }, - { NPCID.EyeofCthulhu, velocityScaleMin }, // Increases in phase 2 - { NPCID.EaterofWorldsHead, bitingEnemeyVelocityScale }, - { NPCID.EaterofWorldsBody, velocityScaleMin }, - { NPCID.EaterofWorldsTail, velocityScaleMin }, - { NPCID.Creeper, velocityScaleMin }, - { NPCID.BrainofCthulhu, velocityScaleMin }, - { NPCID.QueenBee, velocityScaleMin }, - { NPCID.SkeletronHead, velocityScaleMin }, - { NPCID.SkeletronHand, velocityScaleMin }, - { NPCID.TheHungry, bitingEnemeyVelocityScale }, - { NPCID.TheHungryII, bitingEnemeyVelocityScale }, - { NPCID.LeechHead, bitingEnemeyVelocityScale }, - { NPCID.LeechBody, velocityScaleMin }, - { NPCID.LeechTail, velocityScaleMin }, - { NPCID.Spazmatism, velocityScaleMin }, // Increases in phase 2 - { NPCID.Retinazer, velocityScaleMin }, - { NPCID.TheDestroyer, bitingEnemeyVelocityScale }, - { NPCID.TheDestroyerBody, velocityScaleMin }, - { NPCID.TheDestroyerTail, velocityScaleMin }, - { NPCID.Probe, velocityScaleMin }, - { NPCID.SkeletronPrime, velocityScaleMin }, - { NPCID.PrimeCannon, velocityScaleMin }, - { NPCID.PrimeLaser, velocityScaleMin }, - { NPCID.PrimeSaw, velocityScaleMin }, - { NPCID.PrimeVice, velocityScaleMin }, - { NPCID.Plantera, velocityScaleMin }, // Increases in phase 2 - { NPCID.PlanterasTentacle, bitingEnemeyVelocityScale }, - { NPCID.Golem, velocityScaleMin }, - { NPCID.GolemFistLeft, velocityScaleMin }, - { NPCID.GolemFistRight, velocityScaleMin }, - { NPCID.GolemHead, velocityScaleMin }, - { NPCID.DukeFishron, velocityScaleMin }, - { ModContent.NPCType(), bitingEnemeyVelocityScale }, - { ModContent.NPCType(), velocityScaleMin }, - { ModContent.NPCType(), velocityScaleMin }, - { ModContent.NPCType(), bitingEnemeyVelocityScale }, - { ModContent.NPCType(), velocityScaleMin }, - { ModContent.NPCType(), velocityScaleMin }, - { ModContent.NPCType(), bitingEnemeyVelocityScale }, - { ModContent.NPCType(), velocityScaleMin }, - { ModContent.NPCType(), velocityScaleMin }, - { ModContent.NPCType(), bitingEnemeyVelocityScale }, - { ModContent.NPCType(), velocityScaleMin }, - { ModContent.NPCType(), velocityScaleMin }, - { ModContent.NPCType(), bitingEnemeyVelocityScale }, - { ModContent.NPCType(), velocityScaleMin }, - { ModContent.NPCType(), velocityScaleMin }, - { ModContent.NPCType(), bitingEnemeyVelocityScale }, - { ModContent.NPCType(), velocityScaleMin }, - { ModContent.NPCType(), velocityScaleMin }, - { ModContent.NPCType(), velocityScaleMin }, - { ModContent.NPCType(), velocityScaleMin }, - { ModContent.NPCType(), velocityScaleMin }, - { ModContent.NPCType(), velocityScaleMin }, - { ModContent.NPCType(), velocityScaleMin }, - { ModContent.NPCType(), velocityScaleMin }, - { ModContent.NPCType(), velocityScaleMin }, - { ModContent.NPCType(), velocityScaleMin }, - { ModContent.NPCType(), velocityScaleMin }, - { ModContent.NPCType(), velocityScaleMin }, - { ModContent.NPCType(), bitingEnemeyVelocityScale }, - { ModContent.NPCType(), velocityScaleMin }, - { ModContent.NPCType(), velocityScaleMin }, - { ModContent.NPCType(), velocityScaleMin }, - { ModContent.NPCType(), velocityScaleMin }, - { ModContent.NPCType(), velocityScaleMin }, - { ModContent.NPCType(), velocityScaleMin }, - { ModContent.NPCType(), bitingEnemeyVelocityScale }, - { ModContent.NPCType(), velocityScaleMin }, - { ModContent.NPCType(), velocityScaleMin }, - { ModContent.NPCType(), bitingEnemeyVelocityScale }, - { ModContent.NPCType(), velocityScaleMin }, - { ModContent.NPCType(), velocityScaleMin }, - { ModContent.NPCType(), velocityScaleMin }, - { ModContent.NPCType(), velocityScaleMin }, - { ModContent.NPCType(), velocityScaleMin }, - { ModContent.NPCType(), velocityScaleMin }, - { ModContent.NPCType(), velocityScaleMin }, - { ModContent.NPCType(), velocityScaleMin }, - { ModContent.NPCType(), velocityScaleMin }, - { ModContent.NPCType(), velocityScaleMin }, - { ModContent.NPCType(), velocityScaleMin }, - { ModContent.NPCType(), velocityScaleMin }, - { ModContent.NPCType(), velocityScaleMin }, - { ModContent.NPCType(), velocityScaleMin }, - { ModContent.NPCType(), velocityScaleMin }, - { ModContent.NPCType(), velocityScaleMin }, - { ModContent.NPCType(), velocityScaleMin }, - { ModContent.NPCType(), velocityScaleMin }, - { ModContent.NPCType(), velocityScaleMin }, - { ModContent.NPCType(), velocityScaleMin }, - { ModContent.NPCType(), velocityScaleMin }, - { ModContent.NPCType(), bitingEnemeyVelocityScale }, - { ModContent.NPCType(), velocityScaleMin }, - { ModContent.NPCType(), velocityScaleMin }, - { ModContent.NPCType(), bitingEnemeyVelocityScale }, - { ModContent.NPCType(), velocityScaleMin }, - { ModContent.NPCType(), velocityScaleMin }, - { ModContent.NPCType(), velocityScaleMin }, - { ModContent.NPCType(), velocityScaleMin }, - { ModContent.NPCType(), velocityScaleMin }, - { ModContent.NPCType(), velocityScaleMin }, - { ModContent.NPCType(), bitingEnemeyVelocityScale }, - { ModContent.NPCType(), bitingEnemeyVelocityScale }, - { ModContent.NPCType(), velocityScaleMin }, - { ModContent.NPCType(), bitingEnemeyVelocityScale }, - { ModContent.NPCType(), velocityScaleMin }, - { ModContent.NPCType(), velocityScaleMin }, - { ModContent.NPCType(), bitingEnemeyVelocityScale }, - { ModContent.NPCType(), velocityScaleMin }, - { ModContent.NPCType(), velocityScaleMin }, - { ModContent.NPCType(), bitingEnemeyVelocityScale }, - { ModContent.NPCType(), velocityScaleMin }, - { ModContent.NPCType(), velocityScaleMin }, - { ModContent.NPCType(), velocityScaleMin }, - { ModContent.NPCType(), velocityScaleMin }, - { ModContent.NPCType(), velocityScaleMin }, - { ModContent.NPCType(), velocityScaleMin } - }; - } - #endregion + #region Boss Velocity Contact Damage Scale Values + private void SetupBossVelocityScalingValues() + { + bossVelocityDamageScaleValues = new SortedDictionary { + { NPCID.KingSlime, velocityScaleMin }, + { NPCID.EyeofCthulhu, velocityScaleMin }, // Increases in phase 2 + { NPCID.EaterofWorldsHead, bitingEnemeyVelocityScale }, + { NPCID.EaterofWorldsBody, velocityScaleMin }, + { NPCID.EaterofWorldsTail, velocityScaleMin }, + { NPCID.Creeper, velocityScaleMin }, + { NPCID.BrainofCthulhu, velocityScaleMin }, + { NPCID.QueenBee, velocityScaleMin }, + { NPCID.SkeletronHead, velocityScaleMin }, + { NPCID.SkeletronHand, velocityScaleMin }, + { NPCID.TheHungry, bitingEnemeyVelocityScale }, + { NPCID.TheHungryII, bitingEnemeyVelocityScale }, + { NPCID.LeechHead, bitingEnemeyVelocityScale }, + { NPCID.LeechBody, velocityScaleMin }, + { NPCID.LeechTail, velocityScaleMin }, + { NPCID.Spazmatism, velocityScaleMin }, // Increases in phase 2 + { NPCID.Retinazer, velocityScaleMin }, + { NPCID.TheDestroyer, bitingEnemeyVelocityScale }, + { NPCID.TheDestroyerBody, velocityScaleMin }, + { NPCID.TheDestroyerTail, velocityScaleMin }, + { NPCID.Probe, velocityScaleMin }, + { NPCID.SkeletronPrime, velocityScaleMin }, + { NPCID.PrimeCannon, velocityScaleMin }, + { NPCID.PrimeLaser, velocityScaleMin }, + { NPCID.PrimeSaw, velocityScaleMin }, + { NPCID.PrimeVice, velocityScaleMin }, + { NPCID.Plantera, velocityScaleMin }, // Increases in phase 2 + { NPCID.PlanterasTentacle, bitingEnemeyVelocityScale }, + { NPCID.Golem, velocityScaleMin }, + { NPCID.GolemFistLeft, velocityScaleMin }, + { NPCID.GolemFistRight, velocityScaleMin }, + { NPCID.GolemHead, velocityScaleMin }, + { NPCID.DukeFishron, velocityScaleMin }, + { ModContent.NPCType(), bitingEnemeyVelocityScale }, + { ModContent.NPCType(), velocityScaleMin }, + { ModContent.NPCType(), velocityScaleMin }, + { ModContent.NPCType(), bitingEnemeyVelocityScale }, + { ModContent.NPCType(), velocityScaleMin }, + { ModContent.NPCType(), velocityScaleMin }, + { ModContent.NPCType(), bitingEnemeyVelocityScale }, + { ModContent.NPCType(), velocityScaleMin }, + { ModContent.NPCType(), velocityScaleMin }, + { ModContent.NPCType(), bitingEnemeyVelocityScale }, + { ModContent.NPCType(), velocityScaleMin }, + { ModContent.NPCType(), velocityScaleMin }, + { ModContent.NPCType(), bitingEnemeyVelocityScale }, + { ModContent.NPCType(), velocityScaleMin }, + { ModContent.NPCType(), velocityScaleMin }, + { ModContent.NPCType(), bitingEnemeyVelocityScale }, + { ModContent.NPCType(), velocityScaleMin }, + { ModContent.NPCType(), velocityScaleMin }, + { ModContent.NPCType(), velocityScaleMin }, + { ModContent.NPCType(), velocityScaleMin }, + { ModContent.NPCType(), velocityScaleMin }, + { ModContent.NPCType(), velocityScaleMin }, + { ModContent.NPCType(), velocityScaleMin }, + { ModContent.NPCType(), velocityScaleMin }, + { ModContent.NPCType(), velocityScaleMin }, + { ModContent.NPCType(), velocityScaleMin }, + { ModContent.NPCType(), velocityScaleMin }, + { ModContent.NPCType(), velocityScaleMin }, + { ModContent.NPCType(), bitingEnemeyVelocityScale }, + { ModContent.NPCType(), velocityScaleMin }, + { ModContent.NPCType(), velocityScaleMin }, + { ModContent.NPCType(), velocityScaleMin }, + { ModContent.NPCType(), velocityScaleMin }, + { ModContent.NPCType(), velocityScaleMin }, + { ModContent.NPCType(), velocityScaleMin }, + { ModContent.NPCType(), bitingEnemeyVelocityScale }, + { ModContent.NPCType(), velocityScaleMin }, + { ModContent.NPCType(), velocityScaleMin }, + { ModContent.NPCType(), bitingEnemeyVelocityScale }, + { ModContent.NPCType(), velocityScaleMin }, + { ModContent.NPCType(), velocityScaleMin }, + { ModContent.NPCType(), velocityScaleMin }, + { ModContent.NPCType(), velocityScaleMin }, + { ModContent.NPCType(), velocityScaleMin }, + { ModContent.NPCType(), velocityScaleMin }, + { ModContent.NPCType(), velocityScaleMin }, + { ModContent.NPCType(), velocityScaleMin }, + { ModContent.NPCType(), velocityScaleMin }, + { ModContent.NPCType(), velocityScaleMin }, + { ModContent.NPCType(), velocityScaleMin }, + { ModContent.NPCType(), velocityScaleMin }, + { ModContent.NPCType(), velocityScaleMin }, + { ModContent.NPCType(), velocityScaleMin }, + { ModContent.NPCType(), velocityScaleMin }, + { ModContent.NPCType(), velocityScaleMin }, + { ModContent.NPCType(), velocityScaleMin }, + { ModContent.NPCType(), velocityScaleMin }, + { ModContent.NPCType(), velocityScaleMin }, + { ModContent.NPCType(), velocityScaleMin }, + { ModContent.NPCType(), velocityScaleMin }, + { ModContent.NPCType(), bitingEnemeyVelocityScale }, + { ModContent.NPCType(), velocityScaleMin }, + { ModContent.NPCType(), velocityScaleMin }, + { ModContent.NPCType(), bitingEnemeyVelocityScale }, + { ModContent.NPCType(), velocityScaleMin }, + { ModContent.NPCType(), velocityScaleMin }, + { ModContent.NPCType(), velocityScaleMin }, + { ModContent.NPCType(), velocityScaleMin }, + { ModContent.NPCType(), velocityScaleMin }, + { ModContent.NPCType(), velocityScaleMin }, + { ModContent.NPCType(), bitingEnemeyVelocityScale }, + { ModContent.NPCType(), bitingEnemeyVelocityScale }, + { ModContent.NPCType(), velocityScaleMin }, + { ModContent.NPCType(), bitingEnemeyVelocityScale }, + { ModContent.NPCType(), velocityScaleMin }, + { ModContent.NPCType(), velocityScaleMin }, + { ModContent.NPCType(), bitingEnemeyVelocityScale }, + { ModContent.NPCType(), velocityScaleMin }, + { ModContent.NPCType(), velocityScaleMin }, + { ModContent.NPCType(), bitingEnemeyVelocityScale }, + { ModContent.NPCType(), velocityScaleMin }, + { ModContent.NPCType(), velocityScaleMin }, + { ModContent.NPCType(), velocityScaleMin }, + { ModContent.NPCType(), velocityScaleMin }, + { ModContent.NPCType(), velocityScaleMin }, + { ModContent.NPCType(), velocityScaleMin } + }; + } + #endregion - #region Music - public override void UpdateMusic(ref int music, ref MusicPriority priority) + #region Music + public override void UpdateMusic(ref int music, ref MusicPriority priority) { Mod calamityModMusic = ModLoader.GetMod("CalamityModMusic"); if (Main.musicVolume != 0) @@ -901,8 +901,8 @@ namespace CalamityMod bool acidRain = CalamityWorld.rainingAcid; if (calamityModMusic != null) { - string rainMusic = "Sounds/Music/AcidRain"; - string musicChoice = acidRain ? rainMusic + (CalamityWorld.downedPolterghast ? "2" : "1") : "Sounds/Music/Sulphur"; //replace first acidrain1 once second theme is added. + string rainMusic = "Sounds/Music/AcidRain"; + string musicChoice = acidRain ? rainMusic + (CalamityWorld.downedPolterghast ? "2" : "1") : "Sounds/Music/Sulphur"; //replace first acidrain1 once second theme is added. music = calamityModMusic.GetSoundSlot(SoundType.Music, musicChoice); } @@ -957,7 +957,7 @@ namespace CalamityMod layers.Insert(mouseIndex, new LegacyGameInterfaceLayer("Draedon Factory Tiles", () => { - DraedonsFactoryUI.Draw(Main.spriteBatch); + CellFactoryUI.Draw(Main.spriteBatch); DraedonsItemChargerUI.Draw(Main.spriteBatch); return true; }, InterfaceScaleType.Game)); // InterfaceScaleType.Game tells the game that this UI should take zoom into account. @@ -1478,64 +1478,64 @@ namespace CalamityMod #region Lighting const float MaxCaveDarkness = -0.3f; - const float MaxSignusDarkness = -0.4f; - const float MaxAbyssDarkness = -0.7f; + const float MaxSignusDarkness = -0.4f; + const float MaxAbyssDarkness = -0.7f; public override void ModifyLightingBrightness(ref float scale) { - // Apply the calculated darkness value for the local player. - CalamityPlayer modPlayer = Main.LocalPlayer.Calamity(); - float darkRatio = MathHelper.Clamp(modPlayer.caveDarkness, 0f, 1f); + // Apply the calculated darkness value for the local player. + CalamityPlayer modPlayer = Main.LocalPlayer.Calamity(); + float darkRatio = MathHelper.Clamp(modPlayer.caveDarkness, 0f, 1f); - if (modPlayer.ZoneAbyss) - scale += MaxAbyssDarkness * darkRatio; - else if (CalamityWorld.death) - scale += MaxCaveDarkness * darkRatio; + if (modPlayer.ZoneAbyss) + scale += MaxAbyssDarkness * darkRatio; + else if (CalamityWorld.death) + scale += MaxCaveDarkness * darkRatio; - if (CalamityWorld.revenge) - { - if (CalamityGlobalNPC.signus != -1) - { - if (Main.npc[CalamityGlobalNPC.signus].active) - { - if (Vector2.Distance(Main.LocalPlayer.Center, Main.npc[CalamityGlobalNPC.signus].Center) <= 5200f) - { - float signusLifeRatio = 1f - (Main.npc[CalamityGlobalNPC.signus].life / Main.npc[CalamityGlobalNPC.signus].lifeMax); + if (CalamityWorld.revenge) + { + if (CalamityGlobalNPC.signus != -1) + { + if (Main.npc[CalamityGlobalNPC.signus].active) + { + if (Vector2.Distance(Main.LocalPlayer.Center, Main.npc[CalamityGlobalNPC.signus].Center) <= 5200f) + { + float signusLifeRatio = 1f - (Main.npc[CalamityGlobalNPC.signus].life / Main.npc[CalamityGlobalNPC.signus].lifeMax); - // Reduce the power of Signus darkness based on your light level. - float multiplier = 1f; - switch (modPlayer.GetTotalLightStrength()) - { - case 0: - break; - case 1: - case 2: - multiplier = 0.75f; - break; - case 3: - case 4: - multiplier = 0.5f; - break; - case 5: - case 6: - multiplier = 0.25f; - break; - default: - multiplier = 0f; - break; - } + // Reduce the power of Signus darkness based on your light level. + float multiplier = 1f; + switch (modPlayer.GetTotalLightStrength()) + { + case 0: + break; + case 1: + case 2: + multiplier = 0.75f; + break; + case 3: + case 4: + multiplier = 0.5f; + break; + case 5: + case 6: + multiplier = 0.25f; + break; + default: + multiplier = 0f; + break; + } - // Increased darkness in Death Mode - if (CalamityWorld.death) - multiplier += (1f - multiplier) * 0.1f; + // Increased darkness in Death Mode + if (CalamityWorld.death) + multiplier += (1f - multiplier) * 0.1f; - // Total darkness - float signusDarkness = signusLifeRatio * multiplier; - darkRatio = MathHelper.Clamp(signusDarkness, 0f, 1f); - scale += MaxSignusDarkness * darkRatio; - } - } - } - } + // Total darkness + float signusDarkness = signusLifeRatio * multiplier; + darkRatio = MathHelper.Clamp(signusDarkness, 0f, 1f); + scale += MaxSignusDarkness * darkRatio; + } + } + } + } } #endregion @@ -1548,7 +1548,15 @@ namespace CalamityMod CalamityNetcode.SyncWorld(); } #endregion - } + + #region Netcode + public override void HandlePacket(BinaryReader reader, int whoAmI) => CalamityNetcode.HandlePacket(reader, whoAmI); + #endregion + + #region Tile Entity Time Handler + public override void MidUpdateTimeWorld() => TileEntityTimeHandler.Update(); + #endregion + } public enum Season : byte { diff --git a/CalamityNetcode.cs b/CalamityNetcode.cs index 10b3880ab6..d60439f061 100644 --- a/CalamityNetcode.cs +++ b/CalamityNetcode.cs @@ -147,8 +147,8 @@ namespace CalamityMod if (Main.netMode != NetmodeID.MultiplayerClient) NPC.NewNPC(x, y, ModContent.NPCType()); break; - case CalamityModMessageType.DraedonGeneratorStackSync: - (TileEntity.ByID[reader.ReadInt32()] as TEDraedonFuelFactory).HeldItem.stack = reader.ReadInt32(); + case CalamityModMessageType.PowerCellFactory: + TEPowerCellFactory.ReadSyncPacket(reader); break; case CalamityModMessageType.DraedonChargerSync: int entityID = reader.ReadInt32(); @@ -230,8 +230,8 @@ namespace CalamityMod BossRushStage, DoGCountdownSync, BossSpawnCountdownSync, - BRHostileProjKillSync, - ArmoredDiggerCountdownSync, + BRHostileProjKillSync, + ArmoredDiggerCountdownSync, BossTypeSync, DeathCountSync, RevengeanceBoolSync, @@ -241,18 +241,18 @@ namespace CalamityMod ArmageddonBoolSync, DemonTrophyBoolSync, NPCRegenerationSync, - DeathModeUnderworldTimeSync, - DeathModeBlizzardTimeSync, - DeathBossSpawnCountdownSync, + DeathModeUnderworldTimeSync, + DeathModeBlizzardTimeSync, + DeathBossSpawnCountdownSync, AcidRainSync, AcidRainUIDrawFadeSync, AcidRainOldDukeSummonSync, GaelsGreatswordSwingSync, SpawnSuperDummy, - SyncCalamityNPCAIArray, + SyncCalamityNPCAIArray, ProvidenceDyeConditionSync, // We shouldn't fucking need this. Die in a hole, Multiplayer. PSCChallengeSync, // See above - DraedonGeneratorStackSync, + PowerCellFactory, DraedonChargerSync, DraedonFieldGeneratorSync } diff --git a/ExtraTextures/UI/DraedonFuelCellUISlot.png b/ExtraTextures/UI/CellFactoryItemSlot_Empty.png similarity index 100% rename from ExtraTextures/UI/DraedonFuelCellUISlot.png rename to ExtraTextures/UI/CellFactoryItemSlot_Empty.png diff --git a/ExtraTextures/UI/DraedonFuelCellUISlotFilled.png b/ExtraTextures/UI/CellFactoryItemSlot_Filled.png similarity index 100% rename from ExtraTextures/UI/DraedonFuelCellUISlotFilled.png rename to ExtraTextures/UI/CellFactoryItemSlot_Filled.png diff --git a/Items/Placeables/DraedonsFuelFactoryItem.cs b/Items/Placeables/PowerCellFactoryItem.cs similarity index 72% rename from Items/Placeables/DraedonsFuelFactoryItem.cs rename to Items/Placeables/PowerCellFactoryItem.cs index 2a8b73d3a9..ebc4d0bd4d 100644 --- a/Items/Placeables/DraedonsFuelFactoryItem.cs +++ b/Items/Placeables/PowerCellFactoryItem.cs @@ -5,12 +5,12 @@ using Terraria.ModLoader; namespace CalamityMod.Items.Placeables { - public class DraedonsFuelFactoryItem : ModItem + public class PowerCellFactoryItem : ModItem { public override void SetStaticDefaults() { - DisplayName.SetDefault("Draedon's Fuel Factory"); - Tooltip.SetDefault("Produces Draedon Power Cells over time"); + DisplayName.SetDefault("Power Cell Factory"); + Tooltip.SetDefault("Produces Draedon Power Cells over time\n" + "One cell is produced every 15 seconds"); } public override void SetDefaults() @@ -23,11 +23,11 @@ namespace CalamityMod.Items.Placeables item.useAnimation = item.useTime = 15; item.useStyle = ItemUseStyleID.SwingThrow; item.consumable = true; - item.createTile = ModContent.TileType(); + item.createTile = ModContent.TileType(); item.rare = ItemRarityID.Red; item.Calamity().customRarity = CalamityRarity.DraedonRust; - //item.value = Item.buyPrice(gold: 5); + item.value = Item.buyPrice(gold: 50); } } } diff --git a/Items/Placeables/DraedonsFuelFactoryItem.png b/Items/Placeables/PowerCellFactoryItem.png similarity index 100% rename from Items/Placeables/DraedonsFuelFactoryItem.png rename to Items/Placeables/PowerCellFactoryItem.png diff --git a/Items/Weapons/Ranged/Auralis.cs b/Items/Weapons/Ranged/Auralis.cs new file mode 100644 index 0000000000..8f29ddde43 --- /dev/null +++ b/Items/Weapons/Ranged/Auralis.cs @@ -0,0 +1,85 @@ +using CalamityMod.Items.Materials; +using CalamityMod.Items.Potions; +using CalamityMod.Projectiles.Ranged; +using Microsoft.Xna.Framework; +using Microsoft.Xna.Framework.Graphics; +using Terraria; +using Terraria.ID; +using Terraria.ModLoader; + +namespace CalamityMod.Items.Weapons.Ranged +{ + public class Auralis : ModItem + { + public static readonly Color blueColor = new Color(0, 77, 255); + public static readonly Color greenColor = new Color(0, 255, 77); + + public override void SetStaticDefaults() + { + DisplayName.SetDefault("Auralis"); + Tooltip.SetDefault("Fires a high speed glowing bullet that inflicts debilitating debuffs\n" + + "Right click to zoom out\n" + + "Standing still provides increasing damage bonuses up to 25%\n" + + "Standing still for 5 or more seconds while using the scope ability will summon an aurora\n" + + "The aurora reduces the damage of the next projectile hit by a flat 100\n" + + "This effect lasts up to 20 seconds and has a 30 second cooldown\n" + + "50% chance to not consume bullets"); + } + + public override void SetDefaults() + { + item.damage = 650; + item.ranged = true; + item.useTime = item.useAnimation = 30; + item.knockBack = 10f; + item.autoReuse = true; + item.shoot = ModContent.ProjectileType(); + item.shootSpeed = 7.5f; + item.useAmmo = AmmoID.Bullet; + + item.width = 96; + item.height = 34; + item.useStyle = ItemUseStyleID.HoldingOut; + item.noMelee = true; + item.UseSound = mod.GetLegacySoundSlot(SoundType.Item, "Sounds/Item/PlasmaBlast"); + item.value = CalamityGlobalItem.Rarity13BuyPrice; + item.rare = 10; + item.Calamity().customRarity = CalamityRarity.Dedicated; + } + + public override void ModifyWeaponDamage(Player player, ref float add, ref float mult, ref float flat) + { + float damageMult = MathHelper.Lerp(0f, 0.25f, player.Calamity().auralisStealthCounter / 300f); + add += damageMult; + } + + public override bool Shoot(Player player, ref Vector2 position, ref float speedX, ref float speedY, ref int type, ref int damage, ref float knockBack) + { + Projectile.NewProjectile(position, new Vector2(speedX, speedY), item.shoot, damage, knockBack, player.whoAmI); + return false; + } + + public override void PostDrawInWorld(SpriteBatch spriteBatch, Color lightColor, Color alphaColor, float rotation, float scale, int whoAmI) + { + Texture2D glowmask = ModContent.GetTexture("CalamityMod/Items/Weapons/Ranged/AuralisGlow"); + Vector2 origin = new Vector2(glowmask.Width / 2f, glowmask.Height / 2f - 2f); + spriteBatch.Draw(glowmask, item.Center - Main.screenPosition, null, Color.White, rotation, origin, 1f, SpriteEffects.None, 0f); + } + + public override Vector2? HoldoutOffset() => new Vector2(-10, 0); + + public override bool ConsumeAmmo(Player player) => Main.rand.Next(100) >= 50; + + public override void AddRecipes() + { + ModRecipe recipe = new ModRecipe(mod); + recipe.AddIngredient(ModContent.ItemType(), 5); + recipe.AddIngredient(ModContent.ItemType(), 5); + recipe.AddIngredient(ModContent.ItemType(), 50); + recipe.AddIngredient(ItemID.SniperRifle); + recipe.AddTile(TileID.LunarCraftingStation); + recipe.SetResult(this); + recipe.AddRecipe(); + } + } +} diff --git a/Items/Weapons/Ranged/Auralis.png b/Items/Weapons/Ranged/Auralis.png new file mode 100644 index 0000000000..88f823e30a Binary files /dev/null and b/Items/Weapons/Ranged/Auralis.png differ diff --git a/Items/Weapons/Ranged/AuralisGlow.png b/Items/Weapons/Ranged/AuralisGlow.png new file mode 100644 index 0000000000..8abfbe742e Binary files /dev/null and b/Items/Weapons/Ranged/AuralisGlow.png differ diff --git a/Items/Weapons/Ranged/AuroraBlazer.cs b/Items/Weapons/Ranged/AuroraBlazer.cs index 6d6583af85..d772a1b0fc 100644 --- a/Items/Weapons/Ranged/AuroraBlazer.cs +++ b/Items/Weapons/Ranged/AuroraBlazer.cs @@ -30,7 +30,7 @@ namespace CalamityMod.Items.Weapons.Ranged item.width = 68; item.height = 36; - item.useStyle = 5; + item.useStyle = ItemUseStyleID.HoldingOut; item.noMelee = true; item.UseSound = SoundID.Item34; item.value = CalamityGlobalItem.Rarity7BuyPrice; diff --git a/Projectiles/Magic/ThunderstormShot.cs b/Projectiles/Magic/ThunderstormShot.cs index b72603d63b..5d197669c0 100644 --- a/Projectiles/Magic/ThunderstormShot.cs +++ b/Projectiles/Magic/ThunderstormShot.cs @@ -47,26 +47,12 @@ namespace CalamityMod.Projectiles.Magic public override void Kill(int timeLeft) { - Main.PlaySound(SoundID.Item125, projectile.position); + Main.PlaySound(SoundID.Item125, projectile.Center); for (int n = 0; n < 5; n++) { - float x = projectile.position.X + (float)Main.rand.Next(-200, 200); - float y = projectile.position.Y - 1500f; - Vector2 vector = new Vector2(x, y); - float num13 = projectile.position.X + (float)(projectile.width / 2) - vector.X; - float num14 = projectile.position.Y + (float)(projectile.height / 2) - vector.Y; - num13 += (float)Main.rand.Next(-100, 101); - int num15 = 29; - float num16 = (float)Math.Sqrt((double)(num13 * num13 + num14 * num14)); - num16 = (float)num15 / num16; - num13 *= num16; - num14 *= num16; - Projectile.NewProjectile(x, y, num13, num14, ModContent.ProjectileType(), projectile.damage, projectile.knockBack, projectile.owner, 0f, 0f); + CalamityUtils.ProjectileRain(projectile.Center, 200f, 100f, 1500f, 1500f, 29f, ModContent.ProjectileType(), projectile.damage, projectile.knockBack, projectile.owner, projectile.owner); } - projectile.position = projectile.Center; - projectile.width = projectile.height = 36; - projectile.position.X = projectile.position.X - (float)(projectile.width / 2); - projectile.position.Y = projectile.position.Y - (float)(projectile.height / 2); + CalamityGlobalProjectile.ExpandHitboxBy(projectile, 36); int num226 = 36; for (int num227 = 0; num227 < num226; num227++) { @@ -88,6 +74,8 @@ namespace CalamityMod.Projectiles.Magic Main.dust[num228].noLight = true; Main.dust[num228].velocity = vector7; } + projectile.usesLocalNPCImmunity = true; + projectile.localNPCHitCooldown = 10; projectile.Damage(); } } diff --git a/Projectiles/Ranged/AuralisBullet.cs b/Projectiles/Ranged/AuralisBullet.cs new file mode 100644 index 0000000000..8d2362aff0 --- /dev/null +++ b/Projectiles/Ranged/AuralisBullet.cs @@ -0,0 +1,64 @@ +using CalamityMod.Buffs.StatDebuffs; +using CalamityMod.Items.Weapons.Ranged; +using Microsoft.Xna.Framework; +using Terraria; +using Terraria.ID; +using Terraria.ModLoader; +namespace CalamityMod.Projectiles.Ranged +{ + public class AuralisBullet : ModProjectile + { + public override void SetStaticDefaults() + { + DisplayName.SetDefault("Bullet"); + } + + public override void SetDefaults() + { + projectile.width = 4; + projectile.height = 4; + projectile.friendly = true; + projectile.ranged = true; + projectile.penetrate = 5; + projectile.alpha = 255; + projectile.timeLeft = 200; + projectile.extraUpdates = 10; + projectile.usesLocalNPCImmunity = true; + projectile.localNPCHitCooldown = 10; + } + + public override void AI() + { + projectile.ai[0] += 1f; + if (projectile.ai[0] > 6f) + { + for (int d = 0; d < 5; d++) + { + Dust dust = Main.dust[Dust.NewDust(projectile.position, projectile.width, projectile.height, 229, projectile.velocity.X, projectile.velocity.Y, 100, CalamityUtils.ColorSwap(Auralis.blueColor, Auralis.greenColor, 1f), 1f)]; + dust.velocity = Vector2.Zero; + dust.position -= projectile.velocity / 5f * d; + dust.noGravity = true; + dust.scale = 0.65f; + dust.noLight = true; + dust.color = CalamityUtils.ColorSwap(Auralis.blueColor, Auralis.greenColor, 1f); + } + } + } + + public override void OnHitNPC(NPC target, int damage, float knockback, bool crit) + { + int duration = 600; + target.AddBuff(ModContent.BuffType(), duration); + target.AddBuff(BuffID.Ichor, duration); + target.AddBuff(BuffID.CursedInferno, duration); + } + + public override void OnHitPvp(Player target, int damage, bool crit) + { + int duration = 600; + target.AddBuff(ModContent.BuffType(), duration); + target.AddBuff(BuffID.Ichor, duration); + target.AddBuff(BuffID.CursedInferno, duration); + } + } +} diff --git a/Projectiles/Ranged/AuralisBullet.png b/Projectiles/Ranged/AuralisBullet.png new file mode 100644 index 0000000000..0056fc1e24 Binary files /dev/null and b/Projectiles/Ranged/AuralisBullet.png differ diff --git a/TileEntities/TEDraedonFuelFactory.cs b/TileEntities/TEDraedonFuelFactory.cs deleted file mode 100644 index 40436191fc..0000000000 --- a/TileEntities/TEDraedonFuelFactory.cs +++ /dev/null @@ -1,118 +0,0 @@ -using CalamityMod.Items.DraedonMisc; -using CalamityMod.Tiles; -using System.IO; -using Terraria; -using Terraria.ID; -using Terraria.ModLoader; -using Terraria.ModLoader.IO; - -namespace CalamityMod.TileEntities -{ - public class TEDraedonFuelFactory : ModTileEntity - { - public int Time = 0; - public Item HeldItem = new Item(); - - public void ClientToServerSync() - { - if (Main.netMode != NetmodeID.SinglePlayer) - { - var netMessage = CalamityMod.Instance.GetPacket(); - netMessage.Write((byte)CalamityModMessageType.DraedonGeneratorStackSync); - netMessage.Write(ID); - netMessage.Write(HeldItem.type); - netMessage.Write(HeldItem.stack); - netMessage.Send(); - } - } - - public override bool ValidTile(int i, int j) - { - Tile tile = Main.tile[i, j]; - return tile.active() && tile.type == ModContent.TileType() && tile.frameX == 0 && tile.frameY == 0; - } - - public override void Update() - { - if (HeldItem is null || HeldItem.type != ModContent.ItemType()) - { - HeldItem = new Item(); - HeldItem.SetDefaults(ModContent.ItemType()); - HeldItem.stack = 0; - } - HeldItem.favorited = false; - Time++; - // Sometimes the item gets fucked up and it gets a maxStack of 0. Using it as a max can be unreliable as a result. - bool rightTimeToMakeCell = Time % 5 == 4 && Main.tileFrame[Main.tile[Position.X, Position.Y].type] == 43; - if (Main.netMode == NetmodeID.Server) - rightTimeToMakeCell = Time % (DraedonFuelFactory.CellCreationDelay + DraedonFuelFactory.TotalFrames * 5 + 5) == (DraedonFuelFactory.CellCreationDelay + DraedonFuelFactory.TotalFrames * 5 + 4); - if (HeldItem.stack < 999 && rightTimeToMakeCell) - { - HeldItem.stack++; - - // Forcibly sync the tile entity whenever a cell is made. - ClientToServerSync(); - } - } - - // If this factory breaks, anyone who's viewing it is no longer viewing it. - public override void OnKill() - { - for (int i = 0; i < Main.player.Length; i++) - { - if (Main.player[i].Calamity().CurrentlyViewedFactory == this) - Main.player[i].Calamity().CurrentlyViewedFactory = null; - } - base.OnKill(); - } - - public override int Hook_AfterPlacement(int i, int j, int type, int style, int direction) - { - if (Main.netMode == NetmodeID.MultiplayerClient) - { - NetMessage.SendTileSquare(Main.myPlayer, i, j, 5); - NetMessage.SendData(MessageID.TileEntityPlacement, -1, -1, null, i, j, Type, 0f, 0, 0, 0); - return -1; - } - return Place(i, j); - } - - public override TagCompound Save() - { - TagCompound tag = new TagCompound - { - ["Stack"] = HeldItem.stack, - ["Prefix"] = HeldItem.prefix, - }; - CalamityUtils.SaveModItem(tag, HeldItem); - return tag; - } - - public override void Load(TagCompound tag) - { - HeldItem = CalamityUtils.LoadModItem(tag); - HeldItem.stack = tag.GetInt("Stack"); - HeldItem.prefix = tag.GetByte("Prefix"); - } - - public override void NetSend(BinaryWriter writer, bool lightSend) - { - writer.Write(Time); - writer.Write(HeldItem.type); - writer.Write(HeldItem.stack); - writer.Write(HeldItem.prefix); - } - - public override void NetReceive(BinaryReader reader, bool lightReceive) - { - Time = reader.ReadInt32(); - HeldItem = new Item - { - type = reader.ReadInt32() - }; - HeldItem.SetDefaults(HeldItem.type); - HeldItem.stack = reader.ReadInt32(); - HeldItem.prefix = reader.ReadByte(); - } - } -} diff --git a/TileEntities/TEPowerCellFactory.cs b/TileEntities/TEPowerCellFactory.cs new file mode 100644 index 0000000000..a6d6bd8a07 --- /dev/null +++ b/TileEntities/TEPowerCellFactory.cs @@ -0,0 +1,182 @@ +using CalamityMod.CalPlayer; +using CalamityMod.Tiles; +using System.IO; +using System.Reflection; +using Terraria; +using Terraria.DataStructures; +using Terraria.ID; +using Terraria.ModLoader; +using Terraria.ModLoader.IO; + +namespace CalamityMod.TileEntities +{ + public class TEPowerCellFactory : ModTileEntity + { + public long Time = 0; + private short _stack = 0; + public short CellStack + { + get => _stack; + set + { + _stack = value; + SendSyncPacket(); + } + } + + private long CycleFrameCounter + { + get + { + long totalCycleTime = PowerCellFactory.BetweenCellDowntime + PowerCellFactory.TotalFrames * PowerCellFactory.AnimationFramerate; + return Time % totalCycleTime; + } + } + + private bool IsCellFrame + { + get + { + long magicFrame = PowerCellFactory.BetweenCellDowntime + PowerCellFactory.CellCreateFrame * PowerCellFactory.AnimationFramerate + PowerCellFactory.MagicFrameDelay; + return CycleFrameCounter == magicFrame; + } + } + + // Property which allows anyone to get the current animation frame of this specific factory. + public int AnimationFrame + { + get + { + int f = (int)CycleFrameCounter; + + // The animation sticks on the last frame throughout the entire downtime period. + if (f < PowerCellFactory.BetweenCellDowntime) + return PowerCellFactory.TotalFrames - 1; + + // Remove the starting downtime period for the framerate divisor calculation. + return (f - PowerCellFactory.BetweenCellDowntime) / PowerCellFactory.AnimationFramerate; + } + } + + // This guarantees that this tile entity will not persist if not placed directly on the top left corner of a Power Cell Factory tile. + public override bool ValidTile(int i, int j) + { + Tile tile = Main.tile[i, j]; + return tile.active() && tile.type == ModContent.TileType() && tile.frameX == 0 && tile.frameY == 0; + } + + public override void Update() + { + ++Time; + if (IsCellFrame && CellStack < 999) + // The property setter will automatically send the necessary packet. + CellStack++; + } + + // This code is called as a hook when the player places the Power Cell Factory tile so that the tile entity may be placed. + public override int Hook_AfterPlacement(int i, int j, int type, int style, int direction) + { + // If in multiplayer, tell the server to place the tile entity and DO NOT place it yourself. That will mismatch IDs. + // Also tell the server that you placed the 4x4 tiles that make up the Power Cell Factory. + if (Main.netMode == NetmodeID.MultiplayerClient) + { + NetMessage.SendTileRange(Main.myPlayer, i, j, PowerCellFactory.Width, PowerCellFactory.Height); + NetMessage.SendData(MessageID.TileEntityPlacement, -1, -1, null, i, j, Type); + return -1; + } + + // If in single player, just place the tile entity, no problems. + int id = Place(i, j); + return id; + } + + // This code is called on dedicated servers only. It is the server-side response to MessageID.TileEntityPlacement. + // When the server receives such a message from a client, it sends a MessageID.TileEntitySharing to all clients. + // This will cause them to Place the tile entity locally at that position, all with exactly the same ID. + public override void OnNetPlace() => NetMessage.SendData(MessageID.TileEntitySharing, -1, -1, null, ID, Position.X, Position.Y); + + // If this factory breaks, anyone who's viewing it is no longer viewing it. + public override void OnKill() + { + for (int i = 0; i < Main.maxPlayers; i++) + { + Player p = Main.player[i]; + if (!p.active) + continue; + + // Use reflection to stop TML from spitting an error here. + // Try-catching will not stop this error, TML will print it to console anyway. The error is harmless. + ModPlayer[] mpStorageArray = (ModPlayer[])typeof(Player).GetField("modPlayers", BindingFlags.Instance | BindingFlags.NonPublic).GetValue(p); + if (mpStorageArray.Length == 0) + continue; + + CalamityPlayer mp = p.Calamity(); + TEPowerCellFactory factory = mp.CurrentlyViewedFactory; + if (factory is null) + continue; + if (factory.ID == ID) + { + mp.CurrentlyViewedFactory = null; + mp.CurrentlyViewedFactoryX = -1; + mp.CurrentlyViewedFactoryY = -1; + } + } + } + + public override TagCompound Save() => new TagCompound + { + { "time", Time }, + { "cells", _stack } + }; + + public override void Load(TagCompound tag) + { + Time = tag.GetLong("time"); + _stack = tag.GetShort("cells"); + } + + public override void NetSend(BinaryWriter writer, bool lightSend) + { + writer.Write(Time); + writer.Write(_stack); + } + + public override void NetReceive(BinaryReader reader, bool lightReceive) + { + Time = reader.ReadInt64(); + _stack = reader.ReadInt16(); + } + + private void SendSyncPacket() + { + if (Main.netMode == NetmodeID.SinglePlayer) + return; + var netMessage = mod.GetPacket(); + netMessage.Write((byte)CalamityModMessageType.PowerCellFactory); + netMessage.Write(ID); + netMessage.Write(Time); + netMessage.Write(_stack); + netMessage.Send(); + } + + internal static bool ReadSyncPacket(BinaryReader reader) + { + int teID = reader.ReadInt32(); + bool exists = ByID.TryGetValue(teID, out TileEntity te); + + // The rest of the packet must be read even if it turns out the factory doesn't exist for whatever reason. + long time = reader.ReadInt64(); + short cellStack = reader.ReadInt16(); + + if (exists && te is TEPowerCellFactory factory) + { + // Only clients update their timer from this packet. When a server receives this packet it ignores the time variable. + if (Main.netMode == NetmodeID.MultiplayerClient) + factory.Time = time; + factory._stack = cellStack; + return true; + } + return false; + } + } +} diff --git a/TileEntities/TileEntityTimeHandler.cs b/TileEntities/TileEntityTimeHandler.cs new file mode 100644 index 0000000000..9b8031ad7b --- /dev/null +++ b/TileEntities/TileEntityTimeHandler.cs @@ -0,0 +1,31 @@ +using Terraria; +using Terraria.DataStructures; +using Terraria.ID; +using Terraria.ModLoader; + +namespace CalamityMod.TileEntities +{ + public static class TileEntityTimeHandler + { + public static void Update() + { + // Specifically on multiplayer clients, manually update the time variables of Power Cell Factories every frame. + // This makes sure they animate. It will NOT produce cells; that code can only run server side. + // Time is manually synced from the server every time a cell is created, so even under heavy lag they cannot stay desynced indefinitely. + if (Main.netMode == NetmodeID.MultiplayerClient) + { + byte factoryType = ModContent.GetInstance().type; + var enumerator = TileEntity.ByID.Values.GetEnumerator(); + do + { + TileEntity te = enumerator.Current; + if (te != null && te.type == factoryType) + { + TEPowerCellFactory factory = (TEPowerCellFactory)te; + ++factory.Time; + } + } while (enumerator.MoveNext()); + } + } + } +} diff --git a/Tiles/DraedonFuelFactory.cs b/Tiles/DraedonFuelFactory.cs deleted file mode 100644 index 1556e238eb..0000000000 --- a/Tiles/DraedonFuelFactory.cs +++ /dev/null @@ -1,172 +0,0 @@ -using CalamityMod.Items.Placeables; -using CalamityMod.TileEntities; -using Microsoft.Xna.Framework; -using Microsoft.Xna.Framework.Graphics; -using System.Linq; -using Terraria; -using Terraria.DataStructures; -using Terraria.Enums; -using Terraria.ID; -using Terraria.ModLoader; -using Terraria.ObjectData; - -namespace CalamityMod.Tiles -{ - public class DraedonFuelFactory : ModTile - { - public const int Width = 4; - public const int Height = 4; - public const int CellCreationDelay = 600; - public const int TotalFrames = 45; - public override void SetDefaults() - { - Main.tileLighted[Type] = true; - Main.tileFrameImportant[Type] = true; - Main.tileNoAttach[Type] = true; - Main.tileLavaDeath[Type] = false; - Main.tileWaterDeath[Type] = false; - TileObjectData.newTile.CopyFrom(TileObjectData.Style3x2); - TileObjectData.newTile.Width = 4; - TileObjectData.newTile.Height = 4; - TileObjectData.newTile.Origin = new Point16(0, 3); - TileObjectData.newTile.AnchorBottom = new AnchorData(AnchorType.SolidTile | AnchorType.SolidWithTop | AnchorType.SolidSide, TileObjectData.newTile.Width, 0); - TileObjectData.newTile.CoordinateHeights = new int[] { 16, 16, 16, 16 }; - TileObjectData.newTile.HookPostPlaceMyPlayer = new PlacementHook(ModContent.GetInstance().Hook_AfterPlacement, -1, 0, true); - TileObjectData.newTile.LavaDeath = false; - TileObjectData.addTile(Type); - ModTranslation name = CreateMapEntryName(); - name.SetDefault("Fuel Factory"); - AddMapEntry(new Color(67, 72, 81), name); - animationFrameHeight = 68; - } - - public override bool CanExplode(int i, int j) => false; - - public TEDraedonFuelFactory RetrieveTileEntity(int i, int j) - { - // This is very fucking important. ByID and ByPostion can apparently be different and as a result using both together is fucking unreliable. - int left = i - Main.tile[i, j].frameX % (Width * 18) / 18; - int top = j - Main.tile[i, j].frameY % (Height * 18) / 18; - if (!TileEntity.ByID.Any(tileEntity => tileEntity.Value.Position == new Point16(left, top))) - { - var factory = ModTileEntity.ConstructFromType(ModContent.TileEntityType()); - factory.Position = new Point16(left, top); - TileEntity.ByID[TileEntity.ByID.Count] = factory; - } - return (TEDraedonFuelFactory)TileEntity.ByID.Where(tileEntity => tileEntity.Value.Position == new Point16(left, top)).First().Value; - } - - 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() => 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(i * 16, j * 16, 32, 32, ModContent.ItemType()); - int left = i - Main.tile[i, j].frameX % (Width * 18) / 18; - int top = j - Main.tile[i, j].frameY % (Height * 18) / 18; - - TEDraedonFuelFactory factory = RetrieveTileEntity(i, j); - if (factory.HeldItem.stack > 0) - { - Item.NewItem(new Vector2(i, j) * 16f, factory.HeldItem.type, factory.HeldItem.stack); - } - factory.Kill(left, top); - } - - public override void AnimateTile(ref int frame, ref int frameCounter) - { - frameCounter++; - - // After CellCreationDelay frames, start the fuel cell generation animation, and make one at the end. - // Otherwise, just continue waiting. - if (frameCounter % (CellCreationDelay + TotalFrames * 5 + 5) >= CellCreationDelay) - { - if (frameCounter % 5 == 4) - { - frame++; - if (frame >= TotalFrames) - { - frame = 0; - } - } - } - else - { - frame = TotalFrames - 1; - } - } - - public override bool NewRightClick(int i, int j) - { - int left = i - Main.tile[i, j].frameX % (Width * 18) / 18; - int top = j - Main.tile[i, j].frameY % (Height * 18) / 18; - - Player player = Main.LocalPlayer; - TEDraedonFuelFactory factory = RetrieveTileEntity(i, j); - Main.mouseRightRelease = false; - - if (player.sign >= 0) - { - Main.PlaySound(SoundID.MenuClose); - player.sign = -1; - Main.editSign = false; - Main.npcChatText = ""; - } - if (Main.editChest) - { - Main.PlaySound(SoundID.MenuTick); - Main.editChest = false; - Main.npcChatText = ""; - } - if (player.Calamity().CurrentlyViewedFactory == factory) - { - player.Calamity().CurrentlyViewedFactory = null; - player.Calamity().CurrentlyViewedFactoryX = player.Calamity().CurrentlyViewedFactoryY = -1; - Main.PlaySound(SoundID.MenuClose); - } - else - { - // Ensure that the UI position is always centered and above the tile. - player.Calamity().CurrentlyViewedFactoryX = left * 16 + 16; - player.Calamity().CurrentlyViewedFactoryY = top * 16; - - player.Calamity().CurrentlyViewedFactory = factory; - - Main.playerInventory = true; - Main.recBigList = false; - Main.PlaySound(player.Calamity().CurrentlyViewedFactory == null ? SoundID.MenuOpen : SoundID.MenuTick); - } - - Recipe.FindRecipes(); - return true; - } - public override bool PreDraw(int i, int j, SpriteBatch spriteBatch) - { - Tile trackTile = Main.tile[i, j]; - int xPos = Main.tile[i, j].frameX; - int yPos = Main.tile[i, j].frameY; - xPos += Main.tileFrame[trackTile.type] / 15 * 72; - yPos += Main.tileFrame[trackTile.type] % 15 * 72; - Texture2D glowmask = ModContent.GetTexture("CalamityMod/Tiles/DraedonFuelFactory"); - Vector2 offset = Main.drawToScreen ? Vector2.Zero : new Vector2(Main.offScreenRange); - Vector2 drawOffset = new Vector2(i * 16 - Main.screenPosition.X, j * 16 - Main.screenPosition.Y) + offset; - Color drawColor = Lighting.GetColor(i, j); - - if (!trackTile.halfBrick() && trackTile.slope() == 0) - spriteBatch.Draw(glowmask, drawOffset, new Rectangle(xPos, yPos, 16, 16), drawColor, 0.0f, Vector2.Zero, 1f, SpriteEffects.None, 0.0f); - else if (trackTile.halfBrick()) - spriteBatch.Draw(glowmask, drawOffset + Vector2.UnitY * 8f, new Rectangle(xPos, yPos, 16, 16), drawColor, 0.0f, Vector2.Zero, 1f, SpriteEffects.None, 0.0f); - return false; - } - } -} diff --git a/Tiles/InactiveDraedonFuelFactory.cs b/Tiles/InactiveDraedonFuelFactory.cs index 4bc88085ea..c81c36d3ae 100644 --- a/Tiles/InactiveDraedonFuelFactory.cs +++ b/Tiles/InactiveDraedonFuelFactory.cs @@ -47,7 +47,7 @@ namespace CalamityMod.Tiles public override void KillMultiTile(int i, int j, int frameX, int frameY) { - Item.NewItem(i * 16, j * 16, 32, 32, ModContent.ItemType()); + Item.NewItem(i * 16, j * 16, 32, 32, ModContent.ItemType()); } } } diff --git a/Tiles/PowerCellFactory.cs b/Tiles/PowerCellFactory.cs new file mode 100644 index 0000000000..50c9ea4e8d --- /dev/null +++ b/Tiles/PowerCellFactory.cs @@ -0,0 +1,190 @@ +using CalamityMod.CalPlayer; +using CalamityMod.Items.DraedonMisc; +using CalamityMod.Items.Placeables; +using CalamityMod.TileEntities; +using Microsoft.Xna.Framework; +using Microsoft.Xna.Framework.Graphics; +using Terraria; +using Terraria.DataStructures; +using Terraria.Enums; +using Terraria.ID; +using Terraria.ModLoader; +using Terraria.ObjectData; + +namespace CalamityMod.Tiles +{ + public class PowerCellFactory : ModTile + { + public const int Width = 4; + public const int Height = 4; + public const int OriginOffsetX = 1; + public const int OriginOffsetY = 3; + + // The number of animation frames is 45. Cells are created on animation frame 42. + public const int TotalFrames = 45; + private const int FramesPerColumn = 15; + public const int AnimationFramerate = 5; + + // 45 * 5 + 675 = 900 = 15 seconds per complete cell cycle. + // There are this many frames of downtime between cell creations. + public const int BetweenCellDowntime = 675; + // The cell is created on this animation frame. + public const int CellCreateFrame = 42; + // With a delay of this many extra frames after that animation frame starts. + public const int MagicFrameDelay = AnimationFramerate - 1; + + public override void SetDefaults() + { + Main.tileLighted[Type] = true; + Main.tileFrameImportant[Type] = true; + Main.tileNoAttach[Type] = true; + Main.tileLavaDeath[Type] = false; + Main.tileWaterDeath[Type] = false; + TileObjectData.newTile.CopyFrom(TileObjectData.Style3x2); + TileObjectData.newTile.Width = 4; + TileObjectData.newTile.Height = 4; + TileObjectData.newTile.Origin = new Point16(OriginOffsetX, OriginOffsetY); + TileObjectData.newTile.AnchorBottom = new AnchorData(AnchorType.SolidTile | AnchorType.SolidWithTop | AnchorType.SolidSide, TileObjectData.newTile.Width, 0); + TileObjectData.newTile.CoordinateHeights = new int[] { 16, 16, 16, 16 }; + TileObjectData.newTile.LavaDeath = false; + + // When this tile is placed, it places the power cell factory tile entity. + ModTileEntity te = ModContent.GetInstance(); + TileObjectData.newTile.HookPostPlaceMyPlayer = new PlacementHook(te.Hook_AfterPlacement, -1, 0, true); + + TileObjectData.addTile(Type); + ModTranslation name = CreateMapEntryName(); + name.SetDefault("Power Cell Factory"); + AddMapEntry(new Color(67, 72, 81), name); + animationFrameHeight = 68; + } + + public override bool CanExplode(int i, int j) => false; + + // Finds the Tile Entity associated with the Power Cell Factory tile that the player clicked on. + // This can return null, so code using this function needs to be prepared for that. + public TEPowerCellFactory FindTileEntity(int i, int j) + { + // Find the top left corner of the FrameImportant tile that the player clicked on in the world. + int left = i - Main.tile[i, j].frameX % (Width * 18) / 18; + int top = j - Main.tile[i, j].frameY % (Height * 18) / 18; + + byte factoryType = ModContent.GetInstance().type; + bool exists = TileEntity.ByPosition.TryGetValue(new Point16(left, top), out TileEntity te); + return exists && te.type == factoryType ? (TEPowerCellFactory)te : null; + } + + 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() => 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) + { + // Drop the factory itself. + Item.NewItem(i * 16, j * 16, 32, 32, ModContent.ItemType()); + + int left = i - Main.tile[i, j].frameX % (Width * 18) / 18; + int top = j - Main.tile[i, j].frameY % (Height * 18) / 18; + + // Drop any cells contained in the factory. + TEPowerCellFactory factory = FindTileEntity(i, j); + int numCells = factory?.CellStack ?? 0; + if (numCells > 0) + Item.NewItem(new Vector2(i, j) * 16f, ModContent.ItemType(), numCells); + + factory?.Kill(left, top); + } + + public override bool NewRightClick(int i, int j) + { + int left = i - Main.tile[i, j].frameX % (Width * 18) / 18; + int top = j - Main.tile[i, j].frameY % (Height * 18) / 18; + TEPowerCellFactory thisFactory = FindTileEntity(i, j); + + Player player = Main.LocalPlayer; + Main.mouseRightRelease = false; + + // If a sign or chest was in use previously, close those GUIs. + if (player.sign >= 0) + { + Main.PlaySound(SoundID.MenuClose); + player.sign = -1; + Main.editSign = false; + Main.npcChatText = ""; + } + if (Main.editChest) + { + Main.PlaySound(SoundID.MenuTick); + Main.editChest = false; + Main.npcChatText = ""; + } + if (player.chest >= 0) + player.chest = -1; + + CalamityPlayer mp = player.Calamity(); + TEPowerCellFactory viewedFactory = mp.CurrentlyViewedFactory; + + // If this is the factory the player is currently looking at OR this factory is doesn't really exist, close the GUI. + if (viewedFactory != null && (thisFactory is null || thisFactory.ID == viewedFactory.ID)) + { + mp.CurrentlyViewedFactory = null; + mp.CurrentlyViewedFactoryX = mp.CurrentlyViewedFactoryY = -1; + Main.PlaySound(SoundID.MenuClose); + } + + // Otherwise, "switch to" this factory when it exists. This can be either opening the GUI from nothing, or just opening a different factory. + else if(thisFactory != null) + { + // Play a sound depending on whether the player had another factory open previously. + Main.PlaySound(mp.CurrentlyViewedFactory is null ? SoundID.MenuOpen : SoundID.MenuTick); + + // Ensure that the UI position is always centered and above the tile. + mp.CurrentlyViewedFactoryX = left * 16 + 16; + mp.CurrentlyViewedFactoryY = top * 16; + mp.CurrentlyViewedFactory = thisFactory; + + Main.playerInventory = true; + Main.recBigList = false; + } + + Recipe.FindRecipes(); + return true; + } + + // All tile drawcode is done manually because the tile's animation is controlled by a tile entity. + public override bool PreDraw(int i, int j, SpriteBatch spriteBatch) + { + Tile theTile = Main.tile[i, j]; + + // These offsets start as the tile offsets, i.e. which sub-tile of the FrameImportant structure this specific location is. + int frameXPos = Main.tile[i, j].frameX; + int frameYPos = Main.tile[i, j].frameY; + + // Grab the tile entity because its internal timer controls the animation. + TEPowerCellFactory factory = FindTileEntity(i, j); + int frameIndex = factory?.AnimationFrame ?? TotalFrames - 1; + frameXPos += frameIndex / FramesPerColumn * 72; + frameYPos += frameIndex % FramesPerColumn * 72; + + Texture2D tex = ModContent.GetTexture("CalamityMod/Tiles/PowerCellFactory"); + Vector2 offset = Main.drawToScreen ? Vector2.Zero : new Vector2(Main.offScreenRange); + Vector2 drawOffset = new Vector2(i * 16 - Main.screenPosition.X, j * 16 - Main.screenPosition.Y) + offset; + Color drawColor = Lighting.GetColor(i, j); + + if (!theTile.halfBrick() && theTile.slope() == 0) + spriteBatch.Draw(tex, drawOffset, new Rectangle(frameXPos, frameYPos, 16, 16), drawColor, 0.0f, Vector2.Zero, 1f, SpriteEffects.None, 0.0f); + else if (theTile.halfBrick()) + spriteBatch.Draw(tex, drawOffset + Vector2.UnitY * 8f, new Rectangle(frameXPos, frameYPos, 16, 16), drawColor, 0.0f, Vector2.Zero, 1f, SpriteEffects.None, 0.0f); + return false; + } + } +} diff --git a/Tiles/DraedonFuelFactory.png b/Tiles/PowerCellFactory.png similarity index 100% rename from Tiles/DraedonFuelFactory.png rename to Tiles/PowerCellFactory.png diff --git a/UI/CellFactoryUI.cs b/UI/CellFactoryUI.cs new file mode 100644 index 0000000000..ca027898ef --- /dev/null +++ b/UI/CellFactoryUI.cs @@ -0,0 +1,174 @@ +using CalamityMod.CalPlayer; +using CalamityMod.Items.DraedonMisc; +using CalamityMod.TileEntities; +using Microsoft.Xna.Framework; +using Microsoft.Xna.Framework.Graphics; +using System; +using Terraria; +using Terraria.ID; +using Terraria.ModLoader; +using Terraria.UI.Chat; + +namespace CalamityMod.UI +{ + public class CellFactoryUI + { + public const float MaxPlayerDistance = 160f; + public const float IconScale = 0.7f; + private const int GuiWidth = 39; + private const int GuiHeight = 39; + + public static void Draw(SpriteBatch spriteBatch) + { + Player p = Main.LocalPlayer; + CalamityPlayer mp = Main.LocalPlayer.Calamity(); + TEPowerCellFactory factory = mp.CurrentlyViewedFactory; + + // The UI only draws if the player is viewing a factory. + if (factory is null) + return; + + // If the player's inventory isn't open, or they have a chest open, immediately destroy this UI. + if (!Main.playerInventory || p.chest != -1) + { + mp.CurrentlyViewedFactory = null; + return; + } + + // If the player is too far away from their viewed factory, immediately destroy this UI and play the menu close sound. + Vector2 factoryWorldCenter = factory.Position.ToWorldCoordinates(32f, 32f); + if (Vector2.DistanceSquared(p.Center, factoryWorldCenter) > MaxPlayerDistance * MaxPlayerDistance) + { + Main.PlaySound(SoundID.MenuClose); + mp.CurrentlyViewedFactory = null; + return; + } + + // What item is currently in the UI item slot? It's normally nothing, but it could be power cells. + int powercellID = ModContent.ItemType(); + Item powercell = new Item(); + powercell.TurnToAir(); + if (factory.CellStack > 0) + { + powercell.SetDefaults(powercellID); + powercell.stack = factory.CellStack; + } + + Vector2 position = new Vector2(mp.CurrentlyViewedFactoryX, mp.CurrentlyViewedFactoryY); + + // Draw the factory's stored item as an inventory slot. + DrawItemSlot(spriteBatch, ref powercell, position + new Vector2(16f, -34f) - Main.screenPosition); + + int width = GuiWidth, height = GuiHeight; + + Rectangle mouseRectangle = new Rectangle((int)Main.MouseWorld.X, (int)Main.MouseWorld.Y, 2, 2); + Rectangle drawnItemRectangle = new Rectangle((int)position.X, (int)position.Y - 60, width, height); + + // If the player's cursor is over the slot and there are power cells, then interaction with the UI is possible. + if (mouseRectangle.Intersects(drawnItemRectangle) && powercell.stack > 0) + { + Main.HoverItem.SetDefaults(powercell.type); + + // If the slot is clicked, try to grab cells from the factory using both "current items" that a player can have. + int cellsGrabbed = 0; + bool shiftClicked = false; + if (Main.mouseLeft) + { + // If the player is holding shift and has space for the power cells, just spawn all of them on his or her face. + if (Main.keyState.PressingShift() && p.ItemSpace(powercell)) + { + cellsGrabbed = powercell.stack; + shiftClicked = true; + DropHelper.DropItem(p, powercellID, cellsGrabbed); + } + else + { + cellsGrabbed = TryGrabCell(ref Main.mouseItem, ref powercell); + if (cellsGrabbed == 0) + cellsGrabbed = TryGrabCell(ref p.inventory[Main.LocalPlayer.selectedItem], ref powercell); + } + } + + // If any cells were actually grabbed, take them from the factory's stockpile. + // Using the CellStack property setter automatically sends the correct packet to update the entity server side. + if (cellsGrabbed > 0) + { + factory.CellStack -= (short)cellsGrabbed; + + // Play a sound, but ONLY if the player didn't shift click. + // If they did, they're going to hear the item be picked up in a few frames anyway because it spawned on their face. + if (!shiftClicked) + Main.PlaySound(SoundID.Grab); + } + + // Since HoverItem is active, we don't need to input anything into this method. + Main.instance.MouseTextHackZoom(""); + + // Specifically do not block mouse input if holding a pickaxe, so that you can mine blocks behind the UI. + Main.blockMouse = Main.LocalPlayer.ActiveItem().pick <= 0; + } + } + + public static void DrawItemSlot(SpriteBatch spriteBatch, ref Item item, Vector2 drawPosition) + { + Texture2D slotBackgroundTex = ModContent.GetTexture("CalamityMod/ExtraTextures/UI/CellFactoryItemSlot_Empty"); + + // This check is done twice because the draw order matters. We want to draw the background icon before any text. + if (item.stack > 0) + slotBackgroundTex = ModContent.GetTexture("CalamityMod/ExtraTextures/UI/CellFactoryItemSlot_Filled"); + + spriteBatch.Draw(slotBackgroundTex, drawPosition, null, Color.White, 0f, slotBackgroundTex.Size() * 0.5f, IconScale, SpriteEffects.None, 0f); + if (item.stack > 0) + { + float inventoryScale = Main.inventoryScale; + Vector2 numberOffset = slotBackgroundTex.Size() * 0.2f; + ChatManager.DrawColorCodedStringWithShadow(spriteBatch, + Main.fontItemStack, + item.stack.ToString(), + drawPosition + numberOffset * inventoryScale, + Color.White, + 0f, + Vector2.Zero, + new Vector2(inventoryScale), + -1f, + inventoryScale); + } + } + + // Returns the number of cells grabbed. + public static int TryGrabCell(ref Item playerHandItem, ref Item cell) + { + Main.playerInventory = true; + Main.recBigList = false; + + // You can only grab cells if you're stacking them with other cells or holding nothing. + if (playerHandItem.IsAir) + { + playerHandItem.SetDefaults(cell.type); + playerHandItem.stack = cell.stack; + cell.TurnToAir(); + return playerHandItem.stack; + } + + // You can grab cells while holding cells, but your held stack can't go over 999. + if (playerHandItem.type == cell.type) + { + int spaceLeft = 999 - playerHandItem.stack; + + // If there's more cells than space left, take as many as possible. Otherwise take all the cells. + int cellsToTake = Math.Min(cell.stack, spaceLeft); + if (cellsToTake <= 0) + return 0; + + playerHandItem.stack += cellsToTake; + cell.stack -= cellsToTake; + + if (cell.stack == 0) + cell.TurnToAir(); + + return cellsToTake; + } + return 0; + } + } +} diff --git a/UI/DraedonsFactoryUI.cs b/UI/DraedonsFactoryUI.cs deleted file mode 100644 index 15e69d5fb6..0000000000 --- a/UI/DraedonsFactoryUI.cs +++ /dev/null @@ -1,90 +0,0 @@ -using Microsoft.Xna.Framework; -using Microsoft.Xna.Framework.Graphics; -using Terraria; -using Terraria.ID; -using Terraria.ModLoader; -using Terraria.UI.Chat; - -namespace CalamityMod.UI -{ - public class DraedonsFactoryUI - { - public const float IconScale = 0.7f; - public static void Draw(SpriteBatch spriteBatch) - { - if (Main.LocalPlayer.Calamity().CurrentlyViewedFactory != null) - { - var time = Terraria.DataStructures.TileEntity.ByID; - var stack = Main.LocalPlayer.Calamity().CurrentlyViewedFactory; - if (Main.LocalPlayer.chest != -1) - { - Main.LocalPlayer.Calamity().CurrentlyViewedFactory = null; - return; - } - Item fuel = Main.LocalPlayer.Calamity().CurrentlyViewedFactory.HeldItem; - Vector2 position = new Vector2(Main.LocalPlayer.Calamity().CurrentlyViewedFactoryX, Main.LocalPlayer.Calamity().CurrentlyViewedFactoryY); - - // Draw the fuel as an inventory slot. - DrawItemSlot(spriteBatch, ref fuel, position + new Vector2(16f, -34f) - Main.screenPosition); - - int width = 39, height = 39; - Rectangle mouseRectangle = new Rectangle((int)Main.MouseWorld.X, (int)Main.MouseWorld.Y, 2, 2); - Rectangle drawnItemRectangle = new Rectangle((int)position.X, (int)position.Y - 60, width, height); - if (mouseRectangle.Intersects(drawnItemRectangle) && fuel.stack > 0) - { - Main.HoverItem.SetDefaults(fuel.type); - // Take items from the chest if the item is clicked. - bool alreadyUsedItem = UseFuel(ref Main.mouseItem, ref fuel); - if (!alreadyUsedItem) - UseFuel(ref Main.LocalPlayer.inventory[Main.LocalPlayer.selectedItem], ref fuel); - Main.instance.MouseTextHackZoom(""); // Since HoverItem is active, we don't need to input anything into this method. - Main.blockMouse = Main.LocalPlayer.ActiveItem().pick <= 0; // Block mouse input if hovering over the item UI and not holding a pickaxe. - } - } - } - - public static void DrawItemSlot(SpriteBatch spriteBatch, ref Item item, Vector2 drawPosition) - { - Texture2D iconTexture = ModContent.GetTexture("CalamityMod/ExtraTextures/UI/DraedonFuelCellUISlot"); - - // This check is done twice because the draw order matters. We want to draw the background icon before any text. - if (item.stack > 0) - iconTexture = ModContent.GetTexture("CalamityMod/ExtraTextures/UI/DraedonFuelCellUISlotFilled"); - spriteBatch.Draw(iconTexture, drawPosition, null, Color.White, 0f, iconTexture.Size() * 0.5f, IconScale, SpriteEffects.None, 0f); - if (item.stack > 0) - { - float inventoryScale = Main.inventoryScale; - Vector2 numberOffset = iconTexture.Size() * 0.2f; - ChatManager.DrawColorCodedStringWithShadow(spriteBatch, - Main.fontItemStack, - item.stack.ToString(), - drawPosition + numberOffset * inventoryScale, - Color.White, - 0f, - Vector2.Zero, - new Vector2(inventoryScale), - -1f, - inventoryScale); - } - } - - public static bool UseFuel(ref Item itemToUse, ref Item fuel) - { - if (Main.mouseLeft) - { - Main.playerInventory = true; - Main.recBigList = false; - if (itemToUse.type == fuel.type || itemToUse.type == ItemID.None) - { - itemToUse = fuel.Clone(); - int stack = itemToUse.stack; - itemToUse.SetDefaults(itemToUse.type); - itemToUse.stack = stack; - fuel.stack = 0; - return true; - } - } - return false; - } - } -} diff --git a/Utilities/CalamityUtils.cs b/Utilities/CalamityUtils.cs index 06158c887c..43a73657b5 100644 --- a/Utilities/CalamityUtils.cs +++ b/Utilities/CalamityUtils.cs @@ -5,32 +5,8 @@ using CalamityMod.Events; using CalamityMod.Items; using CalamityMod.Items.Tools.ClimateChange; using CalamityMod.NPCs; -using CalamityMod.NPCs.AquaticScourge; -using CalamityMod.NPCs.AstrumAureus; -using CalamityMod.NPCs.AstrumDeus; -using CalamityMod.NPCs.BrimstoneElemental; -using CalamityMod.NPCs.Bumblebirb; -using CalamityMod.NPCs.Calamitas; -using CalamityMod.NPCs.CeaselessVoid; -using CalamityMod.NPCs.Crabulon; -using CalamityMod.NPCs.Cryogen; -using CalamityMod.NPCs.DesertScourge; -using CalamityMod.NPCs.DevourerofGods; -using CalamityMod.NPCs.HiveMind; -using CalamityMod.NPCs.Leviathan; using CalamityMod.NPCs.NormalNPCs; -using CalamityMod.NPCs.OldDuke; -using CalamityMod.NPCs.Perforator; -using CalamityMod.NPCs.PlaguebringerGoliath; -using CalamityMod.NPCs.Polterghast; -using CalamityMod.NPCs.ProfanedGuardians; using CalamityMod.NPCs.Providence; -using CalamityMod.NPCs.Ravager; -using CalamityMod.NPCs.Signus; -using CalamityMod.NPCs.SlimeGod; -using CalamityMod.NPCs.StormWeaver; -using CalamityMod.NPCs.SupremeCalamitas; -using CalamityMod.NPCs.Yharon; using CalamityMod.Projectiles; using CalamityMod.Projectiles.Magic; using CalamityMod.Projectiles.Summon; @@ -54,10 +30,8 @@ using Microsoft.Xna.Framework.Audio; using Microsoft.Xna.Framework.Graphics; using System; using System.Collections.Generic; -using System.IO; using System.Linq; using System.Reflection; -using System.Runtime.Serialization.Formatters.Binary; using System.Text; using Terraria; using Terraria.DataStructures; @@ -70,101 +44,101 @@ using Terraria.ObjectData; namespace CalamityMod { - public static class CalamityUtils - { - public static readonly CalamityRarity[] postMLRarities = - { - CalamityRarity.Turquoise, - CalamityRarity.PureGreen, - CalamityRarity.DarkBlue, - CalamityRarity.Violet, - CalamityRarity.Developer, - CalamityRarity.Rainbow - }; - - #region Object Extensions - public static CalamityPlayer Calamity(this Player player) => player.GetModPlayer(); - public static CalamityGlobalNPC Calamity(this NPC npc) => npc.GetGlobalNPC(); - public static CalamityGlobalItem Calamity(this Item item) => item.GetGlobalItem(); - public static CalamityGlobalProjectile Calamity(this Projectile proj) => proj.GetGlobalProjectile(); - public static Item ActiveItem(this Player player) => Main.mouseItem.IsAir ? player.HeldItem : Main.mouseItem; - #endregion + public static class CalamityUtils + { + public static readonly CalamityRarity[] postMLRarities = + { + CalamityRarity.Turquoise, + CalamityRarity.PureGreen, + CalamityRarity.DarkBlue, + CalamityRarity.Violet, + CalamityRarity.Developer, + CalamityRarity.Rainbow + }; + + #region Object Extensions + public static CalamityPlayer Calamity(this Player player) => player.GetModPlayer(); + public static CalamityGlobalNPC Calamity(this NPC npc) => npc.GetGlobalNPC(); + public static CalamityGlobalItem Calamity(this Item item) => item.GetGlobalItem(); + public static CalamityGlobalProjectile Calamity(this Projectile proj) => proj.GetGlobalProjectile(); + public static Item ActiveItem(this Player player) => Main.mouseItem.IsAir ? player.HeldItem : Main.mouseItem; + #endregion - #region Player Utilities - // These functions factor in TML 0.11 allDamage to get the player's total damage boost which affects the specified class. - public static float MeleeDamage(this Player player) => player.allDamage + player.meleeDamage - 1f; - public static float RangedDamage(this Player player) => player.allDamage + player.rangedDamage - 1f; - public static float MagicDamage(this Player player) => player.allDamage + player.magicDamage - 1f; - public static float MinionDamage(this Player player) => player.allDamage + player.minionDamage - 1f; - public static float ThrownDamage(this Player player) => player.allDamage + player.thrownDamage - 1f; - public static float RogueDamage(this Player player) => player.allDamage + player.thrownDamage + player.Calamity().throwingDamage - 2f; - public static float AverageDamage(this Player player) => player.allDamage + (player.meleeDamage + player.rangedDamage + player.magicDamage + player.minionDamage + player.Calamity().throwingDamage - 5f) / 5f; + #region Player Utilities + // These functions factor in TML 0.11 allDamage to get the player's total damage boost which affects the specified class. + public static float MeleeDamage(this Player player) => player.allDamage + player.meleeDamage - 1f; + public static float RangedDamage(this Player player) => player.allDamage + player.rangedDamage - 1f; + public static float MagicDamage(this Player player) => player.allDamage + player.magicDamage - 1f; + public static float MinionDamage(this Player player) => player.allDamage + player.minionDamage - 1f; + public static float ThrownDamage(this Player player) => player.allDamage + player.thrownDamage - 1f; + public static float RogueDamage(this Player player) => player.allDamage + player.thrownDamage + player.Calamity().throwingDamage - 2f; + public static float AverageDamage(this Player player) => player.allDamage + (player.meleeDamage + player.rangedDamage + player.magicDamage + player.minionDamage + player.Calamity().throwingDamage - 5f) / 5f; - public static bool IsUnderwater(this Player player) => Collision.DrownCollision(player.position, player.width, player.height, player.gravDir); + public static bool IsUnderwater(this Player player) => Collision.DrownCollision(player.position, player.width, player.height, player.gravDir); public static bool StandingStill(this Player player, float velocity = 0.05f) => player.velocity.Length() < velocity; - public static bool InSpace(this Player player) - { - float x = Main.maxTilesX / 4200f; - x *= x; - float spaceGravityMult = (float)((player.position.Y / 16f - (60f + 10f * x)) / (Main.worldSurface / 6.0)); - return spaceGravityMult < 1f; - } - public static bool PillarZone(this Player player) => player.ZoneTowerStardust || player.ZoneTowerSolar || player.ZoneTowerVortex || player.ZoneTowerNebula; - public static bool InCalamity(this Player player) => player.Calamity().ZoneCalamity; - public static bool InSunkenSea(this Player player) => player.Calamity().ZoneSunkenSea; - public static bool InSulphur(this Player player) => player.Calamity().ZoneSulphur; - public static bool InAstral(this Player player, int biome = 0) //1 is above ground, 2 is underground, 3 is desert - { - switch (biome) - { - case 1: - return player.Calamity().ZoneAstral && (player.ZoneOverworldHeight || player.ZoneSkyHeight); + public static bool InSpace(this Player player) + { + float x = Main.maxTilesX / 4200f; + x *= x; + float spaceGravityMult = (float)((player.position.Y / 16f - (60f + 10f * x)) / (Main.worldSurface / 6.0)); + return spaceGravityMult < 1f; + } + public static bool PillarZone(this Player player) => player.ZoneTowerStardust || player.ZoneTowerSolar || player.ZoneTowerVortex || player.ZoneTowerNebula; + public static bool InCalamity(this Player player) => player.Calamity().ZoneCalamity; + public static bool InSunkenSea(this Player player) => player.Calamity().ZoneSunkenSea; + public static bool InSulphur(this Player player) => player.Calamity().ZoneSulphur; + public static bool InAstral(this Player player, int biome = 0) //1 is above ground, 2 is underground, 3 is desert + { + switch (biome) + { + case 1: + return player.Calamity().ZoneAstral && (player.ZoneOverworldHeight || player.ZoneSkyHeight); - case 2: - return player.Calamity().ZoneAstral && (player.ZoneDirtLayerHeight || player.ZoneRockLayerHeight || player.ZoneUnderworldHeight); + case 2: + return player.Calamity().ZoneAstral && (player.ZoneDirtLayerHeight || player.ZoneRockLayerHeight || player.ZoneUnderworldHeight); - case 3: - return player.Calamity().ZoneAstral && player.ZoneDesert; + case 3: + return player.Calamity().ZoneAstral && player.ZoneDesert; - default: - return player.Calamity().ZoneAstral; - } - } - public static bool InAbyss(this Player player, int layer = 0) - { - switch (layer) - { - case 1: - return player.Calamity().ZoneAbyssLayer1; + default: + return player.Calamity().ZoneAstral; + } + } + public static bool InAbyss(this Player player, int layer = 0) + { + switch (layer) + { + case 1: + return player.Calamity().ZoneAbyssLayer1; - case 2: - return player.Calamity().ZoneAbyssLayer2; + case 2: + return player.Calamity().ZoneAbyssLayer2; - case 3: - return player.Calamity().ZoneAbyssLayer3; + case 3: + return player.Calamity().ZoneAbyssLayer3; - case 4: - return player.Calamity().ZoneAbyssLayer4; + case 4: + return player.Calamity().ZoneAbyssLayer4; - default: - return player.Calamity().ZoneAbyss; - } - } - public static bool InventoryHas(this Player player, params int[] items) - { - return player.inventory.Any(item => items.Contains(item.type)); - } - public static bool PortableStorageHas(this Player player, params int[] items) - { + default: + return player.Calamity().ZoneAbyss; + } + } + public static bool InventoryHas(this Player player, params int[] items) + { + return player.inventory.Any(item => items.Contains(item.type)); + } + public static bool PortableStorageHas(this Player player, params int[] items) + { bool hasItem = false; - if (player.bank.item.Any(item => items.Contains(item.type))) + if (player.bank.item.Any(item => items.Contains(item.type))) hasItem = true; - if (player.bank2.item.Any(item => items.Contains(item.type))) + if (player.bank2.item.Any(item => items.Contains(item.type))) hasItem = true; - if (player.bank3.item.Any(item => items.Contains(item.type))) + if (player.bank3.item.Any(item => items.Contains(item.type))) hasItem = true; - return hasItem; - } + return hasItem; + } /// /// Inflict typical exo weapon debuffs in pvp. @@ -195,18 +169,18 @@ namespace CalamityMod /// The value lifeMax will be set to in Revegeneance mode. /// The value lifeMax will be set to during the Boss Rush. public static void LifeMaxNERB(this NPC npc, int normal, int? revengeance = null, int? bossRush = null) - { - npc.lifeMax = normal; + { + npc.lifeMax = normal; - if (bossRush.HasValue && BossRushEvent.BossRushActive) - { - npc.lifeMax = bossRush.Value; - } - else if (revengeance.HasValue && CalamityWorld.revenge) - { - npc.lifeMax = revengeance.Value; - } - } + if (bossRush.HasValue && BossRushEvent.BossRushActive) + { + npc.lifeMax = bossRush.Value; + } + else if (revengeance.HasValue && CalamityWorld.revenge) + { + npc.lifeMax = revengeance.Value; + } + } /// /// Allows you to set the DR value of a NPC to different values based on the mode. @@ -383,92 +357,92 @@ namespace CalamityMod /// Whether to ignore tiles when finding a target or not /// Whether bosses should be prioritized in targetting or not public static NPC ClosestNPCAt(this Vector2 origin, float maxDistanceToCheck, bool ignoreTiles = true, bool bossPriority = false) - { - NPC closestTarget = null; - float distance = maxDistanceToCheck; - if (bossPriority) - { - bool bossFound = false; - for (int index = 0; index < Main.npc.Length; index++) - { - // If we've found a valid boss target, ignore ALL targets which aren't bosses. - if (bossFound && !(Main.npc[index].boss || Main.npc[index].type == NPCID.WallofFleshEye)) - continue; - if (Main.npc[index].CanBeChasedBy(null, false)) - { + { + NPC closestTarget = null; + float distance = maxDistanceToCheck; + if (bossPriority) + { + bool bossFound = false; + for (int index = 0; index < Main.npc.Length; index++) + { + // If we've found a valid boss target, ignore ALL targets which aren't bosses. + if (bossFound && !(Main.npc[index].boss || Main.npc[index].type == NPCID.WallofFleshEye)) + continue; + if (Main.npc[index].CanBeChasedBy(null, false)) + { float extraDistance = (Main.npc[index].width / 2) + (Main.npc[index].height / 2); bool canHit = true; if (extraDistance < distance && !ignoreTiles) canHit = Collision.CanHit(origin, 1, 1, Main.npc[index].Center, 1, 1); - if (Vector2.Distance(origin, Main.npc[index].Center) < (distance + extraDistance) && canHit) - { - if (Main.npc[index].boss || Main.npc[index].type == NPCID.WallofFleshEye) - bossFound = true; - distance = Vector2.Distance(origin, Main.npc[index].Center); - closestTarget = Main.npc[index]; - } - } - } - } - else - { - for (int index = 0; index < Main.npc.Length; index++) - { - if (Main.npc[index].CanBeChasedBy(null, false)) - { + if (Vector2.Distance(origin, Main.npc[index].Center) < (distance + extraDistance) && canHit) + { + if (Main.npc[index].boss || Main.npc[index].type == NPCID.WallofFleshEye) + bossFound = true; + distance = Vector2.Distance(origin, Main.npc[index].Center); + closestTarget = Main.npc[index]; + } + } + } + } + else + { + for (int index = 0; index < Main.npc.Length; index++) + { + if (Main.npc[index].CanBeChasedBy(null, false)) + { float extraDistance = (Main.npc[index].width / 2) + (Main.npc[index].height / 2); bool canHit = true; if (extraDistance < distance && !ignoreTiles) canHit = Collision.CanHit(origin, 1, 1, Main.npc[index].Center, 1, 1); - if (Vector2.Distance(origin, Main.npc[index].Center) < (distance + extraDistance) && canHit) - { - distance = Vector2.Distance(origin, Main.npc[index].Center); - closestTarget = Main.npc[index]; - } - } - } - } - return closestTarget; - } - /// - /// Detects nearby hostile NPCs from a given point with minion support - /// - /// The position where we wish to check for nearby NPCs - /// Maximum amount of pixels to check around the origin - /// Owner of the minion + if (Vector2.Distance(origin, Main.npc[index].Center) < (distance + extraDistance) && canHit) + { + distance = Vector2.Distance(origin, Main.npc[index].Center); + closestTarget = Main.npc[index]; + } + } + } + } + return closestTarget; + } + /// + /// Detects nearby hostile NPCs from a given point with minion support + /// + /// The position where we wish to check for nearby NPCs + /// Maximum amount of pixels to check around the origin + /// Owner of the minion /// Whether to ignore tiles when finding a target or not - public static NPC MinionHoming(this Vector2 origin, float maxDistanceToCheck, Player owner, bool ignoreTiles = true) - { + public static NPC MinionHoming(this Vector2 origin, float maxDistanceToCheck, Player owner, bool ignoreTiles = true) + { if (owner is null || owner.whoAmI < 0 || owner.whoAmI > Main.maxPlayers || owner.MinionAttackTargetNPC < 0 || owner.MinionAttackTargetNPC > Main.maxNPCs) return ClosestNPCAt(origin, maxDistanceToCheck, ignoreTiles); NPC npc = Main.npc[owner.MinionAttackTargetNPC]; bool canHit = true; if (!ignoreTiles) canHit = Collision.CanHit(origin, 1, 1, npc.Center, 1, 1); - if (owner.HasMinionAttackTargetNPC && canHit) - { - return npc; - } - return ClosestNPCAt(origin, maxDistanceToCheck, ignoreTiles); - } + if (owner.HasMinionAttackTargetNPC && canHit) + { + return npc; + } + return ClosestNPCAt(origin, maxDistanceToCheck, ignoreTiles); + } - /// - /// Crude anti-butcher logic based on % max health. - /// - /// The NPC attacked. - /// How much damage the attack would deal. - /// Whether or not the anti-butcher was triggered. - public static bool AntiButcher(NPC npc, ref double damage, float healthPercent) - { - if (damage <= npc.lifeMax * healthPercent) - return false; - damage = 0D; - return true; - } + /// + /// Crude anti-butcher logic based on % max health. + /// + /// The NPC attacked. + /// How much damage the attack would deal. + /// Whether or not the anti-butcher was triggered. + public static bool AntiButcher(NPC npc, ref double damage, float healthPercent) + { + if (damage <= npc.lifeMax * healthPercent) + return false; + damage = 0D; + return true; + } /// /// Check if an NPC is organic @@ -533,13 +507,13 @@ namespace CalamityMod } } - public static void DisplayTextFromLocalizationKey(string key, Color textColor) - { - if (Main.netMode == NetmodeID.SinglePlayer) - Main.NewText(Language.GetTextValue(key), textColor); - else if (Main.netMode == NetmodeID.Server) - NetMessage.BroadcastChatMessage(NetworkText.FromKey(key), textColor); - } + public static void DisplayTextFromLocalizationKey(string key, Color textColor) + { + if (Main.netMode == NetmodeID.SinglePlayer) + Main.NewText(Language.GetTextValue(key), textColor); + else if (Main.netMode == NetmodeID.Server) + NetMessage.BroadcastChatMessage(NetworkText.FromKey(key), textColor); + } /// Inflict typical exo weapon debuffs. Duration multiplier optional. /// @@ -558,219 +532,219 @@ namespace CalamityMod target.AddBuff(BuffID.Frostburn, (int)(120 * multiplier)); target.AddBuff(BuffID.OnFire, (int)(120 * multiplier)); } - #endregion + #endregion - #region Item Utilities - public static bool IsPostML(this CalamityRarity calrare) - { - return calrare != CalamityRarity.NoEffect; - // TODO -- separate out whether an item is post-ML from its custom rarity. - // This is necessary because there are pre-ML rare variants, legendary weapons and dedicated items. - /* - for(int i = 0; i < postMLRarities.Length; ++i) - if (postMLRarities[i] == calrare) - return true; - return false; - */ - } + #region Item Utilities + public static bool IsPostML(this CalamityRarity calrare) + { + return calrare != CalamityRarity.NoEffect; + // TODO -- separate out whether an item is post-ML from its custom rarity. + // This is necessary because there are pre-ML rare variants, legendary weapons and dedicated items. + /* + for(int i = 0; i < postMLRarities.Length; ++i) + if (postMLRarities[i] == calrare) + return true; + return false; + */ + } - /// - /// Converts the given ModHotKey into a string for insertion into item tooltips.

- /// This allows the user's actual keybind choices to be shown to them in tooltips. - ///
- /// The ModHotKey to convert to a string. - /// - public static string TooltipHotkeyString(this ModHotKey mhk) - { - if (Main.dedServ || mhk is null) - return ""; + /// + /// Converts the given ModHotKey into a string for insertion into item tooltips.

+ /// This allows the user's actual keybind choices to be shown to them in tooltips. + ///
+ /// The ModHotKey to convert to a string. + /// + public static string TooltipHotkeyString(this ModHotKey mhk) + { + if (Main.dedServ || mhk is null) + return ""; - List keys = mhk.GetAssignedKeys(); - if (keys.Count == 0) - return "[NONE]"; - else - { - StringBuilder sb = new StringBuilder(16); - sb.Append(keys[0]); + List keys = mhk.GetAssignedKeys(); + if (keys.Count == 0) + return "[NONE]"; + else + { + StringBuilder sb = new StringBuilder(16); + sb.Append(keys[0]); - // In almost all cases, this code won't run, because there won't be multiple bindings for the hotkey. But just in case... - for (int i = 1; i < keys.Count; ++i) - sb.Append(" / ").Append(keys[i]); - return sb.ToString(); - } - } + // In almost all cases, this code won't run, because there won't be multiple bindings for the hotkey. But just in case... + for (int i = 1; i < keys.Count; ++i) + sb.Append(" / ").Append(keys[i]); + return sb.ToString(); + } + } - private const float WorldInsertionOffset = 15f; - /// - /// If the given item is outside the world, force it to be within the world boundaries. - /// - /// The item to possibly relocate. - /// The minimum distance in pixels the item can be from the world boundary. - /// Whether the item was relocated. - public static bool ForceItemIntoWorld(Item item, float desiredDist = WorldInsertionOffset) - { - if (item is null || !item.active) - return false; + private const float WorldInsertionOffset = 15f; + /// + /// If the given item is outside the world, force it to be within the world boundaries. + /// + /// The item to possibly relocate. + /// The minimum distance in pixels the item can be from the world boundary. + /// Whether the item was relocated. + public static bool ForceItemIntoWorld(Item item, float desiredDist = WorldInsertionOffset) + { + if (item is null || !item.active) + return false; - // The world edge needs to be accounted for regardless of the distance chosen as an argument. - float worldEdge = Main.offLimitBorderTiles * 16f; - float dist = worldEdge + desiredDist; + // The world edge needs to be accounted for regardless of the distance chosen as an argument. + float worldEdge = Main.offLimitBorderTiles * 16f; + float dist = worldEdge + desiredDist; - float maxPosX = Main.maxTilesX * 16f; - float maxPosY = Main.maxTilesY * 16f; - bool moved = false; - if (item.position.X < worldEdge) - { - item.position.X = dist; - moved = true; - } - else if(item.position.X + item.width > maxPosX - worldEdge) - { - item.position.X = maxPosX - item.width - dist; - moved = true; - } - if(item.position.Y < worldEdge) - { - item.position.Y = dist; - moved = true; - } - else if(item.position.Y + item.height > maxPosY - worldEdge) - { - item.position.Y = maxPosY - item.height - dist; - moved = true; - } - return moved; - } + float maxPosX = Main.maxTilesX * 16f; + float maxPosY = Main.maxTilesY * 16f; + bool moved = false; + if (item.position.X < worldEdge) + { + item.position.X = dist; + moved = true; + } + else if(item.position.X + item.width > maxPosX - worldEdge) + { + item.position.X = maxPosX - item.width - dist; + moved = true; + } + if(item.position.Y < worldEdge) + { + item.position.Y = dist; + moved = true; + } + else if(item.position.Y + item.height > maxPosY - worldEdge) + { + item.position.Y = maxPosY - item.height - dist; + moved = true; + } + return moved; + } - public static Rectangle FixSwingHitbox(float hitboxWidth, float hitboxHeight) - { - Player player = Main.player[Main.myPlayer]; - Item item = player.ActiveItem(); - float hitbox_X, hitbox_Y; - float mountOffsetY = player.mount.PlayerOffsetHitbox; + public static Rectangle FixSwingHitbox(float hitboxWidth, float hitboxHeight) + { + Player player = Main.player[Main.myPlayer]; + Item item = player.ActiveItem(); + float hitbox_X, hitbox_Y; + float mountOffsetY = player.mount.PlayerOffsetHitbox; - // Third hitbox shifting values - if (player.itemAnimation < player.itemAnimationMax * 0.333) - { - float shiftX = 10f; - if (hitboxWidth >= 92) - shiftX = 38f; - else if (hitboxWidth >= 64) - shiftX = 28f; - else if (hitboxWidth >= 52) - shiftX = 24f; - else if (hitboxWidth > 32) - shiftX = 14f; - hitbox_X = player.position.X + player.width * 0.5f + (hitboxWidth * 0.5f - shiftX) * player.direction; - hitbox_Y = player.position.Y + 24f + mountOffsetY; - } + // Third hitbox shifting values + if (player.itemAnimation < player.itemAnimationMax * 0.333) + { + float shiftX = 10f; + if (hitboxWidth >= 92) + shiftX = 38f; + else if (hitboxWidth >= 64) + shiftX = 28f; + else if (hitboxWidth >= 52) + shiftX = 24f; + else if (hitboxWidth > 32) + shiftX = 14f; + hitbox_X = player.position.X + player.width * 0.5f + (hitboxWidth * 0.5f - shiftX) * player.direction; + hitbox_Y = player.position.Y + 24f + mountOffsetY; + } - // Second hitbox shifting values - else if (player.itemAnimation < player.itemAnimationMax * 0.666) - { - float shift = 10f; - if (hitboxWidth >= 92) - shift = 38f; - else if (hitboxWidth >= 64) - shift = 28f; - else if (hitboxWidth >= 52) - shift = 24f; - else if (hitboxWidth > 32) - shift = 18f; - hitbox_X = player.position.X + (player.width * 0.5f + (hitboxWidth * 0.5f - shift) * player.direction); + // Second hitbox shifting values + else if (player.itemAnimation < player.itemAnimationMax * 0.666) + { + float shift = 10f; + if (hitboxWidth >= 92) + shift = 38f; + else if (hitboxWidth >= 64) + shift = 28f; + else if (hitboxWidth >= 52) + shift = 24f; + else if (hitboxWidth > 32) + shift = 18f; + hitbox_X = player.position.X + (player.width * 0.5f + (hitboxWidth * 0.5f - shift) * player.direction); - shift = 10f; - if (hitboxHeight > 64) - shift = 14f; - else if (hitboxHeight > 52) - shift = 12f; - else if (hitboxHeight > 32) - shift = 8f; + shift = 10f; + if (hitboxHeight > 64) + shift = 14f; + else if (hitboxHeight > 52) + shift = 12f; + else if (hitboxHeight > 32) + shift = 8f; - hitbox_Y = player.position.Y + shift + mountOffsetY; - } + hitbox_Y = player.position.Y + shift + mountOffsetY; + } - // First hitbox shifting values - else - { - float shift = 6f; - if (hitboxWidth >= 92) - shift = 38f; - else if (hitboxWidth >= 64) - shift = 28f; - else if (hitboxWidth >= 52) - shift = 24f; - else if (hitboxWidth >= 48) - shift = 18f; - else if (hitboxWidth > 32) - shift = 14f; - hitbox_X = player.position.X + player.width * 0.5f - (hitboxWidth * 0.5f - shift) * player.direction; + // First hitbox shifting values + else + { + float shift = 6f; + if (hitboxWidth >= 92) + shift = 38f; + else if (hitboxWidth >= 64) + shift = 28f; + else if (hitboxWidth >= 52) + shift = 24f; + else if (hitboxWidth >= 48) + shift = 18f; + else if (hitboxWidth > 32) + shift = 14f; + hitbox_X = player.position.X + player.width * 0.5f - (hitboxWidth * 0.5f - shift) * player.direction; - shift = 10f; - if (hitboxHeight > 64) - shift = 14f; - else if (hitboxHeight > 52) - shift = 12f; - else if (hitboxHeight > 32) - shift = 10f; - hitbox_Y = player.position.Y + shift + mountOffsetY; - } + shift = 10f; + if (hitboxHeight > 64) + shift = 14f; + else if (hitboxHeight > 52) + shift = 12f; + else if (hitboxHeight > 32) + shift = 10f; + hitbox_Y = player.position.Y + shift + mountOffsetY; + } - // Inversion due to grav potion - if (player.gravDir == -1f) - { - hitbox_Y = player.position.Y + player.height + (player.position.Y - hitbox_Y); - } + // Inversion due to grav potion + if (player.gravDir == -1f) + { + hitbox_Y = player.position.Y + player.height + (player.position.Y - hitbox_Y); + } - // Hitbox size adjustments - Rectangle hitbox = new Rectangle((int)hitbox_X, (int)hitbox_Y, 32, 32); - if (item.damage >= 0 && item.type > ItemID.None && !item.noMelee && player.itemAnimation > 0) - { - if (!Main.dedServ) - { - hitbox = new Rectangle((int)hitbox_X, (int)hitbox_Y, (int)hitboxWidth, (int)hitboxHeight); - } - hitbox.Width = (int)(hitbox.Width * item.scale); - hitbox.Height = (int)(hitbox.Height * item.scale); - if (player.direction == -1) - { - hitbox.X -= hitbox.Width; - } - if (player.gravDir == 1f) - { - hitbox.Y -= hitbox.Height; - } + // Hitbox size adjustments + Rectangle hitbox = new Rectangle((int)hitbox_X, (int)hitbox_Y, 32, 32); + if (item.damage >= 0 && item.type > ItemID.None && !item.noMelee && player.itemAnimation > 0) + { + if (!Main.dedServ) + { + hitbox = new Rectangle((int)hitbox_X, (int)hitbox_Y, (int)hitboxWidth, (int)hitboxHeight); + } + hitbox.Width = (int)(hitbox.Width * item.scale); + hitbox.Height = (int)(hitbox.Height * item.scale); + if (player.direction == -1) + { + hitbox.X -= hitbox.Width; + } + if (player.gravDir == 1f) + { + hitbox.Y -= hitbox.Height; + } - // Broadsword use style - if (item.useStyle == ItemUseStyleID.SwingThrow) - { - // Third hitbox size adjustments - if (player.itemAnimation < player.itemAnimationMax * 0.333) - { - if (player.direction == -1) - { - hitbox.X -= (int)(hitbox.Width * 1.4 - hitbox.Width); - } - hitbox.Width = (int)(hitbox.Width * 1.4); - hitbox.Y += (int)(hitbox.Height * 0.5 * player.gravDir); - hitbox.Height = (int)(hitbox.Height * 1.1); - } + // Broadsword use style + if (item.useStyle == ItemUseStyleID.SwingThrow) + { + // Third hitbox size adjustments + if (player.itemAnimation < player.itemAnimationMax * 0.333) + { + if (player.direction == -1) + { + hitbox.X -= (int)(hitbox.Width * 1.4 - hitbox.Width); + } + hitbox.Width = (int)(hitbox.Width * 1.4); + hitbox.Y += (int)(hitbox.Height * 0.5 * player.gravDir); + hitbox.Height = (int)(hitbox.Height * 1.1); + } - // First hitbox size adjustments - else if (player.itemAnimation >= player.itemAnimationMax * 0.666) - { - if (player.direction == 1) - { - hitbox.X -= (int)(hitbox.Width * 1.2); - } - hitbox.Width *= 2; - hitbox.Y -= (int)((hitbox.Height * 1.4 - hitbox.Height) * player.gravDir); - hitbox.Height = (int)(hitbox.Height * 1.4); - } - } - } - return hitbox; - } + // First hitbox size adjustments + else if (player.itemAnimation >= player.itemAnimationMax * 0.666) + { + if (player.direction == 1) + { + hitbox.X -= (int)(hitbox.Width * 1.2); + } + hitbox.Width *= 2; + hitbox.Y -= (int)((hitbox.Height * 1.4 - hitbox.Height) * player.gravDir); + hitbox.Height = (int)(hitbox.Height * 1.4); + } + } + } + return hitbox; + } public static void ConsumeItemViaQuickBuff(Player player, Item item, int buffType, int buffTime, bool reducedPotionSickness) { @@ -830,67 +804,67 @@ namespace CalamityMod Recipe.FindRecipes(); } } - #endregion + #endregion - #region Projectile Utilities - public static int CountProjectiles(int Type) => Main.projectile.Count(proj => proj.type == Type && proj.active); + #region Projectile Utilities + public static int CountProjectiles(int Type) => Main.projectile.Count(proj => proj.type == Type && proj.active); - public static int CountHookProj() => Main.projectile.Count(proj => Main.projHook[proj.type] && proj.ai[0] == 2f && proj.active && proj.owner == Main.myPlayer); + public static int CountHookProj() => Main.projectile.Count(proj => Main.projHook[proj.type] && proj.ai[0] == 2f && proj.active && proj.owner == Main.myPlayer); - public static bool IsSummon(this Projectile proj) => proj.minion || proj.sentry || CalamityLists.projectileMinionList.Contains(proj.type) || ProjectileID.Sets.MinionShot[proj.type] || ProjectileID.Sets.SentryShot[proj.type]; + public static bool IsSummon(this Projectile proj) => proj.minion || proj.sentry || CalamityLists.projectileMinionList.Contains(proj.type) || ProjectileID.Sets.MinionShot[proj.type] || ProjectileID.Sets.SentryShot[proj.type]; - public static void KillAllHostileProjectiles() - { - for (int x = 0; x < Main.maxProjectiles; x++) - { - Projectile projectile = Main.projectile[x]; - if (projectile.active && projectile.hostile && !projectile.friendly && projectile.damage > 0) - { - projectile.Kill(); - } - } - } + public static void KillAllHostileProjectiles() + { + for (int x = 0; x < Main.maxProjectiles; x++) + { + Projectile projectile = Main.projectile[x]; + if (projectile.active && projectile.hostile && !projectile.friendly && projectile.damage > 0) + { + projectile.Kill(); + } + } + } - public static void KillShootProjectiles(bool shouldBreak, int projType, Player player) - { - for (int x = 0; x < Main.maxProjectiles; x++) - { - Projectile proj = Main.projectile[x]; - if (proj.active && proj.owner == player.whoAmI && proj.type == projType) - { - proj.Kill(); + public static void KillShootProjectiles(bool shouldBreak, int projType, Player player) + { + for (int x = 0; x < Main.maxProjectiles; x++) + { + Projectile proj = Main.projectile[x]; + if (proj.active && proj.owner == player.whoAmI && proj.type == projType) + { + proj.Kill(); if (shouldBreak) break; - } - } - } + } + } + } - public static void KillShootProjectileMany(Player player, params int[] projTypes) - { - for (int x = 0; x < Main.maxProjectiles; x++) - { - Projectile proj = Main.projectile[x]; - if (proj.active && proj.owner == player.whoAmI && projTypes.Contains(proj.type)) - { - proj.Kill(); - } - } - } + public static void KillShootProjectileMany(Player player, params int[] projTypes) + { + for (int x = 0; x < Main.maxProjectiles; x++) + { + Projectile proj = Main.projectile[x]; + if (proj.active && proj.owner == player.whoAmI && projTypes.Contains(proj.type)) + { + proj.Kill(); + } + } + } - public static int FindFirstProjectile(int Type) - { + public static int FindFirstProjectile(int Type) + { int index = -1; - for (int x = 0; x < Main.maxProjectiles; x++) - { - Projectile proj = Main.projectile[x]; - if (proj.active && proj.type == Type) - { - index = x; + for (int x = 0; x < Main.maxProjectiles; x++) + { + Projectile proj = Main.projectile[x]; + if (proj.active && proj.type == Type) + { + index = x; break; - } - } + } + } return index; - } + } public static void OnlyOneSentry(Player player, int Type) { @@ -926,177 +900,177 @@ namespace CalamityMod bool spawnDust = false; //the projectile follows the NPC, even if it goes into blocks - projectile.tileCollide = false; + projectile.tileCollide = false; //timer for triggering hit effects - projectile.localAI[0]++; - if (projectile.localAI[0] % 30f == 0f) - { - spawnDust = true; - } + projectile.localAI[0]++; + if (projectile.localAI[0] % 30f == 0f) + { + spawnDust = true; + } //So AI knows what NPC it is sticking to - int npcIndex = (int)projectile.ai[1]; + int npcIndex = (int)projectile.ai[1]; NPC npc = Main.npc[npcIndex]; //Kill projectile after so many seconds or if the NPC it is stuck to no longer exists - if (projectile.localAI[0] >= (float)(60 * seconds)) - { - killProj = true; - } - else if (npcIndex < 0 || npcIndex >= Main.maxNPCs) - { - killProj = true; - } + if (projectile.localAI[0] >= (float)(60 * seconds)) + { + killProj = true; + } + else if (npcIndex < 0 || npcIndex >= Main.maxNPCs) + { + killProj = true; + } - else if (npc.active && !npc.dontTakeDamage) - { + else if (npc.active && !npc.dontTakeDamage) + { //follow the NPC - projectile.Center = npc.Center - projectile.velocity * 2f; - projectile.gfxOffY = npc.gfxOffY; + projectile.Center = npc.Center - projectile.velocity * 2f; + projectile.gfxOffY = npc.gfxOffY; //if attached to npc, trigger npc hit effects every half a second - if (spawnDust) - { - npc.HitEffect(0, 1.0); - } - } - else - { - killProj = true; - } + if (spawnDust) + { + npc.HitEffect(0, 1.0); + } + } + else + { + killProj = true; + } //Kill the projectile if needed - if (killProj) - { - projectile.Kill(); - } - } - } + if (killProj) + { + projectile.Kill(); + } + } + } - /// - /// Call this function in ModifyHitNPC to make your projectiles stick to enemies, needs StickyProjAI to be called in the AI of the projectile - /// - /// The projectile you're giving sticky behaviour to - /// How many projectiles of this type can stick to one enemy - /// Decides if you want the projectile to deal damage while its sticked to enemies or not - public static void ModifyHitNPCSticky(this Projectile projectile, int maxStick, bool constantDamage) - { + /// + /// Call this function in ModifyHitNPC to make your projectiles stick to enemies, needs StickyProjAI to be called in the AI of the projectile + /// + /// The projectile you're giving sticky behaviour to + /// How many projectiles of this type can stick to one enemy + /// Decides if you want the projectile to deal damage while its sticked to enemies or not + public static void ModifyHitNPCSticky(this Projectile projectile, int maxStick, bool constantDamage) + { Player player = Main.player[projectile.owner]; - Rectangle myRect = new Rectangle((int)projectile.position.X, (int)projectile.position.Y, projectile.width, projectile.height); + Rectangle myRect = new Rectangle((int)projectile.position.X, (int)projectile.position.Y, projectile.width, projectile.height); - if (projectile.owner == Main.myPlayer) - { - for (int npcIndex = 0; npcIndex < Main.maxNPCs; npcIndex++) - { + if (projectile.owner == Main.myPlayer) + { + for (int npcIndex = 0; npcIndex < Main.maxNPCs; npcIndex++) + { NPC npc = Main.npc[npcIndex]; //covers most edge cases like voodoo dolls - if (npc.active && !npc.dontTakeDamage && - ((projectile.friendly && (!npc.friendly || (npc.type == NPCID.Guide && projectile.owner < Main.maxPlayers && player.killGuide) || (npc.type == NPCID.Clothier && projectile.owner < Main.maxPlayers && player.killClothier))) || - (projectile.hostile && npc.friendly && !npc.dontTakeDamageFromHostiles)) && (projectile.owner < 0 || npc.immune[projectile.owner] == 0 || projectile.maxPenetrate == 1)) - { - if (npc.noTileCollide || !projectile.ownerHitCheck || projectile.CanHit(npc)) - { - bool stickingToNPC; + if (npc.active && !npc.dontTakeDamage && + ((projectile.friendly && (!npc.friendly || (npc.type == NPCID.Guide && projectile.owner < Main.maxPlayers && player.killGuide) || (npc.type == NPCID.Clothier && projectile.owner < Main.maxPlayers && player.killClothier))) || + (projectile.hostile && npc.friendly && !npc.dontTakeDamageFromHostiles)) && (projectile.owner < 0 || npc.immune[projectile.owner] == 0 || projectile.maxPenetrate == 1)) + { + if (npc.noTileCollide || !projectile.ownerHitCheck || projectile.CanHit(npc)) + { + bool stickingToNPC; //Solar Crawltipede tail has special collision - if (npc.type == NPCID.SolarCrawltipedeTail) - { - Rectangle rect = npc.getRect(); - int num5 = 8; - rect.X -= num5; - rect.Y -= num5; - rect.Width += num5 * 2; - rect.Height += num5 * 2; - stickingToNPC = projectile.Colliding(myRect, rect); - } - else - { - stickingToNPC = projectile.Colliding(myRect, npc.getRect()); - } - if (stickingToNPC) - { + if (npc.type == NPCID.SolarCrawltipedeTail) + { + Rectangle rect = npc.getRect(); + int num5 = 8; + rect.X -= num5; + rect.Y -= num5; + rect.Width += num5 * 2; + rect.Height += num5 * 2; + stickingToNPC = projectile.Colliding(myRect, rect); + } + else + { + stickingToNPC = projectile.Colliding(myRect, npc.getRect()); + } + if (stickingToNPC) + { //reflect projectile if the npc can reflect it (like Selenians) - if (npc.reflectingProjectiles && projectile.CanReflect()) - { - npc.ReflectProjectile(projectile.whoAmI); - return; - } + if (npc.reflectingProjectiles && projectile.CanReflect()) + { + npc.ReflectProjectile(projectile.whoAmI); + return; + } //let the projectile know it is sticking and the npc it is sticking too - projectile.ai[0] = 1f; - projectile.ai[1] = (float)npcIndex; + projectile.ai[0] = 1f; + projectile.ai[1] = (float)npcIndex; //follow the NPC - projectile.velocity = (npc.Center - projectile.Center) * 0.75f; + projectile.velocity = (npc.Center - projectile.Center) * 0.75f; - projectile.netUpdate = true; + projectile.netUpdate = true; //Set projectile damage to 0 if desired - if (!constantDamage) - projectile.damage = 0; + if (!constantDamage) + projectile.damage = 0; //Count how many projectiles are attached, delete as necessary - Point[] array2 = new Point[maxStick]; - int projCount = 0; - for (int projIndex = 0; projIndex < Main.maxProjectiles; projIndex++) - { + Point[] array2 = new Point[maxStick]; + int projCount = 0; + for (int projIndex = 0; projIndex < Main.maxProjectiles; projIndex++) + { Projectile proj = Main.projectile[projIndex]; - if (projIndex != projectile.whoAmI && proj.active && proj.owner == Main.myPlayer && proj.type == projectile.type && proj.ai[0] == 1f && proj.ai[1] == (float)npcIndex) - { - array2[projCount++] = new Point(projIndex, proj.timeLeft); - if (projCount >= array2.Length) - { - break; - } - } - } - if (projCount >= array2.Length) - { - int num30 = 0; - for (int m = 1; m < array2.Length; m++) - { - if (array2[m].Y < array2[num30].Y) - { - num30 = m; - } - } - Main.projectile[array2[num30].X].Kill(); - } - } - } - } - } - } - } + if (projIndex != projectile.whoAmI && proj.active && proj.owner == Main.myPlayer && proj.type == projectile.type && proj.ai[0] == 1f && proj.ai[1] == (float)npcIndex) + { + array2[projCount++] = new Point(projIndex, proj.timeLeft); + if (projCount >= array2.Length) + { + break; + } + } + } + if (projCount >= array2.Length) + { + int num30 = 0; + for (int m = 1; m < array2.Length; m++) + { + if (array2[m].Y < array2[num30].Y) + { + num30 = m; + } + } + Main.projectile[array2[num30].X].Kill(); + } + } + } + } + } + } + } public static void StickToTiles(this Projectile projectile, bool ignorePlatforms, bool stickToEverything) { - try - { - int xLeft = (int)(projectile.position.X / 16f) - 1; - int xRight = (int)((projectile.position.X + (float)projectile.width) / 16f) + 2; - int yBottom = (int)(projectile.position.Y / 16f) - 1; - int yTop = (int)((projectile.position.Y + (float)projectile.height) / 16f) + 2; - if (xLeft < 0) - { - xLeft = 0; - } - if (xRight > Main.maxTilesX) - { - xRight = Main.maxTilesX; - } - if (yBottom < 0) - { - yBottom = 0; - } - if (yTop > Main.maxTilesY) - { - yTop = Main.maxTilesY; - } - for (int x = xLeft; x < xRight; x++) - { - for (int y = yBottom; y < yTop; y++) - { + try + { + int xLeft = (int)(projectile.position.X / 16f) - 1; + int xRight = (int)((projectile.position.X + (float)projectile.width) / 16f) + 2; + int yBottom = (int)(projectile.position.Y / 16f) - 1; + int yTop = (int)((projectile.position.Y + (float)projectile.height) / 16f) + 2; + if (xLeft < 0) + { + xLeft = 0; + } + if (xRight > Main.maxTilesX) + { + xRight = Main.maxTilesX; + } + if (yBottom < 0) + { + yBottom = 0; + } + if (yTop > Main.maxTilesY) + { + yTop = Main.maxTilesY; + } + for (int x = xLeft; x < xRight; x++) + { + for (int y = yBottom; y < yTop; y++) + { Tile tile = Main.tile[x, y]; bool platformCheck = true; if (ignorePlatforms) @@ -1104,22 +1078,22 @@ namespace CalamityMod bool tableCheck = false; if (stickToEverything) tableCheck = Main.tileSolidTop[tile.type] && tile.frameY == 0; - if (tile != null && tile.nactive() && platformCheck && (Main.tileSolid[tile.type] || tableCheck)) - { - Vector2 tileSize; - tileSize.X = (float)(x * 16); - tileSize.Y = (float)(y * 16); - if (projectile.position.X + (float)projectile.width - 4f > tileSize.X && projectile.position.X + 4f < tileSize.X + 16f && projectile.position.Y + (float)projectile.height - 4f > tileSize.Y && projectile.position.Y + 4f < tileSize.Y + 16f) - { - projectile.velocity.X = 0f; - projectile.velocity.Y = -0.2f; - } - } - } - } - } catch - { - } + if (tile != null && tile.nactive() && platformCheck && (Main.tileSolid[tile.type] || tableCheck)) + { + Vector2 tileSize; + tileSize.X = (float)(x * 16); + tileSize.Y = (float)(y * 16); + if (projectile.position.X + (float)projectile.width - 4f > tileSize.X && projectile.position.X + 4f < tileSize.X + 16f && projectile.position.Y + (float)projectile.height - 4f > tileSize.Y && projectile.position.Y + 4f < tileSize.Y + 16f) + { + projectile.velocity.X = 0f; + projectile.velocity.Y = -0.2f; + } + } + } + } + } catch + { + } } public static Projectile ProjectileRain(Vector2 targetPos, float xLimit, float xVariance, float yLimitLower, float yLimitUpper, float projSpeed, int projType, int damage, float knockback, int owner, int forceType = 0, int immunitySetting = 0, int cooldown = 10) @@ -1824,10 +1798,10 @@ namespace CalamityMod TileID.DemonAltar, TileID.ElderCrystalStand }; - for (int i = 0; i < tilesToCheck.Count; ++i) + for (int i = 0; i < tilesToCheck.Count; ++i) tileExcludeList.Add(tilesToCheck[i]); List wallExcludeList = new List(); - for (int i = 0; i < wallsToCheck.Count; ++i) + for (int i = 0; i < wallsToCheck.Count; ++i) wallExcludeList.Add(wallsToCheck[i]); List explosionCheckList = new List() @@ -1913,1970 +1887,1970 @@ namespace CalamityMod } } } - #endregion - - #region Tile Utilities - public static void SafeSquareTileFrame(int x, int y, bool resetFrame = true) - { - if (Main.tile[x, y] is null) - return; - - for (int xIter = x - 1; xIter <= x + 1; ++xIter) - { - if (xIter < 0 || xIter >= Main.maxTilesX) - continue; - for (int yIter = y - 1; yIter <= y + 1; yIter++) - { - if (yIter < 0 || yIter >= Main.maxTilesY) - continue; - if (xIter == x && yIter == y) - { - WorldGen.TileFrame(x, y, resetFrame, false); - } - else - { - WorldGen.TileFrame(xIter, yIter, false, false); - } - } - } - } - - public static void LightHitWire(int type, int i, int j, int tileX, int tileY) - { - int x = i - Main.tile[i, j].frameX / 18 % tileX; - int y = j - Main.tile[i, j].frameY / 18 % tileY; - for (int l = x; l < x + tileX; l++) - { - for (int m = y; m < y + tileY; m++) - { - if (Main.tile[l, m] == null) - { - Main.tile[l, m] = new Tile(); - } - if (Main.tile[l, m].active() && Main.tile[l, m].type == type) - { - if (Main.tile[l, m].frameX < (18 * tileX)) - { - Main.tile[l, m].frameX += (short)(18 * tileX); - } - else - { - Main.tile[l, m].frameX -= (short)(18 * tileX); - } - } - } - } - if (Wiring.running) - { - for (int k = 0; k < tileX; k++) - { - for (int l = 0; l < tileY; l++) - { - Wiring.SkipWire(x + k, y + l); - } - } - } - } - - public static void DrawFlameEffect(Texture2D flameTexture, int i, int j, int offsetX = 0, int offsetY = 0) - { - Tile tile = Main.tile[i, j]; - Vector2 zero = Main.drawToScreen ? Vector2.Zero : new Vector2(Main.offScreenRange, Main.offScreenRange); - - int width = 16; - int height = 16; - int yOffset = TileObjectData.GetTileData(tile).DrawYOffset; - - ulong num190 = Main.TileFrameSeed ^ (ulong)((long)j << 32 | (long)(uint)i); - - for (int c = 0; c < 7; c++) - { - float shakeX = Utils.RandomInt(ref num190, -10, 11) * 0.15f; - float shakeY = Utils.RandomInt(ref num190, -10, 1) * 0.35f; - Main.spriteBatch.Draw(flameTexture, new Vector2(i * 16 - (int)Main.screenPosition.X - (width - 16f) / 2f + shakeX, j * 16 - (int)Main.screenPosition.Y + shakeY + yOffset) + zero, new Rectangle(tile.frameX + offsetX, tile.frameY + offsetY, width, height), new Color(100, 100, 100, 0), 0f, default(Vector2), 1f, SpriteEffects.None, 0f); - } - } - - public static void DrawStaticFlameEffect(Texture2D flameTexture, int i, int j, int offsetX = 0, int offsetY = 0) - { - int xPos = Main.tile[i, j].frameX; - int yPos = Main.tile[i, j].frameY; - Color drawColour = new Color(100, 100, 100, 0); - Vector2 zero = Main.drawToScreen ? Vector2.Zero : new Vector2(Main.offScreenRange); - Vector2 drawOffset = new Vector2(i * 16 - Main.screenPosition.X, j * 16 - Main.screenPosition.Y) + zero; - for (int x = -1; x < 2; x++) - { - for (int y = -1; y < 2; y++) - { - Vector2 flameOffset = new Vector2(x, y).SafeNormalize(Vector2.Zero); - flameOffset *= 1.5f; - Main.spriteBatch.Draw(flameTexture, drawOffset + flameOffset, new Rectangle?(new Rectangle(xPos + offsetX, yPos + offsetY, 18, 18)), drawColour, 0.0f, Vector2.Zero, 1f, SpriteEffects.None, 0.0f); - } - } - } - - public static void DrawFlameSparks(int dustType, int rarity, int i, int j) - { - Tile tile = Main.tile[i, j]; - if (!Main.gamePaused && Main.instance.IsActive && (!Lighting.UpdateEveryFrame || Main.rand.NextBool(4))) - { - if (Main.rand.NextBool(rarity)) - { - int dust = Dust.NewDust(new Vector2(i * 16 + 4, j * 16 + 2), 4, 4, dustType, 0f, 0f, 100, default(Color), 1f); - if (Main.rand.Next(3) != 0) - { - Main.dust[dust].noGravity = true; - } - Main.dust[dust].velocity *= 0.3f; - Main.dust[dust].velocity.Y = Main.dust[dust].velocity.Y - 1.5f; - } - } - } - - public static void DrawItemFlame(Texture2D flameTexture, Item item) - { - int width = flameTexture.Width; - int height = flameTexture.Height; - for (int c = 0; c < 7; c++) - { - float shakeX = Main.rand.Next(-10, 11) * 0.15f; - float shakeY = Main.rand.Next(-10, 1) * 0.35f; - Main.spriteBatch.Draw(flameTexture, new Vector2(item.position.X - Main.screenPosition.X + item.width * 0.5f + shakeX, item.position.Y - Main.screenPosition.Y + item.height - flameTexture.Height * 0.5f + 2f + shakeY), new Rectangle(0, 0, width, height), new Color(100, 100, 100, 0), 0f, default(Vector2), 1f, SpriteEffects.None, 0f); - } - } - public static Tile ParanoidTileRetrieval(int x, int y) - { - if (!WorldGen.InWorld(x, y)) - return new Tile(); - Tile tile = Main.tile[x, y]; - if (tile is null) - { - tile = new Tile(); - Main.tile[x, y] = tile; - } - return tile; - } - public static bool TileSelectionSolid(int x, int y, int width, int height) - { - for (int i = x; i != x + width; i += Math.Sign(width)) - { - for (int j = y; y != y + height; j += Math.Sign(height)) - { - if (!WorldGen.InWorld(i, j)) - return false; - if (!WorldGen.SolidTile(Framing.GetTileSafely(i, j))) - return false; - } - } - return true; - } - public static bool TileSelectionSolidSquare(int x, int y, int width, int height) - { - for (int i = x - width; i != x + width; i += Math.Sign(width)) - { - for (int j = y - height; y != y + height; j += Math.Sign(height)) - { - if (!WorldGen.InWorld(i, j)) - return false; - if (!WorldGen.SolidTile(Framing.GetTileSafely(i, j))) - return false; - } - } - return true; - } - public static bool TileActiveAndOfType(int x, int y, int type) - { - return ParanoidTileRetrieval(x, y).active() && ParanoidTileRetrieval(x, y).type == type; - } - - #region Tile Merge Utilities - /// - /// Sets the mergeability state of two tiles. By default, enables tile merging. - /// - /// The first tile type which should merge (or not). - /// The second tile type which should merge (or not). - /// The mergeability state of the tiles. Defaults to true if omitted. - public static void SetMerge(int type1, int type2, bool merge = true) - { - if (type1 != type2) - { - Main.tileMerge[type1][type2] = merge; - Main.tileMerge[type2][type1] = merge; - } - } - - /// - /// Makes the first tile type argument merge with all the other tile type arguments. Also accepts arrays. - /// - /// The tile whose merging properties will be set. - /// Every tile that should be merged with. - public static void MergeWithSet(int myType, params int[] otherTypes) - { - for (int i = 0; i < otherTypes.Length; ++i) - SetMerge(myType, otherTypes[i]); - } - - /// - /// Makes the specified tile merge with the most common types of tiles found in world generation.

- /// Notably excludes Ice. - ///
- /// The tile whose merging properties will be set. - public static void MergeWithGeneral(int type) => MergeWithSet(type, new int[] { - // Soils - TileID.Dirt, - TileID.Mud, - TileID.ClayBlock, - // Stones - TileID.Stone, - TileID.Ebonstone, - TileID.Crimstone, - TileID.Pearlstone, - // Sands - TileID.Sand, - TileID.Ebonsand, - TileID.Crimsand, - TileID.Pearlsand, - // Snows - TileID.SnowBlock, - // Calamity Tiles - ModContent.TileType(), - ModContent.TileType(), - ModContent.TileType(), - ModContent.TileType(), - ModContent.TileType(), - ModContent.TileType(), - ModContent.TileType(), - ModContent.TileType(), - ModContent.TileType(), - }); - - /// - /// Makes the specified tile merge with all ores, vanilla and Calamity. Particularly useful for stone blocks. - /// - /// The tile whose merging properties will be set. - public static void MergeWithOres(int type) => MergeWithSet(type, new int[] { - // Vanilla Ores - TileID.Copper, - TileID.Tin, - TileID.Iron, - TileID.Lead, - TileID.Silver, - TileID.Tungsten, - TileID.Gold, - TileID.Platinum, - TileID.Demonite, - TileID.Crimtane, - TileID.Cobalt, - TileID.Palladium, - TileID.Mythril, - TileID.Orichalcum, - TileID.Adamantite, - TileID.Titanium, - TileID.LunarOre, - // Calamity Ores - ModContent.TileType(), - ModContent.TileType(), - ModContent.TileType(), - ModContent.TileType(), - ModContent.TileType(), - ModContent.TileType(), - ModContent.TileType(), - ModContent.TileType(), - }); - - /// - /// Makes the specified tile merge with all types of desert tiles, including the Calamity Sunken Sea. - /// - /// The tile whose merging properties will be set. - public static void MergeWithDesert(int type) => MergeWithSet(type, new int[] { - // Sands - TileID.Sand, - TileID.Ebonsand, - TileID.Crimsand, - TileID.Pearlsand, - // Hardened Sands - TileID.HardenedSand, - TileID.CorruptHardenedSand, - TileID.CrimsonHardenedSand, - TileID.HallowHardenedSand, - // Sandstones - TileID.Sandstone, - TileID.CorruptSandstone, - TileID.CrimsonSandstone, - TileID.HallowSandstone, - // Miscellaneous Desert Tiles - TileID.FossilOre, - TileID.DesertFossil, - // Astral Desert - ModContent.TileType(), - ModContent.TileType(), - ModContent.TileType(), - ModContent.TileType(), - // Sunken Sea - ModContent.TileType(), - ModContent.TileType(), - ModContent.TileType(), - }); - - /// - /// Makes the specified tile merge with all types of snow and ice tiles. - /// - /// The tile whose merging properties will be set. - public static void MergeWithSnow(int type) => MergeWithSet(type, new int[] { - // Snows - TileID.SnowBlock, - // Ices - TileID.IceBlock, - TileID.CorruptIce, - TileID.FleshIce, - TileID.HallowedIce, - // Astral Snow - ModContent.TileType(), - ModContent.TileType(), - ModContent.TileType(), - }); - - /// - /// Makes the specified tile merge with all tiles which generate in hell. Does not include Charred Ore. - /// - /// The tile whose merging properties will be set. - public static void MergeWithHell(int type) => MergeWithSet(type, new int[] { - TileID.Ash, - TileID.Hellstone, - TileID.ObsidianBrick, - TileID.HellstoneBrick, - ModContent.TileType(), - }); - - /// - /// Makes the specified tile merge with all tiles which generate in the Abyss or the Sulphurous Sea. Includes Chaotic Ore. - /// - /// The tile whose merging properties will be set. - public static void MergeWithAbyss(int type) => MergeWithSet(type, new int[] { - // Sulphurous Sea - ModContent.TileType(), - ModContent.TileType(), - // Abyss - ModContent.TileType(), - ModContent.TileType(), - ModContent.TileType(), - ModContent.TileType(), - ModContent.TileType(), - }); - - /// - /// Makes the tile merge with all the tile types that generate within various types of astral tiles - /// - /// - public static void MergeAstralTiles(int type) - { - //Astral - SetMerge(type, ModContent.TileType()); - SetMerge(type, ModContent.TileType()); - SetMerge(type, ModContent.TileType()); - SetMerge(type, ModContent.TileType()); - //Astral Desert - SetMerge(type, ModContent.TileType()); - SetMerge(type, ModContent.TileType()); - SetMerge(type, ModContent.TileType()); - SetMerge(type, ModContent.TileType()); - //Astral Snow - SetMerge(type, ModContent.TileType()); - SetMerge(type, ModContent.TileType()); - } - - /// - /// Makes the tile merge with all the decorative 'smooth' tiles - /// - /// - public static void MergeSmoothTiles(int type) - { - //Vanilla - SetMerge(type, TileID.MarbleBlock); - SetMerge(type, TileID.GraniteBlock); - //Calam - SetMerge(type, ModContent.TileType()); - SetMerge(type, ModContent.TileType()); - SetMerge(type, ModContent.TileType()); - SetMerge(type, ModContent.TileType()); - } - - /// - /// Makes the tile merge with other mergable decorative tiles - /// - /// - public static void MergeDecorativeTiles(int type) - { - //Vanilla decor - Main.tileBrick[type] = true; - //Calam - SetMerge(type, ModContent.TileType()); - SetMerge(type, ModContent.TileType()); - SetMerge(type, ModContent.TileType()); - SetMerge(type, ModContent.TileType()); - SetMerge(type, ModContent.TileType()); - SetMerge(type, ModContent.TileType()); - SetMerge(type, ModContent.TileType()); - SetMerge(type, ModContent.TileType()); - } - #endregion - - #region Furniture Interaction - public static void RightClickBreak(int i, int j) - { - if (Main.tile[i, j] != null && Main.tile[i, j].active()) - { - WorldGen.KillTile(i, j, false, false, false); - if (!Main.tile[i, j].active() && Main.netMode != NetmodeID.SinglePlayer) - { - NetMessage.SendData(MessageID.TileChange, -1, -1, null, 0, (float)i, (float)j, 0f, 0, 0, 0); - } - } - } - - public static bool BedRightClick(int i, int j) - { - Player player = Main.LocalPlayer; - Tile tile = Main.tile[i, j]; - int spawnX = i - tile.frameX / 18; - int spawnY = j + 2; - spawnX += tile.frameX >= 72 ? 5 : 2; - if (tile.frameY % 38 != 0) - { - spawnY--; - } - player.FindSpawn(); - if (player.SpawnX == spawnX && player.SpawnY == spawnY) - { - player.RemoveSpawn(); - Main.NewText("Spawn point removed!", 255, 240, 20, false); - } - else if (Player.CheckSpawn(spawnX, spawnY)) - { - player.ChangeSpawn(spawnX, spawnY); - Main.NewText("Spawn point set!", 255, 240, 20, false); - } - return true; - } - - public static bool ChestRightClick(int i, int j) - { - Player player = Main.LocalPlayer; - Tile tile = Main.tile[i, j]; - Main.mouseRightRelease = false; - int left = i; - int top = j; - if (tile.frameX % 36 != 0) - { - left--; - } - if (tile.frameY != 0) - { - top--; - } - if (player.sign >= 0) - { - Main.PlaySound(SoundID.MenuClose); - player.sign = -1; - Main.editSign = false; - Main.npcChatText = ""; - } - if (Main.editChest) - { - Main.PlaySound(SoundID.MenuTick); - Main.editChest = false; - Main.npcChatText = ""; - } - if (player.editedChestName) - { - NetMessage.SendData(MessageID.SyncPlayerChest, -1, -1, NetworkText.FromLiteral(Main.chest[player.chest].name), player.chest, 1f, 0f, 0f, 0, 0, 0); - player.editedChestName = false; - } - - if (Main.netMode == NetmodeID.MultiplayerClient) - { - if (left == player.chestX && top == player.chestY && player.chest >= 0) - { - player.chest = -1; - Recipe.FindRecipes(); - Main.PlaySound(SoundID.MenuClose); - } - else - { - NetMessage.SendData(MessageID.RequestChestOpen, -1, -1, null, left, (float)top, 0f, 0f, 0, 0, 0); - Main.stackSplit = 600; - } - } - else - { - int chest = Chest.FindChest(left, top); - if (chest >= 0) - { - Main.stackSplit = 600; - if (chest == player.chest) - { - player.chest = -1; - Main.PlaySound(SoundID.MenuClose); - } - else - { - player.chest = chest; - Main.playerInventory = true; - Main.recBigList = false; - player.chestX = left; - player.chestY = top; - Main.PlaySound(player.chest < 0 ? SoundID.MenuOpen : SoundID.MenuTick); - } - Recipe.FindRecipes(); - } - } - return true; - } - - public static void ChestMouseOver(string chestName, int i, int j) where T : ModItem - { - Player player = Main.LocalPlayer; - Tile tile = Main.tile[i, j]; - int left = i; - int top = j; - if (tile.frameX % 36 != 0) - { - left--; - } - if (tile.frameY != 0) - { - top--; - } - int chest = Chest.FindChest(left, top); - player.showItemIcon2 = -1; - if (chest < 0) - { - player.showItemIconText = Language.GetTextValue("LegacyChestType.0"); - } - else - { - player.showItemIconText = Main.chest[chest].name.Length > 0 ? Main.chest[chest].name : chestName; - if (player.showItemIconText == chestName) - { - player.showItemIcon2 = ModContent.ItemType(); - player.showItemIconText = ""; - } - } - player.noThrow = 2; - player.showItemIcon = true; - } - - public static void ChestMouseFar(string name, int i, int j) where T : ModItem - { - ChestMouseOver(name, i, j); - Player player = Main.LocalPlayer; - if (player.showItemIconText == "") - { - player.showItemIcon = false; - player.showItemIcon2 = 0; - } - } - - public static bool ClockRightClick() - { - string text = "AM"; - - // Get Terraria's current strange time variable - double time = Main.time; - - // Correct for night time (which for some reason isn't just a different number) by adding 54000. - if (!Main.dayTime) - time += 54000D; - - // Divide by seconds in an hour - time /= 3600D; - - // Terraria night starts at 7:30 PM, so offset accordingly - time -= 19.5; - - // Offset time to ensure it is not negative, then change to PM if necessary - if (time < 0D) - time += 24D; - if (time >= 12D) - text = "PM"; - - // Get the decimal (smaller than hours, so minutes) component of time. - int intTime = (int)time; - double deltaTime = time - intTime; - - // Convert decimal time into an exact number of minutes. - deltaTime = (int)(deltaTime * 60D); - - string minuteText = deltaTime.ToString(); - - // Ensure minutes has a leading zero - if (deltaTime < 10D) - minuteText = "0" + minuteText; - - // Convert from 24 to 12 hour time (PM already handled earlier) - if (intTime > 12) - intTime -= 12; - // 12 AM is actually hour zero in 24 hour time - if (intTime == 0) - intTime = 12; - - // Create an overall time readout and send it to chat - var newText = string.Concat("Time: ", intTime, ":", minuteText, " ", text); - Main.NewText(newText, 255, 240, 20); - return true; - } - - public static bool DresserRightClick() - { - Player player = Main.LocalPlayer; - if (Main.tile[Player.tileTargetX, Player.tileTargetY].frameY == 0) - { - Main.CancelClothesWindow(true); - - int left = (int)(Main.tile[Player.tileTargetX, Player.tileTargetY].frameX / 18); - left %= 3; - left = Player.tileTargetX - left; - int top = Player.tileTargetY - (int)(Main.tile[Player.tileTargetX, Player.tileTargetY].frameY / 18); - if (player.sign > -1) - { - Main.PlaySound(SoundID.MenuClose); - player.sign = -1; - Main.editSign = false; - Main.npcChatText = string.Empty; - } - if (Main.editChest) - { - Main.PlaySound(SoundID.MenuTick); - Main.editChest = false; - Main.npcChatText = string.Empty; - } - if (player.editedChestName) - { - NetMessage.SendData(MessageID.SyncPlayerChest, -1, -1, NetworkText.FromLiteral(Main.chest[player.chest].name), player.chest, 1f, 0f, 0f, 0, 0, 0); - player.editedChestName = false; - } - if (Main.netMode == NetmodeID.MultiplayerClient) - { - if (left == player.chestX && top == player.chestY && player.chest != -1) - { - player.chest = -1; - Recipe.FindRecipes(); - Main.PlaySound(SoundID.MenuClose); - } - else - { - NetMessage.SendData(MessageID.RequestChestOpen, -1, -1, null, left, (float)top, 0f, 0f, 0, 0, 0); - Main.stackSplit = 600; - } - return true; - } - else - { - player.flyingPigChest = -1; - int num213 = Chest.FindChest(left, top); - if (num213 != -1) - { - Main.stackSplit = 600; - if (num213 == player.chest) - { - player.chest = -1; - Recipe.FindRecipes(); - Main.PlaySound(SoundID.MenuClose); - } - else if (num213 != player.chest && player.chest == -1) - { - player.chest = num213; - Main.playerInventory = true; - Main.recBigList = false; - Main.PlaySound(SoundID.MenuOpen); - player.chestX = left; - player.chestY = top; - } - else - { - player.chest = num213; - Main.playerInventory = true; - Main.recBigList = false; - Main.PlaySound(SoundID.MenuTick); - player.chestX = left; - player.chestY = top; - } - Recipe.FindRecipes(); - return true; - } - } - } - else - { - Main.playerInventory = false; - player.chest = -1; - Recipe.FindRecipes(); - Main.dresserX = Player.tileTargetX; - Main.dresserY = Player.tileTargetY; - Main.OpenClothesWindow(); - return true; - } - - return false; - } - - public static void DresserMouseFar(string chestName) where T : ModItem - { - Player player = Main.LocalPlayer; - Tile tile = Main.tile[Player.tileTargetX, Player.tileTargetY]; - int left = Player.tileTargetX; - int top = Player.tileTargetY; - left -= (int)(tile.frameX % 54 / 18); - if (tile.frameY % 36 != 0) - { - top--; - } - int chestIndex = Chest.FindChest(left, top); - player.showItemIcon2 = -1; - if (chestIndex < 0) - { - player.showItemIconText = Language.GetTextValue("LegacyDresserType.0"); - } - else - { - if (Main.chest[chestIndex].name != "") - { - player.showItemIconText = Main.chest[chestIndex].name; - } - else - { - player.showItemIconText = chestName; - } - if (player.showItemIconText == chestName) - { - player.showItemIcon2 = ModContent.ItemType(); - player.showItemIconText = ""; - } - } - player.noThrow = 2; - player.showItemIcon = true; - if (player.showItemIconText == "") - { - player.showItemIcon = false; - player.showItemIcon2 = 0; - } - } - - public static void DresserMouseOver(string chestName) where T : ModItem - { - Player player = Main.LocalPlayer; - Tile tile = Main.tile[Player.tileTargetX, Player.tileTargetY]; - int left = Player.tileTargetX; - int top = Player.tileTargetY; - left -= (int)(tile.frameX % 54 / 18); - if (tile.frameY % 36 != 0) - { - top--; - } - int chestIndex = Chest.FindChest(left, top); - player.showItemIcon2 = -1; - if (chestIndex < 0) - { - player.showItemIconText = Language.GetTextValue("LegacyDresserType.0"); - } - else - { - if (Main.chest[chestIndex].name != "") - { - player.showItemIconText = Main.chest[chestIndex].name; - } - else - { - player.showItemIconText = chestName; - } - if (player.showItemIconText == chestName) - { - player.showItemIcon2 = ModContent.ItemType(); - player.showItemIconText = ""; - } - } - player.noThrow = 2; - player.showItemIcon = true; - if (Main.tile[Player.tileTargetX, Player.tileTargetY].frameY > 0) - { - player.showItemIcon2 = ItemID.FamiliarShirt; - } - } - - public static bool LockedChestRightClick(bool isLocked, int left, int top, int i, int j) - { - Player player = Main.LocalPlayer; - - // If the player right clicked the chest while editing a sign, finish that up - if (player.sign >= 0) - { - Main.PlaySound(SoundID.MenuClose); - player.sign = -1; - Main.editSign = false; - Main.npcChatText = ""; - } - - // If the player right clicked the chest while editing a chest, finish that up - if (Main.editChest) - { - Main.PlaySound(SoundID.MenuTick); - Main.editChest = false; - Main.npcChatText = ""; - } - - // If the player right clicked the chest after changing another chest's name, finish that up - if (player.editedChestName) - { - NetMessage.SendData(MessageID.SyncPlayerChest, -1, -1, NetworkText.FromLiteral(Main.chest[player.chest].name), player.chest, 1f, 0f, 0f, 0, 0, 0); - player.editedChestName = false; - } - if (Main.netMode == NetmodeID.MultiplayerClient && !isLocked) - { - // Right clicking the chest you currently have open closes it. This counts as interaction. - if (left == player.chestX && top == player.chestY && player.chest >= 0) - { - player.chest = -1; - Recipe.FindRecipes(); - Main.PlaySound(SoundID.MenuClose); - } - - // Right clicking this chest opens it if it's not already open. This counts as interaction. - else - { - NetMessage.SendData(MessageID.RequestChestOpen, -1, -1, null, left, (float)top, 0f, 0f, 0, 0, 0); - Main.stackSplit = 600; - } - return true; - } - - else - { - if (isLocked) - { - // If you right click the locked chest and you can unlock it, it unlocks itself but does not open. This counts as interaction. - if (Chest.Unlock(left, top)) - { - if (Main.netMode == NetmodeID.MultiplayerClient) - { - NetMessage.SendData(MessageID.Unlock, -1, -1, null, player.whoAmI, 1f, (float)left, (float)top); - } - return true; - } - } - else - { - int chest = Chest.FindChest(left, top); - if (chest >= 0) - { - Main.stackSplit = 600; - - // If you right click the same chest you already have open, it closes. This counts as interaction. - if (chest == player.chest) - { - player.chest = -1; - Main.PlaySound(SoundID.MenuClose); - } - - // If you right click this chest when you have a different chest selected, that one closes and this one opens. This counts as interaction. - else - { - player.chest = chest; - Main.playerInventory = true; - Main.recBigList = false; - player.chestX = left; - player.chestY = top; - Main.PlaySound(player.chest < 0 ? SoundID.MenuOpen : SoundID.MenuTick); - } - - Recipe.FindRecipes(); - return true; - } - } - } - - // This only occurs when the chest is locked and cannot be unlocked. You did not interact with the chest. - return false; - } - - public static void LockedChestMouseOver(string chestName, int i, int j) - where K : ModItem where C : ModItem - { - Player player = Main.LocalPlayer; - Tile tile = Main.tile[i, j]; - int left = i; - int top = j; - if (tile.frameX % 36 != 0) - { - left--; - } - if (tile.frameY != 0) - { - top--; - } - int chest = Chest.FindChest(left, top); - player.showItemIcon2 = -1; - if (chest < 0) - { - player.showItemIconText = Language.GetTextValue("LegacyChestType.0"); - } - else - { - player.showItemIconText = Main.chest[chest].name.Length > 0 ? Main.chest[chest].name : chestName; - if (player.showItemIconText == chestName) - { - player.showItemIcon2 = ModContent.ItemType(); - if (Main.tile[left, top].frameX / 36 == 1) - player.showItemIcon2 = ModContent.ItemType(); - player.showItemIconText = ""; - } - } - player.noThrow = 2; - player.showItemIcon = true; - } - - public static void LockedChestMouseOverFar(string chestName, int i, int j) - where K : ModItem where C : ModItem - { - LockedChestMouseOver(chestName, i, j); - Player player = Main.LocalPlayer; - if (player.showItemIconText == "") - { - player.showItemIcon = false; - player.showItemIcon2 = 0; - } - } - #endregion - - #region Furniture SetDefaults - /// - /// Extension which initializes a ModTile to be a bathtub. - /// - /// The ModTile which is being initialized. - /// Whether this tile is supposed to be immune to lava. Defaults to false. - internal static void SetUpBathtub(this ModTile mt, bool lavaImmune = false) - { - Main.tileLighted[mt.Type] = true; - Main.tileFrameImportant[mt.Type] = true; - Main.tileLavaDeath[mt.Type] = !lavaImmune; - Main.tileWaterDeath[mt.Type] = false; - TileObjectData.newTile.Width = 4; - TileObjectData.newTile.Height = 2; - TileObjectData.newTile.CoordinateHeights = new int[] { 16, 18 }; - TileObjectData.newTile.CoordinateWidth = 16; - TileObjectData.newTile.CoordinatePadding = 2; - TileObjectData.newTile.Direction = TileObjectDirection.PlaceLeft; - TileObjectData.newTile.StyleHorizontal = true; - TileObjectData.newTile.Origin = new Point16(1, 1); - TileObjectData.newTile.UsesCustomCanPlace = true; - TileObjectData.newTile.AnchorBottom = new AnchorData(AnchorType.SolidTile | AnchorType.SolidWithTop, 4, 0); - TileObjectData.newTile.LavaDeath = !lavaImmune; - TileObjectData.newAlternate.CopyFrom(TileObjectData.newTile); - TileObjectData.newAlternate.Direction = TileObjectDirection.PlaceRight; - TileObjectData.addAlternate(1); - TileObjectData.addTile(mt.Type); - - // All bathtubs count as tables. - mt.AddToArray(ref TileID.Sets.RoomNeeds.CountsAsTable); - } - - /// - /// Extension which initializes a ModTile to be a bed. - /// - /// The ModTile which is being initialized. - /// Whether this tile is supposed to be immune to lava. Defaults to false. - internal static void SetUpBed(this ModTile mt, bool lavaImmune = false) - { - Main.tileFrameImportant[mt.Type] = true; - Main.tileLavaDeath[mt.Type] = !lavaImmune; - Main.tileWaterDeath[mt.Type] = false; - TileID.Sets.HasOutlines[mt.Type] = true; - TileObjectData.newTile.Width = 4; - TileObjectData.newTile.Height = 2; - TileObjectData.newTile.CoordinateHeights = new int[] { 16, 18 }; - TileObjectData.newTile.CoordinateWidth = 16; - TileObjectData.newTile.CoordinatePadding = 2; - TileObjectData.newTile.Direction = TileObjectDirection.PlaceLeft; - TileObjectData.newTile.StyleHorizontal = true; - TileObjectData.newTile.Origin = new Point16(1, 1); - TileObjectData.newTile.UsesCustomCanPlace = true; - TileObjectData.newTile.AnchorBottom = new AnchorData(AnchorType.SolidTile | AnchorType.SolidWithTop, 4, 0); - TileObjectData.newTile.LavaDeath = !lavaImmune; - TileObjectData.newAlternate.CopyFrom(TileObjectData.newTile); - TileObjectData.newAlternate.Direction = TileObjectDirection.PlaceRight; - TileObjectData.addAlternate(1); - TileObjectData.addTile(mt.Type); - - // All beds count as chairs. - mt.AddToArray(ref TileID.Sets.RoomNeeds.CountsAsChair); - } - - /// - /// Extension which initializes a ModTile to be a bookcase. - /// - /// The ModTile which is being initialized. - /// Whether this tile is supposed to be immune to lava. Defaults to false. - /// Whether this tile is supposed to have a solid top. Defaults to true. - internal static void SetUpBookcase(this ModTile mt, bool lavaImmune = false, bool solidTop = true) - { - Main.tileSolidTop[mt.Type] = solidTop; - Main.tileLighted[mt.Type] = true; - Main.tileFrameImportant[mt.Type] = true; - Main.tileTable[mt.Type] = solidTop; - Main.tileLavaDeath[mt.Type] = !lavaImmune; - Main.tileWaterDeath[mt.Type] = false; - TileObjectData.newTile.CopyFrom(TileObjectData.Style3x4); - TileObjectData.newTile.LavaDeath = !lavaImmune; - TileObjectData.addTile(mt.Type); - - // All bookcases count as tables. - mt.AddToArray(ref TileID.Sets.RoomNeeds.CountsAsTable); - } - - /// - /// Extension which initializes a ModTile to be a candelabra. - /// - /// The ModTile which is being initialized. - /// Whether this tile is supposed to be immune to lava. Defaults to false. - internal static void SetUpCandelabra(this ModTile mt, bool lavaImmune = false) - { - Main.tileLighted[mt.Type] = true; - Main.tileFrameImportant[mt.Type] = true; - Main.tileLavaDeath[mt.Type] = true; - Main.tileWaterDeath[mt.Type] = false; - TileObjectData.newTile.CopyFrom(TileObjectData.Style2x2); - TileObjectData.newTile.LavaDeath = !lavaImmune; - TileObjectData.addTile(mt.Type); - - // All candelabras count as light sources. - mt.AddToArray(ref TileID.Sets.RoomNeeds.CountsAsTorch); - } - - /// - /// Extension which initializes a ModTile to be a candle. - /// - /// The ModTile which is being initialized. - /// Whether this tile is supposed to be immune to lava. Defaults to false. - internal static void SetUpCandle(this ModTile mt, bool lavaImmune = false) - { - Main.tileLighted[mt.Type] = true; - Main.tileFrameImportant[mt.Type] = true; - Main.tileLavaDeath[mt.Type] = !lavaImmune; - Main.tileWaterDeath[mt.Type] = false; - TileObjectData.newTile.CopyFrom(TileObjectData.StyleOnTable1x1); - TileObjectData.newTile.CoordinateHeights = new int[] { 20 }; - TileObjectData.newTile.LavaDeath = !lavaImmune; - TileObjectData.newTile.DrawYOffset = -4; - TileObjectData.addTile(mt.Type); - - // All candles count as light sources. - mt.AddToArray(ref TileID.Sets.RoomNeeds.CountsAsTorch); - } - - /// - /// Extension which initializes a ModTile to be a chair. - /// - /// The ModTile which is being initialized. - /// Whether this tile is supposed to be immune to lava. Defaults to false. - internal static void SetUpChair(this ModTile mt, bool lavaImmune = false) - { - Main.tileFrameImportant[mt.Type] = true; - Main.tileNoAttach[mt.Type] = true; - Main.tileLavaDeath[mt.Type] = !lavaImmune; - Main.tileWaterDeath[mt.Type] = false; - TileObjectData.newTile.CopyFrom(TileObjectData.Style1x2); - TileObjectData.newTile.CoordinateHeights = new int[] { 16, 18 }; - TileObjectData.newTile.Direction = TileObjectDirection.PlaceLeft; - TileObjectData.newTile.StyleWrapLimit = 2; - TileObjectData.newTile.StyleMultiplier = 2; - TileObjectData.newTile.StyleHorizontal = true; - TileObjectData.newTile.LavaDeath = !lavaImmune; - TileObjectData.newAlternate.CopyFrom(TileObjectData.newTile); - TileObjectData.newAlternate.Direction = TileObjectDirection.PlaceRight; - TileObjectData.addAlternate(1); - TileObjectData.addTile(mt.Type); - - // As you could probably guess, all chairs count as chairs. - mt.AddToArray(ref TileID.Sets.RoomNeeds.CountsAsChair); - } - - /// - /// Extension which initializes a ModTile to be a chandelier. - /// - /// The ModTile which is being initialized. - /// Whether this tile is supposed to be immune to lava. Defaults to false. - internal static void SetUpChandelier(this ModTile mt, bool lavaImmune = false) - { - Main.tileLighted[mt.Type] = true; - Main.tileFrameImportant[mt.Type] = true; - Main.tileNoAttach[mt.Type] = true; - Main.tileLavaDeath[mt.Type] = !lavaImmune; - Main.tileWaterDeath[mt.Type] = false; - TileObjectData.newTile.Width = 3; - TileObjectData.newTile.Height = 3; - TileObjectData.newTile.CoordinateHeights = new int[] { 16, 16, 16 }; - TileObjectData.newTile.CoordinateWidth = 16; - TileObjectData.newTile.CoordinatePadding = 2; - TileObjectData.newTile.Origin = new Point16(1, 0); - TileObjectData.newTile.UsesCustomCanPlace = true; - TileObjectData.newTile.AnchorTop = new AnchorData(AnchorType.SolidTile, 1, 1); - TileObjectData.newTile.LavaDeath = !lavaImmune; - TileObjectData.addTile(mt.Type); - - // All chandeliers count as light sources. - mt.AddToArray(ref TileID.Sets.RoomNeeds.CountsAsTorch); - } - - /// - /// Extension which initializes a ModTile to be a chest. - /// - /// The ModTile which is being initialized. - internal static void SetUpChest(this ModTile mt, bool offset = false) - { - Main.tileSpelunker[mt.Type] = true; - Main.tileContainer[mt.Type] = true; - Main.tileShine2[mt.Type] = true; - Main.tileShine[mt.Type] = 1200; - Main.tileFrameImportant[mt.Type] = true; - Main.tileNoAttach[mt.Type] = true; - Main.tileValue[mt.Type] = 500; - TileID.Sets.HasOutlines[mt.Type] = true; - TileObjectData.newTile.CopyFrom(TileObjectData.Style2x2); + #endregion + + #region Tile Utilities + public static void SafeSquareTileFrame(int x, int y, bool resetFrame = true) + { + if (Main.tile[x, y] is null) + return; + + for (int xIter = x - 1; xIter <= x + 1; ++xIter) + { + if (xIter < 0 || xIter >= Main.maxTilesX) + continue; + for (int yIter = y - 1; yIter <= y + 1; yIter++) + { + if (yIter < 0 || yIter >= Main.maxTilesY) + continue; + if (xIter == x && yIter == y) + { + WorldGen.TileFrame(x, y, resetFrame, false); + } + else + { + WorldGen.TileFrame(xIter, yIter, false, false); + } + } + } + } + + public static void LightHitWire(int type, int i, int j, int tileX, int tileY) + { + int x = i - Main.tile[i, j].frameX / 18 % tileX; + int y = j - Main.tile[i, j].frameY / 18 % tileY; + for (int l = x; l < x + tileX; l++) + { + for (int m = y; m < y + tileY; m++) + { + if (Main.tile[l, m] == null) + { + Main.tile[l, m] = new Tile(); + } + if (Main.tile[l, m].active() && Main.tile[l, m].type == type) + { + if (Main.tile[l, m].frameX < (18 * tileX)) + { + Main.tile[l, m].frameX += (short)(18 * tileX); + } + else + { + Main.tile[l, m].frameX -= (short)(18 * tileX); + } + } + } + } + if (Wiring.running) + { + for (int k = 0; k < tileX; k++) + { + for (int l = 0; l < tileY; l++) + { + Wiring.SkipWire(x + k, y + l); + } + } + } + } + + public static void DrawFlameEffect(Texture2D flameTexture, int i, int j, int offsetX = 0, int offsetY = 0) + { + Tile tile = Main.tile[i, j]; + Vector2 zero = Main.drawToScreen ? Vector2.Zero : new Vector2(Main.offScreenRange, Main.offScreenRange); + + int width = 16; + int height = 16; + int yOffset = TileObjectData.GetTileData(tile).DrawYOffset; + + ulong num190 = Main.TileFrameSeed ^ (ulong)((long)j << 32 | (long)(uint)i); + + for (int c = 0; c < 7; c++) + { + float shakeX = Utils.RandomInt(ref num190, -10, 11) * 0.15f; + float shakeY = Utils.RandomInt(ref num190, -10, 1) * 0.35f; + Main.spriteBatch.Draw(flameTexture, new Vector2(i * 16 - (int)Main.screenPosition.X - (width - 16f) / 2f + shakeX, j * 16 - (int)Main.screenPosition.Y + shakeY + yOffset) + zero, new Rectangle(tile.frameX + offsetX, tile.frameY + offsetY, width, height), new Color(100, 100, 100, 0), 0f, default(Vector2), 1f, SpriteEffects.None, 0f); + } + } + + public static void DrawStaticFlameEffect(Texture2D flameTexture, int i, int j, int offsetX = 0, int offsetY = 0) + { + int xPos = Main.tile[i, j].frameX; + int yPos = Main.tile[i, j].frameY; + Color drawColour = new Color(100, 100, 100, 0); + Vector2 zero = Main.drawToScreen ? Vector2.Zero : new Vector2(Main.offScreenRange); + Vector2 drawOffset = new Vector2(i * 16 - Main.screenPosition.X, j * 16 - Main.screenPosition.Y) + zero; + for (int x = -1; x < 2; x++) + { + for (int y = -1; y < 2; y++) + { + Vector2 flameOffset = new Vector2(x, y).SafeNormalize(Vector2.Zero); + flameOffset *= 1.5f; + Main.spriteBatch.Draw(flameTexture, drawOffset + flameOffset, new Rectangle?(new Rectangle(xPos + offsetX, yPos + offsetY, 18, 18)), drawColour, 0.0f, Vector2.Zero, 1f, SpriteEffects.None, 0.0f); + } + } + } + + public static void DrawFlameSparks(int dustType, int rarity, int i, int j) + { + Tile tile = Main.tile[i, j]; + if (!Main.gamePaused && Main.instance.IsActive && (!Lighting.UpdateEveryFrame || Main.rand.NextBool(4))) + { + if (Main.rand.NextBool(rarity)) + { + int dust = Dust.NewDust(new Vector2(i * 16 + 4, j * 16 + 2), 4, 4, dustType, 0f, 0f, 100, default(Color), 1f); + if (Main.rand.Next(3) != 0) + { + Main.dust[dust].noGravity = true; + } + Main.dust[dust].velocity *= 0.3f; + Main.dust[dust].velocity.Y = Main.dust[dust].velocity.Y - 1.5f; + } + } + } + + public static void DrawItemFlame(Texture2D flameTexture, Item item) + { + int width = flameTexture.Width; + int height = flameTexture.Height; + for (int c = 0; c < 7; c++) + { + float shakeX = Main.rand.Next(-10, 11) * 0.15f; + float shakeY = Main.rand.Next(-10, 1) * 0.35f; + Main.spriteBatch.Draw(flameTexture, new Vector2(item.position.X - Main.screenPosition.X + item.width * 0.5f + shakeX, item.position.Y - Main.screenPosition.Y + item.height - flameTexture.Height * 0.5f + 2f + shakeY), new Rectangle(0, 0, width, height), new Color(100, 100, 100, 0), 0f, default(Vector2), 1f, SpriteEffects.None, 0f); + } + } + public static Tile ParanoidTileRetrieval(int x, int y) + { + if (!WorldGen.InWorld(x, y)) + return new Tile(); + Tile tile = Main.tile[x, y]; + if (tile is null) + { + tile = new Tile(); + Main.tile[x, y] = tile; + } + return tile; + } + public static bool TileSelectionSolid(int x, int y, int width, int height) + { + for (int i = x; i != x + width; i += Math.Sign(width)) + { + for (int j = y; y != y + height; j += Math.Sign(height)) + { + if (!WorldGen.InWorld(i, j)) + return false; + if (!WorldGen.SolidTile(Framing.GetTileSafely(i, j))) + return false; + } + } + return true; + } + public static bool TileSelectionSolidSquare(int x, int y, int width, int height) + { + for (int i = x - width; i != x + width; i += Math.Sign(width)) + { + for (int j = y - height; y != y + height; j += Math.Sign(height)) + { + if (!WorldGen.InWorld(i, j)) + return false; + if (!WorldGen.SolidTile(Framing.GetTileSafely(i, j))) + return false; + } + } + return true; + } + public static bool TileActiveAndOfType(int x, int y, int type) + { + return ParanoidTileRetrieval(x, y).active() && ParanoidTileRetrieval(x, y).type == type; + } + + #region Tile Merge Utilities + /// + /// Sets the mergeability state of two tiles. By default, enables tile merging. + /// + /// The first tile type which should merge (or not). + /// The second tile type which should merge (or not). + /// The mergeability state of the tiles. Defaults to true if omitted. + public static void SetMerge(int type1, int type2, bool merge = true) + { + if (type1 != type2) + { + Main.tileMerge[type1][type2] = merge; + Main.tileMerge[type2][type1] = merge; + } + } + + /// + /// Makes the first tile type argument merge with all the other tile type arguments. Also accepts arrays. + /// + /// The tile whose merging properties will be set. + /// Every tile that should be merged with. + public static void MergeWithSet(int myType, params int[] otherTypes) + { + for (int i = 0; i < otherTypes.Length; ++i) + SetMerge(myType, otherTypes[i]); + } + + /// + /// Makes the specified tile merge with the most common types of tiles found in world generation.

+ /// Notably excludes Ice. + ///
+ /// The tile whose merging properties will be set. + public static void MergeWithGeneral(int type) => MergeWithSet(type, new int[] { + // Soils + TileID.Dirt, + TileID.Mud, + TileID.ClayBlock, + // Stones + TileID.Stone, + TileID.Ebonstone, + TileID.Crimstone, + TileID.Pearlstone, + // Sands + TileID.Sand, + TileID.Ebonsand, + TileID.Crimsand, + TileID.Pearlsand, + // Snows + TileID.SnowBlock, + // Calamity Tiles + ModContent.TileType(), + ModContent.TileType(), + ModContent.TileType(), + ModContent.TileType(), + ModContent.TileType(), + ModContent.TileType(), + ModContent.TileType(), + ModContent.TileType(), + ModContent.TileType(), + }); + + /// + /// Makes the specified tile merge with all ores, vanilla and Calamity. Particularly useful for stone blocks. + /// + /// The tile whose merging properties will be set. + public static void MergeWithOres(int type) => MergeWithSet(type, new int[] { + // Vanilla Ores + TileID.Copper, + TileID.Tin, + TileID.Iron, + TileID.Lead, + TileID.Silver, + TileID.Tungsten, + TileID.Gold, + TileID.Platinum, + TileID.Demonite, + TileID.Crimtane, + TileID.Cobalt, + TileID.Palladium, + TileID.Mythril, + TileID.Orichalcum, + TileID.Adamantite, + TileID.Titanium, + TileID.LunarOre, + // Calamity Ores + ModContent.TileType(), + ModContent.TileType(), + ModContent.TileType(), + ModContent.TileType(), + ModContent.TileType(), + ModContent.TileType(), + ModContent.TileType(), + ModContent.TileType(), + }); + + /// + /// Makes the specified tile merge with all types of desert tiles, including the Calamity Sunken Sea. + /// + /// The tile whose merging properties will be set. + public static void MergeWithDesert(int type) => MergeWithSet(type, new int[] { + // Sands + TileID.Sand, + TileID.Ebonsand, + TileID.Crimsand, + TileID.Pearlsand, + // Hardened Sands + TileID.HardenedSand, + TileID.CorruptHardenedSand, + TileID.CrimsonHardenedSand, + TileID.HallowHardenedSand, + // Sandstones + TileID.Sandstone, + TileID.CorruptSandstone, + TileID.CrimsonSandstone, + TileID.HallowSandstone, + // Miscellaneous Desert Tiles + TileID.FossilOre, + TileID.DesertFossil, + // Astral Desert + ModContent.TileType(), + ModContent.TileType(), + ModContent.TileType(), + ModContent.TileType(), + // Sunken Sea + ModContent.TileType(), + ModContent.TileType(), + ModContent.TileType(), + }); + + /// + /// Makes the specified tile merge with all types of snow and ice tiles. + /// + /// The tile whose merging properties will be set. + public static void MergeWithSnow(int type) => MergeWithSet(type, new int[] { + // Snows + TileID.SnowBlock, + // Ices + TileID.IceBlock, + TileID.CorruptIce, + TileID.FleshIce, + TileID.HallowedIce, + // Astral Snow + ModContent.TileType(), + ModContent.TileType(), + ModContent.TileType(), + }); + + /// + /// Makes the specified tile merge with all tiles which generate in hell. Does not include Charred Ore. + /// + /// The tile whose merging properties will be set. + public static void MergeWithHell(int type) => MergeWithSet(type, new int[] { + TileID.Ash, + TileID.Hellstone, + TileID.ObsidianBrick, + TileID.HellstoneBrick, + ModContent.TileType(), + }); + + /// + /// Makes the specified tile merge with all tiles which generate in the Abyss or the Sulphurous Sea. Includes Chaotic Ore. + /// + /// The tile whose merging properties will be set. + public static void MergeWithAbyss(int type) => MergeWithSet(type, new int[] { + // Sulphurous Sea + ModContent.TileType(), + ModContent.TileType(), + // Abyss + ModContent.TileType(), + ModContent.TileType(), + ModContent.TileType(), + ModContent.TileType(), + ModContent.TileType(), + }); + + /// + /// Makes the tile merge with all the tile types that generate within various types of astral tiles + /// + /// + public static void MergeAstralTiles(int type) + { + //Astral + SetMerge(type, ModContent.TileType()); + SetMerge(type, ModContent.TileType()); + SetMerge(type, ModContent.TileType()); + SetMerge(type, ModContent.TileType()); + //Astral Desert + SetMerge(type, ModContent.TileType()); + SetMerge(type, ModContent.TileType()); + SetMerge(type, ModContent.TileType()); + SetMerge(type, ModContent.TileType()); + //Astral Snow + SetMerge(type, ModContent.TileType()); + SetMerge(type, ModContent.TileType()); + } + + /// + /// Makes the tile merge with all the decorative 'smooth' tiles + /// + /// + public static void MergeSmoothTiles(int type) + { + //Vanilla + SetMerge(type, TileID.MarbleBlock); + SetMerge(type, TileID.GraniteBlock); + //Calam + SetMerge(type, ModContent.TileType()); + SetMerge(type, ModContent.TileType()); + SetMerge(type, ModContent.TileType()); + SetMerge(type, ModContent.TileType()); + } + + /// + /// Makes the tile merge with other mergable decorative tiles + /// + /// + public static void MergeDecorativeTiles(int type) + { + //Vanilla decor + Main.tileBrick[type] = true; + //Calam + SetMerge(type, ModContent.TileType()); + SetMerge(type, ModContent.TileType()); + SetMerge(type, ModContent.TileType()); + SetMerge(type, ModContent.TileType()); + SetMerge(type, ModContent.TileType()); + SetMerge(type, ModContent.TileType()); + SetMerge(type, ModContent.TileType()); + SetMerge(type, ModContent.TileType()); + } + #endregion + + #region Furniture Interaction + public static void RightClickBreak(int i, int j) + { + if (Main.tile[i, j] != null && Main.tile[i, j].active()) + { + WorldGen.KillTile(i, j, false, false, false); + if (!Main.tile[i, j].active() && Main.netMode != NetmodeID.SinglePlayer) + { + NetMessage.SendData(MessageID.TileChange, -1, -1, null, 0, (float)i, (float)j, 0f, 0, 0, 0); + } + } + } + + public static bool BedRightClick(int i, int j) + { + Player player = Main.LocalPlayer; + Tile tile = Main.tile[i, j]; + int spawnX = i - tile.frameX / 18; + int spawnY = j + 2; + spawnX += tile.frameX >= 72 ? 5 : 2; + if (tile.frameY % 38 != 0) + { + spawnY--; + } + player.FindSpawn(); + if (player.SpawnX == spawnX && player.SpawnY == spawnY) + { + player.RemoveSpawn(); + Main.NewText("Spawn point removed!", 255, 240, 20, false); + } + else if (Player.CheckSpawn(spawnX, spawnY)) + { + player.ChangeSpawn(spawnX, spawnY); + Main.NewText("Spawn point set!", 255, 240, 20, false); + } + return true; + } + + public static bool ChestRightClick(int i, int j) + { + Player player = Main.LocalPlayer; + Tile tile = Main.tile[i, j]; + Main.mouseRightRelease = false; + int left = i; + int top = j; + if (tile.frameX % 36 != 0) + { + left--; + } + if (tile.frameY != 0) + { + top--; + } + if (player.sign >= 0) + { + Main.PlaySound(SoundID.MenuClose); + player.sign = -1; + Main.editSign = false; + Main.npcChatText = ""; + } + if (Main.editChest) + { + Main.PlaySound(SoundID.MenuTick); + Main.editChest = false; + Main.npcChatText = ""; + } + if (player.editedChestName) + { + NetMessage.SendData(MessageID.SyncPlayerChest, -1, -1, NetworkText.FromLiteral(Main.chest[player.chest].name), player.chest, 1f, 0f, 0f, 0, 0, 0); + player.editedChestName = false; + } + + if (Main.netMode == NetmodeID.MultiplayerClient) + { + if (left == player.chestX && top == player.chestY && player.chest >= 0) + { + player.chest = -1; + Recipe.FindRecipes(); + Main.PlaySound(SoundID.MenuClose); + } + else + { + NetMessage.SendData(MessageID.RequestChestOpen, -1, -1, null, left, (float)top, 0f, 0f, 0, 0, 0); + Main.stackSplit = 600; + } + } + else + { + int chest = Chest.FindChest(left, top); + if (chest >= 0) + { + Main.stackSplit = 600; + if (chest == player.chest) + { + player.chest = -1; + Main.PlaySound(SoundID.MenuClose); + } + else + { + player.chest = chest; + Main.playerInventory = true; + Main.recBigList = false; + player.chestX = left; + player.chestY = top; + Main.PlaySound(player.chest < 0 ? SoundID.MenuOpen : SoundID.MenuTick); + } + Recipe.FindRecipes(); + } + } + return true; + } + + public static void ChestMouseOver(string chestName, int i, int j) where T : ModItem + { + Player player = Main.LocalPlayer; + Tile tile = Main.tile[i, j]; + int left = i; + int top = j; + if (tile.frameX % 36 != 0) + { + left--; + } + if (tile.frameY != 0) + { + top--; + } + int chest = Chest.FindChest(left, top); + player.showItemIcon2 = -1; + if (chest < 0) + { + player.showItemIconText = Language.GetTextValue("LegacyChestType.0"); + } + else + { + player.showItemIconText = Main.chest[chest].name.Length > 0 ? Main.chest[chest].name : chestName; + if (player.showItemIconText == chestName) + { + player.showItemIcon2 = ModContent.ItemType(); + player.showItemIconText = ""; + } + } + player.noThrow = 2; + player.showItemIcon = true; + } + + public static void ChestMouseFar(string name, int i, int j) where T : ModItem + { + ChestMouseOver(name, i, j); + Player player = Main.LocalPlayer; + if (player.showItemIconText == "") + { + player.showItemIcon = false; + player.showItemIcon2 = 0; + } + } + + public static bool ClockRightClick() + { + string text = "AM"; + + // Get Terraria's current strange time variable + double time = Main.time; + + // Correct for night time (which for some reason isn't just a different number) by adding 54000. + if (!Main.dayTime) + time += 54000D; + + // Divide by seconds in an hour + time /= 3600D; + + // Terraria night starts at 7:30 PM, so offset accordingly + time -= 19.5; + + // Offset time to ensure it is not negative, then change to PM if necessary + if (time < 0D) + time += 24D; + if (time >= 12D) + text = "PM"; + + // Get the decimal (smaller than hours, so minutes) component of time. + int intTime = (int)time; + double deltaTime = time - intTime; + + // Convert decimal time into an exact number of minutes. + deltaTime = (int)(deltaTime * 60D); + + string minuteText = deltaTime.ToString(); + + // Ensure minutes has a leading zero + if (deltaTime < 10D) + minuteText = "0" + minuteText; + + // Convert from 24 to 12 hour time (PM already handled earlier) + if (intTime > 12) + intTime -= 12; + // 12 AM is actually hour zero in 24 hour time + if (intTime == 0) + intTime = 12; + + // Create an overall time readout and send it to chat + var newText = string.Concat("Time: ", intTime, ":", minuteText, " ", text); + Main.NewText(newText, 255, 240, 20); + return true; + } + + public static bool DresserRightClick() + { + Player player = Main.LocalPlayer; + if (Main.tile[Player.tileTargetX, Player.tileTargetY].frameY == 0) + { + Main.CancelClothesWindow(true); + + int left = (int)(Main.tile[Player.tileTargetX, Player.tileTargetY].frameX / 18); + left %= 3; + left = Player.tileTargetX - left; + int top = Player.tileTargetY - (int)(Main.tile[Player.tileTargetX, Player.tileTargetY].frameY / 18); + if (player.sign > -1) + { + Main.PlaySound(SoundID.MenuClose); + player.sign = -1; + Main.editSign = false; + Main.npcChatText = string.Empty; + } + if (Main.editChest) + { + Main.PlaySound(SoundID.MenuTick); + Main.editChest = false; + Main.npcChatText = string.Empty; + } + if (player.editedChestName) + { + NetMessage.SendData(MessageID.SyncPlayerChest, -1, -1, NetworkText.FromLiteral(Main.chest[player.chest].name), player.chest, 1f, 0f, 0f, 0, 0, 0); + player.editedChestName = false; + } + if (Main.netMode == NetmodeID.MultiplayerClient) + { + if (left == player.chestX && top == player.chestY && player.chest != -1) + { + player.chest = -1; + Recipe.FindRecipes(); + Main.PlaySound(SoundID.MenuClose); + } + else + { + NetMessage.SendData(MessageID.RequestChestOpen, -1, -1, null, left, (float)top, 0f, 0f, 0, 0, 0); + Main.stackSplit = 600; + } + return true; + } + else + { + player.flyingPigChest = -1; + int num213 = Chest.FindChest(left, top); + if (num213 != -1) + { + Main.stackSplit = 600; + if (num213 == player.chest) + { + player.chest = -1; + Recipe.FindRecipes(); + Main.PlaySound(SoundID.MenuClose); + } + else if (num213 != player.chest && player.chest == -1) + { + player.chest = num213; + Main.playerInventory = true; + Main.recBigList = false; + Main.PlaySound(SoundID.MenuOpen); + player.chestX = left; + player.chestY = top; + } + else + { + player.chest = num213; + Main.playerInventory = true; + Main.recBigList = false; + Main.PlaySound(SoundID.MenuTick); + player.chestX = left; + player.chestY = top; + } + Recipe.FindRecipes(); + return true; + } + } + } + else + { + Main.playerInventory = false; + player.chest = -1; + Recipe.FindRecipes(); + Main.dresserX = Player.tileTargetX; + Main.dresserY = Player.tileTargetY; + Main.OpenClothesWindow(); + return true; + } + + return false; + } + + public static void DresserMouseFar(string chestName) where T : ModItem + { + Player player = Main.LocalPlayer; + Tile tile = Main.tile[Player.tileTargetX, Player.tileTargetY]; + int left = Player.tileTargetX; + int top = Player.tileTargetY; + left -= (int)(tile.frameX % 54 / 18); + if (tile.frameY % 36 != 0) + { + top--; + } + int chestIndex = Chest.FindChest(left, top); + player.showItemIcon2 = -1; + if (chestIndex < 0) + { + player.showItemIconText = Language.GetTextValue("LegacyDresserType.0"); + } + else + { + if (Main.chest[chestIndex].name != "") + { + player.showItemIconText = Main.chest[chestIndex].name; + } + else + { + player.showItemIconText = chestName; + } + if (player.showItemIconText == chestName) + { + player.showItemIcon2 = ModContent.ItemType(); + player.showItemIconText = ""; + } + } + player.noThrow = 2; + player.showItemIcon = true; + if (player.showItemIconText == "") + { + player.showItemIcon = false; + player.showItemIcon2 = 0; + } + } + + public static void DresserMouseOver(string chestName) where T : ModItem + { + Player player = Main.LocalPlayer; + Tile tile = Main.tile[Player.tileTargetX, Player.tileTargetY]; + int left = Player.tileTargetX; + int top = Player.tileTargetY; + left -= (int)(tile.frameX % 54 / 18); + if (tile.frameY % 36 != 0) + { + top--; + } + int chestIndex = Chest.FindChest(left, top); + player.showItemIcon2 = -1; + if (chestIndex < 0) + { + player.showItemIconText = Language.GetTextValue("LegacyDresserType.0"); + } + else + { + if (Main.chest[chestIndex].name != "") + { + player.showItemIconText = Main.chest[chestIndex].name; + } + else + { + player.showItemIconText = chestName; + } + if (player.showItemIconText == chestName) + { + player.showItemIcon2 = ModContent.ItemType(); + player.showItemIconText = ""; + } + } + player.noThrow = 2; + player.showItemIcon = true; + if (Main.tile[Player.tileTargetX, Player.tileTargetY].frameY > 0) + { + player.showItemIcon2 = ItemID.FamiliarShirt; + } + } + + public static bool LockedChestRightClick(bool isLocked, int left, int top, int i, int j) + { + Player player = Main.LocalPlayer; + + // If the player right clicked the chest while editing a sign, finish that up + if (player.sign >= 0) + { + Main.PlaySound(SoundID.MenuClose); + player.sign = -1; + Main.editSign = false; + Main.npcChatText = ""; + } + + // If the player right clicked the chest while editing a chest, finish that up + if (Main.editChest) + { + Main.PlaySound(SoundID.MenuTick); + Main.editChest = false; + Main.npcChatText = ""; + } + + // If the player right clicked the chest after changing another chest's name, finish that up + if (player.editedChestName) + { + NetMessage.SendData(MessageID.SyncPlayerChest, -1, -1, NetworkText.FromLiteral(Main.chest[player.chest].name), player.chest, 1f, 0f, 0f, 0, 0, 0); + player.editedChestName = false; + } + if (Main.netMode == NetmodeID.MultiplayerClient && !isLocked) + { + // Right clicking the chest you currently have open closes it. This counts as interaction. + if (left == player.chestX && top == player.chestY && player.chest >= 0) + { + player.chest = -1; + Recipe.FindRecipes(); + Main.PlaySound(SoundID.MenuClose); + } + + // Right clicking this chest opens it if it's not already open. This counts as interaction. + else + { + NetMessage.SendData(MessageID.RequestChestOpen, -1, -1, null, left, (float)top, 0f, 0f, 0, 0, 0); + Main.stackSplit = 600; + } + return true; + } + + else + { + if (isLocked) + { + // If you right click the locked chest and you can unlock it, it unlocks itself but does not open. This counts as interaction. + if (Chest.Unlock(left, top)) + { + if (Main.netMode == NetmodeID.MultiplayerClient) + { + NetMessage.SendData(MessageID.Unlock, -1, -1, null, player.whoAmI, 1f, (float)left, (float)top); + } + return true; + } + } + else + { + int chest = Chest.FindChest(left, top); + if (chest >= 0) + { + Main.stackSplit = 600; + + // If you right click the same chest you already have open, it closes. This counts as interaction. + if (chest == player.chest) + { + player.chest = -1; + Main.PlaySound(SoundID.MenuClose); + } + + // If you right click this chest when you have a different chest selected, that one closes and this one opens. This counts as interaction. + else + { + player.chest = chest; + Main.playerInventory = true; + Main.recBigList = false; + player.chestX = left; + player.chestY = top; + Main.PlaySound(player.chest < 0 ? SoundID.MenuOpen : SoundID.MenuTick); + } + + Recipe.FindRecipes(); + return true; + } + } + } + + // This only occurs when the chest is locked and cannot be unlocked. You did not interact with the chest. + return false; + } + + public static void LockedChestMouseOver(string chestName, int i, int j) + where K : ModItem where C : ModItem + { + Player player = Main.LocalPlayer; + Tile tile = Main.tile[i, j]; + int left = i; + int top = j; + if (tile.frameX % 36 != 0) + { + left--; + } + if (tile.frameY != 0) + { + top--; + } + int chest = Chest.FindChest(left, top); + player.showItemIcon2 = -1; + if (chest < 0) + { + player.showItemIconText = Language.GetTextValue("LegacyChestType.0"); + } + else + { + player.showItemIconText = Main.chest[chest].name.Length > 0 ? Main.chest[chest].name : chestName; + if (player.showItemIconText == chestName) + { + player.showItemIcon2 = ModContent.ItemType(); + if (Main.tile[left, top].frameX / 36 == 1) + player.showItemIcon2 = ModContent.ItemType(); + player.showItemIconText = ""; + } + } + player.noThrow = 2; + player.showItemIcon = true; + } + + public static void LockedChestMouseOverFar(string chestName, int i, int j) + where K : ModItem where C : ModItem + { + LockedChestMouseOver(chestName, i, j); + Player player = Main.LocalPlayer; + if (player.showItemIconText == "") + { + player.showItemIcon = false; + player.showItemIcon2 = 0; + } + } + #endregion + + #region Furniture SetDefaults + /// + /// Extension which initializes a ModTile to be a bathtub. + /// + /// The ModTile which is being initialized. + /// Whether this tile is supposed to be immune to lava. Defaults to false. + internal static void SetUpBathtub(this ModTile mt, bool lavaImmune = false) + { + Main.tileLighted[mt.Type] = true; + Main.tileFrameImportant[mt.Type] = true; + Main.tileLavaDeath[mt.Type] = !lavaImmune; + Main.tileWaterDeath[mt.Type] = false; + TileObjectData.newTile.Width = 4; + TileObjectData.newTile.Height = 2; + TileObjectData.newTile.CoordinateHeights = new int[] { 16, 18 }; + TileObjectData.newTile.CoordinateWidth = 16; + TileObjectData.newTile.CoordinatePadding = 2; + TileObjectData.newTile.Direction = TileObjectDirection.PlaceLeft; + TileObjectData.newTile.StyleHorizontal = true; + TileObjectData.newTile.Origin = new Point16(1, 1); + TileObjectData.newTile.UsesCustomCanPlace = true; + TileObjectData.newTile.AnchorBottom = new AnchorData(AnchorType.SolidTile | AnchorType.SolidWithTop, 4, 0); + TileObjectData.newTile.LavaDeath = !lavaImmune; + TileObjectData.newAlternate.CopyFrom(TileObjectData.newTile); + TileObjectData.newAlternate.Direction = TileObjectDirection.PlaceRight; + TileObjectData.addAlternate(1); + TileObjectData.addTile(mt.Type); + + // All bathtubs count as tables. + mt.AddToArray(ref TileID.Sets.RoomNeeds.CountsAsTable); + } + + /// + /// Extension which initializes a ModTile to be a bed. + /// + /// The ModTile which is being initialized. + /// Whether this tile is supposed to be immune to lava. Defaults to false. + internal static void SetUpBed(this ModTile mt, bool lavaImmune = false) + { + Main.tileFrameImportant[mt.Type] = true; + Main.tileLavaDeath[mt.Type] = !lavaImmune; + Main.tileWaterDeath[mt.Type] = false; + TileID.Sets.HasOutlines[mt.Type] = true; + TileObjectData.newTile.Width = 4; + TileObjectData.newTile.Height = 2; + TileObjectData.newTile.CoordinateHeights = new int[] { 16, 18 }; + TileObjectData.newTile.CoordinateWidth = 16; + TileObjectData.newTile.CoordinatePadding = 2; + TileObjectData.newTile.Direction = TileObjectDirection.PlaceLeft; + TileObjectData.newTile.StyleHorizontal = true; + TileObjectData.newTile.Origin = new Point16(1, 1); + TileObjectData.newTile.UsesCustomCanPlace = true; + TileObjectData.newTile.AnchorBottom = new AnchorData(AnchorType.SolidTile | AnchorType.SolidWithTop, 4, 0); + TileObjectData.newTile.LavaDeath = !lavaImmune; + TileObjectData.newAlternate.CopyFrom(TileObjectData.newTile); + TileObjectData.newAlternate.Direction = TileObjectDirection.PlaceRight; + TileObjectData.addAlternate(1); + TileObjectData.addTile(mt.Type); + + // All beds count as chairs. + mt.AddToArray(ref TileID.Sets.RoomNeeds.CountsAsChair); + } + + /// + /// Extension which initializes a ModTile to be a bookcase. + /// + /// The ModTile which is being initialized. + /// Whether this tile is supposed to be immune to lava. Defaults to false. + /// Whether this tile is supposed to have a solid top. Defaults to true. + internal static void SetUpBookcase(this ModTile mt, bool lavaImmune = false, bool solidTop = true) + { + Main.tileSolidTop[mt.Type] = solidTop; + Main.tileLighted[mt.Type] = true; + Main.tileFrameImportant[mt.Type] = true; + Main.tileTable[mt.Type] = solidTop; + Main.tileLavaDeath[mt.Type] = !lavaImmune; + Main.tileWaterDeath[mt.Type] = false; + TileObjectData.newTile.CopyFrom(TileObjectData.Style3x4); + TileObjectData.newTile.LavaDeath = !lavaImmune; + TileObjectData.addTile(mt.Type); + + // All bookcases count as tables. + mt.AddToArray(ref TileID.Sets.RoomNeeds.CountsAsTable); + } + + /// + /// Extension which initializes a ModTile to be a candelabra. + /// + /// The ModTile which is being initialized. + /// Whether this tile is supposed to be immune to lava. Defaults to false. + internal static void SetUpCandelabra(this ModTile mt, bool lavaImmune = false) + { + Main.tileLighted[mt.Type] = true; + Main.tileFrameImportant[mt.Type] = true; + Main.tileLavaDeath[mt.Type] = true; + Main.tileWaterDeath[mt.Type] = false; + TileObjectData.newTile.CopyFrom(TileObjectData.Style2x2); + TileObjectData.newTile.LavaDeath = !lavaImmune; + TileObjectData.addTile(mt.Type); + + // All candelabras count as light sources. + mt.AddToArray(ref TileID.Sets.RoomNeeds.CountsAsTorch); + } + + /// + /// Extension which initializes a ModTile to be a candle. + /// + /// The ModTile which is being initialized. + /// Whether this tile is supposed to be immune to lava. Defaults to false. + internal static void SetUpCandle(this ModTile mt, bool lavaImmune = false) + { + Main.tileLighted[mt.Type] = true; + Main.tileFrameImportant[mt.Type] = true; + Main.tileLavaDeath[mt.Type] = !lavaImmune; + Main.tileWaterDeath[mt.Type] = false; + TileObjectData.newTile.CopyFrom(TileObjectData.StyleOnTable1x1); + TileObjectData.newTile.CoordinateHeights = new int[] { 20 }; + TileObjectData.newTile.LavaDeath = !lavaImmune; + TileObjectData.newTile.DrawYOffset = -4; + TileObjectData.addTile(mt.Type); + + // All candles count as light sources. + mt.AddToArray(ref TileID.Sets.RoomNeeds.CountsAsTorch); + } + + /// + /// Extension which initializes a ModTile to be a chair. + /// + /// The ModTile which is being initialized. + /// Whether this tile is supposed to be immune to lava. Defaults to false. + internal static void SetUpChair(this ModTile mt, bool lavaImmune = false) + { + Main.tileFrameImportant[mt.Type] = true; + Main.tileNoAttach[mt.Type] = true; + Main.tileLavaDeath[mt.Type] = !lavaImmune; + Main.tileWaterDeath[mt.Type] = false; + TileObjectData.newTile.CopyFrom(TileObjectData.Style1x2); + TileObjectData.newTile.CoordinateHeights = new int[] { 16, 18 }; + TileObjectData.newTile.Direction = TileObjectDirection.PlaceLeft; + TileObjectData.newTile.StyleWrapLimit = 2; + TileObjectData.newTile.StyleMultiplier = 2; + TileObjectData.newTile.StyleHorizontal = true; + TileObjectData.newTile.LavaDeath = !lavaImmune; + TileObjectData.newAlternate.CopyFrom(TileObjectData.newTile); + TileObjectData.newAlternate.Direction = TileObjectDirection.PlaceRight; + TileObjectData.addAlternate(1); + TileObjectData.addTile(mt.Type); + + // As you could probably guess, all chairs count as chairs. + mt.AddToArray(ref TileID.Sets.RoomNeeds.CountsAsChair); + } + + /// + /// Extension which initializes a ModTile to be a chandelier. + /// + /// The ModTile which is being initialized. + /// Whether this tile is supposed to be immune to lava. Defaults to false. + internal static void SetUpChandelier(this ModTile mt, bool lavaImmune = false) + { + Main.tileLighted[mt.Type] = true; + Main.tileFrameImportant[mt.Type] = true; + Main.tileNoAttach[mt.Type] = true; + Main.tileLavaDeath[mt.Type] = !lavaImmune; + Main.tileWaterDeath[mt.Type] = false; + TileObjectData.newTile.Width = 3; + TileObjectData.newTile.Height = 3; + TileObjectData.newTile.CoordinateHeights = new int[] { 16, 16, 16 }; + TileObjectData.newTile.CoordinateWidth = 16; + TileObjectData.newTile.CoordinatePadding = 2; + TileObjectData.newTile.Origin = new Point16(1, 0); + TileObjectData.newTile.UsesCustomCanPlace = true; + TileObjectData.newTile.AnchorTop = new AnchorData(AnchorType.SolidTile, 1, 1); + TileObjectData.newTile.LavaDeath = !lavaImmune; + TileObjectData.addTile(mt.Type); + + // All chandeliers count as light sources. + mt.AddToArray(ref TileID.Sets.RoomNeeds.CountsAsTorch); + } + + /// + /// Extension which initializes a ModTile to be a chest. + /// + /// The ModTile which is being initialized. + internal static void SetUpChest(this ModTile mt, bool offset = false) + { + Main.tileSpelunker[mt.Type] = true; + Main.tileContainer[mt.Type] = true; + Main.tileShine2[mt.Type] = true; + Main.tileShine[mt.Type] = 1200; + Main.tileFrameImportant[mt.Type] = true; + Main.tileNoAttach[mt.Type] = true; + Main.tileValue[mt.Type] = 500; + TileID.Sets.HasOutlines[mt.Type] = true; + TileObjectData.newTile.CopyFrom(TileObjectData.Style2x2); if (offset) TileObjectData.newTile.DrawYOffset = 4; - TileObjectData.newTile.Origin = new Point16(0, 1); - TileObjectData.newTile.CoordinateHeights = new int[] { 16, 18 }; - TileObjectData.newTile.HookCheck = new PlacementHook(new Func(Chest.FindEmptyChest), -1, 0, true); - TileObjectData.newTile.HookPostPlaceMyPlayer = new PlacementHook(new Func(Chest.AfterPlacement_Hook), -1, 0, false); - TileObjectData.newTile.AnchorInvalidTiles = new int[] { 127 }; - TileObjectData.newTile.StyleHorizontal = true; - TileObjectData.newTile.LavaDeath = false; - TileObjectData.newTile.AnchorBottom = new AnchorData(AnchorType.SolidTile | AnchorType.SolidWithTop | AnchorType.SolidSide, TileObjectData.newTile.Width, 0); - TileObjectData.addTile(mt.Type); - } + TileObjectData.newTile.Origin = new Point16(0, 1); + TileObjectData.newTile.CoordinateHeights = new int[] { 16, 18 }; + TileObjectData.newTile.HookCheck = new PlacementHook(new Func(Chest.FindEmptyChest), -1, 0, true); + TileObjectData.newTile.HookPostPlaceMyPlayer = new PlacementHook(new Func(Chest.AfterPlacement_Hook), -1, 0, false); + TileObjectData.newTile.AnchorInvalidTiles = new int[] { 127 }; + TileObjectData.newTile.StyleHorizontal = true; + TileObjectData.newTile.LavaDeath = false; + TileObjectData.newTile.AnchorBottom = new AnchorData(AnchorType.SolidTile | AnchorType.SolidWithTop | AnchorType.SolidSide, TileObjectData.newTile.Width, 0); + TileObjectData.addTile(mt.Type); + } - /// - /// Extension which initializes a ModTile to be a clock. - /// - /// The ModTile which is being initialized. - /// Whether this tile is supposed to be immune to lava. Defaults to false. - internal static void SetUpClock(this ModTile mt, bool lavaImmune = false) - { - Main.tileFrameImportant[mt.Type] = true; - Main.tileNoAttach[mt.Type] = true; - Main.tileLavaDeath[mt.Type] = !lavaImmune; - TileID.Sets.HasOutlines[mt.Type] = true; - TileObjectData.newTile.CopyFrom(TileObjectData.Style2xX); - TileObjectData.newTile.Height = 5; - TileObjectData.newTile.CoordinateHeights = new int[] - { - 16, - 16, - 16, - 16, - 16 - }; - TileObjectData.newTile.Origin = new Point16(0, 4); - TileObjectData.newTile.UsesCustomCanPlace = true; - TileObjectData.newTile.LavaDeath = !lavaImmune; - TileObjectData.addTile(mt.Type); - } + /// + /// Extension which initializes a ModTile to be a clock. + /// + /// The ModTile which is being initialized. + /// Whether this tile is supposed to be immune to lava. Defaults to false. + internal static void SetUpClock(this ModTile mt, bool lavaImmune = false) + { + Main.tileFrameImportant[mt.Type] = true; + Main.tileNoAttach[mt.Type] = true; + Main.tileLavaDeath[mt.Type] = !lavaImmune; + TileID.Sets.HasOutlines[mt.Type] = true; + TileObjectData.newTile.CopyFrom(TileObjectData.Style2xX); + TileObjectData.newTile.Height = 5; + TileObjectData.newTile.CoordinateHeights = new int[] + { + 16, + 16, + 16, + 16, + 16 + }; + TileObjectData.newTile.Origin = new Point16(0, 4); + TileObjectData.newTile.UsesCustomCanPlace = true; + TileObjectData.newTile.LavaDeath = !lavaImmune; + TileObjectData.addTile(mt.Type); + } - /// - /// Extension which initializes a ModTile to be a closed door. - /// - /// The ModTile which is being initialized. - /// Whether this tile is supposed to be immune to lava. Defaults to false. - internal static void SetUpDoorClosed(this ModTile mt, bool lavaImmune = false) - { - Main.tileFrameImportant[mt.Type] = true; - Main.tileBlockLight[mt.Type] = true; - Main.tileSolid[mt.Type] = true; - Main.tileNoAttach[mt.Type] = true; - Main.tileLavaDeath[mt.Type] = !lavaImmune; - Main.tileWaterDeath[mt.Type] = false; - TileID.Sets.NotReallySolid[mt.Type] = true; - TileID.Sets.DrawsWalls[mt.Type] = true; - TileID.Sets.HasOutlines[mt.Type] = true; - TileObjectData.newTile.Width = 1; - TileObjectData.newTile.Height = 3; - TileObjectData.newTile.Origin = new Point16(0, 0); - TileObjectData.newTile.AnchorTop = new AnchorData(AnchorType.SolidTile, TileObjectData.newTile.Width, 0); - TileObjectData.newTile.AnchorBottom = new AnchorData(AnchorType.SolidTile, TileObjectData.newTile.Width, 0); - TileObjectData.newTile.UsesCustomCanPlace = true; - TileObjectData.newTile.LavaDeath = true; - TileObjectData.newTile.CoordinateHeights = new int[] { 16, 16, 16 }; - TileObjectData.newTile.CoordinateWidth = 16; - TileObjectData.newTile.CoordinatePadding = 2; - TileObjectData.newTile.LavaDeath = !lavaImmune; - TileObjectData.newAlternate.CopyFrom(TileObjectData.newTile); - TileObjectData.newAlternate.Origin = new Point16(0, 1); - TileObjectData.addAlternate(0); - TileObjectData.newAlternate.CopyFrom(TileObjectData.newTile); - TileObjectData.newAlternate.Origin = new Point16(0, 2); - TileObjectData.addAlternate(0); - TileObjectData.addTile(mt.Type); + /// + /// Extension which initializes a ModTile to be a closed door. + /// + /// The ModTile which is being initialized. + /// Whether this tile is supposed to be immune to lava. Defaults to false. + internal static void SetUpDoorClosed(this ModTile mt, bool lavaImmune = false) + { + Main.tileFrameImportant[mt.Type] = true; + Main.tileBlockLight[mt.Type] = true; + Main.tileSolid[mt.Type] = true; + Main.tileNoAttach[mt.Type] = true; + Main.tileLavaDeath[mt.Type] = !lavaImmune; + Main.tileWaterDeath[mt.Type] = false; + TileID.Sets.NotReallySolid[mt.Type] = true; + TileID.Sets.DrawsWalls[mt.Type] = true; + TileID.Sets.HasOutlines[mt.Type] = true; + TileObjectData.newTile.Width = 1; + TileObjectData.newTile.Height = 3; + TileObjectData.newTile.Origin = new Point16(0, 0); + TileObjectData.newTile.AnchorTop = new AnchorData(AnchorType.SolidTile, TileObjectData.newTile.Width, 0); + TileObjectData.newTile.AnchorBottom = new AnchorData(AnchorType.SolidTile, TileObjectData.newTile.Width, 0); + TileObjectData.newTile.UsesCustomCanPlace = true; + TileObjectData.newTile.LavaDeath = true; + TileObjectData.newTile.CoordinateHeights = new int[] { 16, 16, 16 }; + TileObjectData.newTile.CoordinateWidth = 16; + TileObjectData.newTile.CoordinatePadding = 2; + TileObjectData.newTile.LavaDeath = !lavaImmune; + TileObjectData.newAlternate.CopyFrom(TileObjectData.newTile); + TileObjectData.newAlternate.Origin = new Point16(0, 1); + TileObjectData.addAlternate(0); + TileObjectData.newAlternate.CopyFrom(TileObjectData.newTile); + TileObjectData.newAlternate.Origin = new Point16(0, 2); + TileObjectData.addAlternate(0); + TileObjectData.addTile(mt.Type); - // As you could probably guess, all closed doors count as doors. - mt.AddToArray(ref TileID.Sets.RoomNeeds.CountsAsDoor); - } + // As you could probably guess, all closed doors count as doors. + mt.AddToArray(ref TileID.Sets.RoomNeeds.CountsAsDoor); + } - /// - /// Extension which initializes a ModTile to be an open door. - /// - /// The ModTile which is being initialized. - /// Whether this tile is supposed to be immune to lava. Defaults to false. - internal static void SetUpDoorOpen(this ModTile mt, bool lavaImmune = false) - { - Main.tileFrameImportant[mt.Type] = true; - Main.tileSolid[mt.Type] = false; - Main.tileLavaDeath[mt.Type] = !lavaImmune; - Main.tileWaterDeath[mt.Type] = false; - Main.tileNoSunLight[mt.Type] = true; - TileObjectData.newTile.Width = 2; - TileObjectData.newTile.Height = 3; - TileObjectData.newTile.Origin = new Point16(0, 0); - TileObjectData.newTile.AnchorTop = new AnchorData(AnchorType.SolidTile, 1, 0); - TileObjectData.newTile.AnchorBottom = new AnchorData(AnchorType.SolidTile, 1, 0); - TileObjectData.newTile.UsesCustomCanPlace = true; - TileObjectData.newTile.LavaDeath = true; - TileObjectData.newTile.CoordinateHeights = new int[] { 16, 16, 16 }; - TileObjectData.newTile.CoordinateWidth = 16; - TileObjectData.newTile.CoordinatePadding = 2; - TileObjectData.newTile.StyleHorizontal = true; - TileObjectData.newTile.StyleMultiplier = 2; - TileObjectData.newTile.StyleWrapLimit = 2; - TileObjectData.newTile.Direction = TileObjectDirection.PlaceRight; - TileObjectData.newTile.LavaDeath = !lavaImmune; - TileObjectData.newAlternate.CopyFrom(TileObjectData.newTile); - TileObjectData.newAlternate.Origin = new Point16(0, 1); - TileObjectData.addAlternate(0); - TileObjectData.newAlternate.CopyFrom(TileObjectData.newTile); - TileObjectData.newAlternate.Origin = new Point16(0, 2); - TileObjectData.addAlternate(0); - TileObjectData.newAlternate.CopyFrom(TileObjectData.newTile); - TileObjectData.newAlternate.Origin = new Point16(1, 0); - TileObjectData.newAlternate.AnchorTop = new AnchorData(AnchorType.SolidTile, 1, 1); - TileObjectData.newAlternate.AnchorBottom = new AnchorData(AnchorType.SolidTile, 1, 1); - TileObjectData.newAlternate.Direction = TileObjectDirection.PlaceLeft; - TileObjectData.addAlternate(1); - TileObjectData.newAlternate.CopyFrom(TileObjectData.newTile); - TileObjectData.newAlternate.Origin = new Point16(1, 1); - TileObjectData.newAlternate.AnchorTop = new AnchorData(AnchorType.SolidTile, 1, 1); - TileObjectData.newAlternate.AnchorBottom = new AnchorData(AnchorType.SolidTile, 1, 1); - TileObjectData.newAlternate.Direction = TileObjectDirection.PlaceLeft; - TileObjectData.addAlternate(1); - TileObjectData.newAlternate.CopyFrom(TileObjectData.newTile); - TileObjectData.newAlternate.Origin = new Point16(1, 2); - TileObjectData.newAlternate.AnchorTop = new AnchorData(AnchorType.SolidTile, 1, 1); - TileObjectData.newAlternate.AnchorBottom = new AnchorData(AnchorType.SolidTile, 1, 1); - TileObjectData.newAlternate.Direction = TileObjectDirection.PlaceLeft; - TileObjectData.addAlternate(1); - TileObjectData.addTile(mt.Type); - TileID.Sets.HousingWalls[mt.Type] = true; - TileID.Sets.HasOutlines[mt.Type] = true; + /// + /// Extension which initializes a ModTile to be an open door. + /// + /// The ModTile which is being initialized. + /// Whether this tile is supposed to be immune to lava. Defaults to false. + internal static void SetUpDoorOpen(this ModTile mt, bool lavaImmune = false) + { + Main.tileFrameImportant[mt.Type] = true; + Main.tileSolid[mt.Type] = false; + Main.tileLavaDeath[mt.Type] = !lavaImmune; + Main.tileWaterDeath[mt.Type] = false; + Main.tileNoSunLight[mt.Type] = true; + TileObjectData.newTile.Width = 2; + TileObjectData.newTile.Height = 3; + TileObjectData.newTile.Origin = new Point16(0, 0); + TileObjectData.newTile.AnchorTop = new AnchorData(AnchorType.SolidTile, 1, 0); + TileObjectData.newTile.AnchorBottom = new AnchorData(AnchorType.SolidTile, 1, 0); + TileObjectData.newTile.UsesCustomCanPlace = true; + TileObjectData.newTile.LavaDeath = true; + TileObjectData.newTile.CoordinateHeights = new int[] { 16, 16, 16 }; + TileObjectData.newTile.CoordinateWidth = 16; + TileObjectData.newTile.CoordinatePadding = 2; + TileObjectData.newTile.StyleHorizontal = true; + TileObjectData.newTile.StyleMultiplier = 2; + TileObjectData.newTile.StyleWrapLimit = 2; + TileObjectData.newTile.Direction = TileObjectDirection.PlaceRight; + TileObjectData.newTile.LavaDeath = !lavaImmune; + TileObjectData.newAlternate.CopyFrom(TileObjectData.newTile); + TileObjectData.newAlternate.Origin = new Point16(0, 1); + TileObjectData.addAlternate(0); + TileObjectData.newAlternate.CopyFrom(TileObjectData.newTile); + TileObjectData.newAlternate.Origin = new Point16(0, 2); + TileObjectData.addAlternate(0); + TileObjectData.newAlternate.CopyFrom(TileObjectData.newTile); + TileObjectData.newAlternate.Origin = new Point16(1, 0); + TileObjectData.newAlternate.AnchorTop = new AnchorData(AnchorType.SolidTile, 1, 1); + TileObjectData.newAlternate.AnchorBottom = new AnchorData(AnchorType.SolidTile, 1, 1); + TileObjectData.newAlternate.Direction = TileObjectDirection.PlaceLeft; + TileObjectData.addAlternate(1); + TileObjectData.newAlternate.CopyFrom(TileObjectData.newTile); + TileObjectData.newAlternate.Origin = new Point16(1, 1); + TileObjectData.newAlternate.AnchorTop = new AnchorData(AnchorType.SolidTile, 1, 1); + TileObjectData.newAlternate.AnchorBottom = new AnchorData(AnchorType.SolidTile, 1, 1); + TileObjectData.newAlternate.Direction = TileObjectDirection.PlaceLeft; + TileObjectData.addAlternate(1); + TileObjectData.newAlternate.CopyFrom(TileObjectData.newTile); + TileObjectData.newAlternate.Origin = new Point16(1, 2); + TileObjectData.newAlternate.AnchorTop = new AnchorData(AnchorType.SolidTile, 1, 1); + TileObjectData.newAlternate.AnchorBottom = new AnchorData(AnchorType.SolidTile, 1, 1); + TileObjectData.newAlternate.Direction = TileObjectDirection.PlaceLeft; + TileObjectData.addAlternate(1); + TileObjectData.addTile(mt.Type); + TileID.Sets.HousingWalls[mt.Type] = true; + TileID.Sets.HasOutlines[mt.Type] = true; - // As you could probably guess, all open doors count as doors. - mt.AddToArray(ref TileID.Sets.RoomNeeds.CountsAsDoor); - } + // As you could probably guess, all open doors count as doors. + mt.AddToArray(ref TileID.Sets.RoomNeeds.CountsAsDoor); + } - /// - /// Extension which initializes a ModTile to be a dresser. - /// - /// The ModTile which is being initialized. - internal static void SetUpDresser(this ModTile mt) - { - Main.tileSolidTop[mt.Type] = true; - Main.tileFrameImportant[mt.Type] = true; - Main.tileNoAttach[mt.Type] = true; - Main.tileTable[mt.Type] = true; - Main.tileContainer[mt.Type] = true; - Main.tileWaterDeath[mt.Type] = false; - Main.tileLavaDeath[mt.Type] = false; - TileID.Sets.HasOutlines[mt.Type] = true; - TileObjectData.newTile.CopyFrom(TileObjectData.Style3x2); - TileObjectData.newTile.Origin = new Point16(1, 1); - TileObjectData.newTile.CoordinateHeights = new int[] { 16, 16 }; - TileObjectData.newTile.HookCheck = new PlacementHook(new Func(Chest.FindEmptyChest), -1, 0, true); - TileObjectData.newTile.HookPostPlaceMyPlayer = new PlacementHook(new Func(Chest.AfterPlacement_Hook), -1, 0, false); - TileObjectData.newTile.AnchorInvalidTiles = new int[] { 127 }; - TileObjectData.newTile.StyleHorizontal = true; - TileObjectData.newTile.LavaDeath = false; - TileObjectData.newTile.AnchorBottom = new AnchorData(AnchorType.SolidTile | AnchorType.SolidWithTop | AnchorType.SolidSide, TileObjectData.newTile.Width, 0); - TileObjectData.addTile(mt.Type); + /// + /// Extension which initializes a ModTile to be a dresser. + /// + /// The ModTile which is being initialized. + internal static void SetUpDresser(this ModTile mt) + { + Main.tileSolidTop[mt.Type] = true; + Main.tileFrameImportant[mt.Type] = true; + Main.tileNoAttach[mt.Type] = true; + Main.tileTable[mt.Type] = true; + Main.tileContainer[mt.Type] = true; + Main.tileWaterDeath[mt.Type] = false; + Main.tileLavaDeath[mt.Type] = false; + TileID.Sets.HasOutlines[mt.Type] = true; + TileObjectData.newTile.CopyFrom(TileObjectData.Style3x2); + TileObjectData.newTile.Origin = new Point16(1, 1); + TileObjectData.newTile.CoordinateHeights = new int[] { 16, 16 }; + TileObjectData.newTile.HookCheck = new PlacementHook(new Func(Chest.FindEmptyChest), -1, 0, true); + TileObjectData.newTile.HookPostPlaceMyPlayer = new PlacementHook(new Func(Chest.AfterPlacement_Hook), -1, 0, false); + TileObjectData.newTile.AnchorInvalidTiles = new int[] { 127 }; + TileObjectData.newTile.StyleHorizontal = true; + TileObjectData.newTile.LavaDeath = false; + TileObjectData.newTile.AnchorBottom = new AnchorData(AnchorType.SolidTile | AnchorType.SolidWithTop | AnchorType.SolidSide, TileObjectData.newTile.Width, 0); + TileObjectData.addTile(mt.Type); - // All dressers count as tables. - mt.AddToArray(ref TileID.Sets.RoomNeeds.CountsAsTable); - } + // All dressers count as tables. + mt.AddToArray(ref TileID.Sets.RoomNeeds.CountsAsTable); + } - /// - /// Extension which initializes a ModTile to be a floor lamp. - /// - /// The ModTile which is being initialized. - /// Whether this tile is supposed to be immune to lava. Defaults to false. - internal static void SetUpLamp(this ModTile mt, bool lavaImmune = false) - { - Main.tileLighted[mt.Type] = true; - Main.tileFrameImportant[mt.Type] = true; - Main.tileLavaDeath[mt.Type] = !lavaImmune; - Main.tileWaterDeath[mt.Type] = false; - TileObjectData.newTile.CopyFrom(TileObjectData.Style1xX); - TileObjectData.newTile.LavaDeath = !lavaImmune; - TileObjectData.addTile(mt.Type); + /// + /// Extension which initializes a ModTile to be a floor lamp. + /// + /// The ModTile which is being initialized. + /// Whether this tile is supposed to be immune to lava. Defaults to false. + internal static void SetUpLamp(this ModTile mt, bool lavaImmune = false) + { + Main.tileLighted[mt.Type] = true; + Main.tileFrameImportant[mt.Type] = true; + Main.tileLavaDeath[mt.Type] = !lavaImmune; + Main.tileWaterDeath[mt.Type] = false; + TileObjectData.newTile.CopyFrom(TileObjectData.Style1xX); + TileObjectData.newTile.LavaDeath = !lavaImmune; + TileObjectData.addTile(mt.Type); - // All floor lamps count as light sources. - mt.AddToArray(ref TileID.Sets.RoomNeeds.CountsAsTorch); - } + // All floor lamps count as light sources. + mt.AddToArray(ref TileID.Sets.RoomNeeds.CountsAsTorch); + } - /// - /// Extension which initializes a ModTile to be a hanging lantern. - /// - /// The ModTile which is being initialized. - /// Whether this tile is supposed to be immune to lava. Defaults to false. - internal static void SetUpLantern(this ModTile mt, bool lavaImmune = false) - { - Main.tileLighted[mt.Type] = true; - Main.tileFrameImportant[mt.Type] = true; - Main.tileLavaDeath[mt.Type] = !lavaImmune; - Main.tileWaterDeath[mt.Type] = false; - TileObjectData.newTile.CopyFrom(TileObjectData.Style1x2Top); - TileObjectData.newTile.LavaDeath = !lavaImmune; - TileObjectData.addTile(mt.Type); + /// + /// Extension which initializes a ModTile to be a hanging lantern. + /// + /// The ModTile which is being initialized. + /// Whether this tile is supposed to be immune to lava. Defaults to false. + internal static void SetUpLantern(this ModTile mt, bool lavaImmune = false) + { + Main.tileLighted[mt.Type] = true; + Main.tileFrameImportant[mt.Type] = true; + Main.tileLavaDeath[mt.Type] = !lavaImmune; + Main.tileWaterDeath[mt.Type] = false; + TileObjectData.newTile.CopyFrom(TileObjectData.Style1x2Top); + TileObjectData.newTile.LavaDeath = !lavaImmune; + TileObjectData.addTile(mt.Type); - // All hanging lanterns count as light sources. - mt.AddToArray(ref TileID.Sets.RoomNeeds.CountsAsTorch); - } + // All hanging lanterns count as light sources. + mt.AddToArray(ref TileID.Sets.RoomNeeds.CountsAsTorch); + } - /// - /// Extension which initializes a ModTile to be a piano. - /// - /// The ModTile which is being initialized. - /// Whether this tile is supposed to be immune to lava. Defaults to false. - internal static void SetUpPiano(this ModTile mt, bool lavaImmune = false) - { - Main.tileLighted[mt.Type] = true; - Main.tileFrameImportant[mt.Type] = true; - Main.tileLavaDeath[mt.Type] = !lavaImmune; - Main.tileWaterDeath[mt.Type] = false; + /// + /// Extension which initializes a ModTile to be a piano. + /// + /// The ModTile which is being initialized. + /// Whether this tile is supposed to be immune to lava. Defaults to false. + internal static void SetUpPiano(this ModTile mt, bool lavaImmune = false) + { + Main.tileLighted[mt.Type] = true; + Main.tileFrameImportant[mt.Type] = true; + Main.tileLavaDeath[mt.Type] = !lavaImmune; + Main.tileWaterDeath[mt.Type] = false; - TileObjectData.newTile.CopyFrom(TileObjectData.Style3x2); - TileObjectData.addTile(mt.Type); + TileObjectData.newTile.CopyFrom(TileObjectData.Style3x2); + TileObjectData.addTile(mt.Type); - // All pianos count as tables. - mt.AddToArray(ref TileID.Sets.RoomNeeds.CountsAsTable); - } + // All pianos count as tables. + mt.AddToArray(ref TileID.Sets.RoomNeeds.CountsAsTable); + } - /// - /// Extension which initializes a ModTile to be a platform. - /// - /// The ModTile which is being initialized. - /// Whether this tile is supposed to be immune to lava. Defaults to false. - internal static void SetUpPlatform(this ModTile mt, bool lavaImmune = false) - { - Main.tileLighted[mt.Type] = true; - Main.tileFrameImportant[mt.Type] = true; - Main.tileSolidTop[mt.Type] = true; - Main.tileSolid[mt.Type] = true; - Main.tileNoAttach[mt.Type] = true; - Main.tileTable[mt.Type] = true; - Main.tileLavaDeath[mt.Type] = !lavaImmune; - TileID.Sets.Platforms[mt.Type] = true; - TileObjectData.newTile.CoordinateHeights = new int[] { 16 }; - TileObjectData.newTile.CoordinateWidth = 16; - TileObjectData.newTile.CoordinatePadding = 2; - TileObjectData.newTile.StyleHorizontal = true; - TileObjectData.newTile.StyleMultiplier = 27; - TileObjectData.newTile.StyleWrapLimit = 27; - TileObjectData.newTile.UsesCustomCanPlace = false; - TileObjectData.newTile.LavaDeath = !lavaImmune; - TileObjectData.addTile(mt.Type); + /// + /// Extension which initializes a ModTile to be a platform. + /// + /// The ModTile which is being initialized. + /// Whether this tile is supposed to be immune to lava. Defaults to false. + internal static void SetUpPlatform(this ModTile mt, bool lavaImmune = false) + { + Main.tileLighted[mt.Type] = true; + Main.tileFrameImportant[mt.Type] = true; + Main.tileSolidTop[mt.Type] = true; + Main.tileSolid[mt.Type] = true; + Main.tileNoAttach[mt.Type] = true; + Main.tileTable[mt.Type] = true; + Main.tileLavaDeath[mt.Type] = !lavaImmune; + TileID.Sets.Platforms[mt.Type] = true; + TileObjectData.newTile.CoordinateHeights = new int[] { 16 }; + TileObjectData.newTile.CoordinateWidth = 16; + TileObjectData.newTile.CoordinatePadding = 2; + TileObjectData.newTile.StyleHorizontal = true; + TileObjectData.newTile.StyleMultiplier = 27; + TileObjectData.newTile.StyleWrapLimit = 27; + TileObjectData.newTile.UsesCustomCanPlace = false; + TileObjectData.newTile.LavaDeath = !lavaImmune; + TileObjectData.addTile(mt.Type); - // All platforms count as doors (so that you may have top-or-bottom entry/exit rooms) - mt.AddToArray(ref TileID.Sets.RoomNeeds.CountsAsDoor); - } + // All platforms count as doors (so that you may have top-or-bottom entry/exit rooms) + mt.AddToArray(ref TileID.Sets.RoomNeeds.CountsAsDoor); + } - /// - /// Extension which initializes a ModTile to be a sink. - /// - /// The ModTile which is being initialized. - /// Whether this tile is supposed to be immune to lava. Defaults to false. - internal static void SetUpSink(this ModTile mt, bool lavaImmune = false) - { - Main.tileLighted[mt.Type] = true; - Main.tileFrameImportant[mt.Type] = true; - Main.tileLavaDeath[mt.Type] = !lavaImmune; - Main.tileWaterDeath[mt.Type] = false; - TileObjectData.newTile.CopyFrom(TileObjectData.Style2x2); - TileObjectData.newTile.LavaDeath = !lavaImmune; - TileObjectData.addTile(mt.Type); - } + /// + /// Extension which initializes a ModTile to be a sink. + /// + /// The ModTile which is being initialized. + /// Whether this tile is supposed to be immune to lava. Defaults to false. + internal static void SetUpSink(this ModTile mt, bool lavaImmune = false) + { + Main.tileLighted[mt.Type] = true; + Main.tileFrameImportant[mt.Type] = true; + Main.tileLavaDeath[mt.Type] = !lavaImmune; + Main.tileWaterDeath[mt.Type] = false; + TileObjectData.newTile.CopyFrom(TileObjectData.Style2x2); + TileObjectData.newTile.LavaDeath = !lavaImmune; + TileObjectData.addTile(mt.Type); + } - /// - /// Extension which initializes a ModTile to be a sofa. - /// - /// The ModTile which is being initialized. - /// Whether this tile is supposed to be immune to lava. Defaults to false. - internal static void SetUpSofa(this ModTile mt, bool lavaImmune = false) - { - Main.tileLighted[mt.Type] = true; - Main.tileFrameImportant[mt.Type] = true; - Main.tileLavaDeath[mt.Type] = !lavaImmune; - Main.tileWaterDeath[mt.Type] = false; - TileObjectData.newTile.CopyFrom(TileObjectData.Style3x2); - TileObjectData.newTile.LavaDeath = !lavaImmune; - TileObjectData.addTile(mt.Type); + /// + /// Extension which initializes a ModTile to be a sofa. + /// + /// The ModTile which is being initialized. + /// Whether this tile is supposed to be immune to lava. Defaults to false. + internal static void SetUpSofa(this ModTile mt, bool lavaImmune = false) + { + Main.tileLighted[mt.Type] = true; + Main.tileFrameImportant[mt.Type] = true; + Main.tileLavaDeath[mt.Type] = !lavaImmune; + Main.tileWaterDeath[mt.Type] = false; + TileObjectData.newTile.CopyFrom(TileObjectData.Style3x2); + TileObjectData.newTile.LavaDeath = !lavaImmune; + TileObjectData.addTile(mt.Type); - // All sofas count as chairs. - mt.AddToArray(ref TileID.Sets.RoomNeeds.CountsAsChair); - } + // All sofas count as chairs. + mt.AddToArray(ref TileID.Sets.RoomNeeds.CountsAsChair); + } - /// - /// Extension which initializes a ModTile to be a table. - /// - /// The ModTile which is being initialized. - /// Whether this tile is supposed to be immune to lava. Defaults to false. - internal static void SetUpTable(this ModTile mt, bool lavaImmune = false) - { - Main.tileSolidTop[mt.Type] = true; - Main.tileLighted[mt.Type] = true; - Main.tileFrameImportant[mt.Type] = true; - Main.tileNoAttach[mt.Type] = true; - Main.tileTable[mt.Type] = true; - Main.tileLavaDeath[mt.Type] = !lavaImmune; - Main.tileWaterDeath[mt.Type] = false; + /// + /// Extension which initializes a ModTile to be a table. + /// + /// The ModTile which is being initialized. + /// Whether this tile is supposed to be immune to lava. Defaults to false. + internal static void SetUpTable(this ModTile mt, bool lavaImmune = false) + { + Main.tileSolidTop[mt.Type] = true; + Main.tileLighted[mt.Type] = true; + Main.tileFrameImportant[mt.Type] = true; + Main.tileNoAttach[mt.Type] = true; + Main.tileTable[mt.Type] = true; + Main.tileLavaDeath[mt.Type] = !lavaImmune; + Main.tileWaterDeath[mt.Type] = false; - TileObjectData.newTile.CopyFrom(TileObjectData.Style3x2); - TileObjectData.newTile.LavaDeath = !lavaImmune; - TileObjectData.addTile(mt.Type); + TileObjectData.newTile.CopyFrom(TileObjectData.Style3x2); + TileObjectData.newTile.LavaDeath = !lavaImmune; + TileObjectData.addTile(mt.Type); - // As you could probably guess, all tables count as tables. - mt.AddToArray(ref TileID.Sets.RoomNeeds.CountsAsTable); - } + // As you could probably guess, all tables count as tables. + mt.AddToArray(ref TileID.Sets.RoomNeeds.CountsAsTable); + } - /// - /// Extension which initializes a ModTile to be a torch. - /// - /// The ModTile which is being initialized. - /// Whether this tile is supposed to be immune to lava. Defaults to false. - internal static void SetUpTorch(this ModTile mt, bool lavaImmune = false, bool waterImmune = false) - { - Main.tileLighted[mt.Type] = true; - Main.tileFrameImportant[mt.Type] = true; - Main.tileSolid[mt.Type] = false; - Main.tileNoAttach[mt.Type] = true; - Main.tileNoFail[mt.Type] = true; - Main.tileWaterDeath[mt.Type] = !waterImmune; - Main.tileLavaDeath[mt.Type] = !lavaImmune; - TileObjectData.newTile.CopyFrom(TileObjectData.StyleTorch); - TileObjectData.newTile.WaterDeath = !waterImmune; - TileObjectData.newTile.LavaDeath = !lavaImmune; - TileObjectData.newTile.AnchorBottom = new AnchorData(AnchorType.SolidTile | AnchorType.SolidSide, TileObjectData.newTile.Width, 0); - TileObjectData.newAlternate.CopyFrom(TileObjectData.StyleTorch); - TileObjectData.newAlternate.WaterDeath = false; - TileObjectData.newAlternate.AnchorLeft = new AnchorData(AnchorType.SolidTile | AnchorType.SolidSide | AnchorType.Tree | AnchorType.AlternateTile, TileObjectData.newTile.Height, 0); - TileObjectData.newAlternate.AnchorAlternateTiles = new int[] { 124 }; - TileObjectData.addAlternate(1); - TileObjectData.newAlternate.CopyFrom(TileObjectData.StyleTorch); - TileObjectData.newAlternate.WaterDeath = false; - TileObjectData.newAlternate.AnchorRight = new AnchorData(AnchorType.SolidTile | AnchorType.SolidSide | AnchorType.Tree | AnchorType.AlternateTile, TileObjectData.newTile.Height, 0); - TileObjectData.newAlternate.AnchorAlternateTiles = new int[] { 124 }; - TileObjectData.addAlternate(2); - TileObjectData.newAlternate.CopyFrom(TileObjectData.StyleTorch); - TileObjectData.newAlternate.WaterDeath = false; - TileObjectData.newAlternate.AnchorWall = true; - TileObjectData.addAlternate(0); - TileObjectData.addTile(mt.Type); + /// + /// Extension which initializes a ModTile to be a torch. + /// + /// The ModTile which is being initialized. + /// Whether this tile is supposed to be immune to lava. Defaults to false. + internal static void SetUpTorch(this ModTile mt, bool lavaImmune = false, bool waterImmune = false) + { + Main.tileLighted[mt.Type] = true; + Main.tileFrameImportant[mt.Type] = true; + Main.tileSolid[mt.Type] = false; + Main.tileNoAttach[mt.Type] = true; + Main.tileNoFail[mt.Type] = true; + Main.tileWaterDeath[mt.Type] = !waterImmune; + Main.tileLavaDeath[mt.Type] = !lavaImmune; + TileObjectData.newTile.CopyFrom(TileObjectData.StyleTorch); + TileObjectData.newTile.WaterDeath = !waterImmune; + TileObjectData.newTile.LavaDeath = !lavaImmune; + TileObjectData.newTile.AnchorBottom = new AnchorData(AnchorType.SolidTile | AnchorType.SolidSide, TileObjectData.newTile.Width, 0); + TileObjectData.newAlternate.CopyFrom(TileObjectData.StyleTorch); + TileObjectData.newAlternate.WaterDeath = false; + TileObjectData.newAlternate.AnchorLeft = new AnchorData(AnchorType.SolidTile | AnchorType.SolidSide | AnchorType.Tree | AnchorType.AlternateTile, TileObjectData.newTile.Height, 0); + TileObjectData.newAlternate.AnchorAlternateTiles = new int[] { 124 }; + TileObjectData.addAlternate(1); + TileObjectData.newAlternate.CopyFrom(TileObjectData.StyleTorch); + TileObjectData.newAlternate.WaterDeath = false; + TileObjectData.newAlternate.AnchorRight = new AnchorData(AnchorType.SolidTile | AnchorType.SolidSide | AnchorType.Tree | AnchorType.AlternateTile, TileObjectData.newTile.Height, 0); + TileObjectData.newAlternate.AnchorAlternateTiles = new int[] { 124 }; + TileObjectData.addAlternate(2); + TileObjectData.newAlternate.CopyFrom(TileObjectData.StyleTorch); + TileObjectData.newAlternate.WaterDeath = false; + TileObjectData.newAlternate.AnchorWall = true; + TileObjectData.addAlternate(0); + TileObjectData.addTile(mt.Type); - // All torches count as light sources. - mt.AddToArray(ref TileID.Sets.RoomNeeds.CountsAsTorch); - } + // All torches count as light sources. + mt.AddToArray(ref TileID.Sets.RoomNeeds.CountsAsTorch); + } - /// - /// Extension which initializes a ModTile to be a work bench. - /// - /// The ModTile which is being initialized. - /// Whether this tile is supposed to be immune to lava. Defaults to false. - internal static void SetUpWorkBench(this ModTile mt, bool lavaImmune = false) - { - Main.tileSolidTop[mt.Type] = true; - Main.tileFrameImportant[mt.Type] = true; - Main.tileNoAttach[mt.Type] = true; - Main.tileTable[mt.Type] = true; - Main.tileLavaDeath[mt.Type] = !lavaImmune; - Main.tileWaterDeath[mt.Type] = false; - TileObjectData.newTile.CopyFrom(TileObjectData.Style2x1); - TileObjectData.newTile.CoordinateHeights = new int[] { 18 }; - TileObjectData.newTile.LavaDeath = !lavaImmune; - TileObjectData.addTile(mt.Type); + /// + /// Extension which initializes a ModTile to be a work bench. + /// + /// The ModTile which is being initialized. + /// Whether this tile is supposed to be immune to lava. Defaults to false. + internal static void SetUpWorkBench(this ModTile mt, bool lavaImmune = false) + { + Main.tileSolidTop[mt.Type] = true; + Main.tileFrameImportant[mt.Type] = true; + Main.tileNoAttach[mt.Type] = true; + Main.tileTable[mt.Type] = true; + Main.tileLavaDeath[mt.Type] = !lavaImmune; + Main.tileWaterDeath[mt.Type] = false; + TileObjectData.newTile.CopyFrom(TileObjectData.Style2x1); + TileObjectData.newTile.CoordinateHeights = new int[] { 18 }; + TileObjectData.newTile.LavaDeath = !lavaImmune; + TileObjectData.addTile(mt.Type); - // All work benches count as tables. - mt.AddToArray(ref TileID.Sets.RoomNeeds.CountsAsTable); - } + // All work benches count as tables. + mt.AddToArray(ref TileID.Sets.RoomNeeds.CountsAsTable); + } - /// - /// Extension which initializes a ModTile to be a fountain. - /// - /// The ModTile which is being initialized. - internal static void SetUpFountain(this ModTile mt) - { + /// + /// Extension which initializes a ModTile to be a fountain. + /// + /// The ModTile which is being initialized. + internal static void SetUpFountain(this ModTile mt) + { //All fountains are immune to lava - Main.tileLighted[mt.Type] = true; - Main.tileFrameImportant[mt.Type] = true; - Main.tileLavaDeath[mt.Type] = false; - Main.tileWaterDeath[mt.Type] = false; - //TileObjectData.newTile.CopyFrom(TileObjectData.Style3x4); - //TileObjectData.newTile.Width = 2; - TileObjectData.newTile.LavaDeath = false; - TileObjectData.addTile(mt.Type); - TileID.Sets.HasOutlines[mt.Type] = true; + Main.tileLighted[mt.Type] = true; + Main.tileFrameImportant[mt.Type] = true; + Main.tileLavaDeath[mt.Type] = false; + Main.tileWaterDeath[mt.Type] = false; + //TileObjectData.newTile.CopyFrom(TileObjectData.Style3x4); + //TileObjectData.newTile.Width = 2; + TileObjectData.newTile.LavaDeath = false; + TileObjectData.addTile(mt.Type); + TileID.Sets.HasOutlines[mt.Type] = true; - TileObjectData.newTile.Width = 2; - TileObjectData.newTile.Height = 4; - TileObjectData.newTile.CoordinateHeights = new int[] { 16, 16, 16, 16 }; - TileObjectData.newTile.CoordinateWidth = 16; - TileObjectData.newTile.CoordinatePadding = 2; - TileObjectData.newTile.Origin = new Point16(0, 3); - TileObjectData.newTile.UsesCustomCanPlace = true; - TileObjectData.newTile.AnchorBottom = new AnchorData(AnchorType.SolidTile | AnchorType.SolidWithTop, 2, 0); - TileObjectData.addTile(mt.Type); - } - #endregion - #endregion + TileObjectData.newTile.Width = 2; + TileObjectData.newTile.Height = 4; + TileObjectData.newTile.CoordinateHeights = new int[] { 16, 16, 16, 16 }; + TileObjectData.newTile.CoordinateWidth = 16; + TileObjectData.newTile.CoordinatePadding = 2; + TileObjectData.newTile.Origin = new Point16(0, 3); + TileObjectData.newTile.UsesCustomCanPlace = true; + TileObjectData.newTile.AnchorBottom = new AnchorData(AnchorType.SolidTile | AnchorType.SolidWithTop, 2, 0); + TileObjectData.addTile(mt.Type); + } + #endregion + #endregion - #region Drawing Utilities - public static void DrawItemGlowmask(this Item item, SpriteBatch spriteBatch, int frameCount, float rotation, Texture2D glowmaskTexture) - { - Vector2 center = new Vector2((float)(Main.itemTexture[item.type].Width / 2), (float)(Main.itemTexture[item.type].Height / frameCount / 2)); - Rectangle frame = Main.itemAnimations[item.type].GetFrame(glowmaskTexture); - Vector2 drawPosition = item.Center - Main.screenPosition; + #region Drawing Utilities + public static void DrawItemGlowmask(this Item item, SpriteBatch spriteBatch, int frameCount, float rotation, Texture2D glowmaskTexture) + { + Vector2 center = new Vector2((float)(Main.itemTexture[item.type].Width / 2), (float)(Main.itemTexture[item.type].Height / frameCount / 2)); + Rectangle frame = Main.itemAnimations[item.type].GetFrame(glowmaskTexture); + Vector2 drawPosition = item.Center - Main.screenPosition; - spriteBatch.Draw(glowmaskTexture, drawPosition, - new Rectangle?(frame), Color.White, rotation, center, 1f, SpriteEffects.None, 0f); - } + spriteBatch.Draw(glowmaskTexture, drawPosition, + new Rectangle?(frame), Color.White, rotation, center, 1f, SpriteEffects.None, 0f); + } - public static void DrawFishingLine(this Projectile projectile, int fishingRodType, Color poleColor, int xPositionAdditive = 45, float yPositionAdditive = 35f) - { - Player player = Main.player[projectile.owner]; + public static void DrawFishingLine(this Projectile projectile, int fishingRodType, Color poleColor, int xPositionAdditive = 45, float yPositionAdditive = 35f) + { + Player player = Main.player[projectile.owner]; Item item = Main.mouseItem.IsAir ? player.HeldItem : Main.mouseItem; - if (projectile.bobber && item.holdStyle > 0) - { - float pPosX = player.MountedCenter.X; - float pPosY = player.MountedCenter.Y; - pPosY += player.gfxOffY; - int type = item.type; - float gravDir = player.gravDir; + if (projectile.bobber && item.holdStyle > 0) + { + float pPosX = player.MountedCenter.X; + float pPosY = player.MountedCenter.Y; + pPosY += player.gfxOffY; + int type = item.type; + float gravDir = player.gravDir; - if (type == fishingRodType) - { - pPosX += (float)(xPositionAdditive * player.direction); - if (player.direction < 0) - { - pPosX -= 13f; - } - pPosY -= yPositionAdditive * gravDir; - } + if (type == fishingRodType) + { + pPosX += (float)(xPositionAdditive * player.direction); + if (player.direction < 0) + { + pPosX -= 13f; + } + pPosY -= yPositionAdditive * gravDir; + } - if (gravDir == -1f) - { - pPosY -= 12f; - } - Vector2 mountedCenter = new Vector2(pPosX, pPosY); - mountedCenter = player.RotatedRelativePoint(mountedCenter + new Vector2(8f), true) - new Vector2(8f); - float projPosX = projectile.position.X + (float)projectile.width * 0.5f - mountedCenter.X; - float projPosY = projectile.position.Y + (float)projectile.height * 0.5f - mountedCenter.Y; - Math.Sqrt((double)(projPosX * projPosX + projPosY * projPosY)); - bool canDraw = true; - if (projPosX == 0f && projPosY == 0f) - { - canDraw = false; - } - else - { - float projPosXY = (float)Math.Sqrt((double)(projPosX * projPosX + projPosY * projPosY)); - projPosXY = 12f / projPosXY; - projPosX *= projPosXY; - projPosY *= projPosXY; - mountedCenter.X -= projPosX; - mountedCenter.Y -= projPosY; - projPosX = projectile.position.X + (float)projectile.width * 0.5f - mountedCenter.X; - projPosY = projectile.position.Y + (float)projectile.height * 0.5f - mountedCenter.Y; - } - while (canDraw) - { - float height = 12f; - float positionMagnitude = (float)Math.Sqrt((double)(projPosX * projPosX + projPosY * projPosY)); - if (float.IsNaN(positionMagnitude) || float.IsNaN(positionMagnitude)) - { - canDraw = false; - } - else - { - if (positionMagnitude < 20f) - { - height = positionMagnitude - 8f; - canDraw = false; - } - positionMagnitude = 12f / positionMagnitude; - projPosX *= positionMagnitude; - projPosY *= positionMagnitude; - mountedCenter.X += projPosX; - mountedCenter.Y += projPosY; - projPosX = projectile.position.X + (float)projectile.width * 0.5f - mountedCenter.X; - projPosY = projectile.position.Y + (float)projectile.height * 0.1f - mountedCenter.Y; - if (positionMagnitude > 12f) - { - float positionInverseMultiplier = 0.3f; - float absVelocitySum = Math.Abs(projectile.velocity.X) + Math.Abs(projectile.velocity.Y); - if (absVelocitySum > 16f) - { - absVelocitySum = 16f; - } - absVelocitySum = 1f - absVelocitySum / 16f; - positionInverseMultiplier *= absVelocitySum; - absVelocitySum = positionMagnitude / 80f; - if (absVelocitySum > 1f) - { - absVelocitySum = 1f; - } - positionInverseMultiplier *= absVelocitySum; - if (positionInverseMultiplier < 0f) - { - positionInverseMultiplier = 0f; - } - absVelocitySum = 1f - projectile.localAI[0] / 100f; - positionInverseMultiplier *= absVelocitySum; - if (projPosY > 0f) - { - projPosY *= 1f + positionInverseMultiplier; - projPosX *= 1f - positionInverseMultiplier; - } - else - { - absVelocitySum = Math.Abs(projectile.velocity.X) / 3f; - if (absVelocitySum > 1f) - { - absVelocitySum = 1f; - } - absVelocitySum -= 0.5f; - positionInverseMultiplier *= absVelocitySum; - if (positionInverseMultiplier > 0f) - { - positionInverseMultiplier *= 2f; - } - projPosY *= 1f + positionInverseMultiplier; - projPosX *= 1f - positionInverseMultiplier; - } - } - float rotation2 = (float)Math.Atan2((double)projPosY, (double)projPosX) - MathHelper.PiOver2; - Color color2 = Lighting.GetColor((int)mountedCenter.X / 16, (int)(mountedCenter.Y / 16f), poleColor); + if (gravDir == -1f) + { + pPosY -= 12f; + } + Vector2 mountedCenter = new Vector2(pPosX, pPosY); + mountedCenter = player.RotatedRelativePoint(mountedCenter + new Vector2(8f), true) - new Vector2(8f); + float projPosX = projectile.position.X + (float)projectile.width * 0.5f - mountedCenter.X; + float projPosY = projectile.position.Y + (float)projectile.height * 0.5f - mountedCenter.Y; + Math.Sqrt((double)(projPosX * projPosX + projPosY * projPosY)); + bool canDraw = true; + if (projPosX == 0f && projPosY == 0f) + { + canDraw = false; + } + else + { + float projPosXY = (float)Math.Sqrt((double)(projPosX * projPosX + projPosY * projPosY)); + projPosXY = 12f / projPosXY; + projPosX *= projPosXY; + projPosY *= projPosXY; + mountedCenter.X -= projPosX; + mountedCenter.Y -= projPosY; + projPosX = projectile.position.X + (float)projectile.width * 0.5f - mountedCenter.X; + projPosY = projectile.position.Y + (float)projectile.height * 0.5f - mountedCenter.Y; + } + while (canDraw) + { + float height = 12f; + float positionMagnitude = (float)Math.Sqrt((double)(projPosX * projPosX + projPosY * projPosY)); + if (float.IsNaN(positionMagnitude) || float.IsNaN(positionMagnitude)) + { + canDraw = false; + } + else + { + if (positionMagnitude < 20f) + { + height = positionMagnitude - 8f; + canDraw = false; + } + positionMagnitude = 12f / positionMagnitude; + projPosX *= positionMagnitude; + projPosY *= positionMagnitude; + mountedCenter.X += projPosX; + mountedCenter.Y += projPosY; + projPosX = projectile.position.X + (float)projectile.width * 0.5f - mountedCenter.X; + projPosY = projectile.position.Y + (float)projectile.height * 0.1f - mountedCenter.Y; + if (positionMagnitude > 12f) + { + float positionInverseMultiplier = 0.3f; + float absVelocitySum = Math.Abs(projectile.velocity.X) + Math.Abs(projectile.velocity.Y); + if (absVelocitySum > 16f) + { + absVelocitySum = 16f; + } + absVelocitySum = 1f - absVelocitySum / 16f; + positionInverseMultiplier *= absVelocitySum; + absVelocitySum = positionMagnitude / 80f; + if (absVelocitySum > 1f) + { + absVelocitySum = 1f; + } + positionInverseMultiplier *= absVelocitySum; + if (positionInverseMultiplier < 0f) + { + positionInverseMultiplier = 0f; + } + absVelocitySum = 1f - projectile.localAI[0] / 100f; + positionInverseMultiplier *= absVelocitySum; + if (projPosY > 0f) + { + projPosY *= 1f + positionInverseMultiplier; + projPosX *= 1f - positionInverseMultiplier; + } + else + { + absVelocitySum = Math.Abs(projectile.velocity.X) / 3f; + if (absVelocitySum > 1f) + { + absVelocitySum = 1f; + } + absVelocitySum -= 0.5f; + positionInverseMultiplier *= absVelocitySum; + if (positionInverseMultiplier > 0f) + { + positionInverseMultiplier *= 2f; + } + projPosY *= 1f + positionInverseMultiplier; + projPosX *= 1f - positionInverseMultiplier; + } + } + float rotation2 = (float)Math.Atan2((double)projPosY, (double)projPosX) - MathHelper.PiOver2; + Color color2 = Lighting.GetColor((int)mountedCenter.X / 16, (int)(mountedCenter.Y / 16f), poleColor); - Main.spriteBatch.Draw(Main.fishingLineTexture, new Vector2(mountedCenter.X - Main.screenPosition.X + (float)Main.fishingLineTexture.Width * 0.5f, mountedCenter.Y - Main.screenPosition.Y + (float)Main.fishingLineTexture.Height * 0.5f), new Microsoft.Xna.Framework.Rectangle?(new Microsoft.Xna.Framework.Rectangle(0, 0, Main.fishingLineTexture.Width, (int)height)), color2, rotation2, new Vector2((float)Main.fishingLineTexture.Width * 0.5f, 0f), 1f, SpriteEffects.None, 0f); - } - } - } - } + Main.spriteBatch.Draw(Main.fishingLineTexture, new Vector2(mountedCenter.X - Main.screenPosition.X + (float)Main.fishingLineTexture.Width * 0.5f, mountedCenter.Y - Main.screenPosition.Y + (float)Main.fishingLineTexture.Height * 0.5f), new Microsoft.Xna.Framework.Rectangle?(new Microsoft.Xna.Framework.Rectangle(0, 0, Main.fishingLineTexture.Width, (int)height)), color2, rotation2, new Vector2((float)Main.fishingLineTexture.Width * 0.5f, 0f), 1f, SpriteEffects.None, 0f); + } + } + } + } - public static void DrawHook(this Projectile projectile, Texture2D hookTexture, float angleAdditive = 0f) - { - Player player = Main.player[projectile.owner]; - Vector2 center = projectile.Center; - float angleToMountedCenter = projectile.AngleTo(player.MountedCenter) - MathHelper.PiOver2; - bool canShowHook = true; - while (canShowHook) - { - float distanceMagnitude = (player.MountedCenter - center).Length(); //Exact same as using a Sqrt - if (distanceMagnitude < hookTexture.Height + 1f) - { - canShowHook = false; - } - else if (float.IsNaN(distanceMagnitude)) - { - canShowHook = false; - } - else - { - center += projectile.DirectionTo(player.MountedCenter) * hookTexture.Height; - Color tileAtCenterColor = Lighting.GetColor((int)center.X / 16, (int)(center.Y / 16f)); - Main.spriteBatch.Draw(hookTexture, center - Main.screenPosition, - new Rectangle?(new Rectangle(0, 0, hookTexture.Width, hookTexture.Height)), - tileAtCenterColor, angleToMountedCenter + angleAdditive, - hookTexture.Size() / 2, 1f, SpriteEffects.None, 0f); - } - } - } + public static void DrawHook(this Projectile projectile, Texture2D hookTexture, float angleAdditive = 0f) + { + Player player = Main.player[projectile.owner]; + Vector2 center = projectile.Center; + float angleToMountedCenter = projectile.AngleTo(player.MountedCenter) - MathHelper.PiOver2; + bool canShowHook = true; + while (canShowHook) + { + float distanceMagnitude = (player.MountedCenter - center).Length(); //Exact same as using a Sqrt + if (distanceMagnitude < hookTexture.Height + 1f) + { + canShowHook = false; + } + else if (float.IsNaN(distanceMagnitude)) + { + canShowHook = false; + } + else + { + center += projectile.DirectionTo(player.MountedCenter) * hookTexture.Height; + Color tileAtCenterColor = Lighting.GetColor((int)center.X / 16, (int)(center.Y / 16f)); + Main.spriteBatch.Draw(hookTexture, center - Main.screenPosition, + new Rectangle?(new Rectangle(0, 0, hookTexture.Width, hookTexture.Height)), + tileAtCenterColor, angleToMountedCenter + angleAdditive, + hookTexture.Size() / 2, 1f, SpriteEffects.None, 0f); + } + } + } - internal static void IterateDisco(ref Color c, ref float aiParam, in byte discoIter = 7) - { - switch (aiParam) - { - case 0f: - c.G += discoIter; - if (c.G >= 255) - { - c.G = 255; - aiParam = 1f; - } - break; - case 1f: - c.R -= discoIter; - if (c.R <= 0) - { - c.R = 0; - aiParam = 2f; - } - break; - case 2f: - c.B += discoIter; - if (c.B >= 255) - { - c.B = 255; - aiParam = 3f; - } - break; - case 3f: - c.G -= discoIter; - if (c.G <= 0) - { - c.G = 0; - aiParam = 4f; - } - break; - case 4f: - c.R += discoIter; - if (c.R >= 255) - { - c.R = 255; - aiParam = 5f; - } - break; - case 5f: - c.B -= discoIter; - if (c.B <= 0) - { - c.B = 0; - aiParam = 0f; - } - break; - default: - aiParam = 0f; - c = Color.Red; - break; - } - } + internal static void IterateDisco(ref Color c, ref float aiParam, in byte discoIter = 7) + { + switch (aiParam) + { + case 0f: + c.G += discoIter; + if (c.G >= 255) + { + c.G = 255; + aiParam = 1f; + } + break; + case 1f: + c.R -= discoIter; + if (c.R <= 0) + { + c.R = 0; + aiParam = 2f; + } + break; + case 2f: + c.B += discoIter; + if (c.B >= 255) + { + c.B = 255; + aiParam = 3f; + } + break; + case 3f: + c.G -= discoIter; + if (c.G <= 0) + { + c.G = 0; + aiParam = 4f; + } + break; + case 4f: + c.R += discoIter; + if (c.R >= 255) + { + c.R = 255; + aiParam = 5f; + } + break; + case 5f: + c.B -= discoIter; + if (c.B <= 0) + { + c.B = 0; + aiParam = 0f; + } + break; + default: + aiParam = 0f; + c = Color.Red; + break; + } + } - public static string ColorMessage(string msg, Color color) - { - StringBuilder sb = new StringBuilder(msg.Length + 12); - sb.Append("[c/").Append(color.Hex3()).Append(':').Append(msg).Append(']'); - return sb.ToString(); - } + public static string ColorMessage(string msg, Color color) + { + StringBuilder sb = new StringBuilder(msg.Length + 12); + sb.Append("[c/").Append(color.Hex3()).Append(':').Append(msg).Append(']'); + return sb.ToString(); + } - /// - /// Returns a color lerp that allows for smooth transitioning between two given colors - /// - /// The first color you want it to switch between - /// The second color you want it to switch between - /// How long you want it to take to swap between colors + /// + /// Returns a color lerp that allows for smooth transitioning between two given colors + /// + /// The first color you want it to switch between + /// The second color you want it to switch between + /// How long you want it to take to swap between colors public static Color ColorSwap(Color firstColor, Color secondColor, float seconds) { double timeMult = (double)(MathHelper.TwoPi / seconds); float colorMePurple = (float)((Math.Sin(timeMult * Main.GlobalTime) + 1) * 0.5f); return Color.Lerp(firstColor, secondColor, colorMePurple); } - /// - /// Returns a color lerp that supports multiple colors. - /// - /// The 0-1 incremental value used when interpolating. - /// The various colors to interpolate across. - /// - public static Color MulticolorLerp(float increment, params Color[] colors) - { - int currentColorIndex = (int)(increment * colors.Length); - Color currentColor = colors[currentColorIndex]; - Color nextColor = colors[(currentColorIndex + 1) % colors.Length]; - return Color.Lerp(currentColor, nextColor, increment * colors.Length % 1f); - } - #endregion + /// + /// Returns a color lerp that supports multiple colors. + /// + /// The 0-1 incremental value used when interpolating. + /// The various colors to interpolate across. + /// + public static Color MulticolorLerp(float increment, params Color[] colors) + { + int currentColorIndex = (int)(increment * colors.Length); + Color currentColor = colors[currentColorIndex]; + Color nextColor = colors[(currentColorIndex + 1) % colors.Length]; + return Color.Lerp(currentColor, nextColor, increment * colors.Length % 1f); + } + #endregion - #region Miscellaneous Utilities - public static T[] ShuffleArray(T[] array, Random rand = null) - { - if (rand is null) - rand = new Random(); + #region Miscellaneous Utilities + public static T[] ShuffleArray(T[] array, Random rand = null) + { + if (rand is null) + rand = new Random(); - for (int i = array.Length; i > 0; --i) - { - int j = rand.Next(i); - T tempElement = array[j]; - array[j] = array[i - 1]; - array[i - 1] = tempElement; - } - return array; - } + for (int i = array.Length; i > 0; --i) + { + int j = rand.Next(i); + T tempElement = array[j]; + array[j] = array[i - 1]; + array[i - 1] = tempElement; + } + return array; + } - /// - /// Retrieves all the colors from a and returns them as a 2D array. - /// - /// The texture to load. - /// - public static Color[,] GetColorsFromTexture(this Texture2D texture) - { - Color[] alignedColors = new Color[texture.Width * texture.Height]; - texture.GetData(alignedColors); // Fills the color array with all the colors in the texture + /// + /// Retrieves all the colors from a and returns them as a 2D array. + /// + /// The texture to load. + /// + public static Color[,] GetColorsFromTexture(this Texture2D texture) + { + Color[] alignedColors = new Color[texture.Width * texture.Height]; + texture.GetData(alignedColors); // Fills the color array with all the colors in the texture - Color[,] colors2D = new Color[texture.Width, texture.Height]; - for (int x = 0; x < texture.Width; x++) - { - for (int y = 0; y < texture.Height; y++) - { - colors2D[x, y] = alignedColors[x + y * texture.Width]; - } - } - return colors2D; - } + Color[,] colors2D = new Color[texture.Width, texture.Height]; + for (int x = 0; x < texture.Width; x++) + { + for (int y = 0; y < texture.Height; y++) + { + colors2D[x, y] = alignedColors[x + y * texture.Width]; + } + } + return colors2D; + } - public static string CombineStrings(params object[] args) - { - StringBuilder result = new StringBuilder(1024); - for(int i = 0; i < args.Length; ++i) - { - object o = args[i]; - result.Append(o.ToString()); - result.Append(' '); - } - return result.ToString(); - } + public static string CombineStrings(params object[] args) + { + StringBuilder result = new StringBuilder(1024); + for(int i = 0; i < args.Length; ++i) + { + object o = args[i]; + result.Append(o.ToString()); + result.Append(' '); + } + return result.ToString(); + } - /// - /// Calculates the sound volume and panning for a sound which is played at the specified location in the game world.
- /// Note that sound does not play on dedicated servers or during world generation. - ///
- /// The position the sound is emitting from. If either X or Y is -1, the sound does not fade with distance. - /// Whether the sound is considered ambient, which makes it use the ambient sound slider in the options. Defaults to false. - /// Volume and pan, in that order. Volume is always between 0 and 1. Pan is always between -1 and 1. - public static (float, float) CalculateSoundStats(Vector2 soundPos, bool ambient = false) - { - float volume = 0f; - float pan = 0f; + /// + /// Calculates the sound volume and panning for a sound which is played at the specified location in the game world.
+ /// Note that sound does not play on dedicated servers or during world generation. + ///
+ /// The position the sound is emitting from. If either X or Y is -1, the sound does not fade with distance. + /// Whether the sound is considered ambient, which makes it use the ambient sound slider in the options. Defaults to false. + /// Volume and pan, in that order. Volume is always between 0 and 1. Pan is always between -1 and 1. + public static (float, float) CalculateSoundStats(Vector2 soundPos, bool ambient = false) + { + float volume = 0f; + float pan = 0f; - if (soundPos.X == -1f || soundPos.Y == -1f) - volume = 1f; - else if (WorldGen.gen || Main.dedServ || Main.netMode == NetmodeID.Server) - volume = 0f; - else - { - float topLeftX = Main.screenPosition.X - Main.screenWidth * 2f; - float topLeftY = Main.screenPosition.Y - Main.screenHeight * 2f; + if (soundPos.X == -1f || soundPos.Y == -1f) + volume = 1f; + else if (WorldGen.gen || Main.dedServ || Main.netMode == NetmodeID.Server) + volume = 0f; + else + { + float topLeftX = Main.screenPosition.X - Main.screenWidth * 2f; + float topLeftY = Main.screenPosition.Y - Main.screenHeight * 2f; - // Sounds cannot be heard from more than ~2.5 screens away. - // This rectangle is 5x5 screens centered on the current screen center position. - Rectangle audibleArea = new Rectangle((int)topLeftX, (int)topLeftY, Main.screenWidth * 5, Main.screenHeight * 5); - Rectangle soundHitbox = new Rectangle((int)soundPos.X, (int)soundPos.Y, 1, 1); - Vector2 screenCenter = Main.screenPosition + new Vector2(Main.screenWidth * 0.5f, Main.screenHeight * 0.5f); - if (audibleArea.Intersects(soundHitbox)) - { - pan = (soundPos.X - screenCenter.X) / (Main.screenWidth * 0.5f); - float dist = Vector2.Distance(soundPos, screenCenter); - volume = 1f - (dist / (Main.screenWidth * 1.5f)); - } - } + // Sounds cannot be heard from more than ~2.5 screens away. + // This rectangle is 5x5 screens centered on the current screen center position. + Rectangle audibleArea = new Rectangle((int)topLeftX, (int)topLeftY, Main.screenWidth * 5, Main.screenHeight * 5); + Rectangle soundHitbox = new Rectangle((int)soundPos.X, (int)soundPos.Y, 1, 1); + Vector2 screenCenter = Main.screenPosition + new Vector2(Main.screenWidth * 0.5f, Main.screenHeight * 0.5f); + if (audibleArea.Intersects(soundHitbox)) + { + pan = (soundPos.X - screenCenter.X) / (Main.screenWidth * 0.5f); + float dist = Vector2.Distance(soundPos, screenCenter); + volume = 1f - (dist / (Main.screenWidth * 1.5f)); + } + } - pan = MathHelper.Clamp(pan, -1f, 1f); - volume = MathHelper.Clamp(volume, 0f, 1f); - if (ambient) - volume = Main.gameInactive ? 0f : volume * Main.ambientVolume; - else - volume *= Main.soundVolume; + pan = MathHelper.Clamp(pan, -1f, 1f); + volume = MathHelper.Clamp(volume, 0f, 1f); + if (ambient) + volume = Main.gameInactive ? 0f : volume * Main.ambientVolume; + else + volume *= Main.soundVolume; - // This is actually done by vanilla. I guess if the sound volume gets corrupted during gameplay, you can't blast your eardrums out. - volume = MathHelper.Clamp(volume, 0f, 1f); - return (volume, pan); - } + // This is actually done by vanilla. I guess if the sound volume gets corrupted during gameplay, you can't blast your eardrums out. + volume = MathHelper.Clamp(volume, 0f, 1f); + return (volume, pan); + } - /// - /// Convenience function to utilize CalculateSoundStats immediately on an existing sound effect.
- /// This allows updating a looping sound every single frame to have the correct volume and pan, even if the player drags the audio sliders around. - ///
- /// The SoundEffectInstance which is having its values updated. - /// The position the sound is emitting from. If either X or Y is -1, the sound does not fade with distance. - /// Whether the sound is considered ambient, which makes it use the ambient sound slider in the options. Defaults to false. - public static void ApplySoundStats(ref SoundEffectInstance sfx, Vector2 soundPos, bool ambient = false) - { - if (sfx is null || sfx.IsDisposed) - return; - (sfx.Volume, sfx.Pan) = CalculateSoundStats(soundPos, ambient); - } + /// + /// Convenience function to utilize CalculateSoundStats immediately on an existing sound effect.
+ /// This allows updating a looping sound every single frame to have the correct volume and pan, even if the player drags the audio sliders around. + ///
+ /// The SoundEffectInstance which is having its values updated. + /// The position the sound is emitting from. If either X or Y is -1, the sound does not fade with distance. + /// Whether the sound is considered ambient, which makes it use the ambient sound slider in the options. Defaults to false. + public static void ApplySoundStats(ref SoundEffectInstance sfx, Vector2 soundPos, bool ambient = false) + { + if (sfx is null || sfx.IsDisposed) + return; + (sfx.Volume, sfx.Pan) = CalculateSoundStats(soundPos, ambient); + } - public static void StartRain(bool torrentialTear = false) - { - int num = 86400; - int num2 = num / 24; - Main.rainTime = Main.rand.Next(num2 * 8, num); - if (Main.rand.NextBool(3)) - { - Main.rainTime += Main.rand.Next(0, num2); - } - if (Main.rand.NextBool(4)) - { - Main.rainTime += Main.rand.Next(0, num2 * 2); - } - if (Main.rand.NextBool(5)) - { - Main.rainTime += Main.rand.Next(0, num2 * 2); - } - if (Main.rand.NextBool(6)) - { - Main.rainTime += Main.rand.Next(0, num2 * 3); - } - if (Main.rand.NextBool(7)) - { - Main.rainTime += Main.rand.Next(0, num2 * 4); - } - if (Main.rand.NextBool(8)) - { - Main.rainTime += Main.rand.Next(0, num2 * 5); - } - float num3 = 1f; - if (Main.rand.NextBool(2)) - { - num3 += 0.05f; - } - if (Main.rand.NextBool(3)) - { - num3 += 0.1f; - } - if (Main.rand.NextBool(4)) - { - num3 += 0.15f; - } - if (Main.rand.NextBool(5)) - { - num3 += 0.2f; - } - Main.rainTime = (int)(Main.rainTime * num3); - Main.raining = true; + public static void StartRain(bool torrentialTear = false) + { + int num = 86400; + int num2 = num / 24; + Main.rainTime = Main.rand.Next(num2 * 8, num); + if (Main.rand.NextBool(3)) + { + Main.rainTime += Main.rand.Next(0, num2); + } + if (Main.rand.NextBool(4)) + { + Main.rainTime += Main.rand.Next(0, num2 * 2); + } + if (Main.rand.NextBool(5)) + { + Main.rainTime += Main.rand.Next(0, num2 * 2); + } + if (Main.rand.NextBool(6)) + { + Main.rainTime += Main.rand.Next(0, num2 * 3); + } + if (Main.rand.NextBool(7)) + { + Main.rainTime += Main.rand.Next(0, num2 * 4); + } + if (Main.rand.NextBool(8)) + { + Main.rainTime += Main.rand.Next(0, num2 * 5); + } + float num3 = 1f; + if (Main.rand.NextBool(2)) + { + num3 += 0.05f; + } + if (Main.rand.NextBool(3)) + { + num3 += 0.1f; + } + if (Main.rand.NextBool(4)) + { + num3 += 0.15f; + } + if (Main.rand.NextBool(5)) + { + num3 += 0.2f; + } + Main.rainTime = (int)(Main.rainTime * num3); + Main.raining = true; if (torrentialTear) TorrentialTear.AdjustRainSeverity(false); - CalamityNetcode.SyncWorld(); - } + CalamityNetcode.SyncWorld(); + } - public static void StartSandstorm() - { - typeof(Terraria.GameContent.Events.Sandstorm).GetMethod("StartSandstorm", BindingFlags.Static | BindingFlags.NonPublic).Invoke(null, null); - } + public static void StartSandstorm() + { + typeof(Terraria.GameContent.Events.Sandstorm).GetMethod("StartSandstorm", BindingFlags.Static | BindingFlags.NonPublic).Invoke(null, null); + } - public static void StopSandstorm() - { - Terraria.GameContent.Events.Sandstorm.Happening = false; - } + public static void StopSandstorm() + { + Terraria.GameContent.Events.Sandstorm.Happening = false; + } - public static void AddWithCondition(this List list, T type, bool condition) - { - if (condition) - list.Add(type); - } + public static void AddWithCondition(this List list, T type, bool condition) + { + if (condition) + list.Add(type); + } - public static void Inflict246DebuffsNPC(NPC target, int buff, float timeBase = 2f) - { + public static void Inflict246DebuffsNPC(NPC target, int buff, float timeBase = 2f) + { if (Main.rand.NextBool(4)) { target.AddBuff(buff, SecondsToFrames(timeBase * 3f), false); @@ -3889,10 +3863,10 @@ namespace CalamityMod { target.AddBuff(buff, SecondsToFrames(timeBase), false); } - } + } - public static void Inflict246DebuffsPvp(Player target, int buff, float timeBase = 2f) - { + public static void Inflict246DebuffsPvp(Player target, int buff, float timeBase = 2f) + { if (Main.rand.NextBool(4)) { target.AddBuff(buff, SecondsToFrames(timeBase * 3f), false); @@ -3905,18 +3879,18 @@ namespace CalamityMod { target.AddBuff(buff, SecondsToFrames(timeBase), false); } - } + } public static int SecondsToFrames(float seconds) => (int)(seconds * 60); - /// - /// Call this function to spawn explosion clouds at the specified location. Good for when NPCs or projectiles die and need to explode. - /// - /// The spot to spawn the explosion clouds - /// Number of times it loops to spawn gores - public static void ExplosionGores (Vector2 goreSource, int goreAmt) - { - Vector2 source = new Vector2(goreSource.X - 24f, goreSource.Y - 24f); + /// + /// Call this function to spawn explosion clouds at the specified location. Good for when NPCs or projectiles die and need to explode. + /// + /// The spot to spawn the explosion clouds + /// Number of times it loops to spawn gores + public static void ExplosionGores (Vector2 goreSource, int goreAmt) + { + Vector2 source = new Vector2(goreSource.X - 24f, goreSource.Y - 24f); for (int goreIndex = 0; goreIndex < goreAmt; goreIndex++) { float velocityMult = 0.33f; @@ -3946,7 +3920,7 @@ namespace CalamityMod gore.velocity.X -= 1f; gore.velocity.Y -= 1f; } - } + } // REMOVE THIS IN CALAMITY 1.4, it's a 1.4 Main.cs function public static float GetLerpValue(float from, float to, float t, bool clamped = false) @@ -3979,19 +3953,19 @@ namespace CalamityMod return (t - from) / (to - from); } - /// - /// Clamps the distance between vectors via normalization. - /// - /// The starting point. - /// The ending point. - /// The maximum possible distance between the two vectors before they get clamped. - public static void DistanceClamp(ref Vector2 start, ref Vector2 end, float maxDistance) - { - if (Vector2.Distance(end, start) > maxDistance) - { - end = start + Vector2.Normalize(end - start) * maxDistance; - } - } + /// + /// Clamps the distance between vectors via normalization. + /// + /// The starting point. + /// The ending point. + /// The maximum possible distance between the two vectors before they get clamped. + public static void DistanceClamp(ref Vector2 start, ref Vector2 end, float maxDistance) + { + if (Vector2.Distance(end, start) > maxDistance) + { + end = start + Vector2.Normalize(end - start) * maxDistance; + } + } // REMOVE THIS IN CALAMITY 1.4, it's a 1.4 World.cs function public static Rectangle ClampToWorld(Rectangle tileRectangle) @@ -4002,85 +3976,53 @@ namespace CalamityMod int num4 = Math.Max(0, Math.Min(tileRectangle.Bottom, Main.maxTilesY)); return new Rectangle(num, num2, num3 - num, num4 - num2); } - #endregion + #endregion - #region Saving, Loading, and Sending Utilities + #region Saving, Loading, and Sending Utilities + /// + /// Saves a mod item and appends the data to a . + /// + /// The tag to append to. + /// The item to save. + /// A number used for discerning the item out of multiple items. + public static void SaveModItem(TagCompound tag, Item itemToSave, int itemIndex = 0) + { + tag.Add($"mod{itemIndex}", itemToSave.modItem?.mod?.Name ?? string.Empty); + tag.Add($"name{itemIndex}", itemToSave.modItem?.Name ?? string.Empty); + } - /// - /// Binary serializes an object and returns the resultant byte array buffer. - /// - /// The object that is to be serialized. - /// The buffer. - public static byte[] SerializeObject(object toSerialize) - { - byte[] buffer; - using (var stream = new MemoryStream()) - { - new BinaryFormatter().Serialize(stream, toSerialize); - buffer = stream.ToArray(); - } - return buffer; - } + /// + /// Loads a mod item from a . + /// + /// The tag that contains the original item. + /// The number used to discern the item out of potentially multiple. + /// The original item. + public static Item LoadModItem(TagCompound tag, int itemIndex = 0) + { + string modName = tag.GetString($"mod{itemIndex}"); + string itemName = tag.GetString($"name{itemIndex}"); + Item item = new Item(); - /// - /// Deserializes a binary serialized buffer and returns the original object. - /// - /// The buffer. - /// The object that was serialized. - public static object DeserializeObject(byte[] buffer) - { - object deserializedData; - using (var stream = new MemoryStream(buffer)) - { - deserializedData = new BinaryFormatter().Deserialize(stream); - } - return deserializedData; - } + // Don't bother checking any further if something is an empty string. + // Doing the checks below would result in checking for a mod with an empty string for a name. + // This can cause highly unpredictable/unstable behavior, such as the game crashing when you hover + // over the item in the GUI. + if (string.IsNullOrEmpty(modName) || string.IsNullOrEmpty(itemName)) + { + item.type = ItemID.None; + return item; + } - /// - /// Saves a mod item and appends the data to a . - /// - /// The tag to append to. - /// The item to save. - /// A number used for discerning the item out of multiple items. - public static void SaveModItem(TagCompound tag, Item itemToSave, int itemIndex = 0) - { - tag.Add($"mod{itemIndex}", itemToSave.modItem?.mod?.Name ?? string.Empty); - tag.Add($"name{itemIndex}", itemToSave.modItem?.Name ?? string.Empty); - } - - /// - /// Loads a mod item from a . - /// - /// The tag that contains the original item. - /// The number used to discern the item out of potentially multiple. - /// The original item. - public static Item LoadModItem(TagCompound tag, int itemIndex = 0) - { - string modName = tag.GetString($"mod{itemIndex}"); - string itemName = tag.GetString($"name{itemIndex}"); - Item item = new Item(); - - // Don't bother checking any further if something is an empty string. - // Doing the checks below would result in checking for a mod with an empty string for a name. - // This can cause highly unpredictable/unstable behavior, such as the game crashing when you hover - // over the item in the GUI. - if (string.IsNullOrEmpty(modName) || string.IsNullOrEmpty(itemName)) - { - item.type = ItemID.None; - return item; - } - - int type = ModLoader.GetMod(modName)?.ItemType(itemName) ?? ItemID.None; - if (type > ItemID.None) - { - item.netDefaults(type); - item.modItem.Load(tag.GetCompound("data")); - object[] loadGlobalsParameters = new object[] { item, tag.GetList("globalData") }; - typeof(ItemIO).GetMethod("LoadGlobals", BindingFlags.Static | BindingFlags.NonPublic, null, new Type[] { typeof(Item), typeof(IList) }, null).Invoke(null, loadGlobalsParameters); - } - return item; - } - #endregion - } + int type = ModLoader.GetMod(modName)?.ItemType(itemName) ?? ItemID.None; + if (type > ItemID.None) + { + item.netDefaults(type); + item.modItem.Load(tag.GetCompound("data")); + object[] loadGlobalsParameters = new object[] { item, tag.GetList("globalData") }; + typeof(ItemIO).GetMethod("LoadGlobals", BindingFlags.Static | BindingFlags.NonPublic, null, new Type[] { typeof(Item), typeof(IList) }, null).Invoke(null, loadGlobalsParameters); + } + return item; + } + #endregion + } }