DarkflameServer/dScripts/CppScripts.h

366 lines
12 KiB
C
Raw Normal View History

#pragma once
#include <cstdint>
#include <string>
#include <vector>
class User;
class Entity;
class NiPoint3;
enum class eMissionState : int32_t;
enum class ePetTamingNotifyType : uint32_t;
enum class eRebuildState : uint32_t;
namespace CppScripts {
/**
* Base class for all scripts. Includes virtual methods to be overridden to handle LUA equivelent events.
2022-07-28 13:39:57 +00:00
*
* All methods pass 'self' as the first parameter, this is the associated parent entity for the event.
* There will only ever be one instance of each script.
2022-07-28 13:39:57 +00:00
*
* Do not use class members as entity specific variables unless you're sure there will only event be one instance of this script.
* Do use class members as script wide variables, variables all entities which this script will access.
2022-07-28 13:39:57 +00:00
*
* Use self->GetVar<type_t>(u"variable_name") and self->SetVar<type_t>(u"variable_name", value) to manage variables.
2022-07-28 13:39:57 +00:00
*
* Designed to yield as close to a 1:1 mapping as possible with LUA.
* There will be events which are not implemented or inheritetly LUA features not easily translated to C++.
* Most of the time these can be worked around or ignored.
*/
class Script {
public:
Script();
~Script();
/**
* Invoked one frame after the script is loaded.
2022-07-28 13:39:57 +00:00
*
* Equivalent to 'function onStartup(self)'
*/
virtual void OnStartup(Entity* self) {};
/**
* Invoked upon an entity entering the phantom collider on self.
2022-07-28 13:39:57 +00:00
*
* Equivalent to 'function onCollisionPhantom(self, msg)'
*/
virtual void OnCollisionPhantom(Entity* self, Entity* target) {};
/**
* Invoked upon an entity leaving the phantom collider on self.
*
* Equivalent to 'function onOffCollisionPhantom(self, msg)'
*/
virtual void OnOffCollisionPhantom(Entity* self, Entity* target) {};
/**
* Invoked when a player accepted a mission.
2022-07-28 13:39:57 +00:00
*
* Equivalent to 'function onMissionDialogueOK(self, msg)'
*/
virtual void OnMissionDialogueOK(Entity* self, Entity* target, int missionID, eMissionState missionState) {};
/**
* Invoked when the client or the server invoked an event server-side.
2022-07-28 13:39:57 +00:00
*
* Equivalent to 'function onFireEventServerSide(self, msg)'
*/
2022-07-28 13:39:57 +00:00
virtual void OnFireEventServerSide(Entity* self, Entity* sender, std::string args, int32_t param1, int32_t param2, int32_t param3) {};
/**
* Invoked upon sending a object notification.
2022-07-28 13:39:57 +00:00
*
* Equivalent to 'function onNotifyObject(self, msg)'
*/
2022-07-28 13:39:57 +00:00
virtual void OnNotifyObject(Entity* self, Entity* sender, const std::string& name, int32_t param1 = 0, int32_t param2 = 0) {};
/**
* Invoked upon a player exiting the modular build minigame.
2022-07-28 13:39:57 +00:00
*
* Equivalent to 'function onModularBuildExit(self, msg)'
*/
virtual void OnModularBuildExit(Entity* self, Entity* player, bool bCompleted, std::vector<LOT> modules) {};
2022-07-28 13:39:57 +00:00
/**
* Invoked when a player has loaded into the zone.
2022-07-28 13:39:57 +00:00
*
* Equivalent to 'function onPlayerLoaded(self, msg)'
*/
virtual void OnPlayerLoaded(Entity* self, Entity* player) {};
/**
* Invoked when a player has died.
2022-07-28 13:39:57 +00:00
*
* Equivalent to 'function onPlayerDied(self, msg)'
*/
virtual void OnPlayerDied(Entity* self, Entity* player) {};
/**
* Invoked when a player has resurrected.
2022-07-28 13:39:57 +00:00
*
* Equivalent to 'function onPlayerResurrected(self, msg)'
*/
virtual void OnPlayerResurrected(Entity* self, Entity* player) {};
/**
* Invoked when a player has left the zone.
2022-07-28 13:39:57 +00:00
*
* Equivalent to 'function onPlayerExit(self, msg)'
*/
virtual void OnPlayerExit(Entity* self, Entity* player) {};
/**
* Invoked when a player has interacted with the proximity collider on self.
2022-07-28 13:39:57 +00:00
*
* Equivalent to 'function onProximityUpdate(self, msg)'
2022-07-28 13:39:57 +00:00
*
* @param name The name of the proximity collider recviving an interaction.
* @param status "ENTER" if a player has entered the proximity collider; "LEAVE" if a player has left the proximity collider
*/
virtual void OnProximityUpdate(Entity* self, Entity* entering, std::string name, std::string status) {};
/**
* Invoked when a timer on self has expired.
2022-07-28 13:39:57 +00:00
*
* Equivalent to 'function onTimerDone(self, msg)'
*/
virtual void OnTimerDone(Entity* self, std::string timerName) {};
/**
* Invoked when a player interactions with self.
2022-07-28 13:39:57 +00:00
*
* Equivalent to 'function onUse(self, msg)'
*/
virtual void OnUse(Entity* self, Entity* user) {};
/**
* Invoked when self has died.
2022-07-28 13:39:57 +00:00
*
* Equivalent to 'function onDie(self, msg)'
*/
virtual void OnDie(Entity* self, Entity* killer) {};
/**
* Invoked when self has received a hit.
2022-07-28 13:39:57 +00:00
*
* Equivalent to 'function onHit(self, msg)'
*/
virtual void OnHit(Entity* self, Entity* attacker) {};
/**
* Invoked when self has received an emote from a player.
2022-07-28 13:39:57 +00:00
*
* Equivalent to 'function onEmoteReceived(self, msg)'
*/
virtual void OnEmoteReceived(Entity* self, int32_t emote, Entity* target) {};
/**
* Invoked when a player has started building this quickbuild.
2022-07-28 13:39:57 +00:00
*
* Equivalent to 'function onRebuildStart(self, msg)'
*/
virtual void OnRebuildStart(Entity* self, Entity* target) {};
2022-07-28 13:39:57 +00:00
/**
* Invoked when this quickbuild has changed state.
2022-07-28 13:39:57 +00:00
*
* Equivalent to 'function onRebuildNotifyState(self, msg)'
*/
virtual void OnRebuildNotifyState(Entity* self, eRebuildState state) {};
/**
* Invoked when this quickbuild has been completed.
2022-07-28 13:39:57 +00:00
*
* Equivalent to 'function onRebuildComplete(self, msg)'
*/
virtual void OnRebuildComplete(Entity* self, Entity* target) {};
/**
* Invoked when self has received either a hit or heal.
2022-07-28 13:39:57 +00:00
*
* Equivalent to 'function onHitOrHealResult(self, msg)'
*/
virtual void OnHitOrHealResult(Entity* self, Entity* attacker, int32_t damage) {};
2022-07-28 13:39:57 +00:00
/**
* Invoked when self has received either a hit or heal. Only used for scripts subscribed to an entity.
*
* Equivalent to 'function notifyHitOrHealResult(self, msg)'
*/
virtual void NotifyHitOrHealResult(Entity* self, Entity* attacker, int32_t damage) {};
/**
* Invoked when a player has responsed to a mission.
2022-07-28 13:39:57 +00:00
*
* Equivalent to 'function onRespondToMission(self, msg)'
*/
virtual void OnRespondToMission(Entity* self, int missionID, Entity* player, int reward) {};
2022-07-28 13:39:57 +00:00
/**
* Invoked once per frame.
2022-07-28 13:39:57 +00:00
*
* No LUA eqivalent.
*/
virtual void OnUpdate(Entity* self) {};
2022-07-28 13:39:57 +00:00
/**
* Invoked when this property has been rented.
2022-07-28 13:39:57 +00:00
*
* Equivalent to 'function onZonePropertyRented(self, msg)'
*/
virtual void OnZonePropertyRented(Entity* self, Entity* renter) {};
2022-07-28 13:39:57 +00:00
/**
* Invoked when a player has begun to edit this property.
2022-07-28 13:39:57 +00:00
*
* Equivalent to 'function onZonePropertyEditBegin(self, msg)'
*/
virtual void OnZonePropertyEditBegin(Entity* self) {};
/**
* Invoked when a player has concluded editing this property.
2022-07-28 13:39:57 +00:00
*
* Equivalent to 'function onZonePropertyEditEnd(self, msg)'
*/
virtual void OnZonePropertyEditEnd(Entity* self) {};
/**
* Invoked when a player has equipped a model while editing this property.
2022-07-28 13:39:57 +00:00
*
* Equivalent to 'function onZonePropertyModelEquipped(self, msg)'
*/
virtual void OnZonePropertyModelEquipped(Entity* self) {};
/**
* Invoked when a player has placed a model while editing this property.
2022-07-28 13:39:57 +00:00
*
* Equivalent to 'function onZonePropertyModelPlaced(self, msg)'
*/
virtual void OnZonePropertyModelPlaced(Entity* self, Entity* player) {};
/**
* Invoked when a player has picked up a model while editing this property.
2022-07-28 13:39:57 +00:00
*
* Equivalent to 'function onZonePropertyModelPickedUp(self, msg)'
*/
virtual void OnZonePropertyModelPickedUp(Entity* self, Entity* player) {};
/**
* Invoked when a player removed a model while editing this property.
2022-07-28 13:39:57 +00:00
*
* Equivalent to 'function onZonePropertyModelRemoved(self, msg)'
*/
virtual void OnZonePropertyModelRemoved(Entity* self, Entity* player) {};
/**
* Invoked when a player removed a model while holding it when editing this property.
2022-07-28 13:39:57 +00:00
*
* Equivalent to 'function onZonePropertyModelRemoved(self, msg)'
*/
virtual void OnZonePropertyModelRemovedWhileEquipped(Entity* self, Entity* player) {};
2022-07-28 13:39:57 +00:00
/**
* Invoked when a player rotated a model while editing this property.
2022-07-28 13:39:57 +00:00
*
* Equivalent to 'function onZonePropertyModelRotated(self, msg)'
*/
virtual void OnZonePropertyModelRotated(Entity* self, Entity* player) {};
/**
* Invoked when the pet taming minigame encounted an event.
2022-07-28 13:39:57 +00:00
*
* Equivalent to 'function onNotifyPetTamingMinigame(self, msg)'
*/
virtual void OnNotifyPetTamingMinigame(Entity* self, Entity* tamer, ePetTamingNotifyType type) {};
2022-07-28 13:39:57 +00:00
/**
* Invoked when a player responded to a message box.
2022-07-28 13:39:57 +00:00
*
* Equivalent to 'function onMessageBoxResponse(self, msg)'
*/
virtual void OnMessageBoxResponse(Entity* self, Entity* sender, int32_t button, const std::u16string& identifier, const std::u16string& userData) {};
2022-07-28 13:39:57 +00:00
/**
* Invoked when a player responded to a choice box.
2022-07-28 13:39:57 +00:00
*
* Equivalent to 'function onChoiceBoxResponse(self, msg)'
*/
virtual void OnChoiceBoxResponse(Entity* self, Entity* sender, int32_t button, const std::u16string& buttonIdentifier, const std::u16string& identifier) {};
2022-07-28 13:39:57 +00:00
/**
* Invoked when self arrived at a moving platform waypoint.
2022-07-28 13:39:57 +00:00
*
* Equivalent to 'function onWaypointReached(self, msg)'
*/
virtual void OnWaypointReached(Entity* self, uint32_t waypointIndex) {};
2022-07-28 13:39:57 +00:00
/**
* Invoked when a player fired a skill event on self.
2022-07-28 13:39:57 +00:00
*
* Equivalent to 'function onSkillEventFired(self, msg)'
*/
virtual void OnSkillEventFired(Entity* self, Entity* caster, const std::string& message) {};
2022-07-28 13:39:57 +00:00
/**
* Invoked when self casted a skill.
2022-07-28 13:39:57 +00:00
*
* Equivalent to 'function onSkillCast(self, msg)'
*/
virtual void OnSkillCast(Entity* self, uint32_t skillID) {};
/**
* Invoked when a player on a rail reaches a waypoint
* Equivalent to: 'onPlayerRailArrivedNotification(self, msg)'
* @param self the parent of the script
* @param sender the entity that sent the event
* @param pathName the name of the path the entity was on
* @param waypoint the waypoint number of the path the entity was on
*/
virtual void OnPlayerRailArrived(Entity* self, Entity* sender, const std::u16string& pathName, int32_t waypoint) {};
/**
* Used by legacy minigames to indicate something has changed about the activity
* @param self the entity the script belongs to
* @param senderID the sender of the message
* @param value1 some value to represent the change
* @param value2 some other value to represent the change
* @param stringValue some string value to represent the change
*/
2022-07-28 13:39:57 +00:00
virtual void OnActivityStateChangeRequest(Entity* self, const LWOOBJID senderID, const int32_t value1,
const int32_t value2, const std::u16string& stringValue) {
};
virtual void OnCinematicUpdate(Entity* self, Entity* sender, eCinematicEvent event, const std::u16string& pathName,
2022-07-28 13:39:57 +00:00
float_t pathTime, float_t totalTime, int32_t waypoint) {
};
/**
* Used by items to tell their owner that they were equipped.
*
* @param itemOwner The owner of the item
* @param itemObjId The items Object ID
*/
virtual void OnFactionTriggerItemEquipped(Entity* itemOwner, LWOOBJID itemObjId) {};
/**
* Used by items to tell their owner that they were unequipped.
*
* @param itemOwner The owner of the item
* @param itemObjId The items Object ID
*/
virtual void OnFactionTriggerItemUnequipped(Entity* itemOwner, LWOOBJID itemObjId) {};
/**
* Handles exiting a scripted activity
*
* @param sender
* @param player the player to remove
* @param canceled if it was done via the cancel button
*/
virtual void OnRequestActivityExit(Entity* sender, LWOOBJID player, bool canceled){};
};
Script* GetScript(Entity* parent, const std::string& scriptName);
std::vector<Script*> GetEntityScripts(Entity* entity);
2022-07-28 13:39:57 +00:00
};