147 lines
4.7 KiB
C++
147 lines
4.7 KiB
C++
#include "precompile.h"
|
|
|
|
#include <f8/utils.h>
|
|
|
|
#include "airdrop.h"
|
|
#include "room.h"
|
|
#include "roomobstacle.h"
|
|
#include "hero.h"
|
|
#include "mapinstance.h"
|
|
|
|
#include "mt/AirDrop.h"
|
|
#include "mt/MapThing.h"
|
|
#include "mt/Hero.h"
|
|
#include "mt/Map.h"
|
|
|
|
AirDrop::AirDrop(Room* room)
|
|
{
|
|
room_ = room;
|
|
}
|
|
|
|
void AirDrop::Init()
|
|
{
|
|
if (room_->IsPveRoom()) {
|
|
return;
|
|
}
|
|
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 MYDEBUG
|
|
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 random_pt;
|
|
if (!room_->RandomSafeAreaPoint(random_pt)) {
|
|
return;
|
|
}
|
|
glm::vec3 box_pos;
|
|
if (!room_->FindWalkablePointWithOutHouse
|
|
(
|
|
random_pt,
|
|
10,
|
|
10,
|
|
box_pos
|
|
)) {
|
|
return;
|
|
}
|
|
room_->frame_event.AddAirDrop(appear_time, box_id, box_pos);
|
|
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<int>& airdrop_mon_list, float radius)
|
|
{
|
|
for (int hero_id : airdrop_mon_list) {
|
|
const mt::Hero* hero_meta = mt::Hero::GetById(hero_id);
|
|
if (hero_meta) {
|
|
int team_id = 666;
|
|
glm::vec3 ref_point = center;
|
|
glm::vec3 point;
|
|
glm::vec3 pos = center;
|
|
room_->map_instance->Scale(ref_point);
|
|
if (room_->map_instance->FindRandomPointAroundCircle
|
|
(
|
|
center,
|
|
80 * room_->GetMapMeta()->scale(),
|
|
point
|
|
)) {
|
|
room_->map_instance->UnScale(point);
|
|
pos = point;
|
|
}
|
|
glm::vec3 dir = GlmHelper::UP;
|
|
GlmHelper::RotateY(dir, a8::RandAngle());
|
|
Hero* hero = room_->CreateHero(nullptr,
|
|
hero_meta,
|
|
pos,
|
|
dir,
|
|
team_id);
|
|
if (hero) {
|
|
#ifdef MYDEBUG
|
|
room_->BroadcastDebugMsg
|
|
(a8::Format("ShuaMon pos:%f,%f,%f hero_id:%d",
|
|
{
|
|
hero->GetPos().GetX(),
|
|
hero->GetPos().GetY(),
|
|
hero->GetPos().GetZ(),
|
|
hero_meta->id()
|
|
}));
|
|
#endif
|
|
}
|
|
}
|
|
}
|
|
}
|