using Godot; using System; using System.Collections.Generic; public partial class Worker : Node2D { [Signal] public delegate void DamageOverflowEventHandler(int OVERFLOW); public bool _dead = false, _available = false, _hovered = false, _selected = false, _launched = false, _placed = false, _potted = false, _isLead = false; public int _defense = 5, _defenseMax = 5; public CollisionShape2D _startArea; public TempBall _tempBall; public Ball _ball; // public static Worker _Create() // { // PackedScene scene = ResourceLoader.Load("res://Gameplay/worker.tscn"); // Worker newWorker = scene.Instantiate(); // return newWorker; // } public override void _Ready() { _ball = GetNode("Ball"); _tempBall = GetNode("TempBall"); RemoveChild(_ball); RemoveChild(_tempBall); } public override void _Process(double delta) { _hovered = (_ball._active && _ball._hovered) || (_tempBall._active && _tempBall._hovered); if (_launched) { if (!_ball._launched) { _launched = false; } } } // public virtual void ChangeBallPosition(Vector2 NEWPOSITION) // { // RemoveChild(_ball); // _ball.Position = NEWPOSITION; // AddChild(_ball); // } public virtual void ChangeDefense(int CHANGE) { _defense += CHANGE; _defense = Math.Min(_defense, _defenseMax); if (_defense < 0) { EmitSignal(SignalName.DamageOverflow, _defense); _defense = 0; } } public void Launch() { _launched = true; _ball.Launch(); } public void SetSprite(string PATH) { GetNode("Image").Texture = GD.Load(PATH); } public void PlaceBall(Vector2 POSITION) { _available = true; _placed = true; _potted = false; _ball.Position = POSITION; _ball._active = true; _ball._placed = true; _ball._potted = false; _ball._active = true; AddChild(_ball); TempBallHide(); } public void PotBall() { _available = false; _placed = false; _potted = true; _ball.Sleeping = true; _ball._moving = false; _ball._active = false; _ball._placed = false; _ball._potted = true; _ball._active = false; RemoveChild(_ball); TempBallShow(); } public void TempBallHide() { _tempBall._active = false; RemoveChild(_tempBall); } public void TempBallShow() { _tempBall._active = true; AddChild(_tempBall); } // Processes public virtual void ProcessOnCollision(Ball TARGET) { Worker TARGETWORKER = TARGET.GetParent(); if (_launched) { TARGETWORKER.ChangeDefense(-3); } } }