diff --git a/Projects/Scripts/Commands/DecorateMag.cs b/Projects/Scripts/Commands/DecorateMag.cs index 9c4367d95..1f038c371 100644 --- a/Projects/Scripts/Commands/DecorateMag.cs +++ b/Projects/Scripts/Commands/DecorateMag.cs @@ -805,7 +805,7 @@ namespace Server.Commands if (indexOf >= 0) { - // Must supress stackable warnings + // Must suppress stackable warnings bool wasStackable = item.Stackable; diff --git a/Projects/Scripts/Commands/Generic/Implementors/AreaCommandImplementor.cs b/Projects/Scripts/Commands/Generic/Implementors/AreaCommandImplementor.cs index 7be1e5c0f..109431398 100644 --- a/Projects/Scripts/Commands/Generic/Implementors/AreaCommandImplementor.cs +++ b/Projects/Scripts/Commands/Generic/Implementors/AreaCommandImplementor.cs @@ -42,8 +42,12 @@ namespace Server.Commands.Generic IPooledEnumerable eable = map.GetObjectsInBounds(rect, items, mobiles); - List objs = eable.Where(obj => !mobiles || !(obj is Mobile) || BaseCommand.IsAccessible(from, obj)) - .Where(obj => ext.IsValid(obj)).Cast().ToList(); + List objs = new List(); + + foreach (IEntity obj in eable) + if ((!mobiles || obj is Mobile) && BaseCommand.IsAccessible(from, obj) && ext.IsValid(obj)) + objs.Add(obj); + eable.Free(); ext.Filter(objs); diff --git a/Projects/Scripts/Items/Misc/Corpses/Corpse.cs b/Projects/Scripts/Items/Misc/Corpses/Corpse.cs index 03367cc66..9c501617f 100644 --- a/Projects/Scripts/Items/Misc/Corpses/Corpse.cs +++ b/Projects/Scripts/Items/Misc/Corpses/Corpse.cs @@ -100,7 +100,7 @@ namespace Server.Items public Corpse(Mobile owner, HairInfo hair, FacialHairInfo facialhair, List equipItems) : base(0x2006) { - // To supress console warnings, stackable must be true + // To suppress console warnings, stackable must be true Stackable = true; Amount = owner.Body; // protocol defines that for itemid 0x2006, amount=body Stackable = false; @@ -859,161 +859,157 @@ namespace Server.Items public virtual void Open(Mobile from, bool checkSelfLoot) { - if (from.AccessLevel > AccessLevel.Player || from.InRange(GetWorldLocation(), 2)) + if (from.AccessLevel <= AccessLevel.Player && !from.InRange(GetWorldLocation(), 2)) { - #region Self Looting + from.SendLocalizedMessage(500446); // That is too far away. + return; + } - if (checkSelfLoot && from == Owner && !GetFlag(CorpseFlag.SelfLooted) && Items.Count != 0) + #region Self Looting + + if (checkSelfLoot && from == Owner && !GetFlag(CorpseFlag.SelfLooted) && Items.Count != 0) + { + if (from.FindItemOnLayer(Layer.OuterTorso) is DeathRobe robe) { - if (from.FindItemOnLayer(Layer.OuterTorso) is DeathRobe robe) - { - Map map = from.Map; + Map map = from.Map; - if (map != null && map != Map.Internal) - { - robe.MoveToWorld(from.Location, map); - robe.BeginDecay(); - } + if (map != null && map != Map.Internal) + { + robe.MoveToWorld(from.Location, map); + robe.BeginDecay(); } + } - Container pack = from.Backpack; + Container pack = from.Backpack; - if (RestoreEquip != null && pack != null) + if (RestoreEquip != null && pack != null) + { + List packItems = new List(pack.Items); // Only items in the top-level pack are re-equipped + + for (int i = 0; i < packItems.Count; i++) { - List - packItems = new List(pack.Items); // Only items in the top-level pack are re-equipped + Item packItem = packItems[i]; - for (int i = 0; i < packItems.Count; i++) - { - Item packItem = packItems[i]; - - if (RestoreEquip.Contains(packItem) && packItem.Movable) - from.EquipItem(packItem); - } + if (RestoreEquip.Contains(packItem) && packItem.Movable) + from.EquipItem(packItem); } + } - List items = new List(Items); + List items = new List(Items); - bool didntFit = false; + bool didntFit = false; - for (int i = 0; !didntFit && i < items.Count; ++i) + for (int i = 0; !didntFit && i < items.Count; ++i) + { + Item item = items[i]; + Point3D loc = item.Location; + + if (item.Layer == Layer.Hair || item.Layer == Layer.FacialHair || !item.Movable || + !GetRestoreInfo(item, ref loc)) + continue; + + if (pack?.CheckHold(from, item, false, true) == true) { - Item item = items[i]; - Point3D loc = item.Location; + item.Location = loc; + pack.AddItem(item); - if (item.Layer == Layer.Hair || item.Layer == Layer.FacialHair || !item.Movable || - !GetRestoreInfo(item, ref loc)) - continue; - - if (pack?.CheckHold(from, item, false, true) == true) - { - item.Location = loc; - pack.AddItem(item); - - if (RestoreEquip?.Contains(item) == true) - from.EquipItem(item); - } - else - { - didntFit = true; - } - } - - from.PlaySound(0x3E3); - - if (Items.Count != 0) - { - from.SendLocalizedMessage( - 1062472); // You gather some of your belongings. The rest remain on the corpse. + if (RestoreEquip?.Contains(item) == true) + from.EquipItem(item); } else { - SetFlag(CorpseFlag.Carved, true); - - if (ItemID == 0x2006) - { - ProcessDelta(); - SendRemovePacket(); - ItemID = Utility.Random(0xECA, 9); // bone graphic - Hue = 0; - ProcessDelta(); - } - - from.SendLocalizedMessage(1062471); // You quickly gather all of your belongings. + didntFit = true; } - - SetFlag(CorpseFlag.SelfLooted, true); } - #endregion + from.PlaySound(0x3E3); - if (!CheckLoot(from, null)) - return; - - #region Quests - - if (from is PlayerMobile player) + if (Items.Count != 0) { - QuestSystem qs = player.Quest; + from.SendLocalizedMessage(1062472); // You gather some of your belongings. The rest remain on the corpse. + } + else + { + SetFlag(CorpseFlag.Carved, true); - if (qs is UzeraanTurmoilQuest) + if (ItemID == 0x2006) { - GetDaemonBoneObjective obj = qs.FindObjective(); - if (obj?.CorpseWithBone == this && (!obj.Completed || UzeraanTurmoilQuest.HasLostDaemonBone(player))) - { - Item bone = new QuestDaemonBone(); - - if (player.PlaceInBackpack(bone)) - { - obj.CorpseWithBone = null; - player.SendLocalizedMessage(1049341, "", - 0x22); // You rummage through the bones and find a Daemon Bone! You quickly place the item in your pack. - - if (!obj.Completed) - obj.Complete(); - } - else - { - bone.Delete(); - player.SendLocalizedMessage(1049342, "", - 0x22); // Rummaging through the bones you find a Daemon Bone, but can't pick it up because your pack is too full. Come back when you have more room in your pack. - } - - return; - } + ProcessDelta(); + SendRemovePacket(); + ItemID = Utility.Random(0xECA, 9); // bone graphic + Hue = 0; + ProcessDelta(); } - else if (qs is TheSummoningQuest) - { - VanquishDaemonObjective obj = qs.FindObjective(); - if (obj?.Completed == true && obj.CorpseWithSkull == this) - { - GoldenSkull sk = new GoldenSkull(); - if (player.PlaceInBackpack(sk)) - { - obj.CorpseWithSkull = null; - player.SendLocalizedMessage( - 1050022); // For your valor in combating the devourer, you have been awarded a golden skull. - qs.Complete(); - } - else - { - sk.Delete(); - player.SendLocalizedMessage( - 1050023); // You find a golden skull, but your backpack is too full to carry it. - } - } - } + from.SendLocalizedMessage(1062471); // You quickly gather all of your belongings. } - #endregion + SetFlag(CorpseFlag.SelfLooted, true); + } - base.OnDoubleClick(from); - } - else + #endregion + + if (!CheckLoot(from, null)) + return; + + #region Quests + + if (!(from is PlayerMobile player)) return; + + QuestSystem qs = player.Quest; + + if (qs is UzeraanTurmoilQuest) { - from.SendLocalizedMessage(500446); // That is too far away. + GetDaemonBoneObjective obj = qs.FindObjective(); + if (obj?.CorpseWithBone == this && (!obj.Completed || UzeraanTurmoilQuest.HasLostDaemonBone(player))) + { + Item bone = new QuestDaemonBone(); + + if (player.PlaceInBackpack(bone)) + { + obj.CorpseWithBone = null; + player.SendLocalizedMessage(1049341, "", + 0x22); // You rummage through the bones and find a Daemon Bone! You quickly place the item in your pack. + + if (!obj.Completed) + obj.Complete(); + } + else + { + bone.Delete(); + player.SendLocalizedMessage(1049342, "", + 0x22); // Rummaging through the bones you find a Daemon Bone, but can't pick it up because your pack is too full. Come back when you have more room in your pack. + } + + return; + } } + else if (qs is TheSummoningQuest) + { + VanquishDaemonObjective obj = qs.FindObjective(); + if (obj?.Completed == true && obj.CorpseWithSkull == this) + { + GoldenSkull sk = new GoldenSkull(); + + if (player.PlaceInBackpack(sk)) + { + obj.CorpseWithSkull = null; + player.SendLocalizedMessage( + 1050022); // For your valor in combating the devourer, you have been awarded a golden skull. + qs.Complete(); + } + else + { + sk.Delete(); + player.SendLocalizedMessage( + 1050023); // You find a golden skull, but your backpack is too full to carry it. + } + } + } + + #endregion + + base.OnDoubleClick(from); } public override void OnDoubleClick(Mobile from) diff --git a/Projects/Scripts/Items/Misc/Corpses/Packets.cs b/Projects/Scripts/Items/Misc/Corpses/Packets.cs index cb4cb10d9..9a23769d5 100644 --- a/Projects/Scripts/Items/Misc/Corpses/Packets.cs +++ b/Projects/Scripts/Items/Misc/Corpses/Packets.cs @@ -11,9 +11,9 @@ namespace Server.Network List list = beheld.EquipItems; int count = list.Count; - if (beheld.Hair != null && beheld.Hair.ItemID > 0) + if (beheld.Hair?.ItemID > 0) count++; - if (beheld.FacialHair != null && beheld.FacialHair.ItemID > 0) + if (beheld.FacialHair?.ItemID > 0) count++; EnsureCapacity(8 + count * 5); @@ -31,13 +31,13 @@ namespace Server.Network } } - if (beheld.Hair != null && beheld.Hair.ItemID > 0) + if (beheld.Hair?.ItemID > 0) { m_Stream.Write((byte)(Layer.Hair + 1)); m_Stream.Write(HairInfo.FakeSerial(beheld.Owner) - 2); } - if (beheld.FacialHair != null && beheld.FacialHair.ItemID > 0) + if (beheld.FacialHair?.ItemID > 0) { m_Stream.Write((byte)(Layer.FacialHair + 1)); m_Stream.Write(FacialHairInfo.FakeSerial(beheld.Owner) - 2); @@ -55,7 +55,7 @@ namespace Server.Network List items = beheld.EquipItems; int count = items.Count; - if (beheld.Hair != null && beheld.Hair.ItemID > 0) + if (beheld.Hair?.ItemID > 0) count++; if (beheld.FacialHair != null && beheld.FacialHair.ItemID > 0) count++; @@ -87,7 +87,7 @@ namespace Server.Network } } - if (beheld.Hair != null && beheld.Hair.ItemID > 0) + if (beheld.Hair?.ItemID > 0) { m_Stream.Write(HairInfo.FakeSerial(beheld.Owner) - 2); m_Stream.Write((ushort)beheld.Hair.ItemID); @@ -128,9 +128,9 @@ namespace Server.Network List items = beheld.EquipItems; int count = items.Count; - if (beheld.Hair != null && beheld.Hair.ItemID > 0) + if (beheld.Hair?.ItemID > 0) count++; - if (beheld.FacialHair != null && beheld.FacialHair.ItemID > 0) + if (beheld.FacialHair?.ItemID > 0) count++; EnsureCapacity(5 + count * 20); @@ -161,7 +161,7 @@ namespace Server.Network } } - if (beheld.Hair != null && beheld.Hair.ItemID > 0) + if (beheld.Hair?.ItemID > 0) { m_Stream.Write(HairInfo.FakeSerial(beheld.Owner) - 2); m_Stream.Write((ushort)beheld.Hair.ItemID); @@ -176,7 +176,7 @@ namespace Server.Network ++written; } - if (beheld.FacialHair != null && beheld.FacialHair.ItemID > 0) + if (beheld.FacialHair?.ItemID > 0) { m_Stream.Write(FacialHairInfo.FakeSerial(beheld.Owner) - 2); m_Stream.Write((ushort)beheld.FacialHair.ItemID); @@ -195,4 +195,4 @@ namespace Server.Network m_Stream.Write((ushort)written); } } -} \ No newline at end of file +} diff --git a/Projects/Scripts/Multis/BaseHouse.cs b/Projects/Scripts/Multis/BaseHouse.cs index c75687e4c..b8ab229ee 100644 --- a/Projects/Scripts/Multis/BaseHouse.cs +++ b/Projects/Scripts/Multis/BaseHouse.cs @@ -646,7 +646,7 @@ namespace Server.Multis } public List AvailableVendorsFor(Mobile m) => - PlayerVendors.Where(vendor => vendor.CanInteractWith(m, false)).Cast().ToList(); + PlayerVendors.Where(vendor => vendor.CanInteractWith(m, false)).ToList(); public bool AreThereAvailableVendorsFor(Mobile m) => PlayerVendors.Any(vendor => vendor.CanInteractWith(m, false)); diff --git a/Projects/Scripts/Multis/Boats/Plank.cs b/Projects/Scripts/Multis/Boats/Plank.cs index f2564dea9..99dd05a22 100644 --- a/Projects/Scripts/Multis/Boats/Plank.cs +++ b/Projects/Scripts/Multis/Boats/Plank.cs @@ -200,10 +200,7 @@ namespace Server.Items return false; } - public bool CanClose() - { - return Map != null && !Deleted && GetObjectsInRange(0).Cast().All(o => o == this); - } + public bool CanClose() => Map != null && !Deleted && GetObjectsInRange(0).All(o => o == this); public void Close() {