-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBoulder.as
258 lines (213 loc) · 5.72 KB
/
Boulder.as
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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
#include "/Entities/Common/Attacks/Hitters.as";
#include "/Entities/Common/Attacks/LimitedAttacks.as";
const int pierce_amount = 8;
const f32 hit_amount_ground = 0.5f;
const f32 hit_amount_air = 1.0f;
const f32 hit_amount_air_fast = 3.0f;
const f32 hit_amount_cata = 10.0f;
void onInit(CBlob @ this)
{
dictionary harvest;
harvest.set("mat_stone", 2);
this.set("harvest", harvest);//Logs leik dis
this.set_u8("launch team", 255);
this.server_setTeamNum(-1);
this.Tag("medium weight");
LimitedAttack_setup(this);
this.set_u8("blocks_pierced", 0);
u32[] tileOffsets;
this.set("tileOffsets", tileOffsets);
// damage
this.getCurrentScript().runFlags |= Script::tick_not_attached;
this.getCurrentScript().tickFrequency = 3;
}
void onTick(CBlob@ this)
{
//rock and roll mode
if (!this.getShape().getConsts().collidable)
{
Vec2f vel = this.getVelocity();
f32 angle = vel.Angle();
Slam(this, angle, vel, this.getShape().vellen * 1.5f);
}
}
void onDetach(CBlob@ this, CBlob@ detached, AttachmentPoint@ attachedPoint)
{
if (detached.getName() == "catapult") // rock n' roll baby
{
this.getShape().getConsts().mapCollisions = false;
this.getShape().getConsts().collidable = false;
this.getCurrentScript().tickFrequency = 3;
}
this.set_u8("launch team", detached.getTeamNum());
}
void onAttach(CBlob@ this, CBlob@ attached, AttachmentPoint @attachedPoint)
{
if(attached.getPlayer() !is null)
{
this.SetDamageOwnerPlayer(attached.getPlayer());
}
if (attached.getName() != "catapult") // end of rock and roll
{
this.getShape().getConsts().mapCollisions = true;
this.getShape().getConsts().collidable = true;
this.getCurrentScript().tickFrequency = 1;
}
this.set_u8("launch team", attached.getTeamNum());
}
void Slam(CBlob @this, f32 angle, Vec2f vel, f32 vellen)
{
if (vellen < 0.1f)
return;
CMap@ map = this.getMap();
Vec2f pos = this.getPosition();
HitInfo@[] hitInfos;
u8 team = this.get_u8("launch team");
if (map.getHitInfosFromArc(pos, -angle, 30, vellen, this, false, @hitInfos))
{
for (uint i = 0; i < hitInfos.length; i++)
{
HitInfo@ hi = hitInfos[i];
f32 dmg = 2.0f;
if (hi.blob is null) // map
{
if (BoulderHitMap(this, hi.hitpos, hi.tileOffset, vel, dmg, Hitters::cata_boulder))
return;
}
else if (team != u8(hi.blob.getTeamNum()))
{
this.server_Hit(hi.blob, pos, vel, dmg, Hitters::cata_boulder, true);
this.setVelocity(vel * 0.9f); //damp
// die when hit something large
if (hi.blob.getRadius() > 32.0f)
{
this.server_Hit(this, pos, vel, 10, Hitters::cata_boulder, true);
}
}
}
}
// chew through backwalls
Tile tile = map.getTile(pos);
if (map.isTileBackgroundNonEmpty(tile))
{
if (map.getSectorAtPosition(pos, "no build") !is null)
{
return;
}
map.server_DestroyTile(pos + Vec2f(7.0f, 7.0f), 10.0f, this);
map.server_DestroyTile(pos - Vec2f(7.0f, 7.0f), 10.0f, this);
}
}
bool BoulderHitMap(CBlob@ this, Vec2f worldPoint, int tileOffset, Vec2f velocity, f32 damage, u8 customData)
{
//check if we've already hit this tile
u32[]@ offsets;
this.get("tileOffsets", @offsets);
if (offsets.find(tileOffset) >= 0) { return false; }
this.getSprite().PlaySound("ArrowHitGroundFast.ogg");
f32 angle = velocity.Angle();
CMap@ map = getMap();
TileType t = map.getTile(tileOffset).type;
u8 blocks_pierced = this.get_u8("blocks_pierced");
bool stuck = false;
if (map.isTileCastle(t) || map.isTileWood(t))
{
Vec2f tpos = this.getMap().getTileWorldPosition(tileOffset);
if (map.getSectorAtPosition(tpos, "no build") !is null)
{
return false;
}
//make a shower of gibs here
map.server_DestroyTile(tpos, 100.0f, this);
Vec2f vel = this.getVelocity();
this.setVelocity(vel * 0.8f); //damp
this.push("tileOffsets", tileOffset);
if (blocks_pierced < pierce_amount)
{
blocks_pierced++;
this.set_u8("blocks_pierced", blocks_pierced);
}
else
{
stuck = true;
}
}
else
{
stuck = true;
}
if (velocity.LengthSquared() < 5)
stuck = true;
if (stuck)
{
this.server_Hit(this, worldPoint, velocity, 10, Hitters::crush, true);
}
return stuck;
}
void onCollision(CBlob@ this, CBlob@ blob, bool solid, Vec2f normal, Vec2f point1)
{
if (solid && blob !is null)
{
Vec2f hitvel = this.getOldVelocity();
Vec2f hitvec = point1 - this.getPosition();
f32 coef = hitvec * hitvel;
if (coef < 0.706f) // check we were flying at it
{
return;
}
f32 vellen = hitvel.Length();
//fast enough
if (vellen < 1.0f)
{
return;
}
u8 tteam = this.get_u8("launch team");
CPlayer@ damageowner = this.getDamageOwnerPlayer();
//not teamkilling (except self)
if (damageowner is null || damageowner !is blob.getPlayer())
{
if (
(blob.getName() != this.getName() &&
(blob.getTeamNum() == this.getTeamNum() || blob.getTeamNum() == tteam))
)
{
return;
}
}
//not hitting static stuff
if (blob.getShape() !is null && blob.getShape().isStatic())
{
return;
}
//hitting less or similar mass
if (this.getMass() < blob.getMass() - 1.0f)
{
return;
}
//get the dmg required
hitvel.Normalize();
f32 dmg = vellen > 8.0f ? 5.0f : (vellen > 4.0f ? 1.5f : 0.5f);
//bounce off if not gibbed
if(dmg < 4.0f)
{
this.setVelocity(blob.getOldVelocity() + hitvec * -Maths::Min(dmg * 0.33f, 1.0f));
}
//hurt
this.server_Hit(blob, point1, hitvel, dmg, Hitters::boulder, true);
return;
}
}
f32 onHit(CBlob@ this, Vec2f worldPoint, Vec2f velocity, f32 damage, CBlob@ hitterBlob, u8 customData)
{
if (customData == Hitters::sword || customData == Hitters::arrow)
{
return damage *= 0.5f;
}
return damage;
}
//sprite
void onInit(CSprite@ this)
{
this.animation.frame = (this.getBlob().getNetworkID() % 4);
this.getCurrentScript().runFlags |= Script::remove_after_this;
}