mirror of
https://github.com/Relintai/entity_spell_system.git
synced 2025-04-19 21:33:15 +02:00
Added helpers for easy checking the target's range for interaction.
This commit is contained in:
parent
77a4ed01e9
commit
6490663c97
@ -710,7 +710,7 @@ void Entity::_setup() {
|
||||
Ref<StatData> stat_data = cc->get_stat_data();
|
||||
|
||||
ERR_FAIL_COND(!stat_data.is_valid());
|
||||
|
||||
|
||||
for (int i = 0; i < ESS::get_singleton()->stat_get_count(); ++i) {
|
||||
stat_set_base(i, stat_data->get_base(i));
|
||||
}
|
||||
@ -2884,6 +2884,79 @@ void Entity::copen_window(int window_id) {
|
||||
emit_signal("onc_open_winow_request", window_id);
|
||||
}
|
||||
|
||||
bool Entity::iss_target_in_interact_range() {
|
||||
return call("_iss_target_in_interact_range");
|
||||
}
|
||||
bool Entity::isc_target_in_interact_range() {
|
||||
return call("_isc_target_in_interact_range");
|
||||
}
|
||||
bool Entity::_iss_target_in_interact_range() {
|
||||
Entity *t = gets_target();
|
||||
|
||||
if (!ObjectDB::instance_validate(t)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
Node2D *b2d = get_body_2d();
|
||||
|
||||
if (b2d) {
|
||||
Node2D *tb = t->get_body_2d();
|
||||
|
||||
if (!tb) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return (b2d->get_transform().get_origin() - tb->get_transform().get_origin()).length_squared() > EntityEnums::ENTITY_INTERACT_RANGE_SQUARED;
|
||||
}
|
||||
|
||||
Spatial *b3d = get_body_3d();
|
||||
|
||||
if (b3d) {
|
||||
Spatial *tb = t->get_body_3d();
|
||||
|
||||
if (!tb) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return (b3d->get_transform().get_origin() - tb->get_transform().get_origin()).length_squared() > EntityEnums::ENTITY_INTERACT_RANGE_SQUARED;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
bool Entity::_isc_target_in_interact_range() {
|
||||
Entity *t = getc_target();
|
||||
|
||||
if (!ObjectDB::instance_validate(t)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
Node2D *b2d = get_body_2d();
|
||||
|
||||
if (b2d) {
|
||||
Node2D *tb = t->get_body_2d();
|
||||
|
||||
if (!tb) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return (b2d->get_transform().get_origin() - tb->get_transform().get_origin()).length_squared() > EntityEnums::ENTITY_INTERACT_RANGE_SQUARED;
|
||||
}
|
||||
|
||||
Spatial *b3d = get_body_3d();
|
||||
|
||||
if (b3d) {
|
||||
Spatial *tb = t->get_body_3d();
|
||||
|
||||
if (!tb) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return (b3d->get_transform().get_origin() - tb->get_transform().get_origin()).length_squared() > EntityEnums::ENTITY_INTERACT_RANGE_SQUARED;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
//XP Operations
|
||||
void Entity::xp_adds(int value) {
|
||||
_s_xp += value;
|
||||
@ -6972,6 +7045,14 @@ void Entity::_bind_methods() {
|
||||
ClassDB::bind_method(D_METHOD("ssend_open_window", "window_id"), &Entity::ssend_open_window);
|
||||
ClassDB::bind_method(D_METHOD("copen_window", "window_id"), &Entity::copen_window);
|
||||
|
||||
BIND_VMETHOD(MethodInfo(PropertyInfo(Variant::BOOL, "ret"), "_iss_target_in_interact_range"));
|
||||
BIND_VMETHOD(MethodInfo(PropertyInfo(Variant::BOOL, "ret"), "_isc_target_in_interact_range"));
|
||||
|
||||
ClassDB::bind_method(D_METHOD("iss_target_in_interact_range"), &Entity::iss_target_in_interact_range);
|
||||
ClassDB::bind_method(D_METHOD("isc_target_in_interact_range"), &Entity::isc_target_in_interact_range);
|
||||
ClassDB::bind_method(D_METHOD("_iss_target_in_interact_range"), &Entity::_iss_target_in_interact_range);
|
||||
ClassDB::bind_method(D_METHOD("_isc_target_in_interact_range"), &Entity::_isc_target_in_interact_range);
|
||||
|
||||
//XP Operations
|
||||
ADD_SIGNAL(MethodInfo("notification_sxp_gained", PropertyInfo(Variant::OBJECT, "entity", PROPERTY_HINT_RESOURCE_TYPE, "Entity"), PropertyInfo(Variant::INT, "value")));
|
||||
ADD_SIGNAL(MethodInfo("notification_cxp_gained", PropertyInfo(Variant::OBJECT, "entity", PROPERTY_HINT_RESOURCE_TYPE, "Entity"), PropertyInfo(Variant::INT, "value")));
|
||||
|
@ -27,15 +27,14 @@ SOFTWARE.
|
||||
|
||||
#if VERSION_MAJOR > 3
|
||||
#include "core/object/object.h"
|
||||
#include "core/templates/vector.h"
|
||||
#include "core/string/ustring.h"
|
||||
#include "core/templates/vector.h"
|
||||
#else
|
||||
#include "core/object.h"
|
||||
#include "core/vector.h"
|
||||
#include "core/ustring.h"
|
||||
#include "core/vector.h"
|
||||
#endif
|
||||
|
||||
|
||||
#include "core/io/networked_multiplayer_peer.h"
|
||||
|
||||
#include "scene/main/node.h"
|
||||
@ -620,6 +619,11 @@ public:
|
||||
void ssend_open_window(int window_id);
|
||||
void copen_window(int window_id);
|
||||
|
||||
bool iss_target_in_interact_range();
|
||||
bool isc_target_in_interact_range();
|
||||
virtual bool _iss_target_in_interact_range();
|
||||
virtual bool _isc_target_in_interact_range();
|
||||
|
||||
//XP Operations
|
||||
void xp_adds(int value);
|
||||
void xp_addc(int value);
|
||||
@ -1196,13 +1200,13 @@ private:
|
||||
|
||||
//// Equipment ////
|
||||
|
||||
Vector<Ref<ItemInstance> > _s_equipment;
|
||||
Vector<Ref<ItemInstance> > _c_equipment;
|
||||
Vector<Ref<ItemInstance>> _s_equipment;
|
||||
Vector<Ref<ItemInstance>> _c_equipment;
|
||||
|
||||
//// Resources ////
|
||||
|
||||
Vector<Ref<EntityResource> > _s_resources;
|
||||
Vector<Ref<EntityResource> > _c_resources;
|
||||
Vector<Ref<EntityResource>> _s_resources;
|
||||
Vector<Ref<EntityResource>> _c_resources;
|
||||
|
||||
//// GCD ////
|
||||
|
||||
@ -1223,8 +1227,8 @@ private:
|
||||
|
||||
//// AuraComponent ////
|
||||
|
||||
Vector<Ref<AuraData> > _s_auras;
|
||||
Vector<Ref<AuraData> > _c_auras;
|
||||
Vector<Ref<AuraData>> _s_auras;
|
||||
Vector<Ref<AuraData>> _c_auras;
|
||||
|
||||
int _s_entity_type;
|
||||
int _c_entity_type;
|
||||
@ -1267,8 +1271,8 @@ private:
|
||||
|
||||
//// Data ////
|
||||
|
||||
Vector<Ref<EntityDataContainer> > _s_data;
|
||||
Vector<Ref<EntityDataContainer> > _c_data;
|
||||
Vector<Ref<EntityDataContainer>> _s_data;
|
||||
Vector<Ref<EntityDataContainer>> _c_data;
|
||||
|
||||
//// Actionbars ////
|
||||
|
||||
@ -1277,21 +1281,21 @@ private:
|
||||
|
||||
//// Crafting System ////
|
||||
|
||||
Vector<Ref<CraftRecipe> > _s_craft_recipes;
|
||||
Vector<Ref<CraftRecipe> > _c_craft_recipes;
|
||||
Vector<Ref<CraftRecipe>> _s_craft_recipes;
|
||||
Vector<Ref<CraftRecipe>> _c_craft_recipes;
|
||||
|
||||
//// Known Spells ////
|
||||
|
||||
int _s_free_spell_points;
|
||||
int _c_free_spell_points;
|
||||
|
||||
Vector<Ref<Spell> > _s_spells;
|
||||
Vector<Ref<Spell> > _c_spells;
|
||||
Vector<Ref<Spell>> _s_spells;
|
||||
Vector<Ref<Spell>> _c_spells;
|
||||
|
||||
//// Skills ////
|
||||
|
||||
Vector<Ref<EntitySkill> > _s_skills;
|
||||
Vector<Ref<EntitySkill> > _c_skills;
|
||||
Vector<Ref<EntitySkill>> _s_skills;
|
||||
Vector<Ref<EntitySkill>> _c_skills;
|
||||
|
||||
//// Stat Allocations ////
|
||||
|
||||
@ -1335,7 +1339,7 @@ private:
|
||||
|
||||
// Callbacks
|
||||
|
||||
Vector<Ref<SpellCastInfo> > _physics_process_scis;
|
||||
Vector<Ref<SpellCastInfo>> _physics_process_scis;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
Loading…
Reference in New Issue
Block a user