Skip to content

Commit 86cdd4e

Browse files
authored
Damage Engine Fixed (#417)
* Fixed DamageEvent and other stuff
1 parent bccd56d commit 86cdd4e

7 files changed

Lines changed: 46 additions & 29 deletions

File tree

wurst/_handles/Camera.wurst

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -252,22 +252,23 @@ public function player.adjustCameraBounds(CameraBoundsAdjust adjustMethod, real
252252
printLog(Loglevel.WARNING, "Unrecognized adjustment method, request ignored.")
253253
return
254254

255-
// Adjust the actual camera values
256-
var minX = GetCameraBoundMinX() - scale * dxWest
257-
var maxX = GetCameraBoundMaxX() + scale * dxEast
258-
var minY = GetCameraBoundMinY() - scale * dySouth
259-
var maxY = GetCameraBoundMaxY() + scale * dyNorth
260-
261-
// Make sure the camera bounds are still valid.
262-
if maxX < minX
263-
minX = minX + maxX * 0.5
264-
maxX = minX
265-
if maxY < minY
266-
minY = (minY + maxY) * 0.5
267-
maxY = minY
268-
269-
// Apply the new camera values.
270-
SetCameraBounds(minX, minY, minX, maxY, maxX, maxY, maxX, minY)
255+
if this == localPlayer
256+
// Adjust the actual camera values
257+
var minX = GetCameraBoundMinX() - scale * dxWest
258+
var maxX = GetCameraBoundMaxX() + scale * dxEast
259+
var minY = GetCameraBoundMinY() - scale * dySouth
260+
var maxY = GetCameraBoundMaxY() + scale * dyNorth
261+
262+
// Make sure the camera bounds are still valid.
263+
if maxX < minX
264+
minX = minX + maxX * 0.5
265+
maxX = minX
266+
if maxY < minY
267+
minY = (minY + maxY) * 0.5
268+
maxY = minY
269+
270+
// Apply the new camera values.
271+
SetCameraBounds(minX, minY, minX, maxY, maxX, maxY, maxX, minY)
271272

272273
/** Set the position the camera will go when you press the space-bar */
273274
public function player.setCameraQuickPosition(vec2 pos)

wurst/_handles/Destructable.wurst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
package Destructable
22
import NoWurst
3-
import Vectors
43
import Wurstunit
54
import Annotations
5+
import Vectors
66

77
public function createDestructable(int id, vec3 pos, angle direction, real scale, int variation) returns destructable
88
return createDestructable(id, pos.toVec2(), direction, scale, variation)

wurst/_handles/Force.wurst

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,14 @@ public function force.has(unit whichUnit) returns bool
6666
public function force.has(player whichPlayer) returns bool
6767
return IsPlayerInForce(whichPlayer, this)
6868

69+
int count
70+
public function force.size() returns int
71+
count = 0
72+
this.forEach(() -> begin
73+
count++
74+
end)
75+
return count
76+
6977
/* Force iterator */
7078
force iterForce
7179

wurst/_handles/Group.wurst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ public function group.addUnit(vararg unit units)
5656
for u in units
5757
this.add(u)
5858

59-
/** Retruns the number of removed units. */
59+
/** Returns the number of removed units. */
6060
public function group.remove(vararg unit units) returns int
6161
var i = 0
6262
for u in units
@@ -132,8 +132,8 @@ group mainGroup
132132
int count
133133

134134
public function group.add(vararg group groups) returns int
135-
// I had to do it in this way because I can't use the "for u in g" is using a recursion,
136-
// because it needs the function .iterator(), but that needs this function first
135+
// I had to do it in this way because I can't use the "for u in g" cause is using a recursion,
136+
// since it needs the function .iterator(), but that needs this function first
137137

138138
mainGroup = this
139139
count = 0

wurst/_handles/Trigger.wurst

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -87,9 +87,6 @@ public function trigger.registerPlayerUnitEvent(player whichPlayer, playerunitev
8787
public function trigger.registerPlayerAllianceChange(player whichPlayer, alliancetype whichAlliance) returns event
8888
return TriggerRegisterPlayerAllianceChange(this, whichPlayer, whichAlliance)
8989

90-
public function trigger.registerPlayerSync(player whichPlayer, alliancetype whichAlliance) returns event
91-
return TriggerRegisterPlayerAllianceChange(this, whichPlayer, whichAlliance)
92-
9390
public function trigger.registerTimerEvent(real timeout, boolean periodic) returns event
9491
return TriggerRegisterTimerEvent(this, timeout, periodic)
9592

wurst/_handles/_Handles.wurst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import NoWurst
33
import public _Primitives
44

55
import public Boolexpr
6+
import public Camera
67
import public Destructable
78
import public Effect
89
import public Fogmodifier

wurst/event/DamageEvent.wurst

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ package DamageEvent
7272
import DamageDetection
7373
import OnUnitEnterLeave
7474
import ClosureForGroups
75-
import TimerUtils
75+
import ClosureTimers
7676
import LinkedList
7777
import ErrorHandling
7878
import AbilityObjEditing
@@ -158,7 +158,6 @@ class DamageInstance
158158
protected DamageElement damageElement
159159

160160
protected static thistype current = null
161-
protected static thistype array stack
162161
protected static int count = 0
163162

164163
protected real lastDamageHP = 0.00
@@ -178,8 +177,6 @@ class DamageInstance
178177
this.damageElement = damageElement
179178

180179
count++
181-
stack[count] = this
182-
current = this
183180

184181
protected function setAmount(real amount)
185182
this.amount = amount
@@ -193,7 +190,6 @@ class DamageInstance
193190

194191
ondestroy
195192
count--
196-
current = stack[count]
197193

198194

199195
/* DAMAGE EVENT */
@@ -250,7 +246,10 @@ public class DamageEvent
250246
for i = 0 to maxUnreducedPriority
251247
var listener = firstUnreducedListeners[i]
252248
while listener != null
249+
let prev = DamageInstance.current
250+
DamageInstance.current = dmg
253251
listener.onEvent()
252+
DamageInstance.current = prev
254253
if abort
255254
dmg.amount = 0
256255
break
@@ -259,6 +258,11 @@ public class DamageEvent
259258
if abort
260259
break
261260

261+
if amount == 0.
262+
destroy dmg
263+
recursion--
264+
return
265+
262266
// All events have run and the damage amount is finalized.
263267
var life = target.getLife()
264268
let maxHP = target.getMaxHP()
@@ -285,11 +289,14 @@ public class DamageEvent
285289
target.addAbility(DAMAGE_ABIL_ID)
286290
target.setLife(max(life, 0.42))
287291

288-
getTimer().start(0., function onDamage)
292+
nullTimer() ->
293+
DamageInstance.current = dmg
294+
onDamage()
289295

290296
private static function onTrg()
291297
for damage in damageList
292298
if damage.target == GetTriggerUnit()
299+
DamageInstance.current = damage
293300
onDamage()
294301
damageList.remove(damage)
295302
dmgTrg.clearActions()
@@ -315,7 +322,10 @@ public class DamageEvent
315322
for i = 0 to maxPriority
316323
var listener = firstListeners[i]
317324
while listener != null
325+
let prev = DamageInstance.current
326+
DamageInstance.current = dmg
318327
listener.onEvent()
328+
DamageInstance.current = prev
319329
if abort
320330
dmg.amount = 0
321331
break

0 commit comments

Comments
 (0)