diff options
author | Andrei Karas <akaras@inbox.ru> | 2016-07-31 21:26:22 +0300 |
---|---|---|
committer | Andrei Karas <akaras@inbox.ru> | 2016-07-31 21:26:22 +0300 |
commit | 1e49a9dd41900d045c94ebfe34909fa9e4dba32f (patch) | |
tree | f521e38b69ea7409645c8b6ac18fc576d9aa74d8 /src/emap/battle.c | |
parent | 48ce547ec3ead9228f81404c7abf4ee99dbe2819 (diff) | |
download | plugin-1e49a9dd41900d045c94ebfe34909fa9e4dba32f.tar.gz plugin-1e49a9dd41900d045c94ebfe34909fa9e4dba32f.tar.bz2 plugin-1e49a9dd41900d045c94ebfe34909fa9e4dba32f.tar.xz plugin-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/battle.c')
-rw-r--r-- | src/emap/battle.c | 54 |
1 files changed, 54 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; +} |