-
Notifications
You must be signed in to change notification settings - Fork 33
/
animation.js
81 lines (77 loc) · 2.4 KB
/
animation.js
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
// this object provides some general call backs for post animation action
var ANIMATION =
{
postAnimationHeal : function(postAnimation, map)
{
postAnimation.seekBuffer();
var x = postAnimation.readDataInt32();
var y = postAnimation.readDataInt32();
var heal = postAnimation.readDataInt32();
if (map.onMap(x, y))
{
var unit = map.getTerrain(x, y).getUnit();
if (unit !== null)
{
unit.setHp(unit.getHpRounded() + heal);
}
}
},
postAnimationDamage : function(postAnimation, map)
{
postAnimation.seekBuffer();
var x = postAnimation.readDataInt32();
var y = postAnimation.readDataInt32();
var damage = postAnimation.readDataInt32();
if (map.onMap(x, y))
{
var unit = map.getTerrain(x, y).getUnit();
if (unit !== null)
{
var hp = unit.getHpRounded();
if (hp - damage <= 0.1)
{
// set hp to very very low
unit.setHp(0.1);
}
else
{
unit.setHp(hp - damage);
}
}
}
},
postAnimationDamageKill : function(postAnimation, map)
{
postAnimation.seekBuffer();
var x = postAnimation.readDataInt32();
var y = postAnimation.readDataInt32();
var damage = postAnimation.readDataInt32();
if (map.onMap(x, y))
{
var unit = map.getTerrain(x, y).getUnit();
if (unit !== null)
{
unit.setHp(unit.getHpRounded() - damage);
if (unit.getHp() <= 0)
{
unit.killUnit();
}
}
}
},
postAnimationSpawnUnit : function(postAnimation, map)
{
postAnimation.seekBuffer();
var x = postAnimation.readDataInt32();
var y = postAnimation.readDataInt32();
var unitId = postAnimation.readDataString();
var owner = postAnimation.readDataInt32();
var hp = postAnimation.readDataInt32();
map.spawnUnit(x, y, unitId, map.getPlayer(owner));
map.getTerrain(x, y).getUnit().setHp(hp);
},
preOnAnimationChangedAnimation : function(animation, map)
{
map.getGameRules().onWeatherChanged();
},
};