1
This commit is contained in:
parent
2a2c8273e7
commit
cb19bbe4c0
@ -54,8 +54,13 @@ void Android::GiveEquip()
|
||||
MetaData::Equip* weapon_meta = MetaMgr::Instance()->GetEquip(tank_meta_->i->bullet_id());
|
||||
if (weapon_meta) {
|
||||
weapons[kGUN_SLOT1].weapon_idx = kGUN_SLOT1;
|
||||
#if 1
|
||||
weapons[kGUN_SLOT1].weapon_id = 12001 + rand() % 11;
|
||||
weapons[kGUN_SLOT1].weapon_lv = rand() % 3;
|
||||
#else
|
||||
weapons[kGUN_SLOT1].weapon_id = weapon_meta->i->id();
|
||||
weapons[kGUN_SLOT1].weapon_lv = robot_meta->i->weapon_lv();
|
||||
#endif
|
||||
weapons[kGUN_SLOT1].ammo = 0;
|
||||
weapons[kGUN_SLOT1].meta = weapon_meta;
|
||||
weapons[kGUN_SLOT1].Recalc();
|
||||
|
@ -12,7 +12,9 @@ class Android : public Human
|
||||
{
|
||||
public:
|
||||
AndroidAI* ai = nullptr;
|
||||
#if 0
|
||||
MetaData::Robot* robot_meta = nullptr;
|
||||
#endif
|
||||
|
||||
Android();
|
||||
virtual ~Android() override;
|
||||
|
@ -34,8 +34,52 @@ Room::~Room()
|
||||
|
||||
}
|
||||
|
||||
void Room::Init()
|
||||
void Room::Init(const cs::CMJoin& msg)
|
||||
{
|
||||
{
|
||||
room_unionid = msg.team_uuid();
|
||||
{
|
||||
RoomMember p;
|
||||
p.accountid = msg.account_id();
|
||||
p.name = msg.name();
|
||||
p.avatar_url = msg.avatar_url();
|
||||
p.tank_id = msg.baseskin();
|
||||
p.tankskin_id = msg.tankskin().skin_id();
|
||||
members_hash_[p.accountid] = p;
|
||||
}
|
||||
for (auto& member : msg.room_member()) {
|
||||
if (members_hash_.size() < kROOM_MAX_PLAYER_NUM) {
|
||||
RoomMember p;
|
||||
p.accountid = member.account_id();
|
||||
p.name = member.name();
|
||||
p.avatar_url = member.avatar_url();
|
||||
p.tank_id = member.skin().skin_id();
|
||||
p.tankskin_id = member.tankskin().skin_id();
|
||||
members_hash_[p.accountid] = p;
|
||||
}
|
||||
}
|
||||
int try_count = 0;
|
||||
while (members_hash_.size() < kROOM_MAX_PLAYER_NUM) {
|
||||
if (try_count > 3000) {
|
||||
abort();
|
||||
}
|
||||
std::vector<MetaData::Robot>* robot_list = MetaMgr::Instance()->GetRobotList();
|
||||
if (robot_list && !robot_list->empty()) {
|
||||
MetaData::Robot& tmp_robot_meta = (*robot_list)[rand() % robot_list->size()];
|
||||
std::string robot_id = a8::Format("$robot_%d", {tmp_robot_meta.i->id()});
|
||||
if (members_hash_.find(robot_id) == members_hash_.end()) {
|
||||
RoomMember p;
|
||||
p.accountid = robot_id;
|
||||
p.name = tmp_robot_meta.i->name();
|
||||
p.avatar_url = "";
|
||||
p.tank_id = MetaMgr::Instance()->RandTank();
|
||||
p.tankskin_id = 0;
|
||||
members_hash_[p.accountid] = p;
|
||||
}
|
||||
}
|
||||
++try_count;
|
||||
}
|
||||
}
|
||||
xtimer.Init(RoomXGetTickCount, this, 100, 100);
|
||||
xtimer_attacher.xtimer = &xtimer;
|
||||
frame_event.room = this;
|
||||
@ -58,7 +102,9 @@ void Room::Init()
|
||||
if (!born_points_ || born_points_->size() != kROOM_MAX_PLAYER_NUM) {
|
||||
abort();
|
||||
}
|
||||
#if 0
|
||||
ShuaAndroid();
|
||||
#endif
|
||||
}
|
||||
|
||||
void Room::UnInit()
|
||||
@ -159,9 +205,19 @@ int Room::AliveCount()
|
||||
void Room::AddPlayer(Player* hum)
|
||||
{
|
||||
assert(gas_data.gas_mode == kGasInactive);
|
||||
{
|
||||
auto itr = members_hash_.find(hum->account_id);
|
||||
if (itr != members_hash_.end()) {
|
||||
itr->second.online = true;
|
||||
} else {
|
||||
abort();
|
||||
}
|
||||
}
|
||||
#if 0
|
||||
while (human_hash_.size() + 1 > kROOM_MAX_PLAYER_NUM) {
|
||||
RandRemoveAndroid();
|
||||
}
|
||||
#endif
|
||||
hum->entity_uniid = AllocUniid();
|
||||
hum->born_point = AllocBornPoint();
|
||||
{
|
||||
@ -264,7 +320,9 @@ void Room::CreateAndroid(int robot_num)
|
||||
Android* hum = new Android();
|
||||
hum->name = robot_meta->i->name();
|
||||
hum->SetMeta(hum_meta);
|
||||
#if 0
|
||||
hum->robot_meta = robot_meta;
|
||||
#endif
|
||||
hum->entity_uniid = AllocUniid();
|
||||
hum->born_point = AllocBornPoint();
|
||||
{
|
||||
@ -757,11 +815,17 @@ bool Room::CanJoin(const cs::CMJoin& msg)
|
||||
if (accountid_hash_.find(msg.account_id()) != accountid_hash_.end()) {
|
||||
return false;
|
||||
}
|
||||
if (members_hash_.find(msg.account_id()) == members_hash_.end()) {
|
||||
return false;
|
||||
}
|
||||
return msg.team_uuid() == room_unionid;
|
||||
#if 0
|
||||
if (App::Instance()->HasFlag(5)) {
|
||||
return accountid_hash_.size() < 1;
|
||||
} else {
|
||||
return accountid_hash_.size() < kROOM_MAX_PLAYER_NUM;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
void Room::OnPlayerOffline(Player* hum)
|
||||
@ -848,10 +912,14 @@ void Room::UpdateGas()
|
||||
MetaMgr::Instance()->gas_inactive_time * kSERVER_FRAME_RATE) {
|
||||
gas_data.gas_mode = kGasStarted;
|
||||
gas_data.gas_start_frameno = frameno;
|
||||
#if 1
|
||||
SpllyAndroid();
|
||||
#else
|
||||
if (human_hash_.size() < kROOM_MAX_PLAYER_NUM) {
|
||||
CreateAndroid(kROOM_MAX_PLAYER_NUM - human_hash_.size());
|
||||
NotifyUiUpdate();
|
||||
}
|
||||
#endif
|
||||
NotifyWxVoip();
|
||||
RoomMgr::Instance()->ActiveRoom(room_uuid);
|
||||
battle_start_frameno_ = frameno;
|
||||
@ -1242,3 +1310,54 @@ void Room::GenDrop(MetaData::AirDrop* air_drop, int drop_id, int airdrop_point_i
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Room::SpllyAndroid()
|
||||
{
|
||||
MetaData::Player* hum_meta = MetaMgr::Instance()->GetPlayer(40002);
|
||||
assert(hum_meta);
|
||||
if (!hum_meta) {
|
||||
abort();
|
||||
}
|
||||
for (auto& pair : members_hash_) {
|
||||
if (GetPlayerByAccountId(pair.second.accountid)) {
|
||||
continue;
|
||||
}
|
||||
Android* hum = new Android();
|
||||
hum->name = pair.second.name;
|
||||
hum->SetMeta(hum_meta);
|
||||
#if 0
|
||||
hum->robot_meta = robot_meta;
|
||||
#endif
|
||||
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->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;
|
||||
++alive_count_;
|
||||
grid_service.AddHuman(hum);
|
||||
hum->RefreshView();
|
||||
{
|
||||
hum->team_id = NewTeam();
|
||||
hum->team_members = &team_hash_[hum->team_id];
|
||||
hum->team_members->insert(hum);
|
||||
}
|
||||
}
|
||||
NotifyUiUpdate();
|
||||
}
|
||||
|
@ -23,6 +23,16 @@ namespace MetaData
|
||||
struct AirDrop;
|
||||
}
|
||||
|
||||
struct RoomMember
|
||||
{
|
||||
std::string accountid;
|
||||
std::string name;
|
||||
std::string avatar_url;
|
||||
int tank_id = 0;
|
||||
int tankskin_id = 0;
|
||||
bool online = false;
|
||||
};
|
||||
|
||||
struct timer_list;
|
||||
struct xtimer_list;
|
||||
class Entity;
|
||||
@ -54,9 +64,10 @@ public:
|
||||
long long battle_start_frameno_ = 0;
|
||||
long long pending_request = 0;
|
||||
int last_kill_timeseq = 0;
|
||||
std::string room_unionid;
|
||||
|
||||
~Room();
|
||||
void Init();
|
||||
void Init(const cs::CMJoin& msg);
|
||||
void UnInit();
|
||||
void Update(int delta_time);
|
||||
int GetPlayerNum();
|
||||
@ -125,6 +136,7 @@ private:
|
||||
void InitAirDrop();
|
||||
void AirDrop(MetaData::AirDrop* air_drop);
|
||||
void GenDrop(MetaData::AirDrop* air_drop, int drop_id, int airdrop_point_id);
|
||||
void SpllyAndroid();
|
||||
|
||||
private:
|
||||
int elapsed_time_ = 0;
|
||||
@ -148,4 +160,6 @@ private:
|
||||
|
||||
std::map<int, std::set<int>> airdrop_hash_;
|
||||
std::map<int, Human*> removed_robot_hash_;
|
||||
|
||||
std::map<std::string, RoomMember> members_hash_;
|
||||
};
|
||||
|
@ -60,7 +60,8 @@ void RoomMgr::_CMJoin(f8::MsgHdr& hdr, const cs::CMJoin& msg)
|
||||
}
|
||||
room->map_tpl_name = room->map_meta->i->template_name();
|
||||
assert(MetaMgr::Instance()->GetMapTplSize(room->map_tpl_name, room->map_width, room->map_height));
|
||||
room->Init();
|
||||
room->Init(msg);
|
||||
room_unionid_hash_[msg.team_uuid()] = room;
|
||||
inactive_room_hash_[room->room_uuid] = room;
|
||||
room_hash_[room->room_uuid] = room;
|
||||
}
|
||||
@ -123,6 +124,7 @@ void RoomMgr::AddOverRoom(long long room_uuid)
|
||||
if (room) {
|
||||
if ((room->pending_request <= 0) ||
|
||||
(a8::XGetTickCount() - room->game_over_tick > 1000 * 8)) {
|
||||
RoomMgr::Instance()->room_unionid_hash_.erase(room->room_unionid);
|
||||
RoomMgr::Instance()->room_hash_.erase(room->room_uuid);
|
||||
RoomMgr::Instance()->over_room_hash_[room->room_uuid] = room;
|
||||
RoomMgr::Instance()->FreeOverRoom(param.sender);
|
||||
@ -143,6 +145,12 @@ void RoomMgr::AddOverRoom(long long room_uuid)
|
||||
|
||||
void RoomMgr::ActiveRoom(long long room_uuid)
|
||||
{
|
||||
{
|
||||
auto itr = inactive_room_hash_.find(room_uuid);
|
||||
if (itr != inactive_room_hash_.end()) {
|
||||
room_unionid_hash_.erase(itr->second->room_unionid);
|
||||
}
|
||||
}
|
||||
inactive_room_hash_.erase(room_uuid);
|
||||
}
|
||||
|
||||
|
@ -39,5 +39,6 @@ class RoomMgr : public a8::Singleton<RoomMgr>
|
||||
std::map<long long, Room*> inactive_room_hash_;
|
||||
std::map<long long, Room*> room_hash_;
|
||||
std::map<long long, Room*> over_room_hash_;
|
||||
std::map<std::string, Room*> room_unionid_hash_;
|
||||
a8::TimerAttacher reportstate_timer_attacher_;
|
||||
};
|
||||
|
Loading…
x
Reference in New Issue
Block a user