summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/Makefile.am2
-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
7 files changed, 87 insertions, 0 deletions
diff --git a/src/Makefile.am b/src/Makefile.am
index ad8da26..7243854 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -32,6 +32,8 @@ LOGIN_SRC = elogin/config.c \
MAP_SRC = emap/atcommand.c \
emap/atcommand.h \
+ emap/battle.c \
+ emap/battle.h \
emap/battleground.c \
emap/battleground.h \
emap/clif.c \
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;