afxSpellBook.h 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  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. virtual void packData(BitStream*);
  50. virtual void unpackData(BitStream*);
  51. bool preload(bool server, String &errorStr);
  52. bool verifyPageSlot(S32 page, S32 slot);
  53. S32 getPageSlotIndex(S32 page, S32 slot);
  54. static void initPersistFields();
  55. DECLARE_CONOBJECT(afxSpellBookData);
  56. DECLARE_CATEGORY("AFX");
  57. };
  58. inline bool afxSpellBookData::verifyPageSlot(S32 page, S32 slot)
  59. {
  60. return (page >= 0 && page < pages_per_book && slot >= 0 && slot < spells_per_page);
  61. }
  62. inline S32 afxSpellBookData::getPageSlotIndex(S32 page, S32 slot)
  63. {
  64. return (verifyPageSlot(page, slot)) ? page*spells_per_page + slot : -1;
  65. }
  66. //~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~~//
  67. class afxMagicSpellData;
  68. class afxSpellButton;
  69. class afxSpellBook : public GameBase, public afxSpellBookDefs
  70. {
  71. typedef GameBase Parent;
  72. enum MaskBits
  73. {
  74. AllSpellCooldownMask = Parent::NextFreeMask << 0,
  75. NextFreeMask = Parent::NextFreeMask << 1
  76. };
  77. private:
  78. afxSpellBookData* mDataBlock;
  79. F32 all_spell_cooldown;
  80. public:
  81. /*C*/ afxSpellBook();
  82. /*D*/ ~afxSpellBook();
  83. virtual bool onNewDataBlock(GameBaseData* dptr, bool reload);
  84. virtual void processTick(const Move*);
  85. virtual void advanceTime(F32 dt);
  86. virtual bool onAdd();
  87. virtual void onRemove();
  88. virtual U32 packUpdate(NetConnection*, U32, BitStream*);
  89. virtual void unpackUpdate(NetConnection*, BitStream*);
  90. static void initPersistFields();
  91. S32 getPageSlotIndex(S32 page, S32 slot);
  92. const char* formatDesc(char* buffer, int len, S32 page, S32 slot) const;
  93. const char* getSpellIcon(S32 page, S32 slot) const;
  94. bool isPlaceholder(S32 page, S32 slot) const;
  95. afxMagicSpellData* getSpellData(S32 page, S32 slot);
  96. afxRPGMagicSpellData* getSpellRPGData(S32 page, S32 slot);
  97. void startAllSpellCooldown();
  98. F32 getCooldownFactor(S32 page, S32 slot);
  99. DECLARE_CONOBJECT(afxSpellBook);
  100. DECLARE_CATEGORY("AFX");
  101. };
  102. inline S32 afxSpellBook::getPageSlotIndex(S32 page, S32 slot)
  103. {
  104. return (mDataBlock) ? mDataBlock->getPageSlotIndex(page, slot) : -1;
  105. }
  106. //~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~~//
  107. #endif // _AFX_SPELL_BOOK_H_