diff --git a/Client/MirControls/MirControl.cs b/Client/MirControls/MirControl.cs index 0a4ea660b..9de49d7d0 100644 --- a/Client/MirControls/MirControl.cs +++ b/Client/MirControls/MirControl.cs @@ -993,7 +993,6 @@ public virtual void OnKeyUp(KeyEventArgs e) public virtual void Redraw() { if (Parent != null) Parent.Redraw(); - } #region Font diff --git a/Client/MirObjects/MapObject.cs b/Client/MirObjects/MapObject.cs index e210fe12f..eee1e4cb7 100644 --- a/Client/MirObjects/MapObject.cs +++ b/Client/MirObjects/MapObject.cs @@ -20,12 +20,12 @@ public abstract class MapObject private static uint mouseObjectID; public static uint MouseObjectID { - get { return mouseObjectID; } + get => mouseObjectID; set { if (mouseObjectID == value) return; mouseObjectID = value; - MouseObject = MapControl.Objects.Find(x => x.ObjectID == value); + MouseObject = MapControl.Objects.TryGetValue(value, out var obj) ? obj : null; } } @@ -33,25 +33,25 @@ public static uint MouseObjectID private static uint targetObjectID; public static uint TargetObjectID { - get { return targetObjectID; } + get => targetObjectID; set { if (targetObjectID == value) return; lastTargetObjectId = value; targetObjectID = value; - TargetObject = value == 0 ? null : MapControl.Objects.Find(x => x.ObjectID == value); + TargetObject = MapControl.Objects.TryGetValue(value, out var obj) ? obj : null; } } private static uint magicObjectID; public static uint MagicObjectID { - get { return magicObjectID; } + get => magicObjectID; set { if (magicObjectID == value) return; magicObjectID = value; - MagicObject = MapControl.Objects.Find(x => x.ObjectID == value); + MagicObject = MapControl.Objects.TryGetValue(value, out var obj) ? obj : null; } } @@ -143,17 +143,14 @@ protected MapObject(uint objectID) { ObjectID = objectID; - for (int i = MapControl.Objects.Count - 1; i >= 0; i--) - { - MapObject ob = MapControl.Objects[i]; - if (ob.ObjectID != ObjectID) continue; - ob.Remove(); - } - - MapControl.Objects.Add(this); + if (MapControl.Objects.TryGetValue(ObjectID, out var existingObject)) + existingObject.Remove(); + MapControl.Objects[ObjectID] = this; + MapControl.ObjectsList.Add(this); RestoreTargetStates(); } + public void Remove() { if (MouseObject == this) MouseObjectID = 0; @@ -167,7 +164,8 @@ public void Remove() if (this == User.NextMagicObject) User.ClearMagic(); - MapControl.Objects.Remove(this); + MapControl.Objects.Remove(ObjectID); + MapControl.ObjectsList.Remove(this); GameScene.Scene.MapControl.RemoveObject(this); if (ObjectID == Hero?.ObjectID) diff --git a/Client/MirObjects/MonsterObject.cs b/Client/MirObjects/MonsterObject.cs index b5dc9636d..4a0357469 100644 --- a/Client/MirObjects/MonsterObject.cs +++ b/Client/MirObjects/MonsterObject.cs @@ -434,28 +434,25 @@ public override void Process() for (int i = 0; i < Effects.Count; i++) Effects[i].Process(); - Color colour = DrawColour; - if (Poison == PoisonType.None) - DrawColour = Color.White; - if (Poison.HasFlag(PoisonType.Green)) - DrawColour = Color.Green; - if (Poison.HasFlag(PoisonType.Red)) - DrawColour = Color.Red; - if (Poison.HasFlag(PoisonType.Bleeding)) - DrawColour = Color.DarkRed; - if (Poison.HasFlag(PoisonType.Slow)) - DrawColour = Color.Purple; - if (Poison.HasFlag(PoisonType.Stun) || Poison.HasFlag(PoisonType.Dazed)) - DrawColour = Color.Yellow; - if (Poison.HasFlag(PoisonType.Blindness)) - DrawColour = Color.MediumVioletRed; - if (Poison.HasFlag(PoisonType.Frozen)) - DrawColour = Color.Blue; - if (Poison.HasFlag(PoisonType.Paralysis) || Poison.HasFlag(PoisonType.LRParalysis)) - DrawColour = Color.Gray; - if (Poison.HasFlag(PoisonType.DelayedExplosion)) - DrawColour = Color.Orange; - if (colour != DrawColour) GameScene.Scene.MapControl.TextureValid = false; + Color newColour = Poison switch + { + _ when (Poison & PoisonType.DelayedExplosion) == PoisonType.DelayedExplosion => Color.Orange, + _ when (Poison & (PoisonType.Paralysis | PoisonType.LRParalysis)) != 0 => Color.Gray, + _ when (Poison & PoisonType.Frozen) == PoisonType.Frozen => Color.Blue, + _ when (Poison & PoisonType.Blindness) == PoisonType.Blindness => Color.MediumVioletRed, + _ when (Poison & (PoisonType.Stun | PoisonType.Dazed)) != 0 => Color.Yellow, + _ when (Poison & PoisonType.Slow) == PoisonType.Slow => Color.Purple, + _ when (Poison & PoisonType.Bleeding) == PoisonType.Bleeding => Color.DarkRed, + _ when (Poison & PoisonType.Red) == PoisonType.Red => Color.Red, + _ when (Poison & PoisonType.Green) == PoisonType.Green => Color.Green, + _ => Color.White + }; + + if (newColour != DrawColour) + { + DrawColour = newColour; + GameScene.Scene.MapControl.TextureValid = false; + } } public bool SetAction() @@ -1037,31 +1034,23 @@ public bool SetAction() case MirAction.Struck: uint attackerID = (uint)action.Params[0]; StruckWeapon = -2; - for (int i = 0; i < MapControl.Objects.Count; i++) + MapObject ob = MapControl.Objects[attackerID]; + if (ob.Race == ObjectType.Player) { - MapObject ob = MapControl.Objects[i]; - if (ob.ObjectID != attackerID) continue; - if (ob.Race != ObjectType.Player) break; - PlayerObject player = ((PlayerObject)ob); + PlayerObject player = (PlayerObject)ob; StruckWeapon = player.Weapon; - if (player.Class != MirClass.Assassin || StruckWeapon == -1) break; //Archer? - StruckWeapon = 1; - break; + if (player.Class == MirClass.Assassin && StruckWeapon > -1) + StruckWeapon = 1; } PlayFlinchSound(); PlayStruckSound(); - - // Sanjian switch (BaseImage) { case Monster.GlacierBeast: Effects.Add(new Effect(Libraries.Monsters[(ushort)Monster.GlacierBeast], 304, 6, 400, this)); break; } - - - break; case MirAction.Die: switch (BaseImage) diff --git a/Client/MirObjects/PlayerObject.cs b/Client/MirObjects/PlayerObject.cs index ebd26250d..6f29cfc49 100644 --- a/Client/MirObjects/PlayerObject.cs +++ b/Client/MirObjects/PlayerObject.cs @@ -747,7 +747,7 @@ public override void Process() GameScene.CanRun = false; } - SkipFrames = this != User && ActionFeed.Count > 1; + SkipFrames = this != User && ActionFeed.Count > 0; ProcessFrames(); @@ -862,33 +862,25 @@ public override void Process() for (int i = 0; i < Effects.Count; i++) Effects[i].Process(); - Color colour = DrawColour; - DrawColour = Color.White; - if (Poison != PoisonType.None) + Color newColour = Poison switch { - - if (Poison.HasFlag(PoisonType.Green)) - DrawColour = Color.Green; - if (Poison.HasFlag(PoisonType.Red)) - DrawColour = Color.Red; - if (Poison.HasFlag(PoisonType.Bleeding)) - DrawColour = Color.DarkRed; - if (Poison.HasFlag(PoisonType.Slow)) - DrawColour = Color.Purple; - if (Poison.HasFlag(PoisonType.Stun) || Poison.HasFlag(PoisonType.Dazed)) - DrawColour = Color.Yellow; - if (Poison.HasFlag(PoisonType.Blindness)) - DrawColour = Color.MediumVioletRed; - if (Poison.HasFlag(PoisonType.Frozen)) - DrawColour = Color.Blue; - if (Poison.HasFlag(PoisonType.Paralysis) || Poison.HasFlag(PoisonType.LRParalysis)) - DrawColour = Color.Gray; - if (Poison.HasFlag(PoisonType.DelayedExplosion)) - DrawColour = Color.Orange; - } - + _ when (Poison & PoisonType.DelayedExplosion) == PoisonType.DelayedExplosion => Color.Orange, + _ when (Poison & (PoisonType.Paralysis | PoisonType.LRParalysis)) != 0 => Color.Gray, + _ when (Poison & PoisonType.Frozen) == PoisonType.Frozen => Color.Blue, + _ when (Poison & PoisonType.Blindness) == PoisonType.Blindness => Color.MediumVioletRed, + _ when (Poison & (PoisonType.Stun | PoisonType.Dazed)) != 0 => Color.Yellow, + _ when (Poison & PoisonType.Slow) == PoisonType.Slow => Color.Purple, + _ when (Poison & PoisonType.Bleeding) == PoisonType.Bleeding => Color.DarkRed, + _ when (Poison & PoisonType.Red) == PoisonType.Red => Color.Red, + _ when (Poison & PoisonType.Green) == PoisonType.Green => Color.Green, + _ => Color.White + }; - if (colour != DrawColour) GameScene.Scene.MapControl.TextureValid = false; + if (newColour != DrawColour) + { + DrawColour = newColour; + GameScene.Scene.MapControl.TextureValid = false; + } } public virtual void SetAction() { @@ -910,11 +902,8 @@ public virtual void SetAction() } } - if (User == this && CMain.Time < MapControl.NextAction)// && CanSetAction) - { - //NextMagic = null; + if (User == this && CMain.Time < MapControl.NextAction) return; - } if (ActionFeed.Count == 0) @@ -922,7 +911,6 @@ public virtual void SetAction() CurrentAction = MirAction.Standing; CurrentAction = CMain.Time > BlizzardStopTime ? CurrentAction : MirAction.Stance2; - //CurrentAction = CMain.Time > SlashingBurstTime ? CurrentAction : MirAction.Lunge; if (RidingMount) { @@ -979,7 +967,6 @@ public virtual void SetAction() QueuedAction action = ActionFeed[0]; ActionFeed.RemoveAt(0); - CurrentAction = action.Action; if (RidingMount) @@ -1036,8 +1023,6 @@ public virtual void SetAction() break; } - temp = new Point(action.Location.X, temp.Y > CurrentLocation.Y ? temp.Y : CurrentLocation.Y); - if (MapLocation != temp) { GameScene.Scene.MapControl.RemoveObject(this); @@ -1064,8 +1049,6 @@ public virtual void SetAction() break; case MirAction.DashFail: Frames.TryGetValue(RidingMount ? MirAction.MountStanding : MirAction.Standing, out Frame); - //Frames.TryGetValue(MirAction.Standing, out Frame); - //CanSetAction = false; break; case MirAction.Jump: Frames.TryGetValue(MirAction.Jump, out Frame); @@ -1619,17 +1602,15 @@ public virtual void SetAction() case MirAction.MountStruck: uint attackerID = (uint)action.Params[0]; StruckWeapon = -2; - for (int i = 0; i < MapControl.Objects.Count; i++) - { - MapObject ob = MapControl.Objects[i]; - if (ob.ObjectID != attackerID) continue; - if (ob.Race != ObjectType.Player) break; - PlayerObject player = ((PlayerObject)ob); - StruckWeapon = player.Weapon; - if (player.Class != MirClass.Assassin || StruckWeapon == -1) break; - StruckWeapon = 1; - break; - } + + if (MapControl.Objects.TryGetValue(attackerID, out MapObject ob)) + if (ob.Race == ObjectType.Player) + { + PlayerObject player = (PlayerObject)ob; + StruckWeapon = player.Weapon; + if (player.Class == MirClass.Assassin && StruckWeapon != -1) + StruckWeapon = 1; + } PlayStruckSound(); PlayFlinchSound(); @@ -2327,20 +2308,14 @@ public virtual void ProcessFrames() case MirAction.Sneek: case MirAction.DashAttack: if (!GameScene.CanMove) return; - GameScene.Scene.MapControl.TextureValid = false; if (this == User) GameScene.Scene.MapControl.FloorValid = false; - //if (CMain.Time < NextMotion) return; - if (SkipFrames) UpdateFrame(); - - + if (SkipFrames) FrameIndex = Frame.Count; if (UpdateFrame(false) >= Frame.Count) { - - FrameIndex = Frame.Count - 1; SetAction(); } @@ -2351,7 +2326,6 @@ public virtual void ProcessFrames() if (FrameIndex == 1 || FrameIndex == 4) PlayStepSound(); } - //NextMotion += FrameInterval; } UpdateWingEffect(); diff --git a/Client/MirScenes/Dialogs/BigMapDialog.cs b/Client/MirScenes/Dialogs/BigMapDialog.cs index d53a63b40..195b0b9e5 100644 --- a/Client/MirScenes/Dialogs/BigMapDialog.cs +++ b/Client/MirScenes/Dialogs/BigMapDialog.cs @@ -683,10 +683,8 @@ private void OnBeforeDraw() { float x; float y; - for (int i = MapControl.Objects.Count - 1; i >= 0; i--) + foreach (var ob in MapControl.Objects.Values) { - MapObject ob = MapControl.Objects[i]; - if (ob.Race == ObjectType.Item || ob.Dead || ob.Race == ObjectType.Spell || ob.ObjectID == MapObject.User.ObjectID) continue; x = ((ob.CurrentLocation.X - startPointX) * ScaleX) + DisplayLocation.X; y = ((ob.CurrentLocation.Y - startPointY) * ScaleY) + DisplayLocation.Y; diff --git a/Client/MirScenes/Dialogs/MainDialogs.cs b/Client/MirScenes/Dialogs/MainDialogs.cs index 1684e017d..1c532c623 100644 --- a/Client/MirScenes/Dialogs/MainDialogs.cs +++ b/Client/MirScenes/Dialogs/MainDialogs.cs @@ -1915,10 +1915,8 @@ private void MiniMap_BeforeDraw(object sender, EventArgs e) int startPointX = (int)(viewRect.X / scaleX); int startPointY = (int)(viewRect.Y / scaleY); - for (int i = MapControl.Objects.Count - 1; i >= 0; i--) + foreach (var ob in MapControl.Objects.Values) { - MapObject ob = MapControl.Objects[i]; - if (ob.Race == ObjectType.Item || ob.Dead || ob.Race == ObjectType.Spell || ob.Sneaking) continue; float x = ((ob.CurrentLocation.X - startPointX) * scaleX) + drawLocation.X; float y = ((ob.CurrentLocation.Y - startPointY) * scaleY) + drawLocation.Y; diff --git a/Client/MirScenes/GameScene.cs b/Client/MirScenes/GameScene.cs index 6438ea1d3..630b68d1d 100644 --- a/Client/MirScenes/GameScene.cs +++ b/Client/MirScenes/GameScene.cs @@ -11,7 +11,6 @@ using Effect = Client.MirObjects.Effect; using Client.MirScenes.Dialogs; using Client.Utils; -using static System.Net.Mime.MediaTypeNames; using Client.MirGraphics.Particles; namespace Client.MirScenes @@ -1072,7 +1071,7 @@ public override void Process() if (CMain.Time >= MoveTime) { - MoveTime += 100; //Move Speed + MoveTime = CMain.Time + 100; //Move Speed CanMove = true; MapControl.AnimationCount++; MapControl.TextureValid = false; @@ -2155,26 +2154,17 @@ private void ObjectRemove(S.ObjectRemove p) { if (p.ObjectID == User.ObjectID) return; - for (int i = MapControl.Objects.Count - 1; i >= 0; i--) - { - MapObject ob = MapControl.Objects[i]; - if (ob.ObjectID != p.ObjectID) continue; - + if (MapControl.Objects.TryGetValue(p.ObjectID, out MapObject ob)) ob.Remove(); - } } private void ObjectTurn(S.ObjectTurn p) { if (p.ObjectID == User.ObjectID && !Observing) return; - for (int i = MapControl.Objects.Count - 1; i >= 0; i--) - { - MapObject ob = MapControl.Objects[i]; - if (ob.ObjectID != p.ObjectID) continue; + if (MapControl.Objects.TryGetValue(p.ObjectID, out MapObject ob)) ob.ActionFeed.Add(new QueuedAction { Action = MirAction.Standing, Direction = p.Direction, Location = p.Location }); - return; - } } + private void ObjectWalk(S.ObjectWalk p) { if (p.ObjectID == User.ObjectID && !Observing) return; @@ -2182,14 +2172,10 @@ private void ObjectWalk(S.ObjectWalk p) if (p.ObjectID == Hero?.ObjectID) Hero.CurrentLocation = p.Location; - for (int i = MapControl.Objects.Count - 1; i >= 0; i--) - { - MapObject ob = MapControl.Objects[i]; - if (ob.ObjectID != p.ObjectID) continue; + if (MapControl.Objects.TryGetValue(p.ObjectID, out MapObject ob)) ob.ActionFeed.Add(new QueuedAction { Action = MirAction.Walking, Direction = p.Direction, Location = p.Location }); - return; - } } + private void ObjectRun(S.ObjectRun p) { if (p.ObjectID == User.ObjectID && !Observing) return; @@ -2197,27 +2183,18 @@ private void ObjectRun(S.ObjectRun p) if (p.ObjectID == Hero?.ObjectID) Hero.CurrentLocation = p.Location; - for (int i = MapControl.Objects.Count - 1; i >= 0; i--) - { - MapObject ob = MapControl.Objects[i]; - if (ob.ObjectID != p.ObjectID) continue; + if (MapControl.Objects.TryGetValue(p.ObjectID, out MapObject ob)) ob.ActionFeed.Add(new QueuedAction { Action = MirAction.Running, Direction = p.Direction, Location = p.Location }); - return; - } } + private void ObjectChat(S.ObjectChat p) { ChatDialog.ReceiveChat(p.Text, p.Type); - for (int i = MapControl.Objects.Count - 1; i >= 0; i--) - { - MapObject ob = MapControl.Objects[i]; - if (ob.ObjectID != p.ObjectID) continue; + if (MapControl.Objects.TryGetValue(p.ObjectID, out MapObject ob)) ob.Chat(RegexFunctions.CleanChatString(p.Text)); - return; - } - } + private void MoveItem(S.MoveItem p) { MirItemCell toCell, fromCell; @@ -2889,16 +2866,10 @@ private void TransferHeroItem(S.TransferHeroItem p) private void MountUpdate(S.MountUpdate p) { - for (int i = MapControl.Objects.Count - 1; i >= 0; i--) + if (MapControl.Objects.TryGetValue(p.ObjectID, out MapObject ob)) { - if (MapControl.Objects[i].ObjectID != p.ObjectID) continue; - - PlayerObject player = MapControl.Objects[i] as PlayerObject; - if (player != null) - { + if (ob is PlayerObject player) player.MountUpdate(p); - } - break; } if (p.ObjectID != User.ObjectID) return; @@ -2907,50 +2878,32 @@ private void MountUpdate(S.MountUpdate p) User.RefreshStats(); - GameScene.Scene.MountDialog.RefreshDialog(); - GameScene.Scene.Redraw(); + MountDialog.RefreshDialog(); + Redraw(); } private void TransformUpdate(S.TransformUpdate p) { - for (int i = MapControl.Objects.Count - 1; i >= 0; i--) - { - if (MapControl.Objects[i].ObjectID != p.ObjectID) continue; - - if (MapControl.Objects[i] is PlayerObject player) - { + if (MapControl.Objects.TryGetValue(p.ObjectID, out MapObject ob)) + if (ob is PlayerObject player) player.TransformType = p.TransformType; - } - break; - } } private void FishingUpdate(S.FishingUpdate p) { - for (int i = MapControl.Objects.Count - 1; i >= 0; i--) - { - if (MapControl.Objects[i].ObjectID != p.ObjectID) continue; - - PlayerObject player = MapControl.Objects[i] as PlayerObject; - if (player != null) - { - player.FishingUpdate(p); - - } - break; - } + if (MapControl.Objects.TryGetValue(p.ObjectID, out var ob) && ob is PlayerObject player) + player.FishingUpdate(p); if (p.ObjectID != User.ObjectID) return; - GameScene.Scene.FishingStatusDialog.ProgressPercent = p.ProgressPercent; - GameScene.Scene.FishingStatusDialog.ChancePercent = p.ChancePercent; - - GameScene.Scene.FishingStatusDialog.ChanceLabel.Text = string.Format("{0}%", GameScene.Scene.FishingStatusDialog.ChancePercent); + FishingStatusDialog.ProgressPercent = p.ProgressPercent; + FishingStatusDialog.ChancePercent = p.ChancePercent; + FishingStatusDialog.ChanceLabel.Text = string.Format("{0}%", FishingStatusDialog.ChancePercent); if (p.Fishing) - GameScene.Scene.FishingStatusDialog.Show(); + FishingStatusDialog.Show(); else - GameScene.Scene.FishingStatusDialog.Hide(); + FishingStatusDialog.Hide(); Redraw(); } @@ -3034,15 +2987,10 @@ private void ChangeQuest(S.ChangeQuest p) private void PlayerUpdate(S.PlayerUpdate p) { - for (int i = MapControl.Objects.Count - 1; i >= 0; i--) - { - if (MapControl.Objects[i].ObjectID != p.ObjectID) continue; - - PlayerObject player = MapControl.Objects[i] as PlayerObject; - if (player != null) player.Update(p); - return; - } + if (MapControl.Objects.TryGetValue(p.ObjectID, out var ob) && ob is PlayerObject player) + player.Update(p); } + private void PlayerInspect(S.PlayerInspect p) { InspectDialog.Items = p.Equipment; @@ -3219,24 +3167,24 @@ private void LoseCredit(S.LoseCredit p) } private void ObjectMonster(S.ObjectMonster p) { - var found = false; - var mob = (MonsterObject)MapControl.Objects.Find(ob => ob.ObjectID == p.ObjectID); - if (mob != null) - found = true; - if (!found) - mob = new MonsterObject(p.ObjectID); - mob.Load(p, found); + if (MapControl.Objects.TryGetValue(p.ObjectID, out var ob) && ob is MonsterObject mob) + { + mob.Load(p, true); + return; + } + + mob = new MonsterObject(p.ObjectID); + mob.Load(p, false); } + private void ObjectAttack(S.ObjectAttack p) { if (p.ObjectID == User.ObjectID && !Observing) return; QueuedAction action = null; - for (int i = MapControl.Objects.Count - 1; i >= 0; i--) + if (MapControl.Objects.TryGetValue(p.ObjectID, out var ob)) { - MapObject ob = MapControl.Objects[i]; - if (ob.ObjectID != p.ObjectID) continue; if (ob.Race == ObjectType.Player) { action = new QueuedAction { Action = MirAction.Attack1, Direction = p.Direction, Location = p.Location, Params = new List() }; @@ -3275,7 +3223,6 @@ private void ObjectAttack(S.ObjectAttack p) action.Params.Add(p.Spell); action.Params.Add(p.Level); ob.ActionFeed.Add(action); - return; } } private void Struck(S.Struck p) @@ -3336,11 +3283,8 @@ private void ObjectStruck(S.ObjectStruck p) { if (p.ObjectID == User.ObjectID) return; - for (int i = MapControl.Objects.Count - 1; i >= 0; i--) + if (MapControl.Objects.TryGetValue(p.ObjectID, out var ob)) { - MapObject ob = MapControl.Objects[i]; - if (ob.ObjectID != p.ObjectID) continue; - if (ob.SkipFrames) return; if (ob.ActionFeed.Count > 0 && ob.ActionFeed[ob.ActionFeed.Count - 1].Action == MirAction.Struck) return; @@ -3374,8 +3318,6 @@ private void ObjectStruck(S.ObjectStruck p) } } } - - return; } } @@ -3383,11 +3325,8 @@ private void DamageIndicator(S.DamageIndicator p) { if (Settings.DisplayDamage) { - for (int i = MapControl.Objects.Count - 1; i >= 0; i--) + if (MapControl.Objects.TryGetValue(p.ObjectID, out var obj)) { - MapObject obj = MapControl.Objects[i]; - if (obj.ObjectID != p.ObjectID) continue; - if (obj.Damages.Count >= 10) return; switch (p.Type) @@ -3664,11 +3603,8 @@ private void ObjectDied(S.ObjectDied p) { if (p.ObjectID == User.ObjectID) return; - for (int i = MapControl.Objects.Count - 1; i >= 0; i--) + if (MapControl.Objects.TryGetValue(p.ObjectID, out var ob)) { - MapObject ob = MapControl.Objects[i]; - if (ob.ObjectID != p.ObjectID) continue; - switch(p.Type) { default: @@ -3685,7 +3621,6 @@ private void ObjectDied(S.ObjectDied p) ob.Remove(); break; } - return; } } private void ColourChanged(S.ColourChanged p) @@ -3696,28 +3631,18 @@ private void ObjectColourChanged(S.ObjectColourChanged p) { if (p.ObjectID == User.ObjectID) return; - for (int i = MapControl.Objects.Count - 1; i >= 0; i--) - { - MapObject ob = MapControl.Objects[i]; - if (ob.ObjectID != p.ObjectID) continue; + if (MapControl.Objects.TryGetValue(p.ObjectID, out var ob)) ob.NameColour = p.NameColour; - return; - } } private void ObjectGuildNameChanged(S.ObjectGuildNameChanged p) { if (p.ObjectID == User.ObjectID) return; - for (int i = MapControl.Objects.Count - 1; i >= 0; i--) - { - MapObject ob = MapControl.Objects[i]; - if (ob.ObjectID != p.ObjectID) continue; - PlayerObject obPlayer = (PlayerObject)ob; + if (MapControl.Objects.TryGetValue(p.ObjectID, out var ob) && ob is PlayerObject obPlayer) obPlayer.GuildName = p.GuildName; - return; - } } + private void GainExperience(S.GainExperience p) { OutputMessage(string.Format(GameLanguage.ExperienceGained, p.Amount)); @@ -3746,43 +3671,30 @@ private void HeroLevelChanged(S.HeroLevelChanged p) Hero.Experience = p.Experience; Hero.MaxExperience = p.MaxExperience; Hero.RefreshStats(); - //OutputMessage(GameLanguage.LevelUp); Hero.Effects.Add(new Effect(Libraries.Magic2, 1200, 20, 2000, User)); SoundManager.PlaySound(SoundList.LevelUp); - //ChatDialog.ReceiveChat(GameLanguage.LevelUp, ChatType.LevelUp); MainDialog.HeroInfoPanel.Update(); } private void ObjectLeveled(S.ObjectLeveled p) { - for (int i = MapControl.Objects.Count - 1; i >= 0; i--) + if (MapControl.Objects.TryGetValue(p.ObjectID, out var ob)) { - MapObject ob = MapControl.Objects[i]; - if (ob.ObjectID != p.ObjectID) continue; ob.Effects.Add(new Effect(Libraries.Magic2, 1180, 16, 2500, ob)); SoundManager.PlaySound(SoundList.LevelUp); - return; } } private void ObjectHarvest(S.ObjectHarvest p) { - for (int i = MapControl.Objects.Count - 1; i >= 0; i--) - { - MapObject ob = MapControl.Objects[i]; - if (ob.ObjectID != p.ObjectID) continue; + if (MapControl.Objects.TryGetValue(p.ObjectID, out var ob)) ob.ActionFeed.Add(new QueuedAction { Action = MirAction.Harvest, Direction = ob.Direction, Location = ob.CurrentLocation }); - return; - } } + private void ObjectHarvested(S.ObjectHarvested p) { - for (int i = MapControl.Objects.Count - 1; i >= 0; i--) - { - MapObject ob = MapControl.Objects[i]; - if (ob.ObjectID != p.ObjectID) continue; + if (MapControl.Objects.TryGetValue(p.ObjectID, out var ob)) ob.ActionFeed.Add(new QueuedAction { Action = MirAction.Skeleton, Direction = ob.Direction, Location = ob.CurrentLocation }); - return; - } } + private void ObjectNPC(S.ObjectNPC p) { NPCObject ob = new NPCObject(p.ObjectID); @@ -3819,19 +3731,14 @@ private void NPCUpdate(S.NPCUpdate p) private void NPCImageUpdate(S.NPCImageUpdate p) { - for (int i = MapControl.Objects.Count - 1; i >= 0; i--) + if (MapControl.Objects.TryGetValue(p.ObjectID, out var ob) && ob is NPCObject npc && ob.Race == ObjectType.Merchant) { - MapObject ob = MapControl.Objects[i]; - if (ob.ObjectID != p.ObjectID || ob.Race != ObjectType.Merchant) continue; - - NPCObject npc = (NPCObject)ob; npc.Image = p.Image; npc.Colour = p.Colour; - npc.LoadLibrary(); - return; } } + private void DefaultNPC(S.DefaultNPC p) { GameScene.DefaultNPCID = p.ObjectID; //Updates the client with the correct Default NPC ID @@ -3840,24 +3747,16 @@ private void DefaultNPC(S.DefaultNPC p) private void ObjectHide(S.ObjectHide p) { - for (int i = MapControl.Objects.Count - 1; i >= 0; i--) - { - MapObject ob = MapControl.Objects[i]; - if (ob.ObjectID != p.ObjectID) continue; + if (MapControl.Objects.TryGetValue(p.ObjectID, out var ob)) ob.ActionFeed.Add(new QueuedAction { Action = MirAction.Hide, Direction = ob.Direction, Location = ob.CurrentLocation }); - return; - } } + private void ObjectShow(S.ObjectShow p) { - for (int i = MapControl.Objects.Count - 1; i >= 0; i--) - { - MapObject ob = MapControl.Objects[i]; - if (ob.ObjectID != p.ObjectID) continue; + if (MapControl.Objects.TryGetValue(p.ObjectID, out var ob)) ob.ActionFeed.Add(new QueuedAction { Action = MirAction.Show, Direction = ob.Direction, Location = ob.CurrentLocation }); - return; - } } + private void Poisoned(S.Poisoned p) { var previousPoisons = User.Poison; @@ -3876,14 +3775,10 @@ private void Poisoned(S.Poisoned p) private void ObjectPoisoned(S.ObjectPoisoned p) { - for (int i = MapControl.Objects.Count - 1; i >= 0; i--) - { - MapObject ob = MapControl.Objects[i]; - if (ob.ObjectID != p.ObjectID) continue; + if (MapControl.Objects.TryGetValue(p.ObjectID, out var ob)) ob.Poison = p.Poison; - return; - } } + private void MapChanged(S.MapChanged p) { var isCurrentMap = (MapControl.Index == p.MapIndex); @@ -3926,10 +3821,8 @@ private void MapChanged(S.MapChanged p) } private void ObjectTeleportOut(S.ObjectTeleportOut p) { - for (int i = MapControl.Objects.Count - 1; i >= 0; i--) + if (MapControl.Objects.TryGetValue(p.ObjectID, out var ob)) { - MapObject ob = MapControl.Objects[i]; - if (ob.ObjectID != p.ObjectID) continue; Effect effect = null; bool playDefaultSound = true; @@ -4008,32 +3901,16 @@ private void ObjectTeleportOut(S.ObjectTeleportOut p) } } - //Doesn't seem to have ever worked properly - Meant to remove object after animation complete, however due to server mechanics will always - //instantly remove object and never play TeleportOut animation. Changing to a MapEffect - not ideal as theres no delay. - MapControl.Effects.Add(effect); - //if (effect != null) - //{ - // effect.Complete += (o, e) => ob.Remove(); - // ob.Effects.Add(effect); - //} - if (playDefaultSound) - { SoundManager.PlaySound(SoundList.Teleport); - } - - return; } } private void ObjectTeleportIn(S.ObjectTeleportIn p) { - for (int i = MapControl.Objects.Count - 1; i >= 0; i--) + if (MapControl.Objects.TryGetValue(p.ObjectID, out var ob)) { - MapObject ob = MapControl.Objects[i]; - if (ob.ObjectID != p.ObjectID) continue; - bool playDefaultSound = true; switch (p.Type) @@ -4110,16 +3987,10 @@ private void ObjectTeleportIn(S.ObjectTeleportIn p) } if (p.ObjectID == User.ObjectID) - { User.TargetID = User.LastTargetObjectId; - } if (playDefaultSound) - { SoundManager.PlaySound(SoundList.Teleport); - } - - return; } } @@ -4603,11 +4474,8 @@ private void ObjectMagic(S.ObjectMagic p) magic.CastTime = CMain.Time; } - for (int i = MapControl.Objects.Count - 1; i >= 0; i--) + if (MapControl.Objects.TryGetValue(p.ObjectID, out var ob)) { - MapObject ob = MapControl.Objects[i]; - if (ob.ObjectID != p.ObjectID) continue; - QueuedAction action = new QueuedAction { Action = MirAction.Spell, Direction = p.Direction, Location = p.Location, Params = new List() }; action.Params.Add(p.Spell); action.Params.Add(p.TargetID); @@ -4617,7 +4485,6 @@ private void ObjectMagic(S.ObjectMagic p) action.Params.Add(p.SecondaryTargetIDs); ob.ActionFeed.Add(action); - return; } } @@ -4653,20 +4520,16 @@ private void ObjectProjectile(S.ObjectProjectile p) private void ObjectEffect(S.ObjectEffect p) { - for (int i = MapControl.Objects.Count - 1; i >= 0; i--) + if (MapControl.Objects.TryGetValue(p.ObjectID, out var ob)) { - MapObject ob = MapControl.Objects[i]; - if (ob.ObjectID != p.ObjectID) continue; PlayerObject player; switch (p.Effect) { - // Sanjian case SpellEffect.FurbolgWarriorCritical: ob.Effects.Add(new Effect(Libraries.Monsters[(ushort)Monster.FurbolgWarrior], 400, 6, 600, ob)); SoundManager.PlaySound(20000 + (ushort)Spell.FatalSword * 10); break; - case SpellEffect.FatalSword: ob.Effects.Add(new Effect(Libraries.Magic2, 1940, 4, 400, ob)); SoundManager.PlaySound(20000 + (ushort)Spell.FatalSword * 10); @@ -4689,16 +4552,10 @@ private void ObjectEffect(S.ObjectEffect p) case SpellEffect.TwinDrakeBlade: ob.Effects.Add(new Effect(Libraries.Magic2, 380, 6, 800, ob)); break; - case SpellEffect.MPEater: - for (int j = MapControl.Objects.Count - 1; j >= 0; j--) - { - MapObject ob2 = MapControl.Objects[j]; - if (ob2.ObjectID == p.EffectType) - { - ob2.Effects.Add(new Effect(Libraries.Magic2, 2411, 19, 1900, ob2)); - break; - } - } + case SpellEffect.MPEater: + if (MapControl.Objects.TryGetValue(p.EffectType, out var ob2)) + ob2.Effects.Add(new Effect(Libraries.Magic2, 2411, 19, 1900, ob2)); + ob.Effects.Add(new Effect(Libraries.Magic2, 2400, 9, 900, ob)); SoundManager.PlaySound(20000 + (ushort)Spell.FatalSword * 10); break; @@ -4855,7 +4712,8 @@ private void ObjectEffect(S.ObjectEffect p) } break; case SpellEffect.FlamingMutantWeb: - ob.Effects.Add(new Effect(Libraries.Monsters[(ushort)Monster.FlamingMutant], 330, 10, 1000, ob) { + ob.Effects.Add(new Effect(Libraries.Monsters[(ushort)Monster.FlamingMutant], 330, 10, 1000, ob) + { Repeat = p.Time > 0, RepeatUntil = p.Time > 0 ? CMain.Time + p.Time : 0 }); @@ -4867,8 +4725,6 @@ private void ObjectEffect(S.ObjectEffect p) ob.Effects.Add(new Effect(Libraries.Magic3, 705, 10, 800, ob)); break; } - - return; } } @@ -4888,28 +4744,18 @@ private void ObjectPushed(S.ObjectPushed p) { if (p.ObjectID == User.ObjectID) return; - for (int i = MapControl.Objects.Count - 1; i >= 0; i--) - { - MapObject ob = MapControl.Objects[i]; - if (ob.ObjectID != p.ObjectID) continue; + if (MapControl.Objects.TryGetValue(p.ObjectID, out var ob)) ob.ActionFeed.Add(new QueuedAction { Action = MirAction.Pushed, Direction = p.Direction, Location = p.Location }); - - return; - } } private void ObjectName(S.ObjectName p) { if (p.ObjectID == User.ObjectID) return; - for (int i = MapControl.Objects.Count - 1; i >= 0; i--) - { - MapObject ob = MapControl.Objects[i]; - if (ob.ObjectID != p.ObjectID) continue; + if (MapControl.Objects.TryGetValue(p.ObjectID, out var ob)) ob.Name = p.Name; - return; - } } + private void UserStorage(S.UserStorage p) { if(Storage.Length != p.Storage.Length) @@ -4995,10 +4841,8 @@ private void Revived() } private void ObjectRevived(S.ObjectRevived p) { - for (int i = MapControl.Objects.Count - 1; i >= 0; i--) + if (MapControl.Objects.TryGetValue(p.ObjectID, out var ob)) { - MapObject ob = MapControl.Objects[i]; - if (ob.ObjectID != p.ObjectID) continue; if (p.Effect) { ob.Effects.Add(new Effect(Libraries.Magic2, 1220, 20, 2000, ob)); @@ -5007,7 +4851,6 @@ private void ObjectRevived(S.ObjectRevived p) ob.Dead = false; ob.ActionFeed.Clear(); ob.ActionFeed.Add(new QueuedAction { Action = MirAction.Revive, Direction = ob.Direction, Location = ob.CurrentLocation }); - return; } } private void SpellToggle(S.SpellToggle p) @@ -5058,13 +4901,10 @@ private void ObjectHealth(S.ObjectHealth p) if (p.ObjectID == Hero?.ObjectID) Hero.PercentHealth = p.Percent; - for (int i = MapControl.Objects.Count - 1; i >= 0; i--) + if (MapControl.Objects.TryGetValue(p.ObjectID, out var ob)) { - MapObject ob = MapControl.Objects[i]; - if (ob.ObjectID != p.ObjectID) continue; ob.PercentHealth = p.Percent; ob.HealthTime = CMain.Time + p.Expire * 1000; - return; } } @@ -5073,15 +4913,11 @@ private void ObjectMana(S.ObjectMana p) if (p.ObjectID == Hero?.ObjectID) Hero.PercentMana = p.Percent; - for (int i = MapControl.Objects.Count - 1; i >= 0; i--) - { - MapObject ob = MapControl.Objects[i]; - if (ob.ObjectID != p.ObjectID) continue; + if (MapControl.Objects.TryGetValue(p.ObjectID, out var ob)) ob.PercentMana = p.Percent; - return; - } } + private void MapEffect(S.MapEffect p) { switch (p.Effect) @@ -5100,46 +4936,28 @@ private void MapEffect(S.MapEffect p) private void ObjectRangeAttack(S.ObjectRangeAttack p) { - if (p.ObjectID == User.ObjectID && - !Observing) return; + if (p.ObjectID == User.ObjectID && !Observing) return; - for (int i = MapControl.Objects.Count - 1; i >= 0; i--) + if (MapControl.Objects.TryGetValue(p.ObjectID, out var ob)) { - MapObject ob = MapControl.Objects[i]; - if (ob.ObjectID != p.ObjectID) continue; QueuedAction action = null; if (ob.Race == ObjectType.Player) { - switch (p.Type) + action = p.Type switch { - default: - { - action = new QueuedAction { Action = MirAction.AttackRange1, Direction = p.Direction, Location = p.Location, Params = new List() }; - break; - } - } + _ => new QueuedAction { Action = MirAction.AttackRange1, Direction = p.Direction, Location = p.Location, Params = new List() } + }; } else { - switch (p.Type) + action = p.Type switch { - case 1: - { - action = new QueuedAction { Action = MirAction.AttackRange2, Direction = p.Direction, Location = p.Location, Params = new List() }; - break; - } - case 2: - { - action = new QueuedAction { Action = MirAction.AttackRange3, Direction = p.Direction, Location = p.Location, Params = new List() }; - break; - } - default: - { - action = new QueuedAction { Action = MirAction.AttackRange1, Direction = p.Direction, Location = p.Location, Params = new List() }; - break; - } - } + 1 => new QueuedAction { Action = MirAction.AttackRange2, Direction = p.Direction, Location = p.Location, Params = new List() }, + 2 => new QueuedAction { Action = MirAction.AttackRange3, Direction = p.Direction, Location = p.Location, Params = new List() }, + _ => new QueuedAction { Action = MirAction.AttackRange1, Direction = p.Direction, Location = p.Location, Params = new List() } + }; } + action.Params.Add(p.TargetID); action.Params.Add(p.Target); action.Params.Add(p.Spell); @@ -5147,7 +4965,6 @@ private void ObjectRangeAttack(S.ObjectRangeAttack p) action.Params.Add(p.Level); ob.ActionFeed.Add(action); - return; } } @@ -5196,20 +5013,11 @@ private void AddBuff(S.AddBuff p) if (!buff.Visible || buff.ObjectID <= 0) return; - for (int i = MapControl.Objects.Count - 1; i >= 0; i--) + if (MapControl.Objects.TryGetValue(buff.ObjectID, out var ob) && (ob is PlayerObject || ob is MonsterObject)) { - MapObject ob = MapControl.Objects[i]; - if (ob.ObjectID != buff.ObjectID) continue; - if ((ob is PlayerObject) || (ob is MonsterObject)) - { - if (!ob.Buffs.Contains(buff.Type)) - { - ob.Buffs.Add(buff.Type); - } - - ob.AddBuffEffect(buff.Type); - return; - } + if (!ob.Buffs.Contains(buff.Type)) + ob.Buffs.Add(buff.Type); + ob.AddBuffEffect(buff.Type); } } @@ -5261,15 +5069,10 @@ private void RemoveBuff(S.RemoveBuff p) if (p.ObjectID <= 0) return; - for (int i = MapControl.Objects.Count - 1; i >= 0; i--) + if (MapControl.Objects.TryGetValue(p.ObjectID, out var ob)) { - MapObject ob = MapControl.Objects[i]; - - if (ob.ObjectID != p.ObjectID) continue; - ob.Buffs.Remove(p.Type); ob.RemoveBuffEffect(p.Type); - return; } } @@ -5324,39 +5127,24 @@ private void PauseBuff(S.PauseBuff p) private void ObjectHidden(S.ObjectHidden p) { - for (int i = MapControl.Objects.Count - 1; i >= 0; i--) - { - MapObject ob = MapControl.Objects[i]; - if (ob.ObjectID != p.ObjectID) continue; + if (MapControl.Objects.TryGetValue(p.ObjectID, out var ob)) ob.Hidden = p.Hidden; - return; - } } private void ObjectSneaking(S.ObjectSneaking p) { - for (int i = MapControl.Objects.Count - 1; i >= 0; i--) + if (MapControl.Objects.TryGetValue(p.ObjectID, out var ob)) { - MapObject ob = MapControl.Objects[i]; - if (ob.ObjectID != p.ObjectID) continue; - // ob.SneakingActive = p.SneakingActive; - return; + // ob.SneakingActive = p.SneakingActive; } } private void ObjectLevelEffects(S.ObjectLevelEffects p) { - for (int i = MapControl.Objects.Count - 1; i >= 0; i--) + if (MapControl.Objects.TryGetValue(p.ObjectID, out var ob) && ob is PlayerObject player) { - MapObject ob = MapControl.Objects[i]; - if (ob.ObjectID != p.ObjectID || ob.Race != ObjectType.Player) continue; - - PlayerObject temp = (PlayerObject)ob; - - temp.LevelEffects = p.LevelEffects; - - temp.SetEffects(); - return; + player.LevelEffects = p.LevelEffects; + player.SetEffects(); } } @@ -5464,35 +5252,20 @@ private void ObjectDash(S.ObjectDash p) { if (p.ObjectID == User.ObjectID) return; - for (int i = MapControl.Objects.Count - 1; i >= 0; i--) + if (MapControl.Objects.TryGetValue(p.ObjectID, out var ob)) { - MapObject ob = MapControl.Objects[i]; - if (ob.ObjectID != p.ObjectID) continue; - - MirAction action = MirAction.DashL; - - if (ob.ActionFeed.Count > 0 && ob.ActionFeed[ob.ActionFeed.Count - 1].Action == action) - action = MirAction.DashR; - + var action = ob.ActionFeed.Count > 0 && ob.ActionFeed[^1].Action == MirAction.DashL ? MirAction.DashR : MirAction.DashL; ob.ActionFeed.Add(new QueuedAction { Action = action, Direction = p.Direction, Location = p.Location }); - - return; } + } private void ObjectDashFail(S.ObjectDashFail p) { if (p.ObjectID == User.ObjectID) return; - for (int i = MapControl.Objects.Count - 1; i >= 0; i--) - { - MapObject ob = MapControl.Objects[i]; - if (ob.ObjectID != p.ObjectID) continue; - + if (MapControl.Objects.TryGetValue(p.ObjectID, out var ob)) ob.ActionFeed.Add(new QueuedAction { Action = MirAction.DashFail, Direction = p.Direction, Location = p.Location }); - - return; - } } private void UserBackStep(S.UserBackStep p) @@ -5509,16 +5282,10 @@ private void ObjectBackStep(S.ObjectBackStep p) { if (p.ObjectID == User.ObjectID) return; - for (int i = MapControl.Objects.Count - 1; i >= 0; i--) + if (MapControl.Objects.TryGetValue(p.ObjectID, out var ob)) { - MapObject ob = MapControl.Objects[i]; - if (ob.ObjectID != p.ObjectID) continue; - ob.JumpDistance = p.Distance; - ob.ActionFeed.Add(new QueuedAction { Action = MirAction.Jump, Direction = p.Direction, Location = p.Location }); - - return; } } @@ -5537,16 +5304,10 @@ private void ObjectDashAttack(S.ObjectDashAttack p) { if (p.ObjectID == User.ObjectID) return; - for (int i = MapControl.Objects.Count - 1; i >= 0; i--) + if (MapControl.Objects.TryGetValue(p.ObjectID, out var ob)) { - MapObject ob = MapControl.Objects[i]; - if (ob.ObjectID != p.ObjectID) continue; - ob.JumpDistance = p.Distance; - ob.ActionFeed.Add(new QueuedAction { Action = MirAction.DashAttack, Direction = p.Direction, Location = p.Location }); - - return; } } @@ -5587,48 +5348,34 @@ private void UserAttackMove(S.UserAttackMove p)//Warrior Skill - SlashingBurst private void SetConcentration(S.SetConcentration p) { - for (int i = MapControl.Objects.Count - 1; i >= 0; i--) + if (MapControl.Objects.TryGetValue(p.ObjectID, out var ob) && (ob.Race == ObjectType.Player || ob.Race == ObjectType.Hero)) { - if (MapControl.Objects[i].Race != ObjectType.Player && MapControl.Objects[i].Race != ObjectType.Hero) continue; + var player = (PlayerObject)ob; + player.Concentrating = p.Enabled; + player.ConcentrateInterrupted = p.Interrupted; - PlayerObject ob = MapControl.Objects[i] as PlayerObject; - if (ob.ObjectID != p.ObjectID) continue; - - ob.Concentrating = p.Enabled; - ob.ConcentrateInterrupted = p.Interrupted; - - if (p.Enabled && !p.Interrupted) + if (p.Enabled && !p.Interrupted && InterruptionEffect.GetOwnerEffectID(player.ObjectID) < 0) { - int idx = InterruptionEffect.GetOwnerEffectID(ob.ObjectID); - - if (idx < 0) - { - ob.Effects.Add(new InterruptionEffect(Libraries.Magic3, 1860, 8, 8 * 100, ob, true)); - SoundManager.PlaySound(20000 + 129 * 10); - } + player.Effects.Add(new InterruptionEffect(Libraries.Magic3, 1860, 8, 8 * 100, player, true)); + SoundManager.PlaySound(20000 + 129 * 10); } - break; } } private void SetElemental(S.SetElemental p) { - for (int i = MapControl.Objects.Count - 1; i >= 0; i--) + if (MapControl.Objects.TryGetValue(p.ObjectID, out var ob) && (ob.Race == ObjectType.Player || ob.Race == ObjectType.Hero)) { - if (MapControl.Objects[i].Race != ObjectType.Player && MapControl.Objects[i].Race != ObjectType.Hero) continue; - - PlayerObject ob = MapControl.Objects[i] as PlayerObject; - if (ob.ObjectID != p.ObjectID) continue; - - ob.HasElements = p.Enabled; - ob.ElementCasted = p.Casted && User.ObjectID != p.ObjectID; - ob.ElementsLevel = (int)p.Value; - int elementType = (int)p.ElementType; - int maxExp = (int)p.ExpLast; + var player = (PlayerObject)ob; + player.HasElements = p.Enabled; + player.ElementCasted = p.Casted && User.ObjectID != p.ObjectID; + player.ElementsLevel = (int)p.Value; if (p.Enabled && p.ElementType > 0) { - ob.Effects.Add(new ElementsEffect(Libraries.Magic3, 1630 + ((elementType - 1) * 10), 10, 10 * 100, ob, true, 1 + (elementType - 1), maxExp, User.ObjectID == p.ObjectID && ((elementType == 4 || elementType == 3)))); + int elementType = (int)p.ElementType; + int maxExp = (int)p.ExpLast; + player.Effects.Add(new ElementsEffect(Libraries.Magic3, 1630 + ((elementType - 1) * 10), 10, 10 * 100, player, true, 1 + (elementType - 1), maxExp, User.ObjectID == p.ObjectID && (elementType == 4 || elementType == 3))); } } } @@ -5641,39 +5388,29 @@ private void RemoveDelayedExplosion(S.RemoveDelayedExplosion p) if (effectid >= 0) DelayedExplosionEffect.effectlist[effectid].Remove(); } - private void SetBindingShot(S.SetBindingShot p) { if (p.ObjectID == User.ObjectID) return; - for (int i = MapControl.Objects.Count - 1; i >= 0; i--) + if (MapControl.Objects.TryGetValue(p.ObjectID, out MapObject ob) && ob.Race == ObjectType.Monster) { - MapObject ob = MapControl.Objects[i]; - if (ob.ObjectID != p.ObjectID) continue; - if (ob.Race != ObjectType.Monster) continue; - - TrackableEffect NetCast = new TrackableEffect(new Effect(Libraries.MagicC, 0, 8, 700, ob)); - NetCast.EffectName = "BindingShotDrop"; - - //TrackableEffect NetDropped = new TrackableEffect(new Effect(Libraries.ArcherMagic, 7, 1, 1000, ob, CMain.Time + 600) { Repeat = true, RepeatUntil = CMain.Time + (p.Value - 1500) }); - TrackableEffect NetDropped = new TrackableEffect(new Effect(Libraries.MagicC, 7, 1, 1000, ob) { Repeat = true, RepeatUntil = CMain.Time + (p.Value - 1500) }); - NetDropped.EffectName = "BindingShotDown"; - - TrackableEffect NetFall = new TrackableEffect(new Effect(Libraries.MagicC, 8, 8, 700, ob)); - NetFall.EffectName = "BindingShotFall"; + var NetCast = new TrackableEffect(new Effect(Libraries.MagicC, 0, 8, 700, ob)) { EffectName = "BindingShotDrop" }; + var NetDropped = new TrackableEffect(new Effect(Libraries.MagicC, 7, 1, 1000, ob) { Repeat = true, RepeatUntil = CMain.Time + (p.Value - 1500) }) { EffectName = "BindingShotDown" }; + var NetFall = new TrackableEffect(new Effect(Libraries.MagicC, 8, 8, 700, ob)) { EffectName = "BindingShotFall" }; NetDropped.Complete += (o1, e1) => { - SoundManager.PlaySound(20000 + 130 * 10 + 6);//sound M130-6 + SoundManager.PlaySound(20000 + 130 * 10 + 6); // sound M130-6 ob.Effects.Add(NetFall); }; + NetCast.Complete += (o, e) => { - SoundManager.PlaySound(20000 + 130 * 10 + 5);//sound M130-5 + SoundManager.PlaySound(20000 + 130 * 10 + 5); // sound M130-5 ob.Effects.Add(NetDropped); }; + ob.Effects.Add(NetCast); - break; } } @@ -5775,14 +5512,10 @@ private void ObjectSitDown(S.ObjectSitDown p) { if (p.ObjectID == User.ObjectID) return; - for (int i = MapControl.Objects.Count - 1; i >= 0; i--) + if (MapControl.Objects.TryGetValue(p.ObjectID, out MapObject ob) && ob.Race == ObjectType.Monster) { - MapObject ob = MapControl.Objects[i]; - if (ob.ObjectID != p.ObjectID) continue; - if (ob.Race != ObjectType.Monster) continue; ob.SitDown = p.Sitting; ob.ActionFeed.Add(new QueuedAction { Action = MirAction.SitDown, Direction = p.Direction, Location = p.Location }); - return; } } @@ -6692,44 +6425,35 @@ private void IntelligentCreatureEnableRename(S.IntelligentCreatureEnableRename p private void IntelligentCreaturePickup(S.IntelligentCreaturePickup p) { - for (int i = MapControl.Objects.Count - 1; i >= 0; i--) - { - MapObject ob = MapControl.Objects[i]; - if (ob.ObjectID != p.ObjectID) continue; - - MonsterObject monOb = (MonsterObject)ob; - - if (monOb != null) monOb.PlayPickupSound(); - } + if (MapControl.Objects.TryGetValue(p.ObjectID, out MapObject ob) && ob is MonsterObject monOb) + monOb.PlayPickupSound(); } + private void FriendUpdate(S.FriendUpdate p) { - GameScene.Scene.FriendDialog.Friends = p.Friends; + FriendDialog.Friends = p.Friends; - if (GameScene.Scene.FriendDialog.Visible) - { - GameScene.Scene.FriendDialog.Update(false); - } + if (FriendDialog.Visible) + FriendDialog.Update(false); } private void LoverUpdate(S.LoverUpdate p) { - GameScene.Scene.RelationshipDialog.LoverName = p.Name; - GameScene.Scene.RelationshipDialog.Date = p.Date; - GameScene.Scene.RelationshipDialog.MapName = p.MapName; - GameScene.Scene.RelationshipDialog.MarriedDays = p.MarriedDays; - GameScene.Scene.RelationshipDialog.UpdateInterface(); + RelationshipDialog.LoverName = p.Name; + RelationshipDialog.Date = p.Date; + RelationshipDialog.MapName = p.MapName; + RelationshipDialog.MarriedDays = p.MarriedDays; + RelationshipDialog.UpdateInterface(); } private void MentorUpdate(S.MentorUpdate p) { - GameScene.Scene.MentorDialog.MentorName = p.Name; - GameScene.Scene.MentorDialog.MentorLevel = p.Level; - GameScene.Scene.MentorDialog.MentorOnline = p.Online; - GameScene.Scene.MentorDialog.MenteeEXP = p.MenteeEXP; - - GameScene.Scene.MentorDialog.UpdateInterface(); + MentorDialog.MentorName = p.Name; + MentorDialog.MentorLevel = p.Level; + MentorDialog.MentorOnline = p.Online; + MentorDialog.MenteeEXP = p.MenteeEXP; + MentorDialog.UpdateInterface(); } private void GameShopUpdate(S.GameShopInfo p) @@ -10279,7 +10003,8 @@ public static UserHeroObject Hero set { MapObject.Hero = value; } } - public static List Objects = new List(); + public static Dictionary Objects = new Dictionary(); + public static List ObjectsList = new List(); public const int CellWidth = 48; public const int CellHeight = 32; @@ -10410,22 +10135,19 @@ public void ResetMap() MapObject.MagicObjectID = 0; if (M2CellInfo != null) - { - for (var i = Objects.Count - 1; i >= 0; i--) - { - var obj = Objects[i]; - if (obj == null) continue; - - obj.Remove(); - } - } + for (var i = ObjectsList.Count - 1; i >= 0; i--) + ObjectsList[i]?.Remove(); Objects.Clear(); + ObjectsList.Clear(); Effects.Clear(); Doors.Clear(); if (User != null) - Objects.Add(User); + { + Objects[User.ObjectID] = User; + ObjectsList.Add(User); + } } public void LoadMap() @@ -10467,12 +10189,10 @@ public void Process() { Processdoors(); User.Process(); - for (int i = Objects.Count - 1; i >= 0; i--) + for (int i = ObjectsList.Count - 1; i >= 0; i--) { - MapObject ob = Objects[i]; - if (ob == User) continue; - // if (ob.ActionFeed.Count > 0 || ob.Effects.Count > 0 || GameScene.CanMove || CMain.Time >= ob.NextMotion) - ob.Process(); + if (ObjectsList[i] == User) continue; + ObjectsList[i].Process(); } for (int i = Effects.Count - 1; i >= 0; i--) @@ -10485,7 +10205,6 @@ public void Process() CheckInput(); - MapObject bestmouseobject = null; for (int y = MapLocation.Y + 2; y >= MapLocation.Y - 2; y--) { @@ -10525,7 +10244,6 @@ public void Process() } } - if (MapObject.MouseObject != null) { MapObject.MouseObjectID = 0; @@ -10535,13 +10253,8 @@ public void Process() public static MapObject GetObject(uint targetID) { - for (int i = 0; i < Objects.Count; i++) - { - MapObject ob = Objects[i]; - if (ob.ObjectID != targetID) continue; - return ob; - } - return null; + Objects.TryGetValue(targetID, out var ob); + return ob; } public override void Draw() @@ -10598,11 +10311,8 @@ protected override void CreateTexture() if (Settings.DropView || GameScene.DropViewTime > CMain.Time) { - for (int i = 0; i < Objects.Count; i++) + foreach (var ob in Objects.Values.OfType()) { - ItemObject ob = Objects[i] as ItemObject; - if (ob == null) continue; - if (!ob.MouseOver(MouseLocation)) ob.DrawName(); } @@ -10615,24 +10325,20 @@ protected override void CreateTexture() if (Settings.DisplayBodyName) { - for (int i = 0; i < Objects.Count; i++) + foreach (var ob in Objects.Values.OfType()) { - MonsterObject ob = Objects[i] as MonsterObject; - if (ob == null) continue; - - if (!ob.MouseOver(MouseLocation)) continue; - ob.DrawName(); + if (ob.MouseOver(MouseLocation)) + ob.DrawName(); } } - for (int i = 0; i < Objects.Count; i++) + foreach (var ob in Objects.Values.OfType()) { - ItemObject ob = Objects[i] as ItemObject; - if (ob == null) continue; - - if (!ob.MouseOver(MouseLocation)) continue; - ob.DrawName(offSet); - offSet -= ob.NameLabel.Size.Height + (ob.NameLabel.Border ? 1 : 0); + if (ob.MouseOver(MouseLocation)) + { + ob.DrawName(offSet); + offSet -= ob.NameLabel.Size.Height + (ob.NameLabel.Border ? 1 : 0); + } } if (MapObject.User.MouseOver(MouseLocation)) @@ -10981,18 +10687,17 @@ private void DrawObjects() MapObject.TargetObject.DrawBlend(); } - for (int i = 0; i < Objects.Count; i++) + foreach (var ob in Objects.Values) { - Objects[i].DrawEffects(Settings.Effect); - - if (Settings.NameView && !(Objects[i] is ItemObject) && !Objects[i].Dead) - Objects[i].DrawName(); + ob.DrawEffects(Settings.Effect); - Objects[i].DrawChat(); - Objects[i].DrawHealth(); - Objects[i].DrawPoison(); + if (Settings.NameView && !(ob is ItemObject) && !ob.Dead) + ob.DrawName(); - Objects[i].DrawDamages(); + ob.DrawChat(); + ob.DrawHealth(); + ob.DrawPoison(); + ob.DrawDamages(); } if (Settings.Effect) @@ -11085,9 +10790,8 @@ private void DrawLights(LightSetting setting) DXManager.Device.SetRenderState(RenderState.DestinationBlend, Blend.One); #region Object Lights (Player/Mob/NPC) - for (int i = 0; i < Objects.Count; i++) + foreach (var ob in Objects.Values) { - MapObject ob = Objects[i]; if (ob.Light > 0 && (!ob.Dead || ob == MapObject.User || ob.Race == ObjectType.Spell)) { light = ob.Light; @@ -12070,20 +11774,17 @@ public static double Distance(PointF p1, PointF p2) public bool EmptyCell(Point p) { - if ((M2CellInfo[p.X, p.Y].BackImage & 0x20000000) != 0 || (M2CellInfo[p.X, p.Y].FrontImage & 0x8000) != 0) // + (M2CellInfo[P.X, P.Y].FrontImage & 0x7FFF) != 0) + if ((M2CellInfo[p.X, p.Y].BackImage & 0x20000000) != 0 || (M2CellInfo[p.X, p.Y].FrontImage & 0x8000) != 0) return false; - for (int i = 0; i < Objects.Count; i++) - { - MapObject ob = Objects[i]; - + foreach (var ob in Objects.Values) if (ob.CurrentLocation == p && ob.Blocking) return false; - } return true; } + private bool CanWalk(MirDirection dir) { return EmptyCell(Functions.PointMove(User.CurrentLocation, dir, 1)) && !User.InTrapRock; @@ -12211,15 +11912,12 @@ public bool ValidPoint(Point p) } public bool HasTarget(Point p) { - for (int i = 0; i < Objects.Count; i++) - { - MapObject ob = Objects[i]; - + foreach (var ob in Objects.Values) if (ob.CurrentLocation == p && ob.Blocking) return true; - } return false; } + public bool CanHalfMoon(Point p, MirDirection d) { d = Functions.PreviousDir(d); diff --git a/Server/MirObjects/HumanObject.cs b/Server/MirObjects/HumanObject.cs index 316e6883f..9e34a98fd 100644 --- a/Server/MirObjects/HumanObject.cs +++ b/Server/MirObjects/HumanObject.cs @@ -2559,8 +2559,10 @@ public bool Run(MirDirection dir) } } if (CheckMovement(location)) return false; - } + Enqueue(new S.UserLocation { Direction = dir, Location = location }); + Broadcast(new S.ObjectRun { ObjectID = ObjectID, Direction = dir, Location = location }); + if (RidingMount && !Sneaking) { DecreaseMountLoyalty(2); @@ -2599,8 +2601,6 @@ public bool Run(MirDirection dir) ChangeHP(-1); } - Enqueue(new S.UserLocation { Direction = Direction, Location = CurrentLocation }); - Broadcast(new S.ObjectRun { ObjectID = ObjectID, Direction = Direction, Location = CurrentLocation }); GetPlayerLocation(); for (int j = 1; j <= steps; j++) diff --git a/Shared/ServerPackets.cs b/Shared/ServerPackets.cs index 60cc01cd8..3fc83b520 100644 --- a/Shared/ServerPackets.cs +++ b/Shared/ServerPackets.cs @@ -4949,13 +4949,13 @@ public sealed class NPCImageUpdate : Packet { public override short Index { get { return (short)ServerPacketIds.NPCImageUpdate; } } - public long ObjectID; + public uint ObjectID; public ushort Image; public Color Colour; protected override void ReadPacket(BinaryReader reader) { - ObjectID = reader.ReadInt64(); + ObjectID = reader.ReadUInt32(); Image = reader.ReadUInt16(); Colour = Color.FromArgb(reader.ReadInt32()); } @@ -4970,13 +4970,13 @@ public sealed class MountUpdate : Packet { public override short Index { get { return (short)ServerPacketIds.MountUpdate; } } - public long ObjectID; + public uint ObjectID; public short MountType; public bool RidingMount; protected override void ReadPacket(BinaryReader reader) { - ObjectID = reader.ReadInt64(); + ObjectID = reader.ReadUInt32(); MountType = reader.ReadInt16(); RidingMount = reader.ReadBoolean(); } @@ -4992,12 +4992,12 @@ public sealed class TransformUpdate : Packet { public override short Index { get { return (short)ServerPacketIds.TransformUpdate; } } - public long ObjectID; + public uint ObjectID; public short TransformType; protected override void ReadPacket(BinaryReader reader) { - ObjectID = reader.ReadInt64(); + ObjectID = reader.ReadUInt32(); TransformType = reader.ReadInt16(); } protected override void WritePacket(BinaryWriter writer) @@ -5043,7 +5043,7 @@ public sealed class FishingUpdate : Packet { public override short Index { get { return (short)ServerPacketIds.FishingUpdate; } } - public long ObjectID; + public uint ObjectID; public bool Fishing; public int ProgressPercent; public int ChancePercent; @@ -5052,7 +5052,7 @@ public sealed class FishingUpdate : Packet protected override void ReadPacket(BinaryReader reader) { - ObjectID = reader.ReadInt64(); + ObjectID = reader.ReadUInt32(); Fishing = reader.ReadBoolean(); ProgressPercent = reader.ReadInt32(); ChancePercent = reader.ReadInt32();