Pol  Revision:4b29d2b
charactr.h
Go to the documentation of this file.
1 
32 #ifndef __CHARACTR_H
33 #define __CHARACTR_H
34 
35 #include <ctime>
36 #include <map>
37 #include <set>
38 #include <string>
39 #include <vector>
40 
41 #include "../../bscript/bobject.h"
42 #include "../../clib/compilerspecifics.h"
43 #include "../../clib/passert.h"
44 #include "../../clib/rawtypes.h"
45 #include "../../clib/refptr.h"
46 #include "../../clib/strset.h"
47 #include "../../clib/weakptr.h"
48 #include "../action.h"
49 #include "../baseobject.h"
50 #include "../dynproperties.h"
51 #include "../gameclck.h"
52 #include "../polclock.h"
53 #include "../reftypes.h"
54 #include "../skillid.h"
55 #include "../uconst.h"
56 #include "../uobject.h"
57 #include "../utype.h"
58 #include "attribute.h"
59 
60 namespace Pol
61 {
62 namespace Bscript
63 {
64 class Executor;
65 } // namespace Bscript
66 namespace Clib
67 {
68 class StreamWriter;
69 } // namespace Clib
70 namespace Core
71 {
72 class UContainer;
73 class WornItemsContainer;
74 } // namespace Core
75 namespace Mobile
76 {
77 class Character;
78 } // namespace Mobile
79 } // namespace Pol
80 
81 namespace Pol
82 {
83 namespace Bscript
84 {
85 class BObjectImp;
86 class EScriptProgram;
87 class ObjArray;
88 }
89 namespace Clib
90 {
91 class ConfigElem;
92 }
93 namespace Accounts
94 {
95 class Account;
96 }
97 namespace Network
98 {
99 class Client;
100 }
101 namespace Items
102 {
103 class Item;
104 class UArmor;
105 class UWeapon;
106 }
107 namespace Core
108 {
109 class Guild;
110 class Menu;
111 class MenuItem;
112 class OneShotTask;
113 class Party;
114 class RepSystem;
115 class SaveContext;
116 class Spellbook;
117 class TargetCursor;
118 class UOExecutor;
119 class USpell;
120 class Vital;
121 struct PKTIN_00;
122 struct PKTIN_7D;
123 struct PKTIN_8D;
124 struct PKTIN_F8;
125 
126 void ClientCreateChar( Network::Client* client, PKTIN_00* msg );
127 void ClientCreateCharKR( Network::Client* client, PKTIN_8D* msg );
128 void ClientCreateChar70160( Network::Client* client, PKTIN_F8* msg );
129 void createchar2( Accounts::Account* acct, unsigned index );
130 void undo_get_item( Mobile::Character* chr, Items::Item* item );
131 void write_characters( SaveContext& sc );
132 void write_npcs( SaveContext& sc );
133 }
134 namespace Module
135 {
136 class UOExecutorModule;
137 }
138 namespace Mobile
139 {
140 class Attribute;
141 class Character;
142 class PrivUpdater;
143 
145 {
146 public:
147  AttributeValue() : _base( 0 ), _temp( 0 ), _intrinsic( 0 ), _lockstate( 0 ), _cap( 0 ) {}
148  int effective() const
149  {
150  int v = _base;
151  v += _temp;
152  v += _intrinsic;
153  return ( v > 0 ) ? ( v / 10 ) : 0;
154  }
155  int effective_tenths() const
156  {
157  int v = _base;
158  v += _temp;
159  v += _intrinsic;
160  return ( v > 0 ) ? v : 0;
161  }
162 
163  int base() const { return _base; }
164  void base( unsigned short base )
165  {
166  passert( base <= ATTRIBUTE_MAX_BASE );
167  _base = base;
168  }
169 
170  int temp_mod() const { return _temp; }
171  void temp_mod( short temp ) { _temp = temp; }
172  int intrinsic_mod() const { return _intrinsic; }
173  void intrinsic_mod( short val ) { _intrinsic = val; }
174  unsigned char lock() const { return _lockstate; }
175  void lock( unsigned char lockstate ) { _lockstate = lockstate; }
176  unsigned short cap() const { return _cap; }
177  void cap( unsigned short cap ) { _cap = cap; }
178 
179 private:
180  unsigned short _base;
181  short _temp;
182  short _intrinsic; // humm, a vector here?
183  unsigned char _lockstate;
184  unsigned short _cap;
185 };
186 
188 {
189 public:
190  VitalValue() : _current( 0 ), _maximum( 0 ), _regenrate( 0 ) {}
191  // accessors:
192  int current() const { return _current; }
193  int current_ones() const { return _current / 100; }
194  int current_thousands() const
195  {
196  // use division to prevent overflow
197  return ( _current / 100 ) * 1000 / ( _maximum / 100 );
198  }
199  int maximum() const { return _maximum; }
200  int maximum_ones() const { return _maximum / 100; }
201  bool is_at_maximum() const { return ( _current >= _maximum ); }
202  int regenrate() const { return _regenrate; }
203  // mutators:
204 protected:
205  friend class Character;
206  void current( int cur )
207  {
208  _current = cur;
209  if ( _current > _maximum )
210  current( _maximum );
211  }
212  void current_ones( int ones )
213  {
214  _current = ones * 100;
215  if ( _current > _maximum )
216  current( _maximum );
217  }
218  void maximum( int val )
219  {
220  _maximum = val;
221  if ( _current > _maximum )
222  current( _maximum );
223  }
224  void regenrate( int rate ) { _regenrate = rate; }
225  bool consume( unsigned int hamt )
226  {
227  if ( _current >= hamt )
228  {
229  _current -= hamt;
230  return true;
231  }
232  else
233  {
234  _current = 0;
235  return false;
236  }
237  }
238  void produce( unsigned int hamt )
239  {
240  unsigned newcur = _current + hamt;
241  if ( newcur > _maximum || newcur < _current )
242  {
243  _current = _maximum;
244  }
245  else
246  {
247  _current = newcur;
248  }
249  }
250 
251 private:
252  unsigned int _current; // 0 to 10000000 [0 to 100000.00]
253  unsigned int _maximum;
254  int _regenrate; // in hundredths of points per minute
255 };
256 
260 struct Buff
261 {
262  // Polclock when the buff will end (only for displaying countdown)
264  // Name cliloc ID
266  // Description cliloc ID
268  // Unicode string, arguments to be replaced in cl_descr, separated by tabs
269  // TODO: use a real unicode string class, maybe a vector of them
270  std::vector<u32> arguments;
271 };
272 
274 {
277 };
278 inline bool operator<( const reportable_t& lhs, const reportable_t& rhs )
279 {
280  return ( lhs.serial < rhs.serial ) || ( lhs.serial == rhs.serial && lhs.polclock < rhs.polclock );
281 }
282 
283 enum class PRIV_FLAGS : u32
284 {
285  MOVE_ANY = 1 << 0, // should everything be moveable?
286  MOVE_ANY_DIST = 1 << 1,
287  RENAME_ANY = 1 << 2, // should everything be renameable?
288  CLOTHE_ANY = 1 << 3,
289  INVUL = 1 << 4,
290  SEE_HIDDEN = 1 << 5,
291  SEE_GHOSTS = 1 << 6,
292  HEAR_GHOSTS = 1 << 7,
293  SEE_INVIS_ITEMS = 1 << 8,
294  DBLCLICK_ANY = 1 << 9,
295  LOS_ANY = 1 << 19, // all targetting ignore LOS?
296  IGNORE_DOORS = 1 << 11,
297  FREEMOVE = 1 << 12,
298  FIRE_WHILE_MOVING = 1 << 13,
299  ATTACK_HIDDEN = 1 << 14,
300  HIDDEN_ATTACK = 1 << 15,
301  PLOG_ANY = 1 << 16,
302  CAN_BE_HEARD_AS_GHOST = 1 << 17,
303  RUN_WHILE_STEALTH = 1 << 18,
304  SPEEDHACK = 1 << 19,
305 
306  ALL = ~0u, // all bits set
307 };
308 
309 
310 enum class MOB_FLAGS : u16
311 {
312  READY_TO_SWING = 1 << 0,
313  MURDERER = 1 << 1,
314  PARTY_CAN_LOOT = 1 << 2,
315  TRADE_ACCEPTED = 1 << 3,
316  DEAD = 1 << 4,
317  HIDDEN = 1 << 5,
318  FROZEN = 1 << 6,
319  PARALYZED = 1 << 7,
320  WARMODE = 1 << 8,
321  POISONED = 1 << 9,
322  LOGGED_IN = 1 << 10, // for NPCs, this is always true.
323  CONNECTED = 1 << 11,
324  USE_ADJUSTMENTS = 1 << 12, // NPCs
325 };
326 
327 // NOTES:
328 // The location of the wornitems container MUST be updated whenever the character
329 // moves. This is so that range checks for things in his pack will succeed.
330 //
331 // Consider: make a class, UCreature, derived from UObject. Character would derive from
332 // this, as might NPC.
333 
334 class Character : public Core::UObject
335 {
336  // types:
337  typedef UObject base;
338  typedef std::set<Character*> CharacterSet;
339 
340 public:
341  explicit Character( u32 objtype,
343  virtual ~Character();
344 
345 private:
346  // non-implemented functions:
347  Character( const Character& );
348  Character& operator=( const Character& );
349 
350  // UOBJECT INTERFACE
351 public:
352  virtual size_t estimatedSize() const POL_OVERRIDE;
353 
354  virtual void destroy() POL_OVERRIDE;
355  virtual unsigned int weight() const POL_OVERRIDE;
356 
357  virtual bool setgraphic( u16 newobjtype ) POL_OVERRIDE;
358  virtual void on_color_changed() POL_OVERRIDE;
359  virtual void setfacing( u8 newfacing ) POL_OVERRIDE;
360  virtual void on_facing_changed() POL_OVERRIDE;
361 
362  virtual void readProperties( Clib::ConfigElem& elem ) POL_OVERRIDE;
363 
364  virtual Bscript::BObjectImp* make_ref() POL_OVERRIDE;
365 
366  virtual Bscript::BObjectImp* get_script_member( const char* membername ) const POL_OVERRIDE;
367  virtual Bscript::BObjectImp* get_script_member_id( const int id ) const POL_OVERRIDE; // id test
368  virtual Bscript::BObjectImp* set_script_member( const char* membername,
369  const std::string& value ) POL_OVERRIDE;
370  virtual Bscript::BObjectImp* set_script_member( const char* membername, int value ) POL_OVERRIDE;
371  virtual Bscript::BObjectImp* set_script_member_id( const int id, const std::string& value )
372  POL_OVERRIDE; // id test
373  virtual Bscript::BObjectImp* set_script_member_id( const int id,
374  int value ) POL_OVERRIDE; // id test
375  virtual Bscript::BObjectImp* set_script_member_id_double( const int id,
376  double value ) POL_OVERRIDE;
377  virtual Bscript::BObjectImp* script_method( const char* methodname,
378  Bscript::Executor& ex ) POL_OVERRIDE;
379  virtual Bscript::BObjectImp* script_method_id( const int id, Bscript::Executor& ex ) POL_OVERRIDE;
380  virtual Bscript::BObjectImp* custom_script_method( const char* methodname,
381  Bscript::Executor& ex ) POL_OVERRIDE;
382  virtual bool script_isa( unsigned isatype ) const POL_OVERRIDE;
383  virtual const char* target_tag() const POL_OVERRIDE;
384 
385 protected:
386  virtual const char* classname() const POL_OVERRIDE;
387  virtual void printOn( Clib::StreamWriter& sw ) const POL_OVERRIDE;
388  virtual void printSelfOn( Clib::StreamWriter& sw ) const POL_OVERRIDE;
389  virtual void printProperties( Clib::StreamWriter& sw ) const POL_OVERRIDE;
390  virtual void printDebugProperties( Clib::StreamWriter& sw ) const POL_OVERRIDE;
391 
392 public:
393  Bscript::BObjectImp* make_offline_ref();
394 
395  // NPC INTERFACE
396 public:
397  virtual Items::UWeapon* intrinsic_weapon();
398 
399  virtual void inform_disengaged( Character* disengaged );
400  virtual void inform_engaged( Character* engaged );
401  virtual void inform_criminal( Character* thecriminal );
402  virtual void inform_leftarea( Character* wholeft );
403  virtual void inform_enteredarea( Character* whoentered );
404  virtual void inform_moved( Character* moved );
405  virtual void inform_imoved( Character* chr );
406  virtual double armor_absorb_damage( double damage );
407  virtual void get_hitscript_params( double damage, Items::UArmor** parmor,
408  unsigned short* rawdamage );
409  virtual unsigned short ar() const;
410  virtual void refresh_ar();
411 
412  virtual void apply_raw_damage_hundredths( unsigned int damage, Character* source,
413  bool userepsys = true,
414  bool send_damage_packet = false );
415  void on_swing_failure( Character* attacker );
416  virtual void on_death( Items::Item* corpse );
417 
418  virtual bool can_be_renamed_by( const Character* chr ) const;
419 
420  virtual void repsys_on_attack( Character* defender );
421  virtual void repsys_on_damage( Character* defender );
422  virtual void repsys_on_help( Character* recipient );
423  virtual unsigned char hilite_color_idx( const Character* seen_by ) const;
424  virtual unsigned short name_color( const Character* seen_by ) const;
425 
426 protected:
427  virtual u16 get_damaged_sound() const;
428 
429  // EQUIPMENT / ITEMS
430 public:
431  unsigned short carrying_capacity() const;
432  bool layer_is_equipped( int layer ) const;
433 
434  bool strong_enough_to_equip( const Items::Item* item ) const;
435  bool equippable( const Items::Item* item ) const;
436  bool is_equipped( const Items::Item* item ) const;
437  void equip( Items::Item* item ); // You MUST check equippable() before calling this
438  void unequip( Items::Item* item );
439 
440  Core::Spellbook* spellbook( u8 school ) const;
441  Core::UContainer* backpack() const;
442  Items::Item* wornitem( int layer ) const;
443  unsigned int gold_carried() const;
444  void spend_gold( unsigned int amount );
445 
446  DYN_PROPERTY_POINTER( gotten_item, Items::Item*, Core::PROP_GOTTEN_BY );
447  void clear_gotten_item();
448 
449  void add_remote_container( Items::Item* );
450  Items::Item* search_remote_containers( u32 find_serial, bool* isRemoteContainer ) const;
451  bool mightsee( const Items::Item* item ) const;
452 
453  Items::Item* find_wornitem( u32 find_serial ) const;
454  bool has_shield() const;
455  Items::UArmor* get_shield() const;
456 
457  // MOVEMENT
458 public:
459  bool on_mount() const;
460  static Core::MOVEMODE decode_movemode( const std::string& str );
461  static std::string encode_movemode( Core::MOVEMODE movemode );
462  // if a move were made, what would the new position be?
463  void getpos_ifmove( Core::UFACING i_facing, unsigned short* px, unsigned short* py );
464  bool can_face( Core::UFACING i_facing );
465  bool face( Core::UFACING i_facing, int flags = 0 );
466  bool move( unsigned char dir );
467  bool CustomHousingMove( unsigned char i_dir );
468  void tellmove( void );
469  void check_region_changes();
470  void check_weather_region_change( bool force = false );
471  void check_light_region_change();
472  void check_justice_region_change();
473  void check_music_region_change();
474  void realm_changed();
475 
476  bool CheckPushthrough();
477  // KLUDGE - a more foolproof way is needed to keep this in sync.
478  void position_changed( void );
479 
480  // COMBAT
481 public:
482  void select_opponent( u32 opp_serial );
483  void set_opponent( Character* opponent, bool inform_old_opponent = true );
484 
485  void clear_opponent_of();
486 
487  void send_warmode();
488  unsigned short get_weapon_skill() const;
489  Core::USKILLID weapon_skillid() const;
490  const AttributeValue& weapon_attribute() const;
491 
492  Core::UACTION weapon_anim() const;
493  unsigned short random_weapon_damage() const;
494  unsigned short min_weapon_damage() const;
495  unsigned short max_weapon_damage() const;
496  void damage_weapon();
497  void do_attack_effects( Character* target );
498  void do_imhit_effects();
499  void do_hit_success_effects();
500  void do_hit_failure_effects();
501 
502  bool is_attackable( Character* who ) const;
503  Character* get_opponent() const;
504  Character* get_attackable_opponent() const;
505 
506  Items::UArmor* choose_armor() const;
507 
508  void showarmor() const;
509 
510  void reset_swing_timer();
511  void check_attack_after_move();
512  void attack( Character* opponent );
513  void send_highlight() const;
514  bool manual_set_swing_timer( int time );
515 
516  const CharacterSet& hostiles() const;
517  void run_hit_script( Character* defender, double damage );
518 
519 private:
520  void schedule_attack();
521  static void swing_task_func( Character* chr );
522 
523  // ATTRIBUTES / VITALS
524 public:
525  void disable_regeneration_for( int seconds );
526  void resetEquipableProperties();
527  void updateEquipableProperties( Items::Item* item );
528 
529  u16 strength() const;
530  u16 intelligence() const;
531  u16 dexterity() const;
532 
533  u16 max_hits() const;
534  u32 max_hits_hundredths() const;
535  u16 max_mana() const;
536  u16 max_stamina() const;
537 
538  void set_strength( u16 strength );
539  void set_intelligence( u16 intelligence );
540  void set_dexterity( u16 dexterity );
541  void validate_stat_ranges();
542 
543  double apply_damage( double damage, Character* source = nullptr, bool userepsys = true,
544  bool send_damage_packet = false );
545  void heal_damage_hundredths( unsigned int damage );
546 
547  void resurrect();
548  void die();
549  bool dead() const;
550  bool check_skill( Core::USKILLID skillid, int difficulty, unsigned short pointvalue );
551 
552  const AttributeValue& attribute( unsigned attrid ) const;
553  AttributeValue& attribute( unsigned attrid );
554  void set_caps_to_default();
555 
556  const VitalValue& vital( unsigned vitalid ) const;
557  VitalValue& vital( unsigned vitalid );
558  void regen_vital( const Core::Vital* ); // throw()
559  void calc_vital_stuff( bool i_mod = true, bool v_mod = true ); // throw()
560  void calc_single_vital( const Core::Vital* pVital );
561  void calc_single_attribute( const Attribute* pAttr );
562  void set_vitals_to_maximum(); // throw();
563  void produce( const Core::Vital* pVital, VitalValue& vv, unsigned int amt );
564  bool consume( const Core::Vital* pVital, VitalValue& vv, unsigned int amt );
565  void set_current_ones( const Core::Vital* pVital, VitalValue& vv, unsigned int ones );
566  void set_current( const Core::Vital* pVital, VitalValue& vv, unsigned int ones );
567 
568  // REPUTATION
569 public:
570  friend class Core::RepSystem;
571 
572  Bscript::ObjArray* GetReportables() const;
573  Bscript::ObjArray* GetAggressorTo() const;
574  Bscript::ObjArray* GetLawFullyDamaged() const;
575 
576  bool is_aggressor_to( const Character* chr ) const;
577  void restart_aggressor_timer( Character* chr, Core::polclock_t until );
578  void remove_as_aggressor_to( Character* chr );
579 
580  bool has_lawfully_damaged( const Character* chr ) const;
581  void restart_lawfully_damaged_timer( Character* chr, Core::polclock_t until );
582  void remove_as_lawful_damager( Character* chr );
583 
584  bool is_criminal() const;
585  bool is_temporally_criminal() const;
586  void restart_criminal_timer( Core::polclock_t until );
587  void clear_criminal_timer();
588 
589  bool is_murderer() const;
590  bool is_innocent_to( const Character* chr ) const;
591  void make_criminal( int level = 1 );
592  void make_murderer( bool newlval = true );
593  void make_aggressor_to( Character* chr );
594  void make_lawfullydamaged_to( Character* chr );
595 
596  void add_to_be_reportable( u32 serial );
597  void clear_to_be_reportables();
598  void commit_to_reportables();
599  void clear_reportable( u32 serial, Core::polclock_t time );
600  void clear_my_aggressors();
601  void clear_my_lawful_damagers();
602  void check_undamaged();
603 
604  void on_criminal_changed();
605  void on_murderer_changed();
606  void on_aggressor_changed();
607  void on_lawfullydamaged_changed();
608 
609  // GUILD
610 public:
611  DYN_PROPERTY_POINTER( guild, Core::Guild*, Core::PROP_GUILD );
612  unsigned int guildid() const;
613  bool is_guild_ally( const Character* chr ) const;
614  bool is_guild_enemy( const Character* chr ) const;
615 
616  // PARTY
617 public:
618  DYN_PROPERTY_POINTER( party, Core::Party*, Core::PROP_PARTY );
619  DYN_PROPERTY_POINTER( candidate_of, Core::Party*, Core::PROP_PARTY_CANDIDATE );
620  DYN_PROPERTY_POINTER( offline_mem_of, Core::Party*, Core::PROP_PARTY_OFFLINE );
621  bool party_can_loot() const;
622  void set_party_can_loot( bool );
623  void set_party_invite_timeout();
624  bool has_party_invite_timeout() const;
625  void cancel_party_invite_timeout();
626 
627  // SECURE TRADING
628 public:
629  bool is_trading() const;
630  void create_trade_container();
631  Core::UContainer* trade_container();
632  bool trade_accepted() const;
633  void trade_accepted( bool newvalue );
634 
635  // SCRIPT
636 public:
637  void schedule_spell( Core::USpell* );
638  bool casting_spell() const;
639  bool skill_ex_active() const;
640  bool start_script( Bscript::EScriptProgram* prog, bool start_attached,
641  Bscript::BObjectImp* param2 = nullptr, Bscript::BObjectImp* param3 = nullptr,
642  Bscript::BObjectImp* param4 = nullptr );
643  bool start_skill_script( Bscript::EScriptProgram* prog );
644  bool start_itemuse_script( Bscript::EScriptProgram* prog, Items::Item* item,
645  bool start_attached );
646  bool start_spell_script( Bscript::EScriptProgram* prog, Core::USpell* spell );
647  void cancel_menu();
648 
649 private:
650  friend void handle_script_cursor( Character* chr, UObject* obj );
651  friend void menu_selection_made( Network::Client* client, Core::MenuItem* mi,
652  Core::PKTIN_7D* msg );
653  friend class Module::UOExecutorModule;
654  void stop_skill_script();
655 
656  // CLIENT
657 public:
658  bool logged_in() const;
659  void logged_in( bool newvalue );
660  bool connected() const;
661  void connected( bool newvalue );
662  bool has_active_client() const;
663  bool has_active_prompt() const;
664  bool has_active_gump() const;
665  bool is_house_editing() const;
666  bool target_cursor_busy() const;
667  u16 last_textcolor() const;
668  void last_textcolor( u16 new_color );
669 
670  u8 get_flag1( Network::Client* other_client ) const;
671 
672  // PRIVS SETTINGS STATUS
673 public:
674  void on_aos_ext_stat_changed();
675  void on_cmdlevel_changed();
676  void on_poison_changed();
677  void on_hidden_changed();
678  void on_concealed_changed();
679 
680  bool warmode() const;
681  void set_warmode( bool warmode );
682  void set_stealthsteps( unsigned short newval );
683  bool doors_block() const;
684  bool ignores_line_of_sight() const;
685 
686  bool is_visible() const; // meant to combine "hiding", "concealed", "invisible" etc.
687  bool is_visible_to_me( const Character* chr ) const;
688  bool hidden() const;
689  void hidden( bool value );
690  void unhide();
691  unsigned char concealed() const;
692  void concealed( unsigned char value );
693  bool is_concealed_from_me( const Character* chr ) const;
694  bool invul() const;
695  bool frozen() const;
696  bool paralyzed() const;
697  bool squelched() const;
698  bool deafened() const;
699  bool poisoned() const;
700  void poisoned( bool value );
701  unsigned char cmdlevel() const;
702  void cmdlevel( unsigned char value, bool update_on_change = true );
703 
704  // Tests whether item is at a legal location and within reach of the character (range).
705  // Range == -1 takes the default accessible distance,
706  // any smaller negative number ignores the range check.
707  bool can_access( const Items::Item* item, int range = -1 ) const;
708 
709  bool can_move( const Items::Item* item ) const;
710  bool can_rename( const Character* chr ) const;
711  bool can_clothe( const Character* chr ) const;
712  bool can_hearghosts() const;
713  bool can_be_heard_as_ghost() const;
714  bool can_seeinvisitems() const;
715  bool can_dblclickany() const;
716  bool can_moveanydist() const;
717  bool can_plogany() const;
718  bool can_speedhack() const;
719  bool can_freemove() const;
720 
721  bool has_privilege( const char* priv ) const;
722  bool setting_enabled( const char* setting ) const;
723  void grant_privilege( const char* priv );
724  void revoke_privilege( const char* priv );
725  void set_setting( const char* setting, bool value );
726  std::string all_settings() const;
727  std::string all_privs() const;
728  void set_privs( const std::string& privlist );
729 
730  void check_concealment_level();
731 
732 private:
733  void refresh_cached_settings( bool update = true );
734 
735  // SERIALIZATION
736 public:
737  void readCommonProperties( Clib::ConfigElem& elem );
738  void readAttributesAndVitals( Clib::ConfigElem& elem );
739 
740 protected:
741  friend void Core::write_characters( Core::SaveContext& sc );
742  friend void Core::write_npcs( Core::SaveContext& sc );
743 
744  void printWornItems( Clib::StreamWriter& sw_pc, Clib::StreamWriter& sw_equip ) const;
745 
746  // CREATION
747 private:
748  friend void Core::ClientCreateChar( Network::Client* client, Core::PKTIN_00* msg );
749  friend void Core::ClientCreateCharKR( Network::Client* client, Core::PKTIN_8D* msg );
750  friend void Core::ClientCreateChar70160( Network::Client* client, Core::PKTIN_F8* msg );
751  friend void Core::createchar2( Accounts::Account* acct, unsigned index );
752 
753  // MISC
754 public:
755  void removal_cleanup();
756  void disconnect_cleanup();
757  int charindex() const; // find account character index, or -1 if not found.
758  void on_delete_from_account();
759 
760 protected:
761  friend void Core::undo_get_item( Character* chr,
762  Items::Item* item ); // this just gets uglier and uglier.
763 
764  // BUFF/DEBUFF BAR
765 public:
766  void addBuff( u16 icon, u16 duration, u32 cl_name, u32 cl_descr,
767  const std::vector<u32>& arguments );
768  bool delBuff( u16 icon );
769  void clearBuffs();
770  void send_buffs();
771 
772  // ==========================================================
773  // DATA:
774  // ==========================================================
775  // UOBJECT INTERFACE
776 
777  // NPC INTERFACE
778 protected:
779  // EQUIPMENT / ITEMS
780 protected:
781  DYN_PROPERTY( carrying_capacity_mod, s16, Core::PROP_CARRY_CAPACITY_MOD, 0 );
782 
783  Items::UWeapon* weapon;
784  Items::UArmor* shield;
785  std::vector<Items::UArmor*> armor_;
786 
787  ref_ptr<Core::WornItemsContainer> wornitems;
788 
789 public:
791  {
794  GOTTEN_ITEM_IN_CONTAINER
795  } gotten_item_source;
796 
797  std::vector<Core::ItemRef> remote_containers_; // does not own its objects
798  // MOVEMENT
799 public:
800  u8 dir; // the entire 'dir' from their last MSG02_WALK
802  u16 lastx, lasty; // position before their last MSG02_WALK
804 
805  enum MOVEREASON : u8
806  {
807  WALKED = 0,
808  OTHER = 0,
809  MULTIMOVE = 1
810  } move_reason;
812  DYN_PROPERTY( lightoverride, int, Core::PROP_LIGHTOVERRIDE, -1 );
814 
817  // COMBAT
818 public:
820 
821 protected:
823  DYN_PROPERTY( ar_mod, s16, Core::PROP_AR_MOD, 0 );
824  DYN_PROPERTY( delay_mod, s16, Core::PROP_DELAY_MOD, 0 );
825  DYN_PROPERTY( hitchance_mod, s16, Core::PROP_HITCHANCE_MOD, 0 );
826  DYN_PROPERTY( evasionchance_mod, s16, Core::PROP_EVASIONCHANCE_MOD, 0 );
827 
829  CharacterSet opponent_of;
832  // ATTRIBUTES / VITALS
833 public:
835  std::vector<AttributeValue> attributes;
836  std::vector<VitalValue> vitals;
837  // REPUTATION
838 private:
839  typedef std::map<Core::CharacterRef, Core::polclock_t> MobileCont;
840  typedef std::set<reportable_t> ReportableList;
841  typedef std::set<USERIAL> ToBeReportableList;
842 
843  mutable MobileCont aggressor_to_;
844  mutable MobileCont lawfully_damaged_;
847  ToBeReportableList to_be_reportable_;
848  ReportableList reportable_;
849  // GUILD
850 private:
851  // PARTY
852 private:
854  // SECURE TRADING
855 public:
858  // SCRIPT
859 public:
860  DYN_PROPERTY( disable_skills_until, time_t, Core::PROP_DISABLE_SKILLS_UNTIL, 0 );
862  weak_ptr<Core::Menu> menu; // TODO: Move this into the client's gamedata
863  void ( *on_menu_selection )( Network::Client* client, Core::MenuItem* mi, Core::PKTIN_7D* msg );
864  void ( *on_popup_menu_selection )( Network::Client* client, u32 serial, u16 id );
865 
866 protected:
869  // CLIENT
870 public:
872  std::string uclang;
873 
874 private:
876  // PRIVS SETTINGS STATUS
877 public:
879 
886 
887 protected:
888  u8 concealed_; // 0 to cmdlevel
891 
894  friend class PrivUpdater;
897 
900 
901 private:
902  // SERIALIZATION
903 
904  // CREATION
905 protected:
907 
908  // BUFF/DEBUFF BAR
909 protected:
910  std::map<u16, Buff> buffs_; // indexed by icon ID
911 
912  // MISC
913 public:
921 
922  DYN_PROPERTY( dblclick_wait, u32, Core::PROP_DOUBLECLICK_WAIT, 0 );
923 
924  DYN_PROPERTY( title_prefix, std::string, Core::PROP_TITLE_PREFIX, "" );
925  DYN_PROPERTY( title_suffix, std::string, Core::PROP_TITLE_SUFFIX, "" );
926  DYN_PROPERTY( title_guild, std::string, Core::PROP_TITLE_GUILD, "" );
927  DYN_PROPERTY( title_race, std::string, Core::PROP_TITLE_RACE, "" );
928 };
929 
930 
931 inline bool Character::dead() const
932 {
933  return mob_flags_.get( MOB_FLAGS::DEAD );
934 }
935 
936 inline bool Character::is_visible() const
937 {
938  return !( hidden() || concealed_ );
939 }
940 
941 inline bool Character::hidden() const
942 {
943  return mob_flags_.get( MOB_FLAGS::HIDDEN );
944 }
945 
946 inline void Character::hidden( bool value )
947 {
948  if ( value != hidden() )
949  {
950  mob_flags_.change( MOB_FLAGS::HIDDEN, value );
951  on_hidden_changed();
952  }
953 }
954 
955 inline unsigned char Character::concealed() const
956 {
957  return concealed_;
958 }
959 
960 inline void Character::concealed( unsigned char value )
961 {
962  if ( concealed_ != value )
963  {
964  concealed_ = value;
965  on_concealed_changed();
966  }
967 }
968 
969 inline bool Character::frozen() const
970 {
971  return mob_flags_.get( MOB_FLAGS::FROZEN );
972 }
973 
974 inline bool Character::paralyzed() const
975 {
976  return mob_flags_.get( MOB_FLAGS::PARALYZED );
977 }
978 
979 inline bool Character::poisoned() const
980 {
981  return mob_flags_.get( MOB_FLAGS::POISONED );
982 }
983 
984 inline void Character::poisoned( bool value )
985 {
986  if ( value != poisoned() )
987  {
988  mob_flags_.change( MOB_FLAGS::POISONED, value );
989  on_poison_changed();
990  }
991 }
992 
993 inline unsigned char Character::cmdlevel() const
994 {
995  return cmdlevel_;
996 }
997 
998 inline void Character::cmdlevel( unsigned char value, bool update_on_change )
999 {
1000  if ( cmdlevel_ != value )
1001  {
1002  cmdlevel_ = value;
1003  if ( update_on_change )
1004  on_cmdlevel_changed();
1005  }
1006 }
1007 
1008 inline unsigned short Character::ar() const
1009 {
1010  return ar_;
1011 }
1012 
1013 inline bool Character::skill_ex_active() const
1014 {
1015  return ( script_ex != nullptr );
1016 }
1017 
1018 inline bool Character::casting_spell() const
1019 {
1020  return ( spell_task != nullptr );
1021 }
1022 
1024 {
1025  return opponent_of;
1026 }
1027 
1029 {
1030  return cached_settings.get( PRIV_FLAGS::LOS_ANY );
1031 }
1032 inline bool Character::can_seeinvisitems() const
1033 {
1034  return cached_settings.get( PRIV_FLAGS::SEE_INVIS_ITEMS );
1035 }
1036 inline bool Character::can_dblclickany() const
1037 {
1038  return cached_settings.get( PRIV_FLAGS::DBLCLICK_ANY );
1039 }
1040 
1041 inline bool Character::has_shield() const
1042 {
1043  return ( shield != nullptr );
1044 }
1045 
1047 {
1048  return shield;
1049 }
1050 
1051 inline const AttributeValue& Character::attribute( unsigned attrid ) const
1052 {
1053  passert( attrid < attributes.size() );
1054  return attributes[attrid];
1055 }
1056 inline AttributeValue& Character::attribute( unsigned attrid )
1057 {
1058  passert( attributes.size() > attrid );
1059  return attributes[attrid];
1060 }
1061 inline const VitalValue& Character::vital( unsigned vitalid ) const
1062 {
1063  passert( vitals.size() > vitalid );
1064  return vitals[vitalid];
1065 }
1066 inline VitalValue& Character::vital( unsigned vitalid )
1067 {
1068  passert( vitalid < vitals.size() );
1069  return vitals[vitalid];
1070 }
1071 
1072 // dave moved this here from .cpp 2/3/3 so i can use it in uoemod.cpp
1073 inline void NpcPropagateMove( Character* chr, Character* moved )
1074 {
1075  if ( chr != moved )
1076  {
1077  chr->inform_moved( moved );
1078  moved->inform_imoved( chr );
1079  }
1080 }
1081 
1082 inline void NpcPropagateCriminal( Character* chr, Character* thecriminal )
1083 {
1084  if ( chr != thecriminal )
1085  chr->inform_criminal( thecriminal );
1086 }
1087 
1088 inline void NpcPropagateLeftArea( Character* chr, Character* wholeft )
1089 {
1090  if ( chr != wholeft )
1091  {
1092  chr->inform_leftarea( wholeft );
1093  }
1094 }
1095 
1096 inline void NpcPropagateEnteredArea( Character* chr, Character* whoentered )
1097 {
1098  if ( chr != whoentered )
1099  {
1100  chr->inform_enteredarea( whoentered );
1101  }
1102 }
1103 }
1104 }
1105 #endif
void handle_script_cursor(Character *chr, UObject *obj)
Definition: uomod.cpp:765
unsigned char u8
Definition: rawtypes.h:25
ToBeReportableList to_be_reportable_
Definition: charactr.h:847
bool poisoned() const
Definition: charactr.h:979
void ClientCreateChar(Network::Client *client, PKTIN_00 *msg)
Definition: create.cpp:201
unsigned int gameclock_t
Definition: gameclck.h:14
Character * opponent_
Definition: charactr.h:828
unsigned int _maximum
Definition: charactr.h:253
#define POL_OVERRIDE
Core::gameclock_t created_at
Definition: charactr.h:906
void NpcPropagateMove(Character *chr, Character *moved)
Definition: charactr.h:1073
void current_ones(int ones)
Definition: charactr.h:212
void maximum(int val)
Definition: charactr.h:218
bool operator<(T *ptr, const ref_ptr< T > &rptr)
Definition: refptr.h:323
unsigned char lock() const
Definition: charactr.h:174
bool skill_ex_active() const
Definition: charactr.h:1013
bool can_dblclickany() const
Definition: charactr.h:1036
unsigned char concealed() const
Definition: charactr.h:955
unsigned short cap() const
Definition: charactr.h:176
Network::Client * client
Definition: charactr.h:871
std::map< u16, Buff > buffs_
Definition: charactr.h:910
MobileCont lawfully_damaged_
Definition: charactr.h:844
int current_thousands() const
Definition: charactr.h:194
Core::UOExecutor * script_ex
Definition: charactr.h:867
time_t disable_regeneration_until
Definition: charactr.h:834
Core::polclock_t polclock
Definition: charactr.h:276
void current(int cur)
Definition: charactr.h:206
static const SkillStatCap DEFAULT
Items::UArmor * get_shield() const
Definition: charactr.h:1046
bool is_visible() const
Definition: charactr.h:936
std::set< reportable_t > ReportableList
Definition: charactr.h:840
STL namespace.
unsigned char cmdlevel() const
Definition: charactr.h:993
Core::TargetCursor * tcursor2
Definition: charactr.h:861
std::map< Core::CharacterRef, Core::polclock_t > MobileCont
Definition: charactr.h:839
bool frozen() const
Definition: charactr.h:969
bool casting_spell() const
Definition: charactr.h:1018
static const ExtStatBarFollowers DEFAULT
Clib::StringSet privs
Definition: charactr.h:892
std::string uclang
Definition: charactr.h:872
std::vector< AttributeValue > attributes
Definition: charactr.h:835
void cap(unsigned short cap)
Definition: charactr.h:177
void menu_selection_made(Network::Client *client, MenuItem *mi, PKTIN_7D *msg)
Definition: uomod.cpp:1544
int current_ones() const
Definition: charactr.h:193
bool can_seeinvisitems() const
Definition: charactr.h:1032
void NpcPropagateLeftArea(Character *chr, Character *wholeft)
Definition: charactr.h:1088
Core::UGENDER gender
Definition: charactr.h:918
void NpcPropagateEnteredArea(Character *chr, Character *whoentered)
Definition: charactr.h:1096
MOVEMODE
Definition: uconst.h:79
void write_npcs(SaveContext &sc)
Definition: uimport.cpp:875
void undo_get_item(Mobile::Character *chr, Items::Item *item)
Definition: getitem.cpp:260
MobileCont aggressor_to_
Definition: charactr.h:843
unsigned short u16
Definition: rawtypes.h:26
#define DYN_PROPERTY_POINTER(name, type, id)
Definition: dynproperties.h:73
unsigned int u32
Definition: rawtypes.h:27
bool consume(unsigned int hamt)
Definition: charactr.h:225
signed short s16
Definition: rawtypes.h:30
void base(unsigned short base)
Definition: charactr.h:164
Definition: refptr.h:65
ref_ptr< Core::UContainer > trading_cont
Definition: charactr.h:856
weak_ptr< Core::Menu > menu
Definition: charactr.h:862
void regenrate(int rate)
Definition: charactr.h:224
int maximum() const
Definition: charactr.h:199
Core::OneShotTask * repsys_task_
Definition: charactr.h:846
unsigned int _current
Definition: charactr.h:252
const AttributeValue & attribute(unsigned attrid) const
Definition: charactr.h:1051
Core::CharacterRef trading_with
Definition: charactr.h:857
virtual unsigned short ar() const
Definition: charactr.h:1008
bool has_shield() const
Definition: charactr.h:1041
bool paralyzed() const
Definition: charactr.h:974
virtual void inform_moved(Character *moved)
Definition: charactr.cpp:2988
void createchar2(Accounts::Account *acct, unsigned index)
Definition: create.cpp:570
ref_ptr< Mobile::Character > CharacterRef
Definition: reftypes.h:42
virtual void inform_leftarea(Character *wholeft)
Definition: charactr.cpp:2978
Core::polclock_t swing_timer_start_clock_
Definition: charactr.h:830
void intrinsic_mod(short val)
Definition: charactr.h:173
signed int s32
Definition: rawtypes.h:31
#define passert(exp)
Definition: passert.h:62
Core::MOVEMODE movemode
Definition: charactr.h:811
int regenrate() const
Definition: charactr.h:202
int effective_tenths() const
Definition: charactr.h:155
signed char s8
Definition: rawtypes.h:29
int polclock_t
Definition: polclock.h:26
ReportableList reportable_
Definition: charactr.h:848
Core::AttributeFlags< PRIV_FLAGS > cached_settings
Definition: charactr.h:895
Clib::StringSet settings
Definition: charactr.h:893
int maximum_ones() const
Definition: charactr.h:200
Core::URACE race
Definition: charactr.h:919
std::vector< u32 > arguments
Definition: charactr.h:270
void temp_mod(short temp)
Definition: charactr.h:171
std::set< USERIAL > ToBeReportableList
Definition: charactr.h:841
Core::AttributeFlags< MOB_FLAGS > mob_flags_
Definition: charactr.h:896
const unsigned ATTRIBUTE_MAX_BASE
Definition: attribute.h:70
static const MovementCostMod DEFAULT
void lock(unsigned char lockstate)
Definition: charactr.h:175
int intrinsic_mod() const
Definition: charactr.h:172
Core::AccountRef acct
Definition: charactr.h:914
virtual void inform_criminal(Character *thecriminal)
Definition: charactr.cpp:2973
std::set< Character * > CharacterSet
Definition: charactr.h:338
void NpcPropagateCriminal(Character *chr, Character *thecriminal)
Definition: charactr.h:1082
Core::polclock_t criminal_until_
Definition: charactr.h:845
#define DYN_PROPERTY(name, type, id, defaultvalue)
Definition: dynproperties.h:62
Core::gameclock_t end
Definition: charactr.h:263
const CharacterSet & hostiles() const
Definition: charactr.h:1023
virtual void inform_enteredarea(Character *whoentered)
Definition: charactr.cpp:2983
const VitalValue & vital(unsigned vitalid) const
Definition: charactr.h:1061
bool ignores_line_of_sight() const
Definition: charactr.h:1028
CharacterSet opponent_of
Definition: charactr.h:829
unsigned short _base
Definition: charactr.h:180
Core::OneShotTask * swing_task
Definition: charactr.h:831
void produce(unsigned int hamt)
Definition: charactr.h:238
void write_characters(SaveContext &sc)
Definition: uimport.cpp:857
unsigned char _lockstate
Definition: charactr.h:183
std::vector< Core::ItemRef > remote_containers_
Definition: charactr.h:797
void ClientCreateCharKR(Network::Client *client, PKTIN_8D *msg)
Definition: create.cpp:595
Core::OneShotTask * party_decline_timeout_
Definition: charactr.h:853
void start_script(const char *filename, Bscript::BObjectImp *param0, Bscript::BObjectImp *param1)
Definition: scrsched.cpp:150
int current() const
Definition: charactr.h:192
Core::OneShotTask * spell_task
Definition: charactr.h:868
Definition: berror.cpp:12
bool is_at_maximum() const
Definition: charactr.h:201
bool dead() const
Definition: charactr.h:931
bool hidden() const
Definition: charactr.h:941
void ClientCreateChar70160(Network::Client *client, PKTIN_F8 *msg)
Definition: create.cpp:953
std::vector< VitalValue > vitals
Definition: charactr.h:836
virtual void inform_imoved(Character *chr)
Definition: charactr.cpp:2992