Spellforce-Spell-framework
Loading...
Searching...
No Matches
sf_spelldamage_handlers.cpp
Go to the documentation of this file.
4#include "../core/sf_hooks.h"
5
6uint16_t __thiscall steelskin_dmg_handler(SF_CGdFigureToolbox *_this,
7 uint16_t source, uint16_t target,
8 uint16_t current_damage,
9 uint16_t is_spell_damage,
10 uint32_t is_ranged_damage,
11 uint16_t spell_id)
12{
13 if (is_ranged_damage)
14 {
15 return 0;
16 }
17 return current_damage;
18}
19
20// same for endurance ability to a T
22 uint16_t source, uint16_t target,
23 uint16_t current_damage,
24 uint16_t is_spell_damage,
25 uint32_t is_ranged_damage,
26 uint16_t spell_id)
27{
28 if ((!is_ranged_damage) && (!is_spell_damage))
29 {
30 SF_CGdResourceSpell spell_data;
31 spellAPI.getResourceSpellData(_this->CGdResource, &spell_data,
32 spell_id);
33 current_damage = (uint16_t)((current_damage * spell_data.params[1]) /
34 100);
35 return current_damage;
36 }
37 return current_damage;
38}
39
41 uint16_t source, uint16_t target,
42 uint16_t current_damage,
43 uint16_t is_spell_damage,
44 uint32_t is_ranged_damage,
45 uint16_t spell_id)
46{
47 return 0;
48}
49
50// fire shield, ice shield, thorn shield, white essence and allmight
51// 0xc, 0xf, 0x2f, 0xaf, 0xb3
53 uint16_t source, uint16_t target,
54 uint16_t current_damage,
55 uint16_t is_spell_damage,
56 uint32_t is_ranged_damage,
57 uint16_t spell_id)
58{
59 if ((!is_ranged_damage) && (!is_spell_damage) && (source != 0))
60 {
61 SF_CGdResourceSpell spell_data;
62 spellAPI.getResourceSpellData(_this->CGdResource, &spell_data,
63 spell_id);
64 SF_CGdTargetData source_data = {1, source, {0, 0}};
65 SF_CGdTargetData target_data = {1, target, {0, 0}};
66 // Attention -- source and target ARE reversed here
67 spellAPI.addSpell(_this->CGdSpell, spell_data.params[1],
68 _this->maybe_random->current_step, &target_data,
69 &source_data, 0);
70 }
71 return current_damage;
72}
73
75 uint16_t source, uint16_t target,
76 uint16_t current_damage,
77 uint16_t is_spell_damage,
78 uint32_t is_ranged_damage,
79 uint16_t spell_id)
80{
81 if (!is_spell_damage)
82 {
83 uint16_t spell_index = toolboxAPI.getSpellIndexOfType(_this, target,
84 0x8c, 0);
85 uint16_t shield_value = (uint16_t)spellAPI.getXData(_this->CGdSpell,
86 spell_index,
88 if (shield_value < current_damage)
89 {
90 current_damage = current_damage - shield_value;
91 shield_value = 0;
92 }
93 else
94 {
95 shield_value = shield_value - current_damage;
96 current_damage = 0;
97 }
98 spellAPI.setXData(_this->CGdSpell, spell_index,
99 SPELL_CONSERVATION_SHIELD, shield_value);
100 if (shield_value == 0)
101 {
102 spellAPI.figTryClrCHkSPlBfrJob2(_this->CGdSpell, spell_index);
103 spellAPI.figClrChkSplBfrChkBattle(_this->CGdSpell, spell_index, 0);
104 spellAPI.removeDLLNode(_this->CGdSpell, spell_index);
105 spellAPI.setEffectDone(_this->CGdSpell, spell_index, 0);
106 }
107 }
108 return current_damage;
109}
110
112 uint16_t source, uint16_t target,
113 uint16_t current_damage,
114 uint16_t is_spell_damage,
115 uint32_t is_ranged_damage,
116 uint16_t spell_id)
117{
118 toolboxAPI.figureSetNewJob(_this->CGdFigureJobs, target, 3, 1, 0, 0);
119 return current_damage;
120}
121
122uint16_t __thiscall feedback_dmg_handler(SF_CGdFigureToolbox *_this,
123 uint16_t source, uint16_t target,
124 uint16_t current_damage,
125 uint16_t is_spell_damage,
126 uint32_t is_ranged_damage,
127 uint16_t spell_id)
128{
129 if (is_spell_damage)
130 {
131 SF_CGdResourceSpell spell_data;
132 spellAPI.getResourceSpellData(_this->CGdResource, &spell_data,
133 spell_id);
134 uint16_t reflect_amount = (uint16_t)((current_damage *
135 spell_data.params[0]) / 100);
136 if (current_damage < reflect_amount)
137 {
138 current_damage = 0;
139 reflect_amount = current_damage;
140 }
141 else
142 {
143 current_damage = current_damage - reflect_amount;
144 }
145 toolboxAPI.dealDamage(_this, target, source, reflect_amount, 1, 0, 0);
146 SF_CGdTargetData source_data = {1, source, {0, 0}};
147 SF_CGdTargetData target_data = {1, target, {0, 0}};
148 SF_Rectangle rect = {0, 0};
150 &source_data, &target_data,
151 _this->maybe_random->current_step, 10, &rect);
152 }
153 return current_damage;
154}
155
157 uint16_t source, uint16_t target,
158 uint16_t current_damage,
159 uint16_t is_spell_damage,
160 uint32_t is_ranged_damage,
161 uint16_t spell_id)
162{
163 SF_CGdResourceSpell spell_data;
164 spellAPI.getResourceSpellData(_this->CGdResource, &spell_data, spell_id);
165 uint16_t roll_value = spellAPI.getRandom(_this->maybe_random, 100);
166 uint16_t current_health = figureAPI.getCurrentHealth(_this->CGdFigure,
167 target);
168 if (current_health <= current_damage)
169 {
170 if (roll_value <= spell_data.params[2])
171 {
172 current_damage = current_health - 1;
173 }
174 }
175 return current_damage;
176}
177
179 uint16_t source, uint16_t target,
180 uint16_t current_damage,
181 uint16_t is_spell_damage,
182 uint32_t is_ranged_damage,
183 uint16_t spell_id)
184{
185 SF_CGdResourceSpell spell_data;
186 spellAPI.getResourceSpellData(_this->CGdResource, &spell_data, spell_id);
187 uint16_t spell_index = toolboxAPI.getSpellIndexOfType(_this, target,
188 spell_data.
189 spell_line_id, 0);
190 while (spell_index != 0)
191 {
192 spellAPI.figTryUnfreeze(_this->CGdSpell, spell_index, 0);
193 spellAPI.figTryClrCHkSPlBfrJob2(_this->CGdSpell, spell_index);
194 spellAPI.figClrChkSplBfrChkBattle(_this->CGdSpell, spell_index, 0);
195 spellAPI.removeDLLNode(_this->CGdSpell, spell_index);
196 spellAPI.setEffectDone(_this->CGdSpell, spell_index, 0);
197 spell_index = toolboxAPI.getSpellIndexOfType(_this, target,
198 spell_data.spell_line_id,
199 0);
200 }
201 return current_damage;
202}
203
204// Need passthough for figureAPI GetCurrentMana, SubMana here.
206 uint16_t source, uint16_t target,
207 uint16_t current_damage,
208 uint16_t is_spell_damage,
209 uint32_t is_ranged_damage,
210 uint16_t spell_id)
211{
212 uint16_t mana_left = figureAPI.getCurrentMana(_this->CGdFigure, target);
213 if (mana_left < current_damage)
214 {
215 current_damage = current_damage - mana_left;
216 figureAPI.subMana(_this->CGdFigure, target, mana_left);
217 }
218 else
219 {
220 figureAPI.subMana(_this->CGdFigure, target, current_damage);
221 current_damage = 0;
222 }
223 SF_CGdTargetData source_data = {0, 0, {0, 0}};
224 SF_CGdTargetData target_data = {1, target, {0, 0}};
225 SF_Rectangle rect = {0, 0};
227 &source_data, &target_data,
228 _this->maybe_random->current_step, 0x14, &rect);
229 return current_damage;
230}
SpellFunctions * spellAPI
Definition TestMod.cpp:11
FigureFunctions * figureAPI
Definition TestMod.cpp:13
ToolboxFunctions * toolboxAPI
Definition TestMod.cpp:12
EffectFunctions effectAPI
Definition sf_hooks.c:37
@ SPELL_CONSERVATION_SHIELD
@ kGdEffectSpellVoodooHitFigure
@ kGdEffectSpellManaShieldHitFigure
uint16_t __thiscall hypnotize_dmg_handler(SF_CGdFigureToolbox *_this, uint16_t source, uint16_t target, uint16_t current_damage, uint16_t is_spell_damage, uint32_t is_ranged_damage, uint16_t spell_id)
uint16_t __thiscall durability_dmg_handler(SF_CGdFigureToolbox *_this, uint16_t source, uint16_t target, uint16_t current_damage, uint16_t is_spell_damage, uint32_t is_ranged_damage, uint16_t spell_id)
uint16_t __thiscall steelskin_dmg_handler(SF_CGdFigureToolbox *_this, uint16_t source, uint16_t target, uint16_t current_damage, uint16_t is_spell_damage, uint32_t is_ranged_damage, uint16_t spell_id)
uint16_t __thiscall mana_shield_dmg_handler(SF_CGdFigureToolbox *_this, uint16_t source, uint16_t target, uint16_t current_damage, uint16_t is_spell_damage, uint32_t is_ranged_damage, uint16_t spell_id)
uint16_t invulnerability_dmg_handler(SF_CGdFigureToolbox *_this, uint16_t source, uint16_t target, uint16_t current_damage, uint16_t is_spell_damage, uint32_t is_ranged_damage, uint16_t spell_id)
uint16_t __thiscall feedback_dmg_handler(SF_CGdFigureToolbox *_this, uint16_t source, uint16_t target, uint16_t current_damage, uint16_t is_spell_damage, uint32_t is_ranged_damage, uint16_t spell_id)
uint16_t __thiscall dmg_shield_dmg_handler(SF_CGdFigureToolbox *_this, uint16_t source, uint16_t target, uint16_t current_damage, uint16_t is_spell_damage, uint32_t is_ranged_damage, uint16_t spell_id)
uint16_t __thiscall death_grasp_dmg_handler(SF_CGdFigureToolbox *_this, uint16_t source, uint16_t target, uint16_t current_damage, uint16_t is_spell_damage, uint32_t is_ranged_damage, uint16_t spell_id)
uint16_t __thiscall feign_death_dmg_handler(SF_CGdFigureToolbox *_this, uint16_t source, uint16_t target, uint16_t current_damage, uint16_t is_spell_damage, uint32_t is_ranged_damage, uint16_t spell_id)
uint16_t __thiscall conservation_dmg_handler(SF_CGdFigureToolbox *_this, uint16_t source, uint16_t target, uint16_t current_damage, uint16_t is_spell_damage, uint32_t is_ranged_damage, uint16_t spell_id)
addEffect_ptr addEffect
getCurrentHealth_ptr getCurrentHealth
getCurrentMana_ptr getCurrentMana
getRandom_ptr getRandom
Generates a random value up to the specified maximum value.
getResourceSpellData_ptr getResourceSpellData
setEffectDone_ptr setEffectDone
Stops a spell effect handler for a given spell.
getXData_ptr getXData
Retrieves the XData value for a specific spell.
addSpell_ptr addSpell
Creates a new spell of a given spell type.
figTryClrCHkSPlBfrJob2_ptr figTryClrCHkSPlBfrJob2
clears the CHECK_SPELLS_BEFORE_JOB2 flag
removeDLLNode_ptr removeDLLNode
Used to remove a spell from the list of active spells over the target.
figTryUnfreeze_ptr figTryUnfreeze
clears the UNFREEZE flag
setXData_ptr setXData
This function is used to assign specific value to an XData key of a given spell.
figClrChkSplBfrChkBattle_ptr figClrChkSplBfrChkBattle
Clears the CHECK_SPELLS_BEFORE_CHECK_BATTLE flag.
dealDamage_ptr dealDamage
figureSetNewJob_ptr figureSetNewJob
getSpellIndexOfType_ptr getSpellIndexOfType