• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

polserver / polserver / 12956160445

24 Jan 2025 07:20PM UTC coverage: 58.017% (+0.05%) from 57.971%
12956160445

push

github

web-flow
moved remaining eprog2/3 methods to eprog (#752)

simplified Token

21 of 65 new or added lines in 4 files covered. (32.31%)

13 existing lines in 5 files now uncovered.

41375 of 71315 relevant lines covered (58.02%)

398443.96 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

53.61
/pol-core/pol/uoscrobj.cpp
1
/** @file
2
 *
3
 * @par History
4
 * - 2005/01/24 Shinigami: added ObjMember character.spyonclient2 to get data from packet 0xd9 (Spy
5
 * on Client 2)
6
 * - 2005/03/09 Shinigami: Added Prop Character::Delay_Mod [ms] for WeaponDelay
7
 * - 2005/04/02 Shinigami: UBoat::script_method_id & UBoat::script_method - added optional realm
8
 * param
9
 * - 2005/04/04 Shinigami: Added Prop Character::CreatedAt [PolClock]
10
 * - 2005/08/29 Shinigami: get-/setspyonclient2 renamed to get-/setclientinfo
11
 * - 2005/11/26 Shinigami: changed "strcmp" into "stricmp" to suppress Script Errors
12
 * - 2005/12/09 MuadDib:   Added uclang member for storing UC language from client.
13
 * - 2005/12/09 MuadDib:   Fixed ~ItemGivenEvent not returning items correctly if the script
14
 *                         did nothing with it. Was incorrect str/int comparision for times.
15
 * - 2006/05/16 Shinigami: added Prop Character.Race [RACE_* Constants] to support Elfs
16
 * - 2006/06/15 Austin:    Added mobile.Privs()
17
 * - 2007/07/09 Shinigami: added Prop Character.isUOKR [bool] - UO:KR client used?
18
 * - 2008/07/08 Turley:    Added character.movemode - returns the MoveMode like given in NPCDesc
19
 *                         Added item.stackable - Is item stackable?
20
 * - 2008/12/17 MuadDub:   Added item.tile_layer - returns layer entry from tiledata/tiles.cfg
21
 * - 2009/07/20 MuadDib:   ReAdded on_facing_change() to MBR_FACING: for items.
22
 * - 2009/08/06 MuadDib:   Added gotten_by code for items.
23
 * - 2009/08/31 MuadDib:   Changed layer check on graphic change, excluding mount layer entirely.
24
 * - 2009/09/03 MuadDib:   Relocation of account related cpp/h
25
 *                         Relocation of multi related cpp/h
26
 * - 2009/09/06 Turley:    Removed isUOKR added ClientType
27
 * - 2009/09/22 MuadDib:   Rewrite for Character/NPC to use ar(), ar_mod(), ar_mod(newvalue)
28
 * virtuals.
29
 * - 2009/10/09 Turley:    Added spellbook.spells() & .hasspell() methods
30
 * - 2009/10/10 Turley:    Added spellbook.addspell() & .removespell() methods
31
 * - 2009/10/14 Turley:    Added char.deaf() methods & char.deafened member
32
 * -            MuadDib:   Squelch and Deaf members set to return the gameclock they are in effect
33
 * till.
34
 * - 2009/10/17 Turley:    Moved PrivUpdater to charactr.cpp - Tomi
35
 * - 2009/11/19 Turley:    lightlevel now supports endless duration - Tomi
36
 * - 2009/12/02 Turley:    gargoyle race support
37
 * - 2009/12/03 Turley:    added gargoyle flying movemode
38
 * - 2009/12/21 Turley:    ._method() call fix
39
 *                         multi support of methodscripts
40
 * - 2010/01/15 Turley:    (Tomi) season stuff
41
 * - 2010/02/03 Turley:    MethodScript support for mobiles
42
 * - 2011/12/13 Tomi:      Boat members MBR_COMPONENT, MBR_HULL, MBR_ROPE, MBR_SAILS, MBR_WHEEL,
43
 * MBR_TILLER, MBR_RUDDER, MBR_STORAGE, MBR_WEAPONSLOT
44
 * - 2012/02/02 Tomi:      Added boat member MBR_MULTIID
45
 * - 2012/03/26 Tomi:      Added MBR_LASTCOORD
46
 * - 2012/04/14 Tomi:      Added MBR_FACETID for new map message packet
47
 * - 2012/04/15 Tomi:      Added MBR_EDITABLE for maps
48
 * - 2012/06/02 Tomi:      Added MBR_ACTIVE_SKILL and MBR_CASTING_SPELL for characters
49
 */
50

51

52
#include "uoscrobj.h"
53

54
#include <memory>
55
#include <string>
56

57
#include "../bscript/berror.h"
58
#include "../bscript/dict.h"
59
#include "../bscript/execmodl.h"
60
#include "../bscript/executor.h"
61
#include "../bscript/impstr.h"
62
#include "../bscript/objmembers.h"
63
#include "../bscript/objmethods.h"
64
#include "../clib/clib.h"
65
#include "../clib/stlutil.h"
66
#include "../plib/poltype.h"
67
#include "../plib/uconst.h"
68
#include "accounts/account.h"
69
#include "accounts/acscrobj.h"
70
#include "cmdlevel.h"
71
#include "containr.h"
72
#include "door.h"
73
#include "dynproperties.h"
74
#include "equipdsc.h"
75
#include "exscrobj.h"
76
#include "fnsearch.h"
77
#include "globals/network.h"
78
#include "globals/uvars.h"
79
#include "item/armor.h"
80
#include "item/equipmnt.h"
81
#include "item/item.h"
82
#include "item/itemdesc.h"
83
#include "item/weapon.h"
84
#include "lockable.h"
85
#include "mobile/charactr.h"
86
#include "mobile/corpse.h"
87
#include "mobile/npc.h"
88
#include "mobile/ufacing.h"
89
#include "module/guildmod.h"
90
#include "module/partymod.h"
91
#include "module/uomod.h"
92
#include "multi/boat.h"
93
#include "multi/boatcomp.h"
94
#include "multi/house.h"
95
#include "multi/multi.h"
96
#include "network/cgdata.h"
97
#include "network/client.h"
98
#include "network/packethelper.h"
99
#include "network/packets.h"
100
#include "network/pktdef.h"
101
#include "npctmpl.h"
102
#include "polclass.h"
103
#include "polclock.h"
104
#include "proplist.h"
105
#include "realms/realm.h"
106
#include "realms/realms.h"
107
#include "spelbook.h"
108
#include "statmsg.h"
109
#include "syshookscript.h"
110
#include "tooltips.h"
111
#include "ufunc.h"
112
#include "umap.h"
113
#include "uobject.h"
114
#include "uoclient.h"
115
#include "uoexec.h"
116
#include "uworld.h"
117

118
namespace Pol
119
{
120
namespace Module
121
{
122
using namespace Bscript;
123

124
BApplicObjType euboatrefobjimp_type;
125
BApplicObjType emultirefobjimp_type;
126
BApplicObjType eitemrefobjimp_type;
127
BApplicObjType echaracterrefobjimp_type;
128
BApplicObjType echaracterequipobjimp_type;
129
BApplicObjType storage_area_type;
130
BApplicObjType menu_type;
131
BApplicObjType eclientrefobjimp_type;
132

133
const char* ECharacterRefObjImp::typeOf() const
15✔
134
{
135
  return "MobileRef";
15✔
136
}
137
u8 ECharacterRefObjImp::typeOfInt() const
×
138
{
139
  return OTMobileRef;
×
140
}
141

142
BObjectImp* ECharacterRefObjImp::copy() const
556✔
143
{
144
  return new ECharacterRefObjImp( obj_.get() );
556✔
145
}
146

147
BObjectRef ECharacterRefObjImp::get_member_id( const int id )
411✔
148
{
149
  BObjectImp* result = obj_->get_script_member_id( id );
411✔
150
  if ( result != nullptr )
411✔
151
    return BObjectRef( result );
411✔
152
  return BObjectRef( UninitObject::create() );
×
153
}
154

155
BObjectRef ECharacterRefObjImp::get_member( const char* membername )
×
156
{
157
  ObjMember* objmember = getKnownObjMember( membername );
×
158
  if ( objmember != nullptr )
×
159
    return this->get_member_id( objmember->id );
×
160
  return BObjectRef( UninitObject::create() );
×
161
}
162

163
BObjectRef ECharacterRefObjImp::set_member_id( const int id, BObjectImp* value, bool /*copy*/ )
34✔
164
{
165
  BObjectImp* result = nullptr;
34✔
166
  if ( auto* l = impptrIf<BLong>( value ) )
34✔
167
    result = obj_->set_script_member_id( id, l->value() );
34✔
168
  else if ( auto* s = impptrIf<String>( value ) )
×
169
    result = obj_->set_script_member_id( id, s->value() );
×
170
  else if ( auto* d = impptrIf<Double>( value ) )
×
171
    result = obj_->set_script_member_id_double( id, d->value() );
×
172
  if ( result != nullptr )
34✔
173
    return BObjectRef( result );
28✔
174
  return BObjectRef( UninitObject::create() );
6✔
175
}
176

177
BObjectRef ECharacterRefObjImp::set_member( const char* membername, BObjectImp* value, bool copy )
×
178
{
179
  ObjMember* objmember = getKnownObjMember( membername );
×
180
  if ( objmember != nullptr )
×
181
    return this->set_member_id( objmember->id, value, copy );
×
182
  return BObjectRef( UninitObject::create() );
×
183
}
184

185
BObjectImp* ECharacterRefObjImp::call_polmethod_id( const int id, Core::UOExecutor& ex,
310✔
186
                                                    bool forcebuiltin )
187
{
188
  // MethodScript for npcs in npc->template_ (npctmpl.h) (aka templatebased)
189
  //             for chars in uoclient_general (uoclient.h) (aka one global definition)
190
  if ( obj_->orphan() )
310✔
191
    return new BError( "That object no longer exists" );
×
192
  ObjMethod* mth = getObjMethod( id );
310✔
193
  if ( mth->overridden && !forcebuiltin )
310✔
194
  {
195
    BObjectImp* imp = obj_->custom_script_method( mth->code, ex );
×
196
    if ( imp )
×
197
      return imp;
×
198
  }
199
  BObjectImp* imp = obj_->script_method_id( id, ex );
310✔
200
  if ( imp != nullptr )
310✔
201
    return imp;
310✔
202
  return base::call_polmethod_id( id, ex );
×
203
}
204

205
BObjectImp* ECharacterRefObjImp::call_polmethod( const char* methodname, Core::UOExecutor& ex )
×
206
{
207
  // MethodScript for npcs in npc->template_ (npctmpl.h) (aka templatebased)
208
  //             for chars in uoclient_general (uoclient.h) (aka one global definition)
209
  bool forcebuiltin{ Executor::builtinMethodForced( methodname ) };
×
210
  ObjMethod* objmethod = getKnownObjMethod( methodname );
×
211
  if ( objmethod != nullptr )
×
212
    return this->call_polmethod_id( objmethod->id, ex, forcebuiltin );
×
213
  BObjectImp* imp = obj_->custom_script_method( methodname, ex );
×
214
  if ( imp )
×
215
    return imp;
×
216
  return base::call_polmethod( methodname, ex );
×
217
}
218

219
bool ECharacterRefObjImp::isTrue() const
84✔
220
{
221
  return ( !obj_->orphan() && obj_->logged_in() );
84✔
222
}
223

224
bool ECharacterRefObjImp::operator==( const BObjectImp& objimp ) const
20✔
225
{
226
  if ( objimp.isa( BObjectImp::OTApplicObj ) )
20✔
227
  {
228
    const BApplicObjBase* aob =
229
        Clib::explicit_cast<const BApplicObjBase*, const BObjectImp*>( &objimp );
20✔
230

231
    if ( aob->object_type() == &echaracterrefobjimp_type )
20✔
232
    {
233
      const ECharacterRefObjImp* chrref_imp =
234
          Clib::explicit_cast<const ECharacterRefObjImp*, const BApplicObjBase*>( aob );
20✔
235

236
      return ( chrref_imp->obj_->serial == obj_->serial );
20✔
237
    }
238
    else
239
      return false;
×
240
  }
241
  else if ( objimp.isa( Bscript::BObjectImp::OTBoolean ) )
×
242
    return isTrue() == static_cast<const Bscript::BBoolean&>( objimp ).isTrue();
×
243
  return false;
×
244
}
245

246
bool ECharacterRefObjImp::operator<( const BObjectImp& objimp ) const
×
247
{
248
  if ( objimp.isa( BObjectImp::OTApplicObj ) )
×
249
  {
250
    const BApplicObjBase* aob =
251
        Clib::explicit_cast<const BApplicObjBase*, const BObjectImp*>( &objimp );
×
252

253
    if ( aob->object_type() == &echaracterrefobjimp_type )
×
254
    {
255
      const ECharacterRefObjImp* chrref_imp =
256
          Clib::explicit_cast<const ECharacterRefObjImp*, const BApplicObjBase*>( aob );
×
257

258
      return ( chrref_imp->obj_->serial < obj_->serial );
×
259
    }
260
    else if ( aob->object_type() == &eitemrefobjimp_type )
×
261
      return true;
×
262
    return false;
×
263
  }
264
  return base::operator<( objimp );
×
265
}
266

267
const char* EOfflineCharacterRefObjImp::typeOf() const
7✔
268
{
269
  return "OfflineMobileRef";
7✔
270
}
271
u8 EOfflineCharacterRefObjImp::typeOfInt() const
×
272
{
273
  return OTOfflineMobileRef;
×
274
}
275

276
BObjectImp* EOfflineCharacterRefObjImp::copy() const
30✔
277
{
278
  return new EOfflineCharacterRefObjImp( obj_.get() );
30✔
279
}
280

281
bool EOfflineCharacterRefObjImp::isTrue() const
42✔
282
{
283
  return ( !obj_->orphan() );
42✔
284
}
285

286
const char* EItemRefObjImp::typeOf() const
42✔
287
{
288
  return "ItemRef";
42✔
289
}
290
u8 EItemRefObjImp::typeOfInt() const
×
291
{
292
  return OTItemRef;
×
293
}
294

295
BObjectImp* EItemRefObjImp::copy() const
211✔
296
{
297
  return new EItemRefObjImp( obj_.get() );
211✔
298
}
299

300
BObjectRef EItemRefObjImp::get_member_id( const int id )
320✔
301
{
302
  BObjectImp* result = obj_->get_script_member_id( id );
320✔
303
  if ( result != nullptr )
320✔
304
    return BObjectRef( result );
320✔
305
  return BObjectRef( UninitObject::create() );
×
306
}
307

308
BObjectRef EItemRefObjImp::get_member( const char* membername )
×
309
{
310
  ObjMember* objmember = getKnownObjMember( membername );
×
311
  if ( objmember != nullptr )
×
312
    return this->get_member_id( objmember->id );
×
313
  return BObjectRef( UninitObject::create() );
×
314
}
315

316
BObjectRef EItemRefObjImp::set_member_id( const int id, BObjectImp* value, bool /*copy*/ )
46✔
317
{
318
  BObjectImp* result = nullptr;
46✔
319
  if ( auto* l = impptrIf<BLong>( value ) )
46✔
320
    result = obj_->set_script_member_id( id, l->value() );
29✔
321
  else if ( auto* s = impptrIf<String>( value ) )
17✔
322
    result = obj_->set_script_member_id( id, s->value() );
9✔
323
  else if ( auto* d = impptrIf<Double>( value ) )
8✔
324
    result = obj_->set_script_member_id_double( id, d->value() );
8✔
325
  if ( result != nullptr )
46✔
326
    return BObjectRef( result );
46✔
327
  return BObjectRef( UninitObject::create() );
×
328
}
329

330
BObjectRef EItemRefObjImp::set_member( const char* membername, BObjectImp* value, bool copy )
×
331
{
332
  ObjMember* objmember = getKnownObjMember( membername );
×
333
  if ( objmember != nullptr )
×
334
    return this->set_member_id( objmember->id, value, copy );
×
335
  return BObjectRef( UninitObject::create() );
×
336
}
337

338
BObjectImp* EItemRefObjImp::call_polmethod_id( const int id, Core::UOExecutor& ex,
212✔
339
                                               bool forcebuiltin )
340
{
341
  if ( obj_->orphan() )
212✔
342
    return new BError( "That object no longer exists" );
×
343

344
  ObjMethod* mth = getObjMethod( id );
212✔
345
  if ( mth->overridden && !forcebuiltin )
212✔
346
  {
347
    BObjectImp* imp = obj_->custom_script_method( mth->code, ex );
×
348
    if ( imp )
×
349
      return imp;
×
350
  }
351
  BObjectImp* imp = obj_->script_method_id( id, ex );
212✔
352
  if ( imp != nullptr )
212✔
353
    return imp;
212✔
354
  return base::call_polmethod_id( id, ex );
×
355
}
356

357
BObjectImp* EItemRefObjImp::call_polmethod( const char* methodname, Core::UOExecutor& ex )
4✔
358
{
359
  bool forcebuiltin{ Executor::builtinMethodForced( methodname ) };
4✔
360

361
  ObjMethod* objmethod = getKnownObjMethod( methodname );
4✔
362
  if ( objmethod != nullptr )
4✔
363
    return this->call_polmethod_id( objmethod->id, ex, forcebuiltin );
×
364
  Items::Item* item = obj_.get();
4✔
365
  BObjectImp* imp = item->custom_script_method( methodname, ex );
4✔
366
  if ( imp )
4✔
367
    return imp;
4✔
368
  return base::call_polmethod( methodname, ex );
×
369
}
370

371
bool EItemRefObjImp::isTrue() const
130✔
372
{
373
  return ( !obj_->orphan() );
130✔
374
}
375

376
bool EItemRefObjImp::operator==( const BObjectImp& objimp ) const
25✔
377
{
378
  if ( objimp.isa( BObjectImp::OTApplicObj ) )
25✔
379
  {
380
    const BApplicObjBase* aob =
381
        Clib::explicit_cast<const BApplicObjBase*, const BObjectImp*>( &objimp );
25✔
382

383
    if ( aob->object_type() == &eitemrefobjimp_type )
25✔
384
    {
385
      const EItemRefObjImp* itemref_imp =
386
          Clib::explicit_cast<const EItemRefObjImp*, const BApplicObjBase*>( aob );
25✔
387

388
      return ( itemref_imp->obj_->serial == obj_->serial );
25✔
389
    }
390
    return false;
×
391
  }
392
  else if ( objimp.isa( Bscript::BObjectImp::OTBoolean ) )
×
393
    return isTrue() == static_cast<const Bscript::BBoolean&>( objimp ).isTrue();
×
394
  return false;
×
395
}
396

397
bool EItemRefObjImp::operator<( const BObjectImp& objimp ) const
×
398
{
399
  if ( objimp.isa( BObjectImp::OTApplicObj ) )
×
400
  {
401
    const BApplicObjBase* aob =
402
        Clib::explicit_cast<const BApplicObjBase*, const BObjectImp*>( &objimp );
×
403

404
    if ( aob->object_type() == &eitemrefobjimp_type )
×
405
    {
406
      const EItemRefObjImp* itemref_imp =
407
          Clib::explicit_cast<const EItemRefObjImp*, const BApplicObjBase*>( aob );
×
408

409
      return ( itemref_imp->obj_->serial < obj_->serial );
×
410
    }
411
    return ( &eitemrefobjimp_type < aob->object_type() );
×
412
  }
413

414
  return base::operator<( objimp );
×
415
}
416

417
const char* EUBoatRefObjImp::typeOf() const
×
418
{
419
  return "BoatRef";
×
420
}
421
u8 EUBoatRefObjImp::typeOfInt() const
×
422
{
423
  return OTBoatRef;
×
424
}
425

426
BObjectImp* EUBoatRefObjImp::copy() const
52✔
427
{
428
  return new EUBoatRefObjImp( obj_.get() );
52✔
429
}
430

431
BObjectRef EUBoatRefObjImp::get_member_id( const int id )
6,174✔
432
{
433
  BObjectImp* result = obj_->get_script_member_id( id );
6,174✔
434
  if ( result != nullptr )
6,174✔
435
    return BObjectRef( result );
6,174✔
436
  return BObjectRef( UninitObject::create() );
×
437
}
438

439
BObjectRef EUBoatRefObjImp::get_member( const char* membername )
×
440
{
441
  ObjMember* objmember = getKnownObjMember( membername );
×
442
  if ( objmember != nullptr )
×
443
    return this->get_member_id( objmember->id );
×
444
  return BObjectRef( UninitObject::create() );
×
445
}
446

447
BObjectRef EUBoatRefObjImp::set_member_id( const int id, BObjectImp* value, bool /*copy*/ )
2✔
448
{
449
  BObjectImp* result = nullptr;
2✔
450
  if ( auto* l = impptrIf<BLong>( value ) )
2✔
451
    result = obj_->set_script_member_id( id, l->value() );
1✔
452
  else if ( auto* s = impptrIf<String>( value ) )
1✔
453
    result = obj_->set_script_member_id( id, s->value() );
1✔
454
  else if ( auto* d = impptrIf<Double>( value ) )
×
455
    result = obj_->set_script_member_id_double( id, d->value() );
×
456
  if ( result != nullptr )
2✔
457
    return BObjectRef( result );
2✔
458
  return BObjectRef( UninitObject::create() );
×
459
}
460

461
BObjectRef EUBoatRefObjImp::set_member( const char* membername, BObjectImp* value, bool copy )
×
462
{
463
  ObjMember* objmember = getKnownObjMember( membername );
×
464
  if ( objmember != nullptr )
×
465
    return this->set_member_id( objmember->id, value, copy );
×
466
  return BObjectRef( UninitObject::create() );
×
467
}
468

469
BObjectImp* EUBoatRefObjImp::call_polmethod_id( const int id, Core::UOExecutor& ex,
40✔
470
                                                bool forcebuiltin )
471
{
472
  if ( obj_->orphan() )
40✔
473
    return new BError( "That object no longer exists" );
1✔
474

475
  ObjMethod* mth = getObjMethod( id );
39✔
476
  if ( mth->overridden && !forcebuiltin )
39✔
477
  {
478
    BObjectImp* imp = obj_->custom_script_method( mth->code, ex );
×
479
    if ( imp )
×
480
      return imp;
×
481
  }
482
  BObjectImp* imp = obj_->script_method_id( id, ex );
39✔
483
  if ( imp != nullptr )
39✔
484
    return imp;
39✔
485
  return base::call_polmethod_id( id, ex );
×
486
}
487

488
BObjectImp* EUBoatRefObjImp::call_polmethod( const char* methodname, Core::UOExecutor& ex )
3✔
489
{
490
  bool forcebuiltin{ Executor::builtinMethodForced( methodname ) };
3✔
491
  ObjMethod* objmethod = getKnownObjMethod( methodname );
3✔
492
  if ( objmethod != nullptr )
3✔
493
    return this->call_polmethod_id( objmethod->id, ex, forcebuiltin );
×
494

495
  Multi::UBoat* boat = obj_.get();
3✔
496
  BObjectImp* imp = boat->custom_script_method( methodname, ex );
3✔
497
  if ( imp )
3✔
498
    return imp;
3✔
499

500
  return base::call_polmethod( methodname, ex );
×
501
}
502

503
bool EUBoatRefObjImp::isTrue() const
87✔
504
{
505
  return ( !obj_->orphan() );
87✔
506
}
507

508
bool EUBoatRefObjImp::operator==( const BObjectImp& objimp ) const
×
509
{
510
  if ( objimp.isa( BObjectImp::OTApplicObj ) )
×
511
  {
512
    const BApplicObjBase* aob =
513
        Clib::explicit_cast<const BApplicObjBase*, const BObjectImp*>( &objimp );
×
514

515
    if ( aob->object_type() == &euboatrefobjimp_type )
×
516
    {
517
      const EUBoatRefObjImp* boatref_imp =
518
          Clib::explicit_cast<const EUBoatRefObjImp*, const BApplicObjBase*>( aob );
×
519

520
      return ( boatref_imp->obj_->serial == obj_->serial );
×
521
    }
522
    return false;
×
523
  }
524
  else if ( objimp.isa( Bscript::BObjectImp::OTBoolean ) )
×
525
    return isTrue() == static_cast<const Bscript::BBoolean&>( objimp ).isTrue();
×
526
  return false;
×
527
}
528

529
BObjectImp* EMultiRefObjImp::call_polmethod( const char* methodname, Core::UOExecutor& ex )
×
530
{
531
  bool forcebuiltin{ Executor::builtinMethodForced( methodname ) };
×
532
  ObjMethod* objmethod = getKnownObjMethod( methodname );
×
533
  if ( objmethod != nullptr )
×
534
    return this->call_polmethod_id( objmethod->id, ex, forcebuiltin );
×
535
  Multi::UMulti* multi = obj_.get();
×
536
  BObjectImp* imp = multi->custom_script_method( methodname, ex );
×
537
  if ( imp )
×
538
    return imp;
×
539
  return base::call_polmethod( methodname, ex );
×
540
}
541

542
BObjectImp* EMultiRefObjImp::call_polmethod_id( const int id, Core::UOExecutor& ex,
14✔
543
                                                bool forcebuiltin )
544
{
545
  Multi::UMulti* multi = obj_.get();
14✔
546
  if ( multi->orphan() )
14✔
547
    return new BError( "That object no longer exists" );
×
548

549
  ObjMethod* mth = getObjMethod( id );
14✔
550
  if ( mth->overridden && !forcebuiltin )
14✔
551
  {
552
    BObjectImp* imp = multi->custom_script_method( mth->code, ex );
×
553
    if ( imp )
×
554
      return imp;
×
555
  }
556

557
  BObjectImp* imp = multi->script_method_id( id, ex );
14✔
558
  if ( imp != nullptr )
14✔
559
    return imp;
14✔
560
  return base::call_polmethod_id( id, ex, forcebuiltin );
×
561
}
562

563
const char* EMultiRefObjImp::typeOf() const
44✔
564
{
565
  return "MultiRef";
44✔
566
}
567
u8 EMultiRefObjImp::typeOfInt() const
×
568
{
569
  return OTMultiRef;
×
570
}
571

572
BObjectImp* EMultiRefObjImp::copy() const
57✔
573
{
574
  return new EMultiRefObjImp( obj_.get() );
57✔
575
}
576

577
BObjectRef EMultiRefObjImp::get_member_id( const int id )
53✔
578
{
579
  BObjectImp* result = obj_->get_script_member_id( id );
53✔
580
  if ( result != nullptr )
53✔
581
    return BObjectRef( result );
53✔
582
  return BObjectRef( UninitObject::create() );
×
583
}
584

585
BObjectRef EMultiRefObjImp::get_member( const char* membername )
×
586
{
587
  ObjMember* objmember = getKnownObjMember( membername );
×
588
  if ( objmember != nullptr )
×
589
    return this->get_member_id( objmember->id );
×
590
  return BObjectRef( UninitObject::create() );
×
591
}
592

593
BObjectRef EMultiRefObjImp::set_member_id( const int id, BObjectImp* value, bool /*copy*/ )
2✔
594
{
595
  BObjectImp* result = nullptr;
2✔
596
  if ( auto* l = impptrIf<BLong>( value ) )
2✔
597
    result = obj_->set_script_member_id( id, l->value() );
×
598
  else if ( auto* s = impptrIf<String>( value ) )
2✔
599
    result = obj_->set_script_member_id( id, s->value() );
2✔
600
  else if ( auto* d = impptrIf<Double>( value ) )
×
601
    result = obj_->set_script_member_id_double( id, d->value() );
×
602
  if ( result != nullptr )
2✔
603
    return BObjectRef( result );
2✔
604
  return BObjectRef( UninitObject::create() );
×
605
}
606
BObjectRef EMultiRefObjImp::set_member( const char* membername, BObjectImp* value, bool copy )
×
607
{
608
  ObjMember* objmember = getKnownObjMember( membername );
×
609
  if ( objmember != nullptr )
×
610
    return this->set_member_id( objmember->id, value, copy );
×
611
  return BObjectRef( UninitObject::create() );
×
612
}
613

614
bool EMultiRefObjImp::isTrue() const
22✔
615
{
616
  return ( !obj_->orphan() );
22✔
617
}
618

619
bool EMultiRefObjImp::operator==( const BObjectImp& objimp ) const
3✔
620
{
621
  if ( objimp.isa( BObjectImp::OTApplicObj ) )
3✔
622
  {
623
    const BApplicObjBase* aob =
624
        Clib::explicit_cast<const BApplicObjBase*, const BObjectImp*>( &objimp );
3✔
625

626
    if ( aob->object_type() == &emultirefobjimp_type )
3✔
627
    {
628
      const EMultiRefObjImp* multiref_imp =
629
          Clib::explicit_cast<const EMultiRefObjImp*, const BApplicObjBase*>( aob );
3✔
630

631
      return ( multiref_imp->obj_->serial == obj_->serial );
3✔
632
    }
633
    return false;
×
634
  }
635
  else if ( objimp.isa( Bscript::BObjectImp::OTBoolean ) )
×
636
    return isTrue() == static_cast<const Bscript::BBoolean&>( objimp ).isTrue();
×
637
  return false;
×
638
}
639
}  // namespace Module
640

641
namespace Core
642
{
643
using namespace Bscript;
644

645
BObjectImp* UObject::get_script_member_id( const int id ) const
7,185✔
646
{
647
  if ( orphan() )
7,185✔
648
    return new UninitObject;
1✔
649
  switch ( id )
7,184✔
650
  {
651
  case MBR_X:
111✔
652
    return new BLong( x() );
111✔
653
    break;
654
  case MBR_Y:
99✔
655
    return new BLong( y() );
99✔
656
    break;
657
  case MBR_Z:
86✔
658
    return new BLong( z() );
86✔
659
    break;
660
  case MBR_NAME:
23✔
661
    return new String( name() );
23✔
662
    break;
663
  case MBR_OBJTYPE:
2✔
664
    return new BLong( objtype_ );
2✔
665
    break;
666
  case MBR_GRAPHIC:
5✔
667
    return new BLong( graphic );
5✔
668
    break;
669
  case MBR_SERIAL:
351✔
670
    return new BLong( serial );
351✔
671
    break;
672
  case MBR_COLOR:
1✔
673
    return new BLong( color );
1✔
674
    break;
675
  case MBR_HEIGHT:
×
676
    return new BLong( height );
×
677
    break;
678
  case MBR_FACING:
5✔
679
    return new BLong( facing );
5✔
680
    break;
681
  case MBR_DIRTY:
×
682
    return new BLong( dirty() ? 1 : 0 );
×
683
    break;
684
  case MBR_WEIGHT:
42✔
685
    return new BLong( weight() );
42✔
686
    break;
687
  case MBR_MULTI:
7✔
688
    if ( realm() != nullptr )
7✔
689
    {
690
      Multi::UMulti* multi;
691
      if ( nullptr != ( multi = realm()->find_supporting_multi( pos3d() ) ) )
7✔
692
        return multi->make_ref();
3✔
693
      else
694
        return new BLong( 0 );
4✔
695
    }
696
    else
697
      return new BLong( 0 );
×
698
    break;
699
  case MBR_REALM:
6,034✔
700
    if ( realm() != nullptr )
6,034✔
701
      return new String( realm()->name() );
6,034✔
702
    else
703
      return new BError( "object does not belong to a realm." );
×
704
    break;
705
  case MBR_SPECIFIC_NAME:
×
706
    return new BLong( specific_name() );
×
707
  default:
418✔
708
    return nullptr;
418✔
709
  }
710
}
711

712
BObjectImp* UObject::get_script_member( const char* membername ) const
×
713
{
714
  ObjMember* objmember = getKnownObjMember( membername );
×
715
  if ( objmember != nullptr )
×
716
    return this->get_script_member_id( objmember->id );
×
717
  return nullptr;
×
718
}
719

720
BObjectImp* UObject::set_script_member_id( const int id, const std::string& value )
25✔
721
{
722
  if ( orphan() )
25✔
723
    return new UninitObject;
×
724

725
  set_dirty();
25✔
726
  switch ( id )
25✔
727
  {
728
  case MBR_NAME:
14✔
729
    if ( ismobile() && ( value.empty() || isspace( value[0] ) ) )
14✔
730
      return new BError( "mobile.name must not be empty, and must not begin with a space" );
×
731
    setname( value );
14✔
732
    return new String( name() );
14✔
733
    break;
734
  default:
11✔
735
    return nullptr;
11✔
736
  }
737
}
738

739
BObjectImp* UObject::set_script_member( const char* membername, const std::string& value )
×
740
{
741
  ObjMember* objmember = getKnownObjMember( membername );
×
742
  if ( objmember != nullptr )
×
743
    return this->set_script_member_id( objmember->id, value );
×
744
  return nullptr;
×
745
}
746

747
BObjectImp* UObject::set_script_member_id( const int id, int value )
223✔
748
{
749
  if ( orphan() )
223✔
750
    return new UninitObject;
×
751

752
  set_dirty();
223✔
753
  switch ( id )
223✔
754
  {
755
  case MBR_GRAPHIC:
1✔
756
    setgraphic( Clib::clamp_convert<u16>( value ) );
1✔
757
    return new BLong( graphic );
1✔
758
  case MBR_COLOR:
1✔
759
  {
760
    bool res = setcolor( Clib::clamp_convert<u16>( value ) );
1✔
761
    if ( !res )  // TODO log?
1✔
762
      return new BError( "Invalid color value " + Clib::hexint( value ) );
×
763
    return new BLong( color );
1✔
764
  }
765
  default:
221✔
766
    return nullptr;
221✔
767
  }
768
}
769

770
BObjectImp* UObject::set_script_member( const char* membername, int value )
×
771
{
772
  ObjMember* objmember = getKnownObjMember( membername );
×
773
  if ( objmember != nullptr )
×
774
    return this->set_script_member_id( objmember->id, value );
×
775
  return nullptr;
×
776
}
777

778
BObjectImp* UObject::set_script_member_id_double( const int /*id*/, double /*value*/ )
17✔
779
{
780
  set_dirty();
17✔
781
  return nullptr;
17✔
782
}
783

784
BObjectImp* UObject::set_script_member_double( const char* membername, double value )
4✔
785
{
786
  ObjMember* objmember = getKnownObjMember( membername );
4✔
787
  if ( objmember != nullptr )
4✔
788
    return this->set_script_member_id_double( objmember->id, value );
4✔
789
  return nullptr;
×
790
}
791
}  // namespace Core
792

793
namespace Items
794
{
795
using namespace Bscript;
796

797
BObjectImp* Item::get_script_member_id( const int id ) const
6,643✔
798
{
799
  BObjectImp* imp = base::get_script_member_id( id );
6,643✔
800
  if ( imp != nullptr )
6,643✔
801
    return imp;
6,468✔
802

803
  switch ( id )
175✔
804
  {
805
  case MBR_AMOUNT:
4✔
806
    return new BLong( amount_ );
4✔
807
    break;
808
  case MBR_LAYER:
×
809
    return new BLong( layer );
×
810
    break;
811
  case MBR_TILE_LAYER:
×
812
    return new BLong( tile_layer );
×
813
    break;
814
  case MBR_CONTAINER:
8✔
815
    if ( container != nullptr )
8✔
816
      return container->make_ref();
8✔
817
    return new BLong( 0 );
×
818
    break;
819
  case MBR_USESCRIPT:
1✔
820
    return new String( on_use_script_ );
1✔
821
    break;
822
  case MBR_SNOOPSCRIPT:
1✔
823
    return new String( snoop_script_ );
1✔
824
    break;
825
  case MBR_EQUIPSCRIPT:
1✔
826
    return new String( equip_script_ );
1✔
827
    break;
828
  case MBR_UNEQUIPSCRIPT:
1✔
829
    return new String( unequip_script_ );
1✔
830
    break;
831
  case MBR_DESC:
×
832
    return new String( description() );
×
833
    break;
834
  case MBR_MOVABLE:
1✔
835
    return new BLong( movable() ? 1 : 0 );
1✔
836
    break;
837
  case MBR_INVISIBLE:
1✔
838
    return new BLong( invisible() ? 1 : 0 );
1✔
839
    break;
840
  case MBR_CURSED:
2✔
841
    return new BLong( cursed() ? 1 : 0 );
2✔
842
    break;
843
  case MBR_DECAYAT:
1✔
844
    return new BLong( decayat_gameclock_ );
1✔
845
    break;
846
  case MBR_SELLPRICE:
1✔
847
    return new BLong( sellprice() );
1✔
848
    break;
849
  case MBR_BUYPRICE:
1✔
850
    return new BLong( buyprice() );
1✔
851
    break;
852
  case MBR_NEWBIE:
1✔
853
    return new BLong( newbie() ? 1 : 0 );
1✔
854
    break;
855
  case MBR_INSURED:
1✔
856
    return new BLong( insured() ? 1 : 0 );
1✔
857
    break;
858
  case MBR_ITEM_COUNT:
×
859
    return new BLong( item_count() );
×
860
    break;
861
  case MBR_STACKABLE:
×
862
    return new BLong( stackable() ? 1 : 0 );
×
863
    break;
864
  case MBR_SAVEONEXIT:
×
865
    return new BLong( saveonexit() );
×
866
    break;
867
  case MBR_FIRE_RESIST:
1✔
868
    return new BLong( fire_resist().sum() );
1✔
869
    break;
870
  case MBR_COLD_RESIST:
1✔
871
    return new BLong( cold_resist().sum() );
1✔
872
    break;
873
  case MBR_ENERGY_RESIST:
1✔
874
    return new BLong( energy_resist().sum() );
1✔
875
    break;
876
  case MBR_POISON_RESIST:
1✔
877
    return new BLong( poison_resist().sum() );
1✔
878
    break;
879
  case MBR_PHYSICAL_RESIST:
1✔
880
    return new BLong( physical_resist().sum() );
1✔
881
    break;
882
  case MBR_LOWER_REAG_COST:
1✔
883
    return new BLong( lower_reagent_cost().sum() );
1✔
884
    break;
885
  case MBR_SPELL_DAMAGE_INCREASE:
1✔
886
    return new BLong( spell_damage_increase().sum() );
1✔
887
    break;
888
  case MBR_FASTER_CASTING:
1✔
889
    return new BLong( faster_casting().sum() );
1✔
890
    break;
891
  case MBR_FASTER_CAST_RECOVERY:
1✔
892
    return new BLong( faster_cast_recovery().sum() );
1✔
893
    break;
894
  case MBR_DEFENCE_CHANCE_INCREASE:
1✔
895
    return new BLong( defence_increase().sum() );
1✔
896
    break;
897
  case MBR_DEFENCE_CHANCE_INCREASE_CAP:
1✔
898
    return new BLong( defence_increase_cap().sum() );
1✔
899
    break;
900
  case MBR_LOWER_MANA_COST:
1✔
901
    return new BLong( lower_mana_cost().sum() );
1✔
902
    break;
903
  case MBR_HIT_CHANCE:
×
904
    return new BLong( hit_chance().sum() );
×
905
    break;
906
  case MBR_FIRE_RESIST_CAP:
1✔
907
    return new BLong( fire_resist_cap().sum() );
1✔
908
    break;
909
  case MBR_COLD_RESIST_CAP:
1✔
910
    return new BLong( cold_resist_cap().sum() );
1✔
911
    break;
912
  case MBR_ENERGY_RESIST_CAP:
1✔
913
    return new BLong( energy_resist_cap().sum() );
1✔
914
    break;
915
  case MBR_POISON_RESIST_CAP:
1✔
916
    return new BLong( poison_resist_cap().sum() );
1✔
917
    break;
918
  case MBR_PHYSICAL_RESIST_CAP:
1✔
919
    return new BLong( physical_resist_cap().sum() );
1✔
920
    break;
921
  case MBR_LUCK:
1✔
922
    return new BLong( luck().sum() );
1✔
923
    break;
924
  case MBR_SWING_SPEED_INCREASE:
1✔
925
    return new BLong( swing_speed_increase().sum() );
1✔
926
    break;
927
  case MBR_MIN_ATTACK_RANGE_INCREASE:
×
928
    return new BLong( min_attack_range_increase().sum() );
×
929
    break;
930
  case MBR_MAX_ATTACK_RANGE_INCREASE:
×
931
    return new BLong( max_attack_range_increase().sum() );
×
932
    break;
933
  case MBR_FIRE_RESIST_MOD:
1✔
934
    return new BLong( fire_resist().mod );
1✔
935
    break;
936
  case MBR_COLD_RESIST_MOD:
1✔
937
    return new BLong( cold_resist().mod );
1✔
938
    break;
939
  case MBR_ENERGY_RESIST_MOD:
1✔
940
    return new BLong( energy_resist().mod );
1✔
941
    break;
942
  case MBR_POISON_RESIST_MOD:
1✔
943
    return new BLong( poison_resist().mod );
1✔
944
    break;
945
  case MBR_PHYSICAL_RESIST_MOD:
1✔
946
    return new BLong( physical_resist().mod );
1✔
947
    break;
948
  case MBR_FIRE_DAMAGE:
1✔
949
    return new BLong( fire_damage().sum() );
1✔
950
    break;
951
  case MBR_COLD_DAMAGE:
1✔
952
    return new BLong( cold_damage().sum() );
1✔
953
    break;
954
  case MBR_ENERGY_DAMAGE:
1✔
955
    return new BLong( energy_damage().sum() );
1✔
956
    break;
957
  case MBR_POISON_DAMAGE:
1✔
958
    return new BLong( poison_damage().sum() );
1✔
959
    break;
960
  case MBR_PHYSICAL_DAMAGE:
1✔
961
    return new BLong( physical_damage().sum() );
1✔
962
    break;
963
  case MBR_FIRE_DAMAGE_MOD:
1✔
964
    return new BLong( fire_damage().mod );
1✔
965
    break;
966
  case MBR_COLD_DAMAGE_MOD:
1✔
967
    return new BLong( cold_damage().mod );
1✔
968
    break;
969
  case MBR_ENERGY_DAMAGE_MOD:
1✔
970
    return new BLong( energy_damage().mod );
1✔
971
    break;
972
  case MBR_POISON_DAMAGE_MOD:
1✔
973
    return new BLong( poison_damage().mod );
1✔
974
    break;
975
  case MBR_PHYSICAL_DAMAGE_MOD:
1✔
976
    return new BLong( physical_damage().mod );
1✔
977
    break;
978
  case MBR_LOWER_REAG_COST_MOD:
1✔
979
    return new BLong( lower_reagent_cost().mod );
1✔
980
    break;
981
  case MBR_SPELL_DAMAGE_INCREASE_MOD:
1✔
982
    return new BLong( spell_damage_increase().mod );
1✔
983
    break;
984
  case MBR_FASTER_CASTING_MOD:
1✔
985
    return new BLong( faster_casting().mod );
1✔
986
    break;
987
  case MBR_FASTER_CAST_RECOVERY_MOD:
1✔
988
    return new BLong( faster_cast_recovery().mod );
1✔
989
    break;
990
  case MBR_DEFENCE_CHANCE_INCREASE_MOD:
1✔
991
    return new BLong( defence_increase().mod );
1✔
992
    break;
993
  case MBR_DEFENCE_CHANCE_INCREASE_CAP_MOD:
1✔
994
    return new BLong( defence_increase_cap().mod );
1✔
995
    break;
996
  case MBR_LOWER_MANA_COST_MOD:
1✔
997
    return new BLong( lower_mana_cost().mod );
1✔
998
    break;
999
  case MBR_HIT_CHANCE_MOD:
1✔
1000
    return new BLong( hit_chance().mod );
1✔
1001
    break;
1002
  case MBR_FIRE_RESIST_CAP_MOD:
1✔
1003
    return new BLong( fire_resist_cap().mod );
1✔
1004
    break;
1005
  case MBR_COLD_RESIST_CAP_MOD:
1✔
1006
    return new BLong( cold_resist_cap().mod );
1✔
1007
    break;
1008
  case MBR_ENERGY_RESIST_CAP_MOD:
1✔
1009
    return new BLong( energy_resist_cap().mod );
1✔
1010
    break;
1011
  case MBR_POISON_RESIST_CAP_MOD:
1✔
1012
    return new BLong( poison_resist_cap().mod );
1✔
1013
    break;
1014
  case MBR_PHYSICAL_RESIST_CAP_MOD:
1✔
1015
    return new BLong( physical_resist_cap().mod );
1✔
1016
    break;
1017
  case MBR_LUCK_MOD:
1✔
1018
    return new BLong( luck().mod );
1✔
1019
    break;
1020
  case MBR_SWING_SPEED_INCREASE_MOD:
1✔
1021
    return new BLong( swing_speed_increase().mod );
1✔
1022
    break;
1023
  case MBR_MIN_ATTACK_RANGE_INCREASE_MOD:
×
1024
    return new BLong( min_attack_range_increase().mod );
×
1025
    break;
1026
  case MBR_MAX_ATTACK_RANGE_INCREASE_MOD:
×
1027
    return new BLong( max_attack_range_increase().mod );
×
1028
    break;
1029

1030
  case MBR_GETGOTTENBY:
×
1031
    if ( has_gotten_by() )
×
1032
      return new Module::ECharacterRefObjImp( gotten_by() );
×
1033
    return new BError( "Gotten By nullptr" );
×
1034
    break;
1035
  case MBR_PROCESS:
4✔
1036
  {
1037
    Module::UOExecutorModule* proc = process();
4✔
1038
    if ( proc )
4✔
1039
    {
1040
      Core::UOExecutor* executor = static_cast<Core::UOExecutor*>( &proc->exec );
3✔
1041
      return new Core::ScriptExObjImp( executor );
3✔
1042
    }
1043
    return new BError( "No script running" );
1✔
1044
    break;
1045
  }
1046
  case MBR_DOUBLECLICKRANGE:
×
1047
  {
1048
    const ItemDesc& itemdesc = this->itemdesc();
×
1049
    return new BLong( itemdesc.doubleclick_range );
×
1050
    break;
1051
  }
1052
  case MBR_QUALITY:
1✔
1053
    return new Double( quality() );
1✔
1054
    break;
1055
  case MBR_HP:
5✔
1056
    return new BLong( hp_ );
5✔
1057
    break;
1058
  case MBR_MAXHP_MOD:
1✔
1059
    return new BLong( maxhp_mod() );
1✔
1060
    break;
1061
  case MBR_MAXHP:
×
1062
    return new BLong( Clib::clamp_convert<s32>( maxhp() * quality() ) );
×
1063
    break;
1064
  case MBR_NAME_SUFFIX:
1✔
1065
    return new String( name_suffix() );
1✔
1066
    break;
1067
  case MBR_HOUSE:
×
1068
    if ( house() != nullptr )
×
1069
      return house()->make_ref();
×
1070
    return new BError( "This is a not component of any house" );
×
1071
    break;
1072
  case MBR_NO_DROP:
2✔
1073
    return new BLong( no_drop() );
2✔
1074
  case MBR_CHARACTER_OWNER:
×
1075
  {
1076
    Mobile::Character* owner = GetCharacterOwner();
×
1077
    if ( owner != nullptr )
×
1078
    {
1079
      return new Module::EOfflineCharacterRefObjImp( owner );
×
1080
    }
1081
    return new BError( "This item is not owned by any character" );
×
1082
    break;
1083
  }
1084
  case MBR_WEIGHT_MULTIPLIER_MOD:
×
1085
    return new Double( weight_multiplier_mod() );
×
1086
    break;
1087
  default:
87✔
1088
    return nullptr;
87✔
1089
  }
1090
}
1091

1092
BObjectImp* Item::get_script_member( const char* membername ) const
71✔
1093
{
1094
  ObjMember* objmember = getKnownObjMember( membername );
71✔
1095
  if ( objmember != nullptr )
71✔
1096
    return this->get_script_member_id( objmember->id );
71✔
1097
  return nullptr;
×
1098
}
1099

1100
BObjectImp* Item::set_script_member_id( const int id, const std::string& value )
21✔
1101
{
1102
  BObjectImp* imp = base::set_script_member_id( id, value );
21✔
1103
  if ( imp != nullptr )
21✔
1104
    return imp;
14✔
1105

1106
  switch ( id )
7✔
1107
  {
1108
  case MBR_USESCRIPT:
1✔
1109
    on_use_script_ = value;
1✔
1110
    return new String( value );
1✔
1111
  case MBR_SNOOPSCRIPT:
1✔
1112
    snoop_script_ = value;
1✔
1113
    return new String( value );
1✔
1114
  case MBR_EQUIPSCRIPT:
1✔
1115
    equip_script_ = value;
1✔
1116
    return new String( value );
1✔
1117
  case MBR_UNEQUIPSCRIPT:
1✔
1118
    unequip_script_ = value;
1✔
1119
    return new String( value );
1✔
1120
  case MBR_NAME_SUFFIX:
1✔
1121
    set_dirty();
1✔
1122
    increv();
1✔
1123
    send_object_cache_to_inrange( this );
1✔
1124
    name_suffix( value );
1✔
1125
    return new String( value );
1✔
1126

1127
  default:
2✔
1128
    return nullptr;
2✔
1129
  }
1130
}
1131

1132
BObjectImp* Item::set_script_member( const char* membername, const std::string& value )
7✔
1133
{
1134
  ObjMember* objmember = getKnownObjMember( membername );
7✔
1135
  if ( objmember != nullptr )
7✔
1136
    return this->set_script_member_id( objmember->id, value );
7✔
1137
  return nullptr;
×
1138
}
1139

1140
BObjectImp* Item::set_script_member_id( const int id, int value )
129✔
1141
{
1142
  BObjectImp* imp = base::set_script_member_id( id, value );
129✔
1143
  if ( imp != nullptr )
129✔
1144
    return imp;
2✔
1145

1146
  switch ( id )
127✔
1147
  {
1148
  case MBR_MOVABLE:
15✔
1149
    restart_decay_timer();
15✔
1150
    movable( value ? true : false );
15✔
1151
    increv();
15✔
1152
    return new BLong( movable() );
15✔
1153
  case MBR_INVISIBLE:
1✔
1154
    restart_decay_timer();
1✔
1155
    invisible( value ? true : false );
1✔
1156
    increv();
1✔
1157
    return new BLong( invisible() );
1✔
1158
  case MBR_CURSED:
1✔
1159
    restart_decay_timer();
1✔
1160
    cursed( value ? true : false );
1✔
1161
    increv();
1✔
1162
    return new BLong( cursed() );
1✔
1163
  case MBR_DECAYAT:
1✔
1164
    decayat_gameclock_ = value;
1✔
1165
    return new BLong( decayat_gameclock_ );
1✔
1166
  case MBR_SELLPRICE:
1✔
1167
    sellprice( value );
1✔
1168
    return new BLong( value );
1✔
1169
  case MBR_BUYPRICE:
1✔
1170
    buyprice( value );
1✔
1171
    return new BLong( value );
1✔
1172
  case MBR_NEWBIE:
1✔
1173
    restart_decay_timer();
1✔
1174
    newbie( value ? true : false );
1✔
1175
    increv();
1✔
1176
    return new BLong( newbie() );
1✔
1177
  case MBR_INSURED:
1✔
1178
    restart_decay_timer();
1✔
1179
    insured( value ? true : false );
1✔
1180
    increv();
1✔
1181
    return new BLong( insured() );
1✔
1182
  case MBR_FACING:
1✔
1183
    setfacing( (u8)value );
1✔
1184
    return new BLong( facing );
1✔
1185
  case MBR_SAVEONEXIT:
×
1186
    saveonexit( value ? true : false );
×
1187
    return new BLong( saveonexit() );
×
1188
  case MBR_FIRE_RESIST_MOD:
3✔
1189
    fire_resist( fire_resist().setAsMod( Clib::clamp_convert<s16>( value ) ) );
3✔
1190
    if ( container != nullptr )
3✔
1191
    {
1192
      if ( Core::IsCharacter( container->serial ) )
2✔
1193
      {
1194
        Mobile::Character* chr = container->get_chr_owner();
2✔
1195
        if ( chr != nullptr )
2✔
1196
          chr->refresh_ar();
2✔
1197
      }
1198
    }
1199
    return new BLong( fire_resist().mod );
3✔
1200
    break;
1201
  case MBR_COLD_RESIST_MOD:
3✔
1202
    cold_resist( cold_resist().setAsMod( Clib::clamp_convert<s16>( value ) ) );
3✔
1203
    if ( container != nullptr )
3✔
1204
    {
1205
      if ( Core::IsCharacter( container->serial ) )
2✔
1206
      {
1207
        Mobile::Character* chr = container->get_chr_owner();
2✔
1208
        if ( chr != nullptr )
2✔
1209
          chr->refresh_ar();
2✔
1210
      }
1211
    }
1212
    return new BLong( cold_resist().mod );
3✔
1213
    break;
1214
  case MBR_ENERGY_RESIST_MOD:
3✔
1215
    energy_resist( energy_resist().setAsMod( Clib::clamp_convert<s16>( value ) ) );
3✔
1216
    if ( container != nullptr )
3✔
1217
    {
1218
      if ( Core::IsCharacter( container->serial ) )
2✔
1219
      {
1220
        Mobile::Character* chr = container->get_chr_owner();
2✔
1221
        if ( chr != nullptr )
2✔
1222
          chr->refresh_ar();
2✔
1223
      }
1224
    }
1225
    return new BLong( energy_resist().mod );
3✔
1226
    break;
1227
  case MBR_POISON_RESIST_MOD:
3✔
1228
    poison_resist( poison_resist().setAsMod( Clib::clamp_convert<s16>( value ) ) );
3✔
1229
    if ( container != nullptr )
3✔
1230
    {
1231
      if ( Core::IsCharacter( container->serial ) )
2✔
1232
      {
1233
        Mobile::Character* chr = container->get_chr_owner();
2✔
1234
        if ( chr != nullptr )
2✔
1235
          chr->refresh_ar();
2✔
1236
      }
1237
    }
1238
    return new BLong( poison_resist().mod );
3✔
1239
    break;
1240
  case MBR_PHYSICAL_RESIST_MOD:
3✔
1241
    physical_resist( physical_resist().setAsMod( Clib::clamp_convert<s16>( value ) ) );
3✔
1242
    if ( container != nullptr )
3✔
1243
    {
1244
      if ( Core::IsCharacter( container->serial ) )
2✔
1245
      {
1246
        Mobile::Character* chr = container->get_chr_owner();
2✔
1247
        if ( chr != nullptr )
2✔
1248
          chr->refresh_ar();
2✔
1249
      }
1250
    }
1251
    return new BLong( physical_resist().mod );
3✔
1252
    break;
1253
  case MBR_FIRE_RESIST_CAP_MOD:
2✔
1254
    fire_resist_cap( fire_resist_cap().setAsMod( Clib::clamp_convert<s16>( value ) ) );
2✔
1255
    if ( container != nullptr )
2✔
1256
    {
1257
      if ( Core::IsCharacter( container->serial ) )
1✔
1258
      {
1259
        Mobile::Character* chr = container->get_chr_owner();
1✔
1260
        if ( chr != nullptr )
1✔
1261
          chr->refresh_ar();
1✔
1262
      }
1263
    }
1264
    return new BLong( fire_resist_cap().mod );
2✔
1265
    break;
1266
  case MBR_COLD_RESIST_CAP_MOD:
2✔
1267
    cold_resist_cap( cold_resist_cap().setAsMod( Clib::clamp_convert<s16>( value ) ) );
2✔
1268
    if ( container != nullptr )
2✔
1269
    {
1270
      if ( Core::IsCharacter( container->serial ) )
1✔
1271
      {
1272
        Mobile::Character* chr = container->get_chr_owner();
1✔
1273
        if ( chr != nullptr )
1✔
1274
          chr->refresh_ar();
1✔
1275
      }
1276
    }
1277
    return new BLong( cold_resist_cap().mod );
2✔
1278
    break;
1279
  case MBR_ENERGY_RESIST_CAP_MOD:
2✔
1280
    energy_resist_cap( energy_resist_cap().setAsMod( Clib::clamp_convert<s16>( value ) ) );
2✔
1281
    if ( container != nullptr )
2✔
1282
    {
1283
      if ( Core::IsCharacter( container->serial ) )
1✔
1284
      {
1285
        Mobile::Character* chr = container->get_chr_owner();
1✔
1286
        if ( chr != nullptr )
1✔
1287
          chr->refresh_ar();
1✔
1288
      }
1289
    }
1290
    return new BLong( energy_resist_cap().mod );
2✔
1291
    break;
1292
  case MBR_POISON_RESIST_CAP_MOD:
2✔
1293
    poison_resist_cap( poison_resist_cap().setAsMod( Clib::clamp_convert<s16>( value ) ) );
2✔
1294
    if ( container != nullptr )
2✔
1295
    {
1296
      if ( Core::IsCharacter( container->serial ) )
1✔
1297
      {
1298
        Mobile::Character* chr = container->get_chr_owner();
1✔
1299
        if ( chr != nullptr )
1✔
1300
          chr->refresh_ar();
1✔
1301
      }
1302
    }
1303
    return new BLong( poison_resist_cap().mod );
2✔
1304
    break;
1305
  case MBR_PHYSICAL_RESIST_CAP_MOD:
2✔
1306
    physical_resist_cap( physical_resist_cap().setAsMod( Clib::clamp_convert<s16>( value ) ) );
2✔
1307
    if ( container != nullptr )
2✔
1308
    {
1309
      if ( Core::IsCharacter( container->serial ) )
1✔
1310
      {
1311
        Mobile::Character* chr = container->get_chr_owner();
1✔
1312
        if ( chr != nullptr )
1✔
1313
          chr->refresh_ar();
1✔
1314
      }
1315
    }
1316
    return new BLong( physical_resist_cap().mod );
2✔
1317
    break;
1318

1319
  case MBR_FIRE_DAMAGE_MOD:
3✔
1320
    fire_damage( fire_damage().setAsMod( Clib::clamp_convert<s16>( value ) ) );
3✔
1321
    if ( container != nullptr )
3✔
1322
    {
1323
      if ( Core::IsCharacter( container->serial ) )
2✔
1324
      {
1325
        Mobile::Character* chr = container->get_chr_owner();
2✔
1326
        if ( chr != nullptr )
2✔
1327
          chr->refresh_ar();
2✔
1328
      }
1329
    }
1330
    return new BLong( fire_damage().mod );
3✔
1331
    break;
1332
  case MBR_COLD_DAMAGE_MOD:
3✔
1333
    cold_damage( cold_damage().setAsMod( Clib::clamp_convert<s16>( value ) ) );
3✔
1334
    if ( container != nullptr )
3✔
1335
    {
1336
      if ( Core::IsCharacter( container->serial ) )
2✔
1337
      {
1338
        Mobile::Character* chr = container->get_chr_owner();
2✔
1339
        if ( chr != nullptr )
2✔
1340
          chr->refresh_ar();
2✔
1341
      }
1342
    }
1343
    return new BLong( cold_damage().mod );
3✔
1344
    break;
1345
  case MBR_ENERGY_DAMAGE_MOD:
3✔
1346
    energy_damage( energy_damage().setAsMod( Clib::clamp_convert<s16>( value ) ) );
3✔
1347
    if ( container != nullptr )
3✔
1348
    {
1349
      if ( Core::IsCharacter( container->serial ) )
2✔
1350
      {
1351
        Mobile::Character* chr = container->get_chr_owner();
2✔
1352
        if ( chr != nullptr )
2✔
1353
          chr->refresh_ar();
2✔
1354
      }
1355
    }
1356
    return new BLong( energy_damage().mod );
3✔
1357
    break;
1358
  case MBR_POISON_DAMAGE_MOD:
3✔
1359
    poison_damage( poison_damage().setAsMod( Clib::clamp_convert<s16>( value ) ) );
3✔
1360
    if ( container != nullptr )
3✔
1361
    {
1362
      if ( Core::IsCharacter( container->serial ) )
2✔
1363
      {
1364
        Mobile::Character* chr = container->get_chr_owner();
2✔
1365
        if ( chr != nullptr )
2✔
1366
          chr->refresh_ar();
2✔
1367
      }
1368
    }
1369
    return new BLong( poison_damage().mod );
3✔
1370
    break;
1371

1372
  case MBR_PHYSICAL_DAMAGE_MOD:
3✔
1373
    physical_damage( physical_damage().setAsMod( Clib::clamp_convert<s16>( value ) ) );
3✔
1374
    if ( container != nullptr )
3✔
1375
    {
1376
      if ( Core::IsCharacter( container->serial ) )
2✔
1377
      {
1378
        Mobile::Character* chr = container->get_chr_owner();
2✔
1379
        if ( chr != nullptr )
2✔
1380
          chr->refresh_ar();
2✔
1381
      }
1382
    }
1383
    return new BLong( physical_damage().mod );
3✔
1384
    break;
1385

1386
  case MBR_LOWER_REAG_COST_MOD:
3✔
1387
    lower_reagent_cost( lower_reagent_cost().setAsMod( Clib::clamp_convert<s16>( value ) ) );
3✔
1388
    if ( container != nullptr )
3✔
1389
    {
1390
      if ( Core::IsCharacter( container->serial ) )
2✔
1391
      {
1392
        Mobile::Character* chr = container->get_chr_owner();
2✔
1393
        if ( chr != nullptr )
2✔
1394
          chr->refresh_ar();
2✔
1395
      }
1396
    }
1397
    return new BLong( lower_reagent_cost().mod );
3✔
1398
    break;
1399
  case MBR_SPELL_DAMAGE_INCREASE_MOD:
3✔
1400
    spell_damage_increase( spell_damage_increase().setAsMod( Clib::clamp_convert<s16>( value ) ) );
3✔
1401
    if ( container != nullptr )
3✔
1402
    {
1403
      if ( Core::IsCharacter( container->serial ) )
2✔
1404
      {
1405
        Mobile::Character* chr = container->get_chr_owner();
2✔
1406
        if ( chr != nullptr )
2✔
1407
          chr->refresh_ar();
2✔
1408
      }
1409
    }
1410
    return new BLong( spell_damage_increase().mod );
3✔
1411
    break;
1412
  case MBR_FASTER_CASTING_MOD:
3✔
1413
    faster_casting( faster_casting().setAsMod( Clib::clamp_convert<s16>( value ) ) );
3✔
1414
    if ( container != nullptr )
3✔
1415
    {
1416
      if ( Core::IsCharacter( container->serial ) )
2✔
1417
      {
1418
        Mobile::Character* chr = container->get_chr_owner();
2✔
1419
        if ( chr != nullptr )
2✔
1420
          chr->refresh_ar();
2✔
1421
      }
1422
    }
1423
    return new BLong( faster_casting().mod );
3✔
1424
    break;
1425
  case MBR_FASTER_CAST_RECOVERY_MOD:
3✔
1426
    faster_cast_recovery( faster_cast_recovery().setAsMod( Clib::clamp_convert<s16>( value ) ) );
3✔
1427
    if ( container != nullptr )
3✔
1428
    {
1429
      if ( Core::IsCharacter( container->serial ) )
2✔
1430
      {
1431
        Mobile::Character* chr = container->get_chr_owner();
2✔
1432
        if ( chr != nullptr )
2✔
1433
          chr->refresh_ar();
2✔
1434
      }
1435
    }
1436
    return new BLong( faster_cast_recovery().mod );
3✔
1437
    break;
1438
  case MBR_DEFENCE_CHANCE_INCREASE_MOD:
3✔
1439
    defence_increase( defence_increase().setAsMod( Clib::clamp_convert<s16>( value ) ) );
3✔
1440
    if ( container != nullptr )
3✔
1441
    {
1442
      if ( Core::IsCharacter( container->serial ) )
2✔
1443
      {
1444
        Mobile::Character* chr = container->get_chr_owner();
2✔
1445
        if ( chr != nullptr )
2✔
1446
          chr->refresh_ar();
2✔
1447
      }
1448
    }
1449
    return new BLong( defence_increase().mod );
3✔
1450
    break;
1451
  case MBR_DEFENCE_CHANCE_INCREASE_CAP_MOD:
2✔
1452
    defence_increase_cap( defence_increase_cap().setAsMod( Clib::clamp_convert<s16>( value ) ) );
2✔
1453
    if ( container != nullptr )
2✔
1454
    {
1455
      if ( Core::IsCharacter( container->serial ) )
1✔
1456
      {
1457
        Mobile::Character* chr = container->get_chr_owner();
1✔
1458
        if ( chr != nullptr )
1✔
1459
          chr->refresh_ar();
1✔
1460
      }
1461
    }
1462
    return new BLong( defence_increase_cap().mod );
2✔
1463
    break;
1464
  case MBR_LOWER_MANA_COST_MOD:
3✔
1465
    lower_mana_cost( lower_mana_cost().setAsMod( Clib::clamp_convert<s16>( value ) ) );
3✔
1466
    if ( container != nullptr )
3✔
1467
    {
1468
      if ( Core::IsCharacter( container->serial ) )
2✔
1469
      {
1470
        Mobile::Character* chr = container->get_chr_owner();
2✔
1471
        if ( chr != nullptr )
2✔
1472
          chr->refresh_ar();
2✔
1473
      }
1474
    }
1475
    return new BLong( lower_mana_cost().mod );
3✔
1476
    break;
1477
  case MBR_HITCHANCE_MOD:  // to be made redundant in the future
3✔
1478
  case MBR_HIT_CHANCE_MOD:
1479
    hit_chance( hit_chance().setAsMod( Clib::clamp_convert<s16>( value ) ) );
3✔
1480
    if ( container != nullptr )
3✔
1481
    {
1482
      if ( Core::IsCharacter( container->serial ) )
2✔
1483
      {
1484
        Mobile::Character* chr = container->get_chr_owner();
2✔
1485
        if ( chr != nullptr )
2✔
1486
          chr->refresh_ar();
2✔
1487
      }
1488
    }
1489
    return new BLong( hit_chance().mod );
3✔
1490
    break;
1491
  case MBR_LUCK_MOD:
3✔
1492
    luck( luck().setAsMod( Clib::clamp_convert<s16>( value ) ) );
3✔
1493
    if ( container != nullptr )
3✔
1494
    {
1495
      if ( Core::IsCharacter( container->serial ) )
2✔
1496
      {
1497
        Mobile::Character* chr = container->get_chr_owner();
2✔
1498
        if ( chr != nullptr )
2✔
1499
          chr->refresh_ar();
2✔
1500
      }
1501
    }
1502
    return new BLong( luck().mod );
3✔
1503
    break;
1504
  case MBR_SWING_SPEED_INCREASE_MOD:
3✔
1505
    swing_speed_increase( swing_speed_increase().setAsMod( Clib::clamp_convert<s16>( value ) ) );
3✔
1506
    if ( container != nullptr )
3✔
1507
    {
1508
      if ( Core::IsCharacter( container->serial ) )
2✔
1509
      {
1510
        Mobile::Character* chr = container->get_chr_owner();
2✔
1511
        if ( chr != nullptr )
2✔
1512
          chr->refresh_ar();
2✔
1513
      }
1514
    }
1515
    return new BLong( swing_speed_increase().mod );
3✔
1516
    break;
1517
  case MBR_MIN_ATTACK_RANGE_INCREASE_MOD:
×
1518
    min_attack_range_increase(
×
1519
        min_attack_range_increase().setAsMod( Clib::clamp_convert<s16>( value ) ) );
×
1520
    if ( container != nullptr )
×
1521
    {
1522
      if ( Core::IsCharacter( container->serial ) )
×
1523
      {
1524
        Mobile::Character* chr = container->get_chr_owner();
×
1525
        if ( chr != nullptr )
×
1526
          chr->refresh_ar();
×
1527
      }
1528
    }
1529
    return new BLong( min_attack_range_increase().mod );
×
1530
    break;
1531
  case MBR_MAX_ATTACK_RANGE_INCREASE_MOD:
×
1532
    max_attack_range_increase(
×
1533
        max_attack_range_increase().setAsMod( Clib::clamp_convert<s16>( value ) ) );
×
1534
    if ( container != nullptr )
×
1535
    {
1536
      if ( Core::IsCharacter( container->serial ) )
×
1537
      {
1538
        Mobile::Character* chr = container->get_chr_owner();
×
1539
        if ( chr != nullptr )
×
1540
          chr->refresh_ar();
×
1541
      }
1542
    }
1543
    return new BLong( max_attack_range_increase().mod );
×
1544
    break;
1545

1546
  case MBR_QUALITY:
×
1547
    quality( double( value ) );
×
1548
    return new Double( double( value ) );
×
1549
    break;
1550
  case MBR_HP:
5✔
1551
    hp_ = Clib::clamp_convert<u16>( value );
5✔
1552

1553
    if ( this->isa( Core::UOBJ_CLASS::CLASS_ARMOR ) )
5✔
1554
    {
1555
      if ( container != nullptr )
×
1556
      {
1557
        if ( Core::IsCharacter( container->serial ) )
×
1558
        {
1559
          Mobile::Character* chr = container->get_chr_owner();
×
1560
          if ( chr != nullptr )
×
1561
            chr->refresh_ar();
×
1562
        }
1563
      }
1564
    }
1565
    return new BLong( hp_ );
5✔
1566
  case MBR_MAXHP_MOD:
1✔
1567
    this->maxhp_mod( Clib::clamp_convert<s16>( value ) );
1✔
1568
    if ( this->isa( Core::UOBJ_CLASS::CLASS_ARMOR ) )
1✔
1569
    {
1570
      if ( container != nullptr )
×
1571
      {
1572
        if ( Core::IsCharacter( container->serial ) )
×
1573
        {
1574
          Mobile::Character* chr = container->get_chr_owner();
×
1575
          if ( chr != nullptr )
×
1576
            chr->refresh_ar();
×
1577
        }
1578
      }
1579
    }
1580
    return new BLong( value );
1✔
1581
  case MBR_NO_DROP:
3✔
1582
    no_drop( value ? true : false );
3✔
1583
    return new BLong( no_drop() );
3✔
1584
  case MBR_WEIGHT_MULTIPLIER_MOD:
1✔
1585
    return set_script_member_id_double( id, value );
1✔
1586
  default:
25✔
1587
    return nullptr;
25✔
1588
  }
1589
}
1590

1591
BObjectImp* Item::set_script_member( const char* membername, int value )
39✔
1592
{
1593
  ObjMember* objmember = getKnownObjMember( membername );
39✔
1594
  if ( objmember != nullptr )
39✔
1595
    return this->set_script_member_id( objmember->id, value );
39✔
1596
  return nullptr;
×
1597
}
1598

1599
BObjectImp* Item::set_script_member_id_double( const int id, double value )
17✔
1600
{
1601
  BObjectImp* imp = base::set_script_member_id_double( id, value );
17✔
1602
  if ( imp != nullptr )
17✔
1603
    return imp;
×
1604
  switch ( id )
17✔
1605
  {
1606
  case MBR_QUALITY:
1✔
1607
    quality( value );
1✔
1608
    return new Double( value );
1✔
1609
  case MBR_WEIGHT_MULTIPLIER_MOD:
4✔
1610
  {
1611
    if ( value < 0.0 )
4✔
1612
    {
1613
      return new BError( "weight_multiplier_mod cannot be less than 0.0" );
×
1614
    }
1615

1616
    if ( container )
4✔
1617
    {
1618
      int old_weight = weight();
2✔
1619
      weight_multiplier_mod( value );
2✔
1620
      int new_weight = weight();
2✔
1621
      int weight_delta = new_weight - old_weight;
2✔
1622
      container->add_bulk( 0, weight_delta );
2✔
1623
    }
1624
    else
1625
    {
1626
      weight_multiplier_mod( value );
2✔
1627
    }
1628

1629
    increv_send_object_recursive();
4✔
1630

1631
    UpdateCharacterWeight( this );
4✔
1632
    return new Double( weight_multiplier_mod() );
4✔
1633
    break;
1634
  }
1635
  default:
12✔
1636
    return nullptr;
12✔
1637
  }
1638
}
1639

1640
BObjectImp* Item::set_script_member_double( const char* membername, double value )
1✔
1641
{
1642
  ObjMember* objmember = getKnownObjMember( membername );
1✔
1643
  if ( objmember != nullptr )
1✔
1644
    return this->set_script_member_id_double( objmember->id, value );
1✔
1645
  return nullptr;
×
1646
}
1647

1648
BObjectImp* Item::script_method_id( const int id, Core::UOExecutor& ex )
265✔
1649
{
1650
  BObjectImp* imp = base::script_method_id( id, ex );
265✔
1651
  if ( imp != nullptr )
265✔
1652
    return imp;
232✔
1653
  switch ( id )
33✔
1654
  {
1655
  case MTH_SPLITSTACK_AT:
×
1656
  {
1657
    unsigned short amt;
1658
    Core::Pos4d newpos;
×
1659
    Item* new_stack( nullptr );
×
1660
    u16 item_amount = this->getamount();
×
1661

1662
    if ( !ex.hasParams( 5 ) )
×
1663
      return new BError( "Not enough parameters" );
×
1664
    else if ( !ex.getPos4dParam( 0, 1, 2, 3, &newpos ) )
×
1665
      return new BError( "Invalid parameter type" );
×
1666
    else if ( !ex.getParam( 4, amt ) )
×
1667
      return new BError( "No amount specified to pull from existing stack" );
×
1668
    else if ( amt > this->getamount() )
×
1669
      return new BError( "Amount must be less than or equal to the stack amount" );
×
1670
    else if ( amt < 1 )
×
1671
      return new BError( "Amount was less than 1" );
×
1672
    else if ( this->inuse() )
×
1673
      return new BError( "Item is in use" );
×
1674

1675
    // Check first if the item is non-stackable and just force stacked with CreateItemInInventory
1676
    if ( !this->stackable() && amt > 1 )
×
1677
    {
1678
      unsigned short i;
1679

1680
      for ( i = 1; i <= amt; i++ )
×
1681
      {
1682
        if ( this->getamount() == 1 )
×
1683
          new_stack = this->clone();
×
1684
        else
1685
          new_stack = this->remove_part_of_stack( 1 );
×
1686
        new_stack->setposition( newpos );
×
1687
        add_item_to_world( new_stack );
×
1688
        move_item( new_stack, newpos );
×
1689
        update_item_to_inrange( new_stack );
×
1690
      }
1691

1692
      if ( this->getamount() == 1 )
×
1693
        destroy_item( this );
×
1694
      else
1695
        update_item_to_inrange( this );
×
1696
      if ( new_stack != nullptr )
×
1697
        return new Module::EItemRefObjImp( new_stack );
×
1698
      return nullptr;
×
1699
    }
1700

1701

1702
    if ( amt == this->getamount() )
×
1703
      new_stack = this->clone();
×
1704
    else
1705
      new_stack = this->remove_part_of_stack( amt );
×
1706

1707
    new_stack->setposition( newpos );
×
1708
    new_stack->setamount( amt );
×
1709
    add_item_to_world( new_stack );
×
1710
    move_item( new_stack, newpos );
×
1711
    update_item_to_inrange( new_stack );
×
1712

1713
    if ( amt == item_amount )
×
1714
      destroy_item( this );
×
1715
    else
1716
      update_item_to_inrange( this );
×
1717

1718
    return new Module::EItemRefObjImp( new_stack );
×
1719

1720
    break;
1721
  }
1722
  case MTH_SPLITSTACK_INTO:
1✔
1723
  {
1724
    unsigned short amt;
1725
    Item* cont_item;
1726

1727
    if ( !ex.hasParams( 2 ) )
1✔
1728
      return new BError( "Not enough parameters" );
×
1729
    else if ( !ex.getItemParam( 0, cont_item ) )
1✔
1730
      return new BError( "No container specified" );
×
1731
    else if ( !ex.getParam( 1, amt ) )
1✔
1732
      return new BError( "No amount specified to pull from existing stack" );
×
1733
    else if ( amt > this->getamount() )
1✔
1734
      return new BError( "Amount must be less than or equal to stack amount" );
×
1735
    else if ( amt < 1 )
1✔
1736
      return new BError( "Amount was less than 1" );
×
1737
    else if ( this->inuse() )
1✔
1738
      return new BError( "Item is in use" );
×
1739
    else if ( !cont_item->isa( Core::UOBJ_CLASS::CLASS_CONTAINER ) )
1✔
1740
      return new BError( "Non-container selected as target" );
×
1741

1742
    Core::UContainer* newcontainer = static_cast<Core::UContainer*>( cont_item );
1✔
1743

1744
    // Check first if the item is non-stackable and just force stacked with CreateItemInInventory
1745

1746
    Item* new_stack( nullptr );
1✔
1747
    u16 item_amount = this->getamount();
1✔
1748

1749
    if ( !this->stackable() && amt > 1 )
1✔
1750
    {
1751
      for ( unsigned short i = 1; i <= amt; i++ )
×
1752
      {
1753
        if ( this->getamount() == 1 )
×
1754
          new_stack = this->clone();
×
1755
        else
1756
          new_stack = this->remove_part_of_stack( 1 );
×
1757

1758
        bool can_insert = newcontainer->can_insert_add_item(
×
1759
            nullptr, Core::UContainer::MT_CORE_MOVED, new_stack );
1760
        if ( !can_insert )
×
1761
        {
1762
          // Put new_stack back with the original stack
1763
          if ( new_stack != this )
×
1764
            this->add_to_self( new_stack );
×
1765
          return new BError( "Could not insert new stack into container" );
×
1766
        }
1767

1768
        newcontainer->add_at_random_location( new_stack );
×
1769
        update_item_to_inrange( new_stack );
×
1770
        UpdateCharacterWeight( new_stack );
×
1771
        newcontainer->on_insert_add_item( nullptr, Core::UContainer::MT_CORE_MOVED, new_stack );
×
1772
      }
1773

1774
      if ( this->getamount() == 1 )
×
1775
        destroy_item( this );
×
1776
      else
1777
        update_item_to_inrange( this );
×
1778
      if ( new_stack != nullptr )
×
1779
        return new Module::EItemRefObjImp( new_stack );
×
1780
      return nullptr;
×
1781
    }
1782

1783
    if ( amt == this->getamount() )
1✔
1784
      new_stack = this->clone();
×
1785
    else
1786
      new_stack = this->remove_part_of_stack( amt );
1✔
1787

1788
    auto create_new_stack = [&]() -> BObjectImp*
1✔
1789
    {
1790
      bool can_insert =
1791
          newcontainer->can_insert_add_item( nullptr, Core::UContainer::MT_CORE_MOVED, new_stack );
1✔
1792
      if ( !can_insert )
1✔
1793
      {
1794
        // Put newstack back with the original stack
1795
        if ( new_stack != this )
×
1796
          this->add_to_self( new_stack );
×
1797
        return new BError( "Could not insert new stack into container" );
×
1798
      }
1799
      newcontainer->add_at_random_location( new_stack );
1✔
1800
      new_stack->setamount( amt );
1✔
1801
      update_item_to_inrange( new_stack );
1✔
1802
      UpdateCharacterWeight( new_stack );
1✔
1803
      newcontainer->on_insert_add_item( nullptr, Core::UContainer::MT_CORE_MOVED, new_stack );
1✔
1804

1805
      if ( amt == item_amount )
1✔
1806
        destroy_item( this );
×
1807
      else
1808
        update_item_to_inrange( this );
1✔
1809

1810
      return new Module::EItemRefObjImp( new_stack );
1✔
1811
    };
1✔
1812

1813
    int add_to_existing_stack;
1814
    if ( !ex.hasParams( 3 ) ||
1✔
1815
         ( ex.getParam( 2, add_to_existing_stack ) && add_to_existing_stack != 0 ) )
×
1816
    {
1817
      Item* existing_stack = newcontainer->find_addable_stack( new_stack );
1✔
1818
      if ( existing_stack != nullptr && new_stack->stackable() )
1✔
1819
      {
1820
        if ( !newcontainer->can_insert_increase_stack( nullptr, Core::UContainer::MT_CORE_MOVED,
×
1821
                                                       existing_stack, new_stack->getamount(),
×
1822
                                                       new_stack ) )
1823
        {
1824
          if ( new_stack != this )
×
1825
            this->add_to_self( new_stack );
×
1826
          return new BError( "Could not add to existing stack" );
×
1827
        }
1828
      }
1829
      else
1830
        return create_new_stack();
1✔
1831

1832
      u16 amount = new_stack->getamount();
×
1833
      existing_stack->add_to_self( new_stack );
×
1834
      update_item_to_inrange( existing_stack );
×
1835

1836
      UpdateCharacterWeight( existing_stack );
×
1837

1838
      newcontainer->on_insert_increase_stack( nullptr, Core::UContainer::MT_CORE_MOVED,
×
1839
                                              existing_stack, amount );
1840

1841
      if ( amt == item_amount )
×
1842
        destroy_item( this );
×
1843
      else
1844
        update_item_to_inrange( this );
×
1845

1846
      return new Module::EItemRefObjImp( existing_stack );
×
1847
    }
1848
    else
1849
      return create_new_stack();
×
1850

1851
    break;
1852
  }
1853
  case MTH_HAS_EXISTING_STACK:
×
1854
  {
1855
    Item* cont = nullptr;
×
1856

1857
    if ( !ex.hasParams( 1 ) )
×
1858
      return new BError( "Not enough params" );
×
1859
    else if ( !ex.getItemParam( 0, cont ) )
×
1860
      return new BError( "No container specified" );
×
1861
    else if ( this->inuse() )
×
1862
      return new BError( "Item is in use" );
×
1863
    else if ( !cont->isa( Core::UOBJ_CLASS::CLASS_CONTAINER ) )
×
1864
      return new BError( "Non-container selected as target" );
×
1865

1866
    Core::UContainer* stackcontainer = static_cast<Core::UContainer*>( cont );
×
1867

1868
    Item* existing_stack = stackcontainer->find_addable_stack( this );
×
1869

1870
    if ( existing_stack != nullptr )
×
1871
      return new Module::EItemRefObjImp( existing_stack );
×
1872
    return nullptr;
×
1873

1874
    break;
1875
  }
1876
  default:
32✔
1877
    return nullptr;
32✔
1878
  }
1879
}
1880

1881
BObjectImp* Item::script_method( const char* methodname, Core::UOExecutor& ex )
×
1882
{
1883
  ObjMethod* objmethod = getKnownObjMethod( methodname );
×
1884
  if ( objmethod != nullptr )
×
1885
    return this->script_method_id( objmethod->id, ex );
×
1886
  return nullptr;
×
1887
}
1888

1889
BObjectImp* Item::custom_script_method( const char* methodname, Core::UOExecutor& ex )
7✔
1890
{
1891
  const ItemDesc& id = itemdesc();
7✔
1892
  if ( id.method_script != nullptr )
7✔
1893
  {
1894
    unsigned PC;
1895
    if ( id.method_script->FindExportedFunction(
6✔
1896
             methodname, static_cast<unsigned int>( ex.numParams() + 1 ), PC ) )
6✔
1897
      return id.method_script->call( PC, make_ref(), ex.fparams );
6✔
1898
  }
1899
  return Core::gamestate.system_hooks.call_script_method( methodname, &ex, this );
1✔
1900
}
1901

1902
BObject Item::call_custom_method( const char* methodname )
×
1903
{
1904
  // no systemhook needed used for openbook uo module function
1905
  BObjectImpRefVec noparams;
×
1906
  return call_custom_method( methodname, noparams );
×
1907
}
×
1908

1909
BObject Item::call_custom_method( const char* methodname, BObjectImpRefVec& pmore )
×
1910
{
1911
  // no systemhook needed used for openbook uo module function
1912
  const ItemDesc& id = itemdesc();
×
1913
  if ( id.method_script != nullptr )
×
1914
  {
1915
    unsigned PC;
1916
    if ( id.method_script->FindExportedFunction(
×
1917
             methodname, static_cast<unsigned int>( pmore.size() + 1 ), PC ) )
×
1918
      return id.method_script->call( PC, new Module::EItemRefObjImp( this ), pmore );
×
1919
    else
1920
    {
1921
      std::string message;
×
1922
      message = "Method script for objtype " + id.objtype_description() +
×
1923
                " does not export function " + std::string( methodname ) + " taking " +
×
1924
                Clib::tostring( pmore.size() + 1 ) + " parameters";
×
1925
      BError* err = new BError( message );
×
1926
      return BObject( err );
×
1927
    }
×
1928
  }
1929
  return BObject( new BError( "No method script defined for " + id.objtype_description() ) );
×
1930
}
1931

1932
BObjectImp* Item::make_ref()
131✔
1933
{
1934
  return new Module::EItemRefObjImp( this );
131✔
1935
}
1936
}  // namespace Items
1937
namespace Mobile
1938
{
1939
using namespace Bscript;
1940

1941
class ARUpdater
1942
{
1943
public:
1944
  static void on_change( Character* chr )
×
1945
  {
1946
    chr->refresh_ar();  // FIXME inefficient
×
1947
    // if (chr->client != nullptr) // already send in refresh_ar()
1948
    //{
1949
    //  send_full_statmsg( chr->client, chr );
1950
    //}
1951
  }
×
1952
};
1953

1954
BObjectImp* Character::make_ref()
11✔
1955
{
1956
  return new Module::ECharacterRefObjImp( this );
11✔
1957
}
1958
BObjectImp* Character::make_offline_ref()
×
1959
{
1960
  return new Module::EOfflineCharacterRefObjImp( this );
×
1961
}
1962

1963
BObjectImp* Character::get_script_member_id( const int id ) const
542✔
1964
{
1965
  BObjectImp* imp = base::get_script_member_id( id );
542✔
1966
  if ( imp != nullptr )
542✔
1967
    return imp;
299✔
1968

1969

1970
  auto EnforceCaps = []( s16 baseValue, const s16 capValue ) -> s16
30✔
1971
  {
1972
    const bool ignore_caps = Core::settingsManager.ssopt.core_ignores_defence_caps;
30✔
1973

1974

1975
    if ( !ignore_caps )
30✔
1976
      baseValue = std::min( baseValue, capValue );
30✔
1977

1978
    return baseValue;
30✔
1979
  };
1980

1981
  switch ( id )
243✔
1982
  {
1983
  case MBR_WARMODE:
×
1984
    return new BLong( warmode() );
×
1985
    break;
1986
  case MBR_GENDER:
1✔
1987
    return new BLong( gender );
1✔
1988
    break;
1989
  case MBR_RACE:
1✔
1990
    return new BLong( race );
1✔
1991
    break;
1992
  case MBR_TRUEOBJTYPE:
1✔
1993
    return new BLong( trueobjtype );
1✔
1994
    break;
1995
  case MBR_TRUECOLOR:
1✔
1996
    return new BLong( truecolor );
1✔
1997
    break;
1998
  case MBR_POSITION_CHANGED_AT:
2✔
1999
    return new Double( static_cast<double>( Core::polclock_t_to_ms( position_changed_at_ ) ) );
2✔
2000
    break;
2001
  case MBR_MOVED_AT:
2✔
2002
    return new Double( static_cast<double>( Core::polclock_t_to_ms( moved_at_ ) ) );
2✔
2003
    break;
2004
  case MBR_AR_MOD:
×
2005
    return new BLong( ar_mod() );
×
2006
    break;
2007
  case MBR_DELAY_MOD:
×
2008
    return new BLong( delay_mod() );
×
2009
    break;
2010
  case MBR_HIDDEN:
1✔
2011
    return new BLong( hidden() ? 1 : 0 );
1✔
2012
    break;
2013
  case MBR_CONCEALED:
1✔
2014
    return new BLong( concealed() );
1✔
2015
    break;
2016
  case MBR_FROZEN:
1✔
2017
    return new BLong( frozen() ? 1 : 0 );
1✔
2018
    break;
2019
  case MBR_PARALYZED:
×
2020
    return new BLong( paralyzed() ? 1 : 0 );
×
2021
    break;
2022
  case MBR_POISONED:
×
2023
    return new BLong( poisoned() ? 1 : 0 );
×
2024
    break;
2025
  case MBR_STEALTHSTEPS:
×
2026
    return new BLong( stealthsteps_ );
×
2027
    break;
2028
  case MBR_MOUNTEDSTEPS:
1✔
2029
    return new BLong( mountedsteps_ );
1✔
2030
    break;
2031
  case MBR_SQUELCHED:
1✔
2032
    return new BLong( squelched() ? 1 : 0 );
1✔
2033
    break;
2034
  case MBR_DEAD:
1✔
2035
    return new BLong( dead() );
1✔
2036
    break;
2037
  case MBR_AR:
1✔
2038
    return new BLong( ar() );
1✔
2039
    break;
2040
  case MBR_BACKPACK:
26✔
2041
  {
2042
    Items::Item* bp = backpack();
26✔
2043
    if ( bp != nullptr )
26✔
2044
      return bp->make_ref();
23✔
2045
    return new BError( "That has no backpack" );
3✔
2046
    break;
2047
  }
2048
  case MBR_TRADEWINDOW:
×
2049
  {
2050
    Core::UContainer* tw = trading_cont.get();
×
2051
    if ( trading_with != nullptr )
×
2052
      return tw->make_ref();
×
2053
    return new BError( "That has no active tradewindow" );
×
2054
    break;
2055
  }
2056
  case MBR_WEAPON:
1✔
2057
    if ( weapon != nullptr )
1✔
2058
      return weapon->make_ref();
1✔
2059
    return new BLong( 0 );
×
2060
    break;
2061
  case MBR_SHIELD:
1✔
2062
    if ( shield != nullptr )
1✔
2063
      return shield->make_ref();
1✔
2064
    return new BLong( 0 );
×
2065
    break;
2066
  case MBR_ACCTNAME:
×
2067
    if ( acct != nullptr )
×
2068
      return new String( acct->name() );
×
2069
    return new BError( "Not attached to an account" );
×
2070
    break;
2071

2072
  case MBR_ACCT:
×
2073
    if ( acct != nullptr )
×
2074
      return new Accounts::AccountObjImp( Accounts::AccountPtrHolder( acct ) );
×
2075
    return new BError( "Not attached to an account" );
×
2076
    break;
2077
  case MBR_CMDLEVEL:
1✔
2078
    return new BLong( cmdlevel() );
1✔
2079
    break;
2080
  case MBR_CMDLEVELSTR:
×
2081
    return new String( Core::gamestate.cmdlevels[cmdlevel()].name );
×
2082
    break;
2083
  case MBR_CRIMINAL:
×
2084
    return new BLong( is_criminal() ? 1 : 0 );
×
2085
    break;
2086
  case MBR_TEMPORALLY_CRIMINAL:
×
2087
    return new BLong( is_temporally_criminal() ? 1 : 0 );
×
2088
    break;
2089
  case MBR_IP:
×
2090
    if ( client != nullptr )
×
2091
      return new String( client->ipaddrAsString() );
×
2092
    return new String( "" );
×
2093
    break;
2094
  case MBR_GOLD:
×
2095
    return new BLong( gold_carried() );
×
2096
    break;
2097

2098
  case MBR_TITLE_PREFIX:
1✔
2099
    return new String( title_prefix() );
1✔
2100
    break;
2101
  case MBR_TITLE_SUFFIX:
1✔
2102
    return new String( title_suffix() );
1✔
2103
    break;
2104
  case MBR_TITLE_GUILD:
1✔
2105
    return new String( title_guild() );
1✔
2106
    break;
2107
  case MBR_TITLE_RACE:
1✔
2108
    return new String( title_race() );
1✔
2109
    break;
2110
  case MBR_UCLANG:
×
2111
    return new String( uclang );
×
2112
    break;
2113
  case MBR_GUILDID:
×
2114
    return new BLong( guildid() );
×
2115
    break;
2116
  case MBR_GUILD:
×
2117
    if ( has_guild() )
×
2118
      return Module::GuildExecutorModule::CreateGuildRefObjImp( guild() );
×
2119
    return new BError( "Not a member of a guild" );
×
2120
    break;
2121

2122
  case MBR_MURDERER:
1✔
2123
    return new BLong( is_murderer() ? 1 : 0 );
1✔
2124
    break;
2125
  case MBR_ATTACHED:
×
2126
    if ( script_ex == nullptr )
×
2127
      return new BError( "No script attached." );
×
2128
    return new Core::ScriptExObjImp( script_ex );
×
2129
    break;
2130
  case MBR_CLIENTVERSION:
×
2131
    if ( client != nullptr )
×
2132
      return new String( client->getversion() );
×
2133
    return new String( "" );
×
2134
    break;
2135
  case MBR_CLIENTVERSIONDETAIL:
×
2136
    if ( client != nullptr )
×
2137
    {
2138
      std::unique_ptr<BStruct> info( new BStruct );
×
2139
      Network::VersionDetailStruct version = client->getversiondetail();
×
2140
      info->addMember( "major", new BLong( version.major ) );
×
2141
      info->addMember( "minor", new BLong( version.minor ) );
×
2142
      info->addMember( "rev", new BLong( version.rev ) );
×
2143
      info->addMember( "patch", new BLong( version.patch ) );
×
2144
      return info.release();
×
2145
    }
×
2146
    else
2147
    {
2148
      std::unique_ptr<BStruct> info( new BStruct );
×
2149
      info->addMember( "major", new BLong( 0 ) );
×
2150
      info->addMember( "minor", new BLong( 0 ) );
×
2151
      info->addMember( "rev", new BLong( 0 ) );
×
2152
      info->addMember( "patch", new BLong( 0 ) );
×
2153
      return info.release();
×
2154
    }
×
2155
    break;
2156

2157
  case MBR_CLIENTINFO:
×
2158
    if ( client != nullptr )
×
2159
      return client->getclientinfo();
×
2160
    return new BLong( 0 );
×
2161
    break;
2162

2163
  case MBR_CREATEDAT:
×
2164
    return new BLong( created_at );
×
2165
    break;
2166

2167
  case MBR_REPORTABLES:
2✔
2168
    return GetReportables();
2✔
2169
    break;
2170

2171
  case MBR_OPPONENT:
×
2172
    if ( opponent_ != nullptr )
×
2173
      return opponent_->make_ref();
×
2174
    return new BError( "Mobile does not have any opponent selected." );
×
2175
    break;
2176
  case MBR_CONNECTED:
×
2177
    return new BLong( connected() ? 1 : 0 );
×
2178
    break;
2179
  case MBR_TRADING_WITH:
×
2180
    if ( trading_with != nullptr )
×
2181
      return trading_with->make_ref();
×
2182
    return new BError( "Mobile is not currently trading with anyone." );
×
2183
    break;
2184
  case MBR_CLIENTTYPE:
×
2185
    return new BLong( client != nullptr ? client->ClientType : 0 );
×
2186
    break;
2187
  case MBR_CURSOR:
×
2188
    if ( client != nullptr )
×
2189
      return new BLong( target_cursor_busy() ? 1 : 0 );
×
2190
    return new BLong( 0 );
×
2191
    break;
2192
  case MBR_GUMP:
×
2193
    if ( client != nullptr )
×
2194
      return new BLong( has_active_gump() ? 1 : 0 );
×
2195
    return new BLong( 0 );
×
2196
    break;
2197
  case MBR_PROMPT:
×
2198
    if ( client != nullptr )
×
2199
      return new BLong( has_active_prompt() ? 1 : 0 );
×
2200
    return new BLong( 0 );
×
2201
    break;
2202
  case MBR_MOVEMODE:
×
2203
  {
2204
    std::string mode = "";
×
2205
    if ( movemode & Plib::MOVEMODE_LAND )
×
2206
      mode = "L";
×
2207
    if ( movemode & Plib::MOVEMODE_SEA )
×
2208
      mode += "S";
×
2209
    if ( movemode & Plib::MOVEMODE_AIR )
×
2210
      mode += "A";
×
2211
    if ( movemode & Plib::MOVEMODE_FLY )
×
2212
      mode += "F";
×
2213
    return new String( mode );
×
2214
    break;
2215
  }
×
2216
  case MBR_HITCHANCE_MOD:
×
2217
    return new BLong( hitchance_mod() );
×
2218
    break;
2219
  case MBR_EVASIONCHANCE_MOD:
×
2220
    return new BLong( evasionchance_mod() );
×
2221
    break;
2222
  case MBR_PARRYCHANCE_MOD:
×
2223
    return new BLong( parrychance_mod() );
×
2224
    break;
2225
  case MBR_CARRYINGCAPACITY_MOD:
1✔
2226
    return new BLong( carrying_capacity_mod() );
1✔
2227
    break;
2228
  case MBR_CARRYINGCAPACITY:
×
2229
    return new BLong( carrying_capacity() );
×
2230
    break;
2231
  case MBR_FIRE_RESIST:
5✔
2232
    return new BLong( EnforceCaps( fire_resist().sum(), fire_resist_cap().sum() ) );
5✔
2233
  case MBR_COLD_RESIST:
5✔
2234
    return new BLong( EnforceCaps( cold_resist().sum(), cold_resist_cap().sum() ) );
5✔
2235
  case MBR_ENERGY_RESIST:
5✔
2236
    return new BLong( EnforceCaps( energy_resist().sum(), energy_resist_cap().sum() ) );
5✔
2237
  case MBR_POISON_RESIST:
5✔
2238
    return new BLong( EnforceCaps( poison_resist().sum(), poison_resist_cap().sum() ) );
5✔
2239
  case MBR_PHYSICAL_RESIST:
5✔
2240
    return new BLong( EnforceCaps( physical_resist().sum(), physical_resist_cap().sum() ) );
5✔
2241
  case MBR_FIRE_RESIST_MOD:
×
2242
    return new BLong( fire_resist().mod );
×
2243
    break;
2244
  case MBR_COLD_RESIST_MOD:
×
2245
    return new BLong( cold_resist().mod );
×
2246
    break;
2247
  case MBR_ENERGY_RESIST_MOD:
×
2248
    return new BLong( energy_resist().mod );
×
2249
    break;
2250
  case MBR_POISON_RESIST_MOD:
×
2251
    return new BLong( poison_resist().mod );
×
2252
    break;
2253
  case MBR_PHYSICAL_RESIST_MOD:
×
2254
    return new BLong( physical_resist().mod );
×
2255
    break;
2256
  case MBR_FIRE_RESIST_CAP:
1✔
2257
    return new BLong( fire_resist_cap().sum() );
1✔
2258
    break;
2259
  case MBR_COLD_RESIST_CAP:
1✔
2260
    return new BLong( cold_resist_cap().sum() );
1✔
2261
    break;
2262
  case MBR_ENERGY_RESIST_CAP:
1✔
2263
    return new BLong( energy_resist_cap().sum() );
1✔
2264
    break;
2265
  case MBR_POISON_RESIST_CAP:
1✔
2266
    return new BLong( poison_resist_cap().sum() );
1✔
2267
    break;
2268
  case MBR_PHYSICAL_RESIST_CAP:
1✔
2269
    return new BLong( physical_resist_cap().sum() );
1✔
2270
    break;
2271
  case MBR_FIRE_RESIST_CAP_MOD:
×
2272
    return new BLong( fire_resist_cap().mod );
×
2273
    break;
2274
  case MBR_COLD_RESIST_CAP_MOD:
×
2275
    return new BLong( cold_resist_cap().mod );
×
2276
    break;
2277
  case MBR_ENERGY_RESIST_CAP_MOD:
×
2278
    return new BLong( energy_resist_cap().mod );
×
2279
    break;
2280
  case MBR_POISON_RESIST_CAP_MOD:
×
2281
    return new BLong( poison_resist_cap().mod );
×
2282
    break;
2283
  case MBR_PHYSICAL_RESIST_CAP_MOD:
×
2284
    return new BLong( physical_resist_cap().mod );
×
2285
    break;
2286
  case MBR_LOWER_REAG_COST:
5✔
2287
    return new BLong( lower_reagent_cost().sum() );
5✔
2288
    break;
2289
  case MBR_SPELL_DAMAGE_INCREASE:
5✔
2290
    return new BLong( spell_damage_increase().sum() );
5✔
2291
    break;
2292
  case MBR_FASTER_CASTING:
5✔
2293
    return new BLong( faster_casting().sum() );
5✔
2294
    break;
2295
  case MBR_FASTER_CAST_RECOVERY:
5✔
2296
    return new BLong( faster_cast_recovery().sum() );
5✔
2297
    break;
2298
  case MBR_LOWER_REAG_COST_MOD:
×
2299
    return new BLong( lower_reagent_cost().mod );
×
2300
    break;
2301
  case MBR_SPELL_DAMAGE_INCREASE_MOD:
×
2302
    return new BLong( spell_damage_increase().mod );
×
2303
    break;
2304
  case MBR_FASTER_CASTING_MOD:
×
2305
    return new BLong( faster_casting().mod );
×
2306
    break;
2307
  case MBR_FASTER_CAST_RECOVERY_MOD:
×
2308
    return new BLong( faster_cast_recovery().mod );
×
2309
    break;
2310
  case MBR_DEFENCE_CHANCE_INCREASE_MOD:
×
2311
    return new BLong( defence_increase().mod );
×
2312
    break;
2313
  case MBR_DEFENCE_CHANCE_INCREASE_CAP_MOD:
×
2314
    return new BLong( defence_increase_cap().mod );
×
2315
    break;
2316
  case MBR_LOWER_MANA_COST_MOD:
×
2317
    return new BLong( lower_mana_cost().mod );
×
2318
    break;
2319
  case MBR_HIT_CHANCE_MOD:
×
2320
    return new BLong( hit_chance().mod );
×
2321
    break;
2322
  case MBR_DEFENCE_CHANCE_INCREASE:
5✔
2323
    return new BLong( EnforceCaps( defence_increase().sum(), defence_increase_cap().sum() ) );
5✔
2324
    break;
2325
  case MBR_DEFENCE_CHANCE_INCREASE_CAP:
1✔
2326
    return new BLong( defence_increase_cap().sum() );
1✔
2327
    break;
2328
  case MBR_LOWER_MANA_COST:
5✔
2329
    return new BLong( lower_mana_cost().sum() );
5✔
2330
    break;
2331
  case MBR_HIT_CHANCE:
4✔
2332
    return new BLong( hit_chance().sum() );
4✔
2333
    break;
2334
  case MBR_STATCAP:
1✔
2335
    return new BLong( skillstatcap().statcap );
1✔
2336
    break;
2337
  case MBR_SKILLCAP:
1✔
2338
    return new BLong( skillstatcap().skillcap );
1✔
2339
    break;
2340
  case MBR_LUCK:
5✔
2341
    return new BLong( luck().sum() );
5✔
2342
    break;
2343
  case MBR_LUCK_MOD:
×
2344
    return new BLong( luck().mod );
×
2345
    break;
2346
  case MBR_SWING_SPEED_INCREASE:
5✔
2347
    return new BLong( swing_speed_increase().sum() );
5✔
2348
    break;
2349
  case MBR_SWING_SPEED_INCREASE_MOD:
×
2350
    return new BLong( swing_speed_increase().mod );
×
2351
    break;
2352
  case MBR_MIN_ATTACK_RANGE_INCREASE:
×
2353
    return new BLong( min_attack_range_increase().sum() );
×
2354
    break;
2355
  case MBR_MIN_ATTACK_RANGE_INCREASE_MOD:
×
2356
    return new BLong( min_attack_range_increase().mod );
×
2357
    break;
2358
  case MBR_MAX_ATTACK_RANGE_INCREASE:
×
2359
    return new BLong( max_attack_range_increase().sum() );
×
2360
    break;
2361
  case MBR_MAX_ATTACK_RANGE_INCREASE_MOD:
×
2362
    return new BLong( max_attack_range_increase().mod );
×
2363
    break;
2364
  case MBR_FOLLOWERSMAX:
1✔
2365
    return new BLong( followers().followers_max );
1✔
2366
    break;
2367
  case MBR_TITHING:
1✔
2368
    return new BLong( tithing() );
1✔
2369
    break;
2370
  case MBR_FOLLOWERS:
1✔
2371
    return new BLong( followers().followers );
1✔
2372
    break;
2373
  case MBR_FIRE_DAMAGE:
5✔
2374
    return new BLong( fire_damage().sum() );
5✔
2375
    break;
2376
  case MBR_COLD_DAMAGE:
5✔
2377
    return new BLong( cold_damage().sum() );
5✔
2378
    break;
2379
  case MBR_ENERGY_DAMAGE:
5✔
2380
    return new BLong( energy_damage().sum() );
5✔
2381
    break;
2382
  case MBR_POISON_DAMAGE:
5✔
2383
    return new BLong( poison_damage().sum() );
5✔
2384
    break;
2385
  case MBR_PHYSICAL_DAMAGE:
5✔
2386
    return new BLong( physical_damage().sum() );
5✔
2387
    break;
2388
  case MBR_FIRE_DAMAGE_MOD:
×
2389
    return new BLong( fire_damage().mod );
×
2390
    break;
2391
  case MBR_COLD_DAMAGE_MOD:
×
2392
    return new BLong( cold_damage().mod );
×
2393
    break;
2394
  case MBR_ENERGY_DAMAGE_MOD:
×
2395
    return new BLong( energy_damage().mod );
×
2396
    break;
2397
  case MBR_POISON_DAMAGE_MOD:
×
2398
    return new BLong( poison_damage().mod );
×
2399
    break;
2400
  case MBR_PHYSICAL_DAMAGE_MOD:
×
2401
    return new BLong( physical_damage().mod );
×
2402
    break;
2403
  case MBR_PARTY:
6✔
2404
    if ( has_party() )
6✔
2405
      return Module::CreatePartyRefObjImp( party() );
6✔
2406
    return new BError( "Not a member of a party" );
×
2407
    break;
2408
  case MBR_PARTYLOOT:
×
2409
    return new BLong( party_can_loot() );
×
2410
  case MBR_CANDIDATE_OF_PARTY:
×
2411
    if ( has_candidate_of() )
×
2412
      return Module::CreatePartyRefObjImp( candidate_of() );
×
2413
    return new BError( "Not a candidate of a party" );
×
2414
    break;
2415
  case MBR_MOVECOST_WALK:
1✔
2416
    return new Double( movement_cost().walk );
1✔
2417
    break;
2418
  case MBR_MOVECOST_RUN:
1✔
2419
    return new Double( movement_cost().run );
1✔
2420
    break;
2421
  case MBR_MOVECOST_WALK_MOUNTED:
1✔
2422
    return new Double( movement_cost().walk_mounted );
1✔
2423
    break;
2424
  case MBR_MOVECOST_RUN_MOUNTED:
1✔
2425
    return new Double( movement_cost().run_mounted );
1✔
2426
    break;
2427

2428
  case MBR_AGGRESSORTO:
×
2429
    return GetAggressorTo();
×
2430
    break;
2431
  case MBR_LAWFULLYDAMAGED:
×
2432
    return GetLawFullyDamaged();
×
2433
    break;
2434

2435
  case MBR_UO_EXPANSION_CLIENT:
×
2436
    return new BLong( client != nullptr ? client->UOExpansionFlagClient : 0 );
×
2437
    break;
2438

2439
  case MBR_DEAFENED:
1✔
2440
    return new BLong( deafened() ? 1 : 0 );
1✔
2441
    break;
2442

2443
  case MBR_CLIENT:
12✔
2444
    if ( ( client != nullptr ) && ( client->isConnected() ) )
12✔
2445
      return client->make_ref();
12✔
UNCOV
2446
    return new BError( "No client attached." );
×
2447
    break;
2448
  case MBR_EDITING:
×
2449
    return new BLong( is_house_editing() ? 1 : 0 );
×
2450
    break;
2451
  case MBR_LASTCOORD:
×
2452
    if ( client != nullptr )
×
2453
    {
2454
      std::unique_ptr<BStruct> lastcoord( new BStruct );
×
2455
      lastcoord->addMember( "lastx", new BLong( lastpos.x() ) );
×
2456
      lastcoord->addMember( "lasty", new BLong( lastpos.y() ) );
×
2457
      lastcoord->addMember( "lastz", new BLong( lastpos.z() ) );
×
2458
      return lastcoord.release();
×
2459
    }
×
2460
    return new BError( "No client attached." );
×
2461
  case MBR_ACTIVE_SKILL:
×
2462
    return new BLong( skill_ex_active() );
×
2463
  case MBR_CASTING_SPELL:
×
2464
    return new BLong( casting_spell() );
×
2465
  case MBR_LAST_TEXTCOLOR:
×
2466
    return new BLong( last_textcolor() );
×
2467
  case MBR_BUFFS:
3✔
2468
  {
2469
    auto buffs = std::make_unique<BDictionary>();
3✔
2470
    for ( const auto& [icon, buf] : buffs_ )
5✔
2471
    {
2472
      auto info = std::make_unique<BStruct>();
2✔
2473
      info->addMember( "name_cliloc", new BLong( buf.cl_name ) );
2✔
2474
      info->addMember( "desc_cliloc", new BLong( buf.cl_descr ) );
2✔
2475
      info->addMember( "end_time", new BLong( buf.end ) );
2✔
2476
      info->addMember( "name_args", new String( buf.name_arguments ) );
2✔
2477
      info->addMember( "desc_args", new String( buf.desc_arguments ) );
2✔
2478
      buffs->addMember( new BLong( icon ), info.release() );
2✔
2479
    }
2✔
2480
    return buffs.release();
3✔
2481
  }
3✔
2482
  }
2483
  // if all else fails, returns nullptr
2484
  return nullptr;
60✔
2485
}
2486

2487
BObjectImp* Character::get_script_member( const char* membername ) const
100✔
2488
{
2489
  ObjMember* objmember = getKnownObjMember( membername );
100✔
2490
  if ( objmember != nullptr )
100✔
2491
    return this->get_script_member_id( objmember->id );
100✔
2492
  return nullptr;
×
2493
}
2494

2495
BObjectImp* Character::set_script_member_id( const int id, const std::string& value )
4✔
2496
{
2497
  BObjectImp* imp = base::set_script_member_id( id, value );
4✔
2498
  if ( imp != nullptr )
4✔
2499
    return imp;
×
2500

2501
  String* ret;
2502
  switch ( id )
4✔
2503
  {
2504
  case MBR_TITLE_PREFIX:
1✔
2505
    title_prefix( value );
1✔
2506
    ret = new String( value );
1✔
2507
    break;
1✔
2508
  case MBR_TITLE_SUFFIX:
1✔
2509
    title_suffix( value );
1✔
2510
    ret = new String( value );
1✔
2511
    break;
1✔
2512
  case MBR_TITLE_GUILD:
1✔
2513
    title_guild( value );
1✔
2514
    ret = new String( value );
1✔
2515
    break;
1✔
2516
  case MBR_TITLE_RACE:
1✔
2517
    title_race( value );
1✔
2518
    ret = new String( value );
1✔
2519
    break;
1✔
2520
  default:
×
2521
    return nullptr;
×
2522
  }
2523
  set_dirty();
4✔
2524
  increv();
4✔
2525
  if ( this->has_active_client() )
4✔
2526
    send_object_cache_to_inrange( this );
×
2527
  return ret;
4✔
2528
}
2529

2530
BObjectImp* Character::set_script_member( const char* membername, const std::string& value )
4✔
2531
{
2532
  ObjMember* objmember = getKnownObjMember( membername );
4✔
2533
  if ( objmember != nullptr )
4✔
2534
    return this->set_script_member_id( objmember->id, value );
4✔
2535
  return nullptr;
×
2536
}
2537

2538
BObjectImp* Character::set_script_member_id( const int id, int value )
94✔
2539
{
2540
  BObjectImp* imp = base::set_script_member_id( id, value );
94✔
2541
  if ( imp != nullptr )
94✔
2542
    return imp;
×
2543

2544
  switch ( id )
94✔
2545
  {
2546
  case MBR_GENDER:
1✔
2547
    if ( value )
1✔
2548
      gender = Plib::GENDER_FEMALE;
1✔
2549
    else
2550
      gender = Plib::GENDER_MALE;
×
2551
    return new BLong( gender );
1✔
2552
  case MBR_RACE:
1✔
2553
    if ( value == Plib::RACE_HUMAN )
1✔
2554
      race = Plib::RACE_HUMAN;
×
2555
    else if ( value == Plib::RACE_ELF )
1✔
2556
      race = Plib::RACE_ELF;
×
2557
    else if ( value == Plib::RACE_GARGOYLE )
1✔
2558
      race = Plib::RACE_GARGOYLE;
1✔
2559
    if ( ( race != Plib::RACE_GARGOYLE ) &&
1✔
2560
         ( movemode & Plib::MOVEMODE_FLY ) )                           // FIXME graphic based maybe?
×
2561
      movemode = ( Plib::MOVEMODE )( movemode ^ Plib::MOVEMODE_FLY );  // remove flying
×
2562
    return new BLong( race );
1✔
2563
  case MBR_TRUEOBJTYPE:
1✔
2564
    return new BLong( trueobjtype = Clib::clamp_convert<u32>( value ) );
1✔
2565
  case MBR_TRUECOLOR:
1✔
2566
    return new BLong( truecolor = Clib::clamp_convert<u16>( value ) );
1✔
2567
  case MBR_AR_MOD:
×
2568
    ar_mod( Clib::clamp_convert<s16>( value ) );
×
2569
    refresh_ar();
×
2570
    return new BLong( ar_mod() );
×
2571
  case MBR_DELAY_MOD:
×
2572
    delay_mod( Clib::clamp_convert<s16>( value ) );
×
2573
    return new BLong( delay_mod() );
×
2574
  case MBR_HIDDEN:
12✔
2575
  {
2576
    // FIXME: don't call on_change unless the value actually changed?
2577
    hidden( value ? true : false );
12✔
2578
    return new BLong( hidden() );
12✔
2579
  }
2580
  case MBR_CONCEALED:
1✔
2581
    concealed( Clib::clamp_convert<u8>( value ) );
1✔
2582
    return new BLong( concealed() );
1✔
2583
  case MBR_FROZEN:
1✔
2584
    mob_flags_.change( MOB_FLAGS::FROZEN, value ? true : false );
1✔
2585
    return new BLong( frozen() );
1✔
2586
  case MBR_PARALYZED:
×
2587
    mob_flags_.change( MOB_FLAGS::PARALYZED, value ? true : false );
×
2588
    return new BLong( paralyzed() );
×
2589
  case MBR_POISONED:
×
2590
    poisoned( value ? true : false );
×
2591
    return new BLong( poisoned() );
×
2592
  case MBR_STEALTHSTEPS:
×
2593
    return new BLong( stealthsteps_ = Clib::clamp_convert<u16>( value ) );
×
2594
  case MBR_MOUNTEDSTEPS:
1✔
2595
    return new BLong( mountedsteps_ = Clib::clamp_convert<u32>( value ) );
1✔
2596
  case MBR_CMDLEVEL:
1✔
2597
    if ( value >= static_cast<int>( Core::gamestate.cmdlevels.size() ) )
1✔
2598
      cmdlevel( static_cast<unsigned char>( Core::gamestate.cmdlevels.size() ) - 1, true );
×
2599
    else
2600
      cmdlevel( static_cast<unsigned char>( value ), true );
1✔
2601
    return new BLong( cmdlevel() );
1✔
2602
  case MBR_MURDERER:
1✔
2603
    // make_murderer handles the updating
2604
    make_murderer( value ? true : false );
1✔
2605
    return new BLong( is_murderer() );
1✔
2606
  case MBR_HITCHANCE_MOD:
2✔
2607
    hitchance_mod( Clib::clamp_convert<s16>( value ) );
2✔
2608
    return new BLong( hitchance_mod() );
2✔
2609
  case MBR_EVASIONCHANCE_MOD:
×
2610
    evasionchance_mod( Clib::clamp_convert<s16>( value ) );
×
2611
    return new BLong( evasionchance_mod() );
×
2612
  case MBR_PARRYCHANCE_MOD:
×
2613
    parrychance_mod( Clib::clamp_convert<s16>( value ) );
×
2614
    return new BLong( parrychance_mod() );
×
2615
  case MBR_CARRYINGCAPACITY_MOD:
1✔
2616
    carrying_capacity_mod( Clib::clamp_convert<s16>( value ) );
1✔
2617
    if ( client != nullptr )
1✔
2618
    {  // CHECKME consider sending less frequently
2619
      send_full_statmsg( client, this );
×
2620
    }
2621
    return new BLong( carrying_capacity_mod() );
1✔
2622
  case MBR_FACING:
5✔
2623
    if ( !face( static_cast<Core::UFACING>( value & PKTIN_02_FACING_MASK ), 0 ) )
5✔
2624
      return new BLong( 0 );
×
2625
    on_facing_changed();
5✔
2626
    return new BLong( 1 );
5✔
2627
  case MBR_FIRE_RESIST_MOD:
2✔
2628
    fire_resist( fire_resist().setAsMod( Clib::clamp_convert<s16>( value ) ) );
2✔
2629
    refresh_ar();
2✔
2630
    return new BLong( fire_resist().mod );
2✔
2631
    break;
2632
  case MBR_COLD_RESIST_MOD:
2✔
2633
    cold_resist( cold_resist().setAsMod( Clib::clamp_convert<s16>( value ) ) );
2✔
2634
    refresh_ar();
2✔
2635
    return new BLong( cold_resist().mod );
2✔
2636
    break;
2637
  case MBR_ENERGY_RESIST_MOD:
2✔
2638
    energy_resist( energy_resist().setAsMod( Clib::clamp_convert<s16>( value ) ) );
2✔
2639
    refresh_ar();
2✔
2640
    return new BLong( energy_resist().mod );
2✔
2641
    break;
2642
  case MBR_POISON_RESIST_MOD:
2✔
2643
    poison_resist( poison_resist().setAsMod( Clib::clamp_convert<s16>( value ) ) );
2✔
2644
    refresh_ar();
2✔
2645
    return new BLong( poison_resist().mod );
2✔
2646
    break;
2647
  case MBR_PHYSICAL_RESIST_MOD:
2✔
2648
    physical_resist( physical_resist().setAsMod( Clib::clamp_convert<s16>( value ) ) );
2✔
2649
    refresh_ar();
2✔
2650
    return new BLong( physical_resist().mod );
2✔
2651
    break;
2652
  case MBR_LOWER_REAG_COST_MOD:
2✔
2653
    lower_reagent_cost( lower_reagent_cost().setAsMod( Clib::clamp_convert<s16>( value ) ) );
2✔
2654
    refresh_ar();
2✔
2655
    return new BLong( lower_reagent_cost().mod );
2✔
2656
    break;
2657
  case MBR_SPELL_DAMAGE_INCREASE_MOD:
2✔
2658
    spell_damage_increase( spell_damage_increase().setAsMod( Clib::clamp_convert<s16>( value ) ) );
2✔
2659
    refresh_ar();
2✔
2660
    return new BLong( spell_damage_increase().mod );
2✔
2661
    break;
2662
  case MBR_FASTER_CASTING_MOD:
2✔
2663
    faster_casting( faster_casting().setAsMod( Clib::clamp_convert<s16>( value ) ) );
2✔
2664
    refresh_ar();
2✔
2665
    return new BLong( faster_casting().mod );
2✔
2666
    break;
2667
  case MBR_FASTER_CAST_RECOVERY_MOD:
2✔
2668
    faster_cast_recovery( faster_cast_recovery().setAsMod( Clib::clamp_convert<s16>( value ) ) );
2✔
2669
    refresh_ar();
2✔
2670
    return new BLong( faster_cast_recovery().mod );
2✔
2671
    break;
2672
  case MBR_DEFENCE_CHANCE_INCREASE_MOD:
2✔
2673
    defence_increase( defence_increase().setAsMod( Clib::clamp_convert<s16>( value ) ) );
2✔
2674
    refresh_ar();
2✔
2675
    return new BLong( defence_increase().mod );
2✔
2676
    break;
2677
  case MBR_DEFENCE_CHANCE_INCREASE_CAP_MOD:
1✔
2678
    defence_increase_cap( defence_increase_cap().setAsMod( Clib::clamp_convert<s16>( value ) ) );
1✔
2679
    refresh_ar();
1✔
2680
    return new BLong( defence_increase_cap().mod );
1✔
2681
    break;
2682
  case MBR_LOWER_MANA_COST_MOD:
2✔
2683
    lower_mana_cost( lower_mana_cost().setAsMod( Clib::clamp_convert<s16>( value ) ) );
2✔
2684
    refresh_ar();
2✔
2685
    return new BLong( lower_mana_cost().mod );
2✔
2686
    break;
2687
  case MBR_HIT_CHANCE_MOD:
2✔
2688
    hit_chance( hit_chance().setAsMod( Clib::clamp_convert<s16>( value ) ) );
2✔
2689
    refresh_ar();
2✔
2690
    return new BLong( hit_chance().mod );
2✔
2691
    break;
2692
  case MBR_FIRE_RESIST_CAP_MOD:
1✔
2693
    fire_resist_cap( fire_resist_cap().setAsMod( Clib::clamp_convert<s16>( value ) ) );
1✔
2694
    refresh_ar();
1✔
2695
    return new BLong( fire_resist_cap().mod );
1✔
2696
    break;
2697
  case MBR_COLD_RESIST_CAP_MOD:
1✔
2698
    cold_resist_cap( cold_resist_cap().setAsMod( Clib::clamp_convert<s16>( value ) ) );
1✔
2699
    refresh_ar();
1✔
2700
    return new BLong( cold_resist_cap().mod );
1✔
2701
    break;
2702
  case MBR_ENERGY_RESIST_CAP_MOD:
1✔
2703
    energy_resist_cap( energy_resist_cap().setAsMod( Clib::clamp_convert<s16>( value ) ) );
1✔
2704
    refresh_ar();
1✔
2705
    return new BLong( energy_resist_cap().mod );
1✔
2706
    break;
2707
  case MBR_PHYSICAL_RESIST_CAP_MOD:
1✔
2708
    physical_resist_cap( physical_resist_cap().setAsMod( Clib::clamp_convert<s16>( value ) ) );
1✔
2709
    refresh_ar();
1✔
2710
    return new BLong( physical_resist_cap().mod );
1✔
2711
    break;
2712
  case MBR_POISON_RESIST_CAP_MOD:
1✔
2713
    poison_resist_cap( poison_resist_cap().setAsMod( Clib::clamp_convert<s16>( value ) ) );
1✔
2714
    refresh_ar();
1✔
2715
    return new BLong( poison_resist_cap().mod );
1✔
2716
    break;
2717
  case MBR_LUCK_MOD:
2✔
2718
    luck( luck().setAsMod( Clib::clamp_convert<s16>( value ) ) );
2✔
2719
    refresh_ar();
2✔
2720
    return new BLong( luck().mod );
2✔
2721
    break;
2722
  case MBR_SWING_SPEED_INCREASE_MOD:
10✔
2723
    swing_speed_increase( swing_speed_increase().setAsMod( Clib::clamp_convert<s16>( value ) ) );
10✔
2724
    refresh_ar();
10✔
2725
    return new BLong( swing_speed_increase().mod );
10✔
2726
    break;
2727
  case MBR_MIN_ATTACK_RANGE_INCREASE_MOD:
×
2728
    min_attack_range_increase(
×
2729
        min_attack_range_increase().setAsMod( Clib::clamp_convert<s16>( value ) ) );
×
2730
    refresh_ar();
×
2731
    return new BLong( min_attack_range_increase().mod );
×
2732
    break;
2733
  case MBR_MAX_ATTACK_RANGE_INCREASE_MOD:
1✔
2734
    max_attack_range_increase(
2✔
2735
        max_attack_range_increase().setAsMod( Clib::clamp_convert<s16>( value ) ) );
1✔
2736
    refresh_ar();
1✔
2737
    return new BLong( max_attack_range_increase().mod );
1✔
2738
    break;
2739
  case MBR_STATCAP:
1✔
2740
  {
2741
    auto val = skillstatcap();
1✔
2742
    val.statcap = Clib::clamp_convert<s16>( value );
1✔
2743
    skillstatcap( val );
1✔
2744
    if ( !this->isa( Core::UOBJ_CLASS::CLASS_NPC ) )
1✔
2745
      on_aos_ext_stat_changed();
1✔
2746
    return new BLong( skillstatcap().statcap );
1✔
2747
  }
2748
  case MBR_SKILLCAP:
1✔
2749
  {
2750
    auto val = skillstatcap();
1✔
2751
    val.skillcap = Clib::clamp_convert<u16>( value );
1✔
2752
    skillstatcap( val );
1✔
2753
    return new BLong( skillstatcap().skillcap );
1✔
2754
  }
2755
  case MBR_FOLLOWERSMAX:
1✔
2756
  {
2757
    auto val = followers();
1✔
2758
    val.followers_max = Clib::clamp_convert<u8>( value );
1✔
2759
    followers( val );
1✔
2760
    if ( !this->isa( Core::UOBJ_CLASS::CLASS_NPC ) )
1✔
2761
      on_aos_ext_stat_changed();
1✔
2762
    return new BLong( followers().followers_max );
1✔
2763
  }
2764
  case MBR_TITHING:
1✔
2765
    tithing( value );
1✔
2766
    if ( !this->isa( Core::UOBJ_CLASS::CLASS_NPC ) )
1✔
2767
      on_aos_ext_stat_changed();
1✔
2768
    return new BLong( tithing() );
1✔
2769
    break;
2770
  case MBR_FOLLOWERS:
1✔
2771
  {
2772
    auto val = followers();
1✔
2773
    val.followers = Clib::clamp_convert<u8>( value );
1✔
2774
    followers( val );
1✔
2775
    if ( !this->isa( Core::UOBJ_CLASS::CLASS_NPC ) )
1✔
2776
      on_aos_ext_stat_changed();
1✔
2777
    return new BLong( followers().followers );
1✔
2778
  }
2779
  case MBR_FIRE_DAMAGE_MOD:
2✔
2780
    fire_damage( fire_damage().setAsMod( Clib::clamp_convert<s16>( value ) ) );
2✔
2781
    refresh_ar();
2✔
2782
    return new BLong( fire_damage().mod );
2✔
2783
    break;
2784
  case MBR_COLD_DAMAGE_MOD:
2✔
2785
    cold_damage( cold_damage().setAsMod( Clib::clamp_convert<s16>( value ) ) );
2✔
2786
    refresh_ar();
2✔
2787
    return new BLong( cold_damage().mod );
2✔
2788
    break;
2789
  case MBR_ENERGY_DAMAGE_MOD:
2✔
2790
    energy_damage( energy_damage().setAsMod( Clib::clamp_convert<s16>( value ) ) );
2✔
2791
    refresh_ar();
2✔
2792
    return new BLong( energy_damage().mod );
2✔
2793
    break;
2794
  case MBR_POISON_DAMAGE_MOD:
2✔
2795
    poison_damage( poison_damage().setAsMod( Clib::clamp_convert<s16>( value ) ) );
2✔
2796
    refresh_ar();
2✔
2797
    return new BLong( poison_damage().mod );
2✔
2798
    break;
2799
  case MBR_PHYSICAL_DAMAGE_MOD:
2✔
2800
    physical_damage( physical_damage().setAsMod( Clib::clamp_convert<s16>( value ) ) );
2✔
2801
    refresh_ar();
2✔
2802
    return new BLong( physical_damage().mod );
2✔
2803
    break;
2804
  case MBR_MOVECOST_WALK:
×
2805
  {
2806
    auto val = movement_cost();
×
2807
    val.walk = static_cast<double>( value );
×
2808
    movement_cost( val );
×
2809
    return new Double( movement_cost().walk );
×
2810
  }
2811
  case MBR_MOVECOST_RUN:
×
2812
  {
2813
    auto val = movement_cost();
×
2814
    val.run = static_cast<double>( value );
×
2815
    movement_cost( val );
×
2816
    return new Double( movement_cost().run );
×
2817
  }
2818
  case MBR_MOVECOST_WALK_MOUNTED:
×
2819
  {
2820
    auto val = movement_cost();
×
2821
    val.walk_mounted = static_cast<double>( value );
×
2822
    movement_cost( val );
×
2823
    return new Double( movement_cost().walk_mounted );
×
2824
  }
2825
  case MBR_MOVECOST_RUN_MOUNTED:
×
2826
  {
2827
    auto val = movement_cost();
×
2828
    val.run_mounted = static_cast<double>( value );
×
2829
    movement_cost( val );
×
2830
    return new Double( movement_cost().run_mounted );
×
2831
  }
2832
  default:
7✔
2833
    return nullptr;
7✔
2834
  }
2835
}
2836

2837
BObjectImp* Character::set_script_member_id_double( const int id, double value )
4✔
2838
{
2839
  switch ( id )
4✔
2840
  {
2841
  case MBR_MOVECOST_WALK:
1✔
2842
  {
2843
    auto val = movement_cost();
1✔
2844
    val.walk = value;
1✔
2845
    movement_cost( val );
1✔
2846
    return new Double( movement_cost().walk );
1✔
2847
  }
2848
  case MBR_MOVECOST_RUN:
1✔
2849
  {
2850
    auto val = movement_cost();
1✔
2851
    val.run = value;
1✔
2852
    movement_cost( val );
1✔
2853
    return new Double( movement_cost().run );
1✔
2854
  }
2855
  case MBR_MOVECOST_WALK_MOUNTED:
1✔
2856
  {
2857
    auto val = movement_cost();
1✔
2858
    val.walk_mounted = value;
1✔
2859
    movement_cost( val );
1✔
2860
    return new Double( movement_cost().walk_mounted );
1✔
2861
  }
2862
  case MBR_MOVECOST_RUN_MOUNTED:
1✔
2863
  {
2864
    auto val = movement_cost();
1✔
2865
    val.run_mounted = value;
1✔
2866
    movement_cost( val );
1✔
2867
    return new Double( movement_cost().run_mounted );
1✔
2868
  }
2869
  default:
×
2870
    return nullptr;
×
2871
  }
2872
}
2873

2874
BObjectImp* Character::set_script_member( const char* membername, int value )
60✔
2875
{
2876
  ObjMember* objmember = getKnownObjMember( membername );
60✔
2877
  if ( objmember != nullptr )
60✔
2878
    return this->set_script_member_id( objmember->id, value );
60✔
2879
  return nullptr;
×
2880
}
2881

2882
BObjectImp* Character::script_method_id( const int id, Core::UOExecutor& ex )
310✔
2883
{
2884
  BObjectImp* imp = base::script_method_id( id, ex );
310✔
2885
  if ( imp != nullptr )
310✔
2886
    return imp;
240✔
2887

2888
  switch ( id )
70✔
2889
  {
2890
  /*
2891
  mobile.SetPoisoned( ispoisoned := 1 )
2892
  If the poisoned flag was changed, and the script has a controller
2893
  If poisoned was SET,
2894
  apply RepSystem rules (Mobile damages Mobile)
2895
  else poisoned was CLEARED, so
2896
  apply RepSystem rules (Mobile helps Mobile)
2897
  */
2898
  case MTH_SETPOISONED:
×
2899
  {
2900
    bool newval = true;
×
2901
    if ( ex.hasParams( 1 ) )
×
2902
    {
2903
      int lval;
2904
      if ( !ex.getParam( 0, lval ) )
×
2905
        return new BError( "Invalid parameter type" );
×
2906
      if ( !lval )
×
2907
        newval = false;
×
2908
    }
2909

2910
    if ( newval != poisoned() )
×
2911
    {
2912
      set_dirty();
×
2913
      poisoned( newval );
×
2914
      check_undamaged();
×
2915
      Module::UOExecutorModule* uoexec =
2916
          static_cast<Module::UOExecutorModule*>( ex.findModule( "UO" ) );
×
2917
      if ( uoexec != nullptr && uoexec->controller_.get() )
×
2918
      {
2919
        Character* attacker = uoexec->controller_.get();
×
2920
        if ( !attacker->orphan() )
×
2921
        {
2922
          if ( poisoned() )
×
2923
            attacker->repsys_on_damage( this );
×
2924
          else
2925
            attacker->repsys_on_help( this );
×
2926
        }
2927
      }
2928
    }
2929
    return new BLong( 1 );
×
2930
  }
2931

2932
  /*
2933
   mobile.SetParalyzed( isparalyzed := 1 )
2934
   If the paralyzed flag was changed, and the script has a controller
2935
   if paralyzed was SET,
2936
   apply RepSystem rules (Mobile damages Mobile)
2937
   else paralyzed was CLEARED, so
2938
   apply RepSystem rules (Mobile heals Mobile)
2939
   */
2940
  case MTH_SETPARALYZED:
×
2941
  {
2942
    bool newval = true;
×
2943
    if ( ex.hasParams( 1 ) )
×
2944
    {
2945
      int lval;
2946
      if ( !ex.getParam( 0, lval ) )
×
2947
        return new BError( "Invalid parameter type" );
×
2948
      if ( !lval )
×
2949
        newval = false;
×
2950
    }
2951

2952
    if ( newval != paralyzed() )
×
2953
    {
2954
      set_dirty();
×
2955
      mob_flags_.change( MOB_FLAGS::PARALYZED, newval );
×
2956
      check_undamaged();
×
2957
      Module::UOExecutorModule* uoexec =
2958
          static_cast<Module::UOExecutorModule*>( ex.findModule( "UO" ) );
×
2959
      if ( uoexec != nullptr && uoexec->controller_.get() )
×
2960
      {
2961
        Character* attacker = uoexec->controller_.get();
×
2962
        if ( !attacker->orphan() )
×
2963
        {
2964
          if ( paralyzed() )
×
2965
            attacker->repsys_on_damage( this );
×
2966
          else
2967
            attacker->repsys_on_help( this );
×
2968
        }
2969
      }
2970
    }
2971
    return new BLong( 1 );
×
2972
  }
2973

2974
  /*
2975
   mobile.SetCriminal( level := 1 )
2976
   if level is 0, clears the CriminalTimer
2977
   */
2978
  case MTH_SETCRIMINAL:
×
2979
  {
2980
    int level = 1;
×
2981
    if ( ex.hasParams( 1 ) )
×
2982
    {
2983
      if ( !ex.getParam( 0, level ) )
×
2984
        return new BError( "Invalid parameter type" );
×
2985
      if ( level < 0 )
×
2986
        return new BError( "Level must be >= 0" );
×
2987
    }
2988
    set_dirty();
×
2989
    // make_criminal handles the updating
2990
    make_criminal( level );
×
2991
    return new BLong( 1 );
×
2992
  }
2993

2994
  case MTH_SETLIGHTLEVEL:
×
2995
  {
2996
    int level, duration;
2997
    if ( !ex.hasParams( 2 ) )
×
2998
      return new BError( "Not enough parameters" );
×
2999
    if ( ex.getParam( 0, level ) && ex.getParam( 1, duration ) )
×
3000
    {
3001
      lightoverride( level );
×
3002

3003
      if ( duration == -1 )
×
3004
        lightoverride_until( ~0u );
×
3005
      else if ( duration == 0 )
×
3006
        lightoverride_until( 0 );
×
3007
      else
3008
        lightoverride_until( Core::read_gameclock() + duration );
×
3009

3010
      check_region_changes();
×
3011
      if ( duration == -1 )
×
3012
        return new BLong( duration );
×
3013
      return new BLong( lightoverride_until() );
×
3014
    }
3015
    break;
×
3016
  }
3017

3018
  case MTH_SETSEASON:
×
3019
  {
3020
    int season_id, playsound;
3021

3022
    if ( !ex.hasParams( 2 ) )
×
3023
      return new BError( "Not enough parameters" );
×
3024
    if ( ex.getParam( 0, season_id ) && ex.getParam( 1, playsound ) )
×
3025
    {
3026
      if ( season_id < 0 || season_id > 4 )
×
3027
        return new BError( "Invalid season id" );
×
3028

3029
      if ( client && client->getversiondetail().major >= 1 )
×
3030
      {
3031
        Network::PktHelper::PacketOut<Network::PktOut_BC> msg;
×
3032
        msg->Write<u8>( Clib::clamp_convert<u8>( season_id ) );
×
3033
        msg->Write<u8>( Clib::clamp_convert<u8>( playsound ) );
×
3034
        msg.Send( client );
×
3035
        return new BLong( 1 );
×
3036
      }
×
3037
    }
3038
    break;
×
3039
  }
3040
  case MTH_SQUELCH:
1✔
3041
  {
3042
    int duration;
3043
    if ( !ex.hasParams( 1 ) )
1✔
3044
      return new BError( "Not enough parameters" );
1✔
3045
    if ( ex.getParam( 0, duration ) )
1✔
3046
    {
3047
      set_dirty();
1✔
3048
      if ( duration == -1 )
1✔
3049
      {
3050
        squelched_until( ~0u );
×
3051
        return new BLong( -1 );
×
3052
      }
3053
      else if ( duration == 0 )
1✔
3054
        squelched_until( 0 );
×
3055
      else
3056
        squelched_until( Core::read_gameclock() + duration );
1✔
3057
      return new BLong( squelched_until() );
1✔
3058
    }
3059
    break;
×
3060
  }
3061
  case MTH_ENABLE:
1✔
3062
  {
3063
    if ( !ex.hasParams( 1 ) )
1✔
3064
      return new BError( "Not enough parameters" );
1✔
3065
    const String* pstr;
3066
    if ( ex.getStringParam( 0, pstr ) )
1✔
3067
    {
3068
      if ( has_privilege( pstr->data() ) )
1✔
3069
      {
3070
        set_dirty();
1✔
3071
        set_setting( pstr->data(), true );
1✔
3072
        return new BLong( 1 );
1✔
3073
      }
3074
      return new BError( "Mobile doesn't have that privilege" );
×
3075
    }
3076
    break;
×
3077
  }
3078

3079
  case MTH_DISABLE:
×
3080
  {
3081
    if ( !ex.hasParams( 1 ) )
×
3082
      return new BError( "Not enough parameters" );
×
3083
    const String* pstr;
3084
    if ( ex.getStringParam( 0, pstr ) )
×
3085
    {
3086
      set_dirty();
×
3087
      set_setting( pstr->data(), false );
×
3088
      return new BLong( 1 );
×
3089
    }
3090
    break;
×
3091
  }
3092

3093
  case MTH_ENABLED:
2✔
3094
  {
3095
    if ( !ex.hasParams( 1 ) )
2✔
3096
      return new BError( "Not enough parameters" );
2✔
3097
    const String* pstr;
3098
    if ( ex.getStringParam( 0, pstr ) )
2✔
3099
      return new BLong( setting_enabled( pstr->data() ) ? 1 : 0 );
2✔
3100
    break;
×
3101
  }
3102

3103
  case MTH_PRIVILEGES:
1✔
3104
  {
3105
    std::unique_ptr<BDictionary> dict( new BDictionary );
1✔
3106
    ISTRINGSTREAM istrm( all_privs() );
1✔
3107
    std::string tmp;
1✔
3108
    while ( istrm >> tmp )
3✔
3109
    {
3110
      dict->addMember( new String( tmp ), new BLong( setting_enabled( tmp.c_str() ) ) );
2✔
3111
    }
3112
    return dict.release();
1✔
3113
    break;
3114
  }
1✔
3115

3116
  case MTH_SETCMDLEVEL:
×
3117
  {
3118
    if ( !ex.hasParams( 1 ) )
×
3119
      return new BError( "Not enough parameters" );
×
3120
    const String* pstr;
3121
    if ( ex.getStringParam( 0, pstr ) )
×
3122
    {
3123
      Core::CmdLevel* pcmdlevel = Core::find_cmdlevel( pstr->data() );
×
3124
      if ( pcmdlevel )
×
3125
      {
3126
        set_dirty();
×
3127
        cmdlevel( pcmdlevel->cmdlevel, true );
×
3128
        return new BLong( 1 );
×
3129
      }
3130
      return new BError( "No such command level" );
×
3131
    }
3132
    break;
×
3133
  }
3134
  case MTH_SPENDGOLD:
×
3135
  {
3136
    u32 amt;
3137
    if ( ex.numParams() != 1 || !ex.getParam( 0, amt ) )
×
3138
      return new BError( "Invalid parameter type" );
×
3139

3140
    if ( gold_carried() < amt )
×
3141
      return new BError( "Insufficient funds" );
×
3142

3143
    spend_gold( amt );
×
3144
    return new BLong( 1 );
×
3145
  }
3146

3147
  case MTH_SETMURDERER:
×
3148
  {
3149
    int lnewval = 1;
×
3150
    if ( ex.hasParams( 1 ) )
×
3151
    {
3152
      if ( !ex.getParam( 0, lnewval ) )
×
3153
        return new BError( "Invalid parameter type" );
×
3154
    }
3155
    set_dirty();
×
3156
    // make_murderer handles the updating
3157
    make_murderer( lnewval ? true : false );
×
3158
    return new BLong( 1 );
×
3159
  }
3160
  case MTH_REMOVEREPORTABLE:
×
3161
  {
3162
    if ( !ex.hasParams( 2 ) )
×
3163
      return new BError( "Not enough parameters" );
×
3164
    int repserial, gameclock;
3165
    if ( ex.getParam( 0, repserial ) && ex.getParam( 1, gameclock ) )
×
3166
    {
3167
      set_dirty();
×
3168
      clear_reportable( repserial, gameclock );
×
3169
      return new BLong( 1 );
×
3170
    }
3171
    break;
×
3172
  }
3173
  case MTH_GETGOTTENITEM:
×
3174
    if ( has_gotten_item() )
×
3175
      return new Module::EItemRefObjImp( gotten_item().item() );
×
3176
    return new BError( "Gotten Item nullptr" );
×
3177
    break;
3178
  case MTH_CLEARGOTTENITEM:
×
3179
    if ( has_gotten_item() )
×
3180
    {
3181
      clear_gotten_item();
×
3182
      return new BLong( 1 );
×
3183
    }
3184
    return new BError( "No Gotten Item" );
×
3185
    break;
3186
  case MTH_SETWARMODE:
3✔
3187
  {
3188
    int newmode;
3189
    if ( !ex.hasParams( 1 ) )
3✔
3190
      return new BError( "Not enough parameters" );
3✔
3191
    if ( ex.getParam( 0, newmode, 0, 1 ) )
3✔
3192
    {
3193
      set_warmode( ( newmode == 0 ) ? false : true );
3✔
3194
      // FIXME: Additional checks needed?
3195
      if ( client )
3✔
3196
        send_warmode();
2✔
3197
      return new BLong( warmode() );
3✔
3198
    }
3199
    break;
×
3200
  }
3201
  case MTH_GETCORPSE:
2✔
3202
  {
3203
    Core::UCorpse* corpse_obj =
3204
        static_cast<Core::UCorpse*>( Core::system_find_item( last_corpse ) );
2✔
3205
    if ( corpse_obj != nullptr && !corpse_obj->orphan() )
2✔
3206
      return new Module::EItemRefObjImp( corpse_obj );
2✔
3207
    return new BError( "No corpse was found." );
×
3208
    break;
3209
  }
3210
  case MTH_SET_SWINGTIMER:
×
3211
  {
3212
    int time;
3213
    if ( !ex.hasParams( 1 ) )
×
3214
      return new BError( "Not enough parameters" );
×
3215
    if ( ex.getParam( 0, time ) )
×
3216
    {
3217
      if ( time < 0 )
×
3218
        return new BError( "Time must be >= 0" );
×
3219
      Core::polclock_t clocks;
3220
      clocks = ( time * Core::POLCLOCKS_PER_SEC ) / 1000;
×
3221
      return new BLong( manual_set_swing_timer( clocks ) ? 1 : 0 );
×
3222
    }
3223
    break;
×
3224
  }
3225
  case MTH_ATTACK_ONCE:
×
3226
  {
3227
    Character* chr;
3228
    if ( ex.hasParams( 1 ) )
×
3229
    {
3230
      if ( ex.getCharacterParam( 0, chr ) )
×
3231
      {
3232
        if ( dead() )
×
3233
          return new BError( "Character is dead" );
×
3234
        if ( is_attackable( chr ) )
×
3235
          attack( chr );
×
3236
        else
3237
          return new BError( "Opponent is not attackable" );
×
3238
      }
3239
      else
3240
        return new BError( "Invalid parameter type" );
×
3241
    }
3242
    else
3243
    {
3244
      chr = get_attackable_opponent();
×
3245
      if ( chr != nullptr )
×
3246
      {
3247
        if ( !dead() )
×
3248
          attack( chr );
×
3249
        else
3250
          return new BError( "Character is dead" );
×
3251
      }
3252
      else
3253
        return new BError( "No opponent" );
×
3254
    }
3255
    return new BLong( 1 );
×
3256
    break;
3257
  }
3258
  case MTH_KILL:
52✔
3259
    if ( ex.hasParams( 1 ) )
52✔
3260
    {
3261
      Character* chr;
3262
      if ( ex.getCharacterParam( 0, chr ) )
1✔
3263
        chr->repsys_on_damage( this );
1✔
3264
    }
3265
    if ( dead() )
52✔
3266
      return new BError( "That is already dead!" );
×
3267

3268
    die();
52✔
3269
    return new BLong( 1 );
52✔
3270
    break;
3271
  case MTH_SETFACING:
×
3272
  {
3273
    int flags = 0;
×
3274
    Core::UFACING i_facing;
3275

3276
    if ( ex.hasParams( 2 ) && !ex.getParam( 1, flags, 0, 1 ) )
×
3277
      return new BError( "Invalid flags for parameter 1" );
×
3278

3279
    BObjectImp* param0 = ex.getParamImp( 0 );
×
3280
    if ( auto* s = impptrIf<String>( param0 ) )
×
3281
    {
3282
      if ( DecodeFacing( s->data(), i_facing ) == false )
×
3283
        return new BError( "Invalid string for parameter 0" );
×
3284
    }
3285
    else if ( auto* l = impptrIf<BLong>( param0 ) )
×
3286
    {
3287
      i_facing = static_cast<Core::UFACING>( l->value() & PKTIN_02_FACING_MASK );
×
3288
    }
3289
    else
3290
      return new BError( "Invalid type for parameter 0" );
×
3291

3292
    if ( !face( i_facing, flags ) )
×
3293
      return new BLong( 0 );
×
3294

3295
    on_facing_changed();
×
3296
    return new BLong( 1 );
×
3297
    break;
3298
  }
3299
  case MTH_COMPAREVERSION:
×
3300
    if ( client != nullptr )
×
3301
    {
3302
      if ( !ex.hasParams( 1 ) )
×
3303
        return new BError( "Not enough parameters" );
×
3304
      const String* pstr;
3305
      if ( ex.getStringParam( 0, pstr ) )
×
3306
        return new BLong( client->compareVersion( pstr->getStringRep() ) ? 1 : 0 );
×
3307
      return new BError( "Invalid parameter type" );
×
3308
    }
3309
    return new BError( "No client attached" );
×
3310
    break;
3311
  case MTH_SETAGGRESSORTO:
×
3312
    if ( ex.hasParams( 1 ) )
×
3313
    {
3314
      Character* chr;
3315
      if ( ex.getCharacterParam( 0, chr ) )
×
3316
      {
3317
        // make_aggressor_to handles the updating
3318
        this->make_aggressor_to( chr );
×
3319
        return new BLong( 1 );
×
3320
      }
3321
      return new BError( "Invalid parameter type" );
×
3322
    }
3323
    return new BError( "Not enough parameters" );
×
3324
    break;
3325
  case MTH_SETLAWFULLYDAMAGEDTO:
×
3326
    if ( ex.hasParams( 1 ) )
×
3327
    {
3328
      Character* chr;
3329
      if ( ex.getCharacterParam( 0, chr ) )
×
3330
      {
3331
        // make_lawfullydamaged_to handled the updating
3332
        this->make_lawfullydamaged_to( chr );
×
3333
        return new BLong( 1 );
×
3334
      }
3335
      return new BError( "Invalid parameter type" );
×
3336
    }
3337
    return new BError( "Not enough parameters" );
×
3338
    break;
3339
  case MTH_CLEARAGGRESSORTO:
×
3340
    if ( ex.hasParams( 1 ) )
×
3341
    {
3342
      Character* chr;
3343
      if ( ex.getCharacterParam( 0, chr ) )
×
3344
      {
3345
        this->remove_as_aggressor_to( chr );
×
3346
        return new BLong( 1 );
×
3347
      }
3348
      return new BError( "Invalid parameter type" );
×
3349
    }
3350
    return new BError( "Not enough parameters" );
×
3351
    break;
3352
  case MTH_CLEARLAWFULLYDAMAGEDTO:
×
3353
    if ( ex.hasParams( 1 ) )
×
3354
    {
3355
      Character* chr;
3356
      if ( ex.getCharacterParam( 0, chr ) )
×
3357
      {
3358
        this->remove_as_lawful_damager( chr );
×
3359
        return new BLong( 1 );
×
3360
      }
3361
      return new BError( "Invalid parameter type" );
×
3362
    }
3363
    return new BError( "Not enough parameters" );
×
3364
    break;
3365
  case MTH_DEAF:
1✔
3366
  {
3367
    int duration;
3368
    if ( !ex.hasParams( 1 ) )
1✔
3369
      return new BError( "Not enough parameters" );
1✔
3370
    if ( ex.getParam( 0, duration ) )
1✔
3371
    {
3372
      set_dirty();
1✔
3373
      if ( duration == -1 )
1✔
3374
      {
3375
        deafened_until( ~0u );
×
3376
        return new BLong( -1 );
×
3377
      }
3378
      else if ( duration == 0 )
1✔
3379
        deafened_until( 0 );
×
3380
      else
3381
        deafened_until( Core::read_gameclock() + duration );
1✔
3382
      return new BLong( deafened_until() );
1✔
3383
    }
3384
    break;
×
3385
  }
3386
  case MTH_DISABLE_SKILLS_FOR:
×
3387
  {
3388
    int duration;
3389
    if ( !ex.hasParams( 1 ) )
×
3390
      return new BError( "Not enough parameters" );
×
3391
    if ( ex.getParam( 0, duration ) )
×
3392
    {
3393
      if ( duration < 0 )
×
3394
        return new BError( "Duration must be >= 0" );
×
3395
      disable_skills_until( Core::poltime() + duration );
×
3396
      return new BLong( static_cast<int>( disable_skills_until() ) );
×
3397
    }
3398
    break;
×
3399
  }
3400
  case MTH_ADD_BUFF:
2✔
3401
  {
3402
    u16 icon;
3403
    u16 duration;
3404
    u32 cl_name;
3405
    u32 cl_descr;
3406
    const String* desc_text;
3407
    std::string name_args;
2✔
3408

3409
    if ( !ex.hasParams( 5 ) )
2✔
3410
      return new BError( "Not enough parameters" );
×
3411
    if ( ex.getParam( 0, icon ) && ex.getParam( 1, duration ) && ex.getParam( 2, cl_name ) &&
4✔
3412
         ex.getParam( 3, cl_descr ) && ex.getUnicodeStringParam( 4, desc_text ) )
4✔
3413
    {
3414
      if ( ex.hasParams( 6 ) )
2✔
3415
      {
3416
        const String* name_text;
3417
        if ( !ex.getUnicodeStringParam( 5, name_text ) )
×
3418
          break;
×
3419
        if ( name_text->length() > SPEECH_MAX_LEN )
×
3420
          return new BError( "Title text exceeds maximum size." );
×
3421
        name_args = name_text->value();
×
3422
      }
3423

3424
      if ( !( icon && cl_name && cl_descr ) )
2✔
3425
        return new BError( "Invalid parameters" );
×
3426

3427
      if ( desc_text->length() > SPEECH_MAX_LEN )
2✔
3428
        return new BError( "Text exceeds maximum size." );
×
3429

3430
      addBuff( icon, duration, cl_name, name_args, cl_descr, desc_text->value() );
2✔
3431
      return new BLong( 1 );
2✔
3432
    }
3433
    break;
×
3434
  }
2✔
3435
  case MTH_CLEAR_BUFFS:
2✔
3436
  {
3437
    clearBuffs();
2✔
3438

3439
    return new BLong( 1 );
2✔
3440
    break;
3441
  }
3442
  case MTH_DEL_BUFF:
2✔
3443
  {
3444
    u16 icon;
3445

3446
    if ( !ex.hasParams( 1 ) )
2✔
3447
      return new BError( "Not enough parameters" );
2✔
3448
    if ( ex.getParam( 0, icon ) )
2✔
3449
    {
3450
      if ( !icon )
2✔
3451
        return new BError( "Invalid parameter" );
×
3452

3453
      if ( !delBuff( icon ) )
2✔
3454
        return new BError( "Buff not found" );
1✔
3455

3456
      return new BLong( 1 );
1✔
3457
    }
3458
    break;
×
3459
  }
3460
  default:
1✔
3461
    return nullptr;
1✔
3462
  }
3463
  return new BError( "Invalid parameter type" );
×
3464
}
3465

3466

3467
BObjectImp* Character::script_method( const char* methodname, Core::UOExecutor& ex )
×
3468
{
3469
  ObjMethod* objmethod = getKnownObjMethod( methodname );
×
3470
  if ( objmethod != nullptr )
×
3471
    return this->script_method_id( objmethod->id, ex );
×
3472
  return nullptr;
×
3473
}
3474

3475
BObjectImp* Character::custom_script_method( const char* methodname, Core::UOExecutor& ex )
×
3476
{
3477
  // TODO uoclient entry deprecated
3478
  if ( Core::networkManager.uoclient_general.method_script != nullptr )
×
3479
  {
3480
    unsigned PC;
3481
    if ( Core::networkManager.uoclient_general.method_script->FindExportedFunction(
×
3482
             methodname, static_cast<unsigned int>( ex.numParams() + 1 ), PC ) )
×
3483
      return Core::networkManager.uoclient_general.method_script->call( PC, make_ref(),
×
3484
                                                                        ex.fparams );
×
3485
  }
3486
  return Core::gamestate.system_hooks.call_script_method( methodname, &ex, this );
×
3487
}
3488

3489
ObjArray* Character::GetReportables() const
2✔
3490
{
3491
  std::unique_ptr<ObjArray> arr( new ObjArray );
2✔
3492

3493
  for ( ReportableList::const_iterator itr = reportable_.begin(), end = reportable_.end();
2✔
3494
        itr != end; ++itr )
4✔
3495
  {
3496
    const reportable_t& rt = ( *itr );
2✔
3497

3498
    std::unique_ptr<BObjectImp> kmember( nullptr );
2✔
3499
    Character* killer = Core::system_find_mobile( rt.serial );
2✔
3500
    if ( killer )
2✔
3501
      kmember.reset( new Module::EOfflineCharacterRefObjImp( killer ) );
2✔
3502
    else
3503
      kmember.reset( new BError( "Mobile not found" ) );
×
3504

3505
    std::unique_ptr<BStruct> elem( new BStruct );
2✔
3506
    elem->addMember( "serial", new BLong( rt.serial ) );
2✔
3507
    elem->addMember( "killer", kmember.release() );
2✔
3508
    elem->addMember( "gameclock", new BLong( static_cast<s32>( rt.polclock ) ) );
2✔
3509

3510
    arr->addElement( elem.release() );
2✔
3511
  }
2✔
3512
  return arr.release();
4✔
3513
}
2✔
3514

3515
ObjArray* Character::GetAggressorTo() const
×
3516
{
3517
  std::unique_ptr<ObjArray> arr( new ObjArray );
×
3518

3519
  for ( Character::MobileCont::const_iterator itr = aggressor_to_.begin(),
×
3520
                                              end = aggressor_to_.end();
×
3521
        itr != end; ++itr )
×
3522
  {
3523
    std::unique_ptr<BObjectImp> member( nullptr );
×
3524
    Character* chr = Core::system_find_mobile( ( *itr ).first->serial );
×
3525
    if ( chr )
×
3526
      member.reset( new Module::EOfflineCharacterRefObjImp( chr ) );
×
3527
    else
3528
      member.reset( new BError( "Mobile not found" ) );
×
3529

3530
    std::unique_ptr<BStruct> elem( new BStruct );
×
3531
    elem->addMember( "serial", new BLong( ( *itr ).first->serial ) );
×
3532
    elem->addMember( "ref", member.release() );
×
3533
    elem->addMember( "seconds",
×
3534
                     new BLong( static_cast<s32>( ( ( *itr ).second - Core::polclock() ) /
×
3535
                                                  Core::POLCLOCKS_PER_SEC ) ) );
×
3536

3537
    arr->addElement( elem.release() );
×
3538
  }
×
3539
  return arr.release();
×
3540
}
×
3541

3542
ObjArray* Character::GetLawFullyDamaged() const
×
3543
{
3544
  std::unique_ptr<ObjArray> arr( new ObjArray );
×
3545

3546
  for ( Character::MobileCont::const_iterator itr = lawfully_damaged_.begin(),
×
3547
                                              end = lawfully_damaged_.end();
×
3548
        itr != end; ++itr )
×
3549
  {
3550
    std::unique_ptr<BObjectImp> member( nullptr );
×
3551
    Character* chr = Core::system_find_mobile( ( *itr ).first->serial );
×
3552
    if ( chr )
×
3553
      member.reset( new Module::EOfflineCharacterRefObjImp( chr ) );
×
3554
    else
3555
      member.reset( new BError( "Mobile not found" ) );
×
3556

3557
    std::unique_ptr<BStruct> elem( new BStruct );
×
3558
    elem->addMember( "serial", new BLong( ( *itr ).first->serial ) );
×
3559
    elem->addMember( "ref", member.release() );
×
3560
    elem->addMember( "seconds",
×
3561
                     new BLong( static_cast<s32>( ( ( *itr ).second - Core::polclock() ) /
×
3562
                                                  Core::POLCLOCKS_PER_SEC ) ) );
×
3563

3564
    arr->addElement( elem.release() );
×
3565
  }
×
3566
  return arr.release();
×
3567
}
×
3568

3569
BObjectImp* NPC::get_script_member_id( const int id ) const
237✔
3570
{
3571
  BObjectImp* imp = base::get_script_member_id( id );
237✔
3572
  if ( imp != nullptr )
237✔
3573
    return imp;
177✔
3574

3575
  switch ( id )
60✔
3576
  {
3577
  case MBR_SCRIPT:
1✔
3578
    return new String( script );
1✔
3579
    break;
3580
  case MBR_NPCTEMPLATE:
×
3581
    return new String( template_name );
×
3582
    break;
3583
  case MBR_MASTER:
1✔
3584
  {
3585
    Character* master = master_.get();
1✔
3586
    if ( master != nullptr && !master->orphan() )
1✔
3587
      return new Module::EOfflineCharacterRefObjImp( master );
1✔
3588
    return new BLong( 0 );
×
3589
    break;
3590
  }
3591

3592
  case MBR_PROCESS:
52✔
3593
    if ( ex )
52✔
3594
      return new Core::ScriptExObjImp( ex );
52✔
3595
    return new BError( "No script running" );
×
3596
    break;
3597

3598
  case MBR_EVENTMASK:
×
3599
    if ( ex )
×
3600
      return new BLong( ex->eventmask );
×
3601
    return new BError( "No script running" );
×
3602
    break;
3603

3604
  case MBR_SPEECH_COLOR:
1✔
3605
    return new BLong( speech_color() );
1✔
3606
    break;
3607
  case MBR_SPEECH_FONT:
1✔
3608
    return new BLong( speech_font() );
1✔
3609
    break;
3610
  case MBR_USE_ADJUSTMENTS:
1✔
3611
    return new BLong( use_adjustments() ? 1 : 0 );
1✔
3612
    break;
3613
  case MBR_RUN_SPEED:
1✔
3614
    return new BLong( run_speed );
1✔
3615
    break;
3616
  case MBR_ALIGNMENT:
×
3617
    return new BLong( template_->alignment );
×
3618
    break;
3619
  case MBR_SAVEONEXIT:
×
3620
    return new BLong( saveonexit() );
×
3621
    break;
3622
  case MBR_NO_DROP_EXCEPTION:
2✔
3623
    return new BLong( no_drop_exception() );
2✔
3624
  default:
×
3625
    return nullptr;
×
3626
  }
3627
}
3628

3629
BObjectImp* NPC::get_script_member( const char* membername ) const
31✔
3630
{
3631
  ObjMember* objmember = getKnownObjMember( membername );
31✔
3632
  if ( objmember != nullptr )
31✔
3633
    return this->get_script_member_id( objmember->id );
31✔
3634
  return nullptr;
×
3635
}
3636

3637
BObjectImp* NPC::set_script_member_id( const int id, const std::string& value )
×
3638
{
3639
  BObjectImp* imp = base::set_script_member_id( id, value );
×
3640
  if ( imp != nullptr )
×
3641
    return imp;
×
3642
  switch ( id )
×
3643
  {
3644
  case MBR_SCRIPT:
×
3645
    return new String( script = value );
×
3646
  default:
×
3647
    return nullptr;
×
3648
  }
3649
}
3650

3651
BObjectImp* NPC::set_script_member( const char* membername, const std::string& value )
×
3652
{
3653
  ObjMember* objmember = getKnownObjMember( membername );
×
3654
  if ( objmember != nullptr )
×
3655
    return this->set_script_member_id( objmember->id, value );
×
3656
  return nullptr;
×
3657
}
3658

3659
BObjectImp* NPC::set_script_member_id( const int id, int value )
29✔
3660
{
3661
  BObjectImp* imp = base::set_script_member_id( id, value );
29✔
3662
  if ( imp != nullptr )
29✔
3663
    return imp;
22✔
3664
  switch ( id )
7✔
3665
  {
3666
  case MBR_SPEECH_COLOR:
×
3667
    speech_color( Clib::clamp_convert<u16>( value ) );
×
3668
    return new BLong( speech_color() );
×
3669
  case MBR_SPEECH_FONT:
×
3670
    speech_font( Clib::clamp_convert<u16>( value ) );
×
3671
    return new BLong( speech_font() );
×
3672
  case MBR_USE_ADJUSTMENTS:
×
3673
    use_adjustments( value ? true : false );
×
3674
    return new BLong( use_adjustments() );
×
3675
  case MBR_RUN_SPEED:
×
3676
    return new BLong( run_speed = Clib::clamp_convert<u16>( value ) );
×
3677
  case MBR_SAVEONEXIT:
1✔
3678
    saveonexit( value ? true : false );
1✔
3679
    return new BLong( saveonexit() );
1✔
3680
  case MBR_NO_DROP_EXCEPTION:
×
3681
    no_drop_exception( value ? true : false );
×
3682
    return new BLong( no_drop_exception() );
×
3683
  default:
6✔
3684
    return nullptr;
6✔
3685
  }
3686
}
3687
BObjectImp* NPC::set_script_member( const char* membername, int value )
×
3688
{
3689
  ObjMember* objmember = getKnownObjMember( membername );
×
3690
  if ( objmember != nullptr )
×
3691
    return this->set_script_member_id( objmember->id, value );
×
3692
  return nullptr;
×
3693
}
3694

3695
BObjectImp* NPC::script_method_id( const int id, Core::UOExecutor& executor )
123✔
3696
{
3697
  BObjectImp* imp = base::script_method_id( id, executor );
123✔
3698
  if ( imp != nullptr )
123✔
3699
    return imp;
122✔
3700

3701
  switch ( id )
1✔
3702
  {
3703
  case MTH_SETMASTER:
1✔
3704
  {
3705
    if ( executor.numParams() != 1 )
1✔
3706
      return new BError( "Not enough parameters" );
×
3707
    Character* chr;
3708
    set_dirty();
1✔
3709
    if ( executor.getCharacterParam( 0, chr ) )
1✔
3710
    {
3711
      master_.set( chr );
1✔
3712
      return new BLong( 1 );
1✔
3713
    }
3714
    else
3715
    {
3716
      master_.clear();
×
3717
      return new BLong( 0 );
×
3718
    }
3719
    break;
3720
  }
3721
  default:
×
3722
    return nullptr;
×
3723
  }
3724
}
3725

3726
BObjectImp* NPC::script_method( const char* methodname, Core::UOExecutor& executor )
×
3727
{
3728
  ObjMethod* objmethod = getKnownObjMethod( methodname );
×
3729
  if ( objmethod != nullptr )
×
3730
    return this->script_method_id( objmethod->id, executor );
×
3731
  return nullptr;
×
3732
}
3733

3734
BObjectImp* NPC::custom_script_method( const char* methodname, Core::UOExecutor& executor )
×
3735
{
3736
  if ( template_->method_script != nullptr )
×
3737
  {
3738
    unsigned PC;
3739
    if ( template_->method_script->FindExportedFunction(
×
3740
             methodname, static_cast<unsigned int>( executor.numParams() + 1 ), PC ) )
×
3741
      return template_->method_script->call( PC, make_ref(), executor.fparams );
×
3742
  }
3743
  return Core::gamestate.system_hooks.call_script_method( methodname, &executor, this );
×
3744
}
3745
}  // namespace Mobile
3746
namespace Core
3747
{
3748
using namespace Bscript;
3749

3750
BObjectImp* ULockable::get_script_member_id( const int id ) const
142✔
3751
{
3752
  BObjectImp* imp = Item::get_script_member_id( id );
142✔
3753
  if ( imp != nullptr )
142✔
3754
    return imp;
122✔
3755

3756
  switch ( id )
20✔
3757
  {
3758
  case MBR_LOCKED:
1✔
3759
    return new BLong( locked() ? 1 : 0 );
1✔
3760
    break;
3761
  default:
19✔
3762
    return nullptr;
19✔
3763
  }
3764
}
3765

3766
BObjectImp* ULockable::get_script_member( const char* membername ) const
×
3767
{
3768
  ObjMember* objmember = getKnownObjMember( membername );
×
3769
  if ( objmember != nullptr )
×
3770
    return this->get_script_member_id( objmember->id );
×
3771
  return nullptr;
×
3772
}
3773

3774
BObjectImp* ULockable::set_script_member_id( const int id, int value )
57✔
3775
{
3776
  BObjectImp* imp = Item::set_script_member_id( id, value );
57✔
3777
  if ( imp != nullptr )
57✔
3778
    return imp;
44✔
3779
  switch ( id )
13✔
3780
  {
3781
  case MBR_LOCKED:
1✔
3782
    locked( value ? true : false );
1✔
3783
    return new BLong( locked() );
1✔
3784
  default:
12✔
3785
    return nullptr;
12✔
3786
  }
3787
}
3788

3789
BObjectImp* ULockable::set_script_member( const char* membername, int value )
×
3790
{
3791
  ObjMember* objmember = getKnownObjMember( membername );
×
3792
  if ( objmember != nullptr )
×
3793
    return this->set_script_member_id( objmember->id, value );
×
3794
  return nullptr;
×
3795
}
3796

3797
BObjectImp* UContainer::get_script_member_id( const int id ) const
125✔
3798
{
3799
  BObjectImp* imp = base::get_script_member_id( id );
125✔
3800
  if ( imp != nullptr )
125✔
3801
    return imp;
106✔
3802

3803
  switch ( id )
19✔
3804
  {
3805
  case MBR_MAX_ITEMS_MOD:
1✔
3806
    return new BLong( max_items_mod() );
1✔
3807
    break;
3808
  case MBR_MAX_WEIGHT_MOD:
1✔
3809
    return new BLong( max_weight_mod() );
1✔
3810
    break;
3811
  case MBR_MAX_SLOTS_MOD:
1✔
3812
    return new BLong( max_slots_mod() );
1✔
3813
    break;
3814
  case MBR_NO_DROP_EXCEPTION:
2✔
3815
    return new BLong( no_drop_exception() );
2✔
3816
  case MBR_HELD_WEIGHT_MULTIPLIER:
7✔
3817
    return new Double( held_weight_multiplier() );
7✔
3818
  default:
7✔
3819
    return nullptr;
7✔
3820
  }
3821
}
3822

3823
BObjectImp* UContainer::get_script_member( const char* membername ) const
5✔
3824
{
3825
  ObjMember* objmember = getKnownObjMember( membername );
5✔
3826
  if ( objmember != nullptr )
5✔
3827
    return this->get_script_member_id( objmember->id );
5✔
3828
  return nullptr;
×
3829
}
3830

3831
BObjectImp* UContainer::set_script_member_id( const int id, int value )
57✔
3832
{
3833
  BObjectImp* imp = base::set_script_member_id( id, value );
57✔
3834
  if ( imp != nullptr )
57✔
3835
    return imp;
45✔
3836
  switch ( id )
12✔
3837
  {
3838
  case MBR_MAX_ITEMS_MOD:
1✔
3839
    max_items_mod( Clib::clamp_convert<s16>( value ) );
1✔
3840
    break;
1✔
3841
  case MBR_MAX_WEIGHT_MOD:
1✔
3842
    max_weight_mod( Clib::clamp_convert<s16>( value ) );
1✔
3843
    break;
1✔
3844
  case MBR_MAX_SLOTS_MOD:
1✔
3845
    max_slots_mod( Clib::clamp_convert<s8>( value ) );
1✔
3846
    break;
1✔
3847
  case MBR_NO_DROP_EXCEPTION:
2✔
3848
    no_drop_exception( value ? true : false );
2✔
3849
    return new BLong( no_drop_exception() );
2✔
3850
  case MBR_WEIGHT_MULTIPLIER_MOD:
×
3851
    return set_script_member_id_double( id, value );
×
3852
  case MBR_HELD_WEIGHT_MULTIPLIER:
7✔
3853
    return set_script_member_id_double( id, value );
7✔
3854
  default:
×
3855
    return nullptr;
×
3856
  }
3857
  return new BLong( value );
3✔
3858
}
3859

3860
Bscript::BObjectImp* UContainer::set_script_member_id_double( const int id, double value )
12✔
3861
{
3862
  BObjectImp* imp = base::set_script_member_id_double( id, value );
12✔
3863
  if ( imp != nullptr )
12✔
3864
    return imp;
×
3865

3866
  switch ( id )
12✔
3867
  {
3868
  case MBR_HELD_WEIGHT_MULTIPLIER:
12✔
3869
  {
3870
    if ( container )
12✔
3871
    {
3872
      int oldweight = weight();
8✔
3873
      held_weight_multiplier( value );
8✔
3874
      container->add_bulk( 0, weight() - oldweight );
8✔
3875
    }
3876
    else
3877
    {
3878
      held_weight_multiplier( value );
4✔
3879
    }
3880

3881
    increv_send_object_recursive();
12✔
3882

3883
    UpdateCharacterWeight( this );
12✔
3884

3885
    return new Double( held_weight_multiplier() );
12✔
3886
  }
3887
  default:
×
3888
    return nullptr;
×
3889
  }
3890
  return new BLong( value );
3891
}
3892

3893
BObjectImp* UContainer::set_script_member( const char* membername, int value )
49✔
3894
{
3895
  ObjMember* objmember = getKnownObjMember( membername );
49✔
3896
  if ( objmember != nullptr )
49✔
3897
    return this->set_script_member_id( objmember->id, value );
49✔
3898
  return nullptr;
×
3899
}
3900

3901
BObjectImp* UCorpse::get_script_member_id( const int id ) const
14✔
3902
{
3903
  BObjectImp* imp = base::get_script_member_id( id );
14✔
3904
  if ( imp != nullptr )
14✔
3905
    return imp;
7✔
3906

3907
  switch ( id )
7✔
3908
  {
3909
  case MBR_CORPSETYPE:
1✔
3910
    return new BLong( corpsetype );
1✔
3911
    break;
3912
  case MBR_OWNERSERIAL:
6✔
3913
    return new BLong( ownerserial );
6✔
3914
    break;
3915
  default:
×
3916
    return nullptr;
×
3917
  }
3918
}
3919

3920
BObjectImp* UCorpse::get_script_member( const char* membername ) const
2✔
3921
{
3922
  ObjMember* objmember = getKnownObjMember( membername );
2✔
3923
  if ( objmember != nullptr )
2✔
3924
    return this->get_script_member_id( objmember->id );
2✔
3925
  return nullptr;
×
3926
}
3927

3928
BObjectImp* Spellbook::script_method_id( const int id, Core::UOExecutor& ex )
4✔
3929
{
3930
  BObjectImp* imp = base::script_method_id( id, ex );
4✔
3931
  if ( imp != nullptr )
4✔
3932
    return imp;
×
3933

3934
  switch ( id )
4✔
3935
  {
3936
  case MTH_HASSPELL:
2✔
3937
  {
3938
    u32 sid;
3939
    if ( !ex.hasParams( 1 ) )
2✔
3940
      return new BError( "Not enough parameters" );
2✔
3941
    if ( ex.getParam( 0, sid ) )
2✔
3942
    {
3943
      if ( sid == 0 )
2✔
3944
        return new BError( "SpellID must be >= 1" );
×
3945
      if ( this->has_spellid( sid ) )
2✔
3946
        return new BLong( 1 );
2✔
3947
      else
3948
        return new BLong( 0 );
×
3949
    }
3950
    break;
×
3951
  }
3952
  case MTH_SPELLS:
×
3953
  {
3954
    std::unique_ptr<ObjArray> arr( new ObjArray );
×
3955
    for ( u16 i = 0; i < 64; ++i )
×
3956
    {
3957
      unsigned int sid;
3958

3959
      // Check for Mysticism spells here
3960
      if ( this->spell_school == 3 )
×
3961
        sid = 678 + i;
×
3962
      else
3963
        sid = this->spell_school * 100 + i + 1;
×
3964

3965
      if ( this->has_spellid( sid ) )
×
3966
        arr->addElement( new BLong( sid ) );
×
3967
    }
3968
    return arr.release();
×
3969
    break;
3970
  }
×
3971
  case MTH_REMOVESPELL:
×
3972
  {
3973
    u32 sid;
3974
    if ( !ex.hasParams( 1 ) )
×
3975
      return new BError( "Not enough parameters" );
×
3976
    if ( ex.getParam( 0, sid ) )
×
3977
    {
3978
      if ( sid == 0 )
×
3979
        return new BError( "SpellID must be >= 1" );
×
3980
      if ( this->remove_spellid( sid ) )
×
3981
        return new BLong( 1 );
×
3982
      else
3983
        return new BLong( 0 );
×
3984
    }
3985
    break;
×
3986
  }
3987
  case MTH_ADDSPELL:
2✔
3988
  {
3989
    u32 sid;
3990
    if ( !ex.hasParams( 1 ) )
2✔
3991
      return new BError( "Not enough parameters" );
2✔
3992
    if ( ex.getParam( 0, sid ) )
2✔
3993
    {
3994
      if ( sid == 0 )
2✔
3995
        return new BError( "SpellID must be >= 1" );
×
3996
      if ( this->add_spellid( sid ) )
2✔
3997
        return new BLong( 1 );
2✔
3998
      else
3999
        return new BLong( 0 );
×
4000
    }
4001
    break;
×
4002
  }
4003

4004
  default:
×
4005
    return nullptr;
×
4006
  }
4007
  return new BError( "Invalid parameter type" );
×
4008
}
4009

4010
BObjectImp* Spellbook::script_method( const char* methodname, Core::UOExecutor& ex )
×
4011
{
4012
  ObjMethod* objmethod = getKnownObjMethod( methodname );
×
4013
  if ( objmethod != nullptr )
×
4014
    return this->script_method_id( objmethod->id, ex );
×
4015
  return nullptr;
×
4016
}
4017
}  // namespace Core
4018
namespace Multi
4019
{
4020
using namespace Bscript;
4021

4022
BObjectImp* UBoat::make_ref()
5✔
4023
{
4024
  return new Module::EUBoatRefObjImp( this );
5✔
4025
}
4026

4027
BObjectImp* UMulti::make_ref()
23✔
4028
{
4029
  return new Module::EMultiRefObjImp( this );
23✔
4030
}
4031

4032
BObjectImp* UBoat::get_script_member_id( const int id ) const
6,176✔
4033
{
4034
  BObjectImp* imp = base::get_script_member_id( id );
6,176✔
4035
  if ( imp != nullptr )
6,176✔
4036
    return imp;
6,142✔
4037

4038
  switch ( id )
34✔
4039
  {
4040
  case MBR_TILLERMAN:
×
4041
  {
4042
    Item* cp = tillerman;
×
4043
    if ( cp != nullptr )
×
4044
      return new Module::EItemRefObjImp( cp );
×
4045
    return new BError( std::string( "This ship doesn't have that component" ) );
×
4046
    break;
4047
  }
4048
  case MBR_PORTPLANK:
17✔
4049
  {
4050
    Item* cp = portplank;
17✔
4051
    if ( cp != nullptr )
17✔
4052
      return new Module::EItemRefObjImp( cp );
17✔
4053
    return new BError( std::string( "This ship doesn't have that component" ) );
×
4054
    break;
4055
  }
4056
  case MBR_STARBOARDPLANK:
×
4057
  {
4058
    Item* cp = starboardplank;
×
4059
    if ( cp != nullptr )
×
4060
      return new Module::EItemRefObjImp( cp );
×
4061
    return new BError( std::string( "This ship doesn't have that component" ) );
×
4062
    break;
4063
  }
4064
  case MBR_HOLD:
×
4065
  {
4066
    Item* cp = hold;
×
4067
    if ( cp != nullptr )
×
4068
      return new Module::EItemRefObjImp( cp );
×
4069
    return new BError( std::string( "This ship doesn't have that component" ) );
×
4070
    break;
4071
  }
4072
  case MBR_ROPE:
×
4073
    return component_list( COMPONENT_ROPE );
×
4074
    break;
4075
  case MBR_WHEEL:
×
4076
    return component_list( COMPONENT_WHEEL );
×
4077
    break;
4078
  case MBR_HULL:
×
4079
    return component_list( COMPONENT_HULL );
×
4080
    break;
4081
  case MBR_TILLER:
×
4082
    return component_list( COMPONENT_TILLER );
×
4083
    break;
4084
  case MBR_RUDDER:
×
4085
    return component_list( COMPONENT_RUDDER );
×
4086
    break;
4087
  case MBR_SAILS:
×
4088
    return component_list( COMPONENT_SAILS );
×
4089
    break;
4090
  case MBR_STORAGE:
×
4091
    return component_list( COMPONENT_STORAGE );
×
4092
    break;
4093
  case MBR_WEAPONSLOT:
×
4094
    return component_list( COMPONENT_WEAPONSLOT );
×
4095
    break;
4096
  case MBR_COMPONENTS:
1✔
4097
    return component_list( COMPONENT_ALL );
1✔
4098
    break;
4099
  case MBR_ITEMS:
3✔
4100
    return items_list();
3✔
4101
    break;
4102
  case MBR_MOBILES:
4✔
4103
    return mobiles_list();
4✔
4104
    break;
4105
  case MBR_HAS_OFFLINE_MOBILES:
×
4106
    return new BLong( has_offline_mobiles() ? 1 : 0 );
×
4107
    break;
4108
  case MBR_MULTIID:
6✔
4109
    return new BLong( multiid_ );
6✔
4110
    break;
4111
  case MBR_PILOT:
3✔
4112
  {
4113
    Mobile::Character* owner = pilot();
3✔
4114
    if ( owner != nullptr )
3✔
4115
    {
4116
      return new Module::ECharacterRefObjImp( owner );
2✔
4117
    }
4118
  }
4119
    return new BLong( 0 );
1✔
4120
  default:
×
4121
    return nullptr;
×
4122
  }
4123
}
4124

4125
BObjectImp* UBoat::get_script_member( const char* membername ) const
2✔
4126
{
4127
  ObjMember* objmember = getKnownObjMember( membername );
2✔
4128
  if ( objmember != nullptr )
2✔
4129
    return this->get_script_member_id( objmember->id );
2✔
4130
  return nullptr;
×
4131
}
4132

4133
BObjectImp* UBoat::script_method_id( const int id, Core::UOExecutor& ex )
39✔
4134
{
4135
  BObjectImp* imp = base::script_method_id( id, ex );
39✔
4136
  if ( imp != nullptr )
39✔
4137
    return imp;
25✔
4138

4139
  switch ( id )
14✔
4140
  {
4141
  case MTH_MOVE_OFFLINE_MOBILES:
×
4142
  {
4143
    if ( ex.numParams() == 3 )
×
4144
    {
4145
      Core::Pos3d pos;
×
4146
      if ( !ex.getPos3dParam( 0, 1, 2, &pos, realm() ) )
×
4147
        return new BError( "Invalid parameter type" );
×
4148
      set_dirty();
×
4149
      move_offline_mobiles( Core::Pos4d( pos, realm() ) );
×
4150
      return new BLong( 1 );
×
4151
    }
4152
    else if ( ex.numParams() == 4 )
×
4153
    {
4154
      Core::Pos4d pos;
×
4155
      if ( !ex.getPos4dParam( 0, 1, 2, 3, &pos ) )
×
4156
        return new BError( "Invalid parameter type" );
×
4157
      set_dirty();
×
4158
      move_offline_mobiles( pos );
×
4159
      return new BLong( 1 );
×
4160
    }
4161
    return new BError( "Not enough parameters" );
×
4162
  }
4163
  case MTH_SET_PILOT:
10✔
4164
  {
4165
    if ( !ex.hasParams( 1 ) )
10✔
4166
    {
4167
      return new BError( "Not enough parameters" );
×
4168
    }
4169

4170
    BObjectImp* impMaybeZero = ex.getParamImp( 0 );
10✔
4171

4172
    if ( auto* value = impptrIf<BLong>( impMaybeZero ) )
10✔
4173
    {
4174
      if ( value->value() != 0 )
6✔
4175
        return new BError( "Invalid parameters" );
×
4176
      return set_pilot( nullptr );
6✔
4177
    }
4178
    else
4179
    {
4180
      Mobile::Character* chr;
4181

4182
      if ( !ex.getCharacterParam( 0, chr ) )
4✔
4183
        return new BError( "Invalid parameters" );
×
4184

4185
      return set_pilot( chr );
4✔
4186
    }
4187
  }
4188
  case MTH_SET_ALTERNATE_MULTIID:
4✔
4189
  {
4190
    if ( ex.numParams() != 1 )
4✔
4191
      return new BError( "Not enough parameters" );
×
4192
    u32 index;
4193
    if ( !ex.getParam( 0, index ) )
4✔
4194
      return new BError( "Invalid parameter type" );
×
4195
    const auto& desc = static_cast<const Items::BoatDesc&>( itemdesc() );
4✔
4196
    if ( index >= desc.alternates.size() )
4✔
4197
      return new BError( "Index out of range" );
1✔
4198

4199
    {
4200
      UBoat::BoatMoveGuard guard( this );
3✔
4201
      u16 new_multiid = desc.alternates[index];
3✔
4202
      u16 base_multi = multiid_ & ~3u;
3✔
4203
      u16 multioffset = multiid_ - base_multi;
3✔
4204
      multiid_ = new_multiid + multioffset;
3✔
4205
    }
3✔
4206
    transform_components( boatshape() );
3✔
4207
    send_display_boat_to_inrange( {} );
3✔
4208
    return new BLong( 1 );
3✔
4209
  }
4210
  default:
×
4211
    return nullptr;
×
4212
  }
4213
}
4214

4215
BObjectImp* UBoat::script_method( const char* methodname, Core::UOExecutor& ex )
×
4216
{
4217
  ObjMethod* objmethod = getKnownObjMethod( methodname );
×
4218
  if ( objmethod != nullptr )
×
4219
    return this->script_method_id( objmethod->id, ex );
×
4220
  return nullptr;
×
4221
}
4222

4223
BObjectImp* UPlank::get_script_member_id( const int id ) const
17✔
4224
{
4225
  switch ( id )
17✔
4226
  {
4227
  case MBR_MULTI:
×
4228
    if ( boat_.get() )
×
4229
      return new Module::EUBoatRefObjImp( boat_.get() );
×
4230
    return new BError( "No boat attached" );
×
4231
    break;
4232
  }
4233
  return base::get_script_member_id( id );
17✔
4234
}
4235

4236
/* UObject defines a 'multi' also, so we have to trap that here first */
4237
BObjectImp* UPlank::get_script_member( const char* membername ) const
×
4238
{
4239
  ObjMember* objmember = getKnownObjMember( membername );
×
4240
  if ( objmember != nullptr )
×
4241
    return this->get_script_member_id( objmember->id );
×
4242
  return base::get_script_member( membername );
×
4243
}
4244
}  // namespace Multi
4245
namespace Core
4246
{
4247
using namespace Bscript;
4248

4249
BObjectImp* Map::get_script_member_id( const int id ) const
9✔
4250
{
4251
  BObjectImp* imp = base::get_script_member_id( id );
9✔
4252
  if ( imp != nullptr )
9✔
4253
    return imp;
1✔
4254

4255
  switch ( id )
8✔
4256
  {
4257
  case MBR_XEAST:
1✔
4258
    return new BLong( xeast );
1✔
4259
  case MBR_XWEST:
1✔
4260
    return new BLong( xwest );
1✔
4261
  case MBR_YNORTH:
1✔
4262
    return new BLong( ynorth );
1✔
4263
  case MBR_YSOUTH:
1✔
4264
    return new BLong( ysouth );
1✔
4265
  case MBR_GUMPWIDTH:
1✔
4266
    return new BLong( gumpsize.x() );
1✔
4267
  case MBR_GUMPHEIGHT:
1✔
4268
    return new BLong( gumpsize.y() );
1✔
4269
  case MBR_FACETID:
1✔
4270
    return new BLong( facetid );
1✔
4271
  case MBR_EDITABLE:
1✔
4272
    return new BLong( editable ? 1 : 0 );
1✔
4273
  default:
×
4274
    return nullptr;
×
4275
  }
4276
}
4277

4278
BObjectImp* Map::get_script_member( const char* membername ) const
8✔
4279
{
4280
  ObjMember* objmember = getKnownObjMember( membername );
8✔
4281
  if ( objmember != nullptr )
8✔
4282
    return this->get_script_member_id( objmember->id );
8✔
4283
  return nullptr;
×
4284
}
4285

4286
BObjectImp* Map::set_script_member_id( const int id, int value )
8✔
4287
{
4288
  BObjectImp* imp = base::set_script_member_id( id, value );
8✔
4289
  if ( imp != nullptr )
8✔
4290
    return imp;
×
4291
  switch ( id )
8✔
4292
  {
4293
  case MBR_XEAST:
1✔
4294
    return new BLong( xeast = Clib::clamp_convert<u16>( value ) );
1✔
4295
  case MBR_XWEST:
1✔
4296
    return new BLong( xwest = Clib::clamp_convert<u16>( value ) );
1✔
4297
  case MBR_YNORTH:
1✔
4298
    return new BLong( ynorth = Clib::clamp_convert<u16>( value ) );
1✔
4299
  case MBR_YSOUTH:
1✔
4300
    return new BLong( ysouth = Clib::clamp_convert<u16>( value ) );
1✔
4301
  case MBR_GUMPWIDTH:
1✔
4302
    gumpsize.x( Clib::clamp_convert<u16>( value ) );
1✔
4303
    return new BLong( gumpsize.x() );
1✔
4304
  case MBR_GUMPHEIGHT:
1✔
4305
    gumpsize.y( Clib::clamp_convert<u16>( value ) );
1✔
4306
    return new BLong( gumpsize.y() );
1✔
4307
  case MBR_FACETID:
1✔
4308
    return new BLong( facetid = Clib::clamp_convert<u16>( value ) );
1✔
4309
  case MBR_EDITABLE:
1✔
4310
    return new BLong( editable = value ? true : false );
1✔
4311
  default:
×
4312
    return nullptr;
×
4313
  }
4314
}
4315
BObjectImp* Map::set_script_member( const char* membername, int value )
8✔
4316
{
4317
  ObjMember* objmember = getKnownObjMember( membername );
8✔
4318
  if ( objmember != nullptr )
8✔
4319
    return this->set_script_member_id( objmember->id, value );
8✔
4320
  return nullptr;
×
4321
}
4322

4323
BObjectImp* UObject::script_method_id( const int id, Core::UOExecutor& ex )
575✔
4324
{
4325
  switch ( id )
575✔
4326
  {
4327
  case MTH_ISA:
×
4328
  {
4329
    if ( !ex.hasParams( 1 ) )
×
4330
      return new BError( "Not enough parameters" );
×
4331
    u32 isatype;
4332
    if ( ex.getParam( 0, isatype ) )
×
4333
      return new BLong( script_isa( isatype ) );
×
4334
    break;
×
4335
  }
4336
  case MTH_SET_MEMBER:
177✔
4337
  {
4338
    if ( !ex.hasParams( 2 ) )
177✔
4339
      return new BError( "Not enough parameters" );
177✔
4340
    BObjectImp* objimp;
4341
    const String* mname;
4342
    if ( ex.getStringParam( 0, mname ) && ( objimp = ex.getParamImp( 1 ) ) != nullptr )
177✔
4343
    {
4344
      BObjectImp* ret;
4345
      if ( auto* l = impptrIf<BLong>( objimp ) )
177✔
4346
        ret = set_script_member( mname->value().c_str(), l->value() );
159✔
4347
      else if ( auto* d = impptrIf<Double>( objimp ) )
18✔
4348
        ret = set_script_member_double( mname->value().c_str(), d->value() );
5✔
4349
      else if ( auto* s = impptrIf<String>( objimp ) )
13✔
4350
        ret = set_script_member( mname->value().c_str(), s->value() );
13✔
4351
      else
4352
        return new BError( "Invalid value type" );
×
4353

4354
      if ( ret != nullptr )
177✔
4355
        return ret;
177✔
4356
      else
4357
      {
4358
        std::string message = std::string( "Member " ) + std::string( mname->value() ) +
×
4359
                              std::string( " not found on that object" );
×
4360
        return new BError( message );
×
4361
      }
×
4362
    }
4363
    break;
×
4364
  }
4365
  case MTH_GET_MEMBER:
227✔
4366
  {
4367
    if ( !ex.hasParams( 1 ) )
227✔
4368
      return new BError( "Not enough parameters" );
227✔
4369

4370
    const String* mname;
4371
    if ( ex.getStringParam( 0, mname ) )
227✔
4372
    {
4373
      BObjectImp* ret = get_script_member( mname->value().c_str() );
227✔
4374
      if ( ret != nullptr )
227✔
4375
        return ret;
227✔
4376
      else
4377
      {
4378
        std::string message = std::string( "Member " ) + std::string( mname->value() ) +
×
4379
                              std::string( " not found on that object" );
×
4380
        return new BError( message );
×
4381
      }
×
4382
    }
4383
    break;
×
4384
  }
4385
  default:
171✔
4386
  {
4387
    bool changed = false;
171✔
4388
    BObjectImp* imp = CallPropertyListMethod_id( proplist_, id, ex, changed );
171✔
4389
    if ( changed )
171✔
4390
      set_dirty();
42✔
4391
    return imp;
171✔
4392
  }
4393
  }
4394
  return new BError( "Invalid parameter type" );
×
4395
}
4396

4397

4398
BObjectImp* UObject::script_method( const char* methodname, Core::UOExecutor& ex )
×
4399
{
4400
  ObjMethod* objmethod = getKnownObjMethod( methodname );
×
4401
  if ( objmethod != nullptr )
×
4402
    return this->script_method_id( objmethod->id, ex );
×
4403
  else
4404
  {
4405
    bool changed = false;
×
4406
    BObjectImp* imp = CallPropertyListMethod( proplist_, methodname, ex, changed );
×
4407
    if ( changed )
×
4408
      set_dirty();
×
4409

4410
    return imp;
×
4411
  }
4412
}
4413

4414
BObjectImp* UObject::custom_script_method( const char* methodname, Core::UOExecutor& ex )
×
4415
{
4416
  ObjMethod* objmethod = getKnownObjMethod( methodname );
×
4417
  if ( objmethod != nullptr )
×
4418
    return this->script_method_id( objmethod->id, ex );
×
4419
  return Core::gamestate.system_hooks.call_script_method( methodname, &ex, this );
×
4420
}
4421

4422
BObjectImp* UDoor::get_script_member_id( const int id ) const
×
4423
{
4424
  BObjectImp* imp = ULockable::get_script_member_id( id );
×
4425
  if ( imp != nullptr )
×
4426
    return imp;
×
4427

4428
  switch ( id )
×
4429
  {
4430
  case MBR_ISOPEN:
×
4431
    return new BLong( is_open() ? 1 : 0 );
×
4432
    break;
4433
  default:
×
4434
    return nullptr;
×
4435
  }
4436
}
4437

4438
BObjectImp* UDoor::get_script_member( const char* membername ) const
×
4439
{
4440
  ObjMember* objmember = getKnownObjMember( membername );
×
4441
  if ( objmember != nullptr )
×
4442
    return this->get_script_member_id( objmember->id );
×
4443
  return nullptr;
×
4444
}
4445

4446
BObjectImp* UDoor::script_method_id( const int id, Core::UOExecutor& ex )
×
4447
{
4448
  BObjectImp* imp = base::script_method_id( id, ex );
×
4449
  if ( imp != nullptr )
×
4450
    return imp;
×
4451

4452
  switch ( id )
×
4453
  {
4454
  case MTH_OPEN:
×
4455
    open();
×
4456
    break;
×
4457
  case MTH_CLOSE:
×
4458
    close();
×
4459
    break;
×
4460
  case MTH_TOGGLE:
×
4461
    toggle();
×
4462
    break;
×
4463
  default:
×
4464
    return nullptr;
×
4465
  }
4466
  return new BLong( 1 );
×
4467
}
4468

4469
BObjectImp* UDoor::script_method( const char* methodname, Core::UOExecutor& ex )
×
4470
{
4471
  ObjMethod* objmethod = getKnownObjMethod( methodname );
×
4472
  if ( objmethod != nullptr )
×
4473
    return this->script_method_id( objmethod->id, ex );
×
4474
  return nullptr;
×
4475
}
4476
}  // namespace Core
4477
namespace Items
4478
{
4479
using namespace Bscript;
4480

4481
BObjectImp* Equipment::get_script_member_id( const int id ) const
7✔
4482
{
4483
  BObjectImp* imp = Item::get_script_member_id( id );
7✔
4484
  if ( imp != nullptr )
7✔
4485
    return imp;
2✔
4486

4487
  switch ( id )
5✔
4488
  {
4489
  case MBR_INTRINSIC:
×
4490
    return new BLong( is_intrinsic() );
×
4491
    break;
4492
  default:
5✔
4493
    return nullptr;
5✔
4494
  }
4495
}
4496
BObjectImp* Equipment::get_script_member( const char* membername ) const
×
4497
{
4498
  ObjMember* objmember = getKnownObjMember( membername );
×
4499
  if ( objmember != nullptr )
×
4500
    return this->get_script_member_id( objmember->id );
×
4501
  return nullptr;
×
4502
}
4503

4504
BObjectImp* Equipment::set_script_member_id( const int id, int value )
3✔
4505
{
4506
  BObjectImp* imp = Item::set_script_member_id( id, value );
3✔
4507
  if ( imp != nullptr )
3✔
4508
    return imp;
×
4509

4510
  return nullptr;
3✔
4511
  /*
4512
  switch(id)
4513
  {
4514
  default: return nullptr;
4515
  }
4516
  */
4517
}
4518
BObjectImp* Equipment::set_script_member( const char* membername, int value )
×
4519
{
4520
  ObjMember* objmember = getKnownObjMember( membername );
×
4521
  if ( objmember != nullptr )
×
4522
    return this->set_script_member_id( objmember->id, value );
×
4523
  return nullptr;
×
4524
}
4525

4526
BObjectImp* Equipment::set_script_member_id_double( const int id, double value )
×
4527
{
4528
  BObjectImp* imp = Item::set_script_member_id_double( id, value );
×
4529
  if ( imp != nullptr )
×
4530
    return imp;
×
4531

4532
  return nullptr;
×
4533
  /*
4534
  switch(id)
4535
  {
4536
  default: return nullptr;
4537
  }
4538
  */
4539
}
4540
BObjectImp* Equipment::set_script_member_double( const char* membername, double value )
×
4541
{
4542
  ObjMember* objmember = getKnownObjMember( membername );
×
4543
  if ( objmember != nullptr )
×
4544
    return this->set_script_member_id_double( objmember->id, value );
×
4545
  return nullptr;
×
4546
}
4547

4548

4549
BObjectImp* UWeapon::get_script_member_id( const int id ) const
4✔
4550
{
4551
  BObjectImp* imp = Equipment::get_script_member_id( id );
4✔
4552
  if ( imp != nullptr )
4✔
4553
    return imp;
1✔
4554

4555
  switch ( id )
3✔
4556
  {
4557
  case MBR_DMG_MOD:
1✔
4558
    return new BLong( damage_mod() );
1✔
4559
    break;
4560
  case MBR_SPEED_MOD:
1✔
4561
    return new BLong( speed_mod() );
1✔
4562
    break;
4563
  case MBR_ATTRIBUTE:
×
4564
    return new String( attribute().name );
×
4565
    break;
4566
  case MBR_HITSCRIPT:
1✔
4567
    return new String( hit_script_.qualifiedname() );
1✔
4568
    break;
4569
  default:
×
4570
    return nullptr;
×
4571
  }
4572
}
4573
BObjectImp* UWeapon::get_script_member( const char* membername ) const
3✔
4574
{
4575
  ObjMember* objmember = getKnownObjMember( membername );
3✔
4576
  if ( objmember != nullptr )
3✔
4577
    return this->get_script_member_id( objmember->id );
3✔
4578
  return nullptr;
×
4579
}
4580

4581
BObjectImp* UWeapon::set_script_member_id( const int id, const std::string& value )
2✔
4582
{
4583
  BObjectImp* imp = Item::set_script_member_id( id, value );
2✔
4584
  if ( imp != nullptr )
2✔
4585
    return imp;
1✔
4586

4587
  switch ( id )
1✔
4588
  {
4589
  case MBR_HITSCRIPT:
1✔
4590
    set_hit_script( value );
1✔
4591
    return new BLong( 1 );
1✔
4592
  default:
×
4593
    return nullptr;
×
4594
  }
4595
}
4596
BObjectImp* UWeapon::set_script_member( const char* membername, const std::string& value )
1✔
4597
{
4598
  ObjMember* objmember = getKnownObjMember( membername );
1✔
4599
  if ( objmember != nullptr )
1✔
4600
    return this->set_script_member_id( objmember->id, value );
1✔
4601
  return nullptr;
×
4602
}
4603

4604
BObjectImp* UWeapon::set_script_member_id( const int id, int value )
2✔
4605
{
4606
  if ( is_intrinsic() )
2✔
4607
    return new BError( "Cannot alter an instrinsic NPC weapon member values" );  // executor won't
×
4608
                                                                                 // return this to
4609
                                                                                 // the script
4610
                                                                                 // currently.
4611

4612
  BObjectImp* imp = Equipment::set_script_member_id( id, value );
2✔
4613
  if ( imp != nullptr )
2✔
4614
    return imp;
×
4615

4616
  switch ( id )
2✔
4617
  {
4618
  case MBR_DMG_MOD:
1✔
4619
    damage_mod( Clib::clamp_convert<s16>( value ) );
1✔
4620
    break;
1✔
4621
  case MBR_SPEED_MOD:
1✔
4622
    speed_mod( Clib::clamp_convert<s16>( value ) );
1✔
4623
    break;
1✔
4624
  default:
×
4625
    return nullptr;
×
4626
  }
4627
  return new BLong( value );
2✔
4628
}
4629

4630
BObjectImp* UWeapon::set_script_member( const char* membername, int value )
2✔
4631
{
4632
  ObjMember* objmember = getKnownObjMember( membername );
2✔
4633
  if ( objmember != nullptr )
2✔
4634
    return this->set_script_member_id( objmember->id, value );
2✔
4635
  return nullptr;
×
4636
}
4637

4638
BObjectImp* UWeapon::set_script_member_id_double( const int id, double value )
×
4639
{
4640
  if ( is_intrinsic() )
×
4641
    return new BError( "Cannot alter an instrinsic NPC weapon member values" );  // executor won't
×
4642
                                                                                 // return this to
4643
                                                                                 // the script
4644
                                                                                 // currently.
4645
  return base::set_script_member_id_double( id, value );
×
4646
}
4647

4648
BObjectImp* UWeapon::set_script_member_double( const char* membername, double value )
×
4649
{
4650
  ObjMember* objmember = getKnownObjMember( membername );
×
4651
  if ( objmember != nullptr )
×
4652
    return this->set_script_member_id_double( objmember->id, value );
×
4653
  return base::set_script_member_double( membername, value );
×
4654
}
4655

4656
BObjectImp* UArmor::get_script_member_id( const int id ) const
3✔
4657
{
4658
  BObjectImp* imp = Equipment::get_script_member_id( id );
3✔
4659
  if ( imp != nullptr )
3✔
4660
    return imp;
1✔
4661

4662
  switch ( id )
2✔
4663
  {
4664
  case MBR_AR_MOD:
1✔
4665
    return new BLong( ar_mod() );
1✔
4666
    break;
4667
  case MBR_AR:
×
4668
    return new BLong( ar() );
×
4669
    break;
4670
  case MBR_AR_BASE:
×
4671
    return new BLong( ar_base() );
×
4672
    break;
4673
  case MBR_ONHIT_SCRIPT:
1✔
4674
    // bad method name? nullptr makes it return the fullpath
4675
    return new String( onhitscript_.qualifiedname() );
1✔
4676
    break;
4677
  default:
×
4678
    return nullptr;
×
4679
  }
4680
}
4681

4682
BObjectImp* UArmor::get_script_member( const char* membername ) const
2✔
4683
{
4684
  ObjMember* objmember = getKnownObjMember( membername );
2✔
4685
  if ( objmember != nullptr )
2✔
4686
    return this->get_script_member_id( objmember->id );
2✔
4687
  return nullptr;
×
4688
}
4689

4690
BObjectImp* UArmor::set_script_member_id( const int id, const std::string& value )
2✔
4691
{
4692
  BObjectImp* imp = Item::set_script_member_id( id, value );
2✔
4693
  if ( imp != nullptr )
2✔
4694
    return imp;
1✔
4695
  switch ( id )
1✔
4696
  {
4697
  case MBR_ONHIT_SCRIPT:
1✔
4698
    set_onhitscript( value );
1✔
4699
    return new BLong( 1 );
1✔
4700
  default:
×
4701
    return nullptr;
×
4702
  }
4703
}
4704

4705
BObjectImp* UArmor::set_script_member( const char* membername, const std::string& value )
1✔
4706
{
4707
  ObjMember* objmember = getKnownObjMember( membername );
1✔
4708
  if ( objmember != nullptr )
1✔
4709
    return this->set_script_member_id( objmember->id, value );
1✔
4710
  return nullptr;
×
4711
}
4712

4713
BObjectImp* UArmor::set_script_member_id( const int id, int value )
1✔
4714
{
4715
  BObjectImp* imp = Equipment::set_script_member_id( id, value );
1✔
4716
  if ( imp != nullptr )
1✔
4717
    return imp;
×
4718

4719
  switch ( id )
1✔
4720
  {
4721
  case MBR_AR_MOD:
1✔
4722
    this->ar_mod( Clib::clamp_convert<s16>( value ) );
1✔
4723
    if ( container != nullptr )
1✔
4724
    {
4725
      if ( Core::IsCharacter( container->serial ) )
×
4726
      {
4727
        Mobile::Character* chr = container->get_chr_owner();
×
4728
        if ( chr != nullptr )
×
4729
          Mobile::ARUpdater::on_change( chr );
×
4730
      }
4731
    }
4732
    return new BLong( value );
1✔
4733
  default:
×
4734
    return nullptr;
×
4735
  }
4736
}
4737

4738
BObjectImp* UArmor::set_script_member( const char* membername, int value )
1✔
4739
{
4740
  ObjMember* objmember = getKnownObjMember( membername );
1✔
4741
  if ( objmember != nullptr )
1✔
4742
    return this->set_script_member_id( objmember->id, value );
1✔
4743
  return nullptr;
×
4744
}
4745
}  // namespace Items
4746
namespace Module
4747
{
4748
using namespace Bscript;
4749

4750
const char* EClientRefObjImp::typeOf() const
×
4751
{
4752
  return "ClientRef";
×
4753
}
4754

4755
u8 EClientRefObjImp::typeOfInt() const
×
4756
{
4757
  return OTClientRef;
×
4758
}
4759

4760
BObjectImp* EClientRefObjImp::copy() const
×
4761
{
4762
  if ( value().exists() )
×
4763
    return value()->make_ref();
×
4764
  return new BError( "Client is disconnected" );
×
4765
}
4766

4767
bool EClientRefObjImp::isTrue() const
2✔
4768
{
4769
  return ( value().exists() && value()->isConnected() );
2✔
4770
}
4771

4772
bool EClientRefObjImp::operator==( const BObjectImp& objimp ) const
×
4773
{
4774
  if ( objimp.isa( BObjectImp::OTApplicObj ) )
×
4775
  {
4776
    const BApplicObjBase* aob =
4777
        Clib::explicit_cast<const BApplicObjBase*, const BObjectImp*>( &objimp );
×
4778

4779
    if ( aob->object_type() == &eclientrefobjimp_type )
×
4780
    {
4781
      const EClientRefObjImp* clientref_imp =
4782
          Clib::explicit_cast<const EClientRefObjImp*, const BApplicObjBase*>( aob );
×
4783

4784
      if ( clientref_imp->value().exists() && value().exists() &&
×
4785
           ( clientref_imp->value()->chr != nullptr ) && ( value()->chr != nullptr ) )
×
4786
        return ( clientref_imp->value()->chr->serial == value()->chr->serial );
×
4787
      return false;
×
4788
    }
4789
    return false;
×
4790
  }
4791
  else if ( objimp.isa( Bscript::BObjectImp::OTBoolean ) )
×
4792
    return isTrue() == static_cast<const Bscript::BBoolean&>( objimp ).isTrue();
×
4793
  return false;
×
4794
}
4795

4796
BObjectRef EClientRefObjImp::get_member_id( const int id )
5✔
4797
{
4798
  if ( ( !obj_.exists() ) || ( !obj_->isConnected() ) )
5✔
4799
    return BObjectRef( new BError( "Client not ready or disconnected" ) );
×
4800

4801
  BObjectImp* result = obj_->get_script_member_id( id );
5✔
4802
  if ( result != nullptr )
5✔
4803
    return BObjectRef( result );
4✔
4804
  return BObjectRef( UninitObject::create() );
1✔
4805
}
4806

4807
BObjectRef EClientRefObjImp::get_member( const char* membername )
1✔
4808
{
4809
  if ( ( !obj_.exists() ) || ( !obj_->isConnected() ) )
1✔
4810
    return BObjectRef( new BError( "Client not ready or disconnected" ) );
×
4811
  ObjMember* objmember = getKnownObjMember( membername );
1✔
4812
  if ( objmember != nullptr )
1✔
4813
    return this->get_member_id( objmember->id );
×
4814
  return BObjectRef( UninitObject::create() );
1✔
4815
}
4816

4817
BObjectRef EClientRefObjImp::set_member( const char* membername, BObjectImp* value, bool copy )
×
4818
{
4819
  if ( !obj_.exists() || !obj_->isConnected() )
×
4820
    return BObjectRef( new BError( "Client not ready or disconnected" ) );
×
4821
  ObjMember* objmember = getKnownObjMember( membername );
×
4822
  if ( objmember != nullptr )
×
4823
    return this->set_member_id( objmember->id, value, copy );
×
4824
  return BObjectRef( UninitObject::create() );
×
4825
}
4826

4827
BObjectRef EClientRefObjImp::set_member_id( const int id, BObjectImp* value, bool /*copy*/ )
2✔
4828
{
4829
  if ( !obj_.exists() || !obj_->isConnected() )
2✔
4830
    return BObjectRef( new BError( "Client not ready or disconnected" ) );
×
4831

4832
  BObjectImp* result = nullptr;
2✔
4833
  if ( auto* v = impptrIf<BLong>( value ) )
2✔
4834
    result = obj_->set_script_member_id( id, v->value() );
2✔
4835

4836
  if ( result != nullptr )
2✔
4837
    return BObjectRef( result );
2✔
4838

4839
  return BObjectRef( UninitObject::create() );
×
4840
}
4841

4842

4843
BObjectImp* EClientRefObjImp::call_polmethod( const char* methodname, Core::UOExecutor& ex )
×
4844
{
4845
  if ( !obj_.exists() || !obj_->isConnected() )
×
4846
    return new BError( "Client not ready or disconnected" );
×
4847
  bool forcebuiltin{ Executor::builtinMethodForced( methodname ) };
×
4848
  ObjMethod* objmethod = getKnownObjMethod( methodname );
×
4849
  if ( objmethod != nullptr )
×
4850
    return this->call_polmethod_id( objmethod->id, ex, forcebuiltin );
×
4851
  return Core::gamestate.system_hooks.call_script_method( methodname, &ex, this );
×
4852
}
4853

4854
BObjectImp* EClientRefObjImp::call_polmethod_id( const int id, Core::UOExecutor& ex,
×
4855
                                                 bool forcebuiltin )
4856
{
4857
  if ( !obj_.exists() || !obj_->isConnected() )
×
4858
    return new BError( "Client not ready or disconnected" );
×
4859

4860
  ObjMethod* mth = getObjMethod( id );
×
4861
  if ( mth->overridden && !forcebuiltin )
×
4862
  {
4863
    auto* imp = Core::gamestate.system_hooks.call_script_method( mth->code, &ex, this );
×
4864
    if ( imp )
×
4865
      return imp;
×
4866
  }
4867
  switch ( id )
×
4868
  {
4869
  case MTH_COMPAREVERSION:
×
4870
  {
4871
    if ( !ex.hasParams( 1 ) )
×
4872
      return new BError( "Not enough parameters" );
×
4873
    const String* pstr;
4874
    if ( ex.getStringParam( 0, pstr ) )
×
4875
      return new BLong( obj_->compareVersion( pstr->getStringRep() ) ? 1 : 0 );
×
4876
    return new BError( "Invalid parameter type" );
×
4877
  }
4878
  }
4879

4880
  return base::call_polmethod_id( id, ex );
×
4881
}
4882

4883
BoatMovementEvent::BoatMovementEvent( Mobile::Character* source, const u8 speed, const u8 direction,
3✔
4884
                                      const u8 relative_direction )
3✔
4885
{
4886
  addMember( "type", new BLong( Core::EVID_BOAT_MOVEMENT ) );
3✔
4887
  addMember( "source", new Module::EOfflineCharacterRefObjImp( source ) );
3✔
4888
  addMember( "speed", new BLong( static_cast<int>( speed ) ) );
3✔
4889
  addMember( "direction", new BLong( static_cast<int>( direction ) ) );
3✔
4890
  addMember( "relative_direction", new BLong( static_cast<int>( relative_direction ) ) );
3✔
4891
}
3✔
4892

4893
SourcedEvent::SourcedEvent( Core::EVENTID type, Mobile::Character* source )
20✔
4894
{
4895
  addMember( "type", new BLong( type ) );
20✔
4896
  addMember( "source", new Module::EOfflineCharacterRefObjImp( source ) );
20✔
4897
}
20✔
4898

4899
SpeechEvent::SpeechEvent( Mobile::Character* speaker, const std::string& speech,
3✔
4900
                          const std::string& texttype, std::string lang,
4901
                          Bscript::ObjArray* speechtokens )
3✔
4902
{
4903
  addMember( "type", new BLong( Core::EVID_SPOKE ) );
3✔
4904
  addMember( "source", new Module::EOfflineCharacterRefObjImp( speaker ) );
3✔
4905
  addMember( "text", new String( speech ) );
3✔
4906
  addMember( "texttype", new String( texttype ) );
3✔
4907
  if ( !lang.empty() )
3✔
4908
    addMember( "langcode", new String( lang ) );
3✔
4909
  if ( speechtokens != nullptr )
3✔
4910
    addMember( "tokens", new Bscript::ObjArray( *speechtokens ) );
3✔
4911
}
3✔
4912

4913
DamageEvent::DamageEvent( Mobile::Character* source, unsigned short damage )
×
4914
{
4915
  addMember( "type", new BLong( Core::EVID_DAMAGED ) );
×
4916

4917
  if ( source != nullptr )
×
4918
    addMember( "source", new Module::EOfflineCharacterRefObjImp( source ) );
×
4919
  else
4920
    addMember( "source", new BLong( 0 ) );
×
4921

4922
  addMember( "damage", new BLong( damage ) );
×
4923
}
×
4924

4925
ItemGivenEvent::ItemGivenEvent( Mobile::Character* chr_givenby, Items::Item* item_given,
×
4926
                                Mobile::NPC* chr_givento )
×
4927
    : SourcedEvent( Core::EVID_ITEM_GIVEN, chr_givenby ), given_by_( nullptr )
×
4928
{
4929
  addMember( "item", new EItemRefObjImp( item_given ) );
×
4930

4931
  given_time_ = Core::read_gameclock();
×
4932
  item_.set( item_given );
×
4933
  cont_.set( item_given->container );
×
4934
  given_by_.set( chr_givenby );
×
4935

4936
  item_given->setprop( "GivenBy", BLong::pack( chr_givenby->serial ) );
×
4937
  item_given->setprop( "GivenTo", BLong::pack( chr_givento->serial ) );
×
4938
  item_given->setprop( "GivenTime", BLong::pack( given_time_ ) );
×
4939
}
×
4940

4941
ItemGivenEvent::~ItemGivenEvent()
×
4942
{
4943
  /* See if the item is still in the container it was in
4944
       This means the AI script didn't do anything with it.
4945
       */
4946
  Items::Item* item = item_.get();
×
4947
  Core::UContainer* cont = cont_.get();
×
4948
  Mobile::Character* chr = given_by_.get();
×
4949

4950
  std::string given_time_str;
×
4951
  if ( !item->getprop( "GivenTime", given_time_str ) )
×
4952
    given_time_str = "";
×
4953

4954
  item->eraseprop( "GivenBy" );
×
4955
  item->eraseprop( "GivenTo" );
×
4956
  item->eraseprop( "GivenTime" );
×
4957

4958
  Bscript::BObject given_value( BObjectImp::unpack( given_time_str.c_str() ) );
×
4959
  int gts = given_value.impptr<BLong>()->value();
×
4960

4961
  if ( item->orphan() || cont->orphan() || chr->orphan() )
×
4962
    return;
×
4963

4964
  if ( item->container == cont && Clib::tostring( given_time_ ) == Clib::tostring( gts ) )
×
4965
  {
4966
    Core::UContainer* backpack = chr->backpack();
×
4967
    if ( backpack != nullptr && !chr->dead() )
×
4968
    {
4969
      if ( backpack->can_add( *item ) )
×
4970
      {
4971
        cont->remove( item );
×
4972
        u8 newSlot = 1;
×
4973
        if ( !backpack->can_add_to_slot( newSlot ) || !item->slot_index( newSlot ) )
×
4974
        {
4975
          item->setposition( chr->pos() );
×
4976
          add_item_to_world( item );
×
4977
          register_with_supporting_multi( item );
×
4978
          move_item( item, item->pos() );
×
4979
          return;
×
4980
        }
4981
        backpack->add( item );
×
4982
        update_item_to_inrange( item );
×
4983
        return;
×
4984
      }
4985
    }
4986
    cont->remove( item );
×
4987
    item->setposition( chr->pos() );
×
4988
    add_item_to_world( item );
×
4989
    register_with_supporting_multi( item );
×
4990
    move_item( item, item->pos() );
×
4991
  }
4992
}
×
4993
}  // namespace Module
4994

4995
namespace Network
4996
{
4997
using namespace Bscript;
4998
BObjectImp* Client::set_script_member_id( const int id, int value )
2✔
4999
{
5000
  switch ( id )
2✔
5001
  {
5002
  case MBR_DISABLE_INACTIVITY_TIMEOUT:
×
5003
    disable_inactivity_timeout( value );
×
5004
    return new BLong( disable_inactivity_timeout() );
×
5005
  case MBR_VISUAL_RANGE:
2✔
5006
    set_update_range_by_script( Clib::clamp_convert<u8>( value ) );
2✔
5007
    return new BLong( update_range() );
2✔
5008
  default:
×
5009
    return nullptr;
×
5010
  }
5011
}
5012

5013
BObjectImp* Client::get_script_member_id( const int id )
5✔
5014
{
5015
  switch ( id )
5✔
5016
  {
5017
  case MBR_ACCTNAME:
2✔
5018
    if ( acct != nullptr )
2✔
5019
      return new String( acct->name() );
2✔
5020
    return new BError( "Not attached to an account" );
×
5021
    break;
5022
  case MBR_ACCT:
2✔
5023
    if ( acct != nullptr )
2✔
5024
      return new Accounts::AccountObjImp( Accounts::AccountPtrHolder( Core::AccountRef( acct ) ) );
2✔
5025
    return new BError( "Not attached to an account" );
×
5026
    break;
5027
  case MBR_IP:
×
5028
    return new String( ipaddrAsString() );
×
5029
    break;
5030
  case MBR_CLIENTVERSION:
×
5031
    return new String( getversion() );
×
5032
    break;
5033
  case MBR_CLIENTVERSIONDETAIL:
×
5034
  {
5035
    std::unique_ptr<BStruct> info( new BStruct );
×
5036
    Network::VersionDetailStruct version = getversiondetail();
×
5037
    info->addMember( "major", new BLong( version.major ) );
×
5038
    info->addMember( "minor", new BLong( version.minor ) );
×
5039
    info->addMember( "rev", new BLong( version.rev ) );
×
5040
    info->addMember( "patch", new BLong( version.patch ) );
×
5041
    return info.release();
×
5042
  }
×
5043
  break;
5044
  case MBR_CLIENTINFO:
×
5045
    return getclientinfo();
×
5046
    break;
5047
  case MBR_CLIENTTYPE:
×
5048
    return new BLong( ClientType );
×
5049
    break;
5050
  case MBR_UO_EXPANSION_CLIENT:
×
5051
    return new BLong( UOExpansionFlagClient );
×
5052
    break;
5053
  case MBR_LAST_ACTIVITY_AT:
×
5054
    return new BLong( static_cast<s32>( last_activity_at() ) );
×
5055
    break;
5056
  case MBR_LAST_PACKET_AT:
×
5057
    return new BLong( static_cast<s32>( last_packet_at() ) );
×
5058
    break;
5059
  case MBR_PORT:
×
5060
    return new BLong( listen_port );
×
5061
    break;
5062
  case MBR_DISABLE_INACTIVITY_TIMEOUT:
×
5063
    return new BLong( disable_inactivity_timeout() );
×
5064
    break;
5065
  case MBR_VISUAL_RANGE:
×
5066
    return new BLong( update_range() );
×
5067
    break;
5068
  }
5069

5070
  return nullptr;
1✔
5071
}
5072

5073
}  // namespace Network
5074

5075
namespace Core
5076
{
5077
bool UObject::script_isa( unsigned isatype ) const
6,174✔
5078
{
5079
  return ( isatype == POLCLASS_OBJECT );
6,174✔
5080
}
5081

5082
bool ULockable::script_isa( unsigned isatype ) const
89✔
5083
{
5084
  return ( isatype == POLCLASS_LOCKABLE ) || base::script_isa( isatype );
89✔
5085
}
5086

5087
bool UContainer::script_isa( unsigned isatype ) const
121✔
5088
{
5089
  return ( isatype == POLCLASS_CONTAINER ) || base::script_isa( isatype );
121✔
5090
}
5091

5092
bool UCorpse::script_isa( unsigned isatype ) const
51✔
5093
{
5094
  return ( isatype == POLCLASS_CORPSE ) || base::script_isa( isatype );
51✔
5095
}
5096

5097
bool UDoor::script_isa( unsigned isatype ) const
×
5098
{
5099
  return ( isatype == POLCLASS_DOOR ) || base::script_isa( isatype );
×
5100
}
5101

5102
bool Spellbook::script_isa( unsigned isatype ) const
×
5103
{
5104
  return ( isatype == POLCLASS_SPELLBOOK ) || base::script_isa( isatype );
×
5105
}
5106

5107
bool Map::script_isa( unsigned isatype ) const
×
5108
{
5109
  return ( isatype == POLCLASS_MAP ) || base::script_isa( isatype );
×
5110
}
5111
}  // namespace Core
5112

5113
namespace Items
5114
{
5115
bool Item::script_isa( unsigned isatype ) const
6,161✔
5116
{
5117
  return ( isatype == Core::POLCLASS_ITEM ) || base::script_isa( isatype );
6,161✔
5118
}
5119

5120
bool Equipment::script_isa( unsigned isatype ) const
×
5121
{
5122
  return ( isatype == Core::POLCLASS_EQUIPMENT ) || base::script_isa( isatype );
×
5123
}
5124

5125
bool UArmor::script_isa( unsigned isatype ) const
×
5126
{
5127
  return ( isatype == Core::POLCLASS_ARMOR ) || base::script_isa( isatype );
×
5128
}
5129

5130
bool UWeapon::script_isa( unsigned isatype ) const
×
5131
{
5132
  return ( isatype == Core::POLCLASS_WEAPON ) || base::script_isa( isatype );
×
5133
}
5134
}  // namespace Items
5135

5136
namespace Mobile
5137
{
5138
bool Character::script_isa( unsigned isatype ) const
111✔
5139
{
5140
  return ( isatype == Core::POLCLASS_MOBILE ) || base::script_isa( isatype );
111✔
5141
}
5142

5143
bool NPC::script_isa( unsigned isatype ) const
56✔
5144
{
5145
  return ( isatype == Core::POLCLASS_NPC ) || base::script_isa( isatype );
56✔
5146
}
5147
}  // namespace Mobile
5148
namespace Multi
5149
{
5150
bool UMulti::script_isa( unsigned isatype ) const
3✔
5151
{
5152
  return ( isatype == Core::POLCLASS_MULTI ) || base::script_isa( isatype );
3✔
5153
}
5154

5155
bool UMulti::setgraphic( u16 /* newobjtype */ )
×
5156
{
5157
  return false;
×
5158
}
5159

5160
bool UBoat::script_isa( unsigned isatype ) const
9✔
5161
{
5162
  return ( isatype == Core::POLCLASS_BOAT ) || base::script_isa( isatype );
9✔
5163
}
5164

5165
bool UHouse::script_isa( unsigned isatype ) const
×
5166
{
5167
  return ( isatype == Core::POLCLASS_HOUSE ) || base::script_isa( isatype );
×
5168
}
5169
}  // namespace Multi
5170
}  // namespace Pol
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc