made an action be owned by a contact instead of actor; made another example action
This commit is contained in:
@@ -4,7 +4,7 @@ using System;
|
|||||||
public partial class Action : Node
|
public partial class Action : Node
|
||||||
{
|
{
|
||||||
public float _timerSeconds, _cooldownSeconds;
|
public float _timerSeconds, _cooldownSeconds;
|
||||||
public Actor _owner;
|
public Contact _contact;
|
||||||
public virtual void Fire()
|
public virtual void Fire()
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|||||||
@@ -16,10 +16,10 @@ public partial class Example1 : Action
|
|||||||
{
|
{
|
||||||
base.Fire();
|
base.Fire();
|
||||||
// GD.Print(_owner);
|
// GD.Print(_owner);
|
||||||
List<Shield> unbrokenShields = [.. _owner._board._shields.Where(s=>!s._broken)];
|
List<Shield> unbrokenShields = [.. _contact._owner._board._shields.Where(s=>!s._broken)];
|
||||||
int shieldNumber = Globals._rng.Next(0, unbrokenShields.Count);
|
int shieldNumber = Globals._rng.Next(0, unbrokenShields.Count);
|
||||||
int damageAmount = Globals._rng.Next(-12,-8);
|
int damageAmount = Globals._rng.Next(-12,-8);
|
||||||
_owner._board._shields[shieldNumber].ChangeHealth(damageAmount);
|
_contact._owner._board._shields[shieldNumber].ChangeHealth(damageAmount);
|
||||||
((Player)_owner)._phone._debug.Text = "Shield " + shieldNumber + " damaged " + damageAmount + "hp";
|
((Player)_contact._owner)._phone._debug.Text = "Shield " + shieldNumber + " damaged " + damageAmount + "hp";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
22
Gameplay/Actions/Example2.cs
Normal file
22
Gameplay/Actions/Example2.cs
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
using Godot;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Runtime.CompilerServices;
|
||||||
|
|
||||||
|
public partial class Example2 : Action
|
||||||
|
{
|
||||||
|
public override void _Ready()
|
||||||
|
{
|
||||||
|
base._Ready();
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void Fire()
|
||||||
|
{
|
||||||
|
base.Fire();
|
||||||
|
int shieldNumber = 2;
|
||||||
|
int damageAmount = Globals._rng.Next(-50,-30);
|
||||||
|
_contact._owner._board._shields[shieldNumber].ChangeHealth(damageAmount);
|
||||||
|
((Player)_contact._owner)._phone._debug.Text = "Shield " + shieldNumber + " damaged " + damageAmount + "hp";
|
||||||
|
}
|
||||||
|
}
|
||||||
1
Gameplay/Actions/Example2.cs.uid
Normal file
1
Gameplay/Actions/Example2.cs.uid
Normal file
@@ -0,0 +1 @@
|
|||||||
|
uid://bsmvcs8l2p211
|
||||||
@@ -4,7 +4,7 @@ using System.Runtime.CompilerServices;
|
|||||||
|
|
||||||
public partial class Contact : Sprite2D
|
public partial class Contact : Sprite2D
|
||||||
{
|
{
|
||||||
public bool _clickable, _interval;
|
public bool _clickable = false, _interval = false;
|
||||||
public int _number, _calls = 0, _maxCalls = 0;
|
public int _number, _calls = 0, _maxCalls = 0;
|
||||||
public Timer _timer, _cooldown;
|
public Timer _timer, _cooldown;
|
||||||
public Action _action;
|
public Action _action;
|
||||||
@@ -15,11 +15,12 @@ public partial class Contact : Sprite2D
|
|||||||
_timer = GetNode<Timer>("Timer");
|
_timer = GetNode<Timer>("Timer");
|
||||||
_cooldown = GetNode<Timer>("Cooldown");
|
_cooldown = GetNode<Timer>("Cooldown");
|
||||||
_action = GetNode<Action>("Action");
|
_action = GetNode<Action>("Action");
|
||||||
|
_action._contact = this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public virtual void CallAction()
|
public virtual void CallAction()
|
||||||
{
|
{
|
||||||
if (_cooldown.TimeLeft > 0 || _action._cooldownSeconds == 0)
|
if (_cooldown.TimeLeft == 0 || _action._cooldownSeconds == 0)
|
||||||
{
|
{
|
||||||
GD.Print("Action fired!!");
|
GD.Print("Action fired!!");
|
||||||
_action.Fire();
|
_action.Fire();
|
||||||
@@ -33,17 +34,20 @@ public partial class Contact : Sprite2D
|
|||||||
public void PassOwner(Actor OWNER)
|
public void PassOwner(Actor OWNER)
|
||||||
{
|
{
|
||||||
_owner = OWNER;
|
_owner = OWNER;
|
||||||
_action._owner = OWNER;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void SetTimer(float SECONDS)
|
public void SetTimer(float SECONDS)
|
||||||
{
|
{
|
||||||
_action._timerSeconds = SECONDS;
|
_action._timerSeconds = SECONDS;
|
||||||
|
_interval = true;
|
||||||
|
_clickable = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void SetCooldown(int SECONDS)
|
public void SetCooldown(float SECONDS)
|
||||||
{
|
{
|
||||||
_action._cooldownSeconds = SECONDS;
|
_action._cooldownSeconds = SECONDS;
|
||||||
|
_interval = false;
|
||||||
|
_clickable = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Start()
|
public void Start()
|
||||||
|
|||||||
@@ -22,8 +22,11 @@ public partial class Phone : Sprite2D
|
|||||||
_phoneButtons[i]._phone = this;
|
_phoneButtons[i]._phone = this;
|
||||||
}
|
}
|
||||||
_phoneButtons[0]._contact._action = new Example1();
|
_phoneButtons[0]._contact._action = new Example1();
|
||||||
_phoneButtons[0]._contact._action._owner = _player;
|
_phoneButtons[0]._contact.PassOwner(_player);
|
||||||
_phoneButtons[0]._contact.SetTimer(1.5f);
|
_phoneButtons[0]._contact.SetTimer(1.5f);
|
||||||
|
_phoneButtons[1]._contact._action = new Example2();
|
||||||
|
_phoneButtons[1]._contact.PassOwner(_player);
|
||||||
|
_phoneButtons[1]._contact.SetCooldown(15f);
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void _Process(double DELTA_)
|
public override void _Process(double DELTA_)
|
||||||
|
|||||||
Reference in New Issue
Block a user