Spellforce-Spell-framework
Loading...
Searching...
No Matches
sf_phys_effect_hook.c
Go to the documentation of this file.
4#include <utility>
5#include <list>
6
7
8void __thiscall sf_phys_effect_hook(SF_CGdEffect *_this, uint16_t effect_id)
9{
10 uint32_t source_id = effectAPI.getEffectXData(_this, effect_id, EFFECT_ENTITY_INDEX);
11 uint32_t source_type = effectAPI.getEffectXData(_this, effect_id, EFFECT_ENTITY_TYPE);
12 uint32_t target_id = effectAPI.getEffectXData(_this, effect_id, EFFECT_ENTITY_INDEX2);
13 uint32_t target_type = effectAPI.getEffectXData(_this, effect_id, EFFECT_ENTITY_TYPE2);
14 uint32_t damage = effectAPI.getEffectXData(_this, effect_id, EFFECT_PHYSICAL_DAMAGE);
15
16 //rain handlers
17 if ((!effectAPI.getEffectXData(_this, effect_id, EFFECT_ADD_SUBSPELL)) &&
18 (effectAPI.effectXDataExists(_this, effect_id, EFFECT_ADD_SUBSPELL)))
19 {
20 uint16_t spell_index = effectAPI.getEffectXData(_this, effect_id, EFFECT_SPELL_INDEX);
21 uint16_t spell_line = spellAPI.getSpellLine(_this->CGdSpell, spell_index);
22 sub_effect_handler_ptr rain_handler = get_rain_handler(spell_line);
23 rain_handler(_this, effect_id);
24 }
25 else
26 {
27 bool isMagicDamage = 0;
28 if (target_type == 1)
29 {
30 if ((figureAPI.isAlive(_this->SF_CGdFigure, target_id))
31 && (toolboxAPI.isTargetable(_this->SF_CGdFigureToolBox, target_id)))
32 {
33 uint16_t spell_line = effectAPI.getEffectXData(_this, effect_id, EFFECT_SPELL_LINE);
34 if (spell_line != 0)
35 {
36 phys_effect_handler_ptr single_handler = get_phys_effect_handler(spell_line);
37 //spark handler by default
38 damage = single_handler(_this, source_id, target_id, &isMagicDamage, damage);
39
40 }
41 if (toolboxAPI.hasSpellOnIt(_this->SF_CGdFigureToolBox, target_id, kGdSpellLineAssistance) &&
42 (damage != 0x7fff))
43 {
44 std::list<std::pair<uint16_t, onhit_handler_ptr>> onhit_list = get_onhit_phase(OnHitPhase::PHASE_2);
45 for (auto it = onhit_list.crbegin(); it != onhit_list.crend(); ++it)
46 {
47 std::pair<uint16_t, onhit_handler_ptr> entry = *it;
48 uint16_t spell_line_id = entry.first;
49 if (spell_line_id == kGdSpellLineAssistance)
50 {
51 onhit_handler_ptr onhit_func = entry.second;
52 damage = onhit_func(_this->SF_CGdFigureToolBox->CGdFigureJobs, source_id, target_id,
53 damage);
54 }
55 }
56
57 }
58 toolboxAPI.dealDamage(_this->SF_CGdFigureToolBox, source_id, target_id, damage, isMagicDamage, 1, 0);
59 //Monument protection handler
60 uint32_t mana_cost = effectAPI.getEffectXData(_this, effect_id, EFFECT_MANA_COST);
61 if (mana_cost != 0)
62 {
63 SF_CGdTargetData source;
64 source.position = {0,0};
65 source.entity_index = source_id;
66 source.entity_type = source_type;
67
68 SF_CGdTargetData target;
69 target.position = {0,0};
70 target.entity_index = target_id;
71 target.entity_type = target_type;
72
73 SF_Rectangle rect = {0,0};
74
75 effectAPI.addEffect(_this, kGdEffectMonumentHitFigure, &source, &target,
76 _this->OpaqueClass->current_step, 0x14, &rect);
77 if (figureAPI.isAlive(_this->SF_CGdFigure, target_id))
78 {
79 figureAPI.subMana(_this->SF_CGdFigure, target_id, mana_cost);
80 }
81 }
82 }
83 }
84 //Siege Aura Handler
85 else
86 {
87
88 if (_this->CGdBuilding->buildings[target_id].health_current != 0)
89 {
90 buildingAPI.buildingDealDamage(_this->SF_CGdBuildingToolbox, source_id, target_id, damage, 0);
91 }
92 }
93 }
94}
95
96/*
97 void __thiscall sf_phys_effect_hook(SF_CGdEffect *_this, uint16_t effect_id)
98 {
99 uint32_t source_id = effectAPI.getEffectXData(_this, effect_id, EFFECT_ENTITY_INDEX);
100 uint32_t source_type = effectAPI.getEffectXData(_this, effect_id, EFFECT_ENTITY_TYPE);
101 uint32_t target_id = effectAPI.getEffectXData(_this, effect_id, EFFECT_ENTITY_INDEX2);
102 uint32_t target_type = effectAPI.getEffectXData(_this, effect_id, EFFECT_ENTITY_TYPE2);
103 uint32_t damage = effectAPI.getEffectXData(_this, effect_id, EFFECT_PHYSICAL_DAMAGE);
104 if (target_type == 1)
105 {
106 bool isMagicDamage = 0;
107 toolboxAPI.dealDamage(_this->SF_CGdFigureToolBox, source_id, target_id, damage, isMagicDamage, 0, 0);
108 return;
109 }
110 if (target_type == 2)
111 {
112 log_debug(DEBUG_HIGH, "Building target? Source [%d] Target [%d]", target_id, source_id);
113
114 if (_this->CGdBuilding->buildings[target_id].health_current != 0)
115 {
116 buildingAPI.buildingDealDamage(_this->SF_CGdBuildingToolbox, source_id, target_id, damage, 0);
117 }
118 }
119 else
120 {
121 log_debug(DEBUG_HIGH, "Unknown target type [%d]", target_type);
122
123 }
124 }
125 */
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
BuildingFunctions buildingAPI
Definition sf_hooks.c:47
void(__thiscall * sub_effect_handler_ptr)(SF_CGdEffect *, uint16_t effect_index)
@ kGdEffectMonumentHitFigure
@ EFFECT_ENTITY_TYPE2
@ EFFECT_SPELL_LINE
@ EFFECT_ENTITY_INDEX2
@ EFFECT_ENTITY_TYPE
@ EFFECT_ADD_SUBSPELL
@ EFFECT_ENTITY_INDEX
@ EFFECT_PHYSICAL_DAMAGE
@ EFFECT_SPELL_INDEX
@ EFFECT_MANA_COST
@ kGdSpellLineAssistance
std::list< std::pair< uint16_t, onhit_handler_ptr > > get_onhit_phase(OnHitPhase phase)
void __thiscall sf_phys_effect_hook(SF_CGdEffect *_this, uint16_t effect_id)
sub_effect_handler_ptr get_rain_handler(uint16_t spell_line_id)
phys_effect_handler_ptr get_phys_effect_handler(uint16_t spell_line_id)
uint16_t(__thiscall * phys_effect_handler_ptr)(SF_CGdEffect *_this, uint16_t source, uint16_t target, bool *isSpellDamage, uint16_t damage)
uint16_t(__thiscall * onhit_handler_ptr)(SF_CGdFigureJobs *, uint16_t source, uint16_t target, uint16_t damage)
GdBuilding buildings[1000]
SF_CGdBuildingToolbox * SF_CGdBuildingToolbox
SF_CGdSpell * CGdSpell
AutoClass14 * OpaqueClass
SF_CGdFigure * SF_CGdFigure
SF_CGdBuilding * CGdBuilding
SF_CGdFigureToolbox * SF_CGdFigureToolBox
SF_CGdFigureJobs * CGdFigureJobs