/
bNoSingleMagic.c
80 lines (74 loc) · 2.42 KB
/
bNoSingleMagic.c
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
//===== Hercules Plugin ======================================
//= bNoSingleMagic (from Epoque Expansion Pack)
//===== By: ==================================================
//= Yan Pitangui
//===== Current Version: =====================================
//= 0.1
//===== Description: =========================================
//= bonus bNoSingleMagic, n;
//= Reduce single target magic damage in n%.
//= Example:
//= bonus bNoSingleMagic,10;
//============================================================
#include "common/hercules.h"
#include "map/pc.h"
#include "map/battle.h"
#include "common/memmgr.h"
#include "common/random.h"
#include "common/utils.h"
#include "plugins/HPMHooking.h"
#include "common/HPMDataCheck.h"
HPExport struct hplugin_info pinfo = {
"bNoSingleMagic",
SERVER_TYPE_MAP,
"0.1",
HPM_VERSION,
};
struct player_data {
int single_magic_resist;
};
int SINGLE_MAGIC_RESIST = 0;
int pc_bonus_pre(struct map_session_data** sd, int *type, int *val) {
if (*sd == NULL )
return 0;
if ( *type == SINGLE_MAGIC_RESIST) {
struct player_data *ssd = getFromMSD( *sd, 0 );
if ( ssd == NULL ) {
CREATE( ssd, struct player_data, 1 );
ssd->single_magic_resist = cap_value(*val, 0, 100);
addToMSD(*sd, ssd, 0, true);
}
else {
ssd->single_magic_resist = cap_value(*val + ssd->single_magic_resist, 0, 100);
}
hookStop();
}
return 0;
}
// flush bNoAreaMagic back to NULL when recalculating bonus
int status_calc_pc_pre(struct map_session_data** sd, enum e_status_calc_opt* opt) {
struct player_data* ssd = getFromMSD(*sd, 0);
if (ssd)
removeFromMSD(*sd, 0);
return 0;
}
int64 battle_calc_damage_post(int64 retVal___, struct block_list* src, struct block_list* bl, struct Damage* d, int64 damage, uint16 skill_id, uint16 skill_lv)
{
if (!damage || !bl || bl->type != BL_PC) return retVal___;
int flag = d->flag;
if (flag & BF_MAGIC) {
struct map_session_data* sd = BL_CAST(BL_PC, bl);
struct player_data* ssd = getFromMSD(sd, 0);
if (ssd && skill->get_casttype(skill_id) == CAST_DAMAGE && ssd->single_magic_resist != 0) {
retVal___ -= retVal___ * ssd->single_magic_resist / 100;
}
}
return retVal___;
}
HPExport void plugin_init (void) {
SINGLE_MAGIC_RESIST = map->get_new_bonus_id();
script->set_constant("bNoSingleMagic", SINGLE_MAGIC_RESIST, false, false );
addHookPre( pc, bonus, pc_bonus_pre);
addHookPost( battle, calc_damage, battle_calc_damage_post);
addHookPre(status, calc_pc_, status_calc_pc_pre);
}