隐藏点Ok

This commit is contained in:
aozhiwei 2021-06-11 11:52:00 +08:00
parent 8438d583af
commit 2b8d8d1993
6 changed files with 134 additions and 26 deletions

View File

@ -331,6 +331,9 @@ enum ObstacleType_e
kObstacleMine = 2, kObstacleMine = 2,
kObstacleTrap = 3, kObstacleTrap = 3,
kObstaclePosionGas = 4, kObstaclePosionGas = 4,
kObstacleSpring = 5,
kObstacleHideHouse = 6,
kObstacleGully = 7,
}; };
const char* const PROJ_NAME_FMT = "game%d_gameserver"; const char* const PROJ_NAME_FMT = "game%d_gameserver";

View File

@ -584,3 +584,36 @@ bool Obstacle::CanThroughable(Bullet* bullet)
{ {
return false; return false;
} }
bool Obstacle::DoInteraction(Human* sender)
{
if (IsDoor()) {
if (GetDoorState(sender->room) == DoorStateClose) {
SetDoorState(sender->room, DoorStateOpen);
float x = GetBuilding()->GetX() + GetDoorState1()->x() - GetBuilding()->meta->i->tilewidth() / 2.0;
float y = GetBuilding()->GetY() + GetDoorState1()->y() - GetBuilding()->meta->i->tileheight() / 2.0;
SetPos(a8::Vec2(x, y));
} else {
SetDoorState(sender->room, DoorStateClose);
float x = GetBuilding()->GetX() + GetDoorState0()->x() - GetBuilding()->meta->i->tilewidth() / 2.0;
float y = GetBuilding()->GetY() + GetDoorState0()->y() - GetBuilding()->meta->i->tileheight() / 2.0;
SetPos(a8::Vec2(x, y));
}
IncDoorOpenTimes(sender->room);
RecalcSelfCollider();
sender->room->TraverseHumanList
(a8::XParams(),
[this] (Human* hum, a8::XParams& param) -> bool
{
hum->AddToNewObjects(this);
if (TestCollision(hum->room, hum)) {
hum->SetLastCollisionDoor(this);
} else if (hum->GetLastCollisionDoor() == this) {
hum->SetLastCollisionDoor(nullptr);
}
return true;
});
return true;
}
return false;
}

View File

@ -44,6 +44,7 @@ class Obstacle : public Entity
virtual bool IsTerminatorAirDropBox(Room* room) { return false; } virtual bool IsTerminatorAirDropBox(Room* room) { return false; }
virtual bool CanThroughable(Creature* c); virtual bool CanThroughable(Creature* c);
virtual bool CanThroughable(Bullet* bullet); virtual bool CanThroughable(Bullet* bullet);
virtual bool DoInteraction(Human* sender);
void Explosion(Bullet* bullet); void Explosion(Bullet* bullet);
void SetDoorInfo(Building* building, int door_id_x); void SetDoorInfo(Building* building, int door_id_x);
bool IsDoor(); bool IsDoor();

View File

@ -478,32 +478,7 @@ void Player::ProcInteraction()
void Player::ObstacleInteraction(Obstacle* entity) void Player::ObstacleInteraction(Obstacle* entity)
{ {
if (entity->IsDoor()) { entity->DoInteraction(this);
if (entity->GetDoorState(room) == DoorStateClose) {
entity->SetDoorState(room, DoorStateOpen);
float x = entity->GetBuilding()->GetX() + entity->GetDoorState1()->x() - entity->GetBuilding()->meta->i->tilewidth() / 2.0;
float y = entity->GetBuilding()->GetY() + entity->GetDoorState1()->y() - entity->GetBuilding()->meta->i->tileheight() / 2.0;
entity->SetPos(a8::Vec2(x, y));
} else {
entity->SetDoorState(room, DoorStateClose);
float x = entity->GetBuilding()->GetX() + entity->GetDoorState0()->x() - entity->GetBuilding()->meta->i->tilewidth() / 2.0;
float y = entity->GetBuilding()->GetY() + entity->GetDoorState0()->y() - entity->GetBuilding()->meta->i->tileheight() / 2.0;
entity->SetPos(a8::Vec2(x, y));
}
entity->IncDoorOpenTimes(room);
entity->RecalcSelfCollider();
room->TraverseHumanList(a8::XParams(),
[entity] (Human* hum, a8::XParams& param) -> bool
{
hum->AddToNewObjects(entity);
if (entity->TestCollision(hum->room, hum)) {
hum->SetLastCollisionDoor(entity);
} else if (hum->GetLastCollisionDoor() == entity) {
hum->SetLastCollisionDoor(nullptr);
}
return true;
});
}
} }
void Player::LootInteraction(Loot* entity) void Player::LootInteraction(Loot* entity)

View File

@ -349,7 +349,24 @@ void RoomObstacle::Active()
ActivePosionGas(); ActivePosionGas();
} }
break; break;
case kObstacleSpring:
{
ActiveSpring();
}
break;
case kObstacleHideHouse:
{
ActiveHideHouse();
}
break;
case kObstacleGully:
{
ActiveGully();
}
break;
default: default:
{
}
break; break;
} }
} }
@ -473,3 +490,71 @@ bool RoomObstacle::CanThroughable(Creature* c)
return temp_through_; return temp_through_;
} }
} }
void RoomObstacle::ActiveSpring()
{
}
void RoomObstacle::ActiveHideHouse()
{
}
void RoomObstacle::ActiveGully()
{
}
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);
}
}

View File

@ -18,6 +18,7 @@ class RoomObstacle : public Obstacle
virtual void RecalcSelfCollider() override; virtual void RecalcSelfCollider() override;
virtual bool IsTerminatorAirDropBox(Room* room) override { return is_terminator_airdrop_box; } virtual bool IsTerminatorAirDropBox(Room* room) override { return is_terminator_airdrop_box; }
virtual bool CanThroughable(Creature* c) override; virtual bool CanThroughable(Creature* c) override;
virtual bool DoInteraction(Human* sender) override;
void ActiveTimerFunc(); void ActiveTimerFunc();
void UpdateTimerFunc(); void UpdateTimerFunc();
void Active(); void Active();
@ -31,12 +32,22 @@ private:
void ActiveMine(); void ActiveMine();
void ActiveTrap(); void ActiveTrap();
void ActivePosionGas(); void ActivePosionGas();
void ActiveSpring();
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: protected:
bool temp_through_ = false; bool temp_through_ = false;
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, std::tuple<long long, a8::Vec2>> interaction_humans_;
RoomObstacle(); RoomObstacle();