Abilities
The ability system draws buttons in the bottom-right corner that can be tapped to affect gameplay. Abilities feature cooldown support and several targetting modes.
Creating an ability
Tip: By creating a MyAbility class in your player, you'll be able to reference the casting player directly in any of your abilities
// MyPlayer.cs
public abstract class MyAbility : Ability
{
public new MyPlayer Player => (MyPlayer)base.Player;
}
Create a class that extends from MyAbility
and override CanTarget
OnTryActivate
and any of the other lifecycle methods
public partial class KillAbility : MyAbility
{
public override TargettingMode TargettingMode => TargettingMode.Nearest;
public override float MaxDistance => 1.5f;
public override int MaxTargets => 1;
public override Texture Icon => Assets.GetAsset<Texture>("Ability_Icons/kill_cleaver_icon.png");
public override float Cooldown => 30f;
public override bool CanTarget(Player p)
{
var op = (OfficePlayer)p;
return op.CurrentRole != Role.JANITOR && op.CurrentRole != Role.OVERSEER;
}
public override bool OnTryActivate(List<Player> targetPlayers, Vector2 positionOrDirection, float magnitude)
{
Player.KillerSpineAnimator.SpineInstance.StateMachine.SetTrigger("attack");
if (Network.IsServer)
{
Player.CallClient_ShowNotification("Kill (+20% EXP +$10)");
Player.Experience.Set(Player.Experience + 20);
Player.Cash.Set(Player.Cash + 10);
CallClient_KillPlayer(targetPlayers[0], Player);
}
return true;
}
public override bool CanUse()
{
return true;
}
[ClientRpc]
public static void KillPlayer(Player player, Player killer)
{
player.AddEffect<KillEffect>();
}
}
Draw the default ability UI in your Player.cs
if (IsLocal)
{
if (HasEffect<KillerEffect>())
{
DrawDefaultAbilityUI(new AbilityDrawOptions() {
AbilityElementSize = 125,
Abilities = new Ability[] { GetAbility<KillAbility>() }
});
}
}