summaryrefslogtreecommitdiff
path: root/src/emap
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2016-07-31 21:26:22 +0300
committerAndrei Karas <akaras@inbox.ru>2016-07-31 21:26:22 +0300
commit1e49a9dd41900d045c94ebfe34909fa9e4dba32f (patch)
treef521e38b69ea7409645c8b6ac18fc576d9aa74d8 /src/emap
parent48ce547ec3ead9228f81404c7abf4ee99dbe2819 (diff)
downloadevol-hercules-1e49a9dd41900d045c94ebfe34909fa9e4dba32f.tar.gz
evol-hercules-1e49a9dd41900d045c94ebfe34909fa9e4dba32f.tar.bz2
evol-hercules-1e49a9dd41900d045c94ebfe34909fa9e4dba32f.tar.xz
evol-hercules-1e49a9dd41900d045c94ebfe34909fa9e4dba32f.zip
Add into item_db.conf support for attribute AllowAmmo for bows.
This allow limit any arrow/ammo for any bows/guns.
Diffstat (limited to 'src/emap')
-rw-r--r--src/emap/battle.c54
-rw-r--r--src/emap/battle.h10
-rw-r--r--src/emap/data/itemd.c1
-rw-r--r--src/emap/init.c2
-rw-r--r--src/emap/itemdb.c17
-rw-r--r--src/emap/struct/itemdext.h1
6 files changed, 85 insertions, 0 deletions
diff --git a/src/emap/battle.c b/src/emap/battle.c
new file mode 100644
index 0000000..5b333fb
--- /dev/null
+++ b/src/emap/battle.c
@@ -0,0 +1,54 @@
+// Copyright (c) Copyright (c) Hercules Dev Team, licensed under GNU GPL.
+// Copyright (c) 2014 - 2015 Evol developers
+
+#include "common/hercules.h"
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include "common/HPMi.h"
+
+#include "map/itemdb.h"
+#include "map/pc.h"
+
+#include "emap/data/itemd.h"
+#include "emap/struct/itemdext.h"
+
+bool ebattle_check_arrows_post(bool retVal,
+ struct map_session_data *sd)
+{
+ if (retVal == true)
+ {
+ if (!sd)
+ return retVal;
+ const int ammoIndex = sd->equip_index[EQI_AMMO];
+ if (ammoIndex < 0)
+ return true;
+
+ const int ammoId = sd->inventory_data[ammoIndex]->nameid;
+ if (ammoId <= 0)
+ return true;
+
+ const int weaponIndex = sd->equip_index[EQI_HAND_L];
+
+ struct ItemdExt *data = itemd_get(sd->inventory_data[weaponIndex]);
+ if (!data)
+ return true;
+
+ const int sz = VECTOR_LENGTH(data->allowedAmmo);
+
+ if (sz == 0) // allow any ammo if AllowedAmmo list is empty
+ return true;
+
+ for (int f = 0; f < sz; f ++)
+ {
+ const int id = VECTOR_INDEX(data->allowedAmmo, f);
+ if (ammoId == id)
+ return true;
+ }
+ clif->arrow_fail(sd, 0);
+ return false;
+ }
+ return true;
+}
diff --git a/src/emap/battle.h b/src/emap/battle.h
new file mode 100644
index 0000000..7ab2db2
--- /dev/null
+++ b/src/emap/battle.h
@@ -0,0 +1,10 @@
+// Copyright (c) Copyright (c) Hercules Dev Team, licensed under GNU GPL.
+// Copyright (c) 2014 - 2015 Evol developers
+
+#ifndef EVOL_MAP_BATTLE
+#define EVOL_MAP_BATTLE
+
+bool ebattle_check_arrows_post(bool retVal,
+ struct map_session_data *sd);
+
+#endif // EVOL_MAP_BATTLE
diff --git a/src/emap/data/itemd.c b/src/emap/data/itemd.c
index d7817e5..e516bcd 100644
--- a/src/emap/data/itemd.c
+++ b/src/emap/data/itemd.c
@@ -72,6 +72,7 @@ struct ItemdExt *itemd_create(void)
data->takeScript = NULL;
data->insertScript = NULL;
VECTOR_INIT(data->allowedCards);
+ VECTOR_INIT(data->allowedAmmo);
data->subX = 8;
data->subY = 8;
return data;
diff --git a/src/emap/init.c b/src/emap/init.c
index df62add..33d5025 100644
--- a/src/emap/init.c
+++ b/src/emap/init.c
@@ -44,6 +44,7 @@
#include "ecommon/config.h"
#include "ecommon/init.h"
#include "emap/atcommand.h"
+#include "emap/battle.h"
#include "emap/battleground.h"
#include "emap/clif.h"
#include "emap/config.h"
@@ -262,6 +263,7 @@ HPExport void plugin_init (void)
addHookPre(status, set_viewdata, estatus_set_viewdata_pre);
addHookPre(homun, gainexp, ehomunculus_gainexp_pre);
+ addHookPost(battle, check_arrows, ebattle_check_arrows_post);
addHookPost(clif, addcards, eclif_addcards_post);
addHookPost(clif, addcards2, eclif_addcards2_post);
addHookPost(clif, getareachar_unit, eclif_getareachar_unit_post);
diff --git a/src/emap/itemdb.c b/src/emap/itemdb.c
index 3a90eab..63daca0 100644
--- a/src/emap/itemdb.c
+++ b/src/emap/itemdb.c
@@ -167,6 +167,23 @@ void eitemdb_readdb_additional_fields_pre(int *itemid,
}
}
+ group = libconfig->setting_get_member(it, "AllowAmmo");
+ if (group)
+ {
+ int idx = 0;
+ struct config_setting_t *it2 = NULL;
+ int cnt = VECTOR_LENGTH(data->allowedAmmo);
+ while ((it2 = libconfig->setting_get_elem(group, idx ++)))
+ {
+ const char *name = config_setting_name(it2);
+ if (name && strncmp(name, "id", 2) && strncmp(name, "Id", 2))
+ continue;
+ VECTOR_ENSURE(data->allowedAmmo, cnt + 1, 1);
+ VECTOR_PUSH(data->allowedAmmo, atoi(name + 2));
+ cnt ++;
+ }
+ }
+
hookStop();
}
diff --git a/src/emap/struct/itemdext.h b/src/emap/struct/itemdext.h
index 6a8d2c0..9a428ba 100644
--- a/src/emap/struct/itemdext.h
+++ b/src/emap/struct/itemdext.h
@@ -34,6 +34,7 @@ struct ItemdExt
int unequipEffect;
int unequipFailEffect;
+ VECTOR_DECL(int) allowedAmmo;
VECTOR_DECL(struct ItemCardExt) allowedCards;
struct script_code *dropScript;
struct script_code *takeScript;