Merge pull request #112 from goremykin/optimizations

Refactor random and more multiple enumerations
This commit is contained in:
Lucca Faria Ferri 2023-01-29 14:22:37 -03:00 committed by GitHub
commit 68a512cae6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
51 changed files with 453 additions and 413 deletions

View File

@ -85,7 +85,7 @@ namespace DiIiS_NA.LoginServer.AccountsSystem
public static Account GetAccountByDiscordId(ulong discordId)
{
List<DBAccount> dbAcc = DBSessions.SessionQueryWhere<DBAccount>(dba => dba.DiscordId == discordId).ToList();
if (dbAcc.Count() == 0)
if (!dbAcc.Any())
{
Logger.Warn("GetAccountByDiscordId {0}: DBAccount is null!", discordId);
return null;

View File

@ -1197,7 +1197,7 @@ public class GameAccount : PersistentRPCObject
public uint AchievementPoints
{
get { return (uint)Achievements.Where(a => a.Completion != -1).Count() * 10U; }
get { return (uint)Achievements.Count(a => a.Completion != -1) * 10U; }
}
public bool IsLoggedIn { get; set; }

View File

@ -14,10 +14,7 @@ namespace DiIiS_NA.LoginServer.AccountsSystem
public static readonly ConcurrentDictionary<ulong, GameAccount> LoadedGameAccounts = new();
public static int TotalAccounts
{
get { return DBSessions.SessionQuery<DBGameAccount>().Count(); }
}
public static int TotalAccounts => DBSessions.SessionQuery<DBGameAccount>().Count;
public static void PreLoadGameAccounts()
{

View File

@ -70,7 +70,7 @@ namespace DiIiS_NA.LoginServer.FriendsSystem
Logger.MethodTrace($": owner {owner.PersistentID}, target {target.PersistentID}");
try
{
if (DBSessions.SessionQueryWhere<DBAccountLists>(dbl => dbl.ListOwner.Id == owner.PersistentID && dbl.ListTarget.Id == target.PersistentID && dbl.Type == "IGNORE").Count() > 0) return;
if (DBSessions.SessionQueryWhere<DBAccountLists>(dbl => dbl.ListOwner.Id == owner.PersistentID && dbl.ListTarget.Id == target.PersistentID && dbl.Type == "IGNORE").Any()) return;
var blockRecord = new DBAccountLists
{

View File

@ -7,6 +7,7 @@ using DiIiS_NA.LoginServer.ChannelSystem;
using System;
using System.Collections.Generic;
using System.Linq;
using DiIiS_NA.Core.Extensions;
namespace DiIiS_NA.LoginServer.GamesSystem
{
@ -19,7 +20,7 @@ namespace DiIiS_NA.LoginServer.GamesSystem
{
get
{
return GameCreators.Values.Where(game => game.PlayersCount > 0).Count();
return GameCreators.Values.Count(game => game.PlayersCount > 0);
}
set { }
}
@ -95,13 +96,12 @@ namespace DiIiS_NA.LoginServer.GamesSystem
GameDescriptor TagGame = null;
if (client.GameTeamTag != "") TagGame = FindTagGame(client.GameTeamTag);
var rand = new Random();
GameDescriptor gameDescriptor = null;
if(TagGame != null)
gameDescriptor = TagGame;
else if (request_type == "find" && matchingGames.Count > 0)
gameDescriptor = matchingGames[rand.Next(matchingGames.Count)];
gameDescriptor = matchingGames.PickRandom();
else
gameDescriptor = CreateGame(client, request.Options, requestId);

View File

@ -224,10 +224,11 @@ namespace DiIiS_NA.Core.Discord
{
var message = await guild.GetTextChannel(channelId).GetMessageAsync(param.First().Value);
var reactedUsers = await (message as IUserMessage).GetReactionUsersAsync(Emote.Parse("<:wolfRNG:607868292979490816>"), 100).FlattenAsync();
var contestants = reactedUsers.Where(u => !u.IsBot).ToList();
if (contestants.Count() > 0)
var contestants = reactedUsers.Where(u => !u.IsBot).ToArray();
if (contestants.Length > 0)
{
var winner = reactedUsers.Where(u => !u.IsBot).ToList()[DiIiS_NA.Core.Helpers.Math.FastRandom.Instance.Next(0, reactedUsers.Count() - 1)];
var winner = contestants[Helpers.Math.FastRandom.Instance.Next(0, contestants.Length - 1)];
winnerName = guild.GetUser(winner.Id).Nickname;
await winner.SendMessageAsync("Congratulations! You have won **7 days of D3 Reflection Premium**!.\nYour account has already had its Premium prolonged. Have a nice game!");
var acc = AccountManager.GetAccountByDiscordId(winner.Id);

View File

@ -33,11 +33,11 @@ namespace DiIiS_NA.Core.Discord.Modules
}
if (registerInfo.Count() == 3)
if (registerInfo.Length == 3)
{
if (!email.Contains('@'))
{
await ReplyAsync($"<@{Context.User.Id}> " + string.Format("'{0}' is not a valid email address.", email));
await ReplyAsync($"<@{Context.User.Id}> " + $"'{email}' is not a valid email address.");
return;
}
if (!IsValid(email))

View File

@ -1,11 +1,11 @@
//Blizzless Project 2022
using System;
using System;
using System.Collections.Generic;
using System.Text;
using System.Linq;
using DiIiS_NA.Core.Helpers.Math;
namespace DiIiS_NA.Core.Extensions;
namespace DiIiS_NA.Core.Extensions
{
public static class EnumerableExtensions
{
public static string HexDump(this IEnumerable<byte> collection)
@ -44,7 +44,7 @@ namespace DiIiS_NA.Core.Extensions
}
hex.Append(value.ToString("X2"));
hex.Append(' ');
text.Append(string.Format("{0}", (char.IsWhiteSpace((char)value) && (char)value != ' ') ? '.' : (char)value)); // prettify text
text.Append($"{((char.IsWhiteSpace((char)value) && (char)value != ' ') ? '.' : (char)value)}"); // prettify text
++i;
}
var hexstring = hex.ToString();
@ -57,5 +57,14 @@ namespace DiIiS_NA.Core.Extensions
output.Append(text);
return output.ToString();
}
public static TItem PickRandom<TItem>(this IEnumerable<TItem> source)
{
return RandomHelper.RandomItem(source);
}
public static bool TryPickRandom<TItem>(this IEnumerable<TItem> source, out TItem randomItem)
{
return RandomHelper.TryGetRandomItem(source, out randomItem);
}
}

View File

@ -1,107 +1,118 @@
//Blizzless Project 2022
using System;
using System;
using System.Linq;
using System.Collections.Generic;
using DiIiS_NA.Core.Logging;
namespace DiIiS_NA.Core.Helpers.Math
{
public class RandomHelper
{
private readonly static Random _random;
namespace DiIiS_NA.Core.Helpers.Math;
static RandomHelper()
public static class RandomHelper
{
_random = new Random();
}
private static readonly Random Random = new();
public static int Next()
{
return _random.Next();
return Random.Next();
}
public static int Next(Int32 maxValue)
public static int Next(int maxValue)
{
return _random.Next(maxValue);
return Random.Next(maxValue);
}
public static int Next(Int32 minValue, Int32 maxValue)
public static int Next(int minValue, int maxValue)
{
return _random.Next(minValue, maxValue);
return Random.Next(minValue, maxValue);
}
public static void NextBytes(byte[] buffer)
{
_random.NextBytes(buffer);
Random.NextBytes(buffer);
}
public static double NextDouble()
{
return _random.NextDouble();
return Random.NextDouble();
}
/*IEnumerable<TValue>*/
public static TValue RandomValue<TKey, TValue>(IDictionary<TKey, TValue> dictionary)
public static T RandomItem<T>(IEnumerable<T> source)
{
List<TValue> values = Enumerable.ToList(dictionary.Values);
int size = dictionary.Count;
/*while (true)
var collection = source as IReadOnlyCollection<T> ?? source?.ToArray();
if (collection == null || collection.Count == 0)
{
yield return values[_random.Next(size)];
}*/
return values[_random.Next(size)];
throw new ArgumentException("Cannot be null or empty", nameof(source));
}
var randomIndex = Next(collection.Count);
return collection.ElementAt(randomIndex);
}
public static bool TryGetRandomItem<T>(IEnumerable<T> source, out T randomItem)
{
var collection = source as IReadOnlyCollection<T> ?? source?.ToArray();
if (collection == null)
{
throw new ArgumentException("Cannot be null", nameof(source));
}
if (collection.Count == 0)
{
randomItem = default;
return false;
}
var randomIndex = Next(collection.Count);
randomItem = collection.ElementAt(randomIndex);
return true;
}
/// <summary>
/// Picks a random item from a list
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="list"></param>
/// <param name="source"></param>
/// <param name="probability">A function that assigns each item a probability. If the probabilities dont sum up to 1, they are normalized</param>
/// <returns></returns>
public static T RandomItem<T>(IEnumerable<T> list, Func<T, float> probability)
public static T RandomItem<T>(IEnumerable<T> source, Func<T, float> probability)
{
int cumulative = (int)list.Select(x => probability(x)).Sum();
var collection = source as IReadOnlyCollection<T> ?? source.ToArray();
int cumulative = (int)collection.Select(probability).Sum();
int randomRoll = RandomHelper.Next(cumulative);
int randomRoll = Next(cumulative);
float cumulativePercentages = 0;
foreach (T element in list)
foreach (T element in collection)
{
cumulativePercentages += probability(element);
if (cumulativePercentages > randomRoll)
return element;
}
return list.First();
return collection.First();
}
}
public class ItemRandomHelper
{
private static readonly Logger Logger = LogManager.CreateLogger("RH");
uint a;
uint b;
uint _a;
uint _b;
public ItemRandomHelper(int seed)
{
a = (uint)seed;
b = 666;
_a = (uint)seed;
_b = 666;
}
public void ReinitSeed()
{
b = 666;
_b = 666;
}
public uint Next()
{
ulong temp = 1791398085UL * (ulong)a + (ulong)b;
a = (uint)temp;
b = (uint)(temp >> 32);
ulong temp = 1791398085UL * _a + _b;
_a = (uint)temp;
_b = (uint)(temp >> 32);
//Logger.MethodTrace("a {0}, b {1}", a, b);
return (uint)a;
return _a;
}
public float Next(float min, float max)
@ -109,4 +120,3 @@ namespace DiIiS_NA.Core.Helpers.Math
return min + (Next() % (uint)(max - min + 1));
}
}
}

View File

@ -7,6 +7,7 @@ using DiIiS_NA.Core.MPQ.FileFormats.Types;
using DiIiS_NA.GameServer.Core.Types.TagMap;
using System.Linq;
using System;
using DiIiS_NA.Core.Extensions;
using DiIiS_NA.Core.Helpers.Math;
using DiIiS_NA.D3_GameServer.Core.Types.SNO;
@ -102,7 +103,9 @@ namespace DiIiS_NA.Core.MPQ.FileFormats
{
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 possibleDeaths.PickRandom();
}
}
public enum AnimationTags

View File

@ -178,7 +178,7 @@ namespace DiIiS_NA.GameServer.AchievementSystem
lock (client.ServiceLock)
{
Logger.MethodTrace($"id {achievementId}");
if (client.Account.GameAccount.Achievements.Where(a => a.AchievementId == achievementId && a.Completion != -1).Count() > 0) return;
if (client.Account.GameAccount.Achievements.Any(a => a.AchievementId == achievementId && a.Completion != -1)) return;
DBAchievements achievement = null;
var achs = DBSessions.SessionQueryWhere<DBAchievements>(dbi =>
dbi.DBGameAccount.Id == client.Account.GameAccount.PersistentID);
@ -218,7 +218,7 @@ namespace DiIiS_NA.GameServer.AchievementSystem
if (IsHardcore(achievementId))
{
if (achs.Where(a => a.CompleteTime != -1 && a.IsHardcore == true).Count() >= 30) //31 in total
if (achs.Count(a => a.CompleteTime != -1 && a.IsHardcore) >= 30) //31 in total
{
var toons = DBSessions.SessionQueryWhere<DBToon>(dbt => dbt.DBGameAccount.Id == client.Account.GameAccount.PersistentID && dbt.isHardcore == true && dbt.Archieved == false);
}
@ -308,7 +308,7 @@ namespace DiIiS_NA.GameServer.AchievementSystem
}
var ach_data = _achievements.AchievementList.Single(a => a.Id == definition.ParentAchievementId);
if (!ach_data.HasSupersedingAchievementId || client.Account.GameAccount.Achievements.Where(a => a.AchievementId == ach_data.SupersedingAchievementId && a.Completion > 0).Count() > 0)
if (!ach_data.HasSupersedingAchievementId || client.Account.GameAccount.Achievements.Any(a => a.AchievementId == ach_data.SupersedingAchievementId && a.Completion > 0))
UpdateSnapshot(client, 0, criteriaId);
}
else
@ -380,14 +380,14 @@ namespace DiIiS_NA.GameServer.AchievementSystem
{
if (additionalQuantity == 0) return;
Logger.MethodTrace($"id {achievementId}");
if (client.Account.GameAccount.Achievements.Where(a => a.AchievementId == achievementId && a.Completion != -1).Count() > 0) return;
if (client.Account.GameAccount.Achievements.Any(a => a.AchievementId == achievementId && a.Completion != -1)) return;
ulong mainCriteriaId = GetMainCriteria(achievementId);
var aa = client.Account.GameAccount.AchievementCriteria;
D3.Achievements.CriteriaUpdateRecord mainCriteria;
lock (client.Account.GameAccount.AchievementCriteria)
{
mainCriteria = client.Account.GameAccount.AchievementCriteria.Where(c => c.CriteriaId32AndFlags8 == (uint)mainCriteriaId).FirstOrDefault();
mainCriteria = client.Account.GameAccount.AchievementCriteria.FirstOrDefault(c => c.CriteriaId32AndFlags8 == (uint)mainCriteriaId);
}
if (mainCriteria == null)
mainCriteria = D3.Achievements.CriteriaUpdateRecord.CreateBuilder()
@ -531,7 +531,7 @@ namespace DiIiS_NA.GameServer.AchievementSystem
(c.AdvanceEvent.Id == 105 && c.AdvanceEvent.Comparand == actorId64)).ToList();
if (!isHardcore)
criterias = criterias.Where(c => c.AdvanceEvent.ModifierList.Where(m => m.NecessaryCondition == 306).Count() == 0).ToList();
criterias = criterias.Where(c => c.AdvanceEvent.ModifierList.All(m => m.NecessaryCondition != 306)).ToList();
criterias = criterias.Where(c => c.AdvanceEvent.ModifierList.Single(m => m.NecessaryCondition == 103).Comparand == type64).ToList();

View File

@ -13,14 +13,14 @@ namespace DiIiS_NA.GameServer.ClientSystem.Base
public ConnectionDataEventArgs(IConnection connection, IEnumerable<byte> data)
: base(connection)
{
Data = data ?? new byte[0];
Data = data ?? Array.Empty<byte>();
}
public override string ToString()
{
return Connection.RemoteEndPoint != null
? string.Format("{0}: {1} bytes", Connection.RemoteEndPoint, Data.Count())
: string.Format("Not Connected: {0} bytes", Data.Count());
? $"{Connection.RemoteEndPoint}: {Data.Count()} bytes"
: $"Not Connected: {Data.Count()} bytes";
}
}
}

View File

@ -54,7 +54,7 @@ namespace DiIiS_NA.GameServer.ClientSystem.Base
{
try
{
if (_newSockets.Count() == 0)
if (!_newSockets.Any())
return;
lock (_newSockets)

View File

@ -33,7 +33,7 @@ namespace DiIiS_NA.GameServer.CommandManager
[Command("add", "Allows you to add a new user account.\nUsage: account add <email> <password> <battletag> [userlevel]", Account.UserLevels.GM)]
public string Add(string[] @params, BattleClient invokerClient)
{
if (@params.Count() < 3)
if (@params.Length < 3)
return "Invalid arguments. Type 'help account add' to get help.";
var email = @params[0];
@ -41,7 +41,7 @@ namespace DiIiS_NA.GameServer.CommandManager
var battleTagName = @params[2];
var userLevel = Account.UserLevels.User;
if (@params.Count() == 4)
if (@params.Length == 4)
{
var level = @params[3].ToLower();
switch (level)
@ -88,7 +88,7 @@ namespace DiIiS_NA.GameServer.CommandManager
[Command("setpassword", "Allows you to set a new password for account\nUsage: account setpassword <email> <password>", Account.UserLevels.GM)]
public string SetPassword(string[] @params, BattleClient invokerClient)
{
if (@params.Count() < 2)
if (@params.Length < 2)
return "Invalid arguments. Type 'help account setpassword' to get help.";
var email = @params[0];
@ -109,7 +109,7 @@ namespace DiIiS_NA.GameServer.CommandManager
[Command("setbtag", "Allows you to change battle tag for account\nUsage: account setbtag <email> <newname>", Account.UserLevels.GM)]
public string SetBTag(string[] @params, BattleClient invokerClient)
{
if (@params.Count() < 2)
if (@params.Length < 2)
return "Invalid arguments. Type 'help account setbtag' to get help.";
var email = @params[0];
@ -127,7 +127,7 @@ namespace DiIiS_NA.GameServer.CommandManager
[Command("setuserlevel", "Allows you to set a new user level for account\nUsage: account setuserlevel <email> <user level>.\nAvailable user levels: owner, admin, gm, user.", Account.UserLevels.GM)]
public string SetLevel(string[] @params, BattleClient invokerClient)
{
if (@params.Count() < 2)
if (@params.Length < 2)
return "Invalid arguments. Type 'help account setuserlevel' to get help.";
var email = @params[0];
@ -170,7 +170,7 @@ namespace DiIiS_NA.GameServer.CommandManager
[DefaultCommand(Account.UserLevels.GM)]
public string Mute(string[] @params, BattleClient invokerClient)
{
if (@params.Count() < 2)
if (@params.Length < 2)
return "Invalid arguments. Type 'help mute' to get help.";
var bTagName = @params[0];
@ -196,7 +196,7 @@ namespace DiIiS_NA.GameServer.CommandManager
{
if(@params == null)
return "Wrong game tag. Example: !tag mytag";
if (@params.Count() != 1)
if (@params.Length != 1)
return "Invalid arguments. Enter one string tag.";
string Tag = @params[0];

View File

@ -175,7 +175,7 @@ namespace DiIiS_NA.GameServer.CommandManager
bool found = false;
var @params = parameters.Split(' ');
var group = @params[0];
var command = @params.Count() > 1 ? @params[1] : string.Empty;
var command = @params.Length > 1 ? @params[1] : string.Empty;
foreach (var pair in CommandGroups.Where(pair => group == pair.Key.Name))
{

View File

@ -301,7 +301,7 @@ public class SpawnCommand : CommandGroup
actorSNO = 6652;
if (@params.Count() > 1)
if (@params.Length > 1)
if (!int.TryParse(@params[1], out amount))
amount = 1;
if (amount > 100) amount = 100;
@ -563,7 +563,7 @@ public class ItemCommand : CommandGroup
return "You need to specify a valid item name!";
if (@params.Count() == 1 || !int.TryParse(@params[1], out amount))
if (@params.Length == 1 || !int.TryParse(@params[1], out amount))
amount = 1;
if (amount > 100) amount = 100;
@ -605,7 +605,7 @@ public class ItemCommand : CommandGroup
if (type == null)
return "The type given is not a valid item type.";
if (@params.Count() == 1 || !int.TryParse(@params[1], out amount))
if (@params.Length == 1 || !int.TryParse(@params[1], out amount))
amount = 1;
if (amount > 100) amount = 100;
@ -766,7 +766,7 @@ public class ConversationCommand : CommandGroup
if (invokerClient.InGameClient == null)
return "You can only invoke this command while in-game.";
if (@params.Count() != 1)
if (@params.Length != 1)
return "Invalid arguments. Type 'help conversation' to get help.";
try
@ -875,7 +875,7 @@ public class ModifySpeedCommand : CommandGroup
if (@params == null)
return Fallback();
if (@params.Count() != 1)
if (@params.Length != 1)
return "Invalid arguments. Type 'help text public' to get help.";
var questId = int.Parse(@params[0]);
@ -897,7 +897,7 @@ public class ModifySpeedCommand : CommandGroup
if (@params == null)
return Fallback();
if (@params.Count() != 2)
if (@params.Length != 2)
return "Invalid arguments. Type 'help text public' to get help.";
var eventId = int.Parse(@params[0]);

View File

@ -436,9 +436,9 @@ namespace DiIiS_NA.GameServer.Core
public Item GetItemByDynId(Player plr, uint dynId)
{
if (Items.Values.Where(it => it.IsRevealedToPlayer(plr) && it.DynamicID(plr) == dynId).Count() > 0)
if (Items.Values.Any(it => it.IsRevealedToPlayer(plr) && it.DynamicID(plr) == dynId))
return Items.Values.Single(it => it.IsRevealedToPlayer(plr) && it.DynamicID(plr) == dynId);
else
return null;
}
}

View File

@ -12,6 +12,7 @@ using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using DiIiS_NA.Core.Extensions;
namespace DiIiS_NA.GameServer.GSSystem.AISystem.Brains
{
@ -70,7 +71,7 @@ namespace DiIiS_NA.GameServer.GSSystem.AISystem.Brains
{
_target = monsters[0];
int powerToUse = PickPowerToUse();
if (powerToUse > 0)
if (powerToUse > 0) // FIXME: probably >= 0 as 0 can be a valid power?
{
PowerSystem.PowerScript power = PowerSystem.PowerLoader.CreateImplementationForPowerSNO(powerToUse);
power.User = Body;
@ -108,9 +109,11 @@ namespace DiIiS_NA.GameServer.GSSystem.AISystem.Brains
{
if (PresetPowers.Count > 0)
{
int powerIndex = RandomHelper.Next(PresetPowers.Count);
if (PowerSystem.PowerLoader.HasImplementationForPowerSNO(PresetPowers[powerIndex]))
return PresetPowers[powerIndex];
var randomPower = PresetPowers.PickRandom();
// should we try several times or pick random from implemented only powers?
if (PowerSystem.PowerLoader.HasImplementationForPowerSNO(randomPower))
return randomPower;
}
return -1;

View File

@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.Linq;
using DiIiS_NA.Core.Extensions;
using DiIiS_NA.Core.Helpers.Math;
using DiIiS_NA.Core.MPQ;
using DiIiS_NA.GameServer.Core.Types.Math;
@ -102,7 +103,7 @@ namespace DiIiS_NA.GameServer.GSSystem.AISystem.Brains
if (targets.Count != 0 && PowerMath.Distance2D(Body.Position, Owner.Position) < 80f)
{
int powerToUse = PickPowerToUse();
if (powerToUse > 0)
if (powerToUse > 0) // maybe >= 0 as 0 can be a valid power???
{
var elite = targets.FirstOrDefault(t => t is Champion or Rare or RareMinion);
_target = elite ?? targets.First();
@ -152,9 +153,11 @@ namespace DiIiS_NA.GameServer.GSSystem.AISystem.Brains
// randomly used an implemented power
if (PresetPowers.Count > 0)
{
int powerIndex = RandomHelper.Next(PresetPowers.Count);
if (PowerLoader.HasImplementationForPowerSNO(PresetPowers[powerIndex]))
return PresetPowers[powerIndex];
var randomPower = PresetPowers.PickRandom();
// should we try several times or pick random from implemented only powers?
if (PowerLoader.HasImplementationForPowerSNO(randomPower))
return randomPower;
}
// no usable power

View File

@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.Linq;
using DiIiS_NA.Core.Extensions;
using DiIiS_NA.Core.Helpers.Math;
using DiIiS_NA.Core.MPQ;
using DiIiS_NA.D3_GameServer.Core.Types.SNO;
@ -197,10 +198,9 @@ namespace DiIiS_NA.GameServer.GSSystem.AISystem.Brains
if (PresetPowers.Count > 0)
{
// int power = this.PresetPowers[RandomHelper.Next(this.PresetPowers.Count)].Key;
List<int> availablePowers = Enumerable.ToList(PresetPowers.Where(p => (p.Value.CooldownTimer == null || p.Value.CooldownTimer.TimedOut) && PowerLoader.HasImplementationForPowerSNO(p.Key)).Select(p => p.Key));
if (availablePowers.Where(p => p != 30592).Count() > 0)
return availablePowers.Where(p => p != 30592).ToList()[RandomHelper.Next(availablePowers.Where(p => p != 30592).ToList().Count())];
else
List<int> availablePowers = PresetPowers.Where(p => (p.Value.CooldownTimer == null || p.Value.CooldownTimer.TimedOut) && PowerLoader.HasImplementationForPowerSNO(p.Key)).Select(p => p.Key).ToList();
if (availablePowers.Where(p => p != 30592).TryPickRandom(out var randomItem))
return randomItem;
if (availablePowers.Contains(30592))
return 30592; // melee attack
}

View File

@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.Linq;
using DiIiS_NA.Core.Extensions;
using DiIiS_NA.Core.Helpers.Math;
using DiIiS_NA.Core.Logging;
using DiIiS_NA.Core.MPQ;
@ -59,7 +60,7 @@ namespace DiIiS_NA.GameServer.GSSystem.AISystem.Brains
}
var monsterData = (DiIiS_NA.Core.MPQ.FileFormats.Monster)MPQStorage.Data.Assets[SNOGroup.Monster][body.ActorData.MonsterSNO].Data;
_mpqPowerCount = monsterData.SkillDeclarations.Count(e => e.SNOPower != -1);
for (int i = 0; i < monsterData.SkillDeclarations.Count(); i++)
for (int i = 0; i < monsterData.SkillDeclarations.Length; i++)
{
if (monsterData.SkillDeclarations[i].SNOPower == -1) continue;
if (PowerLoader.HasImplementationForPowerSNO(monsterData.SkillDeclarations[i].SNOPower))
@ -435,12 +436,9 @@ namespace DiIiS_NA.GameServer.GSSystem.AISystem.Brains
//int power = this.PresetPowers[RandomHelper.Next(this.PresetPowers.Count)].Key;
var availablePowers = PresetPowers.Where(p => (p.Value.CooldownTimer == null || p.Value.CooldownTimer.TimedOut) && PowerLoader.HasImplementationForPowerSNO(p.Key)).Select(p => p.Key).ToList();
if (availablePowers.Count(p => p != 30592) > 0)
if (availablePowers.Where(p => p != 30592).TryPickRandom(out var selectedPower))
{
int SelectedPower = availablePowers.Where(p => p != 30592).ToList()[RandomHelper.Next(availablePowers.Where(p => p != 30592).ToList().Count())];
//if(SelectedPower == 73824)
//if(SkeletonKingWhirlwind)
return SelectedPower;
return selectedPower;
}
if (availablePowers.Contains(30592))

View File

@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.Linq;
using DiIiS_NA.Core.Extensions;
using DiIiS_NA.Core.Helpers.Math;
using DiIiS_NA.Core.MPQ;
using DiIiS_NA.GameServer.Core.Types.SNO;
@ -82,7 +83,7 @@ namespace DiIiS_NA.GameServer.GSSystem.AISystem.Brains
//System.Console.Out.WriteLine("Enemy in range, use powers");
//This will only attack when you and your minions are not moving..TODO: FIX.
int powerToUse = PickPowerToUse();
if (powerToUse > 0)
if (powerToUse > 0) // maybe >= 0 as 0 can be a valid power?
{
PowerScript power = PowerLoader.CreateImplementationForPowerSNO(powerToUse);
power.User = Body;
@ -117,9 +118,11 @@ namespace DiIiS_NA.GameServer.GSSystem.AISystem.Brains
// randomly used an implemented power
if (PresetPowers.Count > 0)
{
int powerIndex = RandomHelper.Next(PresetPowers.Count);
if (PowerLoader.HasImplementationForPowerSNO(PresetPowers[powerIndex]))
return PresetPowers[powerIndex];
var randomPower = PresetPowers.PickRandom();
// should we try several times or pick from implemented only?
if (PowerLoader.HasImplementationForPowerSNO(randomPower))
return randomPower;
}
// no usable power

View File

@ -31,7 +31,7 @@ namespace DiIiS_NA.GameServer.GSSystem.ActorSystem.Implementations
_collapsed = true;
World.Game.SideQuestGizmo = this;
World.Game.QuestManager.LaunchSideQuest(eventIds[DiIiS_NA.Core.Helpers.Math.FastRandom.Instance.Next(0, eventIds.Count())], true);
World.Game.QuestManager.LaunchSideQuest(eventIds[DiIiS_NA.Core.Helpers.Math.FastRandom.Instance.Next(0, eventIds.Count)], true);
}
}
catch { }

View File

@ -35,7 +35,7 @@ namespace DiIiS_NA.GameServer.GSSystem.ActorSystem.Implementations
_collapsed = true;
World.Game.SideQuestGizmo = this;
World.Game.QuestManager.LaunchSideQuest(eventIds[DiIiS_NA.Core.Helpers.Math.FastRandom.Instance.Next(0, eventIds.Count())], true);
World.Game.QuestManager.LaunchSideQuest(eventIds[DiIiS_NA.Core.Helpers.Math.FastRandom.Instance.Next(0, eventIds.Count)], true);
}
}
catch { }

View File

@ -510,11 +510,11 @@ namespace DiIiS_NA.GameServer.GSSystem.ActorSystem.Implementations.Hirelings
UnequipItem(owner, slot, item);
}
public Item GetItemByDynId(Player player, uint DynamicId)
public Item GetItemByDynId(Player player, uint dynamicId)
{
if (_equipment[player].Values.Where(it => it.IsRevealedToPlayer(player) && it.DynamicID(player) == DynamicId).Count() > 0)
return _equipment[player].Values.Single(it => it.IsRevealedToPlayer(player) && it.DynamicID(player) == DynamicId);
else
if (_equipment[player].Values.Any(it => it.IsRevealedToPlayer(player) && it.DynamicID(player) == dynamicId))
return _equipment[player].Values.Single(it => it.IsRevealedToPlayer(player) && it.DynamicID(player) == dynamicId);
return null;
}
@ -530,18 +530,23 @@ namespace DiIiS_NA.GameServer.GSSystem.ActorSystem.Implementations.Hirelings
#region EqupimentStats
public List<Item> GetEquippedItems(Player player)
public IEnumerable<Item> GetEquippedItems(Player player)
{
return _equipment[player].Values.ToList();
return _equipment[player].Values;
}
public float GetItemBonus(GameAttributeF attributeF)
{
var stats = GetEquippedItems(owner).Where(item => item.Attributes[GameAttribute.Durability_Cur] > 0 || item.Attributes[GameAttribute.Durability_Max] == 0);
var stats = GetEquippedItems(owner)
.Where(item => item.Attributes[GameAttribute.Durability_Cur] > 0 ||
item.Attributes[GameAttribute.Durability_Max] == 0);
if (attributeF == GameAttribute.Attacks_Per_Second_Item)
return stats.Count() > 0 ? stats.Select(item => item.Attributes[attributeF]).Where(a => a > 0f).Aggregate(1f, (x, y) => x * y) : 0f;
{
return stats.Any()
? stats.Select(item => item.Attributes[attributeF]).Where(a => a > 0f).Aggregate(1f, (x, y) => x * y)
: 0f;
}
return stats.Sum(item => item.Attributes[attributeF]);
}
@ -552,7 +557,7 @@ namespace DiIiS_NA.GameServer.GSSystem.ActorSystem.Implementations.Hirelings
public bool GetItemBonus(GameAttributeB attributeB)
{
return GetEquippedItems(owner).Where(item => item.Attributes[attributeB] == true).Count() > 0;
return GetEquippedItems(owner).Any(item => item.Attributes[attributeB]);
}
public float GetItemBonus(GameAttributeF attributeF, int attributeKey)

View File

@ -34,12 +34,12 @@ namespace DiIiS_NA.GameServer.GSSystem.ActorSystem.Implementations.Minions
LifeTime = TickTimer.WaitSeconds(world.Game, lifetime);
if (Master != null && context.ScriptFormula(1) < (Master as Player).Followers.Values.Where(f => f == SNO).Count())
if (Master != null && context.ScriptFormula(1) < (Master as Player).Followers.Values.Count(f => f == SNO))
{
if (Master is Player)
{
var rem = new List<uint>();
foreach (var fol in (Master as Player).Followers.Where(f => f.Key != GlobalID).Take((Master as Player).Followers.Values.Where(f => f == SNO).Count() - (int)context.ScriptFormula(1)))
foreach (var fol in (Master as Player).Followers.Where(f => f.Key != GlobalID).Take((Master as Player).Followers.Values.Count(f => f == SNO) - (int)context.ScriptFormula(1)))
if (fol.Value == SNO)
rem.Add(fol.Key);
foreach (var rm in rem)

View File

@ -208,9 +208,9 @@ namespace DiIiS_NA.GameServer.GSSystem.ActorSystem
if (ConversationList != null)
{
var suitable_entries = ConversationList.AmbientConversationListEntries.Where(entry => entry.SpecialEventFlag == World.Game.CurrentAct).ToList();
if (suitable_entries.Count() > 0)
if (suitable_entries.Count > 0)
{
var random_conv = suitable_entries[FastRandom.Instance.Next(suitable_entries.Count())];
var random_conv = suitable_entries[FastRandom.Instance.Next(suitable_entries.Count)];
player.Conversations.StartConversation(random_conv.SNOConversation);
if (ForceConversationSNO == Conversations[0].ConversationSNO) ForceConversationSNO = -1;
}

View File

@ -1716,7 +1716,7 @@ namespace DiIiS_NA.GameServer.GSSystem.GameSystem
public bool WorldCleared(WorldSno worldSno)
{
return _worlds[worldSno].Actors.Values.OfType<Monster>().Where(m => m.OriginalLevelArea != -1 && !m.Dead).Count() < 5;
return _worlds[worldSno].Actors.Values.OfType<Monster>().Count(m => m.OriginalLevelArea != -1 && !m.Dead) < 5;
}
/// <summary>

View File

@ -32,7 +32,7 @@ namespace DiIiS_NA.GameServer.GSSystem.GameSystem
public static GameUpdateThread FindWorker()
{
return UpdateWorkers.OrderBy(t => t.Games.Count()).First();
return UpdateWorkers.OrderBy(t => t.Games.Count).First();
}
}
}

View File

@ -940,7 +940,7 @@ namespace DiIiS_NA.D3_GameServer.GSSystem.GameSystem
{
while (monsterCount < AdditionalTargetCounter + 20)
{
GameServer.Core.Types.Math.Vector3D scenePoint = Scenes[RandomHelper.Next(0, Scenes.Count)].Position;
GameServer.Core.Types.Math.Vector3D scenePoint = Scenes.PickRandom().Position;
GameServer.Core.Types.Math.Vector3D point = null;
while (true)
{
@ -948,7 +948,7 @@ namespace DiIiS_NA.D3_GameServer.GSSystem.GameSystem
if (QuestManager.Game.GetWorld(world).CheckLocationForFlag(point, Scene.NavCellFlags.AllowWalk))
break;
}
QuestManager.Game.GetWorld(world).SpawnMonster((ActorSno)GameServer.GSSystem.GeneratorsSystem.SpawnGenerator.Spawns[LevelArea].melee[FastRandom.Instance.Next(GameServer.GSSystem.GeneratorsSystem.SpawnGenerator.Spawns[LevelArea].melee.Count())], point);
QuestManager.Game.GetWorld(world).SpawnMonster((ActorSno)GameServer.GSSystem.GeneratorsSystem.SpawnGenerator.Spawns[LevelArea].melee[FastRandom.Instance.Next(GameServer.GSSystem.GeneratorsSystem.SpawnGenerator.Spawns[LevelArea].melee.Count)], point);
monsterCount++;
}
} // Need additional monster spawn, there are few of them
@ -978,6 +978,7 @@ namespace DiIiS_NA.D3_GameServer.GSSystem.GameSystem
scenes.Add(scene);
}
// FIXME: Probably RandomHelper.Next(0, scenes.Count)???
GameServer.Core.Types.Math.Vector3D scenePoint = scenes[RandomHelper.Next(0, scenes.Count - 1)].Position;
GameServer.Core.Types.Math.Vector3D point = null;
while (true)

View File

@ -1,6 +1,7 @@
using DiIiS_NA.Core.Logging;
using System.Collections.Generic;
using System.Linq;
using DiIiS_NA.Core.Extensions;
using DiIiS_NA.GameServer.GSSystem.AISystem.Brains;
using static DiIiS_NA.Core.MPQ.FileFormats.GameBalance;
using Actor = DiIiS_NA.GameServer.GSSystem.ActorSystem.Actor;
@ -250,14 +251,14 @@ namespace DiIiS_NA.GameServer.GSSystem.GeneratorsSystem
public static int GeneratePrefixName()
{
var randomPrefix = NamesList.Where(n => n.AffixType == AffixType.Prefix).OrderBy(x => RandomHelper.Next()).ToList().First();
var randomPrefix = NamesList.Where(n => n.AffixType == AffixType.Prefix).PickRandom();
return randomPrefix.Hash;
}
public static int GenerateSuffixName()
{
var randomSuffix = NamesList.Where(n => n.AffixType == AffixType.Suffix).OrderBy(x => RandomHelper.Next()).ToList().First();
return randomSuffix.Hash;
var randomPrefix = NamesList.Where(n => n.AffixType == AffixType.Suffix).PickRandom();
return randomPrefix.Hash;
}
}
}

View File

@ -302,11 +302,8 @@ namespace DiIiS_NA.GameServer.GSSystem.GeneratorsSystem
else
{
var entries = clusterSelected[sceneChunk.SceneSpecification.ClusterID];
SubSceneEntry subSceneEntry = null;
if (entries.Count > 0)
if (entries.TryPickRandom(out var subSceneEntry))
{
subSceneEntry = RandomHelper.RandomItem<SubSceneEntry>(entries, entry => 1);
entries.Remove(subSceneEntry);
}
else
@ -566,7 +563,7 @@ namespace DiIiS_NA.GameServer.GSSystem.GeneratorsSystem
List<Scene> scenes = world.Scenes.Values.ToList();
if (levelArea != -1) scenes = scenes.Where(sc => sc.Specification.SNOLevelAreas[0] == levelArea && !sc.SceneSNO.Name.ToLower().Contains("filler")).ToList();
else scenes = scenes.Where(sc => !sc.SceneSNO.Name.ToLower().Contains("filler")).ToList();
int randomScene = RandomHelper.Next(0, scenes.Count - 1);
int randomScene = RandomHelper.Next(0, scenes.Count - 1); // FIXME: probably RandomHelper.Next(0, scenes.Count)???
Vector3D SSV = scenes[randomScene].Position;
Vector3D startingPoint = null;
@ -638,7 +635,7 @@ namespace DiIiS_NA.GameServer.GSSystem.GeneratorsSystem
bool rift = world.SNO.IsGenerated();
//Getting Enter
var loadedScene = new SceneChunk();
currentScene = DRLGContainers[0][RandomHelper.Next(0, DRLGContainers[0].Count)];
currentScene = DRLGContainers[0].PickRandom();
loadedScene.SNOHandle = new SNOHandle(SNOGroup.Scene, currentScene.SnoID);
loadedScene.PRTransform = new PRTransform(new Quaternion(new Vector3D(0f, 0f, 0f), 1), new Vector3D(0, 0, 0));
loadedScene.SceneSpecification = new SceneSpecification(
@ -676,7 +673,7 @@ namespace DiIiS_NA.GameServer.GSSystem.GeneratorsSystem
{
if (prestScene.SNOHandle.Name.StartsWith("x1_Pand"))
positionOfNav = 3;
currentScene = DRLGContainers[2][RandomHelper.Next(0, DRLGContainers[2].Count)];
currentScene = DRLGContainers[2].PickRandom();
if (currentScene.Asset.Name.Split('_')[positionOfNav].Contains(currentNav) & currentScene.Asset.Name.Split('_')[positionOfNav].ToCharArray().Length > 1) //Way
break;
}
@ -715,7 +712,7 @@ namespace DiIiS_NA.GameServer.GSSystem.GeneratorsSystem
if (prestScene.SNOHandle.Name.StartsWith("x1_Pand"))
positionOfNav = 3;
currentScene = DRLGContainers[2][RandomHelper.Next(0, DRLGContainers[2].Count)];
currentScene = DRLGContainers[2].PickRandom();
if (currentScene.Asset.Name.Split('_')[positionOfNav].Contains(currentNav) & currentScene.Asset.Name.Split('_')[positionOfNav].ToCharArray().Length > 1) //Way
break;
}
@ -753,7 +750,7 @@ namespace DiIiS_NA.GameServer.GSSystem.GeneratorsSystem
if (prestScene.SNOHandle.Name.StartsWith("x1_Pand"))
positionOfNav = 3;
currentScene = DRLGContainers[2][RandomHelper.Next(0, DRLGContainers[2].Count)];
currentScene = DRLGContainers[2].PickRandom();
if (currentScene.Asset.Name.Split('_')[positionOfNav].Contains(currentNav) & currentScene.Asset.Name.Split('_')[positionOfNav].ToCharArray().Length > 1) //Way
break;
}
@ -793,7 +790,7 @@ namespace DiIiS_NA.GameServer.GSSystem.GeneratorsSystem
if (prestScene.SNOHandle.Name.StartsWith("x1_Pand"))
positionOfNav = 3;
currentScene = DRLGContainers[2][RandomHelper.Next(0, DRLGContainers[2].Count)];
currentScene = DRLGContainers[2].PickRandom();
if (currentScene.Asset.Name.Split('_')[positionOfNav].Contains(currentNav) & currentScene.Asset.Name.Split('_')[positionOfNav].ToCharArray().Length > 1) //Way
break;
}
@ -832,7 +829,7 @@ namespace DiIiS_NA.GameServer.GSSystem.GeneratorsSystem
currentNav = 'E';
while (true)
{
currentScene = DRLGContainers[2][RandomHelper.Next(0, DRLGContainers[2].Count)];
currentScene = DRLGContainers[2].PickRandom();
if (currentScene.Asset.Name.Split('_')[positionOfNav].Contains(currentNav) & currentScene.Asset.Name.Split('_')[positionOfNav].ToCharArray().Length > 1) //Way
break;
}
@ -865,7 +862,7 @@ namespace DiIiS_NA.GameServer.GSSystem.GeneratorsSystem
currentNav = 'W';
while (true)
{
currentScene = DRLGContainers[2][RandomHelper.Next(0, DRLGContainers[2].Count)];
currentScene = DRLGContainers[2].PickRandom();
if (currentScene.Asset.Name.Split('_')[positionOfNav].Contains(currentNav) & currentScene.Asset.Name.Split('_')[positionOfNav].ToCharArray().Length > 1) //Way
break;
}
@ -919,7 +916,7 @@ namespace DiIiS_NA.GameServer.GSSystem.GeneratorsSystem
{
if (hasExit)
{
currentScene = DRLGContainers[3][RandomHelper.Next(0, DRLGContainers[3].Count)];
currentScene = DRLGContainers[3].PickRandom();
if (currentScene.Asset.Name.ToLower().Contains("hexmaze_edge") || currentScene.Asset.Name.ToLower().Contains("hexmaze_exit")) positionOfNav = 4;
if (currentScene.Asset.Name.Split('_')[positionOfNav].Contains(currentNav) & currentScene.Asset.Name.Split('_')[positionOfNav].ToCharArray().Length == 1) //Way
{
@ -929,7 +926,7 @@ namespace DiIiS_NA.GameServer.GSSystem.GeneratorsSystem
}
else
{
currentScene = DRLGContainers[1][RandomHelper.Next(0, DRLGContainers[1].Count)];
currentScene = DRLGContainers[1].PickRandom();
if (currentScene.Asset.Name.ToLower().Contains("hexmaze_edge") || currentScene.Asset.Name.ToLower().Contains("hexmaze_exit")) positionOfNav = 4;
if (currentScene.Asset.Name.Split('_')[positionOfNav].Contains(currentNav)) //Exit
{
@ -941,7 +938,7 @@ namespace DiIiS_NA.GameServer.GSSystem.GeneratorsSystem
}
else
{
currentScene = DRLGContainers[2][RandomHelper.Next(0, DRLGContainers[2].Count)];
currentScene = DRLGContainers[2].PickRandom();
#region проверка на будущее
toWaitChunks = currentScene.Asset.Name.Split('_')[positionOfNav].ToCharArray();
bool ForceStop = false;
@ -955,7 +952,7 @@ namespace DiIiS_NA.GameServer.GSSystem.GeneratorsSystem
(reservedChunks.Contains(new Vector3D(placeToNewScene.X + RangetoNext, placeToNewScene.Y, placeToNewScene.Z))))
while (true)
{
currentScene = DRLGContainers[3][RandomHelper.Next(0, DRLGContainers[3].Count)];//CurrentScene Switch
currentScene = DRLGContainers[3].PickRandom(); // CurrentScene Switch
if (currentScene.Asset.Name.ToLower().Contains("hexmaze_edge") || currentScene.Asset.Name.ToLower().Contains("hexmaze_exit")) positionOfNav = 4;
if (currentScene.Asset.Name.Split('_')[positionOfNav].Contains(currentNav) & currentScene.Asset.Name.Split('_')[positionOfNav].ToCharArray().Length == 1) //End
{
@ -972,7 +969,7 @@ namespace DiIiS_NA.GameServer.GSSystem.GeneratorsSystem
(reservedChunks.Contains(new Vector3D(placeToNewScene.X - RangetoNext, placeToNewScene.Y, placeToNewScene.Z))))
while (true)
{
currentScene = DRLGContainers[3][RandomHelper.Next(0, DRLGContainers[3].Count)];//CurrentScene Switch
currentScene = DRLGContainers[3].PickRandom(); // CurrentScene Switch
if (currentScene.Asset.Name.ToLower().Contains("hexmaze_edge") || currentScene.Asset.Name.ToLower().Contains("hexmaze_exit")) positionOfNav = 4;
if (currentScene.Asset.Name.Split('_')[positionOfNav].Contains(currentNav) & currentScene.Asset.Name.Split('_')[positionOfNav].ToCharArray().Length == 1) //End
{
@ -989,7 +986,7 @@ namespace DiIiS_NA.GameServer.GSSystem.GeneratorsSystem
(reservedChunks.Contains(new Vector3D(placeToNewScene.X, placeToNewScene.Y + RangetoNext, placeToNewScene.Z))))
while (true)
{
currentScene = DRLGContainers[3][RandomHelper.Next(0, DRLGContainers[3].Count)];//CurrentScene Switch
currentScene = DRLGContainers[3].PickRandom(); // CurrentScene Switch
if (currentScene.Asset.Name.ToLower().Contains("hexmaze_edge") || currentScene.Asset.Name.ToLower().Contains("hexmaze_exit")) positionOfNav = 4;
if (currentScene.Asset.Name.Split('_')[positionOfNav].Contains(currentNav) & currentScene.Asset.Name.Split('_')[positionOfNav].ToCharArray().Length == 1) //End
{
@ -1006,7 +1003,7 @@ namespace DiIiS_NA.GameServer.GSSystem.GeneratorsSystem
(reservedChunks.Contains(new Vector3D(placeToNewScene.X, placeToNewScene.Y - RangetoNext, placeToNewScene.Z))))
while (true)
{
currentScene = DRLGContainers[3][RandomHelper.Next(0, DRLGContainers[3].Count)];//CurrentScene Switch
currentScene = DRLGContainers[3].PickRandom(); // CurrentScene Switch
if (currentScene.Asset.Name.ToLower().Contains("hexmaze_edge") || currentScene.Asset.Name.ToLower().Contains("hexmaze_exit")) positionOfNav = 4;
if (currentScene.Asset.Name.Split('_')[positionOfNav].Contains(currentNav) & currentScene.Asset.Name.Split('_')[positionOfNav].ToCharArray().Length == 1) //End
{
@ -1067,7 +1064,7 @@ namespace DiIiS_NA.GameServer.GSSystem.GeneratorsSystem
{
if (hasExit)
{
currentScene = DRLGContainers[3][RandomHelper.Next(0, DRLGContainers[3].Count)];
currentScene = DRLGContainers[3].PickRandom();
if (currentScene.Asset.Name.ToLower().Contains("hexmaze_edge") || currentScene.Asset.Name.ToLower().Contains("hexmaze_exit")) positionOfNav = 4;
if (currentScene.Asset.Name.Split('_')[positionOfNav].Contains(currentNav) & currentScene.Asset.Name.Split('_')[positionOfNav].ToCharArray().Length == 1) //Way
{
@ -1077,7 +1074,7 @@ namespace DiIiS_NA.GameServer.GSSystem.GeneratorsSystem
}
else
{
currentScene = DRLGContainers[1][RandomHelper.Next(0, DRLGContainers[1].Count)];
currentScene = DRLGContainers[1].PickRandom();
if (currentScene.Asset.Name.ToLower().Contains("hexmaze_edge") || currentScene.Asset.Name.ToLower().Contains("hexmaze_exit")) positionOfNav = 4;
if (currentScene.Asset.Name.Split('_')[positionOfNav].Contains(currentNav)) //Exit
{
@ -1089,7 +1086,7 @@ namespace DiIiS_NA.GameServer.GSSystem.GeneratorsSystem
}
else
{
currentScene = DRLGContainers[2][RandomHelper.Next(0, DRLGContainers[2].Count)];
currentScene = DRLGContainers[2].PickRandom();
#region проверка на будущее
toWaitChunks = currentScene.Asset.Name.Split('_')[positionOfNav].ToCharArray();
bool forceStop = false;
@ -1103,7 +1100,7 @@ namespace DiIiS_NA.GameServer.GSSystem.GeneratorsSystem
(reservedChunks.Contains(new Vector3D(placeToNewScene.X + RangetoNext, placeToNewScene.Y, placeToNewScene.Z))))
while (true)
{
currentScene = DRLGContainers[3][RandomHelper.Next(0, DRLGContainers[3].Count)];//CurrentScene Switch
currentScene = DRLGContainers[3].PickRandom(); // CurrentScene Switch
if (currentScene.Asset.Name.ToLower().Contains("hexmaze_edge") || currentScene.Asset.Name.ToLower().Contains("hexmaze_exit")) positionOfNav = 4;
if (currentScene.Asset.Name.Split('_')[positionOfNav].Contains(currentNav) & currentScene.Asset.Name.Split('_')[positionOfNav].ToCharArray().Length == 1) //End
{
@ -1119,7 +1116,7 @@ namespace DiIiS_NA.GameServer.GSSystem.GeneratorsSystem
(reservedChunks.Contains(new Vector3D(placeToNewScene.X - RangetoNext, placeToNewScene.Y, placeToNewScene.Z))))
while (true)
{
currentScene = DRLGContainers[3][RandomHelper.Next(0, DRLGContainers[3].Count)];//CurrentScene Switch
currentScene = DRLGContainers[3].PickRandom(); // CurrentScene Switch
if (currentScene.Asset.Name.ToLower().Contains("hexmaze_edge") || currentScene.Asset.Name.ToLower().Contains("hexmaze_exit")) positionOfNav = 4;
if (currentScene.Asset.Name.Split('_')[positionOfNav].Contains(currentNav) & currentScene.Asset.Name.Split('_')[positionOfNav].ToCharArray().Length == 1) //End
{
@ -1135,7 +1132,7 @@ namespace DiIiS_NA.GameServer.GSSystem.GeneratorsSystem
(reservedChunks.Contains(new Vector3D(placeToNewScene.X, placeToNewScene.Y + RangetoNext, placeToNewScene.Z))))
while (true)
{
currentScene = DRLGContainers[3][RandomHelper.Next(0, DRLGContainers[3].Count)];//CurrentScene Switch
currentScene = DRLGContainers[3].PickRandom(); // CurrentScene Switch
if (currentScene.Asset.Name.ToLower().Contains("hexmaze_edge") || currentScene.Asset.Name.ToLower().Contains("hexmaze_exit")) positionOfNav = 4;
if (currentScene.Asset.Name.Split('_')[positionOfNav].Contains(currentNav) & currentScene.Asset.Name.Split('_')[positionOfNav].ToCharArray().Length == 1) //End
{
@ -1151,7 +1148,7 @@ namespace DiIiS_NA.GameServer.GSSystem.GeneratorsSystem
(reservedChunks.Contains(new Vector3D(placeToNewScene.X, placeToNewScene.Y - RangetoNext, placeToNewScene.Z))))
while (true)
{
currentScene = DRLGContainers[3][RandomHelper.Next(0, DRLGContainers[3].Count)];//CurrentScene Switch
currentScene = DRLGContainers[3].PickRandom(); // CurrentScene Switch
if (currentScene.Asset.Name.ToLower().Contains("hexmaze_edge") || currentScene.Asset.Name.ToLower().Contains("hexmaze_exit")) positionOfNav = 4;// else PosOfNav = 3;
if (currentScene.Asset.Name.Split('_')[positionOfNav].Contains(currentNav) & currentScene.Asset.Name.Split('_')[positionOfNav].ToCharArray().Length == 1) //End
{
@ -1212,7 +1209,7 @@ namespace DiIiS_NA.GameServer.GSSystem.GeneratorsSystem
{
if (hasExit)
{
currentScene = DRLGContainers[3][RandomHelper.Next(0, DRLGContainers[3].Count)];
currentScene = DRLGContainers[3].PickRandom();
if (currentScene.Asset.Name.ToLower().Contains("hexmaze_edge") || currentScene.Asset.Name.ToLower().Contains("hexmaze_exit")) positionOfNav = 4;
if (currentScene.Asset.Name.Split('_')[positionOfNav].Contains(currentNav) & currentScene.Asset.Name.Split('_')[positionOfNav].ToCharArray().Length == 1) //Way
{
@ -1222,7 +1219,7 @@ namespace DiIiS_NA.GameServer.GSSystem.GeneratorsSystem
}
else
{
currentScene = DRLGContainers[1][RandomHelper.Next(0, DRLGContainers[1].Count)];
currentScene = DRLGContainers[1].PickRandom();
if (currentScene.Asset.Name.ToLower().Contains("hexmaze_edge") || currentScene.Asset.Name.ToLower().Contains("hexmaze_exit")) positionOfNav = 4;
if (currentScene.Asset.Name.Split('_')[positionOfNav].Contains(currentNav)) //Exit
{
@ -1234,7 +1231,7 @@ namespace DiIiS_NA.GameServer.GSSystem.GeneratorsSystem
}
else
{
currentScene = DRLGContainers[2][RandomHelper.Next(0, DRLGContainers[2].Count)];
currentScene = DRLGContainers[2].PickRandom();
#region проверка на будущее
toWaitChunks = currentScene.Asset.Name.Split('_')[positionOfNav].ToCharArray();
bool ForceStop = false;
@ -1252,7 +1249,7 @@ namespace DiIiS_NA.GameServer.GSSystem.GeneratorsSystem
(reservedChunks.Contains(new Vector3D(placeToNewScene.X + RangetoNext, placeToNewScene.Y, placeToNewScene.Z))))
while (true)
{
currentScene = DRLGContainers[3][RandomHelper.Next(0, DRLGContainers[3].Count)];//CurrentScene Switch
currentScene = DRLGContainers[3].PickRandom();//CurrentScene Switch
if (currentScene.Asset.Name.ToLower().Contains("hexmaze_edge") || currentScene.Asset.Name.ToLower().Contains("hexmaze_exit")) positionOfNav = 4;
if (currentScene.Asset.Name.Split('_')[positionOfNav].Contains(currentNav) & currentScene.Asset.Name.Split('_')[positionOfNav].ToCharArray().Length == 1) //End
{
@ -1267,7 +1264,7 @@ namespace DiIiS_NA.GameServer.GSSystem.GeneratorsSystem
(reservedChunks.Contains(new Vector3D(placeToNewScene.X - RangetoNext, placeToNewScene.Y, placeToNewScene.Z))))
while (true)
{
currentScene = DRLGContainers[3][RandomHelper.Next(0, DRLGContainers[3].Count)];//CurrentScene Switch
currentScene = DRLGContainers[3].PickRandom();//CurrentScene Switch
if (currentScene.Asset.Name.ToLower().Contains("hexmaze_edge") || currentScene.Asset.Name.ToLower().Contains("hexmaze_exit")) positionOfNav = 4;
if (currentScene.Asset.Name.Split('_')[positionOfNav].Contains(currentNav) & currentScene.Asset.Name.Split('_')[positionOfNav].ToCharArray().Length == 1) //End
{
@ -1282,7 +1279,7 @@ namespace DiIiS_NA.GameServer.GSSystem.GeneratorsSystem
(reservedChunks.Contains(new Vector3D(placeToNewScene.X, placeToNewScene.Y + RangetoNext, placeToNewScene.Z))))
while (true)
{
currentScene = DRLGContainers[3][RandomHelper.Next(0, DRLGContainers[3].Count)];//CurrentScene Switch
currentScene = DRLGContainers[3].PickRandom(); // CurrentScene Switch
if (currentScene.Asset.Name.ToLower().Contains("hexmaze_edge") || currentScene.Asset.Name.ToLower().Contains("hexmaze_exit")) positionOfNav = 4;
if (currentScene.Asset.Name.Split('_')[positionOfNav].Contains(currentNav) & currentScene.Asset.Name.Split('_')[positionOfNav].ToCharArray().Length == 1) //End
{
@ -1297,7 +1294,7 @@ namespace DiIiS_NA.GameServer.GSSystem.GeneratorsSystem
(reservedChunks.Contains(new Vector3D(placeToNewScene.X, placeToNewScene.Y - RangetoNext, placeToNewScene.Z))))
while (true)
{
currentScene = DRLGContainers[3][RandomHelper.Next(0, DRLGContainers[3].Count)];//CurrentScene Switch
currentScene = DRLGContainers[3].PickRandom(); // CurrentScene Switch
if (currentScene.Asset.Name.ToLower().Contains("hexmaze_edge") || currentScene.Asset.Name.ToLower().Contains("hexmaze_exit")) positionOfNav = 4;
if (currentScene.Asset.Name.Split('_')[positionOfNav].Contains(currentNav) & currentScene.Asset.Name.Split('_')[positionOfNav].ToCharArray().Length == 1) //End
{
@ -1358,7 +1355,7 @@ namespace DiIiS_NA.GameServer.GSSystem.GeneratorsSystem
{
if (hasExit)
{
currentScene = DRLGContainers[3][RandomHelper.Next(0, DRLGContainers[3].Count)];
currentScene = DRLGContainers[3].PickRandom();
if (currentScene.Asset.Name.ToLower().Contains("hexmaze_edge") || currentScene.Asset.Name.ToLower().Contains("hexmaze_exit")) positionOfNav = 4;
if (currentScene.Asset.Name.Split('_')[positionOfNav].Contains(currentNav) & currentScene.Asset.Name.Split('_')[positionOfNav].ToCharArray().Length == 1) //Way
{
@ -1368,7 +1365,7 @@ namespace DiIiS_NA.GameServer.GSSystem.GeneratorsSystem
}
else
{
currentScene = DRLGContainers[1][RandomHelper.Next(0, DRLGContainers[1].Count)];
currentScene = DRLGContainers[1].PickRandom();
if (currentScene.Asset.Name.ToLower().Contains("hexmaze_edge") || currentScene.Asset.Name.ToLower().Contains("hexmaze_exit")) positionOfNav = 4;
if (currentScene.Asset.Name.Split('_')[positionOfNav].Contains(currentNav)) //Exit
{
@ -1380,7 +1377,7 @@ namespace DiIiS_NA.GameServer.GSSystem.GeneratorsSystem
}
else
{
currentScene = DRLGContainers[2][RandomHelper.Next(0, DRLGContainers[2].Count)];
currentScene = DRLGContainers[2].PickRandom();
#region проверка на будущее
toWaitChunks = currentScene.Asset.Name.Split('_')[positionOfNav].ToCharArray();
bool ForceStop = false;
@ -1398,7 +1395,7 @@ namespace DiIiS_NA.GameServer.GSSystem.GeneratorsSystem
(reservedChunks.Contains(new Vector3D(placeToNewScene.X + RangetoNext, placeToNewScene.Y, placeToNewScene.Z))))
while (true)
{
currentScene = DRLGContainers[3][RandomHelper.Next(0, DRLGContainers[3].Count)];//CurrentScene Switch
currentScene = DRLGContainers[3].PickRandom(); // CurrentScene Switch
if (currentScene.Asset.Name.ToLower().Contains("hexmaze_edge") || currentScene.Asset.Name.ToLower().Contains("hexmaze_exit")) positionOfNav = 4;
if (currentScene.Asset.Name.Split('_')[positionOfNav].Contains(currentNav) & currentScene.Asset.Name.Split('_')[positionOfNav].ToCharArray().Length == 1) //End
{
@ -1413,7 +1410,7 @@ namespace DiIiS_NA.GameServer.GSSystem.GeneratorsSystem
(reservedChunks.Contains(new Vector3D(placeToNewScene.X - RangetoNext, placeToNewScene.Y, placeToNewScene.Z))))
while (true)
{
currentScene = DRLGContainers[3][RandomHelper.Next(0, DRLGContainers[3].Count)];//CurrentScene Switch
currentScene = DRLGContainers[3].PickRandom(); // CurrentScene Switch
if (currentScene.Asset.Name.ToLower().Contains("hexmaze_edge") || currentScene.Asset.Name.ToLower().Contains("hexmaze_exit")) positionOfNav = 4;
if (currentScene.Asset.Name.Split('_')[positionOfNav].Contains(currentNav) & currentScene.Asset.Name.Split('_')[positionOfNav].ToCharArray().Length == 1) //End
{
@ -1428,7 +1425,7 @@ namespace DiIiS_NA.GameServer.GSSystem.GeneratorsSystem
(reservedChunks.Contains(new Vector3D(placeToNewScene.X, placeToNewScene.Y + RangetoNext, placeToNewScene.Z))))
while (true)
{
currentScene = DRLGContainers[3][RandomHelper.Next(0, DRLGContainers[3].Count)];//CurrentScene Switch
currentScene = DRLGContainers[3].PickRandom(); // CurrentScene Switch
if (currentScene.Asset.Name.ToLower().Contains("hexmaze_edge") || currentScene.Asset.Name.ToLower().Contains("hexmaze_exit")) positionOfNav = 4;
if (currentScene.Asset.Name.Split('_')[positionOfNav].Contains(currentNav) & currentScene.Asset.Name.Split('_')[positionOfNav].ToCharArray().Length == 1) //End
{
@ -1443,7 +1440,7 @@ namespace DiIiS_NA.GameServer.GSSystem.GeneratorsSystem
(reservedChunks.Contains(new Vector3D(placeToNewScene.X, placeToNewScene.Y - RangetoNext, placeToNewScene.Z))))
while (true)
{
currentScene = DRLGContainers[3][RandomHelper.Next(0, DRLGContainers[3].Count)];//CurrentScene Switch
currentScene = DRLGContainers[3].PickRandom(); // CurrentScene Switch
if (currentScene.Asset.Name.ToLower().Contains("hexmaze_edge") || currentScene.Asset.Name.ToLower().Contains("hexmaze_exit")) positionOfNav = 4;
if (currentScene.Asset.Name.Split('_')[positionOfNav].Contains(currentNav) & currentScene.Asset.Name.Split('_')[positionOfNav].ToCharArray().Length == 1) //End
{
@ -1540,7 +1537,7 @@ namespace DiIiS_NA.GameServer.GSSystem.GeneratorsSystem
char Nav = chunk.SNOHandle.Name.Split('_')[positionOfNav].ToCharArray()[0];
while (true)
{
currentScene = DRLGContainers[1][RandomHelper.Next(0, DRLGContainers[1].Count)];
currentScene = DRLGContainers[1].PickRandom();
if (currentScene.Asset.Name.Split('_')[positionOfNav].Contains(Nav)) //Exit
{
@ -1603,7 +1600,7 @@ namespace DiIiS_NA.GameServer.GSSystem.GeneratorsSystem
if (!busy)
{
currentScene = DRLGContainers[4][RandomHelper.Next(0, DRLGContainers[4].Count)];
currentScene = DRLGContainers[4].PickRandom();
var newscene = new SceneChunk
{
@ -1975,7 +1972,7 @@ namespace DiIiS_NA.GameServer.GSSystem.GeneratorsSystem
for (int i = 0; i < count; i++)
{
//Chose a random exit to test
Vector3D chosenExitPosition = RandomHelper.RandomValue(exitTypes);
Vector3D chosenExitPosition = exitTypes.PickRandom().Value;
var chosenExitDirection = (from pair in exitTypes
where pair.Value == chosenExitPosition
select pair.Key).FirstOrDefault();
@ -2077,7 +2074,7 @@ namespace DiIiS_NA.GameServer.GSSystem.GeneratorsSystem
//return filler
return GetTileInfo(tiles, TileTypes.Filler);
}
List<TileInfo> tilesWithRightDirection = (from pair in tiles where ((pair.Value.ExitDirectionBits & exitDirectionBits) > 0) select pair.Value).ToList<TileInfo>();
List<TileInfo> tilesWithRightDirection = (from pair in tiles where ((pair.Value.ExitDirectionBits & exitDirectionBits) > 0) select pair.Value).ToList();
if (tilesWithRightDirection.Count == 0)
{
@ -2087,7 +2084,7 @@ namespace DiIiS_NA.GameServer.GSSystem.GeneratorsSystem
return null;
}
return RandomHelper.RandomItem(tilesWithRightDirection, x => 1.0f);
return tilesWithRightDirection.PickRandom();
}
private TileInfo GetTile(Dictionary<int, TileInfo> tiles, int snoId)
@ -2100,12 +2097,12 @@ namespace DiIiS_NA.GameServer.GSSystem.GeneratorsSystem
/// Returns a tileinfo from a list of tiles that has a specific type
/// </summary>
/// <param name="tiles"></param>
/// <param name="exitDirectionBits"></param>
/// <param name="tileType"></param>
/// <returns></returns>
private TileInfo GetTileInfo(Dictionary<int, TileInfo> tiles, TileTypes tileType)
{
var tilesWithRightType = (from pair in tiles where (pair.Value.TileType == (int)tileType) select pair.Value);
return RandomHelper.RandomItem(tilesWithRightType, x => 1);
var tilesWithRightType = tiles.Values.Where(tile => tile.TileType == (int)tileType);
return tilesWithRightType.PickRandom();
}
private TileInfo GetTileInfo(Dictionary<int, TileInfo> tiles, TileTypes tileType, int exitDirectionBits)

View File

@ -171,11 +171,9 @@ namespace DiIiS_NA.GameServer.GSSystem.ItemsSystem
if (IsUnique)
{
var restrictedFamily = item.ItemDefinition.LegendaryAffixFamily.Where(af => af != -1);
filteredList = filteredList.Where(
a =>
!(restrictedFamily.Contains(a.AffixFamily0) || restrictedFamily.Contains(a.AffixFamily1))
);
var restrictedFamily = item.ItemDefinition.LegendaryAffixFamily.Where(af => af != -1).ToHashSet();
filteredList = filteredList
.Where(a => !(restrictedFamily.Contains(a.AffixFamily0) || restrictedFamily.Contains(a.AffixFamily1)));
if (restrictedFamily.Contains(1616088365) ||
restrictedFamily.Contains(-1461069734) ||
@ -184,17 +182,17 @@ namespace DiIiS_NA.GameServer.GSSystem.ItemsSystem
restrictedFamily.Contains(-812845450) ||
restrictedFamily.Contains(1791554648) ||
restrictedFamily.Contains(125900958)) //MinMaxDam and ele damage
filteredList = filteredList.Where(
a =>
!a.Name.Contains("FireD") &&
{
filteredList = filteredList
.Where(a => !a.Name.Contains("FireD") &&
!a.Name.Contains("PoisonD") &&
!a.Name.Contains("HolyD") &&
!a.Name.Contains("ColdD") &&
!a.Name.Contains("LightningD") &&
!a.Name.Contains("ArcaneD") &&
!a.Name.Contains("MinMaxDam") &&
isCrafting ? !a.Name.ToLower().Contains("socket") : !a.Name.Contains("ASDHUIOPASDHIOU")
);
isCrafting ? !a.Name.ToLower().Contains("socket") : !a.Name.Contains("ASDHUIOPASDHIOU"));
}
}
if (affixesCount <= 1)
@ -321,24 +319,28 @@ namespace DiIiS_NA.GameServer.GSSystem.ItemsSystem
public static int FindSuitableAffix(Item item, int affixGroup, int affixLevel, bool extendedFilter)
{
if (affixGroup == -1) return -1;
var all_group = LegendaryAffixList.Where(a => (a.AffixFamily0 == affixGroup || a.AffixFamily1 == affixGroup) && (Item.Is2H(item.ItemType) ? !a.Name.EndsWith("1h") : (!a.Name.Contains("Two-Handed") && !a.Name.EndsWith("2h"))));
var allGroup = LegendaryAffixList
.Where(a => (a.AffixFamily0 == affixGroup || a.AffixFamily1 == affixGroup) && (Item.Is2H(item.ItemType) ? !a.Name.EndsWith("1h") : (!a.Name.Contains("Two-Handed") && !a.Name.EndsWith("2h"))))
.ToArray();
if (all_group.Count() == 0) return -1;
if (!allGroup.Any()) return -1;
bool secondGroup = (all_group.First().AffixFamily1 == affixGroup);
bool secondGroup = allGroup.First().AffixFamily1 == affixGroup;
var suitable = all_group.Where(a => a.AffixLevel <= affixLevel || affixLevel <= 0);
var suitable = allGroup.Where(a => a.AffixLevel <= affixLevel || affixLevel <= 0).ToArray();
if (suitable.Count() == 0) return -1;
if (!suitable.Any()) return -1;
List<int> itemTypes = ItemGroup.HierarchyToHashList(item.ItemType);
suitable = suitable.Where(a => itemTypes.ContainsAtLeastOne(a.ItemGroup) || (extendedFilter ? itemTypes.ContainsAtLeastOne(a.LegendaryAllowedTypes) : false));
suitable = suitable.Where(a =>
itemTypes.ContainsAtLeastOne(a.ItemGroup) ||
(extendedFilter && itemTypes.ContainsAtLeastOne(a.LegendaryAllowedTypes))).ToArray();
if (suitable.Count() == 0) return -1;
if (!suitable.Any()) return -1;
int suitableAffixLevel = suitable.OrderByDescending(a => a.AffixLevel).First().AffixLevel;
suitable = suitable.Where(a => a.AffixLevel == suitableAffixLevel);
int suitableAffixLevel = suitable.MaxBy(a => a.AffixLevel).AffixLevel;
suitable = suitable.Where(a => a.AffixLevel == suitableAffixLevel).ToArray();
//if (i18 && !secondGroup)
// suitable = suitable.Where(a => a.MaxLevel <= (Program.MaxLevel + 4));
@ -347,8 +349,8 @@ namespace DiIiS_NA.GameServer.GSSystem.ItemsSystem
//else
//suitable = suitable.Where(a => itemTypes.ContainsAtLeastOne(a.I10));
if (suitable.Count() == 0)
suitable = all_group.Where(a => a.AffixLevel == 1);
if (!suitable.Any())
suitable = allGroup.Where(a => a.AffixLevel == 1).ToArray();
/*int suitableMaxLevel = suitable.OrderByDescending(a => a.AffixLevel).First().MaxLevel;
int suitableAffixLevel = suitable.OrderByDescending(a => a.AffixLevel).First().AffixLevel;
@ -361,36 +363,36 @@ namespace DiIiS_NA.GameServer.GSSystem.ItemsSystem
if (suitable.Count() > 1 && i18 && !secondGroup && suitable.Where(a => a.Name.Contains("Secondary")).Count() > 0)
suitable = suitable.Where(a => a.Name.Contains("Secondary"));*/
if (suitable.Count() > 0)
return suitable.ToList()[FastRandom.Instance.Next(0, suitable.Count())].Hash;
else
if (suitable.Any())
return suitable[FastRandom.Instance.Next(0, suitable.Length)].Hash;
return -1;
}
public static void AddAffix(Item item, int AffixGbId, bool findFromTotal = false)
public static void AddAffix(Item item, int affixGbId, bool findFromTotal = false)
{
if (AffixGbId == -1) return;
if (affixGbId == -1) return;
AffixTable definition = null;
if (findFromTotal)
{
definition = AllAffix.Where(def => def.Hash == AffixGbId).FirstOrDefault();
var testc = AllAffix.Where(def => def.ItemGroup[0] == AffixGbId || def.ItemGroup[1] == AffixGbId).FirstOrDefault();
definition = AllAffix.FirstOrDefault(def => def.Hash == affixGbId);
var testc = AllAffix.FirstOrDefault(def => def.ItemGroup[0] == affixGbId || def.ItemGroup[1] == affixGbId);
}
else
{
definition = AffixList.Where(def => def.Hash == AffixGbId).FirstOrDefault();
definition = AffixList.FirstOrDefault(def => def.Hash == affixGbId);
if (definition == null)
{
definition = LegendaryAffixList.Where(def => def.Hash == AffixGbId).FirstOrDefault();
definition = LegendaryAffixList.FirstOrDefault(def => def.Hash == affixGbId);
}
}
if (definition == null)
{
Logger.Warn("Affix {0} was not found!", AffixGbId);
Logger.Warn("Affix {0} was not found!", affixGbId);
return;
}
@ -444,7 +446,7 @@ namespace DiIiS_NA.GameServer.GSSystem.ItemsSystem
}
}
}
var affix = new Affix(AffixGbId);
var affix = new Affix(affixGbId);
affix.Score = (Scores.Count == 0 ? 0 : Scores.Average());
item.AffixList.Add(affix);
//item.Attributes[GameAttribute.Item_Quality_Level]++;

View File

@ -1088,7 +1088,7 @@ namespace DiIiS_NA.GameServer.GSSystem.ItemsSystem
break;
}
it = items[RandomHelper.Next(@base, @base + 1)];
it = items[RandomHelper.Next(@base, @base + 1)]; // FIXME: this random always returns @base
player.Inventory.PickUp(ItemGenerator.Cook(player, it));
break;
case -1249067448:
@ -1102,7 +1102,7 @@ namespace DiIiS_NA.GameServer.GSSystem.ItemsSystem
"Unique_Shoulder_Set_09_x1", "Unique_Boots_Set_09_x1",
"Unique_Shoulder_Set_06_x1", "Unique_Boots_Set_06_x1"
};
it = items[RandomHelper.Next(@base, @base + 1)];
it = items[RandomHelper.Next(@base, @base + 1)]; // FIXME: this random always returns @base
player.Inventory.PickUp(ItemGenerator.Cook(player, it));
break;
case -1249067447:
@ -1116,7 +1116,7 @@ namespace DiIiS_NA.GameServer.GSSystem.ItemsSystem
"Unique_Chest_Set_09_x1", "Unique_Pants_Set_09_x1",
"Unique_Chest_Set_06_x1", "Unique_Pants_Set_06_x1"
};
it = items[RandomHelper.Next(@base, @base + 1)];
it = items[RandomHelper.Next(@base, @base + 1)]; // FIXME: this random always returns @base
player.Inventory.PickUp(ItemGenerator.Cook(player, it));
break;

View File

@ -335,7 +335,7 @@ namespace DiIiS_NA.GameServer.GSSystem.ItemsSystem
data.NumberOfCompletionSteps);
foreach (var step in data.QuestSteps)
{
int nextID = step.StepObjectiveSets.Count() > 0
int nextID = step.StepObjectiveSets.Any()
? step.StepObjectiveSets.First().FollowUpStepID
: -1;
Logger.Info("Step [{0}] {1} -> {2}", step.ID, step.Name, nextID);
@ -1168,7 +1168,7 @@ namespace DiIiS_NA.GameServer.GSSystem.ItemsSystem
//var found = false;
//ItemTable itemDefinition = null;
if (pool.Count() == 0) return null;
if (pool.Count == 0) return null;
List<ItemTable> pool_filtered = pool.Where(it =>
it.SNOActor != -1 &&
it.WeaponDamageMin != 100.0f &&
@ -1222,7 +1222,7 @@ namespace DiIiS_NA.GameServer.GSSystem.ItemsSystem
).ToList();
//*/
if (pool_filtered.Count() == 0) return null;
if (pool_filtered.Count == 0) return null;
ItemTable selected = pool_filtered[FastRandom.Instance.Next(0, pool_filtered.Count() - 1)];
@ -1234,7 +1234,7 @@ namespace DiIiS_NA.GameServer.GSSystem.ItemsSystem
//var found = false;
//ItemTable itemDefinition = null;
if (pool.Count() == 0) return null;
if (pool.Count == 0) return null;
List<ItemTable> pool_filtered = pool.Where(it =>
it.SNOActor != -1 &&
it.WeaponDamageMin != 100.0f &&
@ -1262,7 +1262,7 @@ namespace DiIiS_NA.GameServer.GSSystem.ItemsSystem
(it.Cost == 0)) && // i hope it catches all lore with npc spawned /xsochor
!(!GBIDHandlers.ContainsKey(it.Hash) && !AllowedItemTypes.Contains(it.ItemTypesGBID))
).ToList();
if (pool_filtered.Count() == 0) return null;
if (pool_filtered.Count == 0) return null;
ItemTable selected = pool_filtered[FastRandom.Instance.Next(0, pool_filtered.Count() - 1)];
return selected;

View File

@ -282,7 +282,7 @@ namespace DiIiS_NA.GameServer.GSSystem.MapSystem
BuffManager.Update();
PowerManager.Update();
if (tickCounter % 6 == 0 && _flippyTimers.Count() > 0)
if (tickCounter % 6 == 0 && _flippyTimers.Any())
{
UpdateFlippy(tickCounter);
}
@ -1033,7 +1033,7 @@ namespace DiIiS_NA.GameServer.GSSystem.MapSystem
else
{
_flippyTimers.Dequeue().Dequeue().Invoke();
if (_flippyTimers.Count() > 0)
if (_flippyTimers.Any())
_flippyTimers.Peek().Dequeue().Invoke();
}
}

View File

@ -52,6 +52,7 @@ using DiIiS_NA.GameServer.Core.Types.Math;
using DiIiS_NA.GameServer.MessageSystem.Message.Definitions.Conversation;
//Blizzless Project 2022
using System.Collections.Concurrent;
using DiIiS_NA.Core.Extensions;
//Blizzless Project 2022
using DiIiS_NA.GameServer.MessageSystem.Message.Definitions.Quest;
//Blizzless Project 2022
@ -572,8 +573,7 @@ namespace DiIiS_NA.GameServer.GSSystem.PlayerSystem
}
if (asset.RootTreeNodes[lineIndex].ConvNodeType == 4)
currentLineNode = asset.RootTreeNodes[lineIndex]
.ChildNodes[RandomHelper.Next(asset.RootTreeNodes[lineIndex].ChildNodes.Count)];
currentLineNode = asset.RootTreeNodes[lineIndex].ChildNodes.PickRandom();
else
currentLineNode = asset.RootTreeNodes[lineIndex];

View File

@ -261,7 +261,7 @@ namespace DiIiS_NA.GameServer.GSSystem.PlayerSystem
public Item GetItemByDynId(Player plr, uint dynId)
{
if (Items.Values.Where(it => it.IsRevealedToPlayer(plr) && it.DynamicID(plr) == dynId).Count() > 0)
if (Items.Values.Any(it => it.IsRevealedToPlayer(plr) && it.DynamicID(plr) == dynId))
return Items.Values.Single(it => it.IsRevealedToPlayer(plr) && it.DynamicID(plr) == dynId);
else
return null;

View File

@ -286,9 +286,9 @@ namespace DiIiS_NA.GameServer.GSSystem.PlayerSystem
{
string itemType = originalItem.ItemDefinition.Name.Substring(3);
if (itemType.Contains("1HWeapon"))
itemType = OneHandedWeapons[FastRandom.Instance.Next(OneHandedWeapons.Count())];
itemType = OneHandedWeapons[FastRandom.Instance.Next(OneHandedWeapons.Count)];
if (itemType.Contains("2HWeapon"))
itemType = TwoHandedWeapons[FastRandom.Instance.Next(TwoHandedWeapons.Count())];
itemType = TwoHandedWeapons[FastRandom.Instance.Next(TwoHandedWeapons.Count)];
if (itemType.Contains("Pants"))
itemType = "Legs";
_inventoryGrid.AddItem(ItemGenerator.GetRandomItemOfType(_owner, ItemGroup.FromString(itemType)));
@ -739,15 +739,15 @@ namespace DiIiS_NA.GameServer.GSSystem.PlayerSystem
_owner.GrantAchievement(74987243307126);
var items = GetEquippedItems();
if (items.Where(item => ItemGroup.IsSubType(item.ItemType, "Belt_Barbarian")).Count() > 0 && (items.Where(item => ItemGroup.IsSubType(item.ItemType, "MightyWeapon1H")).Count() > 0 || items.Where(item => ItemGroup.IsSubType(item.ItemType, "MightyWeapon2H")).Count() > 0)) //barb
if (items.Any(item => ItemGroup.IsSubType(item.ItemType, "Belt_Barbarian")) && (items.Any(item => ItemGroup.IsSubType(item.ItemType, "MightyWeapon1H")) || items.Any(item => ItemGroup.IsSubType(item.ItemType, "MightyWeapon2H")))) //barb
_owner.GrantAchievement(74987243307046);
if (items.Where(item => ItemGroup.IsSubType(item.ItemType, "Cloak")).Count() > 0 && items.Where(item => ItemGroup.IsSubType(item.ItemType, "HandXbow")).Count() > 0) //dh
if (items.Any(item => ItemGroup.IsSubType(item.ItemType, "Cloak")) && items.Any(item => ItemGroup.IsSubType(item.ItemType, "HandXbow"))) //dh
_owner.GrantAchievement(74987243307058);
if (items.Where(item => ItemGroup.IsSubType(item.ItemType, "SpiritStone_Monk")).Count() > 0 && (items.Where(item => ItemGroup.IsSubType(item.ItemType, "FistWeapon")).Count() > 0 || items.Where(item => ItemGroup.IsSubType(item.ItemType, "CombatStaff")).Count() > 0)) //monk
if (items.Any(item => ItemGroup.IsSubType(item.ItemType, "SpiritStone_Monk")) && (items.Any(item => ItemGroup.IsSubType(item.ItemType, "FistWeapon")) || items.Any(item => ItemGroup.IsSubType(item.ItemType, "CombatStaff")))) //monk
_owner.GrantAchievement(74987243307544);
if (items.Where(item => ItemGroup.IsSubType(item.ItemType, "VoodooMask")).Count() > 0 && items.Where(item => ItemGroup.IsSubType(item.ItemType, "CeremonialDagger")).Count() > 0 && items.Where(item => ItemGroup.IsSubType(item.ItemType, "Mojo")).Count() > 0) //wd
if (items.Any(item => ItemGroup.IsSubType(item.ItemType, "VoodooMask")) && items.Any(item => ItemGroup.IsSubType(item.ItemType, "CeremonialDagger")) && items.Any(item => ItemGroup.IsSubType(item.ItemType, "Mojo"))) //wd
_owner.GrantAchievement(74987243307561);
if (items.Where(item => ItemGroup.IsSubType(item.ItemType, "WizardHat")).Count() > 0 && items.Where(item => ItemGroup.IsSubType(item.ItemType, "Wand")).Count() > 0 && items.Where(item => ItemGroup.IsSubType(item.ItemType, "Orb")).Count() > 0) //wiz
if (items.Any(item => ItemGroup.IsSubType(item.ItemType, "WizardHat")) && items.Any(item => ItemGroup.IsSubType(item.ItemType, "Wand")) && items.Any(item => ItemGroup.IsSubType(item.ItemType, "Orb"))) //wiz
_owner.GrantAchievement(74987243307582);
}
@ -1099,23 +1099,23 @@ namespace DiIiS_NA.GameServer.GSSystem.PlayerSystem
{
if (client.Game.PvP) return;
if (_owner.IsCasting) _owner.StopCasting();
if (message is InventoryRequestMoveMessage) HandleInventoryRequestMoveMessage(message as InventoryRequestMoveMessage);
else if (message is InventoryRequestQuickMoveMessage) HandleInventoryRequestQuickMoveMessage(message as InventoryRequestQuickMoveMessage);
else if (message is InventorySplitStackMessage) OnInventorySplitStackMessage(message as InventorySplitStackMessage);
else if (message is InventoryStackTransferMessage) OnInventoryStackTransferMessage(message as InventoryStackTransferMessage);
else if (message is InventoryDropItemMessage) OnInventoryDropItemMessage(message as InventoryDropItemMessage);
else if (message is InventoryRequestUseMessage) OnInventoryRequestUseMessage(message as InventoryRequestUseMessage);
else if (message is InventoryRequestSocketMessage) OnSocketMessage(message as InventoryRequestSocketMessage);
else if (message is InventoryGemsExtractMessage) OnGemsExtractMessage(message as InventoryGemsExtractMessage);
else if (message is RequestBuySharedStashSlotsMessage) OnBuySharedStashSlots(message as RequestBuySharedStashSlotsMessage);
else if (message is InventoryIdentifyItemMessage) OnInventoryIdentifyItemMessage(message as InventoryIdentifyItemMessage);
else if (message is InventoryUseIdentifyItemMessage) OnInventoryUseIdentifyItemMessage(message as InventoryUseIdentifyItemMessage);
else if (message is TrySalvageMessage) OnTrySalvageMessage(message as TrySalvageMessage);
else if (message is TrySalvageAllMessage) OnTrySalvageAllMessage(message as TrySalvageAllMessage);
else if (message is CraftItemsMessage) OnCraftItemMessage(client, message as CraftItemsMessage);
else if (message is EnchantAffixMessage) OnEnchantAffixMessage(client, message as EnchantAffixMessage);
else if (message is TryTransmogItemMessage) OnTryTransmogItemMessage(client, message as TryTransmogItemMessage);
else if (message is DyeItemMessage) OnDyeItemMessage(client, message as DyeItemMessage);
if (message is InventoryRequestMoveMessage moveMessage) HandleInventoryRequestMoveMessage(moveMessage);
else if (message is InventoryRequestQuickMoveMessage quickMoveMessage) HandleInventoryRequestQuickMoveMessage(quickMoveMessage);
else if (message is InventorySplitStackMessage stackMessage) OnInventorySplitStackMessage(stackMessage);
else if (message is InventoryStackTransferMessage transferMessage) OnInventoryStackTransferMessage(transferMessage);
else if (message is InventoryDropItemMessage dropItemMessage) OnInventoryDropItemMessage(dropItemMessage);
else if (message is InventoryRequestUseMessage useMessage) OnInventoryRequestUseMessage(useMessage);
else if (message is InventoryRequestSocketMessage socketMessage) OnSocketMessage(socketMessage);
else if (message is InventoryGemsExtractMessage extractMessage) OnGemsExtractMessage(extractMessage);
else if (message is RequestBuySharedStashSlotsMessage slotsMessage) OnBuySharedStashSlots(slotsMessage);
else if (message is InventoryIdentifyItemMessage identifyItemMessage) OnInventoryIdentifyItemMessage(identifyItemMessage);
else if (message is InventoryUseIdentifyItemMessage itemMessage) OnInventoryUseIdentifyItemMessage(itemMessage);
else if (message is TrySalvageMessage salvageMessage) OnTrySalvageMessage(salvageMessage);
else if (message is TrySalvageAllMessage allMessage) OnTrySalvageAllMessage(allMessage);
else if (message is CraftItemsMessage itemsMessage) OnCraftItemMessage(client, itemsMessage);
else if (message is EnchantAffixMessage affixMessage) OnEnchantAffixMessage(client, affixMessage);
else if (message is TryTransmogItemMessage transmogItemMessage) OnTryTransmogItemMessage(client, transmogItemMessage);
else if (message is DyeItemMessage dyeItemMessage) OnDyeItemMessage(client, dyeItemMessage);
else if (message is InventoryRepairAllMessage) RepairAll();
else if (message is InventoryRepairEquippedMessage) RepairEquipment();
@ -1201,6 +1201,7 @@ namespace DiIiS_NA.GameServer.GSSystem.PlayerSystem
if (!ReloadAffix.Definition.Name.Contains("Secondary")) filteredList = filteredList.Where( a => !a.Name.Contains("Secondary") );
if (!ReloadAffix.Definition.Name.Contains("Experience")) filteredList = filteredList.Where(a => !a.Name.Contains("Experience"));
if (!ReloadAffix.Definition.Name.Contains("Archon")) filteredList = filteredList.Where(a => !a.Name.Contains("Archon"));
// FIXME: always true?
if (ReloadAffix.Definition.Hash == ReloadAffix.Definition.Hash) filteredList = filteredList.Where(a => a.Hash != ReloadAffix.Definition.Hash);
if (Item.GBHandle.GBID == -4139386) filteredList = filteredList.Where( a => !a.Name.Contains("Str") && !a.Name.Contains("Dex") && !a.Name.Contains("Int") && !a.Name.Contains("Vit" ));
@ -1218,15 +1219,20 @@ namespace DiIiS_NA.GameServer.GSSystem.PlayerSystem
//if (bestDefinitions.Values.Where(a => a.Name.Contains("PoisonD")).Count() > 0) Logger.Debug("PoisonD in bestDefinitions");
List<AffixTable> selectedGroups = bestDefinitions.Values
.OrderBy(x => FastRandom.Instance.Next()) //random order
.GroupBy(x => (x.AffixFamily1 == -1) ? x.AffixFamily0 : x.AffixFamily1)
.OrderBy(_ => FastRandom.Instance.Next()) //random order
.GroupBy(x => x.AffixFamily1 == -1 ? x.AffixFamily0 : x.AffixFamily1)
.Select(x => x.First()) // only one from group
.Take(1) // take needed amount
.ToList();
if (selectedGroups.Count == 0)
if (ReloadAffix.Definition.Name.ToLower().Contains("socket"))
selectedGroups = SocketsAffixs.Where(x => x.OverrideLevelReq <= ReloadAffix.Definition.AffixLevelMax //&& x.AffixLevelMin == ReloadAffix.Definition.AffixLevelMin
).OrderBy(x => FastRandom.Instance.Next()).Take(1).ToList();
{
selectedGroups = SocketsAffixs
.Where(x => x.OverrideLevelReq <= ReloadAffix.Definition.AffixLevelMax) //&& x.AffixLevelMin == ReloadAffix.Definition.AffixLevelMin
.OrderBy(_ => FastRandom.Instance.Next())
.Take(1)
.ToList();
}
else
return;
@ -2196,9 +2202,9 @@ namespace DiIiS_NA.GameServer.GSSystem.PlayerSystem
public Item GetItemByDynId(Player plr, uint dynId)
{
if (_inventoryGrid.Items.Values.Union(_stashGrid.Items.Values).Union(_equipment.Items.Values).Where(it => it.IsRevealedToPlayer(plr) && it.DynamicID(plr) == dynId).Count() > 0)
if (_inventoryGrid.Items.Values.Union(_stashGrid.Items.Values).Union(_equipment.Items.Values).Any(it => it.IsRevealedToPlayer(plr) && it.DynamicID(plr) == dynId))
return _inventoryGrid.Items.Values.Union(_stashGrid.Items.Values).Union(_equipment.Items.Values).Single(it => it.IsRevealedToPlayer(plr) && it.DynamicID(plr) == dynId);
else
return null;
}
@ -2612,7 +2618,7 @@ namespace DiIiS_NA.GameServer.GSSystem.PlayerSystem
public bool GetItemBonus(GameAttributeB attributeB)
{
return Loaded ? (GetEquippedItems().Where(item => item.Attributes[attributeB] == true).Count() > 0) : _owner.Attributes[attributeB];
return Loaded ? GetEquippedItems().Any(item => item.Attributes[attributeB]) : _owner.Attributes[attributeB];
}
public float GetItemBonus(GameAttributeF attributeF, int attributeKey)

View File

@ -1869,7 +1869,7 @@ public class Player : Actor, IMessageConsumer, IUpdateable
foreach (var oldp in World.GetActorsBySNO(ActorSno._x1_openworld_lootrunportal,
ActorSno._x1_openworld_tiered_rifts_portal)) oldp.Destroy();
map = maps[RandomHelper.Next(0, maps.Length)];
map = maps.PickRandom();
//map = 288823;
newTagMap.Add(new TagKeySNO(526850), new TagMapEntry(526850, (int)map, 0)); //World
newTagMap.Add(new TagKeySNO(526853), new TagMapEntry(526853, 288482, 0)); //Zone
@ -1878,7 +1878,7 @@ public class Player : Actor, IMessageConsumer, IUpdateable
while (true)
{
map = maps[RandomHelper.Next(0, maps.Length)];
map = maps.PickRandom();
if (map != InGameClient.Game.WorldOfPortalNephalem) break;
}
@ -2068,7 +2068,7 @@ public class Player : Actor, IMessageConsumer, IUpdateable
InGameClient.Game.NephalemGreater = true;
//disable banner while greater is active enable once boss is killed or portal is closed /advocaite
Attributes[GameAttribute.Banner_Usable] = false;
map = maps[RandomHelper.Next(0, maps.Length)];
map = maps.PickRandom();
newTagMap.Add(new TagKeySNO(526850), new TagMapEntry(526850, (int)map, 0)); //World
newTagMap.Add(new TagKeySNO(526853), new TagMapEntry(526853, 288482, 0)); //Zone
newTagMap.Add(new TagKeySNO(526851), new TagMapEntry(526851, 172, 0)); //Entry-Pointа
@ -4652,8 +4652,7 @@ public class Player : Actor, IMessageConsumer, IUpdateable
public void GrantAchievement(ulong id)
{
if (_unlockedAchievements.Contains(id)) return;
if (InGameClient.BnetClient.Account.GameAccount.Achievements
.Where(a => a.AchievementId == id && a.Completion != -1).Count() > 0) return;
if (InGameClient.BnetClient.Account.GameAccount.Achievements.Any(a => a.AchievementId == id && a.Completion != -1)) return;
if (_unlockedAchievements.Contains(id)) return;
_unlockedAchievements.Add(id);
try
@ -6130,13 +6129,13 @@ public class Player : Actor, IMessageConsumer, IUpdateable
public int FindFollowerIndex(ActorSno sno)
{
if (HaveFollower(sno))
return _followerIndexes.Where(i => i.Value == sno).FirstOrDefault().Key;
else return 0;
return _followerIndexes.FirstOrDefault(i => i.Value == sno).Key;
return 0;
}
public int CountFollowers(ActorSno sno)
{
return Followers.Values.Where(f => f == sno).Count();
return Followers.Values.Count(f => f == sno);
}
public int CountAllFollowers()

View File

@ -15,6 +15,7 @@ using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using DiIiS_NA.Core.Extensions;
namespace DiIiS_NA.GameServer.GSSystem.PowerSystem.Implementations
{
@ -1544,7 +1545,7 @@ namespace DiIiS_NA.GameServer.GSSystem.PowerSystem.Implementations
if (!targets.Actors.Any()) return;
AttackPayload shock = new AttackPayload(this);
shock.SetSingleTarget(targets.Actors[Rand.Next(targets.Actors.Count())]);
shock.SetSingleTarget(targets.Actors.PickRandom());
shock.Targets.Actors.First().PlayEffectGroup(312568);
shock.AddWeaponDamage(ScriptFormula(21), DamageType.Lightning);
shock.OnHit = (hitPayload) =>

View File

@ -17,6 +17,7 @@ using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using DiIiS_NA.Core.Extensions;
namespace DiIiS_NA.GameServer.GSSystem.PowerSystem.Implementations
{
@ -300,10 +301,7 @@ namespace DiIiS_NA.GameServer.GSSystem.PowerSystem.Implementations
for (int i = 0; i < 8; i++)
{
var targets = GetEnemiesInRadius(User.Position, ScriptFormula(18)).Actors;
Actor target = null;
if (targets.Count() > 0)
target = targets[Rand.Next(targets.Count())];
targets.TryPickRandom(out var target);
var position = target == null ? RandomDirection(User.Position, 1f, 15f) : target.Position;
_CreateArrowPool(ActorSno._demonhunter_rainofarrows_indigo_buff, position, ScriptFormula(16), 2f);

View File

@ -1350,7 +1350,7 @@ namespace DiIiS_NA.GameServer.GSSystem.PowerSystem.Implementations
if (Rune_A > 0) //Barrage
{
if (dash.Targets.Actors.Count() > 0)
if (dash.Targets.Actors.Any())
AddBuff(dash.Targets.GetClosestTo(TargetPosition), new DashingBarrageDotBuff());
}
@ -3114,7 +3114,7 @@ namespace DiIiS_NA.GameServer.GSSystem.PowerSystem.Implementations
Target.Attributes[GameAttribute.Damage_Weapon_Percent_Bonus] -= _unityDamageBonus;
Target.Attributes[GameAttribute.Damage_Percent_All_From_Skills] -= _unityDamageBonus;
_unityDamageBonus = 0.05f * Target.GetActorsInRange<Player>(ScriptFormula(0)).Count();
_unityDamageBonus = 0.05f * Target.GetActorsInRange<Player>(ScriptFormula(0)).Count;
Target.Attributes[GameAttribute.Damage_Weapon_Percent_Bonus] += _unityDamageBonus;
Target.Attributes[GameAttribute.Damage_Percent_All_From_Skills] += _unityDamageBonus;
@ -3657,7 +3657,7 @@ namespace DiIiS_NA.GameServer.GSSystem.PowerSystem.Implementations
if (Rune_B > 0) //Water Ally
{
var targets = GetEnemiesInRadius(petAlly.Position, 20f, 7).Actors;
if (targets.Count() <= 0) yield break;
if (!targets.Any()) yield break;
foreach (var target in targets)
{

View File

@ -17,6 +17,7 @@ using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using DiIiS_NA.Core.Extensions;
namespace DiIiS_NA.GameServer.GSSystem.PowerSystem.Implementations
{
@ -2587,8 +2588,8 @@ namespace DiIiS_NA.GameServer.GSSystem.PowerSystem.Implementations
{
if (Rune_C > 0)
{
int[] Effects = new int[] { 47400, 474402, 474435, 474437, 474453, 474455, 474464, 474466 };
Tar.PlayEffectGroup(Effects[RandomHelper.Next(0, 7)]);
int[] Effects = { 47400, 474402, 474435, 474437, 474453, 474455, 474464, 474466 };
Tar.PlayEffectGroup(Effects[RandomHelper.Next(0, 7)]); // FIXME: looks like we can't pick the last effect
yield return WaitSeconds(0.5f);
WeaponDamage(Tar, Damage, DType);
@ -3300,9 +3301,10 @@ namespace DiIiS_NA.GameServer.GSSystem.PowerSystem.Implementations
Remove();
var newms = payload.Target.GetMonstersInRange(40f);
if (newms.Count > 0)
AddBuff(newms.OrderBy(x => Guid.NewGuid()).Take(1).Single(), new Rune_B_Buff());
if (newms.TryPickRandom(out var target))
{
AddBuff(target, new Rune_B_Buff());
}
}
}
}
@ -4493,8 +4495,9 @@ namespace DiIiS_NA.GameServer.GSSystem.PowerSystem.Implementations
if (projectile.GetMonstersInRange(15f).Count > 0)
{
Founded = true;
var Target = projectile.GetMonstersInRange(25f).OrderBy(x => Guid.NewGuid()).Take(1).Single();
projectile.Launch(Target.Position, 1f);
var possibleTargets = projectile.GetMonstersInRange(25f);
var target = possibleTargets.PickRandom();
projectile.Launch(target.Position, 1f);
}
};
yield break;

View File

@ -2316,7 +2316,7 @@ namespace DiIiS_NA.GameServer.GSSystem.PowerSystem.Implementations
if (!HasBuff<GargantuanEnrageCDBuff>(Target))
{
var targets = GetEnemiesInRadius(Target.Position, 10f);
if (targets.Actors.Count >= 5 || targets.Actors.Where(a => a is Boss || a is Champion || a is Rare || a is Unique).Count() > 1)
if (targets.Actors.Count >= 5 || targets.Actors.Count(a => a is Boss or Champion or Rare or Unique) > 1)
{
AddBuff(Target, new GargantuanEnrageCDBuff());
AddBuff(Target, new GargantuanEnrageBuff());
@ -2704,7 +2704,7 @@ namespace DiIiS_NA.GameServer.GSSystem.PowerSystem.Implementations
if (payload is HitPayload && payload.Target == Target)
{
Player usr = (Target as Player);
float dmg = (payload as HitPayload).TotalDamage * ScriptFormula(9) / usr.Followers.Values.Where(a => a == ActorSno._wd_zombiedog).Count();
float dmg = (payload as HitPayload).TotalDamage * ScriptFormula(9) / usr.Followers.Values.Count(a => a == ActorSno._wd_zombiedog);
(payload as HitPayload).TotalDamage *= 1 - ScriptFormula(9);
//List<Actor> dogs = GetAlliesInRadius(Target.Position, 100f).Actors.Where(a => a.ActorSNO.Id == 51353).ToList();
foreach (var dog in GetAlliesInRadius(Target.Position, 100f).Actors.Where(a => a.SNO == ActorSno._wd_zombiedog))
@ -2738,7 +2738,7 @@ namespace DiIiS_NA.GameServer.GSSystem.PowerSystem.Implementations
if (payload is HitPayload && payload.Context.User == Target)
{
Player master = (Target as ZombieDog).Master as Player;
float heal = (payload as HitPayload).TotalDamage * ScriptFormula(8) / (master.Followers.Values.Where(a => a == ActorSno._wd_zombiedog).Count() + 1);
float heal = (payload as HitPayload).TotalDamage * ScriptFormula(8) / (master.Followers.Values.Count(a => a == ActorSno._wd_zombiedog) + 1);
(payload as HitPayload).TotalDamage *= 1 - ScriptFormula(9);
master.AddHP(heal);
foreach (var dog in GetAlliesInRadius(Target.Position, 100f).Actors.Where(a => a.SNO == ActorSno._wd_zombiedog))

View File

@ -724,7 +724,7 @@ namespace DiIiS_NA.GameServer.GSSystem.PowerSystem.Implementations
Vector3D[] spawnPoints = PowerMath.GenerateSpreadPositions(TgtPosition, TgtPosition + new Vector3D(3f, 0, 0), 120, 3);
for (int i = 0; i < spawnPoints.Count(); i++)
for (int i = 0; i < spawnPoints.Length; i++)
{
if (!User.World.CheckLocationForFlag(spawnPoints[i], DiIiS_NA.Core.MPQ.FileFormats.Scene.NavCellFlags.AllowWalk))
continue;
@ -801,7 +801,7 @@ namespace DiIiS_NA.GameServer.GSSystem.PowerSystem.Implementations
Actor curTarget = target;
Actor nextTarget = null;
var c = 0;
while (targets.Count() < 3)
while (targets.Count < 3)
{
nextTarget = GetEnemiesInRadius(curTarget.Position, 6f).Actors.FirstOrDefault(a => !targets.Contains(a));
if (nextTarget == null) break;
@ -1980,7 +1980,7 @@ namespace DiIiS_NA.GameServer.GSSystem.PowerSystem.Implementations
AddBuff(hitPayload.Target, new ShatterDebuff(User, ScriptFormula(14), WaitSeconds(2f)));
}
if (Rune_E > 0) //Deep Freeze
if (nova.Targets.Actors.Count() > ScriptFormula(13))
if (nova.Targets.Actors.Count > ScriptFormula(13))
if (!HasBuff<DeepFreezeChCBuff>(User))
AddBuff(User, new DeepFreezeChCBuff(ScriptFormula(18), WaitSeconds(ScriptFormula(19))));
};

View File

@ -141,7 +141,7 @@ namespace DiIiS_NA.GameServer.GSSystem.PowerSystem.Payloads
float additionalCritChance = chcBonus;
if (user is Player && (user as Player).SkillSet.HasPassive(338859)) //Single Out
if (target.GetMonstersInRange(20f).Where(m => m != target).Count() == 0)
if (target.GetMonstersInRange(20f).All(m => m == target))
additionalCritChance += 0.25f;
//Wizard -> Spectral Blade -> Ice Blades

View File

@ -256,7 +256,7 @@ namespace DiIiS_NA.GameServer.GSSystem.PowerSystem
var targets = Context.GetEnemiesInRadius(ChainCurrent.Position, ChainRadius);
targets.Actors.Remove(ChainCurrent);
if (targets.Actors.Count() == 0)
if (!targets.Actors.Any())
{
Destroy();
return;
@ -266,7 +266,7 @@ namespace DiIiS_NA.GameServer.GSSystem.PowerSystem
nextProj.Position.Z += 5f;
nextProj.ChainCurrent = ChainCurrent;
nextProj.ChainNextPos = targets.Actors[PowerContext.Rand.Next(targets.Actors.Count())].Position;
nextProj.ChainNextPos = targets.Actors[PowerContext.Rand.Next(targets.Actors.Count)].Position;
nextProj.ChainTargetsRemain = ChainTargetsRemain;
nextProj.ChainIteration = ChainIteration + 1;

View File

@ -56,7 +56,7 @@ namespace DiIiS_NA.GameServer.GSSystem.QuestSystem.QuestEvents.Implementations
for (int i = 0; i < 6; i++)
{
var rand_pos = ActorsVector3D[FastRandom.Instance.Next(ActorsVector3D.Count())];
var rand_pos = ActorsVector3D[FastRandom.Instance.Next(ActorsVector3D.Count)];
world.SpawnMonster(ActorSno._ghost_jail_prisoner, rand_pos);
ActorsVector3D.Remove(rand_pos);
}

View File

@ -106,7 +106,7 @@ namespace DiIiS_NA
var cpuTime = proc.TotalProcessorTime;
var text =
$"{name} | " +
$"{PlayerManager.OnlinePlayers.Count()} onlines in {PlayerManager.OnlinePlayers.Count(s => s.InGameClient?.Player?.World != null)} worlds | " +
$"{PlayerManager.OnlinePlayers.Count} onlines in {PlayerManager.OnlinePlayers.Count(s => s.InGameClient?.Player?.World != null)} worlds | " +
$"Memory: {totalMemory:0.000} GB | " +
$"CPU Time: {cpuTime.ToSmallText()} | " +
$"Uptime: {uptime.ToSmallText()}";