obstacle hide ok
This commit is contained in:
parent
baa21030b7
commit
963031c2e1
@ -70,6 +70,7 @@ void MapInstance::AttachRoom(Room* room, RoomInitInfo& init_info)
|
||||
init_info.map_meta = map_meta_;
|
||||
init_info.grid_service = grid_service_;
|
||||
init_info.map_service = map_service_;
|
||||
init_info.map_instance = this;
|
||||
init_info.mini_room_spawn_points = &mini_room_spawn_points_;
|
||||
init_info.normal_room_spawn_points = &normal_room_spawn_points_;
|
||||
init_info.room_monster_spawn_points = &room_monster_spawn_points_;
|
||||
|
@ -23,7 +23,7 @@ class MapInstance
|
||||
|
||||
void AttachRoom(Room* room, RoomInitInfo& init_info);
|
||||
MetaData::Map* GetMapMeta() { return map_meta_; }
|
||||
|
||||
Entity* GetEntityByUniId(int uniid);
|
||||
private:
|
||||
void CreateThings();
|
||||
void CreateTerrain();
|
||||
@ -34,7 +34,6 @@ class MapInstance
|
||||
bool no_grid_service = false,
|
||||
int collider_param1 = 0,
|
||||
int collider_param2 = 0);
|
||||
Entity* GetEntityByUniId(int uniid);
|
||||
int AllocUniid();
|
||||
|
||||
private:
|
||||
|
@ -615,6 +615,17 @@ bool Obstacle::DoInteraction(Human* sender)
|
||||
});
|
||||
return true;
|
||||
}
|
||||
switch (meta->i->thing_type()) {
|
||||
case kObstacleHideHouse:
|
||||
{
|
||||
DoHideHouseInteraction(sender);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
{
|
||||
}
|
||||
break;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -622,3 +633,57 @@ void Obstacle::OnCollisionTrigger(Creature* c)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void Obstacle::DoHideHouseInteraction(Human* sender)
|
||||
{
|
||||
auto p = GetInteractionData(sender);
|
||||
if (p) {
|
||||
sender->SetPos(std::get<1>(*p));
|
||||
ClearObstacleBuff(sender);
|
||||
} else {
|
||||
sender->SetPos(GetPos());
|
||||
AddObstacleBuff(sender);
|
||||
ObstacleData* p = sender->room->GetPermanentObstacleData(GetUniId());
|
||||
if (!a8::HasBitFlag(p->flags, kHealth)) {
|
||||
p->health = health_;
|
||||
a8::SetBitFlag(p->flags, kHealth);
|
||||
}
|
||||
if (!p->interaction_humans) {
|
||||
p->interaction_humans = new std::map<int, std::tuple<long long, a8::Vec2>>();
|
||||
}
|
||||
(*p->interaction_humans)[sender->GetUniId()] = std::make_tuple
|
||||
(sender->room->GetFrameNo(), sender->GetPos());
|
||||
}
|
||||
}
|
||||
|
||||
std::tuple<long long, a8::Vec2>* Obstacle::GetInteractionData(Human* sender)
|
||||
{
|
||||
if (IsPermanent()) {
|
||||
ObstacleData* p = sender->room->GetPermanentObstacleData(GetUniId());
|
||||
if (!a8::HasBitFlag(p->flags, kHealth)) {
|
||||
p->health = health_;
|
||||
a8::SetBitFlag(p->flags, kHealth);
|
||||
}
|
||||
if (!p->interaction_humans) {
|
||||
return nullptr;
|
||||
}
|
||||
auto itr = p->interaction_humans->find(sender->GetUniId());
|
||||
return itr != p->interaction_humans->end() ? &itr->second : nullptr;
|
||||
} else {
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
void Obstacle::AddObstacleBuff(Creature* c)
|
||||
{
|
||||
for (int buff_id : meta->buff_list) {
|
||||
c->TryAddBuff(c, buff_id);
|
||||
}
|
||||
}
|
||||
|
||||
void Obstacle::ClearObstacleBuff(Creature* c)
|
||||
{
|
||||
for (int buff_id : meta->buff_list) {
|
||||
c->RemoveBuffById(buff_id);
|
||||
}
|
||||
}
|
||||
|
@ -69,6 +69,10 @@ class Obstacle : public Entity
|
||||
|
||||
protected:
|
||||
Obstacle();
|
||||
void DoHideHouseInteraction(Human* sender);
|
||||
std::tuple<long long, a8::Vec2>* GetInteractionData(Human* sender);
|
||||
void AddObstacleBuff(Creature* c);
|
||||
void ClearObstacleBuff(Creature* c);
|
||||
|
||||
protected:
|
||||
CircleCollider* self_collider_ = nullptr;
|
||||
|
@ -62,6 +62,7 @@ void Room::InitData(RoomInitInfo& init_info)
|
||||
map_tpl_name_ = init_info.map_tpl_name;
|
||||
grid_service = init_info.grid_service;
|
||||
map_service = init_info.map_service;
|
||||
map_instance = init_info.map_instance;
|
||||
map_meta_ = init_info.map_meta;
|
||||
mini_room_spawn_points_ = init_info.mini_room_spawn_points;
|
||||
normal_room_spawn_points_ = init_info.normal_room_spawn_points;
|
||||
@ -203,6 +204,9 @@ Player* Room::GetPlayerByUniId(int uniid)
|
||||
|
||||
Entity* Room::GetEntityByUniId(int uniid)
|
||||
{
|
||||
if (uniid < FIXED_OBJECT_MAXID) {
|
||||
return map_instance->GetEntityByUniId(uniid);
|
||||
}
|
||||
auto itr = uniid_hash_.find(uniid);
|
||||
return itr != uniid_hash_.end() ? itr->second : nullptr;
|
||||
}
|
||||
|
@ -48,6 +48,7 @@ public:
|
||||
a8::TimerAttacher timer_attacher;
|
||||
GridService* grid_service = nullptr;
|
||||
MapService* map_service = nullptr;
|
||||
MapInstance* map_instance = nullptr;
|
||||
bool debug_trace = false;
|
||||
bool added_to_over_room = false;
|
||||
a8::Vec2 last_player_jump_pos;
|
||||
|
@ -511,50 +511,6 @@ bool RoomObstacle::DoInteraction(Human* sender)
|
||||
if (Obstacle::DoInteraction(sender)) {
|
||||
return true;
|
||||
}
|
||||
switch (meta->i->thing_type()) {
|
||||
case kObstacleHideHouse:
|
||||
{
|
||||
DoHideHouseInteraction(sender);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
{
|
||||
}
|
||||
break;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
void RoomObstacle::DoHideHouseInteraction(Human* sender)
|
||||
{
|
||||
auto p = GetInteractionData(sender);
|
||||
if (p) {
|
||||
sender->SetPos(std::get<1>(*p));
|
||||
ClearObstacleBuff(sender);
|
||||
} else {
|
||||
sender->SetPos(GetPos());
|
||||
AddObstacleBuff(sender);
|
||||
interaction_humans_[sender->GetUniId()] = std::make_tuple
|
||||
(room->GetFrameNo(), sender->GetPos());
|
||||
}
|
||||
}
|
||||
|
||||
std::tuple<long long, a8::Vec2>* RoomObstacle::GetInteractionData(Human* sender)
|
||||
{
|
||||
auto itr = interaction_humans_.find(sender->GetUniId());
|
||||
return itr != interaction_humans_.end() ? &itr->second : nullptr;
|
||||
}
|
||||
|
||||
void RoomObstacle::AddObstacleBuff(Creature* c)
|
||||
{
|
||||
for (int buff_id : meta->buff_list) {
|
||||
c->TryAddBuff(c, buff_id);
|
||||
}
|
||||
}
|
||||
|
||||
void RoomObstacle::ClearObstacleBuff(Creature* c)
|
||||
{
|
||||
for (int buff_id : meta->buff_list) {
|
||||
c->RemoveBuffById(buff_id);
|
||||
}
|
||||
}
|
||||
|
@ -36,18 +36,11 @@ private:
|
||||
void ActiveHideHouse();
|
||||
void ActiveGully();
|
||||
|
||||
void DoHideHouseInteraction(Human* sender);
|
||||
|
||||
std::tuple<long long, a8::Vec2>* GetInteractionData(Human* sender);
|
||||
void AddObstacleBuff(Creature* c);
|
||||
void ClearObstacleBuff(Creature* c);
|
||||
|
||||
protected:
|
||||
bool temp_through_ = false;
|
||||
std::set<GridCell*>* grid_list_ = nullptr;
|
||||
int explosion_times_ = 0;
|
||||
bool detached_ = false;
|
||||
std::map<int, std::tuple<long long, a8::Vec2>> interaction_humans_;
|
||||
|
||||
RoomObstacle();
|
||||
|
||||
|
@ -151,6 +151,7 @@ struct ObstacleData
|
||||
|
||||
int door_open_times = 0;
|
||||
DoorState_e door_state = DoorStateClose;
|
||||
std::map<int, std::tuple<long long, a8::Vec2>>* interaction_humans = nullptr;
|
||||
};
|
||||
|
||||
struct KillInfo
|
||||
@ -178,6 +179,7 @@ struct ObjectSyncFlags
|
||||
|
||||
class GridService;
|
||||
class MapService;
|
||||
class MapInstance;
|
||||
class Building;
|
||||
struct RoomInitInfo
|
||||
{
|
||||
@ -196,6 +198,7 @@ struct RoomInitInfo
|
||||
std::string map_tpl_name;
|
||||
GridService* grid_service = nullptr;
|
||||
MapService* map_service = nullptr;
|
||||
MapInstance* map_instance = nullptr;
|
||||
const std::vector<MetaData::MapTplThing*>* mini_room_spawn_points = nullptr;
|
||||
const std::vector<MetaData::MapTplThing*>* normal_room_spawn_points = nullptr;
|
||||
const std::vector<MetaData::MapTplThing*>* room_monster_spawn_points = nullptr;
|
||||
|
Loading…
x
Reference in New Issue
Block a user