Files
hotdesking/Gameplay/Worker.cs

187 lines
4.1 KiB
C#

using Godot;
using System;
using System.Collections.Generic;
using System.Linq;
public partial class Worker : Area2D
{
// [Signal]
// public delegate void SwapPositionsEventHandler(Worker THIS);
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 Sprite2D _image;
public ProgressBar _healthBar;
public Manager _manager;
public Cell _cell;
public List<Trait> _traits = new();
public override void _Ready()
{
_size = (int)(((CircleShape2D)GetNode<CollisionShape2D>("Bounds").Shape).Radius);
_aptitude._default = 5;
_agility._default = 5;
_ardor._default = 5;
_accumen._default = 5;
_awareness._default = 5;
_appeal._default = 5;
_aptitude._effective = _aptitude._default;
_agility._effective = _agility._default;
_ardor._effective = _ardor._default;
_accumen._effective = _accumen._default;
_awareness._effective = _awareness._default;
_appeal._effective = _appeal._default;
_image = GetNode<Sprite2D>("Sprite2D");
_traits.Add(new BasicAttack(this));
// _healthBar = GetNode<ProgressBar>("HealthBar");
// _healthBar.MaxValue = _healthMax;
// _healthBar.Value = _health;
}
public override void _Process(double DELTA_)
{
if (_hovered)
{
if (Input.IsActionJustPressed("left_click"))
{
Hold();
}
}
if (_held)
{
GlobalPosition = GetGlobalMousePosition();
if (Input.IsActionJustReleased("left_click"))
{
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 Drop()
{
if (_held)
{
_held = false;
GlobalPosition = _cell.GlobalPosition;
}
}
public void FireActions(Trigger.On TRIGGER, Worker TARGET = null)
{
for (int i = 0; i < _traits.Count; i++)
{
if (_traits[i]._triggers.Contains(TRIGGER))
{
_traits[i].Target(TARGET);
_traits[i].Fire();
}
}
}
// public bool HasCondition(string CONDITION)
// {
// List<string> conditionNames = _conditions.GetChildren().Select(c => c.GetType().ToString()).ToList();
// return conditionNames.Contains(CONDITION);
// }
public void Hold()
{
if (_held)
{
return;
}
_held = true;
}
public void ResetStats()
{
_aptitude._effective = _aptitude._default;
_agility._effective = _agility._default;
_ardor._effective = _ardor._default;
_accumen._effective = _accumen._default;
_awareness._effective = _awareness._default;
_appeal._effective = _appeal._default;
}
public void SwapWith(Worker OTHERWORKER)
{
Cell thisCell = _cell, otherCell = OTHERWORKER._cell;
OTHERWORKER.GlobalPosition = thisCell.GlobalPosition;
_cell = otherCell;
OTHERWORKER._cell = thisCell;
int indexA = _manager._workers.IndexOf(this), indexB = _manager._workers.IndexOf(OTHERWORKER);
Worker placeholder = this;
_manager._workers[indexA] = OTHERWORKER;
_manager._workers[indexB] = placeholder;
}
// PRIVATE METHODS
private void OnAreaEntered(Area2D AREA)
{
if (AREA is Worker)
{
if (_held)
{
SwapWith((Worker)AREA);
}
}
}
private void OnMouseEntered()
{
_hovered = true;
}
private void OnMouseExited()
{
_hovered = false;
}
// private void OnBodyEntered(Node NODE)
// {
// if (NODE is Worker)
// {
// FireActions(Trigger.On.Collision, NODE);
// _rotationalForce *= 0.8f;
// Vector2 rotatedForce = LinearVelocity.Rotated(((Worker)NODE)._rotationalForce);
// ApplyCentralForce(rotatedForce);
// }
// else if (NODE is Tchotchke)
// {
// Tchotchke tchotchke = (Tchotchke)NODE;
// tchotchke.FireActions(Trigger.On.Collision, this);
// }
// }
}