Merge pull request #10501 from Discover-/SmartAI-Action-Set-Power

Core/SmartAI: Implement MART_ACTION_SET_POWER, SMART_ACTION_ADD_POWER and SMART_ACTION_REMOVE_POWER (param1 = powertype, para...
This commit is contained in:
Nay
2013-08-10 12:39:32 -07:00
3 changed files with 55 additions and 3 deletions

View File

@@ -2097,13 +2097,47 @@ void SmartScript::ProcessAction(SmartScriptHolder& e, Unit* unit, uint32 var0, u
GetBaseObject()->SummonCreatureGroup(e.action.creatureGroup.group, &summonList);
for (std::list<TempSummon*>::const_iterator itr = summonList.begin(); itr != summonList.end(); ++itr)
{
if (unit && e.action.creatureGroup.attackInvoker)
(*itr)->AI()->AttackStart(unit);
}
break;
}
case SMART_ACTION_SET_POWER:
{
ObjectList* targets = GetTargets(e, unit);
if (targets)
for (ObjectList::const_iterator itr = targets->begin(); itr != targets->end(); ++itr)
if (IsUnit(*itr))
(*itr)->ToUnit()->SetPower(Powers(e.action.power.powerType), e.action.power.newPower);
delete targets;
break;
}
case SMART_ACTION_ADD_POWER:
{
ObjectList* targets = GetTargets(e, unit);
if (targets)
for (ObjectList::const_iterator itr = targets->begin(); itr != targets->end(); ++itr)
if (IsUnit(*itr))
(*itr)->ToUnit()->SetPower(Powers(e.action.power.powerType), (*itr)->ToUnit()->GetPower(Powers(e.action.power.powerType)) + e.action.power.newPower);
delete targets;
break;
}
case SMART_ACTION_REMOVE_POWER:
{
ObjectList* targets = GetTargets(e, unit);
if (targets)
for (ObjectList::const_iterator itr = targets->begin(); itr != targets->end(); ++itr)
if (IsUnit(*itr))
(*itr)->ToUnit()->SetPower(Powers(e.action.power.powerType), (*itr)->ToUnit()->GetPower(Powers(e.action.power.powerType)) - e.action.power.newPower);
delete targets;
break;
}
default:
TC_LOG_ERROR(LOG_FILTER_SQL, "SmartScript::ProcessAction: Entry %d SourceType %u, Event %u, Unhandled Action type %u", e.entryOrGuid, e.GetScriptType(), e.event_id, e.GetActionType());
break;

View File

@@ -838,6 +838,15 @@ bool SmartAIMgr::IsEventValid(SmartScriptHolder& e)
return false;
break;
}
case SMART_ACTION_SET_POWER:
case SMART_ACTION_ADD_POWER:
case SMART_ACTION_REMOVE_POWER:
if (e.action.power.powerType > MAX_POWERS)
{
TC_LOG_ERROR(LOG_FILTER_SQL, "SmartAIMgr: Entry %d SourceType %u Event %u Action %u uses non-existent Power %u, skipped.", e.entryOrGuid, e.GetScriptType(), e.event_id, e.GetActionType(), e.action.power.powerType);
return false;
}
break;
case SMART_ACTION_FOLLOW:
case SMART_ACTION_SET_ORIENTATION:
case SMART_ACTION_STORE_TARGET_LIST:

View File

@@ -489,8 +489,11 @@ enum SMART_ACTION
SMART_ACTION_ADD_GO_FLAG = 105, // Flags
SMART_ACTION_REMOVE_GO_FLAG = 106, // Flags
SMART_ACTION_SUMMON_CREATURE_GROUP = 107, // Group, attackInvoker
SMART_ACTION_SET_POWER = 108, // PowerType, newPower
SMART_ACTION_ADD_POWER = 109, // PowerType, newPower
SMART_ACTION_REMOVE_POWER = 110, // PowerType, newPower
SMART_ACTION_END = 108
SMART_ACTION_END = 111
};
struct SmartAction
@@ -944,6 +947,12 @@ struct SmartAction
uint32 attackInvoker;
} creatureGroup;
struct
{
uint32 powerType;
uint32 newPower;
} power;
//! Note for any new future actions
//! All parameters must have type uint32