Skip to content

Commit

Permalink
First commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Frotty committed Jan 8, 2017
1 parent 636b372 commit 414b4ce
Show file tree
Hide file tree
Showing 18 changed files with 1,031 additions and 0 deletions.
7 changes: 7 additions & 0 deletions .gitignore
@@ -0,0 +1,7 @@
*.w3x
*.w3m

wurst.dependencies
objectEditingOutput/
.vscode/settings.json
compiled.j.txt
Binary file added imports/TC_EnergyBolt.mdx
Binary file not shown.
Binary file added imports/dummy.mdx
Binary file not shown.
144 changes: 144 additions & 0 deletions wurst/buff/Buff.wurst
@@ -0,0 +1,144 @@
package Buff
import public Entity
import LinkedListModule
import Squares
import TextTagEntity
import OnUnitEnterLeave
import BuffObjEditing
import ObjectIds
import AbilityObjEditing
import ObjectIdGenerator

@configurable public constant falsifyTeamattacks = false
@configurable public constant showSquares = false

public constant BUFF_ANIM_PERIOD = 0.25
LinkedList<Buff> array currentBuffs

public function UnitEntity.hasBuffs() returns boolean
return currentBuffs[this castTo int] != null

public function UnitEntity.getBuffs() returns LinkedList<Buff>
return currentBuffs[this castTo int]

public function UnitEntity.clearBuffs()
let buffs = currentBuffs[this castTo int]
if buffs != null
for bff in buffs
bff.done = true
destroy buffs
currentBuffs[this castTo int] = null

public function UnitEntity.newBuffs() returns LinkedList<Buff>
currentBuffs[this castTo int] = new LinkedList<Buff>()
return currentBuffs[this castTo int]

public abstract class Buff
use LinkedListModule

UnitEntity target
real duration
int abilId
boolean done = false

construct(real duration, int abilId)
this.duration = duration
this.abilId = abilId

abstract function apply(UnitEntity target)

function attackModifier()

function defenseModifier()

function onEnd()

function update()
if duration <= 0.
done = true
onEnd()
else
duration -= BUFF_ANIM_PERIOD

function refresh()
if not target.actor.hasAbility(abilId)
target.actor.addAbility(abilId)

ondestroy
onEnd()
if target != null and not target.done and target.hasBuffs()
target.getBuffs().remove(this)
boolean isLast = true
for bff in target.getBuffs()
if bff.typeId == this.typeId
isLast = false
break
if isLast
target.actor.removeAbility(abilId)

/** Creates an ability based on Tornado aura that allows to display a buff without side effects */
public function createBuffObject(string name, string tooltip, string iconpath) returns int
let abilId = ABIL_ID_GEN.next()
let buffId = BUFF_ID_GEN.next()

if compiletime
new BuffDefinition(buffId, 'Basl')
..setName(1, name)
..setTooltipNormal(1, name)
..setTooltipNormalExtended(1, tooltip)
..setIcon(iconpath)

new AbilityDefinitionAuraSlow(abilId)
..setName("Aura Dummy: " + name)
..setMovementSpeedFactor(1, 0)
..setBuffs(1, int2fourchar(buffId))
..presetIcon(iconpath)
..setArtTarget("")
..setTargetsAllowed(1, "self")

return abilId


init
// Call attack and defense modifiers of buffs
EventListener.add(EVENT_UNIT_DAMAGED, () -> begin
let def = GetTriggerUnit()
let att = GetEventDamageSource()
UnitEntity defData = null
UnitEntity attData = null
if att.getEntity() != null and att.isAlive()
//Attacker is alive, apply his attack modifiers
attData = att.getEntity() castTo UnitEntity
if attData.hasBuffs()
for bff in attData.getBuffs()
if not bff.done
bff.attackModifier()

if def.getEntity() != null and def.isAlive()
//Defender is alive, apply his defense modifiers
defData = def.getEntity() castTo UnitEntity
if defData.hasBuffs()
for bff in defData.getBuffs()
if not bff.done
bff.defenseModifier()

if falsifyTeamattacks and defData != null and attData != null
if defData.owner.isAllyOf(attData.owner) or defData.owner == attData.owner
// Falsify teamattacks
if getDamage() > 0.5
modifyDamage(0)
if showSquares
new TextTagEntity(defData.getPos(), vec3(GetRandomReal(-2,2),GetRandomReal(-2,2),GetRandomReal(8,10)), getSquare(), 10, .8
,colorA(GetRandomInt(150,250),GetRandomInt(125,150),GetRandomInt(125,150), 255))
end)
// Update the buff display on unit upgrade
EventListener.add(EVENT_PLAYER_UNIT_UPGRADE_FINISH, () -> begin
let v = GetTriggerUnit()
if v.getUserData() > 0
let victimData = v.getUserData() castTo UnitEntity
if victimData != null and not victimData.done and victimData.hasBuffs()
for bff in victimData.getBuffs()
bff.refresh()
end)


103 changes: 103 additions & 0 deletions wurst/buff/DmgMod.wurst
@@ -0,0 +1,103 @@
package DmgMod
import LinkedListModule
import AbilityObjEditing
/*
* Package that allows to modify the damage of a DamageEvent that is happening at the time.
* Therefore it should only be used in callbacks for the Event EVENT_UNIT_DAMAGED
* Use only getDamage() inside callbacks to receive the damage including modifications
* Healing by supplying negative amounts is possible
*/

// API

/** Returns the damage of the current DamageEvent, uncluding modifications by DmgMod */
public function getDamage() returns real
if Active.last != null and GetEventDamageSource()==Active.last.source and GetTriggerUnit()==Active.last.target and GetEventDamage()==Active.last.realdmg
return Active.last.newdmg
return GetEventDamage()

/** Modifies the damage to the specified amount */
public function modifyDamage( real newdmg )
unit target = GetTriggerUnit()
real actlife = target.getHP()
real dmgtake = GetEventDamage()

if Active.last != null and GetEventDamageSource()==Active.last.source and target==Active.last.target and dmgtake==Active.last.realdmg
Active.last.newdmg = newdmg
else
var moddat = new Active()

moddat.target = target
moddat.taketrg = GetTriggeringTrigger()
moddat.source = GetEventDamageSource()
moddat.oldlife = actlife
moddat.realdmg = dmgtake
moddat.newdmg = newdmg

moddat.setbonus = not target.hasAbility(DAMAGE_ABIL_ID)
if moddat.setbonus
target.addAbility(DAMAGE_ABIL_ID)
actlife = target.getHP()

moddat.setlifed = actlife-0.405 < dmgtake
if moddat.setlifed
actlife = actlife + dmgtake
SetWidgetLife( target, actlife )
moddat.newlife = actlife

/** Modifies the damage by a certain value */
public function modifyDamageBy( real damage)
modifyDamage( getDamage() + damage )

// End of API

class Active
use LinkedListModule
static timer inst_timer = CreateTimer()
trigger taketrg
unit target
unit source
real oldlife
real newlife
real realdmg
real newdmg
boolean setlifed
boolean setbonus

construct()
// If this is the first Active DamageEvent we start the timer to apply this and all further
if this == first
inst_timer.start(0., () -> begin
while Active.first != null
var moddat = Active.first
var actlife = GetWidgetLife( moddat.target )
real resetlife
if moddat.setlifed and not moddat.setbonus
resetlife = actlife
else
resetlife = moddat.oldlife + (actlife - moddat.newlife + moddat.realdmg)

if moddat.setbonus
moddat.target.removeAbility(DAMAGE_ABIL_ID)

if resetlife - moddat.newdmg > 0.405
moddat.target.setHP( resetlife - moddat.newdmg )
else
var b = moddat.taketrg.isEnabled()
moddat.taketrg.disable()
moddat.source.damageTarget( moddat.target, MAX_HP_GAINED + 0. )
if b
moddat.taketrg.enable()

destroy moddat
end)

/** The ID used for the health bonus Ability */
constant DAMAGE_ABIL_ID = 'xdmo'
/** The amount of HP restored by the Ability */
constant MAX_HP_GAINED = 500000

/** Generates the Health-Bonus Ability */
@compiletime function generateObject()
let def = new AbilityDefinitionMaxLifeBonusGreater(DAMAGE_ABIL_ID)
def.setMaxLifeGained(1, MAX_HP_GAINED)
71 changes: 71 additions & 0 deletions wurst/buff/PresetBuffs.wurst
@@ -0,0 +1,71 @@
package PresetBuffs
import public Buff

public abstract class NormalBuff extends Buff

construct(real dur, int abilId)
super(dur, abilId)

override function apply(UnitEntity target)
this.target = target
if not target.hasBuffs()
target.newBuffs()
for bff in target.getBuffs()
if bff.typeId == this.typeId
bff.duration = duration
done = true
return
target.getBuffs().add(this)
refresh()

public abstract class StackingBuff extends Buff

construct(real dur, int abilId)
super(dur, abilId)

override function apply(UnitEntity target)
this.target = target
if not target.hasBuffs()
target.newBuffs()
target.getBuffs().add(this)
refresh()

public class ShieldBuff extends NormalBuff
real blockAmount

construct(real dur, int abilId, real amount)
super(dur, abilId)
blockAmount = amount

override function update()
super.update()
if blockAmount <= 0
done = true

override function apply(UnitEntity target)
this.target = target
if not target.hasBuffs()
target.newBuffs()
for bff in target.getBuffs()
if bff.typeId == this.typeId
let sd = bff castTo thistype
sd.duration = duration
sd.blockAmount += blockAmount
done = true
return
target.getBuffs().add(this)
refresh()


override function defenseModifier()
let dmg = getDamage()
if dmg >= blockAmount
modifyDamageBy(-blockAmount)
blockAmount = 0
done = true
else
modifyDamage(0)
blockAmount = blockAmount - dmg


override function attackModifier()

0 comments on commit 414b4ce

Please sign in to comment.