448 lines
16 KiB
C++
448 lines
16 KiB
C++
#pragma once
|
|
|
|
#include <a8/xtimer.h>
|
|
#include <f8/timer.h>
|
|
|
|
#include "frameevent.h"
|
|
#include "framemaker.h"
|
|
#include "gridservice.h"
|
|
#include "mapservice.h"
|
|
#include "gasdata.h"
|
|
#include "pvedata.h"
|
|
|
|
namespace cs
|
|
{
|
|
class SMJoinedNotify;
|
|
}
|
|
|
|
namespace mt
|
|
{
|
|
struct RankMatchConf;
|
|
}
|
|
|
|
class Entity;
|
|
class RoomEntity;
|
|
class MoveableEntity;
|
|
class Obstacle;
|
|
class RoomObstacle;
|
|
class Bullet;
|
|
class Human;
|
|
class Player;
|
|
class Android;
|
|
class Car;
|
|
class Hero;
|
|
class Incubator;
|
|
class Team;
|
|
class AirDrop;
|
|
class AirRaid;
|
|
struct BornPoint;
|
|
class MapInstance;
|
|
struct RoomInitInfo;
|
|
struct FrameEventData;
|
|
class SandTable;
|
|
class BatchSync;
|
|
class CustomBattle;
|
|
class RoomAgent;
|
|
class RoomOb;
|
|
|
|
struct Plane
|
|
{
|
|
glm::vec3 start_point;
|
|
glm::vec3 end_point;
|
|
glm::vec3 dir;
|
|
glm::vec3 curr_pos;
|
|
};
|
|
|
|
struct CarObject
|
|
{
|
|
int car_id = 0;
|
|
glm::vec3 pos;
|
|
bool taken = false;
|
|
};
|
|
|
|
enum RoomSwitch_e
|
|
{
|
|
kRoomSwitchDisableMove = 0,
|
|
kRoomSwitchDisableUseSkill,
|
|
kRoomSwitchDisableUseItem,
|
|
kRoomSwitchDisableShot,
|
|
};
|
|
|
|
class Room
|
|
{
|
|
public:
|
|
FrameEvent frame_event;
|
|
std::shared_ptr<FrameEventData> frame_event_data;
|
|
FrameMaker frame_maker;
|
|
a8::XTimer xtimer;
|
|
Plane plane;
|
|
f8::Attacher timer_attacher;
|
|
a8::Attacher xtimer_attacher_;
|
|
std::shared_ptr<GridService> grid_service;
|
|
std::shared_ptr<MapService> map_service;
|
|
std::shared_ptr<MapInstance> map_instance;
|
|
bool debug_trace = false;
|
|
bool added_to_over_room = false;
|
|
glm::vec3 last_player_jump_pos;
|
|
std::map<int, EntityWeakPtr> mine_objects;
|
|
const mt::PveGeminiMode* pve_mode_meta = nullptr;
|
|
const mt::PveGemini* pve_instance = nullptr;
|
|
int pve_human_num = 0;
|
|
PveData pve_data;
|
|
bool stop_world = false;
|
|
//target_uniid, frameno
|
|
std::map<int, long long> report_bullet_hash;
|
|
a8::XTimerWp game_over_timer;
|
|
a8::XTimerWp moba_over_timer;
|
|
#ifdef MYDEBUG
|
|
std::map<int, int> debug_params;
|
|
#endif
|
|
|
|
~Room();
|
|
void InitData(RoomInitInfo& init_info);
|
|
void Init();
|
|
void UnInit();
|
|
void Update(int delta_time);
|
|
|
|
inline long long GetFrameNo() { return frameno_; }
|
|
long long GetBattleStartFrameNo() { return battle_start_frameno_; }
|
|
bool IsGameOver() { return game_over_; }
|
|
bool IsGameTimeOut() { return game_timeout_; }
|
|
bool IsForceOver() { return force_over_; }
|
|
const GasData& GetGasData() { return gas_data_; }
|
|
RoomType_e GetRoomType() { return room_type_; }
|
|
RoomMode_e GetRoomMode() { return room_mode_; }
|
|
std::string GetRoomUuid() { return room_uuid_; }
|
|
int GetRoomIdx() { return room_idx_; }
|
|
std::string GetMapTplName() { return map_tpl_name_; }
|
|
const mt::Map* GetMapMeta() { return map_meta_; }
|
|
bool IsBattleStarting() { return battle_starting_; };
|
|
std::shared_ptr<CustomBattle> GetCustomBattle() { return custom_battle_; }
|
|
bool IsPveRoom();
|
|
bool IsDestoryRoom();
|
|
bool IsSurvivalRoom();
|
|
bool IsPvpRankModeRoom() { return GetRoomMode() == kPvpRankMode; }
|
|
bool IsPvpMasterRankModeRoom();
|
|
bool IsMobaModeRoom() { return GetRoomMode() == kMobaMode; }
|
|
|
|
int GetPlayerNum();
|
|
int GetHumanNum();
|
|
int AliveCount();
|
|
long long AliveCountChgFrameNo() { return alive_count_chged_frameno_; };
|
|
inline int RealAliveCount() { return alive_human_hash_.size(); }
|
|
inline int GetAlivePlayerCount() { return alive_player_hash_.size(); }
|
|
Player* GetPlayerByAccountId(const std::string& accountid);
|
|
Player* GetPlayerByUniId(int uniid);
|
|
Entity* GetEntityByUniId(int uniid);
|
|
Creature* GetCreatureByUniId(int uniid);
|
|
Human* GetHumanByUniId(int uniid);
|
|
void OnEnterNewWave(int wave);
|
|
|
|
Player* NewPlayer();
|
|
void AddPlayer(Player* hum, std::shared_ptr<BornPoint> init_born_point = nullptr, bool no_matchteam = false);
|
|
|
|
void RemoveObjectLater(RoomEntity* entity);
|
|
void RemoveObjectLater(RoomObstacle* entity);
|
|
|
|
void FillSMJoinedNotify(Human* self_hum, cs::SMJoinedNotify& msg);
|
|
|
|
void TraversePlayerList(std::function<void (Player*)> cb);
|
|
void TraverseRawPlayerList(std::function<void (Player*)> cb);
|
|
void TraverseHumanList(std::function<bool (Human*)> cb);
|
|
void TraverseRawHumanList(std::function<bool (Human*)> cb);
|
|
void TraverseAliveHumanList(std::function<bool (Human*)> func);
|
|
void TraverseEntityList(std::function<bool (Entity*)> func);
|
|
void TraverseAlivePlayers(std::function<bool (Human*)> func);
|
|
void BroadcastDebugMsg(const std::string& debug_msg);
|
|
|
|
void ScatterDrop(const glm::vec3& center, int drop_id, bool no_adjust = false);
|
|
void DropItem(const glm::vec3& pos, int item_id, int item_count, int item_lv, bool no_adjust =false);
|
|
void DropItemEx(const glm::vec3& born_pos, const glm::vec3& pos, int item_id, int item_count, int item_lv, bool show_anim, bool no_adjust = false);
|
|
|
|
int CreateLoot(int equip_id, const glm::vec3& born_pos, const glm::vec3& pos, int count, int equip_lv, bool no_adjust = false);
|
|
int CreateLootEx(int equip_id, const glm::vec3& born_pos, const glm::vec3& pos, int count, int equip_lv, bool show_anim, bool no_adjust = false);
|
|
int CreateBullet(Creature* sender,
|
|
Creature* passenger,
|
|
const mt::Equip* weapon_meta,
|
|
const mt::Equip* bullet_meta,
|
|
const mt::Skill* skill_meta,
|
|
glm::vec3 pos,
|
|
glm::vec3 dir,
|
|
float fly_distance,
|
|
long long weapon_uniid,
|
|
int trace_target_id,
|
|
int hand,
|
|
a8::XTimerWp keep_shot_animi_timer_ptr,
|
|
float shot_animi_time,
|
|
int weapon_buff_id,
|
|
std::shared_ptr<std::set<int>> reporter_list,
|
|
int shot_uniid,
|
|
std::function<void(Bullet*)> on_bullet_exit);
|
|
Car* CreateCar(Human* driver,
|
|
int car_uniid,
|
|
const mt::Equip* meta,
|
|
const glm::vec3& pos,
|
|
int team_id,
|
|
std::set<int>* special_operators);
|
|
Hero* CreateHero(Creature* master,
|
|
const mt::Hero* meta,
|
|
const glm::vec3& pos,
|
|
const glm::vec3& dir,
|
|
int team_id,
|
|
int obj_uniid = 0);
|
|
|
|
void OnHumanDie(Human* hum);
|
|
void OnHumanRevive(Human* hum);
|
|
bool OverBorder(const glm::vec3& pos, float radius);
|
|
Human* GetWatchWarTarget(Human* hum);
|
|
bool BattleStarted();
|
|
int GetTeamNum();
|
|
Team* GetTeam(int team_id);
|
|
int GetAliveTeamNum();
|
|
Team* GetAliveTeam();
|
|
void TraverseTeams(std::function<bool (Team*)> cb);
|
|
void TraverseRawTeams(std::function<bool (Team*)> cb);
|
|
bool CanJoin(const std::string& accountid,
|
|
RoomType_e self_roomm_type,
|
|
RoomMode_e self_room_mode,
|
|
int self_proto_version,
|
|
int self_channel,
|
|
int init_map_id,
|
|
const cs::CMJoin& msg);
|
|
void OnPlayerOffline(Player* hum);
|
|
void FillSMUiUpdate(cs::SMUiUpdate& msg);
|
|
void NotifyUiUpdate();
|
|
void UpdateCarObject(int old_uniid, int new_uniid, glm::vec3 pos);
|
|
void TakeOnCarObject(int car_uniid);
|
|
void TakeOffCarObject(int car_uniid, glm::vec3 pos);
|
|
int CreateAndTakeonCar(int car_id, glm::vec3 pos);
|
|
bool HaveMyTeam(const std::string& team_uuid);
|
|
long long GetGasInactiveTime();
|
|
long long GetGasInactiveReaminTime();
|
|
void CheckPartObjects(Human* testa = nullptr, Human* testb = nullptr);
|
|
bool RuningInTimer();
|
|
Human* GetOneCanEnableAndroid();
|
|
void GetCanEnableAndroids(std::vector<Human*>& humans, size_t num);
|
|
Player* GetOneAlivePlayer();
|
|
void GetAlivePlayers(std::vector<Player*>& humans, size_t num);
|
|
int GetCanShuaNum(int shua_num);
|
|
void RemoveRescue(Human* hum);
|
|
void NotifyCountdown(const std::string& msg, int time);
|
|
void NotifySysPiao(const std::string& msg, int color, int duration);
|
|
int GetOnlinePlayerNum();
|
|
RoomObstacle* CreateObstacle(int id, float x, float y, float z,
|
|
std::shared_ptr<a8::Args> init_args = nullptr);
|
|
int AllocUniid();
|
|
std::shared_ptr<Incubator>& GetIncubator() { return incubator_;};
|
|
void GetPartObjectWatchList(Entity* entity, std::vector<Human*>& watch_list);
|
|
void SetInfiniteBulletMode();
|
|
bool IsInfiniteBulletMode() { return infinite_bullet_mode_; };
|
|
void AddToPostBattleAutoFreeList(a8::XTimerWp timer);
|
|
bool CanAddObstacle(const glm::vec3& pos, int obstacle_id);
|
|
void AddTask(int task_uniid, std::shared_ptr<a8::CommonCbProcEx> cb);
|
|
void RemoveTask(int task_uniid);
|
|
const mt::AirLine* GetAirLine() { return airline_; }
|
|
int GetPolyExtFlag(int poly_idx);
|
|
size_t GetRoomMaxPlayerNum();
|
|
bool RandomSafeAreaPoint(glm::vec3& point);
|
|
bool FindWalkablePointWithOutHouse(const glm::vec3& center, int try_count, int step, glm::vec3& out_point);
|
|
void AddReportBullet(int bullet_uniid);
|
|
bool IsDestorying() { return destorying_; }
|
|
void SetVictoryTeam(Team* team) { victory_team_ = team;};
|
|
Team* GetVictoryTeam() { return victory_team_;};
|
|
int GetReportRoomMode();
|
|
int GetPvpMatchMode();
|
|
void ForceOver();
|
|
bool SupportSandTable();
|
|
std::shared_ptr<SandTable> GetSandTable() { return sand_table_; }
|
|
bool IsSandTableRoom();
|
|
void LockRoom();
|
|
void CombineTeam();
|
|
void FillTeam();
|
|
bool HasRoomSwitch(int tag);
|
|
void OpenRoomSwitch(int tag);
|
|
void CloseRoomSwitch(int tag);
|
|
void NotifyNewsTicker(int msg_type, std::vector<std::string> msg_content);
|
|
void NotifyKillList(const std::vector<int>& uniid_list);
|
|
std::shared_ptr<AirRaid> GetAirRaid() { return air_raid_; }
|
|
std::shared_ptr<BatchSync> GetBatchSync() { return batch_sync_; }
|
|
void GMFastForward();
|
|
bool BulletCanReach(const glm::vec3& start, const glm::vec3& end);
|
|
bool MoveCanReach(const glm::vec3& start, const glm::vec3& end);
|
|
const mt::RankMatchConf* GetRankMatchConf() { return rank_match_conf_; }
|
|
bool IsCustomBattle() { return custom_battle_ != nullptr;}
|
|
int GetMaxTeamNum();
|
|
bool IsMiniMap();
|
|
bool IsNewerMap();
|
|
int GetMobaLeftTime();
|
|
Team* GetMobaTeamA() { return moba_team_a_; }
|
|
Team* GetMobaTeamB() { return moba_team_b_; }
|
|
Team* GetMobaEnemyTeam(Team* self_team);
|
|
RoomAgent* GetRoomAgent() { return room_agent_; }
|
|
int GenShotUniid() { return ++current_shot_uniid_; }
|
|
int InitWithCustomBattle(long ip_saddr, int socket_handle, std::shared_ptr<cs::CMJoin> msg,
|
|
std::shared_ptr<CustomBattle> p);
|
|
void CreateAndroid(int android_num, std::shared_ptr<Team> team = nullptr);
|
|
int GetFullLevelIdx() { return ++curr_full_level_idx_;}
|
|
std::shared_ptr<RoomOb> GetRoomOb();
|
|
void SendSMTeamFull(Human* hum);
|
|
void OnTeamPartChg(Human* hum);
|
|
|
|
private:
|
|
void ShuaAndroid();
|
|
void UpdateGas();
|
|
void UpdateGasInactive();
|
|
void UpdateGasInactivePvp();
|
|
void UpdateGasInactivePve();
|
|
void UpdateGasInactiveMoba();
|
|
void UpdateGasWaiting();
|
|
void UpdateGasMoving();
|
|
void UpdateGasJump();
|
|
bool GenSmallCircle();
|
|
void MatchTeam(Human* hum);
|
|
void ShuaPlane();
|
|
std::shared_ptr<Team> NewTeam();
|
|
std::shared_ptr<Team> NewViewTeam();
|
|
RoomObstacle* InternalCreateObstacle(int id, float x, float y, float z,
|
|
std::function<void (Obstacle*)> on_precreate,
|
|
std::shared_ptr<a8::Args> init_args = nullptr);
|
|
void AddObjectLater(RoomEntity* entity);
|
|
void OnGameOver();
|
|
void RandRemoveAndroid();
|
|
std::shared_ptr<BornPoint> AllocBornPoint(Human* hum);
|
|
std::shared_ptr<BornPoint> GetBornPoint(int point_uniid);
|
|
void CreateWorldObjects();
|
|
void IncBornPointHumanNum(std::shared_ptr<BornPoint> point, Human* hum);
|
|
void DecBornPointHumanNum(std::shared_ptr<BornPoint> point, Human* hum);
|
|
void NotifyGameStart();
|
|
void EnableHuman(Human* hum);
|
|
void DisableHuman(Human* hum);
|
|
bool HasPlayerInRound(const glm::vec3& pos, float rad);
|
|
|
|
void AddToEntityHash(Entity* entity);
|
|
void AddToHumanHash(Human* hum);
|
|
void AddToAliveHumanHash(Human* hum);
|
|
void AddToMoveableHash(MoveableEntity* entity);
|
|
void AddToAccountHash(Player* hum);
|
|
void AddToLaterAddHash(RoomEntity* entity);
|
|
void AddToRemovedRobotHash(Human* hum);
|
|
void RemoveFromEntityHash(Entity* entity);
|
|
void RemoveFromMoveableHash(MoveableEntity* entity);
|
|
void RemoveFromHuamnHash(Human* hum);
|
|
void RemoveFromAliveHumanHash(Human* hum);
|
|
void RemoveFromLaterAddHash(RoomEntity* entity);
|
|
|
|
void AddPlayerPostProc(Player* hum);
|
|
void ForceSetBornPoint(Human* hum, std::shared_ptr<BornPoint> born_point);
|
|
std::shared_ptr<BornPoint> ForceTakeBornPoint(Human* hum, std::shared_ptr<BornPoint> reserve_born_point);
|
|
bool CanAddToScene(Human* hum);
|
|
void SyncFrameData();
|
|
void InitAndroidAI();
|
|
void ForwardGasRing(int n);
|
|
void InternalRemoveObjectLater(Entity* entity, a8::Attacher& entity_xtimer_attacher);
|
|
void OnBattleStart();
|
|
void ClearPostBattleAutoFreeList();
|
|
void OnAddHuman(Human* hum);
|
|
|
|
#ifdef MYDEBUG
|
|
void InitDebugInfo();
|
|
void UnInitDebugInfo();
|
|
#endif
|
|
|
|
bool IsAllRealDead();
|
|
void AutoJump();
|
|
void IncAliveCount();
|
|
void DecAliveCount();
|
|
|
|
private:
|
|
bool destorying_ = false;
|
|
std::vector<int> poly_ext_datas_;
|
|
int room_idx_ = 0;
|
|
RoomMode_e room_mode_ = kPvpMode;
|
|
std::string room_uuid_;
|
|
const mt::Map* map_meta_ = nullptr;
|
|
std::string map_tpl_name_;
|
|
RoomType_e room_type_ = RoomType_NewBrid;
|
|
|
|
GasData gas_data_;
|
|
long long frameno_ = 0;
|
|
long long battle_start_frameno_ = 0;
|
|
bool game_timeout_ = false;
|
|
bool game_over_ = false;
|
|
long long game_over_frameno_ = 0;
|
|
int elapsed_time_ = 0;
|
|
int alive_count_ = 0;
|
|
long long alive_count_chged_frameno_ = 0;
|
|
int battle_human_count_ = 0;
|
|
int battle_player_count_ = 0;
|
|
int battle_team_count_ = 0;
|
|
const mt::AirLine* airline_ = nullptr;
|
|
bool show_handed_ = false;
|
|
int creator_game_times_ = 0;
|
|
int creator_register_time_ = 0;
|
|
int creator_proto_version_ = 0;
|
|
int creator_channel_ = 0;
|
|
a8::XTimerWp battle_report_timer_;
|
|
|
|
int current_teamid_ = 0;
|
|
int current_uniid_ = FIXED_OBJECT_MAXID;
|
|
int current_shot_uniid_ = 0;
|
|
|
|
std::set<int> refreshed_robot_set_;
|
|
std::map<int, std::shared_ptr<Team>> team_hash_;
|
|
std::map<int, std::shared_ptr<Team>> combineable_team_hash_;
|
|
std::map<std::string, Player*> accountid_hash_;
|
|
std::map<int, MoveableEntity*> moveable_hash_;
|
|
std::map<int, Entity*> uniid_hash_;
|
|
std::map<int, RoomEntity*> later_add_hash_;
|
|
std::map<int, Human*> human_hash_;
|
|
std::map<int, Human*> alive_human_hash_;
|
|
std::map<int, Human*> alive_player_hash_;
|
|
std::map<int, Human*> last_human_hash_;
|
|
std::map<int, Human*> team_part_chg_human_hash_;
|
|
std::map<int, std::shared_ptr<BornPoint>> born_point_hash_;
|
|
std::map<int, std::shared_ptr<a8::CommonCbProcEx>> task_hash_;
|
|
|
|
std::map<int, CarObject> car_hash_;
|
|
std::map<int, Human*> removed_robot_hash_;
|
|
|
|
std::vector<a8::XTimerWp> post_battle_auto_free_list_;
|
|
|
|
a8::XTimerWp auto_jump_timer_;
|
|
|
|
std::shared_ptr<Incubator> incubator_;
|
|
std::shared_ptr<SandTable> sand_table_;
|
|
std::shared_ptr<CustomBattle> custom_battle_;
|
|
|
|
bool infinite_bullet_mode_ = false;
|
|
|
|
bool battle_starting_ = false;
|
|
|
|
std::shared_ptr<AirDrop> air_drop_;
|
|
std::shared_ptr<AirRaid> air_raid_;
|
|
std::shared_ptr<BatchSync> batch_sync_;
|
|
|
|
Team* victory_team_ = nullptr;
|
|
bool force_over_ = false;
|
|
bool lock_room_ = false;
|
|
long long lock_room_frameno_ = 0;
|
|
a8::XTimerWp lock_room_timer_;
|
|
|
|
long long room_switch_ = 0;
|
|
long long acc_inactive_time_ = 0;
|
|
|
|
int curr_full_level_idx_ = 0;
|
|
|
|
const mt::RankMatchConf* rank_match_conf_ = nullptr;
|
|
|
|
Team* moba_team_a_ = nullptr;
|
|
Team* moba_team_b_ = nullptr;
|
|
|
|
std::shared_ptr<RoomOb> ob_;
|
|
|
|
RoomAgent* room_agent_;
|
|
|
|
friend class Incubator;
|
|
friend class Team;
|
|
};
|