Files
TCPlayerbotCore/src/server/game/AI/ScriptedAI/ScriptedSimpleAI.cpp
T

279 lines
8.0 KiB
C++
Raw Normal View History

2009-02-17 18:08:26 +01:00
/* 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
*/
2009-10-17 15:51:44 -07:00
/* ScriptData
SDName: SimpleAI
SD%Complete: 100
SDComment: Base Class for SimpleAI creatures
SDCategory: Creatures
EndScriptData */
2009-10-17 15:51:44 -07:00
#include "ScriptPCH.h"
2010-01-19 11:36:05 +01:00
#include "ScriptedSimpleAI.h"
2009-10-17 15:51:44 -07:00
SimpleAI::SimpleAI(Creature *c) : ScriptedAI(c)
{
//Clear all data
2009-02-20 14:14:16 +01:00
Aggro_TextId[0] = 0;
Aggro_TextId[1] = 0;
Aggro_TextId[2] = 0;
Aggro_Sound[0] = 0;
Aggro_Sound[1] = 0;
Aggro_Sound[2] = 0;
2009-10-17 15:51:44 -07:00
2009-02-20 14:14:16 +01:00
Death_TextId[0] = 0;
Death_TextId[1] = 0;
Death_TextId[2] = 0;
Death_Sound[0] = 0;
Death_Sound[1] = 0;
Death_Sound[2] = 0;
Death_Spell = 0;
Death_Target_Type = 0;
2009-10-17 15:51:44 -07:00
2009-02-20 14:14:16 +01:00
Kill_TextId[0] = 0;
Kill_TextId[1] = 0;
Kill_TextId[2] = 0;
Kill_Sound[0] = 0;
Kill_Sound[1] = 0;
Kill_Sound[2] = 0;
Kill_Spell = 0;
Kill_Target_Type = 0;
2009-10-17 15:51:44 -07:00
memset(Spell,0,sizeof(Spell));
2009-10-17 15:51:44 -07:00
EnterEvadeMode();
}
2009-10-17 15:51:44 -07:00
void SimpleAI::Reset()
{
}
2009-10-17 15:51:44 -07:00
2009-04-27 21:23:42 -05:00
void SimpleAI::EnterCombat(Unit *who)
{
//Reset cast timers
if (Spell[0].First_Cast >= 0)
Spell_Timer[0] = Spell[0].First_Cast;
else Spell_Timer[0] = 1000;
if (Spell[1].First_Cast >= 0)
Spell_Timer[1] = Spell[1].First_Cast;
else Spell_Timer[1] = 1000;
if (Spell[2].First_Cast >= 0)
Spell_Timer[2] = Spell[2].First_Cast;
else Spell_Timer[2] = 1000;
if (Spell[3].First_Cast >= 0)
Spell_Timer[3] = Spell[3].First_Cast;
else Spell_Timer[3] = 1000;
if (Spell[4].First_Cast >= 0)
Spell_Timer[4] = Spell[4].First_Cast;
else Spell_Timer[4] = 1000;
if (Spell[5].First_Cast >= 0)
Spell_Timer[5] = Spell[5].First_Cast;
else Spell_Timer[5] = 1000;
if (Spell[6].First_Cast >= 0)
Spell_Timer[6] = Spell[6].First_Cast;
else Spell_Timer[6] = 1000;
if (Spell[7].First_Cast >= 0)
Spell_Timer[7] = Spell[7].First_Cast;
else Spell_Timer[7] = 1000;
if (Spell[8].First_Cast >= 0)
Spell_Timer[8] = Spell[8].First_Cast;
else Spell_Timer[8] = 1000;
if (Spell[9].First_Cast >= 0)
Spell_Timer[9] = Spell[9].First_Cast;
else Spell_Timer[9] = 1000;
2009-10-17 15:51:44 -07:00
2009-10-14 15:18:02 -07:00
uint8 random_text = urand(0,2);
2009-10-17 15:51:44 -07:00
2009-02-20 14:14:16 +01:00
//Random text
if (Aggro_TextId[random_text])
2010-04-14 23:07:41 +02:00
DoScriptText(Aggro_TextId[random_text], me, who);
2009-10-17 15:51:44 -07:00
//Random sound
if (Aggro_Sound[random_text])
2010-04-14 23:07:41 +02:00
DoPlaySoundToSet(me, Aggro_Sound[random_text]);
}
2009-10-17 15:51:44 -07:00
void SimpleAI::KilledUnit(Unit *victim)
{
2009-10-14 15:18:02 -07:00
uint8 random_text = urand(0,2);
2009-10-17 15:51:44 -07:00
//Random yell
2009-02-20 14:14:16 +01:00
if (Kill_TextId[random_text])
2010-04-14 23:07:41 +02:00
DoScriptText(Kill_TextId[random_text], me, victim);
2009-10-17 15:51:44 -07:00
//Random sound
if (Kill_Sound[random_text])
2010-04-14 23:07:41 +02:00
DoPlaySoundToSet(me, Kill_Sound[random_text]);
2009-10-17 15:51:44 -07:00
if (!Kill_Spell)
return;
2009-10-17 15:51:44 -07:00
2009-10-27 21:28:20 -07:00
Unit *pTarget = NULL;
2009-10-17 15:51:44 -07:00
switch (Kill_Target_Type)
{
case CAST_SELF:
2010-04-14 23:07:41 +02:00
pTarget = me;
break;
case CAST_HOSTILE_TARGET:
2010-04-14 23:07:41 +02:00
pTarget = me->getVictim();
break;
case CAST_HOSTILE_SECOND_AGGRO:
2009-10-27 21:28:20 -07:00
pTarget = SelectUnit(SELECT_TARGET_TOPAGGRO,1);
break;
case CAST_HOSTILE_LAST_AGGRO:
2009-10-27 21:28:20 -07:00
pTarget = SelectUnit(SELECT_TARGET_BOTTOMAGGRO,0);
break;
case CAST_HOSTILE_RANDOM:
2009-10-27 21:28:20 -07:00
pTarget = SelectUnit(SELECT_TARGET_RANDOM,0);
break;
case CAST_KILLEDUNIT_VICTIM:
2009-10-27 21:28:20 -07:00
pTarget = victim;
break;
}
2009-10-17 15:51:44 -07:00
//Target is ok, cast a spell on it
2009-10-27 21:28:20 -07:00
if (pTarget)
DoCast(pTarget, Kill_Spell);
}
2009-10-17 15:51:44 -07:00
void SimpleAI::DamageTaken(Unit *killer, uint32 &damage)
{
//Return if damage taken won't kill us
2010-04-14 23:07:41 +02:00
if (me->GetHealth() > damage)
return;
2009-10-17 15:51:44 -07:00
2009-10-14 15:18:02 -07:00
uint8 random_text = urand(0,2);
2009-10-17 15:51:44 -07:00
//Random yell
2009-02-20 14:14:16 +01:00
if (Death_TextId[random_text])
2010-04-14 23:07:41 +02:00
DoScriptText(Death_TextId[random_text], me, killer);
2009-10-17 15:51:44 -07:00
//Random sound
if (Death_Sound[random_text])
2010-04-14 23:07:41 +02:00
DoPlaySoundToSet(me, Death_Sound[random_text]);
2009-10-17 15:51:44 -07:00
if (!Death_Spell)
return;
2009-10-17 15:51:44 -07:00
2009-10-27 21:28:20 -07:00
Unit *pTarget = NULL;
2009-10-17 15:51:44 -07:00
switch (Death_Target_Type)
{
case CAST_SELF:
2010-04-14 23:07:41 +02:00
pTarget = me;
break;
case CAST_HOSTILE_TARGET:
2010-04-14 23:07:41 +02:00
pTarget = me->getVictim();
break;
case CAST_HOSTILE_SECOND_AGGRO:
2009-10-27 21:28:20 -07:00
pTarget = SelectUnit(SELECT_TARGET_TOPAGGRO,1);
break;
case CAST_HOSTILE_LAST_AGGRO:
2009-10-27 21:28:20 -07:00
pTarget = SelectUnit(SELECT_TARGET_BOTTOMAGGRO,0);
break;
case CAST_HOSTILE_RANDOM:
2009-10-27 21:28:20 -07:00
pTarget = SelectUnit(SELECT_TARGET_RANDOM,0);
break;
case CAST_JUSTDIED_KILLER:
2009-10-27 21:28:20 -07:00
pTarget = killer;
break;
}
2009-10-17 15:51:44 -07:00
//Target is ok, cast a spell on it
2009-10-27 21:28:20 -07:00
if (pTarget)
DoCast(pTarget, Death_Spell);
}
2009-10-17 15:51:44 -07:00
void SimpleAI::UpdateAI(const uint32 diff)
{
//Return since we have no target
2009-01-30 18:10:05 -06:00
if (!UpdateVictim())
return;
2009-10-17 15:51:44 -07:00
//Spells
for (uint32 i = 0; i < 10; ++i)
{
//Spell not valid
if (!Spell[i].Enabled || !Spell[i].Spell_Id)
continue;
2009-10-17 15:51:44 -07:00
2009-10-27 17:07:40 -07:00
if (Spell_Timer[i] <= diff)
{
//Check if this is a percentage based
2010-08-26 01:20:57 +06:00
if (Spell[i].First_Cast < 0 && Spell[i].First_Cast > -100 && HealthAbovePct(uint32(-Spell[i].First_Cast)))
continue;
2009-10-17 15:51:44 -07:00
//Check Current spell
2010-04-14 23:07:41 +02:00
if (!(Spell[i].InterruptPreviousCast && me->IsNonMeleeSpellCasted(false)))
{
2009-10-27 21:28:20 -07:00
Unit *pTarget = NULL;
2009-10-17 15:51:44 -07:00
switch (Spell[i].Cast_Target_Type)
{
case CAST_SELF:
2010-04-14 23:07:41 +02:00
pTarget = me;
break;
case CAST_HOSTILE_TARGET:
2010-04-14 23:07:41 +02:00
pTarget = me->getVictim();
break;
case CAST_HOSTILE_SECOND_AGGRO:
2009-10-27 21:28:20 -07:00
pTarget = SelectUnit(SELECT_TARGET_TOPAGGRO,1);
break;
case CAST_HOSTILE_LAST_AGGRO:
2009-10-27 21:28:20 -07:00
pTarget = SelectUnit(SELECT_TARGET_BOTTOMAGGRO,0);
break;
case CAST_HOSTILE_RANDOM:
2009-10-27 21:28:20 -07:00
pTarget = SelectUnit(SELECT_TARGET_RANDOM,0);
break;
}
2009-10-17 15:51:44 -07:00
//Target is ok, cast a spell on it and then do our random yell
2009-10-27 21:28:20 -07:00
if (pTarget)
{
2010-04-14 23:07:41 +02:00
if (me->IsNonMeleeSpellCasted(false))
me->InterruptNonMeleeSpells(false);
2009-10-17 15:51:44 -07:00
2009-10-27 21:28:20 -07:00
DoCast(pTarget, Spell[i].Spell_Id);
2009-10-17 15:51:44 -07:00
//Yell and sound use the same number so that you can make
2009-08-15 00:32:04 +02:00
//the Creature yell with the correct sound effect attached
2009-10-14 15:18:02 -07:00
uint8 random_text = urand(0,2);
2009-10-17 15:51:44 -07:00
//Random yell
2009-02-20 14:14:16 +01:00
if (Spell[i].TextId[random_text])
2010-04-14 23:07:41 +02:00
DoScriptText(Spell[i].TextId[random_text], me, pTarget);
2009-10-17 15:51:44 -07:00
//Random sound
if (Spell[i].Text_Sound[random_text])
2010-04-14 23:07:41 +02:00
DoPlaySoundToSet(me, Spell[i].Text_Sound[random_text]);
}
2009-10-17 15:51:44 -07:00
}
2009-10-17 15:51:44 -07:00
//Spell will cast agian when the cooldown is up
if (Spell[i].CooldownRandomAddition)
Spell_Timer[i] = Spell[i].Cooldown + (rand() % Spell[i].CooldownRandomAddition);
else Spell_Timer[i] = Spell[i].Cooldown;
2009-10-17 15:51:44 -07:00
2009-10-27 21:28:20 -07:00
} else Spell_Timer[i] -= diff;
2009-10-17 15:51:44 -07:00
}
2009-10-17 15:51:44 -07:00
DoMeleeAttackIfReady();
}
2009-02-17 20:07:49 -06:00