Core/Creatures: Taxi improvements

* Fixed flight master minimap icon
* Fixed crash on Argus
* Implemented teleport taxi nodes
Port From (https://github.com/TrinityCore/TrinityCore/commit/73e0b3e77c04a7821f58d79211f344b9129602f1)
This commit is contained in:
hondacrx
2024-02-02 10:20:04 -05:00
parent 80f4ece2e5
commit 871928ebb7
9 changed files with 126 additions and 67 deletions
+26 -18
View File
@@ -358,7 +358,15 @@ namespace Game.Entities
// checked and error show at loading templates
var factionTemplate = CliDB.FactionTemplateStorage.LookupByKey(cInfo.Faction);
if (factionTemplate != null)
{
SetPvP(factionTemplate.Flags.HasAnyFlag((ushort)FactionTemplateFlags.PVP));
if (IsTaxi())
{
uint taxiNodesId = Global.ObjectMgr.GetNearestTaxiNode(GetPositionX(), GetPositionY(), GetPositionZ(), GetMapId(),
(factionTemplate.FactionGroup & (byte)FactionMasks.Alliance) != 0 ? Team.Alliance : Team.Horde);
SetUpdateFieldValue(m_values.ModifyValue(m_unitData).ModifyValue(m_unitData.TaxiNodesID), (int)taxiNodesId);
}
}
// updates spell bars for vehicles and set player's faction - should be called here, to overwrite faction that is set from the new template
if (IsVehicle())
@@ -407,7 +415,7 @@ namespace Game.Entities
// Apply all other side effects of flag changes
SetTemplateRooted(flags.HasFlag(CreatureStaticFlags.Sessile));
}
public override void Update(uint diff)
{
if (IsAIEnabled() && triggerJustAppeared && m_deathState != DeathState.Dead)
@@ -1132,14 +1140,14 @@ namespace Game.Entities
SummonCreature(npcEntry, GetPosition(), TempSummonType.TimedDespawn, TimeSpan.FromSeconds(1), 0, 0);
}
public bool HasFlag(CreatureStaticFlags flag) { return _staticFlags.HasFlag(flag); }
public bool HasFlag(CreatureStaticFlags2 flag) { return _staticFlags.HasFlag(flag); }
public bool HasFlag(CreatureStaticFlags3 flag) { return _staticFlags.HasFlag(flag); }
public bool HasFlag(CreatureStaticFlags4 flag) { return _staticFlags.HasFlag(flag); }
public bool HasFlag(CreatureStaticFlags5 flag) { return _staticFlags.HasFlag(flag); }
public bool HasFlag(CreatureStaticFlags6 flag) { return _staticFlags.HasFlag(flag); }
public bool HasFlag(CreatureStaticFlags7 flag) { return _staticFlags.HasFlag(flag); }
public bool HasFlag(CreatureStaticFlags8 flag) { return _staticFlags.HasFlag(flag); }
public bool HasFlag(CreatureStaticFlags flag) { return _staticFlags.HasFlag(flag); }
public bool HasFlag(CreatureStaticFlags2 flag) { return _staticFlags.HasFlag(flag); }
public bool HasFlag(CreatureStaticFlags3 flag) { return _staticFlags.HasFlag(flag); }
public bool HasFlag(CreatureStaticFlags4 flag) { return _staticFlags.HasFlag(flag); }
public bool HasFlag(CreatureStaticFlags5 flag) { return _staticFlags.HasFlag(flag); }
public bool HasFlag(CreatureStaticFlags6 flag) { return _staticFlags.HasFlag(flag); }
public bool HasFlag(CreatureStaticFlags7 flag) { return _staticFlags.HasFlag(flag); }
public bool HasFlag(CreatureStaticFlags8 flag) { return _staticFlags.HasFlag(flag); }
public uint GetGossipMenuId()
{
@@ -1150,7 +1158,7 @@ namespace Game.Entities
{
_gossipMenuId = gossipMenuId;
}
public uint GetTrainerId()
{
if (_trainerId.HasValue)
@@ -1202,7 +1210,7 @@ namespace Game.Entities
}
public bool IsTapListNotClearedOnEvade() { return m_dontClearTapListOnEvade; }
public void SetTappedBy(Unit unit, bool withGroup = true)
{
// set the player whose group should receive the right
@@ -1285,7 +1293,7 @@ namespace Game.Entities
public bool CanHaveLoot() { return !_staticFlags.HasFlag(CreatureStaticFlags.NoLoot); }
public void SetCanHaveLoot(bool canHaveLoot) { _staticFlags.ApplyFlag(CreatureStaticFlags.NoLoot, !canHaveLoot); }
public void SaveToDB()
{
// this should only be used when the creature has already been loaded
@@ -1633,7 +1641,7 @@ namespace Game.Entities
return true;
}
bool CreateFromProto(ulong guidlow, uint entry, CreatureData data = null, uint vehId = 0)
{
SetZoneScript();
@@ -1740,7 +1748,7 @@ namespace Game.Entities
}
public bool IsTemplateRooted() { return _staticFlags.HasFlag(CreatureStaticFlags.Sessile); }
public void SetTemplateRooted(bool rooted)
{
_staticFlags.ApplyFlag(CreatureStaticFlags.Sessile, rooted);
@@ -3295,7 +3303,7 @@ namespace Game.Entities
return (CreatureAI)i_AI;
}
public T GetAI<T>() where T : CreatureAI
public new T GetAI<T>() where T : CreatureAI
{
return (T)i_AI;
}
@@ -3308,7 +3316,7 @@ namespace Game.Entities
public void SetCanMelee(bool canMelee) { _staticFlags.ApplyFlag(CreatureStaticFlags.NoMelee, !canMelee); }
public bool CanIgnoreLineOfSightWhenCastingOnMe() { return _staticFlags.HasFlag(CreatureStaticFlags4.IgnoreLosWhenCastingOnMe); }
public sbyte GetOriginalEquipmentId() { return m_originalEquipmentId; }
public byte GetCurrentEquipmentId() { return m_equipmentId; }
public void SetCurrentEquipmentId(byte id) { m_equipmentId = id; }
@@ -3316,7 +3324,7 @@ namespace Game.Entities
public CreatureTemplate GetCreatureTemplate() { return m_creatureInfo; }
public CreatureData GetCreatureData() { return m_creatureData; }
public CreatureDifficulty GetCreatureDifficulty() { return m_creatureDifficulty; }
public override bool LoadFromDB(ulong spawnId, Map map, bool addToMap, bool allowDuplicate)
{
if (!allowDuplicate)
@@ -3458,7 +3466,7 @@ namespace Game.Entities
bool CanRegenerateHealth() { return !_staticFlags.HasFlag(CreatureStaticFlags5.NoHealthRegen) && _regenerateHealth; }
public void SetRegenerateHealth(bool value) { _staticFlags.ApplyFlag(CreatureStaticFlags5.NoHealthRegen, !value); }
public void SetHomePosition(float x, float y, float z, float o)
{
m_homePosition.Relocate(x, y, z, o);
+1 -1
View File
@@ -7036,7 +7036,7 @@ namespace Game.Entities
// change but I couldn't find a suitable alternative. OK to use class because only DK
// can use this taxi.
uint mount_display_id;
if (node.Flags.HasAnyFlag(TaxiNodeFlags.UseFavoriteMount) && preferredMountDisplay != 0)
if (node.GetFlags().HasFlag(TaxiNodeFlags.UsePlayerFavoriteMount) && preferredMountDisplay != 0)
mount_display_id = preferredMountDisplay;
else
mount_display_id = ObjectMgr.GetTaxiMountDisplayId(sourcenode, GetTeam(), npc == null || (sourcenode == 315 && GetClass() == Class.Deathknight));
+28 -19
View File
@@ -84,7 +84,7 @@ namespace Game.Entities
static uint GetVertexIDFromNodeID(TaxiNodesRecord node)
{
return m_verticesByNode.ContainsKey(node.Id) ? m_verticesByNode[node.Id] : uint.MaxValue;
return m_verticesByNode.LookupByKey(node.Id);
}
static uint GetNodeIDFromVertexID(uint vertexID)
@@ -107,7 +107,7 @@ namespace Game.Entities
{
TaxiNodesRecord from = CliDB.TaxiNodesStorage.LookupByKey(path.FromTaxiNode);
TaxiNodesRecord to = CliDB.TaxiNodesStorage.LookupByKey(path.ToTaxiNode);
if (from != null && to != null && from.Flags.HasAnyFlag(TaxiNodeFlags.Alliance | TaxiNodeFlags.Horde) && to.Flags.HasAnyFlag(TaxiNodeFlags.Alliance | TaxiNodeFlags.Horde))
if (from != null && to != null && from.IsPartOfTaxiNetwork() && to.IsPartOfTaxiNetwork())
AddVerticeAndEdgeFromNodeInfo(from, to, path.Id, edges);
}
@@ -141,25 +141,30 @@ namespace Game.Entities
else
{
shortestPath.Clear();
// We want to use Dijkstra on this graph
DijkstraShortestPath g = new(m_graph, (int)GetVertexIDFromNodeID(from));
var path = g.PathTo((int)GetVertexIDFromNodeID(to));
// found a path to the goal
shortestPath.Add(from.Id);
foreach (var edge in path)
{
//todo test me No clue about this....
var To = m_nodesByVertex[(int)edge.To];
TaxiNodeFlags requireFlag = (player.GetTeam() == Team.Alliance) ? TaxiNodeFlags.Alliance : TaxiNodeFlags.Horde;
if (!To.Flags.HasAnyFlag(requireFlag))
continue;
PlayerConditionRecord condition = CliDB.PlayerConditionStorage.LookupByKey(To.ConditionID);
if (condition != null)
if (!ConditionManager.IsPlayerMeetingCondition(player, condition))
uint fromVertexId = GetVertexIDFromNodeID(from);
uint toVertexId = GetVertexIDFromNodeID(to);
if (fromVertexId != 0 && toVertexId != 0)
{
// We want to use Dijkstra on this graph
DijkstraShortestPath dijkstra = new(m_graph, (int)fromVertexId);
var path = dijkstra.PathTo((int)toVertexId);
// found a path to the goal
shortestPath.Add(from.Id);
foreach (var edge in path)
{
var To = m_nodesByVertex[(int)edge.To];
TaxiNodeFlags requireFlag = (player.GetTeam() == Team.Alliance) ? TaxiNodeFlags.ShowOnAllianceMap : TaxiNodeFlags.ShowOnHordeMap;
if (!To.GetFlags().HasFlag(requireFlag))
continue;
shortestPath.Add(GetNodeIDFromVertexID(edge.To));
PlayerConditionRecord condition = CliDB.PlayerConditionStorage.LookupByKey(To.ConditionID);
if (condition != null)
if (!ConditionManager.IsPlayerMeetingCondition(player, condition))
continue;
shortestPath.Add(GetNodeIDFromVertexID(edge.To));
}
}
}
@@ -169,7 +174,11 @@ namespace Game.Entities
//todo test me
public static void GetReachableNodesMask(TaxiNodesRecord from, byte[] mask)
{
DepthFirstSearch depthFirst = new(m_graph, GetVertexIDFromNodeID(from), vertex =>
uint vertexId = GetVertexIDFromNodeID(from);
if (vertexId == 0)
return;
DepthFirstSearch depthFirst = new(m_graph, vertexId, vertex =>
{
TaxiNodesRecord taxiNode = CliDB.TaxiNodesStorage.LookupByKey(GetNodeIDFromVertexID(vertex));
if (taxiNode != null)