killaura: add Lua API to target an entity for killing
needs to have a delay between killaura steps to prevent lag and excessive hunger usage also prob needs a better API that does logic cpp-side in order for frenemies to turn out better also handleKillaura should prob be moved to another file
This commit is contained in:
parent
653966f4db
commit
80e6a28fe2
@ -2425,8 +2425,9 @@ PointedThing Game::updatePointedThing(
|
||||
ClientMap &map = env.getClientMap();
|
||||
const NodeDefManager *nodedef = map.getNodeDefManager();
|
||||
|
||||
if (g_settings->getBool("killaura"))
|
||||
handleKillaura(shootline.start, shootline.getLength());
|
||||
if (g_settings->getBool("killaura")) {
|
||||
client->getScript()->killaura_step();
|
||||
}
|
||||
|
||||
runData.selected_object = NULL;
|
||||
hud->pointing_at_object = false;
|
||||
@ -2504,22 +2505,6 @@ PointedThing Game::updatePointedThing(
|
||||
return result;
|
||||
}
|
||||
|
||||
void Game::handleKillaura(v3f origin, f32 max_d)
|
||||
{
|
||||
ClientEnvironment &env = client->getEnv();
|
||||
std::vector<DistanceSortedActiveObject> allObjects;
|
||||
env.getActiveObjects(origin, max_d, allObjects);
|
||||
for (const auto &allObject : allObjects) {
|
||||
ClientActiveObject *obj = allObject.obj;
|
||||
s16 id = obj->getId();
|
||||
aabb3f selection_box;
|
||||
if (! obj->getSelectionBox(&selection_box))
|
||||
continue;
|
||||
PointedThing pointed(id, v3f(0,0,0), v3s16(0,0,0), 0);
|
||||
client->interact(INTERACT_START_DIGGING, pointed);
|
||||
}
|
||||
}
|
||||
|
||||
void Game::handlePointingAtNothing(const ItemStack &playerItem)
|
||||
{
|
||||
infostream << "Right Clicked in Air" << std::endl;
|
||||
|
@ -771,7 +771,6 @@ public:
|
||||
PointedThing updatePointedThing(
|
||||
const core::line3d<f32> &shootline, bool liquids_pointable,
|
||||
bool look_for_object, const v3s16 &camera_offset);
|
||||
void handleKillaura(v3f origin, f32 max_d);
|
||||
void handlePointingAtNothing(const ItemStack &playerItem);
|
||||
void handlePointingAtNode(const PointedThing &pointed,
|
||||
const ItemStack &selected_item, const ItemStack &hand_item, f32 dtime);
|
||||
|
@ -24,6 +24,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
#include "common/c_converter.h"
|
||||
#include "common/c_content.h"
|
||||
#include "s_item.h"
|
||||
#include "lua_api/l_clientobject.h"
|
||||
|
||||
void ScriptApiClient::on_mods_loaded()
|
||||
{
|
||||
@ -248,6 +249,66 @@ void ScriptApiClient::open_special_inventory()
|
||||
lua_pcall(L, 0, 0, error_handler);
|
||||
}
|
||||
|
||||
#include "client/clientenvironment.h"
|
||||
#include "client/content_cao.h"
|
||||
#include "util/pointedthing.h"
|
||||
|
||||
void handleKillaura(Client *client, u16 id)
|
||||
{
|
||||
//Client *client = getClient();
|
||||
ClientEnvironment &env = client->getEnv();
|
||||
GenericCAO *obj = env.getGenericCAO(id);
|
||||
aabb3f selection_box;
|
||||
|
||||
// if something doesn't have a selection box we're probably not able to hurt it
|
||||
if (!obj || !obj->getSelectionBox(&selection_box))
|
||||
return;
|
||||
|
||||
PointedThing pointed(id, v3f(0,0,0), v3s16(0,0,0), 0);
|
||||
client->interact(INTERACT_START_DIGGING, pointed);
|
||||
}
|
||||
|
||||
// basic client does logic implementation
|
||||
// should check if an object is in range
|
||||
void ScriptApiClient::killaura_step()
|
||||
{
|
||||
SCRIPTAPI_PRECHECKHEADER
|
||||
|
||||
lua_getglobal(L, "core");
|
||||
lua_getfield(L, -1, "killaura");
|
||||
if (!lua_istable(L, -1))
|
||||
return;
|
||||
|
||||
lua_getfield(L, -1, "targets");
|
||||
if (!lua_istable(L, -1))
|
||||
return;
|
||||
|
||||
// move targets to the bottom of the stack
|
||||
lua_insert(L, 1);
|
||||
lua_pushnil(L); // first 'key'
|
||||
|
||||
std::cout << "Got targets" << std::endl;
|
||||
|
||||
// iterate through the top of the stack
|
||||
while (lua_next(L, 1) != 0) {
|
||||
// ToS is a ClientObjectRef, userdata
|
||||
void *userdata = luaL_checkudata(L, -1, "ClientObjectRef");
|
||||
if (!userdata)
|
||||
luaL_typerror(L, -1, "ClientObjectRef");
|
||||
ClientObjectRef *ref = *(ClientObjectRef **)userdata;
|
||||
|
||||
// 2 functions need to be made here
|
||||
// handleKillaura or whatever is in game.cpp i believe, targets all entities
|
||||
// would need to be moved to fix circular dependencies
|
||||
// this version should just target 1, grabbed from ClientActiveObject:get_object(id)
|
||||
// ClientObjectRef::getobject() is feature parity of ObjectRef::getobject()
|
||||
handleKillaura(getClient(), ClientObjectRef::getobject(ref)->getId());
|
||||
|
||||
lua_pop(L, 1); // doesnt pop key
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void ScriptApiClient::setEnv(ClientEnvironment *env)
|
||||
{
|
||||
ScriptApiBase::setEnv(env);
|
||||
|
@ -61,5 +61,7 @@ public:
|
||||
bool on_inventory_open(Inventory *inventory);
|
||||
void open_special_inventory();
|
||||
|
||||
void killaura_step();
|
||||
|
||||
void setEnv(ClientEnvironment *env);
|
||||
};
|
||||
|
@ -29,6 +29,11 @@ GenericCAO *ClientObjectRef::get_generic_cao(ClientObjectRef *ref, lua_State *L)
|
||||
return gcao;
|
||||
}
|
||||
|
||||
ClientActiveObject *ClientObjectRef::getobject(ClientObjectRef *ref)
|
||||
{
|
||||
return get_cao(ref);
|
||||
}
|
||||
|
||||
int ClientObjectRef::l_get_pos(lua_State *L)
|
||||
{
|
||||
ClientObjectRef *ref = checkobject(L, 1);
|
||||
|
@ -17,6 +17,8 @@ public:
|
||||
|
||||
static ClientObjectRef *checkobject(lua_State *L, int narg);
|
||||
|
||||
static ClientActiveObject *getobject(ClientObjectRef *ref);
|
||||
|
||||
private:
|
||||
ClientActiveObject *m_object = nullptr;
|
||||
static const char className[];
|
||||
|
Loading…
x
Reference in New Issue
Block a user