Added a simple Speed and Health resource.

This commit is contained in:
Relintai 2020-04-28 23:54:23 +02:00
parent 2c47f9f550
commit bebab39f34
14 changed files with 418 additions and 17 deletions

4
SCsub
View File

@ -81,7 +81,11 @@ sources = [
"entities/resources/entity_resource_data.cpp", "entities/resources/entity_resource_data.cpp",
"entities/resources/entity_resource_cost_data.cpp", "entities/resources/entity_resource_cost_data.cpp",
"entities/resources/entity_resource_cost_data_health.cpp",
"entities/resources/entity_resource_cost_data_resource.cpp",
"entities/resources/entity_resource.cpp", "entities/resources/entity_resource.cpp",
"entities/resources/entity_resource_health.cpp",
"entities/resources/entity_resource_speed.cpp",
"drag_and_drop/es_drag_and_drop.cpp", "drag_and_drop/es_drag_and_drop.cpp",

View File

@ -49,8 +49,12 @@ def get_doc_classes():
"VendorItemDataEntry", "VendorItemDataEntry",
"VendorItemData", "VendorItemData",
"EntityResourceCostData", "EntityResourceCostData",
"EntityResourceCostDataHealth",
"EntityResourceCostDataResource",
"EntityResourceData", "EntityResourceData",
"EntityResource", "EntityResource",
"EntityResourceHealth",
"EntityResourceSpeed",
"EntitySkillData", "EntitySkillData",
"EntitySkill", "EntitySkill",
"ComplexLevelStatData", "ComplexLevelStatData",

View File

@ -398,8 +398,6 @@ public:
void resource_removes(int index); void resource_removes(int index);
void resource_clears(); void resource_clears();
void resource_addc_rpc(int index, String data);
Ref<EntityResource> resource_getc_index(int index); Ref<EntityResource> resource_getc_index(int index);
Ref<EntityResource> resource_getc_id(int id); Ref<EntityResource> resource_getc_id(int id);
void resource_addc(int index, Ref<EntityResource> resource); void resource_addc(int index, Ref<EntityResource> resource);
@ -407,6 +405,8 @@ public:
void resource_removec(int index); void resource_removec(int index);
void resource_clearc(); void resource_clearc();
void resource_addc_rpc(int index, String data);
void resource_sends_current(int index, int current); void resource_sends_current(int index, int current);
void resource_sends_curr_max(int index, int current, int max); void resource_sends_curr_max(int index, int current, int max);
void resource_sends_data(int index, String data); void resource_sends_data(int index, String data);

View File

@ -22,13 +22,6 @@ SOFTWARE.
#include "entity_resource_cost_data.h" #include "entity_resource_cost_data.h"
Ref<EntityResourceData> EntityResourceCostData::get_entity_resource_data() {
return _entity_resource_data;
}
void EntityResourceCostData::set_entity_resource_data(Ref<EntityResourceData> data) {
_entity_resource_data = data;
}
int EntityResourceCostData::get_cost() { int EntityResourceCostData::get_cost() {
return _cost; return _cost;
} }
@ -41,10 +34,6 @@ EntityResourceCostData::EntityResourceCostData() {
} }
void EntityResourceCostData::_bind_methods() { void EntityResourceCostData::_bind_methods() {
ClassDB::bind_method(D_METHOD("get_entity_resource_data"), &EntityResourceCostData::get_entity_resource_data);
ClassDB::bind_method(D_METHOD("set_entity_resource_data", "value"), &EntityResourceCostData::set_entity_resource_data);
ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "entity_resource_data", PROPERTY_HINT_RESOURCE_TYPE, "EntityResourceData"), "set_entity_resource_data", "get_entity_resource_data");
ClassDB::bind_method(D_METHOD("get_cost"), &EntityResourceCostData::get_cost); ClassDB::bind_method(D_METHOD("get_cost"), &EntityResourceCostData::get_cost);
ClassDB::bind_method(D_METHOD("set_cost", "value"), &EntityResourceCostData::set_cost); ClassDB::bind_method(D_METHOD("set_cost", "value"), &EntityResourceCostData::set_cost);
ADD_PROPERTY(PropertyInfo(Variant::INT, "cost"), "set_cost", "get_cost"); ADD_PROPERTY(PropertyInfo(Variant::INT, "cost"), "set_cost", "get_cost");

View File

@ -32,9 +32,6 @@ class EntityResourceCostData : public Resource {
GDCLASS(EntityResourceCostData, Resource); GDCLASS(EntityResourceCostData, Resource);
public: public:
Ref<EntityResourceData> get_entity_resource_data();
void set_entity_resource_data(Ref<EntityResourceData> data);
int get_cost(); int get_cost();
void set_cost(int value); void set_cost(int value);
@ -44,7 +41,6 @@ protected:
static void _bind_methods(); static void _bind_methods();
private: private:
Ref<EntityResourceData> _entity_resource_data;
int _cost; int _cost;
}; };

View File

@ -0,0 +1,29 @@
/*
Copyright (c) 2019-2020 Péter Magyar
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
#include "entity_resource_cost_data_health.h"
EntityResourceCostDataHealth::EntityResourceCostDataHealth() {
}
void EntityResourceCostDataHealth::_bind_methods() {
}

View File

@ -0,0 +1,41 @@
/*
Copyright (c) 2019-2020 Péter Magyar
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
#ifndef ENTITY_RESOURCE_COST_DATA_HEALTH_H
#define ENTITY_RESOURCE_COST_DATA_HEALTH_H
#include "core/resource.h"
#include "entity_resource_cost_data.h"
#include "entity_resource_data.h"
class EntityResourceCostDataHealth : public EntityResourceCostData {
GDCLASS(EntityResourceCostDataHealth, EntityResourceCostData);
public:
EntityResourceCostDataHealth();
protected:
static void _bind_methods();
};
#endif

View File

@ -0,0 +1,39 @@
/*
Copyright (c) 2019-2020 Péter Magyar
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
#include "entity_resource_cost_data_resource.h"
Ref<EntityResourceData> EntityResourceCostDataResource::get_entity_resource_data() {
return _entity_resource_data;
}
void EntityResourceCostDataResource::set_entity_resource_data(Ref<EntityResourceData> data) {
_entity_resource_data = data;
}
EntityResourceCostDataResource::EntityResourceCostDataResource() {
}
void EntityResourceCostDataResource::_bind_methods() {
ClassDB::bind_method(D_METHOD("get_entity_resource_data"), &EntityResourceCostDataResource::get_entity_resource_data);
ClassDB::bind_method(D_METHOD("set_entity_resource_data", "value"), &EntityResourceCostDataResource::set_entity_resource_data);
ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "entity_resource_data", PROPERTY_HINT_RESOURCE_TYPE, "EntityResourceData"), "set_entity_resource_data", "get_entity_resource_data");
}

View File

@ -0,0 +1,47 @@
/*
Copyright (c) 2019-2020 Péter Magyar
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
#ifndef ENTITY_RESOURCE_COST_DATA_RESOURCE_H
#define ENTITY_RESOURCE_COST_DATA_RESOURCE_H
#include "core/resource.h"
#include "entity_resource_cost_data.h"
#include "entity_resource_data.h"
class EntityResourceCostDataResource : public EntityResourceCostData {
GDCLASS(EntityResourceCostDataResource, EntityResourceCostData);
public:
Ref<EntityResourceData> get_entity_resource_data();
void set_entity_resource_data(Ref<EntityResourceData> data);
EntityResourceCostDataResource();
protected:
static void _bind_methods();
private:
Ref<EntityResourceData> _entity_resource_data;
};
#endif

View File

@ -0,0 +1,74 @@
/*
Copyright (c) 2019-2020 Péter Magyar
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
#include "entity_resource_health.h"
#include "../../database/ess_resource_db.h"
#include "../../singletons/ess.h"
#include "../entity.h"
#include "../stats/stat.h"
#include "entity_resource_data.h"
void EntityResourceHealth::_init() {
set_current_value(100);
stamina_stat_id = 0;
health_stat_id = 0;
if (ESS::get_instance()->stat_is_property("Stamina")) {
stamina_stat_id = ESS::get_instance()->stat_get_id("Stamina");
}
if (ESS::get_instance()->stat_is_property("Health")) {
health_stat_id = ESS::get_instance()->stat_get_id("Health");
}
}
void EntityResourceHealth::_ons_added(Node *entity) {
refresh();
}
void EntityResourceHealth::_notification_sstat_changed(Ref<Stat> stat) {
if (stat->get_id() == stamina_stat_id || stat->get_id() == health_stat_id)
refresh();
}
void EntityResourceHealth::refresh() {
Ref<Stat> stamina = get_owner()->get_stat(stamina_stat_id);
Ref<Stat> health = get_owner()->get_stat(health_stat_id);
int val = int(stamina->gets_current()) * 10 + int(health->gets_current());
set_max_value(val);
set_current_value(val);
}
EntityResourceHealth::EntityResourceHealth() {
stamina_stat_id = 0;
health_stat_id = 0;
}
EntityResourceHealth::~EntityResourceHealth() {
}
void EntityResourceHealth::_bind_methods() {
ClassDB::bind_method(D_METHOD("_init"), &EntityResourceHealth::_init);
ClassDB::bind_method(D_METHOD("_ons_added", "entity"), &EntityResourceHealth::_ons_added);
ClassDB::bind_method(D_METHOD("_notification_sstat_changed", "stat"), &EntityResourceHealth::_notification_sstat_changed);
ClassDB::bind_method(D_METHOD("refresh"), &EntityResourceHealth::refresh);
}

View File

@ -0,0 +1,52 @@
/*
Copyright (c) 2019-2020 Péter Magyar
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
#ifndef ENTITY_RESOURCE_HEALTH_H
#define ENTITY_RESOURCE_HEALTH_H
#include "entity_resource.h"
class Stat;
class Entity;
class EntityResourceData;
class EntityResourceHealth : public EntityResource {
GDCLASS(EntityResourceHealth, EntityResource);
public:
void _init();
void _ons_added(Node *entity);
void _notification_sstat_changed(Ref<Stat> stat);
void refresh();
EntityResourceHealth();
~EntityResourceHealth();
protected:
static void _bind_methods();
private:
int stamina_stat_id;
int health_stat_id;
};
#endif

View File

@ -0,0 +1,66 @@
/*
Copyright (c) 2019-2020 Péter Magyar
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
#include "entity_resource_speed.h"
#include "../../database/ess_resource_db.h"
#include "../../singletons/ess.h"
#include "../entity.h"
#include "../stats/stat.h"
#include "entity_resource_data.h"
void EntityResourceSpeed::_init() {
set_current_value(base_value);
speed_stat_id = 0;
if (ESS::get_instance()->stat_is_property("Speed"))
speed_stat_id = ESS::get_instance()->stat_get_id("Speed");
}
void EntityResourceSpeed::_ons_added(Node *entity) {
refresh();
}
void EntityResourceSpeed::_notification_sstat_changed(Ref<Stat> stat) {
if (stat->get_id() == speed_stat_id)
refresh();
}
void EntityResourceSpeed::refresh() {
Ref<Stat> speed_stat = get_owner()->get_stat(speed_stat_id);
set_max_value(base_value + speed_stat->gets_current() * 0.01);
set_current_value(base_value + speed_stat->gets_current() * 0.01);
}
EntityResourceSpeed::EntityResourceSpeed() {
speed_stat_id = 0;
base_value = 100;
}
EntityResourceSpeed::~EntityResourceSpeed() {
}
void EntityResourceSpeed::_bind_methods() {
ClassDB::bind_method(D_METHOD("_init"), &EntityResourceSpeed::_init);
ClassDB::bind_method(D_METHOD("_ons_added", "entity"), &EntityResourceSpeed::_ons_added);
ClassDB::bind_method(D_METHOD("_notification_sstat_changed", "stat"), &EntityResourceSpeed::_notification_sstat_changed);
ClassDB::bind_method(D_METHOD("refresh"), &EntityResourceSpeed::refresh);
}

View File

@ -0,0 +1,52 @@
/*
Copyright (c) 2019-2020 Péter Magyar
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
#ifndef ENTITY_RESOURCE_SPEED_H
#define ENTITY_RESOURCE_SPEED_H
#include "entity_resource.h"
class Stat;
class Entity;
class EntityResourceData;
class EntityResourceSpeed : public EntityResource {
GDCLASS(EntityResourceSpeed, EntityResource);
public:
void _init();
void _ons_added(Node *entity);
void _notification_sstat_changed(Ref<Stat> stat);
void refresh();
EntityResourceSpeed();
~EntityResourceSpeed();
protected:
static void _bind_methods();
private:
int speed_stat_id;
int base_value;
};
#endif

View File

@ -86,7 +86,11 @@ SOFTWARE.
#include "entities/resources/entity_resource.h" #include "entities/resources/entity_resource.h"
#include "entities/resources/entity_resource_cost_data.h" #include "entities/resources/entity_resource_cost_data.h"
#include "entities/resources/entity_resource_cost_data_health.h"
#include "entities/resources/entity_resource_cost_data_resource.h"
#include "entities/resources/entity_resource_data.h" #include "entities/resources/entity_resource_data.h"
#include "entities/resources/entity_resource_health.h"
#include "entities/resources/entity_resource_speed.h"
#include "entities/auras/aura_data.h" #include "entities/auras/aura_data.h"
#include "entities/entity.h" #include "entities/entity.h"
@ -212,7 +216,11 @@ void register_entity_spell_system_types() {
ClassDB::register_class<EntityResourceData>(); ClassDB::register_class<EntityResourceData>();
ClassDB::register_class<EntityResourceCostData>(); ClassDB::register_class<EntityResourceCostData>();
ClassDB::register_class<EntityResourceCostDataHealth>();
ClassDB::register_class<EntityResourceCostDataResource>();
ClassDB::register_class<EntityResource>(); ClassDB::register_class<EntityResource>();
ClassDB::register_class<EntityResourceHealth>();
ClassDB::register_class<EntityResourceSpeed>();
ClassDB::register_class<AuraTriggerData>(); ClassDB::register_class<AuraTriggerData>();