This commit is contained in:
aozhiwei 2023-05-29 13:40:13 +08:00
commit 9c94c8ec9d
13 changed files with 124 additions and 13 deletions

View File

@ -25,7 +25,7 @@ void AirRaid::Init()
(
[this] (const mt::AirRaid* air_raid, bool& stop)
{
room_->xtimer.SetTimeoutEx
auto timer_wp = room_->xtimer.SetTimeoutWpEx
(SERVER_FRAME_RATE * air_raid->time(),
[this, air_raid] (int event, const a8::Args* args)
{
@ -36,6 +36,9 @@ void AirRaid::Init()
}
},
&room_->xtimer_attacher_);
#ifdef DEBUG
timers_.push_back(timer_wp);
#endif
});
}
@ -104,12 +107,63 @@ bool AirRaid::GenAirRaidPos(const mt::AirRaid* raid_meta, glm::vec3& center)
}
center = point;
}
room_->frame_event.AddAirRaid(raid_meta->appear_time(), center, raid_meta->rad());
room_->frame_event.AddAirRaid(raid_meta->appear_time(),
center,
raid_meta->rad(),
std::get<0>(raid_meta->_bombing_time)
);
return true;
}
void AirRaid::ExecOneRoundAirRaid(const mt::AirRaid* raid_meta, const glm::vec3& pos)
{
#if 1
int continue_time = std::get<0>(raid_meta->_bombing_time);
int interval_time = std::get<1>(raid_meta->_bombing_time);
int bomb_times = continue_time / std::max(1, interval_time);
for (int i = 0; i < bomb_times; ++i) {
glm::vec3 born_pos = pos;
int num = 1;
int delay = i * interval_time * 1000;
auto bomb_cb =
[this, raid_meta, num, delay, born_pos]
(int event, const a8::Args* args)
{
if (a8::TIMER_EXEC_EVENT == event) {
if (room_->IsGameOver()) {
return;
}
glm::vec3 center = born_pos;
room_->map_instance->Scale(center);
glm::vec3 point;
if (room_->map_instance->FindRandomPointAroundCircle
(
center,
100 * room_->GetMapMeta()->scale(),
point
)) {
room_->map_instance->UnScale(point);
for (auto bomb_id : raid_meta->_bomb_ids) {
RoomObstacle* obstacle = room_->CreateObstacle
(
bomb_id,
point.x,
point.y,
point.z
);
obstacle->Active();
}
}
}
};
room_->xtimer.SetTimeoutEx
(delay / FRAME_RATE_MS,
bomb_cb,
&room_->xtimer_attacher_);
}
#else
for (auto& tuple : raid_meta->_raid_waves) {
int num = std::get<0>(tuple);
int delay = std::get<1>(tuple);
@ -154,4 +208,20 @@ void AirRaid::ExecOneRoundAirRaid(const mt::AirRaid* raid_meta, const glm::vec3&
&room_->xtimer_attacher_);
}
}
#endif
}
#ifdef DEBUG
void AirRaid::NextRaid()
{
for (size_t i = 0; i < timers_.size(); ++i) {
auto& timer_wp = timers_.at(i);
if (!timer_wp.expired()) {
room_->xtimer.ModifyTime(timer_wp, 0);
break;
}
}
}
#endif

View File

@ -8,6 +8,9 @@ class AirRaid
AirRaid(Room* room);
void Init();
#ifdef DEBUG
void NextRaid();
#endif
private:
@ -17,4 +20,7 @@ class AirRaid
private:
Room* room_ = nullptr;
#ifdef DEBUG
std::vector<a8::XTimerWp> timers_;
#endif
};

View File

@ -8,6 +8,7 @@
#include "ability.h"
#include "movement.h"
#include "android.h"
#include "airraid.h"
#include "cs_proto.pb.h"
@ -170,6 +171,11 @@ void Player::_CMExecCommand(f8::MsgHdr& hdr, const cs::CMExecCommand& msg)
#if DEBUG
room->debug_params[121] = 1;
#endif
} else if (cmd == "next_raid") {
#if DEBUG
room->debug_params[121] = 1;
room->GetAirRaid()->NextRaid();
#endif
} else if (cmd == "autodie") {
#if DEBUG
if (cmds.size() >= 2) {
@ -287,4 +293,7 @@ void Player::_CMExecCommand(f8::MsgHdr& hdr, const cs::CMExecCommand& msg)
skill->Accelerate(-10000000);
}
}
#ifdef DEBUG
a8::XPrintf("exec_cmd:%s\n", {cmd});
#endif
}

View File

@ -21,11 +21,12 @@ void FrameEvent::AddAirDrop(int appear_time, int box_id, const glm::vec3& box_po
TypeConvert::ToPb(box_pos, airdrop->mutable_pos());
}
void FrameEvent::AddAirRaid(int appear_time, const glm::vec3& raid_pos, float raid_rad)
void FrameEvent::AddAirRaid(int appear_time, const glm::vec3& raid_pos, float raid_rad, int continue_time)
{
cs::MFAirRaid* airraid = room->frame_event_data->airraids_.Add();
airraid->set_appear_time(appear_time);
airraid->set_rad(raid_rad);
airraid->set_continue_time(continue_time);
TypeConvert::ToPb(raid_pos, airraid->mutable_pos());
}

View File

@ -14,7 +14,7 @@ public:
Room* room = nullptr;
void AddAirDrop(int appear_time, int box_id, const glm::vec3& box_pos);
void AddAirRaid(int appear_time, const glm::vec3& raid_pos, float raid_rad);
void AddAirRaid(int appear_time, const glm::vec3& raid_pos, float raid_rad, int continue_time);
void AddEmote(CreatureWeakPtr& sender, int emote_id);
void AddShot(CreatureWeakPtr& sender);
void AddBullet(int bullet_uniid,

View File

@ -28,6 +28,18 @@ namespace mt
);
}
}
{
std::vector<std::string> strings;
a8::Split(bombing_time(), strings, ':');
if (strings.size() == 0) {
_bombing_time = std::make_tuple(0, 0);
} else if (strings.size() == 2) {
_bombing_time = std::make_tuple(a8::XValue(strings[0]).GetInt(),
a8::XValue(strings[1]).GetInt());
} else {
abort();
}
}
}
}

View File

@ -15,6 +15,7 @@ namespace mt
std::vector<std::tuple<int, int>> _raid_waves;
std::vector<int> _bomb_ids;
std::tuple<int, int> _bombing_time;
};

View File

@ -16,6 +16,8 @@ namespace mtb
const std::string bomb_id() const { return bomb_id_; };
const std::string raid_wave() const { return raid_wave_; };
float rad() const { return rad_; };
const std::string bombing_time() const { return bombing_time_; };
float damage() const { return damage_; };
bool has_id() const { return __flags__.test(0);};
bool has_time() const { return __flags__.test(1);};
@ -23,6 +25,8 @@ namespace mtb
bool has_bomb_id() const { return __flags__.test(3);};
bool has_raid_wave() const { return __flags__.test(4);};
bool has_rad() const { return __flags__.test(5);};
bool has_bombing_time() const { return __flags__.test(6);};
bool has_damage() const { return __flags__.test(7);};
protected:
@ -32,9 +36,11 @@ namespace mtb
std::string bomb_id_;
std::string raid_wave_;
float rad_ = 0.0f;
std::string bombing_time_;
float damage_ = 0.0f;
public:
std::bitset<6> __flags__;
std::bitset<8> __flags__;
};
};

View File

@ -524,13 +524,15 @@ namespace mtb
{
a8::reflect::Class* meta_class = nullptr;
if (!meta_class) {
meta_class = new a8::reflect::Class("AirRaid", 6, 0);
meta_class = new a8::reflect::Class("AirRaid", 8, 0);
meta_class->SetSimpleField(0, "id", a8::reflect::ET_INT32, my_offsetof2(AirRaid, id_));
meta_class->SetSimpleField(1, "time", a8::reflect::ET_INT32, my_offsetof2(AirRaid, time_));
meta_class->SetSimpleField(2, "appear_time", a8::reflect::ET_INT32, my_offsetof2(AirRaid, appear_time_));
meta_class->SetSimpleField(3, "bomb_id", a8::reflect::ET_STRING, my_offsetof2(AirRaid, bomb_id_));
meta_class->SetSimpleField(4, "raid_wave", a8::reflect::ET_STRING, my_offsetof2(AirRaid, raid_wave_));
meta_class->SetSimpleField(5, "rad", a8::reflect::ET_FLOAT, my_offsetof2(AirRaid, rad_));
meta_class->SetSimpleField(6, "bombing_time", a8::reflect::ET_STRING, my_offsetof2(AirRaid, bombing_time_));
meta_class->SetSimpleField(7, "damage", a8::reflect::ET_FLOAT, my_offsetof2(AirRaid, damage_));
}
return meta_class;
}

View File

@ -252,6 +252,7 @@ public:
void OpenRoomSwitch(int tag);
void CloseRoomSwitch(int tag);
void NotifyNewsTicker(int msg_type, std::vector<std::string> msg_content);
std::shared_ptr<AirRaid> GetAirRaid() { return air_raid_; }
private:
void ShuaAndroid();

View File

@ -392,16 +392,16 @@ void RoomObstacle::DetachFromMaster()
{
if (!detached_) {
detached_ = true;
xtimer_attacher.ClearTimerList();
if (master.Get()) {
xtimer_attacher.ClearTimerList();
master.Get()->SlaveOnRemove(this);
room->grid_service->DelRoomEntity(room, this);
if (!IsDead(room)) {
Die(room);
BroadcastFullState(room);
}
room->RemoveObjectLater(this);
}
room->grid_service->DelRoomEntity(room, this);
if (!IsDead(room)) {
Die(room);
BroadcastFullState(room);
}
room->RemoveObjectLater(this);
}
if (!list_empty(&entry)) {
list_del_init(&entry);

View File

@ -851,6 +851,7 @@ message MFAirRaid
optional int32 appear_time = 1; //()
optional MFVec3 pos = 3; //
optional float rad = 4; //
optional int32 continue_time = 5; //,(!!!)
}
//buff

View File

@ -419,6 +419,8 @@ message AirRaid
optional string bomb_id = 4;
optional string raid_wave = 5;
optional float rad = 6;
optional string bombling_time = 7;
optional float damage = 8;
}
message AirLine