Core/GameObject: implemented gameobject_overrides table to change faction and flags values on a per-spawn basis
Port From (https://github.com/TrinityCore/TrinityCore/commit/67a1a1d29b76acfcda505fe1a38761a335e93bc5)
This commit is contained in:
@@ -150,16 +150,17 @@ namespace Game.Chat
|
||||
return false;
|
||||
|
||||
uint entry;
|
||||
ulong spawnId = 0;
|
||||
if (param1.Equals("guid"))
|
||||
{
|
||||
string cValue = handler.ExtractKeyFromLink(args, "Hgameobject");
|
||||
if (cValue.IsEmpty())
|
||||
return false;
|
||||
|
||||
if (!ulong.TryParse(cValue, out ulong guidLow))
|
||||
if (!ulong.TryParse(cValue, out spawnId))
|
||||
return false;
|
||||
|
||||
GameObjectData data = Global.ObjectMgr.GetGameObjectData(guidLow);
|
||||
GameObjectData data = Global.ObjectMgr.GetGameObjectData(spawnId);
|
||||
if (data == null)
|
||||
return false;
|
||||
entry = data.Id;
|
||||
@@ -216,9 +217,19 @@ namespace Game.Chat
|
||||
handler.SendSysMessage(CypherStrings.GoinfoName, name);
|
||||
handler.SendSysMessage(CypherStrings.GoinfoSize, gameObjectInfo.size);
|
||||
|
||||
GameObjectTemplateAddon addon = Global.ObjectMgr.GetGameObjectTemplateAddon(entry);
|
||||
if (addon != null)
|
||||
handler.SendSysMessage(CypherStrings.GoinfoAddon, addon.faction, addon.flags);
|
||||
GameObjectOverride goOverride = null;
|
||||
if (spawnId != 0)
|
||||
{
|
||||
GameObjectOverride ovr = Global.ObjectMgr.GetGameObjectOverride(spawnId);
|
||||
if (ovr != null)
|
||||
goOverride = ovr;
|
||||
}
|
||||
|
||||
if (goOverride == null)
|
||||
goOverride = Global.ObjectMgr.GetGameObjectTemplateAddon(entry);
|
||||
|
||||
if (goOverride != null)
|
||||
handler.SendSysMessage(CypherStrings.GoinfoAddon, goOverride.Faction, goOverride.Flags);
|
||||
|
||||
handler.SendSysMessage(CypherStrings.ObjectInfoAIInfo, gameObjectInfo.AIName, Global.ObjectMgr.GetScriptName(gameObjectInfo.ScriptId));
|
||||
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1356,13 +1356,17 @@ namespace Game.Entities
|
||||
#endregion
|
||||
}
|
||||
|
||||
public class GameObjectTemplateAddon
|
||||
// From `gameobject_template_addon`, `gameobject_overrides`
|
||||
public class GameObjectOverride
|
||||
{
|
||||
public uint entry;
|
||||
public uint faction;
|
||||
public uint flags;
|
||||
public uint mingold;
|
||||
public uint maxgold;
|
||||
public uint Faction;
|
||||
public GameObjectFlags Flags;
|
||||
}
|
||||
|
||||
public class GameObjectTemplateAddon : GameObjectOverride
|
||||
{
|
||||
public uint Mingold;
|
||||
public uint Maxgold;
|
||||
public uint WorldEffectID;
|
||||
public uint AIAnimKitID;
|
||||
}
|
||||
|
||||
@@ -6084,7 +6084,7 @@ namespace Game.Entities
|
||||
{
|
||||
GameObjectTemplateAddon addon = go.GetTemplateAddon();
|
||||
if (addon != null)
|
||||
loot.GenerateMoneyLoot(addon.mingold, addon.maxgold);
|
||||
loot.GenerateMoneyLoot(addon.Mingold, addon.Maxgold);
|
||||
}
|
||||
|
||||
if (loot_type == LootType.Fishing)
|
||||
|
||||
@@ -115,10 +115,11 @@ namespace Game.Entities
|
||||
_triggeredArrivalEvent = false;
|
||||
_triggeredDepartureEvent = false;
|
||||
|
||||
if (m_goTemplateAddon != null)
|
||||
GameObjectOverride goOverride = GetGameObjectOverride();
|
||||
if (goOverride != null)
|
||||
{
|
||||
SetFaction(m_goTemplateAddon.faction);
|
||||
SetFlags((GameObjectFlags)m_goTemplateAddon.flags);
|
||||
SetFaction(goOverride.Faction);
|
||||
SetFlags(goOverride.Flags);
|
||||
}
|
||||
|
||||
m_goValue.Transport.PathProgress = 0;
|
||||
|
||||
@@ -3845,18 +3845,18 @@ namespace Game
|
||||
}
|
||||
|
||||
GameObjectTemplateAddon gameObjectAddon = new();
|
||||
gameObjectAddon.faction = result.Read<ushort>(1);
|
||||
gameObjectAddon.flags = result.Read<uint>(2);
|
||||
gameObjectAddon.mingold = result.Read<uint>(3);
|
||||
gameObjectAddon.maxgold = result.Read<uint>(4);
|
||||
gameObjectAddon.Faction = result.Read<ushort>(1);
|
||||
gameObjectAddon.Flags = (GameObjectFlags)result.Read<uint>(2);
|
||||
gameObjectAddon.Mingold = result.Read<uint>(3);
|
||||
gameObjectAddon.Maxgold = result.Read<uint>(4);
|
||||
gameObjectAddon.WorldEffectID = result.Read<uint>(5);
|
||||
gameObjectAddon.AIAnimKitID = result.Read<uint>(6);
|
||||
|
||||
// checks
|
||||
if (gameObjectAddon.faction != 0 && !CliDB.FactionTemplateStorage.ContainsKey(gameObjectAddon.faction))
|
||||
Log.outError(LogFilter.Sql, $"GameObject (Entry: {entry}) has invalid faction ({gameObjectAddon.faction}) defined in `gameobject_template_addon`.");
|
||||
if (gameObjectAddon.Faction != 0 && !CliDB.FactionTemplateStorage.ContainsKey(gameObjectAddon.Faction))
|
||||
Log.outError(LogFilter.Sql, $"GameObject (Entry: {entry}) has invalid faction ({gameObjectAddon.Faction}) defined in `gameobject_template_addon`.");
|
||||
|
||||
if (gameObjectAddon.maxgold > 0)
|
||||
if (gameObjectAddon.Maxgold > 0)
|
||||
{
|
||||
switch (got.type)
|
||||
{
|
||||
@@ -3888,6 +3888,43 @@ namespace Game
|
||||
|
||||
Log.outInfo(LogFilter.ServerLoading, "Loaded {0} game object template addons in {1} ms", count, Time.GetMSTimeDiffToNow(oldMSTime));
|
||||
}
|
||||
public void LoadGameObjectOverrides()
|
||||
{
|
||||
uint oldMSTime = Time.GetMSTime();
|
||||
|
||||
// 0 1 2
|
||||
var result = DB.World.Query("SELECT spawnId, faction, flags FROM gameobject_overrides");
|
||||
if (result.IsEmpty())
|
||||
{
|
||||
Log.outInfo(LogFilter.ServerLoading, "Loaded 0 gameobject faction and flags overrides. DB table `gameobject_overrides` is empty.");
|
||||
return;
|
||||
}
|
||||
|
||||
uint count = 0;
|
||||
do
|
||||
{
|
||||
ulong spawnId = result.Read<ulong>(0);
|
||||
GameObjectData goData = GetGameObjectData(spawnId);
|
||||
if (goData == null)
|
||||
{
|
||||
Log.outError(LogFilter.Sql, $"GameObject (SpawnId: {spawnId}) does not exist but has a record in `gameobject_overrides`");
|
||||
continue;
|
||||
}
|
||||
|
||||
GameObjectOverride gameObjectOverride = new();
|
||||
gameObjectOverride.Faction = result.Read<uint>(1);
|
||||
gameObjectOverride.Flags = (GameObjectFlags)result.Read<uint>(2);
|
||||
|
||||
_gameObjectOverrideStorage[spawnId] = gameObjectOverride;
|
||||
|
||||
if (gameObjectOverride.Faction != 0 && !CliDB.FactionTemplateStorage.ContainsKey(gameObjectOverride.Faction))
|
||||
Log.outError(LogFilter.Sql, $"GameObject (SpawnId: {spawnId}) has invalid faction ({gameObjectOverride.Faction}) defined in `gameobject_overrides`.");
|
||||
|
||||
++count;
|
||||
} while (result.NextRow());
|
||||
|
||||
Log.outInfo(LogFilter.ServerLoading, $"Loaded {count} gameobject faction and flags overrides in {Time.GetMSTimeDiffToNow(oldMSTime)} ms");
|
||||
}
|
||||
public void LoadGameObjects()
|
||||
{
|
||||
var time = Time.GetMSTime();
|
||||
@@ -4380,6 +4417,10 @@ namespace Game
|
||||
{
|
||||
return _gameObjectTemplateAddonStorage.LookupByKey(entry);
|
||||
}
|
||||
public GameObjectOverride GetGameObjectOverride(ulong spawnId)
|
||||
{
|
||||
return _gameObjectOverrideStorage.LookupByKey(spawnId);
|
||||
}
|
||||
public Dictionary<uint, GameObjectTemplate> GetGameObjectTemplates()
|
||||
{
|
||||
return _gameObjectTemplateStorage;
|
||||
@@ -10261,6 +10302,7 @@ namespace Game
|
||||
Dictionary<uint, GameObjectTemplate> _gameObjectTemplateStorage = new();
|
||||
Dictionary<ulong, GameObjectData> gameObjectDataStorage = new();
|
||||
Dictionary<ulong, GameObjectTemplateAddon> _gameObjectTemplateAddonStorage = new();
|
||||
Dictionary<ulong, GameObjectOverride> _gameObjectOverrideStorage = new();
|
||||
Dictionary<ulong, GameObjectAddon> _gameObjectAddonStorage = new();
|
||||
MultiMap<uint, uint> _gameObjectQuestItemStorage = new();
|
||||
List<uint> _gameObjectForQuestStorage = new();
|
||||
|
||||
@@ -623,7 +623,10 @@ namespace Game
|
||||
Global.ObjectMgr.LoadSpawnGroups();
|
||||
|
||||
Log.outInfo(LogFilter.ServerLoading, "Loading GameObject Addon Data...");
|
||||
Global.ObjectMgr.LoadGameObjectAddons(); // must be after LoadGameObjectTemplate() and LoadGameobjects()
|
||||
Global.ObjectMgr.LoadGameObjectAddons(); // must be after LoadGameObjects()
|
||||
|
||||
Log.outInfo(LogFilter.ServerLoading, "Loading GameObject faction and flags overrides...");
|
||||
Global.ObjectMgr.LoadGameObjectOverrides(); // must be after LoadGameObjects()
|
||||
|
||||
Log.outInfo(LogFilter.ServerLoading, "Loading GameObject Quest Items...");
|
||||
Global.ObjectMgr.LoadGameObjectQuestItems();
|
||||
|
||||
Reference in New Issue
Block a user