JNR
rpgAttack.cpp
1 /*
2 
3 Jump'n'Run Engine
4 http://www.atanaslaskov.com/jnr/
5 
6 BSD LICENSE
7 Copyright (c) 2007-2013, Atanas Laskov
8 All rights reserved.
9 
10 Redistribution and use in source and binary forms, with or without
11 modification, are permitted provided that the following conditions are met:
12 1. Redistributions of source code must retain the above copyright notice,
13 this list of conditions and the following disclaimer.
14 2. Redistributions in binary form must reproduce the above copyright notice,
15 this list of conditions and the following disclaimer in the documentation
16 and/or other materials provided with the distribution.
17 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
18 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
20 DISCLAIMED. IN NO EVENT SHALL ATANAS LASKOV BE LIABLE FOR ANY
21 DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
22 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
23 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
24 ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
26 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 
28 */
29 
30 //
31 // FILE: rpgAttack.cpp
32 //
33 // This class contains the RPG properties of an attack,
34 // including the attack element, attack points, and special flags
35 //
36 // Copyright (C) 2007-2013 Atanas Laskov, <latanas@gmail.com>
37 //
38 #include "stdafx.h"
39 #include "RPG.h"
40 
41 #include "Core-Level-JR.h"
42 class laTileset* rpgAttack::_pTS = NULL;
43 
44 // Constructor
45 //
46 rpgAttack::rpgAttack(unsigned element, unsigned ap)
47 {
48  nElement = element;
49  nAP = ap;
50 
51  dRange = M_UNIT * 1.2;
52  dChargeTime = 1;
53 }
54 
55 rpgAttack::~rpgAttack()
56 {
57 }
58 
59 // Load from TS
60 void rpgAttack::load(laPropertyList* pElement)
61 {
62  nElement = pElement->getInt("Element");
63  nAP = pElement->getInt("AP");
64 
65 
66  try{ dRange = pElement->getDouble("range") * M_UNIT; }
67  catch(laError_PropertyNotDefined&){ dRange = M_UNIT * 1.2; };
68 
69  try{ dChargeTime = pElement->getDouble("charge-time"); }
70  catch(laError_PropertyNotDefined&){ dChargeTime = 1; };
71 
72  try{
73  unsigned n = _pTS->getElementIndex( pElement->getText("potion-like-fx") );
74  laPropertyList *pPL = _pTS->getElement( n ); //pElement->getChild("potion");
75 
76  spPotion = shared_ptr<rpgPotion>(new rpgPotion);
77  spPotion->load( pPL->getChild("potion") );
78 
79  //MSG("pot");
80  }
81  catch(laError_PropertyNotDefined&){ };
82 
83  try{
84  laPropertyList *pPL = pElement->getChild("projectile");
85 
86  spProjectile = shared_ptr<rpgProjectile>(new rpgProjectile);
87  //spProjectile->load( pPL );
88  }
89  catch(laError_PropertyNotDefined&){ };
90 
91 
92 
93 }
94 
95 // This method is part of the laLoadableObj interface
96 //
97 // Load attack and its associated special effects from the tileset file ( .ts, for mobs ),
98 // or the save game file ( for the rpgSheet_PlayableChar );
99 //
100 void rpgAttack::load(class laFileParser *fp)
101 {
102  M_BOOL on;
103 
104  fp->readUnsigned(&nElement, M_FALSE);
105  fp->readUnsigned(&nAP, M_FALSE);
106  fp->readDouble(&dChargeTime, M_FALSE);
107 
108  fp->readBool(&on, M_FALSE);
109  if(on)
110  {
111  spProjectile = shared_ptr<rpgProjectile>(new rpgProjectile);
112  spProjectile->load(fp);
113  }
114 
115  fp->readBool(&on, M_FALSE);
116  if(on)
117  {
118  spPotion = shared_ptr<rpgPotion>(new rpgPotion);
119  spProjectile->load(fp);
120  }
121 }
122 
123 // Upgrade attack (called on level up)
124 //
126 {
127  nAP += M_AP_INCREMENT;
128 }
#define M_UNIT
Unit of 1 meter.
void upgrade()
Upgrade attack (called on level up)
Definition: rpgAttack.cpp:125
Potion RPG Properties.
Definition: rpgPotion.h:44
Projectile RPG Properties.
Definition: rpgProjectile.h:42
Tileset Class.
Definition: laTileset.h:46
File Parser.
Definition: laFileParser.h:41