2019-04-28 15:45:38 +08:00

183 lines
4.9 KiB
C++

#pragma once
#include "entity.h"
#include "cs_proto.pb.h"
namespace MetaData
{
struct Player;
struct Equip;
struct Dress;
struct Skill;
}
enum HumanStatus
{
HS_PainKiller = 1,
HS_Fly = 2,
HS_Jump = 3,
HS_Hide = 4,
HS_Accelerate = 5,
HS_DamageAdd = 6,
HS_DefAdd = 7,
HS_RecoverHP = 8,
HS_ReflectDamage = 9,
HS_End
};
struct xtimer_list;
class CircleCollider;
class Obstacle;
class Human : public Entity
{
public:
int team_id = 0;
std::string account_id;
std::string team_uuid;
MetaData::Player* meta = nullptr;
MetaData::Equip* helmet_meta = nullptr;
MetaData::Equip* chest_meta = nullptr;
MetaData::Dress* skin_meta = nullptr;
MetaData::Skill* skill_meta = nullptr;
HumanAbility buff;
Vector2D move_dir;
Vector2D attack_dir;
std::string name;
std::string avatar_url;
float health = 0.0;
bool dead = false;
bool downed = false;
bool disconnected = false;
int anim_type = 0;
int anim_seq = 0;
ActionType_e action_type = AT_None;
long long action_frameno = 0;
int action_duration = 0;
int action_item_id = 0;
int action_target_id = 0;
int skin = 0;
int backpack = 0;
int helmet = 0;
int chest = 0;
int energy_shield = 0;
int max_energy_shield = 0;
int vip = 0;
int sdmg = 0;
bool poisoning = false;
long long poisoning_time = 0;
long long dead_frameno = 0;
long long join_frameno = 0;
int status = 0;
Weapon default_weapon;
std::vector<Weapon> weapons;
Weapon* curr_weapon = nullptr;
int curr_scope_idx = 0;
bool need_sync_team_data = false;
bool need_sync_teammate_data = false;
bool need_sync_active_player = false;
PlayerStats stats;
bool send_gameover = false;
int pain_killer_frameno = 0;
int pain_killer_lastingtime = 0;
xtimer_list* pain_killer_timer = nullptr;
xtimer_list* downed_timer = nullptr;
std::set<Human*>* team_members = nullptr;
long long jump_frameno = 0;
long long send_msg_times = 0;
float def = 0.0f;
Human();
virtual ~Human() override;
virtual void Initialize() override;
virtual float GetSpeed() override;
virtual void FillMFObjectPart(cs::MFObjectPart* part_data) override;
virtual void FillMFObjectFull(cs::MFObjectFull* full_data) override;
virtual ColliderComponent* GetBoxBound() override;
virtual void FillMFPlayerStats(cs::MFPlayerStats* stats);
void FillMFTeamData(cs::MFTeamData* team_data);
void Shot(Vector2D& target_dir);
void RecalcSelfCollider();
bool IsCollision();
void FindPath();
float GetRadius();
float GetMaxHP();
void UpdatePoisoning();
void SyncAroundPlayers();
void AutoLoadingBullet(bool manual = false);
void StartAction(ActionType_e action_type,
int action_duration,
int item_id,
int target_id);
void CancelAction();
void ResetAction();
void FillSMGameOver(cs::SMGameOver& msg);
void BeKill(int killer_id, const std::string& killer_name);
void DecHP(float dec_hp, int killer_id, const std::string& killer_name);
void AddToNewObjects(Entity* entity);
void AddToPartObjects(Entity* entity);
void RemoveObjects(Entity* entity);
bool HasLiveTeammate();
void Land();
void DoJump();
void DoSkill();
void FindLocation();
void RefreshView();
void OnGridListChange(std::set<GridCell*>& old_grid_list,
std::set<GridCell*>& inc_grid_list,
std::set<GridCell*>& dec_grid_list
);
void FillMFActivePlayerData(cs::MFActivePlayerData* player_data);
void FillMFGasData(cs::MFGasData* gas_data);
bool CanSee(Human* hum);
void RecalcAttr();
void RecalcVolume();
int GetInventory(int slot_id);
void AddInventory(int slot_id, int num);
void DecInventory(int slot_id, int num);
int GetVolume(int slot_id);
void RecoverHp(int inc_hp);
void FillBodyState(::google::protobuf::RepeatedPtrField<::cs::MFBodyState>* states);
protected:
long long last_shot_frameno_ = 0;
long long last_use_skill_frameno_ = 0;
long long hide_frameno_ = 0;
long long accelerate_frameno_ = 0;
long long damageadd_frameno_ = 0;
long long defadd_frameno_ = 0;
long long recover_hp_frameno_ = 0;
long long reflect_damage_frameno_ = 0;
a8::XTimerAttacher skill_xtimer_attacher_;
std::array<int, IS_END - 1> inventory_ = {};
std::array<int, IS_END> volume_ = {};
std::set<Entity*> new_objects;
std::set<Entity*> part_objects;
std::set<int> del_objects;
std::vector<int> shots_;
std::vector<int> emotes_;
std::vector<int> bullets_;
std::vector<int> smokes_;
std::vector<int> explosions_;
std::list<Human*> observers_;
private:
CircleCollider* self_collider_ = nullptr;
long long last_sync_gas_frameno = 0;
friend class FrameMaker;
friend class FrameEvent;
};