mirror of
https://github.com/Relintai/entity_spell_system.git
synced 2025-04-17 21:26:35 +02:00
More from_dicts.
This commit is contained in:
parent
8cafa3bf7d
commit
e0183a53c6
@ -234,7 +234,6 @@ Dictionary AuraData::_to_dict() {
|
||||
dict["aura_id"] = _aura_id;
|
||||
dict["remaining_time"] = _remaining_time;
|
||||
dict["caster_name"] = _caster->get_name();
|
||||
dict["spell_scale"] = _spell_scale;
|
||||
|
||||
dict["spell_scale"] = _spell_scale;
|
||||
dict["aura_group"] = _aura_group;
|
||||
@ -254,6 +253,34 @@ Dictionary AuraData::_to_dict() {
|
||||
}
|
||||
void AuraData::_from_dict(const Dictionary &dict) {
|
||||
ERR_FAIL_COND(dict.empty());
|
||||
|
||||
_aura_id = dict.get("aura_id", 0);
|
||||
_remaining_time = dict.get("remaining_time", 0);
|
||||
String caster_name = dict.get("caster_name", "");
|
||||
|
||||
_spell_scale = dict.get("spell_scale", 0);
|
||||
|
||||
_aura_group = dict.get("aura_group", 0);
|
||||
int aura_id = dict.get("aura_id", 0);
|
||||
|
||||
if (DataManager::get_instance() != NULL) {
|
||||
Ref<Aura> aura = DataManager::get_instance()->get_aura(aura_id);
|
||||
|
||||
if (aura.is_valid()) {
|
||||
_aura = aura;
|
||||
}
|
||||
}
|
||||
|
||||
_is_timed = dict.get("is_timed", true);
|
||||
_damage = dict.get("damage", 0);
|
||||
_heal = dict.get("heal", 0);
|
||||
_slow = dict.get("slow", 0);
|
||||
_remaining_absorb = dict.get("remaining_absorb", 0);
|
||||
|
||||
_tick = dict.get("tick", 0);
|
||||
_time_since_last_tick = dict.get("time_since_last_tick", 0);
|
||||
_damage_already_taken = dict.get("damage_already_taken", 0);
|
||||
_unhandled_ticks = dict.get("unhandled_ticks", 0);
|
||||
}
|
||||
|
||||
AuraData::AuraData() {
|
||||
|
@ -443,7 +443,7 @@ void Entity::_from_dict(const Dictionary &dict) {
|
||||
|
||||
Dictionary auras = dict.get("auras", Dictionary());
|
||||
|
||||
for (int i = 0; i < _s_auras.size(); ++i) {
|
||||
for (int i = 0; i < auras.size(); ++i) {
|
||||
Ref<AuraData> r;
|
||||
r.instance();
|
||||
|
||||
@ -501,7 +501,7 @@ void Entity::_from_dict(const Dictionary &dict) {
|
||||
for (int i = 0; i < known_spells.size(); ++i) {
|
||||
int spell_id = known_spells.get(i, 0);
|
||||
|
||||
if (DataManager::get_instance() == NULL) {
|
||||
if (DataManager::get_instance() != NULL) {
|
||||
Ref<Spell> sp = DataManager::get_instance()->get_spell(spell_id);
|
||||
|
||||
if (sp.is_valid()) {
|
||||
|
@ -135,6 +135,12 @@ Dictionary EntityResource::_to_dict() {
|
||||
}
|
||||
void EntityResource::_from_dict(const Dictionary &dict) {
|
||||
ERR_FAIL_COND(dict.empty());
|
||||
|
||||
_dirty = dict.get("dirty", false);
|
||||
_should_process = dict.get("should_process", false);
|
||||
_type = dict.get("type", 0);
|
||||
_current = dict.get("current", 0);
|
||||
_max = dict.get("max", 0);
|
||||
}
|
||||
|
||||
EntityResource::EntityResource() {
|
||||
|
@ -55,6 +55,11 @@ Dictionary EntitySkill::_to_dict() {
|
||||
}
|
||||
void EntitySkill::_from_dict(const Dictionary &dict) {
|
||||
ERR_FAIL_COND(dict.empty());
|
||||
|
||||
_skill_id = dict.get("skill_id", 0);
|
||||
_current = dict.get("current", 0);
|
||||
_max = dict.get("max", 0);
|
||||
_disabled = dict.get("disabled", true);
|
||||
}
|
||||
|
||||
EntitySkill::EntitySkill() {
|
||||
|
@ -4,7 +4,6 @@ const String Stat::STAT_BINDING_STRING = "Health,Speed,Mana,GCD,Haste,Agility,St
|
||||
|
||||
const String Stat::MODIFIER_APPLY_TYPE_BINDING_STRING = "Standard,Only min modifier,Only Max modifier";
|
||||
|
||||
|
||||
_FORCE_INLINE_ Vector<Ref<StatModifier> > *Stat::get_modifiers() {
|
||||
return &_modifiers;
|
||||
}
|
||||
@ -116,7 +115,7 @@ void Stat::apply_modifier(Ref<StatModifier> modifier) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
recalculate();
|
||||
emit_signal("s_changed", Ref<Stat>(this));
|
||||
send();
|
||||
@ -156,7 +155,7 @@ void Stat::de_apply_modifier(Ref<StatModifier> modifier) {
|
||||
recalculate();
|
||||
emit_signal("s_changed", Ref<Stat>(this));
|
||||
send();
|
||||
|
||||
|
||||
// emit_signal("s_changed", Ref<Stat>(this));
|
||||
}
|
||||
|
||||
@ -174,7 +173,7 @@ void Stat::re_apply_modifiers() {
|
||||
} else {
|
||||
re_apply_modifier_not_negative_stacking_percents();
|
||||
}
|
||||
|
||||
|
||||
recalculate();
|
||||
emit_signal("s_changed", Ref<Stat>(this));
|
||||
send();
|
||||
@ -219,7 +218,7 @@ void Stat::re_apply_modifier_not_negative_stacking_percents() {
|
||||
recalculate();
|
||||
emit_signal("s_changed", Ref<Stat>(this));
|
||||
send();
|
||||
|
||||
|
||||
// emit_signal("s_changed", Ref<Stat>(this));
|
||||
}
|
||||
|
||||
@ -320,13 +319,13 @@ void Stat::reset_values() {
|
||||
|
||||
void Stat::recalculate() {
|
||||
float diff = _s_current / _s_max;
|
||||
|
||||
|
||||
_s_max = (_base + _bonus) * (_percent / 100.0);
|
||||
|
||||
if (_s_current > _s_max) {
|
||||
_s_current = _s_max;
|
||||
}
|
||||
|
||||
|
||||
_s_current = _s_max * diff;
|
||||
|
||||
_dirty = true;
|
||||
@ -339,7 +338,6 @@ void Stat::send() {
|
||||
emit_signal("c_changed", Ref<Stat>(this));
|
||||
}
|
||||
|
||||
|
||||
bool Stat::iss_current_zero() {
|
||||
return (fabs(_s_current) < .000001);
|
||||
}
|
||||
@ -429,6 +427,35 @@ Dictionary Stat::_to_dict() {
|
||||
}
|
||||
void Stat::_from_dict(const Dictionary &dict) {
|
||||
ERR_FAIL_COND(dict.empty());
|
||||
|
||||
_id = (Stat::StatId)((int)dict.get("id", 0));
|
||||
_modifier_apply_type = (StatModifierApplyType)((int)dict.get("modifier_apply_type", 0));
|
||||
|
||||
_locked = dict.get("locked", false);
|
||||
_dirty = dict.get("dirty", false);
|
||||
|
||||
_base = dict.get("base", 0);
|
||||
_bonus = dict.get("bonus", 0);
|
||||
_percent = dict.get("percent", 1);
|
||||
|
||||
_s_current = dict.get("current", 0);
|
||||
_s_max = dict.get("max", 0);
|
||||
|
||||
_c_current = _s_current;
|
||||
_c_max = _s_max;
|
||||
|
||||
_modifiers.clear();
|
||||
|
||||
Dictionary modifiers = dict.get("modifiers", Dictionary());
|
||||
|
||||
for (int i = 0; i < modifiers.size(); ++i) {
|
||||
Ref<StatModifier> sm;
|
||||
sm.instance();
|
||||
|
||||
sm->from_dict(modifiers.get(i, Dictionary()));
|
||||
|
||||
_modifiers.push_back(sm);
|
||||
}
|
||||
}
|
||||
|
||||
Stat::Stat() {
|
||||
@ -586,7 +613,6 @@ void Stat::_bind_methods() {
|
||||
//ClassDB::bind_method(D_METHOD("de_apply_modifier", "modifier"), &Stat::de_apply_modifier);
|
||||
ClassDB::bind_method(D_METHOD("re_apply_modifier_not_negative_stacking_percents"), &Stat::re_apply_modifier_not_negative_stacking_percents);
|
||||
|
||||
|
||||
ClassDB::bind_method(D_METHOD("add_modifier", "id", "base_mod", "bonus_mod", "percent_mod", "apply"), &Stat::add_modifier);
|
||||
ClassDB::bind_method(D_METHOD("remove_modifier", "id", "apply"), &Stat::remove_modifier);
|
||||
ClassDB::bind_method(D_METHOD("re_apply_modifiers"), &Stat::re_apply_modifiers);
|
||||
|
@ -50,6 +50,9 @@ Dictionary CategoryCooldown::_to_dict() {
|
||||
}
|
||||
void CategoryCooldown::_from_dict(const Dictionary &dict) {
|
||||
ERR_FAIL_COND(dict.empty());
|
||||
|
||||
_category_id = dict.get("category_id", 0);
|
||||
_remaining = dict.get("remaining", 0);
|
||||
}
|
||||
|
||||
|
||||
|
@ -50,6 +50,9 @@ Dictionary Cooldown::_to_dict() {
|
||||
}
|
||||
void Cooldown::_from_dict(const Dictionary &dict) {
|
||||
ERR_FAIL_COND(dict.empty());
|
||||
|
||||
_spell_id = dict.get("spell_id", 0);
|
||||
_remaining = dict.get("remaining", 0);
|
||||
}
|
||||
|
||||
void Cooldown::_bind_methods() {
|
||||
|
Loading…
Reference in New Issue
Block a user