mirror of
https://github.com/Relintai/entity_spell_system.git
synced 2025-02-20 17:14:44 +01:00
Merged Stat into Entity.
This commit is contained in:
parent
65f0d3e7b3
commit
b97bf3a767
1
SCsub
1
SCsub
@ -60,7 +60,6 @@ sources = [
|
||||
|
||||
"skeleton/character_bones.cpp",
|
||||
|
||||
"entities/stats/stat.cpp",
|
||||
"entities/stats/stat_data.cpp",
|
||||
"entities/stats/stat_data_entry.cpp",
|
||||
"entities/stats/level_stat_data.cpp",
|
||||
|
@ -967,13 +967,15 @@ void Aura::_sapply(Ref<AuraApplyInfo> info) {
|
||||
|
||||
setup_aura_data(ad, info);
|
||||
|
||||
Entity *owner = ad->get_owner();
|
||||
|
||||
for (int i = 0; i < _aura_stat_attribute_count; ++i) {
|
||||
Ref<AuraStatAttribute> stat_attribute = _aura_stat_attributes[i];
|
||||
|
||||
Ref<Stat> stat = info->get_target()->get_stat(stat_attribute->get_stat());
|
||||
stat->mod_base(stat_attribute->get_base_mod());
|
||||
stat->mod_bonus(stat_attribute->get_bonus_mod());
|
||||
stat->mod_percent(stat_attribute->get_percent_mod());
|
||||
int stat_index = stat_attribute->get_stat();
|
||||
owner->stat_mod_base(stat_index, stat_attribute->get_base_mod());
|
||||
owner->stat_mod_bonus(stat_index, stat_attribute->get_bonus_mod());
|
||||
owner->stat_mod_percent(stat_index, stat_attribute->get_percent_mod());
|
||||
}
|
||||
|
||||
if (_add_states != 0) {
|
||||
@ -995,13 +997,15 @@ void Aura::_sapply(Ref<AuraApplyInfo> info) {
|
||||
void Aura::_sdeapply(Ref<AuraData> data) {
|
||||
ERR_FAIL_COND(data->get_owner() == NULL || data->get_caster() == NULL || !data->get_aura().is_valid());
|
||||
|
||||
Entity *owner = data->get_owner();
|
||||
|
||||
for (int i = 0; i < _aura_stat_attribute_count; ++i) {
|
||||
Ref<AuraStatAttribute> stat_attribute = _aura_stat_attributes[i];
|
||||
|
||||
Ref<Stat> stat = data->get_owner()->get_stat(stat_attribute->get_stat());
|
||||
stat->mod_base(-stat_attribute->get_base_mod());
|
||||
stat->mod_bonus(-stat_attribute->get_bonus_mod());
|
||||
stat->mod_percent(-stat_attribute->get_percent_mod());
|
||||
int stat_index = stat_attribute->get_stat();
|
||||
owner->stat_mod_base(stat_index, -stat_attribute->get_base_mod());
|
||||
owner->stat_mod_bonus(stat_index, -stat_attribute->get_bonus_mod());
|
||||
owner->stat_mod_percent(stat_index, -stat_attribute->get_percent_mod());
|
||||
}
|
||||
|
||||
if (_add_states != 0) {
|
||||
|
@ -33,7 +33,6 @@ SOFTWARE.
|
||||
#include "../../spell_enums.h"
|
||||
|
||||
#include "../../entities/entity.h"
|
||||
#include "../../entities/stats/stat.h"
|
||||
#include "../../infos/aura_infos.h"
|
||||
|
||||
#include "aura_stat_attribute.h"
|
||||
|
@ -23,7 +23,6 @@ SOFTWARE.
|
||||
#ifndef AURA_STAT_ATTRIBUTE_H
|
||||
#define AURA_STAT_ATTRIBUTE_H
|
||||
|
||||
#include "../../entities/stats/stat.h"
|
||||
#include "core/reference.h"
|
||||
|
||||
#include "../../singletons/ess.h"
|
||||
|
@ -26,7 +26,6 @@ SOFTWARE.
|
||||
#include "core/reference.h"
|
||||
#include "core/vector.h"
|
||||
|
||||
#include "../../entities/stats/stat.h"
|
||||
#include "../../item_enums.h"
|
||||
#include "item_stat_modifier.h"
|
||||
|
||||
|
@ -23,7 +23,6 @@ SOFTWARE.
|
||||
#ifndef ITEM_STAT_MODIFIER_H
|
||||
#define ITEM_STAT_MODIFIER_H
|
||||
|
||||
#include "../../entities/stats/stat.h"
|
||||
#include "core/reference.h"
|
||||
|
||||
#include "core/version.h"
|
||||
|
@ -27,7 +27,6 @@ SOFTWARE.
|
||||
#include "core/vector.h"
|
||||
#include "scene/resources/texture.h"
|
||||
|
||||
#include "../../entities/stats/stat.h"
|
||||
#include "../../item_enums.h"
|
||||
#include "item_template_stat_modifier.h"
|
||||
#include "item_visual.h"
|
||||
|
@ -23,7 +23,6 @@ SOFTWARE.
|
||||
#ifndef ITEM_TEMPLATE_STAT_MODIFIER_H
|
||||
#define ITEM_TEMPLATE_STAT_MODIFIER_H
|
||||
|
||||
#include "../../entities/stats/stat.h"
|
||||
#include "core/reference.h"
|
||||
|
||||
#include "core/version.h"
|
||||
|
@ -749,10 +749,9 @@ void Spell::handle_gcd(Ref<SpellCastInfo> info) {
|
||||
ERR_FAIL_COND(!info.is_valid());
|
||||
|
||||
if (_global_cooldown_enabled && _cast_time_enabled) {
|
||||
Ref<Stat> gcd = info->get_caster()->get_stat(ESS::get_instance()->stat_get_id("Global Cooldown"));
|
||||
float gcd = info->get_caster()->stat_gets_current(ESS::get_instance()->stat_get_id("Global Cooldown"));
|
||||
|
||||
if (gcd.is_valid())
|
||||
info->get_caster()->gcd_starts(gcd->gets_current());
|
||||
info->get_caster()->gcd_starts(gcd);
|
||||
}
|
||||
}
|
||||
void Spell::handle_cooldown(Ref<SpellCastInfo> info) {
|
||||
|
@ -32,7 +32,6 @@ SOFTWARE.
|
||||
#include "../../infos/spell_cast_info.h"
|
||||
|
||||
#include "../../entities/entity.h"
|
||||
#include "../../entities/stats/stat.h"
|
||||
|
||||
#include "../../infos/aura_infos.h"
|
||||
|
||||
|
@ -39,7 +39,6 @@ SOFTWARE.
|
||||
#include "./resources/entity_resource_health.h"
|
||||
#include "./resources/entity_resource_speed.h"
|
||||
#include "./skills/entity_skill.h"
|
||||
#include "./stats/stat.h"
|
||||
#include "scene/2d/node_2d.h"
|
||||
#include "scene/3d/spatial.h"
|
||||
|
||||
@ -641,14 +640,12 @@ void Entity::_setup() {
|
||||
ERR_FAIL_COND(!cc.is_valid());
|
||||
|
||||
for (int i = 0; i < ESS::get_instance()->stat_get_count(); ++i) {
|
||||
_s_entity_data->get_stat_data()->get_stat_for_stat(_stats[i]);
|
||||
stat_set_base(i, _s_entity_data->get_stat_data()->get_stat_for_stat(i));
|
||||
}
|
||||
|
||||
for (int i = 0; i < ESS::get_instance()->stat_get_count(); ++i) {
|
||||
Ref<Stat> s = _stats[i];
|
||||
|
||||
s->setc_current(s->gets_current());
|
||||
s->set_dirty(false);
|
||||
stat_setc_current(i, stat_gets_current(i));
|
||||
stat_set_dirty(i, false);
|
||||
}
|
||||
|
||||
for (int i = 0; i < cc->get_num_auras(); ++i) {
|
||||
@ -1100,9 +1097,15 @@ Dictionary Entity::_to_dict() {
|
||||
Dictionary sd;
|
||||
|
||||
for (int i = 0; i < ESS::get_instance()->stat_get_count(); ++i) {
|
||||
Ref<Stat> s = _stats[i];
|
||||
Dictionary sdict;
|
||||
|
||||
sd[i] = s->to_dict();
|
||||
sdict["base"] = stat_get_base(i);
|
||||
sdict["base_calculated"] = stat_get_base_calculated(i);
|
||||
sdict["bonus"] = stat_get_bonus(i);
|
||||
sdict["percent"] = stat_get_percent(i);
|
||||
sdict["current"] = stat_gets_current(i);
|
||||
|
||||
sd[i] = sdict;
|
||||
}
|
||||
|
||||
dict["stats"] = sd;
|
||||
@ -1280,9 +1283,18 @@ void Entity::_from_dict(const Dictionary &dict) {
|
||||
Dictionary stats = dict.get("stats", Dictionary());
|
||||
|
||||
for (int i = 0; i < ESS::get_instance()->stat_get_count(); ++i) {
|
||||
Ref<Stat> s = _stats[i];
|
||||
Dictionary sd = stats.get(String::num(i), Dictionary());
|
||||
|
||||
s->from_dict(stats.get(String::num(i), Dictionary()));
|
||||
stat_set_base(i, sd.get("base", 0));
|
||||
stat_set_base_calculated(i, sd.get("base_calculated", 0));
|
||||
stat_set_bonus(i, sd.get("bonus", 0));
|
||||
stat_set_percent(i, sd.get("percent", 1));
|
||||
|
||||
float curr = sd.get("current", 0);
|
||||
stat_sets_current(i, curr);
|
||||
stat_setc_current(i, curr);
|
||||
|
||||
stat_set_dirty(i, true);
|
||||
}
|
||||
|
||||
//// Equipment ////
|
||||
@ -1824,18 +1836,94 @@ int Entity::craft_getc_recipe_count() {
|
||||
|
||||
//// Stat System ////
|
||||
|
||||
Ref<Stat> Entity::get_stat(int index) {
|
||||
ERR_FAIL_INDEX_V(index, ESS::get_instance()->stat_get_count(), Ref<Stat>());
|
||||
EntityStat Entity::get_stat(const int index) const {
|
||||
ERR_FAIL_INDEX_V(index, ESS::get_instance()->stat_get_count(), EntityStat());
|
||||
|
||||
return _stats[index];
|
||||
}
|
||||
|
||||
void Entity::set_stat(int index, Ref<Stat> entry) {
|
||||
void Entity::set_stat(const int index, const EntityStat &entry) {
|
||||
ERR_FAIL_INDEX(index, ESS::get_instance()->stat_get_count());
|
||||
|
||||
_stats.set(index, entry);
|
||||
}
|
||||
|
||||
bool Entity::stat_get_dirty(const int index) const {
|
||||
ERR_FAIL_INDEX_V(index, ESS::get_instance()->stat_get_count(), false);
|
||||
|
||||
return _stats[index].dirty;
|
||||
}
|
||||
void Entity::stat_set_dirty(const int index, const bool value) {
|
||||
ERR_FAIL_INDEX(index, ESS::get_instance()->stat_get_count());
|
||||
}
|
||||
|
||||
float Entity::stat_get_base(const int index) const {
|
||||
ERR_FAIL_INDEX_V(index, ESS::get_instance()->stat_get_count(), 0);
|
||||
|
||||
return _stats[index].base;
|
||||
}
|
||||
void Entity::stat_set_base(const int index, const float value) {
|
||||
ERR_FAIL_INDEX(index, ESS::get_instance()->stat_get_count());
|
||||
}
|
||||
void Entity::stat_mod_base(const int index, const float value) {
|
||||
ERR_FAIL_INDEX(index, ESS::get_instance()->stat_get_count());
|
||||
}
|
||||
|
||||
float Entity::stat_get_base_calculated(const int index) const {
|
||||
ERR_FAIL_INDEX_V(index, ESS::get_instance()->stat_get_count(), 0);
|
||||
|
||||
return _stats[index].base_calculated;
|
||||
}
|
||||
void Entity::stat_set_base_calculated(const int index, const float value) {
|
||||
ERR_FAIL_INDEX(index, ESS::get_instance()->stat_get_count());
|
||||
}
|
||||
|
||||
float Entity::stat_get_bonus(const int index) const {
|
||||
ERR_FAIL_INDEX_V(index, ESS::get_instance()->stat_get_count(), 0);
|
||||
|
||||
return _stats[index].bonus;
|
||||
}
|
||||
void Entity::stat_set_bonus(const int index, const float value) {
|
||||
ERR_FAIL_INDEX(index, ESS::get_instance()->stat_get_count());
|
||||
}
|
||||
void Entity::stat_mod_bonus(const int index, const float value) {
|
||||
ERR_FAIL_INDEX(index, ESS::get_instance()->stat_get_count());
|
||||
}
|
||||
|
||||
float Entity::stat_get_percent(const int index) const {
|
||||
ERR_FAIL_INDEX_V(index, ESS::get_instance()->stat_get_count(), 0);
|
||||
|
||||
return _stats[index].percent;
|
||||
}
|
||||
void Entity::stat_set_percent(const int index, const float value) {
|
||||
ERR_FAIL_INDEX(index, ESS::get_instance()->stat_get_count());
|
||||
}
|
||||
void Entity::stat_mod_percent(const int index, const float value) {
|
||||
ERR_FAIL_INDEX(index, ESS::get_instance()->stat_get_count());
|
||||
}
|
||||
|
||||
float Entity::stat_gets_current(const int index) const {
|
||||
ERR_FAIL_INDEX_V(index, ESS::get_instance()->stat_get_count(), 0);
|
||||
|
||||
return _stats[index].scurrent;
|
||||
}
|
||||
void Entity::stat_sets_current(const int index, const float value) {
|
||||
ERR_FAIL_INDEX(index, ESS::get_instance()->stat_get_count());
|
||||
}
|
||||
|
||||
float Entity::stat_getc_current(const int index) const {
|
||||
ERR_FAIL_INDEX_V(index, ESS::get_instance()->stat_get_count(), 0);
|
||||
|
||||
return _stats[index].ccurrent;
|
||||
}
|
||||
void Entity::stat_setc_current(const int index, const float value) {
|
||||
ERR_FAIL_INDEX(index, ESS::get_instance()->stat_get_count());
|
||||
}
|
||||
|
||||
void Entity::stat_recalculate(const int index) {
|
||||
ERR_FAIL_INDEX(index, ESS::get_instance()->stat_get_count());
|
||||
}
|
||||
|
||||
void Entity::dies() {
|
||||
//serverside
|
||||
|
||||
@ -1854,14 +1942,14 @@ void Entity::diec() {
|
||||
emit_signal("diecd", this);
|
||||
}
|
||||
|
||||
void Entity::notification_sstat_changed(Ref<Stat> stat) {
|
||||
void Entity::notification_sstat_changed(const int statid, const float current) {
|
||||
for (int i = 0; i < _s_resources.size(); ++i) {
|
||||
_s_resources.get(i)->notification_sstat_changed(stat);
|
||||
_s_resources.get(i)->notification_sstat_changed(statid, current);
|
||||
}
|
||||
}
|
||||
void Entity::notification_cstat_changed(Ref<Stat> stat) {
|
||||
void Entity::notification_cstat_changed(const int statid, const float current) {
|
||||
for (int i = 0; i < _c_resources.size(); ++i) {
|
||||
_c_resources.get(i)->notification_cstat_changed(stat);
|
||||
_c_resources.get(i)->notification_cstat_changed(statid, current);
|
||||
}
|
||||
}
|
||||
|
||||
@ -1875,7 +1963,7 @@ void Entity::ssend_stat(int id, int ccurrent) {
|
||||
void Entity::creceive_stat(int id, int ccurrent) {
|
||||
ERR_FAIL_INDEX(id, ESS::get_instance()->stat_get_count());
|
||||
|
||||
_stats.get(id)->setc_current(ccurrent);
|
||||
stat_setc_current(id, ccurrent);
|
||||
}
|
||||
|
||||
//// Equip Slots ////
|
||||
@ -1901,7 +1989,6 @@ bool Entity::equip_should_deny(ItemEnums::EquipSlots equip_slot, Ref<ItemInstanc
|
||||
}
|
||||
|
||||
void Entity::equip_son_success(ItemEnums::EquipSlots equip_slot, Ref<ItemInstance> item, Ref<ItemInstance> old_item, int bag_slot) {
|
||||
|
||||
if (_s_entity_data.is_valid()) {
|
||||
_s_entity_data->equip_son_success(this, equip_slot, item, old_item, bag_slot);
|
||||
}
|
||||
@ -1919,7 +2006,6 @@ void Entity::equip_son_success(ItemEnums::EquipSlots equip_slot, Ref<ItemInstanc
|
||||
}
|
||||
|
||||
void Entity::equip_son_fail(ItemEnums::EquipSlots equip_slot, Ref<ItemInstance> item, Ref<ItemInstance> old_item, int bag_slot) {
|
||||
|
||||
if (_s_entity_data.is_valid()) {
|
||||
_s_entity_data->equip_son_fail(this, equip_slot, item, old_item, bag_slot);
|
||||
}
|
||||
@ -1937,7 +2023,6 @@ void Entity::equip_son_fail(ItemEnums::EquipSlots equip_slot, Ref<ItemInstance>
|
||||
}
|
||||
|
||||
void Entity::equip_con_success(ItemEnums::EquipSlots equip_slot, Ref<ItemInstance> item, Ref<ItemInstance> old_item, int bag_slot) {
|
||||
|
||||
if (_c_entity_data.is_valid()) {
|
||||
_c_entity_data->equip_con_success(this, equip_slot, item, old_item, bag_slot);
|
||||
}
|
||||
@ -1955,7 +2040,6 @@ void Entity::equip_con_success(ItemEnums::EquipSlots equip_slot, Ref<ItemInstanc
|
||||
}
|
||||
|
||||
void Entity::equip_con_fail(ItemEnums::EquipSlots equip_slot, Ref<ItemInstance> item, Ref<ItemInstance> old_item, int bag_slot) {
|
||||
|
||||
if (_c_entity_data.is_valid()) {
|
||||
_c_entity_data->equip_con_fail(this, equip_slot, item, old_item, bag_slot);
|
||||
}
|
||||
@ -2094,13 +2178,11 @@ void Entity::_equip_applys_item(Ref<ItemInstance> item) {
|
||||
if (!mod.is_valid())
|
||||
continue;
|
||||
|
||||
Ref<Stat> stat = get_stat(mod->get_stat_id());
|
||||
int sid = mod->get_stat_id();
|
||||
|
||||
ERR_CONTINUE(!stat.is_valid());
|
||||
|
||||
stat->mod_base(mod->get_base_mod());
|
||||
stat->mod_bonus(mod->get_bonus_mod());
|
||||
stat->mod_percent(mod->get_percent_mod());
|
||||
stat_mod_base(sid, mod->get_base_mod());
|
||||
stat_mod_bonus(sid, mod->get_bonus_mod());
|
||||
stat_mod_percent(sid, mod->get_percent_mod());
|
||||
}
|
||||
}
|
||||
void Entity::_equip_deapplys_item(Ref<ItemInstance> item) {
|
||||
@ -2116,13 +2198,11 @@ void Entity::_equip_deapplys_item(Ref<ItemInstance> item) {
|
||||
if (!mod.is_valid())
|
||||
continue;
|
||||
|
||||
Ref<Stat> stat = get_stat(mod->get_stat_id());
|
||||
int sid = mod->get_stat_id();
|
||||
|
||||
ERR_CONTINUE(!stat.is_valid());
|
||||
|
||||
stat->mod_base(-mod->get_base_mod());
|
||||
stat->mod_bonus(-mod->get_bonus_mod());
|
||||
stat->mod_percent(-mod->get_percent_mod());
|
||||
stat_mod_base(sid, -mod->get_base_mod());
|
||||
stat_mod_bonus(sid, -mod->get_bonus_mod());
|
||||
stat_mod_percent(sid, -mod->get_percent_mod());
|
||||
}
|
||||
}
|
||||
|
||||
@ -3770,7 +3850,6 @@ void Entity::cast_failc() {
|
||||
}
|
||||
|
||||
void Entity::cast_delayc() {
|
||||
|
||||
//c_on_cast_
|
||||
|
||||
notification_scast(SpellEnums::NOTIFICATION_CAST_DELAYED, _c_spell_cast_info);
|
||||
@ -4782,7 +4861,6 @@ void Entity::_talent_sreceive_reset_request() {
|
||||
}
|
||||
|
||||
void Entity::talent_sreset() {
|
||||
|
||||
_s_talents.clear();
|
||||
|
||||
if (has_method("_son_talent_reset"))
|
||||
@ -5322,12 +5400,10 @@ void Entity::update(float delta) {
|
||||
}
|
||||
|
||||
for (int i = 0; i < ESS::get_instance()->stat_get_count(); ++i) {
|
||||
Ref<Stat> s = _stats[i];
|
||||
if (stat_get_dirty(i)) {
|
||||
ssend_stat(i, stat_gets_current(i));
|
||||
|
||||
if (s->get_dirty()) {
|
||||
ssend_stat(s->get_id(), s->gets_current());
|
||||
|
||||
s->set_dirty(false);
|
||||
stat_set_dirty(i, false);
|
||||
}
|
||||
}
|
||||
|
||||
@ -5491,7 +5567,6 @@ int Entity::seen_by_gets_count() {
|
||||
}
|
||||
|
||||
void Entity::vrpc(const StringName &p_method, VARIANT_ARG_DECLARE) {
|
||||
|
||||
VARIANT_ARGPTRS;
|
||||
|
||||
int argc = 0;
|
||||
@ -5530,7 +5605,6 @@ Variant Entity::_vrpc_bind(const Variant **p_args, int p_argcount, Variant::Call
|
||||
#else
|
||||
Variant Entity::_vrpc_bind(const Variant **p_args, int p_argcount, Callable::CallError &r_error) {
|
||||
#endif
|
||||
|
||||
if (p_argcount < 1) {
|
||||
#if VERSION_MAJOR < 4
|
||||
r_error.error = Variant::CallError::CALL_ERROR_TOO_FEW_ARGUMENTS;
|
||||
@ -5694,11 +5768,6 @@ Entity::Entity() {
|
||||
_actionbar_locked = false;
|
||||
|
||||
_stats.resize(ESS::get_instance()->stat_get_count());
|
||||
for (int i = 0; i < _stats.size(); ++i) {
|
||||
Ref<Stat> s = Ref<Stat>(memnew(Stat(i, this)));
|
||||
|
||||
_stats.set(i, s);
|
||||
}
|
||||
|
||||
_sai_state = EntityEnums::AI_STATE_OFF;
|
||||
_sai_state_stored = EntityEnums::AI_STATE_OFF;
|
||||
@ -6037,9 +6106,7 @@ void Entity::_notification_scharacter_level_up(int level) {
|
||||
for (int i = 0; i < ESS::get_instance()->stat_get_main_stat_count(); ++i) {
|
||||
int st = gets_entity_data()->get_stat_data()->get_level_stat_data()->get_stat_diff(i, gets_character_level() - level, gets_character_level());
|
||||
|
||||
Ref<Stat> stat = get_stat(i);
|
||||
|
||||
stat->mod_base(st);
|
||||
stat_mod_base(i, st);
|
||||
}
|
||||
|
||||
if (!ESS::get_instance()->get_use_class_xp()) {
|
||||
@ -6094,7 +6161,6 @@ void Entity::_con_target_changed(Node *p_entity, Node *p_old_target) {
|
||||
}
|
||||
|
||||
void Entity::_notification_sdeath() {
|
||||
|
||||
//only if mob
|
||||
/*
|
||||
if dead:
|
||||
@ -6246,28 +6312,20 @@ bool Entity::_set(const StringName &p_name, const Variant &p_value) {
|
||||
int stat_id = name.get_slicec('/', 1).to_int();
|
||||
String stat_prop_name = name.get_slicec('/', 2);
|
||||
|
||||
Ref<Stat> stat = _stats[stat_id];
|
||||
|
||||
if (!stat.is_valid()) {
|
||||
stat.instance();
|
||||
stat->set_owner(this);
|
||||
_stats.set(stat_id, stat);
|
||||
}
|
||||
|
||||
if (stat_prop_name == "base") {
|
||||
stat->set_base(p_value);
|
||||
stat_set_base(stat_id, p_value);
|
||||
|
||||
return true;
|
||||
} else if (stat_prop_name == "bonus") {
|
||||
stat->set_bonus(p_value);
|
||||
stat_set_bonus(stat_id, p_value);
|
||||
|
||||
return true;
|
||||
} else if (stat_prop_name == "percent") {
|
||||
stat->set_percent(p_value);
|
||||
stat_set_percent(stat_id, p_value);
|
||||
|
||||
return true;
|
||||
} else if (stat_prop_name == "scurrent") {
|
||||
stat->sets_current(p_value);
|
||||
stat_sets_current(stat_id, p_value);
|
||||
|
||||
return true;
|
||||
} else {
|
||||
@ -6543,22 +6601,20 @@ bool Entity::_get(const StringName &p_name, Variant &r_ret) const {
|
||||
int stat_id = name.get_slicec('/', 1).to_int();
|
||||
String stat_prop_name = name.get_slicec('/', 2);
|
||||
|
||||
Ref<Stat> stat = _stats[stat_id];
|
||||
|
||||
if (stat_prop_name == "base") {
|
||||
r_ret = stat->get_base();
|
||||
r_ret = stat_get_base(stat_id);
|
||||
|
||||
return true;
|
||||
} else if (stat_prop_name == "bonus") {
|
||||
r_ret = stat->get_bonus();
|
||||
r_ret = stat_get_bonus(stat_id);
|
||||
|
||||
return true;
|
||||
} else if (stat_prop_name == "percent") {
|
||||
r_ret = stat->get_percent();
|
||||
r_ret = stat_get_percent(stat_id);
|
||||
|
||||
return true;
|
||||
} else if (stat_prop_name == "scurrent") {
|
||||
r_ret = stat->gets_current();
|
||||
r_ret = stat_gets_current(stat_id);
|
||||
|
||||
return true;
|
||||
} else {
|
||||
@ -6722,11 +6778,6 @@ void Entity::_get_property_list(List<PropertyInfo> *p_list) const {
|
||||
int property_usange = PROPERTY_USAGE_DEFAULT;
|
||||
|
||||
for (int i = 0; i < ESS::get_instance()->stat_get_count(); ++i) {
|
||||
Ref<Stat> stat = _stats[i];
|
||||
|
||||
if (!stat.is_valid())
|
||||
continue;
|
||||
|
||||
p_list->push_back(PropertyInfo(Variant::REAL, "stat/" + itos(i) + "/base", PROPERTY_HINT_NONE, "", property_usange));
|
||||
p_list->push_back(PropertyInfo(Variant::REAL, "stat/" + itos(i) + "/percent", PROPERTY_HINT_NONE, "", property_usange));
|
||||
p_list->push_back(PropertyInfo(Variant::REAL, "stat/" + itos(i) + "/scurrent", PROPERTY_HINT_NONE, "", property_usange));
|
||||
@ -7213,9 +7264,6 @@ void Entity::_bind_methods() {
|
||||
ClassDB::bind_method(D_METHOD("setc_entity_data", "value"), &Entity::setc_entity_data);
|
||||
ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "centity_data", PROPERTY_HINT_RESOURCE_TYPE, "EntityData", 0), "setc_entity_data", "getc_entity_data");
|
||||
|
||||
ClassDB::bind_method(D_METHOD("get_stat", "index"), &Entity::get_stat);
|
||||
ClassDB::bind_method(D_METHOD("set_stat", "index", "entry"), &Entity::set_stat);
|
||||
|
||||
//todo
|
||||
//for (int i = 0; i < ESS::get_instance()->stat_get_count(); ++i) {
|
||||
// ADD_PROPERTYI(PropertyInfo(Variant::OBJECT, "stats/" + itos(i), PROPERTY_HINT_RESOURCE_TYPE, "Stat"), "set_stat_int", "get_stat_int", i);
|
||||
|
@ -42,7 +42,6 @@ SOFTWARE.
|
||||
|
||||
#include "../data/spells/spell.h"
|
||||
#include "./resources/entity_resource.h"
|
||||
#include "stats/stat.h"
|
||||
|
||||
#include "../entity_enums.h"
|
||||
#include "../utility/entity_create_info.h"
|
||||
@ -98,6 +97,30 @@ enum PlayerSendFlags {
|
||||
SEND_FLAG_AURAS,
|
||||
};
|
||||
|
||||
struct EntityStat {
|
||||
bool dirty;
|
||||
|
||||
float base;
|
||||
float base_calculated;
|
||||
float bonus;
|
||||
float percent;
|
||||
|
||||
float scurrent;
|
||||
float ccurrent;
|
||||
|
||||
EntityStat() {
|
||||
dirty = false;
|
||||
|
||||
base = 0;
|
||||
base_calculated = 0;
|
||||
bonus = 0;
|
||||
percent = 0;
|
||||
|
||||
scurrent = 0;
|
||||
ccurrent = 0;
|
||||
}
|
||||
};
|
||||
|
||||
#define ISSERVER() (is_inside_tree() && (!get_tree()->has_network_peer() || (get_tree()->has_network_peer() && get_tree()->is_network_server())))
|
||||
#define ISCLIENT() (is_inside_tree() && get_tree()->has_network_peer() && !get_tree()->is_network_server())
|
||||
|
||||
@ -339,18 +362,44 @@ public:
|
||||
void setc_seed(int value);
|
||||
|
||||
//// Stats ////
|
||||
Ref<Stat> get_stat(int index);
|
||||
void set_stat(int index, Ref<Stat> entry);
|
||||
EntityStat get_stat(const int index) const;
|
||||
void set_stat(const int index, const EntityStat &entry);
|
||||
|
||||
void dies();
|
||||
void diec();
|
||||
bool stat_get_dirty(const int index) const;
|
||||
void stat_set_dirty(const int index, const bool value);
|
||||
|
||||
void notification_sstat_changed(Ref<Stat> stat);
|
||||
void notification_cstat_changed(Ref<Stat> stat);
|
||||
float stat_get_base(const int index) const;
|
||||
void stat_set_base(const int index, const float value);
|
||||
void stat_mod_base(const int index, const float value);
|
||||
|
||||
float stat_get_base_calculated(const int index) const;
|
||||
void stat_set_base_calculated(const int index, const float value);
|
||||
|
||||
float stat_get_bonus(const int index) const;
|
||||
void stat_set_bonus(const int index, const float value);
|
||||
void stat_mod_bonus(const int index, const float value);
|
||||
|
||||
float stat_get_percent(const int index) const;
|
||||
void stat_set_percent(const int index, const float value);
|
||||
void stat_mod_percent(const int index, const float value);
|
||||
|
||||
float stat_gets_current(const int index) const;
|
||||
void stat_sets_current(const int index, const float value);
|
||||
|
||||
float stat_getc_current(const int index) const;
|
||||
void stat_setc_current(const int index, const float value);
|
||||
|
||||
void stat_recalculate(const int index);
|
||||
|
||||
void notification_sstat_changed(const int statid, const float current);
|
||||
void notification_cstat_changed(const int statid, const float current);
|
||||
|
||||
void ssend_stat(int id, int ccurrent);
|
||||
void creceive_stat(int id, int ccurrent);
|
||||
|
||||
void dies();
|
||||
void diec();
|
||||
|
||||
//// Equip Slots ////
|
||||
|
||||
bool equip_should_deny(ItemEnums::EquipSlots equip_slot, Ref<ItemInstance> item);
|
||||
@ -1066,7 +1115,7 @@ private:
|
||||
|
||||
//// Stats ////
|
||||
|
||||
Vector<Ref<Stat> > _stats;
|
||||
Vector<EntityStat> _stats;
|
||||
|
||||
//// Equipment ////
|
||||
|
||||
|
@ -25,7 +25,6 @@ SOFTWARE.
|
||||
#include "../../database/ess_resource_db.h"
|
||||
#include "../../singletons/ess.h"
|
||||
#include "../entity.h"
|
||||
#include "../stats/stat.h"
|
||||
#include "entity_resource_data.h"
|
||||
|
||||
bool EntityResource::get_dirty() const {
|
||||
@ -123,13 +122,13 @@ void EntityResource::onc_added(Entity *owner) {
|
||||
call("_onc_added", owner);
|
||||
}
|
||||
|
||||
void EntityResource::notification_sstat_changed(Ref<Stat> stat) {
|
||||
void EntityResource::notification_sstat_changed(const int statid, const float current) {
|
||||
if (has_method("_notification_sstat_changed"))
|
||||
call("_notification_sstat_changed", stat);
|
||||
call("_notification_sstat_changed", statid, current);
|
||||
}
|
||||
void EntityResource::notification_cstat_changed(Ref<Stat> stat) {
|
||||
void EntityResource::notification_cstat_changed(const int statid, const float current) {
|
||||
if (has_method("_notification_cstat_changed"))
|
||||
call("_notification_cstat_changed", stat);
|
||||
call("_notification_cstat_changed", statid, current);
|
||||
}
|
||||
|
||||
void EntityResource::ons_target_changed(Entity *entity, Entity *old_target) {
|
||||
@ -249,8 +248,8 @@ void EntityResource::_bind_methods() {
|
||||
ClassDB::bind_method(D_METHOD("set_owner", "value"), &EntityResource::set_owner_bind);
|
||||
ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "owner", PROPERTY_HINT_RESOURCE_TYPE, "Entity", 0), "set_owner", "get_owner");
|
||||
|
||||
BIND_VMETHOD(MethodInfo("_notification_sstat_changed", PropertyInfo(Variant::OBJECT, "stat", PROPERTY_HINT_RESOURCE_TYPE, "Stat")));
|
||||
BIND_VMETHOD(MethodInfo("_notification_cstat_changed", PropertyInfo(Variant::OBJECT, "stat", PROPERTY_HINT_RESOURCE_TYPE, "Stat")));
|
||||
BIND_VMETHOD(MethodInfo("_notification_sstat_changed", PropertyInfo(Variant::INT, "statid"), PropertyInfo(Variant::REAL, "curent")));
|
||||
BIND_VMETHOD(MethodInfo("_notification_cstat_changed", PropertyInfo(Variant::INT, "statid"), PropertyInfo(Variant::REAL, "curent")));
|
||||
|
||||
BIND_VMETHOD(MethodInfo("_ons_target_changed", PropertyInfo(Variant::OBJECT, "entity", PROPERTY_HINT_RESOURCE_TYPE, "Entity"), PropertyInfo(Variant::OBJECT, "old_target", PROPERTY_HINT_RESOURCE_TYPE, "Entity")));
|
||||
BIND_VMETHOD(MethodInfo("_onc_target_changed", PropertyInfo(Variant::OBJECT, "entity", PROPERTY_HINT_RESOURCE_TYPE, "Entity"), PropertyInfo(Variant::OBJECT, "old_target", PROPERTY_HINT_RESOURCE_TYPE, "Entity")));
|
||||
|
@ -25,7 +25,6 @@ SOFTWARE.
|
||||
|
||||
#include "core/reference.h"
|
||||
|
||||
class Stat;
|
||||
class Entity;
|
||||
class EntityResourceData;
|
||||
|
||||
@ -58,8 +57,8 @@ public:
|
||||
void ons_added(Entity *owner);
|
||||
void onc_added(Entity *owner);
|
||||
|
||||
void notification_sstat_changed(Ref<Stat> stat);
|
||||
void notification_cstat_changed(Ref<Stat> stat);
|
||||
void notification_sstat_changed(const int statid, const float current);
|
||||
void notification_cstat_changed(const int statid, const float current);
|
||||
|
||||
void ons_target_changed(Entity *entity, Entity *old_target);
|
||||
void onc_target_changed(Entity *entity, Entity *old_target);
|
||||
|
@ -25,7 +25,6 @@ SOFTWARE.
|
||||
#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() {
|
||||
@ -44,24 +43,17 @@ void EntityResourceHealth::_init() {
|
||||
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)
|
||||
void EntityResourceHealth::_notification_sstat_changed(int statid, float current) {
|
||||
if (statid == stamina_stat_id || statid == health_stat_id)
|
||||
refresh();
|
||||
}
|
||||
void EntityResourceHealth::refresh() {
|
||||
ERR_FAIL_COND(get_owner() == NULL);
|
||||
|
||||
Ref<Stat> stamina = get_owner()->get_stat(stamina_stat_id);
|
||||
float stamina = get_owner()->stat_gets_current(stamina_stat_id);
|
||||
float health = get_owner()->stat_gets_current(health_stat_id);
|
||||
|
||||
if (!stamina.is_valid())
|
||||
return;
|
||||
|
||||
Ref<Stat> health = get_owner()->get_stat(health_stat_id);
|
||||
|
||||
if (!health.is_valid())
|
||||
return;
|
||||
|
||||
int val = int(stamina->gets_current()) * 10 + int(health->gets_current());
|
||||
int val = int(stamina) * 10 + int(health);
|
||||
|
||||
set_max_value(val);
|
||||
set_current_value(val);
|
||||
@ -81,6 +73,6 @@ 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("_notification_sstat_changed", "statid", "current"), &EntityResourceHealth::_notification_sstat_changed);
|
||||
ClassDB::bind_method(D_METHOD("refresh"), &EntityResourceHealth::refresh);
|
||||
}
|
||||
|
@ -25,7 +25,6 @@ SOFTWARE.
|
||||
|
||||
#include "entity_resource.h"
|
||||
|
||||
class Stat;
|
||||
class Entity;
|
||||
class EntityResourceData;
|
||||
|
||||
@ -35,7 +34,7 @@ class EntityResourceHealth : public EntityResource {
|
||||
public:
|
||||
void _init();
|
||||
void _ons_added(Node *entity);
|
||||
void _notification_sstat_changed(Ref<Stat> stat);
|
||||
void _notification_sstat_changed(int statid, float current);
|
||||
void refresh();
|
||||
|
||||
void resolve_references();
|
||||
|
@ -25,7 +25,6 @@ SOFTWARE.
|
||||
#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() {
|
||||
@ -39,20 +38,17 @@ void EntityResourceSpeed::_init() {
|
||||
void EntityResourceSpeed::_ons_added(Node *entity) {
|
||||
refresh();
|
||||
}
|
||||
void EntityResourceSpeed::_notification_sstat_changed(Ref<Stat> stat) {
|
||||
if (stat->get_id() == speed_stat_id)
|
||||
void EntityResourceSpeed::_notification_sstat_changed(int statid, float current) {
|
||||
if (statid == speed_stat_id)
|
||||
refresh();
|
||||
}
|
||||
void EntityResourceSpeed::refresh() {
|
||||
ERR_FAIL_COND(get_owner() == NULL);
|
||||
|
||||
Ref<Stat> speed_stat = get_owner()->get_stat(speed_stat_id);
|
||||
float speed_stat = get_owner()->stat_gets_current(speed_stat_id);
|
||||
|
||||
if (!speed_stat.is_valid())
|
||||
return;
|
||||
|
||||
set_max_value(base_value + speed_stat->gets_current() * 0.01);
|
||||
set_current_value(base_value + speed_stat->gets_current() * 0.01);
|
||||
set_max_value(base_value + speed_stat * 0.01);
|
||||
set_current_value(base_value + speed_stat * 0.01);
|
||||
}
|
||||
|
||||
void EntityResourceSpeed::resolve_references() {
|
||||
@ -69,6 +65,6 @@ 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("_notification_sstat_changed", "statid", "current"), &EntityResourceSpeed::_notification_sstat_changed);
|
||||
ClassDB::bind_method(D_METHOD("refresh"), &EntityResourceSpeed::refresh);
|
||||
}
|
||||
|
@ -25,7 +25,6 @@ SOFTWARE.
|
||||
|
||||
#include "entity_resource.h"
|
||||
|
||||
class Stat;
|
||||
class Entity;
|
||||
class EntityResourceData;
|
||||
|
||||
@ -35,7 +34,7 @@ class EntityResourceSpeed : public EntityResource {
|
||||
public:
|
||||
void _init();
|
||||
void _ons_added(Node *entity);
|
||||
void _notification_sstat_changed(Ref<Stat> stat);
|
||||
void _notification_sstat_changed(int statid, float current);
|
||||
void refresh();
|
||||
|
||||
void resolve_references();
|
||||
|
@ -25,8 +25,6 @@ SOFTWARE.
|
||||
|
||||
#include "core/resource.h"
|
||||
|
||||
#include "stat.h"
|
||||
|
||||
class LevelStatData : public Resource {
|
||||
GDCLASS(LevelStatData, Resource);
|
||||
|
||||
|
@ -1,210 +0,0 @@
|
||||
/*
|
||||
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 "stat.h"
|
||||
|
||||
#include "../../singletons/ess.h"
|
||||
#include "../entity.h"
|
||||
#include "stat_data_entry.h"
|
||||
|
||||
#include "core/version.h"
|
||||
|
||||
bool Stat::get_dirty() {
|
||||
return _dirty;
|
||||
}
|
||||
void Stat::set_dirty(bool value) {
|
||||
_dirty = value;
|
||||
}
|
||||
|
||||
float Stat::get_base() {
|
||||
return _base;
|
||||
}
|
||||
void Stat::set_base(float value) {
|
||||
_base = value;
|
||||
|
||||
refresh();
|
||||
}
|
||||
void Stat::mod_base(float value) {
|
||||
_base += value;
|
||||
|
||||
refresh();
|
||||
}
|
||||
|
||||
float Stat::get_base_calculated() {
|
||||
return _base_calculated;
|
||||
}
|
||||
void Stat::set_base_calculated(float value) {
|
||||
_base_calculated = value;
|
||||
|
||||
refresh();
|
||||
}
|
||||
|
||||
float Stat::get_bonus() {
|
||||
return _bonus;
|
||||
}
|
||||
void Stat::set_bonus(float value) {
|
||||
_bonus = value;
|
||||
|
||||
refresh();
|
||||
}
|
||||
void Stat::mod_bonus(float value) {
|
||||
_bonus = value;
|
||||
}
|
||||
|
||||
float Stat::get_percent() {
|
||||
return _percent;
|
||||
}
|
||||
void Stat::set_percent(float value) {
|
||||
_percent = value;
|
||||
|
||||
refresh();
|
||||
}
|
||||
void Stat::mod_percent(float value) {
|
||||
_percent = value;
|
||||
}
|
||||
|
||||
float Stat::gets_current() {
|
||||
return _s_current;
|
||||
}
|
||||
void Stat::sets_current(float value) {
|
||||
_s_current = value;
|
||||
}
|
||||
|
||||
float Stat::getc_current() {
|
||||
return _c_current;
|
||||
}
|
||||
void Stat::setc_current(float value) {
|
||||
//ERR_FAIL_COND(_owner == NULL);
|
||||
|
||||
_c_current = value;
|
||||
|
||||
//_owner->notification_cstat_changed(Ref<Stat>(this));
|
||||
emit_signal("c_changed", Ref<Stat>(this));
|
||||
}
|
||||
|
||||
void Stat::refresh() {
|
||||
_s_current = (_base + _base_calculated + _bonus) * (_percent / 100.0);
|
||||
|
||||
_dirty = true;
|
||||
|
||||
//_owner->notification_sstat_changed(Ref<Stat>(this));
|
||||
emit_signal("s_changed", Ref<Stat>(this));
|
||||
}
|
||||
|
||||
Dictionary Stat::to_dict() {
|
||||
return call("_to_dict");
|
||||
}
|
||||
void Stat::from_dict(const Dictionary &dict) {
|
||||
call("_from_dict", dict);
|
||||
}
|
||||
|
||||
Dictionary Stat::_to_dict() {
|
||||
Dictionary dict;
|
||||
|
||||
dict["dirty"] = _dirty;
|
||||
|
||||
dict["base"] = _base;
|
||||
dict["base_calculated"] = _base_calculated;
|
||||
dict["bonus"] = _bonus;
|
||||
dict["percent"] = _percent;
|
||||
|
||||
dict["current"] = _s_current;
|
||||
|
||||
return dict;
|
||||
}
|
||||
void Stat::_from_dict(const Dictionary &dict) {
|
||||
ERR_FAIL_COND(dict.empty());
|
||||
|
||||
_dirty = dict.get("dirty", false);
|
||||
|
||||
_base = dict.get("base", 0);
|
||||
_base_calculated = dict.get("base_calculated", 0);
|
||||
_bonus = dict.get("bonus", 0);
|
||||
_percent = dict.get("percent", 1);
|
||||
|
||||
_s_current = dict.get("current", 0);
|
||||
_c_current = _s_current;
|
||||
|
||||
_dirty = true;
|
||||
}
|
||||
|
||||
Stat::Stat() {
|
||||
_dirty = true;
|
||||
|
||||
_base = 0;
|
||||
_base_calculated = 0;
|
||||
_bonus = 0;
|
||||
_percent = 0;
|
||||
|
||||
_s_current = 0;
|
||||
_c_current = 0;
|
||||
}
|
||||
|
||||
Stat::~Stat() {
|
||||
}
|
||||
|
||||
void Stat::_bind_methods() {
|
||||
ADD_SIGNAL(MethodInfo("s_changed", PropertyInfo(Variant::OBJECT, "stat", PROPERTY_HINT_RESOURCE_TYPE, "Stat")));
|
||||
ADD_SIGNAL(MethodInfo("c_changed", PropertyInfo(Variant::OBJECT, "stat", PROPERTY_HINT_RESOURCE_TYPE, "Stat")));
|
||||
|
||||
ClassDB::bind_method(D_METHOD("get_dirty"), &Stat::get_dirty);
|
||||
ClassDB::bind_method(D_METHOD("set_dirty", "value"), &Stat::set_dirty);
|
||||
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "is_dirty"), "set_dirty", "get_dirty");
|
||||
|
||||
ClassDB::bind_method(D_METHOD("get_base"), &Stat::get_base);
|
||||
ClassDB::bind_method(D_METHOD("set_base", "value"), &Stat::set_base);
|
||||
ADD_PROPERTY(PropertyInfo(Variant::REAL, "base"), "set_base", "get_base");
|
||||
ClassDB::bind_method(D_METHOD("mod_base", "value"), &Stat::mod_base);
|
||||
|
||||
ClassDB::bind_method(D_METHOD("get_base_calculated"), &Stat::get_base_calculated);
|
||||
ClassDB::bind_method(D_METHOD("set_base_calculated", "value"), &Stat::set_base_calculated);
|
||||
ADD_PROPERTY(PropertyInfo(Variant::REAL, "base_calculated"), "set_base_calculated", "get_base_calculated");
|
||||
|
||||
ClassDB::bind_method(D_METHOD("get_bonus"), &Stat::get_bonus);
|
||||
ClassDB::bind_method(D_METHOD("set_bonus", "value"), &Stat::set_bonus);
|
||||
ADD_PROPERTY(PropertyInfo(Variant::REAL, "bonus"), "set_bonus", "get_bonus");
|
||||
ClassDB::bind_method(D_METHOD("mod_bonus", "value"), &Stat::mod_bonus);
|
||||
|
||||
ClassDB::bind_method(D_METHOD("get_percent"), &Stat::get_percent);
|
||||
ClassDB::bind_method(D_METHOD("set_percent", "value"), &Stat::set_percent);
|
||||
ADD_PROPERTY(PropertyInfo(Variant::REAL, "percent"), "set_percent", "get_percent");
|
||||
ClassDB::bind_method(D_METHOD("mod_percent", "value"), &Stat::mod_percent);
|
||||
|
||||
ClassDB::bind_method(D_METHOD("gets_current"), &Stat::gets_current);
|
||||
ClassDB::bind_method(D_METHOD("sets_current", "value"), &Stat::sets_current);
|
||||
ADD_PROPERTY(PropertyInfo(Variant::REAL, "scurrent"), "sets_current", "gets_current");
|
||||
|
||||
ClassDB::bind_method(D_METHOD("getc_current"), &Stat::getc_current);
|
||||
ClassDB::bind_method(D_METHOD("setc_current", "value"), &Stat::setc_current);
|
||||
ADD_PROPERTY(PropertyInfo(Variant::REAL, "ccurrent"), "setc_current", "getc_current");
|
||||
ClassDB::bind_method(D_METHOD("refresh"), &Stat::refresh);
|
||||
|
||||
//Serialization
|
||||
BIND_VMETHOD(MethodInfo("_from_dict", PropertyInfo(Variant::DICTIONARY, "dict")));
|
||||
BIND_VMETHOD(MethodInfo(PropertyInfo(Variant::DICTIONARY, "dict"), "_to_dict"));
|
||||
|
||||
ClassDB::bind_method(D_METHOD("from_dict", "dict"), &Stat::from_dict);
|
||||
ClassDB::bind_method(D_METHOD("to_dict"), &Stat::to_dict);
|
||||
|
||||
ClassDB::bind_method(D_METHOD("_from_dict", "dict"), &Stat::_from_dict);
|
||||
ClassDB::bind_method(D_METHOD("_to_dict"), &Stat::_to_dict);
|
||||
}
|
@ -1,89 +0,0 @@
|
||||
/*
|
||||
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 STAT_H
|
||||
#define STAT_H
|
||||
|
||||
#include "core/reference.h"
|
||||
#include "core/ustring.h"
|
||||
#include "core/vector.h"
|
||||
#include "scene/resources/curve.h"
|
||||
|
||||
class StatDataEntry;
|
||||
class Entity;
|
||||
|
||||
class Stat : public Reference {
|
||||
GDCLASS(Stat, Reference);
|
||||
|
||||
public:
|
||||
bool get_dirty();
|
||||
void set_dirty(bool value);
|
||||
|
||||
float get_base();
|
||||
void set_base(float value);
|
||||
void mod_base(float value);
|
||||
|
||||
float get_base_calculated();
|
||||
void set_base_calculated(float value);
|
||||
|
||||
float get_bonus();
|
||||
void set_bonus(float value);
|
||||
void mod_bonus(float value);
|
||||
|
||||
float get_percent();
|
||||
void set_percent(float value);
|
||||
void mod_percent(float value);
|
||||
|
||||
float gets_current();
|
||||
void sets_current(float value);
|
||||
|
||||
float getc_current();
|
||||
void setc_current(float value);
|
||||
|
||||
void refresh();
|
||||
|
||||
Dictionary to_dict();
|
||||
void from_dict(const Dictionary &dict);
|
||||
|
||||
Dictionary _to_dict();
|
||||
void _from_dict(const Dictionary &dict);
|
||||
|
||||
Stat();
|
||||
~Stat();
|
||||
|
||||
protected:
|
||||
static void _bind_methods();
|
||||
|
||||
private:
|
||||
bool _dirty;
|
||||
|
||||
float _base;
|
||||
float _base_calculated;
|
||||
float _bonus;
|
||||
float _percent;
|
||||
|
||||
float _s_current;
|
||||
|
||||
float _c_current;
|
||||
};
|
||||
|
||||
#endif
|
@ -44,13 +44,13 @@ void StatData::set_level_stat_data(Ref<LevelStatData> value) {
|
||||
_level_stat_data = value;
|
||||
}
|
||||
|
||||
void StatData::get_stat_for_stat(Ref<Stat> stat) {
|
||||
float StatData::get_stat_for_stat(int index) {
|
||||
//Ref<StatDataEntry> sd = get_stat_data(stat->get_id());
|
||||
Ref<StatDataEntry> sd = get_stat_data(0);
|
||||
|
||||
ERR_FAIL_COND(!sd.is_valid());
|
||||
ERR_FAIL_COND_V(!sd.is_valid(), 0);
|
||||
|
||||
sd->get_stats_for_stat(stat);
|
||||
return sd->get_base();
|
||||
}
|
||||
|
||||
StatData::StatData() {
|
||||
|
@ -27,7 +27,6 @@ SOFTWARE.
|
||||
#include "scene/resources/curve.h"
|
||||
|
||||
#include "level_stat_data.h"
|
||||
#include "stat.h"
|
||||
#include "stat_data_entry.h"
|
||||
|
||||
class StatData : public Resource {
|
||||
@ -40,7 +39,7 @@ public:
|
||||
Ref<LevelStatData> get_level_stat_data();
|
||||
void set_level_stat_data(Ref<LevelStatData> value);
|
||||
|
||||
void get_stat_for_stat(Ref<Stat> stat);
|
||||
float get_stat_for_stat(int index);
|
||||
|
||||
StatData();
|
||||
~StatData();
|
||||
|
@ -70,10 +70,6 @@ void StatDataEntry::set_mod_stat_multiplier(int index, float value) {
|
||||
_mod_stats[index].multiplier = value;
|
||||
}
|
||||
|
||||
void StatDataEntry::get_stats_for_stat(Ref<Stat> stat) {
|
||||
stat->mod_base(get_base());
|
||||
}
|
||||
|
||||
StatDataEntry::StatDataEntry() {
|
||||
_base = 0;
|
||||
_mod_stat_count = 0;
|
||||
@ -122,6 +118,4 @@ void StatDataEntry::_bind_methods() {
|
||||
ADD_PROPERTYI(PropertyInfo(Variant::INT, "ModStat_" + itos(i) + "/stat_id", PROPERTY_HINT_ENUM, "", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_INTERNAL), "set_mod_stat_id", "get_mod_stat_id", i);
|
||||
ADD_PROPERTYI(PropertyInfo(Variant::REAL, "ModStat_" + itos(i) + "/multiplier", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_INTERNAL), "set_mod_stat_multiplier", "get_mod_stat_multiplier", i);
|
||||
}
|
||||
|
||||
ClassDB::bind_method(D_METHOD("get_stats_for_stat", "stat"), &StatDataEntry::get_stats_for_stat);
|
||||
}
|
||||
|
@ -27,7 +27,6 @@ SOFTWARE.
|
||||
#include "scene/resources/curve.h"
|
||||
|
||||
#include "level_stat_data.h"
|
||||
#include "stat.h"
|
||||
|
||||
class StatDataEntry : public Resource {
|
||||
GDCLASS(StatDataEntry, Resource);
|
||||
@ -47,8 +46,6 @@ public:
|
||||
float get_mod_stat_multiplier(int index);
|
||||
void set_mod_stat_multiplier(int index, float value);
|
||||
|
||||
void get_stats_for_stat(Ref<Stat> stat);
|
||||
|
||||
StatDataEntry();
|
||||
~StatDataEntry();
|
||||
|
||||
|
@ -67,7 +67,6 @@ SOFTWARE.
|
||||
#include "entities/stats/complex_level_stat_data.h"
|
||||
#include "entities/stats/level_stat_data.h"
|
||||
#include "entities/stats/simple_level_stat_data.h"
|
||||
#include "entities/stats/stat.h"
|
||||
#include "entities/stats/stat_data.h"
|
||||
#include "entities/stats/stat_data_entry.h"
|
||||
|
||||
@ -196,7 +195,6 @@ void register_entity_spell_system_types() {
|
||||
//entity data
|
||||
ClassDB::register_class<EntityEnums>();
|
||||
|
||||
ClassDB::register_class<Stat>();
|
||||
ClassDB::register_class<StatDataEntry>();
|
||||
ClassDB::register_class<StatData>();
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user