This commit is contained in:
aozhiwei 2021-03-10 15:12:28 +08:00
parent 193073bf9d
commit d3d6e91a1a
5 changed files with 75 additions and 4 deletions

View File

@ -19,6 +19,7 @@
#include "gamelog.h"
#include "typeconvert.h"
#include "obstacle.h"
#include "roomobstacle.h"
#include "player.h"
#include "buff.h"
#include "roomobstacle.h"
@ -2154,6 +2155,29 @@ bool Human::IsEnemy(Human* hum)
}
}
RoomObstacle* Human::SummonObstacle(int equip_id, const a8::Vec2& pos)
{
RoomObstacle* obstacle = room->CreateObstacle(equip_id, pos.x, pos.y);
if (obstacle) {
obstacle->master = this;
room->xtimer.AddRepeatTimerAndAttach
(
SERVER_FRAME_RATE,
a8::XParams()
.SetSender(obstacle),
[] (const a8::XParams& param)
{
RoomObstacle* obstacle = (RoomObstacle*)param.sender.GetUserData();
obstacle->ActiveTimerFunc();
},
&obstacle->xtimer_attacher.timer_list_
);
} else {
abort();
}
return obstacle;
}
void Human::_InternalUpdateMove(float speed)
{
float nx = move_dir.x * speed;

View File

@ -32,6 +32,7 @@ struct xtimer_list;
class CircleCollider;
class AabbCollider;
class Obstacle;
class RoomObstacle;
class Loot;
class Buff;
class Human : public MoveableEntity
@ -302,6 +303,7 @@ class Human : public MoveableEntity
HumanCar& GetCar() { return car_; }
void DeadDrop();
bool IsEnemy(Human* hum);
RoomObstacle* SummonObstacle(int equip_id, const a8::Vec2& pos);
protected:
void _InternalUpdateMove(float speed);

View File

@ -152,6 +152,7 @@ public:
void OnZombieAppear(Human* hum);
int GetAliveCountByRace(RaceType_e race);
int GetOnlinePlayerNum();
RoomObstacle* CreateObstacle(int id, float x, float y);
private:
int AllocUniid();
@ -171,7 +172,6 @@ private:
void AdjustAirDropPos(MetaData::MapThing* thing_meta, a8::Vec2& box_pos);
void ShuaPlane();
int NewTeam();
RoomObstacle* CreateObstacle(int id, float x, float y);
RoomObstacle* InternalCreateObstacle(int id, float x, float y,
std::function<void (Obstacle*)> on_precreate);
void AddObjectLater(RoomEntity* entity);

View File

@ -31,6 +31,9 @@ RoomObstacle::~RoomObstacle()
#endif
room->map_service->RemoveCollider(collider);
}
if (!grid_list_) {
A8_SAFE_DELETE(grid_list_);
}
}
void RoomObstacle::Initialize()
@ -83,7 +86,43 @@ void RoomObstacle::RecalcSelfCollider()
}
}
bool RoomObstacle::CanThroughable(Human* num)
bool RoomObstacle::CanThroughable(Human* hum)
{
return true;
if (master) {
return master->team_id == hum->team_id && temp_through_;
} else {
return temp_through_;
}
}
void RoomObstacle::ActiveTimerFunc()
{
if (!master) {
room->xtimer.DeleteTimer(room->xtimer.GetRunningTimer());
return;
}
if (!grid_list_) {
grid_list_ = new std::set<GridCell*>();
room->grid_service->GetAllCellsByXy(room, GetPos().x, GetPos().y, *grid_list_);
}
bool has_hum = false;
room->grid_service->TouchAllLayerHumanList
(room->GetRoomIdx(),
*grid_list_,
[this, &has_hum] (Human* hum, bool& stop)
{
bool old_temp_through = temp_through_;
temp_through_ = false;
if (master->team_id == hum->team_id) {
if (TestCollision(room, hum)) {
has_hum = true;
stop = true;
}
}
temp_through_ = old_temp_through;
}
);
if (!has_hum) {
room->xtimer.DeleteTimer(room->xtimer.GetRunningTimer());
}
}

View File

@ -1,5 +1,6 @@
#pragma once
#include "gridservice.h"
#include "obstacle.h"
class RoomObstacle : public Obstacle
@ -9,14 +10,19 @@ class RoomObstacle : public Obstacle
a8::XTimerAttacher xtimer_attacher;
bool is_treasure_box = false;
bool is_terminator_airdrop_box = false;
class Human* master = nullptr;
virtual ~RoomObstacle() override;
virtual void Initialize() override;
virtual void RecalcSelfCollider() override;
virtual bool IsTerminatorAirDropBox(Room* room) override { return is_terminator_airdrop_box; }
virtual bool CanThroughable(Human* num) override;
virtual bool CanThroughable(Human* hum) override;
void ActiveTimerFunc();
protected:
bool temp_through_ = false;
std::set<GridCell*>* grid_list_ = nullptr;
RoomObstacle();
friend class EntityFactory;