summaryrefslogtreecommitdiff
path: root/src/map/buyingstore.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/map/buyingstore.c')
-rw-r--r--src/map/buyingstore.c97
1 files changed, 58 insertions, 39 deletions
diff --git a/src/map/buyingstore.c b/src/map/buyingstore.c
index 8e3c21bd4..0b59e8f1e 100644
--- a/src/map/buyingstore.c
+++ b/src/map/buyingstore.c
@@ -1,5 +1,6 @@
-// Copyright (c) Athena Dev Teams - Licensed under GNU GPL
-// For more information, see LICENCE in the main folder
+// Copyright (c) Hercules Dev Team, licensed under GNU GPL.
+// See the LICENSE file
+// Portions Copyright (c) Athena Dev Teams
#include "../common/cbasetypes.h"
#include "../common/db.h" // ARR_FIND
@@ -9,9 +10,10 @@
#include "atcommand.h" // msg_txt
#include "battle.h" // battle_config.*
#include "buyingstore.h" // struct s_buyingstore
-#include "clif.h" // clif_buyingstore_*
+#include "clif.h" // clif->buyingstore_*
#include "log.h" // log_pick_pc, log_zeny
#include "pc.h" // struct map_session_data
+#include "chrif.h"
/// constants (client-side restrictions)
@@ -58,13 +60,13 @@ bool buyingstore_setup(struct map_session_data* sd, unsigned char slots)
if( map[sd->bl.m].flag.novending )
{// custom: no vending maps
- clif_displaymessage(sd->fd, msg_txt(276)); // "You can't open a shop on this map"
+ clif->message(sd->fd, msg_txt(276)); // "You can't open a shop on this map"
return false;
}
if( map_getcell(sd->bl.m, sd->bl.x, sd->bl.y, CELL_CHKNOVENDING) )
{// custom: no vending cells
- clif_displaymessage(sd->fd, msg_txt(204)); // "You can't open a shop on this cell."
+ clif->message(sd->fd, msg_txt(204)); // "You can't open a shop on this cell."
return false;
}
@@ -75,7 +77,7 @@ bool buyingstore_setup(struct map_session_data* sd, unsigned char slots)
}
sd->buyingstore.slots = slots;
- clif_buyingstore_open(sd);
+ clif->buyingstore_open(sd);
return true;
}
@@ -94,15 +96,15 @@ void buyingstore_create(struct map_session_data* sd, int zenylimit, unsigned cha
if( !battle_config.feature_buying_store || pc_istrading(sd) || sd->buyingstore.slots == 0 || count > sd->buyingstore.slots || zenylimit <= 0 || zenylimit > sd->status.zeny || !storename[0] )
{// disabled or invalid input
sd->buyingstore.slots = 0;
- clif_buyingstore_open_failed(sd, BUYINGSTORE_CREATE, 0);
+ clif->buyingstore_open_failed(sd, BUYINGSTORE_CREATE, 0);
return;
}
if( !pc_can_give_items(sd) )
{// custom: GM is not allowed to buy (give zeny)
sd->buyingstore.slots = 0;
- clif_displaymessage(sd->fd, msg_txt(246));
- clif_buyingstore_open_failed(sd, BUYINGSTORE_CREATE, 0);
+ clif->message(sd->fd, msg_txt(246));
+ clif->buyingstore_open_failed(sd, BUYINGSTORE_CREATE, 0);
return;
}
@@ -113,13 +115,13 @@ void buyingstore_create(struct map_session_data* sd, int zenylimit, unsigned cha
if( map[sd->bl.m].flag.novending )
{// custom: no vending maps
- clif_displaymessage(sd->fd, msg_txt(276)); // "You can't open a shop on this map"
+ clif->message(sd->fd, msg_txt(276)); // "You can't open a shop on this map"
return;
}
if( map_getcell(sd->bl.m, sd->bl.x, sd->bl.y, CELL_CHKNOVENDING) )
{// custom: no vending cells
- clif_displaymessage(sd->fd, msg_txt(204)); // "You can't open a shop on this cell."
+ clif->message(sd->fd, msg_txt(204)); // "You can't open a shop on this cell."
return;
}
@@ -174,14 +176,14 @@ void buyingstore_create(struct map_session_data* sd, int zenylimit, unsigned cha
if( i != count )
{// invalid item/amount/price
sd->buyingstore.slots = 0;
- clif_buyingstore_open_failed(sd, BUYINGSTORE_CREATE, 0);
+ clif->buyingstore_open_failed(sd, BUYINGSTORE_CREATE, 0);
return;
}
if( (sd->max_weight*90)/100 < weight )
{// not able to carry all wanted items without getting overweight (90%)
sd->buyingstore.slots = 0;
- clif_buyingstore_open_failed(sd, BUYINGSTORE_CREATE_OVERWEIGHT, weight);
+ clif->buyingstore_open_failed(sd, BUYINGSTORE_CREATE_OVERWEIGHT, weight);
return;
}
@@ -191,8 +193,8 @@ void buyingstore_create(struct map_session_data* sd, int zenylimit, unsigned cha
sd->buyingstore.zenylimit = zenylimit;
sd->buyingstore.slots = i; // store actual amount of items
safestrncpy(sd->message, storename, sizeof(sd->message));
- clif_buyingstore_myitemlist(sd);
- clif_buyingstore_entry(sd);
+ clif->buyingstore_myitemlist(sd);
+ clif->buyingstore_entry(sd);
}
@@ -205,7 +207,7 @@ void buyingstore_close(struct map_session_data* sd)
memset(&sd->buyingstore, 0, sizeof(sd->buyingstore));
// notify other players
- clif_buyingstore_disappear_entry(sd);
+ clif->buyingstore_disappear_entry(sd);
}
}
@@ -221,7 +223,7 @@ void buyingstore_open(struct map_session_data* sd, int account_id)
if( !pc_can_give_items(sd) )
{// custom: GM is not allowed to sell
- clif_displaymessage(sd->fd, msg_txt(246));
+ clif->message(sd->fd, msg_txt(246));
return;
}
@@ -230,13 +232,13 @@ void buyingstore_open(struct map_session_data* sd, int account_id)
return;
}
- if( !searchstore_queryremote(sd, account_id) && ( sd->bl.m != pl_sd->bl.m || !check_distance_bl(&sd->bl, &pl_sd->bl, AREA_SIZE) ) )
+ if( !searchstore->queryremote(sd, account_id) && ( sd->bl.m != pl_sd->bl.m || !check_distance_bl(&sd->bl, &pl_sd->bl, AREA_SIZE) ) )
{// out of view range
return;
}
// success
- clif_buyingstore_itemlist(sd, pl_sd);
+ clif->buyingstore_itemlist(sd, pl_sd);
}
@@ -253,30 +255,30 @@ void buyingstore_trade(struct map_session_data* sd, int account_id, unsigned int
if( !battle_config.feature_buying_store || pc_istrading(sd) )
{// not allowed to sell
- clif_buyingstore_trade_failed_seller(sd, BUYINGSTORE_TRADE_SELLER_FAILED, 0);
+ clif->buyingstore_trade_failed_seller(sd, BUYINGSTORE_TRADE_SELLER_FAILED, 0);
return;
}
if( !pc_can_give_items(sd) )
{// custom: GM is not allowed to sell
- clif_displaymessage(sd->fd, msg_txt(246));
- clif_buyingstore_trade_failed_seller(sd, BUYINGSTORE_TRADE_SELLER_FAILED, 0);
+ clif->message(sd->fd, msg_txt(246));
+ clif->buyingstore_trade_failed_seller(sd, BUYINGSTORE_TRADE_SELLER_FAILED, 0);
return;
}
if( ( pl_sd = map_id2sd(account_id) ) == NULL || !pl_sd->state.buyingstore || pl_sd->buyer_id != buyer_id )
{// not online, not buying or not same store
- clif_buyingstore_trade_failed_seller(sd, BUYINGSTORE_TRADE_SELLER_FAILED, 0);
+ clif->buyingstore_trade_failed_seller(sd, BUYINGSTORE_TRADE_SELLER_FAILED, 0);
return;
}
- if( !searchstore_queryremote(sd, account_id) && ( sd->bl.m != pl_sd->bl.m || !check_distance_bl(&sd->bl, &pl_sd->bl, AREA_SIZE) ) )
+ if( !searchstore->queryremote(sd, account_id) && ( sd->bl.m != pl_sd->bl.m || !check_distance_bl(&sd->bl, &pl_sd->bl, AREA_SIZE) ) )
{// out of view range
- clif_buyingstore_trade_failed_seller(sd, BUYINGSTORE_TRADE_SELLER_FAILED, 0);
+ clif->buyingstore_trade_failed_seller(sd, BUYINGSTORE_TRADE_SELLER_FAILED, 0);
return;
}
- searchstore_clearremote(sd);
+ searchstore->clearremote(sd);
if( pl_sd->status.zeny < pl_sd->buyingstore.zenylimit )
{// buyer lost zeny in the mean time? fix the limit
@@ -301,53 +303,53 @@ void buyingstore_trade(struct map_session_data* sd, int account_id, unsigned int
{// duplicate
ShowWarning("buyingstore_trade: Found duplicate item on selling list (prevnameid=%hu, prevamount=%hu, nameid=%hu, amount=%hu, account_id=%d, char_id=%d).\n",
RBUFW(itemlist,k*6+2), RBUFW(itemlist,k*6+4), nameid, amount, sd->status.account_id, sd->status.char_id);
- clif_buyingstore_trade_failed_seller(sd, BUYINGSTORE_TRADE_SELLER_FAILED, nameid);
+ clif->buyingstore_trade_failed_seller(sd, BUYINGSTORE_TRADE_SELLER_FAILED, nameid);
return;
}
}
if( index < 0 || index >= ARRAYLENGTH(sd->status.inventory) || sd->inventory_data[index] == NULL || sd->status.inventory[index].nameid != nameid || sd->status.inventory[index].amount < amount )
{// invalid input
- clif_buyingstore_trade_failed_seller(sd, BUYINGSTORE_TRADE_SELLER_FAILED, nameid);
+ clif->buyingstore_trade_failed_seller(sd, BUYINGSTORE_TRADE_SELLER_FAILED, nameid);
return;
}
if( sd->status.inventory[index].expire_time || !itemdb_cantrade(&sd->status.inventory[index], pc_get_group_level(sd), pc_get_group_level(pl_sd)) || memcmp(sd->status.inventory[index].card, buyingstore_blankslots, sizeof(buyingstore_blankslots)) )
{// non-tradable item
- clif_buyingstore_trade_failed_seller(sd, BUYINGSTORE_TRADE_SELLER_FAILED, nameid);
+ clif->buyingstore_trade_failed_seller(sd, BUYINGSTORE_TRADE_SELLER_FAILED, nameid);
return;
}
ARR_FIND( 0, pl_sd->buyingstore.slots, listidx, pl_sd->buyingstore.items[listidx].nameid == nameid );
if( listidx == pl_sd->buyingstore.slots || pl_sd->buyingstore.items[listidx].amount == 0 )
{// there is no such item or the buyer has already bought all of them
- clif_buyingstore_trade_failed_seller(sd, BUYINGSTORE_TRADE_SELLER_FAILED, nameid);
+ clif->buyingstore_trade_failed_seller(sd, BUYINGSTORE_TRADE_SELLER_FAILED, nameid);
return;
}
if( pl_sd->buyingstore.items[listidx].amount < amount )
{// buyer does not need that much of the item
- clif_buyingstore_trade_failed_seller(sd, BUYINGSTORE_TRADE_SELLER_COUNT, nameid);
+ clif->buyingstore_trade_failed_seller(sd, BUYINGSTORE_TRADE_SELLER_COUNT, nameid);
return;
}
if( pc_checkadditem(pl_sd, nameid, amount) == ADDITEM_OVERAMOUNT )
{// buyer does not have enough space for this item
- clif_buyingstore_trade_failed_seller(sd, BUYINGSTORE_TRADE_SELLER_FAILED, nameid);
+ clif->buyingstore_trade_failed_seller(sd, BUYINGSTORE_TRADE_SELLER_FAILED, nameid);
return;
}
if( amount*(unsigned int)sd->inventory_data[index]->weight > pl_sd->max_weight-weight )
{// normally this is not supposed to happen, as the total weight is
// checked upon creation, but the buyer could have gained items
- clif_buyingstore_trade_failed_seller(sd, BUYINGSTORE_TRADE_SELLER_FAILED, nameid);
+ clif->buyingstore_trade_failed_seller(sd, BUYINGSTORE_TRADE_SELLER_FAILED, nameid);
return;
}
weight+= amount*sd->inventory_data[index]->weight;
if( amount*pl_sd->buyingstore.items[listidx].price > pl_sd->buyingstore.zenylimit-zeny )
{// buyer does not have enough zeny
- clif_buyingstore_trade_failed_seller(sd, BUYINGSTORE_TRADE_SELLER_ZENY, nameid);
+ clif->buyingstore_trade_failed_seller(sd, BUYINGSTORE_TRADE_SELLER_ZENY, nameid);
return;
}
zeny+= amount*pl_sd->buyingstore.items[listidx].price;
@@ -377,19 +379,24 @@ void buyingstore_trade(struct map_session_data* sd, int account_id, unsigned int
pl_sd->buyingstore.zenylimit-= zeny;
// notify clients
- clif_buyingstore_delete_item(sd, index, amount, pl_sd->buyingstore.items[listidx].price);
- clif_buyingstore_update_item(pl_sd, nameid, amount);
+ clif->buyingstore_delete_item(sd, index, amount, pl_sd->buyingstore.items[listidx].price);
+ clif->buyingstore_update_item(pl_sd, nameid, amount);
}
+ if( save_settings&128 ) {
+ chrif_save(sd, 0);
+ chrif_save(pl_sd, 0);
+ }
+
// check whether or not there is still something to buy
ARR_FIND( 0, pl_sd->buyingstore.slots, i, pl_sd->buyingstore.items[i].amount != 0 );
if( i == pl_sd->buyingstore.slots )
{// everything was bought
- clif_buyingstore_trade_failed_buyer(pl_sd, BUYINGSTORE_TRADE_BUYER_NO_ITEMS);
+ clif->buyingstore_trade_failed_buyer(pl_sd, BUYINGSTORE_TRADE_BUYER_NO_ITEMS);
}
else if( pl_sd->buyingstore.zenylimit == 0 )
{// zeny limit reached
- clif_buyingstore_trade_failed_buyer(pl_sd, BUYINGSTORE_TRADE_BUYER_ZENY);
+ clif->buyingstore_trade_failed_buyer(pl_sd, BUYINGSTORE_TRADE_BUYER_ZENY);
}
else
{// continue buying
@@ -463,7 +470,7 @@ bool buyingstore_searchall(struct map_session_data* sd, const struct s_search_st
;
}
- if( !searchstore_result(s->search_sd, sd->buyer_id, sd->status.account_id, sd->message, it->nameid, it->amount, it->price, buyingstore_blankslots, 0) )
+ if( !searchstore->result(s->search_sd, sd->buyer_id, sd->status.account_id, sd->message, it->nameid, it->amount, it->price, buyingstore_blankslots, 0) )
{// result set full
return false;
}
@@ -471,3 +478,15 @@ bool buyingstore_searchall(struct map_session_data* sd, const struct s_search_st
return true;
}
+void buyingstore_defaults(void) {
+ buyingstore = &buyingstore_s;
+
+ buyingstore->setup = buyingstore_setup;
+ buyingstore->create = buyingstore_create;
+ buyingstore->close = buyingstore_close;
+ buyingstore->open = buyingstore_open;
+ buyingstore->trade = buyingstore_trade;
+ buyingstore->search = buyingstore_search;
+ buyingstore->searchall = buyingstore_searchall;
+
+}