添加复活的处理

This commit is contained in:
aozhiwei 2019-07-05 15:54:26 +08:00
parent a86fbc8990
commit e50fd3f181
6 changed files with 96 additions and 31 deletions

View File

@ -48,6 +48,7 @@ class Human : public Entity
MetaData::Skill* skill_meta = nullptr;
MetaData::Tank* skin_jlf_meta = nullptr;
HumanAbility buff;
int born_point = 0;
a8::Vec2 move_dir;
a8::Vec2 attack_dir;

View File

@ -314,19 +314,28 @@ namespace MetaData
void MapTplThing::Init()
{
rand_space = 0;
std::vector<std::string> strings;
a8::Split(i->things(), strings, '\n');
for (auto& str : strings) {
std::vector<std::string> strings2;
a8::Split(str, strings2, ':');
assert(strings2.size() == 2);
rand_space += a8::XValue(strings2[1]).GetInt();
things.push_back(std::make_tuple(
a8::XValue(strings2[0]),
rand_space
)
);
{
rand_space = 0;
std::vector<std::string> strings;
a8::Split(i->things(), strings, '\n');
for (auto& str : strings) {
std::vector<std::string> strings2;
a8::Split(str, strings2, ':');
assert(strings2.size() == 2);
rand_space += a8::XValue(strings2[1]).GetInt();
things.push_back(std::make_tuple(
a8::XValue(strings2[0]),
rand_space
)
);
}
}
{
std::vector<std::string> strings;
a8::Split(i->born_angle(), strings, '\n');
for (auto& str : strings) {
born_angle.push_back(a8::XValue(str).GetDouble());
}
}
}

View File

@ -117,6 +117,7 @@ namespace MetaData
int RandThing();
std::vector<std::tuple<int, int>> things;
std::vector<float> born_angle;
int rand_space = 0;
};

View File

@ -36,10 +36,6 @@ Room::~Room()
void Room::Init()
{
born_points_ = MetaMgr::Instance()->GetMapBornPoints(map_tpl_name);
if (!born_points_ || born_points_->size() != ROOM_MAX_PLAYER_NUM) {
abort();
}
xtimer.Init(RoomXGetTickCount, this, 100, 100);
xtimer_attacher.xtimer = &xtimer;
grid_service.Init(MAP_WIDTH, MAP_HEIGHT, MAP_CELL_WIDTH * 8);
@ -57,6 +53,10 @@ void Room::Init()
},
&xtimer_attacher.timer_list_);
}
born_points_ = MetaMgr::Instance()->GetMapBornPoints(map_tpl_name);
if (!born_points_ || born_points_->size() != ROOM_MAX_PLAYER_NUM) {
abort();
}
ShuaAndroid();
}
@ -154,18 +154,29 @@ int Room::AliveCount()
void Room::AddPlayer(Player* hum)
{
assert(gas_data.gas_mode == GasInactive);
{
hum->pos.x = 200 + rand() % 100;
hum->pos.y = 300 + rand() % 200;
hum->attack_dir = hum->pos;
hum->attack_dir.Normalize();
hum->attack_dir.Rotate(a8::RandAngle());
hum->move_dir = hum->attack_dir;
while (human_hash_.size() + 1 > ROOM_MAX_PLAYER_NUM) {
RandRemoveAndroid();
}
hum->entity_uniid = AllocUniid();
hum->born_point = AllocBornPoint();
{
const MetaData::MapTplThing& thing_tpl = (*born_points_)[hum->born_point];
hum->pos.x = thing_tpl.i->x();
hum->pos.y = thing_tpl.i->y();
hum->attack_dir = a8::Vec2::UP;
hum->attack_dir.Normalize();
if (!thing_tpl.born_angle.empty()){
float angle = thing_tpl.born_angle[rand() % thing_tpl.born_angle.size()];
hum->attack_dir.Rotate(angle / 180.0f);
} else {
hum->attack_dir.Rotate(a8::RandAngle());
}
hum->move_dir = hum->attack_dir;
}
hum->room = this;
hum->join_frameno = frame_no;
hum->Initialize();
born_point_human_hash_[hum->born_point] = hum;
uniid_hash_[hum->entity_uniid] = hum;
moveable_hash_[hum->entity_uniid] = hum;
accountid_hash_[hum->account_id] = hum;
@ -175,9 +186,6 @@ void Room::AddPlayer(Player* hum)
hum->FindLocation();
hum->RefreshView();
MatchTeam(hum);
while (human_hash_.size() > ROOM_MAX_PLAYER_NUM) {
RandRemoveAndroid();
}
NotifyUiUpdate();
}
@ -251,16 +259,24 @@ void Room::CreateAndroid(int robot_num)
hum->meta = hum_meta;
hum->robot_meta = robot_meta;
hum->entity_uniid = AllocUniid();
hum->born_point = AllocBornPoint();
{
hum->pos.x = 200 + rand() % 500;
hum->pos.y = 300 + rand() % 300;
hum->attack_dir = hum->pos;
const MetaData::MapTplThing& thing_tpl = (*born_points_)[hum->born_point];
hum->pos.x = thing_tpl.i->x();
hum->pos.y = thing_tpl.i->y();
hum->attack_dir = a8::Vec2::UP;
hum->attack_dir.Normalize();
hum->attack_dir.Rotate(a8::RandAngle());
if (!thing_tpl.born_angle.empty()){
float angle = thing_tpl.born_angle[rand() % thing_tpl.born_angle.size()];
hum->attack_dir.Rotate(angle / 180.0f);
} else {
hum->attack_dir.Rotate(a8::RandAngle());
}
hum->move_dir = hum->attack_dir;
}
hum->room = this;
hum->Initialize();
born_point_human_hash_[hum->born_point] = hum;
uniid_hash_[hum->entity_uniid] = hum;
moveable_hash_[hum->entity_uniid] = hum;
human_hash_[hum->entity_uniid] = hum;
@ -627,6 +643,20 @@ void Room::OnHumanDie(Human* hum)
void Room::OnHumanRevive(Human* hum)
{
{
const MetaData::MapTplThing& thing_tpl = (*born_points_)[hum->born_point];
hum->pos.x = thing_tpl.i->x();
hum->pos.y = thing_tpl.i->y();
hum->attack_dir = a8::Vec2::UP;
hum->attack_dir.Normalize();
if (!thing_tpl.born_angle.empty()){
float angle = thing_tpl.born_angle[rand() % thing_tpl.born_angle.size()];
hum->attack_dir.Rotate(angle / 180.0f);
} else {
hum->attack_dir.Rotate(a8::RandAngle());
}
hum->move_dir = hum->attack_dir;
}
++alive_count_;
NotifyUiUpdate();
}
@ -954,6 +984,7 @@ void Room::RandRemoveAndroid()
}
cell->human_list.erase(hum);
}
born_point_human_hash_.erase(hum->born_point);
moveable_hash_.erase(hum->entity_uniid);
uniid_hash_.erase(hum->entity_uniid);
human_hash_.erase(hum->entity_uniid);
@ -1043,3 +1074,23 @@ void Room::BattleReport()
game_over_frameno = frame_no;
RoomMgr::Instance()->AddOverRoom(room_uuid);
}
int Room::AllocBornPoint()
{
std::set<int> points;
for (int i = 0; i < ROOM_MAX_PLAYER_NUM; ++i) {
points.insert(i);
}
for (auto& pair : born_point_human_hash_) {
points.erase(pair.first);
}
if (points.empty()) {
abort();
return -1;
}
std::vector<int> point_vec;
for (int point : points) {
point_vec.push_back(point);
}
return point_vec[rand() % point_vec.size()];
}

View File

@ -108,6 +108,7 @@ private:
void NotifyUiUpdate();
void NotifyWxVoip();
void BattleReport();
int AllocBornPoint();
private:
int elapsed_time_ = 0;
@ -117,6 +118,7 @@ private:
int current_teamid = 0;
int current_uniid = 0;
std::map<int, Human*> born_point_human_hash_;
std::vector<MetaData::MapTplThing>* born_points_ = nullptr;
xtimer_list* battle_report_timer_ = nullptr;

View File

@ -232,4 +232,5 @@ message MapTplThingJson
optional float x = 5;
optional float y = 6;
optional int32 is_born_point = 7;
optional string born_angle = 8;
}