blob: 199c301ae6bbed0e2cdf238260db9126caee5945 (
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
|
using Godot;
[GlobalClass]
public abstract partial class Actor : Sprite2D
{
protected ActorDefinition definition;
public MapData Map_Data { get; set; }
private Vector2I gridPosition = Vector2I.Zero;
public Vector2I GridPosition {
set {
gridPosition = value;
Position = Grid.GridToWorld(value);
}
get => gridPosition;
}
public bool BlocksMovement {
get => definition.blocksMovement;
}
public string ActorName {
get => definition.name;
}
private int hp;
public int MaxHp { get; private set; }
public int Hp {
get => hp;
set {
hp = int.Clamp(value, 0, MaxHp);
}
}
private int mp;
public int MaxMp { get; private set; }
public int Mp {
get => mp;
set {
mp = int.Clamp(value, 0, MaxMp);
}
}
public int Atk { get; private set; }
public int Def { get; private set; }
public int Men { get; private set; }
public override void _Ready()
{
base._Ready();
GridPosition = Grid.WorldToGrid(Position);
}
public void Walk(Vector2I offset) {
Map_Data.UnregisterBlockingActor(this);
GridPosition += offset;
Map_Data.RegisterBlockingActor(this);
}
public Actor(Vector2I initialPosition, MapData map, ActorDefinition definition) {
GridPosition = initialPosition;
Map_Data = map;
Centered = false;
SetDefinition(definition);
}
public virtual void SetDefinition(ActorDefinition definition) {
this.definition = definition;
Texture = definition.texture;
MaxHp = definition.Hp;
Hp = definition.Hp;
MaxMp = definition.Mp;
Mp = definition.Mp;
Atk = definition.Atk;
Def = definition.Def;
Men = definition.Men;
}
}
|