summaryrefslogtreecommitdiff
path: root/src/map
diff options
context:
space:
mode:
authorskotlex <skotlex@54d463be-8e91-2dee-dedb-b68131a5f0ec>2006-07-06 21:22:20 +0000
committerskotlex <skotlex@54d463be-8e91-2dee-dedb-b68131a5f0ec>2006-07-06 21:22:20 +0000
commit5b1d1678fd03d6c780e933f6e464e3b02a860c0d (patch)
tree65b746ac53e67d12d9958223e095697bb8f20123 /src/map
parent7afdfd0b4b60c52af9f4e488bb1208a426a5bddc (diff)
downloadhercules-5b1d1678fd03d6c780e933f6e464e3b02a860c0d.tar.gz
hercules-5b1d1678fd03d6c780e933f6e464e3b02a860c0d.tar.bz2
hercules-5b1d1678fd03d6c780e933f6e464e3b02a860c0d.tar.xz
hercules-5b1d1678fd03d6c780e933f6e464e3b02a860c0d.zip
- Rewrote all the item restriction functions so that they will take into account slotted card restrictions as well.
git-svn-id: https://rathena.svn.sourceforge.net/svnroot/rathena/trunk@7552 54d463be-8e91-2dee-dedb-b68131a5f0ec
Diffstat (limited to 'src/map')
-rw-r--r--src/map/clif.c2
-rw-r--r--src/map/itemdb.c43
-rw-r--r--src/map/itemdb.h22
-rw-r--r--src/map/pc.c8
-rw-r--r--src/map/pc.h2
-rw-r--r--src/map/script.c2
-rw-r--r--src/map/storage.c4
-rw-r--r--src/map/trade.c13
-rw-r--r--src/map/vending.c2
9 files changed, 62 insertions, 36 deletions
diff --git a/src/map/clif.c b/src/map/clif.c
index 5f2db6d12..522199539 100644
--- a/src/map/clif.c
+++ b/src/map/clif.c
@@ -1873,7 +1873,7 @@ int clif_selllist(struct map_session_data *sd) {
WFIFOW(fd,0)=0xc7;
for(i=0;i<MAX_INVENTORY;i++) {
if(sd->status.inventory[i].nameid > 0 && sd->inventory_data[i]) {
- if (!itemdb_cansell(sd->status.inventory[i].nameid, pc_isGM(sd)))
+ if (!itemdb_cansell(&sd->status.inventory[i], pc_isGM(sd)))
continue;
val=sd->inventory_data[i]->value_sell;
diff --git a/src/map/itemdb.c b/src/map/itemdb.c
index 80a58a520..669324532 100644
--- a/src/map/itemdb.c
+++ b/src/map/itemdb.c
@@ -289,48 +289,63 @@ static int itemdb_ispetequip(struct item_data *data)
* Trade Restriction functions [Skotlex]
*------------------------------------------
*/
-int itemdb_isdropable(int nameid, int gmlv)
+int itemdb_isdropable_sub(struct item_data *item, int gmlv, int unused)
{
- struct item_data* item = itemdb_exists(nameid);
return (item && (!(item->flag.trade_restriction&1) || gmlv >= item->gm_lv_trade_override));
}
-int itemdb_cantrade(int nameid, int gmlv, int gmlv2)
+int itemdb_cantrade_sub(struct item_data* item, int gmlv, int gmlv2)
{
- struct item_data* item = itemdb_exists(nameid);
return (item && (!(item->flag.trade_restriction&2) || gmlv >= item->gm_lv_trade_override || gmlv2 >= item->gm_lv_trade_override));
}
-int itemdb_canpartnertrade(int nameid, int gmlv, int gmlv2)
+int itemdb_canpartnertrade_sub(struct item_data* item, int gmlv, int gmlv2)
{
- struct item_data* item = itemdb_exists(nameid);
return (item && (item->flag.trade_restriction&4 || gmlv >= item->gm_lv_trade_override || gmlv2 >= item->gm_lv_trade_override));
}
-int itemdb_cansell(int nameid, int gmlv)
+int itemdb_cansell_sub(struct item_data* item, int gmlv, int unused)
{
- struct item_data* item = itemdb_exists(nameid);
return (item && (!(item->flag.trade_restriction&8) || gmlv >= item->gm_lv_trade_override));
}
-int itemdb_cancartstore(int nameid, int gmlv)
+int itemdb_cancartstore_sub(struct item_data* item, int gmlv, int unused)
{
- struct item_data* item = itemdb_exists(nameid);
return (item && (!(item->flag.trade_restriction&16) || gmlv >= item->gm_lv_trade_override));
}
-int itemdb_canstore(int nameid, int gmlv)
+int itemdb_canstore_sub(struct item_data* item, int gmlv, int unused)
{
- struct item_data* item = itemdb_exists(nameid);
return (item && (!(item->flag.trade_restriction&32) || gmlv >= item->gm_lv_trade_override));
}
-int itemdb_canguildstore(int nameid, int gmlv)
+int itemdb_canguildstore_sub(struct item_data* item, int gmlv, int unused)
{
- struct item_data* item = itemdb_exists(nameid);
return (item && (!(item->flag.trade_restriction&64) || gmlv >= item->gm_lv_trade_override));
}
+int itemdb_isrestricted(struct item* item, int gmlv, int gmlv2, int (*func)(struct item_data*, int, int))
+{
+ struct item_data* item_data = itemdb_search(item->nameid);
+ int i;
+
+ if (!func(item_data, gmlv, gmlv2))
+ return 0;
+
+ if(item_data->slot == 0 ||
+ item->card[0] ==(short)0xff00 ||
+ item->card[0]==0x00ff ||
+ item->card[0]==0x00fe)
+ return 1;
+
+ for(i = 0; i < item_data->slot; i++) {
+ if (!item->card[i]) continue;
+ if (!func(itemdb_search(item->card[i]), gmlv, gmlv2))
+ return 0;
+ }
+ return 1;
+}
+
/*==========================================
*
*------------------------------------------
diff --git a/src/map/itemdb.h b/src/map/itemdb.h
index fd3c5191f..a9b74b0ca 100644
--- a/src/map/itemdb.h
+++ b/src/map/itemdb.h
@@ -88,13 +88,21 @@ int itemdb_searchrandomid(int flags);
#define itemdb_value_notoc(n) itemdb_search(n)->flag.value_notoc
#define itemdb_canrefine(n) itemdb_search(n)->flag.no_refine
//Item trade restrictions [Skotlex]
-int itemdb_isdropable(int nameid, int gmlv);
-int itemdb_cantrade(int nameid, int gmlv, int gmlv2);
-int itemdb_cansell(int nameid, int gmlv);
-int itemdb_canstore(int nameid, int gmlv);
-int itemdb_canguildstore(int nameid, int gmlv);
-int itemdb_cancartstore(int nameid, int gmlv);
-int itemdb_canpartnertrade(int nameid, int gmlv, int gmlv2);
+int itemdb_isdropable_sub(struct item_data *, int, int);
+int itemdb_cantrade_sub(struct item_data*, int, int);
+int itemdb_canpartnertrade_sub(struct item_data*, int, int);
+int itemdb_cansell_sub(struct item_data*,int, int);
+int itemdb_cancartstore_sub(struct item_data*, int, int);
+int itemdb_canstore_sub(struct item_data*, int, int);
+int itemdb_canguildstore_sub(struct item_data*, int, int);
+int itemdb_isrestricted(struct item* item, int gmlv, int gmlv2, int (*func)(struct item_data*, int, int));
+#define itemdb_isdropable(item, gmlv) itemdb_isrestricted(item, gmlv, 0, itemdb_isdropable_sub)
+#define itemdb_cantrade(item, gmlv, gmlv2) itemdb_isrestricted(item, gmlv, gmlv2, itemdb_cantrade_sub)
+#define itemdb_canpartnertrade(item, gmlv, gmlv2) itemdb_isrestricted(item, gmlv, gmlv2, itemdb_canpartnertrade_sub)
+#define itemdb_cansell(item, gmlv) itemdb_isrestricted(item, gmlv, 0, itemdb_cansell_sub)
+#define itemdb_cancartstore(item, gmlv) itemdb_isrestricted(item, gmlv, 0, itemdb_cancartstore_sub)
+#define itemdb_canstore(item, gmlv) itemdb_isrestricted(item, gmlv, 0, itemdb_canstore_sub)
+#define itemdb_canguildstore(item, gmlv) itemdb_isrestricted(item , gmlv, 0, itemdb_canguildstore_sub)
int itemdb_isequip(int);
int itemdb_isequip2(struct item_data *);
diff --git a/src/map/pc.c b/src/map/pc.c
index f965fb6e3..4604ef41c 100644
--- a/src/map/pc.c
+++ b/src/map/pc.c
@@ -2672,7 +2672,7 @@ int pc_dropitem(struct map_session_data *sd,int n,int amount)
return 0; //Can't drop items in nodrop mapflag maps.
}
- if (!pc_candrop(sd,sd->status.inventory[n].nameid)) {
+ if (!pc_candrop(sd,&sd->status.inventory[n])) {
clif_displaymessage (sd->fd, msg_txt(263));
return 0;
}
@@ -2914,7 +2914,7 @@ int pc_cart_additem(struct map_session_data *sd,struct item *item_data,int amoun
return 1;
data = itemdb_search(item_data->nameid);
- if(!itemdb_cancartstore(item_data->nameid, pc_isGM(sd)))
+ if(!itemdb_cancartstore(item_data, pc_isGM(sd)))
{ //Check item trade restrictions [Skotlex]
clif_displaymessage (sd->fd, msg_txt(264));
return 1;
@@ -5645,12 +5645,12 @@ int pc_setriding(struct map_session_data *sd)
* アイテムドロップ可不可判定
*------------------------------------------
*/
-int pc_candrop(struct map_session_data *sd,int item_id)
+int pc_candrop(struct map_session_data *sd,struct item *item)
{
int level = pc_isGM(sd);
if ( pc_can_give_items(level) ) //check if this GM level can drop items
return 0;
- return (itemdb_isdropable(item_id, level));
+ return (itemdb_isdropable(item, level));
}
/*==========================================
diff --git a/src/map/pc.h b/src/map/pc.h
index 6cfb9f532..b6d34a873 100644
--- a/src/map/pc.h
+++ b/src/map/pc.h
@@ -246,7 +246,7 @@ struct map_session_data *pc_get_child(struct map_session_data *sd);
int pc_set_gm_level(int account_id, int level);
void pc_setstand(struct map_session_data *sd);
-int pc_candrop(struct map_session_data *sd,int item_id);
+int pc_candrop(struct map_session_data *sd,struct item *item);
int pc_jobid2mapid(unsigned short b_class); // Skotlex
int pc_mapid2jobid(unsigned short class_, int sex); // Skotlex
diff --git a/src/map/script.c b/src/map/script.c
index 9244c00d3..22cd3c8a0 100644
--- a/src/map/script.c
+++ b/src/map/script.c
@@ -3959,7 +3959,7 @@ int buildin_getitem(struct script_state *st)
return 0;
if((flag = pc_additem(sd,&item_tmp,amount))) {
clif_additem(sd,0,0,flag);
- if(pc_candrop(sd,nameid))
+ if (pc_candrop(sd, &item_tmp))
map_addflooritem(&item_tmp,amount,sd->bl.m,sd->bl.x,sd->bl.y,NULL,NULL,NULL,0);
}
diff --git a/src/map/storage.c b/src/map/storage.c
index 29b48527d..0a54f0dde 100644
--- a/src/map/storage.c
+++ b/src/map/storage.c
@@ -168,7 +168,7 @@ static int storage_additem(struct map_session_data *sd,struct storage *stor,stru
data = itemdb_search(item_data->nameid);
- if (!itemdb_canstore(item_data->nameid, pc_isGM(sd)))
+ if (!itemdb_canstore(item_data, pc_isGM(sd)))
{ //Check if item is storable. [Skotlex]
clif_displaymessage (sd->fd, msg_txt(264));
return 1;
@@ -517,7 +517,7 @@ int guild_storage_additem(struct map_session_data *sd,struct guild_storage *stor
if(item_data->nameid <= 0 || amount <= 0)
return 1;
- if (!itemdb_canguildstore(item_data->nameid, pc_isGM(sd)))
+ if (!itemdb_canguildstore(item_data, pc_isGM(sd)))
{ //Check if item is storable. [Skotlex]
clif_displaymessage (sd->fd, msg_txt(264));
return 1;
diff --git a/src/map/trade.c b/src/map/trade.c
index b9c142332..04d4c83e5 100644
--- a/src/map/trade.c
+++ b/src/map/trade.c
@@ -294,7 +294,8 @@ int trade_check(struct map_session_data *sd, struct map_session_data *tsd) {
*/
void trade_tradeadditem(struct map_session_data *sd, int index, int amount) {
struct map_session_data *target_sd;
- int trade_i, trade_weight, nameid;
+ struct item *item;
+ int trade_i, trade_weight;
nullpo_retv(sd);
if (!sd->state.trading || sd->state.deal_locked > 0)
@@ -324,10 +325,12 @@ void trade_tradeadditem(struct map_session_data *sd, int index, int amount) {
if (amount < 0 || amount > sd->status.inventory[index].amount)
return;
- nameid = sd->inventory_data[index]->nameid;
-
- if (!itemdb_cantrade(nameid, pc_isGM(sd), pc_isGM(target_sd)) && //Can't trade
- (pc_get_partner(sd) != target_sd || !itemdb_canpartnertrade(nameid, pc_isGM(sd), pc_isGM(target_sd)))) //Can't partner-trade
+ item = &sd->status.inventory[index];
+ trade_i = pc_isGM(sd); //Recycling the variables to check for trad restrict.
+ trade_weight = pc_isGM(target_sd);
+ if (!itemdb_cantrade(item, trade_i, trade_weight) && //Can't trade
+ (pc_get_partner(sd) != target_sd ||
+ !itemdb_canpartnertrade(item, trade_i, trade_weight))) //Can't partner-trade
{
clif_displaymessage (sd->fd, msg_txt(260));
return;
diff --git a/src/map/vending.c b/src/map/vending.c
index 6d26ef518..073a21303 100644
--- a/src/map/vending.c
+++ b/src/map/vending.c
@@ -231,7 +231,7 @@ void vending_openvending(struct map_session_data *sd,int len,char *message,int f
for(i = 0, j = 0; (85 + 8 * j < len) && (i < MAX_VENDING); i++, j++) {
sd->vending[i].index = *(short*)(p+8*j)-2;
if (sd->vending[i].index < 0 || sd->vending[i].index >= MAX_CART ||
- !itemdb_cantrade(sd->status.cart[sd->vending[i].index].nameid, pc_isGM(sd), pc_isGM(sd)))
+ !itemdb_cantrade(&sd->status.cart[sd->vending[i].index], pc_isGM(sd), pc_isGM(sd)))
{
i--; //Preserve the vending index, skip to the next item.
continue;