Exemplo n.º 1
0
        public void SpawnOwnVehicle(IPlayer player, int vehicleId)
        {
            VehicleEntity   spawnedVehicle  = EntityHelper.GetSpawnedVehicleById(vehicleId);
            CharacterEntity characterEntity = player.GetAccountEntity().characterEntity;

            if (characterEntity == null)
            {
                return;
            }


            if (spawnedVehicle != null)
            {
                if (player.Vehicle == spawnedVehicle.GameVehicle)
                {
                    player.SendErrorNotify(null, $"Aby odpspawnić pojazd musisz z niego wyjść");
                    return;
                }

                if (spawnedVehicle.TrunkOpen)
                {
                    player.SendErrorNotify(null, "Aby odspawnić pojazd musisz zamknąć bagażnik");
                    return;
                }

                if (spawnedVehicle.IsGroupVehicle)
                {
                    if (characterEntity.OnDutyGroup == null)
                    {
                        player.SendChatMessageError("Musisz być na służbie, aby zrespić pojazd");
                        return;
                    }

                    if (characterEntity.OnDutyGroup != spawnedVehicle.GroupOwner)
                    {
                        player.SendChatMessageError("Ten pojazd nie należy do tej grupy");
                        return;
                    }

                    GroupWorkerModel worker = characterEntity.OnDutyGroup.DbModel.Workers.First(c => c.CharacterId == characterEntity.DbModel.Id);
                    if (!characterEntity.OnDutyGroup.CanPlayerVehicle(worker))
                    {
                        player.SendChatMessageError("Nie masz uprawnień do chowania pojazdów w tej grupie");
                        return;
                    }

                    spawnedVehicle.GroupOwner = null;
                }
                else
                {
                    player.GetAccountEntity().characterEntity.RespawnVehicleCount--;
                }

                spawnedVehicle.Dispose();

                player.SendSuccessNotify(null, $"Twój pojazd o ID {spawnedVehicle.DbModel.Id} został odspawniony");

                return;
            }

            VehicleEntity vehicle = new VehicleEntity(EntityHelper.GetVehicleDatabaseById(vehicleId));

            //vehicle.Spawn();


            if (vehicle.IsGroupVehicle)
            {
                if (characterEntity.OnDutyGroup == null)
                {
                    player.SendChatMessageError("Musisz być na służbie, aby zrespić pojazd");
                    return;
                }

                if (characterEntity.OnDutyGroup.DbModel.Id != vehicle.DbModel.GroupId)
                {
                    player.SendChatMessageError("Ten pojazd nie należy do tej grupy");
                    return;
                }

                GroupWorkerModel worker = characterEntity.OnDutyGroup.DbModel.Workers.FirstOrDefault(c => c.CharacterId == characterEntity.DbModel.Id);
                if (!characterEntity.OnDutyGroup.CanPlayerVehicle(worker))
                {
                    player.SendChatMessageError("Nie masz uprawnień do respienia pojazdów w tej grupie");
                    return;
                }

                vehicle.Spawn();
                vehicle.GroupOwner = characterEntity.OnDutyGroup;
            }
            else
            {
                if (characterEntity.RespawnVehicleCount > 3 && !player.GetAccountEntity().HasPremium)
                {
                    if (player.GetAccountEntity().OnAdminDuty)
                    {
                        return;
                    }

                    player.SendErrorNotify(null, $"Aby zrespić więcej niż 3 pojazdy musisz posiadać premium");
                    //vehicle.Dispose();
                    return;
                }

                vehicle.Spawn();
                characterEntity.RespawnVehicleCount++;
            }


            player.SendSuccessNotify(null, $"Twój pojazd o ID {vehicle.DbModel.Id} został zespawniony");
        }