Torque3D Documentation / _generateds / afxSpellBook.cpp

afxSpellBook.cpp

Engine/source/afx/afxSpellBook.cpp

More...

Public Defines

define
myOffset(field) (field, )
define
SPELL_DATA_NOT_FOUND() "\n<just:center><font:Arial:20><color:FF0000>** Spell data not found **\"

Public Functions

ConsoleDocClass(afxSpellBook , "@brief A spellbook <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">object.\n\n</a>" "@ingroup <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">afxMisc\n</a>" "@ingroup <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">AFX\n</a>" )
ConsoleDocClass(afxSpellBookData , "@brief A spellbook <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">datablock.\n\n</a>" "@ingroup <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">afxMisc\n</a>" "@ingroup <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">AFX\n</a>" "@ingroup <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">Datablocks\n</a>" )
DefineEngineMethod(afxSpellBook , getPageSlotIndex , S32 , (Point2I bookSlot) , "...\n\n" "@ingroup AFX" )
DefineEngineMethod(afxSpellBook , getSpellData , S32 , (Point2I bookSlot) , "Get spell datablock <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1a2732ab74fa0237854c2ba0f75f88a624">for</a> spell stored at spellbook index, (page, slot).\<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">n\n</a>" " @ingroup AFX" )
DefineEngineMethod(afxSpellBook , getSpellRPGData , S32 , (Point2I bookSlot) , "Get spell RPG datablock <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1a2732ab74fa0237854c2ba0f75f88a624">for</a> spell stored at spellbook index, (page, slot).\<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">n\n</a>" " @ingroup AFX" )
DefineEngineMethod(afxSpellBook , startAllSpellCooldown , void , () , "...\n\n" "@ingroup AFX" )
DefineEngineMethod(afxSpellBookData , getCapacity , S32 , () , "Get the capacity (total number of spell slots) in <a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a> <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">spellbook.\n\n</a>" "@ingroup AFX" )
DefineEngineMethod(afxSpellBookData , getPageSlotIndex , S32 , (Point2I bookSlot) , "...\n\n" "@ingroup AFX" )

Detailed Description

Public Defines

myOffset(field) (field, )
SPELL_DATA_NOT_FOUND() "\n<just:center><font:Arial:20><color:FF0000>** Spell data not found **\"

Public Functions

ConsoleDocClass(afxSpellBook , "@brief A spellbook <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">object.\n\n</a>" "@ingroup <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">afxMisc\n</a>" "@ingroup <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">AFX\n</a>" )

ConsoleDocClass(afxSpellBookData , "@brief A spellbook <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">datablock.\n\n</a>" "@ingroup <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">afxMisc\n</a>" "@ingroup <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">AFX\n</a>" "@ingroup <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">Datablocks\n</a>" )

DefineEngineMethod(afxSpellBook , getPageSlotIndex , S32 , (Point2I bookSlot) , "...\n\n" "@ingroup AFX" )

DefineEngineMethod(afxSpellBook , getSpellData , S32 , (Point2I bookSlot) , "Get spell datablock <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1a2732ab74fa0237854c2ba0f75f88a624">for</a> spell stored at spellbook index, (page, slot).\<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">n\n</a>" " @ingroup AFX" )

DefineEngineMethod(afxSpellBook , getSpellRPGData , S32 , (Point2I bookSlot) , "Get spell RPG datablock <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1a2732ab74fa0237854c2ba0f75f88a624">for</a> spell stored at spellbook index, (page, slot).\<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">n\n</a>" " @ingroup AFX" )

DefineEngineMethod(afxSpellBook , startAllSpellCooldown , void , () , "...\n\n" "@ingroup AFX" )

DefineEngineMethod(afxSpellBookData , getCapacity , S32 , () , "Get the capacity (total number of spell slots) in <a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a> <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">spellbook.\n\n</a>" "@ingroup AFX" )

DefineEngineMethod(afxSpellBookData , getPageSlotIndex , S32 , (Point2I bookSlot) , "...\n\n" "@ingroup AFX" )

IMPLEMENT_CO_DATABLOCK_V1(afxSpellBookData )

IMPLEMENT_CO_NETOBJECT_V1(afxSpellBook )

  1
  2
  3//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~~//
  4// Arcane-FX for MIT Licensed Open Source version of Torque 3D from GarageGames
  5// Copyright (C) 2015 Faust Logic, Inc.
  6//
  7// Permission is hereby granted, free of charge, to any person obtaining a copy
  8// of this software and associated documentation files (the "Software"), to
  9// deal in the Software without restriction, including without limitation the
 10// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
 11// sell copies of the Software, and to permit persons to whom the Software is
 12// furnished to do so, subject to the following conditions:
 13//
 14// The above copyright notice and this permission notice shall be included in
 15// all copies or substantial portions of the Software.
 16//
 17// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 18// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 19// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 20// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 21// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
 22// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
 23// IN THE SOFTWARE.
 24//
 25//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~~//
 26
 27#include "afx/arcaneFX.h"
 28
 29#include "console/engineAPI.h"
 30#include "console/consoleTypes.h"
 31#include "core/stream/bitStream.h"
 32#include "T3D/gameBase/gameBase.h"
 33
 34#include "afx/afxSpellBook.h"
 35#include "afx/afxMagicSpell.h"
 36#include "afx/rpg/afxRPGMagicSpell.h"
 37#include "afx/ui/afxSpellButton.h"
 38
 39//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~~//
 40// afxSpellBookData
 41
 42IMPLEMENT_CO_DATABLOCK_V1(afxSpellBookData);
 43
 44ConsoleDocClass( afxSpellBookData,
 45   "@brief A spellbook datablock.\n\n"
 46
 47   "@ingroup afxMisc\n"
 48   "@ingroup AFX\n"
 49   "@ingroup Datablocks\n"
 50);
 51
 52afxSpellBookData::afxSpellBookData()
 53{
 54  spells_per_page = 12;
 55  pages_per_book = 12;
 56  dMemset(spells, 0, sizeof(spells));
 57  dMemset(rpg_spells, 0, sizeof(rpg_spells));
 58
 59  // marked true if datablock ids need to
 60  // be converted into pointers
 61  do_id_convert = false;
 62}
 63
 64#define myOffset(field) Offset(field, afxSpellBookData)
 65
 66void afxSpellBookData::initPersistFields()
 67{
 68  addField("spellsPerPage",  TypeS8,                myOffset(spells_per_page),
 69    "...");
 70  addField("pagesPerBook",   TypeS8,                myOffset(pages_per_book),
 71    "...");
 72
 73  addField("spells",       TYPEID<GameBaseData>(),   myOffset(spells),     MAX_PAGES_PER_BOOK*MAX_SPELLS_PER_PAGE,
 74    "...");
 75  addField("rpgSpells",    TYPEID<GameBaseData>(),   myOffset(rpg_spells), MAX_PAGES_PER_BOOK*MAX_SPELLS_PER_PAGE,
 76    "...");
 77
 78  Parent::initPersistFields();
 79}
 80
 81bool afxSpellBookData::preload(bool server, String &errorStr)
 82{
 83  if (!Parent::preload(server, errorStr))
 84    return false;
 85
 86  // Resolve objects transmitted from server
 87  if (!server)
 88  {
 89    if (do_id_convert)
 90    {
 91      for (S32 i = 0; i < pages_per_book*spells_per_page; i++)
 92      {
 93        SimObjectId db_id = SimObjectId((uintptr_t)rpg_spells[i]);
 94        if (db_id != 0)
 95        {
 96          // try to convert id to pointer
 97          if (!Sim::findObject(db_id, rpg_spells[i]))
 98          {
 99            Con::errorf(ConsoleLogEntry::General,
100              "afxSpellBookData::preload() -- bad datablockId: 0x%x (afxRPGMagicSpellData)",
101              db_id);
102          }
103        }
104      }
105      do_id_convert = false;
106    }
107  }
108
109  return true;
110}
111
112void afxSpellBookData::packData(BitStream* stream)
113{
114   Parent::packData(stream);
115
116  stream->write(spells_per_page);
117  stream->write(pages_per_book);
118
119  for (S32 i = 0; i < pages_per_book*spells_per_page; i++)
120    writeDatablockID(stream, rpg_spells[i], mPacked);
121}
122
123void afxSpellBookData::unpackData(BitStream* stream)
124{
125  Parent::unpackData(stream);
126
127  stream->read(&spells_per_page);
128  stream->read(&pages_per_book);
129
130  do_id_convert = true;
131  for (S32 i = 0; i < pages_per_book*spells_per_page; i++)
132    rpg_spells[i] = (afxRPGMagicSpellData*)(uintptr_t)readDatablockID(stream);
133}
134
135DefineEngineMethod(afxSpellBookData, getPageSlotIndex, S32, (Point2I bookSlot),,
136                   "...\n\n"
137                   "@ingroup AFX")
138{
139  return object->getPageSlotIndex(bookSlot.x, bookSlot.y);
140}
141
142DefineEngineMethod(afxSpellBookData, getCapacity, S32, (),,
143                   "Get the capacity (total number of spell slots) in a spellbook.\n\n"
144                   "@ingroup AFX")
145{
146  return object->spells_per_page*object->pages_per_book;
147}
148
149//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~~//
150// afxSpellBook
151
152IMPLEMENT_CO_NETOBJECT_V1(afxSpellBook);
153
154ConsoleDocClass( afxSpellBook,
155   "@brief A spellbook object.\n\n"
156
157   "@ingroup afxMisc\n"
158   "@ingroup AFX\n"
159);
160
161afxSpellBook::afxSpellBook()
162{
163   mNetFlags.set(Ghostable | ScopeAlways);
164   mDataBlock = NULL;
165  all_spell_cooldown = 1.0f;
166}
167
168afxSpellBook::~afxSpellBook()
169{
170}
171
172//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//
173
174void afxSpellBook::initPersistFields()
175{
176   Parent::initPersistFields();
177}
178
179//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//
180
181void afxSpellBook::processTick(const Move* m)
182{
183   Parent::processTick(m);
184}
185
186//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//
187
188void afxSpellBook::advanceTime(F32 dt)
189{
190  Parent::advanceTime(dt);
191
192  if (all_spell_cooldown < 1.0f)
193  {
194    all_spell_cooldown += dt/2.0f;
195    if (all_spell_cooldown > 1.0f)
196      all_spell_cooldown = 1.0f;
197  }
198}
199
200//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//
201
202bool afxSpellBook::onNewDataBlock(GameBaseData* dptr, bool reload)
203{
204  mDataBlock = dynamic_cast<afxSpellBookData*>(dptr);
205  if (!mDataBlock || !Parent::onNewDataBlock(dptr, reload))
206    return false;
207
208  scriptOnNewDataBlock();
209
210  return true;
211}
212
213//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//
214
215bool afxSpellBook::onAdd()
216{
217   if (!Parent::onAdd())
218    return(false);
219
220   return(true);
221}
222
223void afxSpellBook::onRemove()
224{
225   Parent::onRemove();
226}
227
228//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//
229
230U32 afxSpellBook::packUpdate(NetConnection * con, U32 mask, BitStream * stream)
231{
232  U32 retMask = Parent::packUpdate(con, mask, stream);
233
234  if (stream->writeFlag(mask & InitialUpdateMask))
235  {
236  }
237
238  // AllSpellCooldown
239  if (stream->writeFlag(mask & AllSpellCooldownMask))
240  {
241  }
242
243   return(retMask);
244}
245
246void afxSpellBook::unpackUpdate(NetConnection * con, BitStream * stream)
247{
248   Parent::unpackUpdate(con, stream);
249
250  // InitialUpdate
251  if (stream->readFlag())
252  {
253  }
254
255  // AllSpellCooldown
256  if (stream->readFlag())
257  {
258    all_spell_cooldown = 0.0f;
259  }
260}
261
262#define SPELL_DATA_NOT_FOUND "\n<just:center><font:Arial:20><color:FF0000>** Spell data not found **\n\n\n\n"
263
264char* afxSpellBook::formatDesc(char* buffer, int len, S32 page, S32 slot) const
265{
266  S32 idx = mDataBlock->getPageSlotIndex(page, slot);
267  if (idx < 0 || !mDataBlock->rpg_spells[idx])
268    return SPELL_DATA_NOT_FOUND;
269
270  return mDataBlock->rpg_spells[idx]->formatDesc(buffer, len);
271}
272
273const char* afxSpellBook::getSpellIcon(S32 page, S32 slot) const
274{
275  S32 idx = mDataBlock->getPageSlotIndex(page, slot);
276  if (idx < 0 || !mDataBlock->rpg_spells[idx])
277    return 0;
278
279  return mDataBlock->rpg_spells[idx]->icon_name;
280}
281
282bool afxSpellBook::isPlaceholder(S32 page, S32 slot) const
283{
284  S32 idx = mDataBlock->getPageSlotIndex(page, slot);
285  if (idx < 0 || !mDataBlock->rpg_spells[idx])
286    return false;
287
288  return mDataBlock->rpg_spells[idx]->is_placeholder;
289}
290
291
292afxMagicSpellData* afxSpellBook::getSpellData(S32 page, S32 slot)
293{
294  S32 idx = mDataBlock->getPageSlotIndex(page, slot);
295  if (idx < 0 || !mDataBlock->spells[idx])
296    return 0;
297
298  return mDataBlock->spells[idx];
299}
300
301afxRPGMagicSpellData* afxSpellBook::getSpellRPGData(S32 page, S32 slot)
302{
303  S32 idx = mDataBlock->getPageSlotIndex(page, slot);
304  if (idx < 0 || !mDataBlock->rpg_spells[idx])
305    return 0;
306
307  return mDataBlock->rpg_spells[idx];
308}
309
310//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~~//
311
312void afxSpellBook::startAllSpellCooldown()
313{
314  //all_spell_cooldown = 0.0f;
315  setMaskBits(AllSpellCooldownMask);
316}
317
318F32 afxSpellBook::getCooldownFactor(S32 page, S32 slot)
319{
320  return all_spell_cooldown;
321}
322
323//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~~//
324
325DefineEngineMethod(afxSpellBook, getPageSlotIndex, S32, (Point2I bookSlot),,
326                   "...\n\n"
327                   "@ingroup AFX")
328{
329  return object->getPageSlotIndex(bookSlot.x, bookSlot.y);
330}
331
332DefineEngineMethod(afxSpellBook, getSpellData, S32, (Point2I bookSlot),,
333                   "Get spell datablock for spell stored at spellbook index, (page, slot).\n\n"
334                   "@ingroup AFX")
335{
336  afxMagicSpellData* spell_data = object->getSpellData(bookSlot.x, bookSlot.y);
337  return (spell_data) ? spell_data->getId() : 0;
338}
339
340DefineEngineMethod(afxSpellBook, getSpellRPGData, S32, (Point2I bookSlot),,
341                   "Get spell RPG datablock for spell stored at spellbook index, (page, slot).\n\n"
342                   "@ingroup AFX")
343{
344  afxRPGMagicSpellData* spell_data = object->getSpellRPGData(bookSlot.x, bookSlot.y);
345  return (spell_data) ? spell_data->getId() : 0;
346}
347
348DefineEngineMethod(afxSpellBook, startAllSpellCooldown, void, (),,
349                   "...\n\n"
350                   "@ingroup AFX")
351{
352  object->startAllSpellCooldown();
353}
354
355//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~~//
356
357
358
359