Exemple #1
0
        public void SpawnPet(UnturnedPlayer player, PlayerPet pet)
        {
            foreach (var activePet in GetPlayerActivePets(player.Id).ToArray())
            {
                InvokeKillPet(activePet);
            }

            var point = player.Position;

            AnimalManager.spawnAnimal(pet.AnimalId, point, player.Player.transform.rotation);

            // remove animal spawn
            AnimalManager.packs.RemoveAll(x => x.spawns.Exists(y => y.point == point));


            // I know it's crap and but that's the simplest way atm, please pr if you know better
            var animals = new List <Animal>();

            AnimalManager.getAnimalsInRadius(player.Position, 1, animals);

            pet.Animal = animals.FirstOrDefault(x => x.asset.id == pet.AnimalId);
            pet.Player = player.Player;

            ActivePets.Add(pet);
            OnPetSpawned.TryInvoke(pet);
        }
Exemple #2
0
        private IEnumerator KillPet(PlayerPet pet)
        {
            RemovePet(pet);

            yield return(new WaitForSeconds(killSecondsDelay));

            SendDeadPet(pet);
        }
        public void SpawnPet(UnturnedPlayer player, PlayerPet pet)
        {
            foreach (var activePet in GetPlayerActivePets(player.Id).ToArray())
            {
                KillPet(activePet);
            }

            pet.Animal = AnimalsHelper.SpawnAnimal(pet.AnimalId, player.Position, (byte)player.Rotation);
            pet.Player = player.Player;
            ActivePets.Add(pet);
            OnPetSpawned.TryInvoke(pet);
        }
        public void SpawnCommand(UnturnedPlayer player, PetConfig config)
        {
            var       pets = pluginInstance.PetsService.GetPlayerActivePets(player.Id);
            PlayerPet pet;

            if (pets != null && pets.Count() > 0)
            {
                pet = pets.FirstOrDefault(x => x.AnimalId == config.Id);

                if (pet != null)
                {
                    pluginInstance.PetsService.KillPet(pet);
                    pluginInstance.ReplyPlayer(player, "PetDespawnSuccess", config.Name);
                    return;
                }
            }

            RunAsync(() =>
            {
                pet = pluginInstance.Database.GetPlayerPets(player.Id).FirstOrDefault(x => x.AnimalId == config.Id);

                if (pet == null && player.HasPermission($"pet.own.{config.Name}"))
                {
                    pet = new PlayerPet()
                    {
                        AnimalId = config.Id,
                        PlayerId = player.Id
                    };
                }

                if (pet != null)
                {
                    TaskDispatcher.QueueOnMainThread(() =>
                    {
                        pluginInstance.PetsService.SpawnPet(player, pet);
                        pluginInstance.ReplyPlayer(player, "PetSpawnSuccess", config.Name);
                    });
                }
                else
                {
                    pluginInstance.ReplyPlayer(player, "PetSpawnFail", config.Name);
                }
            });
        }
        public void AddPlayerPet(PlayerPet playerPet)
        {
            const string sql = "INSERT INTO PlayersPetsTable (PlayerId, AnimalId, PurchaseDate) VALUES (@PlayerId, @AnimalId, @PurchaseDate);";

            connection.Execute(Query(sql), playerPet);
        }
Exemple #6
0
 public void AddPlayerPet(PlayerPet playerPet)
 {
     playerPet.Id = GetIDForPet();
     playersPets.Add(playerPet);
     DataStorage.Save(playersPets);
 }
Exemple #7
0
 private void SendDeadPet(PlayerPet pet)
 {
     AnimalsHelper.KillAnimal(pet.Animal);
 }
Exemple #8
0
 private void RemovePet(PlayerPet pet)
 {
     pet.Animal.transform.position = undergroundPosition;
     ActivePets.Remove(pet);
     OnPetDespawned.TryInvoke(pet);
 }
Exemple #9
0
 public void InvokeKillPet(PlayerPet pet)
 {
     StartCoroutine(KillPet(pet));
 }
 public void KillPet(PlayerPet pet)
 {
     AnimalsHelper.KillAnimal(pet.Animal);
     ActivePets.Remove(pet);
     OnPetDespawned.TryInvoke(pet);
 }