forked from tdauth/dmdf
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStruct Spell Mana Shield.j
More file actions
executable file
·114 lines (99 loc) · 4.8 KB
/
Struct Spell Mana Shield.j
File metadata and controls
executable file
·114 lines (99 loc) · 4.8 KB
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
/// Wizard
library StructSpellsSpellManaShield requires Asl, StructGameClasses, StructGameSpell
/// Der Zauberer erschafft ein Manaschild um sich herum, das Schaden absorbiert. Verbraucht X Mana pro Schadenspunt und absorbiert maximal Y Schaden.
struct SpellManaShield extends Spell
public static constant integer abilityId = 'A03A'
public static constant integer favouriteAbilityId = 'A03E'
public static constant integer classSelectionAbilityId = 'A1MB'
public static constant integer classSelectionGrimoireAbilityId = 'A1MC'
public static constant integer maxLevel = 5
private static constant integer buffId = 'B00G'
/// Costs per damage point.
private static constant real absorbedDamageManaCostStartValue = 6.0
/// Costs per damage point.
private static constant real absorbedDamageManaCostLevelValue = 1.0
private static constant real maxAbsorbedDamageLevelValue = 100.0
private ADamageRecorder m_damageRecorder
private real m_absorbedDamage
private effect m_effect
private static method onDamageAction takes ADamageRecorder damageRecorder returns nothing
local thistype spell = DmdfGlobalHashTable.global().integer(DMDF_HASHTABLE_GLOBAL_KEY_DAMAGERECORDER, damageRecorder)
local unit caster = damageRecorder.target()
local real maxAbsorbedDamage = spell.level() * thistype.maxAbsorbedDamageLevelValue
local real absorbedDamage
local real manaCostPerDamagePoint = thistype.absorbedDamageManaCostStartValue - thistype.absorbedDamageManaCostLevelValue * spell.level()
local real manaCost = GetEventDamage() * manaCostPerDamagePoint
local boolean disable = false
if (manaCost > GetUnitState(caster, UNIT_STATE_MANA)) then
set absorbedDamage = GetUnitState(caster, UNIT_STATE_MANA) / manaCostPerDamagePoint
else
set absorbedDamage = GetEventDamage()
endif
if (spell.m_absorbedDamage + absorbedDamage > maxAbsorbedDamage) then
set absorbedDamage = maxAbsorbedDamage - spell.m_absorbedDamage
set disable = true
endif
set manaCost = absorbedDamage * manaCostPerDamagePoint
/// @todo Show casting effect
call SetUnitState(caster, UNIT_STATE_MANA, GetUnitState(caster, UNIT_STATE_MANA) - manaCost)
if (GetUnitState(caster, UNIT_STATE_MANA) <= 0.0) then
set disable = true
endif
call SetUnitState(caster, UNIT_STATE_LIFE, GetUnitState(caster, UNIT_STATE_LIFE) + absorbedDamage)
call thistype.showDamageAbsorbationTextTag(caster, absorbedDamage)
if (disable) then
call damageRecorder.disable()
set spell.m_absorbedDamage = 0.0
call DestroyEffect(spell.m_effect)
set spell.m_effect = null
else
set spell.m_absorbedDamage = spell.m_absorbedDamage + absorbedDamage
endif
set caster = null
endmethod
private method action takes nothing returns nothing
debug call Print("Casting mana shield.")
if (this.m_damageRecorder == 0) then
debug call Print("Creating damage recorder.")
set this.m_damageRecorder = ADamageRecorder.create(this.character().unit())
call this.m_damageRecorder.setOnDamageAction(thistype.onDamageAction)
call DmdfGlobalHashTable.global().setInteger(DMDF_HASHTABLE_GLOBAL_KEY_DAMAGERECORDER, this.m_damageRecorder, this)
call this.m_damageRecorder.disable()
endif
if (this.m_damageRecorder.isEnabled()) then
debug call Print("Disable mana shield.")
call this.m_damageRecorder.disable()
set this.m_absorbedDamage = 0.0
call DestroyEffect(this.m_effect)
set this.m_effect = null
else
debug call Print("Enable mana shield.")
call this.m_damageRecorder.enable()
set this.m_effect = AddSpellEffectTargetById(thistype.abilityId, EFFECT_TYPE_CASTER, this.character().unit(), "chest")
endif
endmethod
public static method create takes Character character returns thistype
local thistype this = thistype.allocate(character, Classes.wizard(), Spell.spellTypeNormal, thistype.maxLevel, thistype.abilityId, thistype.favouriteAbilityId, 0, 0, thistype.action)
set this.m_damageRecorder = 0
set this.m_absorbedDamage = 0.0
set this.m_effect = null
call this.addGrimoireEntry('A1MB', 'A1MC')
call this.addGrimoireEntry('A0W6', 'A0WB')
call this.addGrimoireEntry('A0W7', 'A0WC')
call this.addGrimoireEntry('A0W8', 'A0WD')
call this.addGrimoireEntry('A0W9', 'A0WE')
call this.addGrimoireEntry('A0WA', 'A0WF')
return this
endmethod
public method onDestroy takes nothing returns nothing
if (this.m_damageRecorder != 0) then
call DmdfGlobalHashTable.global().removeInteger(DMDF_HASHTABLE_GLOBAL_KEY_DAMAGERECORDER, this.m_damageRecorder)
call this.m_damageRecorder.destroy()
endif
if (this.m_effect != null) then
call DestroyEffect(this.m_effect)
set this.m_effect = null
endif
endmethod
endstruct
endlibrary