Skip to content

Commit

Permalink
Prepare SCRIPT_COMMAND_SPAWN_GROUP(51) for release
Browse files Browse the repository at this point in the history
Only formation code in it for now
Ability to set formation shape, spread and options via script
  • Loading branch information
cyberium committed Jan 3, 2022
1 parent c489723 commit 5c5126b
Show file tree
Hide file tree
Showing 3 changed files with 118 additions and 107 deletions.
12 changes: 12 additions & 0 deletions doc/script_commands.txt
Original file line number Diff line number Diff line change
Expand Up @@ -399,3 +399,15 @@ Defining a buddy could be done in several way:

50 SCRIPT_COMMAND_ZONE_PULSE Pulses zone for combat and attacks closest enemy

51 SCRIPT_COMMAND_SPAWN_GROUP Set of commands for creature spawn group
* datalong = command
only formation command(staring from 100) supported right now
- 100: switch formation shape.
datalong1 should have shape value
Random(0), Queue(1), Side bu side(2), Geese(3), Fanned out behind(4), Fanned out in front(5), Circle leader(6)
- 101: Set formation spread
Spread is set in x field as we need a float for it
- 102: Set formation options
Set flag 0x1 for keep compact option (after a member death)
Set flag 0x2 for disabling pathfinding (not impemented yet)

208 changes: 104 additions & 104 deletions src/game/DBScripts/ScriptMgr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -786,33 +786,33 @@ void ScriptMgr::LoadScripts(ScriptMapMapName& scripts, const char* tablename)
case SCRIPT_COMMAND_ZONE_PULSE: // 50
break;

case SCRIPT_COMMAND_SPAWN_GROUP: // 60
case SCRIPT_COMMAND_SPAWN_GROUP: // 51
{
switch (tmp.formationData.command)
{
case 2: // SetFormation
break;
case 3: // Add buddy to formation
{
if (!tmp.buddyEntry)
{
sLog.outErrorDb("Table `%s` has no buddy entry defined in SCRIPT_COMMAND_FORMATION for script id %u", tablename, tmp.id);
continue;
}
break;
}

case 4: // remove buddy to formation
{
if (!tmp.buddyEntry)
{
sLog.outErrorDb("Table `%s` has no buddy entry defined in SCRIPT_COMMAND_FORMATION for script id %u", tablename, tmp.id);
continue;
}
break;
}

case 5: // switch formation shape
// case 2: // SetFormation
// break;
// case 3: // Add buddy to formation
// {
// if (!tmp.buddyEntry)
// {
// sLog.outErrorDb("Table `%s` has no buddy entry defined in SCRIPT_COMMAND_FORMATION for script id %u", tablename, tmp.id);
// continue;
// }
// break;
// }
//
// case 4: // remove buddy to formation
// {
// if (!tmp.buddyEntry)
// {
// sLog.outErrorDb("Table `%s` has no buddy entry defined in SCRIPT_COMMAND_FORMATION for script id %u", tablename, tmp.id);
// continue;
// }
// break;
// }

case 100: // switch formation shape
{
if (tmp.formationData.data1 >= SpawnGroupFormationType::SPAWN_GROUP_FORMATION_TYPE_COUNT)
{
Expand All @@ -822,7 +822,7 @@ void ScriptMgr::LoadScripts(ScriptMapMapName& scripts, const char* tablename)
break;
}

case 6: // change formation spread
case 101: // change formation spread
{
if (tmp.x < 0.5f || tmp.x > 15.0f)
{
Expand All @@ -832,7 +832,7 @@ void ScriptMgr::LoadScripts(ScriptMapMapName& scripts, const char* tablename)
break;
}

case 7: // change formation options
case 102: // change formation options
{
break;
}
Expand Down Expand Up @@ -2709,82 +2709,82 @@ bool ScriptAction::ExecuteDbscriptCommand(WorldObject* pSource, WorldObject* pTa

switch (m_script->formationData.command)
{
case 2: // set formation
{
if (LogIfNotCreature(pSource))
return false;

CreatureGroup* targetGroup = nullptr;
if (!m_script->formationData.data1)
{
if (!leaderGroup)
{
sLog.outErrorDb(" DB-SCRIPTS: Process table `%s` script id %u, command %u and subcommand formation create(2) failed. Target group(%u) not found!",
m_table, m_script->id, m_script->command, m_script->formationData.data1);
break;
}
leaderGroup->SetFormationData(nullptr);
break;
}
else
{
auto sgData = leader->GetMap()->GetSpawnManager().GetSpawnGroup(m_script->formationData.data1);
if (!sgData || !sgData->GetCreatureGroup())
{
sLog.outErrorDb(" DB-SCRIPTS: Process table `%s` script id %u, command %u and subcommand formation create(2) failed. Target group(%u) not found!",
m_table, m_script->id, m_script->command, m_script->formationData.data1);
break;
}
targetGroup = sgData->GetCreatureGroup();
}

if (targetGroup->GetFormationData())
{
//
break;
}

FormationEntrySPtr fEntry = std::make_shared<FormationEntry>();
fEntry->GroupId = targetGroup->GetGroupId();
fEntry->Type = static_cast<SpawnGroupFormationType>(m_script->textId[0]);
fEntry->Spread = m_script->x;
fEntry->Options = m_script->textId[1];
fEntry->MovementType = m_script->textId[2]; // todo need to check that data!!!
fEntry->MovementID = m_script->textId[3];
fEntry->Comment = "Dynamically created formation!";

targetGroup->SetFormationData(fEntry);
break;
}
case 3: // add creature to the formation
{
if (LogIfNotCreature(pSource))
return false;

if (!leaderFormation)
{
sLog.outErrorDb(" DB-SCRIPTS: Process table `%s` id %u, command %u failed. %s is not in formation!",
m_table, m_script->id, m_script->command, leader->GetGuidStr().c_str());
break;
}
leaderFormation->Add(static_cast<Creature*>(pSource));
break;
}
case 4: // remove creature from the formation
{
if (LogIfNotCreature(pSource))
return false;

if (!leaderFormation)
{
sLog.outErrorDb(" DB-SCRIPTS: Process table `%s` id %u, command %u failed. %s is not in formation!",
m_table, m_script->id, m_script->command, leader->GetGuidStr().c_str());
break;
}
leaderFormation->Remove(static_cast<Creature*>(pSource));
break;
}
case 5: // switch formation shape
// case 2: // set formation
// {
// if (LogIfNotCreature(pSource))
// return false;
//
// CreatureGroup* targetGroup = nullptr;
// if (!m_script->formationData.data1)
// {
// if (!leaderGroup)
// {
// sLog.outErrorDb(" DB-SCRIPTS: Process table `%s` script id %u, command %u and subcommand formation create(2) failed. Target group(%u) not found!",
// m_table, m_script->id, m_script->command, m_script->formationData.data1);
// break;
// }
// leaderGroup->SetFormationData(nullptr);
// break;
// }
// else
// {
// auto sgData = leader->GetMap()->GetSpawnManager().GetSpawnGroup(m_script->formationData.data1);
// if (!sgData || !sgData->GetCreatureGroup())
// {
// sLog.outErrorDb(" DB-SCRIPTS: Process table `%s` script id %u, command %u and subcommand formation create(2) failed. Target group(%u) not found!",
// m_table, m_script->id, m_script->command, m_script->formationData.data1);
// break;
// }
// targetGroup = sgData->GetCreatureGroup();
// }
//
// if (targetGroup->GetFormationData())
// {
// //
// break;
// }
//
// FormationEntrySPtr fEntry = std::make_shared<FormationEntry>();
// fEntry->GroupId = targetGroup->GetGroupId();
// fEntry->Type = static_cast<SpawnGroupFormationType>(m_script->textId[0]);
// fEntry->Spread = m_script->x;
// fEntry->Options = m_script->textId[1];
// fEntry->MovementType = m_script->textId[2]; // todo need to check that data!!!
// fEntry->MovementID = m_script->textId[3];
// fEntry->Comment = "Dynamically created formation!";
//
// targetGroup->SetFormationData(fEntry);
// break;
// }
// case 3: // add creature to the formation
// {
// if (LogIfNotCreature(pSource))
// return false;
//
// if (!leaderFormation)
// {
// sLog.outErrorDb(" DB-SCRIPTS: Process table `%s` id %u, command %u failed. %s is not in formation!",
// m_table, m_script->id, m_script->command, leader->GetGuidStr().c_str());
// break;
// }
// leaderFormation->Add(static_cast<Creature*>(pSource));
// break;
// }
// case 4: // remove creature from the formation
// {
// if (LogIfNotCreature(pSource))
// return false;
//
// if (!leaderFormation)
// {
// sLog.outErrorDb(" DB-SCRIPTS: Process table `%s` id %u, command %u failed. %s is not in formation!",
// m_table, m_script->id, m_script->command, leader->GetGuidStr().c_str());
// break;
// }
// leaderFormation->Remove(static_cast<Creature*>(pSource));
// break;
// }
case 100: // switch formation shape
{
if (!leaderFormation)
{
Expand All @@ -2807,7 +2807,7 @@ bool ScriptAction::ExecuteDbscriptCommand(WorldObject* pSource, WorldObject* pTa
}
break;
}
case 6: // set formation spread
case 101: // set formation spread
{
if (!leaderFormation)
{
Expand All @@ -2828,7 +2828,7 @@ bool ScriptAction::ExecuteDbscriptCommand(WorldObject* pSource, WorldObject* pTa
}
break;
}
case 7: // set formation options
case 102: // set formation options
{
if (!leaderFormation)
{
Expand Down
5 changes: 2 additions & 3 deletions src/game/DBScripts/ScriptMgr.h
Original file line number Diff line number Diff line change
Expand Up @@ -131,9 +131,8 @@ enum ScriptCommand // resSource, resTar
// datalong=UnitFlags
// datalong2:0x00=add, 0x01=remove, 0x02=toggle
SCRIPT_COMMAND_SET_DATA_64 = 49, // datalong = set data param 1, datalong2 = set data param 2
SCRIPT_COMMAND_ZONE_PULSE = 50, //

SCRIPT_COMMAND_SPAWN_GROUP = 60,
SCRIPT_COMMAND_ZONE_PULSE = 50, //
SCRIPT_COMMAND_SPAWN_GROUP = 51, // dalalong = command
};

#define MAX_TEXT_ID 4 // used for SCRIPT_COMMAND_TALK, SCRIPT_COMMAND_EMOTE, SCRIPT_COMMAND_CAST_SPELL, SCRIPT_COMMAND_TERMINATE_SCRIPT
Expand Down

0 comments on commit 5c5126b

Please sign in to comment.