protected override async Task OnExecuteAsync()
        {
            UnturnedUser user = (UnturnedUser)Context.Actor;
            uint         id   = await Context.Parameters.GetAsync <uint>(1);

            string vic = await Context.Parameters.GetAsync <string>(0);

            Player player = PlayerTool.getPlayer(vic);

            if (player == null)
            {
                await user.PrintMessageAsync(m_StringLocalizer["translations:player_notfound"], System.Drawing.Color.Red, false, "");
            }
#pragma warning disable CS8602
            UnturnedUser?victim = (UnturnedUser?)await m_UserManager.FindUserAsync(KnownActorTypes.Player, player.channel.owner.playerID.steamID.ToString(), UserSearchMode.FindById);

#pragma warning restore CS8602
            if (victim == null)
            {
                await user.PrintMessageAsync(m_StringLocalizer["translations:player_notfound"], System.Drawing.Color.Red, false, "");
            }
            else if (victim == user)
            {
                await user.PrintMessageAsync(m_StringLocalizer["translations:yourself_error"], System.Drawing.Color.Red, false, "");
            }
            else if (victim != null && user != null)
            {
                PlayerBunch?userBunch = await m_KeysManager.TryGetPlayerBunch(user.Id);

                PlayerBunch?victimBunch = await m_KeysManager.TryGetPlayerBunch(victim.Id);

                if (userBunch != null && victimBunch != null)
                {
                    if (!userBunch.VehiclesKey.Any(v => v.InstanceId == id))
                    {
                        if (victimBunch.VehiclesKey.Count >= (victimBunch.MaxKeys - 1))
                        {
                            await user.PrintMessageAsync(m_StringLocalizer["translations:victim_maxkeys"]);
                        }
                        else
                        {
                            var vehicleKey = await m_KeysManager.TransferVehicle(user.Id, victim.Id, id);

                            await user.PrintMessageAsync(m_StringLocalizer["translations:user_vehicle_transfer", new { vehicle = vehicleKey.VehicleName, victim = victim.DisplayName }], System.Drawing.Color.Green);

                            await victim.PrintMessageAsync(m_StringLocalizer["translations:victim_vehicle_transfer", new { vehicle = vehicleKey.VehicleName, user = user.DisplayName }], System.Drawing.Color.Green);
                        }
                    }
                    else
                    {
                        await user.PrintMessageAsync(m_StringLocalizer["translations:no_vehicle", new { vehicleID = id }]);
                    }
                }
            }
            else
            {
                throw new UserFriendlyException("Internal error!");
            }
        }
Exemplo n.º 2
0
        protected override async Task OnExecuteAsync()
        {
            UnturnedUser user = (UnturnedUser)Context.Actor;
            uint         id   = await Context.Parameters.GetAsync <uint>(0);

            PlayerBunch?pBunch = await m_KeysManager.TryGetPlayerBunch(user.SteamId.ToString());

            if (pBunch == null || pBunch.VehiclesKey.Count == 0)
            {
                await user.PrintMessageAsync(m_StringLocalizer["translations:no_key"], System.Drawing.Color.Red, false, "");
            }
            else if (!pBunch.VehiclesKey.Any(v => v.InstanceId == id))
            {
                InteractableVehicle vehicle = VehicleManager.findVehicleByNetInstanceID(id);
                if (vehicle != null && !vehicle.isExploded && !vehicle.isDead)
                {
                    await UniTask.SwitchToMainThread();

                    await user.PrintMessageAsync(m_StringLocalizer["translations:vehicle_position", new { vehicle = pBunch.VehiclesKey.Where(z => z.InstanceId == id).First().VehicleName }], System.Drawing.Color.Green);

                    user.Player.Player.quests.replicateSetMarker(true, vehicle.transform.position, "Your vehicle!");
                }
                else
                {
                    await user.PrintMessageAsync(m_StringLocalizer["translations:vehicle_explode"]);

                    await m_KeysManager.TryRemoveKeyFromBunch(user.SteamId.ToString(), id);
                }
            }
            else
            {
                await user.PrintMessageAsync(m_StringLocalizer["translations:no_vehicle", new { vehicleID = id }]);
            }
        }
Exemplo n.º 3
0
        protected override async Task OnExecuteAsync()
        {
            UnturnedUser user = (UnturnedUser)Context.Actor;

            PlayerBunch?pBunch = await m_KeysManager.TryGetPlayerBunch(user.SteamId.ToString());

            if (pBunch == null || pBunch.VehiclesKey.Count == 0)
            {
                await user.PrintMessageAsync(m_StringLocalizer["translations:no_key"], System.Drawing.Color.Red, false, "");
            }
            else
            {
                await user.PrintMessageAsync(m_StringLocalizer["translations:your_keys"]);

                for (int i = 0; i < pBunch.VehiclesKey.Count; i++)
                {
                    await user.PrintMessageAsync($"{pBunch.VehiclesKey[i].VehicleName} - {pBunch.VehiclesKey[i].InstanceId}", System.Drawing.Color.FromName(m_Configuration.GetSection("configuration:keys_message_color").Get <string>()), false, "");
                }
            }
        }
Exemplo n.º 4
0
        private void Patch_OnPlayerLockVehicle(Steamworks.CSteamID steamId, uint instanceId, bool locked)
        {
            if (!locked || Provider.server == steamId)
            {
                return;
            }
            AsyncHelper.RunSync(async() =>
            {
                var pBunch = await m_KeysManager.TryGetPlayerBunch(steamId.ToString());
                var user   = PlayerTool.getPlayer(steamId);
                InteractableVehicle vehicle = VehicleManager.findVehicleByNetInstanceID(instanceId);
                if (pBunch != null)
                {
                    if (locked)
                    {
                        if (pBunch.VehiclesKey.Count >= m_Configuration.GetSection("configuration:max_keys").Get <int>())
                        {
                            await UniTask.SwitchToMainThread();
                            VehicleManager.instance.channel.send("tellVehicleLock", ESteamCall.ALL, ESteamPacket.UPDATE_RELIABLE_BUFFER, new object[]
                            {
                                instanceId,
                                steamId,
                                user.quests.groupID,
                                false
                            });

                            ChatManager.say(steamId, m_StringLocalizer["translations:max_keys_reach"], Color.red, EChatMode.SAY, false);
                        }
                        else
                        {
                            await m_KeysManager.TryAddKeyToBunch(steamId.ToString(), new Key {
                                InstanceId = instanceId, VehicleName = vehicle.asset.name
                            });
                            await UniTask.SwitchToMainThread();
                            ChatManager.say(steamId, m_StringLocalizer["translations:vehicle_added", new { vehicleId = instanceId, vehicle = vehicle.asset.name }], Color.red, EChatMode.SAY, false);
                        }
                    }
                }
            });
        }