gameover ok

This commit is contained in:
aozhiwei 2019-04-10 15:14:03 +08:00
parent feef53a8b8
commit 0c2d2fe0bf
7 changed files with 41 additions and 11 deletions

View File

@ -78,7 +78,10 @@ void Bullet::OnHit(std::vector<Entity*>& objects)
switch (target->entity_type) { switch (target->entity_type) {
case ET_Player: case ET_Player:
{ {
Human* hum = (Human*)target;
if (!hum->dead) {
hum->DecHP(10, 0, "");
}
} }
break; break;
case ET_Obstacle: case ET_Obstacle:

View File

@ -264,7 +264,7 @@ void Human::UpdatePoisoning()
health = std::max(0.0f, health - room->gas_data.old_area_meta->i->hurt()); health = std::max(0.0f, health - room->gas_data.old_area_meta->i->hurt());
} }
if (health <= 0.0f) { if (health <= 0.0f) {
dead = true; BeKill(-1, "安全区");
downed = true; downed = true;
poisoning_time = 0; poisoning_time = 0;
break; break;
@ -376,8 +376,22 @@ void Human::FillSMGameOver(cs::SMGameOver& msg)
void Human::BeKill(int killer_id, const std::string& killer_name) void Human::BeKill(int killer_id, const std::string& killer_name)
{ {
stats.killer_id = killer_id; if (!dead) {
stats.killer_name = killer_name; stats.killer_id = killer_id;
dead = true; stats.killer_name = killer_name;
health = 0.0f; dead = true;
health = 0.0f;
dead_frameno = room->frame_no;
send_gameover = true;
--room->alive_count_;
SyncAroundPlayers();
}
}
void Human::DecHP(float dec_hp, int killer_id, const std::string& killer_name)
{
health = std::min(0.0f, health - dec_hp);
if (health <= 0.0001f) {
BeKill(killer_id, killer_name);
}
} }

View File

@ -84,6 +84,8 @@ class Human : public Entity
HumanFrameData frame_data; HumanFrameData frame_data;
PlayerStats stats; PlayerStats stats;
bool send_gameover = false;
std::set<Entity*> new_objects; std::set<Entity*> new_objects;
std::set<Entity*> part_objects; std::set<Entity*> part_objects;
@ -112,6 +114,7 @@ class Human : public Entity
void ResetAction(); void ResetAction();
void FillSMGameOver(cs::SMGameOver& msg); void FillSMGameOver(cs::SMGameOver& msg);
void BeKill(int killer_id, const std::string& killer_name); void BeKill(int killer_id, const std::string& killer_name);
void DecHP(float dec_hp, int killer_id, const std::string& killer_name);
private: private:
CircleCollider* self_collider_ = nullptr; CircleCollider* self_collider_ = nullptr;

View File

@ -77,6 +77,9 @@ void Player::Update(int delta_time)
} }
MakeUpdateMsg(); MakeUpdateMsg();
SendNotifyMsg(*update_msg); SendNotifyMsg(*update_msg);
if (send_gameover) {
UpdateGameOver();
}
{ {
if (!new_objects.empty()) { if (!new_objects.empty()) {
new_objects.clear(); new_objects.clear();
@ -254,13 +257,18 @@ void Player::UpdateUseItemIdx()
void Player::UpdateSpectate() void Player::UpdateSpectate()
{ {
stats.killer_id = entity_uniid; BeKill(entity_uniid, name);
stats.killer_name = name;
dead = true;
health = 0.0f;
spectate = false; spectate = false;
} }
void Player::UpdateGameOver()
{
cs::SMGameOver msg;
FillSMGameOver(msg);
SendNotifyMsg(msg);
send_gameover = false;
}
void Player::Shot() void Player::Shot()
{ {
if (!curr_weapon->meta) { if (!curr_weapon->meta) {

View File

@ -77,6 +77,7 @@ class Player : public Human
void UpdateCancelAction(); void UpdateCancelAction();
void UpdateUseItemIdx(); void UpdateUseItemIdx();
void UpdateSpectate(); void UpdateSpectate();
void UpdateGameOver();
void Shot(); void Shot();
void ProcInteraction(); void ProcInteraction();
void ObstacleInteraction(Obstacle* entity); void ObstacleInteraction(Obstacle* entity);

View File

@ -24,4 +24,5 @@ enum SMMessageId_e
_SMPickup = 1006; _SMPickup = 1006;
_SMVoiceNotify = 1007; _SMVoiceNotify = 1007;
_SMDisconnectNotify = 1008; _SMDisconnectNotify = 1008;
_SMGameOver = 1009;
} }

View File

@ -490,7 +490,7 @@ message MFPlayerStats
optional int32 score = 11; // optional int32 score = 11; //
optional bool dead = 5; // optional bool dead = 5; //
optional int32 killer_id = 7; //id() optional int32 killer_id = 7; //id() id: -1:
optional string killer_name = 40; // optional string killer_name = 40; //
optional string account_id = 21; //id optional string account_id = 21; //id