本文整理汇总了C++中ARR_FIND函数的典型用法代码示例。如果您正苦于以下问题:C++ ARR_FIND函数的具体用法?C++ ARR_FIND怎么用?C++ ARR_FIND使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了ARR_FIND函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。
示例1: chat_changechatowner
/*==========================================
* change a chatroom's owner
*------------------------------------------*/
int chat_changechatowner(struct map_session_data* sd, const char* nextownername)
{
struct chat_data* cd;
struct map_session_data* tmpsd;
int i;
nullpo_retr(1, sd);
cd = (struct chat_data*)map_id2bl(sd->chatID);
if( cd == NULL || (struct block_list*) sd != cd->owner )
return 1;
ARR_FIND( 1, cd->users, i, strncmp(cd->usersd[i]->status.name, nextownername, NAME_LENGTH) == 0 );
if( i == cd->users )
return -1; // name not found
// erase temporarily
clif_clearchat(cd,0);
// set new owner
cd->owner = (struct block_list*) cd->usersd[i];
clif_changechatowner(cd,cd->usersd[i]);
// swap the old and new owners' positions
tmpsd = cd->usersd[i];
cd->usersd[i] = cd->usersd[0];
cd->usersd[0] = tmpsd;
// set the new chatroom position
map_delblock( &cd->bl );
cd->bl.x = cd->owner->x;
cd->bl.y = cd->owner->y;
map_addblock( &cd->bl );
// and display again
clif_dispchat(cd,0);
return 0;
}
开发者ID:darkmeistersp,项目名称:test,代码行数:42,代码来源:chat.c
示例2: chat_changechatowner
/*==========================================
* Change a chatroom's owner
* Return
* 0: User not found/Missing data
* 1: Success
*------------------------------------------*/
bool chat_changechatowner(struct map_session_data* sd, const char* nextownername) {
struct chat_data* cd;
struct map_session_data* tmpsd;
int i;
nullpo_ret(sd);
nullpo_ret(nextownername);
cd = map->id2cd(sd->chat_id);
if (cd == NULL || &sd->bl != cd->owner)
return false;
ARR_FIND( 1, cd->users, i, strncmp(cd->usersd[i]->status.name, nextownername, NAME_LENGTH) == 0 );
if( i == cd->users )
return false; // name not found
// erase temporarily
clif->clearchat(cd,0);
// set new owner
cd->owner = &cd->usersd[i]->bl;
clif->changechatowner(cd,cd->usersd[i]);
// swap the old and new owners' positions
tmpsd = cd->usersd[i];
cd->usersd[i] = cd->usersd[0];
cd->usersd[0] = tmpsd;
// set the new chatroom position
map->delblock( &cd->bl );
cd->bl.x = cd->owner->x;
cd->bl.y = cd->owner->y;
map->addblock( &cd->bl );
// and display again
clif->dispchat(cd,0);
return true;
}
开发者ID:EPuncker,项目名称:Hercules,代码行数:45,代码来源:chat.c
示例3: elemental_change_mode_ack
/*===============================================================
* Action that elemental perform after changing mode.
* Activates one of the skills of the new mode.
*-------------------------------------------------------------*/
int elemental_change_mode_ack(struct elemental_data *ed, int mode) {
struct block_list *bl = &ed->master->bl;
uint16 skill_id, skill_lv;
int i;
nullpo_ret(ed);
if( !bl )
return 0;
// Select a skill.
ARR_FIND(0, MAX_ELESKILLTREE, i, ed->db->skill[i].id && (ed->db->skill[i].mode&mode));
if( i == MAX_ELESKILLTREE )
return 0;
skill_id = ed->db->skill[i].id;
skill_lv = ed->db->skill[i].lv;
if( elemental_skillnotok(skill_id, ed) )
return 0;
if( ed->ud.skilltimer != INVALID_TIMER )
return 0;
else if( DIFF_TICK(gettick(), ed->ud.canact_tick) < 0 )
return 0;
ed->target_id = bl->id; // Set new target
ed->last_thinktime = gettick();
if( skill_get_inf(skill_id) & INF_GROUND_SKILL )
unit_skilluse_pos(&ed->bl, bl->x, bl->y, skill_id, skill_lv);
else
unit_skilluse_id(&ed->bl,bl->id,skill_id,skill_lv);
ed->target_id = 0; // Reset target after casting the skill to avoid continious attack.
return 1;
}
开发者ID:newmessage,项目名称:rathena,代码行数:42,代码来源:elemental.c
示例4: hplugins_addconf
/**
* Adds a configuration listener for a plugin.
*
* @param pluginID The plugin identifier.
* @param type The configuration type to listen for.
* @param name The configuration entry name.
* @param func The callback function.
* @retval true if the listener was added successfully.
* @retval false in case of error.
*/
bool hplugins_addconf(unsigned int pluginID, enum HPluginConfType type, char *name, void (*parse_func) (const char *key, const char *val), int (*return_func) (const char *key))
{
struct HPConfListenStorage *conf;
int i;
if (parse_func == NULL) {
ShowError("HPM->addConf:%s: missing setter function for config '%s'\n",HPM->pid2name(pluginID),name);
return false;
}
if (type == HPCT_BATTLE && return_func == NULL) {
ShowError("HPM->addConf:%s: missing getter function for config '%s'\n",HPM->pid2name(pluginID),name);
return false;
}
if (type >= HPCT_MAX) {
ShowError("HPM->addConf:%s: unknown point '%u' specified for config '%s'\n",HPM->pid2name(pluginID),type,name);
return false;
}
ARR_FIND(0, VECTOR_LENGTH(HPM->config_listeners[type]), i, strcmpi(name, VECTOR_INDEX(HPM->config_listeners[type], i).key) == 0);
if (i != VECTOR_LENGTH(HPM->config_listeners[type])) {
ShowError("HPM->addConf:%s: duplicate '%s', already in use by '%s'!",
HPM->pid2name(pluginID), name, HPM->pid2name(VECTOR_INDEX(HPM->config_listeners[type], i).pluginID));
return false;
}
VECTOR_ENSURE(HPM->config_listeners[type], 1, 1);
VECTOR_PUSHZEROED(HPM->config_listeners[type]);
conf = &VECTOR_LAST(HPM->config_listeners[type]);
conf->pluginID = pluginID;
safestrncpy(conf->key, name, HPM_ADDCONF_LENGTH);
conf->parse_func = parse_func;
conf->return_func = return_func;
return true;
}
开发者ID:DeepBugs,项目名称:Hercules,代码行数:48,代码来源:HPM.c
示例5: channel_clean
/**
* Make player leave the channel and cleanup association
* - If no one remains in the chat, delete it
* @param channel: Channel data
* @param sd: Player data
* @param flag: Called from deletion process, do not recall delete
* @return
* 0: Success
* -1: Invalid player or channel
*/
int channel_clean(struct Channel *channel, struct map_session_data *sd, int flag) {
unsigned char i;
if(!channel || !sd)
return -1;
if( channel == sd->gcbind )
sd->gcbind = NULL;
ARR_FIND(0, sd->channel_count, i, sd->channels[i] == channel);
if( i < sd->channel_count ) {
unsigned char cursor = i;
sd->channels[i] = NULL;
sd->channel_tick[i] = 0;
for(; i < sd->channel_count; i++ ) { //slice move list down
if( sd->channels[i] == NULL )
continue;
if(i != cursor) {
sd->channels[cursor] = sd->channels[i];
sd->channel_tick[cursor] = sd->channel_tick[i];
}
cursor++;
}
if ( !(sd->channel_count = cursor) ) { //if in no more chan delete db
aFree(sd->channels);
aFree(sd->channel_tick);
sd->channels = NULL;
sd->channel_tick = NULL;
}
}
idb_remove(channel->users,sd->status.char_id); //remove user for channel user list
//auto delete when no more user in
if( !db_size(channel->users) && !(flag&1) )
channel_delete(channel,false);
return 0;
}
开发者ID:Atemo,项目名称:rathena,代码行数:48,代码来源:channel.cpp
示例6: quest_update_status
int quest_update_status(TBL_PC * sd, int quest_id, quest_state status)
{
int i;
//Only status of active and inactive quests can be updated. Completed quests can't (for now). [Inkfish]
ARR_FIND(0, sd->avail_quests, i, sd->quest_log[i].quest_id == quest_id);
if(i == sd->avail_quests)
{
ShowError("quest_update_status: Character %d doesn't have quest %d.\n", sd->status.char_id, quest_id);
return -1;
}
sd->quest_log[i].state = status;
sd->save_quest = true;
if( status < Q_COMPLETE )
{
clif_quest_update_status(sd, quest_id, (bool)status);
return 0;
}
achievement_validate_quest(sd,quest_id);
if( i != (--sd->avail_quests) )
{
struct quest tmp_quest;
memcpy(&tmp_quest, &sd->quest_log[i],sizeof(struct quest));
memcpy(&sd->quest_log[i], &sd->quest_log[sd->avail_quests],sizeof(struct quest));
memcpy(&sd->quest_log[sd->avail_quests], &tmp_quest,sizeof(struct quest));
}
clif_quest_delete(sd, quest_id);
if( save_settings&64 )
chrif_save(sd,0);
return 0;
}
开发者ID:philg666,项目名称:Latest_eAmod,代码行数:38,代码来源:quest.c
示例7: party_removemember2
int party_removemember2(struct map_session_data *sd,uint32 char_id,int party_id)
{
if( sd ) {
if( !sd->status.party_id )
return -3;
party_trade_bound_cancel(sd);
intif_party_leave(sd->status.party_id,sd->status.account_id,sd->status.char_id);
return 1;
} else {
int i;
struct party_data *p;
if( !(p = party_search(party_id)) )
return -2;
ARR_FIND(0,MAX_PARTY,i,p->party.member[i].char_id == char_id );
if( i >= MAX_PARTY )
return -1;
intif_party_leave(party_id,p->party.member[i].account_id,char_id);
return 1;
}
}
开发者ID:julius5,项目名称:rathena,代码行数:23,代码来源:party.c
示例8: chat_kickchat
/*==========================================
* Kick an user from a chatroom
* Return:
* 0: User cannot be kicked (is gm)/Missing data
* 1: Success
*------------------------------------------*/
bool chat_kickchat(struct map_session_data* sd, const char* kickusername) {
struct chat_data* cd;
int i;
nullpo_ret(sd);
cd = (struct chat_data *)map->id2bl(sd->chatID);
if( cd==NULL || (struct block_list *)sd != cd->owner )
return false;
ARR_FIND( 0, cd->users, i, strncmp(cd->usersd[i]->status.name, kickusername, NAME_LENGTH) == 0 );
if( i == cd->users ) // User not found
return false;
if (pc_has_permission(cd->usersd[i], PC_PERM_NO_CHAT_KICK))
return false; //gm kick protection [Valaris]
idb_iput(cd->kick_list,cd->usersd[i]->status.char_id,1);
chat->leave(cd->usersd[i], true);
return true;
}
开发者ID:kwang1go,项目名称:Hercules,代码行数:29,代码来源:chat.c
示例9: mapif_parse_PartyAddMember
// Add a player to party request
int mapif_parse_PartyAddMember(int fd, int party_id, struct party_member *member)
{
struct party_data *p;
int i;
nullpo_ret(member);
p = inter_party->fromsql(party_id);
if( p == NULL || p->size == MAX_PARTY ) {
mapif->party_memberadded(fd, party_id, member->account_id, member->char_id, 1);
return 0;
}
ARR_FIND( 0, MAX_PARTY, i, p->party.member[i].account_id == 0 );
if( i == MAX_PARTY )
{// Party full
mapif->party_memberadded(fd, party_id, member->account_id, member->char_id, 1);
return 0;
}
memcpy(&p->party.member[i], member, sizeof(struct party_member));
p->party.member[i].leader = 0;
if (p->party.member[i].online) p->party.count++;
p->size++;
if (p->size == 2 || p->size == 3) // Check family state. And also accept either of their Parents. [RoM]
inter_party->calc_state(p);
else //Check even share range.
if (member->lv < p->min_lv || member->lv > p->max_lv || p->family) {
if (p->family) p->family = 0; //Family state broken.
inter_party->check_lv(p);
}
mapif->party_info(-1, &p->party, 0);
mapif->party_memberadded(fd, party_id, member->account_id, member->char_id, 0);
inter_party->tosql(&p->party, PS_ADDMEMBER, i);
return 0;
}
开发者ID:Mateuus,项目名称:Cronus,代码行数:38,代码来源:int_party.c
示例10: quest_update_status
/**
* Updates a quest's state.
* Only status of active and inactive quests can be updated. Completed quests can't (for now).
* @param sd : Character's data
* @param quest_id : Quest ID to update
* @param qs : New quest state
* @return 0 in case of success, nonzero otherwise
* @author [Inkfish]
*/
int quest_update_status(TBL_PC *sd, int quest_id, enum quest_state status)
{
int i;
ARR_FIND(0, sd->avail_quests, i, sd->quest_log[i].quest_id == quest_id);
if( i == sd->avail_quests ) {
ShowError("quest_update_status: Character %d doesn't have quest %d.\n", sd->status.char_id, quest_id);
return -1;
}
sd->quest_log[i].state = status;
sd->save_quest = true;
if( status < Q_COMPLETE ) {
clif_quest_update_status(sd, quest_id, status == Q_ACTIVE ? true : false);
return 0;
}
achievement_validate_quest(sd,quest_id);
// The quest is complete, so it needs to be moved to the completed quests block at the end of the array.
if( i < (--sd->avail_quests) ) {
struct quest tmp_quest;
memcpy(&tmp_quest, &sd->quest_log[i], sizeof(struct quest));
memcpy(&sd->quest_log[i], &sd->quest_log[sd->avail_quests], sizeof(struct quest));
memcpy(&sd->quest_log[sd->avail_quests], &tmp_quest, sizeof(struct quest));
}
clif_quest_delete(sd, quest_id);
if( save_settings&64 )
chrif_save(sd,0);
return 0;
}
开发者ID:LKJeronimo,项目名称:eamod,代码行数:45,代码来源:quest.c
示例11: mapif_parse_GuildAddMember
// ギルドメンバ追加要求
int mapif_parse_GuildAddMember(int fd, int guild_id, struct guild_member *m)
{
struct guild *g;
int i;
g = (struct guild*)idb_get(guild_db, guild_id);
if (g == NULL) {
mapif_guild_memberadded(fd, guild_id, m->account_id, m->char_id, 1);
return 0;
}
ARR_FIND( 0, g->max_member, i, g->member[i].account_id == 0 );
if( i < g->max_member )
{
memcpy(&g->member[i], m, sizeof(struct guild_member));
mapif_guild_memberadded(fd, guild_id, m->account_id, m->char_id, 0);
guild_calcinfo(g);
mapif_guild_info(-1, g);
}
else
mapif_guild_memberadded(fd, guild_id, m->account_id, m->char_id, 1);
return 0;
}
开发者ID:KimKyung-wook,项目名称:ilathena-project,代码行数:25,代码来源:int_guild.c
示例12: chat_kickchat
/*==========================================
* kick an user from a chatroom
*------------------------------------------*/
int chat_kickchat(struct map_session_data *sd, const char *kickusername)
{
struct chat_data *cd;
int i;
nullpo_retr(1, sd);
cd = (struct chat_data *)map_id2bl(sd->chatID);
if(cd==NULL || (struct block_list *)sd != cd->owner)
return -1;
ARR_FIND(0, cd->users, i, strncmp(cd->usersd[i]->status.name, kickusername, NAME_LENGTH) == 0);
if(i == cd->users)
return -1;
if(pc_has_permission(cd->usersd[i], PC_PERM_NO_CHAT_KICK))
return 0; //gm kick protection [Valaris]
idb_put(cd->kick_list,cd->usersd[i]->status.char_id,(void *)1);
chat_leavechat(cd->usersd[i],1);
return 0;
}
开发者ID:philg666,项目名称:Latest_eAmod,代码行数:27,代码来源:chat.c
示例13: read_homunculus_skilldb_sub
/**
* Read homunculus skill db
*/
static bool read_homunculus_skilldb_sub(char* split[], int columns, int current)
{// <hom class>,<skill id>,<max level>[,<job level>],<req id1>,<req lv1>,<req id2>,<req lv2>,<req id3>,<req lv3>,<req id4>,<req lv4>,<req id5>,<req lv5>,<intimacy lv req>
int skill_id, class_idx;
int i, j;
int minJobLevelPresent = 0;
if (columns == 14)
minJobLevelPresent = 1; // MinJobLvl has been added
// check for bounds [celest]
if ((class_idx = hom_class2index(atoi(split[0]))) == -1) {
ShowWarning("read_homunculus_skilldb: Invalud homunculus class %d.\n", atoi(split[0]));
return false;
}
skill_id = atoi(split[1]); //This is to avoid adding two lines for the same skill. [Skotlex]
// Search an empty line or a line with the same skill_id (stored in j)
ARR_FIND( 0, MAX_SKILL_TREE, j, !hskill_tree[class_idx][j].id || hskill_tree[class_idx][j].id == skill_id );
if (j == MAX_SKILL_TREE) {
ShowWarning("Unable to load skill %d into homunculus %d's tree. Maximum number of skills per class has been reached.\n", skill_id, atoi(split[0]));
return false;
}
hskill_tree[class_idx][j].id = skill_id;
hskill_tree[class_idx][j].max = atoi(split[2]);
if (minJobLevelPresent)
hskill_tree[class_idx][j].joblv = atoi(split[3]);
for (i = 0; i < MAX_HOM_SKILL_REQUIRE; i++) {
hskill_tree[class_idx][j].need[i].id = atoi(split[3+i*2+minJobLevelPresent]);
hskill_tree[class_idx][j].need[i].lv = atoi(split[3+i*2+minJobLevelPresent+1]);
}
hskill_tree[class_idx][j].intimacylv = atoi(split[13+minJobLevelPresent]);
return true;
}
开发者ID:Lucciola541,项目名称:rathena,代码行数:39,代码来源:homunculus.c
示例14: bg_team_join
/// Player joins team
bool bg_team_join(int bg_id, struct map_session_data *sd) {
int i;
struct battleground_data *bgd = bg->team_search(bg_id);
if( bgd == NULL || sd == NULL || sd->bg_id ) return false;
ARR_FIND(0, MAX_BG_MEMBERS, i, bgd->members[i].sd == NULL);
if( i == MAX_BG_MEMBERS ) return false; // No free slots
sd->bg_id = bg_id;
bgd->members[i].sd = sd;
bgd->members[i].x = sd->bl.x;
bgd->members[i].y = sd->bl.y;
/* populate 'where i came from' */
if(map->list[sd->bl.m].flag.nosave || map->list[sd->bl.m].instance_id >= 0) {
struct map_data *m=&map->list[sd->bl.m];
if(m->save.map)
memcpy(&bgd->members[i].source,&m->save,sizeof(struct point));
else
memcpy(&bgd->members[i].source,&sd->status.save_point,sizeof(struct point));
} else
memcpy(&bgd->members[i].source,&sd->status.last_point,sizeof(struct point));
bgd->count++;
guild->send_dot_remove(sd);
for( i = 0; i < MAX_BG_MEMBERS; i++ ) {
struct map_session_data *pl_sd = bgd->members[i].sd;
if (pl_sd != NULL && pl_sd != sd)
clif->hpmeter_single(sd->fd, pl_sd->bl.id, pl_sd->battle_status.hp, pl_sd->battle_status.max_hp);
}
clif->bg_hp(sd);
clif->bg_xy(sd);
return true;
}
开发者ID:IeYasuru,项目名称:CrystalCore,代码行数:37,代码来源:battleground.c
示例15: cashshop_parse_dbrow
/*
* Reads one line from database and assigns it to RAM.
* return
* 0 = failure
* 1 = success
*/
static int cashshop_parse_dbrow( char** str, const char* source, int line ){
unsigned short nameid = atoi( str[1] );
if( itemdb_exists( nameid ) ){
uint16 tab = atoi( str[0] );
uint32 price = atoi( str[2] );
struct cash_item_data* cid;
int j;
if( tab > CASHSHOP_TAB_SEARCH ){
ShowWarning( "cashshop_parse_dbrow: Invalid tab %d in line %d of \"%s\", skipping...\n", tab, line, source );
return 0;
}else if( price < 1 ){
ShowWarning( "cashshop_parse_dbrow: Invalid price %d in line %d of \"%s\", skipping...\n", price, line, source );
return 0;
}
ARR_FIND( 0, cash_shop_items[tab].count, j, nameid == cash_shop_items[tab].item[j]->nameid );
if( j == cash_shop_items[tab].count ){
RECREATE( cash_shop_items[tab].item, struct cash_item_data *, ++cash_shop_items[tab].count );
CREATE( cash_shop_items[tab].item[ cash_shop_items[tab].count - 1], struct cash_item_data, 1 );
cid = cash_shop_items[tab].item[ cash_shop_items[tab].count - 1];
}else{
开发者ID:MyKafra,项目名称:rAthena,代码行数:30,代码来源:cashshop.c
示例16: quest_update_status
/**
* Updates a quest's state.
*
* Only status of active and inactive quests can be updated. Completed quests can't (for now). [Inkfish]
*
* @param sd Character's data
* @param quest_id Quest ID to update
* @param qs New quest state
* @return 0 in case of success, nonzero otherwise
*/
static int quest_update_status(struct map_session_data *sd, int quest_id, enum quest_state qs)
{
int i;
nullpo_retr(-1, sd);
ARR_FIND(0, sd->avail_quests, i, sd->quest_log[i].quest_id == quest_id);
if( i == sd->avail_quests ) {
ShowError("quest_update_status: Character %d doesn't have quest %d.\n", sd->status.char_id, quest_id);
return -1;
}
sd->quest_log[i].state = qs;
sd->save_quest = true;
if( qs < Q_COMPLETE ) {
clif->quest_update_status(sd, quest_id, qs == Q_ACTIVE ? true : false);
return 0;
}
// The quest is complete, so it needs to be moved to the completed quests block at the end of the array.
if( i < (--sd->avail_quests) ) {
struct quest tmp_quest;
memcpy(&tmp_quest, &sd->quest_log[i],sizeof(struct quest));
memcpy(&sd->quest_log[i], &sd->quest_log[sd->avail_quests],sizeof(struct quest));
memcpy(&sd->quest_log[sd->avail_quests], &tmp_quest,sizeof(struct quest));
}
clif->quest_delete(sd, quest_id);
quest->questinfo_refresh(sd);
if( map->save_settings&64 )
chrif->save(sd,0);
return 0;
}
开发者ID:AnnieRuru,项目名称:Hercules,代码行数:46,代码来源:quest.c
示例17: quest_delete
/**
* Removes a quest from a player's list
*
* @param sd Player's data
* @param quest_id ID of the quest to remove
* @return 0 in case of success, nonzero otherwise
*/
static int quest_delete(struct map_session_data *sd, int quest_id)
{
int i;
nullpo_retr(-1, sd);
//Search for quest
ARR_FIND(0, sd->num_quests, i, sd->quest_log[i].quest_id == quest_id);
if(i == sd->num_quests) {
ShowError("quest_delete: Character %d doesn't have quest %d.\n", sd->status.char_id, quest_id);
return -1;
}
if( sd->quest_log[i].state != Q_COMPLETE )
sd->avail_quests--;
if( i < --sd->num_quests ) {
// Compact the array
memmove(&sd->quest_log[i], &sd->quest_log[i+1], sizeof(struct quest)*(sd->num_quests-i));
}
if( sd->num_quests == 0 ) {
aFree(sd->quest_log);
sd->quest_log = NULL;
} else {
RECREATE(sd->quest_log, struct quest, sd->num_quests);
}
sd->save_quest = true;
clif->quest_delete(sd, quest_id);
quest->questinfo_refresh(sd);
if( map->save_settings&64 )
chrif->save(sd,0);
return 0;
}
开发者ID:AnnieRuru,项目名称:Hercules,代码行数:43,代码来源:quest.c
示例18: trade_tradeadditem
/*==========================================
* Adds an item/qty to the trade window
*------------------------------------------*/
void trade_tradeadditem (struct map_session_data *sd, short index, short amount)
{
struct map_session_data *target_sd;
struct item *item;
int trade_i, trade_weight;
int src_lv, dst_lv;
nullpo_retv (sd);
if (!sd->state.trading || sd->state.deal_locked > 0)
return; //Can't add stuff.
if ( (target_sd = map_id2sd (sd->trade_partner)) == NULL) {
trade_tradecancel (sd);
return;
}
if (amount == 0) {
//Why do this.. ~.~ just send an ack, the item won't display on the trade window.
clif_tradeitemok (sd, index, 0);
return;
}
index -= 2; // 0 is for zeny, 1 is unknown. Gravity, go figure...
//Item checks...
if (index < 0 || index >= MAX_INVENTORY)
return;
if (amount < 0 || amount > sd->status.inventory[index].amount)
return;
item = &sd->status.inventory[index];
src_lv = pc_get_group_level (sd);
dst_lv = pc_get_group_level (target_sd);
if (!itemdb_cantrade (item, src_lv, dst_lv) && //Can't trade
(pc_get_partner (sd) != target_sd || !itemdb_canpartnertrade (item, src_lv, dst_lv))) { //Can't partner-trade
clif_displaymessage (sd->fd, msg_txt (260));
clif_tradeitemok (sd, index + 2, 1);
return;
}
if (item->expire_time) {
// Rental System
clif_displaymessage (sd->fd, msg_txt (260));
clif_tradeitemok (sd, index + 2, 1);
return;
}
//Locate a trade position
ARR_FIND (0, 10, trade_i, sd->deal.item[trade_i].index == index || sd->deal.item[trade_i].amount == 0);
if (trade_i == 10) { //No space left
clif_tradeitemok (sd, index + 2, 1);
return;
}
trade_weight = sd->inventory_data[index]->weight * amount;
if (target_sd->weight + sd->deal.weight + trade_weight > target_sd->max_weight) {
//fail to add item -- the player was over weighted.
clif_tradeitemok (sd, index + 2, 1);
return;
}
if (sd->deal.item[trade_i].index == index) {
//The same item as before is being readjusted.
if (sd->deal.item[trade_i].amount + amount > sd->status.inventory[index].amount) {
//packet deal exploit check
amount = sd->status.inventory[index].amount - sd->deal.item[trade_i].amount;
trade_weight = sd->inventory_data[index]->weight * amount;
}
sd->deal.item[trade_i].amount += amount;
} else {
//New deal item
sd->deal.item[trade_i].index = index;
sd->deal.item[trade_i].amount = amount;
}
sd->deal.weight += trade_weight;
clif_tradeitemok (sd, index + 2, 0); // Return the index as it was received
clif_tradeadditem (sd, target_sd, index + 2, amount);
}
开发者ID:Celso1415,项目名称:Fusion,代码行数:87,代码来源:trade.c
示例19: 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
示例20: merc_search_index
int merc_search_index(int class_)
{
int i;
ARR_FIND(0, MAX_MERCENARY_CLASS, i, mercenary_db[i].class_ == class_);
return (i == MAX_MERCENARY_CLASS)?-1:i;
}
开发者ID:Alvero,项目名称:Hercules,代码行数:6,代码来源:mercenary.c
注:本文中的ARR_FIND函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论