Esempio n. 1
0
 /// <summary>
 /// Initializes a new instance of the <see cref="SearchingPickupEventArgs"/> class.
 /// </summary>
 /// <param name="player"><inheritdoc cref="Player"/></param>
 /// <param name="pickup"><inheritdoc cref="Pickup"/></param>
 /// <param name="searchSession"><inheritdoc cref="SearchSession"/></param>
 /// <param name="searchCompletor"><inheritdoc cref="SearchCompletor"/></param>
 /// <param name="searchTime"><inheritdoc cref="SearchTime"/></param>
 public SearchingPickupEventArgs(Player player, ItemPickupBase pickup, SearchSession searchSession, SearchCompletor searchCompletor, float searchTime)
 {
     Player          = player;
     Pickup          = Pickup.Get(pickup);
     SearchSession   = searchSession;
     SearchCompletor = searchCompletor;
     SearchTime      = searchTime;
     IsAllowed       = searchCompletor.ValidateStart();
 }
Esempio n. 2
0
        private static bool Prefix(SearchCoordinator __instance, ref bool __result, out SearchSession?session, out SearchCompletor completor)
        {
            try
            {
                SearchRequest request = __instance.SessionPipe.Request;

                SearchingPickupEventArgs ev = new(Player.Get(__instance.Hub), request.Target, request.Body, SearchCompletor.FromPickup(__instance, request.Target, __instance.ServerMaxRayDistanceSqr), request.Target.SearchTimeForPlayer(__instance.Hub));
                Handlers.Player.OnSearchPickupRequest(ev);

                completor = ev.SearchCompletor;
                if (!ev.IsAllowed)
                {
                    session   = null;
                    completor = null;
                    __result  = true;
                    return(false);
                }

                SearchSession body = ev.SearchSession;
                if (!__instance.isLocalPlayer)
                {
                    double num        = NetworkTime.time - request.InitialTime;
                    double num2       = LiteNetLib4MirrorServer.Peers[__instance.connectionToClient.connectionId].Ping * 0.001 * __instance.serverDelayThreshold;
                    float  searchTime = ev.SearchTime;
                    if (num < 0.0 || num2 < num)
                    {
                        body.InitialTime = NetworkTime.time - num2;
                        body.FinishTime  = body.InitialTime + searchTime;
                    }
                    else if (Math.Abs(body.FinishTime - body.InitialTime - searchTime) > 0.001)
                    {
                        body.FinishTime = body.InitialTime + searchTime;
                    }
                }

                session  = body;
                __result = true;
                return(false);
            }
            catch (Exception exception)
            {
                Log.Error($"{typeof(SearchingPickupEvent).FullName}.{nameof(Prefix)}:\n{exception}");
                session   = null;
                completor = null;
                return(true);
            }
        }