*Integrate Script system to Core

-added ScriptMgr for loading scripts
-removed bindings
-moved script system to src/game
-moved scripts to src/scripts
-VC project files updated
-cmakes updated (not 100% done yet)

NOTE to Devs:
-file locations changed
-precompiled renamed to ScriptedPch
-ecsort_ai renamed to ScriptedEscortAI
-follower_ai renamed to ScriptedFollowerAI
-guard_ai renamed to ScriptedGuardAI
-simple_ai renamed to ScriptedSimpleAI
-sc_creature renamed to ScriptedCreature
-sc_gossip renamed to ScriptedGossip
-sc_instance  renamed to ScriptedInstance

*use the new headers in scripts, thank you

NOTE to ALL:
cmake not fully tested, please report any errors with it
could make creashes, incompability
USE AT YOUR OWN RISK before further tests!!

--HG--
branch : trunk
This commit is contained in:
Rat
2010-01-19 11:36:05 +01:00
parent f5dea61b66
commit 0cc053ea4d
601 changed files with 3908 additions and 7245 deletions
+265
View File
@@ -0,0 +1,265 @@
/* Copyright (C) 2006 - 2009 ScriptDev2 <https://scriptdev2.svn.sourceforge.net/>
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
/* ScriptData
SDName: Example_Creature
SD%Complete: 100
SDComment: Short custom scripting example
SDCategory: Script Examples
EndScriptData */
#include "ScriptedPch.h"
// **** This script is designed as an example for others to build on ****
// **** Please modify whatever you'd like to as this script is only for developement ****
// **** Script Info ****
// This script is written in a way that it can be used for both friendly and hostile monsters
// Its primary purpose is to show just how much you can really do with scripts
// I recommend trying it out on both an agressive NPC and on friendly npc
// **** Quick Info ****
// Functions with Handled Function marked above them are functions that are called automatically by the core
// Functions that are marked Custom Function are functions I've created to simplify code
enum eEnums
{
//List of text id's. The text is stored in database, also in a localized version
//(if translation not exist for the textId, default english text will be used)
//Not required to define in this way, but simplify if changes are needed.
SAY_AGGRO = -1999900,
SAY_RANDOM_0 = -1999901,
SAY_RANDOM_1 = -1999902,
SAY_RANDOM_2 = -1999903,
SAY_RANDOM_3 = -1999904,
SAY_RANDOM_4 = -1999905,
SAY_BESERK = -1999906,
SAY_PHASE = -1999907,
SAY_DANCE = -1999908,
SAY_SALUTE = -1999909,
//List of spells. Not required to define them in this way, but will make it easier to maintain in case spellId change
SPELL_BUFF = 25661,
SPELL_ONE = 12555,
SPELL_ONE_ALT = 24099,
SPELL_TWO = 10017,
SPELL_THREE = 26027,
SPELL_ENRAGE = 23537,
SPELL_BESERK = 32309,
FACTION_WORGEN = 24
};
//List of gossip item texts. Items will appear in the gossip window.
#define GOSSIP_ITEM "I'm looking for a fight"
struct TRINITY_DLL_DECL example_creatureAI : public ScriptedAI
{
//*** HANDLED FUNCTION ***
//This is the constructor, called only once when the Creature is first created
example_creatureAI(Creature *c) : ScriptedAI(c) {Reset();}
//*** CUSTOM VARIABLES ****
//These variables are for use only by this individual script.
//Nothing else will ever call them but us.
uint32 m_uiSay_Timer; //Timer for random chat
uint32 m_uiRebuff_Timer; //Timer for rebuffing
uint32 m_uiSpell_1_Timer; //Timer for spell 1 when in combat
uint32 m_uiSpell_2_Timer; //Timer for spell 1 when in combat
uint32 m_uiSpell_3_Timer; //Timer for spell 1 when in combat
uint32 m_uiBeserk_Timer; //Timer until we go into Beserk (enraged) mode
uint32 m_uiPhase; //The current battle phase we are in
uint32 m_uiPhase_Timer; //Timer until phase transition
//*** HANDLED FUNCTION ***
//This is called whenever the core decides we need to evade
void Reset()
{
m_uiPhase = 1; //Start in phase 1
m_uiPhase_Timer = 60000; //60 seconds
m_uiSpell_1_Timer = 5000; //5 seconds
m_uiSpell_2_Timer = 37000; //37 seconds
m_uiSpell_3_Timer = 19000; //19 seconds
m_uiBeserk_Timer = 120000; //2 minutes
}
//*** HANDLED FUNCTION ***
//Attack Start is called whenever someone hits us.
void EnterCombat(Unit* pWho)
{
//Say some stuff
DoScriptText(SAY_AGGRO, m_creature, pWho);
}
//Our Recive emote function
void ReceiveEmote(Player* pPlayer, uint32 uiTextEmote)
{
m_creature->HandleEmoteCommand(uiTextEmote);
switch(uiTextEmote)
{
case TEXTEMOTE_DANCE:
DoScriptText(SAY_DANCE, m_creature);
break;
case TEXTEMOTE_SALUTE:
DoScriptText(SAY_SALUTE, m_creature);
break;
}
}
//*** HANDLED FUNCTION ***
//Update AI is called Every single map update (roughly once every 100ms if a player is within the grid)
void UpdateAI(const uint32 uiDiff)
{
//Out of combat timers
if (!m_creature->getVictim())
{
//Random Say timer
if (m_uiSay_Timer <= uiDiff)
{
//Random switch between 5 outcomes
DoScriptText(RAND(SAY_RANDOM_0,SAY_RANDOM_1,SAY_RANDOM_2,SAY_RANDOM_3,SAY_RANDOM_4), m_creature);
m_uiSay_Timer = 45000; //Say something agian in 45 seconds
}
else
m_uiSay_Timer -= uiDiff;
//Rebuff timer
if (m_uiRebuff_Timer <= uiDiff)
{
DoCast(m_creature, SPELL_BUFF);
m_uiRebuff_Timer = 900000; //Rebuff agian in 15 minutes
}
else
m_uiRebuff_Timer -= uiDiff;
}
//Return since we have no target
if (!UpdateVictim())
return;
//Spell 1 timer
if (m_uiSpell_1_Timer <= uiDiff)
{
//Cast spell one on our current target.
if (rand()%50 > 10)
DoCast(m_creature->getVictim(), SPELL_ONE_ALT);
else if (m_creature->IsWithinDist(m_creature->getVictim(), 25.0f))
DoCast(m_creature->getVictim(), SPELL_ONE);
m_uiSpell_1_Timer = 5000;
}
else
m_uiSpell_1_Timer -= uiDiff;
//Spell 2 timer
if (m_uiSpell_2_Timer <= uiDiff)
{
//Cast spell one on our current target.
DoCast(m_creature->getVictim(), SPELL_TWO);
m_uiSpell_2_Timer = 37000;
}
else
m_uiSpell_2_Timer -= uiDiff;
//Beserk timer
if (m_uiPhase > 1)
{
//Spell 3 timer
if (m_uiSpell_3_Timer <= uiDiff)
{
//Cast spell one on our current target.
DoCast(m_creature->getVictim(), SPELL_THREE);
m_uiSpell_3_Timer = 19000;
}
else
m_uiSpell_3_Timer -= uiDiff;
if (m_uiBeserk_Timer <= uiDiff)
{
//Say our line then cast uber death spell
DoScriptText(SAY_BESERK, m_creature, m_creature->getVictim());
DoCast(m_creature->getVictim(), SPELL_BESERK);
//Cast our beserk spell agian in 12 seconds if we didn't kill everyone
m_uiBeserk_Timer = 12000;
}
else
m_uiBeserk_Timer -= uiDiff;
}
else if (m_uiPhase == 1) //Phase timer
{
if (m_uiPhase_Timer <= uiDiff)
{
//Go to next phase
++m_uiPhase;
DoScriptText(SAY_PHASE, m_creature);
DoCast(m_creature, SPELL_ENRAGE);
}
else
m_uiPhase_Timer -= uiDiff;
}
DoMeleeAttackIfReady();
}
};
//This is the GetAI method used by all scripts that involve AI
//It is called every time a new Creature using this script is created
CreatureAI* GetAI_example_creature(Creature* pCreature)
{
return new example_creatureAI (pCreature);
}
//This function is called when the player clicks an option on the gossip menu
bool GossipSelect_example_creature(Player* pPlayer, Creature* pCreature, uint32 uiSender, uint32 uiAction)
{
if (uiAction == GOSSIP_ACTION_INFO_DEF+1)
{
pPlayer->CLOSE_GOSSIP_MENU();
//Set our faction to hostile twoards all
pCreature->setFaction(FACTION_WORGEN);
pCreature->AI()->AttackStart(pPlayer);
}
return true;
}
//This function is called when the player opens the gossip menu
bool GossipHello_example_creature(Player* pPlayer, Creature* pCreature)
{
pPlayer->ADD_GOSSIP_ITEM(GOSSIP_ICON_CHAT, GOSSIP_ITEM, GOSSIP_SENDER_MAIN, GOSSIP_ACTION_INFO_DEF + 1);
pPlayer->SEND_GOSSIP_MENU(907, pCreature->GetGUID());
return true;
}
//This is the actual function called only once durring InitScripts()
//It must define all handled functions that are to be run in this script
void AddSC_example_creature()
{
Script* newscript;
newscript = new Script;
newscript->Name = "example_creature";
newscript->GetAI = &GetAI_example_creature;
newscript->pGossipHello = &GossipHello_example_creature;
newscript->pGossipSelect = &GossipSelect_example_creature;
newscript->RegisterSelf();
}
+229
View File
@@ -0,0 +1,229 @@
/* Copyright (C) 2006 - 2009 ScriptDev2 <https://scriptdev2.svn.sourceforge.net/>
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
/* ScriptData
SDName: Example_Escort
SD%Complete: 100
SDComment: Script used for testing escortAI
SDCategory: Script Examples
EndScriptData */
#include "ScriptedPch.h"
#include "ScriptedEscortAI.h"
enum eEnums
{
NPC_FELBOAR = 21878,
SPELL_DEATH_COIL = 33130,
SPELL_ELIXIR_OF_FORTITUDE = 3593,
SPELL_BLUE_FIREWORK = 11540,
SAY_AGGRO1 = -1999910,
SAY_AGGRO2 = -1999911,
SAY_WP_1 = -1999912,
SAY_WP_2 = -1999913,
SAY_WP_3 = -1999914,
SAY_WP_4 = -1999915,
SAY_DEATH_1 = -1999916,
SAY_DEATH_2 = -1999917,
SAY_DEATH_3 = -1999918,
SAY_SPELL = -1999919,
SAY_RAND_1 = -1999920,
SAY_RAND_2 = -1999921
};
#define GOSSIP_ITEM_1 "Click to Test Escort(Attack, Run)"
#define GOSSIP_ITEM_2 "Click to Test Escort(NoAttack, Walk)"
#define GOSSIP_ITEM_3 "Click to Test Escort(NoAttack, Run)"
struct TRINITY_DLL_DECL example_escortAI : public npc_escortAI
{
// CreatureAI functions
example_escortAI(Creature* pCreature) : npc_escortAI(pCreature) { }
uint32 m_uiDeathCoilTimer;
uint32 m_uiChatTimer;
void JustSummoned(Creature* pSummoned)
{
pSummoned->AI()->AttackStart(m_creature);
}
// Pure Virtual Functions (Have to be implemented)
void WaypointReached(uint32 uiWP)
{
switch (uiWP)
{
case 1:
DoScriptText(SAY_WP_1, m_creature);
break;
case 3:
DoScriptText(SAY_WP_2, m_creature);
m_creature->SummonCreature(NPC_FELBOAR, m_creature->GetPositionX()+5.0f, m_creature->GetPositionY()+7.0f, m_creature->GetPositionZ(), 0.0f, TEMPSUMMON_TIMED_DESPAWN_OUT_OF_COMBAT, 3000);
break;
case 4:
if (Player* pPlayer = GetPlayerForEscort())
{
//pTmpPlayer is the target of the text
DoScriptText(SAY_WP_3, m_creature, pPlayer);
//pTmpPlayer is the source of the text
DoScriptText(SAY_WP_4, pPlayer);
}
break;
}
}
void EnterCombat(Unit* pWho)
{
if (HasEscortState(STATE_ESCORT_ESCORTING))
{
if (Player* pPlayer = GetPlayerForEscort())
DoScriptText(SAY_AGGRO1, m_creature, pPlayer);
}
else
DoScriptText(SAY_AGGRO2, m_creature);
}
void Reset()
{
m_uiDeathCoilTimer = 4000;
m_uiChatTimer = 4000;
}
void JustDied(Unit* pKiller)
{
if (HasEscortState(STATE_ESCORT_ESCORTING))
{
if (Player* pPlayer = GetPlayerForEscort())
{
// not a likely case, code here for the sake of example
if (pKiller == m_creature)
{
DoScriptText(SAY_DEATH_1, m_creature, pPlayer);
}
else
DoScriptText(SAY_DEATH_2, m_creature, pPlayer);
}
}
else
DoScriptText(SAY_DEATH_3, m_creature);
}
void UpdateAI(const uint32 uiDiff)
{
//Must update npc_escortAI
npc_escortAI::UpdateAI(uiDiff);
//Combat check
if (m_creature->getVictim())
{
if (m_uiDeathCoilTimer <= uiDiff)
{
DoScriptText(SAY_SPELL, m_creature);
DoCast(m_creature->getVictim(), SPELL_DEATH_COIL, false);
m_uiDeathCoilTimer = 4000;
}
else
m_uiDeathCoilTimer -= uiDiff;
}
else
{
//Out of combat but being escorted
if (HasEscortState(STATE_ESCORT_ESCORTING))
{
if (m_uiChatTimer <= uiDiff)
{
if (m_creature->HasAura(SPELL_ELIXIR_OF_FORTITUDE, 0))
{
DoScriptText(SAY_RAND_1, m_creature);
DoCast(m_creature, SPELL_BLUE_FIREWORK, false);
}
else
{
DoScriptText(SAY_RAND_2, m_creature);
DoCast(m_creature, SPELL_ELIXIR_OF_FORTITUDE, false);
}
m_uiChatTimer = 12000;
}
else
m_uiChatTimer -= uiDiff;
}
}
}
};
CreatureAI* GetAI_example_escort(Creature* pCreature)
{
return new example_escortAI(pCreature);
}
bool GossipHello_example_escort(Player* pPlayer, Creature* pCreature)
{
pPlayer->TalkedToCreature(pCreature->GetEntry(), pCreature->GetGUID());
pPlayer->PrepareGossipMenu(pCreature, 0);
pPlayer->ADD_GOSSIP_ITEM(GOSSIP_ICON_CHAT, GOSSIP_ITEM_1, GOSSIP_SENDER_MAIN, GOSSIP_ACTION_INFO_DEF+1);
pPlayer->ADD_GOSSIP_ITEM(GOSSIP_ICON_CHAT, GOSSIP_ITEM_2, GOSSIP_SENDER_MAIN, GOSSIP_ACTION_INFO_DEF+2);
pPlayer->ADD_GOSSIP_ITEM(GOSSIP_ICON_CHAT, GOSSIP_ITEM_3, GOSSIP_SENDER_MAIN, GOSSIP_ACTION_INFO_DEF+3);
pPlayer->SendPreparedGossip(pCreature);
return true;
}
bool GossipSelect_example_escort(Player* pPlayer, Creature* pCreature, uint32 uiSender, uint32 uiAction)
{
npc_escortAI* pEscortAI = CAST_AI(example_escortAI, pCreature->AI());
switch(uiAction)
{
case GOSSIP_ACTION_INFO_DEF+1:
pPlayer->CLOSE_GOSSIP_MENU();
if (pEscortAI)
pEscortAI->Start(true, true, pPlayer->GetGUID());
break;
case GOSSIP_ACTION_INFO_DEF+2:
pPlayer->CLOSE_GOSSIP_MENU();
if (pEscortAI)
pEscortAI->Start(false, false, pPlayer->GetGUID());
break;
case GOSSIP_ACTION_INFO_DEF+3:
pPlayer->CLOSE_GOSSIP_MENU();
if (pEscortAI)
pEscortAI->Start(false, true, pPlayer->GetGUID());
break;
default:
return false; // nothing defined -> trinity core handling
}
return true; // no default handling -> prevent trinity core handling
}
void AddSC_example_escort()
{
Script *newscript;
newscript = new Script;
newscript->Name = "example_escort";
newscript->GetAI = &GetAI_example_escort;
newscript->pGossipHello = &GossipHello_example_escort;
newscript->pGossipSelect = &GossipSelect_example_escort;
newscript->RegisterSelf();
}
@@ -0,0 +1,99 @@
/* Copyright (C) 2006 - 2009 ScriptDev2 <https://scriptdev2.svn.sourceforge.net/>
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
/* ScriptData
SDName: Example_Gossip_Codebox
SD%Complete: 100
SDComment: Show a codebox in gossip option
SDCategory: Script Examples
EndScriptData */
#include "ScriptedPch.h"
#include <cstring>
enum eEnums
{
SPELL_POLYMORPH = 12826,
SPELL_MARK_OF_THE_WILD = 26990,
SAY_NOT_INTERESTED = -1999922,
SAY_WRONG = -1999923,
SAY_CORRECT = -1999924
};
#define GOSSIP_ITEM_1 "A quiz: what's your name?"
#define GOSSIP_ITEM_2 "I'm not interested"
//This function is called when the player opens the gossip menubool
bool GossipHello_example_gossip_codebox(Player* pPlayer, Creature* pCreature)
{
pPlayer->ADD_GOSSIP_ITEM_EXTENDED(0, GOSSIP_ITEM_1, GOSSIP_SENDER_MAIN, GOSSIP_ACTION_INFO_DEF+1, "", 0, true);
pPlayer->ADD_GOSSIP_ITEM(GOSSIP_ICON_CHAT, GOSSIP_ITEM_2, GOSSIP_SENDER_MAIN, GOSSIP_ACTION_INFO_DEF+2);
pPlayer->PlayerTalkClass->SendGossipMenu(907, pCreature->GetGUID());
return true;
}
//This function is called when the player clicks an option on the gossip menubool
bool GossipSelect_example_gossip_codebox(Player* pPlayer, Creature* pCreature, uint32 uiSender, uint32 uiAction)
{
if (uiAction == GOSSIP_ACTION_INFO_DEF+2)
{
DoScriptText(SAY_NOT_INTERESTED, pCreature);
pPlayer->CLOSE_GOSSIP_MENU();
}
return true;
}
bool GossipSelectWithCode_example_gossip_codebox(Player* pPlayer, Creature* pCreature, uint32 uiSender, uint32 uiAction, const char* sCode)
{
if (uiSender == GOSSIP_SENDER_MAIN)
{
switch (uiAction)
{
case GOSSIP_ACTION_INFO_DEF+1:
if (std::strcmp(sCode, pPlayer->GetName())!=0)
{
DoScriptText(SAY_WRONG, pCreature);
pCreature->CastSpell(pPlayer, SPELL_POLYMORPH, true);
}
else
{
DoScriptText(SAY_CORRECT, pCreature);
pCreature->CastSpell(pPlayer, SPELL_MARK_OF_THE_WILD, true);
}
pPlayer->CLOSE_GOSSIP_MENU();
return true;
}
}
return false;
}
void AddSC_example_gossip_codebox()
{
Script* newscript;
newscript = new Script;
newscript->Name = "example_gossip_codebox";
newscript->pGossipHello = &GossipHello_example_gossip_codebox;
newscript->pGossipSelect = &GossipSelect_example_gossip_codebox;
newscript->pGossipSelectWithCode = &GossipSelectWithCode_example_gossip_codebox;
newscript->RegisterSelf();
}
+69
View File
@@ -0,0 +1,69 @@
/* Copyright (C) 2006 - 2009 ScriptDev2 <https://scriptdev2.svn.sourceforge.net/>
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
/* ScriptData
SDName: Example_Misc
SD%Complete: 100
SDComment: Item, Areatrigger and other small code examples
SDCategory: Script Examples
EndScriptData */
#include "ScriptedPch.h"
#include "ScriptMgr.h"
enum eSay
{
SAY_HI = -1999925
};
bool AT_example_areatrigger(Player* pPlayer, const AreaTriggerEntry *pAt)
{
DoScriptText(SAY_HI, pPlayer);
return true;
}
extern void LoadDatabase();
bool ItemUse_example_item(Player* pPlayer, Item* pItem, SpellCastTargets const& scTargets)
{
sScriptMgr.LoadDatabase();
return true;
}
bool GOHello_example_go_teleporter(Player* pPlayer, GameObject* pGo)
{
pPlayer->TeleportTo(0, 1807.07f, 336.105f, 70.3975f, 0.0f);
return false;
}
void AddSC_example_misc()
{
Script* newscript;
newscript = new Script;
newscript->Name = "example_areatrigger";
newscript->pAreaTrigger = &AT_example_areatrigger;
newscript->RegisterSelf();
newscript = new Script;
newscript->Name = "example_item";
newscript->pItemUse = &ItemUse_example_item;
newscript->RegisterSelf();
newscript = new Script;
newscript->Name = "example_go_teleporter";
newscript->pGOHello = &GOHello_example_go_teleporter;
newscript->RegisterSelf();
}