Planeshift

psattack.h

Go to the documentation of this file.
00001 /*
00002  * psattack.cpp              author: hartra344 [at] gmail [dot] com
00003  *
00004  * Copyright (C) 2001-2011 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 #ifndef psAttack_HEADER
00020 #define psAttack_HEADER
00021 //====================================================================================
00022 // Crystal Space Includes
00023 //====================================================================================
00024 #include <csutil/csstring.h>
00025 #include <csutil/weakreferenced.h>
00026 //====================================================================================
00027 // Project Includes
00028 //====================================================================================
00029 #include <idal.h>
00030 #include "util/scriptvar.h"
00031 #include "util/gameevent.h"
00032 
00033 
00034 //=============================================================================
00035 // Local Includes
00036 //=============================================================================
00037 #include "psskills.h"
00038 #include "psitemstats.h"
00039 #include "psitem.h"
00040 #include "deleteobjcallback.h"
00041 #include "combatmanager.h"
00042 
00043 using namespace CS;
00044 
00045 class psQuestPrereqOp;
00046 class psCharacter;
00047 class psAttack;
00048 class Client;
00049 class gemActor;
00050 class ProgressionScript;
00051 class MathExpression;
00052 class CombatManager;
00053 struct Stance;
00054 class psCombatAttackGameEvent;
00055 
00060 struct psAttackType
00061 {
00062     unsigned int           id;
00063     csString               name;
00064     unsigned int           weaponID;
00065     csArray<psWeaponType*> weaponTypes;
00066     bool                   OneHand;
00067     PSSKILL                related_stat; 
00068 
00069 };
00070 
00071 struct psAttackCost// may be expanded later if more balance is needed
00072 {
00073     float physStamina;
00074 };
00075 
00082 class psAttack : public csRefCount
00083 {
00084 public:
00085     psAttack();
00086     ~psAttack();
00087 
00091     bool Load(iResultRow& row);
00092 
00096     bool CanAttack(Client* client);
00097 
00101     bool Attack(gemActor* attacker, gemActor* target, INVENTORY_SLOT_NUMBER slot);
00102 
00107     virtual void Affect(psCombatAttackGameEvent* event);
00108 
00112     int GetID() const
00113     {
00114         return id;
00115     }
00116 
00120     const csString &GetName() const
00121     {
00122         return name;
00123     }
00124 
00128     const csString &GetImage() const
00129     {
00130         return image;
00131     }
00132 
00136     const csString &GetDescription() const
00137     {
00138         return description;
00139     }
00140 
00141     psAttackType* GetType() const
00142     {
00143         return type;
00144     }
00145 
00146 protected:
00147     int CalculateAttack(psCombatAttackGameEvent* event, psItem* subWeapon = NULL);
00148     void AffectTarget(gemActor* target, psCombatAttackGameEvent* event, int attack_result);
00149 
00150     int id;                     
00151     csString name;              
00152     csString image;             
00153     csString animation;         
00154     csString description;       
00155     psAttackType* type;         
00156     csRef<psQuestPrereqOp> requirements; 
00157     csRef<psQuestPrereqOp> TypeRequirements; 
00158 
00160     MathExpression* attackDelay;
00162     MathExpression* attackRange;
00164     MathExpression* aoeRadius;
00166     MathExpression* aoeAngle;
00168     MathScript* damage_script;
00170     ProgressionScript* outcome;
00171 };
00172 
00173 //-----------------------------------------------------------------------------
00174 
00178 class psCombatAttackGameEvent : public psGameEvent
00179 {
00180 public:
00181     psCombatAttackGameEvent(csTicks delayticks,
00182                             psAttack* attack,
00183                             gemActor* attacker,
00184                             gemActor* target,
00185                             INVENTORY_SLOT_NUMBER weaponslot,
00186                             psItem* weapon);
00187 
00188     virtual ~psCombatAttackGameEvent();
00189 
00190     virtual void Trigger();  // Abstract event processing function
00191 
00192     psAttack* GetAttack()
00193     {
00194         return attack;
00195     }
00196 
00197     gemActor* GetAttacker()
00198     {
00199         return attacker;
00200     }
00201 
00202     gemActor* GetTarget()
00203     {
00204         return target;
00205     }
00206 
00207     INVENTORY_SLOT_NUMBER GetWeaponSlot()
00208     {
00209         return weaponSlot;
00210     }
00211 
00212     psItem* GetWeapon()
00213     {
00214         return weapon;
00215     }
00216 
00217     uint32_t GetTargetID()
00218     {
00219         return TargetCID;
00220     }
00221 
00222     uint32_t GetAttackerID()
00223     {
00224         return AttackerCID;
00225     }
00226 
00227     // These are just here to make it easy to pass data from Affect().
00228     MathEnvironment env;
00229     INVENTORY_SLOT_NUMBER AttackLocation;  
00230     float FinalDamage;               
00231 
00232 protected:
00233     psAttack* attack;                
00234     csWeakRef<gemActor> attacker;    
00235     csWeakRef<gemActor> target;      
00236     uint32_t AttackerCID;            
00237     uint32_t TargetCID;              
00238 
00239     INVENTORY_SLOT_NUMBER weaponSlot; 
00240     // XXX There is some risk this pointer could point to trash
00241     // if the item is deleted/stored.
00242     psItem* weapon;                   
00243 };
00244 
00245 #endif