Implemented the Battleground Queue System (#3995)

* Fixes #1310.
* Added a battle config which allows toggling of the Battleground Queue client feature and also toggles between the modes of scripts.
* Added script commands bg_reserve, bg_unbook, and bg_desert.
* Removed old custom Battleground scripts.
Thanks to @Lemongrass3110, @Locien, @secretdataz, @InusualZ, @Normynator, @Atemo, @iubantot, @admkakaroto, and @noobzter003!
This commit is contained in:
Aleos
2020-02-12 08:26:59 -05:00
committed by GitHub
parent c292794154
commit 2931c00bd4
44 changed files with 2687 additions and 4804 deletions

View File

@@ -19662,9 +19662,10 @@ BUILDIN_FUNC(waitingroom2bg)
{
struct npc_data *nd;
struct chat_data *cd;
const char *map_name, *ev = "", *dev = "";
int x, y, mapindex = 0, bg_id;
const char *map_name;
int mapindex = 0, bg_id;
unsigned char i,c=0;
struct s_battleground_team team;
if( script_hasdata(st,7) )
nd = npc_name2id(script_getstr(st,7));
@@ -19684,17 +19685,20 @@ BUILDIN_FUNC(waitingroom2bg)
return SCRIPT_CMD_SUCCESS;
}
x = script_getnum(st,3);
y = script_getnum(st,4);
if(script_hasdata(st,5))
ev = script_getstr(st,5); // Logout Event
if(script_hasdata(st,6))
dev = script_getstr(st,6); // Die Event
team.warp_x = script_getnum(st,3);
team.warp_y = script_getnum(st,4);
if (script_hasdata(st,5)) {
team.quit_event = script_getstr(st,5); // Logout Event
check_event(st, team.quit_event.c_str());
} else
team.quit_event = "";
if (script_hasdata(st,6)) {
team.death_event = script_getstr(st,6); // Die Event
check_event(st, team.death_event.c_str());
} else
team.death_event = "";
check_event(st, ev);
check_event(st, dev);
if( (bg_id = bg_create(mapindex, x, y, ev, dev)) == 0 )
if( (bg_id = bg_create(mapindex, &team)) == 0 )
{ // Creation failed
script_pushint(st,0);
return SCRIPT_CMD_SUCCESS;
@@ -19702,7 +19706,7 @@ BUILDIN_FUNC(waitingroom2bg)
for (i = 0; i < cd->users; i++) { // Only add those who are in the chat room
struct map_session_data *sd;
if( (sd = cd->usersd[i]) != NULL && bg_team_join(bg_id, sd) ){
if( (sd = cd->usersd[i]) != NULL && bg_team_join(bg_id, sd, false) ){
mapreg_setreg(reference_uid(add_str("$@arenamembers"), c), sd->bl.id);
++c;
}
@@ -19719,11 +19723,10 @@ BUILDIN_FUNC(waitingroom2bg_single)
struct npc_data *nd;
struct chat_data *cd;
struct map_session_data *sd;
struct battleground_data *bg;
int x, y, mapindex, bg_id;
int x, y, mapindex, bg_id = script_getnum(st,2);
std::shared_ptr<s_battleground_data> bg = util::umap_find(bg_team_db, bg_id);
bg_id = script_getnum(st,2);
if ((bg = bg_team_search(bg_id)) == NULL) {
if (!bg) {
script_pushint(st, false);
return SCRIPT_CMD_SUCCESS;
}
@@ -19737,9 +19740,9 @@ BUILDIN_FUNC(waitingroom2bg_single)
y = script_getnum(st, 5);
}
else {
mapindex = bg->mapindex;
x = bg->x;
y = bg->y;
mapindex = bg->cemetery.map;
x = bg->cemetery.x;
y = bg->cemetery.y;
}
nd = npc_name2id(script_getstr(st,6));
@@ -19750,7 +19753,7 @@ BUILDIN_FUNC(waitingroom2bg_single)
if( (sd = cd->usersd[0]) == NULL )
return SCRIPT_CMD_SUCCESS;
if( bg_team_join(bg_id, sd) && pc_setpos(sd, mapindex, x, y, CLR_TELEPORT) == SETPOS_OK)
if( bg_team_join(bg_id, sd, false) && pc_setpos(sd, mapindex, x, y, CLR_TELEPORT) == SETPOS_OK)
{
script_pushint(st, true);
}
@@ -19765,8 +19768,9 @@ BUILDIN_FUNC(waitingroom2bg_single)
/// *bg_create("<map name>",<x>,<y>{,"<On Quit Event>","<On Death Event>"});
/// @author [secretdataz]
BUILDIN_FUNC(bg_create) {
const char *map_name, *ev = "", *dev = "";
int x, y, mapindex = 0;
const char *map_name;
int mapindex = 0;
struct s_battleground_team team;
map_name = script_getstr(st, 2);
if (strcmp(map_name, "-") != 0 && (mapindex = mapindex_name2id(map_name)) == 0)
@@ -19775,17 +19779,20 @@ BUILDIN_FUNC(bg_create) {
return SCRIPT_CMD_SUCCESS;
}
x = script_getnum(st, 3);
y = script_getnum(st, 4);
if(script_hasdata(st, 5))
ev = script_getstr(st, 5); // Logout Event
if(script_hasdata(st, 6))
dev = script_getstr(st, 6); // Die Event
team.warp_x = script_getnum(st,3);
team.warp_y = script_getnum(st,4);
if (script_hasdata(st,5)) {
team.quit_event = script_getstr(st,5); // Logout Event
check_event(st, team.quit_event.c_str());
} else
team.quit_event = "";
if (script_hasdata(st,6)) {
team.death_event = script_getstr(st,6); // Die Event
check_event(st, team.death_event.c_str());
} else
team.death_event = "";
check_event(st, ev);
check_event(st, dev);
script_pushint(st, bg_create(mapindex, x, y, ev, dev));
script_pushint(st, bg_create(mapindex, &team));
return SCRIPT_CMD_SUCCESS;
}
@@ -19797,11 +19804,10 @@ BUILDIN_FUNC(bg_create) {
BUILDIN_FUNC(bg_join) {
const char* map_name;
struct map_session_data *sd;
struct battleground_data *bg;
int x, y, bg_id, mapindex;
int x, y, mapindex, bg_id = script_getnum(st, 2);
std::shared_ptr<s_battleground_data> bg = util::umap_find(bg_team_db, bg_id);
bg_id = script_getnum(st, 2);
if ((bg = bg_team_search(bg_id)) == NULL) {
if (!bg) {
script_pushint(st, false);
return SCRIPT_CMD_SUCCESS;
}
@@ -19814,9 +19820,9 @@ BUILDIN_FUNC(bg_join) {
x = script_getnum(st, 4);
y = script_getnum(st, 5);
} else {
mapindex = bg->mapindex;
x = bg->x;
y = bg->y;
mapindex = bg->cemetery.map;
x = bg->cemetery.x;
y = bg->cemetery.y;
}
if (!script_charid2sd(6, sd)) {
@@ -19824,7 +19830,7 @@ BUILDIN_FUNC(bg_join) {
return SCRIPT_CMD_FAILURE;
}
if (bg_team_join(bg_id, sd) && pc_setpos(sd, mapindex, x, y, CLR_TELEPORT) == SETPOS_OK)
if (bg_team_join(bg_id, sd, false) && pc_setpos(sd, mapindex, x, y, CLR_TELEPORT) == SETPOS_OK)
{
script_pushint(st, true);
}
@@ -19836,15 +19842,14 @@ BUILDIN_FUNC(bg_join) {
BUILDIN_FUNC(bg_team_setxy)
{
struct battleground_data *bg;
int bg_id;
int bg_id = script_getnum(st,2);
std::shared_ptr<s_battleground_data> bg = util::umap_find(bg_team_db, bg_id);
bg_id = script_getnum(st,2);
if( (bg = bg_team_search(bg_id)) == NULL )
return SCRIPT_CMD_SUCCESS;
if (bg) {
bg->cemetery.x = script_getnum(st, 3);
bg->cemetery.y = script_getnum(st, 4);
}
bg->x = script_getnum(st,3);
bg->y = script_getnum(st,4);
return SCRIPT_CMD_SUCCESS;
}
@@ -19903,10 +19908,15 @@ BUILDIN_FUNC(bg_monster_set_team)
BUILDIN_FUNC(bg_leave)
{
struct map_session_data *sd = NULL;
bool deserter = false;
if( !script_charid2sd(2,sd) || !sd->bg_id )
return SCRIPT_CMD_SUCCESS;
bg_team_leave(sd,0);
if (!strcmp(script_getfuncname(st), "bg_desert"))
deserter = true;
bg_team_leave(sd, false, deserter);
return SCRIPT_CMD_SUCCESS;
}
@@ -19919,17 +19929,13 @@ BUILDIN_FUNC(bg_destroy)
BUILDIN_FUNC(bg_getareausers)
{
const char *str;
const char *str = script_getstr(st, 3);
int16 m, x0, y0, x1, y1;
int bg_id;
int bg_id = script_getnum(st, 2);
int i = 0, c = 0;
struct battleground_data *bg = NULL;
std::shared_ptr<s_battleground_data> bg = util::umap_find(bg_team_db, bg_id);
bg_id = script_getnum(st,2);
str = script_getstr(st,3);
if( (bg = bg_team_search(bg_id)) == NULL || (m = map_mapname2mapid(str)) < 0 )
{
if (!bg || (m = map_mapname2mapid(str)) < 0) {
script_pushint(st,0);
return SCRIPT_CMD_SUCCESS;
}
@@ -19939,7 +19945,7 @@ BUILDIN_FUNC(bg_getareausers)
x1 = script_getnum(st,6);
y1 = script_getnum(st,7);
for( i = 0; i < MAX_BG_MEMBERS; i++ )
for( i = 0; i < bg->members.size(); i++ )
{
struct map_session_data *sd;
if( (sd = bg->members[i].sd) == NULL )
@@ -19973,29 +19979,102 @@ BUILDIN_FUNC(bg_updatescore)
BUILDIN_FUNC(bg_get_data)
{
struct battleground_data *bg = bg_team_search( script_getnum(st, 2) );
int bg_id = script_getnum(st,2), type = script_getnum(st,3), i;
std::shared_ptr<s_battleground_data> bg = util::umap_find(bg_team_db, bg_id);
if (bg == NULL) {
script_pushint(st, 0);
return SCRIPT_CMD_SUCCESS;
}
int i, j, type = script_getnum(st, 3);
switch( type ) {
case 0:
script_pushint(st, bg->count);
break;
case 1:
for (i = 0, j = 0; i < ARRAYLENGTH(bg->members); i++) {
if (bg->members[i].sd != NULL)
mapreg_setreg(reference_uid(add_str("$@arenamembers"), j++), bg->members[i].sd->bl.id);
if (bg) {
switch (type) {
case 0:
script_pushint(st, bg->members.size());
break;
case 1:
for (i = 0; bg->members[i].sd != NULL; i++)
mapreg_setreg(reference_uid(add_str("$@arenamembers"), i), bg->members[i].sd->bl.id);
mapreg_setreg(add_str("$@arenamemberscount"), i);
script_pushint(st, i);
break;
default:
ShowError("script:bg_get_data: unknown data identifier %d\n", type);
break;
}
mapreg_setreg(add_str("$@arenamemberscount"), j);
script_pushint(st, j);
break;
default:
ShowError("script:bg_get_data: unknown data identifier %d\n", type);
break;
} else
script_pushint(st, 0);
return SCRIPT_CMD_SUCCESS;
}
/**
* Reserves a slot for the given Battleground.
* bg_reserve(<"bg_name">);
*/
BUILDIN_FUNC(bg_reserve)
{
const char *str = script_getstr(st, 2);
if (!bg_queue_reserve(str))
ShowWarning("buildin_bg_reserve: Could not reserve battleground with name %s\n", str);
return SCRIPT_CMD_SUCCESS;
}
/**
* Removes a spot for the given Battleground.
* bg_unbook(<"bg_name">);
*/
BUILDIN_FUNC(bg_unbook)
{
const char *str = script_getstr(st, 2);
if (!bg_queue_unbook(str))
ShowWarning("buildin_bg_unbook: Could not unreserve battleground with name %s\n", str);
return SCRIPT_CMD_SUCCESS;
}
/**
* Gets battleground database information.
* bg_info("<battleground name>", <type>);
*/
BUILDIN_FUNC(bg_info)
{
std::shared_ptr<s_battleground_type> bg = bg_search_name(script_getstr(st, 2));
if (!bg) {
ShowError("bg_info: Invalid Battleground name %s.\n", script_getstr(st, 2));
return SCRIPT_CMD_FAILURE;
}
int type = script_getnum(st, 3);
switch (type) {
case BG_INFO_ID:
script_pushint(st, bg->id);
break;
case BG_INFO_REQUIRED_PLAYERS:
script_pushint(st, bg->required_players);
break;
case BG_INFO_MAX_PLAYERS:
script_pushint(st, bg->max_players);
break;
case BG_INFO_MIN_LEVEL:
script_pushint(st, bg->min_lvl);
break;
case BG_INFO_MAX_LEVEL:
script_pushint(st, bg->max_lvl);
break;
case BG_INFO_MAPS: {
size_t i;
for (i = 0; i < bg->maps.size(); i++)
setd_sub_str(st, nullptr, ".@bgmaps$", i, map_mapid2mapname(bg->maps[i].mapid), nullptr);
setd_sub_num(st, nullptr, ".@bgmapscount", 0, i, nullptr);
script_pushint(st, i);
break;
}
case BG_INFO_DESERTER_TIME:
script_pushint(st, bg->deserter_time);
break;
default:
ShowError("bg_info: Unknown battleground info type %d given.\n", type);
return SCRIPT_CMD_FAILURE;
}
return SCRIPT_CMD_SUCCESS;
@@ -25028,6 +25107,7 @@ struct script_function buildin_func[] = {
BUILDIN_DEF(bg_monster,"isiisi?"),
BUILDIN_DEF(bg_monster_set_team,"ii"),
BUILDIN_DEF(bg_leave,"?"),
BUILDIN_DEF2(bg_leave,"bg_desert","?"),
BUILDIN_DEF(bg_destroy,"i"),
BUILDIN_DEF(areapercentheal,"siiiiii"),
BUILDIN_DEF(bg_get_data,"ii"),
@@ -25035,6 +25115,9 @@ struct script_function buildin_func[] = {
BUILDIN_DEF(bg_updatescore,"sii"),
BUILDIN_DEF(bg_join,"i????"),
BUILDIN_DEF(bg_create,"sii??"),
BUILDIN_DEF(bg_reserve,"s"),
BUILDIN_DEF(bg_unbook,"s"),
BUILDIN_DEF(bg_info,"si"),
// Instancing
BUILDIN_DEF(instance_create,"s??"),