basic capture functionality
This commit is contained in:
parent
246f3c0840
commit
c141e6a169
20 changed files with 430 additions and 14 deletions
121
scripts/ui/CaptureUI.cs
Normal file
121
scripts/ui/CaptureUI.cs
Normal file
|
|
@ -0,0 +1,121 @@
|
|||
using Godot;
|
||||
|
||||
public partial class CaptureUI : CanvasLayer
|
||||
{
|
||||
[Export] public float BaseTimeLimit = 3.0f;
|
||||
[Export] public float BaseRequired = 14.0f; // “energy” required
|
||||
[Export] public float EnergyPerPress = 1.0f;
|
||||
|
||||
private Creature? _target;
|
||||
private SaveManager? _save;
|
||||
|
||||
private float _timeLeft;
|
||||
private float _required;
|
||||
private float _energy;
|
||||
|
||||
private OptionButton _ballOption = null!;
|
||||
private ProgressBar _bar = null!;
|
||||
private Label _timer = null!;
|
||||
private Label _title = null!;
|
||||
|
||||
public override void _Ready()
|
||||
{
|
||||
_ballOption = GetNode<OptionButton>("Panel/VBoxContainer/SoulballOption");
|
||||
_bar = GetNode<ProgressBar>("Panel/VBoxContainer/MashBar");
|
||||
_timer = GetNode<Label>("Panel/VBoxContainer/TimerLabel");
|
||||
_title = GetNode<Label>("Panel/VBoxContainer/CreatureNameLabel");
|
||||
|
||||
Visible = false;
|
||||
|
||||
// v0 balls
|
||||
_ballOption.Clear();
|
||||
_ballOption.AddItem("Basic Soulball (easy)", 0);
|
||||
_ballOption.AddItem("Heavy Soulball (hard)", 1);
|
||||
|
||||
_save = GetNodeOrNull<SaveManager>("/root/Main/SaveManager"); // or export a path if you prefer
|
||||
}
|
||||
|
||||
public void StartCapture(Creature target)
|
||||
{
|
||||
_target = target;
|
||||
_energy = 0;
|
||||
|
||||
// Ball selection affects difficulty (v0)
|
||||
int ballId = _ballOption.GetSelectedId();
|
||||
float difficultyMul = ballId switch
|
||||
{
|
||||
0 => 1.0f,
|
||||
1 => 1.4f,
|
||||
_ => 1.0f
|
||||
};
|
||||
|
||||
_required = BaseRequired * difficultyMul;
|
||||
_timeLeft = BaseTimeLimit;
|
||||
|
||||
_title.Text = $"Capture: {target.CreatureId}";
|
||||
_bar.MinValue = 0;
|
||||
_bar.MaxValue = _required;
|
||||
_bar.Value = 0;
|
||||
|
||||
Visible = true;
|
||||
|
||||
// Optional: pause world while capturing
|
||||
GetTree().Paused = true;
|
||||
ProcessMode = ProcessModeEnum.WhenPaused;
|
||||
}
|
||||
|
||||
public override void _Process(double delta)
|
||||
{
|
||||
if (!Visible || _target == null) return;
|
||||
|
||||
// Count presses
|
||||
if (Input.IsActionJustPressed("capture_mash"))
|
||||
{
|
||||
_energy += EnergyPerPress;
|
||||
_bar.Value = _energy;
|
||||
}
|
||||
|
||||
_timeLeft -= (float)delta;
|
||||
_timer.Text = $"Time: {_timeLeft:0.00}s";
|
||||
|
||||
if (_energy >= _required)
|
||||
{
|
||||
OnCaptureSuccess();
|
||||
}
|
||||
else if (_timeLeft <= 0)
|
||||
{
|
||||
OnCaptureFail();
|
||||
}
|
||||
}
|
||||
|
||||
private void EndCapture()
|
||||
{
|
||||
Visible = false;
|
||||
GetTree().Paused = false;
|
||||
ProcessMode = ProcessModeEnum.Inherit;
|
||||
_target = null;
|
||||
}
|
||||
|
||||
private void OnCaptureSuccess()
|
||||
{
|
||||
if (_target == null) return;
|
||||
|
||||
GD.Print($"Captured {_target.CreatureId}");
|
||||
|
||||
// v0: store captured creature IDs
|
||||
if (_save != null)
|
||||
{
|
||||
_save.State.CapturedCreatures.Add(_target.CreatureId);
|
||||
_save.Save();
|
||||
}
|
||||
|
||||
_target.Despawn();
|
||||
EndCapture();
|
||||
}
|
||||
|
||||
private void OnCaptureFail()
|
||||
{
|
||||
GD.Print("Capture failed");
|
||||
EndCapture();
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue