Enemy.h 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789
  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. #pragma once
  16. #include <OgreString.h>
  17. #include "ScriptManager.h"
  18. /**
  19. * Any enemy in a battle.
  20. */
  21. class Enemy{
  22. public:
  23. struct Element{
  24. /**
  25. * The element ID.
  26. */
  27. unsigned int id;
  28. /**
  29. * Damage modification factor when attacked by the element.
  30. *
  31. * 1 means normal damage taken.
  32. * 0 means no damage taken.
  33. * [0-1] means reduced damage.
  34. * [1-10) means extended damage.
  35. * (-10-0) means recovery
  36. * >10 means death.
  37. * <-10 means full recovery.
  38. */
  39. float factor;
  40. };
  41. /**
  42. * Enemy attack data.
  43. */
  44. struct Attack{
  45. /**
  46. * Attack ID.
  47. */
  48. unsigned int id;
  49. /**
  50. * Camera ID to use during the attack.
  51. *
  52. * -1 to not move the camera.
  53. */
  54. int camera;
  55. };
  56. /**
  57. * Data for drop and steal items.
  58. */
  59. struct Item{
  60. /**
  61. * Item ID.
  62. */
  63. unsigned int id;
  64. /**
  65. * Steal or drop rate.
  66. */
  67. float rate;
  68. };
  69. /**
  70. * Status immunity.
  71. */
  72. struct Immunity{
  73. /**
  74. * Status ID.
  75. */
  76. unsigned int status;
  77. /**
  78. * Immunity rate.
  79. *
  80. * 0 or lower means no immunity, 1 or higher completely immune. Values between 0 and 1
  81. * indicate resistance.
  82. */
  83. float rate;
  84. };
  85. /**
  86. * Constructor.
  87. *
  88. * @param[in] id Enemy ID.
  89. */
  90. Enemy(const unsigned int id);
  91. /**
  92. * Constructor.
  93. *
  94. * @param[in] id Enemy ID.
  95. * @param[in] pos Enemy position (x, y, z).
  96. * @param[in] front True to set the enemy in the front row, false for back row.
  97. * @param[in] visible Indicates enemy visibility.
  98. * @param[in] targeteable Indicates if the enemy can be targeted.
  99. * @param[in] active Indicates whether the enemy main script is active or not.
  100. * @param[in] cover Cover binary flags string.
  101. */
  102. Enemy(
  103. const unsigned int id, const Ogre::Vector3 pos, const bool front, const bool visible,
  104. const bool targeteable, const bool active, const std::string cover
  105. );
  106. /**
  107. * Destructor.
  108. */
  109. virtual ~Enemy();
  110. /**
  111. * Retrieves the enemy ID.
  112. *
  113. * @return The enemy ID, or -1 if it's not loaded.
  114. */
  115. const int GetId() const;
  116. /**
  117. * Sets the enemy ID.
  118. *
  119. * @param[in] id The enemy ID.
  120. */
  121. void SetId(const int id);
  122. /**
  123. * Retrieves the enemy name.
  124. *
  125. * @return The enemy name.
  126. */
  127. const Ogre::String& GetName() const;
  128. /**
  129. * Sets the enemy name.
  130. *
  131. * @param[in] name The enemy name.
  132. */
  133. void SetName(const Ogre::String& name);
  134. /**
  135. * Retrieves the enemy level.
  136. *
  137. * @return The enemy level.
  138. */
  139. unsigned int GetLevel() const;
  140. /**
  141. * Sets the enemy level.
  142. *
  143. * @param[in] level The enemy level.
  144. */
  145. void SetLevel(const unsigned int level);
  146. /**
  147. * Retrieves the AP gain upon defeating the enemy.
  148. *
  149. * @return The AP gain.
  150. */
  151. unsigned int GetAp() const;
  152. /**
  153. * Sets the AP gain upon defeating the enemy.
  154. *
  155. * @param[in] ap The AP gain.
  156. */
  157. void SetAp(unsigned int ap);
  158. /**
  159. * Retrieves the EXP gain upon defeating the enemy.
  160. *
  161. * @return The EXP gain.
  162. */
  163. unsigned int GetExp() const;
  164. /**
  165. * Sets the EXP gain upon defeating the enemy.
  166. *
  167. * @param[in] exp The EXP gain.
  168. */
  169. void SetExp(const unsigned int exp);
  170. /**
  171. * Retrieves the money gain upon defeating the enemy.
  172. *
  173. * @return The money gain.
  174. */
  175. unsigned int GetMoney() const;
  176. /**
  177. * Sets the money gain upon defeating the enemy.
  178. *
  179. * @param[in] money The money gain.
  180. */
  181. void SetMoney(const unsigned int money);
  182. /**
  183. * Retrieves the enemy animation IDs.
  184. *
  185. * @return The list of animation IDs
  186. */
  187. std::vector<unsigned int> GetAnimations() const;
  188. /**
  189. * Adds an animation for the enemy.
  190. *
  191. * @param[in] Animation ID.
  192. */
  193. void AddAnimation(const unsigned int animation);
  194. /**
  195. * Retrieves the enemy attacks.
  196. *
  197. * @return The list of attacks.
  198. */
  199. std::vector<Attack> GetAttacks() const;
  200. /**
  201. * Adds an attack for the enemy.
  202. *
  203. * @param[in] Attack to add.
  204. */
  205. void AddAttack(const Attack attack);
  206. /**
  207. * Retrieves the enemy possible item drops.
  208. *
  209. * @return List of items that can be droped by the enemy.
  210. */
  211. std::vector<Item> GetDrop() const;
  212. /**
  213. * Adds an item drop for the enemy.
  214. *
  215. * @param[in] item The dropable item.
  216. */
  217. void AddDrop(const Item item);
  218. /**
  219. * Retrieves the list of the enemy elemental affinities.
  220. *
  221. * @return The list of elemental affinities.
  222. */
  223. std::vector<Element> GetElements() const;
  224. /**
  225. * Adds an elemental affinity to the monster.
  226. *
  227. * @param[in] element Elemental affinity.
  228. */
  229. void AddElement(const Element element);
  230. /**
  231. * Retrieves the list of status immunities.
  232. *
  233. * @return The list of status immunities.
  234. */
  235. std::vector<Immunity> GetImmunities() const;
  236. /**
  237. * Adds an immunity to the monster.
  238. *
  239. * @param[in] immunity The immunity to add.
  240. */
  241. void AddImmunity(const Immunity immunity);
  242. /**
  243. * Retrieves the list of attacks that can be used during the manipulated state.
  244. *
  245. * The first attack of the list is also the attack the enemy will use when in berserkr
  246. * state. If the list is empty, the enemy can't be manipulated or berserkred.
  247. *
  248. * @return List of IDs of attacks usable during manipulation
  249. */
  250. std::vector<unsigned int> GetManipulateAttacks() const;
  251. /**
  252. * Adds an attack usable during manipulation.
  253. *
  254. * @param[in] attack ID of the attack.
  255. */
  256. void AddManipulateAttack(const unsigned int attack);
  257. /**
  258. * Retrieves the enemy possible item stelas.
  259. *
  260. * @return List of items that can be stolen from the enemy.
  261. */
  262. std::vector<Item> GetSteal() const;
  263. /**
  264. * Adds an item steal to the enemy.
  265. *
  266. * @param[in] item The stealableitem.
  267. */
  268. void AddSteal(const Item item);
  269. /**
  270. * Retrieves the ID of the item the monster can be morphed into.
  271. *
  272. * @return ID of the item the enemy can be morphed into, -1 if none.
  273. */
  274. unsigned int GetMorph() const;
  275. /**
  276. * Sets the ID of the item the monster can be morphed into.
  277. *
  278. * @param[in] morph ID of the item the enemy can be morphed into, -1 if none.
  279. */
  280. void SetMorph(const int morph);
  281. /**
  282. * Retrieves the multiplier for the damage the enemy receives when attacked from the back.
  283. *
  284. * @return Back attack damage multiplier.
  285. */
  286. float GetBackDamage() const;
  287. /**
  288. * Sets the multiplier for the damage the enemy receives when attacked from the back.
  289. *
  290. * @param[in] back_damage Back attack damage multiplier, 0 or positive.
  291. */
  292. void SetBackDamage(const float back_damage);
  293. /**
  294. * Retrieves the enemy's strength stat.
  295. *
  296. * @return The strength stat.
  297. */
  298. unsigned int GetStr() const;
  299. /**
  300. * Sets the enemy's strength stat.
  301. *
  302. * @param[in] str The strength stat.
  303. */
  304. void SetStr(const unsigned int str);
  305. /**
  306. * Retrieves the enemy's defense stat.
  307. *
  308. * @return The defense stat.
  309. */
  310. unsigned int GetDef() const;
  311. /**
  312. * Sets the enemy's defense stat.
  313. *
  314. * @param[in] def The defense stat.
  315. */
  316. void SetDef(const unsigned int def);
  317. /**
  318. * Retrieves the enemy's magic stat.
  319. *
  320. * @return The magic stat.
  321. */
  322. unsigned int GetMag() const;
  323. /**
  324. * Sets the enemy's magic stat.
  325. *
  326. * @param[in] mag The magic stat.
  327. */
  328. void SetMag(const unsigned int mag);
  329. /**
  330. * Retrieves the enemy's spirit stat.
  331. *
  332. * @return The spirit stat.
  333. */
  334. unsigned int GetSpr() const;
  335. /**
  336. * Sets the enemy's spirit stat.
  337. *
  338. * @param[in] spr The spirit stat.
  339. */
  340. void SetSpr(const unsigned int spr);
  341. /**
  342. * Retrieves the enemy's dexterity stat.
  343. *
  344. * @return The dexterity stat.
  345. */
  346. unsigned int GetDex() const;
  347. /**
  348. * Sets the enemy's dexterity stat.
  349. *
  350. * @param[in] dex The dexterity stat.
  351. */
  352. void SetDex(const unsigned int dex);
  353. /**
  354. * Retrieves the enemy's luck stat.
  355. *
  356. * @return The luck stat.
  357. */
  358. unsigned int GetLck() const;
  359. /**
  360. * Sets the enemy's luck stat.
  361. *
  362. * @param[in] lck The luck stat.
  363. */
  364. void SetLck(const unsigned int lck);
  365. /**
  366. * Retrieves the enemy's evasion stat.
  367. *
  368. * @return The evasion stat.
  369. */
  370. unsigned int GetEva() const;
  371. /**
  372. * Sets the enemy's evasion stat.
  373. *
  374. * @param[in] eva The evasion stat.
  375. */
  376. void SetEva(const unsigned int eva);
  377. /**
  378. * Retrieves the enemy's magic evasion stat.
  379. *
  380. * @return The magic evasion stat.
  381. */
  382. unsigned int GetMeva() const;
  383. /**
  384. * Sets the enemy's magic evasion stat.
  385. *
  386. * @param[in] meva The magic evasion stat.
  387. */
  388. void SetMeva(const unsigned int meva);
  389. /**
  390. * Retrieves the enemy's current HP.
  391. *
  392. * @return The current HP.
  393. */
  394. unsigned int GetHp() const;
  395. /**
  396. * Sets the enemy's current HP.
  397. *
  398. * If set to higher then max HP reported by {@see GetHpMax()}, it will be capped to that
  399. * value.
  400. *
  401. * @param[in] hp The current HP.
  402. */
  403. void SetHp(const unsigned int hp);
  404. /**
  405. * Retrieves the enemy's max HP.
  406. *
  407. * @return The max HP.
  408. */
  409. unsigned int GetHpMax() const;
  410. /**
  411. * Sets the enemy's max HP.
  412. *
  413. * If the new max HP is higher than the current HP, the current HP will be set to the new
  414. * max HP.
  415. *
  416. * @param[in] str The strength stat.
  417. */
  418. void SetHpMax(const unsigned int hp_max);
  419. /**
  420. * Retrieves the enemy's current MP.
  421. *
  422. * @return The current MP.
  423. */
  424. unsigned int GetMp() const;
  425. /**
  426. * Sets the enemy's current MP.
  427. *
  428. * If set to higher then max MP reported by {@see GetMpMax()}, it will be capped to that
  429. * value.
  430. *
  431. * @param[in] mp The current MP.
  432. */
  433. void SetMp(const unsigned int mp);
  434. /**
  435. * Retrieves the enemy's max MP.
  436. *
  437. * @return The max MP.
  438. */
  439. unsigned int GetMpMax() const;
  440. /**
  441. * Sets the enemy's max MP.
  442. *
  443. * If the new max MP is higher than the current MP, the current MP will be set to the new
  444. * max MP.
  445. *
  446. * @param[in] str The strength stat.
  447. */
  448. void SetMpMax(const unsigned int mp_max);
  449. /**
  450. * Retrieves the enemy position in the battlefield.
  451. *
  452. * @return The enemy position (x, y, z).
  453. */
  454. Ogre::Vector3& GetPos();
  455. /**
  456. * Sets the enemy position in the battlefield.
  457. *
  458. * @param[in] pos The enemy position (x, y, z).
  459. */
  460. void SetPos(const Ogre::Vector3 &pos);
  461. /**
  462. * Checks if the enemy is in the front row.
  463. *
  464. * @return True if the enemy is in the front row. false if not.
  465. */
  466. bool IsFront() const;
  467. /**
  468. * Sets the enemy in or out the front row.
  469. *
  470. * @param[in] front True to set the enemy in the front row, false for the back row.
  471. */
  472. void SetFront(bool front);
  473. /**
  474. * Checks the enemy visibility.
  475. *
  476. * @return True if the enemy is visible, false if not.
  477. */
  478. bool IsVisible() const;
  479. /**
  480. * Toggles the enemy visibility.
  481. *
  482. * @param[in] visible True to make the enemy visible, false to make it invisible.
  483. */
  484. void SetVisible(bool visible);
  485. /**
  486. * Checks whether the enemy can be targeted.
  487. *
  488. * @return True if the enemy can be targeted, false if not.
  489. */
  490. bool IsTargeteable() const;
  491. /**
  492. * Determines whether the enemy can be targeted.
  493. *
  494. * @param[in] targeteable True to allow targeting the enemy false to prevent it.
  495. */
  496. void SetTargeteable(bool targeteable);
  497. /**
  498. * Checks whether the enemy's main script is active.
  499. *
  500. * @return True if the script is active, false if not.
  501. */
  502. bool IsActive() const;
  503. /**
  504. * Activates or deactivates the enemy main script.
  505. *
  506. * @param[in] active True to activate the script, false to deactivate it.
  507. */
  508. void SetActive(bool active);
  509. /**
  510. * Retrieves the flags for enemy covering.
  511. *
  512. * {@see https://wiki.ffrtt.ru/index.php/FF7/Battle/Battle_Scenes#Binary_.22Cover_Flags.22}
  513. * for more info about cover flags.
  514. *
  515. * @return A string with five 0s or 1s indicating the cover flags.
  516. */
  517. std::string GetCover() const;
  518. /**
  519. * Sets the flags for enemy covering.
  520. *
  521. * {@see https://wiki.ffrtt.ru/index.php/FF7/Battle/Battle_Scenes#Binary_.22Cover_Flags.22}
  522. * for more info about cover flags.
  523. *
  524. * @param[in] A string with five 0s or 1s indicating the cover flags.
  525. */
  526. void SetCover(std::string cover);
  527. private:
  528. /**
  529. * Reads enemy data from the xml file.
  530. */
  531. void ReadFromXml();
  532. /**
  533. * The enemy ID.
  534. */
  535. int id_;
  536. /**
  537. * The name of the enemy.
  538. */
  539. Ogre::String name_;
  540. /**
  541. * The enemy level.
  542. */
  543. unsigned int level_;
  544. /**
  545. * EXP given upon defeating the enemy.
  546. */
  547. unsigned int exp_;
  548. /**
  549. * AP given upon defeating the enemy.
  550. */
  551. unsigned int ap_;
  552. /**
  553. * Money given upon defeating the enemy.
  554. */
  555. unsigned int money_;
  556. /**
  557. * List of animations.
  558. */
  559. std::vector<unsigned int> animations_;
  560. /**
  561. * Elemental affinities.
  562. */
  563. std::vector<Element> elements_;
  564. /**
  565. * Status immunities and resistances.
  566. */
  567. std::vector<Immunity> immunities_;
  568. /**
  569. * Enemy attacks.
  570. */
  571. std::vector<Attack> attacks_;
  572. /**
  573. * List of attacks that can be used while manipulated.
  574. *
  575. * The first one is also the one used in berserkr. If empty, it means the enemy can't be
  576. * manipulated or berserkd.
  577. */
  578. std::vector<unsigned int> manipulate_attacks_;
  579. /**
  580. * List of the items that can be stolen from the enemy.
  581. */
  582. std::vector<Item> steal_;
  583. /**
  584. * List of the items that can be dropped from the enemy.
  585. */
  586. std::vector<Item> drop_;
  587. /**
  588. * ID of the item the enemy can be morphed into. -1 if none..
  589. */
  590. int morph_;
  591. /**
  592. * Multiplier for back damage.
  593. */
  594. float back_damage_;
  595. /**
  596. * Enemy strength stat.
  597. */
  598. unsigned int str_;
  599. /**
  600. * Enemy defense stat.
  601. */
  602. unsigned int def_;
  603. /**
  604. * Enemy magic stat.
  605. */
  606. unsigned int mag_;
  607. /**
  608. * Enemy spirit stat.
  609. */
  610. unsigned int spr_;
  611. /**
  612. * Enemy dexterity stat.
  613. */
  614. unsigned int dex_;
  615. /**
  616. * Enemy luck stat.
  617. */
  618. unsigned int lck_;
  619. /**
  620. * Enemy evasion stat.
  621. */
  622. unsigned int eva_;
  623. /**
  624. * Enemy magic evasion stat.
  625. */
  626. unsigned int meva_;
  627. /**
  628. * Enemy's current HP.
  629. */
  630. unsigned int hp_;
  631. /**
  632. * Enemy's current MP.
  633. */
  634. unsigned int mp_;
  635. /**
  636. * Enemy's max HP.
  637. */
  638. unsigned int hp_max_;
  639. /**
  640. * Enemy's max MP.
  641. */
  642. unsigned int mp_max_;
  643. /**
  644. * Enemy position in the battlefield (x, y, z).
  645. */
  646. Ogre::Vector3 pos_;
  647. /**
  648. * Indicates if the enmy is in the frontline.
  649. */
  650. bool front_;
  651. /**
  652. * Indicates if the enemy is visible.
  653. */
  654. bool visible_;
  655. /**
  656. * Indicates if the enemy can be targeted.
  657. */
  658. bool targeteable_;
  659. /**
  660. * Indicates if the enemy's main script is active.
  661. */
  662. bool active_;
  663. /**
  664. * Cover binary flags.
  665. */
  666. std::string cover_;
  667. };