Spellforce-Spell-framework
Loading...
Searching...
No Matches
sf_onhit_handlers.cpp
Go to the documentation of this file.
1#include "sf_onhit_handlers.h"
3#include "../core/sf_hooks.h"
4#include <list>
5
6uint16_t __thiscall trueshot_onhit_handler(SF_CGdFigureJobs *_this,
7 uint16_t source_index,
8 uint16_t target_index,
9 uint16_t damage)
10{
11 SF_SGtFigureAction action;
12 aiAPI.getTargetAction(_this->CGdFigure, &action, source_index);
13
14 if (isActionMelee(&action))
15 {
16 return damage;
17 }
18
19 uint16_t spell_index_of_type =
22 SF_CGdResourceSpell spell_data;
23 uint16_t spell_id = spellAPI.getSpellID(_this->CGdSpell,
24 spell_index_of_type);
25 spellAPI.getResourceSpellData(_this->CGdResource, &spell_data, spell_id);
26 uint16_t current_damage = (spell_data.params[1] * damage) / 100;
27 return current_damage;
28}
29
30uint16_t __thiscall riposte_onhit_handler(SF_CGdFigureJobs *_this,
31 uint16_t source_index,
32 uint16_t target_index,
33 uint16_t damage)
34{
35 SF_SGtFigureAction action;
36 aiAPI.getTargetAction(_this->CGdFigure, &action, source_index);
37 bool isMeleeAttack = isActionMelee(&action);
38
39 if (!isMeleeAttack)
40 {
41 return damage;
42 }
43
44 SF_CGdResourceSpell spell_data;
45 uint16_t spell_index =
48 uint16_t spell_id = spellAPI.getSpellID(_this->CGdSpell, spell_index);
49 spellAPI.getResourceSpellData(_this->CGdResource, &spell_data, spell_id);
50
51 uint16_t return_damage = (damage * spell_data.params[0]) / 100;
52
53 // Lower the damage by the amount that will be reflected
54 uint16_t final_damage = (damage - return_damage);
55 if (final_damage != 0)
56 {
57 toolboxAPI.dealDamage(_this->CGdFigureToolBox, target_index,
58 source_index, return_damage, 0, 0, 0);
59 }
60
61 return final_damage;
62}
63
64uint16_t __thiscall durability_onhit_handler(SF_CGdFigureJobs *_this,
65 uint16_t source_index,
66 uint16_t target_index,
67 uint16_t damage)
68{
69 SF_SGtFigureAction action;
70 aiAPI.getTargetAction(_this->CGdFigure, &action, source_index);
71 bool isMeleeAttack = isActionMelee(&action);
72
73 if (!isMeleeAttack)
74 {
75 return damage;
76 }
77
78 SF_CGdResourceSpell spell_data;
79 uint16_t spell_index =
82 uint16_t spell_id = spellAPI.getSpellID(_this->CGdSpell, spell_index);
83 spellAPI.getResourceSpellData(_this->CGdResource, &spell_data, spell_id);
84 return (damage * spell_data.params[1]) / 100;
85}
86
88 uint16_t source_index,
89 uint16_t target_index,
90 uint16_t damage)
91{
92 // no need to calculate damage in this cases
93 if (damage == 0)
94 {
95 return damage;
96 }
97 uint16_t target_level = _this->CGdFigure->figures[target_index].level;
98 uint16_t source_level = _this->CGdFigure->figures[source_index].level;
99 // not proccing on targets 5+ levels above source
100 if (source_level + 5 <= target_level)
101 {
102 return damage;
103 }
104 // outright killing targets 15+ levels below
105 if (source_level - 0xf > target_level)
106 {
107 return 0x7fff;
108 }
109 SF_CGdResourceSpell spell_data;
110 uint16_t spell_index =
113 uint16_t spell_id = spellAPI.getSpellID(_this->CGdSpell, spell_index);
114 spellAPI.getResourceSpellData(_this->CGdResource, &spell_data, spell_id);
115
116 uint16_t tmp_damage = damage * spell_data.params[1];
117 uint16_t hp_left = figureAPI.getCurrentHealth(_this->CGdFigure,
118 target_index);
119 if (tmp_damage < hp_left)
120 {
121 return damage;
122 }
123
124 tmp_damage = ((tmp_damage - hp_left) * 100) / tmp_damage;
125 uint16_t chance = 5 * tmp_damage *
126 (5 + (int16_t)(source_level - target_level));
127 if (spellAPI.getRandom(_this->OpaqueClass, 10000) > chance)
128 {
129 return damage;
130 }
131 return 0x7fff;
132}
133
134uint16_t __thiscall endurance_onhit_handler(SF_CGdFigureJobs *_this,
135 uint16_t source_index,
136 uint16_t target_index,
137 uint16_t damage)
138{
139 SF_SGtFigureAction action;
140 aiAPI.getTargetAction(_this->CGdFigure, &action, source_index);
141 bool isMeleeAttack = isActionMelee(&action);
142
143 if (!isMeleeAttack)
144 {
145 return damage;
146 }
147 if (toolboxAPI.hasSpellOnIt(_this->CGdFigureToolBox, source_index,
149 {
150 return damage;
151 }
152
153 SF_CGdResourceSpell spell_data;
154 uint16_t spell_index =
157 uint16_t spell_id = spellAPI.getSpellID(_this->CGdSpell, spell_index);
158 spellAPI.getResourceSpellData(_this->CGdResource, &spell_data, spell_id);
159 return (damage * spell_data.params[1]) / 100;
160}
161
162uint16_t __thiscall berserk_onhit_handler(SF_CGdFigureJobs *_this,
163 uint16_t source_index,
164 uint16_t target_index,
165 uint16_t damage)
166{
167 SF_SGtFigureAction action;
168 aiAPI.getTargetAction(_this->CGdFigure, &action, source_index);
169 bool isMeleeAttack = isActionMelee(&action);
170
171 if (!isMeleeAttack)
172 {
173 return damage;
174 }
175 if (toolboxAPI.hasSpellOnIt(_this->CGdFigureToolBox, source_index,
177 {
178 return damage;
179 }
180 if (toolboxAPI.hasSpellOnIt(_this->CGdFigureToolBox, source_index,
182 {
183 return damage;
184 }
185 SF_CGdResourceSpell spell_data;
186 uint16_t spell_index =
189 uint16_t spell_id = spellAPI.getSpellID(_this->CGdSpell, spell_index);
190 spellAPI.getResourceSpellData(_this->CGdResource, &spell_data, spell_id);
191 return (damage * spell_data.params[1]) / 100;
192}
193
194uint16_t __thiscall warcry_onhit_handler(SF_CGdFigureJobs *_this,
195 uint16_t source_index,
196 uint16_t target_index, uint16_t damage)
197{
198 SF_SGtFigureAction action;
199 aiAPI.getTargetAction(_this->CGdFigure, &action, source_index);
200 bool isMeleeAttack = isActionMelee(&action);
201
202 if (!isMeleeAttack)
203 {
204 return damage;
205 }
206 if (toolboxAPI.hasSpellOnIt(_this->CGdFigureToolBox, source_index,
208 {
209 return damage;
210 }
211 if (toolboxAPI.hasSpellOnIt(_this->CGdFigureToolBox, source_index,
213 {
214 return damage;
215 }
216 if (toolboxAPI.hasSpellOnIt(_this->CGdFigureToolBox, source_index,
218 {
219 return damage;
220 }
221 SF_CGdResourceSpell spell_data;
222 uint16_t spell_index =
225 uint16_t spell_id = spellAPI.getSpellID(_this->CGdSpell, spell_index);
226 spellAPI.getResourceSpellData(_this->CGdResource, &spell_data, spell_id);
227 return (damage * spell_data.params[1]) / 100;
228}
229
231 uint16_t source_index,
232 uint16_t target_index,
233 uint16_t damage)
234{
235 // oneshot or zero damage
236 if (damage == 0x7fff || damage == 0)
237 {
238 return damage;
239 }
240 SF_CGdResourceSpell spell_data;
241 uint16_t spell_index =
244 uint16_t spell_id = spellAPI.getSpellID(_this->CGdSpell, spell_index);
245 spellAPI.getResourceSpellData(_this->CGdResource, &spell_data, spell_id);
247 iteratorAPI.figureIteratorInit(&iter, 0, 0, 0x3ff, 0x3ff);
249 _this->AutoClass22, _this->CGdWorld);
251 spell_data.params[0]);
252 std::list<uint16_t> affected_figures;
253 uint16_t figure_id = iteratorAPI.getNextFigure(&iter);
254 uint16_t element_count = 0;
255 while (figure_id != 0)
256 {
258 target_index, figure_id))
259 {
260 if (figure_id != target_index)
261 {
262 affected_figures.push_back(figure_id);
263 element_count++;
264 }
265 if (element_count == spell_data.params[1])
266 {
267 break;
268 }
269 }
270 figure_id = iteratorAPI.getNextFigure(&iter);
271 }
272 if (element_count != 0)
273 {
274 uint16_t shared_damage = (damage / (element_count + 1));
275 uint16_t remainder = (damage % (element_count + 1));
276 SF_Coord source_pos = _this->CGdFigure->figures[target_index].position;
277 SF_CGdTargetData source_data;
278 source_data.entity_index = target_index;
279 source_data.entity_type = 1;
280 source_data.position = source_pos;
281 for (auto t : affected_figures)
282 {
283 SF_Coord friend_pos = _this->CGdFigure->figures[t].position;
284 uint32_t distance = getDistance(&source_pos, &friend_pos);
285 distance = (distance * 0x578) / 1000;
286 if (distance == 0)
287 {
288 distance = 1;
289 }
290 SF_CGdTargetData friend_data;
291 friend_data.entity_type = 1;
292 friend_data.entity_index = t;
293 friend_pos = friend_pos;
294 SF_Rectangle unused = {0, 0};
297 &friend_data,
298 _this->OpaqueClass->current_step, distance,
299 &unused);
300 toolboxAPI.dealDamage(_this->CGdFigureToolBox, source_index, t,
301 shared_damage, 0, 0, 0);
302 }
303 damage = shared_damage + remainder;
304 }
306 return damage;
307}
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
IteratorFunctions iteratorAPI
Definition sf_hooks.c:40
AiFunctions aiAPI
Definition sf_hooks.c:41
uint32_t getDistance(SF_Coord *pointA, SF_Coord *pointB)
bool __thiscall isActionMelee(SF_SGtFigureAction *_this)
@ kGdEffectSpellAssistanceHitFigure
uint16_t __thiscall critical_hits_onhit_handler(SF_CGdFigureJobs *_this, uint16_t source_index, uint16_t target_index, uint16_t damage)
uint16_t __thiscall endurance_onhit_handler(SF_CGdFigureJobs *_this, uint16_t source_index, uint16_t target_index, uint16_t damage)
uint16_t __thiscall warcry_onhit_handler(SF_CGdFigureJobs *_this, uint16_t source_index, uint16_t target_index, uint16_t damage)
uint16_t __thiscall assistance_onhit_handler(SF_CGdFigureJobs *_this, uint16_t source_index, uint16_t target_index, uint16_t damage)
uint16_t __thiscall berserk_onhit_handler(SF_CGdFigureJobs *_this, uint16_t source_index, uint16_t target_index, uint16_t damage)
uint16_t __thiscall riposte_onhit_handler(SF_CGdFigureJobs *_this, uint16_t source_index, uint16_t target_index, uint16_t damage)
uint16_t __thiscall durability_onhit_handler(SF_CGdFigureJobs *_this, uint16_t source_index, uint16_t target_index, uint16_t damage)
uint16_t __thiscall trueshot_onhit_handler(SF_CGdFigureJobs *_this, uint16_t source_index, uint16_t target_index, uint16_t damage)
@ kGdSpellLineAbilityTrueShot
@ kGdSpellLineAbilityDurability
@ kGdSpellLineAbilityCriticalHits
@ kGdSpellLineAbilityWarCry
@ kGdSpellLineAssistance
@ kGdSpellLineAbilityRiposte
@ kGdSpellLineAbilityBerserk
@ kGdSpellLineAbilityEndurance
getTargetAction_ptr getTargetAction
addEffect_ptr addEffect
getCurrentHealth_ptr getCurrentHealth
disposeFigureIterator_ptr disposeFigureIterator
getNextFigure_ptr getNextFigure
figureIteratorSetPointers_ptr figureIteratorSetPointers
iteratorSetArea_ptr iteratorSetArea
figureIteratorInit_ptr figureIteratorInit
GdFigure figures[2000]
SF_CGdFigureToolbox * CGdFigureToolBox
getRandom_ptr getRandom
Generates a random value up to the specified maximum value.
getResourceSpellData_ptr getResourceSpellData
getSpellID_ptr getSpellID
Retrieves the Spell Effect ID for a given spell index. The spell effect ID can be used to obtain spel...
dealDamage_ptr dealDamage
hasSpellOnIt_ptr hasSpellOnIt
figuresCheckFriendly_ptr figuresCheckFriendly
getSpellIndexOfType_ptr getSpellIndexOfType