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

polserver / polserver / 25853153562

14 May 2026 09:41AM UTC coverage: 60.906%. Remained the same
25853153562

push

github

web-flow
fixed problem when sending vitals bigger then 0xffff to other clients (#877)

* fixed problem when sending vitals bigger then 0xffff to other clients.
The percent value was calculated based on the already capped values

* directly use the correct type

* docs

1 of 24 new or added lines in 1 file covered. (4.17%)

2 existing lines in 2 files now uncovered.

44604 of 73234 relevant lines covered (60.91%)

515568.44 hits per line

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

56.46
/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 "eventid.h"
76
#include "exscrobj.h"
77
#include "fnsearch.h"
78
#include "globals/network.h"
79
#include "globals/uvars.h"
80
#include "item/armor.h"
81
#include "item/equipmnt.h"
82
#include "item/item.h"
83
#include "item/itemdesc.h"
84
#include "item/weapon.h"
85
#include "lockable.h"
86
#include "mobile/charactr.h"
87
#include "mobile/corpse.h"
88
#include "mobile/npc.h"
89
#include "mobile/ufacing.h"
90
#include "module/guildmod.h"
91
#include "module/partymod.h"
92
#include "module/uomod.h"
93
#include "multi/boat.h"
94
#include "multi/boatcomp.h"
95
#include "multi/house.h"
96
#include "multi/multi.h"
97
#include "network/cgdata.h"
98
#include "network/client.h"
99
#include "network/packethelper.h"
100
#include "network/packets.h"
101
#include "network/pktdef.h"
102
#include "npctmpl.h"
103
#include "polclass.h"
104
#include "polclock.h"
105
#include "proplist.h"
106
#include "realms/realm.h"
107
#include "realms/realms.h"
108
#include "spelbook.h"
109
#include "statmsg.h"
110
#include "syshookscript.h"
111
#include "tooltips.h"
112
#include "ufunc.h"
113
#include "umap.h"
114
#include "uobject.h"
115
#include "uoclient.h"
116
#include "uoexec.h"
117
#include "uworld.h"
118

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

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

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

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

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

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

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

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

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

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

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

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

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

237
      return ( chrref_imp->obj_->serial == obj_->serial );
41✔
238
    }
239
    return false;
×
240
  }
241
  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
    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
9✔
268
{
269
  return "OfflineMobileRef";
9✔
270
}
271
u8 EOfflineCharacterRefObjImp::typeOfInt() const
×
272
{
273
  return OTOfflineMobileRef;
×
274
}
275

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

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

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

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

300
BObjectRef EItemRefObjImp::get_member_id( const int id )
552✔
301
{
302
  BObjectImp* result = obj_->get_script_member_id( id );
552✔
303
  if ( result != nullptr )
552✔
304
    return BObjectRef( result );
552✔
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*/ )
47✔
317
{
318
  BObjectImp* result = nullptr;
47✔
319
  if ( auto* l = impptrIf<BLong>( value ) )
47✔
320
    result = obj_->set_script_member_id( id, l->value() );
30✔
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 )
47✔
326
    return BObjectRef( result );
47✔
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,
227✔
339
                                               bool forcebuiltin )
340
{
341
  if ( obj_->orphan() )
227✔
342
    return new BError( "That object no longer exists" );
×
343

344
  ObjMethod* mth = getObjMethod( id );
227✔
345
  if ( mth->overridden && !forcebuiltin )
227✔
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 );
227✔
352
  if ( imp != nullptr )
227✔
353
    return imp;
227✔
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
242✔
372
{
373
  return ( !obj_->orphan() );
242✔
374
}
375

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

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

388
      return ( itemref_imp->obj_->serial == obj_->serial );
35✔
389
    }
390
    return false;
×
391
  }
392
  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
12✔
418
{
419
  return "BoatRef";
12✔
420
}
421
u8 EUBoatRefObjImp::typeOfInt() const
×
422
{
423
  return OTBoatRef;
×
424
}
425

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

431
BObjectRef EUBoatRefObjImp::get_member_id( const int id )
6,157✔
432
{
433
  BObjectImp* result = obj_->get_script_member_id( id );
6,157✔
434
  if ( result != nullptr )
6,157✔
435
    return BObjectRef( result );
6,157✔
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,
43✔
470
                                                bool forcebuiltin )
471
{
472
  if ( obj_->orphan() )
43✔
473
    return new BError( "That object no longer exists" );
×
474

475
  ObjMethod* mth = getObjMethod( id );
43✔
476
  if ( mth->overridden && !forcebuiltin )
43✔
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 );
43✔
483
  if ( imp != nullptr )
43✔
484
    return imp;
43✔
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
117✔
504
{
505
  return ( !obj_->orphan() );
117✔
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
  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
  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,781✔
646
{
647
  if ( orphan() )
7,781✔
648
    return new UninitObject;
20✔
649
  switch ( id )
7,761✔
650
  {
651
  case MBR_X:
185✔
652
    return new BLong( x() );
185✔
653
    break;
654
  case MBR_Y:
173✔
655
    return new BLong( y() );
173✔
656
    break;
657
  case MBR_Z:
154✔
658
    return new BLong( z() );
154✔
659
    break;
660
  case MBR_NAME:
45✔
661
    return new String( name() );
45✔
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:
546✔
670
    return new BLong( serial );
546✔
671
    break;
672
  case MBR_COLOR:
1✔
673
    return new BLong( color );
1✔
674
    break;
675
  case MBR_HEIGHT:
22✔
676
    return new BLong( height );
22✔
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
      return new BLong( 0 );
4✔
694
    }
695
    else
696
      return new BLong( 0 );
×
697
    break;
698
  case MBR_REALM:
6,056✔
699
    if ( realm() != nullptr )
6,056✔
700
      return new String( realm()->name() );
6,056✔
701
    else
702
      return new BError( "object does not belong to a realm." );
×
703
    break;
704
  case MBR_SPECIFIC_NAME:
×
705
    return new BLong( specific_name() );
×
706
  default:
518✔
707
    return nullptr;
518✔
708
  }
709
}
710

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

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

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

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

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

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

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

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

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

792
namespace Items
793
{
794
using namespace Bscript;
795

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

1628
    increv_send_object_recursive();
5✔
1629

1630
    UpdateCharacterWeight( this );
5✔
1631
    return new Double( weight_multiplier_mod() );
5✔
1632
    break;
1633
  }
1634
  default:
13✔
1635
    return nullptr;
13✔
1636
  }
1637
}
1638

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

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

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

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

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

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

1700

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

1835
      UpdateCharacterWeight( existing_stack );
×
1836

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

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

1845
      return new Module::EItemRefObjImp( existing_stack );
×
1846
    }
1847
    return create_new_stack();
×
1848

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

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

1864
    Core::UContainer* stackcontainer = static_cast<Core::UContainer*>( cont );
×
1865

1866
    Item* existing_stack = stackcontainer->find_addable_stack( this );
×
1867

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

1872
    break;
1873
  }
1874
  default:
32✔
1875
    return nullptr;
32✔
1876
  }
1877
}
1878

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

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

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

1907
BObject Item::call_custom_method( const char* methodname, BObjectImpRefVec& pmore )
×
1908
{
1909
  // no systemhook needed used for openbook uo module function
1910
  const ItemDesc& id = itemdesc();
×
1911
  if ( id.method_script != nullptr )
×
1912
  {
1913
    unsigned PC;
1914
    if ( id.method_script->FindExportedFunction(
×
1915
             methodname, static_cast<unsigned int>( pmore.size() + 1 ), PC ) )
×
1916
      return id.method_script->call( PC, new Module::EItemRefObjImp( this ), pmore );
×
1917

1918
    std::string message;
×
1919
    message = "Method script for objtype " + id.objtype_description() +
×
1920
              " does not export function " + std::string( methodname ) + " taking " +
×
1921
              Clib::tostring( pmore.size() + 1 ) + " parameters";
×
1922
    BError* err = new BError( message );
×
1923
    return BObject( err );
×
1924
  }
×
1925
  return BObject( new BError( "No method script defined for " + id.objtype_description() ) );
×
1926
}
1927

1928
BObjectImp* Item::make_ref()
167✔
1929
{
1930
  return new Module::EItemRefObjImp( this );
167✔
1931
}
1932
}  // namespace Items
1933
namespace Mobile
1934
{
1935
using namespace Bscript;
1936

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

1950
BObjectImp* Character::make_ref()
17✔
1951
{
1952
  return new Module::ECharacterRefObjImp( this );
17✔
1953
}
1954
BObjectImp* Character::make_offline_ref()
×
1955
{
1956
  return new Module::EOfflineCharacterRefObjImp( this );
×
1957
}
1958

1959
BObjectImp* Character::get_script_member_id( const int id ) const
916✔
1960
{
1961
  BObjectImp* imp = base::get_script_member_id( id );
916✔
1962
  if ( imp != nullptr )
916✔
1963
    return imp;
622✔
1964

1965

1966
  auto EnforceCaps = []( s16 baseValue, const s16 capValue ) -> s16
36✔
1967
  {
1968
    const bool ignore_caps = Core::settingsManager.ssopt.core_ignores_defence_caps;
36✔
1969

1970

1971
    if ( !ignore_caps )
36✔
1972
      baseValue = std::min( baseValue, capValue );
36✔
1973

1974
    return baseValue;
36✔
1975
  };
1976

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

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

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

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

2153
  case MBR_CLIENTINFO:
×
2154
    if ( client != nullptr )
×
2155
      return client->getclientinfo();
×
2156
    return new BLong( 0 );
×
2157
    break;
2158

2159
  case MBR_CREATEDAT:
×
2160
    return new BLong( created_at );
×
2161
    break;
2162

2163
  case MBR_REPORTABLES:
2✔
2164
    return GetReportables();
2✔
2165
    break;
2166

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

2424
  case MBR_AGGRESSORTO:
×
2425
    return GetAggressorTo();
×
2426
    break;
2427
  case MBR_LAWFULLYDAMAGED:
×
2428
    return GetLawFullyDamaged();
×
2429
    break;
2430

2431
  case MBR_UO_EXPANSION_CLIENT:
×
2432
    return new BLong( client != nullptr ? client->UOExpansionFlagClient : 0 );
×
2433
    break;
2434

2435
  case MBR_DEAFENED:
1✔
2436
    return new BLong( deafened() ? 1 : 0 );
1✔
2437
    break;
2438

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

3465

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

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

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

3492
  for ( auto rt : reportable_ )
4✔
3493
  {
3494
    std::unique_ptr<BObjectImp> kmember( nullptr );
2✔
3495
    Character* killer = Core::system_find_mobile( rt.serial );
2✔
3496
    if ( killer )
2✔
3497
      kmember = std::make_unique<Module::EOfflineCharacterRefObjImp>( killer );
2✔
3498
    else
3499
      kmember = std::make_unique<BError>( "Mobile not found" );
×
3500

3501
    std::unique_ptr<BStruct> elem( new BStruct );
2✔
3502
    elem->addMember( "serial", new BLong( rt.serial ) );
2✔
3503
    elem->addMember( "killer", kmember.release() );
2✔
3504
    elem->addMember( "gameclock", new BLong( static_cast<s32>( rt.polclock ) ) );
2✔
3505

3506
    arr->addElement( elem.release() );
2✔
3507
  }
2✔
3508
  return arr.release();
4✔
3509
}
2✔
3510

3511
ObjArray* Character::GetAggressorTo() const
×
3512
{
3513
  std::unique_ptr<ObjArray> arr( new ObjArray );
×
3514

3515
  for ( const auto& itr : aggressor_to_ )
×
3516
  {
3517
    std::unique_ptr<BObjectImp> member( nullptr );
×
3518
    Character* chr = Core::system_find_mobile( itr.first->serial );
×
3519
    if ( chr )
×
3520
      member = std::make_unique<Module::EOfflineCharacterRefObjImp>( chr );
×
3521
    else
3522
      member = std::make_unique<BError>( "Mobile not found" );
×
3523

3524
    std::unique_ptr<BStruct> elem( new BStruct );
×
3525
    elem->addMember( "serial", new BLong( itr.first->serial ) );
×
3526
    elem->addMember( "ref", member.release() );
×
3527
    elem->addMember( "seconds", new BLong( static_cast<s32>( ( itr.second - Core::polclock() ) /
×
3528
                                                             Core::POLCLOCKS_PER_SEC ) ) );
×
3529

3530
    arr->addElement( elem.release() );
×
3531
  }
×
3532
  return arr.release();
×
3533
}
×
3534

3535
ObjArray* Character::GetLawFullyDamaged() const
×
3536
{
3537
  std::unique_ptr<ObjArray> arr( new ObjArray );
×
3538

3539
  for ( const auto& itr : lawfully_damaged_ )
×
3540
  {
3541
    std::unique_ptr<BObjectImp> member( nullptr );
×
3542
    Character* chr = Core::system_find_mobile( itr.first->serial );
×
3543
    if ( chr )
×
3544
      member = std::make_unique<Module::EOfflineCharacterRefObjImp>( chr );
×
3545
    else
3546
      member = std::make_unique<BError>( "Mobile not found" );
×
3547

3548
    std::unique_ptr<BStruct> elem( new BStruct );
×
3549
    elem->addMember( "serial", new BLong( itr.first->serial ) );
×
3550
    elem->addMember( "ref", member.release() );
×
3551
    elem->addMember( "seconds", new BLong( static_cast<s32>( ( itr.second - Core::polclock() ) /
×
3552
                                                             Core::POLCLOCKS_PER_SEC ) ) );
×
3553

3554
    arr->addElement( elem.release() );
×
3555
  }
×
3556
  return arr.release();
×
3557
}
×
3558

3559
BObjectImp* NPC::get_script_member_id( const int id ) const
488✔
3560
{
3561
  BObjectImp* imp = base::get_script_member_id( id );
488✔
3562
  if ( imp != nullptr )
488✔
3563
    return imp;
428✔
3564

3565
  switch ( id )
60✔
3566
  {
3567
  case MBR_SCRIPT:
1✔
3568
    return new String( script );
1✔
3569
    break;
3570
  case MBR_NPCTEMPLATE:
×
3571
    return new String( template_name );
×
3572
    break;
3573
  case MBR_MASTER:
1✔
3574
  {
3575
    Character* master = master_.get();
1✔
3576
    if ( master != nullptr && !master->orphan() )
1✔
3577
      return new Module::EOfflineCharacterRefObjImp( master );
1✔
3578
    return new BLong( 0 );
×
3579
    break;
3580
  }
3581

3582
  case MBR_PROCESS:
52✔
3583
    if ( ex )
52✔
3584
      return new Core::ScriptExObjImp( ex );
52✔
3585
    return new BError( "No script running" );
×
3586
    break;
3587

3588
  case MBR_EVENTMASK:
×
3589
    if ( ex )
×
3590
      return new BLong( ex->eventmask );
×
3591
    return new BError( "No script running" );
×
3592
    break;
3593

3594
  case MBR_SPEECH_COLOR:
1✔
3595
    return new BLong( speech_color() );
1✔
3596
    break;
3597
  case MBR_SPEECH_FONT:
1✔
3598
    return new BLong( speech_font() );
1✔
3599
    break;
3600
  case MBR_USE_ADJUSTMENTS:
1✔
3601
    return new BLong( use_adjustments() ? 1 : 0 );
1✔
3602
    break;
3603
  case MBR_RUN_SPEED:
1✔
3604
    return new BLong( run_speed );
1✔
3605
    break;
3606
  case MBR_ALIGNMENT:
×
3607
    return new BLong( template_->alignment );
×
3608
    break;
3609
  case MBR_SAVEONEXIT:
×
3610
    return new BLong( saveonexit() );
×
3611
    break;
3612
  case MBR_NO_DROP_EXCEPTION:
2✔
3613
    return new BLong( no_drop_exception() );
2✔
3614
  default:
×
3615
    return nullptr;
×
3616
  }
3617
}
3618

3619
BObjectImp* NPC::get_script_member( const char* membername ) const
62✔
3620
{
3621
  ObjMember* objmember = getKnownObjMember( membername );
62✔
3622
  if ( objmember != nullptr )
62✔
3623
    return this->get_script_member_id( objmember->id );
62✔
3624
  return nullptr;
×
3625
}
3626

3627
BObjectImp* NPC::set_script_member_id( const int id, const std::string& value )
×
3628
{
3629
  BObjectImp* imp = base::set_script_member_id( id, value );
×
3630
  if ( imp != nullptr )
×
3631
    return imp;
×
3632
  switch ( id )
×
3633
  {
3634
  case MBR_SCRIPT:
×
3635
    return new String( script = value );
×
3636
  default:
×
3637
    return nullptr;
×
3638
  }
3639
}
3640

3641
BObjectImp* NPC::set_script_member( const char* membername, const std::string& value )
×
3642
{
3643
  ObjMember* objmember = getKnownObjMember( membername );
×
3644
  if ( objmember != nullptr )
×
3645
    return this->set_script_member_id( objmember->id, value );
×
3646
  return nullptr;
×
3647
}
3648

3649
BObjectImp* NPC::set_script_member_id( const int id, int value )
30✔
3650
{
3651
  BObjectImp* imp = base::set_script_member_id( id, value );
30✔
3652
  if ( imp != nullptr )
30✔
3653
    return imp;
23✔
3654
  switch ( id )
7✔
3655
  {
3656
  case MBR_SPEECH_COLOR:
×
3657
    speech_color( Clib::clamp_convert<u16>( value ) );
×
3658
    return new BLong( speech_color() );
×
3659
  case MBR_SPEECH_FONT:
×
3660
    speech_font( Clib::clamp_convert<u16>( value ) );
×
3661
    return new BLong( speech_font() );
×
3662
  case MBR_USE_ADJUSTMENTS:
×
3663
    use_adjustments( value ? true : false );
×
3664
    return new BLong( use_adjustments() );
×
3665
  case MBR_RUN_SPEED:
×
3666
    return new BLong( run_speed = Clib::clamp_convert<u16>( value ) );
×
3667
  case MBR_SAVEONEXIT:
1✔
3668
    saveonexit( value ? true : false );
1✔
3669
    return new BLong( saveonexit() );
1✔
3670
  case MBR_NO_DROP_EXCEPTION:
×
3671
    no_drop_exception( value ? true : false );
×
3672
    return new BLong( no_drop_exception() );
×
3673
  default:
6✔
3674
    return nullptr;
6✔
3675
  }
3676
}
3677
BObjectImp* NPC::set_script_member( const char* membername, int value )
×
3678
{
3679
  ObjMember* objmember = getKnownObjMember( membername );
×
3680
  if ( objmember != nullptr )
×
3681
    return this->set_script_member_id( objmember->id, value );
×
3682
  return nullptr;
×
3683
}
3684

3685
BObjectImp* NPC::script_method_id( const int id, Core::UOExecutor& executor )
186✔
3686
{
3687
  BObjectImp* imp = base::script_method_id( id, executor );
186✔
3688
  if ( imp != nullptr )
186✔
3689
    return imp;
175✔
3690

3691
  switch ( id )
11✔
3692
  {
3693
  case MTH_SETMASTER:
11✔
3694
  {
3695
    if ( executor.numParams() != 1 )
11✔
3696
      return new BError( "Not enough parameters" );
×
3697
    Character* chr;
3698
    set_dirty();
11✔
3699
    if ( executor.getCharacterParam( 0, chr ) )
11✔
3700
    {
3701
      master_.set( chr );
11✔
3702
      return new BLong( 1 );
11✔
3703
    }
3704

3705
    master_.clear();
×
3706
    return new BLong( 0 );
×
3707

3708
    break;
3709
  }
3710
  default:
×
3711
    return nullptr;
×
3712
  }
3713
}
3714

3715
BObjectImp* NPC::script_method( const char* methodname, Core::UOExecutor& executor )
×
3716
{
3717
  ObjMethod* objmethod = getKnownObjMethod( methodname );
×
3718
  if ( objmethod != nullptr )
×
3719
    return this->script_method_id( objmethod->id, executor );
×
3720
  return nullptr;
×
3721
}
3722

3723
BObjectImp* NPC::custom_script_method( const char* methodname, Core::UOExecutor& executor )
×
3724
{
3725
  if ( template_->method_script != nullptr )
×
3726
  {
3727
    unsigned PC;
3728
    if ( template_->method_script->FindExportedFunction(
×
3729
             methodname, static_cast<unsigned int>( executor.numParams() + 1 ), PC ) )
×
3730
      return template_->method_script->call( PC, make_ref(), executor.fparams );
×
3731
  }
3732
  return Core::gamestate.system_hooks.call_script_method( methodname, &executor, this );
×
3733
}
3734
}  // namespace Mobile
3735
namespace Core
3736
{
3737
using namespace Bscript;
3738

3739
BObjectImp* ULockable::get_script_member_id( const int id ) const
254✔
3740
{
3741
  BObjectImp* imp = Item::get_script_member_id( id );
254✔
3742
  if ( imp != nullptr )
254✔
3743
    return imp;
201✔
3744

3745
  switch ( id )
53✔
3746
  {
3747
  case MBR_LOCKED:
1✔
3748
    return new BLong( locked() ? 1 : 0 );
1✔
3749
    break;
3750
  default:
52✔
3751
    return nullptr;
52✔
3752
  }
3753
}
3754

3755
BObjectImp* ULockable::get_script_member( const char* membername ) const
×
3756
{
3757
  ObjMember* objmember = getKnownObjMember( membername );
×
3758
  if ( objmember != nullptr )
×
3759
    return this->get_script_member_id( objmember->id );
×
3760
  return nullptr;
×
3761
}
3762

3763
BObjectImp* ULockable::set_script_member_id( const int id, int value )
61✔
3764
{
3765
  BObjectImp* imp = Item::set_script_member_id( id, value );
61✔
3766
  if ( imp != nullptr )
61✔
3767
    return imp;
48✔
3768
  switch ( id )
13✔
3769
  {
3770
  case MBR_LOCKED:
1✔
3771
    locked( value ? true : false );
1✔
3772
    return new BLong( locked() );
1✔
3773
  default:
12✔
3774
    return nullptr;
12✔
3775
  }
3776
}
3777

3778
BObjectImp* ULockable::set_script_member( const char* membername, int value )
×
3779
{
3780
  ObjMember* objmember = getKnownObjMember( membername );
×
3781
  if ( objmember != nullptr )
×
3782
    return this->set_script_member_id( objmember->id, value );
×
3783
  return nullptr;
×
3784
}
3785

3786
BObjectImp* UContainer::get_script_member_id( const int id ) const
228✔
3787
{
3788
  BObjectImp* imp = base::get_script_member_id( id );
228✔
3789
  if ( imp != nullptr )
228✔
3790
    return imp;
176✔
3791

3792
  switch ( id )
52✔
3793
  {
3794
  case MBR_MAX_ITEMS_MOD:
1✔
3795
    return new BLong( max_items_mod() );
1✔
3796
    break;
3797
  case MBR_MAX_WEIGHT_MOD:
1✔
3798
    return new BLong( max_weight_mod() );
1✔
3799
    break;
3800
  case MBR_MAX_SLOTS_MOD:
1✔
3801
    return new BLong( max_slots_mod() );
1✔
3802
    break;
3803
  case MBR_NO_DROP_EXCEPTION:
2✔
3804
    return new BLong( no_drop_exception() );
2✔
3805
  case MBR_HELD_WEIGHT_MULTIPLIER:
8✔
3806
    return new Double( held_weight_multiplier() );
8✔
3807
  default:
39✔
3808
    return nullptr;
39✔
3809
  }
3810
}
3811

3812
BObjectImp* UContainer::get_script_member( const char* membername ) const
6✔
3813
{
3814
  ObjMember* objmember = getKnownObjMember( membername );
6✔
3815
  if ( objmember != nullptr )
6✔
3816
    return this->get_script_member_id( objmember->id );
6✔
3817
  return nullptr;
×
3818
}
3819

3820
BObjectImp* UContainer::set_script_member_id( const int id, int value )
61✔
3821
{
3822
  BObjectImp* imp = base::set_script_member_id( id, value );
61✔
3823
  if ( imp != nullptr )
61✔
3824
    return imp;
49✔
3825
  switch ( id )
12✔
3826
  {
3827
  case MBR_MAX_ITEMS_MOD:
1✔
3828
    max_items_mod( Clib::clamp_convert<s16>( value ) );
1✔
3829
    break;
1✔
3830
  case MBR_MAX_WEIGHT_MOD:
1✔
3831
    max_weight_mod( Clib::clamp_convert<s16>( value ) );
1✔
3832
    break;
1✔
3833
  case MBR_MAX_SLOTS_MOD:
1✔
3834
    max_slots_mod( Clib::clamp_convert<s8>( value ) );
1✔
3835
    break;
1✔
3836
  case MBR_NO_DROP_EXCEPTION:
2✔
3837
    no_drop_exception( value ? true : false );
2✔
3838
    return new BLong( no_drop_exception() );
2✔
3839
  case MBR_WEIGHT_MULTIPLIER_MOD:
×
3840
    return set_script_member_id_double( id, value );
×
3841
  case MBR_HELD_WEIGHT_MULTIPLIER:
7✔
3842
    return set_script_member_id_double( id, value );
7✔
3843
  default:
×
3844
    return nullptr;
×
3845
  }
3846
  return new BLong( value );
3✔
3847
}
3848

3849
Bscript::BObjectImp* UContainer::set_script_member_id_double( const int id, double value )
13✔
3850
{
3851
  BObjectImp* imp = base::set_script_member_id_double( id, value );
13✔
3852
  if ( imp != nullptr )
13✔
3853
    return imp;
×
3854

3855
  switch ( id )
13✔
3856
  {
3857
  case MBR_HELD_WEIGHT_MULTIPLIER:
13✔
3858
  {
3859
    if ( container )
13✔
3860
    {
3861
      int oldweight = weight();
8✔
3862
      held_weight_multiplier( value );
8✔
3863
      container->add_bulk( 0, weight() - oldweight );
8✔
3864
    }
3865
    else
3866
    {
3867
      held_weight_multiplier( value );
5✔
3868
    }
3869

3870
    increv_send_object_recursive();
13✔
3871

3872
    UpdateCharacterWeight( this );
13✔
3873

3874
    return new Double( held_weight_multiplier() );
13✔
3875
  }
3876
  default:
×
3877
    break;
×
3878
  }
3879
  return nullptr;
×
3880
}
3881

3882
BObjectImp* UContainer::set_script_member( const char* membername, int value )
53✔
3883
{
3884
  ObjMember* objmember = getKnownObjMember( membername );
53✔
3885
  if ( objmember != nullptr )
53✔
3886
    return this->set_script_member_id( objmember->id, value );
53✔
3887
  return nullptr;
×
3888
}
3889

3890
BObjectImp* UCorpse::get_script_member_id( const int id ) const
46✔
3891
{
3892
  BObjectImp* imp = base::get_script_member_id( id );
46✔
3893
  if ( imp != nullptr )
46✔
3894
    return imp;
7✔
3895

3896
  switch ( id )
39✔
3897
  {
3898
  case MBR_CORPSETYPE:
1✔
3899
    return new BLong( corpsetype );
1✔
3900
    break;
3901
  case MBR_OWNERSERIAL:
38✔
3902
    return new BLong( ownerserial );
38✔
3903
    break;
3904
  default:
×
3905
    return nullptr;
×
3906
  }
3907
}
3908

3909
BObjectImp* UCorpse::get_script_member( const char* membername ) const
2✔
3910
{
3911
  ObjMember* objmember = getKnownObjMember( membername );
2✔
3912
  if ( objmember != nullptr )
2✔
3913
    return this->get_script_member_id( objmember->id );
2✔
3914
  return nullptr;
×
3915
}
3916

3917
BObjectImp* Spellbook::script_method_id( const int id, Core::UOExecutor& ex )
4✔
3918
{
3919
  BObjectImp* imp = base::script_method_id( id, ex );
4✔
3920
  if ( imp != nullptr )
4✔
3921
    return imp;
×
3922

3923
  switch ( id )
4✔
3924
  {
3925
  case MTH_HASSPELL:
2✔
3926
  {
3927
    u32 sid;
3928
    if ( !ex.hasParams( 1 ) )
2✔
3929
      return new BError( "Not enough parameters" );
2✔
3930
    if ( ex.getParam( 0, sid ) )
2✔
3931
    {
3932
      if ( sid == 0 )
2✔
3933
        return new BError( "SpellID must be >= 1" );
×
3934
      if ( this->has_spellid( sid ) )
2✔
3935
        return new BLong( 1 );
2✔
3936
      return new BLong( 0 );
×
3937
    }
3938
    break;
×
3939
  }
3940
  case MTH_SPELLS:
×
3941
  {
3942
    std::unique_ptr<ObjArray> arr( new ObjArray );
×
3943
    for ( u16 i = 0; i < 64; ++i )
×
3944
    {
3945
      unsigned int sid;
3946

3947
      // Check for Mysticism spells here
3948
      if ( this->spell_school == 3 )
×
3949
        sid = 678 + i;
×
3950
      else
3951
        sid = this->spell_school * 100 + i + 1;
×
3952

3953
      if ( this->has_spellid( sid ) )
×
3954
        arr->addElement( new BLong( sid ) );
×
3955
    }
3956
    return arr.release();
×
3957
    break;
3958
  }
×
3959
  case MTH_REMOVESPELL:
×
3960
  {
3961
    u32 sid;
3962
    if ( !ex.hasParams( 1 ) )
×
3963
      return new BError( "Not enough parameters" );
×
3964
    if ( ex.getParam( 0, sid ) )
×
3965
    {
3966
      if ( sid == 0 )
×
3967
        return new BError( "SpellID must be >= 1" );
×
3968
      if ( this->remove_spellid( sid ) )
×
3969
        return new BLong( 1 );
×
3970
      return new BLong( 0 );
×
3971
    }
3972
    break;
×
3973
  }
3974
  case MTH_ADDSPELL:
2✔
3975
  {
3976
    u32 sid;
3977
    if ( !ex.hasParams( 1 ) )
2✔
3978
      return new BError( "Not enough parameters" );
2✔
3979
    if ( ex.getParam( 0, sid ) )
2✔
3980
    {
3981
      if ( sid == 0 )
2✔
3982
        return new BError( "SpellID must be >= 1" );
×
3983
      if ( this->add_spellid( sid ) )
2✔
3984
        return new BLong( 1 );
2✔
3985
      return new BLong( 0 );
×
3986
    }
3987
    break;
×
3988
  }
3989

3990
  default:
×
3991
    return nullptr;
×
3992
  }
3993
  return new BError( "Invalid parameter type" );
×
3994
}
3995

3996
BObjectImp* Spellbook::script_method( const char* methodname, Core::UOExecutor& ex )
×
3997
{
3998
  ObjMethod* objmethod = getKnownObjMethod( methodname );
×
3999
  if ( objmethod != nullptr )
×
4000
    return this->script_method_id( objmethod->id, ex );
×
4001
  return nullptr;
×
4002
}
4003
}  // namespace Core
4004
namespace Multi
4005
{
4006
using namespace Bscript;
4007

4008
BObjectImp* UBoat::make_ref()
5✔
4009
{
4010
  return new Module::EUBoatRefObjImp( this );
5✔
4011
}
4012

4013
BObjectImp* UMulti::make_ref()
23✔
4014
{
4015
  return new Module::EMultiRefObjImp( this );
23✔
4016
}
4017

4018
BObjectImp* UBoat::get_script_member_id( const int id ) const
6,159✔
4019
{
4020
  BObjectImp* imp = base::get_script_member_id( id );
6,159✔
4021
  if ( imp != nullptr )
6,159✔
4022
    return imp;
6,122✔
4023

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

4111
BObjectImp* UBoat::get_script_member( const char* membername ) const
2✔
4112
{
4113
  ObjMember* objmember = getKnownObjMember( membername );
2✔
4114
  if ( objmember != nullptr )
2✔
4115
    return this->get_script_member_id( objmember->id );
2✔
4116
  return nullptr;
×
4117
}
4118

4119
BObjectImp* UBoat::script_method_id( const int id, Core::UOExecutor& ex )
43✔
4120
{
4121
  BObjectImp* imp = base::script_method_id( id, ex );
43✔
4122
  if ( imp != nullptr )
43✔
4123
    return imp;
29✔
4124

4125
  switch ( id )
14✔
4126
  {
4127
  case MTH_MOVE_OFFLINE_MOBILES:
×
4128
  {
4129
    if ( ex.numParams() == 3 )
×
4130
    {
4131
      Core::Pos3d pos;
×
4132
      if ( !ex.getPos3dParam( 0, 1, 2, &pos, realm() ) )
×
4133
        return new BError( "Invalid parameter type" );
×
4134
      set_dirty();
×
4135
      move_offline_mobiles( Core::Pos4d( pos, realm() ) );
×
4136
      return new BLong( 1 );
×
4137
    }
4138
    if ( ex.numParams() == 4 )
×
4139
    {
4140
      Core::Pos4d pos;
×
4141
      if ( !ex.getPos4dParam( 0, 1, 2, 3, &pos ) )
×
4142
        return new BError( "Invalid parameter type" );
×
4143
      set_dirty();
×
4144
      move_offline_mobiles( pos );
×
4145
      return new BLong( 1 );
×
4146
    }
4147
    return new BError( "Not enough parameters" );
×
4148
  }
4149
  case MTH_SET_PILOT:
10✔
4150
  {
4151
    if ( !ex.hasParams( 1 ) )
10✔
4152
    {
4153
      return new BError( "Not enough parameters" );
×
4154
    }
4155

4156
    BObjectImp* impMaybeZero = ex.getParamImp( 0 );
10✔
4157

4158
    if ( auto* value = impptrIf<BLong>( impMaybeZero ) )
10✔
4159
    {
4160
      if ( value->value() != 0 )
6✔
4161
        return new BError( "Invalid parameters" );
×
4162
      return set_pilot( nullptr );
6✔
4163
    }
4164

4165
    Mobile::Character* chr;
4166

4167
    if ( !ex.getCharacterParam( 0, chr ) )
4✔
4168
      return new BError( "Invalid parameters" );
×
4169

4170
    return set_pilot( chr );
4✔
4171
  }
4172
  case MTH_SET_ALTERNATE_MULTIID:
4✔
4173
  {
4174
    if ( ex.numParams() != 1 )
4✔
4175
      return new BError( "Not enough parameters" );
×
4176
    u32 index;
4177
    if ( !ex.getParam( 0, index ) )
4✔
4178
      return new BError( "Invalid parameter type" );
×
4179
    const auto& desc = static_cast<const Items::BoatDesc&>( itemdesc() );
4✔
4180
    if ( index >= desc.alternates.size() )
4✔
4181
      return new BError( "Index out of range" );
1✔
4182

4183
    {
4184
      UBoat::BoatMoveGuard guard( this );
3✔
4185
      u16 new_multiid = desc.alternates[index];
3✔
4186
      u16 base_multi = multiid_ & ~3u;
3✔
4187
      u16 multioffset = multiid_ - base_multi;
3✔
4188
      multiid_ = new_multiid + multioffset;
3✔
4189
    }
3✔
4190
    transform_components( boatshape() );
3✔
4191
    send_display_boat_to_inrange( {} );
3✔
4192
    return new BLong( 1 );
3✔
4193
  }
4194
  default:
×
4195
    return nullptr;
×
4196
  }
4197
}
4198

4199
BObjectImp* UBoat::script_method( const char* methodname, Core::UOExecutor& ex )
×
4200
{
4201
  ObjMethod* objmethod = getKnownObjMethod( methodname );
×
4202
  if ( objmethod != nullptr )
×
4203
    return this->script_method_id( objmethod->id, ex );
×
4204
  return nullptr;
×
4205
}
4206

4207
BObjectImp* UPlank::get_script_member_id( const int id ) const
20✔
4208
{
4209
  switch ( id )
20✔
4210
  {
4211
  case MBR_MULTI:
×
4212
    if ( boat_.get() )
×
4213
      return new Module::EUBoatRefObjImp( boat_.get() );
×
4214
    return new BError( "No boat attached" );
×
4215
    break;
4216
  }
4217
  return base::get_script_member_id( id );
20✔
4218
}
4219

4220
/* UObject defines a 'multi' also, so we have to trap that here first */
4221
BObjectImp* UPlank::get_script_member( const char* membername ) const
×
4222
{
4223
  ObjMember* objmember = getKnownObjMember( membername );
×
4224
  if ( objmember != nullptr )
×
4225
    return this->get_script_member_id( objmember->id );
×
4226
  return base::get_script_member( membername );
×
4227
}
4228
}  // namespace Multi
4229
namespace Core
4230
{
4231
using namespace Bscript;
4232

4233
BObjectImp* Map::get_script_member_id( const int id ) const
9✔
4234
{
4235
  BObjectImp* imp = base::get_script_member_id( id );
9✔
4236
  if ( imp != nullptr )
9✔
4237
    return imp;
1✔
4238

4239
  switch ( id )
8✔
4240
  {
4241
  case MBR_XEAST:
1✔
4242
    return new BLong( xeast );
1✔
4243
  case MBR_XWEST:
1✔
4244
    return new BLong( xwest );
1✔
4245
  case MBR_YNORTH:
1✔
4246
    return new BLong( ynorth );
1✔
4247
  case MBR_YSOUTH:
1✔
4248
    return new BLong( ysouth );
1✔
4249
  case MBR_GUMPWIDTH:
1✔
4250
    return new BLong( gumpsize.x() );
1✔
4251
  case MBR_GUMPHEIGHT:
1✔
4252
    return new BLong( gumpsize.y() );
1✔
4253
  case MBR_FACETID:
1✔
4254
    return new BLong( facetid );
1✔
4255
  case MBR_EDITABLE:
1✔
4256
    return new BLong( editable ? 1 : 0 );
1✔
4257
  default:
×
4258
    return nullptr;
×
4259
  }
4260
}
4261

4262
BObjectImp* Map::get_script_member( const char* membername ) const
8✔
4263
{
4264
  ObjMember* objmember = getKnownObjMember( membername );
8✔
4265
  if ( objmember != nullptr )
8✔
4266
    return this->get_script_member_id( objmember->id );
8✔
4267
  return nullptr;
×
4268
}
4269

4270
BObjectImp* Map::set_script_member_id( const int id, int value )
8✔
4271
{
4272
  BObjectImp* imp = base::set_script_member_id( id, value );
8✔
4273
  if ( imp != nullptr )
8✔
4274
    return imp;
×
4275
  switch ( id )
8✔
4276
  {
4277
  case MBR_XEAST:
1✔
4278
    return new BLong( xeast = Clib::clamp_convert<u16>( value ) );
1✔
4279
  case MBR_XWEST:
1✔
4280
    return new BLong( xwest = Clib::clamp_convert<u16>( value ) );
1✔
4281
  case MBR_YNORTH:
1✔
4282
    return new BLong( ynorth = Clib::clamp_convert<u16>( value ) );
1✔
4283
  case MBR_YSOUTH:
1✔
4284
    return new BLong( ysouth = Clib::clamp_convert<u16>( value ) );
1✔
4285
  case MBR_GUMPWIDTH:
1✔
4286
    gumpsize.x( Clib::clamp_convert<u16>( value ) );
1✔
4287
    return new BLong( gumpsize.x() );
1✔
4288
  case MBR_GUMPHEIGHT:
1✔
4289
    gumpsize.y( Clib::clamp_convert<u16>( value ) );
1✔
4290
    return new BLong( gumpsize.y() );
1✔
4291
  case MBR_FACETID:
1✔
4292
    return new BLong( facetid = Clib::clamp_convert<u16>( value ) );
1✔
4293
  case MBR_EDITABLE:
1✔
4294
    return new BLong( editable = value ? true : false );
1✔
4295
  default:
×
4296
    return nullptr;
×
4297
  }
4298
}
4299
BObjectImp* Map::set_script_member( const char* membername, int value )
8✔
4300
{
4301
  ObjMember* objmember = getKnownObjMember( membername );
8✔
4302
  if ( objmember != nullptr )
8✔
4303
    return this->set_script_member_id( objmember->id, value );
8✔
4304
  return nullptr;
×
4305
}
4306

4307
BObjectImp* UObject::script_method_id( const int id, Core::UOExecutor& ex )
676✔
4308
{
4309
  switch ( id )
676✔
4310
  {
4311
  case MTH_ISA:
×
4312
  {
4313
    if ( !ex.hasParams( 1 ) )
×
4314
      return new BError( "Not enough parameters" );
×
4315
    u32 isatype;
4316
    if ( ex.getParam( 0, isatype ) )
×
4317
      return new BLong( script_isa( isatype ) );
×
4318
    break;
×
4319
  }
4320
  case MTH_SET_MEMBER:
189✔
4321
  {
4322
    if ( !ex.hasParams( 2 ) )
189✔
4323
      return new BError( "Not enough parameters" );
189✔
4324
    BObjectImp* objimp;
4325
    const String* mname;
4326
    if ( ex.getStringParam( 0, mname ) && ( objimp = ex.getParamImp( 1 ) ) != nullptr )
189✔
4327
    {
4328
      BObjectImp* ret;
4329
      if ( auto* l = impptrIf<BLong>( objimp ) )
189✔
4330
        ret = set_script_member( mname->value().c_str(), l->value() );
170✔
4331
      else if ( auto* d = impptrIf<Double>( objimp ) )
19✔
4332
        ret = set_script_member_double( mname->value().c_str(), d->value() );
6✔
4333
      else if ( auto* s = impptrIf<String>( objimp ) )
13✔
4334
        ret = set_script_member( mname->value().c_str(), s->value() );
13✔
4335
      else
4336
        return new BError( "Invalid value type" );
×
4337

4338
      if ( ret != nullptr )
189✔
4339
        return ret;
189✔
4340

4341
      std::string message = std::string( "Member " ) + std::string( mname->value() ) +
×
4342
                            std::string( " not found on that object" );
×
4343
      return new BError( message );
×
4344
    }
×
4345
    break;
×
4346
  }
4347
  case MTH_GET_MEMBER:
273✔
4348
  {
4349
    if ( !ex.hasParams( 1 ) )
273✔
4350
      return new BError( "Not enough parameters" );
273✔
4351

4352
    const String* mname;
4353
    if ( ex.getStringParam( 0, mname ) )
273✔
4354
    {
4355
      BObjectImp* ret = get_script_member( mname->value().c_str() );
273✔
4356
      if ( ret != nullptr )
273✔
4357
        return ret;
273✔
4358

4359
      std::string message = std::string( "Member " ) + std::string( mname->value() ) +
×
4360
                            std::string( " not found on that object" );
×
4361
      return new BError( message );
×
4362
    }
×
4363
    break;
×
4364
  }
4365
  default:
214✔
4366
  {
4367
    bool changed = false;
214✔
4368
    BObjectImp* imp = CallPropertyListMethod_id( proplist_, id, ex, changed );
214✔
4369
    if ( changed )
214✔
4370
      set_dirty();
46✔
4371
    return imp;
214✔
4372
  }
4373
  }
4374
  return new BError( "Invalid parameter type" );
×
4375
}
4376

4377

4378
BObjectImp* UObject::script_method( const char* methodname, Core::UOExecutor& ex )
×
4379
{
4380
  ObjMethod* objmethod = getKnownObjMethod( methodname );
×
4381
  if ( objmethod != nullptr )
×
4382
    return this->script_method_id( objmethod->id, ex );
×
4383

4384
  bool changed = false;
×
4385
  BObjectImp* imp = CallPropertyListMethod( proplist_, methodname, ex, changed );
×
4386
  if ( changed )
×
4387
    set_dirty();
×
4388

4389
  return imp;
×
4390
}
4391

4392
BObjectImp* UObject::custom_script_method( const char* methodname, Core::UOExecutor& ex )
×
4393
{
4394
  ObjMethod* objmethod = getKnownObjMethod( methodname );
×
4395
  if ( objmethod != nullptr )
×
4396
    return this->script_method_id( objmethod->id, ex );
×
4397
  return Core::gamestate.system_hooks.call_script_method( methodname, &ex, this );
×
4398
}
4399

4400
BObjectImp* UDoor::get_script_member_id( const int id ) const
6✔
4401
{
4402
  BObjectImp* imp = ULockable::get_script_member_id( id );
6✔
4403
  if ( imp != nullptr )
6✔
4404
    return imp;
6✔
4405

4406
  switch ( id )
×
4407
  {
4408
  case MBR_ISOPEN:
×
4409
    return new BLong( is_open() ? 1 : 0 );
×
4410
    break;
4411
  default:
×
4412
    return nullptr;
×
4413
  }
4414
}
4415

4416
BObjectImp* UDoor::get_script_member( const char* membername ) const
×
4417
{
4418
  ObjMember* objmember = getKnownObjMember( membername );
×
4419
  if ( objmember != nullptr )
×
4420
    return this->get_script_member_id( objmember->id );
×
4421
  return nullptr;
×
4422
}
4423

4424
BObjectImp* UDoor::script_method_id( const int id, Core::UOExecutor& ex )
×
4425
{
4426
  BObjectImp* imp = base::script_method_id( id, ex );
×
4427
  if ( imp != nullptr )
×
4428
    return imp;
×
4429

4430
  switch ( id )
×
4431
  {
4432
  case MTH_OPEN:
×
4433
    open();
×
4434
    break;
×
4435
  case MTH_CLOSE:
×
4436
    close();
×
4437
    break;
×
4438
  case MTH_TOGGLE:
×
4439
    toggle();
×
4440
    break;
×
4441
  default:
×
4442
    return nullptr;
×
4443
  }
4444
  return new BLong( 1 );
×
4445
}
4446

4447
BObjectImp* UDoor::script_method( const char* methodname, Core::UOExecutor& ex )
×
4448
{
4449
  ObjMethod* objmethod = getKnownObjMethod( methodname );
×
4450
  if ( objmethod != nullptr )
×
4451
    return this->script_method_id( objmethod->id, ex );
×
4452
  return nullptr;
×
4453
}
4454
}  // namespace Core
4455
namespace Items
4456
{
4457
using namespace Bscript;
4458

4459
BObjectImp* Equipment::get_script_member_id( const int id ) const
9✔
4460
{
4461
  BObjectImp* imp = Item::get_script_member_id( id );
9✔
4462
  if ( imp != nullptr )
9✔
4463
    return imp;
4✔
4464

4465
  switch ( id )
5✔
4466
  {
4467
  case MBR_INTRINSIC:
×
4468
    return new BLong( is_intrinsic() );
×
4469
    break;
4470
  default:
5✔
4471
    return nullptr;
5✔
4472
  }
4473
}
4474
BObjectImp* Equipment::get_script_member( const char* membername ) const
×
4475
{
4476
  ObjMember* objmember = getKnownObjMember( membername );
×
4477
  if ( objmember != nullptr )
×
4478
    return this->get_script_member_id( objmember->id );
×
4479
  return nullptr;
×
4480
}
4481

4482
BObjectImp* Equipment::set_script_member_id( const int id, int value )
3✔
4483
{
4484
  BObjectImp* imp = Item::set_script_member_id( id, value );
3✔
4485
  if ( imp != nullptr )
3✔
4486
    return imp;
×
4487

4488
  return nullptr;
3✔
4489
  /*
4490
  switch(id)
4491
  {
4492
  default: return nullptr;
4493
  }
4494
  */
4495
}
4496
BObjectImp* Equipment::set_script_member( const char* membername, int value )
×
4497
{
4498
  ObjMember* objmember = getKnownObjMember( membername );
×
4499
  if ( objmember != nullptr )
×
4500
    return this->set_script_member_id( objmember->id, value );
×
4501
  return nullptr;
×
4502
}
4503

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

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

4526

4527
BObjectImp* UWeapon::get_script_member_id( const int id ) const
4✔
4528
{
4529
  BObjectImp* imp = Equipment::get_script_member_id( id );
4✔
4530
  if ( imp != nullptr )
4✔
4531
    return imp;
1✔
4532

4533
  switch ( id )
3✔
4534
  {
4535
  case MBR_DMG_MOD:
1✔
4536
    return new BLong( damage_mod() );
1✔
4537
    break;
4538
  case MBR_SPEED_MOD:
1✔
4539
    return new BLong( speed_mod() );
1✔
4540
    break;
4541
  case MBR_ATTRIBUTE:
×
4542
    return new String( attribute().name );
×
4543
    break;
4544
  case MBR_HITSCRIPT:
1✔
4545
    return new String( hit_script_.qualifiedname() );
1✔
4546
    break;
4547
  default:
×
4548
    return nullptr;
×
4549
  }
4550
}
4551
BObjectImp* UWeapon::get_script_member( const char* membername ) const
3✔
4552
{
4553
  ObjMember* objmember = getKnownObjMember( membername );
3✔
4554
  if ( objmember != nullptr )
3✔
4555
    return this->get_script_member_id( objmember->id );
3✔
4556
  return nullptr;
×
4557
}
4558

4559
BObjectImp* UWeapon::set_script_member_id( const int id, const std::string& value )
2✔
4560
{
4561
  BObjectImp* imp = Item::set_script_member_id( id, value );
2✔
4562
  if ( imp != nullptr )
2✔
4563
    return imp;
1✔
4564

4565
  switch ( id )
1✔
4566
  {
4567
  case MBR_HITSCRIPT:
1✔
4568
    set_hit_script( value );
1✔
4569
    return new BLong( 1 );
1✔
4570
  default:
×
4571
    return nullptr;
×
4572
  }
4573
}
4574
BObjectImp* UWeapon::set_script_member( const char* membername, const std::string& value )
1✔
4575
{
4576
  ObjMember* objmember = getKnownObjMember( membername );
1✔
4577
  if ( objmember != nullptr )
1✔
4578
    return this->set_script_member_id( objmember->id, value );
1✔
4579
  return nullptr;
×
4580
}
4581

4582
BObjectImp* UWeapon::set_script_member_id( const int id, int value )
2✔
4583
{
4584
  if ( is_intrinsic() )
2✔
4585
    return new BError( "Cannot alter an instrinsic NPC weapon member values" );  // executor won't
×
4586
                                                                                 // return this to
4587
                                                                                 // the script
4588
                                                                                 // currently.
4589

4590
  BObjectImp* imp = Equipment::set_script_member_id( id, value );
2✔
4591
  if ( imp != nullptr )
2✔
4592
    return imp;
×
4593

4594
  switch ( id )
2✔
4595
  {
4596
  case MBR_DMG_MOD:
1✔
4597
    damage_mod( Clib::clamp_convert<s16>( value ) );
1✔
4598
    break;
1✔
4599
  case MBR_SPEED_MOD:
1✔
4600
    speed_mod( Clib::clamp_convert<s16>( value ) );
1✔
4601
    break;
1✔
4602
  default:
×
4603
    return nullptr;
×
4604
  }
4605
  return new BLong( value );
2✔
4606
}
4607

4608
BObjectImp* UWeapon::set_script_member( const char* membername, int value )
2✔
4609
{
4610
  ObjMember* objmember = getKnownObjMember( membername );
2✔
4611
  if ( objmember != nullptr )
2✔
4612
    return this->set_script_member_id( objmember->id, value );
2✔
4613
  return nullptr;
×
4614
}
4615

4616
BObjectImp* UWeapon::set_script_member_id_double( const int id, double value )
×
4617
{
4618
  if ( is_intrinsic() )
×
4619
    return new BError( "Cannot alter an instrinsic NPC weapon member values" );  // executor won't
×
4620
                                                                                 // return this to
4621
                                                                                 // the script
4622
                                                                                 // currently.
4623
  return base::set_script_member_id_double( id, value );
×
4624
}
4625

4626
BObjectImp* UWeapon::set_script_member_double( const char* membername, double value )
×
4627
{
4628
  ObjMember* objmember = getKnownObjMember( membername );
×
4629
  if ( objmember != nullptr )
×
4630
    return this->set_script_member_id_double( objmember->id, value );
×
4631
  return base::set_script_member_double( membername, value );
×
4632
}
4633

4634
BObjectImp* UArmor::get_script_member_id( const int id ) const
5✔
4635
{
4636
  BObjectImp* imp = Equipment::get_script_member_id( id );
5✔
4637
  if ( imp != nullptr )
5✔
4638
    return imp;
3✔
4639

4640
  switch ( id )
2✔
4641
  {
4642
  case MBR_AR_MOD:
1✔
4643
    return new BLong( ar_mod() );
1✔
4644
    break;
4645
  case MBR_AR:
×
4646
    return new BLong( ar() );
×
4647
    break;
4648
  case MBR_AR_BASE:
×
4649
    return new BLong( ar_base() );
×
4650
    break;
4651
  case MBR_ONHIT_SCRIPT:
1✔
4652
    // bad method name? nullptr makes it return the fullpath
4653
    return new String( onhitscript_.qualifiedname() );
1✔
4654
    break;
4655
  default:
×
4656
    return nullptr;
×
4657
  }
4658
}
4659

4660
BObjectImp* UArmor::get_script_member( const char* membername ) const
2✔
4661
{
4662
  ObjMember* objmember = getKnownObjMember( membername );
2✔
4663
  if ( objmember != nullptr )
2✔
4664
    return this->get_script_member_id( objmember->id );
2✔
4665
  return nullptr;
×
4666
}
4667

4668
BObjectImp* UArmor::set_script_member_id( const int id, const std::string& value )
2✔
4669
{
4670
  BObjectImp* imp = Item::set_script_member_id( id, value );
2✔
4671
  if ( imp != nullptr )
2✔
4672
    return imp;
1✔
4673
  switch ( id )
1✔
4674
  {
4675
  case MBR_ONHIT_SCRIPT:
1✔
4676
    set_onhitscript( value );
1✔
4677
    return new BLong( 1 );
1✔
4678
  default:
×
4679
    return nullptr;
×
4680
  }
4681
}
4682

4683
BObjectImp* UArmor::set_script_member( const char* membername, const std::string& value )
1✔
4684
{
4685
  ObjMember* objmember = getKnownObjMember( membername );
1✔
4686
  if ( objmember != nullptr )
1✔
4687
    return this->set_script_member_id( objmember->id, value );
1✔
4688
  return nullptr;
×
4689
}
4690

4691
BObjectImp* UArmor::set_script_member_id( const int id, int value )
1✔
4692
{
4693
  BObjectImp* imp = Equipment::set_script_member_id( id, value );
1✔
4694
  if ( imp != nullptr )
1✔
4695
    return imp;
×
4696

4697
  switch ( id )
1✔
4698
  {
4699
  case MBR_AR_MOD:
1✔
4700
    this->ar_mod( Clib::clamp_convert<s16>( value ) );
1✔
4701
    if ( container != nullptr )
1✔
4702
    {
4703
      if ( Core::IsCharacter( container->serial ) )
×
4704
      {
4705
        Mobile::Character* chr = container->get_chr_owner();
×
4706
        if ( chr != nullptr )
×
4707
          Mobile::ARUpdater::on_change( chr );
×
4708
      }
4709
    }
4710
    return new BLong( value );
1✔
4711
  default:
×
4712
    return nullptr;
×
4713
  }
4714
}
4715

4716
BObjectImp* UArmor::set_script_member( const char* membername, int value )
1✔
4717
{
4718
  ObjMember* objmember = getKnownObjMember( membername );
1✔
4719
  if ( objmember != nullptr )
1✔
4720
    return this->set_script_member_id( objmember->id, value );
1✔
4721
  return nullptr;
×
4722
}
4723
}  // namespace Items
4724
namespace Module
4725
{
4726
using namespace Bscript;
4727

4728
const char* EClientRefObjImp::typeOf() const
×
4729
{
4730
  return "ClientRef";
×
4731
}
4732

4733
u8 EClientRefObjImp::typeOfInt() const
×
4734
{
4735
  return OTClientRef;
×
4736
}
4737

4738
BObjectImp* EClientRefObjImp::copy() const
×
4739
{
4740
  if ( value().exists() )
×
4741
    return value()->make_ref();
×
4742
  return new BError( "Client is disconnected" );
×
4743
}
4744

4745
bool EClientRefObjImp::isTrue() const
2✔
4746
{
4747
  return ( value().exists() && value()->isConnected() );
2✔
4748
}
4749

4750
bool EClientRefObjImp::operator==( const BObjectImp& objimp ) const
×
4751
{
4752
  if ( objimp.isa( BObjectImp::OTApplicObj ) )
×
4753
  {
4754
    const BApplicObjBase* aob =
4755
        Clib::explicit_cast<const BApplicObjBase*, const BObjectImp*>( &objimp );
×
4756

4757
    if ( aob->object_type() == &eclientrefobjimp_type )
×
4758
    {
4759
      const EClientRefObjImp* clientref_imp =
4760
          Clib::explicit_cast<const EClientRefObjImp*, const BApplicObjBase*>( aob );
×
4761

4762
      if ( clientref_imp->value().exists() && value().exists() &&
×
4763
           ( clientref_imp->value()->chr != nullptr ) && ( value()->chr != nullptr ) )
×
4764
        return ( clientref_imp->value()->chr->serial == value()->chr->serial );
×
4765
      return false;
×
4766
    }
4767
    return false;
×
4768
  }
4769
  if ( objimp.isa( Bscript::BObjectImp::OTBoolean ) )
×
4770
    return isTrue() == static_cast<const Bscript::BBoolean&>( objimp ).isTrue();
×
4771
  return false;
×
4772
}
4773

4774
BObjectRef EClientRefObjImp::get_member_id( const int id )
5✔
4775
{
4776
  if ( ( !obj_.exists() ) || ( !obj_->isConnected() ) )
5✔
4777
    return BObjectRef( new BError( "Client not ready or disconnected" ) );
×
4778

4779
  BObjectImp* result = obj_->get_script_member_id( id );
5✔
4780
  if ( result != nullptr )
5✔
4781
    return BObjectRef( result );
4✔
4782
  return BObjectRef( UninitObject::create() );
1✔
4783
}
4784

4785
BObjectRef EClientRefObjImp::get_member( const char* membername )
1✔
4786
{
4787
  if ( ( !obj_.exists() ) || ( !obj_->isConnected() ) )
1✔
4788
    return BObjectRef( new BError( "Client not ready or disconnected" ) );
×
4789
  ObjMember* objmember = getKnownObjMember( membername );
1✔
4790
  if ( objmember != nullptr )
1✔
4791
    return this->get_member_id( objmember->id );
×
4792
  return BObjectRef( UninitObject::create() );
1✔
4793
}
4794

4795
BObjectRef EClientRefObjImp::set_member( const char* membername, BObjectImp* value, bool copy )
×
4796
{
4797
  if ( !obj_.exists() || !obj_->isConnected() )
×
4798
    return BObjectRef( new BError( "Client not ready or disconnected" ) );
×
4799
  ObjMember* objmember = getKnownObjMember( membername );
×
4800
  if ( objmember != nullptr )
×
4801
    return this->set_member_id( objmember->id, value, copy );
×
4802
  return BObjectRef( UninitObject::create() );
×
4803
}
4804

4805
BObjectRef EClientRefObjImp::set_member_id( const int id, BObjectImp* value, bool /*copy*/ )
2✔
4806
{
4807
  if ( !obj_.exists() || !obj_->isConnected() )
2✔
4808
    return BObjectRef( new BError( "Client not ready or disconnected" ) );
×
4809

4810
  BObjectImp* result = nullptr;
2✔
4811
  if ( auto* v = impptrIf<BLong>( value ) )
2✔
4812
    result = obj_->set_script_member_id( id, v->value() );
2✔
4813

4814
  if ( result != nullptr )
2✔
4815
    return BObjectRef( result );
2✔
4816

4817
  return BObjectRef( UninitObject::create() );
×
4818
}
4819

4820

4821
BObjectImp* EClientRefObjImp::call_polmethod( const char* methodname, Core::UOExecutor& ex )
×
4822
{
4823
  if ( !obj_.exists() || !obj_->isConnected() )
×
4824
    return new BError( "Client not ready or disconnected" );
×
4825
  bool forcebuiltin{ Executor::builtinMethodForced( methodname ) };
×
4826
  ObjMethod* objmethod = getKnownObjMethod( methodname );
×
4827
  if ( objmethod != nullptr )
×
4828
    return this->call_polmethod_id( objmethod->id, ex, forcebuiltin );
×
4829
  return Core::gamestate.system_hooks.call_script_method( methodname, &ex, this );
×
4830
}
4831

4832
BObjectImp* EClientRefObjImp::call_polmethod_id( const int id, Core::UOExecutor& ex,
×
4833
                                                 bool forcebuiltin )
4834
{
4835
  if ( !obj_.exists() || !obj_->isConnected() )
×
4836
    return new BError( "Client not ready or disconnected" );
×
4837

4838
  ObjMethod* mth = getObjMethod( id );
×
4839
  if ( mth->overridden && !forcebuiltin )
×
4840
  {
4841
    auto* imp = Core::gamestate.system_hooks.call_script_method( mth->code, &ex, this );
×
4842
    if ( imp )
×
4843
      return imp;
×
4844
  }
4845
  switch ( id )
×
4846
  {
4847
  case MTH_COMPAREVERSION:
×
4848
  {
4849
    if ( !ex.hasParams( 1 ) )
×
4850
      return new BError( "Not enough parameters" );
×
4851
    const String* pstr;
4852
    if ( ex.getStringParam( 0, pstr ) )
×
4853
      return new BLong( obj_->compareVersion( pstr->getStringRep() ) ? 1 : 0 );
×
4854
    return new BError( "Invalid parameter type" );
×
4855
  }
4856
  }
4857

4858
  return base::call_polmethod_id( id, ex );
×
4859
}
4860

4861
BoatMovementEvent::BoatMovementEvent( Mobile::Character* source, const u8 speed, const u8 direction,
3✔
4862
                                      const u8 relative_direction )
3✔
4863
{
4864
  addMember( "type", new BLong( Core::EVID_BOAT_MOVEMENT ) );
3✔
4865
  addMember( "source", new Module::EOfflineCharacterRefObjImp( source ) );
3✔
4866
  addMember( "speed", new BLong( static_cast<int>( speed ) ) );
3✔
4867
  addMember( "direction", new BLong( static_cast<int>( direction ) ) );
3✔
4868
  addMember( "relative_direction", new BLong( static_cast<int>( relative_direction ) ) );
3✔
4869
}
3✔
4870

4871
SourcedEvent::SourcedEvent( Core::EVENTID type, Mobile::Character* source )
26✔
4872
{
4873
  addMember( "type", new BLong( type ) );
26✔
4874
  addMember( "source", new Module::EOfflineCharacterRefObjImp( source ) );
26✔
4875
}
26✔
4876

4877
SpeechEvent::SpeechEvent( Mobile::Character* speaker, const std::string& speech,
3✔
4878
                          const std::string& texttype, std::string lang,
4879
                          Bscript::ObjArray* speechtokens )
3✔
4880
{
4881
  addMember( "type", new BLong( Core::EVID_SPOKE ) );
3✔
4882
  addMember( "source", new Module::EOfflineCharacterRefObjImp( speaker ) );
3✔
4883
  addMember( "text", new String( speech ) );
3✔
4884
  addMember( "texttype", new String( texttype ) );
3✔
4885
  if ( !lang.empty() )
3✔
4886
    addMember( "langcode", new String( lang ) );
3✔
4887
  if ( speechtokens != nullptr )
3✔
4888
    addMember( "tokens", new Bscript::ObjArray( *speechtokens ) );
3✔
4889
}
3✔
4890

4891
DamageEvent::DamageEvent( Mobile::Character* source, unsigned short damage )
×
4892
{
4893
  addMember( "type", new BLong( Core::EVID_DAMAGED ) );
×
4894

4895
  if ( source != nullptr )
×
4896
    addMember( "source", new Module::EOfflineCharacterRefObjImp( source ) );
×
4897
  else
4898
    addMember( "source", new BLong( 0 ) );
×
4899

4900
  addMember( "damage", new BLong( damage ) );
×
4901
}
×
4902

4903
ItemGivenEvent::ItemGivenEvent( Mobile::Character* chr_givenby, Items::Item* item_given,
×
4904
                                Mobile::NPC* chr_givento )
×
4905
    : SourcedEvent( Core::EVID_ITEM_GIVEN, chr_givenby ), given_by_( nullptr )
×
4906
{
4907
  addMember( "item", new EItemRefObjImp( item_given ) );
×
4908

4909
  given_time_ = Core::read_gameclock();
×
4910
  item_.set( item_given );
×
4911
  cont_.set( item_given->container );
×
4912
  given_by_.set( chr_givenby );
×
4913

4914
  item_given->setprop( "GivenBy", BLong::pack( chr_givenby->serial ) );
×
4915
  item_given->setprop( "GivenTo", BLong::pack( chr_givento->serial ) );
×
4916
  item_given->setprop( "GivenTime", BLong::pack( given_time_ ) );
×
4917
}
×
4918

4919
ItemGivenEvent::~ItemGivenEvent()
×
4920
{
4921
  /* See if the item is still in the container it was in
4922
       This means the AI script didn't do anything with it.
4923
       */
4924
  Items::Item* item = item_.get();
×
4925
  Core::UContainer* cont = cont_.get();
×
4926
  Mobile::Character* chr = given_by_.get();
×
4927

4928
  std::string given_time_str;
×
4929
  if ( !item->getprop( "GivenTime", given_time_str ) )
×
4930
    given_time_str = "";
×
4931

4932
  item->eraseprop( "GivenBy" );
×
4933
  item->eraseprop( "GivenTo" );
×
4934
  item->eraseprop( "GivenTime" );
×
4935

4936
  Bscript::BObject given_value( BObjectImp::unpack( given_time_str.c_str() ) );
×
4937
  int gts = given_value.impptr<BLong>()->value();
×
4938

4939
  if ( item->orphan() || cont->orphan() || chr->orphan() )
×
4940
    return;
×
4941

4942
  if ( item->container == cont && Clib::tostring( given_time_ ) == Clib::tostring( gts ) )
×
4943
  {
4944
    Core::UContainer* backpack = chr->backpack();
×
4945
    if ( backpack != nullptr && !chr->dead() )
×
4946
    {
4947
      if ( backpack->can_add( *item ) )
×
4948
      {
4949
        cont->remove( item );
×
4950
        u8 newSlot = 1;
×
4951
        if ( !backpack->can_add_to_slot( newSlot ) || !item->slot_index( newSlot ) )
×
4952
        {
4953
          item->setposition( chr->pos() );
×
4954
          add_item_to_world( item );
×
4955
          register_with_supporting_multi( item );
×
4956
          move_item( item, item->pos() );
×
4957
          return;
×
4958
        }
4959
        backpack->add( item, item->pos2d() );
×
4960
        update_item_to_inrange( item );
×
4961
        return;
×
4962
      }
4963
    }
4964
    cont->remove( item );
×
4965
    item->setposition( chr->pos() );
×
4966
    add_item_to_world( item );
×
4967
    register_with_supporting_multi( item );
×
4968
    move_item( item, item->pos() );
×
4969
  }
4970
}
×
4971

4972
GumpEvent::GumpEvent( Mobile::Character* source, Bscript::BObjectImp* resp )
6✔
4973
    : SourcedEvent( Core::EVID_GUMP_RESPONSE, source )
6✔
4974
{
4975
  addMember( "response", resp );
6✔
4976
}
6✔
4977
}  // namespace Module
4978

4979
namespace Network
4980
{
4981
using namespace Bscript;
4982
BObjectImp* Client::set_script_member_id( const int id, int value )
2✔
4983
{
4984
  switch ( id )
2✔
4985
  {
4986
  case MBR_DISABLE_INACTIVITY_TIMEOUT:
×
4987
    disable_inactivity_timeout( value );
×
4988
    return new BLong( disable_inactivity_timeout() );
×
4989
  case MBR_VISUAL_RANGE:
2✔
4990
    set_update_range_by_script( Clib::clamp_convert<u8>( value ) );
2✔
4991
    return new BLong( update_range() );
2✔
4992
  default:
×
4993
    return nullptr;
×
4994
  }
4995
}
4996

4997
BObjectImp* Client::get_script_member_id( const int id )
5✔
4998
{
4999
  switch ( id )
5✔
5000
  {
5001
  case MBR_ACCTNAME:
2✔
5002
    if ( acct != nullptr )
2✔
5003
      return new String( acct->name() );
2✔
5004
    return new BError( "Not attached to an account" );
×
5005
    break;
5006
  case MBR_ACCT:
2✔
5007
    if ( acct != nullptr )
2✔
5008
      return new Accounts::AccountObjImp( Accounts::AccountPtrHolder( Core::AccountRef( acct ) ) );
2✔
5009
    return new BError( "Not attached to an account" );
×
5010
    break;
5011
  case MBR_IP:
×
5012
    return new String( ipaddrAsString() );
×
5013
    break;
5014
  case MBR_CLIENTVERSION:
×
5015
    return new String( getversion() );
×
5016
    break;
5017
  case MBR_CLIENTVERSIONDETAIL:
×
5018
  {
5019
    std::unique_ptr<BStruct> info( new BStruct );
×
5020
    Network::VersionDetailStruct version = getversiondetail();
×
5021
    info->addMember( "major", new BLong( version.major ) );
×
5022
    info->addMember( "minor", new BLong( version.minor ) );
×
5023
    info->addMember( "rev", new BLong( version.rev ) );
×
5024
    info->addMember( "patch", new BLong( version.patch ) );
×
5025
    return info.release();
×
5026
  }
×
5027
  break;
5028
  case MBR_CLIENTINFO:
×
5029
    return getclientinfo();
×
5030
    break;
5031
  case MBR_CLIENTTYPE:
×
5032
    return new BLong( ClientType );
×
5033
    break;
5034
  case MBR_UO_EXPANSION_CLIENT:
×
5035
    return new BLong( UOExpansionFlagClient );
×
5036
    break;
5037
  case MBR_LAST_ACTIVITY_AT:
×
5038
    return new BLong( static_cast<s32>( last_activity_at() ) );
×
5039
    break;
5040
  case MBR_LAST_PACKET_AT:
×
5041
    return new BLong( static_cast<s32>( last_packet_at() ) );
×
5042
    break;
5043
  case MBR_PORT:
×
5044
    return new BLong( listen_port );
×
5045
    break;
5046
  case MBR_DISABLE_INACTIVITY_TIMEOUT:
×
5047
    return new BLong( disable_inactivity_timeout() );
×
5048
    break;
5049
  case MBR_VISUAL_RANGE:
×
5050
    return new BLong( update_range() );
×
5051
    break;
5052
  }
5053

5054
  return nullptr;
1✔
5055
}
5056

5057
}  // namespace Network
5058

5059
namespace Core
5060
{
5061
bool UObject::script_isa( unsigned isatype ) const
6,249✔
5062
{
5063
  return ( isatype == POLCLASS_OBJECT );
6,249✔
5064
}
5065

5066
bool ULockable::script_isa( unsigned isatype ) const
127✔
5067
{
5068
  return ( isatype == POLCLASS_LOCKABLE ) || base::script_isa( isatype );
127✔
5069
}
5070

5071
bool UContainer::script_isa( unsigned isatype ) const
174✔
5072
{
5073
  return ( isatype == POLCLASS_CONTAINER ) || base::script_isa( isatype );
174✔
5074
}
5075

5076
bool UCorpse::script_isa( unsigned isatype ) const
73✔
5077
{
5078
  return ( isatype == POLCLASS_CORPSE ) || base::script_isa( isatype );
73✔
5079
}
5080

5081
bool UDoor::script_isa( unsigned isatype ) const
1✔
5082
{
5083
  return ( isatype == POLCLASS_DOOR ) || base::script_isa( isatype );
1✔
5084
}
5085

5086
bool Spellbook::script_isa( unsigned isatype ) const
×
5087
{
5088
  return ( isatype == POLCLASS_SPELLBOOK ) || base::script_isa( isatype );
×
5089
}
5090

5091
bool Map::script_isa( unsigned isatype ) const
×
5092
{
5093
  return ( isatype == POLCLASS_MAP ) || base::script_isa( isatype );
×
5094
}
5095
}  // namespace Core
5096

5097
namespace Items
5098
{
5099
bool Item::script_isa( unsigned isatype ) const
6,232✔
5100
{
5101
  return ( isatype == Core::POLCLASS_ITEM ) || base::script_isa( isatype );
6,232✔
5102
}
5103

5104
bool Equipment::script_isa( unsigned isatype ) const
1✔
5105
{
5106
  return ( isatype == Core::POLCLASS_EQUIPMENT ) || base::script_isa( isatype );
1✔
5107
}
5108

5109
bool UArmor::script_isa( unsigned isatype ) const
1✔
5110
{
5111
  return ( isatype == Core::POLCLASS_ARMOR ) || base::script_isa( isatype );
1✔
5112
}
5113

5114
bool UWeapon::script_isa( unsigned isatype ) const
×
5115
{
5116
  return ( isatype == Core::POLCLASS_WEAPON ) || base::script_isa( isatype );
×
5117
}
5118
}  // namespace Items
5119

5120
namespace Mobile
5121
{
5122
bool Character::script_isa( unsigned isatype ) const
142✔
5123
{
5124
  return ( isatype == Core::POLCLASS_MOBILE ) || base::script_isa( isatype );
142✔
5125
}
5126

5127
bool NPC::script_isa( unsigned isatype ) const
56✔
5128
{
5129
  return ( isatype == Core::POLCLASS_NPC ) || base::script_isa( isatype );
56✔
5130
}
5131
}  // namespace Mobile
5132
namespace Multi
5133
{
5134
bool UMulti::script_isa( unsigned isatype ) const
3✔
5135
{
5136
  return ( isatype == Core::POLCLASS_MULTI ) || base::script_isa( isatype );
3✔
5137
}
5138

5139
bool UMulti::setgraphic( u16 /* newobjtype */ )
×
5140
{
5141
  return false;
×
5142
}
5143

5144
bool UBoat::script_isa( unsigned isatype ) const
9✔
5145
{
5146
  return ( isatype == Core::POLCLASS_BOAT ) || base::script_isa( isatype );
9✔
5147
}
5148

5149
bool UHouse::script_isa( unsigned isatype ) const
×
5150
{
5151
  return ( isatype == Core::POLCLASS_HOUSE ) || base::script_isa( isatype );
×
5152
}
5153
}  // namespace Multi
5154
}  // 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