mirror of
https://github.com/YouHaveTrouble/YHTMod.git
synced 2026-05-11 21:56:54 +00:00
fix running without calamity installed
This commit is contained in:
+17
-11
@@ -1,9 +1,4 @@
|
||||
using System.Collections.Generic;
|
||||
using CalamityMod.NPCs.Crabulon;
|
||||
using CalamityMod.NPCs.DesertScourge;
|
||||
using CalamityMod.NPCs.HiveMind;
|
||||
using CalamityMod.NPCs.Perforator;
|
||||
using CalamityMod.NPCs.SlimeGod;
|
||||
using Microsoft.Xna.Framework;
|
||||
using Terraria;
|
||||
using Terraria.Chat;
|
||||
@@ -13,6 +8,7 @@ using Terraria.ModLoader;
|
||||
|
||||
namespace YHTMod.Changes;
|
||||
|
||||
[ExtendsFromMod("CalamityMod")]
|
||||
public class BossKillListener : GlobalNPC {
|
||||
|
||||
private static readonly Dictionary<int, string> BossIds = new();
|
||||
@@ -29,12 +25,22 @@ public class BossKillListener : GlobalNPC {
|
||||
BossIds.Add(NPCID.SkeletronHead, "skeletron");
|
||||
BossIds.Add(NPCID.WallofFlesh, "wall_of_flesh");
|
||||
|
||||
if (ModLoader.HasMod("CalamityMod")) {
|
||||
BossIds.Add(ModContent.NPCType<DesertScourgeHead>(), "desert_scourge");
|
||||
BossIds.Add(ModContent.NPCType<Crabulon>(), "crabulon");
|
||||
BossIds.Add(ModContent.NPCType<PerforatorHive>(), "perforators");
|
||||
BossIds.Add(ModContent.NPCType<HiveMind>(), "hive_mind");
|
||||
BossIds.Add(ModContent.NPCType<SlimeGodCore>(), "slime_god");
|
||||
Mod calamity = CalamityHelper.GetCalamityMod();
|
||||
if (calamity == null) return;
|
||||
if (calamity.TryFind("DesertScourgeHead", out ModNPC desertScourgeHead)) {
|
||||
BossIds.Add(desertScourgeHead.Type, "desert_scourge_head");
|
||||
}
|
||||
if (calamity.TryFind("Crabulon", out ModNPC crabulon)) {
|
||||
BossIds.Add(crabulon.Type, "crabulon");
|
||||
}
|
||||
if (calamity.TryFind("PerforatorHive", out ModNPC perforatorHive)) {
|
||||
BossIds.Add(perforatorHive.Type, "perforators");
|
||||
}
|
||||
if (calamity.TryFind("HiveMind", out ModNPC hiveMind)) {
|
||||
BossIds.Add(hiveMind.Type, "hive_mind");
|
||||
}
|
||||
if (calamity.TryFind("SlimeGodCore", out ModNPC slimeGodCore)) {
|
||||
BossIds.Add(slimeGodCore.Type, "slime_god");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,37 @@
|
||||
using System.Collections.Generic;
|
||||
using Terraria.ModLoader;
|
||||
|
||||
namespace YHTMod.Changes;
|
||||
|
||||
[ExtendsFromMod("CalamityMod")]
|
||||
public class CalamityHelper {
|
||||
|
||||
public static readonly CalamityHelper Instance = new();
|
||||
|
||||
private static Dictionary<string, int> _bossIconIds;
|
||||
|
||||
private static Mod _calamity;
|
||||
|
||||
private CalamityHelper() {
|
||||
ModLoader.TryGetMod("CalamityMod", out Mod calamity);
|
||||
_calamity = calamity;
|
||||
if (_calamity == null) return;
|
||||
|
||||
_bossIconIds = new Dictionary<string, int> {
|
||||
{ "desert_scourge", ModContent.TryFind("CalamityMod", "LoreDesertScourge", out ModItem item1) ? item1.Type : -1 },
|
||||
{ "crabulon", ModContent.TryFind("CalamityMod", "LoreCrabulon", out ModItem item2) ? item2.Type : -1 },
|
||||
{ "perforators", ModContent.TryFind("CalamityMod", "LorePerforators", out ModItem item3) ? item3.Type : -1 },
|
||||
{ "hive_mind", ModContent.TryFind("CalamityMod", "LoreHiveMind", out ModItem item4) ? item4.Type : -1 },
|
||||
{ "slime_god", ModContent.TryFind("CalamityMod", "LoreSlimeGod", out ModItem item5) ? item5.Type : -1 }
|
||||
};
|
||||
}
|
||||
|
||||
public static int GetBossIconId(string bossKey) {
|
||||
return _bossIconIds.GetValueOrDefault(bossKey, -1);
|
||||
}
|
||||
|
||||
public static Mod GetCalamityMod() {
|
||||
return _calamity;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -7,20 +7,39 @@ using Vector2 = Microsoft.Xna.Framework.Vector2;
|
||||
|
||||
namespace YHTMod.Changes;
|
||||
|
||||
[ExtendsFromMod("CalamityMod")]
|
||||
public class SummonerOnHitEffects : GlobalProjectile {
|
||||
|
||||
public override void OnSpawn(Projectile projectile, IEntitySource source) {
|
||||
if (ModLoader.HasMod("CalamityMod") && projectile.type == ModContent.ProjectileType<CalamityMod.Projectiles.Boss.ShaderainHostile>()) {
|
||||
if (source is EntitySource_Parent { Entity: Projectile parentProj }) {
|
||||
int shadeType = ModContent.ProjectileType<CalamityMod.Projectiles.Boss.ShadeNimbusHostile>();
|
||||
if (parentProj.type == shadeType && parentProj.friendly && !parentProj.hostile) {
|
||||
projectile.friendly = true;
|
||||
projectile.hostile = false;
|
||||
projectile.DamageType = DamageClass.Summon;
|
||||
projectile.damage = parentProj.damage;
|
||||
}
|
||||
}
|
||||
Mod calamity = CalamityHelper.GetCalamityMod();
|
||||
|
||||
if (calamity is null
|
||||
|| source is not EntitySource_Parent { Entity: Projectile { friendly: true } parentProj }
|
||||
|| parentProj.hostile
|
||||
) {
|
||||
base.OnSpawn(projectile, source);
|
||||
return;
|
||||
}
|
||||
|
||||
// Get Calamity projectile types safely
|
||||
if (!calamity.TryFind("ShadeNimbusHostile", out ModProjectile shadeNimbus)
|
||||
|| parentProj.type != shadeNimbus.Type
|
||||
) {
|
||||
base.OnSpawn(projectile, source);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!calamity.TryFind("ShaderainHostile", out ModProjectile shaderainHostile) ||
|
||||
projectile.type != shaderainHostile.Type) {
|
||||
base.OnSpawn(projectile, source);
|
||||
return;
|
||||
}
|
||||
|
||||
projectile.friendly = true;
|
||||
projectile.hostile = false;
|
||||
projectile.DamageType = DamageClass.Summon;
|
||||
projectile.damage = parentProj.damage;
|
||||
|
||||
base.OnSpawn(projectile, source);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user