initial
This commit is contained in:
parent
2d7050a065
commit
f89d2ccf53
24 changed files with 324 additions and 30 deletions
3
modules/tabtargeting/SCsub
Normal file
3
modules/tabtargeting/SCsub
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
Import('env')
|
||||
|
||||
env.add_source_files(env.modules_sources, "*.cpp")
|
||||
BIN
modules/tabtargeting/__pycache__/config.cpython-313.pyc
Normal file
BIN
modules/tabtargeting/__pycache__/config.cpython-313.pyc
Normal file
Binary file not shown.
10
modules/tabtargeting/actor_body.cpp
Normal file
10
modules/tabtargeting/actor_body.cpp
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
#include "actor_body.h"
|
||||
#include "core/string/print_string.h"
|
||||
|
||||
void ActorBody::_bind_methods() {
|
||||
}
|
||||
|
||||
void ActorBody::receive_damage(DamageEvent event) {
|
||||
this->health -= event.compound_damage;
|
||||
print_line(vformat("Damage dealth (%d to %s, %d remaining", event.compound_damage, this->get_name(), this->health));
|
||||
}
|
||||
20
modules/tabtargeting/actor_body.h
Normal file
20
modules/tabtargeting/actor_body.h
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
#ifndef ACTOR_BODY_H
|
||||
#define ACTOR_BODY_H
|
||||
|
||||
#include "scene/3d/physics/character_body_3d.h"
|
||||
#include "equipment.h"
|
||||
class ActorBody;
|
||||
|
||||
class ActorBody : public CharacterBody3D {
|
||||
GDCLASS(ActorBody, CharacterBody3D);
|
||||
static void _bind_methods();
|
||||
public:
|
||||
void receive_damage(DamageEvent event);
|
||||
void send_damage(int amount, ActorBody *target);
|
||||
private:
|
||||
int health{10};
|
||||
int max_health{10};
|
||||
|
||||
class Equipment *equipment{nullptr};
|
||||
};
|
||||
#endif // !ACTOR_BODY_H
|
||||
13
modules/tabtargeting/actor_state_machine.h
Normal file
13
modules/tabtargeting/actor_state_machine.h
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
#ifndef ACTOR_STATE_MACHINE_H
|
||||
#define ACTOR_STATE_MACHINE_H
|
||||
|
||||
#include "scene/main/node.h"
|
||||
|
||||
class ActorStateMachine : public Node {
|
||||
GDCLASS(ActorStateMachine, Node);
|
||||
static void _bind_methods();
|
||||
public:
|
||||
private:
|
||||
};
|
||||
|
||||
#endif // !ACTOR_STATE_MACHINE_H
|
||||
5
modules/tabtargeting/config.py
Normal file
5
modules/tabtargeting/config.py
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
def can_build(env, platform):
|
||||
return True;
|
||||
|
||||
def configure(env):
|
||||
pass;
|
||||
138
modules/tabtargeting/equipment.cpp
Normal file
138
modules/tabtargeting/equipment.cpp
Normal file
|
|
@ -0,0 +1,138 @@
|
|||
#include "equipment.h"
|
||||
#include "macros.h"
|
||||
#include "tabtargeting/actor_body.h"
|
||||
|
||||
DamageEvent::DamageEvent(int damage, ActorBody *source)
|
||||
: compound_damage{damage}
|
||||
, initial_damage{damage}
|
||||
, source{source}
|
||||
{}
|
||||
|
||||
void DamageStats::_bind_methods() {
|
||||
BIND_PROPERTY(Variant::INT, damage_add);
|
||||
BIND_PROPERTY(Variant::INT, damage_mul);
|
||||
BIND_PROPERTY(Variant::INT, defend_add);
|
||||
BIND_PROPERTY(Variant::INT, defend_mul);
|
||||
}
|
||||
|
||||
DamageEvent DamageStats::apply(DamageEvent event, ActorBody *owner) {
|
||||
if(owner == event.get_source()) {
|
||||
event.compound_damage *= this->damage_mul;
|
||||
event.compound_damage += this->damage_add;
|
||||
} else {
|
||||
event.compound_damage *= this->defend_mul;
|
||||
event.compound_damage += this->defend_add;
|
||||
}
|
||||
return event;
|
||||
}
|
||||
|
||||
void DamageStats::set_damage_add(int val) {
|
||||
this->damage_add = val;
|
||||
}
|
||||
int DamageStats::get_damage_add() const {
|
||||
return this->damage_add;
|
||||
}
|
||||
void DamageStats::set_damage_mul(float val) {
|
||||
this->damage_mul = val;
|
||||
}
|
||||
float DamageStats::get_damage_mul() const {
|
||||
return this->damage_mul;
|
||||
}
|
||||
void DamageStats::set_defend_add(int val) {
|
||||
this->defend_add = val;
|
||||
}
|
||||
int DamageStats::get_defend_add() const {
|
||||
return this->defend_add;
|
||||
}
|
||||
void DamageStats::set_defend_mul(float val) {
|
||||
this->defend_mul = val;
|
||||
}
|
||||
float DamageStats::get_defend_mul() const {
|
||||
return this->defend_mul;
|
||||
}
|
||||
|
||||
void EquipItem::_bind_methods() {
|
||||
BIND_HPROPERTY(Variant::OBJECT, stats, PROPERTY_HINT_RESOURCE_TYPE, "DamageStats");
|
||||
}
|
||||
|
||||
DamageEvent EquipItem::apply(DamageEvent event, ActorBody *owner) {
|
||||
return this->stats->apply(event, owner);
|
||||
}
|
||||
|
||||
void EquipItem::set_stats(Ref<DamageStats> stats) {
|
||||
this->stats = stats;
|
||||
}
|
||||
|
||||
Ref<DamageStats> EquipItem::get_stats() const {
|
||||
return this->stats;
|
||||
}
|
||||
|
||||
void Weapon::_bind_methods() {
|
||||
BIND_PROPERTY(Variant::INT, base_damage);
|
||||
}
|
||||
|
||||
void Weapon::set_base_damage(int amount) {
|
||||
this->base_damage = amount;
|
||||
}
|
||||
|
||||
int Weapon::get_base_damage() const {
|
||||
return this->base_damage;
|
||||
}
|
||||
|
||||
DamageEvent Weapon::create_base_damage_event(ActorBody *source) {
|
||||
return DamageEvent(this->base_damage, source);
|
||||
}
|
||||
|
||||
void Armor::_bind_methods() {
|
||||
BIND_HPROPERTY(Variant::INT, armor_type, PROPERTY_HINT_ENUM, "Helmet, Chest, Legs");
|
||||
}
|
||||
void Armor::set_armor_type(int type) {
|
||||
this->type = ArmorType(type);
|
||||
}
|
||||
int Armor::get_armor_type() const {
|
||||
return this->type;
|
||||
}
|
||||
|
||||
void Equipment::_bind_methods() {
|
||||
BIND_HPROPERTY(Variant::OBJECT, weapon, PROPERTY_HINT_RESOURCE_TYPE, "Weapon");
|
||||
BIND_HPROPERTY(Variant::OBJECT, helmet, PROPERTY_HINT_RESOURCE_TYPE, "Armor");
|
||||
BIND_HPROPERTY(Variant::OBJECT, chest, PROPERTY_HINT_RESOURCE_TYPE, "Armor");
|
||||
BIND_HPROPERTY(Variant::OBJECT, legs, PROPERTY_HINT_RESOURCE_TYPE, "Armor");
|
||||
}
|
||||
|
||||
DamageEvent Equipment::apply(DamageEvent event, ActorBody *target) {
|
||||
|
||||
}
|
||||
|
||||
void Equipment::set_weapon(Ref<Weapon> weapon) {
|
||||
this->weapon = weapon;
|
||||
}
|
||||
|
||||
Ref<Weapon> Equipment::get_weapon() const {
|
||||
return this->weapon;
|
||||
}
|
||||
|
||||
void Equipment::set_helmet(Ref<Armor> helmet) {
|
||||
this->helmet = helmet;
|
||||
}
|
||||
|
||||
Ref<Armor> Equipment::get_helmet() const {
|
||||
return this->helmet;
|
||||
}
|
||||
|
||||
void Equipment::set_chest(Ref<Armor> chest) {
|
||||
this->chest = chest;
|
||||
}
|
||||
|
||||
Ref<Armor> Equipment::get_chest() const {
|
||||
return this->chest;
|
||||
}
|
||||
|
||||
void Equipment::set_legs(Ref<Armor> legs) {
|
||||
this->legs = legs;
|
||||
}
|
||||
|
||||
Ref<Armor> Equipment::get_legs() const {
|
||||
return this->legs;
|
||||
}
|
||||
|
||||
104
modules/tabtargeting/equipment.h
Normal file
104
modules/tabtargeting/equipment.h
Normal file
|
|
@ -0,0 +1,104 @@
|
|||
#ifndef EQUIPMENT_H
|
||||
#define EQUIPMENT_H
|
||||
|
||||
#include "core/io/resource.h"
|
||||
#include "core/templates/vector.h"
|
||||
#include "scene/main/node.h"
|
||||
class ActorBody;
|
||||
|
||||
struct DamageEvent {
|
||||
DamageEvent(int damage, ActorBody *source);
|
||||
int compound_damage{1};
|
||||
int get_initial_damage() const;
|
||||
ActorBody *get_source() const;
|
||||
private:
|
||||
int initial_damage{1};
|
||||
ActorBody *source{nullptr};
|
||||
};
|
||||
|
||||
class DamageModifier {
|
||||
public:
|
||||
virtual DamageEvent apply(DamageEvent event, ActorBody *target) = 0;
|
||||
};
|
||||
|
||||
class DamageStats : public Resource,
|
||||
public DamageModifier {
|
||||
GDCLASS(DamageStats, Resource);
|
||||
static void _bind_methods();
|
||||
public:
|
||||
virtual DamageEvent apply(DamageEvent event, ActorBody *target) override;
|
||||
void set_damage_add(int val);
|
||||
int get_damage_add() const;
|
||||
void set_damage_mul(float val);
|
||||
float get_damage_mul() const;
|
||||
void set_defend_add(int val);
|
||||
int get_defend_add() const;
|
||||
void set_defend_mul(float val);
|
||||
float get_defend_mul() const;
|
||||
public:
|
||||
int damage_add{0};
|
||||
float damage_mul{1.f};
|
||||
int defend_add{0};
|
||||
float defend_mul{1.f};
|
||||
};
|
||||
|
||||
class EquipItem : public Resource,
|
||||
public DamageModifier {
|
||||
GDCLASS(EquipItem, Resource);
|
||||
static void _bind_methods();
|
||||
public:
|
||||
virtual DamageEvent apply(DamageEvent event, ActorBody *target) override;
|
||||
void set_stats(Ref<DamageStats> stats);
|
||||
Ref<DamageStats> get_stats() const;
|
||||
private:
|
||||
Ref<DamageStats> stats{};
|
||||
};
|
||||
|
||||
class Weapon : public EquipItem {
|
||||
GDCLASS(Weapon, EquipItem);
|
||||
static void _bind_methods();
|
||||
public:
|
||||
void set_base_damage(int amount);
|
||||
int get_base_damage() const;
|
||||
|
||||
DamageEvent create_base_damage_event(ActorBody *source);
|
||||
private:
|
||||
int base_damage{1};
|
||||
};
|
||||
|
||||
enum ArmorType {
|
||||
Helmet, Chest, Legs
|
||||
};
|
||||
|
||||
class Armor : public EquipItem {
|
||||
GDCLASS(Armor, EquipItem);
|
||||
static void _bind_methods();
|
||||
public:
|
||||
void set_armor_type(int type);
|
||||
int get_armor_type() const;
|
||||
private:
|
||||
ArmorType type{};
|
||||
};
|
||||
|
||||
class Equipment : public Node,
|
||||
public DamageModifier {
|
||||
GDCLASS(Equipment, Node);
|
||||
static void _bind_methods();
|
||||
public:
|
||||
virtual DamageEvent apply(DamageEvent event, ActorBody *target) override;
|
||||
void set_weapon(Ref<Weapon> weapon);
|
||||
Ref<Weapon> get_weapon() const;
|
||||
void set_helmet(Ref<Armor> helmet);
|
||||
Ref<Armor> get_helmet() const;
|
||||
void set_chest(Ref<Armor> chest);
|
||||
Ref<Armor> get_chest() const;
|
||||
void set_legs(Ref<Armor> legs);
|
||||
Ref<Armor> get_legs() const;
|
||||
private:
|
||||
Ref<Weapon> weapon{};
|
||||
Ref<Armor> helmet{};
|
||||
Ref<Armor> chest{};
|
||||
Ref<Armor> legs{};
|
||||
};
|
||||
|
||||
#endif // !EQUIPMENT_H
|
||||
16
modules/tabtargeting/macros.h
Normal file
16
modules/tabtargeting/macros.h
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
#ifndef GODOT_EXTRA_MACROS_H
|
||||
#define GODOT_EXTRA_MACROS_H
|
||||
|
||||
#define BIND_GET_SET(m_property)\
|
||||
ClassDB::bind_method(D_METHOD("set_" #m_property, #m_property), &self_type::set_##m_property);\
|
||||
ClassDB::bind_method(D_METHOD("get_" #m_property), &self_type::get_##m_property)
|
||||
|
||||
#define BIND_HPROPERTY(m_type, m_property, ...)\
|
||||
BIND_GET_SET(m_property);\
|
||||
ADD_PROPERTY(PropertyInfo(m_type, #m_property, __VA_ARGS__), "set_" #m_property, "get_" #m_property)
|
||||
|
||||
#define BIND_PROPERTY(m_type, m_property)\
|
||||
BIND_GET_SET(m_property);\
|
||||
ADD_PROPERTY(PropertyInfo(m_type, #m_property), "set_" #m_property, "get_" #m_property)
|
||||
|
||||
#endif // !GODOT_EXTRA_MACROS_H
|
||||
23
modules/tabtargeting/register_types.cpp
Normal file
23
modules/tabtargeting/register_types.cpp
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
#include "register_types.h"
|
||||
|
||||
#include "core/object/class_db.h"
|
||||
#include "tabtargeting/equipment.h"
|
||||
#include "tabtargeting/actor_body.h"
|
||||
|
||||
void initialize_tabtargeting_module(ModuleInitializationLevel p_level) {
|
||||
if (p_level != MODULE_INITIALIZATION_LEVEL_SCENE) {
|
||||
return;
|
||||
}
|
||||
ClassDB::register_class<ActorBody>();
|
||||
ClassDB::register_class<DamageStats>();
|
||||
ClassDB::register_class<EquipItem>();
|
||||
ClassDB::register_class<Weapon>();
|
||||
ClassDB::register_class<Armor>();
|
||||
ClassDB::register_class<Equipment>();
|
||||
}
|
||||
|
||||
void uninitialize_tabtargeting_module(ModuleInitializationLevel p_level) {
|
||||
if (p_level != MODULE_INITIALIZATION_LEVEL_SCENE) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
9
modules/tabtargeting/register_types.h
Normal file
9
modules/tabtargeting/register_types.h
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
#ifndef tabtargeting_REGISTER_TYPES_H
|
||||
#define tabtargeting_REGISTER_TYPES_H
|
||||
|
||||
#include "modules/register_module_types.h"
|
||||
|
||||
void initialize_tabtargeting_module(ModuleInitializationLevel p_level);
|
||||
void uninitialize_tabtargeting_module(ModuleInitializationLevel p_level);
|
||||
|
||||
#endif // !tabtargeting_REGISTER_TYPES_H
|
||||
Loading…
Add table
Add a link
Reference in a new issue