example-grass/Eat Da Rich/Eat/Eat.cs

119 lines
2.4 KiB
C#
Raw Normal View History

2025-07-20 11:22:53 +00:00
using Godot;
using System.Collections;
using System.Collections.Generic;
using Godot.Collections;
namespace Rokojori
{
[GlobalClass,Tool]
public partial class Eat:Action
{
[Export]
public OnCollision onCollision;
[Export]
public Action onAteSomething;
[Export]
public Pointer pointer;
2025-07-25 08:13:54 +00:00
[Export]
public Jump jump;
float _lastPig = 0;
2025-07-20 11:22:53 +00:00
protected override void _OnTrigger()
{
var pigs = onCollision.GetNodesInside();
var hasEaten = false;
2025-07-25 08:13:54 +00:00
var edr = Unique<EatDaRichGame>.Get();
var now = TimeLine.osTime;
var elapsed = now - _lastPig;
var fastMultiply = 1f;
var isFast = false;
var isAir = jump.IsJumping();
var isLongAir = jump.GetAirTime() > edr.gameStats.longAirDuration;
if ( elapsed < edr.gameStats.fastDurationInSeconds )
{
isFast = true;
fastMultiply = edr.gameStats.fastMultiply;
}
var ti = Unique<TimeInfo>.Get();
2025-07-20 11:22:53 +00:00
pigs.ForEach(
( p )=>
{
var eatable = p.Get<Eatable>();
this.LogInfo( eatable );
2025-07-22 14:08:35 +00:00
if ( eatable == null || ! eatable.isEatable )
{
2025-07-20 11:22:53 +00:00
return;
}
2025-07-22 14:08:35 +00:00
eatable.GetEaten();
2025-07-20 11:22:53 +00:00
2025-07-25 08:13:54 +00:00
var value = edr.gameStats.basicPigSeconds;
var info = "PIG";
if ( isAir )
{
value = edr.gameStats.pigInAirSeconds;
if ( isLongAir )
{
value *= edr.gameStats.longAirMultiply;
}
info = isLongAir ? "PIG + LONG-AIR-TIME" : "PIG + AIR";
}
if ( isFast )
{
info = "( " + info + ") * SUPER-FAST ";
}
if ( pigs.Count > 1 )
{
if ( ! isFast )
{
info = "( " + info + " )";
}
info += " x MULTI x " + pigs.Count;
}
var combinedValue = ( value * fastMultiply ) * pigs.Count;
edr.ChangeTime( combinedValue );
2025-07-20 11:22:53 +00:00
hasEaten = true;
2025-07-25 08:13:54 +00:00
ti.Show( info, 1 );
ti.Show( "+" + combinedValue._F() + "sec ", 2 );
2025-07-20 11:22:53 +00:00
}
);
if ( hasEaten )
{
2025-07-25 08:13:54 +00:00
_lastPig = now;
2025-07-20 11:22:53 +00:00
Trigger( onAteSomething );
}
this.LogInfo( pigs );
}
}
}