Skip to content

Commit

Permalink
Cleaned up AI scripts.
Browse files Browse the repository at this point in the history
  • Loading branch information
AnchyDev committed Nov 14, 2023
1 parent 7ab3cf0 commit 1d60fbb
Show file tree
Hide file tree
Showing 7 changed files with 137 additions and 407 deletions.
4 changes: 2 additions & 2 deletions data/sql/db-world/base/tos_world_base.sql
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,7 @@ INSERT INTO `creature_template` (`entry`, `difficulty_entry_1`, `difficulty_entr
DELETE FROM `creature_template` WHERE `entry`=441506;
INSERT INTO `creature_template` (`entry`, `difficulty_entry_1`, `difficulty_entry_2`, `difficulty_entry_3`, `KillCredit1`, `KillCredit2`, `modelid1`, `modelid2`, `modelid3`, `modelid4`, `name`, `subname`, `IconName`, `gossip_menu_id`, `minlevel`, `maxlevel`, `exp`, `faction`, `npcflag`, `speed_walk`, `speed_run`, `speed_swim`, `speed_flight`, `detection_range`, `scale`, `rank`, `dmgschool`, `DamageModifier`, `BaseAttackTime`, `RangeAttackTime`, `BaseVariance`, `RangeVariance`, `unit_class`, `unit_flags`, `unit_flags2`, `dynamicflags`, `family`, `trainer_type`, `trainer_spell`, `trainer_class`, `trainer_race`, `type`, `type_flags`, `lootid`, `pickpocketloot`, `skinloot`, `PetSpellDataId`, `VehicleId`, `mingold`, `maxgold`, `AIName`, `MovementType`, `HoverHeight`, `HealthModifier`, `ManaModifier`, `ArmorModifier`, `ExperienceModifier`, `RacialLeader`, `movementId`, `RegenHealth`, `mechanic_immune_mask`, `spell_school_immune_mask`, `flags_extra`, `ScriptName`, `VerifiedBuild`) VALUES (441506, 0, 0, 0, 0, 0, 2029, 0, 0, 0, 'Edwin VanCleef', 'Defias Kingpin', NULL, 0, 80, 80, 0, 17, 0, 1, 1.14286, 1, 1, 20, 1, 1, 0, 2, 2000, 2000, 1, 1, 1, 64, 2048, 0, 0, 0, 0, 0, 0, 7, 0, 0, 0, 0, 0, 0, 0, 0, 'SmartAI', 0, 1, 3, 1, 1, 2, 0, 0, 1, 0, 0, 0, '', -1);
DELETE FROM `creature_template` WHERE `entry`=441505;
INSERT INTO `creature_template` (`entry`, `difficulty_entry_1`, `difficulty_entry_2`, `difficulty_entry_3`, `KillCredit1`, `KillCredit2`, `modelid1`, `modelid2`, `modelid3`, `modelid4`, `name`, `subname`, `IconName`, `gossip_menu_id`, `minlevel`, `maxlevel`, `exp`, `faction`, `npcflag`, `speed_walk`, `speed_run`, `speed_swim`, `speed_flight`, `detection_range`, `scale`, `rank`, `dmgschool`, `DamageModifier`, `BaseAttackTime`, `RangeAttackTime`, `BaseVariance`, `RangeVariance`, `unit_class`, `unit_flags`, `unit_flags2`, `dynamicflags`, `family`, `trainer_type`, `trainer_spell`, `trainer_class`, `trainer_race`, `type`, `type_flags`, `lootid`, `pickpocketloot`, `skinloot`, `PetSpellDataId`, `VehicleId`, `mingold`, `maxgold`, `AIName`, `MovementType`, `HoverHeight`, `HealthModifier`, `ManaModifier`, `ArmorModifier`, `ExperienceModifier`, `RacialLeader`, `movementId`, `RegenHealth`, `mechanic_immune_mask`, `spell_school_immune_mask`, `flags_extra`, `ScriptName`, `VerifiedBuild`) VALUES (441505, 0, 0, 0, 0, 0, 2338, 2339, 0, 0, 'Defias Pillager', '', NULL, 0, 80, 80, 0, 17, 0, 1, 1.14286, 1, 1, 18, 1, 0, 0, 1, 2000, 2000, 1, 1, 8, 32768, 2048, 0, 0, 0, 0, 0, 0, 7, 0, 0, 0, 0, 0, 0, 0, 0, 'SmartAI', 1, 1, 2, 1, 1, 1, 0, 0, 1, 0, 0, 0, 'ToSEnemyCombatantSpellAlphaScript', -1);
INSERT INTO `creature_template` (`entry`, `difficulty_entry_1`, `difficulty_entry_2`, `difficulty_entry_3`, `KillCredit1`, `KillCredit2`, `modelid1`, `modelid2`, `modelid3`, `modelid4`, `name`, `subname`, `IconName`, `gossip_menu_id`, `minlevel`, `maxlevel`, `exp`, `faction`, `npcflag`, `speed_walk`, `speed_run`, `speed_swim`, `speed_flight`, `detection_range`, `scale`, `rank`, `dmgschool`, `DamageModifier`, `BaseAttackTime`, `RangeAttackTime`, `BaseVariance`, `RangeVariance`, `unit_class`, `unit_flags`, `unit_flags2`, `dynamicflags`, `family`, `trainer_type`, `trainer_spell`, `trainer_class`, `trainer_race`, `type`, `type_flags`, `lootid`, `pickpocketloot`, `skinloot`, `PetSpellDataId`, `VehicleId`, `mingold`, `maxgold`, `AIName`, `MovementType`, `HoverHeight`, `HealthModifier`, `ManaModifier`, `ArmorModifier`, `ExperienceModifier`, `RacialLeader`, `movementId`, `RegenHealth`, `mechanic_immune_mask`, `spell_school_immune_mask`, `flags_extra`, `ScriptName`, `VerifiedBuild`) VALUES (441505, 0, 0, 0, 0, 0, 2338, 2339, 0, 0, 'Defias Pillager', '', NULL, 0, 80, 80, 0, 17, 0, 1, 1.14286, 1, 1, 18, 1, 0, 0, 1, 2000, 2000, 1, 1, 8, 32768, 2048, 0, 0, 0, 0, 0, 0, 7, 0, 0, 0, 0, 0, 0, 0, 0, 'SmartAI', 1, 1, 2, 1, 1, 1, 0, 0, 1, 0, 0, 0, 'ToSAISpellElemental', -1);
DELETE FROM `creature_template` WHERE `entry`=441504;
INSERT INTO `creature_template` (`entry`, `difficulty_entry_1`, `difficulty_entry_2`, `difficulty_entry_3`, `KillCredit1`, `KillCredit2`, `modelid1`, `modelid2`, `modelid3`, `modelid4`, `name`, `subname`, `IconName`, `gossip_menu_id`, `minlevel`, `maxlevel`, `exp`, `faction`, `npcflag`, `speed_walk`, `speed_run`, `speed_swim`, `speed_flight`, `detection_range`, `scale`, `rank`, `dmgschool`, `DamageModifier`, `BaseAttackTime`, `RangeAttackTime`, `BaseVariance`, `RangeVariance`, `unit_class`, `unit_flags`, `unit_flags2`, `dynamicflags`, `family`, `trainer_type`, `trainer_spell`, `trainer_class`, `trainer_race`, `type`, `type_flags`, `lootid`, `pickpocketloot`, `skinloot`, `PetSpellDataId`, `VehicleId`, `mingold`, `maxgold`, `AIName`, `MovementType`, `HoverHeight`, `HealthModifier`, `ManaModifier`, `ArmorModifier`, `ExperienceModifier`, `RacialLeader`, `movementId`, `RegenHealth`, `mechanic_immune_mask`, `spell_school_immune_mask`, `flags_extra`, `ScriptName`, `VerifiedBuild`) VALUES (441504, 0, 0, 0, 0, 0, 4418, 4419, 0, 0, 'Defias Smuggler', '', NULL, 0, 80, 80, 0, 17, 0, 1, 1.14286, 1, 1, 18, 1, 0, 0, 1, 2000, 2000, 1, 1, 1, 32768, 2048, 0, 0, 0, 0, 0, 0, 7, 0, 0, 0, 0, 0, 0, 0, 0, 'SmartAI', 0, 1, 1, 1, 1, 1, 0, 0, 1, 0, 0, 0, '', -1);
DELETE FROM `creature_template` WHERE `entry`=441503;
Expand All @@ -303,7 +303,7 @@ INSERT INTO `creature_template` (`entry`, `difficulty_entry_1`, `difficulty_entr
DELETE FROM `creature_template` WHERE `entry`=441502;
INSERT INTO `creature_template` (`entry`, `difficulty_entry_1`, `difficulty_entry_2`, `difficulty_entry_3`, `KillCredit1`, `KillCredit2`, `modelid1`, `modelid2`, `modelid3`, `modelid4`, `name`, `subname`, `IconName`, `gossip_menu_id`, `minlevel`, `maxlevel`, `exp`, `faction`, `npcflag`, `speed_walk`, `speed_run`, `speed_swim`, `speed_flight`, `detection_range`, `scale`, `rank`, `dmgschool`, `DamageModifier`, `BaseAttackTime`, `RangeAttackTime`, `BaseVariance`, `RangeVariance`, `unit_class`, `unit_flags`, `unit_flags2`, `dynamicflags`, `family`, `trainer_type`, `trainer_spell`, `trainer_class`, `trainer_race`, `type`, `type_flags`, `lootid`, `pickpocketloot`, `skinloot`, `PetSpellDataId`, `VehicleId`, `mingold`, `maxgold`, `AIName`, `MovementType`, `HoverHeight`, `HealthModifier`, `ManaModifier`, `ArmorModifier`, `ExperienceModifier`, `RacialLeader`, `movementId`, `RegenHealth`, `mechanic_immune_mask`, `spell_school_immune_mask`, `flags_extra`, `ScriptName`, `VerifiedBuild`) VALUES (441502, 0, 0, 0, 0, 0, 384, 0, 0, 0, 'Hogger', NULL, NULL, 0, 80, 80, 0, 20, 0, 1.2, 1.14286, 1, 1, 20, 1, 1, 0, 2, 2000, 2000, 1, 1, 1, 64, 2048, 0, 0, 0, 0, 0, 0, 7, 0, 0, 0, 0, 0, 0, 0, 0, 'SmartAI', 1, 1, 3, 1, 1, 1, 0, 0, 1, 0, 0, 0, '', -1);
DELETE FROM `creature_template` WHERE `entry`=441501;
INSERT INTO `creature_template` (`entry`, `difficulty_entry_1`, `difficulty_entry_2`, `difficulty_entry_3`, `KillCredit1`, `KillCredit2`, `modelid1`, `modelid2`, `modelid3`, `modelid4`, `name`, `subname`, `IconName`, `gossip_menu_id`, `minlevel`, `maxlevel`, `exp`, `faction`, `npcflag`, `speed_walk`, `speed_run`, `speed_swim`, `speed_flight`, `detection_range`, `scale`, `rank`, `dmgschool`, `DamageModifier`, `BaseAttackTime`, `RangeAttackTime`, `BaseVariance`, `RangeVariance`, `unit_class`, `unit_flags`, `unit_flags2`, `dynamicflags`, `family`, `trainer_type`, `trainer_spell`, `trainer_class`, `trainer_race`, `type`, `type_flags`, `lootid`, `pickpocketloot`, `skinloot`, `PetSpellDataId`, `VehicleId`, `mingold`, `maxgold`, `AIName`, `MovementType`, `HoverHeight`, `HealthModifier`, `ManaModifier`, `ArmorModifier`, `ExperienceModifier`, `RacialLeader`, `movementId`, `RegenHealth`, `mechanic_immune_mask`, `spell_school_immune_mask`, `flags_extra`, `ScriptName`, `VerifiedBuild`) VALUES (441501, 0, 0, 0, 0, 0, 10791, 0, 0, 0, 'Riverpaw Runt', NULL, NULL, 0, 80, 80, 0, 20, 0, 1, 0.85714, 1, 1, 18, 1, 0, 0, 1, 2000, 2000, 1, 1, 1, 0, 2048, 0, 0, 0, 0, 0, 0, 7, 0, 0, 0, 0, 0, 0, 0, 0, 'SmartAI', 1, 1, 1, 1, 1, 1, 0, 100, 1, 0, 0, 0, '', -1);
INSERT INTO `creature_template` (`entry`, `difficulty_entry_1`, `difficulty_entry_2`, `difficulty_entry_3`, `KillCredit1`, `KillCredit2`, `modelid1`, `modelid2`, `modelid3`, `modelid4`, `name`, `subname`, `IconName`, `gossip_menu_id`, `minlevel`, `maxlevel`, `exp`, `faction`, `npcflag`, `speed_walk`, `speed_run`, `speed_swim`, `speed_flight`, `detection_range`, `scale`, `rank`, `dmgschool`, `DamageModifier`, `BaseAttackTime`, `RangeAttackTime`, `BaseVariance`, `RangeVariance`, `unit_class`, `unit_flags`, `unit_flags2`, `dynamicflags`, `family`, `trainer_type`, `trainer_spell`, `trainer_class`, `trainer_race`, `type`, `type_flags`, `lootid`, `pickpocketloot`, `skinloot`, `PetSpellDataId`, `VehicleId`, `mingold`, `maxgold`, `AIName`, `MovementType`, `HoverHeight`, `HealthModifier`, `ManaModifier`, `ArmorModifier`, `ExperienceModifier`, `RacialLeader`, `movementId`, `RegenHealth`, `mechanic_immune_mask`, `spell_school_immune_mask`, `flags_extra`, `ScriptName`, `VerifiedBuild`) VALUES (441501, 0, 0, 0, 0, 0, 10791, 0, 0, 0, 'Riverpaw Runt', NULL, NULL, 0, 80, 80, 0, 20, 0, 1, 0.85714, 1, 1, 18, 1, 0, 0, 1, 2000, 2000, 1, 1, 1, 0, 2048, 0, 0, 0, 0, 0, 0, 7, 0, 0, 0, 0, 0, 0, 0, 0, 'SmartAI', 1, 1, 1, 1, 1, 1, 0, 100, 1, 0, 0, 0, 'ToSAIMeleeAngry', -1);
DELETE FROM `creature_template` WHERE `entry`=441500;
INSERT INTO `creature_template` (`entry`, `difficulty_entry_1`, `difficulty_entry_2`, `difficulty_entry_3`, `KillCredit1`, `KillCredit2`, `modelid1`, `modelid2`, `modelid3`, `modelid4`, `name`, `subname`, `IconName`, `gossip_menu_id`, `minlevel`, `maxlevel`, `exp`, `faction`, `npcflag`, `speed_walk`, `speed_run`, `speed_swim`, `speed_flight`, `detection_range`, `scale`, `rank`, `dmgschool`, `DamageModifier`, `BaseAttackTime`, `RangeAttackTime`, `BaseVariance`, `RangeVariance`, `unit_class`, `unit_flags`, `unit_flags2`, `dynamicflags`, `family`, `trainer_type`, `trainer_spell`, `trainer_class`, `trainer_race`, `type`, `type_flags`, `lootid`, `pickpocketloot`, `skinloot`, `PetSpellDataId`, `VehicleId`, `mingold`, `maxgold`, `AIName`, `MovementType`, `HoverHeight`, `HealthModifier`, `ManaModifier`, `ArmorModifier`, `ExperienceModifier`, `RacialLeader`, `movementId`, `RegenHealth`, `mechanic_immune_mask`, `spell_school_immune_mask`, `flags_extra`, `ScriptName`, `VerifiedBuild`) VALUES (441500, 0, 0, 0, 0, 0, 512, 0, 0, 0, 'Riverpaw Outrunner', NULL, NULL, 0, 80, 80, 0, 20, 0, 1.2, 0.85714, 1, 1, 18, 1, 0, 0, 1, 2000, 2000, 1, 1, 1, 0, 2048, 0, 0, 0, 0, 0, 0, 7, 0, 0, 0, 0, 0, 0, 0, 0, 'SmartAI', 1, 1, 1, 1, 1, 1, 0, 100, 1, 0, 0, 0, '', -1);

Expand Down
13 changes: 8 additions & 5 deletions src/TrialOfStrength.cpp
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
#include "TrialOfStrength.h"
#include "ToSMapMgr.h"

#include "scripts/AI/ToSEnemyCombatantMeleeAlphaScript.h"
#include "scripts/AI/ToSAIArenaSpectator.h"
#include "scripts/AI/ToSAIMeleeAngry.h"
#include "scripts/AI/ToSAISpellElemental.h"

#include "scripts/AI/ToSEnemyCombatantBossScript.h"

#include "scripts/ToSArenaMasterScript.h"
#include "scripts/AI/ToSArenaSpectatorScript.h"

#include "scripts/ToSInstanceScript.h"
#include "scripts/ToSInstanceMapScript.h"
Expand Down Expand Up @@ -179,10 +179,13 @@ void SC_AddTrialOfStrengthScripts()
new ToSWorldScript();

new ToSArenaMasterScript();
new ToSArenaSpectatorScript();

new ToSEnemyCombatantMeleeAlphaScript();
new ToSAISpellElemental();
// AI Scripts
{
new ToSAIArenaSpectator();
new ToSAIMeleeAngry();
new ToSAISpellElemental();
}

new ToSEnemyCombatantBossScript();

Expand Down
Original file line number Diff line number Diff line change
@@ -1,29 +1,30 @@
#ifndef MODULE_TRIAL_OF_STRENGTH_ARENA_SPECTATOR_H
#define MODULE_TRIAL_OF_STRENGTH_ARENA_SPECTATOR_H

#include "ToSInstanceScript.h"
#ifndef MODULE_TRIAL_OF_STRENGTH_AI_ARENA_SPECTATOR_H
#define MODULE_TRIAL_OF_STRENGTH_AI_ARENA_SPECTATOR_H

#include "ScriptMgr.h"
#include "ScriptedCreature.h"
#include "ToSInstanceScript.h"

class ToSArenaSpectatorScript : public CreatureScript
class ToSAIArenaSpectator : public CreatureScript
{
public:
ToSArenaSpectatorScript() : CreatureScript("ToSArenaSpectatorScript") { }
ToSAIArenaSpectator() : CreatureScript("ToSAIArenaSpectator") { }

CreatureAI* GetAI(Creature* creature) const override
{
return new ToSArenaSpectatorAIScript(creature);
return new ToSAIArenaSpectatorAI(creature);
}

class ToSArenaSpectatorAIScript : public ScriptedAI
struct ToSAIArenaSpectatorAI : public ScriptedAI
{
enum ToSSpectatorConstants
{
TOS_ARENA_SPEC_DO_EMOTE = 1
};

public:
ToSArenaSpectatorAIScript(Creature* creature) : ScriptedAI(creature)
EventMap events;

ToSAIArenaSpectatorAI(Creature* creature) : ScriptedAI(creature)
{
events.Reset();
events.ScheduleEvent(TOS_ARENA_SPEC_DO_EMOTE, randtime(3s, 10s));
Expand Down Expand Up @@ -73,13 +74,7 @@ class ToSArenaSpectatorScript : public CreatureScript
break;
}
}

private:
EventMap events;
};

private:
EventMap events;
};

#endif // MODULE_TRIAL_OF_STRENGTH_ARENA_SPECTATOR_H
#endif // MODULE_TRIAL_OF_STRENGTH_AI_ARENA_SPECTATOR_H
108 changes: 108 additions & 0 deletions src/scripts/AI/ToSAIMeleeAngry.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
#ifndef MODULE_TRIAL_OF_STRENGTH_AI_MELEE_ANGRY_H
#define MODULE_TRIAL_OF_STRENGTH_AI_MELEE_ANGRY_H

#include "ScriptMgr.h"

class ToSAIMeleeAngry : public CreatureScript
{
public:
ToSAIMeleeAngry() : CreatureScript("ToSAIMeleeAngry") { }

CreatureAI* GetAI(Creature* creature) const override
{
return new ToSAIMeleeAngryAI(creature);
}

struct ToSAIMeleeAngryAI : public CombatAI
{
enum CombatantEvents
{
TOS_EVENT_COMBATANT_START_PUNCHING = 1,
TOS_EVENT_COMBATANT_AURA_ANGRY = 23128, /* Enrage */
TOS_EVENT_COMBATANT_SPELL_PUNCH = 29581,
};

EventMap events;

bool isPunching;
bool isAngry;

ToSAIMeleeAngryAI(Creature* creature) : CombatAI(creature)
{
events.Reset();

isPunching = false;
isAngry = false;
}

void Reset() override
{
if (me->HasAura(TOS_EVENT_COMBATANT_AURA_ANGRY))
{
me->RemoveAura(TOS_EVENT_COMBATANT_AURA_ANGRY);
}

isPunching = false;
isAngry = false;

events.Reset();
}

void UpdateAI(uint32 diff) override
{
if (!UpdateVictim())
return;

events.Update(diff);

switch (events.ExecuteEvent())
{
case TOS_EVENT_COMBATANT_START_PUNCHING:
TryPunching();

events.RescheduleEvent(TOS_EVENT_COMBATANT_START_PUNCHING, 3s);
break;
}

if (me->GetHealthPct() < 66 && !isPunching)
{
isPunching = true;

events.ScheduleEvent(TOS_EVENT_COMBATANT_START_PUNCHING, 1s);
}

if (me->GetHealthPct() < 50 && !isAngry)
{
GetAngry();
}

DoMeleeAttackIfReady();
}

void GetAngry()
{
me->AddAura(TOS_EVENT_COMBATANT_AURA_ANGRY, me);

isAngry = true;
}

void TryPunching()
{
auto creature = me->GetVictim();
if (!creature)
{
return;
}

// Outside 5yd range.
if (creature->GetPosition().GetExactDist(me->GetPosition()) > 5.0f)
{
return;
}

me->CastSpell(creature, TOS_EVENT_COMBATANT_SPELL_PUNCH);
}
};
};

#endif // MODULE_TRIAL_OF_STRENGTH_AI_MELEE_ANGRY_H
14 changes: 7 additions & 7 deletions src/scripts/AI/ToSAISpellElemental.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#ifndef MODULE_TRIAL_OF_STRENGTH_ENEMY_COMBATANT_SPELL_ALPHA_H
#define MODULE_TRIAL_OF_STRENGTH_ENEMY_COMBATANT_SPELL_ALPHA_H
#ifndef MODULE_TRIAL_OF_STRENGTH_AI_SPELL_ELEMENTAL_H
#define MODULE_TRIAL_OF_STRENGTH_AI_SPELL_ELEMENTAL_H

#include "ScriptMgr.h"

Expand All @@ -8,12 +8,12 @@ class ToSAISpellElemental : public CreatureScript
public:
ToSAISpellElemental() : CreatureScript("ToSAISpellElemental") { }

virtual CreatureAI* GetAI(Creature* creature) const
CreatureAI* GetAI(Creature* creature) const override
{
return new ToSEnemyCombatantSpellAlphaAI(creature);
return new ToSAISpellElementalAI(creature);
}

struct ToSEnemyCombatantSpellAlphaAI : public CombatAI
struct ToSAISpellElementalAI : public CombatAI
{
enum CombatantEvents
{
Expand All @@ -35,7 +35,7 @@ class ToSAISpellElemental : public CreatureScript

uint32 currentSpell;

ToSEnemyCombatantSpellAlphaAI(Creature* creature) : CombatAI(creature)
ToSAISpellElementalAI(Creature* creature) : CombatAI(creature)
{
Reset();
}
Expand Down Expand Up @@ -104,4 +104,4 @@ class ToSAISpellElemental : public CreatureScript
};
};

#endif // MODULE_TRIAL_OF_STRENGTH_ENEMY_COMBATANT_SPELL_ALPHA_H
#endif // MODULE_TRIAL_OF_STRENGTH_AI_SPELL_ELEMENTAL_H
Loading

0 comments on commit 1d60fbb

Please sign in to comment.