diff options
Diffstat (limited to 'src/map/vending.c')
-rw-r--r-- | src/map/vending.c | 66 |
1 files changed, 40 insertions, 26 deletions
diff --git a/src/map/vending.c b/src/map/vending.c index 6e74e6c3e..9a9585d2f 100644 --- a/src/map/vending.c +++ b/src/map/vending.c @@ -2,7 +2,7 @@ * This file is part of Hercules. * http://herc.ws - http://github.com/HerculesWS/Hercules * - * Copyright (C) 2012-2015 Hercules Dev Team + * Copyright (C) 2012-2016 Hercules Dev Team * Copyright (C) Athena Dev Teams * * Hercules is free software: you can redistribute it and/or modify @@ -44,14 +44,16 @@ struct vending_interface vending_s; struct vending_interface *vending; /// Returns an unique vending shop id. -static inline unsigned int getid(void) { +static inline unsigned int getid(void) +{ return vending->next_id++; } /*========================================== * Close shop *------------------------------------------*/ -void vending_closevending(struct map_session_data* sd) { +void vending_closevending(struct map_session_data* sd) +{ nullpo_retv(sd); if( sd->state.vending ) { @@ -64,7 +66,8 @@ void vending_closevending(struct map_session_data* sd) { /*========================================== * Request a shop's item list *------------------------------------------*/ -void vending_vendinglistreq(struct map_session_data* sd, unsigned int id) { +void vending_vendinglistreq(struct map_session_data* sd, unsigned int id) +{ struct map_session_data* vsd; nullpo_retv(sd); @@ -74,8 +77,7 @@ void vending_vendinglistreq(struct map_session_data* sd, unsigned int id) { return; // not vending if (!pc_can_give_items(sd) || !pc_can_give_items(vsd)) { //check if both GMs are allowed to trade - // GM is not allowed to trade - clif->message(sd->fd, msg_sd(sd,246)); + clif->message(sd->fd, msg_sd(sd,246)); // Your GM level doesn't authorize you to perform this action. return; } @@ -87,13 +89,15 @@ void vending_vendinglistreq(struct map_session_data* sd, unsigned int id) { /*========================================== * Purchase item(s) from a shop *------------------------------------------*/ -void vending_purchasereq(struct map_session_data* sd, int aid, unsigned int uid, const uint8* data, int count) { +void vending_purchasereq(struct map_session_data* sd, int aid, unsigned int uid, const uint8* data, int count) +{ int i, j, cursor, w, new_ = 0, blank, vend_list[MAX_VENDING]; int64 z; struct s_vending vend[MAX_VENDING]; // against duplicate packets struct map_session_data* vsd = map->id2sd(aid); nullpo_retv(sd); + nullpo_retv(data); if( vsd == NULL || !vsd->state.vending || vsd->bl.id == sd->bl.id ) return; // invalid shop @@ -118,9 +122,9 @@ void vending_purchasereq(struct map_session_data* sd, int aid, unsigned int uid, // some checks z = 0; // zeny counter w = 0; // weight counter - for( i = 0; i < count; i++ ) { - short amount = *(uint16*)(data + 4*i + 0); - short idx = *(uint16*)(data + 4*i + 2); + for (i = 0; i < count; i++) { + short amount = *(const uint16*)(data + 4*i + 0); + short idx = *(const uint16*)(data + 4*i + 2); idx -= 2; if( amount <= 0 ) @@ -184,22 +188,22 @@ void vending_purchasereq(struct map_session_data* sd, int aid, unsigned int uid, z -= apply_percentrate64(z, battle_config.vending_tax, 10000); pc->getzeny(vsd, (int)z, LOG_TYPE_VENDING, sd); - for( i = 0; i < count; i++ ) { - short amount = *(uint16*)(data + 4*i + 0); - short idx = *(uint16*)(data + 4*i + 2); + for (i = 0; i < count; i++) { + short amount = *(const uint16*)(data + 4*i + 0); + short idx = *(const uint16*)(data + 4*i + 2); idx -= 2; // vending item pc->additem(sd, &vsd->status.cart[idx], amount, LOG_TYPE_VENDING); vsd->vending[vend_list[i]].amount -= amount; + clif->vendingreport(vsd, idx, amount, sd->status.char_id, (int)z); pc->cart_delitem(vsd, idx, amount, 0, LOG_TYPE_VENDING); - clif->vendingreport(vsd, idx, amount); //print buyer's name if( battle_config.buyer_name ) { char temp[256]; sprintf(temp, msg_sd(vsd,265), sd->status.name); - clif_disp_onlyself(vsd,temp,strlen(temp)); + clif_disp_onlyself(vsd, temp); } } @@ -241,7 +245,8 @@ void vending_purchasereq(struct map_session_data* sd, int aid, unsigned int uid, * Open shop * data := {<index>.w <amount>.w <value>.l}[count] *------------------------------------------*/ -void vending_openvending(struct map_session_data* sd, const char* message, const uint8* data, int count) { +void vending_openvending(struct map_session_data* sd, const char* message, const uint8* data, int count) +{ int i, j; int vending_skill_lvl; nullpo_retv(sd); @@ -265,10 +270,10 @@ void vending_openvending(struct map_session_data* sd, const char* message, const // filter out invalid items i = 0; - for( j = 0; j < count; j++ ) { - short index = *(uint16*)(data + 8*j + 0); - short amount = *(uint16*)(data + 8*j + 2); - unsigned int value = *(uint32*)(data + 8*j + 4); + for (j = 0; j < count; j++) { + short index = *(const uint16*)(data + 8*j + 0); + short amount = *(const uint16*)(data + 8*j + 2); + unsigned int value = *(const uint32*)(data + 8*j + 4); index -= 2; // offset adjustment (client says that the first cart position is 2) @@ -276,7 +281,7 @@ void vending_openvending(struct map_session_data* sd, const char* message, const || pc->cartitem_amount(sd, index, amount) < 0 // invalid item or insufficient quantity //NOTE: official server does not do any of the following checks! || !sd->status.cart[index].identify // unidentified item - || sd->status.cart[index].attribute == 1 // broken item + || (sd->status.cart[index].attribute & ATTR_BROKEN) != 0 // broken item || sd->status.cart[index].expire_time // It should not be in the cart but just in case || (sd->status.cart[index].bound && !pc_can_give_bound_items(sd)) // can't trade bound items w/o permission || !itemdb_cantrade(&sd->status.cart[index], pc_get_group_level(sd), pc_get_group_level(sd)) ) // untradeable item @@ -310,9 +315,11 @@ void vending_openvending(struct map_session_data* sd, const char* message, const /// Checks if an item is being sold in given player's vending. -bool vending_search(struct map_session_data* sd, unsigned short nameid) { +bool vending_search(struct map_session_data* sd, unsigned short nameid) +{ int i; + nullpo_retr(false, sd); if( !sd->state.vending ) { // not vending return false; } @@ -328,11 +335,14 @@ bool vending_search(struct map_session_data* sd, unsigned short nameid) { /// 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) { +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; + nullpo_retr(false, sd); + nullpo_retr(false, s); if( !sd->state.vending ) // not vending return true; @@ -378,16 +388,20 @@ bool vending_searchall(struct map_session_data* sd, const struct s_search_store_ return true; } -void final(void) { + +void final(void) +{ db_destroy(vending->db); } -void init(bool minimal) { +void init(bool minimal) +{ vending->db = idb_alloc(DB_OPT_BASE); vending->next_id = 0; } -void vending_defaults(void) { +void vending_defaults(void) +{ vending = &vending_s; vending->init = init; |