2019-06-29 13:59:56 +08:00

128 lines
3.6 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"
namespace MetaData
{
struct Map;
struct SafeArea;
struct Building;
}
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;
FrameEvent frame_event;
FrameMaker frame_maker;
long long frame_no = 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;
~Room();
void Init();
void UnInit();
void Update(int delta_time);
int GetPlayerNum();
int AliveCount();
Player* GetPlayerByAccountId(const std::string& accountid);
Player* GetPlayerByUniId(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);
void CreateLoot(int equip_id, a8::Vec2 pos, int count, int equip_lv);
void CreateBullet(Human* hum, Weapon* weapon,
a8::Vec2 pos, a8::Vec2 dir, float fly_distance);
void OnHumanDie(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);
void OnPlayerOffline(Player* hum);
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();
Obstacle* CreateObstacle(int id, float x, float y);
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 OnGameOver();
void RandRemoveAndroid();
void NotifyUiUpdate();
void NotifyWxVoip();
private:
int elapsed_time_ = 0;
int alive_count_ = 0;
a8::XTimerAttacher xtimer_attacher;
int current_teamid = 0;
int current_uniid = 0;
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, Human*> removed_robot_hash_;
};