Planeshift

psspell.h

Go to the documentation of this file.
00001 /*
00002  * psspell.h
00003  *
00004  * Copyright (C) 2003 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 __PSSPELL_H__
00021 #define __PSSPELL_H__
00022 
00023 //=============================================================================
00024 // Crystal Space Includes
00025 //=============================================================================
00026 #include <csutil/csstring.h>
00027 
00028 //=============================================================================
00029 // Project Includes
00030 //=============================================================================
00031 #include <idal.h>
00032 #include "util/scriptvar.h"
00033 #include "util/gameevent.h"
00034 
00035 //=============================================================================
00036 // Local Includes
00037 //=============================================================================
00038 #include "psskills.h"
00039 #include "psitemstats.h"
00040 #include "deleteobjcallback.h"
00041 
00042 class Client;
00043 class gemObject;
00044 class gemActor;
00045 class ProgressionScript;
00046 class MathExpression;
00047 
00052 struct psWay
00053 {
00054     unsigned int     id;
00055     PSSKILL          skill;    // for example, Crystal Way
00056     PSSKILL                      related_stat_skill; // for example, Charisma
00057     csString         name;
00058 };
00059 
00060 struct psSpellCost
00061 {
00062     float mana;
00063     float stamina;
00064 };
00065 
00066 typedef csArray <psItemStats*> glyphList_t;
00067 
00068 
00074 class psSpell : public iScriptableVar
00075 {
00076 public:
00077     psSpell();
00078     ~psSpell();
00079 
00080     bool Load(iResultRow &row);
00081     int GetID() const
00082     {
00083         return id;
00084     }
00085     const csString &GetName() const
00086     {
00087         return name;
00088     }
00089     const csString &GetImage() const
00090     {
00091         return image;
00092     }
00093     const csString &GetDescription() const
00094     {
00095         return description;
00096     }
00097     psSpellCost ManaCost(psCharacter* caster, float kFactor) const;
00098     float PowerLevel(psCharacter* caster, float kFactor) const;
00099     float ChanceOfCastSuccess(psCharacter* caster, float kFactor) const;
00100     float ChanceOfResearchSuccess(psCharacter* researcher);
00101 
00105     bool MatchGlyphs(const csArray<psItemStats*> &glyphs);
00106 
00113     bool CanCast(gemActor* caster, float kFactor, csString &reason, bool canCastAllSpells);
00114 
00122     void Cast(gemActor* caster, float kFactor, Client* client) const;
00123 
00124     /*
00125      * @param castingDuration The time it was waited before the spell could affect targets.
00126      */
00127     void Affect(gemActor* caster, gemObject* target, float range, float kFactor, float power, Client* client, csTicks castingDuration) const;
00128 
00129     int GetRealm()
00130     {
00131         return realm;
00132     }
00133     psWay* GetWay()
00134     {
00135         return way;
00136     }
00137     csArray<psItemStats*> &GetGlyphList()
00138     {
00139         return glyphList;
00140     }
00141 
00145 
00146     double GetProperty(MathEnvironment* env, const char* ptr);
00147     double CalcFunction(MathEnvironment* env, const char* functionName, const double* params);
00148     const char* ToString()
00149     {
00150         return name.GetDataSafe();
00151     }
00153 
00154 protected:
00155     bool AffectTarget(gemActor* caster, gemObject* origTarget, gemObject* target, float power, Client* client) const;
00156 
00157     int id;
00158     csString name;
00159     psWay* way;
00160     int realm;
00161     csString image;
00162     csString description;
00163     csString castingEffect;
00164     bool offensive;
00165 
00167     float maxPower;
00168 
00170     int targetTypes;
00171 
00174     MathExpression* castDuration;
00176     MathExpression* range;
00178     MathExpression* aoeRadius;
00180     MathExpression* aoeAngle;
00182     ProgressionScript* outcome;
00183 
00185     csArray<psItemStats*> glyphList;
00186 
00188     csString npcSpellCategory;
00189 
00191     uint32_t npcSpellCategoryID;
00192 
00194     float    npcSpellRelativePower;
00195 };
00196 
00197 //-----------------------------------------------------------------------------
00198 
00202 class psSpellCastGameEvent : public psGameEvent, public iDeleteObjectCallback
00203 {
00204 public:
00205     gemActor*      caster; 
00206     gemObject*     target; 
00207     Client*        client; 
00208     const psSpell* spell;  
00209 
00210     float max_range;
00211     float kFactor;
00212     float powerLevel;
00213     csTicks duration;
00214 
00215     psSpellCastGameEvent(const psSpell* spell,
00216                          gemActor* caster,
00217                          gemObject* target,
00218                          csTicks castingDuration,
00219                          float max_range,
00220                          float kFactor,
00221                          float power,
00222                          Client* client);
00223 
00224     ~psSpellCastGameEvent();
00225 
00226     void Interrupt();
00227 
00228     virtual void Trigger();  // Abstract event processing function
00229     virtual void DeleteObjectCallback(iDeleteNotificationObject* object);
00230 };
00231 
00234 #endif