Updates rest of the random list (#197)

This commit is contained in:
Kamron Batman 2020-08-22 00:23:51 -07:00 • committed by GitHub
parent 4403d6c1c7
commit 8caf5a422f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
18 changed files with 116 additions and 79 deletions

View file

@ -1,5 +1,4 @@
using System;
using System.Linq;
using Server.Mobiles;
namespace Server.Engines.Quests.Collector
@ -56,8 +55,6 @@ namespace Server.Engines.Quests.Collector
new ImageTypeInfo(9746, typeof(Juggernaut), 55, 38)
};
private static ImageType[] m_ImageTypeList;
public ImageTypeInfo(int figurine, Type type, int x, int y)
{
Figurine = figurine;
@ -66,6 +63,8 @@ namespace Server.Engines.Quests.Collector
Y = y;
}
public ImageType Image { get; }
public int Figurine { get; }
public Type Type { get; }
@ -82,16 +81,21 @@ namespace Server.Engines.Quests.Collector
public static ImageType[] RandomList(int count)
{
if (m_ImageTypeList == null)
{
m_ImageTypeList = new ImageType[m_Table.Length];
for (int i = 0; i < m_Table.Length; i++)
m_ImageTypeList[i] = (ImageType)i;
}
if (count <= 0) return Array.Empty<ImageType>();
ImageType[] array = m_ImageTypeList.ToArray();
Utility.Shuffle(array);
return array.Take(count).ToArray();
var length = m_Table.Length;
Span<bool> list = stackalloc bool[length];
var imageTypes = new ImageType[count];
int i = 0;
do
{
var rand = Utility.Random(length);
if (!(list[rand] && (list[rand] = true)))
imageTypes[i++] = (ImageType)rand;
} while (i < count);
return imageTypes;
}
}
}
}

View file

@ -13,7 +13,7 @@ namespace Server.Engines.Quests.Ninja
};
[Constructible]
public HiddenFigure() => Message = Utility.RandomList(Messages);
public HiddenFigure() => Message = Messages.RandomElement();
public HiddenFigure(Serial serial) : base(serial)
{
@ -83,4 +83,4 @@ namespace Server.Engines.Quests.Ninja
Message = reader.ReadInt();
}
}
}
}