Skip to content

Commit

Permalink
- Changed: GameLiving.Attackers is an List<GameObject> instead of Arr…
Browse files Browse the repository at this point in the history
…ayList (caution: many scripts depend of this property, if you need to access to this list, don't forget to lock it before with "lock(living.Attackers)")

- Changed: NPC uses their intelligence for acuity in SpellHandler
- Bugfix: NPC with a emblem (ID > 65535) was not correctly displayed
  • Loading branch information
Dre77 authored and Dre77 committed Aug 1, 2011
1 parent 81533cb commit cbe4093
Show file tree
Hide file tree
Showing 10 changed files with 60 additions and 68 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -150,24 +150,23 @@ public override void Shade(bool makeShade)
if (Player.ControlledBrain != null && Player.ControlledBrain.Body != null)
{
GameNPC pet = Player.ControlledBrain.Body;
ArrayList attackerList = (ArrayList)((ArrayList)Player.Attackers).Clone();
List<GameObject> attackerList;
lock (Player.Attackers)
attackerList = new List<GameObject>(Player.Attackers);

if (pet != null)
foreach (GameObject obj in attackerList)
{
foreach (GameObject obj in attackerList)
if (obj is GameNPC)
{
if (obj is GameNPC)
GameNPC npc = (GameNPC) obj;
if (npc.TargetObject == Player && npc.AttackState)
{
GameNPC npc = (GameNPC)obj;
if (npc.TargetObject == Player && npc.AttackState)
IOldAggressiveBrain brain = npc.Brain as IOldAggressiveBrain;
if (brain != null)
{
IOldAggressiveBrain brain = npc.Brain as IOldAggressiveBrain;
if (brain != null)
{
(npc).AddAttacker(pet);
npc.StopAttack();
brain.AddToAggroList(pet, (int)(brain.GetAggroAmountForLiving(Player) + 1));
}
npc.AddAttacker(pet);
npc.StopAttack();
brain.AddToAggroList(pet, (int) (brain.GetAggroAmountForLiving(Player) + 1));
}
}
}
Expand Down
48 changes: 23 additions & 25 deletions GameServer/gameobjects/GameLiving.cs
Original file line number Diff line number Diff line change
Expand Up @@ -579,7 +579,8 @@ public virtual void DisableTurning(bool add)
/// To be more exact, the objects that are in combat
/// and have this living as target.
/// </summary>
protected readonly ArrayList m_attackers;
protected readonly List<GameObject> m_attackers;

/// <summary>
/// Returns the current active weapon slot of this living
/// </summary>
Expand Down Expand Up @@ -2267,9 +2268,7 @@ protected virtual GameObject RangeAttackTarget
/// <returns></returns>
protected virtual AttackAction CreateAttackAction()
{
return (m_attackAction == null)
? new AttackAction(this)
: m_attackAction;
return m_attackAction ?? new AttackAction(this);
}

/// <summary>
Expand Down Expand Up @@ -4164,14 +4163,14 @@ public virtual int ChangeHealth(GameObject changeSource, eHealthChangeType healt
//natural regeneration, this allows for aggro on healers!
if (healthChanged > 0 && healthChangeType != eHealthChangeType.Regenerate)
{
IList attackers;
lock (m_attackers.SyncRoot) { attackers = (IList)m_attackers.Clone(); }
IList<GameObject> attackers;
lock (Attackers) { attackers = new List<GameObject>(m_attackers); }
EnemyHealedEventArgs args = new EnemyHealedEventArgs(this, changeSource, healthChangeType, healthChanged);
foreach (GameObject attacker in attackers)
{
if (attacker is GameLiving)
{
(attacker as GameLiving).Notify(GameLivingEvent.EnemyHealed, (GameLiving)attacker, args);
(attacker as GameLiving).Notify(GameLivingEvent.EnemyHealed, attacker, args);
(attacker as GameLiving).AddXPGainer(changeSource, healthChanged);
}
}
Expand Down Expand Up @@ -4224,17 +4223,18 @@ public virtual void EnemyHealed(GameLiving enemy, GameObject healSource, eHealth
/// <summary>
/// Returns the list of attackers
/// </summary>
public virtual IList Attackers
public List<GameObject> Attackers
{
get { return m_attackers; }
}

/// <summary>
/// Adds an attacker to the attackerlist
/// </summary>
/// <param name="attacker">the attacker to add</param>
public virtual void AddAttacker(GameObject attacker)
{
lock (m_attackers.SyncRoot)
lock (Attackers)
{
if (attacker == this) return;
if (m_attackers.Contains(attacker)) return;
Expand All @@ -4249,12 +4249,9 @@ public virtual void RemoveAttacker(GameObject attacker)
{
// log.Warn(Name + ": RemoveAttacker "+attacker.Name);
// log.Error(Environment.StackTrace);
lock (m_attackers.SyncRoot)
lock (Attackers)
{
if (m_attackers.Contains(attacker))
{
m_attackers.Remove(attacker);
}
m_attackers.Remove(attacker);
}
}
/// <summary>
Expand All @@ -4270,10 +4267,13 @@ public virtual void Die(GameObject killer)

StopAttack();

if (m_attackers.Contains(killer) == false)
m_attackers.Add(killer);

ArrayList clone = m_attackers.Clone() as ArrayList;
List<GameObject> clone;
lock (Attackers)
{
if (m_attackers.Contains(killer) == false)
m_attackers.Add(killer);
clone = new List<GameObject>(m_attackers);
}
List<GamePlayer> playerAttackers = null;

foreach (GameObject obj in clone)
Expand Down Expand Up @@ -6254,15 +6254,13 @@ public override bool RemoveFromWorld()
if (!base.RemoveFromWorld()) return false;

StopAttack();
ArrayList temp;
lock (m_attackers.SyncRoot)
List<GameObject> temp;
lock (Attackers)
{
temp = (ArrayList)m_attackers.Clone();
temp = new List<GameObject>(m_attackers);
m_attackers.Clear();
}
foreach (GameObject obj in temp)
if (obj is GameLiving)
((GameLiving)obj).EnemyKilled(this);
temp.OfType<GameLiving>().ForEach(o => o.EnemyKilled(this));
StopHealthRegeneration();
StopPowerRegeneration();
StopEnduranceRegeneration();
Expand Down Expand Up @@ -6613,7 +6611,7 @@ public GameLiving()
m_xpGainers = new HybridDictionary();
m_effects = CreateEffectsList();
m_concEffects = new ConcentrationList(this);
m_attackers = new ArrayList(1);
m_attackers = new List<GameObject>();

m_health = 1;
m_mana = 1;
Expand Down
2 changes: 1 addition & 1 deletion GameServer/keeps/Gameobjects/Guards/GameKeepGuard.cs
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ public static void AttackFinished(DOLEvent e, object sender, EventArgs arguments
if (result == eAttackResult.OutOfRange)
{
guard.StopAttack();
lock (guard.Attackers.SyncRoot)
lock (guard.Attackers)
{
foreach (GameLiving living in guard.Attackers)
{
Expand Down
10 changes: 3 additions & 7 deletions GameServer/packets/Server/PacketLib176.cs
Original file line number Diff line number Diff line change
Expand Up @@ -274,13 +274,9 @@ public override void SendLivingEquipmentUpdate(GameLiving living)
{
ushort model = (ushort)(item.Model & 0x1FFF);
int slot = item.SlotPosition;
int texture = item.Color;
if (item.Emblem != 0)
{
texture = (ushort)item.Emblem;
if (item.SlotPosition == Slot.LEFTHAND || item.SlotPosition == Slot.CLOAK) // for test only cloack and shield
slot = slot | ((item.Emblem & 0x010000) >> 9); // slot & 0x80 if new emblem
}
int texture = (item.Emblem != 0) ? item.Emblem : item.Color;
if (item.SlotPosition == Slot.LEFTHAND || item.SlotPosition == Slot.CLOAK) // for test only cloack and shield
slot = slot | ((texture & 0x010000) >> 9); // slot & 0x80 if new emblem
pak.WriteByte((byte)slot);
if ((texture & ~0xFF) != 0)
model |= 0x8000;
Expand Down
10 changes: 3 additions & 7 deletions GameServer/packets/Server/PacketLib189.cs
Original file line number Diff line number Diff line change
Expand Up @@ -69,13 +69,9 @@ public override void SendLivingEquipmentUpdate(GameLiving living)
ushort model = (ushort)(item.Model & 0x1FFF);
int slot = item.SlotPosition;
//model = GetModifiedModel(model);
int texture = item.Color;
if (item.Emblem != 0)
{
texture = (ushort)item.Emblem;
if (item.SlotPosition == Slot.LEFTHAND || item.SlotPosition == Slot.CLOAK) // for test only cloack and shield
slot = slot | ((item.Emblem & 0x010000) >> 9); // slot & 0x80 if new emblem
}
int texture = item.Emblem != 0 ? item.Emblem : item.Color;
if (item.SlotPosition == Slot.LEFTHAND || item.SlotPosition == Slot.CLOAK) // for test only cloack and shield
slot = slot | ((texture & 0x010000) >> 9); // slot & 0x80 if new emblem
pak.WriteByte((byte)slot);
if ((texture & ~0xFF) != 0)
model |= 0x8000;
Expand Down
5 changes: 3 additions & 2 deletions GameServer/realmabilities/handlers/VanishAbility.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,9 @@ effect.SpellHandler is AbstractCCSpellHandler ||
}
}

ArrayList attackers = new ArrayList();
attackers.AddRange(living.Attackers);
var attackers = new List<GameObject>();
lock (living.Attackers)
attackers.AddRange(living.Attackers);
foreach (GameLiving attacker in attackers)
{
if (attacker.TargetObject == living)
Expand Down
3 changes: 2 additions & 1 deletion GameServer/skillhandler/StealthSpecHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
*
*/
using System;
using System.Collections.Generic;
using DOL.GS.Effects;
using DOL.GS.PacketHandler;
using System.Collections;
Expand Down Expand Up @@ -140,7 +141,7 @@ public void Execute(Specialization spec, GamePlayer player)
}
//since 1.88 (?), players which stealth, doesn't be followed by mobs [by Suncheck]
//TODO: Some further checks need?
ArrayList attackers = new ArrayList();
var attackers = new List<GameObject>();
attackers.AddRange(player.Attackers);
foreach (GameLiving attacker in attackers)
{
Expand Down
9 changes: 4 additions & 5 deletions GameServer/spells/CharmSpellHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -359,11 +359,10 @@ public override int OnEffectExpires(GameSpellEffect effect, bool noMessages)
}

// remove NPC with new brain from all attackers aggro list
ArrayList attackers;
lock (npc.Attackers.SyncRoot)
{
attackers = new ArrayList(npc.Attackers);
}
List<GameObject> attackers;
lock (npc.Attackers)
attackers = new List<GameObject>(npc.Attackers);

foreach (GameObject obj in attackers)
{
GameNPC npcAttacker = obj as GameNPC;
Expand Down
4 changes: 2 additions & 2 deletions GameServer/spells/ResurrectSpellHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -193,8 +193,8 @@ protected virtual void ResurrectLiving(GameLiving living)
RezDmgImmunityEffect rezImmune = new RezDmgImmunityEffect();
rezImmune.Start(player);

IList attackers;
lock (player.Attackers.SyncRoot) { attackers = (IList)(player.Attackers as ArrayList).Clone(); }
IList<GameObject> attackers;
lock (player.Attackers) { attackers = new List<GameObject>(player.Attackers); }

foreach (GameObject attacker in attackers)
{
Expand Down
12 changes: 7 additions & 5 deletions GameServer/spells/SpellHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3408,17 +3408,17 @@ public virtual double CalculateDamageBase(GameLiving target)
spellDamage = CapPetSpellDamage(spellDamage, player);
}

if (this.SpellLine.KeyName == GlobalSpellsLines.Combat_Styles_Effect)
if (SpellLine.KeyName == GlobalSpellsLines.Combat_Styles_Effect)
{
double WeaponSkill = player.GetWeaponSkill(player.AttackWeapon);
WeaponSkill /= 5;
spellDamage *= (WeaponSkill + 200) / 275.0;
}

if (player.CharacterClass.ManaStat != eStat.UNDEFINED
&& this.SpellLine.KeyName != GlobalSpellsLines.Combat_Styles_Effect
&& this.m_spellLine.KeyName != GlobalSpellsLines.Mundane_Poisons
&& this.SpellLine.KeyName != GlobalSpellsLines.Item_Effects
&& SpellLine.KeyName != GlobalSpellsLines.Combat_Styles_Effect
&& m_spellLine.KeyName != GlobalSpellsLines.Mundane_Poisons
&& SpellLine.KeyName != GlobalSpellsLines.Item_Effects
&& player.CharacterClass.ID != (int)eCharacterClass.MaulerAlb
&& player.CharacterClass.ID != (int)eCharacterClass.MaulerMid
&& player.CharacterClass.ID != (int)eCharacterClass.MaulerHib
Expand All @@ -3430,7 +3430,9 @@ public virtual double CalculateDamageBase(GameLiving target)
}
else if (Caster is GameNPC)
{
spellDamage = CapNPCSpellDamage(spellDamage, Caster as GameNPC);
var npc = (GameNPC) Caster;
int manaStatValue = npc.GetModified(eProperty.Intelligence);
spellDamage = CapNPCSpellDamage(spellDamage, npc)*(manaStatValue + 200)/275.0;
}

if (spellDamage < 0)
Expand Down

0 comments on commit cbe4093

Please sign in to comment.