file refactor
This commit is contained in:
parent
da5a3e874b
commit
bffb012a26
175 changed files with 1086 additions and 1107 deletions
47
scripts/plants/behaviours/AloeBehaviour.cs
Normal file
47
scripts/plants/behaviours/AloeBehaviour.cs
Normal file
|
|
@ -0,0 +1,47 @@
|
|||
using Godot;
|
||||
using Newlon.Components.Level;
|
||||
|
||||
namespace Newlon.Components.Plants.Behaviours;
|
||||
|
||||
public partial class AloeBehaviour : BaseBehaviour
|
||||
{
|
||||
[Export] private float _hpTreshold = 0.25f;
|
||||
private Timer _timer;
|
||||
private bool _charge = true;
|
||||
|
||||
public override void _Ready()
|
||||
{
|
||||
base._Ready();
|
||||
_timer = GetNode<Timer>("Timer");
|
||||
}
|
||||
|
||||
public override void _Process(double delta)
|
||||
{
|
||||
_tree.Set("parameters/Tree/conditions/charged",_charge);
|
||||
|
||||
var checkPos = GetParent<Node2D>().GlobalPosition + Vector2.Right * Utility.TileWidth;
|
||||
if(_charge && PoolContainer.Instance.TryGetEntity(checkPos, out RuntimePlantData plantData))
|
||||
{
|
||||
if((float)plantData.HP / (float)plantData.MaxHP < _hpTreshold)
|
||||
{
|
||||
_charge = false;
|
||||
_tree.Set("parameters/Tree/conditions/heal",true);
|
||||
_timer.Start();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void Heal()
|
||||
{
|
||||
var checkPos = GetParent<Node2D>().GlobalPosition + Vector2.Right * Utility.TileWidth;
|
||||
if (PoolContainer.Instance.TryGetEntity(checkPos, out RuntimePlantData plantData))
|
||||
{
|
||||
plantData.Heal(3000 + 25 * plantData.MaxHP, GetParent());
|
||||
}
|
||||
}
|
||||
|
||||
public void OnTimeout()
|
||||
{
|
||||
_charge = true;
|
||||
}
|
||||
}
|
||||
1
scripts/plants/behaviours/AloeBehaviour.cs.uid
Normal file
1
scripts/plants/behaviours/AloeBehaviour.cs.uid
Normal file
|
|
@ -0,0 +1 @@
|
|||
uid://cljytsmqac0w7
|
||||
12
scripts/plants/behaviours/BaseBehaviour.cs
Normal file
12
scripts/plants/behaviours/BaseBehaviour.cs
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
using Godot;
|
||||
|
||||
namespace Newlon.Components;
|
||||
|
||||
public abstract partial class BaseBehaviour : Node
|
||||
{
|
||||
protected AnimationTree _tree;
|
||||
public override void _Ready()
|
||||
{
|
||||
_tree = GetNode<AnimationTree>("../AnimationTree");
|
||||
}
|
||||
}
|
||||
1
scripts/plants/behaviours/BaseBehaviour.cs.uid
Normal file
1
scripts/plants/behaviours/BaseBehaviour.cs.uid
Normal file
|
|
@ -0,0 +1 @@
|
|||
uid://3dbmgnr7qxee
|
||||
18
scripts/plants/behaviours/HpBasedBehaviour.cs
Normal file
18
scripts/plants/behaviours/HpBasedBehaviour.cs
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
using Godot;
|
||||
|
||||
namespace Newlon.Components.Plants.Behaviours;
|
||||
|
||||
public partial class HpBasedBehaviour : BaseBehaviour
|
||||
{
|
||||
private RuntimePlantData _data;
|
||||
public override void _Ready()
|
||||
{
|
||||
base._Ready();
|
||||
_data = GetParent<RuntimePlantData>();
|
||||
}
|
||||
|
||||
public void OnHPChanged(int amount,Node origin)
|
||||
{
|
||||
_tree.Set("parameters/Tree/blend_position",(float)_data.HP/_data.MaxHP);
|
||||
}
|
||||
}
|
||||
1
scripts/plants/behaviours/HpBasedBehaviour.cs.uid
Normal file
1
scripts/plants/behaviours/HpBasedBehaviour.cs.uid
Normal file
|
|
@ -0,0 +1 @@
|
|||
uid://btkmd86pn828y
|
||||
16
scripts/plants/behaviours/PeashooterBehaviour.cs
Normal file
16
scripts/plants/behaviours/PeashooterBehaviour.cs
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
using Godot;
|
||||
|
||||
namespace Newlon.Components.Plants.Behaviours;
|
||||
|
||||
public partial class PeashooterBehaviour : BaseBehaviour
|
||||
{
|
||||
[Export] private Timer _shootTimer;
|
||||
[Export] private Eyesight _sight;
|
||||
|
||||
public override void _Process(double delta)
|
||||
{
|
||||
bool readyToShoot = _sight.EnemyDetected && _shootTimer.TimeLeft <= 0;
|
||||
|
||||
_tree.Set("parameters/Tree/conditions/ready",readyToShoot);
|
||||
}
|
||||
}
|
||||
1
scripts/plants/behaviours/PeashooterBehaviour.cs.uid
Normal file
1
scripts/plants/behaviours/PeashooterBehaviour.cs.uid
Normal file
|
|
@ -0,0 +1 @@
|
|||
uid://bdk5iqtw4xbkl
|
||||
28
scripts/plants/behaviours/PotatomineBehaviour.cs
Normal file
28
scripts/plants/behaviours/PotatomineBehaviour.cs
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
using Godot;
|
||||
|
||||
namespace Newlon.Components.Plants.Behaviours;
|
||||
|
||||
public partial class PotatomineBehaviour : BaseBehaviour
|
||||
{
|
||||
[Export] private Area2D _hitbox;
|
||||
[Export] private CollisionShape2D _unprimedShape;
|
||||
[Export] private CollisionShape2D _primedShape;
|
||||
private bool _primed = false;
|
||||
public void Prime()
|
||||
{
|
||||
_tree.Set("parameters/Tree/conditions/primed",true);
|
||||
|
||||
_hitbox.Monitorable = false;
|
||||
|
||||
_primed = true;
|
||||
_unprimedShape.Disabled = true;
|
||||
_primedShape.Disabled = false;
|
||||
}
|
||||
|
||||
public void OnAreaEntered(Area2D area)
|
||||
{
|
||||
if (_primed == false) return;
|
||||
_tree.Set("parameters/Tree/conditions/explode",true);
|
||||
_primed = false;
|
||||
}
|
||||
}
|
||||
1
scripts/plants/behaviours/PotatomineBehaviour.cs.uid
Normal file
1
scripts/plants/behaviours/PotatomineBehaviour.cs.uid
Normal file
|
|
@ -0,0 +1 @@
|
|||
uid://c7qfh4py0uulo
|
||||
19
scripts/plants/behaviours/SpikeweedBehaviour.cs
Normal file
19
scripts/plants/behaviours/SpikeweedBehaviour.cs
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
using Godot;
|
||||
|
||||
namespace Newlon.Components.Plants.Behaviours;
|
||||
|
||||
public partial class SpikeweedBehaviour : BaseBehaviour
|
||||
{
|
||||
private int _inCount = 0;
|
||||
public void OnHitboxEntered(Area2D _area)
|
||||
{
|
||||
if (_inCount++ == 0)
|
||||
_tree.Set("parameters/Tree/blend_position",1);
|
||||
}
|
||||
|
||||
public void OnHitboxExited(Area2D _area)
|
||||
{
|
||||
if (--_inCount == 0)
|
||||
_tree.Set("parameters/Tree/blend_position",0);
|
||||
}
|
||||
}
|
||||
1
scripts/plants/behaviours/SpikeweedBehaviour.cs.uid
Normal file
1
scripts/plants/behaviours/SpikeweedBehaviour.cs.uid
Normal file
|
|
@ -0,0 +1 @@
|
|||
uid://dqquodxaijmem
|
||||
12
scripts/plants/behaviours/SunflowerBehaviour.cs
Normal file
12
scripts/plants/behaviours/SunflowerBehaviour.cs
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
using Godot;
|
||||
|
||||
namespace Newlon.Components.Plants.Behaviours;
|
||||
|
||||
public partial class SunflowerBehaviour : BaseBehaviour
|
||||
{
|
||||
public void Timeout()
|
||||
{
|
||||
_tree.Set("parameters/Tree/conditions/produce", true);
|
||||
}
|
||||
|
||||
}
|
||||
1
scripts/plants/behaviours/SunflowerBehaviour.cs.uid
Normal file
1
scripts/plants/behaviours/SunflowerBehaviour.cs.uid
Normal file
|
|
@ -0,0 +1 @@
|
|||
uid://bth7gah4tn7uj
|
||||
Loading…
Add table
Add a link
Reference in a new issue