aboutsummaryrefslogtreecommitdiff
path: root/src/server/game/Entities/GameObject
diff options
context:
space:
mode:
authorGiacomo Pozzoni <giacomopoz@gmail.com>2021-11-07 19:17:12 +0100
committerGitHub <noreply@github.com>2021-11-07 20:17:12 +0200
commit0817be8f76dead48e2c0eeb7d5a7434a452f0dcf (patch)
tree0a49a89d1928ae1ec6023bf208017fc4a10826fe /src/server/game/Entities/GameObject
parent8f4bf97b44ace657a288a3bc99afb56e0151d76a (diff)
Core/SAI: Add SMART_ACTION_ACTIVATE_GAMEOBJECT action (#27216)
Closes #27196
Diffstat (limited to 'src/server/game/Entities/GameObject')
-rw-r--r--src/server/game/Entities/GameObject/GameObject.cpp73
-rw-r--r--src/server/game/Entities/GameObject/GameObject.h1
-rw-r--r--src/server/game/Entities/GameObject/GameObjectData.h49
3 files changed, 99 insertions, 24 deletions
diff --git a/src/server/game/Entities/GameObject/GameObject.cpp b/src/server/game/Entities/GameObject/GameObject.cpp
index 4a290700fc4..2df3f55d7fa 100644
--- a/src/server/game/Entities/GameObject/GameObject.cpp
+++ b/src/server/game/Entities/GameObject/GameObject.cpp
@@ -1432,6 +1432,79 @@ void GameObject::UseDoorOrButton(uint32 time_to_restore, bool alternative /* = f
m_cooldownTime = time_to_restore ? (GameTime::GetGameTimeMS() + time_to_restore) : 0;
}
+void GameObject::ActivateObject(GameObjectActions action, WorldObject* spellCaster, uint32 spellId, int32 effectIndex)
+{
+ Unit* unitCaster = spellCaster ? spellCaster->ToUnit() : nullptr;
+
+ switch (action)
+ {
+ case GameObjectActions::AnimateCustom0:
+ case GameObjectActions::AnimateCustom1:
+ case GameObjectActions::AnimateCustom2:
+ case GameObjectActions::AnimateCustom3:
+ SendCustomAnim(uint32(action) - uint32(GameObjectActions::AnimateCustom0));
+ break;
+ case GameObjectActions::Disturb: // What's the difference with Open?
+ case GameObjectActions::Open:
+ if (unitCaster)
+ Use(unitCaster);
+ break;
+ case GameObjectActions::OpenAndUnlock:
+ if (unitCaster)
+ UseDoorOrButton(0, false, unitCaster);
+ [[fallthrough]];
+ case GameObjectActions::Unlock:
+ case GameObjectActions::Lock:
+ ApplyModFlag(GAMEOBJECT_FLAGS, GO_FLAG_LOCKED, action == GameObjectActions::Lock);
+ break;
+ case GameObjectActions::Close:
+ case GameObjectActions::Rebuild:
+ ResetDoorOrButton();
+ break;
+ case GameObjectActions::Despawn:
+ DespawnOrUnsummon();
+ break;
+ case GameObjectActions::MakeInert:
+ case GameObjectActions::MakeActive:
+ ApplyModFlag(GAMEOBJECT_FLAGS, GO_FLAG_NOT_SELECTABLE, action == GameObjectActions::MakeInert);
+ break;
+ case GameObjectActions::CloseAndLock:
+ ResetDoorOrButton();
+ SetFlag(GAMEOBJECT_FLAGS, GO_FLAG_LOCKED);
+ break;
+ case GameObjectActions::Destroy:
+ if (unitCaster)
+ UseDoorOrButton(0, true, unitCaster);
+ break;
+ case GameObjectActions::UseArtKit0:
+ case GameObjectActions::UseArtKit1:
+ case GameObjectActions::UseArtKit2:
+ case GameObjectActions::UseArtKit3:
+ {
+ GameObjectTemplateAddon const* templateAddon = GetTemplateAddon();
+
+ uint32 artKitIndex = uint32(action) - uint32(GameObjectActions::UseArtKit0);
+
+ uint32 artKitValue = 0;
+ if (templateAddon != nullptr)
+ artKitValue = templateAddon->artKits[artKitIndex];
+
+ if (artKitValue == 0)
+ TC_LOG_ERROR("sql.sql", "GameObject %d hit by spell %d needs `artkit%d` in `gameobject_template_addon`", GetEntry(), spellId, artKitIndex);
+ else
+ SetGoArtKit(artKitValue);
+
+ break;
+ }
+ case GameObjectActions::None:
+ TC_LOG_FATAL("spell", "Spell %d has action type NONE in effect %d", spellId, effectIndex);
+ break;
+ default:
+ TC_LOG_ERROR("spell", "Spell %d has unhandled action %d in effect %d", spellId, int32(action), effectIndex);
+ break;
+ }
+}
+
void GameObject::SetGoArtKit(uint8 kit)
{
SetByteValue(GAMEOBJECT_BYTES_1, 2, kit);
diff --git a/src/server/game/Entities/GameObject/GameObject.h b/src/server/game/Entities/GameObject/GameObject.h
index f06a4fcbdd3..ec0547c2aaa 100644
--- a/src/server/game/Entities/GameObject/GameObject.h
+++ b/src/server/game/Entities/GameObject/GameObject.h
@@ -226,6 +226,7 @@ class TC_GAME_API GameObject : public WorldObject, public GridObject<GameObject>
void UseDoorOrButton(uint32 time_to_restore = 0, bool alternative = false, Unit* user = nullptr);
// 0 = use `gameobject`.`spawntimesecs`
void ResetDoorOrButton();
+ void ActivateObject(GameObjectActions action, WorldObject* spellCaster = nullptr, uint32 spellId = 0, int32 effectIndex = -1);
void TriggeringLinkedGameObject(uint32 trapEntry, Unit* target);
diff --git a/src/server/game/Entities/GameObject/GameObjectData.h b/src/server/game/Entities/GameObject/GameObjectData.h
index ef7c95035e0..087eb8c18bd 100644
--- a/src/server/game/Entities/GameObject/GameObjectData.h
+++ b/src/server/game/Entities/GameObject/GameObjectData.h
@@ -675,30 +675,31 @@ struct GameObjectData : public SpawnData
enum class GameObjectActions : uint32
{
// Name from client executable // Comments
- None, // -NONE-
- AnimateCustom0, // Animate Custom0
- AnimateCustom1, // Animate Custom1
- AnimateCustom2, // Animate Custom2
- AnimateCustom3, // Animate Custom3
- Disturb, // Disturb // Triggers trap
- Unlock, // Unlock // Resets GO_FLAG_LOCKED
- Lock, // Lock // Sets GO_FLAG_LOCKED
- Open, // Open // Sets GO_STATE_ACTIVE
- OpenAndUnlock, // Open + Unlock // Sets GO_STATE_ACTIVE and resets GO_FLAG_LOCKED
- Close, // Close // Sets GO_STATE_READY
- ToggleOpen, // Toggle Open
- Destroy, // Destroy // Sets GO_STATE_DESTROYED
- Rebuild, // Rebuild // Resets from GO_STATE_DESTROYED
- Creation, // Creation
- Despawn, // Despawn
- MakeInert, // Make Inert // Disables interactions
- MakeActive, // Make Active // Enables interactions
- CloseAndLock, // Close + Lock // Sets GO_STATE_READY and sets GO_FLAG_LOCKED
- UseArtKit0, // Use ArtKit0 // 46904: 121
- UseArtKit1, // Use ArtKit1 // 36639: 81, 46903: 122
- UseArtKit2, // Use ArtKit2
- UseArtKit3, // Use ArtKit3
- SetTapList, // Set Tap List
+ None = 0, // -NONE-
+ AnimateCustom0 = 1, // Animate Custom0
+ AnimateCustom1 = 2, // Animate Custom1
+ AnimateCustom2 = 3, // Animate Custom2
+ AnimateCustom3 = 4, // Animate Custom3
+ Disturb = 5, // Disturb // Triggers trap
+ Unlock = 6, // Unlock // Resets GO_FLAG_LOCKED
+ Lock = 7, // Lock // Sets GO_FLAG_LOCKED
+ Open = 8, // Open // Sets GO_STATE_ACTIVE
+ OpenAndUnlock = 9, // Open + Unlock // Sets GO_STATE_ACTIVE and resets GO_FLAG_LOCKED
+ Close = 10, // Close // Sets GO_STATE_READY
+ ToggleOpen = 11, // Toggle Open
+ Destroy = 12, // Destroy // Sets GO_STATE_DESTROYED
+ Rebuild = 13, // Rebuild // Resets from GO_STATE_DESTROYED
+ Creation = 14, // Creation
+ Despawn = 15, // Despawn
+ MakeInert = 16, // Make Inert // Disables interactions
+ MakeActive = 17, // Make Active // Enables interactions
+ CloseAndLock = 18, // Close + Lock // Sets GO_STATE_READY and sets GO_FLAG_LOCKED
+ UseArtKit0 = 19, // Use ArtKit0 // 46904: 121
+ UseArtKit1 = 20, // Use ArtKit1 // 36639: 81, 46903: 122
+ UseArtKit2 = 21, // Use ArtKit2
+ UseArtKit3 = 22, // Use ArtKit3
+ SetTapList = 23, // Set Tap List
+ Max
};
#endif // GameObjectData_h__