Enemy.cpp 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266
  1. /*
  2. * Copyright (C) 2022 The V-Gears Team
  3. *
  4. * This file is part of V-Gears
  5. *
  6. * V-Gears is free software: you can redistribute it and/or modify it under
  7. * terms of the GNU General Public License as published by the Free Software
  8. * Foundation, version 3.0 (GPLv3) of the License.
  9. *
  10. * V-Gears is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. */
  15. #include <OgreSceneNode.h>
  16. #include <OgreMaterialManager.h>
  17. #include "core/Enemy.h"
  18. #include "core/ConfigVar.h"
  19. #include "core/DebugDraw.h"
  20. #include "core/Logger.h"
  21. #include "core/XmlEnemyFile.h"
  22. Enemy::Enemy(const unsigned int id):
  23. id_(id),
  24. name_("UNKNOWN"),
  25. level_(1),
  26. exp_(0),
  27. ap_(0),
  28. money_(0),
  29. morph_(-1),
  30. back_damage_(1.5f),
  31. str_(0),
  32. mag_(0),
  33. def_(0),
  34. spr_(0),
  35. dex_(0),
  36. lck_(0),
  37. eva_(0),
  38. meva_(0),
  39. hp_(1),
  40. mp_(0),
  41. hp_max_(1),
  42. mp_max_(0),
  43. pos_(Ogre::Vector3(0, 0, 0)),
  44. front_(false),
  45. visible_(false),
  46. active_(false),
  47. cover_("00000")
  48. {
  49. ReadFromXml();
  50. LOG_TRIVIAL("Enemy " + std::to_string(id_) + " '" + name_ + "' created.");
  51. }
  52. Enemy::Enemy(
  53. const unsigned int id, const Ogre::Vector3 pos, const bool front, const bool visible,
  54. const bool targeteable, const bool active, const std::string cover
  55. ):
  56. id_(id),
  57. name_("UNKNOWN"),
  58. level_(1),
  59. exp_(0),
  60. ap_(0),
  61. money_(0),
  62. morph_(-1),
  63. back_damage_(1.5f),
  64. str_(0),
  65. mag_(0),
  66. def_(0),
  67. spr_(0),
  68. dex_(0),
  69. lck_(0),
  70. eva_(0),
  71. meva_(0),
  72. hp_(1),
  73. mp_(0),
  74. hp_max_(1),
  75. mp_max_(0),
  76. pos_(pos),
  77. front_(front),
  78. visible_(visible),
  79. active_(active),
  80. cover_(cover)
  81. {
  82. ReadFromXml();
  83. LOG_TRIVIAL("Enemy " + std::to_string(id_) + " '" + name_ + "' created.");
  84. }
  85. Enemy::~Enemy(){
  86. LOG_TRIVIAL("Enemy " + std::to_string(id_) + " '" + name_ + "' destroyed.");
  87. }
  88. const int Enemy::GetId() const{return id_;}
  89. void Enemy::SetId(const int id){id_ = id;}
  90. const std::string Enemy::GetModel() const{return model_;}
  91. void Enemy::SetModel(const std::string model){model_ = model;}
  92. const std::string Enemy::GetName() const{return name_;}
  93. void Enemy::SetName(const Ogre::String& name){name_ = name;}
  94. unsigned int Enemy::GetLevel() const{return level_;}
  95. void Enemy::SetLevel(const unsigned int level){level_ = level;}
  96. unsigned int Enemy::GetAp() const{return ap_;}
  97. void Enemy::SetAp(unsigned int ap){ap_ = ap;}
  98. unsigned int Enemy::GetExp() const{return exp_;}
  99. void Enemy::SetExp(const unsigned int exp){exp_ = exp;}
  100. unsigned int Enemy::GetMoney() const{return money_;}
  101. void Enemy::SetMoney(const unsigned int money){money_ = money;}
  102. std::vector<unsigned int> Enemy::GetAnimations() const{return animations_;}
  103. void Enemy::AddAnimation(const unsigned int animation){animations_.push_back(animation);}
  104. std::vector<Enemy::Attack> Enemy::GetAttacks() const{return attacks_;}
  105. void Enemy::AddAttack(const Attack attack){attacks_.push_back(attack);}
  106. std::vector<Enemy::Item> Enemy::GetDrop() const{return drop_;}
  107. void Enemy::AddDrop(const Item item){drop_.push_back(item);}
  108. std::vector<Enemy::Element> Enemy::GetElements() const{return elements_;}
  109. void Enemy::AddElement(const Element element){elements_.push_back(element);}
  110. std::vector<Enemy::Immunity> Enemy::GetImmunities() const{return immunities_;}
  111. void Enemy::AddImmunity(const Immunity immunity){immunities_.push_back(immunity);}
  112. std::vector<unsigned int> Enemy::GetManipulateAttacks() const{return manipulate_attacks_;}
  113. void Enemy::AddManipulateAttack(const unsigned int attack){manipulate_attacks_.push_back(attack);}
  114. std::vector<Enemy::Item> Enemy::GetSteal() const{return steal_;}
  115. void Enemy::AddSteal(const Item item){steal_.push_back(item);}
  116. unsigned int Enemy::GetMorph() const{return morph_;}
  117. void Enemy::SetMorph(const int morph){morph_ = std::max(-1, morph);}
  118. float Enemy::GetBackDamage() const{return back_damage_;}
  119. void Enemy::SetBackDamage(const float back_damage){
  120. if (back_damage < 0.0f) back_damage_ = 0.0f;
  121. else back_damage_ = back_damage;
  122. }
  123. unsigned int Enemy::GetStr() const{return str_;}
  124. void Enemy::SetStr(const unsigned int str){str_ = str;}
  125. unsigned int Enemy::GetDef() const{return def_;}
  126. void Enemy::SetDef(const unsigned int def){def_ = def;}
  127. unsigned int Enemy::GetMag() const{return mag_;}
  128. void Enemy::SetMag(const unsigned int mag){mag_ = mag;}
  129. unsigned int Enemy::GetSpr() const{return spr_;}
  130. void Enemy::SetSpr(const unsigned int spr){spr_ = spr;}
  131. unsigned int Enemy::GetDex() const{return dex_;}
  132. void Enemy::SetDex(const unsigned int dex){dex_ = dex;}
  133. unsigned int Enemy::GetLck() const{return lck_;}
  134. void Enemy::SetLck(const unsigned int lck){lck_ = lck;}
  135. unsigned int Enemy::GetEva() const{return eva_;}
  136. void Enemy::SetEva(const unsigned int eva){eva_ = eva;}
  137. unsigned int Enemy::GetMeva() const{return meva_;}
  138. void Enemy::SetMeva(const unsigned int meva){meva_ = meva;}
  139. unsigned int Enemy::GetHp() const{return hp_;}
  140. void Enemy::SetHp(const unsigned int hp){hp_ = std::min(hp, hp_max_);}
  141. unsigned int Enemy::GetHpMax() const{return hp_max_;}
  142. void Enemy::SetHpMax(const unsigned int hp_max){
  143. hp_max_ = hp_max;
  144. hp_ = std::min(hp_, hp_max_);
  145. }
  146. unsigned int Enemy::GetMp() const{return mp_;}
  147. void Enemy::SetMp(const unsigned int mp){mp_ = std::min(mp, mp_max_);}
  148. unsigned int Enemy::GetMpMax() const{return mp_max_;}
  149. void Enemy::SetMpMax(const unsigned int mp_max){
  150. mp_max_ = mp_max;
  151. mp_ = std::min(mp_, mp_max_);
  152. }
  153. Ogre::Vector3& Enemy::GetPos(){return pos_;}
  154. void Enemy::SetPos(const Ogre::Vector3 &pos){pos_ = pos;}
  155. void Enemy::ScriptGetPos() const{
  156. ScriptManager::getSingleton().AddValueToStack(pos_.x);
  157. ScriptManager::getSingleton().AddValueToStack(pos_.y);
  158. ScriptManager::getSingleton().AddValueToStack(pos_.z);
  159. }
  160. bool Enemy::IsFront() const{return front_;}
  161. void Enemy::SetFront(bool front){front_ = front;}
  162. bool Enemy::IsVisible() const{return visible_;}
  163. void Enemy::SetVisible(bool visible){visible_ = visible;}
  164. bool Enemy::IsTargeteable() const{return targeteable_;}
  165. void Enemy::SetTargeteable(bool targeteable){targeteable_ = targeteable;}
  166. bool Enemy::IsActive() const{return active_;}
  167. void Enemy::SetActive(bool active){active_ = active;}
  168. std::string Enemy::GetCover() const{return cover_;}
  169. void Enemy::SetCover(std::string cover){cover_ = cover;}
  170. int Enemy::ScriptGetAttackCount(){return attacks_.size();}
  171. int Enemy::ScriptGetAttack(const unsigned int index){
  172. if (attacks_.size() < index) return -1;
  173. return attacks_[index].id;
  174. }
  175. int Enemy::ScriptGetCameraForAttack(const unsigned int index){
  176. if (attacks_.size() < index) return -1;
  177. return attacks_[index].camera;
  178. }
  179. void Enemy::ReadFromXml(){
  180. std::string filename = std::to_string(id_);
  181. while (filename.length() < 4) filename = "0" + filename;
  182. filename = "./data/gamedata/enemy/" + filename + ".xml";
  183. XmlEnemyFile(filename).LoadEnemy(*this);
  184. }