Pol  Revision:cb584c9
useskill.cpp
Go to the documentation of this file.
1 
8 #include <stdlib.h>
9 #include <string>
10 
11 #include "../bscript/eprog.h"
12 #include "../clib/refptr.h"
13 #include "../plib/systemstate.h"
14 #include "globals/network.h"
15 #include "mobile/attribute.h"
16 #include "mobile/charactr.h"
17 #include "network/client.h"
18 #include "pktin.h"
19 #include "polclock.h"
20 #include "scrdef.h"
21 #include "scrstore.h"
22 #include "skills.h"
23 #include "ufunc.h"
24 #include "uoskills.h"
25 
26 namespace Pol
27 {
28 namespace Core
29 {
31 {
32  char* params;
33  unsigned int skillnum = (int)strtoul( (char*)msg->data, &params, 10 );
34 
35  if ( skillnum > networkManager.uoclient_general.maxskills )
36  return;
37 
38  const UOSkill& uoskill = GetUOSkill( skillnum );
39  if ( !uoskill.inited )
40  return;
41  const Mobile::Attribute* attrib = uoskill.pAttr;
42 
43  if ( !attrib->disable_core_checks && !CanUseSkill( client ) )
44  return;
45  else if ( !attrib->script_.empty() )
46  {
47  if ( StartSkillScript( client, attrib ) )
48  return;
49  }
50 
51  /*Log("Client#%lu: (%s, acct:%s) No handler for skill %d\n",
52  client->instance_, client->chr->name().c_str(), client->acct->name(), int(skillnum));
53  cerr << "Character " << client->chr->name() << " (acct: " << client->chr->acct->name() <<
54  "): No handler for skill " << int(skillnum) << endl;*/
55  send_sysmessage( client, "That skill cannot be used directly." );
56 }
57 
58 
59 bool StartSkillScript( Network::Client* client, const Mobile::Attribute* attrib )
60 {
61  Mobile::Character* chr = client->chr;
63  attrib->script_, true,
64  /* complain if not found */ Plib::systemstate.config.cache_interactive_scripts );
65 
66  if ( prog.get() != nullptr )
67  {
68  if ( chr->start_skill_script( prog.get() ) )
69  {
70  // Should the script handle the unhiding instead?
71  if ( chr->hidden() && attrib->unhides )
72  chr->unhide();
73  if ( attrib->delay_seconds )
74  {
75  chr->disable_skills_until( poltime() + attrib->delay_seconds );
76  }
77  return true;
78  }
79  }
80  std::string msg = "Unable to start skill script:"; //+attrib->script_.c_str();
81  msg += attrib->script_.c_str();
82  send_sysmessage( client, msg.c_str() );
83 
84  return false;
85 }
86 
88 {
89  Mobile::Character* chr = client->chr;
90 
91  if ( chr->dead() )
92  {
93  private_say_above( chr, chr, "I am dead and cannot do that." );
94  return false;
95  }
96  else if ( chr->skill_ex_active() || chr->casting_spell() )
97  {
98  private_say_above( chr, chr, "I am already performing another action." );
99  return false;
100  }
101  else if ( poltime() < chr->disable_skills_until() )
102  {
103  send_sysmessage( client, "You must wait to perform another action." );
104  return false;
105  }
106  else if ( chr->frozen() )
107  {
108  private_say_above( chr, chr, "I am frozen and cannot do that." );
109  return false;
110  }
111  else if ( chr->paralyzed() )
112  {
113  private_say_above( chr, chr, "I am paralyzed and cannot do that." );
114  return false;
115  }
116 
117  return true;
118 }
119 }
120 }
bool empty() const
Definition: scrdef.h:41
unsigned delay_seconds
Definition: attribute.h:50
ref_ptr< Bscript::EScriptProgram > find_script2(const ScriptDef &script, bool complain_if_not_found, bool cache_script)
Definition: scrstore.cpp:83
bool skill_ex_active() const
Definition: charactr.h:1013
const Mobile::Attribute * pAttr
Definition: uoskills.h:38
SystemState systemstate
Definition: systemstate.cpp:12
Core::PolConfig config
Definition: systemstate.h:43
T * get() const
Definition: refptr.h:176
bool frozen() const
Definition: charactr.h:969
bool casting_spell() const
Definition: charactr.h:1018
bool start_skill_script(Bscript::EScriptProgram *prog)
Definition: chrskuse.cpp:14
Mobile::Character * chr
Definition: client.h:182
bool private_say_above(Character *chr, const UObject *obj, const char *text, unsigned short font, unsigned short color, unsigned int journal_print)
Definition: ufunc.cpp:1328
unsigned short maxskills
Definition: uoclient.h:55
const UOSkill & GetUOSkill(unsigned skillid)
Definition: uoskills.cpp:21
NetworkManager networkManager
Definition: network.cpp:28
bool StartSkillScript(Network::Client *client, const Mobile::Attribute *attrib)
Definition: useskill.cpp:59
bool paralyzed() const
Definition: charactr.h:974
time_t poltime()
Definition: polclock.cpp:102
bool cache_interactive_scripts
Definition: polcfg.h:51
bool CanUseSkill(Network::Client *client)
Definition: useskill.cpp:87
const char * c_str() const
Definition: scrdef.h:42
u8 data[300]
Definition: pktin.h:185
void handle_use_skill(Network::Client *client, PKTIN_12 *msg)
Definition: useskill.cpp:30
Core::ScriptDef script_
Definition: attribute.h:57
Definition: berror.cpp:12
bool dead() const
Definition: charactr.h:931
void send_sysmessage(Network::Client *client, const char *text, unsigned short font, unsigned short color)
Definition: ufunc.cpp:1147
bool hidden() const
Definition: charactr.h:941
UoClientGeneral uoclient_general
Definition: network.h:67