#include "precompile.h" #include #include "airdrop.h" #include "room.h" #include "roomobstacle.h" #include "mt/AirDrop.h" #include "mt/MapThing.h" #include "mt/Hero.h" AirDrop::AirDrop(Room* room) { room_ = room; } void AirDrop::Init() { mt::AirDrop::Traverse ( [this] (const mt::AirDrop* air_drop_meta, bool& stop) { if (air_drop_meta->id() >= 1 && air_drop_meta->id() <= 6) { room_->xtimer.SetTimeoutEx (SERVER_FRAME_RATE * air_drop_meta->time(), [this, air_drop_meta] (int event, const a8::Args* args) mutable { if (a8::TIMER_EXEC_EVENT == event) { if (!room_->IsGameOver()) { Exec( air_drop_meta->appear_time(), air_drop_meta->RandDrop(), air_drop_meta->id() ); } } }, &room_->xtimer_attacher_); } }); } void AirDrop::Exec(int appear_time, int box_id, int airdrop_id) { #ifdef DEBUG if (!f8::IsTestEnv()) { a8::XPrintf("AirDrop appear_time:%d box_id:%d airdrop_id:%d\n", { appear_time, box_id, airdrop_id }); } #endif const mt::MapThing* thing_meta = mt::MapThing::GetById(box_id); if (thing_meta && thing_meta->type() == 2) { glm::vec3 box_pos; #if 0 frame_event.AddAirDrop(appear_time, box_id, final_box_pos); #endif room_->xtimer.SetTimeoutEx (SERVER_FRAME_RATE * appear_time / 1000.f, [this, box_pos, airdrop_id, box_id] (int event, const a8::Args* args) { if (a8::TIMER_EXEC_EVENT == event) { if (!room_->IsGameOver()) { RoomObstacle* obstacle = room_->CreateObstacle ( box_id, box_pos.x, box_pos.y, box_pos.z, nullptr ); obstacle->PushCollisionObjects(); } } }, &room_->xtimer_attacher_); ShuaMon(box_pos, thing_meta->_airdrop_mon_list, std::max(thing_meta->width(), thing_meta->height())); ++airdrop_times_; } } void AirDrop::ShuaMon(const glm::vec3& center, const std::vector& airdrop_mon_list, float radius) { int last_hero_idx = 0; for (int hero_id : airdrop_mon_list) { const mt::Hero* hero_meta = mt::Hero::GetById(hero_id); if (hero_meta) { int team_id = 666; Creature* master = nullptr; for (int i = 0; i < 10; ++i) { glm::vec3 born_dir = center; glm::vec3 born_offset(hero_meta->radius() + 1 + radius + (50 * i), 0.0f, hero_meta->radius() + 1 + radius + (50 * i)); GlmHelper::RotateY(born_offset, GlmHelper::CalcAngle(born_dir, GlmHelper::UP)); GlmHelper::RotateY(born_offset, (last_hero_idx + i) * 0.5); glm::vec3 hero_pos = center + born_offset; glm::vec3 dir = born_offset; GlmHelper::Normalize(dir); Position pos; pos.SetX(hero_pos.x); pos.SetY(hero_pos.y); // 888 #if 0 CircleCollider collider; collider.pos = hero_pos; collider.rad = hero_meta->radius(); if (!map_service->CollisionDetection ( this, false, pos, &collider )) { Hero* hero = CreateHero(master, hero_meta, pos, dir, team_id); if (!hero) { A8_ABORT(); } last_hero_idx = i; #ifdef DEBUG BroadcastDebugMsg(a8::Format("ShuaMon pos:%d,%d hero_id:%d", { hero_pos.x, hero_pos.y, hero->meta->id() })); #endif break; } #endif }//end for i }//end if }//end for hero_id }