server/game/src/xmas_event.cpp

213 lines
4.6 KiB
C++
Raw Normal View History

2022-03-05 12:44:06 +02:00
#include "stdafx.h"
#include "config.h"
#include "xmas_event.h"
#include "desc.h"
#include "desc_manager.h"
#include "sectree_manager.h"
#include "char.h"
#include "char_manager.h"
#include "questmanager.h"
namespace xmas
{
void ProcessEventFlag(const std::string& name, int prev_value, int value)
{
if (name == "xmas_snow" || name == "xmas_boom" || name == "xmas_song" || name == "xmas_tree")
{
// <20>ѷ<EFBFBD><D1B7>ش<EFBFBD>
const DESC_MANAGER::DESC_SET & c_ref_set = DESC_MANAGER::instance().GetClientSet();
for (itertype(c_ref_set) it = c_ref_set.begin(); it != c_ref_set.end(); ++it)
{
LPCHARACTER ch = (*it)->GetCharacter();
if (!ch)
continue;
ch->ChatPacket(CHAT_TYPE_COMMAND, "%s %d", name.c_str(), value);
}
if (name == "xmas_boom")
{
if (value && !prev_value)
{
SpawnEventHelper(true);
}
else if (!value && prev_value)
{
SpawnEventHelper(false);
}
}
else if (name == "xmas_tree")
{
if (value > 0 && prev_value == 0)
{
CharacterVectorInteractor i;
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ش<EFBFBD>
if (!CHARACTER_MANAGER::instance().GetCharactersByRaceNum(MOB_XMAS_TREE_VNUM, i))
CHARACTER_MANAGER::instance().SpawnMob(MOB_XMAS_TREE_VNUM, 61, 76500 + 358400, 60900 + 153600, 0, false, -1);
}
else if (prev_value > 0 && value == 0)
{
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD>ش<EFBFBD>
CharacterVectorInteractor i;
if (CHARACTER_MANAGER::instance().GetCharactersByRaceNum(MOB_XMAS_TREE_VNUM, i))
{
CharacterVectorInteractor::iterator it = i.begin();
while (it != i.end())
M2_DESTROY_CHARACTER(*it++);
}
}
}
}
else if (name == "xmas_santa")
{
switch (value)
{
case 0:
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20>ڵ<EFBFBD>
{
CharacterVectorInteractor i;
if (CHARACTER_MANAGER::instance().GetCharactersByRaceNum(MOB_SANTA_VNUM, i))
{
CharacterVectorInteractor::iterator it = i.begin();
while (it != i.end())
M2_DESTROY_CHARACTER(*it++);
}
}
break;
case 1:
// <20><><EFBFBD><EFBFBD> <20><><EFBFBD>ѻ<EFBFBD><D1BB≯<EFBFBD> <20><>Ÿ <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD>¸<EFBFBD> 2<><32> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>.
if (map_allow_find(61))
{
quest::CQuestManager::instance().RequestSetEventFlag("xmas_santa", 2);
CharacterVectorInteractor i;
if (CHARACTER_MANAGER::instance().GetCharactersByRaceNum(MOB_SANTA_VNUM, i))
CHARACTER_MANAGER::instance().SpawnMobRandomPosition(MOB_SANTA_VNUM, 61);
}
break;
case 2:
break;
}
}
}
EVENTINFO(spawn_santa_info)
{
int lMapIndex;
2022-03-05 12:44:06 +02:00
spawn_santa_info()
: lMapIndex( 0 )
{
}
};
EVENTFUNC(spawn_santa_event)
{
spawn_santa_info* info = dynamic_cast<spawn_santa_info*>( event->info );
if ( info == NULL )
{
sys_err( "spawn_santa_event> <Factor> Null pointer" );
return 0;
}
int lMapIndex = info->lMapIndex;
2022-03-05 12:44:06 +02:00
if (quest::CQuestManager::instance().GetEventFlag("xmas_santa") == 0)
return 0;
CharacterVectorInteractor i;
if (CHARACTER_MANAGER::instance().GetCharactersByRaceNum(MOB_SANTA_VNUM, i))
return 0;
if (CHARACTER_MANAGER::instance().SpawnMobRandomPosition(xmas::MOB_SANTA_VNUM, lMapIndex))
{
sys_log(0, "santa comes to town!");
return 0;
}
return PASSES_PER_SEC(5);
}
void SpawnSanta(int lMapIndex, int iTimeGapSec)
2022-03-05 12:44:06 +02:00
{
if (test_server)
{
iTimeGapSec /= 60;
}
sys_log(0, "santa respawn time = %d", iTimeGapSec);
spawn_santa_info* info = AllocEventInfo<spawn_santa_info>();
info->lMapIndex = lMapIndex;
event_create(spawn_santa_event, info, PASSES_PER_SEC(iTimeGapSec));
}
void SpawnEventHelper(bool spawn)
{
if ( spawn == true )
{
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ش<EFBFBD>
struct SNPCSellFireworkPosition
{
int lMapIndex;
2022-03-05 12:44:06 +02:00
int x;
int y;
} positions[] = {
{ 1, 615, 618 },
{ 3, 500, 625 },
{ 21, 598, 665 },
{ 23, 476, 360 },
{ 41, 318, 629 },
{ 43, 478, 375 },
{ 0, 0, 0 },
};
SNPCSellFireworkPosition* p = positions;
while (p->lMapIndex)
{
if (map_allow_find(p->lMapIndex))
{
PIXEL_POSITION posBase;
if (!SECTREE_MANAGER::instance().GetMapBasePositionByMapIndex(p->lMapIndex, posBase))
{
sys_err("cannot get map base position %d", p->lMapIndex);
p++;
continue;
}
CHARACTER_MANAGER::instance().SpawnMob(
MOB_XMAS_FIRWORK_SELLER_VNUM, p->lMapIndex, posBase.x + p->x * 100, posBase.y + p->y * 100, 0, false, -1);
}
p++;
}
}
else
{
CharacterVectorInteractor i;
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD>ش<EFBFBD>
if (CHARACTER_MANAGER::instance().GetCharactersByRaceNum(MOB_XMAS_FIRWORK_SELLER_VNUM, i))
{
CharacterVectorInteractor::iterator it = i.begin();
while (it != i.end())
M2_DESTROY_CHARACTER(*it++);
}
}
}
}