From 07758e21abf23ad6742b0f6aacedbb7c60c81e98 Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Mon, 28 Sep 2015 18:36:58 +0300 Subject: Add support for team id for battleground players. New script function: setbgteam bgid, num It set for 'bgid' team id to 'num'. --- src/emap/battleground.c | 52 ++++++++++++++++++++++++++++++++++++++++ src/emap/battleground.h | 9 +++++++ src/emap/clif.c | 56 ++++++++++++++++++++++++++++++++++++++++++++ src/emap/clif.h | 2 ++ src/emap/data/bgd.c | 5 ++++ src/emap/data/session.c | 1 + src/emap/init.c | 6 +++++ src/emap/script.c | 20 ++++++++++++++++ src/emap/script.h | 1 + src/emap/struct/sessionext.h | 1 + 10 files changed, 153 insertions(+) create mode 100644 src/emap/battleground.c create mode 100644 src/emap/battleground.h (limited to 'src/emap') diff --git a/src/emap/battleground.c b/src/emap/battleground.c new file mode 100644 index 0000000..9b028a5 --- /dev/null +++ b/src/emap/battleground.c @@ -0,0 +1,52 @@ +// Copyright (c) Copyright (c) Hercules Dev Team, licensed under GNU GPL. +// Copyright (c) 2014 Evol developers + +#include "common/hercules.h" + +#include +#include +#include + +#include "common/db.h" +#include "common/HPMi.h" +#include "common/malloc.h" +#include "common/mmo.h" +#include "common/socket.h" +#include "common/strlib.h" +#include "common/timer.h" +#include "map/battleground.h" +#include "map/itemdb.h" +#include "map/map.h" +#include "map/pc.h" + +#include "emap/data/bgd.h" +#include "emap/data/session.h" +#include "emap/struct/bgdext.h" +#include "emap/struct/sessionext.h" + +bool ebg_team_warp(int *bg_idPtr, unsigned short *map_index, short *x, short *y) +{ + int i; + int bg_id = *bg_idPtr; + struct battleground_data *bgd = bg->team_search(bg_id); + if (bgd == NULL) + return false; + struct BgdExt *bdata = bgd_get(bgd); + if (!bdata) + { + ShowWarning("bdata empty\n"); + return true; + } + for (i = 0; i < MAX_BG_MEMBERS; i++) + { + TBL_PC *sd = bgd->members[i].sd; + if (sd != NULL) + { + struct SessionExt *sdata = session_get_bysd(sd); + if (sdata) + sdata->teamId = bdata->teamId; + pc->setpos(bgd->members[i].sd, *map_index, *x, *y, CLR_TELEPORT); + } + } + return true; +} diff --git a/src/emap/battleground.h b/src/emap/battleground.h new file mode 100644 index 0000000..cfcc0f1 --- /dev/null +++ b/src/emap/battleground.h @@ -0,0 +1,9 @@ +// Copyright (c) Copyright (c) Hercules Dev Team, licensed under GNU GPL. +// Copyright (c) 2014 Evol developers + +#ifndef EVOL_MAP_BATTLEGROUND +#define EVOL_MAP_BATTLEGROUND + +bool ebg_team_warp(int *bg_idPtr, unsigned short *map_index, short *x, short *y); + +#endif // EVOL_MAP_BATTLEGROUND diff --git a/src/emap/clif.c b/src/emap/clif.c index 9583ac3..117a7c6 100644 --- a/src/emap/clif.c +++ b/src/emap/clif.c @@ -389,6 +389,28 @@ int eclif_send_actual(int *fd, void *buf, int *len) return 0; } } + if (packet == 0x2dd) + { + struct SessionExt *data = session_get(*fd); + if (!data) + return 0; + if (data->clientVersion >= 12) + { // not sending old packets to new clients + hookStop(); + return 0; + } + } + if (packet == 0xb1a) + { + struct SessionExt *data = session_get(*fd); + if (!data) + return 0; + if (data->clientVersion < 12) + { // not sending new packets to old clients + hookStop(); + return 0; + } + } } return 0; } @@ -615,3 +637,37 @@ void eclif_dropflooritem(struct flooritem_data* fitem) clif->send(&buf, 28, &fitem->bl, AREA); } + +void eclif_sendbgemblem_area(struct map_session_data *sd) +{ + unsigned char buf[34]; + struct SessionExt *data = session_get_bysd(sd); + if (!sd || !data || data->clientVersion < 12) + return; + + WBUFW(buf, 0) = 0xb1a; + WBUFL(buf, 2) = sd->bl.id; + safestrncpy((char*)WBUFP(buf,6), sd->status.name, NAME_LENGTH); // name don't show in screen. + WBUFW(buf, 30) = sd->bg_id; + WBUFW(buf, 32) = data->teamId; + clif->send(buf, 34, &sd->bl, AREA); +} + +void eclif_sendbgemblem_single(int *fdPtr, struct map_session_data *sd) +{ + int fd = *fdPtr; + struct SessionExt *data = session_get_bysd(sd); + struct SessionExt *ddata = session_get_bysd(sd); + if (!sd || !data || !ddata || ddata->clientVersion < 12) + return; + + WFIFOHEAD(fd, 34); + WFIFOW(fd, 0) = 0xb1a; + WFIFOL(fd, 2) = sd->bl.id; + safestrncpy((char*)WFIFOP(fd, 6), sd->status.name, NAME_LENGTH); + WFIFOW(fd, 30) = sd->bg_id; + WFIFOW(fd, 32) = data->teamId; + WFIFOSET(fd, 34); + hookStop(); + return; +} diff --git a/src/emap/clif.h b/src/emap/clif.h index dfa0d19..ff00061 100644 --- a/src/emap/clif.h +++ b/src/emap/clif.h @@ -28,5 +28,7 @@ void eclif_changelook2(struct block_list *bl, int type, int val, struct item_data *id, int n); void eclif_getareachar_item(struct map_session_data *sd, struct flooritem_data *fitem); void eclif_dropflooritem(struct flooritem_data* fitem); +void eclif_sendbgemblem_area(struct map_session_data *sd); +void eclif_sendbgemblem_single(int *fdPtr, struct map_session_data *sd); #endif // EVOL_MAP_CLIF diff --git a/src/emap/data/bgd.c b/src/emap/data/bgd.c index 6f5956c..187317e 100644 --- a/src/emap/data/bgd.c +++ b/src/emap/data/bgd.c @@ -23,9 +23,14 @@ struct BgdExt *bgd_get(struct battleground_data *bd) struct BgdExt *data = getFromBGDATA(bd, 0); if (!data) { + ShowWarning("creating bg\n"); data = bgd_create(); addToBGDATA(bd, data, 0, true); } + else + { + ShowWarning("getting bg\n"); + } return data; } diff --git a/src/emap/data/session.c b/src/emap/data/session.c index 0275ca5..fe8a423 100644 --- a/src/emap/data/session.c +++ b/src/emap/data/session.c @@ -46,5 +46,6 @@ struct SessionExt *session_create(void) data->language = 0; data->state = 0; data->onlinelistlasttime = 0; + data->teamId = 0; return data; } diff --git a/src/emap/init.c b/src/emap/init.c index 1441487..d625b42 100644 --- a/src/emap/init.c +++ b/src/emap/init.c @@ -42,6 +42,7 @@ #include "ecommon/config.h" #include "ecommon/init.h" #include "emap/atcommand.h" +#include "emap/battleground.h" #include "emap/clif.h" #include "emap/itemdb.h" #include "emap/lang.h" @@ -123,6 +124,7 @@ HPExport void plugin_init (void) addScriptCommand("downrefindex", "ii", downRefIndex); addScriptCommand("successrefindex", "ii", successRefIndex); addScriptCommand("isstr", "v", isStr); + addScriptCommand("setbgteam", "ii", setBgTeam); do_init_langs(); @@ -141,6 +143,8 @@ HPExport void plugin_init (void) addHookPre("atcommand->msgfd", eatcommand_msgfd); addHookPre("atcommand->msgsd", eatcommand_msgsd); + + addHookPre("bg->team_warp", ebg_team_warp); addHookPre("pc->readparam", epc_readparam_pre); addHookPre("pc->setregistry", epc_setregistry); addHookPre("pc->equipitem_pos", epc_equipitem_pos); @@ -161,6 +165,8 @@ HPExport void plugin_init (void) addHookPre("clif->dropflooritem", eclif_dropflooritem); addHookPre("clif->sendlook", eclif_sendlook); addHookPre("clif->send", eclif_send); + addHookPre("clif->sendbgemblem_area", eclif_sendbgemblem_area); + addHookPre("clif->sendbgemblem_single", eclif_sendbgemblem_single); addHookPre("clif->set_unit_idle", eclif_set_unit_idle); addHookPre("clif->send_actual", eclif_send_actual); addHookPre("clif->pLoadEndAck", eclif_parse_LoadEndAck_pre); diff --git a/src/emap/script.c b/src/emap/script.c index 72b50c7..ebcc33b 100644 --- a/src/emap/script.c +++ b/src/emap/script.c @@ -27,9 +27,11 @@ #include "emap/lang.h" #include "emap/scriptdefines.h" #include "emap/send.h" +#include "emap/data/bgd.h" #include "emap/data/mapd.h" #include "emap/data/npcd.h" #include "emap/data/session.h" +#include "emap/struct/bgdext.h" #include "emap/struct/mapdext.h" #include "emap/struct/npcdext.h" #include "emap/struct/sessionext.h" @@ -1669,3 +1671,21 @@ BUILDIN(npcWalkTo) return true; } + +BUILDIN(setBgTeam) +{ + int bgId = script_getnum(st, 2); + int teamId = script_getnum(st, 3); + + struct battleground_data *bgd = bg->team_search(bgId); + struct BgdExt *data = bgd_get(bgd); + if (!data) + { + ShowWarning("bettle ground not found\n"); + script->reportsrc(st); + return false; + } + + data->teamId = teamId; + return true; +} diff --git a/src/emap/script.h b/src/emap/script.h index d17cd29..cc55a71 100644 --- a/src/emap/script.h +++ b/src/emap/script.h @@ -56,5 +56,6 @@ BUILDIN(isStr); BUILDIN(npcSit); BUILDIN(npcStand); BUILDIN(npcWalkTo); +BUILDIN(setBgTeam); #endif // EVOL_MAP_SCRIPT diff --git a/src/emap/struct/sessionext.h b/src/emap/struct/sessionext.h index a592e50..ba37871 100644 --- a/src/emap/struct/sessionext.h +++ b/src/emap/struct/sessionext.h @@ -9,6 +9,7 @@ struct SessionExt time_t onlinelistlasttime; int clientVersion; int language; + int teamId; uint8 state; }; -- cgit v1.2.3-60-g2f50