Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Attempt to create new command for EventAI and db_script, which can be used together with FollowerAI, and separate from it. #33

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion doc/EventAI.txt
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ For all ACTION_T_RANDOM Actions, When a Particular Param is selected for the Eve
46 ACTION_T_SET_THROW_MASK EventTypeMask Marks for which AIEvents the npc will throw AIEvents on its own.
47 ACTION_T_SET_STAND_STATE StandState Set the unit stand state (Param1) of the current creature.
48 ACTION_T_CHANGE_MOVEMENT MovementType, WanderDistance Change the unit movement type (Param1). If the movement type is Random Movement (1), the WanderDistance (Param2) must be provided.

49 ACTION_T_FOLLOW_TARGET Distance, Angle, Target Add the unit follow movement type on target.
* = Use -1 where the param is expected to do nothing. Random constant is generated for each event, so if you have a random yell and a random sound, they will be linked up with each other (ie. param2 with param2).


Expand Down Expand Up @@ -916,6 +916,12 @@ Parameter 1: StandState - Stand state id to be used by the creature as defined i
Parameter 1: MovementType - Movement type id to be used by the creature. Can be 0 = Idle, 1 = Random, 2 = Waypoint.
Parameter 2: WanderDistance - Wander distance to be used in case the movement type is 1 (Random).

------------------------------
49 = ACTION_T_FOLLOW_TARGET:
------------------------------
Parameter 1: Distance - The distance at which the creature will follow on target.
Parameter 2: Angle - The angle at which the creature will follow target.
Parameter 3: Target - Preferably ACTION_INVOKER and EVENT_SENDER, but can use any other except TARGET_SELF.
=========================================
Target Types
=========================================
Expand Down
4 changes: 4 additions & 0 deletions doc/script_commands.txt
Original file line number Diff line number Diff line change
Expand Up @@ -319,3 +319,7 @@ Where "A -> B" means that the command is executed from A with B as target.
* datalong = mailTemplateId
* datalong2: AlternativeSenderEntry. Use as sender-Entry of the sent mail
* dataint1: Delay (>= 0) in Seconds

39 SCRIPT_COMMAND_FOLLOW Move Follow resultingSource = Creature, resultingTarget = Unit
* datalong = distance
* datalong2 = angle
18 changes: 18 additions & 0 deletions src/game/CreatureEventAI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1019,6 +1019,24 @@ void CreatureEventAI::ProcessAction(CreatureEventAI_Action const& action, uint32
}
break;
}
case ACTION_T_FOLLOW_TARGET:
m_followDistance = (float)action.follow_movement.distance;
m_followAngle = action.follow_movement.angle.angle;
Unit* target = GetTargetByType(action.follow_movement, pActionInvoker, pAIEventSender, reportTargetError);
if (!target)
{
if (reportTargetError)
sLog.outErrorEventAI("NULL target for ACTION_T_FOLLOW_TARGET creature entry %u follow target %u", m_creature->GetEntry(), action.follow_movement);
return;
}
if (m_creature->GetMotionMaster()->GetCurrentMovementGeneratorType() == WAYPOINT_MOTION_TYPE)
{
// Drop current movement gen
m_creature->GetMotionMaster()->Clear;
m_creature->GetMotionMaster()->MoveFollow(target, m_followDistance, m_followAngle);
}
}
break;
}
}

Expand Down
8 changes: 8 additions & 0 deletions src/game/CreatureEventAI.h
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ enum EventAI_ActionType
ACTION_T_SET_THROW_MASK = 46, // EventTypeMask, unused, unused
ACTION_T_SET_STAND_STATE = 47, // StandState, unused, unused
ACTION_T_CHANGE_MOVEMENT = 48, // MovementType, WanderDistance, unused
ACTION_T_FOLLOW_TARGET = 49, // Distance, Angle, Target.

ACTION_T_END,
};
Expand Down Expand Up @@ -414,6 +415,13 @@ struct CreatureEventAI_Action
uint32 wanderDistance;
uint32 unused1;
} changeMovement;
// ACTION_T_FOLLOW_TARGET = 49
struct
{
uint32 distance;
uint32 angle;
uint32 target;
} follow_movement;
// RAW
struct
{
Expand Down
7 changes: 6 additions & 1 deletion src/game/CreatureEventAIMgr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -881,7 +881,12 @@ void CreatureEventAIMgr::LoadCreatureEventAI_Scripts()
continue;
}
break;

case ACTION_T_FOLLOW_TARGET:
if (action.follow_movement == TARGET_T_SELF)
{
sLog.outErrorEventAI("Event %u Action %u uses invalid target_type %u.", i, j + 1, action.follow_movement.follow);
continue;
}
default:
sLog.outErrorEventAI("Event %u Action %u have currently not checked at load action type (%u). Need check code update?", i, j + 1, temp.action[j].type);
break;
Expand Down
11 changes: 11 additions & 0 deletions src/game/ScriptMgr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -738,6 +738,8 @@ void ScriptMgr::LoadScripts(ScriptMapMapName& scripts, const char* tablename)
sLog.outErrorDb("Table `%s` unknown command %u, skipping.", tablename, tmp.command);
continue;
}
case SCRIPT_COMMAND_FOLLOW: // 39
break;
}

if (scripts.second.find(tmp.id) == scripts.second.end())
Expand Down Expand Up @@ -1962,6 +1964,15 @@ bool ScriptAction::HandleScriptStep()
default:
sLog.outErrorDb(" DB-SCRIPTS: Process table `%s` id %u, command %u unknown command used.", m_table, m_script->id, m_script->command);
break;
case SCRIPT_COMMAND_FOLLOW: // 39
{
if (LogIfNotCreature(pSource))
return false;
if (LogIfNotUnit(pTarget))
return false;
((Creature*)pSource)->GetMotionMaster()->MoveFollow(pTarget, distance, angle);
break;
}
}

return false;
Expand Down
9 changes: 9 additions & 0 deletions src/game/ScriptMgr.h
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,9 @@ enum ScriptCommand // resSource, resTar
// datalong: Send mailTemplateId from resSource (if provided) to player resTarget
// datalong2: AlternativeSenderEntry. Use as sender-Entry
// dataint1: Delay (>= 0) in Seconds
SCRIPT_COMMAND_FOLLOW = 39, // resSource Creature, resTarget Creature/Player. Move Follow towards Target.
// datalong = distance
// datalong2 = angle
};

#define MAX_TEXT_ID 4 // used for SCRIPT_COMMAND_TALK, SCRIPT_COMMAND_EMOTE, SCRIPT_COMMAND_CAST_SPELL, SCRIPT_COMMAND_TERMINATE_SCRIPT
Expand Down Expand Up @@ -363,6 +366,12 @@ struct ScriptInfo
uint32 mailTemplateId; // datalong
uint32 altSender; // datalong2;
} sendMail;

struct // SCRIPT_COMMAND_FOLLOW (39)
{
uint32 Distance; //datalong
uint32 Angle; //datalong2;
} moveFollow;

struct
{
Expand Down