Core/Maps: Replaced spawnmask with difficulty list
This commit is contained in:
@@ -158,7 +158,7 @@ namespace Game.Entities
|
||||
|
||||
// get difficulty 1 mode entry
|
||||
CreatureTemplate cinfo = null;
|
||||
DifficultyRecord difficultyEntry = CliDB.DifficultyStorage.LookupByKey(GetMap().GetSpawnMode());
|
||||
DifficultyRecord difficultyEntry = CliDB.DifficultyStorage.LookupByKey(GetMap().GetDifficultyID());
|
||||
while (cinfo == null && difficultyEntry != null)
|
||||
{
|
||||
int idx = CreatureTemplate.DifficultyIDToDifficultyEntryIndex(difficultyEntry.Id);
|
||||
@@ -992,10 +992,10 @@ namespace Game.Entities
|
||||
}
|
||||
|
||||
uint mapId = GetTransport() ? (uint)GetTransport().GetGoInfo().MoTransport.SpawnMap : GetMapId();
|
||||
SaveToDB(mapId, data.spawnMask);
|
||||
SaveToDB(mapId, data.spawnDifficulties);
|
||||
}
|
||||
|
||||
public virtual void SaveToDB(uint mapid, ulong spawnMask)
|
||||
public virtual void SaveToDB(uint mapid, List<Difficulty> spawnDifficulties)
|
||||
{
|
||||
// update in loaded data
|
||||
if (m_spawnId == 0)
|
||||
@@ -1052,7 +1052,7 @@ namespace Game.Entities
|
||||
// prevent add data integrity problems
|
||||
data.movementType = (byte)(m_respawnradius == 0 && GetDefaultMovementType() == MovementGeneratorType.Random
|
||||
? MovementGeneratorType.Idle : GetDefaultMovementType());
|
||||
data.spawnMask = spawnMask;
|
||||
data.spawnDifficulties = spawnDifficulties;
|
||||
data.npcflag = npcflag;
|
||||
data.unit_flags = unitFlags;
|
||||
data.unit_flags2 = unitFlags2;
|
||||
@@ -1075,7 +1075,7 @@ namespace Game.Entities
|
||||
stmt.AddValue(index++, m_spawnId);
|
||||
stmt.AddValue(index++, GetEntry());
|
||||
stmt.AddValue(index++, mapid);
|
||||
stmt.AddValue(index++, spawnMask);
|
||||
stmt.AddValue(index++, string.Join(",", data.spawnDifficulties));
|
||||
stmt.AddValue(index++, data.phaseId);
|
||||
stmt.AddValue(index++, data.phaseGroup);
|
||||
stmt.AddValue(index++, displayId);
|
||||
|
||||
@@ -291,7 +291,7 @@ namespace Game.Entities
|
||||
public uint curhealth;
|
||||
public uint curmana;
|
||||
public byte movementType;
|
||||
public ulong spawnMask;
|
||||
public List<Difficulty> spawnDifficulties = new List<Difficulty>();
|
||||
public ulong npcflag;
|
||||
public uint unit_flags; // enum UnitFlags mask values
|
||||
public uint unit_flags2; // enum UnitFlags2 mask values
|
||||
|
||||
@@ -875,10 +875,10 @@ namespace Game.Entities
|
||||
return;
|
||||
}
|
||||
|
||||
SaveToDB(GetMapId(), data.spawnMask);
|
||||
SaveToDB(GetMapId(), data.spawnDifficulties);
|
||||
}
|
||||
|
||||
public void SaveToDB(uint mapid, ulong spawnMask)
|
||||
public void SaveToDB(uint mapid, List<Difficulty> spawnDifficulties)
|
||||
{
|
||||
GameObjectTemplate goI = GetGoInfo();
|
||||
|
||||
@@ -902,7 +902,7 @@ namespace Game.Entities
|
||||
data.spawntimesecs = (int)(m_spawnedByDefault ? m_respawnDelayTime : -m_respawnDelayTime);
|
||||
data.animprogress = GetGoAnimProgress();
|
||||
data.go_state = GetGoState();
|
||||
data.spawnMask = spawnMask;
|
||||
data.spawnDifficulties = spawnDifficulties;
|
||||
data.artKit = GetGoArtKit();
|
||||
Global.ObjectMgr.NewGOData(m_spawnId, data);
|
||||
|
||||
@@ -919,7 +919,7 @@ namespace Game.Entities
|
||||
stmt.AddValue(index++, m_spawnId);
|
||||
stmt.AddValue(index++, GetEntry());
|
||||
stmt.AddValue(index++, mapid);
|
||||
stmt.AddValue(index++, spawnMask);
|
||||
stmt.AddValue(index++, string.Join(",", data.spawnDifficulties));
|
||||
stmt.AddValue(index++, data.phaseId);
|
||||
stmt.AddValue(index++, data.phaseGroup);
|
||||
stmt.AddValue(index++, GetPositionX());
|
||||
|
||||
@@ -18,6 +18,7 @@
|
||||
using Framework.Collections;
|
||||
using Framework.Constants;
|
||||
using Framework.GameMath;
|
||||
using System.Collections.Generic;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace Game.Entities
|
||||
@@ -1087,7 +1088,7 @@ namespace Game.Entities
|
||||
public int spawntimesecs;
|
||||
public uint animprogress;
|
||||
public GameObjectState go_state;
|
||||
public ulong spawnMask;
|
||||
public List<Difficulty> spawnDifficulties = new List<Difficulty>();
|
||||
public byte artKit;
|
||||
public PhaseUseFlagsValues phaseUseFlags;
|
||||
public uint phaseId;
|
||||
|
||||
@@ -1010,8 +1010,7 @@ namespace Game.Entities
|
||||
}
|
||||
void _LoadBoundInstances(SQLResult result)
|
||||
{
|
||||
for (byte i = 0; i < (int)Difficulty.Max; ++i)
|
||||
m_boundInstances[i].Clear();
|
||||
m_boundInstances.Clear();
|
||||
|
||||
Group group = GetGroup();
|
||||
|
||||
|
||||
@@ -75,7 +75,7 @@ namespace Game.Entities
|
||||
bool m_bPassOnGroupLoot;
|
||||
GroupUpdateCounter[] m_groupUpdateSequences = new GroupUpdateCounter[2];
|
||||
|
||||
public Dictionary<uint, InstanceBind>[] m_boundInstances = new Dictionary<uint, InstanceBind>[(int)Difficulty.Max];
|
||||
public Dictionary<Difficulty, Dictionary<uint, InstanceBind>> m_boundInstances = new Dictionary<Difficulty, Dictionary<uint, InstanceBind>>();
|
||||
Dictionary<uint, long> _instanceResetTimes = new Dictionary<uint, long>();
|
||||
uint _pendingBindId;
|
||||
uint _pendingBindTimer;
|
||||
|
||||
@@ -24,7 +24,6 @@ using Game.Maps;
|
||||
using Game.Network.Packets;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
namespace Game.Entities
|
||||
{
|
||||
@@ -236,14 +235,18 @@ namespace Game.Entities
|
||||
if (mapDiff == null)
|
||||
return null;
|
||||
|
||||
var bind = m_boundInstances[(int)difficulty].LookupByKey(mapid);
|
||||
if (bind != null)
|
||||
if (bind.extendState != 0 || withExpired)
|
||||
return bind;
|
||||
var difficultyDic = m_boundInstances.LookupByKey(difficulty);
|
||||
if (difficultyDic == null)
|
||||
return null;
|
||||
|
||||
var instanceBind = difficultyDic.LookupByKey(mapid);
|
||||
if (instanceBind != null)
|
||||
if (instanceBind.extendState != 0 || withExpired)
|
||||
return instanceBind;
|
||||
|
||||
return null;
|
||||
}
|
||||
public Dictionary<uint, InstanceBind> GetBoundInstances(Difficulty difficulty) { return m_boundInstances[(int)difficulty]; }
|
||||
public Dictionary<uint, InstanceBind> GetBoundInstances(Difficulty difficulty) { return m_boundInstances.LookupByKey(difficulty); }
|
||||
|
||||
public InstanceSave GetInstanceSave(uint mapid)
|
||||
{
|
||||
@@ -266,28 +269,16 @@ namespace Game.Entities
|
||||
|
||||
public void UnbindInstance(uint mapid, Difficulty difficulty, bool unload = false)
|
||||
{
|
||||
var bound = m_boundInstances[(int)difficulty].LookupByKey(mapid);
|
||||
if (bound != null)
|
||||
var difficultyDic = m_boundInstances.LookupByKey(difficulty);
|
||||
if (difficultyDic != null)
|
||||
{
|
||||
if (!unload)
|
||||
{
|
||||
PreparedStatement stmt = DB.Characters.GetPreparedStatement(CharStatements.DEL_CHAR_INSTANCE_BY_INSTANCE_GUID);
|
||||
|
||||
stmt.AddValue(0, GetGUID().GetCounter());
|
||||
stmt.AddValue(1, bound.save.GetInstanceId());
|
||||
|
||||
DB.Characters.Execute(stmt);
|
||||
}
|
||||
|
||||
if (bound.perm)
|
||||
GetSession().SendCalendarRaidLockout(bound.save, false);
|
||||
|
||||
bound.save.RemovePlayer(this); // save can become invalid
|
||||
m_boundInstances[(int)difficulty].Remove(mapid);
|
||||
var pair = difficultyDic.Find(mapid);
|
||||
if (pair.Value != null)
|
||||
UnbindInstance(pair, difficultyDic, unload);
|
||||
}
|
||||
}
|
||||
|
||||
public void UnbindInstance(KeyValuePair<uint, InstanceBind> pair, Difficulty difficulty, bool unload)
|
||||
public void UnbindInstance(KeyValuePair<uint, InstanceBind> pair, Dictionary<uint, InstanceBind> difficultyDic, bool unload)
|
||||
{
|
||||
if (pair.Value != null)
|
||||
{
|
||||
@@ -305,7 +296,7 @@ namespace Game.Entities
|
||||
GetSession().SendCalendarRaidLockout(pair.Value.save, false);
|
||||
|
||||
pair.Value.save.RemovePlayer(this); // save can become invalid
|
||||
m_boundInstances[(int)difficulty].Remove(pair.Key);
|
||||
difficultyDic.Remove(pair.Key);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -314,8 +305,8 @@ namespace Game.Entities
|
||||
if (save != null)
|
||||
{
|
||||
InstanceBind bind = new InstanceBind();
|
||||
if (m_boundInstances[(int)save.GetDifficultyID()].ContainsKey(save.GetMapId()))
|
||||
bind = m_boundInstances[(int)save.GetDifficultyID()][save.GetMapId()];
|
||||
if (m_boundInstances[save.GetDifficultyID()].ContainsKey(save.GetMapId()))
|
||||
bind = m_boundInstances[save.GetDifficultyID()][save.GetMapId()];
|
||||
|
||||
if (extendState == BindExtensionState.Keep) // special flag, keep the player's current extend state when updating for new boss down
|
||||
{
|
||||
@@ -373,7 +364,7 @@ namespace Game.Entities
|
||||
|
||||
Global.ScriptMgr.OnPlayerBindToInstance(this, save.GetDifficultyID(), save.GetMapId(), permanent, extendState);
|
||||
|
||||
m_boundInstances[(int)save.GetDifficultyID()][save.GetMapId()] = bind;
|
||||
m_boundInstances[save.GetDifficultyID()][save.GetMapId()] = bind;
|
||||
return bind;
|
||||
}
|
||||
|
||||
@@ -407,21 +398,19 @@ namespace Game.Entities
|
||||
InstanceInfoPkt instanceInfo = new InstanceInfoPkt();
|
||||
|
||||
long now = Time.UnixTime;
|
||||
for (byte i = 0; i < (int)Difficulty.Max; ++i)
|
||||
foreach (var difficultyDic in m_boundInstances.Values)
|
||||
{
|
||||
foreach (var pair in m_boundInstances[i])
|
||||
foreach (var instanceBind in difficultyDic.Values)
|
||||
{
|
||||
InstanceBind bind = pair.Value;
|
||||
if (bind.perm)
|
||||
if (instanceBind.perm)
|
||||
{
|
||||
InstanceSave save = pair.Value.save;
|
||||
InstanceSave save = instanceBind.save;
|
||||
|
||||
InstanceLockInfos lockInfos;
|
||||
|
||||
lockInfos.InstanceID = save.GetInstanceId();
|
||||
lockInfos.MapID = save.GetMapId();
|
||||
lockInfos.DifficultyID = (uint)save.GetDifficultyID();
|
||||
if (bind.extendState != BindExtensionState.Extended)
|
||||
if (instanceBind.extendState != BindExtensionState.Extended)
|
||||
lockInfos.TimeRemaining = (int)(save.GetResetTime() - now);
|
||||
else
|
||||
lockInfos.TimeRemaining = (int)(Global.InstanceSaveMgr.GetSubsequentResetTime(save.GetMapId(), save.GetDifficultyID(), save.GetResetTime()) - now);
|
||||
@@ -435,8 +424,8 @@ namespace Game.Entities
|
||||
lockInfos.CompletedMask = instanceScript.GetCompletedEncounterMask();
|
||||
}
|
||||
|
||||
lockInfos.Locked = bind.extendState != BindExtensionState.Expired;
|
||||
lockInfos.Extended = bind.extendState == BindExtensionState.Extended;
|
||||
lockInfos.Locked = instanceBind.extendState != BindExtensionState.Expired;
|
||||
lockInfos.Extended = instanceBind.extendState == BindExtensionState.Extended;
|
||||
|
||||
instanceInfo.LockList.Add(lockInfos);
|
||||
}
|
||||
@@ -617,26 +606,30 @@ namespace Game.Entities
|
||||
// method can be INSTANCE_RESET_ALL, INSTANCE_RESET_CHANGE_DIFFICULTY, INSTANCE_RESET_GROUP_JOIN
|
||||
|
||||
// we assume that when the difficulty changes, all instances that can be reset will be
|
||||
Difficulty diff = GetDungeonDifficultyID();
|
||||
Difficulty difficulty = GetDungeonDifficultyID();
|
||||
if (isRaid)
|
||||
{
|
||||
if (!isLegacy)
|
||||
diff = GetRaidDifficultyID();
|
||||
difficulty = GetRaidDifficultyID();
|
||||
else
|
||||
diff = GetLegacyRaidDifficultyID();
|
||||
difficulty = GetLegacyRaidDifficultyID();
|
||||
}
|
||||
|
||||
foreach (var pair in m_boundInstances[(int)diff].ToList())
|
||||
var difficultyDic = m_boundInstances.LookupByKey(difficulty);
|
||||
if (difficultyDic == null)
|
||||
return;
|
||||
|
||||
foreach (var pair in difficultyDic)
|
||||
{
|
||||
InstanceSave p = pair.Value.save;
|
||||
MapRecord entry = CliDB.MapStorage.LookupByKey(pair.Key);
|
||||
MapRecord entry = CliDB.MapStorage.LookupByKey(difficulty);
|
||||
if (entry == null || entry.IsRaid() != isRaid || !p.CanReset())
|
||||
continue;
|
||||
|
||||
if (method == InstanceResetMethod.All)
|
||||
{
|
||||
// the "reset all instances" method can only reset normal maps
|
||||
if (entry.InstanceType == MapTypes.Raid || diff == Difficulty.Heroic)
|
||||
if (entry.InstanceType == MapTypes.Raid || difficulty == Difficulty.Heroic)
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -651,7 +644,7 @@ namespace Game.Entities
|
||||
SendResetInstanceSuccess(p.GetMapId());
|
||||
|
||||
p.DeleteFromDB();
|
||||
m_boundInstances[(int)diff].Remove(pair.Key);
|
||||
difficultyDic.Remove(pair.Key);
|
||||
|
||||
// the following should remove the instance save from the manager and delete it as well
|
||||
p.RemovePlayer(this);
|
||||
|
||||
@@ -71,9 +71,6 @@ namespace Game.Entities
|
||||
m_logintime = Time.UnixTime;
|
||||
m_Last_tick = m_logintime;
|
||||
|
||||
for (byte i = 0; i < (int)Difficulty.Max; ++i)
|
||||
m_boundInstances[i] = new Dictionary<uint, InstanceBind>();
|
||||
|
||||
m_dungeonDifficulty = Difficulty.Normal;
|
||||
m_raidDifficulty = Difficulty.NormalRaid;
|
||||
m_legacyRaidDifficulty = Difficulty.Raid10N;
|
||||
@@ -839,9 +836,9 @@ namespace Game.Entities
|
||||
GetTransport().RemovePassenger(this);
|
||||
|
||||
// clean up player-instance binds, may unload some instance saves
|
||||
for (byte i = 0; i < (int)Difficulty.Max; ++i)
|
||||
foreach (var bound in m_boundInstances[i])
|
||||
bound.Value.save.RemovePlayer(this);
|
||||
foreach (var difficultyDic in m_boundInstances.Values)
|
||||
foreach (var instanceBind in difficultyDic.Values)
|
||||
instanceBind.save.RemovePlayer(this);
|
||||
}
|
||||
|
||||
public override void AddToWorld()
|
||||
|
||||
@@ -288,7 +288,7 @@ namespace Game.Entities
|
||||
base.RemoveFromWorld();
|
||||
}
|
||||
|
||||
public override void SaveToDB(uint mapid, ulong spawnMask) { }
|
||||
public override void SaveToDB(uint mapid, List<Difficulty> spawnDifficulties) { }
|
||||
|
||||
public ObjectGuid GetSummonerGUID() { return m_summonerGUID; }
|
||||
|
||||
|
||||
@@ -536,7 +536,7 @@ namespace Game.Entities
|
||||
void LoadStaticPassengers()
|
||||
{
|
||||
uint mapId = (uint)GetGoInfo().MoTransport.SpawnMap;
|
||||
var cells = Global.ObjectMgr.GetMapObjectGuids(mapId, (byte)GetMap().GetSpawnMode());
|
||||
var cells = Global.ObjectMgr.GetMapObjectGuids(mapId, (byte)GetMap().GetDifficultyID());
|
||||
if (cells == null)
|
||||
return;
|
||||
foreach (var cell in cells)
|
||||
|
||||
Reference in New Issue
Block a user