Creates random element extension (#196)

This commit is contained in:
Kamron Batman 2020-08-21 19:50:36 -07:00 committed by GitHub
parent 0926b5abaa
commit 4403d6c1c7
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
84 changed files with 226 additions and 330 deletions

View file

@ -4798,7 +4798,7 @@ namespace Server
var sb = new StringBuilder(text.Length, text.Length);
for (var i = 0; i < text.Length; ++i)
sb.Append(text[i] != ' ' ? GhostChars[Utility.Random(GhostChars.Length)] : ' ');
sb.Append(text[i] != ' ' ? GhostChars.RandomElement() : ' ');
text = sb.ToString();
context = m_GhostMutateContext;

View file

@ -502,9 +502,9 @@ namespace Server
public static SkillName RandomSkill() =>
m_AllSkills[Random(m_AllSkills.Length - (Core.ML ? 0 : Core.SE ? 1 : Core.AOS ? 3 : 6))];
public static SkillName RandomCombatSkill() => m_CombatSkills[Random(m_CombatSkills.Length)];
public static SkillName RandomCombatSkill() => m_CombatSkills.RandomElement();
public static SkillName RandomCraftSkill() => m_CraftSkills[Random(m_CraftSkills.Length)];
public static SkillName RandomCraftSkill() => m_CraftSkills.RandomElement();
public static void FixPoints(ref Point3D top, ref Point3D bottom)
{
@ -862,10 +862,10 @@ namespace Server
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static int RandomList(params int[] list) => RandomList<int>(list);
public static T RandomList<T>(params T[] list) => list.RandomElement();
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static T RandomList<T>(IList<T> list) => list[Random(list.Count)];
public static T RandomElement<T>(this IList<T> list) => list.Count == 0 ? default : list[Random(list.Count)];
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static bool RandomBool() => RandomSources.Source.NextBool();

View file

@ -80,7 +80,7 @@ namespace Server.Engines.BulkOrders
List<RewardItem> rewards = ComputeRewards(false);
reward = rewards.Count <= 0 ? null : rewards[Utility.Random(rewards.Count)].Construct();
reward = rewards.RandomElement()?.Construct();
}
public virtual List<RewardItem> ComputeRewards(bool full)

View file

@ -387,7 +387,7 @@ namespace Server.Engines.BulkOrders
{
return type switch
{
1 => (Item)new LeatherGlovesOfMining(1),
1 => new LeatherGlovesOfMining(1),
3 => new StuddedGlovesOfMining(3),
5 => new RingmailGlovesOfMining(5),
_ => throw new InvalidOperationException()
@ -644,11 +644,7 @@ namespace Server.Engines.BulkOrders
private static Item CreateCloth(int type)
{
if (type >= 0 && type < m_ClothHues.Length)
{
UncutCloth cloth = new UncutCloth(100);
cloth.Hue = m_ClothHues[type][Utility.Random(m_ClothHues[type].Length)];
return cloth;
}
return new UncutCloth(100) {Hue = m_ClothHues[type].RandomElement()};
throw new InvalidOperationException();
}
@ -660,40 +656,34 @@ namespace Server.Engines.BulkOrders
0x484, 0x497
};
private static Item CreateSandals(int type) => new Sandals(m_SandalHues[Utility.Random(m_SandalHues.Length)]);
private static Item CreateSandals(int type) => new Sandals(m_SandalHues.RandomElement());
private static Item CreateStretchedHide(int type)
{
return Utility.Random(4) switch
private static Item CreateStretchedHide(int type) =>
Utility.Random(4) switch
{
1 => (Item)new SmallStretchedHideSouthDeed(),
1 => new SmallStretchedHideSouthDeed(),
2 => new MediumStretchedHideEastDeed(),
3 => new MediumStretchedHideSouthDeed(),
_ => new SmallStretchedHideEastDeed()
};
}
private static Item CreateTapestry(int type)
{
return Utility.Random(4) switch
private static Item CreateTapestry(int type) =>
Utility.Random(4) switch
{
1 => (Item)new LightFlowerTapestrySouthDeed(),
1 => new LightFlowerTapestrySouthDeed(),
2 => new DarkFlowerTapestryEastDeed(),
3 => new DarkFlowerTapestrySouthDeed(),
_ => new LightFlowerTapestryEastDeed()
};
}
private static Item CreateBearRug(int type)
{
return Utility.Random(4) switch
private static Item CreateBearRug(int type) =>
Utility.Random(4) switch
{
1 => (Item)new BrownBearRugSouthDeed(),
1 => new BrownBearRugSouthDeed(),
2 => new PolarBearRugEastDeed(),
3 => new PolarBearRugSouthDeed(),
_ => new BrownBearRugEastDeed()
};
}
private static Item CreateRunicKit(int type)
{

View file

@ -43,7 +43,7 @@ namespace Server.Engines.BulkOrders
bool reqExceptional = Utility.RandomBool() || material == BulkMaterialType.None;
SmallBulkEntry entry = entries[Utility.Random(entries.Length)];
SmallBulkEntry entry = entries.RandomElement();
Hue = hue;
AmountMax = amountMax;
@ -151,7 +151,7 @@ namespace Server.Engines.BulkOrders
if (validEntries.Count <= 0)
return null;
SmallBulkEntry entry = validEntries[Utility.Random(validEntries.Count)];
SmallBulkEntry entry = validEntries.RandomElement();
return new SmallSmithBOD(entry, material, amountMax, reqExceptional);
}

View file

@ -35,7 +35,7 @@ namespace Server.Engines.BulkOrders
: BulkMaterialType.None;
bool reqExceptional = Utility.RandomBool() || material == BulkMaterialType.None;
SmallBulkEntry entry = entries[Utility.Random(entries.Length)];
SmallBulkEntry entry = entries.RandomElement();
Hue = hue;
AmountMax = amountMax;
@ -147,7 +147,7 @@ namespace Server.Engines.BulkOrders
if (validEntries.Count > 0)
{
SmallBulkEntry entry = validEntries[Utility.Random(validEntries.Count)];
SmallBulkEntry entry = validEntries.RandomElement();
return new SmallTailorBOD(entry, material, amountMax, reqExceptional);
}
}

View file

@ -682,7 +682,7 @@ namespace Server.Engines.CannedEvil
{
try
{
return ActivatorUtil.CreateInstance(types[Utility.Random(types.Length)]) as Mobile;
return ActivatorUtil.CreateInstance(types.RandomElement()) as Mobile;
}
catch
{

View file

@ -692,7 +692,7 @@ namespace Server.Engines.ConPVP
rn -= ae.Value;
}
return arenas[Utility.Random(arenas.Count)].m_Arena;
return arenas.RandomElement().m_Arena;
}
public static Arena FindArena()

View file

@ -284,7 +284,7 @@ namespace Server.Engines.ConPVP
}
case TieType.Random:
{
TourneyParticipant advanced = remaining[Utility.Random(remaining.Count)];
TourneyParticipant advanced = remaining.RandomElement();
for (int i = 0; i < remaining.Count; ++i)
if (remaining[i] != advanced)

View file

@ -131,13 +131,13 @@ namespace Server.Engines.ConPVP
if (toAdvance.Count == 0)
toAdvance = copy; // sanity
int idx = Utility.Random(toAdvance.Count);
var random = toAdvance.RandomElement();
toAdvance[idx].AddLog(
random.AddLog(
"Advanced automatically due to an odd number of challengers.");
level.FreeAdvance = toAdvance[idx];
level.FreeAdvance = random;
++level.FreeAdvance.FreeAdvances;
copy.Remove(toAdvance[idx]);
copy.Remove(random);
}
while (copy.Count >= partsPerMatch)

View file

@ -103,7 +103,7 @@ namespace Server.Engines.Craft
if (m_Recipes.Count == 0)
return -1;
return m_Recipes[Utility.Random(m_Recipes.Count)];
return m_Recipes.RandomElement();
}
public int RandomRareRecipe()
@ -111,7 +111,7 @@ namespace Server.Engines.Craft
if (m_RareRecipes.Count == 0)
return -1;
return m_RareRecipes[Utility.Random(m_RareRecipes.Count)];
return m_RareRecipes.RandomElement();
}
public int AddCraft(Type typeItem, TextDefinition group, TextDefinition name, double minSkill, double maxSkill,

View file

@ -153,7 +153,7 @@ namespace Server.Factions
return;
for (int i = 0; i < distrib; ++i)
activePlayers[Utility.Random(activePlayers.Count)].KillPoints++;
activePlayers.RandomElement().KillPoints++;
}
public static void DistributePoints(int distrib)
@ -167,7 +167,7 @@ namespace Server.Factions
if (activePlayers.Count > 0)
for (int i = 0; i < distrib; ++i)
activePlayers[Utility.Random(activePlayers.Count)].KillPoints++;
activePlayers.RandomElement().KillPoints++;
}
public void BeginHonorLeadership(Mobile from)

View file

@ -224,12 +224,10 @@ namespace Server.Factions
while (Silver + flow < 0 && toDelete.Count > 0)
{
int index = Utility.Random(toDelete.Count);
Mobile mob = toDelete[index];
Mobile mob = toDelete.RandomElement();
mob.Delete();
toDelete.RemoveAt(index);
toDelete.Remove(mob);
flow = NetCashFlow;
}
}

View file

@ -267,8 +267,7 @@ namespace Server.Engines.Harvest
from.Region.GetResource(type);
public virtual Type GetResourceType(Mobile from, Item tool, HarvestDefinition def, Map map, Point3D loc,
HarvestResource resource) =>
resource.Types.Length > 0 ? resource.Types[Utility.Random(resource.Types.Length)] : null;
HarvestResource resource) => resource.Types.RandomElement();
public virtual HarvestResource MutateResource(Mobile from, Item tool, HarvestDefinition def, Map map, Point3D loc,
HarvestVein vein, HarvestResource primary, HarvestResource fallback)

View file

@ -146,7 +146,7 @@ namespace Server.Engines.Harvest
double chance = (skillValue - entry.m_MinSkill) / (entry.m_MaxSkill - entry.m_MinSkill);
if (chance > Utility.RandomDouble())
return entry.m_Types[Utility.Random(entry.m_Types.Length)];
return entry.m_Types.RandomElement();
}
}

View file

@ -263,8 +263,7 @@ namespace Server.Menus.Questions
return;
}
int idx = Utility.Random(m_Destination.Locations.Length);
Point3D dest = m_Destination.Locations[idx];
Point3D dest = m_Destination.Locations.RandomElement();
Map destMap;
if (m_Mobile.Map == Map.Trammel)

View file

@ -234,9 +234,9 @@ namespace Server.Items
for (int i = 0; i < Hints.Length; i++)
{
int pos = Utility.Random(list.Count);
Hints[i] = list[pos];
list.RemoveAt(pos);
var random = list.RandomElement();
Hints[i] = random;
list.Remove(random);
}
}

View file

@ -17,7 +17,7 @@ namespace Server.Engines.MLQuests.Items
protected void AddBaseLoot(params Type[][] lootSets)
{
Item loot = Loot.Construct(lootSets[Utility.Random(lootSets.Length)]);
Item loot = Loot.Construct(lootSets.RandomElement());
if (loot == null)
return;

View file

@ -569,7 +569,7 @@ namespace Server.Engines.MLQuests
m_EligiblePool.Add(quest);
}
return m_EligiblePool.Count == 0 ? fallback : m_EligiblePool[Utility.Random(m_EligiblePool.Count)];
return m_EligiblePool.Count == 0 ? fallback : m_EligiblePool.RandomElement();
}
public static void TurnToFace(IQuestGiver quester, Mobile mob)

View file

@ -127,13 +127,7 @@ namespace Server.Engines.Quests.Collector
public override bool ForceShowProperties => ObjectPropertyList.Enabled;
public static string RandomName(Mobile from)
{
int index = Utility.Random(m_Names.Length);
if (m_Names[index] == null)
return from.Name;
return m_Names[index];
}
public static string RandomName(Mobile from) => m_Names.RandomElement() ?? from.Name;
public override void AddNameProperty(ObjectPropertyList list)
{
@ -256,4 +250,4 @@ namespace Server.Engines.Quests.Collector
}
}
}
}
}

View file

@ -98,9 +98,7 @@ namespace Server.Engines.Quests.Hag
ingredients[n++] = currIngredient;
}
int index = Utility.Random(ingredients.Length);
return ingredients[index];
return ingredients.RandomElement();
}
}
}
}

View file

@ -31,12 +31,7 @@ namespace Server.Engines.Quests.Hag
public Corpse Corpse { get; private set; }
private static Point3D RandomCorpseLocation()
{
int index = Utility.Random(m_CorpseLocations.Length);
return m_CorpseLocations[index];
}
private static Point3D RandomCorpseLocation() => m_CorpseLocations.RandomElement();
public override void CheckProgress()
{

View file

@ -82,11 +82,6 @@ namespace Server.Engines.Quests.Hag
AddConversation(new AcceptConversation());
}
public static Point3D RandomZeefzorpulLocation()
{
int index = Utility.Random(m_ZeefzorpulLocations.Length);
return m_ZeefzorpulLocations[index];
}
public static Point3D RandomZeefzorpulLocation() => m_ZeefzorpulLocations.RandomElement();
}
}
}

View file

@ -628,7 +628,7 @@ namespace Server.Items
private string m_UrnName;
[Constructible]
public AncientUrn() : this(Names[Utility.Random(Names.Length)])
public AncientUrn() : this(Names.RandomElement())
{
}
@ -725,7 +725,7 @@ namespace Server.Items
private string m_SwordsName;
[Constructible]
public HonorableSwords() : this(AncientUrn.Names[Utility.Random(AncientUrn.Names.Length)])
public HonorableSwords() : this(AncientUrn.Names.RandomElement())
{
}
@ -869,7 +869,7 @@ namespace Server.Items
public FluteOfRenewal()
{
Slayer = SlayerGroup.Groups[Utility.Random(SlayerGroup.Groups.Length - 1)].Super
.Name; // -1 to exclude Fey slayer. Try to confrim no fey slayer on this on OSI
.Name; // -1 to exclude Fey slayer. Try to confirm no fey slayer on this on OSI
ReplenishesCharges = true;
}

View file

@ -154,7 +154,7 @@ namespace Server.Misc
try
{
i = ActivatorUtil.CreateInstance(
m_LesserArtifacts[(int)DropEra - 1][Utility.Random(m_LesserArtifacts[(int)DropEra - 1].Length)])
m_LesserArtifacts[(int)DropEra - 1].RandomElement())
as
Item;
}

View file

@ -297,10 +297,10 @@ namespace Server.Engines.Events
{
return target.Map.MapID switch
{
2 => Ilshenar_Locations[Utility.Random(Ilshenar_Locations.Length)],
3 => Malas_Locations[Utility.Random(Malas_Locations.Length)],
4 => Tokuno_Locations[Utility.Random(Tokuno_Locations.Length)],
_ => Felucca_Locations[Utility.Random(Felucca_Locations.Length)]
2 => Ilshenar_Locations.RandomElement(),
3 => Malas_Locations.RandomElement(),
4 => Tokuno_Locations.RandomElement(),
_ => Felucca_Locations.RandomElement()
};
}

View file

@ -55,7 +55,7 @@ namespace Server.Items
private void AssignRandomName()
{
Name = $"{m_Staff[Utility.Random(m_Staff.Length)]}'s Jack-O-Lantern";
Name = $"{m_Staff.RandomElement()}'s Jack-O-Lantern";
}
public override bool OnDragLift(Mobile from)
@ -93,4 +93,4 @@ namespace Server.Items
AssignRandomName();
}
}
}
}

View file

@ -18,13 +18,11 @@ namespace Server.Items.Holiday
private string m_Staffer;
public BasePaintedMask(int itemid)
: this(m_Staffers[Utility.Random(m_Staffers.Length)], itemid)
public BasePaintedMask(int itemid) : this(m_Staffers.RandomElement(), itemid)
{
}
public BasePaintedMask(string staffer, int itemid)
: base(itemid + Utility.Random(2))
public BasePaintedMask(string staffer, int itemid) : base(itemid + Utility.Random(2))
{
m_Staffer = staffer;
@ -56,4 +54,4 @@ namespace Server.Items.Holiday
if (version == 1) m_Staffer = Utility.Intern(reader.ReadString());
}
}
}
}

View file

@ -97,7 +97,7 @@ namespace Server.Engines.Events
{
Map map = Utility.RandomBool() ? Map.Trammel : Map.Felucca;
Point3D home = GetRandomPointInRect(m_Cemetaries[Utility.Random(m_Cemetaries.Length)], map);
Point3D home = GetRandomPointInRect(m_Cemetaries.RandomElement(), map);
if (map.CanSpawnMobile(home))
{

View file

@ -36,8 +36,8 @@ namespace Server.Events.Halloween
public static DateTime FinishHalloween => new DateTime(2012, 11, 15);
public static Item RandomGMBeggerItem =>
(Item)ActivatorUtil.CreateInstance(m_GMBeggarTreats[Utility.Random(m_GMBeggarTreats.Length)]);
(Item)ActivatorUtil.CreateInstance(m_GMBeggarTreats.RandomElement());
public static Item RandomTreat => (Item)ActivatorUtil.CreateInstance(m_Treats[Utility.Random(m_Treats.Length)]);
public static Item RandomTreat => (Item)ActivatorUtil.CreateInstance(m_Treats.RandomElement());
}
}

View file

@ -538,11 +538,9 @@ namespace Server.Items
while (amount > 0 && toKill.Count > 0)
{
int kill = Utility.Random(toKill.Count);
toKill[kill].Kill();
toKill.RemoveAt(kill);
var kill = toKill.RandomElement();
kill.Kill();
toKill.Remove(kill);
amount -= 1;
LiveCreatures = Math.Max(LiveCreatures - 1, 0);
@ -639,7 +637,7 @@ namespace Server.Items
}
if (Utility.RandomDouble() < 0.05)
fish.Hue = FishHues[Utility.Random(FishHues.Length)];
fish.Hue = FishHues.RandomElement();
else if (Utility.RandomDouble() < 0.5)
fish.Hue = Utility.RandomMinMax(0x100, 0x3E5);

View file

@ -287,7 +287,7 @@ namespace Server.Items
}
if (level == 6 && Core.AOS)
cont.DropItem((Item)ActivatorUtil.CreateInstance(Artifacts[Utility.Random(Artifacts.Length)]));
cont.DropItem((Item)ActivatorUtil.CreateInstance(Artifacts.RandomElement()));
}
public override bool CheckLocked(Mobile from)

View file

@ -22,11 +22,10 @@ namespace Server.Engines.Mahjong
public MahjongTileType Next()
{
int random = Utility.Random(LeftTileTypes.Count);
MahjongTileType next = LeftTileTypes[random];
LeftTileTypes.RemoveAt(random);
MahjongTileType next = LeftTileTypes.RandomElement();
LeftTileTypes.Remove(next);
return next;
}
}
}
}

View file

@ -163,10 +163,7 @@ namespace Server.Items
if (m_Locations == null)
LoadLocations();
if (m_Locations.Length > 0)
return m_Locations[Utility.Random(m_Locations.Length)];
return Point2D.Zero;
return m_Locations?.RandomElement() ?? Point2D.Zero;
}
public static Point2D GetRandomHavenLocation()
@ -174,10 +171,7 @@ namespace Server.Items
if (m_HavenLocations == null)
LoadLocations();
if (m_HavenLocations.Length > 0)
return m_HavenLocations[Utility.Random(m_HavenLocations.Length)];
return Point2D.Zero;
return m_HavenLocations?.RandomElement() ?? Point2D.Zero;
}
private static void LoadLocations()
@ -225,8 +219,7 @@ namespace Server.Items
try
{
bc = (BaseCreature)ActivatorUtil.CreateInstance(
m_SpawnTypes[level][Utility.Random(m_SpawnTypes[level].Length)]);
bc = (BaseCreature)ActivatorUtil.CreateInstance(m_SpawnTypes[level].RandomElement());
}
catch
{

View file

@ -153,7 +153,7 @@ namespace Server.Items
{
Map map = Map;
BaseCreature bc =
(BaseCreature)ActivatorUtil.CreateInstance(Creatures[Utility.Random(Creatures.Length)]);
(BaseCreature)ActivatorUtil.CreateInstance(Creatures.RandomElement());
Point3D spawnLoc = GetSpawnPosition();

View file

@ -35,7 +35,7 @@ namespace Server.Items
{
if (m_TurnedOn && IsLockedDown && (!m.Hidden || m.AccessLevel == AccessLevel.Player) &&
Utility.InRange(m.Location, Location, 2) && !Utility.InRange(oldLocation, Location, 2))
Effects.PlaySound(Location, Map, Sounds[Utility.Random(Sounds.Length)]);
Effects.PlaySound(Location, Map, Sounds.RandomElement());
base.OnMovement(m, oldLocation);
}

View file

@ -82,8 +82,7 @@ namespace Server.Items
if (list.Count == 0)
return Point3D.Zero;
int idx = Utility.Random(list.Count);
return list[idx];
return list.RandomElement();
}
private void AddOffsetLocation(Mobile from, int offsetX, int offsetY, List<Point3D> list)

View file

@ -187,7 +187,7 @@ namespace Server.Items
for (int i = 0; i < 50; ++i)
{
Rectangle2D reg = regions[Utility.Random(regions.Length)];
Rectangle2D reg = regions.RandomElement();
int x = Utility.Random(reg.X, reg.Width);
int y = Utility.Random(reg.Y, reg.Height);

View file

@ -204,7 +204,7 @@ namespace Server.Items
maxIntensity = 15;
}
int propertyCount = propertyCounts[Utility.Random(propertyCounts.Length)];
int propertyCount = propertyCounts.RandomElement();
BaseRunicTool.ApplyAttributesTo(this, true, 0, propertyCount, minIntensity, maxIntensity);
}

View file

@ -439,8 +439,8 @@ namespace Server.Items
if (randomizeOrder)
for (int i = 0; i < attrs.Length; i++)
{
int rand = Utility.Random(attrs.Length);
AosElementAttribute temp = attrs[i];
int rand = Utility.Random(attrs.Length);
attrs[i] = attrs[rand];
attrs[rand] = temp;
@ -501,7 +501,7 @@ namespace Server.Items
if (entries.Length == 0)
return SlayerName.None;
entry = entries[Utility.Random(entries.Length)];
entry = entries.RandomElement();
}
return entry.Name;

View file

@ -302,7 +302,7 @@ namespace Server.Items
_ => m_CommonTracks
};
return list[Utility.Random(list.Length)];
return list.RandomElement();
}
}
}

View file

@ -38,7 +38,7 @@
[Constructible]
public HolidayBell()
: this(m_StaffNames[Utility.Random(m_StaffNames.Length)])
: this(m_StaffNames.RandomElement())
{
}
@ -49,7 +49,7 @@
m_Maker = maker;
LootType = LootType.Blessed;
Hue = m_Hues[Utility.Random(m_Hues.Length)];
Hue = m_Hues.RandomElement();
SoundID = 0x0F5 + Utility.Random(14);
}
@ -108,4 +108,4 @@
Utility.Intern(ref m_Maker);
}
}
}
}

View file

@ -136,7 +136,7 @@ namespace Server.Items
public override bool Eat(Mobile from)
{
int message = m_Messages[Utility.Random(m_Messages.Length)];
int message = m_Messages.RandomElement();
if (message != 0)
{

View file

@ -38,8 +38,8 @@
0x448
};
public static int RandomGiftBoxHue => m_NormalHues[Utility.Random(m_NormalHues.Length)];
public static int RandomNeonBoxHue => m_NeonHues[Utility.Random(m_NeonHues.Length)];
public static int RandomGiftBoxHue => m_NormalHues.RandomElement();
public static int RandomNeonBoxHue => m_NeonHues.RandomElement();
}
[Flippable(0x46A5, 0x46A6)]
@ -205,4 +205,4 @@
int version = reader.ReadInt();
}
}
}
}

View file

@ -31,11 +31,12 @@ namespace Server.Items
public class BadCard : Item
{
private static readonly int[] m_CardHues = { 0x45, 0x27, 0x3d0 };
[Constructible]
public BadCard() : base(0x14ef)
{
int[] m_CardHues = { 0x45, 0x27, 0x3d0 };
Hue = m_CardHues[Utility.Random(m_CardHues.Length)];
Hue = m_CardHues.RandomElement();
Stackable = false;
LootType = LootType.Blessed;
Movable = true;

View file

@ -6,7 +6,7 @@
[Constructible]
public SnowPileDeco()
: this(m_Types[Utility.Random(m_Types.Length)])
: this(m_Types.RandomElement())
{
}
@ -37,4 +37,4 @@
int version = reader.ReadInt();
}
}
}
}

View file

@ -55,71 +55,65 @@ namespace Server.Items
return true;
}
public static string GetRandomTitle()
// All hail OSI staff
private static readonly string[] titles =
{
// All hail OSI staff
string[] titles =
{
/* 1 */ "Backflash",
/* 2 */ "Carbon",
/* 3 */ "Colbalistic",
/* 4 */ "Comforl",
/* 5 */ "Coppacchia",
/* 6 */ "Cyrus",
/* 7 */ "DannyB",
/* 8 */ "DJSoul",
/* 9 */ "DraconisRex",
/* 10 */ "Earia",
/* 11 */ "Foster",
/* 12 */ "Gonzo",
/* 13 */ "Haan",
/* 14 */ "Halona",
/* 15 */ "Hugo",
/* 16 */ "Hyacinth",
/* 17 */ "Imirian",
/* 18 */ "Jinsol",
/* 19 */ "Liciatia",
/* 20 */ "Loewen",
/* 21 */ "Loke",
/* 22 */ "Magnus",
/* 23 */ "Maleki",
/* 24 */ "Morpheus",
/* 25 */ "Obberron",
/* 26 */ "Odee",
/* 27 */ "Orbeus",
/* 28 */ "Pax",
/* 29 */ "Phields",
/* 30 */ "Pigpen",
/* 31 */ "Platinum",
/* 32 */ "Polpol",
/* 33 */ "Prume",
/* 34 */ "Quinnly",
/* 35 */ "Ragnarok",
/* 36 */ "Rend",
/* 37 */ "Roland",
/* 38 */ "RyanM",
/* 39 */ "Screach",
/* 40 */ "Seraph",
/* 41 */ "Silvani",
/* 42 */ "Sherbear",
/* 43 */ "SkyWalker",
/* 44 */ "Snark",
/* 45 */ "Sowl",
/* 46 */ "Spada",
/* 47 */ "Starblade",
/* 48 */ "Tenacious",
/* 49 */ "Tnez",
/* 50 */ "Wasia",
/* 51 */ "Zilo",
/* 52 */ "Zippy",
/* 53 */ "Zoer"
};
/* 1 */ "Backflash",
/* 2 */ "Carbon",
/* 3 */ "Colbalistic",
/* 4 */ "Comforl",
/* 5 */ "Coppacchia",
/* 6 */ "Cyrus",
/* 7 */ "DannyB",
/* 8 */ "DJSoul",
/* 9 */ "DraconisRex",
/* 10 */ "Earia",
/* 11 */ "Foster",
/* 12 */ "Gonzo",
/* 13 */ "Haan",
/* 14 */ "Halona",
/* 15 */ "Hugo",
/* 16 */ "Hyacinth",
/* 17 */ "Imirian",
/* 18 */ "Jinsol",
/* 19 */ "Liciatia",
/* 20 */ "Loewen",
/* 21 */ "Loke",
/* 22 */ "Magnus",
/* 23 */ "Maleki",
/* 24 */ "Morpheus",
/* 25 */ "Obberron",
/* 26 */ "Odee",
/* 27 */ "Orbeus",
/* 28 */ "Pax",
/* 29 */ "Phields",
/* 30 */ "Pigpen",
/* 31 */ "Platinum",
/* 32 */ "Polpol",
/* 33 */ "Prume",
/* 34 */ "Quinnly",
/* 35 */ "Ragnarok",
/* 36 */ "Rend",
/* 37 */ "Roland",
/* 38 */ "RyanM",
/* 39 */ "Screach",
/* 40 */ "Seraph",
/* 41 */ "Silvani",
/* 42 */ "Sherbear",
/* 43 */ "SkyWalker",
/* 44 */ "Snark",
/* 45 */ "Sowl",
/* 46 */ "Spada",
/* 47 */ "Starblade",
/* 48 */ "Tenacious",
/* 49 */ "Tnez",
/* 50 */ "Wasia",
/* 51 */ "Zilo",
/* 52 */ "Zippy",
/* 53 */ "Zoer"
};
if (titles.Length > 0)
return titles[Utility.Random(titles.Length)];
return null;
}
public static string GetRandomTitle() => titles.RandomElement();
public override void GetProperties(ObjectPropertyList list)
{

View file

@ -479,9 +479,7 @@ namespace Server.Items
if (m_Region != null && Entries.Count != 0)
{
int winner = Utility.Random(Entries.Count);
m_Winner = Entries[winner].From;
m_Winner = Entries.RandomElement().From;
if (m_Winner != null)
{

View file

@ -200,7 +200,7 @@ namespace Server.Items
int[] sounds = MonsterStatuetteInfo.GetInfo(m_Type).Sounds;
if (sounds.Length > 0)
Effects.PlaySound(Location, Map, sounds[Utility.Random(sounds.Length)]);
Effects.PlaySound(Location, Map, sounds.RandomElement());
}
base.OnMovement(m, oldLocation);

View file

@ -83,7 +83,7 @@ namespace Server.Items
organ = random switch
{
0 => (PlagueBeastOrgan)new PlagueBeastRockOrgan(),
0 => new PlagueBeastRockOrgan(),
1 => new PlagueBeastMaidenOrgan(),
2 => new PlagueBeastRubbleOrgan(),
_ => new PlagueBeastRockOrgan()
@ -99,10 +99,9 @@ namespace Server.Items
for (int i = 0; i < m_BrainHues.Length; i++)
{
int random = Utility.Random(organs.Count);
organ = organs[random];
organ = organs.RandomElement();
organ.BrainHue = m_BrainHues[i];
organs.RemoveAt(random);
organs.Remove(organ);
}
organs.Clear();
@ -174,4 +173,4 @@ namespace Server.Items
int version = reader.ReadEncodedInt();
}
}
}
}

View file

@ -135,7 +135,7 @@ namespace Server.Items
min /= 5;
max /= 5;
return new PowerScroll(Skills[Utility.Random(Skills.Count)], 100 + Utility.RandomMinMax(min, max) * 5);
return new PowerScroll(Skills.RandomElement(), 100 + Utility.RandomMinMax(min, max) * 5);
}
public static PowerScroll CreateRandomNoCraft(int min, int max)
@ -147,7 +147,7 @@ namespace Server.Items
do
{
skillName = Skills[Utility.Random(Skills.Count)];
skillName = Skills.RandomElement();
} while (skillName == SkillName.Blacksmith || skillName == SkillName.Tailoring);
return new PowerScroll(skillName, 100 + Utility.RandomMinMax(min, max) * 5);

View file

@ -30,12 +30,8 @@ namespace Server.Items
public override string DefaultTitle =>
$"<basefont color=#FFFFFF>Scroll of Transcendence ({Value} Skill):</basefont>";
public static ScrollofTranscendence CreateRandom(int min, int max)
{
SkillName skill = (SkillName)Utility.Random(SkillInfo.Table.Length);
return new ScrollofTranscendence(skill, Utility.RandomMinMax(min, max) * 0.1);
}
public static ScrollofTranscendence CreateRandom(int min, int max) =>
new ScrollofTranscendence(Utility.RandomSkill(), Utility.RandomMinMax(min, max) * 0.1);
public override void GetProperties(ObjectPropertyList list)
{

View file

@ -955,7 +955,7 @@ namespace Server.Items
1023817 // clean bandage
};
public static Type GetRandomSummonType() => m_Summons[Utility.Random(m_Summons.Length)];
public static Type GetRandomSummonType() => m_Summons.RandomElement();
public static TalismanAttribute GetRandomSummoner()
{
@ -1049,7 +1049,7 @@ namespace Server.Items
SkillName.Tinkering
};
public static SkillName GetRandomSkill() => m_Skills[Utility.Random(m_Skills.Length)];
public static SkillName GetRandomSkill() => m_Skills.RandomElement();
public static int GetRandomExceptional()
{

View file

@ -17,8 +17,7 @@ namespace Server.Items
{
ItemID = 0x13B1;
Hue = 0x48F;
SkillBonuses.SetValues(0, m_PossibleBonusSkills[Utility.Random(m_PossibleBonusSkills.Length)],
Utility.Random(4) == 0 ? 10.0 : 5.0);
SkillBonuses.SetValues(0, m_PossibleBonusSkills.RandomElement(), Utility.Random(4) == 0 ? 10.0 : 5.0);
WeaponAttributes.SelfRepair = 5;
Attributes.WeaponSpeed = 50;
Attributes.WeaponDamage = 35;
@ -49,8 +48,7 @@ namespace Server.Items
int version = reader.ReadInt();
if (version < 1)
SkillBonuses.SetValues(0, m_PossibleBonusSkills[Utility.Random(m_PossibleBonusSkills.Length)],
Utility.Random(4) == 0 ? 10.0 : 5.0);
SkillBonuses.SetValues(0, m_PossibleBonusSkills.RandomElement(), Utility.Random(4) == 0 ? 10.0 : 5.0);
}
}
}
}

View file

@ -201,10 +201,7 @@ namespace Server.Items
{
int index = Utility.Random(1 + group.Entries.Length);
if (index == 0)
return group.Super.Name;
return group.Entries[index - 1].Name;
return index == 0 ? group.Super.Name : group.Entries[index - 1].Name;
}
}

View file

@ -1102,7 +1102,7 @@ namespace Server.Misc
int[] hues = { 0x1A8, 0xEC, 0x99, 0x90, 0xB5, 0x336, 0x89 };
// TODO: Verify that's ALL the hues for that above.
EquipItem(new TattsukeHakama(hues[Utility.Random(hues.Length)]));
EquipItem(new TattsukeHakama(hues.RandomElement()));
EquipItem(new HakamaShita(0x2C3));
EquipItem(new NinjaTabi(0x2C3));

View file

@ -26,7 +26,7 @@ namespace Server.Items
[Constructible]
public LightOfTheWinterSolstice(string dipper = null) : base(0x236E)
{
Dipper = dipper ?? m_StaffNames[Utility.Random(m_StaffNames.Length)];
Dipper = dipper ?? m_StaffNames.RandomElement();
Weight = 1.0;
LootType = LootType.Blessed;
@ -81,7 +81,7 @@ namespace Server.Items
}
case 0:
{
Dipper = m_StaffNames[Utility.Random(m_StaffNames.Length)];
Dipper = m_StaffNames.RandomElement();
break;
}
}

View file

@ -134,7 +134,7 @@ namespace Server.Guilds
public void CalculateAllianceLeader()
{
m_Leader = m_Members.Count >= 2 ? m_Members[Utility.Random(m_Members.Count)] : null;
m_Leader = m_Members.Count >= 2 ? m_Members.RandomElement() : null;
}
public void CheckLeader()

View file

@ -300,7 +300,7 @@ namespace Server.Misc
public IHSFlags Flags { get; set; }
public string GetRandomSyllable() => Syllables[Utility.Random(Syllables.Length)];
public string GetRandomSyllable() => Syllables.RandomElement();
public string ConstructWord(int syllableCount)
{
@ -367,17 +367,14 @@ namespace Server.Misc
public void SayRandomTranslate(Mobile mob, params string[] sentancesInEnglish)
{
SaySentance(mob, Utility.RandomMinMax(2, 3));
mob.Say(sentancesInEnglish[Utility.Random(sentancesInEnglish.Length)]);
mob.Say(sentancesInEnglish.RandomElement());
}
private string GetRandomResponseWord(List<string> keywordsFound)
{
int random = Utility.Random(keywordsFound.Count + Responses.Length);
if (random < keywordsFound.Count)
return keywordsFound[random];
return Responses[random - keywordsFound.Count];
return random < keywordsFound.Count ? keywordsFound[random] : Responses[random - keywordsFound.Count];
}
public bool OnSpeech(Mobile mob, Mobile speaker, string text)
@ -411,7 +408,7 @@ namespace Server.Misc
if (Utility.RandomBool())
responseWord = GetRandomResponseWord(keywordsFound);
else
responseWord = keywordsFound[Utility.Random(keywordsFound.Count)];
responseWord = keywordsFound.RandomElement();
string secondResponseWord = GetRandomResponseWord(keywordsFound);

View file

@ -539,13 +539,7 @@ namespace Server
public static Item RandomNecromancyReagent() => Construct(NecroRegTypes);
public static Item RandomPossibleReagent()
{
if (Core.AOS)
return Construct(RegTypes, NecroRegTypes);
return Construct(RegTypes);
}
public static Item RandomPossibleReagent() => Core.AOS ? Construct(RegTypes, NecroRegTypes) : Construct(RegTypes);
public static Item RandomPotion() => Construct(PotionTypes);
@ -621,6 +615,8 @@ namespace Server
public static Item Construct(Type type)
{
if (type == null) return null;
try
{
return ActivatorUtil.CreateInstance(type) as Item;
@ -631,13 +627,7 @@ namespace Server
}
}
public static Item Construct(Type[] types)
{
if (types.Length > 0)
return Construct(types, Utility.Random(types.Length));
return null;
}
public static Item Construct(Type[] types) => Construct(types.RandomElement());
public static Item Construct(Type[] types, int index)
{

View file

@ -27,7 +27,7 @@ namespace Server
public static void GiveArtifactTo(Mobile m)
{
if (!(ActivatorUtil.CreateInstance(Artifacts[Utility.Random(Artifacts.Length)]) is Item item))
if (!(ActivatorUtil.CreateInstance(Artifacts.RandomElement()) is Item item))
return;
if (m.AddToBackpack(item))

View file

@ -23,7 +23,7 @@ namespace Server
return false;
}
public string GetRandomName() => List.Length > 0 ? List[Utility.Random(List.Length)] : "";
public string GetRandomName() => List.RandomElement() ?? "";
public static NameList GetNameList(string type)
{

View file

@ -184,7 +184,7 @@ namespace Server.Misc
return m_SkinHues[0];
}
public override int RandomSkinHue() => m_SkinHues[Utility.Random(m_SkinHues.Length)] | 0x8000;
public override int RandomSkinHue() => m_SkinHues.RandomElement() | 0x8000;
public override int ClipHairHue(int hue)
{
@ -195,7 +195,7 @@ namespace Server.Misc
return m_HairHues[0];
}
public override int RandomHairHue() => m_HairHues[Utility.Random(m_HairHues.Length)];
public override int RandomHairHue() => m_HairHues.RandomElement();
}
private class Gargoyle : Race
@ -258,7 +258,7 @@ namespace Server.Misc
public override int ClipSkinHue(int hue) => hue;
public override int RandomSkinHue() => m_BodyHues[Utility.Random(m_BodyHues.Length)] | 0x8000;
public override int RandomSkinHue() => m_BodyHues.RandomElement() | 0x8000;
public override int ClipHairHue(int hue)
{
@ -269,7 +269,7 @@ namespace Server.Misc
return m_HornHues[0];
}
public override int RandomHairHue() => m_HornHues[Utility.Random(m_HornHues.Length)];
public override int RandomHairHue() => m_HornHues.RandomElement();
}
}
}

View file

@ -2108,20 +2108,14 @@ namespace Server.Mobiles
public Spell GetAttackSpellRandom()
{
if (m_SpellAttack.Count == 0)
return null;
Type type = m_SpellAttack[Utility.Random(m_SpellAttack.Count)];
return ActivatorUtil.CreateInstance(type, this, null) as Spell;
Type type = m_SpellAttack.RandomElement();
return type == null ? null : ActivatorUtil.CreateInstance(type, this, null) as Spell;
}
public Spell GetDefenseSpellRandom()
{
if (m_SpellDefense.Count == 0)
return null;
Type type = m_SpellDefense[Utility.Random(m_SpellDefense.Count)];
return ActivatorUtil.CreateInstance(type, this, null) as Spell;
Type type = m_SpellDefense.RandomElement();
return type == null ? null : ActivatorUtil.CreateInstance(type, this, null) as Spell;
}
public Spell GetSpellSpecific(Type type)
@ -2853,7 +2847,7 @@ namespace Server.Mobiles
for (int i = 0; i < items.Count; ++i)
{
Item item = items[Utility.Random(items.Count)];
Item item = items.RandomElement();
Lift(item, item.Amount, out bool rejected, out LRReason _);

View file

@ -143,10 +143,7 @@ namespace Server.Mobiles
rights.RemoveAt(i);
}
if (rights.Count > 0)
return rights[Utility.Random(rights.Count)].m_Mobile;
return null;
return rights.RandomElement()?.m_Mobile;
}
public static void DistributeArtifact(BaseCreature creature)

View file

@ -84,7 +84,7 @@ namespace Server.Mobiles
"{0}!! You will pay for that!"
};
Say(true, string.Format(toSay[Utility.Random(toSay.Length)], from.Name));
Say(true, string.Format(toSay.RandomElement(), from.Name));
}
base.OnDamage(amount, from, willKill);

View file

@ -74,7 +74,7 @@ namespace Server.Mobiles
if (to != null)
QuestSystem.FocusTo(this, to);
Say(m_Vocabulary[Utility.Random(m_Vocabulary.Length)]);
Say(m_Vocabulary.RandomElement());
if (to != null && Utility.RandomBool())
Timer.DelayCall(TimeSpan.FromSeconds(Utility.RandomMinMax(5, 8)), to.Talk);

View file

@ -79,9 +79,9 @@ namespace Server.Mobiles
while (spiritsOrVortexes.Count > 6)
{
int index = Utility.Random(spiritsOrVortexes.Count);
Dispel(spiritsOrVortexes[index]);
spiritsOrVortexes.RemoveAt(index);
var random = spiritsOrVortexes.RandomElement();
Dispel(random);
spiritsOrVortexes.Remove(random);
}
}

View file

@ -86,9 +86,9 @@ namespace Server.Mobiles
while (spiritsOrVortexes.Count > 6)
{
int index = Utility.Random(spiritsOrVortexes.Count);
Dispel(spiritsOrVortexes[index]);
spiritsOrVortexes.RemoveAt(index);
var random = spiritsOrVortexes.RandomElement();
Dispel(random);
spiritsOrVortexes.Remove(random);
}
}

View file

@ -12,7 +12,7 @@ namespace Server.Mobiles
[Constructible]
public OphidianArchmage() : base(AIType.AI_Mage, FightMode.Closest, 10, 1, 0.2, 0.4)
{
Name = m_Names[Utility.Random(m_Names.Length)];
Name = m_Names.RandomElement();
Body = 85;
BaseSoundID = 639;
@ -76,4 +76,4 @@ namespace Server.Mobiles
int version = reader.ReadInt();
}
}
}
}

View file

@ -12,7 +12,7 @@ namespace Server.Mobiles
[Constructible]
public OphidianMage() : base(AIType.AI_Mage, FightMode.Closest, 10, 1, 0.2, 0.4)
{
Name = m_Names[Utility.Random(m_Names.Length)];
Name = m_Names.RandomElement();
Body = 85;
BaseSoundID = 639;
@ -77,4 +77,4 @@ namespace Server.Mobiles
int version = reader.ReadInt();
}
}
}
}

View file

@ -14,7 +14,7 @@ namespace Server.Mobiles
[Constructible]
public OphidianKnight() : base(AIType.AI_Melee, FightMode.Closest, 10, 1, 0.2, 0.4)
{
Name = m_Names[Utility.Random(m_Names.Length)];
Name = m_Names.RandomElement();
Body = 86;
BaseSoundID = 634;
@ -79,4 +79,4 @@ namespace Server.Mobiles
int version = reader.ReadInt();
}
}
}
}

View file

@ -11,7 +11,7 @@ namespace Server.Mobiles
[Constructible]
public OphidianWarrior() : base(AIType.AI_Melee, FightMode.Closest, 10, 1, 0.2, 0.4)
{
Name = m_Names[Utility.Random(m_Names.Length)];
Name = m_Names.RandomElement();
Body = 86;
BaseSoundID = 634;
@ -72,4 +72,4 @@ namespace Server.Mobiles
int version = reader.ReadInt();
}
}
}
}

View file

@ -59,15 +59,13 @@ namespace Server.Mobiles
if (list.Length == 0)
return null;
int random = Utility.Random(list.Length);
Type type = list[random];
Type type = list.RandomElement();
Item artifact = Loot.Construct(type);
if (artifact is MonsterStatuette statuette && StatueTypes.Length > 0)
if (StatueTypes.Length > 0 && artifact is MonsterStatuette statuette)
{
statuette.Type = StatueTypes[Utility.Random(StatueTypes.Length)];
statuette.Type = StatueTypes.RandomElement();
statuette.LootType = LootType.Regular;
}
@ -249,7 +247,7 @@ namespace Server.Mobiles
}
if (toGive.Count > 0)
toGive[Utility.Random(toGive.Count)].AddToBackpack(new ChampionSkull(SkullType));
toGive.RandomElement().AddToBackpack(new ChampionSkull(SkullType));
else
c.DropItem(new ChampionSkull(SkullType));
}

View file

@ -116,7 +116,7 @@ namespace Server.Mobiles
if (Instances.Count > 0)
return null;
SpawnEntry entry = m_Entries[Utility.Random(m_Entries.Length)];
SpawnEntry entry = m_Entries.RandomElement();
Harrower harrower = new Harrower();
@ -454,17 +454,7 @@ namespace Server.Mobiles
return null;
}
public Item CreateArtifact(Type[] list)
{
if (list.Length == 0)
return null;
int random = Utility.Random(list.Length);
Type type = list[random];
return Loot.Construct(type);
}
public Item CreateArtifact(Type[] list) => Loot.Construct(list.RandomElement());
private class SpawnEntry
{

View file

@ -180,7 +180,7 @@ namespace Server.Mobiles
public static void GiveArtifactTo(Mobile m)
{
Item item = (Item)ActivatorUtil.CreateInstance(Artifacts[Utility.Random(Artifacts.Length)]);
Item item = (Item)ActivatorUtil.CreateInstance(Artifacts.RandomElement());
if (m.AddToBackpack(item))
m.SendMessage("As a reward for slaying the mighty paragon, an artifact has been placed in your backpack.");

View file

@ -586,7 +586,7 @@ namespace Server.Mobiles
while (picked == null)
{
picked = possible[Utility.Random(possible.Length)];
picked = possible.RandomElement();
EDI test = EDI.Find(picked);
if (test.Contains(Location))

View file

@ -42,10 +42,7 @@ namespace Server.Mobiles
RemoveEntry(tce);
}
if (Entries == null || Entries.Count == 0)
return null;
return Entries[Utility.Random(Entries.Count)];
return Entries.RandomElement();
}
public TownCrierEntry AddEntry(string[] lines, TimeSpan duration)
@ -372,10 +369,7 @@ namespace Server.Mobiles
TownCrierEntry entry = GlobalTownCrierEntryList.Instance.GetRandomEntry();
if (entry == null || Utility.RandomBool())
entry = Entries[Utility.Random(Entries.Count)];
return entry;
return entry ?? (Utility.RandomBool() ? Entries.RandomElement() : null);
}
public TownCrierEntry AddEntry(string[] lines, TimeSpan duration)

View file

@ -324,10 +324,8 @@ namespace Server.SkillHandlers
if (pack?.Items.Count > 0)
{
int randomIndex = Utility.Random(pack.Items.Count);
root = mobile;
stolen = TryStealItem(pack.Items[randomIndex], ref caught);
stolen = TryStealItem(pack.Items.RandomElement(), ref caught);
}
}
else

View file

@ -63,7 +63,7 @@ namespace Server.Misc
private static bool HasDisconnected(Mobile m) => m.NetState?.Connection == null;
private static LocationInfo GetRandomDestination() => m_Destinations[Utility.Random(m_Destinations.Length)];
private static LocationInfo GetRandomDestination() => m_Destinations.RandomElement();
private class LocationInfo
{

View file

@ -32,7 +32,7 @@ namespace Server.Spells.Bushido
if (!CheckMana(attacker, true))
return;
Mobile target = targets[Utility.Random(targets.Count)];
Mobile target = targets.RandomElement();
double damageBonus = attacker.Skills.Bushido.Value / 100.0;

View file

@ -63,7 +63,7 @@ namespace Server.Spells.Fifth
if (CheckSequence())
try
{
BaseCreature creature = (BaseCreature)ActivatorUtil.CreateInstance(m_Types[Utility.Random(m_Types.Length)]);
BaseCreature creature = (BaseCreature)ActivatorUtil.CreateInstance(m_Types.RandomElement());
// creature.ControlSlots = 2;

View file

@ -38,7 +38,7 @@ namespace Server.Spells.First
{
if (CheckSequence())
{
FoodInfo foodInfo = m_Food[Utility.Random(m_Food.Length)];
FoodInfo foodInfo = m_Food.RandomElement();
Item food = foodInfo.Create();
if (food != null)

View file

@ -277,7 +277,7 @@ namespace Server.Spells.Necromancy
Type[] animates = entry.m_ToSummon;
toSummon = animates[Utility.Random(animates.Length)];
toSummon = animates.RandomElement();
}
if (toSummon == null)