summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2015-08-14 17:58:29 +0300
committerAndrei Karas <akaras@inbox.ru>2015-08-14 17:58:29 +0300
commit2ed4142dfcde097648857f41f8064b0a19c350c7 (patch)
tree5777014a74b30081ac39cda28ea9c64280cbebb5 /src
parentf8b3342f690816022d26038389431002e9cf3648 (diff)
downloadevol-hercules-2ed4142dfcde097648857f41f8064b0a19c350c7.tar.gz
evol-hercules-2ed4142dfcde097648857f41f8064b0a19c350c7.tar.bz2
evol-hercules-2ed4142dfcde097648857f41f8064b0a19c350c7.tar.xz
evol-hercules-2ed4142dfcde097648857f41f8064b0a19c350c7.zip
Add basic support for charm items (If item present in inventory it give own bonuses)
For char item in items.conf need add attribute "Charm: true"
Diffstat (limited to 'src')
-rw-r--r--src/emap/data/itemd.c1
-rw-r--r--src/emap/init.c4
-rw-r--r--src/emap/itemdb.c2
-rw-r--r--src/emap/pc.c56
-rw-r--r--src/emap/pc.h12
-rw-r--r--src/emap/status.c41
-rw-r--r--src/emap/status.h1
-rw-r--r--src/emap/struct/itemdext.h1
8 files changed, 118 insertions, 0 deletions
diff --git a/src/emap/data/itemd.c b/src/emap/data/itemd.c
index 4b171b2..e7af7f2 100644
--- a/src/emap/data/itemd.c
+++ b/src/emap/data/itemd.c
@@ -64,5 +64,6 @@ struct ItemdExt *itemd_create(void)
data->useFailEffect = -1;
data->unequipEffect = -1;
data->unequipFailEffect = -1;
+ data->charmItem = false;
return data;
}
diff --git a/src/emap/init.c b/src/emap/init.c
index 31a7cfc..32a8859 100644
--- a/src/emap/init.c
+++ b/src/emap/init.c
@@ -138,6 +138,7 @@ HPExport void plugin_init (void)
addHookPre("pc->takeitem", epc_takeitem);
addHookPre("pc->validate_levels", epc_validate_levels);
addHookPre("pc->check_job_name", epc_check_job_name);
+ addHookPre("pc->delitem", epc_delitem_pre);
addHookPre("mob->deleteslave_sub", emob_deleteslave_sub);
addHookPre("npc->parse_unknown_mapflag", enpc_parse_unknown_mapflag);
addHookPre("npc->buysellsel", enpc_buysellsel);
@@ -155,6 +156,7 @@ HPExport void plugin_init (void)
addHookPre("unit->can_move", eunit_can_move);
addHookPre("unit->walktoxy", eunit_walktoxy);
addHookPre("mail->invalid_operation", email_invalid_operation);
+ addHookPre("status->calc_pc_additional", estatus_calc_pc_additional);
addHookPost("clif->getareachar_unit", eclif_getareachar_unit_post);
addHookPost("clif->authok", eclif_authok_post);
@@ -167,12 +169,14 @@ HPExport void plugin_init (void)
addHookPost("clif->move", eclif_move);
addHookPost("map->addflooritem", emap_addflooritem_post);
addHookPost("skill->check_condition_castend", eskill_check_condition_castend_post);
+ addHookPost("pc->additem", epc_additem_post);
addHookPost("pc->isequip", epc_isuseequip_post);
addHookPost("pc->isUseitem", epc_isuseequip_post);
addHookPost("pc->useitem", epc_useitem_post);
addHookPost("pc->equipitem", epc_equipitem_post);
addHookPost("pc->unequipitem", epc_unequipitem_post);
addHookPost("pc->setnewpc", epc_setnewpc);
+ addHookPost("pc->delitem", epc_delitem_post);
langScriptId = script->add_str("Lang");
}
diff --git a/src/emap/itemdb.c b/src/emap/itemdb.c
index 34905a9..54003ba 100644
--- a/src/emap/itemdb.c
+++ b/src/emap/itemdb.c
@@ -78,6 +78,8 @@ void eitemdb_readdb_additional_fields(int *itemid,
data->requiredDef = i32;
if (libconfig->setting_lookup_int(it, "RequiredMDef", &i32) && i32 >= 0)
data->requiredMDef = i32;
+ if (libconfig->setting_lookup_bool(it, "Charm", &i32) && i32 >= 0)
+ data->charmItem = i32 ? true : false;
if (itemdb->lookup_const(it, "UseEffect", &i32))
data->useEffect = i32;
diff --git a/src/emap/pc.c b/src/emap/pc.c
index 96bc074..c0957d9 100644
--- a/src/emap/pc.c
+++ b/src/emap/pc.c
@@ -361,3 +361,59 @@ int epc_setnewpc(int retVal, struct map_session_data *sd,
}
return retVal;
}
+
+int epc_additem_post(int retVal, struct map_session_data *sd,
+ struct item *item_data,
+ int *amountPtr __attribute__ ((unused)),
+ e_log_pick_type *log_type __attribute__ ((unused)))
+{
+ if (!retVal)
+ {
+ struct ItemdExt *data = itemd_get_by_item(item_data);
+ if (data && data->charmItem)
+ status_calc_pc(sd, SCO_NONE);
+ }
+ return retVal;
+}
+
+static bool calcPc = false;
+
+int epc_delitem_pre(struct map_session_data *sd,
+ int *nPtr, int *amountPtr,
+ int *typePtr __attribute__ ((unused)),
+ short *reasonPtr __attribute__ ((unused)),
+ e_log_pick_type *log_type __attribute__ ((unused)))
+{
+ if (!sd)
+ return 1;
+ const int n = *nPtr;
+ const int amount = *amountPtr;
+
+ if (sd->status.inventory[n].nameid == 0 ||
+ amount <= 0 ||
+ sd->status.inventory[n].amount < amount ||
+ sd->inventory_data[n] == NULL)
+ {
+ return 1;
+ }
+
+ struct ItemdExt *data = itemd_get(sd->inventory_data[n]);
+ if (data && data->charmItem)
+ calcPc = true;
+
+ return 0;
+}
+
+int epc_delitem_post(int retVal,
+ struct map_session_data *sd,
+ int *nPtr __attribute__ ((unused)),
+ int *amountPtr __attribute__ ((unused)),
+ int *typePtr __attribute__ ((unused)),
+ short *reasonPtr __attribute__ ((unused)),
+ e_log_pick_type *log_type __attribute__ ((unused)))
+{
+ if (!retVal && calcPc && sd)
+ status_calc_pc(sd, SCO_NONE);
+ calcPc = false;
+ return retVal;
+}
diff --git a/src/emap/pc.h b/src/emap/pc.h
index 388c606..7250de6 100644
--- a/src/emap/pc.h
+++ b/src/emap/pc.h
@@ -39,4 +39,16 @@ int epc_setnewpc(int retVal, struct map_session_data *sd,
int *account_id, int *char_id, int *login_id1,
unsigned int *client_tick, int *sex, int *fd);
+int epc_additem_post(int retVal, struct map_session_data *sd,
+ struct item *item_data, int *amountPtr,
+ e_log_pick_type *log_type);
+
+int epc_delitem_pre(struct map_session_data *sd, int *nPtr, int *amountPtr,
+ int *typePtr, short *reasonPtr,
+ e_log_pick_type *log_type);
+
+int epc_delitem_post(int retVal, struct map_session_data *sd, int *nPtr, int *amountPtr,
+ int *typePtr, short *reasonPtr,
+ e_log_pick_type *log_type);
+
#endif // EVOL_MAP_PC
diff --git a/src/emap/status.c b/src/emap/status.c
index 6f853d5..912a96c 100644
--- a/src/emap/status.c
+++ b/src/emap/status.c
@@ -16,7 +16,9 @@
#include "map/pc.h"
#include "map/status.h"
+#include "emap/data/itemd.h"
#include "emap/data/npcd.h"
+#include "emap/struct/itemdext.h"
#include "emap/struct/npcdext.h"
int class_move_speed[CLASS_COUNT];
@@ -68,3 +70,42 @@ int estatus_calc_pc_(int retVal,
}
return retVal;
}
+
+int estatus_calc_pc_additional(struct map_session_data* sd,
+ enum e_status_calc_opt *opt __attribute__ ((unused)))
+{
+ hookStop();
+
+ for (int f = 0; f < MAX_INVENTORY; f ++)
+ {
+ struct item_data *const item = sd->inventory_data[f];
+ if (!item)
+ continue;
+
+ struct ItemdExt *data = itemd_get(item);
+ if (!data || !data->charmItem)
+ continue;
+
+ int k;
+ for (k = 0; k < map->list[sd->bl.m].zone->disabled_items_count; k ++)
+ {
+ if (map->list[sd->bl.m].zone->disabled_items[k] == item->nameid)
+ break;
+ }
+
+ if (k < map->list[sd->bl.m].zone->disabled_items_count)
+ continue;
+
+ if (!pc->isequip(sd, f))
+ continue;
+
+
+ struct status_data *bstatus = &sd->base_status;
+ bstatus->def += item->def;
+
+ script->run_use_script(sd, item, 0);
+
+ // here can be refine bonuses
+ }
+ return 0;
+}
diff --git a/src/emap/status.h b/src/emap/status.h
index fb0198b..a1eacf8 100644
--- a/src/emap/status.h
+++ b/src/emap/status.h
@@ -8,5 +8,6 @@ void status_init(void);
void estatus_set_viewdata_post(struct block_list *bl, int *class_);
void estatus_read_job_db_sub(int *idxPtr, const char *name, config_setting_t *jdb);
int estatus_calc_pc_(int retVal, struct map_session_data* sd, enum e_status_calc_opt *opt);
+int estatus_calc_pc_additional(struct map_session_data* sd, enum e_status_calc_opt *opt);
#endif // EVOL_MAP_STATUS
diff --git a/src/emap/struct/itemdext.h b/src/emap/struct/itemdext.h
index 8d4a555..0144fbe 100644
--- a/src/emap/struct/itemdext.h
+++ b/src/emap/struct/itemdext.h
@@ -28,6 +28,7 @@ struct ItemdExt
int unequipFailEffect;
bool allowPickup;
+ bool charmItem;
};
#endif // EVOL_MAP_ITEMDEXT