Merged Mob and Player into Entity.

This commit is contained in:
Relintai 2019-11-04 01:38:27 +01:00
parent bac30cf901
commit 0d98a36668
8 changed files with 110 additions and 105 deletions

2
SCsub
View File

@ -80,8 +80,6 @@ module_env.add_source_files(env.modules_sources,"pipelines/spell_damage_info.cpp
module_env.add_source_files(env.modules_sources,"pipelines/spell_heal_info.cpp")
module_env.add_source_files(env.modules_sources,"entities/auras/aura_data.cpp")
module_env.add_source_files(env.modules_sources,"entities/entity.cpp")
module_env.add_source_files(env.modules_sources,"entities/player.cpp")
module_env.add_source_files(env.modules_sources,"entities/mob.cpp")
module_env.add_source_files(env.modules_sources,"entities/entity_resource.cpp")
module_env.add_source_files(env.modules_sources,"ui/unit_frame.cpp")

View File

@ -240,6 +240,30 @@ void Entity::setc_entity_data(Ref<EntityData> value) {
emit_signal("centity_data_changed", value);
}
EntityEnums::AIStates Entity::gets_ai_state() const {
return _sai_state;
}
void Entity::sets_ai_state(EntityEnums::AIStates state) {
_sai_state = state;
}
int Entity::gets_seed() {
return _s_seed;
}
void Entity::sets_seed(int value) {
_s_seed = value;
ORPC(setc_seed, value);
}
int Entity::getc_seed() {
return _c_seed;
}
void Entity::setc_seed(int value) {
_c_seed = value;
}
void Entity::setup() {
if (has_method("_setup")) {
call_multilevel("_setup");
@ -343,6 +367,42 @@ void Entity::_setup() {
set_process(_s_entity_data.is_valid());
}
void Entity::setup_actionbars() {
if (!gets_entity_data().is_valid())
return;
if (is_deserialized()) {
return;
}
ProfileManager *pm = ProfileManager::get_instance();
if (pm != NULL) {
Ref<ClassProfile> cp = pm->get_class_profile(gets_entity_data()->get_id());
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()) {
Ref<Bag> bag;
bag.instance();
bag->set_size(gets_entity_data()->get_bag_size());
sets_bag(bag);
}
}
// AI
int Entity::get_formation_index() {
@ -388,6 +448,7 @@ Dictionary Entity::_to_dict() {
dict["level"] = _s_level;
dict["xp"] = _s_xp;
dict["money"] = _s_money;
dict["seed"] = _s_seed;
if (_s_entity_data.is_valid())
dict["entity_data_id"] = _s_entity_data->get_id();
@ -560,6 +621,8 @@ void Entity::_from_dict(const Dictionary &dict) {
sets_entity_name(dict.get("entity_name", ""));
sets_seed(dict.get("seed", _s_seed));
//// Stats ////
Dictionary stats = dict.get("stats", Dictionary());
@ -4505,6 +4568,11 @@ Entity::Entity() {
_s_interaction_type = EntityEnums::ENITIY_INTERACTION_TYPE_NORMAL;
_c_interaction_type = EntityEnums::ENITIY_INTERACTION_TYPE_NORMAL;
_sai_state = EntityEnums::AI_STATE_OFF;
_s_seed = 0;
_c_seed = _s_seed;
for (int i = 0; i < EntityEnums::ENTITY_STATE_TYPE_INDEX_MAX; ++i) {
_s_states[i] = 0;
}
@ -4555,6 +4623,7 @@ Entity::Entity() {
SET_RPC_REMOTE("setc_gender");
SET_RPC_REMOTE("setc_level");
SET_RPC_REMOTE("setc_xp");
SET_RPC_REMOTE("setc_seed");
//EntityType
@ -4876,6 +4945,7 @@ void Entity::_bind_methods() {
ClassDB::bind_method(D_METHOD("setup"), &Entity::setup);
ClassDB::bind_method(D_METHOD("_setup"), &Entity::_setup);
ClassDB::bind_method(D_METHOD("setup_actionbars"), &Entity::setup_actionbars);
//binds
@ -5198,6 +5268,18 @@ void Entity::_bind_methods() {
ClassDB::bind_method(D_METHOD("setc_entity_type", "value"), &Entity::sets_entity_type);
ADD_PROPERTY(PropertyInfo(Variant::INT, "centity_type", PROPERTY_HINT_ENUM, EntityEnums::BINDING_STRING_ENTITY_TYPES), "setc_entity_type", "getc_entity_type");
ClassDB::bind_method(D_METHOD("gets_ai_state"), &Entity::gets_ai_state);
ClassDB::bind_method(D_METHOD("sets_ai_state", "value"), &Entity::sets_ai_state);
ADD_PROPERTY(PropertyInfo(Variant::INT, "ai_state", PROPERTY_HINT_ENUM, EntityEnums::BINDING_STRING_AI_STATES), "sets_ai_state", "gets_ai_state");
ClassDB::bind_method(D_METHOD("gets_seed"), &Entity::gets_seed);
ClassDB::bind_method(D_METHOD("sets_seed", "value"), &Entity::sets_seed);
ADD_PROPERTY(PropertyInfo(Variant::INT, "sseed"), "sets_seed", "gets_seed");
ClassDB::bind_method(D_METHOD("getc_seed"), &Entity::getc_seed);
ClassDB::bind_method(D_METHOD("setc_seed", "value"), &Entity::setc_seed);
ADD_PROPERTY(PropertyInfo(Variant::INT, "cseed"), "setc_seed", "getc_seed");
//Interaction type
ClassDB::bind_method(D_METHOD("gets_entity_interaction_type"), &Entity::gets_entity_interaction_type);
ClassDB::bind_method(D_METHOD("sets_entity_interaction_type", "value"), &Entity::sets_entity_interaction_type);

View File

@ -40,6 +40,9 @@
#include "../data/aura_group.h"
#include "../profile_manager/input/input_profile.h"
#include "../profile_manager/profile_manager.h"
class EntityData;
class AuraData;
class Spell;
@ -243,6 +246,15 @@ public:
int getc_entity_data_id();
void setc_entity_data_id(int value);
EntityEnums::AIStates gets_ai_state() const;
void sets_ai_state(EntityEnums::AIStates state);
int gets_seed();
void sets_seed(int value);
int getc_seed();
void setc_seed(int value);
//// Stats ////
_FORCE_INLINE_ Ref<Stat> get_health() { return _stats[Stat::STAT_ID_HEALTH]; }
@ -740,6 +752,7 @@ public:
void setup();
virtual void _setup();
void setup_actionbars();
//// AI ////
@ -836,6 +849,11 @@ private:
int _s_is_dead;
int _c_is_dead;
EntityEnums::AIStates _sai_state;
int _s_seed;
int _c_seed;
//// Stats ////
Ref<Stat> _stats[Stat::STAT_ID_TOTAL_STATS];

View File

@ -1,19 +1,12 @@
#include "mob.h"
EntityEnums::AIStates Mob::gets_ai_state() const {
return _sai_state;
}
void Mob::sets_ai_state(EntityEnums::AIStates state) {
_sai_state = state;
}
Mob::Mob() : Entity() {
_sai_state = EntityEnums::AI_STATE_OFF;
}
void Mob::_bind_methods() {
ClassDB::bind_method(D_METHOD("gets_ai_state"), &Mob::gets_ai_state);
ClassDB::bind_method(D_METHOD("sets_ai_state", "value"), &Mob::sets_ai_state);
ADD_PROPERTY(PropertyInfo(Variant::INT, "ai_state", PROPERTY_HINT_ENUM, EntityEnums::BINDING_STRING_AI_STATES), "sets_ai_state", "gets_ai_state");
}

View File

@ -10,14 +10,13 @@ class Mob : public Entity {
public:
Mob();
EntityEnums::AIStates gets_ai_state() const;
void sets_ai_state(EntityEnums::AIStates state);
protected:
static void _bind_methods();
private:
EntityEnums::AIStates _sai_state;
};
#endif

View File

@ -2,85 +2,19 @@
#include "../inventory/bag.h"
int Player::gets_seed() {
return _s_seed;
}
void Player::sets_seed(int value) {
_s_seed = value;
ORPC(setc_seed, value);
}
int Player::getc_seed() {
return _c_seed;
}
void Player::setc_seed(int value) {
_c_seed = value;
}
//Ref<InputProfile> Player::get_input_profile() {
// return _input_profile;
//}
void Player::_setup() {
Entity::_setup();
if (!gets_entity_data().is_valid())
return;
if (is_deserialized()) {
return;
}
ProfileManager *pm = ProfileManager::get_instance();
if (pm != NULL) {
Ref<ClassProfile> cp = pm->get_class_profile(gets_entity_data()->get_id());
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()) {
Ref<Bag> bag;
bag.instance();
bag->set_size(gets_entity_data()->get_bag_size());
sets_bag(bag);
}
}
Dictionary Player::_to_dict() {
Dictionary dict = Entity::_to_dict();
dict["seed"] = _s_seed;
return dict;
}
void Player::_from_dict(const Dictionary &dict) {
Entity::_from_dict(dict);
sets_seed(dict.get("seed", _s_seed));
}
Player::Player() {
_s_seed = 0;
_c_seed = _s_seed;
//_input_profile = Ref<InputProfile>(memnew(InputProfile()));
SET_RPC_REMOTE("setc_seed");
}
Player::~Player() {
@ -88,13 +22,7 @@ Player::~Player() {
}
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);
ADD_PROPERTY(PropertyInfo(Variant::INT, "sseed"), "sets_seed", "gets_seed");
ClassDB::bind_method(D_METHOD("getc_seed"), &Player::getc_seed);
ClassDB::bind_method(D_METHOD("setc_seed", "value"), &Player::setc_seed);
ADD_PROPERTY(PropertyInfo(Variant::INT, "cseed"), "setc_seed", "getc_seed");
//ClassDB::bind_method(D_METHOD("get_input_profile"), &Player::get_input_profile);
}

View File

@ -3,8 +3,7 @@
#include "entity.h"
#include "../profile_manager/input/input_profile.h"
#include "../profile_manager/profile_manager.h"
class Bag;
@ -12,11 +11,7 @@ class Player : public Entity {
GDCLASS(Player, Entity);
public:
int gets_seed();
void sets_seed(int value);
int getc_seed();
void setc_seed(int value);
//// Profiles ////
@ -24,9 +19,6 @@ public:
void _setup();
Dictionary _to_dict();
void _from_dict(const Dictionary &dict);
Player();
~Player();
@ -34,8 +26,7 @@ protected:
static void _bind_methods();
private:
int _s_seed;
int _c_seed;
//Ref<InputProfile> _input_profile;
};

View File

@ -63,8 +63,6 @@
#include "entities/entity_resource.h"
#include "entities/auras/aura_data.h"
#include "entities/entity.h"
#include "entities/player.h"
#include "entities/mob.h"
#include "data/aura_trigger_data.h"
#include "data/aura_stat_attribute.h"
@ -199,8 +197,6 @@ void register_entity_spell_system_types() {
//entities
ClassDB::register_class<EntityCreateInfo>();
ClassDB::register_class<Entity>();
ClassDB::register_class<Player>();
ClassDB::register_class<Mob>();
//spellinfos
ClassDB::register_class<SpellCastInfo>();