Skip to content

Commit

Permalink
Add AbilityHelper, bump version
Browse files Browse the repository at this point in the history
  • Loading branch information
doombubbles committed Sep 2, 2023
1 parent 80924e4 commit 9aa6923
Show file tree
Hide file tree
Showing 4 changed files with 226 additions and 10 deletions.
216 changes: 216 additions & 0 deletions BloonsTD6 Mod Helper/Api/Helpers/AbilityHelper.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,216 @@
using Il2CppAssets.Scripts.Models;
using Il2CppAssets.Scripts.Models.Towers.Behaviors.Abilities;
using Il2CppAssets.Scripts.Utils;
namespace BTD_Mod_Helper.Api.Helpers;

/// <summary>
/// A wrapper around AbilityModels for making them easier to create
/// </summary>
public class AbilityHelper : ModelHelper<AbilityModel>
{
/// Default name
/// <seealso cref="AbilityModel.displayName"/>
public string DisplayName
{
get => Model.displayName;
set => Model.displayName = value;
}

/// Default name
/// <seealso cref="AbilityModel.description"/>
public string Description
{
get => Model.description;
set => Model.description = value;
}

/// Default -1
/// <seealso cref="AbilityModel.animation"/>
public int Animation
{
get => Model.animation;
set => Model.animation = value;
}

/// Default 0
/// <seealso cref="AbilityModel.AnimationOffset"/>
public float AnimationOffset
{
get => Model.AnimationOffset;
set => Model.AnimationOffset = value;
}

/// Default ""
/// <seealso cref="AbilityModel.icon"/>
public string Icon
{
get => Model.icon.guidRef;
set => Model.icon.guidRef = value;
}

/// Default { guidRef = "" }
/// <seealso cref="AbilityModel.icon"/>
public SpriteReference IconReference
{
get => Model.icon;
set => Model.icon = value;
}

/// Default 0
/// <seealso cref="AbilityModel.Cooldown"/>
public float Cooldown
{
get => Model.Cooldown;
set => Model.Cooldown = value;
}

/// Default null
/// <seealso cref="AbilityModel.behaviors"/>
public Model[] Behaviors
{
get => Model.behaviors ?? new Il2CppReferenceArray<Model>(0);
set
{
Model.RemoveChildDependants(Model.behaviors);
Model.behaviors = value;
Model.AddChildDependants(Model.behaviors);
}
}


/// Default false
/// <seealso cref="AbilityModel.activateOnPreLeak"/>
public bool ActivateOnPreLeak
{
get => Model.activateOnPreLeak;
set => Model.activateOnPreLeak = value;
}

/// Default false
/// <seealso cref="AbilityModel.activateOnLeak"/>
public bool ActivateOnLeak
{
get => Model.activateOnLeak;
set => Model.activateOnLeak = value;
}

/// Default ""
/// <seealso cref="AbilityModel.addedViaUpgrade"/>
public string AddedViaUpgrade
{
get => Model.addedViaUpgrade;
set => Model.addedViaUpgrade = value;
}

/// Default 0
/// <seealso cref="AbilityModel.CooldownSpeedScale" />
public float CooldownSpeedScale
{
get => Model.CooldownSpeedScale;
set => Model.CooldownSpeedScale = value;
}

/// Default 0
/// <seealso cref="AbilityModel.livesCost" />
public int LivesCost
{
get => Model.livesCost;
set => Model.livesCost = value;
}

/// Default -1
/// <seealso cref="AbilityModel.maxActivationsPerRound" />
public int MaxActivationsPerRound
{
get => Model.maxActivationsPerRound;
set => Model.maxActivationsPerRound = value;
}

/// Default false
/// <seealso cref="AbilityModel.resetCooldownOnTierUpgrade" />
public bool ResetCooldownOnTierUpgrade
{
get => Model.resetCooldownOnTierUpgrade;
set => Model.resetCooldownOnTierUpgrade = value;
}

/// Default false
/// <seealso cref="AbilityModel.activateOnLivesLost" />
public bool ActivateOnLivesLost
{
get => Model.activateOnLivesLost;
set => Model.activateOnLivesLost = value;
}

/// Default true
/// <seealso cref="AbilityModel.enabled" />
public bool Enabled
{
get => Model.enabled;
set => Model.enabled = value;
}

/// Default false
/// <seealso cref="AbilityModel.canActivateBetweenRounds" />
public bool CanActivateBetweenRounds
{
get => Model.canActivateBetweenRounds;
set => Model.canActivateBetweenRounds = value;
}

/// Default false
/// <seealso cref="AbilityModel.sharedCooldown" />
public bool SharedCooldown
{
get => Model.sharedCooldown;
set => Model.sharedCooldown = value;
}

/// Default false
/// <seealso cref="AbilityModel.dontShowStacked" />
public bool DontShowStacked
{
get => Model.dontShowStacked;
set => Model.dontShowStacked = value;
}

/// Default false
/// <seealso cref="AbilityModel.animateOnMainAttackDisplay" />
public bool AnimateOnMainAttackDisplay
{
get => Model.animateOnMainAttackDisplay;
set => Model.animateOnMainAttackDisplay = value;
}

/// Default false
/// <seealso cref="AbilityModel.restrictAbilityAfterMaxRoundTimer" />
public bool RestrictAbilityAfterMaxRoundTimer
{
get => Model.restrictAbilityAfterMaxRoundTimer;
set => Model.restrictAbilityAfterMaxRoundTimer = value;
}

private AbilityHelper(AbilityModel model) : base(model)
{
}

/// <summary>
/// Begins construction of a new AttackModel with sensible default values
/// <param name="name">The model name (don't need the AbilityModel_ part)</param>
/// </summary>
public AbilityHelper
(string name = "") : base(new AbilityModel(name, name, name, -1, 0, new SpriteReference {guidRef = ""}, 0, null,
false, false, "", 0, 0, -1, false, false))
{
}

/// <summary>
/// Unwraps the model
/// </summary>
public static implicit operator AbilityModel(AbilityHelper helper) => helper.Model;

/// <summary>
/// Wraps a model
/// </summary>
public static implicit operator AbilityHelper(AbilityModel model) => new(model);
}
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,13 @@ public static bool Is<T>(this Il2CppObjectBase instance, out T castObject) where
castObject = instance?.TryCast<T>();
return castObject != null;
}

/// <inheritdoc cref="IsType{T}(Il2CppSystem.Object,out T)" />
public static bool Is<T>(this T instance, out T castObject) where T : Il2CppObjectBase
{
castObject = instance?.TryCast<T>();
return castObject != null;
}

/// <summary>
/// Gets the exact il2cpp type name of an object
Expand Down
11 changes: 2 additions & 9 deletions BloonsTD6 Mod Helper/LATEST.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,2 @@
- Now natively works on Epic Games version, and prompts user to download the compatability plugin to make other mods work if they don't have it
- Added ModHelperData `bool Plugin` field for mods that are MelonPlugins
- Fixed SteamWebView usage on the Epic Games version
- Fixed a crash that could happen on Linux (thanks @GrahamKracker)
- Fixed more crashes from TowerInventory / subtower interactions (thanks @Onixiya)
- Added `AttackHelper`, `WeaponHelper` and `ProjectileHelper` that can be used to less painfully create those models
from scratch
- The classes will implicitly convert themselves to their respective models
- Make use of the object initialization syntax; don't need to specific every single field, will use sensible defaults
- Added `AbilityHelper` class
- Reverted a previous change that was leading to a selling / rebuying 5th tiers issue
2 changes: 1 addition & 1 deletion BloonsTD6 Mod Helper/ModHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ namespace BTD_Mod_Helper;
public static class ModHelper
{
internal const string Name = "BloonsTD6 Mod Helper";
internal const string Version = "3.1.13";
internal const string Version = "3.1.14";
internal const string RepoOwner = "gurrenm3";
internal const string RepoName = "BTD-Mod-Helper";
internal const string Description =
Expand Down

1 comment on commit 9aa6923

@MLXVII
Copy link

@MLXVII MLXVII commented on 9aa6923 Sep 13, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yah

Please sign in to comment.