Pol  Revision:4b29d2b
attributemod.cpp
Go to the documentation of this file.
1 
8 #include "attributemod.h"
9 
10 #include "../../bscript/berror.h"
11 #include "../../bscript/impstr.h"
12 #include "../globals/uvars.h"
13 #include "../mobile/attribute.h"
14 #include "../mobile/charactr.h"
15 #include "../network/cliface.h"
16 #include "../skilladv.h"
17 #include "../skillid.h"
18 #include "../uoexhelp.h"
19 
20 
21 namespace Pol
22 {
23 namespace Bscript
24 {
25 using namespace Module;
26 template <>
30  {"GetAttributeName", &AttributeExecutorModule::mf_GetAttributeName},
31  {"GetAttributeDefaultCap", &AttributeExecutorModule::mf_GetAttributeDefaultCap},
33  {"GetAttributeBaseValue", &AttributeExecutorModule::mf_GetAttributeBaseValue},
34  {"GetAttributeTemporaryMod", &AttributeExecutorModule::mf_GetAttributeTemporaryMod},
35  {"GetAttributeIntrinsicMod", &AttributeExecutorModule::mf_GetAttributeIntrinsicMod},
36  {"GetAttributeLock", &AttributeExecutorModule::mf_GetAttributeLock},
37  {"GetAttributeCap", &AttributeExecutorModule::mf_GetAttributeCap},
38  {"SetAttributeCap", &AttributeExecutorModule::mf_SetAttributeCap},
39  {"SetAttributeLock", &AttributeExecutorModule::mf_SetAttributeLock},
40  {"SetAttributeBaseValue", &AttributeExecutorModule::mf_SetAttributeBaseValue},
41  {"SetAttributeTemporaryMod", &AttributeExecutorModule::mf_SetAttributeTemporaryMod},
42  {"AlterAttributeTemporaryMod", &AttributeExecutorModule::mf_AlterAttributeTemporaryMod},
43  {"RawSkillToBaseSkill", &AttributeExecutorModule::mf_RawSkillToBase},
44  {"BaseSkillToRawSkill", &AttributeExecutorModule::mf_BaseSkillToRaw}};
45 }
46 namespace Module
47 {
48 using namespace Bscript;
49 using namespace Mobile;
50 
52  : TmplExecutorModule<AttributeExecutorModule>( "attributes", exec )
53 {
54 }
55 
57 {
58  Mobile::Character* chr;
59  Core::USKILLID skillid;
60  int difficulty;
61  unsigned short points;
62 
63  if ( Core::getCharacterParam( exec, 0, chr ) && getSkillIdParam( exec, 1, skillid ) &&
64  getParam( 2, difficulty ) && getParam( 3, points ) )
65  {
66  return new Bscript::BLong( chr->check_skill( skillid, difficulty, points ) );
67  }
68  else
69  {
70  return new Bscript::BError( "Invalid parameter" );
71  }
72 }
73 
75 {
76  const Attribute* attr;
77 
78  if ( !Core::getAttributeParam( exec, 0, attr ) )
79  {
80  return new Bscript::BError( "Invalid parameter type." );
81  }
82 
83  return new Bscript::String( attr->name );
84 }
85 
87 {
88  const Attribute* attr;
89 
90  if ( !Core::getAttributeParam( exec, 0, attr ) )
91  {
92  return new Bscript::BError( "Invalid parameter type." );
93  }
94 
95  return new Bscript::BLong( attr->default_cap );
96 }
97 
99 {
100  Character* chr;
101  const Attribute* attr;
102 
103  if ( getCharacterParam( exec, 0, chr ) && Core::getAttributeParam( exec, 1, attr ) )
104  {
105  const AttributeValue& av = chr->attribute( attr->attrid );
106  return new Bscript::BLong( av.effective() );
107  }
108  else
109  {
110  return new Bscript::BError( "Invalid parameter type" );
111  }
112 }
113 
115 {
116  Character* chr;
117  const Attribute* attr;
118 
119  if ( getCharacterParam( exec, 0, chr ) && Core::getAttributeParam( exec, 1, attr ) )
120  {
121  const AttributeValue& av = chr->attribute( attr->attrid );
122  return new Bscript::BLong( av.base() );
123  }
124  else
125  {
126  return new Bscript::BError( "Invalid parameter type" );
127  }
128 }
129 
131 {
132  Character* chr;
133  const Attribute* attr;
134 
135  if ( getCharacterParam( exec, 0, chr ) && Core::getAttributeParam( exec, 1, attr ) )
136  {
137  const AttributeValue& av = chr->attribute( attr->attrid );
138  return new Bscript::BLong( av.temp_mod() );
139  }
140  else
141  {
142  return new Bscript::BError( "Invalid parameter type" );
143  }
144 }
145 
147 {
148  Character* chr;
149  const Attribute* attr;
150 
151  if ( getCharacterParam( exec, 0, chr ) && Core::getAttributeParam( exec, 1, attr ) )
152  {
153  const AttributeValue& av = chr->attribute( attr->attrid );
154  return new Bscript::BLong( av.intrinsic_mod() );
155  }
156  else
157  {
158  return new Bscript::BError( "Invalid parameter type" );
159  }
160 }
161 
163 {
164  Character* chr;
165  const Attribute* attr;
166 
167  if ( getCharacterParam( exec, 0, chr ) && Core::getAttributeParam( exec, 1, attr ) )
168  {
169  const AttributeValue& av = chr->attribute( attr->attrid );
170  return new Bscript::BLong( av.lock() );
171  }
172  else
173  {
174  return new Bscript::BError( "Invalid parameter type" );
175  }
176 }
178 {
179  Character* chr;
180  const Attribute* attr;
181 
182  if ( getCharacterParam( exec, 0, chr ) && Core::getAttributeParam( exec, 1, attr ) )
183  {
184  const AttributeValue& av = chr->attribute( attr->attrid );
185  return new Bscript::BLong( av.cap() );
186  }
187  else
188  {
189  return new Bscript::BError( "Invalid parameter type" );
190  }
191 }
192 
194 {
195  Character* chr;
196  const Attribute* attr;
197  unsigned short capvalue;
198 
199  // FIXME: SetAttributeCap(mob, attributeid) should reset cap to default value :)
200 
201  if ( getCharacterParam( exec, 0, chr ) && Core::getAttributeParam( exec, 1, attr ) &&
203  {
204  chr->set_dirty();
205  AttributeValue& av = chr->attribute( attr->attrid );
206  int old_cap = av.cap();
207  av.cap( capvalue );
208 
209  if ( old_cap != capvalue )
210  {
212  }
213 
214  return new Bscript::BLong( 1 );
215  }
216  else
217  {
218  return new Bscript::BError( "Invalid parameter type" );
219  }
220 }
221 
223  /* mob, attributeid, lockstate */ )
224 {
225  Character* chr;
226  const Attribute* attr;
227  unsigned short lockstate;
228 
229  if ( getCharacterParam( exec, 0, chr ) && Core::getAttributeParam( exec, 1, attr ) &&
230  getParam( 2, lockstate, 0,
231  2 ) ) // FIXME: hard-coded lock states min and max (0 and 2) -- Nando
232  {
233  chr->set_dirty();
234  AttributeValue& av = chr->attribute( attr->attrid );
235 
236  unsigned char old_state = av.lock();
237  av.lock( (unsigned char)lockstate );
238 
239  if ( old_state != lockstate )
240  {
242  }
243 
244  return new Bscript::BLong( 1 );
245  }
246  else
247  {
248  return new Bscript::BError( "Invalid parameter type" );
249  }
250 }
251 
253  /* mob, attributeid, basevalue */ )
254 {
255  Character* chr;
256  const Attribute* attr;
257  unsigned short basevalue;
258 
259  if ( getCharacterParam( exec, 0, chr ) && Core::getAttributeParam( exec, 1, attr ) &&
261  {
262  chr->set_dirty();
263  AttributeValue& av = chr->attribute( attr->attrid );
264  int eff = av.effective_tenths();
265  av.base( basevalue );
266 
267  if ( eff != av.effective_tenths() )
268  {
270  if ( attr->attrid == Core::gamestate.pAttrParry->attrid )
271  {
272  if ( chr->has_shield() )
273  chr->refresh_ar();
274  }
275  }
276 
277  return new Bscript::BLong( 1 );
278  }
279  else
280  {
281  return new Bscript::BError( "Invalid parameter type" );
282  }
283 }
284 
286  /* mob, attributeid, temporary_mod */ )
287 {
288  Character* chr;
289  const Attribute* attr;
290  int tempmod;
291 
292  if ( getCharacterParam( exec, 0, chr ) && Core::getAttributeParam( exec, 1, attr ) &&
294  {
295  AttributeValue& av = chr->attribute( attr->attrid );
296  int eff = av.effective_tenths();
297  av.temp_mod( static_cast<short>( tempmod ) );
298 
299  if ( eff != av.effective_tenths() )
300  {
302  if ( attr->attrid == Core::gamestate.pAttrParry->attrid )
303  {
304  if ( chr->has_shield() )
305  chr->refresh_ar();
306  }
307  }
308 
309  return new Bscript::BLong( 1 );
310  }
311  else
312  {
313  return new Bscript::BError( "Invalid parameter type" );
314  }
315 }
316 
318  /* mob, attributeid, temporary_mod */ )
319 {
320  Character* chr;
321  const Attribute* attr;
322  int delta;
323 
324  if ( getCharacterParam( exec, 0, chr ) && Core::getAttributeParam( exec, 1, attr ) &&
325  getParam( 2, delta ) )
326  {
327  AttributeValue& av = chr->attribute( attr->attrid );
328  int eff = av.effective_tenths();
329  int newmod = av.temp_mod() + delta;
330 
331  if ( newmod < ATTRIBUTE_MIN_TEMP_MOD || newmod > ATTRIBUTE_MAX_TEMP_MOD )
332  return new BError( "New modifier value is out of range" );
333 
334  av.temp_mod( static_cast<short>( newmod ) );
335 
336  if ( eff != av.effective_tenths() )
337  {
339  if ( attr->attrid == Core::gamestate.pAttrParry->attrid )
340  {
341  if ( chr->has_shield() )
342  chr->refresh_ar();
343  }
344  }
345 
346  return new Bscript::BLong( 1 );
347  }
348  else
349  {
350  return new Bscript::BError( "Invalid parameter type" );
351  }
352 }
353 
354 
356 {
357  int rawskill;
358  if ( getParam( 0, rawskill ) )
359  {
360  if ( rawskill < 0 )
361  rawskill = 0;
362  return new Bscript::BLong( Core::raw_to_base( rawskill ) );
363  }
364  else
365  {
366  return new Bscript::BError( "Invalid parameter type" );
367  }
368 }
369 
371 {
372  unsigned short baseskill;
373  if ( getParam( 0, baseskill ) )
374  return new Bscript::BLong( Core::base_to_raw( baseskill ) );
375  else
376  return new Bscript::BError( "Invalid parameter type" );
377 }
378 }
379 }
Bscript::BObjectImp * mf_CheckSkill()
Bscript::BObjectImp * mf_GetAttribute()
Bscript::BObjectImp * mf_SetAttributeBaseValue()
unsigned char lock() const
Definition: charactr.h:174
Bscript::BObjectImp * mf_GetAttributeName()
unsigned short cap() const
Definition: charactr.h:176
const Mobile::Attribute * pAttrParry
Definition: uvars.h:182
bool getParam(unsigned param, int &value)
Definition: execmodl.cpp:62
unsigned int base_to_raw(unsigned short base)
Definition: skilladv.cpp:72
Bscript::BObjectImp * mf_BaseSkillToRaw()
Bscript::BObjectImp * mf_GetAttributeBaseValue()
bool getAttributeParam(Executor &exec, unsigned param, const Mobile::Attribute *&attr)
Definition: uoexhelp.cpp:610
void set_dirty()
Definition: uobject.h:291
bool getCharacterParam(Bscript::Executor &exec, unsigned param, Mobile::Character *&chrptr)
Definition: uoexhelp.cpp:140
Bscript::BObjectImp * mf_RawSkillToBase()
const unsigned ATTRIBUTE_MIN_BASE
Definition: attribute.h:69
Bscript::BObjectImp * mf_GetAttributeDefaultCap()
Bscript::BObjectImp * mf_GetAttributeIntrinsicMod()
const AttributeValue & attribute(unsigned attrid) const
Definition: charactr.h:1051
unsigned short raw_to_base(unsigned int raw)
Definition: skilladv.cpp:45
bool has_shield() const
Definition: charactr.h:1041
static void tell_attribute_changed(Mobile::Character *who, const Mobile::Attribute *attr)
Definition: cliface.cpp:79
int effective_tenths() const
Definition: charactr.h:155
GameState gamestate
Definition: uvars.cpp:74
Bscript::BObjectImp * mf_GetAttributeLock()
const short ATTRIBUTE_MAX_TEMP_MOD
Definition: attribute.h:73
AttributeExecutorModule(Bscript::Executor &exec)
Bscript::BObjectImp * mf_SetAttributeLock()
const unsigned ATTRIBUTE_MAX_BASE
Definition: attribute.h:70
int intrinsic_mod() const
Definition: charactr.h:172
Bscript::BObjectImp * mf_AlterAttributeTemporaryMod()
Bscript::BObjectImp * mf_SetAttributeCap()
virtual void refresh_ar()
Definition: charactr.cpp:2484
Bscript::BObjectImp * mf_GetAttributeTemporaryMod()
Bscript::BObjectImp * mf_SetAttributeTemporaryMod()
bool getSkillIdParam(Executor &exec, unsigned param, USKILLID &skillid)
Definition: uoexhelp.cpp:594
bool check_skill(Core::USKILLID skillid, int difficulty, unsigned short pointvalue)
Definition: charactr.cpp:2626
Definition: berror.cpp:12
const short ATTRIBUTE_MIN_TEMP_MOD
Definition: attribute.h:72
Bscript::BObjectImp * mf_GetAttributeCap()
std::string name
Definition: attribute.h:40
unsigned short default_cap
Definition: attribute.h:55