-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathEntity.cs
83 lines (77 loc) · 2.64 KB
/
Entity.cs
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 System;
namespace ttc_wtc
{
[Serializable]
class Entity
{
public int Stunned { get; set; }
public bool Alive { get; set; }
public char Symbol { get; }
public string Name { get; }
public int X { get; set; }
public int Y { get; set; }
public int MapId { get; set; }
public (int BasicDamage, int CurrentDamage) Damage { get; set; }
public (int BasicDefense, int CurrentDefense) Defense { get; set; }
public (int CurrentHP, int MaximumHP) HP { get; set; }
public Entity(string name, int hp, int damage, int defense, int mapId, int x, int y, char symb)
{
Name = name;
MapId = mapId;
X = x;
Y = y;
Symbol = symb;
Alive = true;
Stunned = 0;
HP = (hp, hp);
Damage = (damage, damage);
Defense = (defense, defense);
}
public bool Move(int dirX, int dirY, bool endless = false)
{
int startingMapId = MapId;
if (!MovementManager.TryMove(this, dirX, dirY, endless))
{
int gameStatus = MovementManager.CantMoveDecider(MapId, X + dirX, Y + dirY);
if (this is Player)
{
Game.GameStatus = (Game.Status)gameStatus;
}
else if (this is Enemy)
{
if (gameStatus == (int)Game.Status.InBattleForEntity)
{
Game.GameStatus = Game.Status.InBattle;
}
}
return false;
}
return startingMapId == MapId;
}
public void MoveTowards(int x, int y)
{
Point direction = Pathfinder.GetPath(X, (Y + 1) / 2, x, (y + 1) / 2, CollectedMaps.GetPassable(MapId));
Move(direction.x, direction.y);
}
public int GetDamaged(int damage, bool ignoreArmor = false)
{
int damageRecieved;
if (!ignoreArmor)
{
double percentBlocked = (Defense.CurrentDefense * 0.01) / (1 + Defense.CurrentDefense * 0.01);
damageRecieved = (int)Math.Round(Convert.ToDouble(damage) * (1 - percentBlocked));
}
else damageRecieved = damage;
if (damageRecieved >= HP.CurrentHP)
{
HP = (0, HP.MaximumHP);
Alive = false;
}
else
{
HP = (HP.CurrentHP - damageRecieved, HP.MaximumHP);
}
return damageRecieved;
}
}
}