修复地雷问题

This commit is contained in:
aozhiwei 2019-05-08 14:33:13 +08:00
parent 067f582f28
commit f61e029f61
6 changed files with 99 additions and 2 deletions

View File

@ -135,6 +135,10 @@ void Bullet::OnHit(std::set<Entity*>& objects)
room->ScatterDrop(obstacle->pos, obstacle->meta->i->drop());
}
obstacle->BroadcastFullState();
if (obstacle->meta->i->damage_dia() > 0.01f &&
obstacle->meta->i->damage() > 0.01f) {
obstacle->Explosion(this);
}
}
}
break;

View File

@ -110,11 +110,15 @@ enum VirtualWeapon_e
VW_SafeArea = 9000000,
VW_Spectate = 9000001,
VW_SelfDetonate = 9000002,
VW_Mine = 9000003,
};
enum VirtualPlayer_e
{
VP_SafeArea = 9000000,
VP_Spectate = 9000001,
VP_SelfDetonate = 9000002,
VP_Mine = 9000003,
};
const char* const PROJ_NAME_FMT = "game%d_gameserver";

View File

@ -491,7 +491,7 @@ void Human::BeKill(int killer_id, const std::string& killer_name, int weapon_id)
SendRollMsg(msg);
}
} else {
switch (killer_id) {
switch (weapon_id) {
case VW_SafeArea:
{
std::string msg = a8::Format("%s 被毒圈干掉",
@ -519,6 +519,15 @@ void Human::BeKill(int killer_id, const std::string& killer_name, int weapon_id)
SendRollMsg(msg);
}
break;
case VW_Mine:
{
std::string msg = a8::Format("%s 被地雷炸死",
{
name
});
SendRollMsg(msg);
}
break;
}
}
stats.killer_id = killer_id;

View File

@ -5,6 +5,7 @@
#include "room.h"
#include "collider.h"
#include "building.h"
#include "human.h"
Obstacle::Obstacle():Entity()
{
@ -121,3 +122,79 @@ ColliderComponent* Obstacle::GetBoxBound()
}
return nullptr;
}
void Obstacle::Explosion(Bullet* bullet)
{
if (meta->i->damage_dia() > 0.01f &&
meta->i->damage() > 0.01f) {
std::set<Entity*> objects;
for (auto& grid : grid_list) {
for (Human* hum: grid->human_list) {
{
if (TestCollision(hum)) {
objects.insert(hum);
}
}
for (Entity* entity : grid->entity_list) {
switch (entity->entity_type) {
case ET_Obstacle:
case ET_Building:
{
if (TestCollision(entity)) {
objects.insert(entity);
}
}
break;
default:
{
}
break;
}
}
}//end for
}
Vector2D bomb_pos = pos;
room->frame_event.AddExplosion(bullet, meta->i->thing_id(), bomb_pos);
for (auto& target : objects) {
switch (target->entity_type) {
case ET_Player:
{
Human* hum = (Human*)target;
#if 1
if (!hum->dead) {
#else
if (!hum->dead && (hum->team_id == 0 || hum->team_id != player->team_id)) {
#endif
float dmg = meta->i->damage();
float def = hum->def + hum->buff.def_add;
float finaly_dmg = dmg * (1 - def/MetaMgr::Instance()->K);
hum->DecHP(finaly_dmg, VP_Mine, "地雷", VW_Mine);
}
}
break;
case ET_Obstacle:
{
Obstacle* obstacle = (Obstacle*)target;
if (!obstacle->dead && obstacle->meta->i->attack_type() == 1) {
float dmg = meta->i->damage();
float def = 0;
float finaly_dmg = dmg * (1 - def/MetaMgr::Instance()->K);
obstacle->health = std::max(0.0f, obstacle->health - finaly_dmg);
obstacle->dead = obstacle->health <= 0.01f;
obstacle->dead_frameno = room->frame_no;
if (obstacle->dead) {
obstacle->ClearColliders();
room->ScatterDrop(obstacle->pos, obstacle->meta->i->drop());
}
obstacle->BroadcastFullState();
}
}
break;
default:
break;
}
}
}
}

View File

@ -19,6 +19,7 @@ class Human;
class Building;
class CircleCollider;
class AabbCollider;
class Bullet;
class Obstacle : public Entity
{
public:
@ -42,6 +43,8 @@ class Obstacle : public Entity
virtual void FillMFObjectPart(cs::MFObjectPart* part_data) override;
virtual void FillMFObjectFull(cs::MFObjectFull* full_data) override;
virtual ColliderComponent* GetBoxBound() override;
void Explosion(Bullet* bullet);
private:
CircleCollider* self_collider_ = nullptr;
AabbCollider* self_collider2_ = nullptr;

View File

@ -441,7 +441,7 @@ void Player::Shot()
return;
}
if (action_type != AT_Reload) {
if (action_type == AT_Reload) {
CancelAction();
}