game2004/server/gameserver/roomobstacle.cc
2020-05-30 16:06:02 +08:00

82 lines
2.4 KiB
C++

#include "precompile.h"
#include "metamgr.h"
#include "room.h"
#include "collider.h"
#include "building.h"
#include "human.h"
#include "app.h"
#include "typeconvert.h"
#include "bullet.h"
#include "mapservice.h"
#include "roomobstacle.h"
RoomObstacle::RoomObstacle():Obstacle()
{
entity_subtype_ = EST_RoomObstacle;
}
RoomObstacle::~RoomObstacle()
{
for (auto& itr : colliders_) {
ColliderComponent* collider = itr;
#ifdef DEBUG
a8::UdpLog::Instance()->Debug("OnRemoveCollider %d %d %d",
{
room->GetRoomIdx(),
entity_uniid,
(long long)collider
});
#endif
room->map_service->RemoveCollider(collider);
}
}
void RoomObstacle::Initialize()
{
Obstacle::Initialize();
xtimer_attacher.xtimer = &room->xtimer;
}
void RoomObstacle::RecalcSelfCollider()
{
if (meta->i->attack_type() != 2){
switch (meta->i->type()) {
case 1:
{
if (!self_collider_) {
self_collider_ = new CircleCollider();
self_collider_->owner = this;
AddEntityCollider(self_collider_);
}
self_collider_->pos = a8::Vec2();
self_collider_->rad = meta->i->height() / 2.0;
room->map_service->AddCollider(self_collider_);
}
break;
case 2:
{
if (!self_collider2_) {
self_collider2_ = new AabbCollider();
self_collider2_->owner = this;
AddEntityCollider(self_collider2_);
}
self_collider2_->_min = a8::Vec2(meta->i->width() / -2.0f, meta->i->height() / -2.0f);
self_collider2_->_max = a8::Vec2(meta->i->width() / 2.0f, meta->i->height() / 2.0f);
room->map_service->AddCollider(self_collider2_);
}
break;
}
}
if (!self_collider_) {
#ifdef DEBUG
a8::UdpLog::Instance()->Debug("OnAddCollider %d %d %d",
{
room->GetRoomIdx(),
entity_uniid,
(long long)self_collider_
});
#endif
}
}