Core/SmartAI: Various fixes and extensions for smart scripts: (#18673)

- Possible crashes fixed
- Memory leak fixed
- Implemented checking of vehicle conditions
- Extended eventphasemask to 12 bits (sql required to change DB field type)
- SMART_EVENT_GOSSIP_HELLO - added possibility to detect for gameobject reportUse call
- Renamed action SMART_ACTION_SET_FLY to SMART_ACTION_SET_DISABLE_GRAVITY (to reflect actual functionality)
- Added targetsLimit to action SMART_ACTION_CAST and SMART_ACTION_INVOKER_CAST to limit max amount of targets (selected randomly)
- Action SMART_ACTION_TALK corrected to always work as intended
- Properly call GroupEventHappens in action SMART_ACTION_CALL_GROUPEVENTHAPPENS if invoker was charmed or owned by the player
- Properly utilize followAngle in action SMART_ACTION_FOLLOW (db orientation should be in degrees), but keep backward compatibility
- Added action SMART_ACTION_SET_CAN_FLY (119) 0/1
- Added action SMART_ACTION_REMOVE_AURAS_BY_TYPE (120) AuraType, can be used to exit vehicle for example
- Added action SMART_ACTION_SET_SIGHT_DIST (121) sightDist
- Added action SMART_ACTION_FLEE (122) fleeTime
- Added action SMART_ACTION_ADD_THREAT (123) +threat, -threat
- Added action SMART_ACTION_LOAD_EQUIPMENT (124) equipmentId
- Added action SMART_ACTION_TRIGGER_RANDOM_TIMED_EVENT (125) minId, maxId
- Added action SMART_ACTION_REMOVE_ALL_GAMEOBJECTS (126), removes all owned gameobjects
- Added action SMART_ACTION_STOP_MOTION (127), stopMoving, movementExpired
- Extended target SMART_TARGET_HOSTILE_SECOND_AGGRO with following parameters maxdist, playerOnly, powerType + 1
- Extended target SMART_TARGET_HOSTILE_LAST_AGGRO with following parameters maxdist, playerOnly, powerType + 1
- Extended target SMART_TARGET_HOSTILE_RANDOM with following parameters maxdist, playerOnly, powerType + 1
- Extended target SMART_TARGET_HOSTILE_RANDOM_NOT_TOP with following parameters maxdist, playerOnly, powerType + 1
- Extended target SMART_TARGET_THREAT_LIST with maxdist
- Extended target SMART_TARGET_OWNER_OR_SUMMONER to be able to get charmer/owner of current owner
- Added new target SMART_TARGET_FARTHEST with maxDist, playerOnly, isInLos restrictions
- Added SpellHit hook to GameObjectAI and extended SmartGameObjectAI to call SMART_EVENT_SPELLHIT when gameobject is hit by spell
- Call GameObjectAI Reset hook on gameobject respawn (for ex. to reset one time events in smart scripts)
- Fixed some logic errors in code
- SmartAI Escorts properly despawn escortee if no players are in range
- Disable Evading while charming creature with SmartAI
- Don't call SMART_EVENT_RESPAWN for dead units before they actually respawn
- Don't call SMART_EVENT_RESPAWN for not spawned gameobjects
- Properly call SMART_EVENT_RESPAWN for gameobject respawn
- Allow action SMART_ACTION_SET_IN_COMBAT_WITH_ZONE to utilize targetlist
- Allow action SMART_ACTION_CALL_FOR_HELP to utilize targetList
- Allow action SMART_ACTION_SET_INVINCIBILITY_HP_LEVEL to utilize targetList
- Allow action SMART_ACTION_SET_VISIBILITY to utilize targetList
- Allow action SMART_ACTION_SET_ACTIVE to utilize targetList
- Allow action SMART_ACTION_ATTACK_START to select random attack target instead of first on the list
- Allow gameobjects to summon gameobjects with action SMART_ACTION_SUMMON_GO
- Properly store action invokers for action SMART_ACTION_WP_START, if no player invokers are found, distance despawn check won't be used
- Allow action SMART_ACTION_WP_RESUME to compensate for the state the unit actually is in (eg. combat)
- Allow action SMART_ACTION_MOVE_TO_POS to select random of the avaiable targets, not only the first one.
- Allow action SMART_ACTION_MOVE_TO_POS to utilize x, y, z parameters as an offset to calculated coordinates
- Action SMART_ACTION_RESPAWN_TARGET should never modify respawntime of already spawned gameobjects, use dedicated function
- Properly delete ontime events created by SMART_ACTION_CREATE_TIMED_EVENT
- If action could not be started because conditions were not satisfied, do not recalculate the waittime to action repeattime, use smaller value to recheck more frequently
- Allow target SMART_TARGET_CLOSEST_PLAYER to be used by gameobjects
- Allow target SMART_TARGET_OWNER_OR_SUMMONER to be used by gameobjects
- Fixed SMART_EVENT_COUNTER_SET to be only called for the id that was incremented
- Changed the way counters work
- Protect PhaseInc from surpassing maximum phase
- Added loading checks for missing NON_REPEATABLE flag if no repeatmin, repeatmax is set
- Added spell validation for SMART_ACTION_CROSS_CAST
This commit is contained in:
xinef1 authored and Aokromes committed 2017-02-19 09:10:29 +01:00
1 parent e09c37334d
commit 62111a8c4a
21 files changed
+830 -251

No files matched your search

@@ -66,9 +66,12 @@ enum SMART_EVENT_PHASE
SMART_EVENT_PHASE_7 = 7,
SMART_EVENT_PHASE_8 = 8,
SMART_EVENT_PHASE_9 = 9,
SMART_EVENT_PHASE_MAX = 10,
SMART_EVENT_PHASE_10 = 10,
SMART_EVENT_PHASE_11 = 11,
SMART_EVENT_PHASE_12 = 12,
SMART_EVENT_PHASE_MAX = 13,
SMART_EVENT_PHASE_COUNT = 9
SMART_EVENT_PHASE_COUNT = 12
};
enum SMART_EVENT_PHASE_BITS
@@ -83,7 +86,12 @@ enum SMART_EVENT_PHASE_BITS
SMART_EVENT_PHASE_7_BIT = 64,
SMART_EVENT_PHASE_8_BIT = 128,
SMART_EVENT_PHASE_9_BIT = 256,
SMART_EVENT_PHASE_ALL = SMART_EVENT_PHASE_1_BIT + SMART_EVENT_PHASE_2_BIT + SMART_EVENT_PHASE_3_BIT + SMART_EVENT_PHASE_4_BIT + SMART_EVENT_PHASE_5_BIT + SMART_EVENT_PHASE_6_BIT + SMART_EVENT_PHASE_7_BIT + SMART_EVENT_PHASE_8_BIT + SMART_EVENT_PHASE_9_BIT
SMART_EVENT_PHASE_10_BIT = 512,
SMART_EVENT_PHASE_11_BIT = 1024,
SMART_EVENT_PHASE_12_BIT = 2048,
SMART_EVENT_PHASE_ALL = SMART_EVENT_PHASE_1_BIT + SMART_EVENT_PHASE_2_BIT + SMART_EVENT_PHASE_3_BIT + SMART_EVENT_PHASE_4_BIT + SMART_EVENT_PHASE_5_BIT +
SMART_EVENT_PHASE_6_BIT + SMART_EVENT_PHASE_7_BIT + SMART_EVENT_PHASE_8_BIT + SMART_EVENT_PHASE_9_BIT + SMART_EVENT_PHASE_10_BIT +
SMART_EVENT_PHASE_11_BIT + SMART_EVENT_PHASE_12_BIT
};
const uint32 SmartPhaseMask[SMART_EVENT_PHASE_COUNT][2] =
@@ -96,7 +104,10 @@ const uint32 SmartPhaseMask[SMART_EVENT_PHASE_COUNT][2] =
{SMART_EVENT_PHASE_6, SMART_EVENT_PHASE_6_BIT },
{SMART_EVENT_PHASE_7, SMART_EVENT_PHASE_7_BIT },
{SMART_EVENT_PHASE_8, SMART_EVENT_PHASE_8_BIT },
{SMART_EVENT_PHASE_9, SMART_EVENT_PHASE_9_BIT }
{SMART_EVENT_PHASE_9, SMART_EVENT_PHASE_9_BIT },
{SMART_EVENT_PHASE_10, SMART_EVENT_PHASE_10_BIT },
{SMART_EVENT_PHASE_11, SMART_EVENT_PHASE_11_BIT },
{SMART_EVENT_PHASE_12, SMART_EVENT_PHASE_12_BIT }
};
enum SMART_EVENT
@@ -165,7 +176,7 @@ enum SMART_EVENT
SMART_EVENT_LINK = 61, // INTERNAL USAGE, no params, used to link together multiple events, does not use any extra resources to iterate event lists needlessly
SMART_EVENT_GOSSIP_SELECT = 62, // menuID, actionID
SMART_EVENT_JUST_CREATED = 63, // none
SMART_EVENT_GOSSIP_HELLO = 64, // none
SMART_EVENT_GOSSIP_HELLO = 64, // noReportUse (for GOs)
SMART_EVENT_FOLLOW_COMPLETED = 65, // none
SMART_EVENT_DUMMY_EFFECT = 66, // spellId, effectIndex
SMART_EVENT_IS_BEHIND_TARGET = 67, // cooldownMin, CooldownMax
@@ -359,6 +370,11 @@ struct SmartEvent
uint32 id;
} timedEvent;
struct
{
uint32 noReportUse;
} gossipHello;
struct
{
uint32 sender;
@@ -500,7 +516,7 @@ enum SMART_ACTION
SMART_ACTION_REMOVE_ITEM = 57, // itemID, count
SMART_ACTION_INSTALL_AI_TEMPLATE = 58, // AITemplateID
SMART_ACTION_SET_RUN = 59, // 0/1
SMART_ACTION_SET_FLY = 60, // 0/1
SMART_ACTION_SET_DISABLE_GRAVITY = 60, // 0/1
SMART_ACTION_SET_SWIM = 61, // 0/1
SMART_ACTION_TELEPORT = 62, // mapID,
SMART_ACTION_SET_COUNTER = 63, // id, value, reset (0/1)
@@ -559,8 +575,17 @@ enum SMART_ACTION
SMART_ACTION_SET_CORPSE_DELAY = 116, // timer
SMART_ACTION_DISABLE_EVADE = 117, // 0/1 (1 = disabled, 0 = enabled)
SMART_ACTION_GO_SET_GO_STATE = 118, // state
SMART_ACTION_SET_CAN_FLY = 119, // 0/1
SMART_ACTION_REMOVE_AURAS_BY_TYPE = 120, // type
SMART_ACTION_SET_SIGHT_DIST = 121, // sightDistance
SMART_ACTION_FLEE = 122, // fleeTime
SMART_ACTION_ADD_THREAT = 123, // +threat, -threat
SMART_ACTION_LOAD_EQUIPMENT = 124, // id
SMART_ACTION_TRIGGER_RANDOM_TIMED_EVENT = 125, // id min range, id max range
SMART_ACTION_REMOVE_ALL_GAMEOBJECTS = 126,
SMART_ACTION_STOP_MOTION = 127, // stopMoving, movementExpired
SMART_ACTION_END = 119
SMART_ACTION_END = 128
};
struct SmartAction
@@ -629,6 +654,7 @@ struct SmartAction
uint32 spell;
uint32 castFlags;
uint32 triggerFlags;
uint32 targetsLimit;
} cast;
struct
@@ -859,6 +885,11 @@ struct SmartAction
uint32 run;
} setRun;
struct
{
uint32 disable;
} setDisableGravity;
struct
{
uint32 fly;
@@ -976,6 +1007,11 @@ struct SmartAction
struct
{
uint32 withEmote;
} fleeAssist;
struct
{
uint32 fleeTime;
} flee;
struct
@@ -1081,6 +1117,34 @@ struct SmartAction
uint32 disable;
} disableEvade;
struct
{
uint32 type;
} auraType;
struct
{
uint32 dist;
} sightDistance;
struct
{
uint32 id;
uint32 force;
} loadEquipment;
struct
{
uint32 minId;
uint32 maxId;
} randomTimedEvent;
struct
{
uint32 stopMovement;
uint32 movementExpired;
} stopMotion;
//! Note for any new future actions
//! All parameters must have type uint32
@@ -1112,10 +1176,10 @@ enum SMARTAI_TARGETS
SMART_TARGET_NONE = 0, // NONE, defaulting to invoket
SMART_TARGET_SELF = 1, // Self cast
SMART_TARGET_VICTIM = 2, // Our current target (ie: highest aggro)
SMART_TARGET_HOSTILE_SECOND_AGGRO = 3, // Second highest aggro
SMART_TARGET_HOSTILE_LAST_AGGRO = 4, // Dead last on aggro
SMART_TARGET_HOSTILE_RANDOM = 5, // Just any random target on our threat list
SMART_TARGET_HOSTILE_RANDOM_NOT_TOP = 6, // Any random target except top threat
SMART_TARGET_HOSTILE_SECOND_AGGRO = 3, // Second highest aggro, maxdist, playerOnly, powerType + 1
SMART_TARGET_HOSTILE_LAST_AGGRO = 4, // Dead last on aggro, maxdist, playerOnly, powerType + 1
SMART_TARGET_HOSTILE_RANDOM = 5, // Just any random target on our threat list, maxdist, playerOnly, powerType + 1
SMART_TARGET_HOSTILE_RANDOM_NOT_TOP = 6, // Any random target except top threat, maxdist, playerOnly, powerType + 1
SMART_TARGET_ACTION_INVOKER = 7, // Unit who caused this Event to occur
SMART_TARGET_POSITION = 8, // use xyz from event params
SMART_TARGET_CREATURE_RANGE = 9, // CreatureEntry(0any), minDist, maxDist
@@ -1132,13 +1196,14 @@ enum SMARTAI_TARGETS
SMART_TARGET_CLOSEST_GAMEOBJECT = 20, // entry(0any), maxDist
SMART_TARGET_CLOSEST_PLAYER = 21, // maxDist
SMART_TARGET_ACTION_INVOKER_VEHICLE = 22, // Unit's vehicle who caused this Event to occur
SMART_TARGET_OWNER_OR_SUMMONER = 23, // Unit's owner or summoner
SMART_TARGET_THREAT_LIST = 24, // All units on creature's threat list
SMART_TARGET_OWNER_OR_SUMMONER = 23, // Unit's owner or summoner, Use Owner/Charmer of this unit
SMART_TARGET_THREAT_LIST = 24, // All units on creature's threat list, maxdist
SMART_TARGET_CLOSEST_ENEMY = 25, // maxDist, playerOnly
SMART_TARGET_CLOSEST_FRIENDLY = 26, // maxDist, playerOnly
SMART_TARGET_LOOT_RECIPIENTS = 27, // all players that have tagged this creature (for kill credit)
SMART_TARGET_FARTHEST = 28, // maxDist, playerOnly, isInLos
SMART_TARGET_END = 28
SMART_TARGET_END = 29
};
struct SmartTarget
@@ -1158,6 +1223,20 @@ struct SmartTarget
float x, y, z, o;
union
{
struct
{
uint32 maxDist;
uint32 playerOnly;
uint32 powerType;
} hostilRandom;
struct
{
uint32 maxDist;
uint32 playerOnly;
uint32 isInLos;
} farthest;
struct
{
uint32 creature;
@@ -1236,6 +1315,11 @@ struct SmartTarget
uint32 playerOnly;
} closestFriendly;
struct
{
uint32 useCharmerOrOwner;
} owner;
struct
{
uint32 param1;
@@ -1507,6 +1591,7 @@ class TC_GAME_API SmartWaypointMgr
// all events for a single entry
typedef std::vector<SmartScriptHolder> SmartAIEventList;
typedef std::vector<SmartScriptHolder> SmartAIEventStoredList;
// all events for all entries / guids
typedef std::unordered_map<int32, SmartAIEventList> SmartAIEventMap;