Added HOOK_PROJECTILE_HIT_ENTITY
This commit is contained in:
parent
773ce7fde6
commit
339d555111
@ -90,6 +90,7 @@ public:
|
||||
virtual bool OnPluginsLoaded (void) = 0;
|
||||
virtual bool OnPostCrafting (const cPlayer * a_Player, const cCraftingGrid * a_Grid, cCraftingRecipe * a_Recipe) = 0;
|
||||
virtual bool OnPreCrafting (const cPlayer * a_Player, const cCraftingGrid * a_Grid, cCraftingRecipe * a_Recipe) = 0;
|
||||
virtual bool OnProjectileHitEntity (cProjectileEntity & a_Projectile, cEntity & a_HitEntity) = 0;
|
||||
virtual bool OnSpawnedEntity (cWorld & a_World, cEntity & a_Entity) = 0;
|
||||
virtual bool OnSpawnedMonster (cWorld & a_World, cMonster & a_Monster) = 0;
|
||||
virtual bool OnSpawningEntity (cWorld & a_World, cEntity & a_Entity) = 0;
|
||||
|
@ -1108,6 +1108,26 @@ bool cPluginLua::OnPreCrafting(const cPlayer * a_Player, const cCraftingGrid * a
|
||||
|
||||
|
||||
|
||||
bool cPluginLua::OnProjectileHitEntity(cProjectileEntity & a_Projectile, cEntity & a_HitEntity)
|
||||
{
|
||||
cCSLock Lock(m_CriticalSection);
|
||||
bool res = false;
|
||||
cLuaRefs & Refs = m_HookMap[cPluginManager::HOOK_PROJECTILE_HIT_ENTITY];
|
||||
for (cLuaRefs::iterator itr = Refs.begin(), end = Refs.end(); itr != end; ++itr)
|
||||
{
|
||||
m_LuaState.Call((int)(**itr), &a_Projectile, &a_HitEntity, cLuaState::Return, res);
|
||||
if (res)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
bool cPluginLua::OnSpawnedEntity(cWorld & a_World, cEntity & a_Entity)
|
||||
{
|
||||
cCSLock Lock(m_CriticalSection);
|
||||
|
@ -113,6 +113,7 @@ public:
|
||||
virtual bool OnPluginsLoaded (void) override;
|
||||
virtual bool OnPostCrafting (const cPlayer * a_Player, const cCraftingGrid * a_Grid, cCraftingRecipe * a_Recipe) override;
|
||||
virtual bool OnPreCrafting (const cPlayer * a_Player, const cCraftingGrid * a_Grid, cCraftingRecipe * a_Recipe) override;
|
||||
virtual bool OnProjectileHitEntity (cProjectileEntity & a_Projectile, cEntity & a_HitEntity) override;
|
||||
virtual bool OnSpawnedEntity (cWorld & a_World, cEntity & a_Entity) override;
|
||||
virtual bool OnSpawnedMonster (cWorld & a_World, cMonster & a_Monster) override;
|
||||
virtual bool OnSpawningEntity (cWorld & a_World, cEntity & a_Entity) override;
|
||||
|
@ -1154,6 +1154,27 @@ bool cPluginManager::CallHookPreCrafting(const cPlayer * a_Player, const cCrafti
|
||||
|
||||
|
||||
|
||||
bool cPluginManager::CallHookProjectileHitEntity(cProjectileEntity & a_Projectile, cEntity & a_HitEntity)
|
||||
{
|
||||
HookMap::iterator Plugins = m_Hooks.find(HOOK_PROJECTILE_HIT_ENTITY);
|
||||
if (Plugins == m_Hooks.end())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
for (PluginList::iterator itr = Plugins->second.begin(); itr != Plugins->second.end(); ++itr)
|
||||
{
|
||||
if ((*itr)->OnProjectileHitEntity(a_Projectile, a_HitEntity))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
bool cPluginManager::CallHookSpawnedEntity(cWorld & a_World, cEntity & a_Entity)
|
||||
{
|
||||
HookMap::iterator Plugins = m_Hooks.find(HOOK_SPAWNED_ENTITY);
|
||||
|
@ -18,6 +18,9 @@ class cChunkDesc;
|
||||
// fwd: Entities/Entity.h
|
||||
class cEntity;
|
||||
|
||||
// fwd: Entities/ProjectileEntity.h
|
||||
class cProjectileEntity;
|
||||
|
||||
// fwd: Mobs/Monster.h
|
||||
class cMonster;
|
||||
|
||||
@ -102,6 +105,7 @@ public: // tolua_export
|
||||
HOOK_PLUGINS_LOADED,
|
||||
HOOK_POST_CRAFTING,
|
||||
HOOK_PRE_CRAFTING,
|
||||
HOOK_PROJECTILE_HIT_ENTITY,
|
||||
HOOK_SPAWNED_ENTITY,
|
||||
HOOK_SPAWNED_MONSTER,
|
||||
HOOK_SPAWNING_ENTITY,
|
||||
@ -201,6 +205,7 @@ public: // tolua_export
|
||||
bool CallHookPluginsLoaded (void);
|
||||
bool CallHookPostCrafting (const cPlayer * a_Player, const cCraftingGrid * a_Grid, cCraftingRecipe * a_Recipe);
|
||||
bool CallHookPreCrafting (const cPlayer * a_Player, const cCraftingGrid * a_Grid, cCraftingRecipe * a_Recipe);
|
||||
bool CallHookProjectileHitEntity (cProjectileEntity & a_Projectile, cEntity & a_HitEntity);
|
||||
bool CallHookSpawnedEntity (cWorld & a_World, cEntity & a_Entity);
|
||||
bool CallHookSpawnedMonster (cWorld & a_World, cMonster & a_Monster);
|
||||
bool CallHookSpawningEntity (cWorld & a_World, cEntity & a_Entity);
|
||||
|
@ -4,6 +4,7 @@
|
||||
// Implements the cProjectileEntity class representing the common base class for projectiles, as well as individual projectile types
|
||||
|
||||
#include "Globals.h"
|
||||
#include "../Bindings/PluginManager.h"
|
||||
#include "ProjectileEntity.h"
|
||||
#include "../ClientHandle.h"
|
||||
#include "Player.h"
|
||||
@ -148,6 +149,11 @@ public:
|
||||
|
||||
// TODO: Some entities don't interact with the projectiles (pickups, falling blocks)
|
||||
// TODO: Allow plugins to interfere about which entities can be hit
|
||||
if (cPluginManager::Get()->CallHookProjectileHitEntity(*m_Projectile, *a_Entity))
|
||||
{
|
||||
// A plugin disagreed.
|
||||
return false;
|
||||
}
|
||||
|
||||
if (LineCoeff < m_MinCoeff)
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user