/// Executes 'func' for each party member on the same map and in range (0:whole map) int party_foreachsamemap(int (*func)(struct block_list*,va_list),struct map_session_data *sd,int range,...) { struct party_data *p = NULL; struct battleground_data *bg = NULL; struct map_session_data *psd; int i,x0,y0,x1,y1; struct block_list *list[MAX_BG_MEMBERS]; int blockcount=0; int total = 0; //Return value. nullpo_retr(0,sd); if( map[sd->bl.m].flag.battleground && (bg = bg_team_search(sd->state.bg_id)) == NULL ) return 0; else if( !map[sd->bl.m].flag.battleground && (p = party_search(sd->status.party_id)) == NULL ) return 0; x0 = sd->bl.x-range; y0 = sd->bl.y-range; x1 = sd->bl.x+range; y1 = sd->bl.y+range; if( bg ) { for( i = 0; i < MAX_BG_MEMBERS; i++ ) { if( (psd = bg->members[i].sd) == NULL ) continue; if( psd->bl.m != sd->bl.m || !psd->bl.prev ) continue; if( range && (psd->bl.x < x0 || psd->bl.y < y0 || psd->bl.x > x1 || psd->bl.y > y1) ) continue; list[blockcount++] = &psd->bl; } } else if( p ) { for( i = 0; i < MAX_PARTY; i++ ) { if( (psd = p->data[i].sd) == NULL ) continue; if( psd->bl.m != sd->bl.m || !psd->bl.prev ) continue; if( range && (psd->bl.x < x0 || psd->bl.y < y0 || psd->bl.x > x1 || psd->bl.y > y1) ) continue; list[blockcount++] = &psd->bl; } } else return 0; map_freeblock_lock(); for( i = 0; i < blockcount; i++ ) { va_list ap; va_start(ap, range); total += func(list[i], ap); va_end(ap); } map_freeblock_unlock(); return total; }
int bg_team_leave(struct map_session_data *sd, int flag) { // Single Player leaves team int i, bg_id; struct battleground_data *bg; char output[128]; if( sd == NULL || !sd->bg_id ) return 0; bg_send_dot_remove(sd); bg_id = sd->bg_id; sd->bg_id = 0; if( (bg = bg_team_search(bg_id)) == NULL ) return 0; ARR_FIND(0, MAX_BG_MEMBERS, i, bg->members[i].sd == sd); if( i < MAX_BG_MEMBERS ) // Removes member from BG memset(&bg->members[i], 0, sizeof(bg->members[0])); bg->count--; if( flag ) sprintf(output, "Server : %s has quit the game...", sd->status.name); else sprintf(output, "Server : %s is leaving the battlefield...", sd->status.name); clif_bg_message(bg, 0, "Server", output, strlen(output) + 1); if( bg->logout_event[0] && flag ) npc_event(sd, bg->logout_event, 0); return bg->count; }
int bg_team_join(int bg_id, struct map_session_data *sd) { // Player joins team int i; struct battleground_data *bg = bg_team_search(bg_id); struct map_session_data *pl_sd; if( bg == NULL || sd == NULL || sd->bg_id ) return 0; ARR_FIND(0, MAX_BG_MEMBERS, i, bg->members[i].sd == NULL); if( i == MAX_BG_MEMBERS ) return 0; // No free slots sd->bg_id = bg_id; bg->members[i].sd = sd; bg->members[i].x = sd->bl.x; bg->members[i].y = sd->bl.y; bg->count++; guild_send_dot_remove(sd); for( i = 0; i < MAX_BG_MEMBERS; i++ ) { if( (pl_sd = bg->members[i].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 1; }
void bg_team_get_kafrapoints(int bg_id, int amount) { struct battleground_data *bg; struct map_session_data *sd; int i, j, get_amount, rank = 0; if( (bg = bg_team_search(bg_id)) == NULL ) return; if( battle_config.bg_reward_rates != 100 ) amount = amount * battle_config.bg_reward_rates / 100; for( i = 0; i < MAX_BG_MEMBERS; i++ ) { if( (sd = bg->members[i].sd) == NULL ) continue; if( battle_config.bg_ranking_bonus ) { rank = 0; ARR_FIND(0,MAX_FAME_LIST,j,bgrank_fame_list[j].id == sd->status.char_id); if( j < MAX_FAME_LIST ) rank = 1; else { ARR_FIND(0,MAX_FAME_LIST,j,bg_fame_list[j].id == sd->status.char_id); if( j < MAX_FAME_LIST ) rank = 1; } } get_amount = amount; if( rank ) get_amount += battle_config.bg_ranking_bonus * get_amount / 100; pc_getcash(sd,0,get_amount); } }
int bg_block_skill_end(int tid, unsigned int tick, int id, intptr_t data) { struct battleground_data *bg; char output[128]; int idx = battle_config.guild_skills_separed_delay ? (int)data - GD_SKILLBASE : 0; if( (bg = bg_team_search(id)) == NULL ) return 1; if( idx < 0 || idx >= MAX_GUILDSKILL ) { ShowError("bg_block_skill_end invalid skillnum %d.\n", (int)data); return 0; } if( tid != bg->skill_block_timer[idx] ) { ShowError("bg_block_skill_end %d != %d.\n", bg->skill_block_timer[idx], tid); return 0; } sprintf(output, "%s : Guild Skill %s Ready!!", bg->g->name, skill_get_desc((int)data)); clif_bg_message(bg, bg->bg_id, bg->g->name, output, strlen(output) + 1); bg->skill_block_timer[idx] = INVALID_TIMER; return 1; }
int bg_team_warp(int bg_id, unsigned short mapindex, short x, short y) { // Warps a Team int i; struct battleground_data *bg = bg_team_search(bg_id); if( bg == NULL ) return 0; for( i = 0; i < MAX_BG_MEMBERS; i++ ) if( bg->members[i].sd != NULL ) pc_setpos(bg->members[i].sd, mapindex, x, y, CLR_TELEPORT); return 1; }
int bg_send_message(struct map_session_data *sd, const char *mes, int len) { struct battleground_data *bg; nullpo_ret(sd); if( sd->bg_id == 0 || (bg = bg_team_search(sd->bg_id)) == NULL ) return 0; clif_bg_message(bg, sd->bl.id, sd->status.name, mes, len); return 0; }
int bg_member_respawn(struct map_session_data *sd) { // Respawn after killed struct battleground_data *bg; if( sd == NULL || !pc_isdead(sd) || !sd->bg_id || (bg = bg_team_search(sd->bg_id)) == NULL ) return 0; if( bg->mapindex == 0 ) return 0; // Respawn not handled by Core pc_setpos(sd, bg->mapindex, bg->x, bg->y, CLR_OUTSIGHT); status_revive(&sd->bl, 1, 100); return 1; // Warped }
int bg_send_dot_remove(struct map_session_data *sd) { struct battleground_data *bg; int m; if( sd && sd->bg_id && (bg = bg_team_search(sd->bg_id)) != NULL ) { clif_bg_xy_remove(sd); if( bg->reveal_pos && (m = map_mapindex2mapid(bg->mapindex)) == sd->bl.m ) map_foreachinmap(bg_reveal_pos,m,BL_PC,sd,2,0xFFFFFF); } return 0; }
int bg_team_delete(int bg_id) { // Deletes BG Team from db int i; struct map_session_data *sd; struct battleground_data *bg = bg_team_search(bg_id); if( bg == NULL ) return 0; for( i = 0; i < MAX_BG_MEMBERS; i++ ) { if( (sd = bg->members[i].sd) == NULL ) continue; bg_send_dot_remove(sd); sd->bg_id = 0; } idb_remove(bg_team_db, bg_id); return 1; }
void bg_team_getitem(int bg_id, int nameid, int amount) { struct battleground_data *bg; struct map_session_data *sd; struct item_data *id; struct item it; int get_amount, i, j, flag, rank = 0; if( amount < 1 || (bg = bg_team_search(bg_id)) == NULL || (id = itemdb_exists(nameid)) == NULL ) return; if( nameid != 7828 && nameid != 7829 && nameid != 7773 ) return; if( battle_config.bg_reward_rates != 100 ) amount = amount * battle_config.bg_reward_rates / 100; memset(&it, 0, sizeof(it)); it.nameid = nameid; it.identify = 1; for( j = 0; j < MAX_BG_MEMBERS; j++ ) { if( (sd = bg->members[j].sd) == NULL ) continue; if( battle_config.bg_ranking_bonus ) { rank = 0; ARR_FIND(0,MAX_FAME_LIST,i,bgrank_fame_list[i].id == sd->status.char_id); if( i < MAX_FAME_LIST ) rank = 1; else { ARR_FIND(0,MAX_FAME_LIST,i,bg_fame_list[i].id == sd->status.char_id); if( i < MAX_FAME_LIST ) rank = 1; } } get_amount = amount; if( rank ) get_amount += battle_config.bg_ranking_bonus * get_amount / 100; if( (flag = pc_additem(sd,&it,get_amount,LOG_TYPE_SCRIPT)) ) clif_additem(sd,0,0,flag); } }
/* ============================================================== bg_arena (0 EoS | 1 Boss | 2 TI | 3 CTF | 4 TD | 5 SC | 6 CON | 7 RUSH | 8 DOM) bg_result (0 Won | 1 Tie | 2 Lost) ============================================================== */ void bg_team_rewards(int bg_id, int nameid, int amount, int kafrapoints, int quest_id, const char *var, int add_value, int bg_arena, int bg_result) { struct battleground_data *bg; struct map_session_data *sd; struct item_data *id; struct item it; int i, j, flag, fame, get_amount, rank = 0, type; if( amount < 1 || (bg = bg_team_search(bg_id)) == NULL || (id = itemdb_exists(nameid)) == NULL ) return; if( battle_config.bg_reward_rates != 100 ) { // BG Reward Rates amount = amount * battle_config.bg_reward_rates / 100; kafrapoints = kafrapoints * battle_config.bg_reward_rates / 100; } bg_result = cap_value(bg_result,0,2); memset(&it,0,sizeof(it)); if( nameid == 7828 || nameid == 7829 || nameid == 7773 ) { it.nameid = nameid; it.identify = 1; } else nameid = 0; for( j = 0; j < MAX_BG_MEMBERS; j++ ) { if( (sd = bg->members[j].sd) == NULL ) continue; if( battle_config.bg_ranking_bonus ) { rank = 0; ARR_FIND(0,MAX_FAME_LIST,i,bgrank_fame_list[i].id == sd->status.char_id); if( i < MAX_FAME_LIST ) rank = 1; else { ARR_FIND(0,MAX_FAME_LIST,i,bg_fame_list[i].id == sd->status.char_id); if( i < MAX_FAME_LIST ) rank = 1; } } if( quest_id ) quest_add(sd,quest_id); pc_setglobalreg(sd,var,pc_readglobalreg(sd,var) + add_value); if( kafrapoints > 0 ) { get_amount = kafrapoints; if( rank ) get_amount += battle_config.bg_ranking_bonus * get_amount / 100; pc_getcash(sd,0,get_amount); } if( nameid && amount > 0 ) { get_amount = amount; if( rank ) get_amount += battle_config.bg_ranking_bonus * get_amount / 100; if( (flag = pc_additem(sd,&it,get_amount,LOG_TYPE_SCRIPT)) ) clif_additem(sd,0,0,flag); } type = bg->members[j].ranked ? 2 : 3; // Where to Add Fame switch( bg_result ) { case 0: // Won add2limit(sd->status.bgstats.win,1,USHRT_MAX); achievement_validate_bg(sd,ATB_VICTORY,1); fame = 100; if( sd->bmaster_flag ) { add2limit(sd->status.bgstats.leader_win,1,USHRT_MAX); achievement_validate_bg(sd,ATB_LEADER_VICTORY,1); fame += 25; } pc_addfame(sd,fame,type); switch( bg_arena ) { case 0: add2limit(sd->status.bgstats.eos_wins,1,USHRT_MAX); achievement_validate_bg(sd,ATB_EOS_VICTORY,1); break; case 1: add2limit(sd->status.bgstats.boss_wins,1,USHRT_MAX); achievement_validate_bg(sd,ATB_BOSS_VICTORY,1); break; case 2: add2limit(sd->status.bgstats.ti_wins,1,USHRT_MAX); achievement_validate_bg(sd,ATB_TI_VICTORY,1); break; case 3: add2limit(sd->status.bgstats.ctf_wins,1,USHRT_MAX); achievement_validate_bg(sd,ATB_CTF_VICTORY,1); break; case 4: add2limit(sd->status.bgstats.td_wins,1,USHRT_MAX); achievement_validate_bg(sd,ATB_TDM_VICTORY,1); break; case 5: add2limit(sd->status.bgstats.sc_wins,1,USHRT_MAX); achievement_validate_bg(sd,ATB_SC_VICTORY,1); break; case 6: add2limit(sd->status.bgstats.cq_wins,1,USHRT_MAX); achievement_validate_bg(sd,ATB_CON_VICTORY,1); break; case 7: add2limit(sd->status.bgstats.ru_wins,1,USHRT_MAX); achievement_validate_bg(sd,ATB_RU_VICTORY,1); break; case 8: add2limit(sd->status.bgstats.dom_wins,1,USHRT_MAX); achievement_validate_bg(sd,ATB_DOM_VICTORY,1); break; } break; case 1: // Tie add2limit(sd->status.bgstats.tie,1,USHRT_MAX); fame = 75; if( sd->bmaster_flag ) { add2limit(sd->status.bgstats.leader_tie,1,USHRT_MAX); fame += 10; } pc_addfame(sd,fame,type); switch( bg_arena ) { case 0: add2limit(sd->status.bgstats.eos_tie,1,USHRT_MAX); break; case 1: add2limit(sd->status.bgstats.boss_tie,1,USHRT_MAX); break; case 2: add2limit(sd->status.bgstats.ti_tie,1,USHRT_MAX); break; case 3: add2limit(sd->status.bgstats.ctf_tie,1,USHRT_MAX); break; case 4: add2limit(sd->status.bgstats.td_tie,1,USHRT_MAX); break; case 5: add2limit(sd->status.bgstats.sc_tie,1,USHRT_MAX); break; // No Tie for Conquest or Rush case 8: add2limit(sd->status.bgstats.dom_tie,1,USHRT_MAX); break; } break; case 2: // Lost add2limit(sd->status.bgstats.lost,1,USHRT_MAX); achievement_validate_bg(sd,ATB_DEFEAT,1); fame = 50; if( sd->bmaster_flag ) { add2limit(sd->status.bgstats.leader_lost,1,USHRT_MAX); achievement_validate_bg(sd,ATB_LEADER_DEFEAT,1); } pc_addfame(sd,fame,type); switch( bg_arena ) { case 0: add2limit(sd->status.bgstats.eos_lost,1,USHRT_MAX); break; case 1: add2limit(sd->status.bgstats.boss_lost,1,USHRT_MAX); break; case 2: add2limit(sd->status.bgstats.ti_lost,1,USHRT_MAX); break; case 3: add2limit(sd->status.bgstats.ctf_lost,1,USHRT_MAX); break; case 4: add2limit(sd->status.bgstats.td_lost,1,USHRT_MAX); break; case 5: add2limit(sd->status.bgstats.sc_lost,1,USHRT_MAX); break; case 6: add2limit(sd->status.bgstats.cq_lost,1,USHRT_MAX); break; case 7: add2limit(sd->status.bgstats.ru_lost,1,USHRT_MAX); break; case 8: add2limit(sd->status.bgstats.dom_lost,1,USHRT_MAX); break; } break; } } }
struct guild* bg_guild_get(int bg_id) { // Return Fake Guild for BG Members struct battleground_data *bg = bg_team_search(bg_id); if( bg == NULL ) return NULL; return bg->g; }
int bg_team_leave(struct map_session_data *sd, int flag) { // Single Player leaves team int i; struct battleground_data *bg; struct map_session_data *pl_sd; struct guild *g; if( sd == NULL || !sd->bg_id ) return 0; bg = bg_team_search(sd->bg_id); if( bg && bg->logout_event[0] && flag ) npc_event(sd, bg->logout_event, 0); // Packets if( battle_config.bg_eAmod_mode ) clif_bg_leave_single(sd, sd->status.name, "Leaving Battle..."); bg_send_dot_remove(sd); sd->bg_id = 0; sd->bg_kills = 0; sd->state.bg_afk = 0; sd->bmaster_flag = NULL; bg_member_removeskulls(sd); // Remove Guild Skill Buffs status_change_end(&sd->bl,SC_GUILDAURA,INVALID_TIMER); status_change_end(&sd->bl,SC_BATTLEORDERS,INVALID_TIMER); status_change_end(&sd->bl,SC_REGENERATION,INVALID_TIMER); if( battle_config.bg_eAmod_mode ) { // Refresh Guild Information if( sd->status.guild_id && (g = guild_search(sd->status.guild_id)) != NULL ) { clif_guild_belonginfo(sd, g); clif_guild_basicinfo(sd); clif_guild_allianceinfo(sd); clif_guild_memberlist(sd); clif_guild_skillinfo(sd); clif_guild_emblem(sd, g); } clif_charnameupdate(sd); clif_guild_emblem_area(&sd->bl); } if( !bg ) return 0; ARR_FIND(0, MAX_BG_MEMBERS, i, bg->members[i].sd == sd); if( i < MAX_BG_MEMBERS ) // Removes member from BG memset(&bg->members[i], 0, sizeof(bg->members[0])); if( bg->leader_char_id == sd->status.char_id ) bg->leader_char_id = 0; bg->count--; for( i = 0; i < MAX_BG_MEMBERS; i++ ) { // Update other BG members if( (pl_sd = bg->members[i].sd) == NULL ) continue; if( !bg->leader_char_id ) { // Set new Leader first on the list bg->leader_char_id = pl_sd->status.char_id; pl_sd->bmaster_flag = bg; } if( battle_config.bg_eAmod_mode ) { switch( flag ) { case 3: clif_bg_expulsion_single(pl_sd, sd->status.name, "Kicked by AFK Status..."); break; case 2: clif_bg_expulsion_single(pl_sd, sd->status.name, "Kicked by AFK Report..."); break; case 1: clif_bg_expulsion_single(pl_sd, sd->status.name, "User has quit the game..."); break; case 0: clif_bg_leave_single(pl_sd, sd->status.name, "Leaving Battle..."); break; } clif_guild_basicinfo(pl_sd); clif_bg_emblem(pl_sd, bg->g); clif_bg_memberlist(pl_sd); } } if( !battle_config.bg_eAmod_mode ) { char output[128]; switch( flag ) { case 3: sprintf(output, "Server : %s kicked by AFK Status...", sd->status.name); break; case 2: sprintf(output, "Server : %s kicked by AFK Report...", sd->status.name); break; case 1: sprintf(output, "Server : %s has quit the game...", sd->status.name); break; case 0: sprintf(output, "Server : %s is leaving the battlefield...", sd->status.name); break; } clif_bg_message(bg, 0, "Server", output, strlen(output) + 1); } return bg->count; }
int bg_team_join(int bg_id, struct map_session_data *sd) { // Player joins team int i; struct battleground_data *bg = bg_team_search(bg_id); struct map_session_data *pl_sd; if( bg == NULL || sd == NULL || sd->bg_id ) return 0; ARR_FIND(0, MAX_BG_MEMBERS, i, bg->members[i].sd == NULL); if( i == MAX_BG_MEMBERS ) return 0; // No free slots pc_update_last_action(sd,0); // Start count from here... sd->bg_id = bg_id; sd->bg_kills = 0; sd->state.bg_afk = 0; bg->members[i].sd = sd; bg->members[i].x = sd->bl.x; bg->members[i].y = sd->bl.y; bg->count++; if( bg->creation_tick == 0 ) bg->creation_tick = last_tick; // Creation Tick = First member joined. if( bg->leader_char_id == 0 ) { // First Join = Team Leader bg->leader_char_id = sd->status.char_id; sd->bmaster_flag = bg; } if( battle_config.bg_ranked_mode && sd->status.bgstats.rank_games < battle_config.bg_ranked_max_games && DIFF_TICK(last_tick,bg->creation_tick) < 60 ) { char output[128]; bg->members[i].ranked = true; sd->status.bgstats.rank_games++; sprintf(output,"-- RANKED BATTLEGROUND MATCH %d OF %d --", sd->status.bgstats.rank_games, battle_config.bg_ranked_max_games); clif_displaymessage(sd->fd,output); } guild_send_dot_remove(sd); if( battle_config.bg_eAmod_mode ) { clif_bg_belonginfo(sd); clif_charnameupdate(sd); } for( i = 0; i < MAX_BG_MEMBERS; i++ ) { if( (pl_sd = bg->members[i].sd) == NULL ) continue; if( battle_config.bg_eAmod_mode ) { // Simulate Guild Information clif_guild_basicinfo(pl_sd); clif_bg_emblem(pl_sd, bg->g); clif_bg_memberlist(pl_sd); } if( pl_sd != sd ) clif_bg_hp_single(sd->fd,pl_sd); } if( battle_config.bg_eAmod_mode ) clif_guild_emblem_area(&sd->bl); clif_bg_hp(sd); clif_bg_xy(sd); return 1; }
int bg_team_clean(int bg_id, bool remove) { // Deletes BG Team from db int i; struct map_session_data *sd; struct battleground_data *bg = bg_team_search(bg_id); struct guild *g; if( bg == NULL ) return 0; for( i = 0; i < MAX_BG_MEMBERS; i++ ) { if( (sd = bg->members[i].sd) == NULL ) continue; bg_send_dot_remove(sd); sd->bg_id = 0; sd->state.bg_afk = 0; sd->bmaster_flag = NULL; bg_member_removeskulls(sd); // Remove Guild Skill Buffs status_change_end(&sd->bl,SC_GUILDAURA,INVALID_TIMER); status_change_end(&sd->bl,SC_BATTLEORDERS,INVALID_TIMER); status_change_end(&sd->bl,SC_REGENERATION,INVALID_TIMER); if( !battle_config.bg_eAmod_mode ) continue; // No need to touch Guild stuff if( sd->status.guild_id && (g = guild_search(sd->status.guild_id)) != NULL ) { clif_guild_belonginfo(sd,g); clif_guild_basicinfo(sd); clif_guild_allianceinfo(sd); clif_guild_memberlist(sd); clif_guild_skillinfo(sd); } else clif_bg_leave_single(sd, sd->status.name, "Leaving Battleground..."); clif_charnameupdate(sd); clif_guild_emblem_area(&sd->bl); } for( i = 0; i < MAX_GUILDSKILL; i++ ) { if( bg->skill_block_timer[i] == INVALID_TIMER ) continue; delete_timer(bg->skill_block_timer[i], bg_block_skill_end); } if( remove ) idb_remove(bg_team_db, bg_id); else { bg->count = 0; bg->leader_char_id = 0; bg->team_score = 0; bg->creation_tick = 0; memset(&bg->members, 0, sizeof(bg->members)); } return 1; }