Planeshift

pscharacter.h

Go to the documentation of this file.
00001 /*
00002  * pscharacter.h
00003  *
00004  * Copyright (C) 2001 Atomic Blue ([email protected], http://www.atomicblue.org)
00005  *
00006  *
00007  * This program is free software; you can redistribute it and/or
00008  * modify it under the terms of the GNU General Public License
00009  * as published by the Free Software Foundation (version 2 of the License)
00010  * This program is distributed in the hope that it will be useful,
00011  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00012  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013  * GNU General Public License for more details.
00014  * You should have received a copy of the GNU General Public License
00015  * along with this program; if not, write to the Free Software
00016  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
00017  *
00018  */
00019 
00020 #ifndef __PSCHARACTER_H__
00021 #define __PSCHARACTER_H__
00022 //=============================================================================
00023 // Crystal Space Includes
00024 //=============================================================================
00025 #include <csutil/sysfunc.h>
00026 
00027 //=============================================================================
00028 // Project Includes
00029 //=============================================================================
00030 #include "util/poolallocator.h"
00031 #include "util/psconst.h"
00032 #include "util/scriptvar.h"
00033 #include "util/skillcache.h"
00034 #include "util/slots.h"
00035 
00036 #include "net/charmessages.h"
00037 
00038 #include "../icachedobject.h"
00039 #include "../playergroup.h"
00040 #include "rpgrules/factions.h"
00041 
00042 //=============================================================================
00043 // Local Includes
00044 //=============================================================================
00045 #include "buffable.h"
00046 #include "psskills.h"
00047 #include "psstdint.h"
00048 #include "pscharinventory.h"
00049 #include "psinventorycachesvr.h"
00050 #include "psitemstats.h"
00051 #include "servervitals.h"
00052 #include "psguildinfo.h"
00053 #include "psattackqueue.h"
00054 #include "pscharquestmgr.h"
00055 
00056 class psServerVitals;
00057 class MsgEntry;
00058 class psItemStats;
00059 class psItem;
00060 class psQuest;
00061 
00062 struct psRaceInfo;
00063 class psSectorInfo;
00064 
00065 class ExchangeManager;
00066 class MathScript;
00067 class NpcResponse;
00068 class gemActor;
00069 struct psGuildLevel;
00070 class psGuildMember;
00071 class psLootMessage;
00072 class psMerchantInfo;
00073 class psQuestListMessage;
00074 class psSpell;
00075 class psTradeTransformations;
00076 class psTradeProcesses;
00077 class psTrainerInfo;
00078 struct psTrait;
00079 class psWorkGameEvent;
00080 
00081 struct Result;
00082 struct Faction;
00083 
00089 csString NormalizeCharacterName(const csString &name);
00090 
00092 
00093 enum PSCHARACTER_TYPE
00094 {
00095     PSCHARACTER_TYPE_PLAYER    = 0,
00096     PSCHARACTER_TYPE_NPC       = 1,
00097     PSCHARACTER_TYPE_PET       = 2,
00098     PSCHARACTER_TYPE_MOUNT     = 3,
00099     PSCHARACTER_TYPE_MOUNTPET  = 4,
00100     PSCHARACTER_TYPE_COUNT     = 5,
00101     PSCHARACTER_TYPE_UNKNOWN   = ~0
00102 } ;
00103 
00104 #define PSCHARACTER_BULK_COUNT INVENTORY_BULK_COUNT
00105 #define PSCHARACTER_BANK_BULK_COUNT 16
00106 
00110 class CharacterAttribute
00111 {
00112 protected:
00113     psCharacter* self;
00114 public:
00115     CharacterAttribute(psCharacter* character) : self(character) { }
00116 };
00117 
00118 // Remember to update the translation table in GetModeStr when adding modes.
00119 enum PSCHARACTER_MODE
00120 {
00121     PSCHARACTER_MODE_UNKNOWN = 0,
00122     PSCHARACTER_MODE_PEACE,
00123     PSCHARACTER_MODE_COMBAT,
00124     PSCHARACTER_MODE_SPELL_CASTING,
00125     PSCHARACTER_MODE_WORK,
00126     PSCHARACTER_MODE_DEAD,
00127     PSCHARACTER_MODE_SIT,
00128     PSCHARACTER_MODE_OVERWEIGHT,
00129     PSCHARACTER_MODE_EXHAUSTED,
00130     PSCHARACTER_MODE_DEFEATED,
00131     PSCHARACTER_MODE_STATUE,
00132     PSCHARACTER_MODE_PLAY,
00133     PSCHARACTER_MODE_COUNT
00134 };
00135 
00136 enum PSCHARACTER_CUSTOM
00137 {
00138     PSCHARACTER_CUSTOM_EYES = 0,
00139     PSCHARACTER_CUSTOM_HAIR,
00140     PSCHARACTER_CUSTOM_BEARD,
00141     PSCHARACTER_CUSTOM_COLOUR,
00142     PSCHARACTER_CUSTOM_SKIN,
00143     PSCHARACTER_CUSTOM_COUNT
00144 };
00145 
00147 enum PSCHARACTER_JOINNOTIFICATION
00148 {
00149     PSCHARACTER_JOINNOTIFICATION_GUILD    = 1,
00150     PSCHARACTER_JOINNOTIFICATION_ALLIANCE = 2
00151 };
00152 
00153 
00154 
00158 struct GMEventsAssignment
00159 {
00161     int runningEventIDAsGM;
00163     int runningEventID;
00165     csArray<int> completedEventIDsAsGM;
00167     csArray<int> completedEventIDs;
00168 };
00169 
00174 enum PSCHARACTER_WORKSTATE
00175 {
00176     PSCHARACTER_WORKSTATE_HALTED = 0,
00177     PSCHARACTER_WORKSTATE_STARTED,
00178     PSCHARACTER_WORKSTATE_COMPLETE,
00179     PSCHARACTER_WORKSTATE_OVERDONE
00180 };
00181 
00182 
00184 #define PSCHARACTER_EQUIPMENTFLAG_AUTOATTACK       0x00000001
00185 
00186 #define PSCHARACTER_EQUIPMENTFLAG_SINGLEATTACK     0x00000002
00187 
00188 #define PSCHARACTER_EQUIPMENTFLAG_ATTACKIFEMPTY    0x00000004
00189 
00190 //-----------------------------------------------------------------------------
00191 
00195 class psBuddyManager
00196 {
00197 public:
00198     struct Buddy
00199     {
00200         csString name;      
00201         PID playerId;       
00202     };
00203 
00209     void Initialize(PID charID)
00210     {
00211         characterId = charID;
00212     }
00213 
00220     bool AddBuddy(PID buddyID, csString &name);
00221 
00227     void RemoveBuddy(PID buddyID);
00228 
00235     bool IsBuddy(PID buddyID);
00236 
00242     void AddBuddyOf(PID buddyID);
00243 
00249     void RemoveBuddyOf(PID buddyID);
00250 
00257     bool LoadBuddies(Result &myBuddies, Result &buddyOf);
00258 
00259 
00260     csArray<psBuddyManager::Buddy>  GetBuddyList()
00261     {
00262         return buddyList;
00263     }
00264     csArray<PID>                    GetBuddyOfList()
00265     {
00266         return buddyOfList;
00267     }
00268 
00269 private:
00270 
00271     csArray<psBuddyManager::Buddy> buddyList;       
00272     csArray<PID> buddyOfList;       
00273 
00274     PID characterId;                
00275 };
00276 
00277 
00278 //-----------------------------------------------------------------------------
00279 
00280 // Need to recalculate Max HP/Mana/Stamina and inventory limits whenever stats
00281 // change (whether via buffs or base value changes).
00282 class SkillStatBuffable : public ClampedPositiveBuffable<int>
00283 {
00284 public:
00285     void Initialize(psCharacter* c)
00286     {
00287         chr = c;
00288     }
00289 protected:
00290     virtual void OnChange();
00291     psCharacter* chr;
00292 };
00293 
00294 // When base stats change, we also need to recalculate skill training costs.
00295 // However, since training ignores buffs, we don't need to for all changes.
00296 class CharStat : public SkillStatBuffable
00297 {
00298 public:
00299     void SetBase(int x);
00300 };
00301 
00302 typedef SkillStatBuffable SkillRank;
00303 
00304 class StatSet : public CharacterAttribute
00305 {
00306 public:
00307     StatSet(psCharacter* self);
00308 
00309     CharStat &Get(PSITEMSTATS_STAT attrib);
00310     CharStat &operator [](PSITEMSTATS_STAT which)
00311     {
00312         return Get(which);
00313     }
00314 
00315 protected:
00316     CharStat stats[PSITEMSTATS_STAT_COUNT];
00317 };
00318 
00322 struct Skill
00323 {
00324     unsigned short z;        
00325     unsigned short y;        
00326     SkillRank rank;          
00327 
00328     unsigned short zCost;    
00329     unsigned short yCost;    
00330     unsigned short zCostNext;
00331     unsigned short yCostNext;
00332     bool dirtyFlag;          
00333 
00334     psSkillInfo* info;       
00335 
00336     Skill()
00337     {
00338         Clear();
00339     }
00340     void Clear()
00341     {
00342         z=y=0;
00343         zCost=yCost=0;
00344         info = NULL;
00345         dirtyFlag = false;
00346     }
00347 
00348     void CalculateCosts(psCharacter* user);
00349 
00352     bool CanTrain()
00353     {
00354         return y < yCost;
00355     }
00356 
00365     void Train(int yIncrease);
00366 
00379     bool CheckDoRank(psCharacter* user);
00380 
00397     bool Practice(unsigned int amount, unsigned int &actuallyAdded, psCharacter* user);
00398 };
00399 
00400 
00407 class SkillSet : public CharacterAttribute
00408 {
00409 protected:
00410     csArray<Skill> skills; 
00411 
00412 public:
00418     SkillSet(psCharacter* self);
00419 
00427     void SetSkillInfo(PSSKILL which, psSkillInfo* info, bool recalculatestats = true);
00428 
00437     void SetSkillPractice(PSSKILL which, int z_value);
00438 
00448     void SetSkillKnowledge(PSSKILL which, int y_value);
00449 
00460     void SetSkillRank(PSSKILL which, unsigned int rank, bool recalculatestats = true);
00461 
00465     void Calculate();
00466 
00476     bool CanTrain(PSSKILL skill);
00477 
00485     void CheckDoRank(PSSKILL skill);
00486 
00487 
00497     void Train(PSSKILL skill, int yIncrease);
00498 
00499 
00506     SkillRank &GetSkillRank(PSSKILL which);
00507 
00514     unsigned int GetSkillKnowledge(PSSKILL skill);
00515 
00522     unsigned int GetSkillPractice(PSSKILL skill);
00523 
00534     bool  AddToSkillPractice(PSSKILL skill, unsigned int val, unsigned int &added);
00535 
00539     int AddSkillPractice(psSkillInfo* skill, unsigned int val);
00540 
00544     int AddSkillPractice(PSSKILL skill, unsigned int val);
00545 
00552     unsigned int GetBestSkillSlot(bool withBuff);
00553 
00554     Skill &Get(PSSKILL skill);
00555 };
00556 
00557 #define ALWAYS_IMPERVIOUS      1
00558 #define TEMPORARILY_IMPERVIOUS 2
00559 
00560 
00561 //-----------------------------------------------------------------------------
00562 
00563 struct Stance
00564 {
00565     unsigned int stance_id;
00566     csString stance_name;
00567     float stamina_drain_P;
00568     float stamina_drain_M;
00569     float attack_speed_mod;
00570     float attack_damage_mod;
00571     float defense_avoid_mod;
00572     float defense_absorb_mod;
00573 };
00574 
00582 class charVariable
00583 {
00584 public:
00585     csString name;          
00586     csString value;         
00587     bool dirty;             
00588     Buffable<int> intBuff;  
00589 
00590 
00591     Buffable<int> &GetBuffable()
00592     {
00593         return intBuff;
00594     }
00595 
00596     charVariable() : dirty(false) {}
00597     charVariable(csString name, csString value) : name(name), value(value), dirty(false)
00598     {
00599         intBuff.SetBase(strtoul(value.GetDataSafe(),NULL,0));
00600     }
00601     charVariable(csString name, csString value, bool dirty) : name(name), value(value), dirty(dirty)
00602     {
00603         intBuff.SetBase(strtoul(value.GetDataSafe(),NULL,0));
00604     }
00605 };
00606 
00607 class OverridableRace : public Overridable<psRaceInfo*>
00608 {
00609 public:
00610 
00616     OverridableRace(psRaceInfo* race) : Overridable<psRaceInfo*>(race) {}
00617 
00621     virtual ~OverridableRace() { }
00622 
00628     void SetCharacter(psCharacter* psChar)
00629     {
00630         character = psChar;
00631     }
00632 
00633 protected:
00634 
00640     virtual void OnChange();
00641 
00642     psCharacter* character; 
00643 };
00644 
00645 //-----------------------------------------------------------------------------
00646 
00647 class psCharacter : public iScriptableVar, public iCachedObject
00648 {
00649 public:
00650     enum TradingStatus
00651     {
00652         NOT_TRADING,
00653         SELLING,
00654         BUYING,
00655         WITHDRAWING,
00656         STORING
00657     };
00658 
00659     struct st_location
00660     {
00661         psSectorInfo* loc_sector;
00662         csVector3 loc;
00663         float loc_yrot;
00664         InstanceID worldInstance;
00665     };
00666 
00667     psCharacter();
00668 
00669     virtual ~psCharacter();
00670 
00671     bool Load(iResultRow &row);
00672 
00673     bool IsStatue()
00674     {
00675         return isStatue;
00676     }
00677 
00678     psCharacterInventory &Inventory()
00679     {
00680         return inventory;
00681     }
00682 
00683     psMoney Money()
00684     {
00685         return money;
00686     }
00687 
00688     psMoney &BankMoney()
00689     {
00690         return bankMoney;
00691     }
00692 
00693     void SetMoney(psMoney m);
00694 
00702     void SetMoney(psItem* &moneyObject);
00703 
00712     void SetMoney(psItemStats* MoneyObject,  int amount);
00713 
00714     void AdjustMoney(psMoney m, bool bank);
00715 
00716     void SaveMoney(bool bank);
00717 
00718     void ResetStats();
00719 
00720 
00722     bool NeedsHelpEvent(int which)
00723     {
00724         return (helpEventFlags & (1 << which))==0;
00725     }
00726 
00728     void CompleteHelpEvent(int which)
00729     {
00730         helpEventFlags |= (1 << which);
00731     }
00732 
00734     void SetGuild(psGuildInfo* g)
00735     {
00736         guildinfo = g;
00737     }
00739     psGuildInfo* GetGuild()
00740     {
00741         return guildinfo;
00742     }
00744     psGuildLevel* GetGuildLevel();
00746     psGuildMember* GetGuildMembership();
00747 
00749     bool IsGettingGuildNotifications()
00750     {
00751         return (joinNotifications & PSCHARACTER_JOINNOTIFICATION_GUILD);
00752     }
00754     bool IsGettingAllianceNotifications()
00755     {
00756         return (joinNotifications & PSCHARACTER_JOINNOTIFICATION_ALLIANCE);
00757     }
00759     void SetGuildNotifications(bool enabled)
00760     {
00761         if(enabled) joinNotifications |= PSCHARACTER_JOINNOTIFICATION_GUILD;
00762         else joinNotifications &= ~PSCHARACTER_JOINNOTIFICATION_GUILD;
00763     }
00765     void SetAllianceNotifications(bool enabled)
00766     {
00767         if(enabled) joinNotifications |= PSCHARACTER_JOINNOTIFICATION_ALLIANCE;
00768         else joinNotifications &= ~PSCHARACTER_JOINNOTIFICATION_ALLIANCE;
00769     }
00770 
00772     int GetNotifications()
00773     {
00774         return joinNotifications;
00775     }
00777     void SetNotifications(int notifications)
00778     {
00779         joinNotifications = notifications;
00780     }
00781 
00782     SkillSet &Skills()
00783     {
00784         return skills;
00785     }
00786 
00790     psSkillCache* GetSkillCache()
00791     {
00792         return &skillCache;
00793     }
00794 
00798     void GetSkillValues(MathEnvironment* env);
00799     void GetSkillBaseValues(MathEnvironment* env);
00800 
00801     // iCachedObject Functions below
00802     virtual void ProcessCacheTimeout() {}  
00803     virtual void* RecoverObject()
00804     {
00805         return this;    
00806     }
00807     virtual void DeleteSelf()
00808     {
00809         delete this;    
00810     }
00811 
00812 
00813 
00815     bool QuickLoad(iResultRow &row, bool noInventory);
00816 
00817     void LoadIntroductions();
00818 
00819     void LoadActiveSpells();
00820     void AddSpell(psSpell* spell);
00821     bool Store(const char* location,const char* slot,psItem* what);
00822 
00823     void SetPID(PID characterID)
00824     {
00825         pid = characterID;
00826     }
00827     PID GetPID() const
00828     {
00829         return pid;
00830     }
00831 
00832     PID GetMasterNPCID() const
00833     {
00834         return npcMasterId ? npcMasterId : pid;
00835     }
00836 
00837     void SetAccount(AccountID id)
00838     {
00839         accountid = id;
00840     }
00841     AccountID GetAccount() const
00842     {
00843         return accountid;
00844     }
00845 
00846     void SetName(const char* newName)
00847     {
00848         SetFullName(newName,lastname.GetData());
00849     }
00850     void SetLastName(const char* newLastName)
00851     {
00852         SetFullName(name.GetData(),newLastName);
00853     }
00854     void SetFullName(const char* newFirstName, const char* newLastName);
00855     void SetOldLastName(const char* oldLastName)
00856     {
00857         this->oldlastname = oldLastName;
00858     }
00859 
00860     const char* GetCharName() const
00861     {
00862         return name.GetData();
00863     }
00864     const char* GetCharLastName() const
00865     {
00866         return lastname.GetData();
00867     }
00868     const char* GetCharFullName() const
00869     {
00870         return fullName.GetData();
00871     }
00872     const char* GetOldLastName() const
00873     {
00874         return oldlastname.GetData();
00875     }
00876 
00877     // Introductions
00879     bool Knows(PID charid);
00880     bool Knows(psCharacter* c)
00881     {
00882         return (c ? Knows(c->GetPID()) : false);
00883     }
00885     bool Introduce(psCharacter* c);
00887     bool Unintroduce(psCharacter* c);
00888 
00889     unsigned int GetCharType() const
00890     {
00891         return characterType;
00892     }
00893     void SetCharType(unsigned int v)
00894     {
00895         CS_ASSERT(v < PSCHARACTER_TYPE_COUNT);
00896         characterType = v;
00897     }
00898     const char* GetCharTypeName()
00899     {
00900         return characterTypeName[characterType];
00901     }
00902 
00906     void SetLastLoginTime();
00907 
00911     csString GetLastLoginTime() const;
00912 
00916     void SetPetElapsedTime(double elapsedTime);
00917 
00921     double GetPetElapsedTime() const;
00922 
00926     void SetSpouseName(const char* name);
00927 
00933     const char* GetSpouseName() const
00934     {
00935         return spouseName.GetData();
00936     }
00937     void SetIsMarried(bool married)
00938     {
00939         isMarried = married;
00940     }
00941     bool GetIsMarried() const
00942     {
00943         return isMarried;
00944     }
00945 
00954     void SetRaceInfo(psRaceInfo* rinfo);
00955 
00961     psRaceInfo* GetRaceInfo();
00962 
00968     OverridableRace &GetOverridableRace();
00969 
00976     float GetScale();
00977 
00985     float GetScaleValue();
00986 
00992     bool AddExploredArea(PID explored);
00993 
00999     bool HasExploredArea(PID explored);
01000 
01001     FactionSet* GetFactions()
01002     {
01003         return factions;
01004     }
01005 
01006     void SetLootCategory(int id)
01007     {
01008         lootCategoryId = id;
01009     }
01010     int  GetLootCategory() const
01011     {
01012         return lootCategoryId;
01013     }
01014 
01024     psItem* RemoveLootItem(int id);
01025 
01035     csArray<psItem*> RemoveLootItems(csArray<csString> categories = csArray<csString>());
01036 
01042     void AddLootItem(psItem* item);
01043     void AddLootMoney(int money)
01044     {
01045         lootMoney += money;
01046     }
01047     size_t GetLootItems(psLootMessage &msg, EID entity, int cnum);
01048 
01050     int  GetLootMoney();
01051 
01053     void ClearLoot();
01054 
01056     int GetLastResponse()
01057     {
01058         return lastResponse;
01059     }
01060     void SetLastResponse(int response)
01061     {
01062         lastResponse=response;
01063     }
01064     bool CheckResponsePrerequisite(NpcResponse* resp);
01065 
01066     void CombatDrain(int);
01067 
01074     bool HasVariableDefined(const csString &name);
01075 
01082     csString GetVariableValue(const csString &name);
01083 
01092     Buffable<int> &GetBuffableVariable(const csString &name, const csString &value = "0");
01093 
01100     void SetVariable(const csString &name, const csString &value);
01101 
01108     void SetVariable(const csString &name);
01109 
01114     void UnSetVariable(const csString &name);
01115 
01119     csHash<charVariable, csString>::ConstGlobalIterator GetVariables() const;
01120 
01121     unsigned int GetExperiencePoints(); // W
01122     void SetExperiencePoints(unsigned int W);
01123     unsigned int AddExperiencePoints(unsigned int W);
01124     unsigned int AddExperiencePointsNotify(unsigned int W);
01125     unsigned int CalculateAddExperience(PSSKILL skill, unsigned int awardedPoints, float modifier = 1);
01126     unsigned int GetProgressionPoints(); // X
01127     void SetProgressionPoints(unsigned int X,bool save);
01128     void UseProgressionPoints(unsigned int X);
01129 
01131     int GetMaxAllowedRealm(PSSKILL skill);
01132     SkillRank &GetSkillRank(PSSKILL skill)
01133     {
01134         return skills.GetSkillRank(skill);
01135     }
01136 
01137     void KilledBy(psCharacter* attacker)
01138     {
01139         deaths++;
01140         if(!attacker) suicides++;
01141     }
01142     void Kills(psCharacter* target)
01143     {
01144         kills++;
01145     }
01146 
01147     unsigned int GetKills() const
01148     {
01149         return kills;
01150     }
01151     unsigned int GetDeaths() const
01152     {
01153         return deaths;
01154     }
01155     unsigned int GetSuicides() const
01156     {
01157         return suicides;
01158     }
01159 
01170     void DropItem(psItem* &item, csVector3 pos = 0, const csVector3 &rot = csVector3(0), bool guarded = true, bool transient = true, bool inplace = false);
01171 
01172     float GetHP();
01173     float GetMana();
01174     float GetStamina(bool pys);
01175 
01176     void SetHitPoints(float v);
01177     void SetMana(float v);
01178     void SetStamina(float v, bool pys);
01179 
01180     void AdjustHitPoints(float adjust);
01181     void AdjustMana(float adjust);
01182     void AdjustStamina(float adjust, bool pys);
01183 
01184     VitalBuffable &GetMaxHP();
01185     VitalBuffable &GetMaxMana();
01186     VitalBuffable &GetMaxPStamina();
01187     VitalBuffable &GetMaxMStamina();
01188 
01189     VitalBuffable &GetHPRate();
01190     VitalBuffable &GetManaRate();
01191     VitalBuffable &GetPStaminaRate();
01192     VitalBuffable &GetMStaminaRate();
01193 
01194     void SetStaminaRegenerationNone(bool physical = true, bool mental = true);
01195     void SetStaminaRegenerationWalk(bool physical = true, bool mental = true);
01196     void SetStaminaRegenerationSitting();
01197     void SetStaminaRegenerationStill(bool physical = true, bool mental = true);
01198     void SetStaminaRegenerationWork(int skill);
01199 
01203     void CalculateMaxStamina();
01204 
01208     unsigned int GetStatsDirtyFlags() const;
01209 
01213     void SetAllStatsDirty();
01214 
01218     void ClearStatsDirtyFlags(unsigned int dirtyFlags);
01219 
01220     const char* GetHelmGroup()
01221     {
01222         return helmGroup.GetData();
01223     }
01224     const char* GetBracerGroup()
01225     {
01226         return BracerGroup.GetData();
01227     }
01228     const char* GetBeltGroup()
01229     {
01230         return BeltGroup.GetData();
01231     }
01232     const char* GetCloakGroup()
01233     {
01234         return CloakGroup.GetData();
01235     }
01236 
01237     void SetHelmGroup(const char* Group)
01238     {
01239         helmGroup = Group;
01240     }
01241     void SetBracerGroup(const char* Group)
01242     {
01243         BracerGroup = Group;
01244     }
01245     void SetBeltGroup(const char* Group)
01246     {
01247         BeltGroup = Group;
01248     }
01249     void SetCloakGroup(const char* Group)
01250     {
01251         CloakGroup = Group;
01252     }
01253 
01254     size_t GetAssignedGMEvents(psGMEventListMessage &gmevents, int clientnum);
01255     void AssignGMEvent(int id, bool playerIsGM);
01256     void CompleteGMEvent(bool playerIsGM);
01257     void RemoveGMEvent(int id, bool playerIsGM=false);
01258 
01262     void UpdateRespawn(csVector3 pos, float yrot, psSectorInfo* sector, InstanceID instance);
01263 
01264 
01268     bool UpdateFaction(Faction* faction, int delta);
01269 
01273     bool CheckFaction(Faction* faction, int value);
01274 
01278     void StartSong();
01279 
01286     void EndSong(csTicks bonusTime);
01287 
01291     csTicks GetSongStartTime() const
01292     {
01293         return songExecutionTime;
01294     }
01295 
01299     bool IsBanker() const
01300     {
01301         return banker;
01302     }
01303 
01309     bool IsStorage() const
01310     {
01311         return IsBanker();
01312     }
01313     void RecalculateStats();
01314 
01315     bool IsNPC()
01316     {
01317         return characterType == PSCHARACTER_TYPE_NPC;
01318     }
01319 
01325     bool IsPlayer()
01326     {
01327         return characterType == PSCHARACTER_TYPE_PLAYER;
01328     }
01329 
01331     bool IsPet()
01332     {
01333         return (characterType == PSCHARACTER_TYPE_PET || characterType == PSCHARACTER_TYPE_MOUNTPET);
01334     }
01336     bool IsMount()
01337     {
01338         return (characterType == PSCHARACTER_TYPE_MOUNT || characterType == PSCHARACTER_TYPE_MOUNTPET);
01339     }
01340     PID  GetFamiliarID(size_t id)
01341     {
01342         return familiarsId.GetSize() > id ? familiarsId.Get(id) : 0;
01343     }
01344     void SetFamiliarID(PID v);
01345     size_t GetNumFamiliars()
01346     {
01347         return familiarsId.GetSize();
01348     }
01349     bool CanSummonFamiliar()
01350     {
01351         return canSummonFamiliar.Current() > 0;
01352     }
01353     Buffable<int> &GetCanSummonFamiliar()
01354     {
01355         return canSummonFamiliar;
01356     }
01357     const char* GetAnimalAffinity()
01358     {
01359         return animalAffinity.GetDataSafe();
01360     }
01361     void SetAnimialAffinity(const char* v)
01362     {
01363         animalAffinity = v;
01364     }
01365     PID  GetOwnerID()
01366     {
01367         return ownerId;
01368     }
01369     void SetOwnerID(PID v)
01370     {
01371         ownerId = v;
01372     }
01373     bool IsHired()
01374     {
01375         return hired;
01376     }
01377     void SetHired(bool hired)
01378     {
01379         this->hired = hired;
01380     }
01381 
01382     bool UpdateStatDRData(csTicks now);
01383     bool SendStatDRMessage(uint32_t clientnum, EID eid, int flags, csRef<PlayerGroup> group = NULL);
01384 
01391     bool GetSlotAttackable(INVENTORY_SLOT_NUMBER slot);
01392 
01393     bool GetSlotAutoAttackable(INVENTORY_SLOT_NUMBER slot);
01394     bool GetSlotSingleAttackable(INVENTORY_SLOT_NUMBER slot);
01395     void ResetSwings(csTicks timeofattack);
01396     void TagEquipmentObject(INVENTORY_SLOT_NUMBER slot,int eventId);
01397     int GetSlotEventId(INVENTORY_SLOT_NUMBER slot);
01398 
01400     //float GetAttackValue(psItem *slotitem);
01401     //float GetAttackValueForWeaponInSlot(int slot);
01402     float GetTargetedBlockValueForWeaponInSlot(INVENTORY_SLOT_NUMBER slot);
01403     float GetUntargetedBlockValueForWeaponInSlot(INVENTORY_SLOT_NUMBER slot);
01404     float GetTotalTargetedBlockValue();
01405     float GetTotalUntargetedBlockValue();
01406     float GetCounterBlockValueForWeaponInSlot(INVENTORY_SLOT_NUMBER slot);
01407     float GetDodgeValue();
01408 
01409     Multiplier &AttackModifier()
01410     {
01411         return attackModifier;
01412     }
01413     Multiplier &DefenseModifier()
01414     {
01415         return defenseModifier;
01416     }
01417 
01419     void PracticeArmorSkills(unsigned int practice, INVENTORY_SLOT_NUMBER attackLocation);
01420     void PracticeWeaponSkills(unsigned int practice);
01421     void PracticeWeaponSkills(psItem* weapon, unsigned int practice);
01422 
01423     void SetTraitForLocation(PSTRAIT_LOCATION location,psTrait* trait);
01424     psTrait* GetTraitForLocation(PSTRAIT_LOCATION location);
01425 
01426     void GetLocationInWorld(InstanceID &instance,psSectorInfo* &sectorinfo,float &loc_x,float &loc_y,float &loc_z,float &loc_yrot);
01427     void SetLocationInWorld(InstanceID instance,psSectorInfo* sectorinfo,float loc_x,float loc_y,float loc_z,float loc_yrot);
01428     void SaveLocationInWorld();
01429 
01431     void MakeTextureString(csString &textureString);
01432 
01434     void MakeEquipmentString(csString &equipmentString);
01435 
01437     unsigned int GetCharLevel(bool physical);
01438 
01439     bool IsMerchant()
01440     {
01441         return (merchantInfo != NULL);
01442     }
01443     psMerchantInfo* GetMerchantInfo()
01444     {
01445         return merchantInfo;
01446     }
01447     bool IsTrainer()
01448     {
01449         return (trainerInfo != NULL);
01450     }
01451     psTrainerInfo* GetTrainerInfo()
01452     {
01453         return trainerInfo;
01454     }
01455     psCharacter* GetTrainer()
01456     {
01457         return trainer;
01458     }
01459     void SetTrainer(psCharacter* trainer)
01460     {
01461         this->trainer = trainer;
01462     }
01463 
01473     bool CanTrain(PSSKILL skill);
01474 
01484     void Train(PSSKILL skill, int yIncrease);
01485 
01490     void SetSkillRank(PSSKILL which, unsigned int rank);
01491 
01492     psSpell* GetSpellByName(const csString &spellName);
01493     psSpell* GetSpellByIdx(int index);
01494     csArray<psSpell*> &GetSpellList()
01495     {
01496         return spellList;
01497     }
01498 
01499 
01500     psCharacter* GetMerchant()
01501     {
01502         return merchant;
01503     }
01504     TradingStatus GetTradingStatus()
01505     {
01506         return tradingStatus;
01507     }
01508     void SetTradingStatus(TradingStatus trading, psCharacter* merchant)
01509     {
01510         tradingStatus = trading;
01511         this->merchant = merchant;
01512     }
01513 
01514     gemActor* GetActor()
01515     {
01516         return actor;
01517     }
01518     void SetActor(gemActor* actor);
01519 
01520     bool SetTradingStopped(bool stopped);
01521 
01522     bool ReadyToExchange();
01523 
01525     unsigned int GetOnlineTimeThisSession()
01526     {
01527         return (csGetTicks() - startTimeThisSession)/1000;
01528     }
01529 
01531     unsigned int GetTotalOnlineTime()
01532     {
01533         return timeconnected + GetOnlineTimeThisSession();
01534     }
01535 
01536 
01537     unsigned int GetTimeConnected()
01538     {
01539         return timeconnected;
01540     }
01541 
01546     const char* GetDescription();
01547 
01552     void SetDescription(const char* newValue);
01553 
01558     const char* GetOOCDescription();
01559 
01564     void SetOOCDescription(const char* newValue);
01565 
01570     const char* GetCreationInfo();
01571 
01576     void SetCreationInfo(const char* newValue);
01577 
01583     bool GetFactionEventsDescription(csString &factionDescription);
01584 
01589     const char* GetLifeDescription();
01590 
01595     void SetLifeDescription(const char* newValue);
01596 
01598     double GetProperty(MathEnvironment* env, const char* ptr);
01599     double CalcFunction(MathEnvironment* env, const char* functionName, const double* params);
01600     const char* ToString()
01601     {
01602         return fullName.GetData();
01603     }
01604 
01606     int GetKillExperience()
01607     {
01608         return killExp;
01609     }
01610     void SetKillExperience(int newValue)
01611     {
01612         killExp=newValue;
01613     }
01614 
01615     void SetImperviousToAttack(int newValue)
01616     {
01617         imperviousToAttack=newValue;
01618     }
01619     int GetImperviousToAttack()
01620     {
01621         return imperviousToAttack;
01622     }
01623 
01624     void CalculateEquipmentModifiers();
01625     float GetStatModifier(PSITEMSTATS_STAT attrib);
01626 
01627     bool AppendCharacterSelectData(psAuthApprovedMessage &auth);
01628 
01629     // NPC based functions - should these go here?
01630     int NPC_GetSpawnRuleID()
01631     {
01632         return npcSpawnRuleId;
01633     }
01634     void NPC_SetSpawnRuleID(int v)
01635     {
01636         npcSpawnRuleId=v;
01637     }
01638 
01639     psBuddyManager &GetBuddyMgr()
01640     {
01641         return buddyManager;
01642     }
01643     psCharacterQuestManager &GetQuestMgr()
01644     {
01645         return questManager;
01646     }
01647 
01649     void* operator new(size_t);
01651     void operator delete(void*);
01652 
01657     AccountID GetAccountId()
01658     {
01659         return accountid;
01660     }
01661 
01666     st_location GetSpawnLocation()
01667     {
01668         return spawnLoc;
01669     }
01670 
01675     st_location GetLocation() const
01676     {
01677         return location;
01678     }
01679 
01683     psAttackQueue* GetAttackQueue() { return attackQueue; } 
01684     friend class psCharacterLoader;
01685 
01686 protected:
01687 
01688     bool LoadSpells(PID use_id);
01689     bool LoadAdvantages(PID use_id);
01690     bool LoadSkills(PID use_id);
01691     bool LoadTraits(PID use_id);
01692     bool LoadRelationshipInfo(PID pid);
01693     bool LoadBuddies(Result &myBuddy, Result &buddyOf);
01694     bool LoadMarriageInfo(Result &result);
01695     bool LoadFamiliar(Result &pet, Result &owner);
01697     bool LoadFactions(PID pid);
01699     void UpdateFactions();
01700 
01705     bool LoadVariables(PID pid);
01706 
01710     void UpdateVariables();
01711 
01712     bool LoadExploration(Result &exploration);
01713     bool LoadGMEvents();
01714 
01715     psCharacterInventory        inventory;                    
01716     psGuildInfo*                guildinfo;
01717     StatSet                     modifiers;
01718     SkillSet                    skills;
01719     csSet<PID>                  acquaintances;
01720     int                         npcMasterId;
01721     unsigned int                deaths;
01722     unsigned int                kills;
01723     unsigned int                suicides;
01724     bool                        loaded;
01725     psBuddyManager              buddyManager;
01726     psCharacterQuestManager     questManager;
01727 
01728     csRef<psMerchantInfo>       merchantInfo;           
01729     psCharacter*                merchant;               
01730 
01731     bool                        tradingStopped;
01732     TradingStatus               tradingStatus;          
01733 
01734     gemActor* actor;                
01735     PID pid;                        
01736     AccountID accountid;            
01737 
01738     csRef<psTrainerInfo>    trainerInfo;        
01739     psCharacter*            trainer;            
01740 
01741     csString description;     
01742     csString oocdescription;  
01743     csString creationinfo;    
01744     csString lifedescription; 
01745 
01746     int killExp; 
01747 
01748     Multiplier attackModifier;  
01749     Multiplier defenseModifier; 
01750 
01751     st_location spawnLoc;
01752 
01753     csString name;
01754     csString lastname;
01755     csString fullName;
01756     csString oldlastname;
01757 
01758     csString spouseName;
01759     bool     isMarried;
01760 
01761     OverridableRace race; 
01762 
01763     FactionSet* factions;
01764 
01765     csString progressionScriptText; 
01766 
01767     int     imperviousToAttack;
01768 
01770     unsigned int     helpEventFlags;
01771 
01772     st_location location;
01773     psServerVitals* vitals;
01774 
01775     psTrait* traits[PSTRAIT_LOCATION_COUNT];
01776 
01778     int npcSpawnRuleId;
01779 
01781     int  lootCategoryId;
01782 
01783     csString animalAffinity;
01784     PID ownerId;
01785     csArray<PID> familiarsId;
01786     Buffable<int> canSummonFamiliar;
01787 
01789     unsigned int timeconnected;
01790     csTicks startTimeThisSession;
01791 
01792     csString lastLoginTime;
01793     double petElapsedTime;
01794     double lastSavedPetElapsedTime; 
01795 
01796     psMoney money;                                          
01797     psMoney bankMoney;                                      
01798 
01799     csArray<psSpell*>         spellList;
01800 
01801     csHash<charVariable, csString> charVariables; 
01802 
01803     psSkillCache              skillCache;
01804     GMEventsAssignment        assignedEvents;
01805     csArray<PID>              exploredAreas;
01806 
01808     int joinNotifications;
01809 
01810     float overrideMaxHp,overrideMaxMana;  
01811 
01812 
01813     static const char* characterTypeName[];
01814     unsigned int characterType;
01815 
01817     csArray<psItem*> lootPending;
01819     int  lastResponse;
01821     int  lootMoney;
01823     bool isStatue;
01824 
01825     //The attack queue
01826     csRef<psAttackQueue> attackQueue;
01827 private:
01828     void CalculateArmorForSlot(INVENTORY_SLOT_NUMBER slot, float &heavy_p, float &med_p, float &light_p);
01829     bool ArmorUsesSkill(INVENTORY_SLOT_NUMBER slot, PSITEMSTATS_ARMORTYPE skill);
01830 
01831     int FindGlyphSlot(const csArray<glyphSlotInfo> &slots, psItemStats* glyphType, int purifyStatus);
01832 
01833     csTicks songExecutionTime;   
01834 
01839     csString helmGroup;
01840 
01845     csString BracerGroup;
01846 
01851     csString BeltGroup;
01852 
01857     csString CloakGroup;
01858 
01859     bool banker;    
01860 
01861     bool hired;     
01862 
01864     static PoolAllocator<psCharacter> characterpool;
01865 };
01866 
01869 #endif
01870 
01871