Mod Calls

From Mod of Redemption Wiki
Jump to navigation Jump to search

Mod Calls are special functions that can be used with tModLoader's .Call() function to get or set different values from other mods. This page lists the Mod Calls that are provided by the Mod of Redemption along with what they are used for.

Mod Calls Table

Function Returns Parameters
addElementNPC (bool) Whether the NPC possesses the Elemental bonus.
(int) The ID of the Elemental bonus to be applied to the NPC.
(int) The ID of the NPC to receive the Elemental bonus.
addElementItem (bool) Whether the item possesses the Elemental bonus. (int) The ID of the Elemental bonus to be applied to the item.
(int) The ID of the item to receive the Elemental bonus.
(optional bool) Whether projectiles fired from the item should inherit its elements. Only affects projectiles that don't already have elements.
addElementProj (bool) Whether the projectile possesses the Elemental bonus. (int) The ID of the Elemental bonus to be applied to the projectile.
(int) The ID of the projectile to receive the Elemental bonus.
(optional bool) Whether projectiles spawned from this projectile should inherit its elements. Only affects projectiles that don't already have elements.
addItemToBluntSwing (null) (int) The ID of the item to be excluded from receiving the Slash bonus.
addNPCToElementTypeList (null) (int) The ID of the NPC to be associated with an NPC type.
(string) The name of the NPC type. Many aliases are accepted.
elementOverrideItem (null) (Item) The item to apply the element to.
(int) The ID of the Elemental bonus to be applied to the item.
(int) The ID of override behavior. -1 to remove the element, 1 to add the element, 0 to set it to default.
elementOverrideNPC (null) (NPC) The NPC to apply the element to.
(int) The ID of the Elemental bonus to be applied to the NPC.
(int) The ID of override behavior. -1 to remove the element, 1 to add the element, 0 to set it to default.
elementOverrideProj (null) (Projectile) The projectile to apply the element to.
(int) The ID of the Elemental bonus to be applied to the projectile.
(int) The ID of override behavior. -1 to remove the element, 1 to add the element, 0 to set it to default.
hasElementItem (bool) Whether the item possesses the Elemental bonus. (Item) The item to check for an element.
(int) The ID of the Elemental bonus to be checked for.
hasElementNPC (bool) Whether the NPC possesses the Elemental bonus. (NPC) The NPC to check for an element.
(int) The ID of the Elemental bonus to be checked for.
hasElementProj (bool) Whether the projectile possesses the Elemental bonus. (Projectile) The projectile to check for an element.
(int) The ID of the Elemental bonus to be checked for.
getFirstElementItem (int) The ID of the first Elemental bonus found on the item. (Item) The item to check for.
(bool) Whether to ignore the Explosive bonus's ID.
getFirstElementNPC (int) The ID of the first Elemental bonus found on the NPC. (NPC) The NPC to check for.
(bool) Whether to ignore the Explosive bonus's ID.
getFirstElementProj (int) The ID of the first Elemental bonus found on the projectile. (Projectile) The projectile to check for.
(bool) Whether to ignore the Explosive bonus's ID.
elementMultiplier (null) (NPC) The NPC to apply the Elemental multiplier to.
(int) The ID of the Element to gain this multiplier.
(float) The damage multiplier for the element.
(optional bool) By default, this Mod Call automatically sets the NPC's multiplier values, for cases where your mod's SetDefaults() runs after this mod's. Setting this to true will disable that.
uncapBossElementMultiplier (bool) Whether the multiplier is uncapped or not (NPC) The boss NPC to uncap the Elemental Multiplier for.
(bool) Whether to uncap the Elemental Multiplier.
hideElementIcon (null) (Item) The item to hide the element icon.
(int) The ID of the Element to hide from tooltips.
(bool) Whether the element's tooltip is hidden.
decapitation (bool) Whether the NPC gets decapitated (NPC) The NPC target, this would usually be the 'target' parameter in a projectile's OnHitNPC() method.
(int) The hit's damage dealt, this would usually be the 'damageDone' parameter in a projectile's OnHitNPC() method.
(bool) Whether this was a crit or not, this would usually be 'hit.Crit', using the 'hit' parameter in a projectile's OnHitNPC() method.
(optional int) The chance to decapitate on this hit. 200 by default (1/200 chance).
setSlashBonus (bool) Whether the item has Slash Bonus applied. (Item) The item to give Slash Bonus to. This Mod Call is mostly for weapons that shoot held projectiles, and is automatically applied to weapons with the Swing useStyle (Unless tagged as Blunt).
(optional bool) Whether to set the bonus. True by default.
setAxeBonus (bool) Whether the item has Axe Bonus applied. (Item) The item to give Axe Bonus to. This Mod Call is mostly for axes that shoot held projectiles, and is automatically applied to items with axe power.
(optional bool) Whether to set the bonus. True by default.
setHammerBonus (bool) Whether the item has Hammer Bonus applied. (Item) The item to give Hammer Bonus to. This Mod Call is mostly for hammers that shoot held projectiles, and is automatically applied to items with hammer power.
(optional bool) Whether to set the bonus. True by default.
setHammerProj (bool) Whether the projectile has Hammer Bonus applied. (Projectile) The projectile to give Hammer Bonus to.
(optional bool) Whether to set the bonus. True by default.
setAxeProj (bool) Whether the projectile has Axe Bonus applied. (Projectile) The projectile to give Axe Bonus to.
(optional bool) Whether to set the bonus. True by default.
setSpearProj (bool) Whether the projectile has Spear Bonus applied. (Projectile) The projectile to give Spear Bonus to. For applying to items, use ItemID.Sets.Spears[].
(optional bool) Whether to set the bonus. True by default.
increaseElementalResistance (null) (Player) The player getting the increase.
(int) The ID of the Elemental bonus to be increased.
(float) The resistance increase. e.g. 0.1f would be 10% increase, -0.25f would be a 25% decrease.
increaseElementalDamage (null) (Player) The player getting the increase.
(int) The ID of the Elemental bonus to be increased.
(float) The damage increase. e.g. 0.1f would be 10% increase, -0.25f would be a 25% decrease.
RaveyardActive (bool) Whether the Raveyard event is currently active or not. (N/A)
alignment (int) The value of Alignment. (N/A)
bastionPos (Vector2) The top-left position of the Blazing Bastion area. (N/A)
UGPortalPos (Vector2) The top-left position of the Underground Portal area. (N/A)
goldenGatewayPos (Vector2) The top-left position of the Golden Gateway area. (N/A)
hallOfHeroesPos (Vector2) The top-left position of the Hall of Heroes area. (N/A)
natureShrinePos (Point16) The top-left position of the Nature Shrine area. (N/A)
labPos (Vector2) The top-left position of the Abandoned Laboratory area. (N/A)
surfacePortalPos (Vector2) The top-left position of the Surface Portal area. (N/A)
slayerShipPos (Vector2) The top-left position of the Crashed Ship area. (N/A)

An example class featuring methods and variables to help with using these Mod Calls is at the bottom of the page.

Aliases

Some of the functions above mention accepting different aliases for the string parameters. One alias for each flag will be listed below in tables for each function, however alternatives that use different cases or spacing will still be accepted.

addNPCToElementTypeList

Queriable Strings
Skeleton
SkeletonHumanoid
Humanoid
Undead
Spirit
Plantlike
Demon
Cold
Hot
Wet
Dragonlike
Inorganic
Robotic
Armed
Hallowed
Dark
Blood
Slime

Notes

  • Providing incorrect or too few/many arguments to any of these functions will result in an ArgumentException being thrown.

Helper Class Example

This assumes you have created a Mod variable in your Mod.cs called "redemptionMod"

public class Redemption 
{
    public static Mod Mod => YourMod.Instance.redemptionMod;
    public static class ElementID
    {
        public const short Arcane = 1;
        public const short Fire = 2;
        public const short Water = 3;
        public const short Ice = 4;
        public const short Earth = 5;
        public const short Wind = 6;
        public const short Thunder = 7;
        public const short Holy = 8;
        public const short Shadow = 9;
        public const short Nature = 10;
        public const short Poison = 11;
        public const short Blood = 12;
        public const short Psychic = 13;
        public const short Celestial = 14;
        public const short Explosive = 15;
    }

    public static class NPCType
	{
        public const string Skeleton = "Skeleton";
        public const string SkeletonHumanoid = "SkeletonHumanoid";
        public const string Humanoid = "Humanoid";
        public const string Undead = "Undead";
        public const string Spirit = "Spirit";
        public const string Plantlike = "Plantlike";
        public const string Demon = "Demon";
        public const string Cold = "Cold";
        public const string Hot = "Hot";
        public const string Wet = "Wet";
        public const string Dragonlike = "Dragonlike";
        public const string Inorganic = "Inorganic";
        public const string Robotic = "Robotic";
        public const string Armed = "Armed";
        public const string Hallowed = "Hallowed";
        public const string Dark = "Dark";
        public const string Blood = "Blood";
        public const string Slime = "Slime";
    }

    // ------------------------------------------------------------------------------------------------------
    // These go in SetStaticDefaults()
    public static void AddItemToBluntSwing(int itemType)
	{
		if (/* Check for if MoR is not enabled */)
			return;
        Mod.Call("addItemToBluntSwing", itemType);
	}

	public static void AddElement(Entity entity, int elementID, bool projsInheritElements = false)
	{
		if (/* Check for if MoR is not enabled */)
			return;
		if (entity is Item item)
            Mod.Call("addElementItem", elementID, item.type, projsInheritElements);
		else if (entity is NPC npc)
			Mod.Call("addElementNPC", elementID, npc.type);
		else if (entity is Projectile proj)
			Mod.Call("addElementProj", elementID, proj.type, projsInheritElements);
	}

	public static void AddElementToItem(int type, int elementID, bool projsInheritElements = false)
	{
		if (/* Check for if MoR is not enabled */)
			return;
		Mod.Call("addElementItem", elementID, type, projsInheritElements);
	}

	public static void AddElementToNPC(int type, int elementID)
	{
		if (/* Check for if MoR is not enabled */)
			return;
		Mod.Call("addElementNPC", elementID, type);
	}

	public static void AddElementToProjectile(int type, int elementID, bool projsInheritElements = false)
	{
		if (/* Check for if MoR is not enabled */)
			return;
		Mod.Call("addElementProj", elementID, type, projsInheritElements);
	}

	public static void AddNPCToElementList(int npcType, string typeString)
	{
		if (/* Check for if MoR is not enabled */)
			return;
		Mod.Call("addNPCToElementTypeList", typeString, npcType);
	}

	// ------------------------------------------------------------------------------------------------------
	// These are dynamic, so they can go in SetDefaults or wherever you want to update them
	// Keep in mind they don't get reset, so not required to put in an Update method that happens every frame
	public static void OverrideElement(Entity entity, int elementID, int overrideID = 1)
	{
		if (/* Check for if MoR is not enabled */)
			return;
		if (entity is Item item)
			Mod.Call("elementOverrideItem", item, elementID, overrideID);
		else if (entity is NPC npc)
			Mod.Call("elementOverrideNPC", npc, elementID, overrideID);
		else if (entity is Projectile proj)
			Mod.Call("elementOverrideProj", proj, elementID, overrideID);
	}

	public static void OverrideElementMultiplier(NPC npc, int elementID, float value = 1, bool dontSetMultipliers = false)
	{
		if (/* Check for if MoR is not enabled */)
			return;
		Mod.Call("elementMultiplier", npc, elementID, value, dontSetMultipliers);
	}

	public static void NoBossMultiplierCap(NPC npc, bool uncap = true)
	{
		if (/* Check for if MoR is not enabled */)
			return;
		Mod.Call("uncapBossElementMultiplier", npc, uncap);
	}

	public static void HideElementIcon(Item item, int elementID, bool hidden = true)
	{
		if (/* Check for if MoR is not enabled */)
			return;
		Mod.Call("hideElementIcon", item, elementID, hidden);
	}

	public static bool Decapitation(NPC target, ref int damageDone, ref bool crit, int chance = 200)
	{
		if (/* Check for if MoR is not enabled */)
			return false;
		return (bool)Mod.Call("decapitation", target, damageDone, crit, chance);
	}

	public static bool SetSlashBonus(Item item, bool setBonus = true)
	{
		if (/* Check for if MoR is not enabled */)
			return false;
		return (bool)Mod.Call("setSlashBonus", item, setBonus);
	}

	public static bool SetAxeBonus(Item item, bool setBonus = true)
	{
		if (/* Check for if MoR is not enabled */)
			return false;
		return (bool)Mod.Call("setAxeBonus", item, setBonus);
	}

	public static bool SetAxeBonus(Projectile proj, bool setBonus = true)
	{
		if (!CrossMod.Redemption.Enabled)
			return false;
		return (bool)Mod.Call("setAxeProj", proj, setBonus);
	}

	public static bool SetHammerBonus(Item item, bool setBonus = true)
	{
		if (!CrossMod.Redemption.Enabled)
			return false;
		return (bool)Mod.Call("setHammerBonus", item, setBonus);
	}

	public static bool SetHammerBonus(Projectile proj, bool setBonus = true)
	{
		if (!CrossMod.Redemption.Enabled)
			return false;
		return (bool)Mod.Call("setHammerProj", proj, setBonus);
	}

	// Items already have "ItemID.Sets.Spears[Item.type]" to set them as spears
	public static bool SetSpearBonus(Projectile proj, bool setBonus = true)
	{
		if (!CrossMod.Redemption.Enabled)
			return false;
		return (bool)Mod.Call("setSpearProj", proj, setBonus);
	}

	// ------------------------------------------------------------------------------------------------------
	public static bool HasElement(Entity entity, int elementID)
	{
		if (!CrossMod.Redemption.Enabled)
			return false;
		if (entity is Item item)
			return (bool)Mod.Call("hasElementItem", item, elementID);
		else if (entity is NPC npc)
			return (bool)Mod.Call("elementOverrideNPC", npc, elementID);
		else if (entity is Projectile proj)
			return (bool)Mod.Call("elementOverrideProj", proj, elementID);
		return false;
	}
	public static int GetFirstElement(Entity entity, bool ignoreExplosive = false)
	{
		if (!CrossMod.Redemption.Enabled)
			return 0;
		if (entity is Item item)
			return (int)Mod.Call("getFirstElementItem", item, ignoreExplosive);
		else if (entity is NPC npc)
			return (int)Mod.Call("getFirstElementNPC", npc, ignoreExplosive);
		else if (entity is Projectile proj)
			return (int)Mod.Call("getFirstElementProj", proj, ignoreExplosive);
		return 0;
	}
}