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

polserver / polserver / 25939934106

15 May 2026 08:30PM UTC coverage: 60.882% (-0.05%) from 60.929%
25939934106

push

github

turleypol
apply damage for items + evid_damaged

0 of 36 new or added lines in 2 files covered. (0.0%)

1083 existing lines in 14 files now uncovered.

44698 of 73417 relevant lines covered (60.88%)

524562.92 hits per line

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

26.09
/pol-core/pol/module/vitalmod.cpp
1
/** @file
2
 *
3
 * @par History
4
 * - 2006/10/07 Shinigami: GCC 3.4.x fix - added "template<>" to TmplExecutorModule
5
 * - 2009/09/22 Turley:    repsys param to applydamage
6
 * - 2009/11/20 Turley:    RecalcVitals can update single Attributes/Vitals - based on Tomi
7
 * - 2010/01/15 Turley:    (Tomi) send damage param ApplyDamage/ApplyRawDamage
8
 */
9

10

11
#include "vitalmod.h"
12
#include "../../bscript/berror.h"
13
#include "../../bscript/bobject.h"
14
#include "../../bscript/impstr.h"
15
#include "../cmbtcfg.h"
16
#include "../globals/settings.h"
17
#include "../item/item.h"
18
#include "../mobile/attribute.h"
19
#include "../mobile/charactr.h"
20
#include "../spells.h"
21
#include "../ufunc.h"
22
#include "../vital.h"
23
#include "clib/clib.h"
24

25
#include <module_defs/vitals.h>
26

27

28
namespace Pol::Module
29
{
30
using namespace Bscript;
31

32
VitalExecutorModule::VitalExecutorModule( Bscript::Executor& exec )
379✔
33
    : Bscript::TmplExecutorModule<VitalExecutorModule, Core::PolModule>( exec )
379✔
34
{
35
}
379✔
36

37
BObjectImp* VitalExecutorModule::mf_ApplyRawDamage()
×
38
{
39
  Core::UObject* obj;
40
  int damage;
41
  int userepsys;
42
  int send_damage_packet;
NEW
43
  if ( getUObjectParam( 0, obj ) && getParam( 1, damage ) && getParam( 2, userepsys ) &&
×
44
       getParam( 3, send_damage_packet ) && damage >= 0 && damage <= USHRT_MAX )
×
45
  {
NEW
46
    Mobile::Attackable att{ obj };
×
NEW
47
    if ( !att )
×
NEW
48
      return new BError( "Object is not damageable" );
×
49
    bool send_dmg = send_damage_packet == 2 ? Core::settingsManager.combat_config.send_damage_packet
×
50
                                            : ( send_damage_packet > 0 ? true : false );
×
NEW
51
    if ( auto* chr = att.mobile() )
×
NEW
52
      chr->apply_raw_damage_hundredths( static_cast<unsigned int>( damage * 100 ),
×
53
                                        GetUOController(), userepsys > 0 ? true : false, send_dmg );
NEW
54
    else if ( auto* item = att.item() )
×
NEW
55
      item->apply_damage( Clib::clamp_convert<u16>( damage ), GetUOController(), send_dmg );
×
UNCOV
56
    return new BLong( 1 );
×
57
  }
58
  return new BLong( 0 );
×
59
}
60

61
BObjectImp* VitalExecutorModule::mf_ApplyDamage()
×
62
{
63
  Core::UObject* obj;
64
  double damage;
65
  int userepsys;
66
  int send_damage_packet;
NEW
67
  if ( !getUObjectParam( 0, obj ) || !getRealParam( 1, damage ) || !getParam( 2, userepsys ) ||
×
NEW
68
       !getParam( 3, send_damage_packet ) )
×
NEW
69
    return new BError( "Invalid parameter type" );
×
NEW
70
  if ( damage < 0.0 || damage > 30000.0 )
×
UNCOV
71
    return new BError( "Damage is out of range" );
×
NEW
72
  Mobile::Attackable att{ obj };
×
NEW
73
  if ( !att )
×
NEW
74
    return new BError( "Object is not damageable" );
×
75

NEW
76
  bool send_dmg = send_damage_packet == 2 ? Core::settingsManager.combat_config.send_damage_packet
×
NEW
77
                                          : ( send_damage_packet > 0 ? true : false );
×
NEW
78
  if ( auto* chr = att.mobile() )
×
NEW
79
    damage = chr->apply_damage( static_cast<unsigned short>( damage ), GetUOController(),
×
80
                                userepsys > 0 ? true : false, send_dmg );
NEW
81
  else if ( auto* item = att.item() )
×
NEW
82
    item->apply_damage( Clib::clamp_convert<u16>( damage ), GetUOController(), send_dmg );
×
NEW
83
  return new BLong( static_cast<int>( damage ) );
×
84
}
85

86
BObjectImp* VitalExecutorModule::mf_HealDamage()
×
87
{
88
  Mobile::Character* chr;
89
  int amount;
90
  if ( getCharacterParam( 0, chr ) && getParam( 1, amount ) && amount >= 0 && amount <= USHRT_MAX )
×
91
  {
92
    Mobile::Character* controller = GetUOController();
×
93
    if ( controller )
×
94
      controller->repsys_on_help( chr );
×
95

96
    chr->heal_damage_hundredths( static_cast<unsigned short>( amount ) * 100L );
×
97
    return new BLong( 1 );
×
98
  }
99

100
  return new BError( "Invalid parameter" );
×
101
}
102

103
BObjectImp* VitalExecutorModule::mf_ConsumeMana()
×
104
{
105
  Mobile::Character* chr;
106
  int spellid;
107
  if ( getCharacterParam( 0, chr ) && getParam( 1, spellid ) )
×
108
  {
109
    if ( !Core::VALID_SPELL_ID( spellid ) )
×
110
      return new BError( "Spell ID out of range" );
×
111

112
    Core::USpell* spell = Core::gamestate.spells[spellid];
×
113
    if ( spell == nullptr )
×
114
      return new BError( "No such spell" );
×
115
    if ( spell->check_mana( chr ) == false )
×
116
      return new BLong( 0 );
×
117

118
    spell->consume_mana( chr );
×
119
    if ( chr->has_active_client() )
×
120
      Core::send_mana_level( chr->client );
×
121

122
    return new BLong( 1 );
×
123
  }
124

125
  return new BError( "Invalid parameter" );
×
126
}
127

128
BObjectImp* VitalExecutorModule::mf_GetVitalName( /* alias_name */ )
×
129
{
130
  const Core::Vital* vital;
131

132
  if ( !getVitalParam( 0, vital ) )
×
133
  {
134
    return new BError( "Invalid parameter type." );
×
135
  }
136

137
  return new String( vital->name );
×
138
}
139

140
BObjectImp* VitalExecutorModule::mf_GetVital( /* mob, vitalid */ )
11✔
141
{
142
  Mobile::Character* chr;
143
  const Core::Vital* vital;
144

145
  if ( getCharacterParam( 0, chr ) && getVitalParam( 1, vital ) )
11✔
146
  {
147
    const Mobile::VitalValue& vv = chr->vital( vital->vitalid );
11✔
148
    return new BLong( vv.current() );
11✔
149
  }
150
  return new BError( "Invalid parameter type" );
×
151
}
152

153
BObjectImp* VitalExecutorModule::mf_GetVitalMaximumValue( /* mob, vitalid */ )
6✔
154
{
155
  Mobile::Character* chr;
156
  const Core::Vital* vital;
157

158
  if ( getCharacterParam( 0, chr ) && getVitalParam( 1, vital ) )
6✔
159
  {
160
    const Mobile::VitalValue& vv = chr->vital( vital->vitalid );
6✔
161
    return new BLong( vv.maximum() );
6✔
162
  }
163
  return new BError( "Invalid parameter type" );
×
164
}
165

166
BObjectImp* VitalExecutorModule::mf_GetVitalRegenRate( /* mob, vitalid */ )
×
167
{
168
  Mobile::Character* chr;
169
  const Core::Vital* vital;
170

171
  if ( getCharacterParam( 0, chr ) && getVitalParam( 1, vital ) )
×
172
  {
173
    const Mobile::VitalValue& vv = chr->vital( vital->vitalid );
×
174
    return new BLong( vv.regenrate() );
×
175
  }
176
  return new BError( "Invalid parameter type" );
×
177
}
178

179
BObjectImp* VitalExecutorModule::mf_SetVital( /* mob, vitalid, hundredths */ )
9✔
180
{
181
  Mobile::Character* chr;
182
  const Core::Vital* vital;
183
  int value;
184

185
  if ( getCharacterParam( 0, chr ) && getVitalParam( 1, vital ) &&
18✔
186
       getParam( 2, value, Core::VITAL_MAX_HUNDREDTHS ) )
9✔
187
  {
188
    Mobile::VitalValue& vv = chr->vital( vital->vitalid );
9✔
189
    chr->set_current( vital, vv, value, Mobile::Character::VitalDepletedReason::SCRIPT );
9✔
190
    return new BLong( 1 );
9✔
191
  }
192
  return new BError( "Invalid parameter type" );
×
193
}
194

195
BObjectImp* VitalExecutorModule::mf_ConsumeVital( /* mob, vital, hundredths */ )
×
196
{
197
  Mobile::Character* chr;
198
  const Core::Vital* vital;
199
  int hundredths;
200

201
  if ( getCharacterParam( 0, chr ) && getVitalParam( 1, vital ) &&
×
202
       getParam( 2, hundredths, Core::VITAL_MAX_HUNDREDTHS ) )
×
203
  {
204
    Mobile::VitalValue& vv = chr->vital( vital->vitalid );
×
205
    bool res =
206
        chr->consume( vital, vv, hundredths, Mobile::Character::VitalDepletedReason::SCRIPT );
×
207
    return new BLong( res ? 1 : 0 );
×
208
  }
209
  return new BError( "Invalid parameter type" );
×
210
}
211

212
BObjectImp* VitalExecutorModule::mf_RecalcVitals( /* mob, attributes, vitals */ )
2✔
213
{
214
  Mobile::Character* chr;
215
  BObjectImp* param1 = getParamImp( 1 );
2✔
216
  BObjectImp* param2 = getParamImp( 2 );
2✔
217

218
  if ( getCharacterParam( 0, chr ) && param1 != nullptr && param2 != nullptr )
2✔
219
  {
220
    if ( chr->logged_in() )
2✔
221
    {
222
      bool calc_attr = false;
2✔
223
      bool calc_vital = false;
2✔
224

225
      if ( auto* v = impptrIf<BLong>( param1 ) )
2✔
226
        calc_attr = v->isTrue();
2✔
227
      else if ( auto* attrname = impptrIf<String>( param1 ) )
×
228
      {
229
        Mobile::Attribute* attr = Mobile::Attribute::FindAttribute( attrname->value() );
×
230
        if ( attr == nullptr )
×
231
          return new BError( "Attribute not defined: " + attrname->value() );
×
232
        chr->calc_single_attribute( attr );
×
233
      }
234
      else
235
        return new BError( "Invalid parameter type" );
×
236

237
      if ( auto* v = impptrIf<BLong>( param2 ) )
2✔
238
        calc_vital = v->isTrue();
2✔
239
      else if ( auto* vitalname = impptrIf<String>( param2 ) )
×
240
      {
241
        Core::Vital* vital = Core::FindVital( vitalname->value() );
×
242
        if ( vital == nullptr )
×
243
          return new BError( "Vital not defined: " + vitalname->value() );
×
244
        chr->calc_single_vital( vital );
×
245
      }
246
      else
247
        return new BError( "Invalid parameter type" );
×
248

249
      chr->calc_vital_stuff( calc_attr, calc_vital );
2✔
250
      return new BLong( 1 );
2✔
251
    }
252
    return new BError( "Mobile must be online." );
×
253
  }
254
  return new BError( "Invalid parameter type" );
×
255
}
256
}  // namespace Pol::Module
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