aboutsummaryrefslogtreecommitdiff
path: root/src/server/game/AI/SmartScripts
diff options
context:
space:
mode:
authorDiscover- <amort11@hotmail.com>2013-09-23 16:47:47 +0200
committerDiscover- <amort11@hotmail.com>2013-09-23 16:47:47 +0200
commita0db0728f2f48e7ca4156115b03e63d7ff2164c1 (patch)
treec17b6d0bdc34f0a8297216f21dd7deb5df4eddcc /src/server/game/AI/SmartScripts
parent9653576cb4cc9449898d6af691c045d68e9361c5 (diff)
parent4498ac0062d56aa0a0f2b9a21358f12f83c4b1f7 (diff)
Merge branch 'master' of https://github.com/TrinityCore/TrinityCore
Diffstat (limited to 'src/server/game/AI/SmartScripts')
-rw-r--r--src/server/game/AI/SmartScripts/SmartAI.cpp4
-rw-r--r--src/server/game/AI/SmartScripts/SmartScript.cpp35
-rw-r--r--src/server/game/AI/SmartScripts/SmartScriptMgr.cpp39
3 files changed, 67 insertions, 11 deletions
diff --git a/src/server/game/AI/SmartScripts/SmartAI.cpp b/src/server/game/AI/SmartScripts/SmartAI.cpp
index a1862c07d14..a56d0f94f2d 100644
--- a/src/server/game/AI/SmartScripts/SmartAI.cpp
+++ b/src/server/game/AI/SmartScripts/SmartAI.cpp
@@ -699,6 +699,10 @@ void SmartAI::InitializeAI()
void SmartAI::OnCharmed(bool apply)
{
GetScript()->ProcessEventsFor(SMART_EVENT_CHARMED, NULL, 0, 0, apply);
+
+ if (!apply && !me->IsInEvadeMode() && me->GetUInt64Value(UNIT_FIELD_CHARMEDBY))
+ if (Unit* charmer = ObjectAccessor::GetUnit(*me, me->GetUInt64Value(UNIT_FIELD_CHARMEDBY)))
+ AttackStart(charmer);
}
void SmartAI::DoAction(int32 param)
diff --git a/src/server/game/AI/SmartScripts/SmartScript.cpp b/src/server/game/AI/SmartScripts/SmartScript.cpp
index 8b12b2a2cc5..70dd9e9d1ee 100644
--- a/src/server/game/AI/SmartScripts/SmartScript.cpp
+++ b/src/server/game/AI/SmartScripts/SmartScript.cpp
@@ -1447,7 +1447,6 @@ void SmartScript::ProcessAction(SmartScriptHolder& e, Unit* unit, uint32 var0, u
if (!einfo)
{
TC_LOG_ERROR(LOG_FILTER_SQL, "SmartScript: SMART_ACTION_EQUIP uses non-existent equipment info id %u for creature %u", equipId, npc->GetEntry());
- delete targets;
break;
}
@@ -1771,10 +1770,14 @@ void SmartScript::ProcessAction(SmartScriptHolder& e, Unit* unit, uint32 var0, u
if (!targets)
break;
+ bool foundTarget = false;
+
for (ObjectList::const_iterator itr = targets->begin(); itr != targets->end(); ++itr)
{
if (IsCreature((*itr)))
{
+ foundTarget = true;
+
if (e.action.moveRandom.distance)
(*itr)->ToCreature()->GetMotionMaster()->MoveRandom((float)e.action.moveRandom.distance);
else
@@ -1782,6 +1785,14 @@ void SmartScript::ProcessAction(SmartScriptHolder& e, Unit* unit, uint32 var0, u
}
}
+ if (!foundTarget && me && IsCreature(me))
+ {
+ if (e.action.moveRandom.distance)
+ me->GetMotionMaster()->MoveRandom((float)e.action.moveRandom.distance);
+ else
+ me->GetMotionMaster()->MoveIdle();
+ }
+
delete targets;
break;
}
@@ -1991,13 +2002,7 @@ void SmartScript::ProcessAction(SmartScriptHolder& e, Unit* unit, uint32 var0, u
e.GetTargetType() == SMART_TARGET_OWNER_OR_SUMMONER || e.GetTargetType() == SMART_TARGET_ACTION_INVOKER ||
e.GetTargetType() == SMART_TARGET_CLOSEST_ENEMY || e.GetTargetType() == SMART_TARGET_CLOSEST_FRIENDLY)
{
- if (ObjectList* targets = GetTargets(e, unit))
- {
- if (WorldObject* target = targets->front())
- (*itr)->ToCreature()->SetHomePosition(target->GetPositionX(), target->GetPositionY(), target->GetPositionZ(), target->GetOrientation());
-
- delete targets;
- }
+ (*itr)->ToCreature()->SetHomePosition((*itr)->GetPositionX(), (*itr)->GetPositionY(), (*itr)->GetPositionZ(), (*itr)->GetOrientation());
}
else
TC_LOG_ERROR(LOG_FILTER_SQL, "SmartScript: Action target for SMART_ACTION_SET_HOME_POS is invalid, skipping");
@@ -2294,8 +2299,9 @@ ObjectList* SmartScript::GetTargets(SmartScriptHolder const& e, Unit* invoker /*
l->push_back(baseObject);
break;
case SMART_TARGET_VICTIM:
- if (me && me->GetVictim())
- l->push_back(me->GetVictim());
+ if (me)
+ if (Unit* victim = me->GetVictim())
+ l->push_back(victim);
break;
case SMART_TARGET_HOSTILE_SECOND_AGGRO:
if (me)
@@ -2508,8 +2514,15 @@ ObjectList* SmartScript::GetTargets(SmartScriptHolder const& e, Unit* invoker /*
case SMART_TARGET_OWNER_OR_SUMMONER:
{
if (me)
- if (Unit* owner = ObjectAccessor::GetUnit(*me, me->GetCharmerOrOwnerGUID()))
+ {
+ uint64 charmerOrOwnerGuid = me->GetCharmerOrOwnerGUID();
+
+ if (!charmerOrOwnerGuid)
+ charmerOrOwnerGuid = me->GetCreatorGUID();
+
+ if (Unit* owner = ObjectAccessor::GetUnit(*me, charmerOrOwnerGuid))
l->push_back(owner);
+ }
break;
}
case SMART_TARGET_THREAT_LIST:
diff --git a/src/server/game/AI/SmartScripts/SmartScriptMgr.cpp b/src/server/game/AI/SmartScripts/SmartScriptMgr.cpp
index 01f9080fba1..361cf025647 100644
--- a/src/server/game/AI/SmartScripts/SmartScriptMgr.cpp
+++ b/src/server/game/AI/SmartScripts/SmartScriptMgr.cpp
@@ -771,6 +771,26 @@ bool SmartAIMgr::IsEventValid(SmartScriptHolder& e)
case SMART_ACTION_SUMMON_CREATURE:
if (!IsCreatureValid(e, e.action.summonCreature.creature))
return false;
+
+ for (uint32 i = 0; i < sSpellMgr->GetSpellInfoStoreSize(); ++i)
+ {
+ SpellInfo const* spellInfo = sSpellMgr->GetSpellInfo(i);
+ if (!spellInfo)
+ continue;
+
+ for (uint32 j = 0; j < MAX_SPELL_EFFECTS; ++j)
+ {
+ if (spellInfo->Effects[j].Effect == SPELL_EFFECT_SUMMON)
+ {
+ uint32 creatureSummonEntry = spellInfo->Effects[j].MiscValue;
+
+ if (e.action.summonCreature.creature == creatureSummonEntry)
+ TC_LOG_ERROR(LOG_FILTER_SQL, "SmartAIMgr: Entry %d SourceType %u Event %u Action %u creature summon: %u has already summon spell (SpellId: %u effect: %u)",
+ e.entryOrGuid, e.GetScriptType(), e.event_id, e.GetActionType(), e.action.summonCreature.creature, spellInfo->Id, j);
+ }
+ }
+ }
+
if (e.action.summonCreature.type < TEMPSUMMON_TIMED_OR_DEAD_DESPAWN || e.action.summonCreature.type > TEMPSUMMON_MANUAL_DESPAWN)
{
TC_LOG_ERROR(LOG_FILTER_SQL, "SmartAIMgr: Entry %d SourceType %u Event %u Action %u uses incorrect TempSummonType %u, skipped.", e.entryOrGuid, e.GetScriptType(), e.event_id, e.GetActionType(), e.action.summonCreature.type);
@@ -828,6 +848,25 @@ bool SmartAIMgr::IsEventValid(SmartScriptHolder& e)
case SMART_ACTION_SUMMON_GO:
if (!IsGameObjectValid(e, e.action.summonGO.entry))
return false;
+
+ for (uint32 i = 0; i < sSpellMgr->GetSpellInfoStoreSize(); ++i)
+ {
+ SpellInfo const* spellInfo = sSpellMgr->GetSpellInfo(i);
+ if (!spellInfo)
+ continue;
+
+ for (uint32 j = 0; j < MAX_SPELL_EFFECTS; ++j)
+ {
+ if (spellInfo->Effects[j].Effect == SPELL_EFFECT_SUMMON_OBJECT_WILD)
+ {
+ uint32 goSummonEntry = spellInfo->Effects[j].MiscValue;
+
+ if (e.action.summonGO.entry == goSummonEntry)
+ TC_LOG_ERROR(LOG_FILTER_SQL, "SmartAIMgr: Entry %d SourceType %u Event %u Action %u gameobject summon: %u has already summon spell (SpellId: %u effect: %u)",
+ e.entryOrGuid, e.GetScriptType(), e.event_id, e.GetActionType(), e.action.summonGO.entry, spellInfo->Id, j);
+ }
+ }
+ }
break;
case SMART_ACTION_ADD_ITEM:
case SMART_ACTION_REMOVE_ITEM: