aozhiwei ec9b1dc98f 1
2019-07-25 15:53:40 +08:00

151 lines
4.4 KiB
C++

#pragma once
#include <a8/xtimer.h>
#include <a8/timer_attacher.h>
#include "frameevent.h"
#include "framemaker.h"
#include "gridservice.h"
#include "mapservice.h"
#include "metadata.h"
namespace cs
{
class SMUiUpdate;
}
namespace MetaData
{
struct Map;
struct SafeArea;
struct Building;
struct AirDrop;
}
struct timer_list;
struct xtimer_list;
class Entity;
class Obstacle;
class Bullet;
class Human;
class Player;
class Building;
class Hero;
class Room
{
public:
long long room_uuid = 0;
MetaData::Map* map_meta = nullptr;
std::string map_tpl_name;
int map_width = 0;
int map_height = 0;
FrameEvent frame_event;
FrameMaker frame_maker;
long long frameno = 0;
GasData gas_data;
bool game_over = false;
long long game_over_frameno = 0;
long long game_over_tick = 0;
timer_list* game_over_timer = nullptr;
a8::XTimer xtimer;
GridService grid_service;
MapService map_service;
long long battle_start_frameno_ = 0;
long long pending_request = 0;
int last_kill_timeseq = 0;
~Room();
void Init();
void UnInit();
void Update(int delta_time);
int GetPlayerNum();
int AliveCount();
Player* GetPlayerByAccountId(const std::string& accountid);
Player* GetPlayerByUniId(int uniid);
Human* GetHumanByUniId(int uniid);
Entity* GetEntityByUniId(int uniid);
void AddPlayer(Player* hum);
Human* FindEnemy(Human* hum);
void RemoveObjectLater(Entity* entity);
void FetchBuilding(Human* hum);
void FillSMJoinedNotify(Player* self_hum, cs::SMJoinedNotify& msg);
void TouchPlayerList(a8::XParams param,
std::function<void (Player*, a8::XParams&)> func);
void TouchHumanList(a8::XParams param,
std::function<bool (Human*, a8::XParams&)> func);
void TouchEntityList(a8::XParams param,
std::function<bool (Entity*, a8::XParams&)> func);
void ScatterDrop(a8::Vec2 center, int drop_id);
void DropItem(a8::Vec2 pos, int item_id, int item_count, int item_lv);
Hero* CreateHero(Human* hum);
int CreateLoot(int equip_id, a8::Vec2 pos, int count, int equip_lv);
void CreateBullet(Human* hum, MetaData::Equip* bullet_meta,
a8::Vec2 pos, a8::Vec2 dir, float fly_distance, int skill_id);
void OnHumanDie(Human* hum);
void OnHumanRevive(Human* hum);
bool OverBorder(const a8::Vec2 pos, float radius);
Human* GetWatchWarTarget(Human* hum);
bool BattleStarted();
int GetAliveTeamNum();
std::set<Human*>* GetAliveTeam();
bool CanJoin(const std::string& accountid, const std::string& team_uuid);
void OnPlayerOffline(Player* hum);
Obstacle* CreateObstacle(int id, float x, float y);
bool IsGameOver();
void FillSMUiUpdate(cs::SMUiUpdate& msg);
private:
int AllocUniid();
void ShuaAndroid();
void CreateAndroid(int android_num);
void UpdateGas();
bool GenSmallCircle(a8::Vec2 big_circle_pos, float big_circle_rad, float small_circle_rad,
a8::Vec2& out_pos);
void AutoMatchTeam();
void MatchTeam(Human* hum);
int NewTeam();
void CreateThings();
void CreateBuilding(int thing_id, float building_x, float building_y);
Obstacle* InternalCreateObstacle(int id, float x, float y,
std::function<void (Obstacle*)> on_precreate);
void AddObjectLater(Entity* entity);
void RandRemoveAndroid();
void NotifyUiUpdate();
void NotifyWxVoip();
void BattleReport();
int AllocBornPoint();
void InitAirDrop();
void AirDrop(MetaData::AirDrop* air_drop);
void GenDrop(MetaData::AirDrop* air_drop, int drop_id, int airdrop_point_id);
private:
int elapsed_time_ = 0;
int alive_count_ = 0;
a8::XTimerAttacher xtimer_attacher;
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;
std::set<int> refreshed_robot_set_;
std::map<int, std::set<Human*>> team_hash_;
std::map<std::string, Player*> accountid_hash_;
std::map<int, Entity*> moveable_hash_;
std::map<int, Entity*> uniid_hash_;
std::map<int, Entity*> later_add_hash_;
std::map<int, Human*> human_hash_;
std::map<int, std::set<int>> airdrop_hash_;
std::map<int, Human*> removed_robot_hash_;
};