summaryrefslogtreecommitdiff
path: root/scripts/Entities
diff options
context:
space:
mode:
Diffstat (limited to 'scripts/Entities')
-rw-r--r--scripts/Entities/Actions/Action.cs32
-rw-r--r--scripts/Entities/Actions/DropAction.cs2
-rw-r--r--scripts/Entities/Actions/ItemAction.cs23
-rw-r--r--scripts/Entities/Actions/MeleeAction.cs2
-rw-r--r--scripts/Entities/Actions/MovementAction.cs2
-rw-r--r--scripts/Entities/Actions/PickUpAction.cs15
-rw-r--r--scripts/Entities/Actions/SpellAction.cs4
-rw-r--r--scripts/Entities/Actions/WaitAction.cs2
-rw-r--r--scripts/Entities/Actors/AI/BaseAI.cs8
-rw-r--r--scripts/Entities/Actors/AI/HostileEnemyAI.cs32
-rw-r--r--scripts/Entities/Actors/Actor.cs22
-rw-r--r--scripts/Entities/Actors/ActorDefinition.cs2
-rw-r--r--scripts/Entities/Actors/Enemy.cs8
-rw-r--r--scripts/Entities/Actors/Inventory.cs8
-rw-r--r--scripts/Entities/Actors/Player.cs5
-rw-r--r--scripts/Entities/Entity.cs14
-rw-r--r--scripts/Entities/Items/HealingConsumable.cs2
-rw-r--r--scripts/Entities/Items/ScrollConsumable.cs4
18 files changed, 70 insertions, 117 deletions
diff --git a/scripts/Entities/Actions/Action.cs b/scripts/Entities/Actions/Action.cs
index b2d6a4b..0bbcc24 100644
--- a/scripts/Entities/Actions/Action.cs
+++ b/scripts/Entities/Actions/Action.cs
@@ -10,47 +10,29 @@ namespace TheLegendOfGustav.Entities.Actions;
/// </summary>
public abstract partial class Action : RefCounted
{
- private Actor actor;
-
- private int cost;
+ /// <summary>
+ /// O custo da ação.
+ /// </summary>
+ protected int cost;
public Action(Actor actor)
{
Actor = actor;
// Custo base, subclasses podem sobreescrever isto se quiserem.
- Cost = 10;
+ cost = 10;
}
/// <summary>
/// O ator que realiza a ação.
/// </summary>
- public Actor Actor
- {
- get => actor;
- private set
- {
- actor = value;
- }
- }
-
- /// <summary>
- /// O custo da ação.
- /// </summary>
- protected int Cost
- {
- get => cost;
- set
- {
- cost = value;
- }
- }
+ public Actor Actor { get; private set; }
/// <summary>
/// É conveniente ter acesso ao mapa dentro de uma ação.
/// </summary>
protected MapData MapData
{
- get => actor.MapData;
+ get => Actor.MapData;
}
/// <summary>
diff --git a/scripts/Entities/Actions/DropAction.cs b/scripts/Entities/Actions/DropAction.cs
index 00ddd7e..51d4ce6 100644
--- a/scripts/Entities/Actions/DropAction.cs
+++ b/scripts/Entities/Actions/DropAction.cs
@@ -11,7 +11,7 @@ public partial class DropAction : ItemAction
public override bool Perform()
{
- Player.Inventory.Drop(Item);
+ Player.Inventory.Drop(item);
return true;
}
} \ No newline at end of file
diff --git a/scripts/Entities/Actions/ItemAction.cs b/scripts/Entities/Actions/ItemAction.cs
index 14c5d93..a2ca1a2 100644
--- a/scripts/Entities/Actions/ItemAction.cs
+++ b/scripts/Entities/Actions/ItemAction.cs
@@ -5,32 +5,15 @@ namespace TheLegendOfGustav.Entities.Actions;
public partial class ItemAction : Action
{
- private ConsumableItem item;
- private Player player;
+ protected ConsumableItem item;
public ItemAction(Player player, ConsumableItem item) : base(player)
{
- Item = item;
+ this.item = item;
Player = player;
}
- public Player Player
- {
- get => player;
- private set
- {
- player = value;
- }
- }
-
- protected ConsumableItem Item
- {
- get => item;
- set
- {
- item = value;
- }
- }
+ public Player Player { get; private set; }
public override bool Perform()
{
diff --git a/scripts/Entities/Actions/MeleeAction.cs b/scripts/Entities/Actions/MeleeAction.cs
index fcd8368..5e53ec7 100644
--- a/scripts/Entities/Actions/MeleeAction.cs
+++ b/scripts/Entities/Actions/MeleeAction.cs
@@ -49,7 +49,7 @@ public partial class MeleeAction : DirectionalAction
}
MessageLogData.Instance.AddMessage(attackDesc);
- Actor.Energy -= Cost;
+ Actor.Energy -= cost;
return true;
}
}
diff --git a/scripts/Entities/Actions/MovementAction.cs b/scripts/Entities/Actions/MovementAction.cs
index 0ac842c..f78d95d 100644
--- a/scripts/Entities/Actions/MovementAction.cs
+++ b/scripts/Entities/Actions/MovementAction.cs
@@ -23,7 +23,7 @@ public partial class MovementAction : DirectionalAction
if (GetTarget() != null) return true;
Actor.Walk(Offset);
- Actor.Energy -= Cost;
+ Actor.Energy -= cost;
return true;
}
diff --git a/scripts/Entities/Actions/PickUpAction.cs b/scripts/Entities/Actions/PickUpAction.cs
index 0dbd672..eaed01c 100644
--- a/scripts/Entities/Actions/PickUpAction.cs
+++ b/scripts/Entities/Actions/PickUpAction.cs
@@ -12,18 +12,9 @@ public partial class PickupAction : DirectionalAction
public PickupAction(Player player, Vector2I offset) : base(player, offset)
{
- Player = player;
+ this.player = player;
// Pegar itens requer um tempo menor.
- Cost = 2;
- }
-
- protected Player Player
- {
- get => player;
- private set
- {
- player = value;
- }
+ cost = 2;
}
public override bool Perform()
@@ -45,7 +36,7 @@ public partial class PickupAction : DirectionalAction
MapData.RemoveEntity(item);
player.Inventory.Add(item);
- player.Energy -= Cost;
+ player.Energy -= cost;
return true;
}
} \ No newline at end of file
diff --git a/scripts/Entities/Actions/SpellAction.cs b/scripts/Entities/Actions/SpellAction.cs
index d9e9952..28d6caa 100644
--- a/scripts/Entities/Actions/SpellAction.cs
+++ b/scripts/Entities/Actions/SpellAction.cs
@@ -16,7 +16,7 @@ public partial class SpellAction : DirectionalAction
{
this.spell = spell;
- Cost = 5;
+ cost = 5;
}
public override bool Perform()
@@ -53,7 +53,7 @@ public partial class SpellAction : DirectionalAction
effect.Apply(Actor, target);
}
- Actor.Energy -= Cost;
+ Actor.Energy -= cost;
return true;
}
}
diff --git a/scripts/Entities/Actions/WaitAction.cs b/scripts/Entities/Actions/WaitAction.cs
index 011703b..993e4f4 100644
--- a/scripts/Entities/Actions/WaitAction.cs
+++ b/scripts/Entities/Actions/WaitAction.cs
@@ -98,7 +98,7 @@ public partial class WaitAction : Action
//@@@@@@@@@@@@*====+==++=*@. @ @@* .@* @ .*#. @ @* #: -@ @@% @ -+ =*%@@= @@: @ @ +. #+ *@@@@@@@@@@@@@@@@@@@@@@@
//@@@@@@@@@@@======++====+*%@@@@%%%@@@@%*+#@@@@@%#%@@#=+**=. =**+=***==*#*: :%@@@@@@@@@**=+#*==*###*=. -=**+::@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
//@@@@@@@@@@+==+==++=====++=====++=+++++++++===+++++#% +@@@* :#%= =@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
- Actor.Energy -= Cost;
+ Actor.Energy -= cost;
return true;
}
} \ No newline at end of file
diff --git a/scripts/Entities/Actors/AI/BaseAI.cs b/scripts/Entities/Actors/AI/BaseAI.cs
index bdd1e61..3b9ae3e 100644
--- a/scripts/Entities/Actors/AI/BaseAI.cs
+++ b/scripts/Entities/Actors/AI/BaseAI.cs
@@ -20,13 +20,13 @@ public abstract partial class BaseAI : Node
/// Corpo controlado pela IA.
/// O corpo é a marionete da alma.
/// </summary>
- protected Actor Body { get; set; }
+ protected Actor body;
public override void _Ready()
{
base._Ready();
// Por padrão, a IA é filha do nó de seu corpo.
- Body = GetParent<Actor>();
+ body = GetParent<Actor>();
}
/// <summary>
@@ -42,12 +42,12 @@ public abstract partial class BaseAI : Node
/// </summary>
/// <param name="destination">Destino</param>
/// <returns>Vetor com vetores, passo a passo para chegar no destino.</returns>
- public Godot.Collections.Array<Vector2> GetPathTo(Vector2I destination)
+ protected Godot.Collections.Array<Vector2> GetPathTo(Vector2I destination)
{
// Arrays do Godot são muito mais confortáveis de manipular, então
// eu converto o Array do C# em um array do Godot antes de retornar o caminho.
Godot.Collections.Array<Vector2> list = [];
- Vector2[] path = Body.MapData.Pathfinder.GetPointPath(Body.GridPosition, destination);
+ Vector2[] path = body.MapData.Pathfinder.GetPointPath(body.GridPosition, destination);
list.AddRange(path);
return list;
}
diff --git a/scripts/Entities/Actors/AI/HostileEnemyAI.cs b/scripts/Entities/Actors/AI/HostileEnemyAI.cs
index 2f925c1..62e3d47 100644
--- a/scripts/Entities/Actors/AI/HostileEnemyAI.cs
+++ b/scripts/Entities/Actors/AI/HostileEnemyAI.cs
@@ -12,29 +12,29 @@ public partial class HostileEnemyAI : BaseAI
/// <summary>
/// Caminho até a última posição conhecida do jogador.
/// </summary>
- private Godot.Collections.Array<Vector2> Path { get; set; } = [];
+ private Godot.Collections.Array<Vector2> path = [];
public override void Perform()
{
// O alvo da IA sempre é o jogador.
- Player target = Body.MapData.Player;
+ Player target = body.MapData.Player;
// Vetor que parte do inimigo até o jogador.
- Vector2I offset = target.GridPosition - Body.GridPosition;
+ Vector2I offset = target.GridPosition - body.GridPosition;
// Distância entre o inimigo e o jogador. Leva em consideração somente
// um dos eixos.
- int distance = Grid.Distance(Body.GridPosition, target.GridPosition);
+ int distance = Grid.Distance(body.GridPosition, target.GridPosition);
// A ação executada no turno pode ser de ataque ou de movimento.
Action action;
// Só faz sentido atacar o jogador se o inimigo estiver visível.
- if (Body.MapData.GetTile(Body.GridPosition).IsInView)
+ if (body.MapData.GetTile(body.GridPosition).IsInView)
{
// Se o inimigo consegue ver que o jogador está morto,
// IT'S OVER.
if (!target.IsAlive)
{
- action = new WaitAction(Body);
+ action = new WaitAction(body);
action.Perform();
return;
}
@@ -42,7 +42,7 @@ public partial class HostileEnemyAI : BaseAI
// Se estiver do lado do jogador, ataque.
if (distance <= 1)
{
- action = new MeleeAction(Body, offset);
+ action = new MeleeAction(body, offset);
action.Perform();
// Executada a ação, acabamos nosso turno aqui.
return;
@@ -51,34 +51,34 @@ public partial class HostileEnemyAI : BaseAI
// Se o inimigo estiver visível para o jogador,
// consideramos que ele também consiga ver o jogador.
// Logo, atualizamos o caminho para a posição atual do jogador.
- Path = GetPathTo(target.GridPosition);
+ path = GetPathTo(target.GridPosition);
// O primeiro passo é a posição atual do inimigo, podemos remover.
- Path.RemoveAt(0);
+ path.RemoveAt(0);
}
// Se existir um caminho conhecido para o jogador.
- if (Path.Count > 0)
+ if (path.Count > 0)
{
// Pegamos o próximo passo para o destino.
- Vector2I destination = (Vector2I)Path[0];
+ Vector2I destination = (Vector2I)path[0];
// Se tiver o caminho estiver bloqueado, paramos o nosso turno aqui.
- if (Body.MapData.GetBlockingEntityAtPosition(destination) != null)
+ if (body.MapData.GetBlockingEntityAtPosition(destination) != null)
{
- action = new WaitAction(Body);
+ action = new WaitAction(body);
action.Perform();
return;
}
// Caso o contrário, criamos uma nova ação de movimentação e a executamos.
- action = new MovementAction(Body, destination - Body.GridPosition);
+ action = new MovementAction(body, destination - body.GridPosition);
action.Perform();
// Podemos remover o passo do caminho.
- Path.RemoveAt(0);
+ path.RemoveAt(0);
return;
}
// Senão, espere.
- action = new WaitAction(Body);
+ action = new WaitAction(body);
action.Perform();
return;
}
diff --git a/scripts/Entities/Actors/Actor.cs b/scripts/Entities/Actors/Actor.cs
index 7e228f8..ec00e30 100644
--- a/scripts/Entities/Actors/Actor.cs
+++ b/scripts/Entities/Actors/Actor.cs
@@ -16,6 +16,12 @@ public partial class Actor : Entity
private int hp;
private int energy;
+
+ /// <summary>
+ /// A definição do ator possui caracterísitcas padrões que definem
+ /// o ator em questão.
+ /// </summary>
+ private ActorDefinition definition;
#endregion
#region Constructors
@@ -77,7 +83,7 @@ public partial class Actor : Entity
/// <summary>
/// Taxa de recarga de energia.
/// </summary>
- public int Speed { get => Definition.Speed; }
+ public int Speed { get => definition.Speed; }
/// <summary>
/// HP máximo do ator.
@@ -142,16 +148,6 @@ public partial class Actor : Entity
/// </summary>
public int MpRegenPerTurn { get; private set; } = 5;
- /// <summary>
- /// A definição do ator possui caracterísitcas padrões que definem
- /// o ator em questão.
- /// </summary>
- private ActorDefinition Definition
- {
- get;
- set;
- }
-
public SpellBook SpellBook { get; private set; } = new();
#endregion
@@ -220,7 +216,7 @@ public partial class Actor : Entity
public virtual void SetDefinition(ActorDefinition definition)
{
base.SetDefinition(definition);
- Definition = definition;
+ this.definition = definition;
Type = definition.Type;
@@ -275,7 +271,7 @@ public partial class Actor : Entity
MessageLogData.Instance.AddMessage(deathMessage);
- Texture = Definition.deathTexture;
+ Texture = definition.deathTexture;
BlocksMovement = false;
Type = EntityType.CORPSE;
DisplayName = $"Restos mortais de {DisplayName}";
diff --git a/scripts/Entities/Actors/ActorDefinition.cs b/scripts/Entities/Actors/ActorDefinition.cs
index 5bd8073..bc34cb6 100644
--- a/scripts/Entities/Actors/ActorDefinition.cs
+++ b/scripts/Entities/Actors/ActorDefinition.cs
@@ -15,7 +15,7 @@ public partial class ActorDefinition : EntityDefinition
[ExportCategory("Mechanics")]
[Export]
- public int Speed { get; set; } = 10;
+ public int Speed = 10;
// Estatísticas padrão do ator.
[ExportCategory("Stats")]
diff --git a/scripts/Entities/Actors/Enemy.cs b/scripts/Entities/Actors/Enemy.cs
index c152a0b..d398176 100644
--- a/scripts/Entities/Actors/Enemy.cs
+++ b/scripts/Entities/Actors/Enemy.cs
@@ -10,9 +10,11 @@ namespace TheLegendOfGustav.Entities.Actors;
/// </summary>
public partial class Enemy : Actor
{
+ private EnemyDefinition definition;
+
public Enemy(Vector2I initialPosition, MapData map, EnemyDefinition definition) : base(initialPosition, map, definition)
{
- Definition = definition;
+ this.definition = definition;
SetDefinition(definition);
}
@@ -21,8 +23,6 @@ public partial class Enemy : Actor
/// </summary>
public BaseAI Soul { get; private set; }
- private EnemyDefinition Definition { get; set; }
-
/// <summary>
/// Além de definir as características gerais de um ator,
/// também define qual IA utilizar.
@@ -31,7 +31,7 @@ public partial class Enemy : Actor
public void SetDefinition(EnemyDefinition definition)
{
// Definimos as características do ator.
- base.SetDefinition(Definition);
+ base.SetDefinition(this.definition);
// Definimos qual IA utilizar.
switch (definition.AI)
diff --git a/scripts/Entities/Actors/Inventory.cs b/scripts/Entities/Actors/Inventory.cs
index f65dc59..057316a 100644
--- a/scripts/Entities/Actors/Inventory.cs
+++ b/scripts/Entities/Actors/Inventory.cs
@@ -7,27 +7,27 @@ namespace TheLegendOfGustav.Entities.Actors;
public partial class Inventory(int capacity) : Node
{
- private Player Player { get; set; }
+ private Player player;
public int Capacity { get; private set; } = capacity;
public Godot.Collections.Array<ConsumableItem> Items { get; private set; } = [];
public override void _Ready()
{
base._Ready();
- Player = GetParent<Player>();
+ player = GetParent<Player>();
}
public void Drop(ConsumableItem item)
{
Items.Remove(item);
- MapData data = Player.MapData;
+ MapData data = player.MapData;
data.InsertEntity(item);
data.EmitSignal(MapData.SignalName.EntityPlaced, item);
item.MapData = data;
- item.GridPosition = Player.GridPosition;
+ item.GridPosition = player.GridPosition;
MessageLogData.Instance.AddMessage($"Você descarta {item.DisplayName}.");
}
diff --git a/scripts/Entities/Actors/Player.cs b/scripts/Entities/Actors/Player.cs
index 7fd80d4..d6fedb9 100644
--- a/scripts/Entities/Actors/Player.cs
+++ b/scripts/Entities/Actors/Player.cs
@@ -9,13 +9,14 @@ namespace TheLegendOfGustav.Entities.Actors;
[GlobalClass]
public partial class Player : Actor
{
+ private PlayerDefinition definition;
+
public Player(Vector2I initialPosition, MapData map, PlayerDefinition definition) : base(initialPosition, map, definition)
{
- Definition = definition;
+ this.definition = definition;
SetDefinition(definition);
}
- private PlayerDefinition Definition { get; set; }
public Inventory Inventory { get; private set; }
public void SetDefinition(PlayerDefinition definition)
diff --git a/scripts/Entities/Entity.cs b/scripts/Entities/Entity.cs
index 412bd7a..c0e026d 100644
--- a/scripts/Entities/Entity.cs
+++ b/scripts/Entities/Entity.cs
@@ -26,6 +26,12 @@ public abstract partial class Entity : Sprite2D
private bool blocksMovement;
private string displayName;
+ /// <summary>
+ /// A definição da entidade possui caracterísitcas padrões que definem
+ /// a entidade em questão.
+ /// </summary>
+ private EntityDefinition definition;
+
public Entity(Vector2I initialPosition, MapData map, EntityDefinition definition)
{
GridPosition = initialPosition;
@@ -94,12 +100,6 @@ public abstract partial class Entity : Sprite2D
}
}
- /// <summary>
- /// A definição da entidade possui caracterísitcas padrões que definem
- /// a entidade em questão.
- /// </summary>
- private EntityDefinition Definition;
-
public override void _Ready()
{
base._Ready();
@@ -118,7 +118,7 @@ public abstract partial class Entity : Sprite2D
/// <param name="definition">A definição do ator.</param>
public virtual void SetDefinition(EntityDefinition definition)
{
- Definition = definition;
+ this.definition = definition;
BlocksMovement = definition.blocksMovement;
DisplayName = definition.name;
Type = definition.Type;
diff --git a/scripts/Entities/Items/HealingConsumable.cs b/scripts/Entities/Items/HealingConsumable.cs
index 32f76a6..85377d3 100644
--- a/scripts/Entities/Items/HealingConsumable.cs
+++ b/scripts/Entities/Items/HealingConsumable.cs
@@ -8,7 +8,7 @@ namespace TheLegendOfGustav.Entities.Items;
public partial class HealingConsumable(Vector2I initialPosition, MapData map, HealingConsumableDefinition definition) : ConsumableItem(initialPosition, map, definition)
{
- private HealingConsumableDefinition Definition { get; set; } = definition;
+ private HealingConsumableDefinition definition = definition;
public float HealingPercentage { get; private set; } = definition.healingPercentage;
public override bool Activate(ItemAction action)
diff --git a/scripts/Entities/Items/ScrollConsumable.cs b/scripts/Entities/Items/ScrollConsumable.cs
index 7dc8e48..2869deb 100644
--- a/scripts/Entities/Items/ScrollConsumable.cs
+++ b/scripts/Entities/Items/ScrollConsumable.cs
@@ -17,8 +17,6 @@ namespace TheLegendOfGustav.Entities.Items;
/// <param name="definition">Definição do item.</param>
public partial class ScrollConsumable(Vector2I initialPosition, MapData map, ScrollConsumableDefinition definition) : ConsumableItem(initialPosition, map, definition)
{
- public SpellResource Spell { get; private set; } = definition.Spell;
-
/// <summary>
/// O pergaminho só pode ser usado uma única vez.
/// Alguns feitiços precisam de um alvo, o que significa que
@@ -41,6 +39,8 @@ public partial class ScrollConsumable(Vector2I initialPosition, MapData map, Scr
/// </summary>
private SignalBus.PlayerSpellCastEventHandler bindSignal = null;
+ public SpellResource Spell { get; private set; } = definition.Spell;
+
public override bool Activate(ItemAction action)
{
if (awaitingTermination)