修正[_属性调整_区域平衡光环]
1、优化UpdateAura函数逻辑 2、添加Mod_ZoneAuraAllMapScript脚本实现地图更新
This commit is contained in:
parent
c619160211
commit
c743eac3c2
@ -1,31 +1,19 @@
|
||||
#include "PlayerScript.h"
|
||||
#include "Player.h"
|
||||
#include "DatabaseEnvFwd.h"
|
||||
#include "AllMapScript.h"
|
||||
|
||||
#include "mod_CustomDBCStores.h"
|
||||
#include "mod_ZoneAura/ZoneAura.h"
|
||||
#include <DataLoader.h>
|
||||
#include <mod_CustomMapData.h>
|
||||
#include <SpellMgr.h>
|
||||
|
||||
std::unordered_map<uint32/*zone*/, ZoneAuraTemplate> ZoneAuraMap;
|
||||
std::unordered_map<uint32, uint32> ZoneAura::m_zoneAuraTimers;
|
||||
|
||||
void ZoneAura::Load()
|
||||
{
|
||||
//ZoneAuraMap.clear();
|
||||
//QueryResult result = WorldDatabase.Query("SELECT 区域ID,光环ID,玩家最小血量 FROM acore_custom._属性调整_区域平衡光环");
|
||||
|
||||
//if (result)
|
||||
//{
|
||||
// do
|
||||
// {
|
||||
// Field* fields = result->Fetch();
|
||||
// uint32 zone = fields[0].Get<uint32>();
|
||||
// ZoneAuraTemplate Temp;
|
||||
// Temp.aura = fields[1].Get<uint32>();
|
||||
// Temp.limitHP = fields[2].Get<uint32>();
|
||||
// ZoneAuraMap.insert(std::make_pair(zone,Temp));
|
||||
// } while (result->NextRow());
|
||||
//}
|
||||
|
||||
// 加载 _物品_额外描述 数据
|
||||
sDataLoader->LoadDataToMap(ZoneAuraMap, "SELECT 区域ID,光环ID,玩家最小血量 FROM acore_custom._属性调整_区域平衡光环", "_属性调整_区域平衡光环---",
|
||||
// 过滤函数:无过滤
|
||||
@ -45,77 +33,169 @@ void ZoneAura::Load()
|
||||
|
||||
int32 ZoneAura::GetAuraStack(Map* map, uint32 zone, uint32 limitHP)
|
||||
{
|
||||
if (!map)
|
||||
return 0;
|
||||
if (!map)
|
||||
return 0;
|
||||
|
||||
int32 A_Count = 0;
|
||||
int32 H_Count = 0;
|
||||
int32 A_Count = 0;
|
||||
int32 H_Count = 0;
|
||||
|
||||
Map::PlayerList const& players = map->GetPlayers();
|
||||
Map::PlayerList const& players = map->GetPlayers();
|
||||
|
||||
if (players.IsEmpty())
|
||||
return 0;
|
||||
if (players.IsEmpty())
|
||||
return 0;
|
||||
|
||||
for (Map::PlayerList::const_iterator i = players.begin(); i != players.end(); ++i)
|
||||
{
|
||||
if (Player* player = i->GetSource())
|
||||
{
|
||||
if (player->GetZoneId() != zone || player->GetMaxHealth() < limitHP)
|
||||
continue;
|
||||
for (Map::PlayerList::const_iterator i = players.begin(); i != players.end(); ++i)
|
||||
{
|
||||
if (Player* player = i->GetSource())
|
||||
{
|
||||
if (player->GetZoneId() != zone || player->GetMaxHealth() < limitHP)
|
||||
continue;
|
||||
|
||||
if (player->GetTeamId() == TEAM_ALLIANCE)
|
||||
A_Count++;
|
||||
else
|
||||
H_Count++;
|
||||
}
|
||||
}
|
||||
if (player->GetTeamId() == TEAM_ALLIANCE)
|
||||
A_Count++;
|
||||
else
|
||||
H_Count++;
|
||||
}
|
||||
}
|
||||
|
||||
return A_Count - H_Count;
|
||||
return A_Count - H_Count;
|
||||
}
|
||||
|
||||
void ZoneAura::UpdateAura(Map* map)
|
||||
{
|
||||
if (!map || ZoneAuraMap.empty())
|
||||
return;
|
||||
if (!map || ZoneAuraMap.empty())
|
||||
return;
|
||||
|
||||
for (auto iter = ZoneAuraMap.begin(); iter != ZoneAuraMap.end(); iter++)
|
||||
{
|
||||
if (map->GetId() != CustomDBCStores::GetMapIdByZone(iter->first))
|
||||
continue;
|
||||
Map::PlayerList const& players = map->GetPlayers();
|
||||
if (players.IsEmpty())
|
||||
return;
|
||||
|
||||
int32 stack = GetAuraStack(map, iter->first, iter->second.limitHP);
|
||||
for (auto iter = ZoneAuraMap.begin(); iter != ZoneAuraMap.end(); iter++)
|
||||
{
|
||||
// 验证地图ID匹配
|
||||
if (map->GetId() != CustomDBCStores::GetMapIdByZone(iter->first))
|
||||
continue;
|
||||
|
||||
Map::PlayerList const& players = map->GetPlayers();
|
||||
int32 stack = GetAuraStack(map, iter->first, iter->second.limitHP);
|
||||
|
||||
if (players.IsEmpty())
|
||||
continue;
|
||||
for (Map::PlayerList::const_iterator i = players.begin(); i != players.end(); ++i)
|
||||
{
|
||||
if (Player* player = i->GetSource())
|
||||
{
|
||||
// 确保玩家在线且有效且在正确区域
|
||||
if (!player->IsInWorld() || !player->IsAlive() ||
|
||||
player->GetZoneId() != iter->first ||
|
||||
player->GetMaxHealth() < iter->second.limitHP)
|
||||
continue;
|
||||
|
||||
for (Map::PlayerList::const_iterator i = players.begin(); i != players.end(); ++i)
|
||||
{
|
||||
if (Player* player = i->GetSource())
|
||||
{
|
||||
if (player->GetZoneId() != iter->first)
|
||||
continue;
|
||||
|
||||
if (stack > 0)
|
||||
{
|
||||
if (player->GetTeamId() == TEAM_HORDE)
|
||||
player->SetAuraStack(iter->second.aura, player, stack);
|
||||
else
|
||||
player->RemoveAura(iter->second.aura);
|
||||
|
||||
}
|
||||
else if (stack < 0)
|
||||
{
|
||||
if (player->GetTeamId() == TEAM_ALLIANCE)
|
||||
player->SetAuraStack(iter->second.aura, player, -stack);
|
||||
else
|
||||
player->RemoveAura(iter->second.aura);
|
||||
|
||||
}else
|
||||
player->RemoveAura(iter->second.aura);
|
||||
}
|
||||
}
|
||||
}
|
||||
// 检查玩家当前光环状态
|
||||
bool hadAura = player->HasAura(iter->second.aura);
|
||||
uint32 oldStack = 0;
|
||||
if (hadAura)
|
||||
{
|
||||
if (Aura* aura = player->GetAura(iter->second.aura))
|
||||
oldStack = aura->GetStackAmount();
|
||||
}
|
||||
|
||||
// 应用光环逻辑
|
||||
bool shouldApplyAura = false;
|
||||
uint32 targetStack = 0;
|
||||
|
||||
if (stack > 0)
|
||||
{
|
||||
// 联盟人数多,部落获得BUFF
|
||||
if (player->GetTeamId() == TEAM_HORDE)
|
||||
{
|
||||
shouldApplyAura = true;
|
||||
targetStack = static_cast<uint32>(stack);
|
||||
}
|
||||
}
|
||||
else if (stack < 0)
|
||||
{
|
||||
// 部落人数多,联盟获得BUFF
|
||||
if (player->GetTeamId() == TEAM_ALLIANCE)
|
||||
{
|
||||
shouldApplyAura = true;
|
||||
targetStack = static_cast<uint32>(-stack);
|
||||
}
|
||||
}
|
||||
// stack == 0 时,双方人数相等,不给任何人BUFF
|
||||
|
||||
// 发送提示消息部分的优化
|
||||
if (shouldApplyAura)
|
||||
{
|
||||
// 需要应用或更新光环
|
||||
if (!hadAura || oldStack != targetStack)
|
||||
{
|
||||
player->SetAuraStack(iter->second.aura, player, targetStack);
|
||||
|
||||
// 获取光环名称
|
||||
SpellInfo const* spellInfo = sSpellMgr->GetSpellInfo(iter->second.aura);
|
||||
std::string auraName = spellInfo ? spellInfo->SpellName[player->GetSession()->GetSessionDbcLocale()] : "未知光环";
|
||||
|
||||
// 发送详细的提示消息
|
||||
if (!hadAura)
|
||||
{
|
||||
std::string teamName = (player->GetTeamId() == TEAM_HORDE) ? "部落" : "联盟";
|
||||
std::string oppositeTeam = (player->GetTeamId() == TEAM_HORDE) ? "联盟" : "部落";
|
||||
player->SendSystemMessage(fmt::format("由于{}玩家数量优势,你获得了{}层「{}」!",
|
||||
oppositeTeam, targetStack, auraName));
|
||||
}
|
||||
else if (oldStack != targetStack)
|
||||
{
|
||||
if (targetStack > oldStack)
|
||||
{
|
||||
player->SendSystemMessage(fmt::format("区域玩家数量变化,你的「{}」从{}层增强到{}层。",
|
||||
auraName, oldStack, targetStack));
|
||||
}
|
||||
else
|
||||
{
|
||||
player->SendSystemMessage(fmt::format("区域玩家数量变化,你的「{}」从{}层减弱到{}层。",
|
||||
auraName, oldStack, targetStack));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// 需要移除光环
|
||||
if (hadAura)
|
||||
{
|
||||
// 获取光环名称
|
||||
SpellInfo const* spellInfo = sSpellMgr->GetSpellInfo(iter->second.aura);
|
||||
std::string auraName = spellInfo ? spellInfo->SpellName[player->GetSession()->GetSessionDbcLocale()] : "未知光环";
|
||||
|
||||
player->RemoveAura(iter->second.aura);
|
||||
player->SendSystemMessage(fmt::format("区域玩家数量已平衡,「{}」效果消失。", auraName));
|
||||
}
|
||||
}
|
||||
|
||||
// 添加调试日志
|
||||
bool hasAuraAfter = player->HasAura(iter->second.aura);
|
||||
uint32 currentStack = 0;
|
||||
if (hasAuraAfter)
|
||||
{
|
||||
if (Aura* aura = player->GetAura(iter->second.aura))
|
||||
currentStack = aura->GetStackAmount();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void ZoneAura::UpdateMapTimer(Map* map, uint32 diff)
|
||||
{
|
||||
if (!map)
|
||||
return;
|
||||
|
||||
uint32 mapId = map->GetId();
|
||||
m_zoneAuraTimers[mapId] += diff;
|
||||
|
||||
if (m_zoneAuraTimers[mapId] > 2 * IN_MILLISECONDS)
|
||||
{
|
||||
m_zoneAuraTimers[mapId] = 0;
|
||||
UpdateAura(map);
|
||||
}
|
||||
}
|
||||
|
||||
class ZoneAuraScript : PlayerScript
|
||||
@ -129,7 +209,21 @@ public:
|
||||
}
|
||||
};
|
||||
|
||||
// 地图脚本实现
|
||||
class Mod_ZoneAuraAllMapScript : public AllMapScript
|
||||
{
|
||||
public:
|
||||
Mod_ZoneAuraAllMapScript() : AllMapScript("Mod_ZoneAuraAllMapScript") {}
|
||||
|
||||
// 处理地图更新
|
||||
void OnMapUpdate(Map* map, uint32 diff) override
|
||||
{
|
||||
ZoneAura::UpdateMapTimer(map, diff);
|
||||
}
|
||||
};
|
||||
|
||||
void AddSC_ZoneAura()
|
||||
{
|
||||
new ZoneAuraScript();
|
||||
new Mod_ZoneAuraAllMapScript();
|
||||
}
|
||||
|
||||
@ -17,10 +17,19 @@ public:
|
||||
static ZoneAura instance;
|
||||
return &instance;
|
||||
}
|
||||
|
||||
uint32 ZoneAuraTimer;
|
||||
|
||||
void Load();
|
||||
int32 GetAuraStack(Map* map, uint32 zone, uint32 limitHP);
|
||||
void UpdateAura(Map* map);
|
||||
static int32 GetAuraStack(Map* map, uint32 zone, uint32 limitHP);
|
||||
|
||||
static void UpdateMapTimer(Map* map, uint32 diff);
|
||||
|
||||
static void UpdateAura(Map* map);
|
||||
|
||||
private:
|
||||
static std::unordered_map<uint32/*mapId*/, uint32/*timer*/> m_zoneAuraTimers;
|
||||
|
||||
};
|
||||
#define sZoneAura ZoneAura::instance()
|
||||
#endif //MOD_CUSTOM_ZONEAURA_H
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user