mirror of
https://github.com/misternebula/quantum-space-buddies.git
synced 2025-01-26 18:35:34 +00:00
Merge pull request #206 from Raicuparta/alek/net-changes-stuff
some stuff
This commit is contained in:
commit
66a7c7a915
@ -2,7 +2,6 @@
|
||||
using QSB.Messaging;
|
||||
using QSB.TransformSync;
|
||||
using QSB.Utility;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using UnityEngine.Networking;
|
||||
@ -42,11 +41,7 @@ namespace QSB
|
||||
|
||||
public static bool PlayerExists(uint id)
|
||||
{
|
||||
if (id == uint.MaxValue)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return PlayerList.Any(x => x.PlayerId == id);
|
||||
return id != uint.MaxValue && PlayerList.Any(x => x.PlayerId == id);
|
||||
}
|
||||
|
||||
public static void HandleFullStateMessage(PlayerStateMessage message)
|
||||
@ -102,20 +97,8 @@ namespace QSB
|
||||
|
||||
public static List<uint> GetPlayerNetIds(PlayerInfo player)
|
||||
{
|
||||
var ints = Enumerable.Range((int)player.PlayerId, PlayerSyncObjects.DistinctBy(x => x.AttachedNetId).Count(x => x.Player.PlayerId == player.PlayerId)).Select(x => (uint)x).ToList();
|
||||
return ints;
|
||||
}
|
||||
|
||||
private static IEnumerable<TSource> DistinctBy<TSource, TKey>(this IEnumerable<TSource> source, Func<TSource, TKey> keySelector)
|
||||
{
|
||||
var seenKeys = new HashSet<TKey>();
|
||||
foreach (var element in source)
|
||||
{
|
||||
if (seenKeys.Add(keySelector(element)))
|
||||
{
|
||||
yield return element;
|
||||
}
|
||||
}
|
||||
var count = PlayerSyncObjects.DistinctBy(x => x.AttachedNetId).Count(x => x.Player.PlayerId == player.PlayerId);
|
||||
return Enumerable.Range((int)player.PlayerId, count).Select(x => (uint)x).ToList();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -164,6 +164,7 @@
|
||||
<Compile Include="TransformSync\QSBSectorManager.cs" />
|
||||
<Compile Include="TransformSync\TransformSync.cs" />
|
||||
<Compile Include="Utility\GOExtensions.cs" />
|
||||
<Compile Include="Utility\ListExtensions.cs" />
|
||||
<Compile Include="WorldSync\BoolWorldObjectMessage.cs" />
|
||||
<Compile Include="WorldSync\WorldObjectMessage.cs" />
|
||||
<Compile Include="Tools\QSBFlashlight.cs" />
|
||||
|
20
QSB/Utility/ListExtensions.cs
Normal file
20
QSB/Utility/ListExtensions.cs
Normal file
@ -0,0 +1,20 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace QSB.Utility
|
||||
{
|
||||
public static class ListExtensions
|
||||
{
|
||||
public static IEnumerable<TSource> DistinctBy<TSource, TKey>(this IEnumerable<TSource> source, Func<TSource, TKey> keySelector)
|
||||
{
|
||||
var seenKeys = new HashSet<TKey>();
|
||||
foreach (var element in source)
|
||||
{
|
||||
if (seenKeys.Add(keySelector(element)))
|
||||
{
|
||||
yield return element;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user