Core/Creatures: Implemented serverside checks for UNIT_FLAG2_INTERACT_WHILE_HOSTILE and UNIT_FLAG3_ALLOW_INTERACTION_WHILE_IN_COMBAT
* Also stop sending npc flags for hostile creatures Port From (https://github.com/TrinityCore/TrinityCore/commit/c2e36dea6c6af6139bf60454e9299447ec7d9897)
This commit is contained in:
@@ -286,6 +286,7 @@ namespace Game.Entities
|
||||
|
||||
// TODO: migrate these in DB
|
||||
_staticFlags.ApplyFlag(CreatureStaticFlags2.AllowMountedCombat, GetCreatureDifficulty().TypeFlags.HasFlag(CreatureTypeFlags.AllowMountedCombat));
|
||||
SetInteractionAllowedInCombat(GetCreatureDifficulty().TypeFlags.HasAnyFlag(CreatureTypeFlags.AllowInteractionWhileInCombat));
|
||||
SetTreatAsRaidUnit(GetCreatureDifficulty().TypeFlags.HasAnyFlag(CreatureTypeFlags.TreatAsRaidUnit));
|
||||
|
||||
return true;
|
||||
@@ -2756,6 +2757,33 @@ namespace Game.Entities
|
||||
m_respawnTime = Math.Max(m_corpseRemoveTime + m_respawnDelay, m_respawnTime);
|
||||
}
|
||||
|
||||
public override void SetInteractionAllowedWhileHostile(bool interactionAllowed)
|
||||
{
|
||||
_staticFlags.ApplyFlag(CreatureStaticFlags5.InteractWhileHostile, interactionAllowed);
|
||||
base.SetInteractionAllowedWhileHostile(interactionAllowed);
|
||||
}
|
||||
|
||||
public override void SetInteractionAllowedInCombat(bool interactionAllowed)
|
||||
{
|
||||
_staticFlags.ApplyFlag(CreatureStaticFlags3.AllowInteractionWhileInCombat, interactionAllowed);
|
||||
base.SetInteractionAllowedInCombat(interactionAllowed);
|
||||
}
|
||||
|
||||
public override void UpdateNearbyPlayersInteractions()
|
||||
{
|
||||
base.UpdateNearbyPlayersInteractions();
|
||||
|
||||
// If as a result of npcflag updates we stop seeing UNIT_NPC_FLAG_QUESTGIVER then
|
||||
// we must also send SMSG_QUEST_GIVER_STATUS_MULTIPLE because client will not request it automatically
|
||||
if (IsQuestGiver())
|
||||
{
|
||||
var sender = (Player receiver) => receiver.PlayerTalkClass.SendQuestGiverStatus(receiver.GetQuestDialogStatus(this), GetGUID());
|
||||
|
||||
MessageDistDeliverer notifier = new(this, sender, GetVisibilityRange());
|
||||
Cell.VisitWorldObjects(this, notifier, GetVisibilityRange());
|
||||
}
|
||||
}
|
||||
|
||||
public bool HasScalableLevels()
|
||||
{
|
||||
return m_unitData.ContentTuningID != 0;
|
||||
|
||||
@@ -2332,16 +2332,25 @@ namespace Game.Entities
|
||||
uint GetViewerDependentNpcFlags(UnitData unitData, int i, Unit unit, Player receiver)
|
||||
{
|
||||
uint npcFlag = unitData.NpcFlags[i];
|
||||
if (i == 0)
|
||||
if (npcFlag != 0)
|
||||
{
|
||||
Creature creature = unit.ToCreature();
|
||||
if (creature != null)
|
||||
if ((!unit.IsInteractionAllowedInCombat() && unit.IsInCombat())
|
||||
|| (!unit.IsInteractionAllowedWhileHostile() && unit.IsHostileTo(receiver)))
|
||||
npcFlag = 0;
|
||||
else
|
||||
{
|
||||
if (!receiver.CanSeeGossipOn(creature))
|
||||
npcFlag &= ~(uint)(NPCFlags.Gossip | NPCFlags.QuestGiver);
|
||||
Creature creature = unit.ToCreature();
|
||||
if (creature != null)
|
||||
{
|
||||
if (i == 0)
|
||||
{
|
||||
if (!receiver.CanSeeGossipOn(creature))
|
||||
npcFlag &= ~(uint)(NPCFlags.Gossip | NPCFlags.QuestGiver);
|
||||
|
||||
if (!receiver.CanSeeSpellClickOn(creature))
|
||||
npcFlag &= ~(uint)NPCFlags.SpellClick;
|
||||
if (!receiver.CanSeeSpellClickOn(creature))
|
||||
npcFlag &= ~(uint)NPCFlags.SpellClick;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -2032,6 +2032,14 @@ namespace Game.Entities
|
||||
}
|
||||
case TypeId.Unit:
|
||||
{
|
||||
Creature questGiverCreature = questgiver.ToCreature();
|
||||
if (!questGiverCreature.IsInteractionAllowedWhileHostile() && questGiverCreature.IsHostileTo(this))
|
||||
return QuestGiverStatus.None;
|
||||
|
||||
if (!questGiverCreature.IsInteractionAllowedInCombat() && questGiverCreature.IsInCombat())
|
||||
return QuestGiverStatus.None;
|
||||
|
||||
|
||||
CreatureAI ai = questgiver.ToCreature().GetAI();
|
||||
if (ai != null)
|
||||
{
|
||||
@@ -3220,7 +3228,7 @@ namespace Game.Entities
|
||||
{
|
||||
// need also pet quests case support
|
||||
Creature questgiver = ObjectAccessor.GetCreatureOrPetOrVehicle(this, itr);
|
||||
if (questgiver == null || questgiver.IsHostileTo(this))
|
||||
if (questgiver == null)
|
||||
continue;
|
||||
|
||||
if (!questgiver.HasNpcFlag(NPCFlags.QuestGiver))
|
||||
|
||||
@@ -5472,7 +5472,10 @@ namespace Game.Entities
|
||||
return null;
|
||||
|
||||
// not unfriendly/hostile
|
||||
if (!creature.HasUnitFlag2(UnitFlags2.InteractWhileHostile) && creature.GetReactionTo(this) <= ReputationRank.Unfriendly)
|
||||
if (!creature.IsInteractionAllowedWhileHostile() && creature.GetReactionTo(this) <= ReputationRank.Unfriendly)
|
||||
return nullptr;
|
||||
|
||||
if (creature.IsInCombat() && !creature.IsInteractionAllowedInCombat())
|
||||
return null;
|
||||
|
||||
// not too far, taken from CGGameUI::SetInteractTarget
|
||||
|
||||
@@ -35,6 +35,9 @@ namespace Game.Entities
|
||||
|
||||
RemoveAurasWithInterruptFlags(SpellAuraInterruptFlags.EnteringCombat);
|
||||
ProcSkillsAndAuras(this, null, new ProcFlagsInit(ProcFlags.EnterCombat), new ProcFlagsInit(ProcFlags.None), ProcFlagsSpellType.MaskAll, ProcFlagsSpellPhase.None, ProcFlagsHit.None, null, null, null);
|
||||
|
||||
if (!IsInteractionAllowedInCombat())
|
||||
UpdateNearbyPlayersInteractions();
|
||||
}
|
||||
|
||||
public virtual void AtExitCombat()
|
||||
@@ -43,6 +46,9 @@ namespace Game.Entities
|
||||
pair.Value.GetBase().CallScriptEnterLeaveCombatHandlers(pair.Value, false);
|
||||
|
||||
RemoveAurasWithInterruptFlags(SpellAuraInterruptFlags.LeavingCombat);
|
||||
|
||||
if (!IsInteractionAllowedInCombat())
|
||||
UpdateNearbyPlayersInteractions();
|
||||
}
|
||||
|
||||
public virtual void AtEngage(Unit target) { }
|
||||
@@ -1654,5 +1660,46 @@ namespace Game.Entities
|
||||
/// enables / disables combat interaction of this unit
|
||||
/// </summary>
|
||||
public void SetIsCombatDisallowed(bool apply) { _isCombatDisallowed = apply; }
|
||||
|
||||
public bool IsInteractionAllowedWhileHostile()
|
||||
{
|
||||
return HasUnitFlag2(UnitFlags2.InteractWhileHostile);
|
||||
}
|
||||
|
||||
public virtual void SetInteractionAllowedWhileHostile(bool interactionAllowed)
|
||||
{
|
||||
if (interactionAllowed)
|
||||
SetUnitFlag2(UnitFlags2.InteractWhileHostile);
|
||||
else
|
||||
RemoveUnitFlag2(UnitFlags2.InteractWhileHostile);
|
||||
|
||||
UpdateNearbyPlayersInteractions();
|
||||
}
|
||||
|
||||
public bool IsInteractionAllowedInCombat()
|
||||
{
|
||||
return HasUnitFlag3(UnitFlags3.AllowInteractionWhileInCombat);
|
||||
}
|
||||
|
||||
public virtual void SetInteractionAllowedInCombat(bool interactionAllowed)
|
||||
{
|
||||
if (interactionAllowed)
|
||||
SetUnitFlag3(UnitFlags3.AllowInteractionWhileInCombat);
|
||||
else
|
||||
RemoveUnitFlag3(UnitFlags3.AllowInteractionWhileInCombat);
|
||||
|
||||
if (IsInCombat())
|
||||
UpdateNearbyPlayersInteractions();
|
||||
}
|
||||
|
||||
public virtual void UpdateNearbyPlayersInteractions()
|
||||
{
|
||||
for (int i = 0; i < m_unitData.NpcFlags.GetSize(); ++i)
|
||||
if (m_unitData.NpcFlags[i] != 0)
|
||||
{
|
||||
m_values.ModifyValue(m_unitData).ModifyValue(m_unitData.NpcFlags, i);
|
||||
ForceUpdateFieldChange();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -98,7 +98,12 @@ namespace Game
|
||||
if (staticFlags.HasFlag(CreatureStaticFlags3.CannotTurn))
|
||||
unitFlags2 |= (uint)UnitFlags2.CannotTurn;
|
||||
|
||||
if (staticFlags.HasFlag(CreatureStaticFlags5.InteractWhileHostile))
|
||||
unitFlags2 |= (uint)UnitFlags2.InteractWhileHostile;
|
||||
|
||||
unitFlags3 = data != null && data.unit_flags3.HasValue ? data.unit_flags3.Value : cInfo.UnitFlags3;
|
||||
if (staticFlags.HasFlag(CreatureStaticFlags3.AllowInteractionWhileInCombat))
|
||||
unitFlags3 |= (uint)UnitFlags3.AllowInteractionWhileInCombat;
|
||||
}
|
||||
|
||||
public static ResponseCodes CheckPlayerName(string name, Locale locale, bool create = false)
|
||||
|
||||
@@ -17,28 +17,14 @@ namespace Game
|
||||
[WorldPacketHandler(ClientOpcodes.QuestGiverStatusQuery, Processing = PacketProcessing.Inplace)]
|
||||
void HandleQuestgiverStatusQuery(QuestGiverStatusQuery packet)
|
||||
{
|
||||
QuestGiverStatus questStatus = QuestGiverStatus.None;
|
||||
|
||||
var questgiver = Global.ObjAccessor.GetObjectByTypeMask(GetPlayer(), packet.QuestGiverGUID, TypeMask.Unit | TypeMask.GameObject);
|
||||
if (questgiver == null)
|
||||
var questGiver = Global.ObjAccessor.GetObjectByTypeMask(GetPlayer(), packet.QuestGiverGUID, TypeMask.Unit | TypeMask.GameObject);
|
||||
if (questGiver == null)
|
||||
{
|
||||
Log.outInfo(LogFilter.Network, "Error in CMSG_QUESTGIVER_STATUS_QUERY, called for non-existing questgiver {0}", packet.QuestGiverGUID.ToString());
|
||||
return;
|
||||
}
|
||||
|
||||
switch (questgiver.GetTypeId())
|
||||
{
|
||||
case TypeId.Unit:
|
||||
if (!questgiver.ToCreature().IsHostileTo(GetPlayer()))// do not show quest status to enemies
|
||||
questStatus = GetPlayer().GetQuestDialogStatus(questgiver);
|
||||
break;
|
||||
case TypeId.GameObject:
|
||||
questStatus = GetPlayer().GetQuestDialogStatus(questgiver);
|
||||
break;
|
||||
default:
|
||||
Log.outError(LogFilter.Network, "QuestGiver called for unexpected type {0}", questgiver.GetTypeId());
|
||||
break;
|
||||
}
|
||||
QuestGiverStatus questStatus = _player.GetQuestDialogStatus(questGiver);
|
||||
|
||||
//inform client about status of quest
|
||||
GetPlayer().PlayerTalkClass.SendQuestGiverStatus(questStatus, packet.QuestGiverGUID);
|
||||
@@ -396,7 +382,7 @@ namespace Game
|
||||
|
||||
if (GetPlayer().GetQuestStatus(packet.QuestID) != QuestStatus.Complete)
|
||||
return;
|
||||
|
||||
|
||||
GetPlayer().PlayerTalkClass.SendQuestGiverOfferReward(quest, packet.QuestGiverGUID, true);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user