mirror of
https://github.com/mangosfour/server.git
synced 2025-12-13 22:37:03 +00:00
[11823] Add SCRIPT_COMMAND_MODIFY_NPC_FLAG to change NPC flags by db-script
Note that the npc flags will be restored when the npc respawns Signed-off-by: Schmoozerd <schmoozerd@scriptdev2.com>
This commit is contained in:
parent
1606bb2e45
commit
46e604a089
5 changed files with 100 additions and 8 deletions
|
|
@ -2513,7 +2513,7 @@ void Map::ScriptsProcess()
|
|||
if (target && target->GetTypeId() == TYPEID_UNIT)
|
||||
pMover = (Creature*)target;
|
||||
}
|
||||
else if (pSource->GetTypeId() == TYPEID_UNIT)
|
||||
else
|
||||
pMover = (Creature*)pSource;
|
||||
}
|
||||
else // If step has a buddy entry defined, search for it
|
||||
|
|
@ -2574,7 +2574,7 @@ void Map::ScriptsProcess()
|
|||
if (target && target->GetTypeId() == TYPEID_UNIT)
|
||||
pOwner = (Creature*)target;
|
||||
}
|
||||
else if (pSource->GetTypeId() == TYPEID_UNIT)
|
||||
else
|
||||
pOwner = (Creature*)pSource;
|
||||
}
|
||||
else // If step has a buddy entry defined, search for it
|
||||
|
|
@ -2620,7 +2620,7 @@ void Map::ScriptsProcess()
|
|||
if (target && target->GetTypeId() == TYPEID_UNIT)
|
||||
pOwner = (Creature*)target;
|
||||
}
|
||||
else if (pSource->GetTypeId() == TYPEID_UNIT)
|
||||
else
|
||||
pOwner = (Creature*)pSource;
|
||||
}
|
||||
else // If step has a buddy entry defined, search for it
|
||||
|
|
@ -2670,7 +2670,7 @@ void Map::ScriptsProcess()
|
|||
if (target && target->GetTypeId() == TYPEID_UNIT)
|
||||
pOwner = (Creature*)target;
|
||||
}
|
||||
else if (pSource->GetTypeId() == TYPEID_UNIT)
|
||||
else
|
||||
pOwner = (Creature*)pSource;
|
||||
}
|
||||
else // If step has a buddy entry defined, search for it
|
||||
|
|
@ -2727,7 +2727,7 @@ void Map::ScriptsProcess()
|
|||
if (target && target->GetTypeId() == TYPEID_UNIT)
|
||||
pOwner = (Creature*)target;
|
||||
}
|
||||
else if (pSource->GetTypeId() == TYPEID_UNIT)
|
||||
else
|
||||
pOwner = (Creature*)pSource;
|
||||
}
|
||||
else // If step has a buddy entry defined, search for it
|
||||
|
|
@ -2784,7 +2784,7 @@ void Map::ScriptsProcess()
|
|||
if (target && target->GetTypeId() == TYPEID_UNIT)
|
||||
pOwner = (Creature*)target;
|
||||
}
|
||||
else if (pSource->GetTypeId() == TYPEID_UNIT)
|
||||
else
|
||||
pOwner = (Creature*)pSource;
|
||||
}
|
||||
else // If step has a buddy entry defined, search for it
|
||||
|
|
@ -2963,8 +2963,66 @@ void Map::ScriptsProcess()
|
|||
((Unit*)pSource)->SetStandState(step.script->standState.stand_state);
|
||||
break;
|
||||
}
|
||||
case SCRIPT_COMMAND_MODIFY_NPC_FLAGS:
|
||||
{
|
||||
if (!source && !target)
|
||||
{
|
||||
sLog.outError("SCRIPT_COMMAND_MODIFY_NPC_FLAGS (script id %u) call for NULL source and NULL target.", step.script->id);
|
||||
break;
|
||||
}
|
||||
|
||||
if ((!source || !source->isType(TYPEMASK_WORLDOBJECT)) && (!target || !target->isType(TYPEMASK_WORLDOBJECT)))
|
||||
{
|
||||
sLog.outError("SCRIPT_COMMAND_MODIFY_NPC_FLAGS (script id %u) call for unsupported non-worldobject (TypeId: %u), skipping.", step.script->id, source ? source->GetTypeId() : target->GetTypeId());
|
||||
break;
|
||||
}
|
||||
|
||||
WorldObject* pSource = source && source->isType(TYPEMASK_WORLDOBJECT) ? (WorldObject*)source : (WorldObject*)target;
|
||||
Creature* pBuddy = NULL;
|
||||
|
||||
// No buddy defined, so try use source (or target if source is not creature)
|
||||
if (!step.script->npcFlag.creatureEntry)
|
||||
{
|
||||
if (pSource->GetTypeId() != TYPEID_UNIT)
|
||||
{
|
||||
// we can't be non-creature, so see if target is creature
|
||||
if (target && target->GetTypeId() == TYPEID_UNIT)
|
||||
pBuddy = (Creature*)target;
|
||||
}
|
||||
else
|
||||
pBuddy = (Creature*)pSource;
|
||||
}
|
||||
else // If step has a buddy entry defined, search for it
|
||||
{
|
||||
MaNGOS::NearestCreatureEntryWithLiveStateInObjectRangeCheck u_check(*pSource, step.script->npcFlag.creatureEntry, true, step.script->npcFlag.searchRadius);
|
||||
MaNGOS::CreatureLastSearcher<MaNGOS::NearestCreatureEntryWithLiveStateInObjectRangeCheck> searcher(pBuddy, u_check);
|
||||
|
||||
Cell::VisitGridObjects(pSource, searcher, step.script->npcFlag.searchRadius);
|
||||
}
|
||||
|
||||
if (!pBuddy)
|
||||
{
|
||||
sLog.outError("SCRIPT_COMMAND_MODIFY_NPC_FLAGS (script id %u) call for non-creature (TypeIdSource: %u)(TypeIdTarget: %u), skipping.", step.script->id, source ? source->GetTypeId() : 0, target ? target->GetTypeId() : 0);
|
||||
break;
|
||||
}
|
||||
|
||||
// Add Flags
|
||||
if (step.script->npcFlag.data_flags & 0x01)
|
||||
pBuddy->SetFlag(UNIT_NPC_FLAGS, step.script->npcFlag.flag);
|
||||
// Remove Flags
|
||||
else if (step.script->npcFlag.data_flags & 0x02)
|
||||
pBuddy->RemoveFlag(UNIT_NPC_FLAGS, step.script->npcFlag.flag);
|
||||
// Toggle Flags
|
||||
else
|
||||
{
|
||||
if (pBuddy->HasFlag(UNIT_NPC_FLAGS, step.script->npcFlag.flag))
|
||||
pBuddy->RemoveFlag(UNIT_NPC_FLAGS, step.script->npcFlag.flag);
|
||||
else
|
||||
pBuddy->SetFlag(UNIT_NPC_FLAGS, step.script->npcFlag.flag);
|
||||
}
|
||||
}
|
||||
default:
|
||||
sLog.outError("Unknown SCRIPT_COMMAND_ %u called for script id %u.",step.script->command, step.script->id);
|
||||
sLog.outError("Unknown SCRIPT_COMMAND_ %u called for script id %u.", step.script->command, step.script->id);
|
||||
break;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue