Ported .Net Core commits:
hondacrx: - Initial commit: Switch to .Net Core 2.0 - Fix build and removed not needed files Fabi: - Updated solution platforms. - Changed folder structure. - Change library target framework to netstandard2.0. - Updated solution platforms again... - Removed windows specific kernel32 function usage (Ctrl-C handler).
This commit is contained in:
@@ -0,0 +1,183 @@
|
||||
/*
|
||||
* Copyright (C) 2012-2017 CypherCore <http://github.com/CypherCore>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
using Framework.Constants;
|
||||
using Framework.Database;
|
||||
using Game.Achievements;
|
||||
using Game.DataStorage;
|
||||
using Game.Maps;
|
||||
using Game.Network;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Game.Scenarios
|
||||
{
|
||||
public class InstanceScenario : Scenario
|
||||
{
|
||||
public InstanceScenario(Map map, ScenarioData scenarioData) : base(scenarioData)
|
||||
{
|
||||
_map = map;
|
||||
|
||||
//ASSERT(_map);
|
||||
LoadInstanceData(_map.GetInstanceId());
|
||||
|
||||
var players = map.GetPlayers();
|
||||
foreach (var player in players)
|
||||
SendScenarioState(player);
|
||||
}
|
||||
|
||||
public void SaveToDB()
|
||||
{
|
||||
if (_criteriaProgress.Empty())
|
||||
return;
|
||||
|
||||
DifficultyRecord difficultyEntry = CliDB.DifficultyStorage.LookupByKey(_map.GetDifficultyID());
|
||||
if (difficultyEntry == null || difficultyEntry.Flags.HasAnyFlag(DifficultyFlags.ChallengeMode)) // Map should have some sort of "CanSave" boolean that returns whether or not the map is savable. (Challenge modes cannot be saved for example)
|
||||
return;
|
||||
|
||||
uint id = _map.GetInstanceId();
|
||||
if (id == 0)
|
||||
{
|
||||
Log.outDebug(LogFilter.Scenario, "Scenario.SaveToDB: Can not save scenario progress without an instance save. Map.GetInstanceId() did not return an instance save.");
|
||||
return;
|
||||
}
|
||||
|
||||
SQLTransaction trans = new SQLTransaction();
|
||||
foreach (var iter in _criteriaProgress)
|
||||
{
|
||||
if (!iter.Value.Changed)
|
||||
continue;
|
||||
|
||||
Criteria criteria = Global.CriteriaMgr.GetCriteria(iter.Key);
|
||||
switch (criteria.Entry.Type)
|
||||
{
|
||||
// Blizzard only appears to store creature kills
|
||||
case CriteriaTypes.KillCreature:
|
||||
break;
|
||||
default:
|
||||
continue;
|
||||
}
|
||||
|
||||
if (iter.Value.Counter != 0)
|
||||
{
|
||||
PreparedStatement stmt = DB.Characters.GetPreparedStatement(CharStatements.DEL_SCENARIO_INSTANCE_CRITERIA);
|
||||
stmt.AddValue(0, id);
|
||||
stmt.AddValue(1, iter.Key);
|
||||
trans.Append(stmt);
|
||||
|
||||
stmt = DB.Characters.GetPreparedStatement(CharStatements.INS_SCENARIO_INSTANCE_CRITERIA);
|
||||
stmt.AddValue(0, id);
|
||||
stmt.AddValue(1, iter.Key);
|
||||
stmt.AddValue(2, iter.Value.Counter);
|
||||
stmt.AddValue(3, (uint)iter.Value.Date);
|
||||
trans.Append(stmt);
|
||||
}
|
||||
|
||||
iter.Value.Changed = false;
|
||||
}
|
||||
|
||||
DB.Characters.CommitTransaction(trans);
|
||||
}
|
||||
|
||||
void LoadInstanceData(uint instanceId)
|
||||
{
|
||||
PreparedStatement stmt = DB.Characters.GetPreparedStatement(CharStatements.SEL_SCENARIO_INSTANCE_CRITERIA_FOR_INSTANCE);
|
||||
stmt.AddValue(0, instanceId);
|
||||
|
||||
SQLResult result = DB.Characters.Query(stmt);
|
||||
if (!result.IsEmpty())
|
||||
{
|
||||
SQLTransaction trans = new SQLTransaction();
|
||||
long now = Time.UnixTime;
|
||||
|
||||
List<CriteriaTree> criteriaTrees = new List<CriteriaTree>();
|
||||
do
|
||||
{
|
||||
uint id = result.Read<uint>(0);
|
||||
ulong counter = result.Read<ulong>(1);
|
||||
long date = result.Read<uint>(2);
|
||||
|
||||
Criteria criteria = Global.CriteriaMgr.GetCriteria(id);
|
||||
if (criteria == null)
|
||||
{
|
||||
// Removing non-existing criteria data for all instances
|
||||
Log.outError(LogFilter.Scenario, "Removing scenario criteria {0} data from the table `instance_scenario_progress`.", id);
|
||||
|
||||
stmt = DB.Characters.GetPreparedStatement(CharStatements.DEL_SCENARIO_INSTANCE_CRITERIA);
|
||||
stmt.AddValue(0, instanceId);
|
||||
stmt.AddValue(1, id);
|
||||
trans.Append(stmt);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (criteria.Entry.StartTimer != 0 && (date + criteria.Entry.StartTimer) < now)
|
||||
continue;
|
||||
|
||||
switch (criteria.Entry.Type)
|
||||
{
|
||||
// Blizzard appears to only stores creatures killed progress for unknown reasons. Either technical shortcoming or intentional
|
||||
case CriteriaTypes.KillCreature:
|
||||
break;
|
||||
default:
|
||||
continue;
|
||||
}
|
||||
|
||||
SetCriteriaProgress(criteria, counter, null, ProgressType.Set);
|
||||
|
||||
List<CriteriaTree> trees = Global.CriteriaMgr.GetCriteriaTreesByCriteria(criteria.ID);
|
||||
if (trees != null)
|
||||
{
|
||||
foreach (CriteriaTree tree in trees)
|
||||
criteriaTrees.Add(tree);
|
||||
}
|
||||
}
|
||||
while (result.NextRow());
|
||||
|
||||
DB.Characters.CommitTransaction(trans);
|
||||
|
||||
foreach (CriteriaTree tree in criteriaTrees)
|
||||
{
|
||||
ScenarioStepRecord step = tree.ScenarioStep;
|
||||
if (step == null)
|
||||
continue;
|
||||
|
||||
if (IsCompletedCriteriaTree(tree))
|
||||
SetStepState(step, ScenarioStepState.Done);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public override string GetOwnerInfo()
|
||||
{
|
||||
return string.Format("Instance ID {0}", _map.GetInstanceId());
|
||||
}
|
||||
|
||||
public override void SendPacket(ServerPacket data)
|
||||
{
|
||||
//Hack todo fix me
|
||||
if (_map == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
_map.SendToPlayers(data);
|
||||
}
|
||||
|
||||
Map _map;
|
||||
Dictionary<byte, Dictionary<uint, CriteriaProgress>> _stepCriteriaProgress = new Dictionary<byte, Dictionary<uint, CriteriaProgress>>();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,368 @@
|
||||
/*
|
||||
* Copyright (C) 2012-2017 CypherCore <http://github.com/CypherCore>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
using Framework.Constants;
|
||||
using Game.Achievements;
|
||||
using Game.DataStorage;
|
||||
using Game.Entities;
|
||||
using Game.Network;
|
||||
using Game.Network.Packets;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Game.Scenarios
|
||||
{
|
||||
public class Scenario : CriteriaHandler
|
||||
{
|
||||
public Scenario(ScenarioData scenarioData)
|
||||
{
|
||||
_data = scenarioData;
|
||||
_currentstep = null;
|
||||
|
||||
//ASSERT(_data);
|
||||
|
||||
foreach (var step in _data.Steps)
|
||||
SetStepState(step.Value, ScenarioStepState.NotStarted);
|
||||
|
||||
ScenarioStepRecord firstStep = GetFirstStep();
|
||||
if (firstStep != null)
|
||||
SetStep(firstStep);
|
||||
else
|
||||
Log.outError(LogFilter.Scenario, "Scenario.Scenario: Could not launch Scenario (id: {0}), found no valid scenario step", _data.Entry.Id);
|
||||
}
|
||||
|
||||
~Scenario()
|
||||
{
|
||||
foreach (ObjectGuid guid in _players)
|
||||
{
|
||||
Player player = Global.ObjAccessor.FindPlayer(guid);
|
||||
if (player)
|
||||
SendBootPlayer(player);
|
||||
}
|
||||
|
||||
_players.Clear();
|
||||
}
|
||||
|
||||
public override void Reset()
|
||||
{
|
||||
base.Reset();
|
||||
SetStep(GetFirstStep());
|
||||
}
|
||||
|
||||
public virtual void CompleteStep(ScenarioStepRecord step)
|
||||
{
|
||||
Quest quest = Global.ObjectMgr.GetQuestTemplate(step.QuestRewardID);
|
||||
if (quest != null)
|
||||
{
|
||||
foreach (ObjectGuid guid in _players)
|
||||
{
|
||||
Player player = Global.ObjAccessor.FindPlayer(guid);
|
||||
if (player)
|
||||
player.RewardQuest(quest, 0, null, false);
|
||||
}
|
||||
}
|
||||
|
||||
if (step.IsBonusObjective())
|
||||
return;
|
||||
|
||||
ScenarioStepRecord newStep = null;
|
||||
foreach (var _step in _data.Steps.Values)
|
||||
{
|
||||
if (_step.IsBonusObjective())
|
||||
continue;
|
||||
|
||||
if (GetStepState(_step) == ScenarioStepState.Done)
|
||||
continue;
|
||||
|
||||
if (newStep == null || _step.Step < newStep.Step)
|
||||
newStep = _step;
|
||||
}
|
||||
|
||||
SetStep(newStep);
|
||||
if (IsComplete())
|
||||
CompleteScenario();
|
||||
else
|
||||
Log.outError(LogFilter.Scenario, "Scenario.CompleteStep: Scenario (id: {0}, step: {1}) was completed, but could not determine new step, or validate scenario completion.", step.ScenarioID, step.Id);
|
||||
}
|
||||
|
||||
public virtual void CompleteScenario()
|
||||
{
|
||||
SendPacket(new ScenarioCompleted(_data.Entry.Id));
|
||||
}
|
||||
|
||||
void SetStep(ScenarioStepRecord step)
|
||||
{
|
||||
_currentstep = step;
|
||||
if (step != null)
|
||||
SetStepState(step, ScenarioStepState.InProgress);
|
||||
|
||||
ScenarioState scenarioState = new ScenarioState();
|
||||
BuildScenarioState(scenarioState);
|
||||
SendPacket(scenarioState);
|
||||
}
|
||||
|
||||
public virtual void OnPlayerEnter(Player player)
|
||||
{
|
||||
_players.Add(player.GetGUID());
|
||||
SendScenarioState(player);
|
||||
}
|
||||
|
||||
public virtual void OnPlayerExit(Player player)
|
||||
{
|
||||
_players.Remove(player.GetGUID());
|
||||
SendBootPlayer(player);
|
||||
}
|
||||
|
||||
bool IsComplete()
|
||||
{
|
||||
foreach (var step in _data.Steps.Values)
|
||||
{
|
||||
if (step.IsBonusObjective())
|
||||
continue;
|
||||
|
||||
if (GetStepState(step) != ScenarioStepState.Done)
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
ScenarioStepState GetStepState(ScenarioStepRecord step)
|
||||
{
|
||||
if (!_stepStates.ContainsKey(step))
|
||||
return ScenarioStepState.Invalid;
|
||||
|
||||
return _stepStates[step];
|
||||
}
|
||||
|
||||
public override void SendCriteriaUpdate(Criteria criteria, CriteriaProgress progress, uint timeElapsed, bool timedCompleted)
|
||||
{
|
||||
ScenarioProgressUpdate progressUpdate = new ScenarioProgressUpdate();
|
||||
progressUpdate.CriteriaProgress.Id = criteria.ID;
|
||||
progressUpdate.CriteriaProgress.Quantity = progress.Counter;
|
||||
progressUpdate.CriteriaProgress.Player = progress.PlayerGUID;
|
||||
progressUpdate.CriteriaProgress.Date = progress.Date;
|
||||
if (criteria.Entry.StartTimer != 0)
|
||||
progressUpdate.CriteriaProgress.Flags = timedCompleted ? 1 : 0u;
|
||||
|
||||
progressUpdate.CriteriaProgress.TimeFromStart = timeElapsed;
|
||||
progressUpdate.CriteriaProgress.TimeFromCreate = 0;
|
||||
|
||||
SendPacket(progressUpdate);
|
||||
}
|
||||
|
||||
public override bool CanUpdateCriteriaTree(Criteria criteria, CriteriaTree tree, Player referencePlayer)
|
||||
{
|
||||
ScenarioStepRecord step = tree.ScenarioStep;
|
||||
if (step == null)
|
||||
return false;
|
||||
|
||||
if (step.ScenarioID != _data.Entry.Id)
|
||||
return false;
|
||||
|
||||
ScenarioStepRecord currentStep = GetStep();
|
||||
if (currentStep == null)
|
||||
return false;
|
||||
|
||||
if (step.IsBonusObjective())
|
||||
return true;
|
||||
|
||||
return currentStep == step;
|
||||
}
|
||||
|
||||
public override bool CanCompleteCriteriaTree(CriteriaTree tree)
|
||||
{
|
||||
ScenarioStepRecord step = tree.ScenarioStep;
|
||||
if (step == null)
|
||||
return false;
|
||||
|
||||
if (step.ScenarioID != _data.Entry.Id)
|
||||
return false;
|
||||
|
||||
if (step.IsBonusObjective())
|
||||
return !IsComplete();
|
||||
|
||||
if (step != GetStep())
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public override void CompletedCriteriaTree(CriteriaTree tree, Player referencePlayer)
|
||||
{
|
||||
ScenarioStepRecord step = tree.ScenarioStep;
|
||||
if (step == null)
|
||||
return;
|
||||
|
||||
if (!step.IsBonusObjective() && step != GetStep())
|
||||
return;
|
||||
|
||||
if (GetStepState(step) == ScenarioStepState.Done)
|
||||
return;
|
||||
|
||||
SetStepState(step, ScenarioStepState.Done);
|
||||
CompleteStep(step);
|
||||
}
|
||||
|
||||
public override void SendPacket(ServerPacket data)
|
||||
{
|
||||
foreach (ObjectGuid guid in _players)
|
||||
{
|
||||
Player player = Global.ObjAccessor.FindPlayer(guid);
|
||||
if (player)
|
||||
player.SendPacket(data);
|
||||
}
|
||||
}
|
||||
|
||||
void BuildScenarioState(ScenarioState scenarioState)
|
||||
{
|
||||
scenarioState.ScenarioID = (int)_data.Entry.Id;
|
||||
ScenarioStepRecord step = GetStep();
|
||||
if (step != null)
|
||||
scenarioState.CurrentStep = (int)step.Id;
|
||||
scenarioState.CriteriaProgress = GetCriteriasProgress();
|
||||
scenarioState.BonusObjectives = GetBonusObjectivesData();
|
||||
// Don't know exactly what this is for, but seems to contain list of scenario steps that we're either on or that are completed
|
||||
foreach (var state in _stepStates)
|
||||
{
|
||||
if (state.Key.IsBonusObjective())
|
||||
continue;
|
||||
|
||||
switch (state.Value)
|
||||
{
|
||||
case ScenarioStepState.InProgress:
|
||||
case ScenarioStepState.Done:
|
||||
break;
|
||||
case ScenarioStepState.NotStarted:
|
||||
default:
|
||||
continue;
|
||||
}
|
||||
|
||||
scenarioState.PickedSteps.Add(state.Key.Id);
|
||||
}
|
||||
scenarioState.ScenarioComplete = IsComplete();
|
||||
}
|
||||
|
||||
ScenarioStepRecord GetFirstStep()
|
||||
{
|
||||
// Do it like this because we don't know what order they're in inside the container.
|
||||
ScenarioStepRecord firstStep = null;
|
||||
foreach (var scenarioStep in _data.Steps.Values)
|
||||
{
|
||||
if (scenarioStep.IsBonusObjective())
|
||||
continue;
|
||||
|
||||
if (firstStep == null || scenarioStep.Step < firstStep.Step)
|
||||
firstStep = scenarioStep;
|
||||
}
|
||||
|
||||
return firstStep;
|
||||
}
|
||||
|
||||
public void SendScenarioState(Player player)
|
||||
{
|
||||
ScenarioState scenarioState = new ScenarioState();
|
||||
BuildScenarioState(scenarioState);
|
||||
player.SendPacket(scenarioState);
|
||||
}
|
||||
|
||||
List<BonusObjectiveData> GetBonusObjectivesData()
|
||||
{
|
||||
List<BonusObjectiveData> bonusObjectivesData = new List<BonusObjectiveData>();
|
||||
foreach (var step in _data.Steps.Values)
|
||||
{
|
||||
if (!step.IsBonusObjective())
|
||||
continue;
|
||||
|
||||
if (Global.CriteriaMgr.GetCriteriaTree(step.CriteriaTreeID) != null)
|
||||
{
|
||||
BonusObjectiveData bonusObjectiveData;
|
||||
bonusObjectiveData.BonusObjectiveID = (int)step.Id;
|
||||
bonusObjectiveData.ObjectiveComplete = GetStepState(step) == ScenarioStepState.Done;
|
||||
bonusObjectivesData.Add(bonusObjectiveData);
|
||||
}
|
||||
}
|
||||
|
||||
return bonusObjectivesData;
|
||||
}
|
||||
|
||||
List<CriteriaProgressPkt> GetCriteriasProgress()
|
||||
{
|
||||
List<CriteriaProgressPkt> criteriasProgress = new List<CriteriaProgressPkt>();
|
||||
|
||||
if (!_criteriaProgress.Empty())
|
||||
{
|
||||
foreach (var pair in _criteriaProgress)
|
||||
{
|
||||
CriteriaProgressPkt criteriaProgress = new CriteriaProgressPkt();
|
||||
criteriaProgress.Id = pair.Key;
|
||||
criteriaProgress.Quantity = pair.Value.Counter;
|
||||
criteriaProgress.Date = pair.Value.Date;
|
||||
criteriaProgress.Player = pair.Value.PlayerGUID;
|
||||
criteriasProgress.Add(criteriaProgress);
|
||||
}
|
||||
}
|
||||
|
||||
return criteriasProgress;
|
||||
}
|
||||
|
||||
public override List<Criteria> GetCriteriaByType(CriteriaTypes type)
|
||||
{
|
||||
return Global.CriteriaMgr.GetScenarioCriteriaByType(type);
|
||||
}
|
||||
|
||||
void SendBootPlayer(Player player)
|
||||
{
|
||||
ScenarioBoot scenarioBoot = new ScenarioBoot();
|
||||
scenarioBoot.ScenarioID = (int)_data.Entry.Id;
|
||||
player.SendPacket(scenarioBoot);
|
||||
}
|
||||
|
||||
public virtual void Update(uint diff) { }
|
||||
|
||||
public void SetStepState(ScenarioStepRecord step, ScenarioStepState state) { _stepStates[step] = state; }
|
||||
ScenarioStepRecord GetStep()
|
||||
{
|
||||
return _currentstep;
|
||||
}
|
||||
|
||||
public override void SendCriteriaProgressRemoved(uint criteriaId) { }
|
||||
public override void AfterCriteriaTreeUpdate(CriteriaTree tree, Player referencePlayer) { }
|
||||
public override void SendAllData(Player receiver) { }
|
||||
|
||||
List<ObjectGuid> _players = new List<ObjectGuid>();
|
||||
ScenarioData _data;
|
||||
ScenarioStepRecord _currentstep;
|
||||
Dictionary<ScenarioStepRecord, ScenarioStepState> _stepStates = new Dictionary<ScenarioStepRecord, ScenarioStepState>();
|
||||
}
|
||||
|
||||
public enum ScenarioStepState
|
||||
{
|
||||
Invalid = 0,
|
||||
NotStarted = 1,
|
||||
InProgress = 2,
|
||||
Done = 3
|
||||
}
|
||||
|
||||
enum ScenarioType
|
||||
{
|
||||
Scenario = 0,
|
||||
ChallengeMode = 1,
|
||||
Solo = 2,
|
||||
Dungeon = 10,
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,266 @@
|
||||
/*
|
||||
* Copyright (C) 2012-2017 CypherCore <http://github.com/CypherCore>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
using Framework.Constants;
|
||||
using Framework.Database;
|
||||
using Framework.GameMath;
|
||||
using Game.Achievements;
|
||||
using Game.DataStorage;
|
||||
using Game.Maps;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
namespace Game.Scenarios
|
||||
{
|
||||
public class ScenarioManager : Singleton<ScenarioManager>
|
||||
{
|
||||
ScenarioManager() { }
|
||||
|
||||
public InstanceScenario CreateInstanceScenario(Map map, int team)
|
||||
{
|
||||
var dbData = _scenarioDBData.LookupByKey(Tuple.Create(map.GetId(), (byte)map.GetDifficultyID()));
|
||||
// No scenario registered for this map and difficulty in the database
|
||||
if (dbData == null)
|
||||
return null;
|
||||
|
||||
uint scenarioID = 0;
|
||||
switch (team)
|
||||
{
|
||||
case TeamId.Alliance:
|
||||
scenarioID = dbData.Scenario_A;
|
||||
break;
|
||||
case TeamId.Horde:
|
||||
scenarioID = dbData.Scenario_H;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
var scenarioData = _scenarioData.LookupByKey(scenarioID);
|
||||
if (scenarioData == null)
|
||||
{
|
||||
Log.outError(LogFilter.Scenario, "Table `scenarios` contained data linking scenario (Id: {0}) to map (Id: {1}), difficulty (Id: {2}) but no scenario data was found related to that scenario Id.",
|
||||
scenarioID, map.GetId(), map.GetDifficultyID());
|
||||
return null;
|
||||
}
|
||||
|
||||
return new InstanceScenario(map, scenarioData);
|
||||
}
|
||||
|
||||
public void LoadDBData()
|
||||
{
|
||||
_scenarioDBData.Clear();
|
||||
|
||||
uint oldMSTime = Time.GetMSTime();
|
||||
|
||||
SQLResult result = DB.World.Query("SELECT map, difficulty, scenario_A, scenario_H FROM scenarios");
|
||||
if (result.IsEmpty())
|
||||
{
|
||||
Log.outInfo(LogFilter.ServerLoading, "Loaded 0 scenarios. DB table `scenarios` is empty!");
|
||||
return;
|
||||
}
|
||||
|
||||
do
|
||||
{
|
||||
uint mapId = result.Read<uint>(0);
|
||||
byte difficulty = result.Read<byte>(1);
|
||||
|
||||
uint scenarioAllianceId = result.Read<uint>(2);
|
||||
if (scenarioAllianceId > 0 && !_scenarioData.ContainsKey(scenarioAllianceId))
|
||||
{
|
||||
Log.outError(LogFilter.Sql, "ScenarioMgr.LoadDBData: DB Table `scenarios`, column scenario_A contained an invalid scenario (Id: {0})!", scenarioAllianceId);
|
||||
continue;
|
||||
}
|
||||
|
||||
uint scenarioHordeId = result.Read<uint>(3);
|
||||
if (scenarioHordeId > 0 && !_scenarioData.ContainsKey(scenarioHordeId))
|
||||
{
|
||||
Log.outError(LogFilter.Sql, "ScenarioMgr.LoadDBData: DB Table `scenarios`, column scenario_H contained an invalid scenario (Id: {0})!", scenarioHordeId);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (scenarioHordeId == 0)
|
||||
scenarioHordeId = scenarioAllianceId;
|
||||
|
||||
ScenarioDBData data = new ScenarioDBData();
|
||||
data.MapID = mapId;
|
||||
data.DifficultyID = difficulty;
|
||||
data.Scenario_A = scenarioAllianceId;
|
||||
data.Scenario_H = scenarioHordeId;
|
||||
_scenarioDBData[Tuple.Create(mapId, difficulty)] = data;
|
||||
}
|
||||
while (result.NextRow());
|
||||
|
||||
Log.outInfo(LogFilter.ServerLoading, "Loaded {0} instance scenario entries in {1} ms", _scenarioDBData.Count, Time.GetMSTimeDiffToNow(oldMSTime));
|
||||
}
|
||||
|
||||
public void LoadDB2Data()
|
||||
{
|
||||
_scenarioData.Clear();
|
||||
|
||||
Dictionary<uint, Dictionary<byte, ScenarioStepRecord>> scenarioSteps = new Dictionary<uint, Dictionary<byte, ScenarioStepRecord>>();
|
||||
uint deepestCriteriaTreeSize = 0;
|
||||
|
||||
foreach (ScenarioStepRecord step in CliDB.ScenarioStepStorage.Values)
|
||||
{
|
||||
if (!scenarioSteps.ContainsKey(step.ScenarioID))
|
||||
scenarioSteps[step.ScenarioID] = new Dictionary<byte, ScenarioStepRecord>();
|
||||
|
||||
scenarioSteps[step.ScenarioID][step.Step] = step;
|
||||
CriteriaTree tree = Global.CriteriaMgr.GetCriteriaTree(step.CriteriaTreeID);
|
||||
if (tree != null)
|
||||
{
|
||||
uint criteriaTreeSize = 0;
|
||||
CriteriaManager.WalkCriteriaTree(tree, treeFunc =>
|
||||
{
|
||||
++criteriaTreeSize;
|
||||
});
|
||||
deepestCriteriaTreeSize = Math.Max(deepestCriteriaTreeSize, criteriaTreeSize);
|
||||
}
|
||||
}
|
||||
|
||||
//ASSERT(deepestCriteriaTreeSize < MAX_ALLOWED_SCENARIO_POI_QUERY_SIZE, "MAX_ALLOWED_SCENARIO_POI_QUERY_SIZE must be at least {0}", deepestCriteriaTreeSize + 1);
|
||||
|
||||
foreach (ScenarioRecord scenario in CliDB.ScenarioStorage.Values)
|
||||
{
|
||||
ScenarioData data = new ScenarioData();
|
||||
data.Entry = scenario;
|
||||
data.Steps = scenarioSteps.LookupByKey(scenario.Id);
|
||||
_scenarioData[scenario.Id] = data;
|
||||
}
|
||||
}
|
||||
|
||||
public void LoadScenarioPOI()
|
||||
{
|
||||
uint oldMSTime = Time.GetMSTime();
|
||||
|
||||
_scenarioPOIStore.Clear(); // need for reload case
|
||||
|
||||
uint count = 0;
|
||||
|
||||
// 0 1 2 6 7 8 9 10 11 12
|
||||
SQLResult result = DB.World.Query("SELECT CriteriaTreeID, BlobIndex, Idx1, MapID, WorldMapAreaId, Floor, Priority, Flags, WorldEffectID, PlayerConditionID FROM scenario_poi ORDER BY CriteriaTreeID, Idx1");
|
||||
if (result.IsEmpty())
|
||||
{
|
||||
Log.outInfo(LogFilter.ServerLoading, "Loaded 0 scenario POI definitions. DB table `scenario_poi` is empty.");
|
||||
return;
|
||||
}
|
||||
|
||||
// 0 1 2 3
|
||||
SQLResult points = DB.World.Query("SELECT CriteriaTreeID, Idx1, X, Y FROM scenario_poi_points ORDER BY CriteriaTreeID DESC, Idx1, Idx2");
|
||||
|
||||
List<Vector2>[][] POIs = new List<Vector2>[0][];
|
||||
|
||||
if (!points.IsEmpty())
|
||||
{
|
||||
// The first result should have the highest criteriaTreeId
|
||||
uint criteriaTreeIdMax = result.Read<uint>(0);
|
||||
POIs = new List<Vector2>[criteriaTreeIdMax + 1][];
|
||||
|
||||
do
|
||||
{
|
||||
int CriteriaTreeID = points.Read<int>(0);
|
||||
int Idx1 = points.Read<int>(1);
|
||||
int X = points.Read<int>(2);
|
||||
int Y = points.Read<int>(3);
|
||||
|
||||
if (POIs[CriteriaTreeID].Length <= Idx1 + 1)
|
||||
POIs[CriteriaTreeID] = new List<Vector2>[Idx1 + 10];
|
||||
|
||||
POIs[CriteriaTreeID][Idx1].Add(new Vector2(X, Y));
|
||||
} while (points.NextRow());
|
||||
}
|
||||
|
||||
do
|
||||
{
|
||||
int CriteriaTreeID = result.Read<int>(0);
|
||||
int BlobIndex = result.Read<int>(1);
|
||||
int Idx1 = result.Read<int>(2);
|
||||
int MapID = result.Read<int>(3);
|
||||
int WorldMapAreaId = result.Read<int>(4);
|
||||
int Floor = result.Read<int>(5);
|
||||
int Priority = result.Read<int>(6);
|
||||
int Flags = result.Read<int>(7);
|
||||
int WorldEffectID = result.Read<int>(8);
|
||||
int PlayerConditionID = result.Read<int>(9);
|
||||
|
||||
if (Global.CriteriaMgr.GetCriteriaTree((uint)CriteriaTreeID) == null)
|
||||
Log.outError(LogFilter.Sql, "`scenario_poi` CriteriaTreeID ({0}) Idx1 ({1}) does not correspond to a valid criteria tree", CriteriaTreeID, Idx1);
|
||||
|
||||
if (CriteriaTreeID < POIs.Length && Idx1 < POIs[CriteriaTreeID].Length)
|
||||
_scenarioPOIStore.Add((uint)CriteriaTreeID, new ScenarioPOI(BlobIndex, MapID, WorldMapAreaId, Floor, Priority, Flags, WorldEffectID, PlayerConditionID, POIs[CriteriaTreeID][Idx1]));
|
||||
else
|
||||
Log.outError(LogFilter.ServerLoading, "Table scenario_poi references unknown scenario poi points for criteria tree id {0} POI id {1}", CriteriaTreeID, BlobIndex);
|
||||
|
||||
++count;
|
||||
} while (result.NextRow());
|
||||
|
||||
Log.outInfo(LogFilter.ServerLoading, "Loaded {0} scenario POI definitions in {1} ms", count, Time.GetMSTimeDiffToNow(oldMSTime));
|
||||
}
|
||||
|
||||
public List<ScenarioPOI> GetScenarioPOIs(uint CriteriaTreeID)
|
||||
{
|
||||
if (!_scenarioPOIStore.ContainsKey(CriteriaTreeID))
|
||||
return null;
|
||||
|
||||
return _scenarioPOIStore[CriteriaTreeID];
|
||||
}
|
||||
|
||||
Dictionary<uint, ScenarioData> _scenarioData = new Dictionary<uint, ScenarioData>();
|
||||
MultiMap<uint, ScenarioPOI> _scenarioPOIStore = new MultiMap<uint, ScenarioPOI>();
|
||||
Dictionary<Tuple<uint, byte>, ScenarioDBData> _scenarioDBData = new Dictionary<Tuple<uint, byte>, ScenarioDBData>();
|
||||
}
|
||||
|
||||
public class ScenarioData
|
||||
{
|
||||
public ScenarioRecord Entry;
|
||||
public Dictionary<byte, ScenarioStepRecord> Steps = new Dictionary<byte, ScenarioStepRecord>();
|
||||
}
|
||||
|
||||
class ScenarioDBData
|
||||
{
|
||||
public uint MapID;
|
||||
public byte DifficultyID;
|
||||
public uint Scenario_A;
|
||||
public uint Scenario_H;
|
||||
}
|
||||
|
||||
public class ScenarioPOI
|
||||
{
|
||||
public ScenarioPOI(int blobIndex, int mapID, int worldMapAreaID, int floor, int priority, int flags, int worldEffectID, int playerConditionID, List<Vector2> points)
|
||||
{
|
||||
BlobIndex = blobIndex;
|
||||
MapID = mapID;
|
||||
WorldMapAreaID = worldMapAreaID;
|
||||
Floor = floor;
|
||||
Priority = priority;
|
||||
Flags = flags;
|
||||
WorldEffectID = worldEffectID;
|
||||
PlayerConditionID = playerConditionID;
|
||||
Points = points;
|
||||
}
|
||||
|
||||
public int BlobIndex;
|
||||
public int MapID;
|
||||
public int WorldMapAreaID;
|
||||
public int Floor;
|
||||
public int Priority;
|
||||
public int Flags;
|
||||
public int WorldEffectID;
|
||||
public int PlayerConditionID;
|
||||
public List<Vector2> Points = new List<Vector2>();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user