Optimize random

This commit is contained in:
Stepan Goremykin 2023-01-29 02:42:08 +01:00
parent 4fd52bc31f
commit 2367f93daf
3 changed files with 13 additions and 6 deletions

View File

@ -102,7 +102,9 @@ namespace DiIiS_NA.Core.MPQ.FileFormats
{ {
return AnimationSno._NONE; return AnimationSno._NONE;
} }
return deathTags.Select(x => GetAniSNO(x)).Where(x => x != AnimationSno._NONE).OrderBy(x => RandomHelper.Next()).First();
var possibleDeaths = deathTags.Select(GetAniSNO).Where(x => x != AnimationSno._NONE);
return RandomHelper.RandomItem(possibleDeaths);
} }
} }
public enum AnimationTags public enum AnimationTags

View File

@ -250,14 +250,18 @@ namespace DiIiS_NA.GameServer.GSSystem.GeneratorsSystem
public static int GeneratePrefixName() public static int GeneratePrefixName()
{ {
var randomPrefix = NamesList.Where(n => n.AffixType == AffixType.Prefix).OrderBy(x => RandomHelper.Next()).ToList().First(); var prefixes = NamesList.Where(n => n.AffixType == AffixType.Prefix);
var randomPrefix = RandomHelper.RandomItem(prefixes);
return randomPrefix.Hash; return randomPrefix.Hash;
} }
public static int GenerateSuffixName() public static int GenerateSuffixName()
{ {
var randomSuffix = NamesList.Where(n => n.AffixType == AffixType.Suffix).OrderBy(x => RandomHelper.Next()).ToList().First(); var prefixes = NamesList.Where(n => n.AffixType == AffixType.Suffix);
return randomSuffix.Hash; var randomPrefix = RandomHelper.RandomItem(prefixes);
return randomPrefix.Hash;
} }
} }
} }

View File

@ -4493,8 +4493,9 @@ namespace DiIiS_NA.GameServer.GSSystem.PowerSystem.Implementations
if (projectile.GetMonstersInRange(15f).Count > 0) if (projectile.GetMonstersInRange(15f).Count > 0)
{ {
Founded = true; Founded = true;
var Target = projectile.GetMonstersInRange(25f).OrderBy(x => Guid.NewGuid()).Take(1).Single(); var possibleTargets = projectile.GetMonstersInRange(25f);
projectile.Launch(Target.Position, 1f); var target = RandomHelper.RandomItem(possibleTargets);
projectile.Launch(target.Position, 1f);
} }
}; };
yield break; yield break;