summaryrefslogtreecommitdiff
path: root/src/map/vending.c
diff options
context:
space:
mode:
authorai4rei <ai4rei@54d463be-8e91-2dee-dedb-b68131a5f0ec>2011-03-06 19:16:09 +0000
committerai4rei <ai4rei@54d463be-8e91-2dee-dedb-b68131a5f0ec>2011-03-06 19:16:09 +0000
commitc7a8f268c8110899f374cd367afaa564d47ff691 (patch)
tree2330fd66b29e75dbfdcaaae976a67859f7908019 /src/map/vending.c
parentcc77964c3e6134a6b2257501fd1b79c4330af4ea (diff)
downloadhercules-c7a8f268c8110899f374cd367afaa564d47ff691.tar.gz
hercules-c7a8f268c8110899f374cd367afaa564d47ff691.tar.bz2
hercules-c7a8f268c8110899f374cd367afaa564d47ff691.tar.xz
hercules-c7a8f268c8110899f374cd367afaa564d47ff691.zip
* Implemented search store info system (aka. vending and buying store search) together with related items.
- Requires 2010-08-03aRagexeRE or later and can be disabled in 'conf/battle/feature.conf'. git-svn-id: https://rathena.svn.sourceforge.net/svnroot/rathena/trunk@14732 54d463be-8e91-2dee-dedb-b68131a5f0ec
Diffstat (limited to 'src/map/vending.c')
-rw-r--r--src/map/vending.c90
1 files changed, 89 insertions, 1 deletions
diff --git a/src/map/vending.c b/src/map/vending.c
index a47be9057..08e15d733 100644
--- a/src/map/vending.c
+++ b/src/map/vending.c
@@ -87,8 +87,11 @@ void vending_purchasereq(struct map_session_data* sd, int aid, int uid, const ui
return;
}
- if( sd->bl.m != vsd->bl.m || !check_distance_bl(&sd->bl, &vsd->bl, AREA_SIZE) )
+ if( !searchstore_queryremote(sd, aid) && ( sd->bl.m != vsd->bl.m || !check_distance_bl(&sd->bl, &vsd->bl, AREA_SIZE) ) )
return; // shop too far away
+
+ searchstore_clearremote(sd);
+
if( count < 1 || count > MAX_VENDING || count > vsd->vend_num )
return; // invalid amount of purchased items
@@ -314,3 +317,88 @@ void vending_openvending(struct map_session_data* sd, const char* message, bool
clif_openvending(sd,sd->bl.id,sd->vending);
clif_showvendingboard(&sd->bl,message,0);
}
+
+
+/// Checks if an item is being sold in given player's vending.
+bool vending_search(struct map_session_data* sd, unsigned short nameid)
+{
+ int i;
+
+ if( !sd->vender_id )
+ {// not vending
+ return false;
+ }
+
+ ARR_FIND( 0, sd->vend_num, i, sd->status.cart[sd->vending[i].index].nameid == (short)nameid );
+ if( i == sd->vend_num )
+ {// not found
+ return false;
+ }
+
+ return true;
+}
+
+
+/// Searches for all items in a vending, that match given ids, price and possible cards.
+/// @return Whether or not the search should be continued.
+bool vending_searchall(struct map_session_data* sd, const struct s_search_store_search* s)
+{
+ int i, c, slot;
+ unsigned int idx, cidx;
+ struct item* it;
+
+ if( !sd->vender_id )
+ {// not vending
+ return true;
+ }
+
+ for( idx = 0; idx < s->item_count; idx++ )
+ {
+ ARR_FIND( 0, sd->vend_num, i, sd->status.cart[sd->vending[i].index].nameid == (short)s->itemlist[idx] );
+ if( i == sd->vend_num )
+ {// not found
+ continue;
+ }
+ it = &sd->status.cart[sd->vending[i].index];
+
+ if( s->min_price && s->min_price > sd->vending[i].value )
+ {// too low price
+ continue;
+ }
+
+ if( s->max_price && s->max_price < sd->vending[i].value )
+ {// too high price
+ continue;
+ }
+
+ if( s->card_count )
+ {// check cards
+ if( itemdb_isspecial(it->card[0]) )
+ {// something, that is not a carded
+ continue;
+ }
+ slot = itemdb_slot(it->nameid);
+
+ for( c = 0; c < slot && it->card[c]; c ++ )
+ {
+ ARR_FIND( 0, s->card_count, cidx, s->cardlist[cidx] == it->card[c] );
+ if( cidx != s->card_count )
+ {// found
+ break;
+ }
+ }
+
+ if( c == slot || !it->card[c] )
+ {// no card match
+ continue;
+ }
+ }
+
+ if( !searchstore_result(s->search_sd, sd->vender_id, sd->status.account_id, sd->message, it->nameid, sd->vending[i].amount, sd->vending[i].value, it->card, it->refine) )
+ {// result set full
+ return false;
+ }
+ }
+
+ return true;
+}