diff options
Diffstat (limited to 'scripts/actors')
| -rw-r--r-- | scripts/actors/Actor.cs | 5 | ||||
| -rw-r--r-- | scripts/actors/actions/Action.cs | 13 | ||||
| -rw-r--r-- | scripts/actors/actions/BumpAction.cs | 12 | ||||
| -rw-r--r-- | scripts/actors/actions/DirectionalAction.cs | 6 | ||||
| -rw-r--r-- | scripts/actors/actions/MeleeAction.cs | 6 | ||||
| -rw-r--r-- | scripts/actors/actions/MovementAction.cs | 8 |
6 files changed, 34 insertions, 16 deletions
diff --git a/scripts/actors/Actor.cs b/scripts/actors/Actor.cs index f35939a..f429ead 100644 --- a/scripts/actors/Actor.cs +++ b/scripts/actors/Actor.cs @@ -1,10 +1,13 @@ using Godot; [GlobalClass] -public abstract partial class Actor : Sprite2D { +public abstract partial class Actor : Sprite2D +{ [Export] private ActorDefinition definition; private Vector2I gridPosition = Vector2I.Zero; + [Export] + public DungeonLevel Map { get; private set; } public Vector2I GridPosition { set { gridPosition = value; diff --git a/scripts/actors/actions/Action.cs b/scripts/actors/actions/Action.cs index 21efa1a..76ae5d5 100644 --- a/scripts/actors/actions/Action.cs +++ b/scripts/actors/actions/Action.cs @@ -1,6 +1,17 @@ using Godot; using System; +using System.Data; public abstract partial class Action : RefCounted { - public abstract void Perform(Game game, Actor actor); + protected Actor actor; + + public Action(Actor actor) { + this.actor = actor; + } + + public abstract void Perform(); + + protected DungeonLevel Map { + get => actor.Map; + } } diff --git a/scripts/actors/actions/BumpAction.cs b/scripts/actors/actions/BumpAction.cs index e1fb706..5958b11 100644 --- a/scripts/actors/actions/BumpAction.cs +++ b/scripts/actors/actions/BumpAction.cs @@ -3,22 +3,22 @@ using System; public partial class BumpAction : DirectionalAction { - public BumpAction(Vector2I offset) : base(offset) + public BumpAction(Actor actor, Vector2I offset) : base(actor, offset) { } - public override void Perform(Game game, Actor actor) + public override void Perform() { Vector2I destination = actor.GridPosition + Offset; Action action; - if (game.Map.GetBlockingActorAtPosition(destination) != null) { - action = new MeleeAction(Offset); + if (GetBlockingActorAtPosition(destination) != null) { + action = new MeleeAction(actor, Offset); } else { - action = new MovementAction(Offset); + action = new MovementAction(actor, Offset); } - action.Perform(game, actor); + action.Perform(); } } diff --git a/scripts/actors/actions/DirectionalAction.cs b/scripts/actors/actions/DirectionalAction.cs index 7512141..077f475 100644 --- a/scripts/actors/actions/DirectionalAction.cs +++ b/scripts/actors/actions/DirectionalAction.cs @@ -4,8 +4,12 @@ using System; public abstract partial class DirectionalAction : Action { public Vector2I Offset { get; private set; } - public DirectionalAction(Vector2I offset) + public DirectionalAction(Actor actor, Vector2I offset) : base(actor) { Offset = offset; } + + protected Actor GetBlockingActorAtPosition(Vector2I pos) { + return Map.GetBlockingActorAtPosition(pos); + } } diff --git a/scripts/actors/actions/MeleeAction.cs b/scripts/actors/actions/MeleeAction.cs index 1a74c22..c6d0960 100644 --- a/scripts/actors/actions/MeleeAction.cs +++ b/scripts/actors/actions/MeleeAction.cs @@ -4,15 +4,15 @@ using System.Net.NetworkInformation; public partial class MeleeAction : DirectionalAction { - public MeleeAction(Vector2I offset) : base(offset) + public MeleeAction(Actor actor, Vector2I offset) : base(actor, offset) { } - public override void Perform(Game game, Actor actor) + public override void Perform() { Vector2I destination = actor.GridPosition + Offset; - Actor target = game.Map.GetBlockingActorAtPosition(destination); + Actor target = GetBlockingActorAtPosition(destination); if (target == null) return; diff --git a/scripts/actors/actions/MovementAction.cs b/scripts/actors/actions/MovementAction.cs index 3b203ca..c9474b0 100644 --- a/scripts/actors/actions/MovementAction.cs +++ b/scripts/actors/actions/MovementAction.cs @@ -3,17 +3,17 @@ using System; public partial class MovementAction : DirectionalAction { - public MovementAction(Vector2I offset) : base(offset) + public MovementAction(Actor actor, Vector2I offset) : base(actor, offset) { } - public override void Perform(Game game, Actor actor) + public override void Perform() { Vector2I finalDestination = actor.GridPosition + Offset; - if (!game.Map.IsTileWalkable(finalDestination)) return; + if (!Map.IsTileWalkable(finalDestination)) return; - if (game.Map.GetBlockingActorAtPosition(finalDestination) != null) return; + if (GetBlockingActorAtPosition(finalDestination) != null) return; actor.Walk(Offset); } |
