本文整理汇总了C++中check_distance_bl函数的典型用法代码示例。如果您正苦于以下问题:C++ check_distance_bl函数的具体用法?C++ check_distance_bl怎么用?C++ check_distance_bl使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了check_distance_bl函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。
示例1: buyingstore_open
void buyingstore_open(struct map_session_data* sd, int account_id)
{
struct map_session_data* pl_sd;
if( !battle_config.feature_buying_store || pc_istrading(sd) )
{// not allowed to sell
return;
}
if( !pc->can_give_items(sd) )
{// custom: GM is not allowed to sell
clif->message(sd->fd, msg_txt(246));
return;
}
if( ( pl_sd = iMap->id2sd(account_id) ) == NULL || !pl_sd->state.buyingstore )
{// not online or not buying
return;
}
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);
}
开发者ID:i-nan,项目名称:Hercules,代码行数:28,代码来源:buyingstore.c
示例2: pet_attackskill
/*==========================================
* Pet Attack Skill [Skotlex]
*------------------------------------------*/
int pet_attackskill(struct pet_data *pd, int target_id)
{
if (!battle_config.pet_status_support || !pd->a_skill ||
(battle_config.pet_equip_required && !pd->pet.equip))
return 0;
if (DIFF_TICK(pd->ud.canact_tick, gettick()) > 0)
return 0;
if (rnd()%100 < (pd->a_skill->rate + pd->pet.intimate * pd->a_skill->bonusrate / 1000)) { //Skotlex: Use pet's skill
int inf;
struct block_list *bl;
bl = map_id2bl(target_id);
if (bl == NULL || pd->bl.m != bl->m || bl->prev == NULL || status_isdead(bl) ||
!check_distance_bl(&pd->bl,bl,pd->db->range3))
return 0;
inf = skill_get_inf(pd->a_skill->id);
if (inf&INF_GROUND_SKILL)
unit_skilluse_pos(&pd->bl,bl->x,bl->y,pd->a_skill->id,pd->a_skill->lv);
else //Offensive self skill? Could be stuff like GX
unit_skilluse_id(&pd->bl,(inf&INF_SELF_SKILL ? pd->bl.id : bl->id),pd->a_skill->id,pd->a_skill->lv);
return 1; //Skill invoked
}
return 0;
}
开发者ID:SamuelHercules,项目名称:idathena,代码行数:30,代码来源:pet.c
示例3: elemental_ai_sub_timer_activesearch
static int elemental_ai_sub_timer_activesearch(struct block_list *bl, va_list ap) {
struct elemental_data *ed;
struct block_list **target;
int dist;
nullpo_ret(bl);
ed = va_arg(ap,struct elemental_data *);
target = va_arg(ap,struct block_list**);
//If can't seek yet, not an enemy, or you can't attack it, skip.
if( (*target) == bl || !status_check_skilluse(&ed->bl, bl, 0, 0) )
return 0;
if( battle_check_target(&ed->bl,bl,BCT_ENEMY) <= 0 )
return 0;
switch( bl->type ) {
case BL_PC:
if( !map_flag_vs(ed->bl.m) )
return 0;
default:
dist = distance_bl(&ed->bl, bl);
if( ((*target) == NULL || !check_distance_bl(&ed->bl, *target, dist)) && battle_check_range(&ed->bl,bl,ed->db->range2) ) { //Pick closest target?
(*target) = bl;
ed->target_id = bl->id;
ed->min_chase = dist + ed->db->range3;
if( ed->min_chase > AREA_SIZE )
ed->min_chase = AREA_SIZE;
return 1;
}
break;
}
return 0;
}
开发者ID:newmessage,项目名称:rathena,代码行数:35,代码来源:elemental.c
示例4: trade_traderequest
/*==========================================
* Initiates a trade request.
*------------------------------------------*/
void trade_traderequest(struct map_session_data *sd, struct map_session_data *target_sd)
{
nullpo_retv(sd);
if (map[sd->bl.m].flag.notrade) {
clif_displaymessage (sd->fd, msg_txt(272));
return; //Can't trade in notrade mapflag maps.
}
if (target_sd == NULL || sd == target_sd) {
clif_tradestart(sd, 1); // character does not exist
return;
}
if (target_sd->npc_id)
{ //Trade fails if you are using an NPC.
clif_tradestart(sd, 2);
return;
}
if (!battle_config.invite_request_check) {
if (target_sd->guild_invite > 0 || target_sd->party_invite > 0 || target_sd->adopt_invite) {
clif_tradestart(sd, 2);
return;
}
}
if ( sd->trade_partner != 0 ) { // If a character tries to trade to another one then cancel the previous one
struct map_session_data *previous_sd = map_id2sd(sd->trade_partner);
if( previous_sd ){
previous_sd->trade_partner = 0;
clif_tradecancelled(previous_sd);
} // Once cancelled then continue to the new one.
sd->trade_partner = 0;
clif_tradecancelled(sd);
}
if (target_sd->trade_partner != 0) {
clif_tradestart(sd, 2); // person is in another trade
return;
}
if (!pc_can_give_items(sd) || !pc_can_give_items(target_sd)) //check if both GMs are allowed to trade
{
clif_displaymessage(sd->fd, msg_txt(246));
clif_tradestart(sd, 2); // GM is not allowed to trade
return;
}
// Players can not request trade from far away, unless they are allowed to use @trade.
if (!pc_can_use_command(sd, "trade", COMMAND_ATCOMMAND) &&
(sd->bl.m != target_sd->bl.m || !check_distance_bl(&sd->bl, &target_sd->bl, TRADE_DISTANCE))) {
clif_tradestart(sd, 0); // too far
return ;
}
target_sd->trade_partner = sd->status.account_id;
sd->trade_partner = target_sd->status.account_id;
clif_traderequest(target_sd, sd->status.name);
}
开发者ID:Judasu,项目名称:rAthena-1,代码行数:63,代码来源:trade.c
示例5: buyingstore_open
void buyingstore_open(struct map_session_data* sd, int account_id)
{
struct map_session_data* pl_sd;
if( !battle_config.feature_buying_store || pc_istrading(sd) )
{// not allowed to sell
return;
}
if( !pc_can_give_items(pc_isGM(sd)) )
{// custom: GM is not allowed to sell
clif_displaymessage(sd->fd, msg_txt(246));
return;
}
if( ( pl_sd = map_id2sd(account_id) ) == NULL || !pl_sd->state.buyingstore )
{// not online or not buying
return;
}
if( !battle_config.faction_allow_vending && pl_sd->status.faction_id != sd->status.faction_id )
{
clif_displaymessage(sd->fd,"You cannot sell to other faction members.");
return;
}
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);
}
开发者ID:Chocolate31,项目名称:eamod,代码行数:34,代码来源:buyingstore.c
示例6: trade_traderequest
/*==========================================
* Initiates a trade request.
*------------------------------------------*/
void trade_traderequest(struct map_session_data *sd, struct map_session_data *target_sd)
{
int level;
nullpo_retv(sd);
if (map[sd->bl.m].flag.notrade) {
clif_displaymessage (sd->fd, msg_txt(272));
return; //Can't trade in notrade mapflag maps.
}
if (target_sd == NULL || sd == target_sd) {
clif_tradestart(sd, 1); // character does not exist
return;
}
if (target_sd->npc_id)
{ //Trade fails if you are using an NPC.
clif_tradestart(sd, 2);
return;
}
if (!battle_config.invite_request_check) {
if (target_sd->guild_invite > 0 || target_sd->party_invite > 0 || target_sd->adopt_invite) {
clif_tradestart(sd, 2);
return;
}
}
if ((target_sd->trade_partner != 0) || (sd->trade_partner != 0)) {
clif_tradestart(sd, 2); // person is in another trade
return;
}
level = pc_isGM(sd);
if ( !pc_can_give_items(level) || !pc_can_give_items(pc_isGM(target_sd)) ) //check if both GMs are allowed to trade
{
clif_displaymessage(sd->fd, msg_txt(246));
clif_tradestart(sd, 2); // GM is not allowed to trade
return;
}
//Fixed. Only real GMs can request trade from far away! [Lupus]
if (level < battle_config.lowest_gm_level && (sd->bl.m != target_sd->bl.m ||
!check_distance_bl(&sd->bl, &target_sd->bl, TRADE_DISTANCE)
)) {
clif_tradestart(sd, 0); // too far
return ;
}
target_sd->trade_partner = sd->status.account_id;
sd->trade_partner = target_sd->status.account_id;
clif_traderequest(target_sd, sd->status.name);
}
开发者ID:KimKyung-wook,项目名称:ilathena-project,代码行数:57,代码来源:trade.c
示例7: elemental_set_target
int elemental_set_target( struct map_session_data *sd, struct block_list *bl ) {
struct elemental_data *ed = sd->ed;
nullpo_ret(ed);
nullpo_ret(bl);
if( ed->bl.m != bl->m || !check_distance_bl(&ed->bl, bl, ed->db->range2) )
return 0;
if( !status_check_skilluse(&ed->bl, bl, 0, 0) )
return 0;
if( ed->target_id == 0 )
ed->target_id = bl->id;
return 1;
}
开发者ID:newmessage,项目名称:rathena,代码行数:17,代码来源:elemental.c
示例8: pet_target_check
/**
* Make sure pet can attack from given config values.
* @param sd : player requesting (owner)
* @param bl : target
* @param type : pet's attack rate type
* @return 0
*/
int pet_target_check(struct map_session_data *sd,struct block_list *bl,int type)
{
struct pet_data *pd;
int rate;
pd = sd->pd;
Assert((pd->master == 0) || (pd->master->pd == pd));
if(bl == NULL || bl->type != BL_MOB || bl->prev == NULL ||
pd->pet.intimate < battle_config.pet_support_min_friendly ||
pd->pet.hungry < 1 ||
pd->pet.class_ == status_get_class(bl))
return 0;
if(pd->bl.m != bl->m ||
!check_distance_bl(&pd->bl, bl, pd->db->range2))
return 0;
if (!status_check_skilluse(&pd->bl, bl, 0, 0))
return 0;
if(!type) {
rate = pd->petDB->attack_rate;
rate = rate * pd->rate_fix / 1000;
if(pd->petDB->attack_rate > 0 && rate <= 0)
rate = 1;
} else {
rate = pd->petDB->defence_attack_rate;
rate = rate * pd->rate_fix / 1000;
if(pd->petDB->defence_attack_rate > 0 && rate <= 0)
rate = 1;
}
if(rnd()%10000 < rate) {
if(pd->target_id == 0 || rnd()%10000 < pd->petDB->change_target_rate)
pd->target_id = bl->id;
}
return 0;
}
开发者ID:Chocolate31,项目名称:eamod,代码行数:50,代码来源:pet.c
示例9: buyingstore_open
/**
* Open buying store from buyer
* @param sd Player
* @param account_id Buyer account ID
*/
void buyingstore_open(struct map_session_data *sd, int account_id) {
struct map_session_data *pl_sd;
nullpo_retv(sd);
if( !battle_config.feature_buying_store || pc_istrading(sd) ) // Not allowed to sell
return;
if( !pc_can_give_items(sd) ) { // Custom: GM is not allowed to sell
clif_displaymessage(sd->fd, msg_txt(246));
return;
}
if( (pl_sd = map_id2sd(account_id)) == NULL || !pl_sd->state.buyingstore ) // Not online or not buying
return;
// Out of view range
if( !searchstore_queryremote(sd, account_id) && (sd->bl.m != pl_sd->bl.m ||
!check_distance_bl(&sd->bl, &pl_sd->bl, AREA_SIZE)) )
return;
// Success
clif_buyingstore_itemlist(sd, pl_sd);
}
开发者ID:BlazingSpear,项目名称:idathena,代码行数:29,代码来源:buyingstore.c
示例10: trade_tradeack
/*==========================================
* Reply to a trade-request.
* Type values:
* 0: Char is too far
* 1: Character does not exist
* 2: Trade failed
* 3: Accept
* 4: Cancel
* Weird enough, the client should only send 3/4
* and the server is the one that can reply 0~2
*------------------------------------------*/
void trade_tradeack (struct map_session_data *sd, int type)
{
struct map_session_data *tsd;
nullpo_retv (sd);
sd->state.can_tradeack = 0;
if (sd->state.trading || !sd->trade_partner)
return; //Already trading or no partner set.
if ( (tsd = map_id2sd (sd->trade_partner)) == NULL) {
clif_tradestart (sd, 1); // character does not exist
sd->trade_partner = 0;
return;
}
if (tsd->state.trading || tsd->trade_partner != sd->bl.id) {
clif_tradestart (sd, 2);
sd->trade_partner = 0;
return; //Already trading or wrong partner.
}
if (type == 4) { // Cancel
clif_tradestart (tsd, type);
clif_tradestart (sd, type);
sd->state.deal_locked = 0;
sd->trade_partner = 0;
tsd->state.deal_locked = 0;
tsd->trade_partner = 0;
return;
}
if (type != 3)
return; //If client didn't send accept, it's a broken packet?
// Players can not request trade from far away, unless they are allowed to use @trade.
// Check here as well since the original character could had warped.
if (!pc_can_use_command (sd, "trade", COMMAND_ATCOMMAND) &&
(sd->bl.m != tsd->bl.m || !check_distance_bl (&sd->bl, &tsd->bl, TRADE_DISTANCE))) {
clif_tradestart (sd, 0); // too far
sd->trade_partner = 0;
tsd->trade_partner = 0;
return;
}
//Check if you can start trade.
if (sd->npc_id || sd->state.vending || sd->state.buyingstore || sd->state.storage_flag ||
tsd->npc_id || tsd->state.vending || tsd->state.buyingstore || tsd->state.storage_flag) {
//Fail
clif_tradestart (sd, 2);
clif_tradestart (tsd, 2);
sd->state.deal_locked = 0;
sd->trade_partner = 0;
tsd->state.deal_locked = 0;
tsd->trade_partner = 0;
return;
}
//Initiate trade
sd->state.trading = 1;
tsd->state.trading = 1;
memset (&sd->deal, 0, sizeof (sd->deal));
memset (&tsd->deal, 0, sizeof (tsd->deal));
clif_tradestart (tsd, type);
clif_tradestart (sd, type);
}
开发者ID:Celso1415,项目名称:Fusion,代码行数:76,代码来源:trade.c
示例11: buyingstore_trade
void buyingstore_trade(struct map_session_data* sd, int account_id, unsigned int buyer_id, const uint8* itemlist, unsigned int count)
{
int zeny = 0;
unsigned int i, weight, listidx, k;
struct map_session_data* pl_sd;
if( count == 0 )
{// nothing to do
return;
}
if( !battle_config.feature_buying_store || pc_istrading(sd) )
{// not allowed to sell
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->message(sd->fd, msg_txt(246));
clif->buyingstore_trade_failed_seller(sd, BUYINGSTORE_TRADE_SELLER_FAILED, 0);
return;
}
if( ( pl_sd = iMap->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);
return;
}
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);
return;
}
searchstore->clearremote(sd);
if( pl_sd->status.zeny < pl_sd->buyingstore.zenylimit )
{// buyer lost zeny in the mean time? fix the limit
pl_sd->buyingstore.zenylimit = pl_sd->status.zeny;
}
weight = pl_sd->weight;
// check item list
for( i = 0; i < count; i++ )
{// itemlist: <index>.W <name id>.W <amount>.W
unsigned short nameid, amount;
int index;
index = RBUFW(itemlist,i*6+0)-2;
nameid = RBUFW(itemlist,i*6+2);
amount = RBUFW(itemlist,i*6+4);
if( i )
{// duplicate check. as the client does this too, only malicious intent should be caught here
ARR_FIND( 0, i, k, RBUFW(itemlist,k*6+0)-2 == index );
if( k != i )
{// 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);
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);
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);
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);
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);
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);
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
//.........这里部分代码省略.........
开发者ID:i-nan,项目名称:Hercules,代码行数:101,代码来源:buyingstore.c
示例12: vending_purchasereq
/**
* Purchase item(s) from a shop
* @param sd : buyer player session
* @param aid : account id of vender
* @param uid : shop unique id
* @param data : items data who would like to purchase \n
* data := {<index>.w <amount>.w }[count]
* @param count : number of different items he's trying to buy
*/
void vending_purchasereq(struct map_session_data* sd, int aid, int uid, const uint8* data, int count)
{
int i, j, cursor, w, new_ = 0, blank, vend_list[MAX_VENDING];
double z;
struct s_vending vending[MAX_VENDING]; // against duplicate packets
struct map_session_data* vsd = map_id2sd(aid);
nullpo_retv(sd);
if( vsd == NULL || !vsd->state.vending || vsd->bl.id == sd->bl.id )
return; // invalid shop
if( vsd->vender_id != uid ) { // shop has changed
clif_buyvending(sd, 0, 0, 6); // store information was incorrect
return;
}
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
blank = pc_inventoryblank(sd); //number of free cells in the buyer's inventory
// duplicate item in vending to check hacker with multiple packets
memcpy(&vending, &vsd->vending, sizeof(vsd->vending)); // copy vending list
// 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);
idx -= 2;
if( amount <= 0 )
return;
// check of item index in the cart
if( idx < 0 || idx >= MAX_CART )
return;
ARR_FIND( 0, vsd->vend_num, j, vsd->vending[j].index == idx );
if( j == vsd->vend_num )
return; //picked non-existing item
else
vend_list[i] = j;
z += ((double)vsd->vending[j].value * (double)amount);
if( z > (double)sd->status.zeny || z < 0. || z > (double)MAX_ZENY )
{
clif_buyvending(sd, idx, amount, 1); // you don't have enough zeny
return;
}
if( z + (double)vsd->status.zeny > (double)MAX_ZENY && !battle_config.vending_over_max )
{
clif_buyvending(sd, idx, vsd->vending[j].amount, 4); // too much zeny = overflow
return;
}
w += itemdb_weight(vsd->status.cart[idx].nameid) * amount;
if( w + sd->weight > sd->max_weight ) {
clif_buyvending(sd, idx, amount, 2); // you can not buy, because overweight
return;
}
//Check to see if cart/vend info is in sync.
if( vending[j].amount > vsd->status.cart[idx].amount )
vending[j].amount = vsd->status.cart[idx].amount;
// if they try to add packets (example: get twice or more 2 apples if marchand has only 3 apples).
// here, we check cumulative amounts
if( vending[j].amount < amount )
{
// send more quantity is not a hack (an other player can have buy items just before)
clif_buyvending(sd, idx, vsd->vending[j].amount, 4); // not enough quantity
return;
}
vending[j].amount -= amount;
switch( pc_checkadditem(sd, vsd->status.cart[idx].nameid, amount) ) {
case CHKADDITEM_EXIST:
break; //We'd add this item to the existing one (in buyers inventory)
case CHKADDITEM_NEW:
new_++;
if (new_ > blank)
return; //Buyer has no space in his inventory
break;
//.........这里部分代码省略.........
开发者ID:Escada28,项目名称:rathena,代码行数:101,代码来源:vending.c
示例13: vending_purchasereq
/*==========================================
* Compra de item(s) de uma venda
*------------------------------------------*/
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];
double z;
struct s_vending vend[MAX_VENDING]; // contra duplicagem de packtes
struct map_session_data* vsd = map->id2sd(aid);
nullpo_retv(sd);
if( vsd == NULL || !vsd->state.vending || vsd->bl.id == sd->bl.id )
return; // venda invalida
if( vsd->vender_id != uid ) { // venda mudou
clif->buyvending(sd, 0, 0, 6); // informacao de loja estava incorreta
return;
}
if( !searchstore->queryremote(sd, aid) && ( sd->bl.m != vsd->bl.m || !check_distance_bl(&sd->bl, &vsd->bl, AREA_SIZE) ) )
return; // venda muito distante
searchstore->clearremote(sd);
if( count < 1 || count > MAX_VENDING || count > vsd->vend_num )
return; // quantidade de itens comprados invalida
blank = pc->inventoryblank(sd); //numero de celulas livres no invetorio do comprador
// Duplica item na venda para checar hacker com packets multiplos
memcpy(&vend, &vsd->vending, sizeof(vsd->vending)); // copia lista de venda
// alguns checks
z = 0.; // contador de zeny
w = 0; // contador de weight
for( i = 0; i < count; i++ ) {
short amount = *(uint16*)(data + 4*i + 0);
short idx = *(uint16*)(data + 4*i + 2);
idx -= 2;
if( amount <= 0 )
return;
// check de index de item no carrinho
if( idx < 0 || idx >= MAX_CART )
return;
ARR_FIND( 0, vsd->vend_num, j, vsd->vending[j].index == idx );
if( j == vsd->vend_num )
return; //colhido um item inexistente
else
vend_list[i] = j;
z += ((double)vsd->vending[j].value * (double)amount);
if( z > (double)sd->status.zeny || z < 0. || z > (double)MAX_ZENY ) {
clif->buyvending(sd, idx, amount, 1); // voce nao tem zeny suficiente
return;
}
if( z + (double)vsd->status.zeny > (double)MAX_ZENY && !battle_config.vending_over_max ) {
clif->buyvending(sd, idx, vsd->vending[j].amount, 4); // muito zeny = overflow
return;
}
w += itemdb_weight(vsd->status.cart[idx].nameid) * amount;
if( w + sd->weight > sd->max_weight ) {
clif->buyvending(sd, idx, amount, 2); // voce nao pode comprar, por causa do peso-limite
return;
}
//Check para ver se a info do(a) carrinho/venda esta sincronizada.
if( vend[j].amount > vsd->status.cart[idx].amount )
vend[j].amount = vsd->status.cart[idx].amount;
// se tentarem adicionar packets (exemplo: pega 2x ou mais 2 maçãs se o mercador tem apenas 3 maçãs)
// aqui, checamos quantidade acumulativa
if( vend[j].amount < amount ) {
// enviar mais quantidade não é um hack (um outro jogador pode ter comprado os itens um pouco antes)
clif->buyvending(sd, idx, vsd->vending[j].amount, 4); // quantidade insuficiente
return;
}
vend[j].amount -= amount;
switch( pc->checkadditem(sd, vsd->status.cart[idx].nameid, amount) ) {
case ADDITEM_EXIST:
break; //Adicionariamos esse item para o Item existente (no inventorio do comprador)
case ADDITEM_NEW:
new_++;
if (new_ > blank)
return; //Comprador não tem espaço no seu inventorio
break;
case ADDITEM_OVERAMOUNT:
return; //muitos itens
}
}
pc->payzeny(sd, (int)z, LOG_TYPE_VENDING, vsd);
if( battle_config.vending_tax )
z -= z * (battle_config.vending_tax/10000.);
pc->getzeny(vsd, (int)z, LOG_TYPE_VENDING, sd);
//.........这里部分代码省略.........
开发者ID:Cronus-Emulator,项目名称:Cronus,代码行数:101,代码来源:vending.c
示例14: vending_purchasereq
/*==========================================
* Purchase item(s) from a shop
*------------------------------------------*/
void vending_purchasereq(struct map_session_data* sd, int aid, int uid, const uint8* data, int count)
{
int i, j, cursor, w, new_ = 0, blank, vend_list[MAX_VENDING];
double z;
struct s_vending vending[MAX_VENDING]; // against duplicate packets
struct map_session_data* vsd = map_id2sd(aid);
char output[256];
nullpo_retv(sd);
if( vsd == NULL || !vsd->state.vending || vsd->bl.id == sd->bl.id )
return; // invalid shop
if( vsd->vender_id != uid )
{// shop has changed
clif_buyvending(sd, 0, 0, 6); // store information was incorrect
return;
}
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
blank = pc_inventoryblank(sd); //number of free cells in the buyer's inventory
// duplicate item in vending to check hacker with multiple packets
memcpy(&vending, &vsd->vending, sizeof(vsd->vending)); // copy vending list
// 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);
idx -= 2;
if( amount <= 0 )
return;
// check of item index in the cart
if( idx < 0 || idx >= MAX_CART )
return;
ARR_FIND( 0, vsd->vend_num, j, vsd->vending[j].index == idx );
if( j == vsd->vend_num )
return; //picked non-existing item
else
vend_list[i] = j;
z += ((double)vsd->vending[j].value * (double)amount);
if( !vsd->vend_coin || vsd->vend_coin == battle_config.vending_zeny_id )
{ // Normal Vending - Zeny Option
if( z > (double)sd->status.zeny || z < 0. || z > (double)MAX_ZENY )
{
clif_buyvending(sd, idx, amount, 1); // you don't have enough zeny
return;
}
if( z + (double)vsd->status.zeny > (double)MAX_ZENY && !battle_config.vending_over_max )
{
clif_buyvending(sd, idx, vsd->vending[j].amount, 4); // too much zeny = overflow
return;
}
}
else if( battle_config.vending_cash_id && vsd->vend_coin == battle_config.vending_cash_id )
{ // Cash Shop
if( z > (double)sd->cashPoints || z < 0. || z > (double)MAX_ZENY )
{
sprintf(output,msg_txt(915),itemdb_jname(vsd->vend_coin));
clif_displaymessage(sd->fd,output);
return;
}
if( z + (double)vsd->cashPoints > (double)MAX_ZENY && !battle_config.vending_over_max )
{
sprintf(output,msg_txt(916),itemdb_jname(vsd->vend_coin));
clif_displaymessage(sd->fd,output);
return;
}
}
w += itemdb_weight(vsd->status.cart[idx].nameid) * amount;
if( w + sd->weight > sd->max_weight )
{
clif_buyvending(sd, idx, amount, 2); // you can not buy, because overweight
return;
}
//Check to see if cart/vend info is in sync.
if( vending[j].amount > vsd->status.cart[idx].amount )
vending[j].amount = vsd->status.cart[idx].amount;
// if they try to add packets (example: get twice or more 2 apples if marchand has only 3 apples).
// here, we check cumulative amounts
if( vending[j].amount < amount )
//.........这里部分代码省略.........
开发者ID:ranfs,项目名称:fa6d4ae1781f9a68f1a4d5,代码行数:101,代码来源:vending.c
示例15: trade_tradeack
/*==========================================
* Reply to a trade-request.
* Type values:
* 0: Char is too far
* 1: Character does not exist
* 2: Trade failed
* 3: Accept
* 4: Cancel
* Weird enough, the client should only send 3/4
* and the server is the one that can reply 0~2
*------------------------------------------*/
void trade_tradeack(struct map_session_data *sd, int type)
{
struct map_session_data *tsd;
nullpo_retv(sd);
if (sd->state.trading || !sd->trade_partner)
return; //Already trading or no partner set.
if ((tsd = map_id2sd(sd->trade_partner)) == NULL) {
clif_tradestart(sd, 1); // character does not exist
sd->trade_partner=0;
return;
}
if (tsd->state.trading || tsd->trade_partner != sd->bl.id)
{
clif_tradestart(sd, 2);
return; //Already trading or wrong partner.
}
if (type == 4) { // Cancel
clif_tradestart(tsd, type);
clif_tradestart(sd, type);
sd->state.deal_locked = 0;
sd->trade_partner = 0;
tsd->state.deal_locked = 0;
tsd->trade_partner = 0;
return;
}
if (type != 3)
return; //If client didn't send accept, it's a broken packet?
//Copied here as well since the original character could had warped.
if (pc_isGM(tsd) < battle_config.lowest_gm_level && (sd->bl.m != tsd->bl.m ||
!check_distance_bl(&sd->bl, &tsd->bl, TRADE_DISTANCE)
)) {
clif_tradestart(sd, 0); // too far
sd->trade_partner=0;
tsd->trade_partner = 0;
return;
}
//Check if you can start trade.
if (sd->npc_id || sd->vender_id || sd->state.storage_flag ||
tsd->npc_id || tsd->vender_id || tsd->state.storage_flag)
{ //Fail
clif_tradestart(sd, 2);
clif_tradestart(tsd, 2);
sd->state.deal_locked = 0;
sd->trade_partner = 0;
tsd->state.deal_locked = 0;
tsd->trade_partner = 0;
return;
}
//Initiate trade
sd->state.trading = 1;
tsd->state.trading = 1;
memset(&sd->deal, 0, sizeof(sd->deal));
memset(&tsd->deal, 0, sizeof(tsd->deal));
clif_tradestart(tsd, type);
clif_tradestart(sd, type);
}
开发者ID:KimKyung-wook,项目名称:ilathena-project,代码行数:75,代码来源:trade.c
注:本文中的check_distance_bl函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论