Automatic cooldown registration + Mod call to register cooldowns from other mods
This commit is contained in:
1 parent
b6c2c82c57
commit
2b7a4f8de4
2 files changed
+71
-31
No files matched your search
@@ -1,4 +1,8 @@
|
||||
using System.Collections.Generic;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Reflection;
|
||||
using System.Runtime.Serialization;
|
||||
using Terraria.ModLoader;
|
||||
|
||||
namespace CalamityMod.Cooldowns
|
||||
{
|
||||
@@ -19,40 +23,67 @@ namespace CalamityMod.Cooldowns
|
||||
nameToNetID = new Dictionary<string, ushort>(defaultSize);
|
||||
|
||||
// TODO -- CooldownHandlers should be ILoadable in 1.4
|
||||
RegisterModCooldowns(CalamityMod.Instance);
|
||||
|
||||
#region Unused manual registration left here as backup
|
||||
// Vanilla cooldowns represented by the interface
|
||||
var potionSickness = Register<PotionSickness>(PotionSickness.ID);
|
||||
var chaosState = Register<ChaosState>(ChaosState.ID);
|
||||
var globalDodge = Register<GlobalDodge>(GlobalDodge.ID);
|
||||
//var potionSickness = Register<PotionSickness>(PotionSickness.ID);
|
||||
//var chaosState = Register<ChaosState>(ChaosState.ID);
|
||||
//var globalDodge = Register<GlobalDodge>(GlobalDodge.ID);
|
||||
|
||||
// Calamity cooldowns
|
||||
var aquaticHeartIceShield = Register<AquaticHeartIceShield>(AquaticHeartIceShield.ID);
|
||||
var bloodflareFrenzy = Register<BloodflareFrenzy>(BloodflareFrenzy.ID);
|
||||
var bloodflareRanged = Register<BloodflareRangedSet>(BloodflareRangedSet.ID);
|
||||
var brimflameFrenzy = Register<BrimflameFrenzy>(BrimflameFrenzy.ID);
|
||||
var counterScarf = Register<CounterScarf>(CounterScarf.ID);
|
||||
var divineBless = Register<DivineBless>(DivineBless.ID);
|
||||
var divingPlatesBreaking = Register<DivingPlatesBreaking>(DivingPlatesBreaking.ID);
|
||||
var divingPlatesBroken = Register<DivingPlatesBroken>(DivingPlatesBroken.ID);
|
||||
var draconicElixir = Register<DraconicElixir>(DraconicElixir.ID);
|
||||
var evasionScarf = Register<EvasionScarf>(EvasionScarf.ID);
|
||||
var fleshTotem = Register<FleshTotem>(FleshTotem.ID);
|
||||
var godSlayerDash = Register<GodSlayerDash>(GodSlayerDash.ID);
|
||||
var inkBomb = Register<InkBomb>(InkBomb.ID);
|
||||
var lionHeartShield = Register<LionHeartShield>(LionHeartShield.ID);
|
||||
var nebulousCore = Register<NebulousCore>(NebulousCore.ID);
|
||||
var omegaBlue = Register<OmegaBlue>(OmegaBlue.ID);
|
||||
var permafrostConcoction = Register<PermafrostConcoction>(PermafrostConcoction.ID);
|
||||
var plagueBlackout = Register<PlagueBlackout>(PlagueBlackout.ID);
|
||||
var prismaticLaser = Register<PrismaticLaser>(PrismaticLaser.ID);
|
||||
var profanedSoulArtifact = Register<ProfanedSoulArtifact>(ProfanedSoulArtifact.ID);
|
||||
var relicOfResilience = Register<RelicOfResilience>(RelicOfResilience.ID);
|
||||
var rogueBooster = Register<RogueBooster>(RogueBooster.ID);
|
||||
var sandCloak = Register<SandCloak>(SandCloak.ID);
|
||||
var silvaRevive = Register<SilvaRevive>(SilvaRevive.ID);
|
||||
var tarragonCloak = Register<TarragonCloak>(TarragonCloak.ID);
|
||||
var tarragonImmunity = Register<TarragonImmunity>(TarragonImmunity.ID);
|
||||
var universeSplitter = Register<UniverseSplitter>(UniverseSplitter.ID);
|
||||
//var aquaticHeartIceShield = Register<AquaticHeartIceShield>(AquaticHeartIceShield.ID);
|
||||
//var bloodflareFrenzy = Register<BloodflareFrenzy>(BloodflareFrenzy.ID);
|
||||
//var bloodflareRanged = Register<BloodflareRangedSet>(BloodflareRangedSet.ID);
|
||||
//var brimflameFrenzy = Register<BrimflameFrenzy>(BrimflameFrenzy.ID);
|
||||
//var counterScarf = Register<CounterScarf>(CounterScarf.ID);
|
||||
//var divineBless = Register<DivineBless>(DivineBless.ID);
|
||||
//var divingPlatesBreaking = Register<DivingPlatesBreaking>(DivingPlatesBreaking.ID);
|
||||
//var divingPlatesBroken = Register<DivingPlatesBroken>(DivingPlatesBroken.ID);
|
||||
//var draconicElixir = Register<DraconicElixir>(DraconicElixir.ID);
|
||||
//var evasionScarf = Register<EvasionScarf>(EvasionScarf.ID);
|
||||
//var fleshTotem = Register<FleshTotem>(FleshTotem.ID);
|
||||
//var godSlayerDash = Register<GodSlayerDash>(GodSlayerDash.ID);
|
||||
//var inkBomb = Register<InkBomb>(InkBomb.ID);
|
||||
//var lionHeartShield = Register<LionHeartShield>(LionHeartShield.ID);
|
||||
//var nebulousCore = Register<NebulousCore>(NebulousCore.ID);
|
||||
//var omegaBlue = Register<OmegaBlue>(OmegaBlue.ID);
|
||||
//var permafrostConcoction = Register<PermafrostConcoction>(PermafrostConcoction.ID);
|
||||
//var plagueBlackout = Register<PlagueBlackout>(PlagueBlackout.ID);
|
||||
//var prismaticLaser = Register<PrismaticLaser>(PrismaticLaser.ID);
|
||||
//var profanedSoulArtifact = Register<ProfanedSoulArtifact>(ProfanedSoulArtifact.ID);
|
||||
//var relicOfResilience = Register<RelicOfResilience>(RelicOfResilience.ID);
|
||||
//var rogueBooster = Register<RogueBooster>(RogueBooster.ID);
|
||||
//var sandCloak = Register<SandCloak>(SandCloak.ID);
|
||||
//var silvaRevive = Register<SilvaRevive>(SilvaRevive.ID);
|
||||
//var tarragonCloak = Register<TarragonCloak>(TarragonCloak.ID);
|
||||
//var tarragonImmunity = Register<TarragonImmunity>(TarragonImmunity.ID);
|
||||
//var universeSplitter = Register<UniverseSplitter>(UniverseSplitter.ID);
|
||||
#endregion
|
||||
}
|
||||
|
||||
public static void RegisterModCooldowns(Mod mod)
|
||||
{
|
||||
Type baseHandlerType = typeof(CooldownHandler);
|
||||
foreach (Type type in mod.Code.GetTypes())
|
||||
{
|
||||
if (type.IsSubclassOf(baseHandlerType) && !type.IsAbstract && type != baseHandlerType)
|
||||
{
|
||||
//Get the static property ID of the handler
|
||||
string handlerID = (string)type.GetProperty("ID").GetValue(null);
|
||||
|
||||
//If for whatever reason the ID is not set, create an ID from the mod and handler name
|
||||
if (handlerID == null)
|
||||
handlerID = mod.Name + "_" + type.Name;
|
||||
|
||||
//Use reflection to call the method. You can't use the type as the generic type argument of register here
|
||||
MethodInfo methodInfo = typeof(CooldownRegistry).GetMethod("Register", BindingFlags.Public | BindingFlags.Static);
|
||||
Type[] genericArguments = new Type[] { type };
|
||||
|
||||
MethodInfo genericRegister = methodInfo.MakeGenericMethod(genericArguments);
|
||||
genericRegister.Invoke(null, new object[] { handlerID });
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void Unload()
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using CalamityMod.CalPlayer;
|
||||
using CalamityMod.Cooldowns;
|
||||
using CalamityMod.Events;
|
||||
using CalamityMod.Items;
|
||||
using CalamityMod.Particles;
|
||||
@@ -2000,6 +2001,14 @@ namespace CalamityMod
|
||||
GeneralParticleHandler.LoadModParticleInstances(args[1] as Mod);
|
||||
return null;
|
||||
|
||||
case "RegisterModCoodlowns":
|
||||
if (args.Length != 2 || !(args[1] is Mod))
|
||||
return new ArgumentNullException("ERROR: Must specify a Mod instance to register cooldowns from.");
|
||||
|
||||
CooldownRegistry.RegisterModCooldowns(args[1] as Mod);
|
||||
return null;
|
||||
|
||||
|
||||
default:
|
||||
return new ArgumentException("ERROR: Invalid method name.");
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user