public override object Call(params object[] args) { try { string functionName = args[0] as string; switch (functionName) { case "AddWeaponRule": { // Vanilla Weapon Rule // args[1]: Mode ("Ban" or "Allow") // args[2]: Vanilla Weapon Type. e.g. ItemID.BeesKnees // Modded Weapon Rule // args[1]: Mode ("Ban" or "Allow") // args[2]: Your Mod's Internal Name. e.g. "ChensGradiusMod" // args[3]: Your Weapon's Internal name. e.g. "NewBowWeapon" if (args.Length > 4 && args.Length < 3) { throw new Exception($"ChensGradiusMod {functionName} Error: " + "Wrong number of arguments."); } string mode = args[1] as string; if (mode != "Ban" && mode != "Allow") { throw new Exception($"ChensGradiusMod {functionName} Error: " + "Unsupported mode. \"Ban\" and \"Allow\" are the supported modes."); } bool result = false; if (args.Length == 3) { result = OptionRules.AddWeaponRule(mode, Convert.ToInt32(args[2])); } else { result = OptionRules.AddWeaponRule(mode, args[2] as string, args[3] as string); } return(result); } case "AddProjectileRule": { // Vanilla Projectile Rule // args[1]: Mode ("Ban" or "Allow") // args[2]: Vanilla Projectile Type. e.g. ProjectileID.BeeArrow // Mod Projectile Rule // args[1]: Mode ("Ban" or "Allow") // args[2]: Your Mod's Internal Name. e.g. "ChensGradiusMod" // args[3]: Your Projectile's Internal name. e.g. "NewArrow" if (args.Length > 4 && args.Length < 3) { throw new Exception($"ChensGradiusMod {functionName} Error: " + "Wrong number of arguments."); } string mode = args[1] as string; if (mode != "Ban" && mode != "Allow") { throw new Exception($"ChensGradiusMod {functionName} Error: " + "Unsupported mode. \"Ban\" and \"Allow\" are the supported modes."); } bool result = false; if (args.Length == 3) { result = OptionRules.AddProjectileRule(mode, Convert.ToInt32(args[2])); } else { result = OptionRules.AddProjectileRule(mode, args[2] as string, args[3] as string); } return(result); } case "AddWeaponProjectilePairRule": { // Vanilla Weapon Projectile Pair Rule (or if the mod owns the modded weapons and projectiles) // args[1]: Mode ("Ban" or "Allow") // args[2]: Vanilla Weapon Type. e.g. ItemID.BeesKnees or ModContent.ItemType<NewGradiusGun>() // args[3]: Vanilla Projectile Type. e.g. ProjectileID.BeeArrow or ModContent.ProjectileType<GradiusLazor>() // Mod Projectile Rule // args[1]: Mode ("Ban" or "Allow") // args[2]: Your Mod's Internal Name. e.g. "ChensGradiusMod" // args[3]: Vanilla Projectile Type. e.g. "NewGradiusGun" // args[4]: Your Projectile's Internal name. e.g. "GradiusLazor" if (args.Length > 5 && args.Length < 4) { throw new Exception($"ChensGradiusMod {functionName} Error: " + "Wrong number of arguments."); } string mode = args[1] as string; if (mode != "Ban" && mode != "Allow") { throw new Exception($"ChensGradiusMod {functionName} Error: " + "Unsupported mode. \"Ban\" and \"Allow\" are the supported modes."); } bool result = false; if (args.Length == 4) { result = OptionRules.AddWeaponProjectilePairRule(mode, Convert.ToInt32(args[2]), Convert.ToInt32(args[3])); } else { result = OptionRules.AddWeaponProjectilePairRule(mode, args[2] as string, args[3] as string, args[4] as string); } return(result); } case "AddCustomDamage": { // Global Projectile Way // args[1]: Your Mod's Internal Name. e.g. "ChensGradiusMod" // args[2]: Internal class name of GlobalProjectile containing // the custom damage type. e.g. "MyGlobalProjectile" // args[3]: Internal boolean variable name of your custom damage. // Mod Projectile Way // args[1]: Your Mod's Internal Name. e.g. "ChensGradiusMod" // args[2]: Internal boolean variable name of your custom damage // found in your ModProjectile. if (!(args.Length == 4 || args.Length == 3)) { throw new Exception($"ChensGradiusMod {functionName} Error: " + "Wrong number of arguments."); } bool result = false; if (args.Length == 4) { result = OptionRules.ImportDamageType(args[1] as string, args[2] as string, args[3] as string); } else if (args.Length == 3) { result = OptionRules.ImportDamageType(args[1] as string, args[2] as string); } return(result); } default: { throw new Exception($"ChensGradiusMod {functionName} Error: " + "The function does not exist. Please visit the Wiki for the updated API."); } } } catch (Exception e) { Logger.Error("ChensGradiusMod Call Error: " + e.Message + e.StackTrace); } return(null); }
public override object Call(params object[] args) { try { string functionName = args[0] as string; switch (functionName) { case "BanOptionRule": { // Vanilla Projectile Rule // args[1]: Vanilla Weapon Type. e.g. ItemID.BeesKnees // args[2]: Vanilla Projectile Type. e.g. ProjectileID.Bee // ... or Mod Projectile Rule // args[1]: Your Mod's Internal Name. e.g. "ChensGradiusMod" // args[2]: Your Weapon's Internal name. e.g. "NewBowWeapon" // args[3]: Your Projectile's Internal name. e.g. "NewArrowsProjectile" if (args.Length > 4 && args.Length < 3) { throw new Exception($"ChensGradiusMod {functionName} Error: " + "Wrong number of arguments."); } bool result = false; if (args.Length == 3) { result = OptionRules.ImportBanOptionRule(Convert.ToInt32(args[1]), Convert.ToInt32(args[2])); } else { result = OptionRules.ImportBanOptionRule(args[1] as string, args[2] as string, args[3] as string); } return(result); } case "AllowOptionRule": { // Vanilla Projectile Rule // args[1]: Vanilla Weapon Type. e.g. ItemID.OnyxBlaster // args[2]: Vanilla Projectile Type. e.g. ProjectileID.BlackBolt // ... or Mod Projectile Rule // args[1]: Your Mod's Internal Name. e.g. "ChensGradiusMod" // args[2]: Your Weapon's Internal name. e.g. "NewBowWeapon" // args[3]: Your Projectile's Internal name. e.g. "NewArrowsProjectile" if (args.Length > 4 && args.Length < 3) { throw new Exception($"ChensGradiusMod {functionName} Error: " + "Wrong number of arguments."); } bool result = false; if (args.Length == 3) { result = OptionRules.ImportAllowOptionRule(Convert.ToInt32(args[1]), Convert.ToInt32(args[2])); } else { result = OptionRules.ImportAllowOptionRule(args[1] as string, args[2] as string, args[3] as string); } return(result); } case "AddCustomDamage": { // Global Projectile Way // args[1]: Your Mod's Internal Name. e.g. "ChensGradiusMod" // args[2]: Internal class name of GlobalProjectile containing // the custom damage type. e.g. "MyGlobalProjectile" // args[3]: Internal boolean variable name of your custom damage. // ... or Mod Projectile Way // args[1]: Your Mod's Internal Name. e.g. "ChensGradiusMod" // args[2]: Internal boolean variable name of your custom damage // found in your ModProjectile. if (!(args.Length == 4 || args.Length == 3)) { throw new Exception($"ChensGradiusMod {functionName} Error: " + "Wrong number of arguments."); } bool result = false; if (args.Length == 4) { result = OptionRules.ImportDamageType(args[1] as string, args[2] as string, args[3] as string); } else if (args.Length == 3) { result = OptionRules.ImportDamageType(args[1] as string, args[2] as string); } return(result); } case "BanCheck": { // args[1]: integer Type of the weapon to check. (item.type) // args[2]: integer Type of the projectile to check. (projectile.type) if (args.Length != 3) { throw new Exception($"ChensGradiusMod {functionName} Error: " + "Wrong number of arguments."); } return(OptionRules.IsBanned(Convert.ToInt32(args[1]), Convert.ToInt32(args[2]))); } case "AllowCheck": { // args[1]: integer Type of the weapon to check. (item.type) // args[2]: integer Type of the projectile to check. (projectile.type) if (args.Length != 3) { throw new Exception($"ChensGradiusMod {functionName} Error: " + "Wrong number of arguments."); } return(OptionRules.IsAllowed(Convert.ToInt32(args[1]), Convert.ToInt32(args[2]))); } default: { throw new Exception($"ChensGradiusMod {functionName} Error: " + "The function does not exist. Please visit the Wiki for the updated API."); } } } catch (Exception e) { Logger.Error("ChensGradiusMod Call Error: " + e.Message + e.StackTrace); } return(null); }