From 411b5865063ae7ef37280f809a24f088cd45177f Mon Sep 17 00:00:00 2001 From: aozhiwei Date: Wed, 28 Sep 2022 15:19:25 +0800 Subject: [PATCH] 1 --- server/gameserver/incubator.cc | 116 +++++++++++++++++---------------- 1 file changed, 59 insertions(+), 57 deletions(-) diff --git a/server/gameserver/incubator.cc b/server/gameserver/incubator.cc index f2349977..557a207a 100644 --- a/server/gameserver/incubator.cc +++ b/server/gameserver/incubator.cc @@ -287,6 +287,64 @@ void Incubator::SpawnWaveMon(int wave) #ifdef DEBUG a8::XPrintf("SpawnWaveMon wave:%d \n", {wave}); #endif + auto cb = + [] (const a8::XParams& param) + { + Incubator* incubator = (Incubator*)param.sender.GetUserData(); + MetaData::PveGeminiContent* content = (MetaData::PveGeminiContent*)param.param1.GetUserData(); + Room* room = incubator->room; + int wave = param.param2.GetInt(); + int monIdx = param.param3.GetInt(); +#ifdef DEBUG + a8::XPrintf("wave i:%d enemys_size:%d\n", {wave, content->enemys.size()}); +#endif + if (monIdx < content->enemys.size()) { + int enemy_id = content->enemys[monIdx]; + MetaData::Player* hero_meta = MetaMgr::Instance()->GetPlayer(enemy_id); + if (hero_meta) { + a8::Vec2 hero_pos = content->spawn_point; + + int team_id = 666; + Creature* master = nullptr; + + a8::Vec2 dir = hero_pos; + dir.Normalize(); + + Hero* hero = room->CreateHero(master, + hero_meta, + hero_pos, + dir, + team_id); + if (!hero) { + A8_ABORT(); + } +#ifdef DEBUG + { + room->xtimer.AddDeadLineTimerAndAttach + ( + SERVER_FRAME_RATE * (rand() % 3), + a8::XParams() + .SetSender(hero), + [] (const a8::XParams& param) + { + Hero* hero = (Hero*)param.sender.GetUserData(); + hero->BeKill(VP_Gas, TEXT("battle_server_killer_gas", "毒圈"), VW_Gas); + }, + &hero->xtimer_attacher.timer_list_); + } +#endif + if (wave + 1 == room->pve_mode_meta->waves.size()) { + hero->is_pve_boss = true; +#ifdef DEBGU + a8::XPrintf("pve_boss appear\n", {}); +#endif + } + + ++room->pve_data.mon_num; + room->NotifyUiUpdate(); + } + } + }; auto& mons = room->pve_mode_meta->waves[wave]; for (MetaData::PveGeminiContent* content : mons) { for (int i = 0; i < content->enemys.size(); ++i) { @@ -298,63 +356,7 @@ void Incubator::SpawnWaveMon(int wave) .SetParam1(content) .SetParam2(wave) .SetParam3(i), - [] (const a8::XParams& param) - { - Incubator* incubator = (Incubator*)param.sender.GetUserData(); - MetaData::PveGeminiContent* content = (MetaData::PveGeminiContent*)param.param1.GetUserData(); - Room* room = incubator->room; - int wave = param.param2.GetInt(); - int idx = param.param3.GetInt(); -#ifdef DEBUG - a8::XPrintf("wave i:%d enemys_size:%d\n", {wave, content->enemys.size()}); -#endif - if (idx < content->enemys.size()) { - int enemy_id = content->enemys[idx]; - MetaData::Player* hero_meta = MetaMgr::Instance()->GetPlayer(enemy_id); - if (hero_meta) { - a8::Vec2 hero_pos = content->spawn_point; - - int team_id = 666; - Creature* master = nullptr; - - a8::Vec2 dir = hero_pos; - dir.Normalize(); - - Hero* hero = room->CreateHero(master, - hero_meta, - hero_pos, - dir, - team_id); - if (!hero) { - A8_ABORT(); - } -#ifdef DEBUG - { - room->xtimer.AddDeadLineTimerAndAttach - ( - SERVER_FRAME_RATE * (rand() % 3), - a8::XParams() - .SetSender(hero), - [] (const a8::XParams& param) - { - Hero* hero = (Hero*)param.sender.GetUserData(); - hero->BeKill(VP_Gas, TEXT("battle_server_killer_gas", "毒圈"), VW_Gas); - }, - &hero->xtimer_attacher.timer_list_); - } -#endif - if (wave + 1 == room->pve_mode_meta->waves.size()) { - hero->is_pve_boss = true; -#ifdef DEBGU - a8::XPrintf("pve_boss appear\n", {}); -#endif - } - - ++room->pve_data.mon_num; - room->NotifyUiUpdate(); - } - } - }, + cb, &xtimer_attacher_.timer_list_); } room->pve_data.refreshed_mon += content->enemys.size();