More work on scripts.
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
// Copyright (c) CypherCore <http://github.com/CypherCore> All rights reserved.
|
||||
// Copyright (c) CypherCore <http://github.com/CypherCore> All rights reserved.
|
||||
// Licensed under the GNU GENERAL PUBLIC LICENSE. See LICENSE file in the project root for full license information.
|
||||
|
||||
using Framework.Constants;
|
||||
@@ -6,108 +6,99 @@ using Game.AI;
|
||||
using Game.Combat;
|
||||
using Game.Entities;
|
||||
using Game.Scripting;
|
||||
using Game.Spells;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Scripts.Pets
|
||||
namespace Scripts.Pets.Hunter
|
||||
{
|
||||
namespace Hunter
|
||||
[Script]
|
||||
class npc_pet_hunter_snake_trap : ScriptedAI
|
||||
{
|
||||
struct SpellIds
|
||||
const uint SpellHunterCripplingPoison = 30981; // Viper
|
||||
const uint SpellHunterDeadlyPoisonPassive = 34657; // Venomous Snake
|
||||
const uint SpellHunterMindNumbingPoison = 25810; // Viper
|
||||
|
||||
const uint NpcHunterViper = 19921;
|
||||
|
||||
bool _isViper;
|
||||
uint _spellTimer;
|
||||
|
||||
public npc_pet_hunter_snake_trap(Creature creature) : base(creature) { }
|
||||
|
||||
public override void JustEngagedWith(Unit who) { }
|
||||
|
||||
public override void JustAppeared()
|
||||
{
|
||||
public const uint CripplingPoison = 30981; // Viper
|
||||
public const uint DeadlyPoisonPassive = 34657; // Venomous Snake
|
||||
public const uint MindNumbingPoison = 25810; // Viper
|
||||
_isViper = me.GetEntry() == NpcHunterViper ? true : false;
|
||||
|
||||
me.SetMaxHealth((uint)(107 * (me.GetLevel() - 40) * 0.025f));
|
||||
// Add delta to make them not all hit the same time
|
||||
me.SetBaseAttackTime(WeaponAttackType.BaseAttack, me.GetBaseAttackTime(WeaponAttackType.BaseAttack) + RandomHelper.URand(0, 6));
|
||||
|
||||
if (!_isViper && !me.HasAura(SpellHunterDeadlyPoisonPassive))
|
||||
DoCast(me, SpellHunterDeadlyPoisonPassive, true);
|
||||
}
|
||||
|
||||
struct CreatureIds
|
||||
// Redefined for random target selection:
|
||||
public override void MoveInLineOfSight(Unit who) { }
|
||||
|
||||
public override void UpdateAI(uint diff)
|
||||
{
|
||||
public const int Viper = 19921;
|
||||
}
|
||||
|
||||
[Script]
|
||||
class npc_pet_hunter_snake_trap : ScriptedAI
|
||||
{
|
||||
public npc_pet_hunter_snake_trap(Creature creature) : base(creature) { }
|
||||
|
||||
public override void JustEngagedWith(Unit who) { }
|
||||
|
||||
public override void JustAppeared()
|
||||
{
|
||||
_isViper = me.GetEntry() == CreatureIds.Viper ? true : false;
|
||||
|
||||
me.SetMaxHealth((uint)(107 * (me.GetLevel() - 40) * 0.025f));
|
||||
// Add delta to make them not all hit the same time
|
||||
me.SetBaseAttackTime(WeaponAttackType.BaseAttack, me.GetBaseAttackTime(WeaponAttackType.BaseAttack) + RandomHelper.URand(0, 6) * Time.InMilliseconds);
|
||||
|
||||
if (!_isViper && !me.HasAura(SpellIds.DeadlyPoisonPassive))
|
||||
DoCast(me, SpellIds.DeadlyPoisonPassive, new CastSpellExtraArgs(true));
|
||||
if (me.GetVictim() != null && me.GetVictim().HasBreakableByDamageCrowdControlAura())
|
||||
{ // don't break cc
|
||||
me.GetThreatManager().ClearFixate();
|
||||
me.InterruptNonMeleeSpells(false);
|
||||
me.AttackStop();
|
||||
return;
|
||||
}
|
||||
|
||||
// Redefined for random target selection:
|
||||
public override void MoveInLineOfSight(Unit who) { }
|
||||
if (me.IsSummon() && me.GetThreatManager().GetFixateTarget() == null)
|
||||
{ // find new target
|
||||
Unit summoner = me.ToTempSummon().GetSummonerUnit();
|
||||
|
||||
public override void UpdateAI(uint diff)
|
||||
{
|
||||
if (me.GetVictim() && me.GetVictim().HasBreakableByDamageCrowdControlAura())
|
||||
{ // don't break cc
|
||||
me.GetThreatManager().ClearFixate();
|
||||
me.InterruptNonMeleeSpells(false);
|
||||
me.AttackStop();
|
||||
return;
|
||||
List<Unit> targets = new();
|
||||
|
||||
void addTargetIfValid(CombatReference refe)
|
||||
{
|
||||
Unit enemy = refe.GetOther(summoner);
|
||||
if (!enemy.HasBreakableByDamageCrowdControlAura() && me.CanCreatureAttack(enemy) && me.IsWithinDistInMap(enemy, me.GetAttackDistance(enemy)))
|
||||
targets.Add(enemy);
|
||||
}
|
||||
|
||||
if (me.IsSummon() && !me.GetThreatManager().GetFixateTarget())
|
||||
{ // find new target
|
||||
Unit summoner = me.ToTempSummon().GetSummonerUnit();
|
||||
List<Unit> targets = new();
|
||||
foreach (var pair in summoner.GetCombatManager().GetPvPCombatRefs())
|
||||
addTargetIfValid(pair.Value);
|
||||
|
||||
void addTargetIfValid(CombatReference refe)
|
||||
{
|
||||
Unit enemy = refe.GetOther(summoner);
|
||||
if (!enemy.HasBreakableByDamageCrowdControlAura() && me.CanCreatureAttack(enemy) && me.IsWithinDistInMap(enemy, me.GetAttackDistance(enemy)))
|
||||
targets.Add(enemy);
|
||||
}
|
||||
|
||||
foreach (var pair in summoner.GetCombatManager().GetPvPCombatRefs())
|
||||
if (targets.Empty())
|
||||
foreach (var pair in summoner.GetCombatManager().GetPvECombatRefs())
|
||||
addTargetIfValid(pair.Value);
|
||||
|
||||
if (targets.Empty())
|
||||
foreach (var pair in summoner.GetCombatManager().GetPvECombatRefs())
|
||||
addTargetIfValid(pair.Value);
|
||||
foreach (Unit target in targets)
|
||||
me.EngageWithTarget(target);
|
||||
|
||||
foreach (Unit target in targets)
|
||||
me.EngageWithTarget(target);
|
||||
|
||||
if (!targets.Empty())
|
||||
{
|
||||
Unit target = targets.SelectRandom();
|
||||
me.GetThreatManager().FixateTarget(target);
|
||||
}
|
||||
}
|
||||
|
||||
if (!UpdateVictim())
|
||||
return;
|
||||
|
||||
// Viper
|
||||
if (_isViper)
|
||||
if (!targets.Empty())
|
||||
{
|
||||
if (_spellTimer <= diff)
|
||||
{
|
||||
if (RandomHelper.URand(0, 2) == 0) // 33% chance to cast
|
||||
DoCastVictim(RandomHelper.RAND(SpellIds.MindNumbingPoison, SpellIds.CripplingPoison));
|
||||
|
||||
_spellTimer = 3000;
|
||||
}
|
||||
else
|
||||
_spellTimer -= diff;
|
||||
Unit target = targets.SelectRandom();
|
||||
me.GetThreatManager().FixateTarget(target);
|
||||
}
|
||||
|
||||
DoMeleeAttackIfReady();
|
||||
}
|
||||
|
||||
bool _isViper;
|
||||
uint _spellTimer;
|
||||
if (!UpdateVictim())
|
||||
return;
|
||||
|
||||
// Viper
|
||||
if (_isViper)
|
||||
{
|
||||
if (_spellTimer <= diff)
|
||||
{
|
||||
if (RandomHelper.URand(0, 2) == 0) // 33% chance to cast
|
||||
DoCastVictim(RandomHelper.RAND(SpellHunterMindNumbingPoison, SpellHunterCripplingPoison));
|
||||
|
||||
_spellTimer = 3000;
|
||||
}
|
||||
else
|
||||
_spellTimer -= diff;
|
||||
}
|
||||
|
||||
DoMeleeAttackIfReady();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user