From 6ef32ce9107d20935a2d6bc9f6047b8c2da69a87 Mon Sep 17 00:00:00 2001 From: Kamron Batman <3953314+kamronbatman@users.noreply.github.com> Date: Mon, 3 Sep 2018 09:34:36 -0700 Subject: [PATCH] Fixes unavailable syntax for Mono. --- Scripts/Commands/GenCategorization.cs | 8 +- .../Factions/Mobiles/Guards/GuardAI.cs | 10 +-- Scripts/Engines/MLQuests/Items/RewardBags.cs | 23 +++--- Scripts/Items/Containers/SalvageBag.cs | 76 +++++++------------ Scripts/Items/Misc/ArcaneGem.cs | 64 +++++----------- Scripts/Items/Misc/InteriorDecorator.cs | 60 +++++++-------- Server/Persistence/DualSaveStrategy.cs | 2 +- 7 files changed, 99 insertions(+), 144 deletions(-) diff --git a/Scripts/Commands/GenCategorization.cs b/Scripts/Commands/GenCategorization.cs index 729289e4d..e9b27e5a3 100644 --- a/Scripts/Commands/GenCategorization.cs +++ b/Scripts/Commands/GenCategorization.cs @@ -247,13 +247,13 @@ namespace Server.Commands if ( x is CategoryEntry entry ) a = entry.Title; - else if ( x is CategoryTypeEntry typeEntry ) - a = typeEntry.Type.Name; + else if ( x is CategoryTypeEntry xTypeEntry ) + a = xTypeEntry.Type.Name; if ( y is CategoryEntry categoryEntry ) b = categoryEntry.Title; - else if ( y is CategoryTypeEntry typeEntry ) - b = typeEntry.Type.Name; + else if ( y is CategoryTypeEntry yTypeEntry ) + b = yTypeEntry.Type.Name; if ( a == null && b == null ) return 0; diff --git a/Scripts/Engines/Factions/Mobiles/Guards/GuardAI.cs b/Scripts/Engines/Factions/Mobiles/Guards/GuardAI.cs index 0958df537..cbd23528b 100644 --- a/Scripts/Engines/Factions/Mobiles/Guards/GuardAI.cs +++ b/Scripts/Engines/Factions/Mobiles/Guards/GuardAI.cs @@ -573,10 +573,10 @@ namespace Server.Factions StartBandage(); } - if ( m_Mobile.Spell == null && Core.TickCount - m_Mobile.NextSpellTime >= 0 ) - { - Spell spell = null; + Spell spell = m_Mobile.Spell as Spell; + if ( spell == null && Core.TickCount - m_Mobile.NextSpellTime >= 0 ) + { DateTime toRelease = DateTime.MinValue; if ( IsPoisoned ) @@ -678,7 +678,7 @@ namespace Server.Factions if ( types.Count > 1 ) spell = new BlessSpell( m_Guard, null ); else if ( types.Count == 1 ) - spell = (Spell) Activator.CreateInstance( types[0], new object[]{ m_Guard, null } ); + spell = Activator.CreateInstance( types[0], new object[]{ m_Guard, null } ) as Spell; } else if ( types.Count > 0 ) { @@ -757,7 +757,7 @@ namespace Server.Factions if ( spell == null || !spell.Cast() ) EquipWeapon(); } - else if ( m_Mobile.Spell is Spell spell && spell.State == SpellState.Sequencing ) + else if ( spell?.State == SpellState.Sequencing ) { EquipWeapon(); } diff --git a/Scripts/Engines/MLQuests/Items/RewardBags.cs b/Scripts/Engines/MLQuests/Items/RewardBags.cs index e75051371..299202a91 100644 --- a/Scripts/Engines/MLQuests/Items/RewardBags.cs +++ b/Scripts/Engines/MLQuests/Items/RewardBags.cs @@ -43,17 +43,20 @@ namespace Server.Engines.MLQuests.Items public static void Enhance( Item loot ) { - switch (loot) + if (loot is BaseWeapon weapon) { - case BaseWeapon weapon: - BaseRunicTool.ApplyAttributesTo( weapon, Utility.RandomMinMax( 1, 5 ), 10, 80 ); - break; - case BaseArmor armor: - BaseRunicTool.ApplyAttributesTo( armor, Utility.RandomMinMax( 1, 5 ), 10, 80 ); - break; - default: - BaseRunicTool.ApplyAttributesTo((BaseJewel)loot, Utility.RandomMinMax( 1, 5 ), 10, 80 ); - break; + BaseRunicTool.ApplyAttributesTo( weapon, Utility.RandomMinMax( 1, 5 ), 10, 80 ); + return; + } + + if (loot is BaseArmor armor) + { + BaseRunicTool.ApplyAttributesTo( armor, Utility.RandomMinMax( 1, 5 ), 10, 80 ); + } + + if (loot is BaseJewel jewel) + { + BaseRunicTool.ApplyAttributesTo(jewel, Utility.RandomMinMax( 1, 5 ), 10, 80 ); } } } diff --git a/Scripts/Items/Containers/SalvageBag.cs b/Scripts/Items/Containers/SalvageBag.cs index a3f3ce9aa..518b93146 100644 --- a/Scripts/Items/Containers/SalvageBag.cs +++ b/Scripts/Items/Containers/SalvageBag.cs @@ -43,19 +43,14 @@ namespace Server.Items #region Checks private bool Resmeltables() //Where context menu checks for metal items and dragon barding deeds { - foreach( Item i in Items ) + foreach (Item i in Items) { - if (i?.Deleted != false) - continue; - - switch (i) - { - case BaseWeapon weapon when CraftResources.GetType( weapon.Resource ) == CraftResourceType.Metal: - case BaseArmor armor when CraftResources.GetType( armor.Resource ) == CraftResourceType.Metal: - case DragonBardingDeed _: - return true; - } + return i?.Deleted == false && ( + i is BaseWeapon weapon && CraftResources.GetType(weapon.Resource) == CraftResourceType.Metal || + i is BaseArmor armor && CraftResources.GetType(armor.Resource) == CraftResourceType.Metal || + i is DragonBardingDeed); } + return false; } @@ -63,20 +58,14 @@ namespace Server.Items { foreach( Item i in Items ) { - if (!(i is IScissorable && !i.Deleted)) + if (!(i is IScissorable) || i.Deleted) continue; - switch (i) - { - case BaseClothing _: - case BaseArmor armor when CraftResources.GetType( armor.Resource ) == CraftResourceType.Leather: - case Cloth _: - case BoltOfCloth _: - case Hides _: - case BonePile _: - return true; - } + if (i is BaseClothing || i is Cloth || i is BoltOfCloth || i is Hides || i is BonePile || + i is BaseArmor armor && CraftResources.GetType(armor.Resource) == CraftResourceType.Leather) + return true; } + return false; } #endregion @@ -192,32 +181,25 @@ namespace Server.Items Container sBag = this; - List Smeltables = sBag.FindItemsByType(); + List smeltables = sBag.FindItemsByType(); + + foreach (Item item in smeltables) + { + if (item?.Deleted != false) + continue; + + if (item is BaseArmor armor && Resmelt(from, armor, armor.Resource) || + item is BaseWeapon weapon && Resmelt(from, weapon, weapon.Resource) || + item is DragonBardingDeed) + { + salvaged++; + } + else + { + notSalvaged++; + } + } - for(int i = Smeltables.Count - 1; i >= 0; i--) - { - switch (Smeltables[i]) - { - case BaseArmor armor when Resmelt( from, armor, armor.Resource ): - salvaged++; - break; - case BaseArmor _: - notSalvaged++; - break; - case BaseWeapon weapon when Resmelt( from, weapon, weapon.Resource ): - salvaged++; - break; - case BaseWeapon _: - notSalvaged++; - break; - case DragonBardingDeed deed when Resmelt( from, deed, deed.Resource ): - salvaged++; - break; - case DragonBardingDeed _: - notSalvaged++; - break; - } - } if ( m_Failure ) { from.SendLocalizedMessage( 1079975 ); // You failed to smelt some metal for lack of skill. diff --git a/Scripts/Items/Misc/ArcaneGem.cs b/Scripts/Items/Misc/ArcaneGem.cs index b79bc9dca..9ffc2a19c 100644 --- a/Scripts/Items/Misc/ArcaneGem.cs +++ b/Scripts/Items/Misc/ArcaneGem.cs @@ -61,21 +61,11 @@ namespace Server.Items if ( obj is IArcaneEquip eq && eq is Item item ) { - CraftResource resource = CraftResource.None; + BaseClothing clothing = item as BaseClothing; + BaseArmor armor = item as BaseArmor; + BaseWeapon weapon = item as BaseWeapon; - switch (item) - { - case BaseClothing clothing: - resource = clothing.Resource; - break; - case BaseArmor armor: - resource = armor.Resource; - break; - // Sanity, weapons cannot receive gems... - case BaseWeapon weapon: - resource = weapon.Resource; - break; - } + CraftResource resource = clothing?.Resource ?? armor?.Resource ?? weapon?.Resource ?? CraftResource.None; if ( !item.IsChildOf( from.Backpack ) ) { @@ -119,39 +109,27 @@ namespace Server.Items } else if ( from.Skills[SkillName.Tailoring].Value >= 80.0 ) { - bool isExceptional = false; - - switch (item) - { - case BaseClothing clothing: - isExceptional = clothing.Quality == ClothingQuality.Exceptional; - break; - case BaseArmor armor: - isExceptional = armor.Quality == ArmorQuality.Exceptional; - break; - case BaseWeapon weapon: - isExceptional = weapon.Quality == WeaponQuality.Exceptional; - break; - } + bool isExceptional = clothing?.Quality == ClothingQuality.Exceptional || + armor?.Quality == ArmorQuality.Exceptional || + weapon?.Quality == WeaponQuality.Exceptional; if ( isExceptional ) { - switch (item) + if (clothing != null) { - case BaseClothing clothing: - clothing.Quality = ClothingQuality.Regular; - clothing.Crafter = @from; - break; - case BaseArmor armor: - armor.Quality = ArmorQuality.Regular; - armor.Crafter = @from; - armor.PhysicalBonus = armor.FireBonus = armor.ColdBonus = armor.PoisonBonus = armor.EnergyBonus = 0; // Is there a method to remove bonuses? - break; - // Sanity, weapons cannot receive gems... - case BaseWeapon weapon: - weapon.Quality = WeaponQuality.Regular; - weapon.Crafter = @from; - break; + clothing.Quality = ClothingQuality.Regular; + clothing.Crafter = from; + } + else if (armor != null) + { + armor.Quality = ArmorQuality.Regular; + armor.Crafter = from; + armor.PhysicalBonus = armor.FireBonus = armor.ColdBonus = armor.PoisonBonus = armor.EnergyBonus = 0; // Is there a method to remove bonuses? + } + else if (weapon != null) + { + weapon.Quality = WeaponQuality.Regular; + weapon.Crafter = from; } eq.CurArcaneCharges = eq.MaxArcaneCharges = charges; diff --git a/Scripts/Items/Misc/InteriorDecorator.cs b/Scripts/Items/Misc/InteriorDecorator.cs index 4938ff4f5..22bcf57dd 100644 --- a/Scripts/Items/Misc/InteriorDecorator.cs +++ b/Scripts/Items/Misc/InteriorDecorator.cs @@ -155,28 +155,25 @@ namespace Server.Items BaseHouse house = BaseHouse.FindHouseAt( from ); bool isDecorableComponent = false; + object addon = null; + int count = 0; - if ( item is AddonComponent || item is AddonContainerComponent || item is BaseAddonContainer ) + if (item is AddonComponent component) { - object addon = null; - int count = 0; - - switch (item) - { - case AddonComponent component: - count = component.Addon.Components.Count; - addon = component.Addon; - break; - case AddonContainerComponent containerComponent: - count = containerComponent.Addon.Components.Count; - addon = containerComponent.Addon; - break; - case BaseAddonContainer container: - count = container.Components.Count; - addon = container; - break; - } + count = component.Addon.Components.Count; + addon = component.Addon; + } else if (item is AddonContainerComponent containerComponent) + { + count = containerComponent.Addon.Components.Count; + addon = containerComponent.Addon; + } else if (item is BaseAddonContainer container) + { + count = container.Components.Count; + addon = container; + } + if (addon != null) + { if ( count == 1 && Core.SE ) isDecorableComponent = true; @@ -236,22 +233,17 @@ namespace Server.Items private static void Turn( Item item, Mobile from ) { - if ( item is AddonComponent || item is AddonContainerComponent || item is BaseAddonContainer ) - { - object addon = null; + object addon = null; - switch (item) - { - case AddonComponent component: - addon = component.Addon; - break; - case AddonContainerComponent containerComponent: - addon = containerComponent.Addon; - break; - case BaseAddonContainer container: - addon = container; - break; - } + if (item is AddonComponent component) + addon = component.Addon; + else if (item is AddonContainerComponent containerComponent) + addon = containerComponent.Addon; + else if (item is BaseAddonContainer container) + addon = container; + + if (addon != null) + { FlippableAddonAttribute[] aAttributes = (FlippableAddonAttribute[]) addon.GetType().GetCustomAttributes( typeof( FlippableAddonAttribute ), false ); diff --git a/Server/Persistence/DualSaveStrategy.cs b/Server/Persistence/DualSaveStrategy.cs index b9a933095..eebc299f3 100644 --- a/Server/Persistence/DualSaveStrategy.cs +++ b/Server/Persistence/DualSaveStrategy.cs @@ -39,7 +39,7 @@ namespace Server { { this.PermitBackgroundWrite = permitBackgroundWrite; - Thread saveThread = new Thread( delegate { + Thread saveThread = new Thread( delegate() { SaveItems(metrics); } );