添加壁垒逻辑

This commit is contained in:
aozhiwei 2021-07-19 11:18:59 +00:00
parent 9107a5ef4c
commit 58b2c78184
6 changed files with 95 additions and 0 deletions

View File

@ -357,6 +357,9 @@ void Bullet::Check(float distance)
//穿人 //穿人
return; return;
} }
if (c->HasBuffEffect(kBET_BulletThrough)) {
return;
}
AabbCollider aabb_box; AabbCollider aabb_box;
c->GetHitAabbBox(aabb_box); c->GetHitAabbBox(aabb_box);
if (c != sender.Get() && !c->dead && TestCollision(room, &aabb_box)) { if (c != sender.Get() && !c->dead && TestCollision(room, &aabb_box)) {

View File

@ -359,6 +359,7 @@ enum ObstacleType_e
kObstacleGully = 7, kObstacleGully = 7,
kObstacleAirDropBox = 8, kObstacleAirDropBox = 8,
kObstacleOilBucket = 9, kObstacleOilBucket = 9,
kObstacleKeepRangeBuff = 10,
}; };
enum BulletHit_e enum BulletHit_e

View File

@ -67,6 +67,7 @@ enum BuffEffectType_e
kBET_Rescue = 45, //救援 kBET_Rescue = 45, //救援
kBET_AddCarBuff = 46, //给载具加buff kBET_AddCarBuff = 46, //给载具加buff
kBET_RemoveCarBuff = 47, //移除载具身上的buff kBET_RemoveCarBuff = 47, //移除载具身上的buff
kBET_BulletThrough = 48, //穿透
kBET_FollowMaster = 49, //跟随主人 kBET_FollowMaster = 49, //跟随主人
kBET_ThroughWall = 50, //穿墙 kBET_ThroughWall = 50, //穿墙

View File

@ -116,6 +116,9 @@ void Explosion::InternalAttack()
} }
); );
for (auto& target : objects) { for (auto& target : objects) {
if (target->HasBuffEffect(kBET_BulletThrough)) {
continue;
}
target->OnExplosionHit(this); target->OnExplosionHit(this);
} }
} }

View File

@ -41,6 +41,9 @@ RoomObstacle::~RoomObstacle()
if (!grid_list_) { if (!grid_list_) {
A8_SAFE_DELETE(grid_list_); A8_SAFE_DELETE(grid_list_);
} }
if (!hit_objects_) {
A8_SAFE_DELETE(hit_objects_);
}
} }
void RoomObstacle::Initialize() void RoomObstacle::Initialize()
@ -277,6 +280,11 @@ void RoomObstacle::Active()
ActiveAirDrop(); ActiveAirDrop();
} }
break; break;
case kObstacleKeepRangeBuff:
{
ActiveKeepRangeBuff();
}
break;
default: default:
{ {
} }
@ -465,3 +473,79 @@ Entity* RoomObstacle::GetRealObject(Room* room)
{ {
return room->GetEntityByUniId(real_object_uniid); return room->GetEntityByUniId(real_object_uniid);
} }
void RoomObstacle::ActiveKeepRangeBuff()
{
auto check_cb =
[] (const a8::XParams& param)
{
RoomObstacle* obstacle = (RoomObstacle*)param.sender.GetUserData();
obstacle->ProcKeepRangeBuff();
};
room->xtimer.AddRepeatTimerAndAttach
(
1,
a8::XParams()
.SetSender(this),
check_cb,
&xtimer_attacher.timer_list_
);
room->xtimer.AddDeadLineTimerAndAttach
(
meta->i->time() / FRAME_RATE_MS,
a8::XParams()
.SetSender(this),
[] (const a8::XParams& param)
{
RoomObstacle* obstacle = (RoomObstacle*)param.sender.GetUserData();
obstacle->DetachFromMaster();
},
&xtimer_attacher.timer_list_
);
}
void RoomObstacle::ProcKeepRangeBuff()
{
if (!grid_list_) {
grid_list_ = new std::set<GridCell*>();
room->grid_service->GetAllCellsByXy(room, GetPos().x, GetPos().y, *grid_list_);
}
if (!hit_objects_) {
hit_objects_ = new std::map<int, CreatureWeakPtr>();
}
if (grid_list_ && master.Get() && !IsDead(room)) {
std::set<Creature*> target_list;
room->grid_service->TraverseCreatures
(room->GetRoomIdx(),
*grid_list_,
[this, &target_list] (Creature* hum, bool& stop)
{
if (master.Get()->team_id != hum->team_id && TestCollision(room, hum)) {
target_list.insert(hum);
}
}
);
for (Creature* hum : target_list) {
for (int buff_id : meta->buff_list) {
MetaData::Buff* buff_meta = MetaMgr::Instance()->GetBuff(buff_id);
if (buff_meta && hum->GetBuffById(buff_id)) {
hum->AddBuff(master.Get(),
buff_meta,
1);
}
}
if (hit_objects_->find(hum->GetUniId()) == hit_objects_->end()) {
(*hit_objects_)[hum->GetUniId()] = hum->GetWeakPtrRef();
}
}
for (auto& pair : *hit_objects_) {
for (int buff_id : meta->buff_list) {
if (pair.second.Get() && target_list.find(pair.second.Get()) == target_list.end()) {
pair.second.Get()->RemoveBuffById(buff_id);
}
}
}
} else {
room->xtimer.DeleteTimer(room->xtimer.GetRunningTimer());
}
}

View File

@ -38,13 +38,16 @@ private:
void ActiveHideHouse(); void ActiveHideHouse();
void ActiveGully(); void ActiveGully();
void ActiveAirDrop(); void ActiveAirDrop();
void ActiveKeepRangeBuff();
void SummonAirDropBox(int box_id); void SummonAirDropBox(int box_id);
void ProcKeepRangeBuff();
protected: protected:
std::set<GridCell*>* grid_list_ = nullptr; std::set<GridCell*>* grid_list_ = nullptr;
int explosion_times_ = 0; int explosion_times_ = 0;
bool detached_ = false; bool detached_ = false;
std::map<int, CreatureWeakPtr>* hit_objects_ = nullptr;
RoomObstacle(); RoomObstacle();