This commit is contained in:
aozhiwei 2023-04-20 14:38:47 +08:00
parent 8b19c8d637
commit 1630fbfacc
2 changed files with 111 additions and 9 deletions

View File

@ -4,9 +4,13 @@
#include "human.h" #include "human.h"
#include "room.h" #include "room.h"
#include "glmhelper.h" #include "glmhelper.h"
#include "hero.h"
#include "trigger.h"
#include "skill.h"
#include "mt/GuideStep.h" #include "mt/GuideStep.h"
#include "mt/Hero.h" #include "mt/Hero.h"
#include "mt/Skill.h"
void Guide::Init(Human* owner) void Guide::Init(Human* owner)
{ {
@ -142,6 +146,7 @@ void Guide::ProcMoveTargetAndPickup()
} }
} }
if (done) { if (done) {
owner_->room->xtimer.DeleteCurrentTimer();
NextStep(); NextStep();
} }
} }
@ -159,7 +164,7 @@ void Guide::ProcKillEnemy()
auto context = A8_MAKE_ANON_STRUCT_SHARED auto context = A8_MAKE_ANON_STRUCT_SHARED
( (
std::vector<Hero*> heros; std::vector<int> heros;
); );
{ {
@ -173,7 +178,7 @@ void Guide::ProcKillEnemy()
continue; continue;
} }
++i; ++i;
context->heros.push_back(nullptr); context->heros.push_back(-1);
owner_->room->xtimer.SetTimeoutEx owner_->room->xtimer.SetTimeoutEx
( (
time / FRAME_RATE_MS, time / FRAME_RATE_MS,
@ -188,7 +193,7 @@ void Guide::ProcKillEnemy()
pos, pos,
pos, pos,
666 666
) )->GetUniId()
; ;
} }
}, },
@ -202,9 +207,22 @@ void Guide::ProcKillEnemy()
{ {
if (a8::TIMER_EXEC_EVENT == event) { if (a8::TIMER_EXEC_EVENT == event) {
bool done = true; 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) { if (done) {
owner_->room->xtimer.DeleteCurrentTimer();
NextStep(); NextStep();
} }
} }
@ -220,6 +238,72 @@ void Guide::ProcUseSkillAndKillEnemy()
return; return;
} }
auto context = A8_MAKE_ANON_STRUCT_SHARED
(
std::vector<int> 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() void Guide::ProcUseSkill()
@ -229,6 +313,24 @@ void Guide::ProcUseSkill()
return; return;
} }
auto context = A8_MAKE_ANON_STRUCT_SHARED
(
std::vector<std::weak_ptr<EventHandlerPtr>> handlers;
);
context->handlers.push_back
(owner_->GetTrigger()->AddListener
(
kUseSkillEvent,
[this, context] (const a8::Args& args) mutable
{
Skill* skill = args.Get<Skill*>(0);
if (curr_step_meta_->_int_param1 == skill->meta->skill_id()) {
owner_->GetTrigger()->RemoveEventHandlers(context->handlers);
NextStep();
}
})
);
} }
void Guide::NextStep() void Guide::NextStep()

View File

@ -113,11 +113,11 @@ void Hero::Update(int delta_time)
return; return;
} }
} }
#ifdef DEBUG if (room->IsNewBieRoom()) {
agent_->Exec();
#else } else {
agent_->Exec(); agent_->Exec();
#endif }
} }
void Hero::OnExplosionHit(Explosion* e) void Hero::OnExplosionHit(Explosion* e)