Core/OutdoorPvP: refactor using Position and Quat to pack parameters

Port From (https://github.com/TrinityCore/TrinityCore/commit/bd96262248fa4d9c8e867b4056e52c44852364c3)
This commit is contained in:
hondacrx
2020-07-23 19:29:11 -04:00
parent 2b13cba15b
commit f7aa724d8f
5 changed files with 34 additions and 77 deletions
+8 -17
View File
@@ -3460,7 +3460,7 @@ namespace Game
cellguids.creatures.Remove(guid);
}
}
public ulong AddCreatureData(uint entry, uint team, uint mapId, float x, float y, float z, float o, uint spawntimedelay)
public ulong AddCreatureData(uint entry, uint mapId, Position pos, uint spawntimedelay)
{
CreatureTemplate cInfo = GetCreatureTemplate(entry);
if (cInfo == null)
@@ -3480,10 +3480,7 @@ namespace Game
data.mapid = (ushort)mapId;
data.displayid = 0;
data.equipmentId = 0;
data.posX = x;
data.posY = y;
data.posZ = z;
data.orientation = o;
pos.GetPosition(out data.posX, out data.posY, out data.posZ, out data.orientation);
data.spawntimesecs = spawntimedelay;
data.spawndist = 0;
data.currentwaypoint = 0;
@@ -3499,7 +3496,7 @@ namespace Game
AddCreatureToGrid(guid, data);
// We use spawn coords to spawn
if (!map.Instanceable() && !map.IsRemovalGrid(x, y))
if (!map.Instanceable() && !map.IsRemovalGrid(data.posX, data.posY))
{
Creature creature = Creature.CreateCreatureFromDB(guid, map);
if (!creature)
@@ -4332,7 +4329,7 @@ namespace Game
cellguids.gameobjects.Remove(guid);
}
}
public ulong AddGOData(uint entry, uint mapId, float x, float y, float z, float o, uint spawntimedelay, float rotation0, float rotation1, float rotation2, float rotation3)
public ulong AddGOData(uint entry, uint mapId, Position pos, Quaternion rot, uint spawntimedelay)
{
GameObjectTemplate goinfo = GetGameObjectTemplate(entry);
if (goinfo == null)
@@ -4346,14 +4343,8 @@ namespace Game
GameObjectData data = new GameObjectData();
data.id = entry;
data.mapid = (ushort)mapId;
data.posX = x;
data.posY = y;
data.posZ = z;
data.orientation = o;
data.rotation.X = rotation0;
data.rotation.Y = rotation1;
data.rotation.Z = rotation2;
data.rotation.W = rotation3;
pos.GetPosition(out data.posX, out data.posY, out data.posZ, out data.orientation);
data.rotation = rot;
data.spawntimesecs = (int)spawntimedelay;
data.animprogress = 100;
data.spawnDifficulties.Add(Difficulty.None);
@@ -4366,7 +4357,7 @@ namespace Game
// Spawn if necessary (loaded grids only)
// We use spawn coords to spawn
if (!map.Instanceable() && map.IsGridLoaded(x, y))
if (!map.Instanceable() && map.IsGridLoaded(data.posX, data.posY))
{
GameObject go = GameObject.CreateGameObjectFromDB(guid, map);
if (!go)
@@ -4376,7 +4367,7 @@ namespace Game
}
}
Log.outDebug(LogFilter.Maps, "AddGOData: dbguid:{0} entry:{1} map:{2} x:{3} y:{4} z:{5} o:{6}", guid, entry, mapId, x, y, z, o);
Log.outDebug(LogFilter.Maps, "AddGOData: dbguid:{0} entry:{1} map:{2} x:{3} y:{4} z:{5} o:{6}", guid, entry, mapId, data.posX, data.posY, data.posZ, data.orientation);
return guid;
}
+13 -30
View File
@@ -17,6 +17,7 @@
using Framework.Constants;
using Framework.Database;
using Framework.GameMath;
using Game.Chat;
using Game.DataStorage;
using Game.Entities;
@@ -375,9 +376,9 @@ namespace Game.PvP
m_CreatureTypes[guid] = type;
}
public bool AddObject(uint type, uint entry, uint map, float x, float y, float z, float o, float rotation0, float rotation1, float rotation2, float rotation3)
public bool AddObject(uint type, uint entry, uint map, Position pos, Quaternion rot)
{
ulong guid = Global.ObjectMgr.AddGOData(entry, map, x, y, z, o, 0, rotation0, rotation1, rotation2, rotation3);
ulong guid = Global.ObjectMgr.AddGOData(entry, map, pos, rot, 0);
if (guid != 0)
{
AddGO(type, guid);
@@ -387,9 +388,9 @@ namespace Game.PvP
return false;
}
public bool AddCreature(uint type, uint entry, uint team, uint map, float x, float y, float z, float o, uint spawntimedelay)
public bool AddCreature(uint type, uint entry, uint map, Position pos, uint team, uint spawntimedelay)
{
ulong guid = Global.ObjectMgr.AddCreatureData(entry, team, map, x, y, z, o, spawntimedelay);
ulong guid = Global.ObjectMgr.AddCreatureData(entry, map, pos, spawntimedelay);
if (guid != 0)
{
AddCre(type, guid);
@@ -399,7 +400,7 @@ namespace Game.PvP
return false;
}
public bool SetCapturePointData(uint entry, uint map, float x, float y, float z, float o, float rotation0, float rotation1, float rotation2, float rotation3)
public bool SetCapturePointData(uint entry, uint map, Position pos, Quaternion rot)
{
Log.outDebug(LogFilter.Outdoorpvp, "Creating capture point {0}", entry);
@@ -411,7 +412,7 @@ namespace Game.PvP
return false;
}
m_capturePointSpawnId = Global.ObjectMgr.AddGOData(entry, map, x, y, z, o, 0, rotation0, rotation1, rotation2, rotation3);
m_capturePointSpawnId = Global.ObjectMgr.AddGOData(entry, map, pos, rot, 0);
if (m_capturePointSpawnId == 0)
return false;
@@ -755,26 +756,14 @@ namespace Game.PvP
{
entry = _entry;
map = _map;
x = _x;
y = _y;
z = _z;
o = _o;
rot0 = _rot0;
rot1 = _rot1;
rot2 = _rot2;
rot3 = _rot3;
pos = new Position(_x, _y, _z, _o);
rot = new Quaternion(_rot0, _rot1, _rot2, _rot3);
}
public uint entry;
public uint map;
public float x;
public float y;
public float z;
public float o;
public float rot0;
public float rot1;
public float rot2;
public float rot3;
public Position pos;
public Quaternion rot;
}
class creature_type
@@ -783,17 +772,11 @@ namespace Game.PvP
{
entry = _entry;
map = _map;
x = _x;
y = _y;
z = _z;
o = _o;
pos = new Position(_x, _y, _z, _o);
}
public uint entry;
public uint map;
public float x;
public float y;
public float z;
public float o;
Position pos;
}
}
+9 -20
View File
@@ -43,11 +43,10 @@ namespace Game.PvP
}
uint count = 0;
uint typeId = 0;
do
{
typeId = result.Read<byte>(0);
uint typeId = result.Read<byte>(0);
if (Global.DisableMgr.IsDisabledFor(DisableType.OutdoorPVP, typeId, null))
continue;
@@ -58,36 +57,32 @@ namespace Game.PvP
continue;
}
OutdoorPvPData data = new OutdoorPvPData();
OutdoorPvPTypes realTypeId = (OutdoorPvPTypes)typeId;
data.TypeId = realTypeId;
data.ScriptId = Global.ObjectMgr.GetScriptId(result.Read<string>(1));
m_OutdoorPvPDatas[realTypeId] = data;
OutdoorPvPScriptIds[realTypeId] = Global.ObjectMgr.GetScriptId(result.Read<string>(1));
++count;
}
while (result.NextRow());
OutdoorPvP pvp;
for (byte i = 1; i < (int)OutdoorPvPTypes.Max; ++i)
for (OutdoorPvPTypes outdoorPvpType = OutdoorPvPTypes.HellfirePeninsula; outdoorPvpType < OutdoorPvPTypes.Max; ++outdoorPvpType)
{
var outdoor = m_OutdoorPvPDatas.LookupByKey((OutdoorPvPTypes)i);
if (outdoor == null)
if (!OutdoorPvPScriptIds.ContainsKey(outdoorPvpType))
{
Log.outError(LogFilter.Sql, "Could not initialize OutdoorPvP object for type ID {0}; no entry in database.", i);
Log.outError(LogFilter.Sql, "Could not initialize OutdoorPvP object for type ID {0}; no entry in database.", outdoorPvpType);
continue;
}
pvp = Global.ScriptMgr.CreateOutdoorPvP(outdoor);
pvp = Global.ScriptMgr.CreateOutdoorPvP(OutdoorPvPScriptIds[outdoorPvpType]);
if (pvp == null)
{
Log.outError(LogFilter.Outdoorpvp, "Could not initialize OutdoorPvP object for type ID {0}; got NULL pointer from script.", i);
Log.outError(LogFilter.Outdoorpvp, "Could not initialize OutdoorPvP object for type ID {0}; got NULL pointer from script.", outdoorPvpType);
continue;
}
if (!pvp.SetupOutdoorPvP())
{
Log.outError(LogFilter.Outdoorpvp, "Could not initialize OutdoorPvP object for type ID {0}; SetupOutdoorPvP failed.", i);
Log.outError(LogFilter.Outdoorpvp, "Could not initialize OutdoorPvP object for type ID {0}; SetupOutdoorPvP failed.", outdoorPvpType);
continue;
}
@@ -237,15 +232,9 @@ namespace Game.PvP
Dictionary<uint, OutdoorPvP> m_OutdoorPvPMap = new Dictionary<uint, OutdoorPvP>();
// Holds the outdoor PvP templates
Dictionary<OutdoorPvPTypes, OutdoorPvPData> m_OutdoorPvPDatas = new Dictionary<OutdoorPvPTypes, OutdoorPvPData>();
Dictionary<OutdoorPvPTypes, uint> OutdoorPvPScriptIds = new Dictionary<OutdoorPvPTypes, uint>();
// update interval
uint m_UpdateTimer;
}
public class OutdoorPvPData
{
public OutdoorPvPTypes TypeId;
public uint ScriptId;
}
}
@@ -166,13 +166,8 @@ namespace Game.PvP
{
m_TowerType = (uint)type;
var capturepoint = HPConst.CapturePoints[m_TowerType];
var towerflag = HPConst.TowerFlags[m_TowerType];
SetCapturePointData(capturepoint.entry, capturepoint.map, capturepoint.x, capturepoint.y, capturepoint.z, capturepoint.o, capturepoint.rot0,
capturepoint.rot1, capturepoint.rot2, capturepoint.rot3);
AddObject((uint)type, towerflag.entry, towerflag.map, towerflag.x, towerflag.y, towerflag.z, towerflag.o, towerflag.rot0, towerflag.rot1, towerflag.rot2, towerflag.rot3);
SetCapturePointData(HPConst.CapturePoints[m_TowerType].entry, HPConst.CapturePoints[m_TowerType].map, HPConst.CapturePoints[m_TowerType].pos, HPConst.CapturePoints[m_TowerType].rot);
AddObject(m_TowerType, HPConst.TowerFlags[m_TowerType].entry, HPConst.TowerFlags[m_TowerType].map, HPConst.TowerFlags[m_TowerType].pos, HPConst.TowerFlags[m_TowerType].rot);
}
public override void ChangeState()
+2 -3
View File
@@ -729,10 +729,9 @@ namespace Game.Scripting
}
// OutdoorPvPScript
public OutdoorPvP CreateOutdoorPvP(OutdoorPvPData data)
public OutdoorPvP CreateOutdoorPvP(uint scriptId)
{
Cypher.Assert(data != null);
return RunScriptRet<OutdoorPvPScript, OutdoorPvP>(p => p.GetOutdoorPvP(), data.ScriptId, null);
return RunScriptRet<OutdoorPvPScript, OutdoorPvP>(p => p.GetOutdoorPvP(), scriptId, null);
}
// WeatherScript