diff --git a/server/gameserver/creature.cc b/server/gameserver/creature.cc index 4641c7c8..dd11bd23 100644 --- a/server/gameserver/creature.cc +++ b/server/gameserver/creature.cc @@ -3080,19 +3080,16 @@ Obstacle* Creature::SummonObstacle(Buff* buff, const glm::vec3& dir ) { - #if 0 - Obstacle* hero = nullptr; - const mt::Hero* hero_meta = mt::Hero::GetById(buff->meta->_int_buff_param2); - if (hero_meta) { - hero = InternalSummonHero(buff, - hero_meta, - GetAttackDir(), - pos - ); - hero->hero_level = GetBattleContext()->GetHeroLevel(); + Obstacle* ob = nullptr; + const mt::MapThing* thing_meta = mt::MapThing::GetById(buff->meta->_int_buff_param2); + if (thing_meta) { + ob = InternalSummonObstacle(buff, + thing_meta, + GetAttackDir(), + pos + ); } - return hero; - #endif + return ob; } void Creature::RemoveSurplusObstacle(int id, int num) @@ -3114,3 +3111,49 @@ void Creature::RemoveSurplusObstacle(int id, int num) } #endif } + +Obstacle* Creature::InternalSummonObstacle(Buff* buff, const mt::MapThing* thing_meta, + glm::vec3 dir, const glm::vec3 born_pos) +{ + float *p_rotate = nullptr; + float rotate = 0.0f; + RoomObstacle* ob = room->CreateObstacle(thing_meta->thing_id(), + born_pos.x, + born_pos.y, + born_pos.z); + if (ob) { + ob->buff_meta = buff->meta; + ob->skill_meta = buff->skill_meta; + ob->master.Attach(this); + ob->SetTeamId(room, team_id); + ob->SetMasterId(room, GetUniId()); + ob->Active(); + if (p_rotate) { + ob->SetRotate(*p_rotate); + } + { + auto itr = slave_things2_.find(thing_meta->thing_id()); + if (itr != slave_things2_.end()) { + list_add_tail(&ob->entry, &itr->second); + } else { + slave_things2_[thing_meta->thing_id()] = list_head(); + itr = slave_things2_.find(thing_meta->thing_id()); + INIT_LIST_HEAD(&itr->second); + list_add_tail(&ob->entry, &itr->second); + } + } +#ifdef DEBUG + SendDebugMsg(a8::Format("召唤物件 buff_id:%d thing_id:%d pos:%f,%f,%f target_pos:%f,%f,%f", + {buff->meta->buff_id(), + thing_meta->thing_id(), + GetPos().GetX(), + GetPos().GetY(), + GetPos().GetZ(), + born_pos.x, + born_pos.y, + born_pos.z + })); +#endif + } + return ob; +} diff --git a/server/gameserver/roomobstacle.cc b/server/gameserver/roomobstacle.cc index a5c931b4..36f64045 100644 --- a/server/gameserver/roomobstacle.cc +++ b/server/gameserver/roomobstacle.cc @@ -26,6 +26,7 @@ RoomObstacle::RoomObstacle():Obstacle() { weak_ptr_chunk_.Set(this); + INIT_LIST_HEAD(&entry); } RoomObstacle::~RoomObstacle() @@ -402,6 +403,9 @@ void RoomObstacle::DetachFromMaster() room->RemoveObjectLater(this); } } + if (!list_empty(&entry)) { + list_del_init(&entry); + } } void RoomObstacle::Die(Room* room) diff --git a/server/gameserver/roomobstacle.h b/server/gameserver/roomobstacle.h index dc5ccf9e..0cef8907 100644 --- a/server/gameserver/roomobstacle.h +++ b/server/gameserver/roomobstacle.h @@ -20,6 +20,7 @@ class RoomObstacle : public Obstacle long long born_frameno = 0; a8::XTimerWp life_time_timer; std::shared_ptr init_args; + list_head entry; virtual ~RoomObstacle() override; virtual void Initialize() override;