chore(content): Updates to C# 9 syntax (#373)

This commit is contained in:
Kamron Batman 2020-12-30 12:50:10 -08:00 committed by GitHub
parent a59fda6a3a
commit 1e2242bb1a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
25 changed files with 155 additions and 405 deletions

View file

@ -1,6 +1,3 @@
using System;
using Server.HuePickers;
namespace Server.Network
{
public sealed class StatLockInfo : Packet

View file

@ -25,12 +25,12 @@ namespace Server.Tests.Network
DelayedExecute(() =>
{
; // Write some data into the pipe
var result = writer.TryGetMemory();
Assert.True(result.Buffer[0].Count == 99);
result.Buffer[0][0] = 0x1;
result.Buffer[0][1] = 0x2;
result.Buffer[0][2] = 0x3;
// Write some data into the pipe
var r = writer.TryGetMemory();
Assert.True(r.Buffer[0].Count == 99);
r.Buffer[0][0] = 0x1;
r.Buffer[0][1] = 0x2;
r.Buffer[0][2] = 0x3;
writer.Advance(3);
writer.Flush();

View file

@ -336,7 +336,7 @@ namespace Server.Commands
{
var built = ctor.Invoke(values);
if (built != null && realProps != null)
if (realProps != null)
{
var hadError = false;

View file

@ -1138,7 +1138,7 @@ namespace Server.Commands
while (m_DeleteQueue.Count > 0)
{
((Item)m_DeleteQueue.Dequeue()).Delete();
((Item)m_DeleteQueue.Dequeue())?.Delete();
}
return res;

View file

@ -136,7 +136,7 @@ namespace Server.Commands
);
}
e.Mobile.SendMessage("Object table has been generated. See the file : <runuo root>/objects.log");
e.Mobile.SendMessage("Object table has been generated. See the file : objects.log");
}
[Usage("TraceExpanded"), Description("Generates a log file describing all items using expanded memory.")]

View file

@ -86,20 +86,13 @@ namespace Server.Engines.BulkOrders
}
var theirSkill = m.Skills.Blacksmith.Base;
int amountMax;
if (theirSkill >= 70.1)
int amountMax = theirSkill switch
{
amountMax = Utility.RandomList(10, 15, 20, 20);
}
else if (theirSkill >= 50.1)
{
amountMax = Utility.RandomList(10, 15, 15, 20);
}
else
{
amountMax = Utility.RandomList(10, 10, 15, 20);
}
>= 70.1 => Utility.RandomList(10, 15, 20, 20),
>= 50.1 => Utility.RandomList(10, 15, 15, 20),
_ => Utility.RandomList(10, 10, 15, 20)
};
var material = BulkMaterialType.None;

View file

@ -86,20 +86,12 @@ namespace Server.Engines.BulkOrders
if (entries.Length > 0)
{
int amountMax;
if (theirSkill >= 70.1)
int amountMax = theirSkill switch
{
amountMax = Utility.RandomList(10, 15, 20, 20);
}
else if (theirSkill >= 50.1)
{
amountMax = Utility.RandomList(10, 15, 15, 20);
}
else
{
amountMax = Utility.RandomList(10, 10, 15, 20);
}
>= 70.1 => Utility.RandomList(10, 15, 20, 20),
>= 50.1 => Utility.RandomList(10, 15, 15, 20),
_ => Utility.RandomList(10, 10, 15, 20)
};
var material = BulkMaterialType.None;

View file

@ -215,26 +215,14 @@ namespace Server.Engines.Doom
var random = Utility.Random(100);
if (random < 22)
trap = random switch
{
trap = new SawTrap(Utility.RandomBool() ? SawTrapType.WestFloor : SawTrapType.NorthFloor);
}
else if (random < 44)
{
trap = new SpikeTrap(Utility.RandomBool() ? SpikeTrapType.WestFloor : SpikeTrapType.NorthFloor);
}
else if (random < 66)
{
trap = new GasTrap(Utility.RandomBool() ? GasTrapType.NorthWall : GasTrapType.WestWall);
}
else if (random < 88)
{
trap = new FireColumnTrap();
}
else
{
trap = new MushroomTrap();
}
< 22 => new SawTrap(Utility.RandomBool() ? SawTrapType.WestFloor : SawTrapType.NorthFloor),
< 44 => new SpikeTrap(Utility.RandomBool() ? SpikeTrapType.WestFloor : SpikeTrapType.NorthFloor),
< 66 => new GasTrap(Utility.RandomBool() ? GasTrapType.NorthWall : GasTrapType.WestWall),
< 88 => new FireColumnTrap(),
_ => new MushroomTrap()
};
if (trap is FireColumnTrap || trap is MushroomTrap)
{

View file

@ -1489,26 +1489,15 @@ namespace Server.Items
if (m_Resource == CraftResource.None)
{
if (mat == ArmorMaterialType.Studded || mat == ArmorMaterialType.Leather)
m_Resource = mat switch
{
m_Resource = CraftResource.RegularLeather;
}
else if (mat == ArmorMaterialType.Spined)
{
m_Resource = CraftResource.SpinedLeather;
}
else if (mat == ArmorMaterialType.Horned)
{
m_Resource = CraftResource.HornedLeather;
}
else if (mat == ArmorMaterialType.Barbed)
{
m_Resource = CraftResource.BarbedLeather;
}
else
{
m_Resource = CraftResource.Iron;
}
ArmorMaterialType.Studded => CraftResource.RegularLeather,
ArmorMaterialType.Leather => CraftResource.RegularLeather,
ArmorMaterialType.Spined => CraftResource.SpinedLeather,
ArmorMaterialType.Horned => CraftResource.HornedLeather,
ArmorMaterialType.Barbed => CraftResource.BarbedLeather,
_ => CraftResource.Iron
};
}
if (m_MaxHitPoints == 0 && m_HitPoints == 0)

View file

@ -1,3 +1,4 @@
using System;
using Server.Network;
namespace Server.Items
@ -149,19 +150,7 @@ namespace Server.Items
*/
if (owner.CheckSkill(SkillName.Parry, chance))
{
if (weapon.Skill == SkillName.Archery)
{
damage -= (int)ar;
}
else
{
damage -= (int)(ar / 2.0);
}
if (damage < 0)
{
damage = 0;
}
damage -= Math.Min(damage, weapon.Skill == SkillName.Archery ? (int)ar : (int)(ar / 2.0));
owner.FixedEffect(0x37B9, 10, 16);

View file

@ -294,100 +294,33 @@ namespace Server.Items
return false;
}
string option = null;
if (this is ArmorIgnore)
string option = this switch
{
option = "Armor Ignore";
}
else if (this is BleedAttack)
{
option = "Bleed Attack";
}
else if (this is ConcussionBlow)
{
option = "Concussion Blow";
}
else if (this is CrushingBlow)
{
option = "Crushing Blow";
}
else if (this is Disarm)
{
option = "Disarm";
}
else if (this is Dismount)
{
option = "Dismount";
}
else if (this is DoubleStrike)
{
option = "Double Strike";
}
else if (this is InfectiousStrike)
{
option = "Infectious Strike";
}
else if (this is MortalStrike)
{
option = "Mortal Strike";
}
else if (this is MovingShot)
{
option = "Moving Shot";
}
else if (this is ParalyzingBlow)
{
option = "Paralyzing Blow";
}
else if (this is ShadowStrike)
{
option = "Shadow Strike";
}
else if (this is WhirlwindAttack)
{
option = "Whirlwind Attack";
}
else if (this is RidingSwipe)
{
option = "Riding Swipe";
}
else if (this is FrenziedWhirlwind)
{
option = "Frenzied Whirlwind";
}
else if (this is Block)
{
option = "Block";
}
else if (this is DefenseMastery)
{
option = "Defense Mastery";
}
else if (this is NerveStrike)
{
option = "Nerve Strike";
}
else if (this is TalonStrike)
{
option = "Talon Strike";
}
else if (this is Feint)
{
option = "Feint";
}
else if (this is DualWield)
{
option = "Dual Wield";
}
else if (this is DoubleShot)
{
option = "Double Shot";
}
else if (this is ArmorPierce)
{
option = "Armor Pierce";
}
ArmorIgnore _ => "Armor Ignore",
BleedAttack _ => "Bleed Attack",
ConcussionBlow _ => "Concussion Blow",
CrushingBlow _ => "Crushing Blow",
Disarm _ => "Disarm",
Dismount _ => "Dismount",
DoubleStrike _ => "Double Strike",
InfectiousStrike _ => "Infectious Strike",
MortalStrike _ => "Mortal Strike",
MovingShot _ => "Moving Shot",
ParalyzingBlow _ => "Paralyzing Blow",
ShadowStrike _ => "Shadow Strike",
WhirlwindAttack _ => "Whirlwind Attack",
RidingSwipe _ => "Riding Swipe",
FrenziedWhirlwind _ => "Frenzied Whirlwind",
Block _ => "Block",
DefenseMastery _ => "Defense Mastery",
NerveStrike _ => "Nerve Strike",
TalonStrike _ => "Talon Strike",
Feint _ => "Feint",
DualWield _ => "Dual Wield",
DoubleShot _ => "Double Shot",
ArmorPierce _ => "Armor Pierce",
_ => null
};
if (option != null && !DuelContext.AllowSpecialAbility(from, option, true))
{

View file

@ -865,24 +865,9 @@ namespace Server.Misc
{
var vMax = max - 30;
var vStr = str - 10;
var vDex = dex - 10;
var vInt = intel - 10;
if (vStr < 0)
{
vStr = 0;
}
if (vDex < 0)
{
vDex = 0;
}
if (vInt < 0)
{
vInt = 0;
}
var vStr = Math.Max(str - 10, 0);
var vDex = Math.Max(dex - 10, 0);
var vInt = Math.Max(intel - 10, 0);
var total = vStr + vDex + vInt;

View file

@ -80,27 +80,14 @@ namespace Server
* 6:00 AM -> 9:59 PM : Day
*/
if (hours < 4)
return hours switch
{
return NightLevel;
}
if (hours < 6)
{
return NightLevel + ((hours - 4) * 60 + minutes) * (DayLevel - NightLevel) / 120;
}
if (hours < 22)
{
return DayLevel;
}
if (hours < 24)
{
return DayLevel + ((hours - 22) * 60 + minutes) * (NightLevel - DayLevel) / 120;
}
return NightLevel; // should never be
< 4 => NightLevel,
< 6 => NightLevel + ((hours - 4) * 60 + minutes) * (DayLevel - NightLevel) / 120,
< 22 => DayLevel,
< 24 => DayLevel + ((hours - 22) * 60 + minutes) * (NightLevel - DayLevel) / 120,
_ => NightLevel
};
}
private class LightCycleTimer : Timer

View file

@ -841,7 +841,7 @@ namespace Server
}
else if (item is BaseInstrument instr)
{
var slayer = SlayerName.None;
SlayerName slayer;
if (Core.AOS)
{

View file

@ -329,16 +329,7 @@ namespace Server.Misc
}
else
{
density = 150 - m_Stage * 5;
if (density < 10)
{
density = 10;
}
else if (density > 70)
{
density = 70;
}
density = Math.Clamp(150 - m_Stage * 5, 10, 70);
}
if (density == 0)

View file

@ -1284,30 +1284,30 @@ namespace Server.Mobiles
(int)((useBaseSkill ? m.Skills.AnimalTaming.Base : m.Skills.AnimalTaming.Value) * 10);
var lore =
(int)((useBaseSkill ? m.Skills.AnimalLore.Base : m.Skills.AnimalLore.Value) * 10);
int bonus, chance = 700;
int bonus;
if (Core.ML)
{
var SkillBonus = taming - (int)(dMinTameSkill * 10);
var LoreBonus = lore - (int)(dMinTameSkill * 10);
var skillBonus = taming - (int)(dMinTameSkill * 10);
var loreBonus = lore - (int)(dMinTameSkill * 10);
var SkillMod = 6;
var LoreMod = 6;
var skillMod = 6;
var loreMod = 6;
if (SkillBonus < 0)
if (skillBonus < 0)
{
SkillMod = 28;
skillMod = 28;
}
if (LoreBonus < 0)
if (loreBonus < 0)
{
LoreMod = 14;
loreMod = 14;
}
SkillBonus *= SkillMod;
LoreBonus *= LoreMod;
skillBonus *= skillMod;
loreBonus *= loreMod;
bonus = (SkillBonus + LoreBonus) / 2;
bonus = (skillBonus + loreBonus) / 2;
}
else
{
@ -1325,16 +1325,16 @@ namespace Server.Mobiles
}
}
chance += bonus;
var chance = 700 + bonus;
if (chance >= 0 && chance < 200)
{
chance = 200;
}
else if (chance > 990)
if (chance > 990)
{
chance = 990;
}
else if (chance >= 0)
{
chance = 220;
}
chance -= (MaxLoyalty - m_Loyalty) * 10;

View file

@ -52,7 +52,6 @@ namespace Server.Mobiles
KarmaLocked = 0x00000020,
AutoRenewInsurance = 0x00000040,
UseOwnFilter = 0x00000080,
PublicMyRunUO = 0x00000100,
PagingSquelched = 0x00000200,
Young = 0x00000400,
AcceptGuildInvites = 0x00000800,
@ -562,13 +561,6 @@ namespace Server.Mobiles
set => SetFlag(PlayerFlag.UseOwnFilter, value);
}
[CommandProperty(AccessLevel.GameMaster)]
public bool PublicMyRunUO
{
get => GetFlag(PlayerFlag.PublicMyRunUO);
set => SetFlag(PlayerFlag.PublicMyRunUO, value);
}
[CommandProperty(AccessLevel.GameMaster)]
public bool AcceptGuildInvites
{

View file

@ -15,17 +15,14 @@ namespace Server.Mobiles
if (item is BaseArmor armor)
{
if (armor.Quality == ArmorQuality.Low)
price = armor.Quality switch
{
price = (int)(price * 0.60);
}
else if (armor.Quality == ArmorQuality.Exceptional)
{
price = (int)(price * 1.25);
}
ArmorQuality.Low => (int)(price * 0.60),
ArmorQuality.Exceptional => (int)(price * 1.25),
_ => price
};
price += 100 * (int)armor.Durability;
price += 100 * (int)armor.ProtectionLevel;
if (price < 1)
@ -35,17 +32,14 @@ namespace Server.Mobiles
}
else if (item is BaseWeapon weapon)
{
if (weapon.Quality == WeaponQuality.Low)
price = weapon.Quality switch
{
price = (int)(price * 0.60);
}
else if (weapon.Quality == WeaponQuality.Exceptional)
{
price = (int)(price * 1.25);
}
WeaponQuality.Low => (int)(price * 0.60),
WeaponQuality.Exceptional => (int)(price * 1.25),
_ => price
};
price += 100 * (int)weapon.DurabilityLevel;
price += 100 * (int)weapon.DamageLevel;
if (price < 1)

View file

@ -126,66 +126,30 @@ namespace Server.Mobiles
public int ComputePriceFor(HouseDeed deed)
{
var price = 0;
if (deed is SmallBrickHouseDeed || deed is StonePlasterHouseDeed || deed is FieldStoneHouseDeed ||
deed is WoodHouseDeed || deed is WoodPlasterHouseDeed ||
deed is ThatchedRoofCottageDeed)
var price = deed switch
{
price = 43800;
}
else if (deed is BrickHouseDeed)
{
price = 144500;
}
else if (deed is TwoStoryWoodPlasterHouseDeed || deed is TwoStoryStonePlasterHouseDeed)
{
price = 192400;
}
else if (deed is TowerDeed)
{
price = 433200;
}
else if (deed is KeepDeed)
{
price = 665200;
}
else if (deed is CastleDeed)
{
price = 1022800;
}
else if (deed is LargePatioDeed)
{
price = 152800;
}
else if (deed is LargeMarbleDeed)
{
price = 192800;
}
else if (deed is SmallTowerDeed)
{
price = 88500;
}
else if (deed is LogCabinDeed)
{
price = 97800;
}
else if (deed is SandstonePatioDeed)
{
price = 90900;
}
else if (deed is VillaDeed)
{
price = 136500;
}
else if (deed is StoneWorkshopDeed)
{
price = 60600;
}
else if (deed is MarbleWorkshopDeed)
{
price = 60300;
}
SmallBrickHouseDeed => 43800,
StonePlasterHouseDeed => 43800,
FieldStoneHouseDeed => 43800,
WoodHouseDeed => 43800,
WoodPlasterHouseDeed => 43800,
ThatchedRoofCottageDeed => 43800,
BrickHouseDeed => 144500,
TwoStoryWoodPlasterHouseDeed => 192400,
TwoStoryStonePlasterHouseDeed => 192400,
TowerDeed => 433200,
KeepDeed => 665200,
CastleDeed => 1022800,
LargePatioDeed => 152800,
LargeMarbleDeed => 192800,
SmallTowerDeed => 88500,
LogCabinDeed => 97800,
SandstonePatioDeed => 90900,
VillaDeed => 136500,
StoneWorkshopDeed => 60600,
MarbleWorkshopDeed => 60300,
_ => 0
};
return AOS.Scale(price, 80); // refunds 80% of the purchase price
}

View file

@ -50,18 +50,12 @@ namespace Server.Mobiles
{
var theirSkill = pm.Skills.Tailoring.Base;
if (theirSkill >= 70.1)
pm.NextTailorBulkOrder = theirSkill switch
{
pm.NextTailorBulkOrder = TimeSpan.FromHours(6.0);
}
else if (theirSkill >= 50.1)
{
pm.NextTailorBulkOrder = TimeSpan.FromHours(2.0);
}
else
{
pm.NextTailorBulkOrder = TimeSpan.FromHours(1.0);
}
>= 70.1 => TimeSpan.FromHours(6.0),
>= 50.1 => TimeSpan.FromHours(2.0),
_ => TimeSpan.FromHours(1.0)
};
if (theirSkill >= 70.1 && (theirSkill - 40.0) / 300.0 > Utility.RandomDouble())
{

View file

@ -702,42 +702,22 @@ namespace Server.Mobiles
{
var item = Items[i];
if (item is BaseHat)
item.Layer = item switch
{
item.Layer = Layer.Helm;
}
else if (item is BaseMiddleTorso)
{
item.Layer = Layer.MiddleTorso;
}
else if (item is BaseOuterLegs)
{
item.Layer = Layer.OuterLegs;
}
else if (item is BaseOuterTorso)
{
item.Layer = Layer.OuterTorso;
}
else if (item is BasePants)
{
item.Layer = Layer.Pants;
}
else if (item is BaseShirt)
{
item.Layer = Layer.Shirt;
}
else if (item is BaseWaist)
{
item.Layer = Layer.Waist;
}
else if (item is BaseShoes)
{
if (item is Sandals)
{
item.Hue = 0;
}
BaseHat => Layer.Helm,
BaseMiddleTorso => Layer.MiddleTorso,
BaseOuterLegs => Layer.OuterLegs,
BaseOuterTorso => Layer.OuterTorso,
BasePants => Layer.Pants,
BaseShirt => Layer.Shirt,
BaseWaist => Layer.Waist,
BaseShoes => Layer.Shoes,
_ => item.Layer
};
item.Layer = Layer.Shoes;
if (item is Sandals)
{
item.Hue = 0;
}
}
}

View file

@ -1840,12 +1840,14 @@ namespace Server.Multis
{
door = new GenericHouseDoor(GetSADoorFacing(itemID - 0x5142), itemID, 0xF0, 0xEF, false);
}
// TODO: Fix this because the heuristic is broken, or remove the type calculation
else if (itemID >= 0x9AD7 && itemID <= 0x9AE6)
{
var type = (itemID - 0x9AD7) / 16;
var facing = (DoorFacing)((itemID - 0x9AD7) / 2 % 8);
door = new GenericHouseDoor(facing, 0x9AD7 + type * 16, 0xED, 0xF4);
}
// TODO: Fix this because the heuristic is broken, or remove the type calculation
else if (itemID >= 0x9B3C && itemID <= 0x9B4B)
{
var type = (itemID - 0x9B3C) / 16;

View file

@ -107,17 +107,7 @@ namespace Server.SkillHandlers
{
if (from.CheckTargetSkill(SkillName.ArmsLore, pet, 0, 100))
{
var perc = 4 * pet.BardingHP / pet.BardingMaxHP;
if (perc < 0)
{
perc = 0;
}
else if (perc > 4)
{
perc = 4;
}
var perc = Math.Clamp(4 * pet.BardingHP / pet.BardingMaxHP, 0, 4);
pet.PrivateOverheadMessage(MessageType.Regular, 0x3B2, 1053021 - perc, from.NetState);
}
else

View file

@ -31,23 +31,13 @@ namespace Server.SkillHandlers
{
var foundAnyone = false;
Point3D p;
if (targ is Mobile mobile)
Point3D p = targ switch
{
p = mobile.Location;
}
else if (targ is Item item)
{
p = item.Location;
}
else if (targ is IPoint3D d)
{
p = new Point3D(d);
}
else
{
p = src.Location;
}
Mobile mobile => mobile.Location,
Item item => item.Location,
IPoint3D d => new Point3D(d),
_ => src.Location
};
var srcSkill = src.Skills.DetectHidden.Value;
var range = (int)(srcSkill / 10.0);

View file

@ -210,9 +210,9 @@ namespace Server.Misc
{
switch (info.ButtonID)
{
case 1: // RunUO
case 1:
{
sender.LaunchBrowser("https://github.com/runuo/");
sender.LaunchBrowser("https://www.modernuo.com");
break;
}
case 2: // List of skills