大秘境开始时重置副本
This commit is contained in:
parent
b1d25b2af7
commit
215f2d45c2
@ -16,7 +16,62 @@
|
||||
#include <mod_CustomItemData.h>
|
||||
#include <Mythic_Script.h>
|
||||
#include "MythicPlusWrapperInstance.h"
|
||||
#include <MapMgr.h>
|
||||
#include <GridNotifiers.h>
|
||||
|
||||
void ResetInstanceCreaturesAndObjects(Player* player, InstanceMap* instanceMap)
|
||||
{
|
||||
if (!instanceMap)
|
||||
return;
|
||||
|
||||
// 重置所有副本内的生物和对象
|
||||
if (InstanceMap* map = player->GetMap()->ToInstanceMap())
|
||||
{
|
||||
// 使用AzerothCore的标准重置方法
|
||||
map->DoForAllPlayers([](Player* p) {
|
||||
p->CombatStop();
|
||||
p->getHostileRefMgr().deleteReferences();
|
||||
});
|
||||
|
||||
// 重置实例脚本状态
|
||||
if (InstanceScript* inst = map->GetInstanceScript())
|
||||
{
|
||||
// 重置所有遭遇战状态
|
||||
for (uint32 i = 0; i < inst->GetEncounterCount(); ++i)
|
||||
{
|
||||
inst->SetBossState(i, NOT_STARTED);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 重置所有生物
|
||||
for (auto& pair : instanceMap->GetCreatureBySpawnIdStore())
|
||||
{
|
||||
if (Creature* creature = pair.second)
|
||||
{
|
||||
if (!creature->IsAlive())
|
||||
{
|
||||
creature->Respawn(true); // 强制重生
|
||||
}
|
||||
else
|
||||
{
|
||||
creature->SetFullHealth();
|
||||
creature->CombatStop(true);
|
||||
creature->GetThreatMgr().ClearAllThreat();
|
||||
creature->AI()->Reset();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 重置游戏对象
|
||||
for (auto& pair : instanceMap->GetGameObjectBySpawnIdStore())
|
||||
{
|
||||
if (GameObject* go = pair.second)
|
||||
{
|
||||
go->Respawn();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 根据guidLow在背包中查找物品
|
||||
Item* ModSMAddon::GetItemByGuidLow(Player* player, uint32 guidLow)
|
||||
@ -762,7 +817,7 @@ bool ModSMAddon::OnRecv(Player* player, std::string msg)
|
||||
if (InstanceScript* instance = player->GetInstanceScript())
|
||||
{
|
||||
uint32 currentState = instance->GetData(DATA_KEYSTONE_VALIDATED);
|
||||
LOG_INFO("server.loading", "Current keystone state: {}", currentState);
|
||||
LOG_INFO("server.loading", "当前梯形图状态:{}", currentState);
|
||||
|
||||
if (currentState == DONE)
|
||||
{
|
||||
@ -784,7 +839,7 @@ bool ModSMAddon::OnRecv(Player* player, std::string msg)
|
||||
}
|
||||
else
|
||||
ChatHandler(player->GetSession()).SendNotification(errorMsg);
|
||||
}
|
||||
}
|
||||
|
||||
// 钥石验证成功,开始大秘境挑战
|
||||
else if (sGCAddon->IsOpcode(opcode, "SM_C_MYTHICPLUS_START"))
|
||||
@ -792,11 +847,38 @@ bool ModSMAddon::OnRecv(Player* player, std::string msg)
|
||||
ChatHandler(player->GetSession()).SendNotification("大秘境开始");
|
||||
if (InstanceScript* instance = player->GetInstanceScript())
|
||||
{
|
||||
// 先显示空气墙
|
||||
instance->SetData(DATA_KEYSTONE_VALIDATED, DONE);
|
||||
// 然后开始倒计时
|
||||
instance->DoAction(ACTION_START_MYTHIC_COUNTDOWN);
|
||||
sGCAddon->SendPacketTo(player, "SM_S_MYTHICPLUS_COUNTDOWN","");
|
||||
// 获取正确的InstanceMap指针
|
||||
if (InstanceMap* instanceMap = player->GetMap()->ToInstanceMap())
|
||||
{
|
||||
// 使用异步回调来处理重置和位面恢复
|
||||
player->GetSession()->GetQueryProcessor().AddCallback(
|
||||
CharacterDatabase.AsyncQuery("SELECT 1").WithCallback([player, instance, instanceMap](QueryResult result)
|
||||
{
|
||||
ResetInstanceCreaturesAndObjects(player, instanceMap);
|
||||
|
||||
// 设置大秘境状态
|
||||
instance->SetData(DATA_KEYSTONE_VALIDATED, DONE);
|
||||
instance->DoAction(ACTION_START_MYTHIC_COUNTDOWN);
|
||||
|
||||
// 发送相关数据包
|
||||
sGCAddon->SendPacketTo(player, "SM_S_MYTHICPLUS_COUNTDOWN", "");
|
||||
|
||||
// 发送大秘境信息
|
||||
if (MythicPlusWrapperInstanceScript* mythicScript =
|
||||
dynamic_cast<MythicPlusWrapperInstanceScript*>(instance))
|
||||
{
|
||||
std::string mythicInstanceInfo = mythicScript->SendMythicPlusInfoToPlayers();
|
||||
if (!mythicInstanceInfo.empty())
|
||||
{
|
||||
sGCAddon->SendPacketTo(player, "SM_S_MYTHICPLUS_INFO", mythicInstanceInfo);
|
||||
}
|
||||
}
|
||||
|
||||
// 发送重置完成通知
|
||||
ChatHandler(player->GetSession()).SendNotification("副本已重置,大秘境挑战开始!");
|
||||
})
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user