mirror of
https://github.com/Relintai/entity_spell_system.git
synced 2025-05-09 22:41:39 +02:00
Stat refactor part2.
This commit is contained in:
parent
7224490a99
commit
5c4f0a1fe3
@ -59,11 +59,9 @@ bool AuraData::update(float delta) {
|
||||
Entity *AuraData::get_owner() {
|
||||
return _owner;
|
||||
}
|
||||
|
||||
void AuraData::set_owner(Entity *value) {
|
||||
_owner = value;
|
||||
}
|
||||
|
||||
void AuraData::set_owner_bind(Node *value) {
|
||||
if (!value) {
|
||||
return;
|
||||
|
@ -246,54 +246,69 @@ void Entity::sets_entity_data(Ref<EntityData> value) {
|
||||
}
|
||||
|
||||
void Entity::setup() {
|
||||
if (_deserialized)
|
||||
return;
|
||||
|
||||
if (has_method("_setup")) {
|
||||
call_multilevel("_setup");
|
||||
}
|
||||
}
|
||||
|
||||
void Entity::_setup() {
|
||||
if (_s_entity_data.is_valid()) {
|
||||
sinitialize_stats();
|
||||
if (!_s_entity_data.is_valid())
|
||||
return;
|
||||
|
||||
_s_entity_data->setup_resources(this);
|
||||
if (_deserialized) {
|
||||
Ref<EntityClassData> cc = gets_entity_data()->get_entity_class_data();
|
||||
ERR_FAIL_COND(!cc.is_valid());
|
||||
|
||||
sets_entity_data_id(_s_entity_data->get_id());
|
||||
Ref<StatData> stat_data = cc->get_stat_data();
|
||||
|
||||
sets_entity_type(_s_entity_data->get_entity_type());
|
||||
sets_entity_interaction_type(_s_entity_data->get_entity_interaction_type());
|
||||
sets_immunity_flags(_s_entity_data->get_immunity_flags());
|
||||
sets_entity_flags(_s_entity_data->get_entity_flags());
|
||||
ERR_FAIL_COND(!stat_data.is_valid());
|
||||
|
||||
if (_s_entity_controller == EntityEnums::ENITIY_CONTROLLER_NONE)
|
||||
sets_entity_controller(_s_entity_data->get_entity_controller());
|
||||
for (int i = 0; i < Stat::STAT_ID_TOTAL_STATS; ++i) {
|
||||
Ref<StatDataEntry> sde = stat_data->get_stat_data_int(i);
|
||||
|
||||
//sets_entity_name(_s_entity_data->get_entity_name());
|
||||
sets_money(_s_entity_data->get_money());
|
||||
|
||||
Ref<EntityClassData> cd = _s_entity_data->get_entity_class_data();
|
||||
|
||||
if (cd.is_valid()) {
|
||||
for (int i = 0; i < cd->get_num_start_spells(); ++i) {
|
||||
adds_spell(cd->get_start_spell(i));
|
||||
}
|
||||
_stats[i]->set_stat_data_entry(sde);
|
||||
}
|
||||
|
||||
for (int i = 0; i < _s_entity_data->get_num_craft_recipes(); ++i) {
|
||||
adds_craft_recipe(_s_entity_data->get_craft_recipe(i));
|
||||
return;
|
||||
}
|
||||
|
||||
sinitialize_stats();
|
||||
|
||||
_s_entity_data->setup_resources(this);
|
||||
|
||||
sets_entity_data_id(_s_entity_data->get_id());
|
||||
|
||||
sets_entity_type(_s_entity_data->get_entity_type());
|
||||
sets_entity_interaction_type(_s_entity_data->get_entity_interaction_type());
|
||||
sets_immunity_flags(_s_entity_data->get_immunity_flags());
|
||||
sets_entity_flags(_s_entity_data->get_entity_flags());
|
||||
|
||||
if (_s_entity_controller == EntityEnums::ENITIY_CONTROLLER_NONE)
|
||||
sets_entity_controller(_s_entity_data->get_entity_controller());
|
||||
|
||||
//sets_entity_name(_s_entity_data->get_entity_name());
|
||||
sets_money(_s_entity_data->get_money());
|
||||
|
||||
Ref<EntityClassData> cd = _s_entity_data->get_entity_class_data();
|
||||
|
||||
if (cd.is_valid()) {
|
||||
for (int i = 0; i < cd->get_num_start_spells(); ++i) {
|
||||
adds_spell(cd->get_start_spell(i));
|
||||
}
|
||||
}
|
||||
|
||||
if (_s_entity_data->get_equipment_data().is_valid()) {
|
||||
Ref<EquipmentData> eqd = _s_entity_data->get_equipment_data();
|
||||
for (int i = 0; i < _s_entity_data->get_num_craft_recipes(); ++i) {
|
||||
adds_craft_recipe(_s_entity_data->get_craft_recipe(i));
|
||||
}
|
||||
|
||||
for (int i = 0; i < ItemEnums::EQUIP_SLOT_EQUIP_SLOT_MAX; ++i) {
|
||||
Ref<ItemInstance> ii = eqd->get_item(i);
|
||||
if (_s_entity_data->get_equipment_data().is_valid()) {
|
||||
Ref<EquipmentData> eqd = _s_entity_data->get_equipment_data();
|
||||
|
||||
if (ii.is_valid())
|
||||
_s_equipment[i] = ii;
|
||||
}
|
||||
for (int i = 0; i < ItemEnums::EQUIP_SLOT_EQUIP_SLOT_MAX; ++i) {
|
||||
Ref<ItemInstance> ii = eqd->get_item(i);
|
||||
|
||||
if (ii.is_valid())
|
||||
_s_equipment[i] = ii;
|
||||
}
|
||||
}
|
||||
|
||||
@ -301,6 +316,12 @@ void Entity::_setup() {
|
||||
set_process(_s_entity_data.is_valid());
|
||||
}
|
||||
|
||||
//// Serialization ////
|
||||
|
||||
bool Entity::is_deserialized() {
|
||||
return _deserialized;
|
||||
}
|
||||
|
||||
Dictionary Entity::to_dict() {
|
||||
return call("_to_dict");
|
||||
}
|
||||
@ -824,10 +845,7 @@ Entity::Entity() {
|
||||
_actionbar_locked = false;
|
||||
|
||||
for (int i = 0; i < Stat::STAT_ID_TOTAL_STATS; ++i) {
|
||||
Ref<Stat> s = Ref<Stat>(memnew(Stat(static_cast<Stat::StatId>(i))));
|
||||
|
||||
s->connect("s_changed", this, "ons_stat_changed");
|
||||
s->connect("c_changed", this, "onc_stat_changed");
|
||||
Ref<Stat> s = Ref<Stat>(memnew(Stat(static_cast<Stat::StatId>(i), this)));
|
||||
|
||||
_stats[i] = s;
|
||||
}
|
||||
@ -989,25 +1007,6 @@ void Entity::initialize(Ref<EntityCreateInfo> info) {
|
||||
setc_xp(info->get_xp());
|
||||
|
||||
sets_entity_data(info->get_entity_data());
|
||||
|
||||
//setc_entity_data(info->get_entity_data());
|
||||
/*
|
||||
if (gets_entity_data() != NULL) {
|
||||
Ref<StatData> sd = gets_entity_data()->get_stat_data();
|
||||
|
||||
for (int i = 0; i < Stat::STAT_ID_TOTAL_STATS; ++i) {
|
||||
Ref<StatDataEntry> entry = sd->get_stat_data_int(i);
|
||||
Ref<Stat> stat = get_stat_int(i);
|
||||
|
||||
entry->get_stats_for_stat(stat);
|
||||
|
||||
if (entry->has_dependency()) {
|
||||
Ref<Stat> other = get_stat_enum(entry->get_depends_on());
|
||||
|
||||
stat->set_dependency(other, entry->get_dependdency_curve());
|
||||
}
|
||||
}
|
||||
}*/
|
||||
}
|
||||
|
||||
void Entity::sinitialize_stats() {
|
||||
@ -4153,58 +4152,6 @@ void Entity::loaded() {
|
||||
|
||||
//// PlayerData ////
|
||||
|
||||
void Entity::reward_xp_for_mob(int level) {
|
||||
/*
|
||||
int l = level - Level;
|
||||
|
||||
if (Mathf.Abs(l) > 5) {
|
||||
if (l < 0) {
|
||||
l = -5;
|
||||
} else {
|
||||
l = 5;
|
||||
}
|
||||
}
|
||||
|
||||
l += 5;
|
||||
|
||||
Xp += (l * 20);*/
|
||||
}
|
||||
|
||||
void Entity::level_up(int num) {
|
||||
/*
|
||||
Xp = 0;
|
||||
Level += num;
|
||||
|
||||
if (SOnLevelUp != null) {
|
||||
SOnLevelUp(owner);
|
||||
}
|
||||
|
||||
RpcLevelUp();*/
|
||||
}
|
||||
|
||||
void Entity::set_level_without_modifiers(int newLevel, bool a) {
|
||||
/*
|
||||
level = newLevel;
|
||||
|
||||
if (SOnLevelChanged != null) {
|
||||
SOnLevelChanged(owner, newLevel);
|
||||
}*/
|
||||
}
|
||||
|
||||
void Entity::apply_level_modifiers() {
|
||||
/*
|
||||
owner.Stats.SHealth.Modifiers.Remove(-10);
|
||||
|
||||
owner.Stats.SHealth.Modifiers.Add(-10, 0f, -((1 - character.Stats.HPScaling.Evaluate((float)Level)) * 100f));*/
|
||||
}
|
||||
|
||||
void Entity::rpc_level_up() {
|
||||
/*
|
||||
if (COnLevelUp != null) {
|
||||
COnLevelUp(owner);
|
||||
}*/
|
||||
}
|
||||
|
||||
void Entity::update(float delta) {
|
||||
if (_s_gcd > 0.0000001) {
|
||||
_s_gcd -= delta;
|
||||
@ -5086,16 +5033,6 @@ void Entity::_bind_methods() {
|
||||
ClassDB::bind_method(D_METHOD("crequest_loot"), &Entity::crequest_loot);
|
||||
ClassDB::bind_method(D_METHOD("sloot"), &Entity::sloot);
|
||||
|
||||
//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"), &Entity::from_dict);
|
||||
ClassDB::bind_method(D_METHOD("to_dict"), &Entity::to_dict);
|
||||
|
||||
ClassDB::bind_method(D_METHOD("_from_dict", "dict"), &Entity::_from_dict);
|
||||
ClassDB::bind_method(D_METHOD("_to_dict"), &Entity::_to_dict);
|
||||
|
||||
//Actionbars
|
||||
|
||||
ClassDB::bind_method(D_METHOD("get_actionbar_locked"), &Entity::get_actionbar_locked);
|
||||
@ -5103,4 +5040,16 @@ void Entity::_bind_methods() {
|
||||
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "actionbar_locked"), "set_actionbar_locked", "get_actionbar_locked");
|
||||
|
||||
ClassDB::bind_method(D_METHOD("get_action_bar_profile"), &Entity::get_action_bar_profile);
|
||||
|
||||
//Serialization
|
||||
BIND_VMETHOD(MethodInfo("_from_dict", PropertyInfo(Variant::DICTIONARY, "dict")));
|
||||
BIND_VMETHOD(MethodInfo(PropertyInfo(Variant::DICTIONARY, "dict"), "_to_dict"));
|
||||
|
||||
ClassDB::bind_method(D_METHOD("is_deserialized"), &Entity::is_deserialized);
|
||||
|
||||
ClassDB::bind_method(D_METHOD("from_dict", "dict"), &Entity::from_dict);
|
||||
ClassDB::bind_method(D_METHOD("to_dict"), &Entity::to_dict);
|
||||
|
||||
ClassDB::bind_method(D_METHOD("_from_dict", "dict"), &Entity::_from_dict);
|
||||
ClassDB::bind_method(D_METHOD("_to_dict"), &Entity::_to_dict);
|
||||
}
|
||||
|
@ -199,13 +199,6 @@ public:
|
||||
|
||||
void sinitialize_stats();
|
||||
|
||||
void reward_xp_for_mob(int level);
|
||||
void level_up(int num = 1);
|
||||
void set_level_without_modifiers(int newLevel, bool a);
|
||||
void apply_level_modifiers();
|
||||
void rpc_level_up();
|
||||
void registers();
|
||||
|
||||
//// Stats ////
|
||||
|
||||
_FORCE_INLINE_ Ref<Stat> get_health() { return _stats[Stat::STAT_ID_HEALTH]; }
|
||||
@ -671,6 +664,10 @@ public:
|
||||
void setup();
|
||||
virtual void _setup();
|
||||
|
||||
//// Serialization ////
|
||||
|
||||
bool is_deserialized();
|
||||
|
||||
Dictionary to_dict();
|
||||
void from_dict(const Dictionary &dict);
|
||||
|
||||
|
@ -25,32 +25,38 @@ void Player::setc_seed(int value) {
|
||||
void Player::_setup() {
|
||||
Entity::_setup();
|
||||
|
||||
if (gets_entity_data().is_valid()) {
|
||||
ProfileManager *pm = ProfileManager::get_instance();
|
||||
if (!gets_entity_data().is_valid())
|
||||
return;
|
||||
|
||||
if (pm != NULL) {
|
||||
Ref<ClassProfile> cp = pm->get_class_profile(gets_entity_data()->get_id());
|
||||
if (is_deserialized()) {
|
||||
|
||||
if (cp.is_valid()) {
|
||||
set_actionbar_locked(cp->get_actionbar_locked());
|
||||
return;
|
||||
}
|
||||
|
||||
get_action_bar_profile()->clear_action_bars();
|
||||
ProfileManager *pm = ProfileManager::get_instance();
|
||||
|
||||
Ref<ActionBarProfile> abp = cp->get_action_bar_profile();
|
||||
if (pm != NULL) {
|
||||
Ref<ClassProfile> cp = pm->get_class_profile(gets_entity_data()->get_id());
|
||||
|
||||
get_action_bar_profile()->from_actionbar_profile(abp);
|
||||
}
|
||||
if (cp.is_valid()) {
|
||||
set_actionbar_locked(cp->get_actionbar_locked());
|
||||
|
||||
get_action_bar_profile()->clear_action_bars();
|
||||
|
||||
Ref<ActionBarProfile> abp = cp->get_action_bar_profile();
|
||||
|
||||
get_action_bar_profile()->from_actionbar_profile(abp);
|
||||
}
|
||||
}
|
||||
|
||||
if (!gets_bag().is_valid()) {
|
||||
if (!gets_bag().is_valid()) {
|
||||
|
||||
Ref<Bag> bag;
|
||||
bag.instance();
|
||||
Ref<Bag> bag;
|
||||
bag.instance();
|
||||
|
||||
bag->set_size(gets_entity_data()->get_bag_size());
|
||||
bag->set_size(gets_entity_data()->get_bag_size());
|
||||
|
||||
sets_bag(bag);
|
||||
}
|
||||
sets_bag(bag);
|
||||
}
|
||||
}
|
||||
|
||||
@ -79,7 +85,6 @@ Player::~Player() {
|
||||
//_input_profile.unref();
|
||||
}
|
||||
|
||||
|
||||
void Player::_bind_methods() {
|
||||
ClassDB::bind_method(D_METHOD("gets_seed"), &Player::gets_seed);
|
||||
ClassDB::bind_method(D_METHOD("sets_seed", "value"), &Player::sets_seed);
|
||||
|
@ -1,5 +1,8 @@
|
||||
#include "stat.h"
|
||||
|
||||
#include "../entity.h"
|
||||
#include "stat_data_entry.h"
|
||||
|
||||
const String Stat::STAT_BINDING_STRING = "Health,Speed,Mana,GCD,Haste,Agility,Strength,Stamina,Intellect,Luck,Haste Rating,Resilience,Armor,Attack Power,Spell Power,Melee Crit,Melee Crit bonus,Spell Crit,Spell Crit Bonus,Block,Parry,Damage Reduction,Melee Damage Reduction,Spell Damage Reduction,Damage Taken,Heal Taken,Melee Damage,Spell Damage,Holy Resist,Shadow Resist,Nature Resist,Fire Resist,Frost Resist,Lightning Resist,Chaos Resist,Silence Resist,Fear Resist,Stun Resist,Energy,Rage,XP Rate,None";
|
||||
const String Stat::MAIN_STAT_BINDING_STRING = "Agility,Strength,Stamina,Intellect,Luck";
|
||||
|
||||
@ -103,7 +106,6 @@ String Stat::stat_id_name(int stat_id) {
|
||||
return "";
|
||||
}
|
||||
|
||||
|
||||
Stat::StatId Stat::get_id() {
|
||||
return _id;
|
||||
}
|
||||
@ -111,6 +113,33 @@ void Stat::set_id(Stat::StatId id) {
|
||||
_id = id;
|
||||
}
|
||||
|
||||
Ref<StatDataEntry> Stat::get_stat_data_entry() {
|
||||
return _stat_data_entry;
|
||||
}
|
||||
void Stat::set_stat_data_entry(Ref<StatDataEntry> entry) {
|
||||
_stat_data_entry = entry;
|
||||
}
|
||||
|
||||
Entity *Stat::get_owner() {
|
||||
return _owner;
|
||||
}
|
||||
void Stat::set_owner(Entity *value) {
|
||||
_owner = value;
|
||||
}
|
||||
void Stat::set_owner_bind(Node *value) {
|
||||
if (!value) {
|
||||
return;
|
||||
}
|
||||
|
||||
Entity *e = cast_to<Entity>(value);
|
||||
|
||||
if (!e) {
|
||||
return;
|
||||
}
|
||||
|
||||
_owner = e;
|
||||
}
|
||||
|
||||
Stat::StatModifierApplyType Stat::get_stat_modifier_type() {
|
||||
return _modifier_apply_type;
|
||||
}
|
||||
@ -118,7 +147,6 @@ void Stat::set_stat_modifier_type(Stat::StatModifierApplyType value) {
|
||||
_modifier_apply_type = value;
|
||||
}
|
||||
|
||||
|
||||
bool Stat::get_public() {
|
||||
return _public;
|
||||
}
|
||||
@ -183,8 +211,12 @@ float Stat::getc_current() {
|
||||
return _c_current;
|
||||
}
|
||||
void Stat::setc_current(float value) {
|
||||
ERR_FAIL_COND(_owner == NULL);
|
||||
|
||||
_c_current = value;
|
||||
|
||||
_owner->onc_stat_changed(Ref<Stat>(this));
|
||||
|
||||
emit_signal("c_changed", Ref<Stat>(this));
|
||||
}
|
||||
|
||||
@ -192,15 +224,22 @@ float Stat::getc_max() {
|
||||
return _c_max;
|
||||
}
|
||||
void Stat::setc_max(float value) {
|
||||
ERR_FAIL_COND(_owner == NULL);
|
||||
|
||||
_s_current = value;
|
||||
|
||||
_owner->onc_stat_changed(Ref<Stat>(this));
|
||||
|
||||
emit_signal("c_changed", Ref<Stat>(this));
|
||||
}
|
||||
|
||||
void Stat::setc_values(int ccurrent, int cmax) {
|
||||
ERR_FAIL_COND(_owner == NULL);
|
||||
|
||||
_c_current = ccurrent;
|
||||
_c_max = cmax;
|
||||
|
||||
_owner->onc_stat_changed(Ref<Stat>(this));
|
||||
emit_signal("c_changed", Ref<Stat>(this));
|
||||
}
|
||||
|
||||
@ -234,8 +273,22 @@ Ref<StatModifier> Stat::add_modifier(int id, float base_mod, float bonus_mod, fl
|
||||
return stat_modifier;
|
||||
}
|
||||
|
||||
Ref<StatModifier> Stat::get_or_add_modifier(int id) {
|
||||
for (int i = 0; i < _modifiers.size(); ++i) {
|
||||
if (_modifiers.get(i)->get_id() == id) {
|
||||
return _modifiers.get(i);
|
||||
}
|
||||
}
|
||||
|
||||
Ref<StatModifier> stat_modifier = Ref<StatModifier>(memnew(StatModifier(id, 0, 0, 0, this)));
|
||||
|
||||
_modifiers.push_back(stat_modifier);
|
||||
|
||||
return stat_modifier;
|
||||
}
|
||||
|
||||
void Stat::remove_modifier(int id) {
|
||||
for (int i = 0; i < _modifiers.size(); i += 1) {
|
||||
for (int i = 0; i < _modifiers.size(); ++i) {
|
||||
if (_modifiers.get(i)->get_id() == id) {
|
||||
Ref<StatModifier> modifier = _modifiers.get(i);
|
||||
_modifiers.remove(i);
|
||||
@ -247,7 +300,14 @@ void Stat::remove_modifier(int id) {
|
||||
}
|
||||
}
|
||||
|
||||
void Stat::remove_modifier_index(int index) {
|
||||
_modifiers.remove(index);
|
||||
}
|
||||
|
||||
void Stat::apply_modifiers() {
|
||||
ERR_FAIL_COND(_owner == NULL);
|
||||
ERR_FAIL_COND(!_stat_data_entry.is_valid());
|
||||
|
||||
reset_values();
|
||||
|
||||
if (_modifier_apply_type == MODIFIER_APPLY_TYPE_STANDARD) {
|
||||
@ -293,12 +353,25 @@ void Stat::apply_modifiers() {
|
||||
}
|
||||
}
|
||||
|
||||
refresh_currmax();
|
||||
_dirty_mods = false;
|
||||
|
||||
for (int i = 0; i < _stat_data_entry->get_mod_stat_count(); ++i) {
|
||||
Ref<Stat> stat = _owner->get_stat_enum(_stat_data_entry->get_mod_stat_id(i));
|
||||
Ref<Curve> curve = _stat_data_entry->get_mod_stat_curve(i);
|
||||
|
||||
ERR_FAIL_COND(!stat.is_valid());
|
||||
ERR_FAIL_COND(!curve.is_valid());
|
||||
|
||||
Ref<StatModifier> sm = stat->get_or_add_modifier(-(static_cast<int>(_id) + 1));
|
||||
|
||||
sm->set_base_mod(_s_current * curve->interpolate(_s_current));
|
||||
}
|
||||
|
||||
_owner->ons_stat_changed(Ref<Stat>(this));
|
||||
emit_signal("s_changed", Ref<Stat>(this));
|
||||
}
|
||||
|
||||
|
||||
void Stat::reset_values() {
|
||||
_percent = 100;
|
||||
_bonus = 0;
|
||||
@ -331,10 +404,13 @@ bool Stat::isc_current_zero() {
|
||||
}
|
||||
|
||||
void Stat::set_to_max() {
|
||||
ERR_FAIL_COND(_owner == NULL);
|
||||
|
||||
_s_current = _s_max;
|
||||
|
||||
_dirty = true;
|
||||
|
||||
_owner->ons_stat_changed(Ref<Stat>(this));
|
||||
emit_signal("s_changed", Ref<Stat>(this));
|
||||
}
|
||||
|
||||
@ -342,7 +418,6 @@ void Stat::modifier_changed(Ref<StatModifier> modifier) {
|
||||
_dirty_mods = true;
|
||||
}
|
||||
|
||||
|
||||
Dictionary Stat::to_dict() {
|
||||
return call("_to_dict");
|
||||
}
|
||||
@ -389,7 +464,6 @@ void Stat::_from_dict(const Dictionary &dict) {
|
||||
_dirty = dict.get("dirty", false);
|
||||
_dirty_mods = dict.get("dirty_mods", false);
|
||||
|
||||
|
||||
_base = dict.get("base", 0);
|
||||
_bonus = dict.get("bonus", 0);
|
||||
_percent = dict.get("percent", 1);
|
||||
@ -407,7 +481,7 @@ void Stat::_from_dict(const Dictionary &dict) {
|
||||
for (int i = 0; i < modifiers.size(); ++i) {
|
||||
Ref<StatModifier> sm;
|
||||
sm.instance();
|
||||
|
||||
|
||||
sm->from_dict(modifiers.get(i, Dictionary()));
|
||||
sm->set_owner(this);
|
||||
|
||||
@ -417,6 +491,7 @@ void Stat::_from_dict(const Dictionary &dict) {
|
||||
|
||||
Stat::Stat() {
|
||||
_id = Stat::STAT_ID_NONE;
|
||||
_owner = NULL;
|
||||
|
||||
_modifier_apply_type = MODIFIER_APPLY_TYPE_STANDARD;
|
||||
|
||||
@ -437,8 +512,9 @@ Stat::Stat() {
|
||||
_c_max = 0;
|
||||
}
|
||||
|
||||
Stat::Stat(Stat::StatId id) {
|
||||
Stat::Stat(Stat::StatId id, Entity *owner) {
|
||||
_id = id;
|
||||
_owner = owner;
|
||||
|
||||
_modifier_apply_type = MODIFIER_APPLY_TYPE_STANDARD;
|
||||
|
||||
@ -459,8 +535,9 @@ Stat::Stat(Stat::StatId id) {
|
||||
_c_max = 0;
|
||||
}
|
||||
|
||||
Stat::Stat(Stat::StatId id, StatModifierApplyType modifier_apply_type) {
|
||||
Stat::Stat(Stat::StatId id, StatModifierApplyType modifier_apply_type, Entity *owner) {
|
||||
_id = id;
|
||||
_owner = owner;
|
||||
|
||||
_modifier_apply_type = modifier_apply_type;
|
||||
|
||||
@ -481,9 +558,10 @@ Stat::Stat(Stat::StatId id, StatModifierApplyType modifier_apply_type) {
|
||||
_c_max = 0;
|
||||
}
|
||||
|
||||
|
||||
Stat::~Stat() {
|
||||
_modifiers.clear();
|
||||
_owner = NULL;
|
||||
_stat_data_entry.unref();
|
||||
}
|
||||
|
||||
void Stat::_bind_methods() {
|
||||
@ -494,6 +572,14 @@ void Stat::_bind_methods() {
|
||||
ClassDB::bind_method(D_METHOD("set_id", "id"), &Stat::set_id);
|
||||
ADD_PROPERTY(PropertyInfo(Variant::INT, "id", PROPERTY_HINT_ENUM, STAT_BINDING_STRING), "set_id", "get_id");
|
||||
|
||||
ClassDB::bind_method(D_METHOD("get_stat_data_entry"), &Stat::get_stat_data_entry);
|
||||
ClassDB::bind_method(D_METHOD("set_stat_data_entry", "value"), &Stat::set_stat_data_entry);
|
||||
ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "stat_data_entry", PROPERTY_HINT_RESOURCE_TYPE, "StatDataEntry"), "set_stat_data_entry", "get_stat_data_entry");
|
||||
|
||||
ClassDB::bind_method(D_METHOD("get_owner"), &Stat::get_owner);
|
||||
ClassDB::bind_method(D_METHOD("set_owner", "value"), &Stat::set_owner_bind);
|
||||
ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "owner", PROPERTY_HINT_RESOURCE_TYPE, "Entity"), "set_owner", "get_owner");
|
||||
|
||||
ClassDB::bind_method(D_METHOD("get_stat_modifier_type"), &Stat::get_stat_modifier_type);
|
||||
ClassDB::bind_method(D_METHOD("set_stat_modifier_type", "value"), &Stat::set_stat_modifier_type);
|
||||
ADD_PROPERTY(PropertyInfo(Variant::INT, "stat_type", PROPERTY_HINT_ENUM, "Standard, Min Modifier, Max modifier"), "set_stat_modifier_type", "get_stat_modifier_type");
|
||||
@ -537,7 +623,9 @@ void Stat::_bind_methods() {
|
||||
ClassDB::bind_method(D_METHOD("setc_values", "ccurrent", "cmax"), &Stat::setc_values);
|
||||
|
||||
ClassDB::bind_method(D_METHOD("add_modifier", "id", "base_mod", "bonus_mod", "percent_mod"), &Stat::add_modifier);
|
||||
ClassDB::bind_method(D_METHOD("get_or_add_modifier", "id"), &Stat::get_or_add_modifier);
|
||||
ClassDB::bind_method(D_METHOD("remove_modifier", "id"), &Stat::remove_modifier);
|
||||
ClassDB::bind_method(D_METHOD("remove_modifier_index", "index"), &Stat::remove_modifier_index);
|
||||
ClassDB::bind_method(D_METHOD("get_modifier_count"), &Stat::get_modifier_count);
|
||||
ClassDB::bind_method(D_METHOD("clear_modifiers"), &Stat::clear_modifiers);
|
||||
ClassDB::bind_method(D_METHOD("get_modifier", "index"), &Stat::get_modifier);
|
||||
|
@ -1,13 +1,16 @@
|
||||
#ifndef STAT_H
|
||||
#define STAT_H
|
||||
|
||||
#include "core/ustring.h"
|
||||
#include "core/reference.h"
|
||||
#include "core/ustring.h"
|
||||
#include "core/vector.h"
|
||||
#include "scene/resources/curve.h"
|
||||
|
||||
#include "stat_modifier.h"
|
||||
|
||||
class StatDataEntry;
|
||||
class Entity;
|
||||
|
||||
class Stat : public Reference {
|
||||
GDCLASS(Stat, Reference);
|
||||
|
||||
@ -102,6 +105,13 @@ public:
|
||||
Stat::StatId get_id();
|
||||
void set_id(Stat::StatId id);
|
||||
|
||||
Ref<StatDataEntry> get_stat_data_entry();
|
||||
void set_stat_data_entry(Ref<StatDataEntry> entry);
|
||||
|
||||
Entity *get_owner();
|
||||
void set_owner(Entity *value);
|
||||
void set_owner_bind(Node *value);
|
||||
|
||||
StatModifierApplyType get_stat_modifier_type();
|
||||
void set_stat_modifier_type(StatModifierApplyType value);
|
||||
|
||||
@ -135,7 +145,9 @@ public:
|
||||
|
||||
Vector<Ref<StatModifier> > *get_modifiers();
|
||||
Ref<StatModifier> add_modifier(int id, float base_mod, float bonus_mod, float percent_mod);
|
||||
Ref<StatModifier> get_or_add_modifier(int id);
|
||||
void remove_modifier(int id);
|
||||
void remove_modifier_index(int index);
|
||||
int get_modifier_count();
|
||||
void clear_modifiers();
|
||||
Ref<StatModifier> get_modifier(int index);
|
||||
@ -158,8 +170,8 @@ public:
|
||||
void _from_dict(const Dictionary &dict);
|
||||
|
||||
Stat();
|
||||
Stat(Stat::StatId id);
|
||||
Stat(Stat::StatId id, StatModifierApplyType modifier_apply_type);
|
||||
Stat(Stat::StatId id, Entity* owner);
|
||||
Stat(Stat::StatId id, StatModifierApplyType modifier_apply_type, Entity *owner);
|
||||
~Stat();
|
||||
|
||||
protected:
|
||||
@ -186,6 +198,9 @@ private:
|
||||
|
||||
float _c_current;
|
||||
float _c_max;
|
||||
|
||||
Entity *_owner;
|
||||
Ref<StatDataEntry> _stat_data_entry;
|
||||
};
|
||||
|
||||
VARIANT_ENUM_CAST(Stat::StatId);
|
||||
|
@ -49,7 +49,7 @@ StatData::StatData() {
|
||||
_entries[i] = Ref<StatDataEntry>(entry);
|
||||
}
|
||||
|
||||
get_stat_data_enum(Stat::STAT_ID_HEALTH)->set_base(10000);
|
||||
get_stat_data_enum(Stat::STAT_ID_HEALTH)->set_base(100);
|
||||
get_stat_data_enum(Stat::STAT_ID_MANA)->set_base(100);
|
||||
get_stat_data_enum(Stat::STAT_ID_SPEED)->set_base(4.2);
|
||||
get_stat_data_enum(Stat::STAT_ID_GLOBAL_COOLDOWN)->set_base(1.5);
|
||||
|
@ -1,2 +1,153 @@
|
||||
#include "stat_data_entry.h"
|
||||
|
||||
Stat::StatId StatDataEntry::get_stat_id() {
|
||||
return _stat_id;
|
||||
}
|
||||
void StatDataEntry::set_stat_id(Stat::StatId value) {
|
||||
_stat_id = value;
|
||||
|
||||
if (static_cast<int>(value) < Stat::STAT_ID_GLOBAL_COOLDOWN)
|
||||
_public = true;
|
||||
}
|
||||
|
||||
bool StatDataEntry::get_public() {
|
||||
return _public;
|
||||
}
|
||||
void StatDataEntry::set_public(bool value) {
|
||||
_public = value;
|
||||
}
|
||||
|
||||
float StatDataEntry::get_base() {
|
||||
return _base;
|
||||
}
|
||||
void StatDataEntry::set_base(float value) {
|
||||
_base = value;
|
||||
}
|
||||
|
||||
float StatDataEntry::get_bonus() {
|
||||
return _bonus;
|
||||
}
|
||||
void StatDataEntry::set_bonus(float value) {
|
||||
_bonus = value;
|
||||
}
|
||||
|
||||
float StatDataEntry::get_percent() {
|
||||
return _percent;
|
||||
}
|
||||
void StatDataEntry::set_percent(float value) {
|
||||
_percent = value;
|
||||
}
|
||||
|
||||
Stat::StatModifierApplyType StatDataEntry::get_modifier_apply_type() {
|
||||
return _modifier_apply_type;
|
||||
}
|
||||
void StatDataEntry::set_modifier_apply_type(Stat::StatModifierApplyType value) {
|
||||
_modifier_apply_type = value;
|
||||
}
|
||||
|
||||
bool StatDataEntry::has_mod_stats() {
|
||||
return _mod_stat_count > 0;
|
||||
}
|
||||
int StatDataEntry::get_mod_stat_count() {
|
||||
return _mod_stat_count;
|
||||
}
|
||||
|
||||
Stat::StatId StatDataEntry::get_mod_stat_id(int index) {
|
||||
ERR_FAIL_INDEX_V(index, MAX_MOD_STATS, Stat::STAT_ID_HEALTH);
|
||||
|
||||
return _mod_stats[index].stat_id;
|
||||
}
|
||||
void StatDataEntry::set_mod_stat_id(int index, Stat::StatId value) {
|
||||
ERR_FAIL_INDEX(index, MAX_MOD_STATS);
|
||||
|
||||
_mod_stats[index].stat_id = value;
|
||||
}
|
||||
|
||||
Ref<Curve> StatDataEntry::get_mod_stat_curve(int index) {
|
||||
ERR_FAIL_INDEX_V(index, MAX_MOD_STATS, Ref<Curve>());
|
||||
|
||||
return _mod_stats[index].curve;
|
||||
}
|
||||
void StatDataEntry::set_mod_stat_curve(int index, Ref<Curve> curve) {
|
||||
ERR_FAIL_INDEX(index, MAX_MOD_STATS);
|
||||
|
||||
_mod_stats[index].curve = curve;
|
||||
}
|
||||
|
||||
void StatDataEntry::get_stats_for_stat(Ref<Stat> stat) {
|
||||
stat->set_stat_modifier_type(get_modifier_apply_type());
|
||||
|
||||
stat->clear_modifiers();
|
||||
|
||||
stat->set_public(_public);
|
||||
stat->add_modifier(0, get_base(), get_bonus(), get_percent());
|
||||
stat->set_stat_data_entry(Ref<StatDataEntry>(this));
|
||||
|
||||
stat->set_to_max();
|
||||
}
|
||||
|
||||
StatDataEntry::StatDataEntry() {
|
||||
_stat_id = Stat::STAT_ID_NONE;
|
||||
|
||||
_public = false;
|
||||
_base = 0;
|
||||
_bonus = 0;
|
||||
_percent = 100;
|
||||
_mod_stat_count = 0;
|
||||
|
||||
_modifier_apply_type = Stat::MODIFIER_APPLY_TYPE_STANDARD;
|
||||
}
|
||||
|
||||
StatDataEntry::~StatDataEntry() {
|
||||
for (int i = 0; i < MAX_MOD_STATS; ++i) {
|
||||
_mod_stats[i].curve.unref();
|
||||
}
|
||||
}
|
||||
|
||||
void StatDataEntry::_bind_methods() {
|
||||
ClassDB::bind_method(D_METHOD("get_stat_id"), &StatDataEntry::get_stat_id);
|
||||
ClassDB::bind_method(D_METHOD("set_stat_id", "value"), &StatDataEntry::set_stat_id);
|
||||
ADD_PROPERTY(PropertyInfo(Variant::INT, "stat_id", PROPERTY_HINT_ENUM, Stat::STAT_BINDING_STRING), "set_stat_id", "get_stat_id");
|
||||
|
||||
ClassDB::bind_method(D_METHOD("get_base"), &StatDataEntry::get_base);
|
||||
ClassDB::bind_method(D_METHOD("set_base", "value"), &StatDataEntry::set_base);
|
||||
ADD_PROPERTY(PropertyInfo(Variant::REAL, "base"), "set_base", "get_base");
|
||||
|
||||
ClassDB::bind_method(D_METHOD("get_bonus"), &StatDataEntry::get_bonus);
|
||||
ClassDB::bind_method(D_METHOD("set_bonus", "value"), &StatDataEntry::set_bonus);
|
||||
ADD_PROPERTY(PropertyInfo(Variant::REAL, "bonus"), "set_bonus", "get_bonus");
|
||||
|
||||
ClassDB::bind_method(D_METHOD("get_percent"), &StatDataEntry::get_percent);
|
||||
ClassDB::bind_method(D_METHOD("set_percent", "value"), &StatDataEntry::set_percent);
|
||||
ADD_PROPERTY(PropertyInfo(Variant::REAL, "percent"), "set_percent", "get_percent");
|
||||
|
||||
ClassDB::bind_method(D_METHOD("get_modifier_apply_type"), &StatDataEntry::get_modifier_apply_type);
|
||||
ClassDB::bind_method(D_METHOD("set_modifier_apply_type", "value"), &StatDataEntry::set_modifier_apply_type);
|
||||
ADD_PROPERTY(PropertyInfo(Variant::INT, "modifier_apply_type", PROPERTY_HINT_ENUM, Stat::MODIFIER_APPLY_TYPE_BINDING_STRING), "set_modifier_apply_type", "get_modifier_apply_type");
|
||||
|
||||
ClassDB::bind_method(D_METHOD("has_mod_stats"), &StatDataEntry::has_mod_stats);
|
||||
ClassDB::bind_method(D_METHOD("get_mod_stat_count"), &StatDataEntry::get_mod_stat_count);
|
||||
|
||||
ClassDB::bind_method(D_METHOD("get_mod_stat_id", "index"), &StatDataEntry::get_mod_stat_id);
|
||||
ClassDB::bind_method(D_METHOD("set_mod_stat_id", "index", "value"), &StatDataEntry::set_mod_stat_id);
|
||||
|
||||
ClassDB::bind_method(D_METHOD("get_mod_stat_curve", "index"), &StatDataEntry::get_mod_stat_curve);
|
||||
ClassDB::bind_method(D_METHOD("set_mod_stat_curve", "index", "value"), &StatDataEntry::set_mod_stat_curve);
|
||||
|
||||
for (int i = 0; i < MAX_MOD_STATS; i++) {
|
||||
ADD_PROPERTYI(PropertyInfo(Variant::INT, "ModStat_" + itos(i) + "/stat_id", PROPERTY_HINT_ENUM, Stat::STAT_BINDING_STRING, PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_INTERNAL), "set_mod_stat_id", "get_mod_stat_id", i);
|
||||
ADD_PROPERTYI(PropertyInfo(Variant::OBJECT, "ModStat_" + itos(i) + "/curve", PROPERTY_HINT_RESOURCE_TYPE, "Curve", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_INTERNAL), "set_mod_stat_curve", "get_mod_stat_curve", i);
|
||||
}
|
||||
|
||||
ClassDB::bind_method(D_METHOD("get_stats_for_stat", "stat"), &StatDataEntry::get_stats_for_stat);
|
||||
}
|
||||
|
||||
void StatDataEntry::_validate_property(PropertyInfo &property) const {
|
||||
String prop = property.name;
|
||||
if (prop.begins_with("ModStat_")) {
|
||||
int frame = prop.get_slicec('/', 0).get_slicec('_', 1).to_int();
|
||||
if (frame >= _mod_stat_count) {
|
||||
property.usage = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,107 +1,73 @@
|
||||
#ifndef STAT_DATA_ENTRY_H
|
||||
#define STAT_DATA_ENTRY_H
|
||||
|
||||
#include "scene/resources/curve.h"
|
||||
#include "core/resource.h"
|
||||
#include "scene/resources/curve.h"
|
||||
|
||||
#include "stat.h"
|
||||
#include "level_stat_data.h"
|
||||
#include "stat.h"
|
||||
|
||||
class StatDataEntry : public Resource {
|
||||
GDCLASS(StatDataEntry, Resource);
|
||||
GDCLASS(StatDataEntry, Resource);
|
||||
|
||||
public:
|
||||
Stat::StatId get_stat_id() { return _stat_id; }
|
||||
void set_stat_id(Stat::StatId value) { _stat_id = value; }
|
||||
Stat::StatId get_stat_id();
|
||||
void set_stat_id(Stat::StatId value);
|
||||
|
||||
float get_base() { return _base; }
|
||||
void set_base(float value) { _base = value; }
|
||||
bool get_public();
|
||||
void set_public(bool value);
|
||||
|
||||
float get_bonus() { return _bonus; }
|
||||
void set_bonus(float value) { _bonus = value; }
|
||||
float get_base();
|
||||
void set_base(float value);
|
||||
|
||||
float get_percent() { return _percent; }
|
||||
void set_percent(float value) { _percent = value; }
|
||||
float get_bonus();
|
||||
void set_bonus(float value);
|
||||
|
||||
Stat::StatModifierApplyType get_modifier_apply_type() { return _modifier_apply_type; }
|
||||
void set_modifier_apply_type(Stat::StatModifierApplyType value) { _modifier_apply_type = value; }
|
||||
float get_percent();
|
||||
void set_percent(float value);
|
||||
|
||||
bool has_dependency() { return _depends_on != Stat::STAT_ID_NONE; }
|
||||
Stat::StatModifierApplyType get_modifier_apply_type();
|
||||
void set_modifier_apply_type(Stat::StatModifierApplyType value);
|
||||
|
||||
Stat::StatId get_depends_on() { return _depends_on; }
|
||||
void set_depends_on(Stat::StatId value) { _depends_on = value; }
|
||||
bool has_mod_stats();
|
||||
int get_mod_stat_count();
|
||||
|
||||
Ref<Curve> get_dependdency_curve() { return _dependdency_curve; }
|
||||
void set_dependdency_curve(Ref<Curve> curve) { _dependdency_curve = curve; }
|
||||
Stat::StatId get_mod_stat_id(int index);
|
||||
void set_mod_stat_id(int index, Stat::StatId value);
|
||||
|
||||
Ref<Curve> get_mod_stat_curve(int index);
|
||||
void set_mod_stat_curve(int index, Ref<Curve> curve);
|
||||
|
||||
void get_stats_for_stat(Ref<Stat> stat) {
|
||||
stat->set_stat_modifier_type(get_modifier_apply_type());
|
||||
void get_stats_for_stat(Ref<Stat> stat);
|
||||
|
||||
stat->clear_modifiers();
|
||||
|
||||
stat->add_modifier(0, get_base(), get_bonus(), get_percent());
|
||||
|
||||
stat->set_to_max();
|
||||
}
|
||||
|
||||
StatDataEntry() {
|
||||
_stat_id = Stat::STAT_ID_NONE;
|
||||
|
||||
_base = 0;
|
||||
_bonus = 0;
|
||||
_percent = 100;
|
||||
|
||||
_modifier_apply_type = Stat::MODIFIER_APPLY_TYPE_STANDARD;
|
||||
|
||||
_depends_on = Stat::STAT_ID_NONE;
|
||||
}
|
||||
StatDataEntry();
|
||||
~StatDataEntry();
|
||||
|
||||
protected:
|
||||
static void _bind_methods() {
|
||||
ClassDB::bind_method(D_METHOD("get_stat_id"), &StatDataEntry::get_stat_id);
|
||||
ClassDB::bind_method(D_METHOD("set_stat_id", "value"), &StatDataEntry::set_stat_id);
|
||||
ADD_PROPERTY(PropertyInfo(Variant::INT, "stat_id", PROPERTY_HINT_ENUM, Stat::STAT_BINDING_STRING), "set_stat_id", "get_stat_id");
|
||||
static void _bind_methods();
|
||||
void _validate_property(PropertyInfo &property) const;
|
||||
|
||||
ClassDB::bind_method(D_METHOD("get_base"), &StatDataEntry::get_base);
|
||||
ClassDB::bind_method(D_METHOD("set_base", "value"), &StatDataEntry::set_base);
|
||||
ADD_PROPERTY(PropertyInfo(Variant::REAL, "base"), "set_base", "get_base");
|
||||
public:
|
||||
struct ModStat {
|
||||
Stat::StatId stat_id;
|
||||
Ref<Curve> curve;
|
||||
};
|
||||
|
||||
ClassDB::bind_method(D_METHOD("get_bonus"), &StatDataEntry::get_bonus);
|
||||
ClassDB::bind_method(D_METHOD("set_bonus", "value"), &StatDataEntry::set_bonus);
|
||||
ADD_PROPERTY(PropertyInfo(Variant::REAL, "bonus"), "set_bonus", "get_bonus");
|
||||
|
||||
ClassDB::bind_method(D_METHOD("get_percent"), &StatDataEntry::get_percent);
|
||||
ClassDB::bind_method(D_METHOD("set_percent", "value"), &StatDataEntry::set_percent);
|
||||
ADD_PROPERTY(PropertyInfo(Variant::REAL, "percent"), "set_percent", "get_percent");
|
||||
|
||||
ClassDB::bind_method(D_METHOD("get_modifier_apply_type"), &StatDataEntry::get_modifier_apply_type);
|
||||
ClassDB::bind_method(D_METHOD("set_modifier_apply_type", "value"), &StatDataEntry::set_modifier_apply_type);
|
||||
ADD_PROPERTY(PropertyInfo(Variant::INT, "modifier_apply_type", PROPERTY_HINT_ENUM, Stat::MODIFIER_APPLY_TYPE_BINDING_STRING), "set_modifier_apply_type", "get_modifier_apply_type");
|
||||
|
||||
ClassDB::bind_method(D_METHOD("has_dependency"), &StatDataEntry::has_dependency);
|
||||
|
||||
ClassDB::bind_method(D_METHOD("get_depends_on"), &StatDataEntry::get_depends_on);
|
||||
ClassDB::bind_method(D_METHOD("set_depends_on", "value"), &StatDataEntry::set_depends_on);
|
||||
ADD_PROPERTY(PropertyInfo(Variant::INT, "depends_on", PROPERTY_HINT_ENUM, Stat::STAT_BINDING_STRING), "set_depends_on", "get_depends_on");
|
||||
|
||||
ClassDB::bind_method(D_METHOD("get_dependdency_curve"), &StatDataEntry::get_dependdency_curve);
|
||||
ClassDB::bind_method(D_METHOD("set_dependdency_curve", "value"), &StatDataEntry::set_dependdency_curve);
|
||||
ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "dependdency_curve", PROPERTY_HINT_RESOURCE_TYPE, "Curve"), "set_dependdency_curve", "get_dependdency_curve");
|
||||
|
||||
ClassDB::bind_method(D_METHOD("get_stats_for_stat", "stat"), &StatDataEntry::get_stats_for_stat);
|
||||
}
|
||||
enum {
|
||||
MAX_MOD_STATS = 3,
|
||||
};
|
||||
|
||||
private:
|
||||
Stat::StatId _stat_id;
|
||||
bool _public;
|
||||
float _base;
|
||||
float _bonus;
|
||||
float _percent;
|
||||
|
||||
Stat::StatModifierApplyType _modifier_apply_type;
|
||||
int _mod_stat_count;
|
||||
ModStat _mod_stats[MAX_MOD_STATS];
|
||||
|
||||
Stat::StatId _depends_on;
|
||||
Ref<Curve> _dependdency_curve;
|
||||
Stat::StatModifierApplyType _modifier_apply_type;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
Loading…
Reference in New Issue
Block a user