Wednesday, 27 August 2025 01:54:42
This commit is contained in:
@@ -5,22 +5,26 @@ using System.ComponentModel.DataAnnotations;
|
||||
using System.Diagnostics;
|
||||
using System.Linq;
|
||||
|
||||
public partial class Worker : RigidBody2D
|
||||
public partial class Worker : CharacterBody2D
|
||||
{
|
||||
public bool _dead = false, _hovered = false, _held = false, _placed = false, _selected = false, _primed = false, _moving = false, _staminaCanDrain = true;
|
||||
public int _health, _healthMax;
|
||||
public float _stamina, _staminaMax;
|
||||
public bool _dead = false, _hovered = false, _held = false, _selected = false;
|
||||
public int _size, _health, _healthMax;
|
||||
public float _distanceTraveled, _stamina, _staminaMax;
|
||||
public Stat _aptitude = new(), _agility = new(), _ardor = new(), _accumen = new(), _awareness = new(), _appeal = new();
|
||||
public float _rotationalForce = 0;
|
||||
public Vector2 _force = Vector2.Zero;
|
||||
public Node _collisionTarget;
|
||||
public Vector2 _chainPosition = new Vector2(-1, -1);
|
||||
public List<Vector2> _moves = new();
|
||||
public Sprite2D _image;
|
||||
public ProgressBar _healthBar;
|
||||
public Manager _manager;
|
||||
public List<Action> _actions = new();
|
||||
public List<Condition> _conditions = new();
|
||||
public Node _actions;
|
||||
public Node _conditions;
|
||||
public override void _Ready()
|
||||
{
|
||||
_actions = GetNode("Actions");
|
||||
_conditions = GetNode("Conditions");
|
||||
_size = (int)(((CircleShape2D)GetNode<CollisionShape2D>("Bounds").Shape).Radius);
|
||||
|
||||
_aptitude._default = 5;
|
||||
_agility._default = 5;
|
||||
_ardor._default = 5;
|
||||
@@ -37,7 +41,7 @@ public partial class Worker : RigidBody2D
|
||||
|
||||
_image = GetNode<Sprite2D>("Sprite2D");
|
||||
|
||||
_actions.Add(new BasicAttack(this));
|
||||
_actions.AddChild(new BasicAttack(this));
|
||||
|
||||
// _healthBar = GetNode<ProgressBar>("HealthBar");
|
||||
// _healthBar.MaxValue = _healthMax;
|
||||
@@ -46,118 +50,62 @@ public partial class Worker : RigidBody2D
|
||||
|
||||
public override void _Process(double DELTA_)
|
||||
{
|
||||
if (!_moving)
|
||||
if (Globals.Instance._battleRunning)
|
||||
{
|
||||
if (!_placed)
|
||||
{
|
||||
if (!_held)
|
||||
{
|
||||
if (_hovered)
|
||||
{
|
||||
if (Input.IsActionJustPressed("left_click"))
|
||||
{
|
||||
Hold();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (_selected)
|
||||
{
|
||||
Vector2 mousePosition = GetGlobalMousePosition();
|
||||
LookAt(mousePosition);
|
||||
if (Input.IsActionJustReleased("left_click"))
|
||||
{
|
||||
_selected = false;
|
||||
_force = (GlobalPosition - mousePosition) * 100;
|
||||
_stamina = _agility._effective;
|
||||
_primed = true;
|
||||
}
|
||||
}
|
||||
else if (_hovered)
|
||||
{
|
||||
if (Input.IsActionJustPressed("left_click"))
|
||||
{
|
||||
_selected = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
_chainPosition = GlobalPosition;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Vector2 towardCenter = (Globals.Instance._screenCenter - GlobalPosition).Normalized();
|
||||
// ApplyCentralForce(towardCenter * 100);
|
||||
_image.Rotate(_stamina);
|
||||
if (_staminaCanDrain)
|
||||
{
|
||||
_stamina -= 0.25f / 60;
|
||||
}
|
||||
if (_stamina <= 0f)
|
||||
{
|
||||
Stop();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public override void _PhysicsProcess(double DELTA_)
|
||||
{
|
||||
if (_held)
|
||||
{
|
||||
GlobalPosition = GetGlobalMousePosition();
|
||||
if (Input.IsActionJustReleased("left_click"))
|
||||
{
|
||||
Transform2D newTransform = GlobalTransform;
|
||||
newTransform.Origin = Position;
|
||||
GlobalTransform = newTransform;
|
||||
Drop();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void ChangeHealth(int CHANGE, Node CHANGEMAKER)
|
||||
{
|
||||
if (_health <= 0 && CHANGE < 0)
|
||||
{
|
||||
// knock the piece off the board and out for the round!
|
||||
// process on knockout
|
||||
}
|
||||
_health += CHANGE;
|
||||
_healthBar.Value = _health;
|
||||
if (_health <= 0)
|
||||
{
|
||||
Sleeping = true;
|
||||
_dead = true;
|
||||
_health = 0;
|
||||
FireActions(Trigger.On.Death, _manager);
|
||||
}
|
||||
}
|
||||
// public void ChangeHealth(int CHANGE, Node CHANGEMAKER)
|
||||
// {
|
||||
// if (_health <= 0 && CHANGE < 0)
|
||||
// {
|
||||
// // knock the piece off the board and out for the round!
|
||||
// // process on knockout
|
||||
// }
|
||||
// _health += CHANGE;
|
||||
// _healthBar.Value = _health;
|
||||
// if (_health <= 0)
|
||||
// {
|
||||
// Sleeping = true;
|
||||
// _dead = true;
|
||||
// _health = 0;
|
||||
// FireActions(Trigger.On.Death, _manager);
|
||||
// }
|
||||
// }
|
||||
|
||||
public void Drop()
|
||||
{
|
||||
if (_held)
|
||||
{
|
||||
_held = false;
|
||||
_placed = true;
|
||||
Freeze = false;
|
||||
}
|
||||
}
|
||||
|
||||
public void FireActions(Trigger.On TRIGGER, Node TARGET = null)
|
||||
{
|
||||
List<Action> triggeredActions = _actions.Where(e => e._triggers.Contains(TRIGGER)).ToList();
|
||||
for (int i = 0; i < triggeredActions.Count; i++)
|
||||
List<Node> children = _actions.GetChildren().ToList();
|
||||
for (int i = 0; i < children.Count; i++)
|
||||
{
|
||||
triggeredActions[i].Target(TARGET);
|
||||
triggeredActions[i].Fire();
|
||||
if (children[i] is Action)
|
||||
{
|
||||
Action action = (Action)children[i];
|
||||
if (action._triggers.Contains(TRIGGER))
|
||||
{
|
||||
action.Target(TARGET);
|
||||
action.Fire();
|
||||
}
|
||||
}
|
||||
}
|
||||
List<Action> expiredActions = _actions.Where(e => e._triggers.Contains(TRIGGER)).ToList();
|
||||
_actions.Except(expiredActions);
|
||||
}
|
||||
|
||||
public bool HasCondition(string CONDITION)
|
||||
{
|
||||
List<string> conditionNames = _conditions.Select(c => c.GetType().ToString()).ToList();
|
||||
List<string> conditionNames = _conditions.GetChildren().Select(c => c.GetType().ToString()).ToList();
|
||||
return conditionNames.Contains(CONDITION);
|
||||
}
|
||||
|
||||
@@ -167,29 +115,9 @@ public partial class Worker : RigidBody2D
|
||||
{
|
||||
return;
|
||||
}
|
||||
Freeze = true;
|
||||
_held = true;
|
||||
}
|
||||
|
||||
public void Launch()
|
||||
{
|
||||
GravityScale = 1.0f;
|
||||
_moving = true;
|
||||
ApplyCentralForce(_force);
|
||||
_force = Vector2.Zero;
|
||||
_primed = false;
|
||||
FireActions(Trigger.On.Launch, _manager);
|
||||
}
|
||||
|
||||
public void Stop()
|
||||
{
|
||||
GravityScale = 0.0f;
|
||||
Sleeping = true;
|
||||
_moving = false;
|
||||
_stamina = 0f;
|
||||
FireActions(Trigger.On.Stop, _manager);
|
||||
}
|
||||
|
||||
public void ResetStats()
|
||||
{
|
||||
_aptitude._effective = _aptitude._default;
|
||||
@@ -211,24 +139,22 @@ public partial class Worker : RigidBody2D
|
||||
_hovered = false;
|
||||
}
|
||||
|
||||
private void OnBodyEntered(Node NODE)
|
||||
{
|
||||
if (NODE is Worker)
|
||||
{
|
||||
_collisionTarget = NODE;
|
||||
FireActions(Trigger.On.Collision, NODE);
|
||||
// private void OnBodyEntered(Node NODE)
|
||||
// {
|
||||
// if (NODE is Worker)
|
||||
// {
|
||||
// FireActions(Trigger.On.Collision, NODE);
|
||||
|
||||
_rotationalForce *= 0.8f;
|
||||
Vector2 rotatedForce = LinearVelocity.Rotated(((Worker)NODE)._rotationalForce);
|
||||
// _rotationalForce *= 0.8f;
|
||||
// Vector2 rotatedForce = LinearVelocity.Rotated(((Worker)NODE)._rotationalForce);
|
||||
|
||||
ApplyCentralForce(rotatedForce);
|
||||
_collisionTarget = null;
|
||||
}
|
||||
else if (NODE is Tchotchke)
|
||||
{
|
||||
Tchotchke tchotchke = (Tchotchke)NODE;
|
||||
tchotchke.FireActions(Trigger.On.Collision, this);
|
||||
}
|
||||
}
|
||||
// ApplyCentralForce(rotatedForce);
|
||||
// }
|
||||
// else if (NODE is Tchotchke)
|
||||
// {
|
||||
// Tchotchke tchotchke = (Tchotchke)NODE;
|
||||
// tchotchke.FireActions(Trigger.On.Collision, this);
|
||||
// }
|
||||
// }
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user