Core/Spells: Implement SPELL_EFFECT_TELEPORT_TO_RETURN_POINT

Port From (https://github.com/TrinityCore/TrinityCore/commit/1c852af7f2c820e429eaf8389822e8c910f961a1)
This commit is contained in:
hondacrx
2021-03-29 16:36:05 -04:00
parent 369e36819d
commit 047a6babfc
11 changed files with 208 additions and 7 deletions
@@ -92,7 +92,7 @@ namespace Framework.Constants
ModStalked = 68,
SchoolAbsorb = 69,
PeriodicWeaponPercentDamage = 70,
StoreTeleportReturnPoint = 71, // NYI
StoreTeleportReturnPoint = 71,
ModPowerCostSchoolPct = 72,
ModPowerCostSchool = 73,
ReflectSpellsSchool = 74,
+1
View File
@@ -62,6 +62,7 @@ namespace Framework.Constants
Ejectable = 0x20, // Ejectable
UsableForced2 = 0x40,
UsableForced3 = 0x100,
PassengerMirrorsAnims = 0x10000, // Passenger forced to repeat all vehicle animations
KeepPet = 0x20000,
UsableForced4 = 0x02000000,
CanSwitch = 0x4000000,
@@ -793,6 +793,12 @@ namespace Framework.Database
PrepareStatement(CharStatements.DEL_SCENARIO_INSTANCE_CRITERIA, "DELETE FROM instance_scenario_progress WHERE id = ? AND criteria = ?");
PrepareStatement(CharStatements.INS_SCENARIO_INSTANCE_CRITERIA, "INSERT INTO instance_scenario_progress (id, criteria, counter, date) VALUES (?, ?, ?, ?)");
PrepareStatement(CharStatements.DEL_SCENARIO_INSTANCE_CRITERIA_FOR_INSTANCE, "DELETE FROM instance_scenario_progress WHERE id = ?");
// Spell Location
PrepareStatement(CharStatements.SEL_CHARACTER_AURA_STORED_LOCATIONS, "SELECT Spell, MapId, PositionX, PositionY, PositionZ, Orientation FROM character_aura_stored_location WHERE Guid = ?");
PrepareStatement(CharStatements.DEL_CHARACTER_AURA_STORED_LOCATIONS_BY_GUID, "DELETE FROM character_aura_stored_location WHERE Guid = ?");
PrepareStatement(CharStatements.DEL_CHARACTER_AURA_STORED_LOCATION, "DELETE FROM character_aura_stored_location WHERE Guid = ? AND Spell = ?");
PrepareStatement(CharStatements.INS_CHARACTER_AURA_STORED_LOCATION, "INSERT INTO character_aura_stored_location (Guid, Spell, MapId, PositionX, PositionY, PositionZ, Orientation) VALUES (?, ?, ?, ?, ?, ?, ?)");
}
}
@@ -1442,6 +1448,11 @@ namespace Framework.Database
INS_SCENARIO_INSTANCE_CRITERIA,
DEL_SCENARIO_INSTANCE_CRITERIA_FOR_INSTANCE,
SEL_CHARACTER_AURA_STORED_LOCATIONS,
DEL_CHARACTER_AURA_STORED_LOCATIONS_BY_GUID,
DEL_CHARACTER_AURA_STORED_LOCATION,
INS_CHARACTER_AURA_STORED_LOCATION,
MAX_CHARACTERDATABASE_STATEMENTS
}
}
+72
View File
@@ -1353,6 +1353,38 @@ namespace Game.Entities
SetArenaTeamInfoField(slot, ArenaTeamInfoType.PersonalRating, personalRatingCache[slot]);
}
}
void _LoadStoredAuraTeleportLocations(SQLResult result)
{
// 0 1 2 3 4 5
//QueryResult* result = CharacterDatabase.PQuery("SELECT Spell, MapId, PositionX, PositionY, PositionZ, Orientation FROM character_spell_location WHERE Guid = ?", GetGUIDLow());
m_storedAuraTeleportLocations.Clear();
if (!result.IsEmpty())
{
do
{
uint spellId = result.Read<uint>(0);
if (!Global.SpellMgr.HasSpellInfo(spellId, Difficulty.None))
{
Log.outError(LogFilter.Spells, $"Player._LoadStoredAuraTeleportLocations: Player {GetName()} ({GetGUID()}) spell (ID: {spellId}) does not exist");
continue;
}
WorldLocation location = new WorldLocation(result.Read<uint>(1), result.Read<float>(2), result.Read<float>(3), result.Read<float>(4), result.Read<float>(5));
if (!GridDefines.IsValidMapCoord(location))
{
Log.outError(LogFilter.Spells, $"Player._LoadStoredAuraTeleportLocations: Player {GetName()} ({GetGUID()}) spell (ID: {spellId}) has invalid position on map {location.GetMapId()}, {location}.");
continue;
}
StoredAuraTeleportLocation storedLocation = m_storedAuraTeleportLocations[spellId];
storedLocation.Loc = location;
storedLocation.CurrentState = StoredAuraTeleportLocation.State.Unchanged;
}
while (result.NextRow());
}
}
void _LoadGroup(SQLResult result)
{
if (!result.IsEmpty())
@@ -2188,6 +2220,38 @@ namespace Game.Entities
m_mailsUpdated = false;
}
void _SaveStoredAuraTeleportLocations(SQLTransaction trans)
{
foreach (var pair in m_storedAuraTeleportLocations.ToList())
{
var storedLocation = pair.Value;
if (storedLocation.CurrentState == StoredAuraTeleportLocation.State.Deleted)
{
PreparedStatement stmt = DB.Characters.GetPreparedStatement(CharStatements.DEL_CHARACTER_AURA_STORED_LOCATION);
stmt.AddValue(0, GetGUID().GetCounter());
trans.Append(stmt);
m_storedAuraTeleportLocations.Remove(pair.Key);
continue;
}
if (storedLocation.CurrentState == StoredAuraTeleportLocation.State.Changed)
{
PreparedStatement stmt = DB.Characters.GetPreparedStatement(CharStatements.DEL_CHARACTER_AURA_STORED_LOCATION);
stmt.AddValue(0, GetGUID().GetCounter());
trans.Append(stmt);
stmt = DB.Characters.GetPreparedStatement(CharStatements.INS_CHARACTER_AURA_STORED_LOCATION);
stmt.AddValue(0, GetGUID().GetCounter());
stmt.AddValue(1, pair.Key);
stmt.AddValue(2, storedLocation.Loc.GetMapId());
stmt.AddValue(3, storedLocation.Loc.GetPositionX());
stmt.AddValue(4, storedLocation.Loc.GetPositionY());
stmt.AddValue(5, storedLocation.Loc.GetPositionZ());
stmt.AddValue(6, storedLocation.Loc.GetOrientation());
trans.Append(stmt);
}
}
}
void _SaveStats(SQLTransaction trans)
{
// check if stat saving is enabled and if char level is high enough
@@ -3036,6 +3100,9 @@ namespace Game.Entities
if (HasPlayerFlag(PlayerFlags.Ghost))
m_deathState = DeathState.Dead;
// Load spell locations - must be after loading auras
_LoadStoredAuraTeleportLocations(holder.GetResult(PlayerLoginQueryLoad.AuraStoredLocations));
// after spell load, learn rewarded spell if need also
_LoadQuestStatus(holder.GetResult(PlayerLoginQueryLoad.QuestStatus));
_LoadQuestStatusObjectives(holder.GetResult(PlayerLoginQueryLoad.QuestStatusObjectives));
@@ -3572,6 +3639,7 @@ namespace Game.Entities
_SaveActions(characterTransaction);
_SaveAuras(characterTransaction);
_SaveSkills(characterTransaction);
_SaveStoredAuraTeleportLocations(characterTransaction);
m_achievementSys.SaveToDB(characterTransaction);
reputationMgr.SaveToDB(characterTransaction);
m_questObjectiveCriteriaMgr.SaveToDB(characterTransaction);
@@ -4096,6 +4164,10 @@ namespace Game.Entities
stmt.AddValue(0, guid);
trans.Append(stmt);
stmt = DB.Characters.GetPreparedStatement(CharStatements.DEL_CHARACTER_AURA_STORED_LOCATIONS_BY_GUID);
stmt.AddValue(0, guid);
trans.Append(stmt);
Corpse.DeleteFromDB(playerGuid, trans);
Garrison.DeleteFromDB(guid, trans);
@@ -120,6 +120,7 @@ namespace Game.Entities
MultiMap<uint, uint> m_overrideSpells = new();
public Spell m_spellModTakingSpell;
uint m_oldpetspell;
Dictionary<uint, StoredAuraTeleportLocation> m_storedAuraTeleportLocations = new();
//Mail
List<Mail> m_mail = new();
@@ -611,4 +612,17 @@ namespace Game.Entities
public ObjectGuid GroupGuid;
public int UpdateSequenceNumber;
}
class StoredAuraTeleportLocation
{
public WorldLocation Loc;
public State CurrentState;
public enum State
{
Unchanged,
Changed,
Deleted
}
}
}
@@ -2288,6 +2288,31 @@ namespace Game.Entities
return false;
}
public void AddStoredAuraTeleportLocation(uint spellId)
{
StoredAuraTeleportLocation storedLocation = new();
storedLocation.Loc = new WorldLocation(this);
storedLocation.CurrentState = StoredAuraTeleportLocation.State.Changed;
m_storedAuraTeleportLocations[spellId] = storedLocation;
}
public void RemoveStoredAuraTeleportLocation(uint spellId)
{
StoredAuraTeleportLocation storedLocation = m_storedAuraTeleportLocations.LookupByKey(spellId);
if (storedLocation != null)
storedLocation.CurrentState = StoredAuraTeleportLocation.State.Deleted;
}
public WorldLocation GetStoredAuraTeleportLocation(uint spellId)
{
StoredAuraTeleportLocation auraLocation = m_storedAuraTeleportLocations.LookupByKey(spellId);
if (auraLocation != null)
return auraLocation.Loc;
return null;
}
bool AddSpell(uint spellId, bool active, bool learning, bool dependent, bool disabled, bool loading = false, uint fromSkill = 0)
{
SpellInfo spellInfo = Global.SpellMgr.GetSpellInfo(spellId, Difficulty.None);
+5
View File
@@ -2570,6 +2570,10 @@ namespace Game
stmt.AddValue(0, lowGuid);
SetQuery(PlayerLoginQueryLoad.AuraEffects, stmt);
stmt = DB.Characters.GetPreparedStatement(CharStatements.SEL_CHARACTER_AURA_STORED_LOCATIONS);
stmt.AddValue(0, lowGuid);
SetQuery(PlayerLoginQueryLoad.AuraStoredLocations, stmt);
stmt = DB.Characters.GetPreparedStatement(CharStatements.SEL_CHARACTER_SPELL);
stmt.AddValue(0, lowGuid);
SetQuery(PlayerLoginQueryLoad.Spells, stmt);
@@ -2818,6 +2822,7 @@ namespace Game
BoundInstances,
Auras,
AuraEffects,
AuraStoredLocations,
Spells,
QuestStatus,
QuestStatusObjectives,
+21 -5
View File
@@ -139,7 +139,7 @@ namespace Game.Spells
return totalTicks;
}
void ResetPeriodic(bool resetPeriodicTimer = false)
{
_ticksDone = 0;
@@ -774,9 +774,9 @@ namespace Game.Spells
public void SetPeriodicTimer(int periodicTimer) { _periodicTimer = periodicTimer; }
void RecalculateAmount(AuraEffect triggeredBy = null)
{
{
if (!CanBeRecalculated())
return;
return;
ChangeAmount(CalculateAmount(GetCaster()), false, false, triggeredBy);
}
@@ -3099,7 +3099,7 @@ namespace Game.Spells
player.UpdateArmor();
}
[AuraEffectHandler(AuraType.ModStatBonusPct)]
void HandleModStatBonusPercent(AuraApplication aurApp, AuraEffectHandleModes mode, bool apply)
{
@@ -4640,7 +4640,7 @@ namespace Game.Spells
target.CastSpell(target, triggerSpell, true);
}
[AuraEffectHandler(AuraType.OpenStable)]
void HandleAuraOpenStable(AuraApplication aurApp, AuraEffectHandleModes mode, bool apply)
{
@@ -5698,6 +5698,22 @@ namespace Game.Spells
else
bg.RemovePlayerPosition(target.GetGUID());
}
[AuraEffectHandler(AuraType.StoreTeleportReturnPoint)]
void HandleStoreTeleportReturnPoint(AuraApplication aurApp, AuraEffectHandleModes mode, bool apply)
{
if (!mode.HasAnyFlag(AuraEffectHandleModes.Real))
return;
Player playerTarget = aurApp.GetTarget().ToPlayer();
if (playerTarget == null)
return;
if (apply)
playerTarget.AddStoredAuraTeleportLocation(GetSpellInfo().Id);
else if (!playerTarget.GetSession().IsLogingOut())
playerTarget.RemoveStoredAuraTeleportLocation(GetSpellInfo().Id);
}
#endregion
}
+14
View File
@@ -5139,6 +5139,20 @@ namespace Game.Spells
player.SendPacket(packet);
}
void EffectTeleportToReturnPoint(uint effIndex)
{
if (effectHandleMode != SpellEffectHandleMode.HitTarget)
return;
Player player = unitTarget.ToPlayer();
if (player != null)
{
WorldLocation dest = player.GetStoredAuraTeleportLocation((uint)effectInfo.MiscValue);
if (dest != null)
player.TeleportTo(dest, unitTarget == m_caster ? TeleportToOptions.Spell | TeleportToOptions.NotLeaveCombat : 0);
}
}
[SpellEffectHandler(SpellEffectName.SummonRafFriend)]
void EffectSummonRaFFriend(uint effIndex)
{