You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
48 lines
1.8 KiB
48 lines
1.8 KiB
using System;
|
|
using System.Diagnostics;
|
|
using System.Threading.Tasks;
|
|
using Babushka.scripts.CSharp.Common.Inventory;
|
|
using Babushka.scripts.CSharp.Common.Util;
|
|
|
|
namespace Babushka.scripts.CSharp.Common.Fight.Actions;
|
|
|
|
public class EatBeetrootAction : FighterAction
|
|
{
|
|
public override Variant<float, Func<bool>> GetAnimationEnd() => 1;
|
|
public override bool NextDetail() => false;
|
|
|
|
private const int HealAmount = 20;
|
|
|
|
public override bool ShouldAbort()
|
|
{
|
|
Debug.Assert(FightWorld.Instance.itemBeetrootToEatForHealth != null,
|
|
"Item to eat for health has not been set in the FightWorld autoload");
|
|
return !InventoryManager.Instance.playerInventory!.HasItems(new ItemInstance
|
|
{ blueprint = FightWorld.Instance.itemBeetrootToEatForHealth });
|
|
}
|
|
|
|
public override async Task AnimateAction(AllFightersVisual allFightersVisual,
|
|
FightHappeningAnimationContext animationContext)
|
|
{
|
|
var fighter = HappeningData.fighterTurn.Current;
|
|
var fighterVisual = allFightersVisual.GetVisualForFighter(fighter);
|
|
fighterVisual.SpawnDamageIndicatorNumber($"+{HealAmount}");
|
|
animationContext.useHealItemIndicator.SpawnIndicator();
|
|
await fighterVisual.AnimateHeal();
|
|
}
|
|
|
|
public override void ExecuteAction()
|
|
{
|
|
var fighter = HappeningData.fighterTurn.Current;
|
|
|
|
var result = InventoryManager.Instance.playerInventory!.TryRemoveAllItems(
|
|
new ItemInstance { blueprint = FightWorld.Instance.itemBeetrootToEatForHealth! });
|
|
|
|
if (result != InventoryActionResult.Success)
|
|
throw new Exception("No Beetroot in inventory. This case should have been handled earlier");
|
|
|
|
fighter.ChangeHealth(HealAmount);
|
|
}
|
|
|
|
public override AllyActionButton BindToActionButton() => AllyActionButton.Talk; // Temporarily bound to talk button
|
|
} |