blob: 4994534ce4b1263524a3a0b6e22ae6fff4ef3d73 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
|
using Godot;
using Godot.Collections;
using TheLegendOfGustav.Entities.Actors.AI;
using TheLegendOfGustav.Map;
namespace TheLegendOfGustav.Entities.Actors;
/// <summary>
/// Um inimigo é uma espécie de ator que é
/// hostil ao jogador. Inimigos são controlados por IA.
/// </summary>
public partial class Enemy : Actor, ISaveable
{
private EnemyDefinition definition;
public Enemy(Vector2I initialPosition, MapData map, EnemyDefinition definition) : base(initialPosition, map, definition)
{
this.definition = definition;
SetDefinition(definition);
}
public Enemy(Vector2I initialPosition, MapData map) : base(initialPosition, map)
{
}
/// <summary>
/// A alma do ator. Gera ações que são executadas todo turno.
/// </summary>
public BaseAI Soul { get; private set; }
/// <summary>
/// Além de definir as características gerais de um ator,
/// também define qual IA utilizar.
/// </summary>
/// <param name="definition">Definição do inimigo.</param>
public void SetDefinition(EnemyDefinition definition)
{
this.definition = definition;
// Definimos as características do ator.
base.SetDefinition(this.definition);
Soul?.QueueFree();
// Definimos qual IA utilizar.
switch (definition.AI)
{
case AIType.None:
break;
case AIType.DefaultHostile:
Soul = new HostileEnemyAI();
AddChild(Soul);
break;
}
}
public override void Die()
{
Soul.QueueFree();
Soul = null;
base.Die();
}
public new Dictionary<string, Variant> GetSaveData()
{
Dictionary<string, Variant> baseData = base.GetSaveData();
baseData.Add("definition", definition.ResourcePath);
return baseData;
}
public new bool LoadSaveData(Dictionary<string, Variant> saveData)
{
string definitionPath = (string)saveData["definition"];
EnemyDefinition definition = GD.Load<EnemyDefinition>(definitionPath);
SetDefinition(definition);
if (!base.LoadSaveData(saveData))
{
return false;
}
return true;
}
}
|