feat(Core/SmartScripts): SMART_EVENT_EVENT_PHASE_CHANGE (#10054)

* cherry-pick commit (619a5534c5)
This commit is contained in:
IntelligentQuantum
2022-04-17 04:25:52 +04:30
committed by GitHub
parent 02ba514f0a
commit e38a17d2da
4 changed files with 92 additions and 24 deletions

View File

@@ -105,7 +105,7 @@ void SmartScript::ProcessEventsFor(SMART_EVENT e, Unit* unit, uint32 var0, uint3
if (eventType == SMART_EVENT_LINK)//special handling
continue;
if (eventType == e/* && (!(*i).event.event_phase_mask || IsInPhase((*i).event.event_phase_mask)) && !((*i).event.event_flags & SMART_EVENT_FLAG_NOT_REPEATABLE && (*i).runOnce)*/)
if (eventType == e)
{
ConditionList conds = sConditionMgr->GetConditionsForSmartEvent((*i).entryOrGuid, (*i).event_id, (*i).source_type);
ConditionSourceInfo info = ConditionSourceInfo(unit, GetBaseObject(), me ? me->GetVictim() : nullptr);
@@ -1496,6 +1496,8 @@ void SmartScript::ProcessAction(SmartScriptHolder& e, Unit* unit, uint32 var0, u
unitTarget->AttackStop();
}
}
delete targets;
break;
}
case SMART_ACTION_SUMMON_CREATURE:
@@ -4456,6 +4458,16 @@ void SmartScript::ProcessEvent(SmartScriptHolder& e, Unit* unit, uint32 var0, ui
ProcessAction(e, unit, var0, var1);
break;
}
case SMART_EVENT_EVENT_PHASE_CHANGE:
{
if (!IsInPhase(e.event.eventPhaseChange.phasemask))
{
return;
}
ProcessAction(e, GetLastInvoker());
break;
}
case SMART_EVENT_GAME_EVENT_START:
case SMART_EVENT_GAME_EVENT_END:
{
@@ -5092,3 +5104,43 @@ Unit* SmartScript::GetLastInvoker(Unit* invoker)
return ObjectAccessor::GetUnit(*invoker, mLastInvoker);
return nullptr;
}
void SmartScript::IncPhase(uint32 p)
{
// protect phase from overflowing
SetPhase(std::min<uint32>(SMART_EVENT_PHASE_12, mEventPhase + p));
}
void SmartScript::DecPhase(uint32 p)
{
if (p >= mEventPhase)
{
SetPhase(0);
}
else
{
SetPhase(mEventPhase - p);
}
}
void SmartScript::SetPhase(uint32 p)
{
uint32 oldPhase = mEventPhase;
mEventPhase = p;
if (oldPhase != mEventPhase)
{
ProcessEventsFor(SMART_EVENT_EVENT_PHASE_CHANGE);
}
}
bool SmartScript::IsInPhase(uint32 p) const
{
if (mEventPhase == 0)
{
return false;
}
return ((1 << (mEventPhase - 1)) & p) != 0;
}