afxSpellBook.h 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. //~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~~//
  2. // Arcane-FX for MIT Licensed Open Source version of Torque 3D from GarageGames
  3. // Copyright (C) 2015 Faust Logic, Inc.
  4. //
  5. // Permission is hereby granted, free of charge, to any person obtaining a copy
  6. // of this software and associated documentation files (the "Software"), to
  7. // deal in the Software without restriction, including without limitation the
  8. // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
  9. // sell copies of the Software, and to permit persons to whom the Software is
  10. // furnished to do so, subject to the following conditions:
  11. //
  12. // The above copyright notice and this permission notice shall be included in
  13. // all copies or substantial portions of the Software.
  14. //
  15. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  16. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  17. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  18. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  19. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  20. // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
  21. // IN THE SOFTWARE.
  22. //
  23. //~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~~//
  24. #ifndef _AFX_SPELL_BOOK_H_
  25. #define _AFX_SPELL_BOOK_H_
  26. //~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~~//
  27. #include "T3D/gameBase/gameBase.h"
  28. class afxSpellBookDefs
  29. {
  30. public:
  31. enum {
  32. MAX_SPELLS_PER_PAGE = 12,
  33. MAX_PAGES_PER_BOOK = 12
  34. };
  35. };
  36. class afxMagicSpellData;
  37. class afxRPGMagicSpellData;
  38. class afxSpellBookData : public GameBaseData, public afxSpellBookDefs
  39. {
  40. typedef GameBaseData Parent;
  41. bool do_id_convert;
  42. public:
  43. U8 spells_per_page;
  44. U8 pages_per_book;
  45. afxMagicSpellData* spells[MAX_PAGES_PER_BOOK*MAX_SPELLS_PER_PAGE];
  46. afxRPGMagicSpellData* rpg_spells[MAX_PAGES_PER_BOOK*MAX_SPELLS_PER_PAGE];
  47. public:
  48. /*C*/ afxSpellBookData();
  49. void packData(BitStream*) override;
  50. void unpackData(BitStream*) override;
  51. bool preload(bool server, String &errorStr) override;
  52. bool verifyPageSlot(S32 page, S32 slot);
  53. S32 getPageSlotIndex(S32 page, S32 slot);
  54. static void initPersistFields();
  55. DECLARE_CONOBJECT(afxSpellBookData);
  56. };
  57. inline bool afxSpellBookData::verifyPageSlot(S32 page, S32 slot)
  58. {
  59. return (page >= 0 && page < pages_per_book && slot >= 0 && slot < spells_per_page);
  60. }
  61. inline S32 afxSpellBookData::getPageSlotIndex(S32 page, S32 slot)
  62. {
  63. return (verifyPageSlot(page, slot)) ? page*spells_per_page + slot : -1;
  64. }
  65. //~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~~//
  66. class afxMagicSpellData;
  67. class afxSpellButton;
  68. class afxSpellBook : public GameBase, public afxSpellBookDefs
  69. {
  70. typedef GameBase Parent;
  71. enum MaskBits
  72. {
  73. AllSpellCooldownMask = Parent::NextFreeMask << 0,
  74. NextFreeMask = Parent::NextFreeMask << 1
  75. };
  76. private:
  77. afxSpellBookData* mDataBlock;
  78. F32 all_spell_cooldown;
  79. public:
  80. /*C*/ afxSpellBook();
  81. /*D*/ ~afxSpellBook();
  82. bool onNewDataBlock(GameBaseData* dptr, bool reload) override;
  83. void processTick(const Move*) override;
  84. void advanceTime(F32 dt) override;
  85. bool onAdd() override;
  86. void onRemove() override;
  87. U32 packUpdate(NetConnection*, U32, BitStream*) override;
  88. void unpackUpdate(NetConnection*, BitStream*) override;
  89. static void initPersistFields();
  90. S32 getPageSlotIndex(S32 page, S32 slot);
  91. const char* formatDesc(char* buffer, int len, S32 page, S32 slot) const;
  92. const char* getSpellIcon(S32 page, S32 slot) const;
  93. bool isPlaceholder(S32 page, S32 slot) const;
  94. afxMagicSpellData* getSpellData(S32 page, S32 slot);
  95. afxRPGMagicSpellData* getSpellRPGData(S32 page, S32 slot);
  96. void startAllSpellCooldown();
  97. F32 getCooldownFactor(S32 page, S32 slot);
  98. DECLARE_CONOBJECT(afxSpellBook);
  99. DECLARE_CATEGORY("UNLISTED");
  100. };
  101. inline S32 afxSpellBook::getPageSlotIndex(S32 page, S32 slot)
  102. {
  103. return (mDataBlock) ? mDataBlock->getPageSlotIndex(page, slot) : -1;
  104. }
  105. //~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~~//
  106. #endif // _AFX_SPELL_BOOK_H_