diff --git a/server/gameserver/guide.cc b/server/gameserver/guide.cc index 4753a24e..68d5cd83 100644 --- a/server/gameserver/guide.cc +++ b/server/gameserver/guide.cc @@ -4,9 +4,13 @@ #include "human.h" #include "room.h" #include "glmhelper.h" +#include "hero.h" +#include "trigger.h" +#include "skill.h" #include "mt/GuideStep.h" #include "mt/Hero.h" +#include "mt/Skill.h" void Guide::Init(Human* owner) { @@ -142,6 +146,7 @@ void Guide::ProcMoveTargetAndPickup() } } if (done) { + owner_->room->xtimer.DeleteCurrentTimer(); NextStep(); } } @@ -159,7 +164,7 @@ void Guide::ProcKillEnemy() auto context = A8_MAKE_ANON_STRUCT_SHARED ( - std::vector heros; + std::vector heros; ); { @@ -173,7 +178,7 @@ void Guide::ProcKillEnemy() continue; } ++i; - context->heros.push_back(nullptr); + context->heros.push_back(-1); owner_->room->xtimer.SetTimeoutEx ( time / FRAME_RATE_MS, @@ -188,7 +193,7 @@ void Guide::ProcKillEnemy() pos, pos, 666 - ) + )->GetUniId() ; } }, @@ -202,9 +207,22 @@ void Guide::ProcKillEnemy() { if (a8::TIMER_EXEC_EVENT == event) { bool done = true; - for (Hero* hero : context->heros) { + for (int hero_uniid : context->heros) { + if (hero_uniid <= 0) { + done = false; + break; + } + Entity* e = owner_->room->GetEntityByUniId(hero_uniid); + if (e && e->IsEntityType(ET_Hero)) { + Hero* hero = (Hero*)e; + if (!hero->dead) { + done = false; + break; + } + } } if (done) { + owner_->room->xtimer.DeleteCurrentTimer(); NextStep(); } } @@ -220,6 +238,72 @@ void Guide::ProcUseSkillAndKillEnemy() return; } + auto context = A8_MAKE_ANON_STRUCT_SHARED + ( + std::vector heros; + ); + + { + int i = 0; + for (auto& tuple : curr_step_meta_->_params) { + int time = std::get<0>(tuple); + glm::vec3 pos = std::get<1>(tuple); + int hero_id = std::get<2>(tuple); + const mt::Hero* hero_meta = mt::Hero::GetById(hero_id); + if (!hero_meta){ + continue; + } + ++i; + context->heros.push_back(-1); + owner_->room->xtimer.SetTimeoutEx + ( + time / FRAME_RATE_MS, + [this, hero_id, hero_meta, pos, context, i ] (int event, const a8::Args* args) + { + if (a8::TIMER_EXEC_EVENT == event) { + context->heros[i] = + owner_->room->CreateHero + ( + nullptr, + hero_meta, + pos, + pos, + 666 + )->GetUniId() + ; + } + }, + &owner_->xtimer_attacher); + } + } + + owner_->room->xtimer.SetTimeoutEx + (1, + [this, context] (int event, const a8::Args* args) + { + if (a8::TIMER_EXEC_EVENT == event) { + bool done = true; + for (int hero_uniid : context->heros) { + if (hero_uniid <= 0) { + done = false; + break; + } + Entity* e = owner_->room->GetEntityByUniId(hero_uniid); + if (e && e->IsEntityType(ET_Hero)) { + Hero* hero = (Hero*)e; + if (!hero->dead) { + done = false; + break; + } + } + } + if (done) { + owner_->room->xtimer.DeleteCurrentTimer(); + NextStep(); + } + } + }, + &owner_->xtimer_attacher); } void Guide::ProcUseSkill() @@ -229,6 +313,24 @@ void Guide::ProcUseSkill() return; } + auto context = A8_MAKE_ANON_STRUCT_SHARED + ( + std::vector> handlers; + ); + + context->handlers.push_back + (owner_->GetTrigger()->AddListener + ( + kUseSkillEvent, + [this, context] (const a8::Args& args) mutable + { + Skill* skill = args.Get(0); + if (curr_step_meta_->_int_param1 == skill->meta->skill_id()) { + owner_->GetTrigger()->RemoveEventHandlers(context->handlers); + NextStep(); + } + }) + ); } void Guide::NextStep() diff --git a/server/gameserver/hero.cc b/server/gameserver/hero.cc index b82281cd..6763cfb9 100644 --- a/server/gameserver/hero.cc +++ b/server/gameserver/hero.cc @@ -113,11 +113,11 @@ void Hero::Update(int delta_time) return; } } -#ifdef DEBUG - agent_->Exec(); -#else - agent_->Exec(); -#endif + if (room->IsNewBieRoom()) { + + } else { + agent_->Exec(); + } } void Hero::OnExplosionHit(Explosion* e)