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, spell_id);
32 current_damage = (uint16_t)((current_damage * spell_data.params[1]) / 100);
33 return current_damage;
34 }
35 return current_damage;
36}
37
39 uint16_t source, uint16_t target,
40 uint16_t current_damage,
41 uint16_t is_spell_damage,
42 uint32_t is_ranged_damage,
43 uint16_t spell_id)
44{
45 return 0;
46}
47
48// fire shield, ice shield, thorn shield, white essence and allmight
49// 0xc, 0xf, 0x2f, 0xaf, 0xb3
51 uint16_t source, uint16_t target,
52 uint16_t current_damage,
53 uint16_t is_spell_damage,
54 uint32_t is_ranged_damage,
55 uint16_t spell_id)
56{
57 if ((!is_ranged_damage) && (!is_spell_damage) && (source != 0))
58 {
59 SF_CGdResourceSpell spell_data;
60 spellAPI.getResourceSpellData(_this->CGdResource, &spell_data, spell_id);
61 SF_CGdTargetData source_data = {1, source, {0, 0}};
62 SF_CGdTargetData target_data = {1, target, {0, 0}};
63 // Attention -- source and target ARE reversed here
64 spellAPI.addSpell(_this->CGdSpell, spell_data.params[1], _this->maybe_random->current_step, &target_data,
65 &source_data, 0);
66 }
67 return current_damage;
68}
69
71 uint16_t source, uint16_t target,
72 uint16_t current_damage,
73 uint16_t is_spell_damage,
74 uint32_t is_ranged_damage,
75 uint16_t spell_id)
76{
77 if (!is_spell_damage)
78 {
79 uint16_t spell_index = toolboxAPI.getSpellIndexOfType(_this, target, kGdSpellLineConservation, 0);
80 uint16_t shield_value = (uint16_t)spellAPI.getXData(_this->CGdSpell, spell_index, SPELL_CONSERVATION_SHIELD);
81 if (shield_value < current_damage)
82 {
83 current_damage = current_damage - shield_value;
84 shield_value = 0;
85 }
86 else
87 {
88 shield_value = shield_value - current_damage;
89 current_damage = 0;
90 }
91 spellAPI.setXData(_this->CGdSpell, spell_index, SPELL_CONSERVATION_SHIELD, shield_value);
92 if (shield_value == 0)
93 {
94 spellAPI.figTryClrCHkSPlBfrJob2(_this->CGdSpell, spell_index);
95 spellAPI.figClrChkSplBfrChkBattle(_this->CGdSpell, spell_index, 0);
96 spellAPI.removeDLLNode(_this->CGdSpell, spell_index);
97 spellAPI.setEffectDone(_this->CGdSpell, spell_index, 0);
98 }
99 }
100 return current_damage;
101}
102
104 uint16_t source, uint16_t target,
105 uint16_t current_damage,
106 uint16_t is_spell_damage,
107 uint32_t is_ranged_damage,
108 uint16_t spell_id)
109{
110 toolboxAPI.figureSetNewJob(_this->CGdFigureJobs, target, 3, 1, 0, 0);
111 return current_damage;
112}
113
114uint16_t __thiscall feedback_dmg_handler(SF_CGdFigureToolbox *_this,
115 uint16_t source, uint16_t target,
116 uint16_t current_damage,
117 uint16_t is_spell_damage,
118 uint32_t is_ranged_damage,
119 uint16_t spell_id)
120{
121 if (is_spell_damage)
122 {
123 SF_CGdResourceSpell spell_data;
124 spellAPI.getResourceSpellData(_this->CGdResource, &spell_data, spell_id);
125 uint16_t reflect_amount = (uint16_t)((current_damage * spell_data.params[0]) / 100);
126 if (current_damage < reflect_amount)
127 {
128 current_damage = 0;
129 reflect_amount = current_damage;
130 }
131 else
132 {
133 current_damage = current_damage - reflect_amount;
134 }
135 if (((_this->CGdFigure->figures[source].flags & TOWER) == 0) && (figureAPI.isAlive(_this->CGdFigure, source)))
136 {
137 toolboxAPI.dealDamage(_this, target, source, reflect_amount, 1, 0, 0);
138 SF_CGdTargetData source_data = {1, source, {0, 0}};
139 SF_CGdTargetData target_data = {1, target, {0, 0}};
140 SF_Rectangle rect = {0, 0};
141 effectAPI.addEffect(_this->CGdEffect, kGdEffectSpellVoodooHitFigure, &target_data, &source_data,
142 _this->maybe_random->current_step, 10, &rect);
143 }
144 }
145 return current_damage;
146}
147
149 uint16_t source, uint16_t target,
150 uint16_t current_damage,
151 uint16_t is_spell_damage,
152 uint32_t is_ranged_damage,
153 uint16_t spell_id)
154{
155 SF_CGdResourceSpell spell_data;
156 spellAPI.getResourceSpellData(_this->CGdResource, &spell_data, spell_id);
157 uint16_t roll_value = spellAPI.getRandom(_this->maybe_random, 100);
158 uint16_t current_health = figureAPI.getCurrentStat(_this->CGdFigure, target, HEALTH);
159 if (current_health <= current_damage)
160 {
161 if (roll_value <= spell_data.params[2])
162 {
163 current_damage = current_health - 1;
164 }
165 }
166 return current_damage;
167}
168
170 uint16_t source, uint16_t target,
171 uint16_t current_damage,
172 uint16_t is_spell_damage,
173 uint32_t is_ranged_damage,
174 uint16_t spell_id)
175{
176 SF_CGdResourceSpell spell_data;
177 spellAPI.getResourceSpellData(_this->CGdResource, &spell_data, spell_id);
178 uint16_t spell_index = toolboxAPI.getSpellIndexOfType(_this, target, spell_data.spell_line_id, 0);
179 while (spell_index != 0)
180 {
181 spellAPI.figTryUnfreeze(_this->CGdSpell, spell_index, 0);
182 spellAPI.figTryClrCHkSPlBfrJob2(_this->CGdSpell, spell_index);
183 spellAPI.figClrChkSplBfrChkBattle(_this->CGdSpell, spell_index, 0);
184 spellAPI.removeDLLNode(_this->CGdSpell, spell_index);
185 spellAPI.setEffectDone(_this->CGdSpell, spell_index, 0);
186 spell_index = toolboxAPI.getSpellIndexOfType(_this, target, spell_data.spell_line_id, 0);
187 }
188 return current_damage;
189}
190
192 uint16_t source, uint16_t target,
193 uint16_t current_damage,
194 uint16_t is_spell_damage,
195 uint32_t is_ranged_damage,
196 uint16_t spell_id)
197{
198 SF_CGdResourceSpell spell_data;
199 spellAPI.getResourceSpellData(_this->CGdResource, &spell_data, spell_id);
200 uint16_t spell_index = toolboxAPI.getSpellIndexOfType(_this, target, spell_data.spell_line_id, 0);
201 while (spell_index != 0)
202 {
203 toolboxAPI.removeSpellFromList(_this, target, spell_index);
204 spellAPI.figTryUnfreeze(_this->CGdSpell, spell_index, target);
205 tryClearCheckSpellsBeforeJob(_this->CGdSpell, spell_index, target);
206 spellAPI.figClrChkSplBfrChkBattle(_this->CGdSpell, spell_index, target);
207 spell_index = toolboxAPI.getSpellIndexOfType(_this, target, spell_data.spell_line_id, 0);
208 }
209 return current_damage;
210}
211
212// Need passthough for figureAPI GetCurrentMana, SubMana here.
214 uint16_t source, uint16_t target,
215 uint16_t current_damage,
216 uint16_t is_spell_damage,
217 uint32_t is_ranged_damage,
218 uint16_t spell_id)
219{
220 uint16_t mana_left = figureAPI.getCurrentStat(_this->CGdFigure, target, MANA);
221 if (mana_left < current_damage)
222 {
223 current_damage = current_damage - mana_left;
224 figureAPI.subMana(_this->CGdFigure, target, mana_left);
225 }
226 else
227 {
228 figureAPI.subMana(_this->CGdFigure, target, current_damage);
229 current_damage = 0;
230 }
231 SF_CGdTargetData source_data = {0, 0, {0, 0}};
232 SF_CGdTargetData target_data = {1, target, {0, 0}};
233 SF_Rectangle rect = {0, 0};
234 effectAPI.addEffect(_this->CGdEffect, kGdEffectSpellManaShieldHitFigure, &source_data, &target_data,
235 _this->maybe_random->current_step, 0x14, &rect);
236 return current_damage;
237}
SpellFunctions * spellAPI
Definition TestMod.cpp:11
FigureFunctions * figureAPI
Definition TestMod.cpp:13
ToolboxFunctions * toolboxAPI
Definition TestMod.cpp:12
EffectFunctions effectAPI
Definition sf_hooks.c:45
void __thiscall tryClearCheckSpellsBeforeJob(SF_CGdSpell *_this, uint16_t spell_index, uint16_t figure_index)
@ kGdEffectSpellVoodooHitFigure
@ kGdEffectSpellManaShieldHitFigure
@ SPELL_CONSERVATION_SHIELD
@ kGdSpellLineConservation
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 hypnotize_area_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)
GdFigure figures[2000]
SF_CGdFigureJobs * CGdFigureJobs
SF_CGdResource * CGdResource