Creates random element extension (#196)
This commit is contained in:
parent
0926b5abaa
commit
4403d6c1c7
84 changed files with 226 additions and 330 deletions
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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
|
||||
{
|
||||
|
|
|
|||
|
|
@ -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()
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -98,9 +98,7 @@ namespace Server.Engines.Quests.Hag
|
|||
ingredients[n++] = currIngredient;
|
||||
}
|
||||
|
||||
int index = Utility.Random(ingredients.Length);
|
||||
|
||||
return ingredients[index];
|
||||
return ingredients.RandomElement();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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()
|
||||
{
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue