public static void BuyCommand(UnturnedPlayer player, PetConfig config)
        {
            if (!player.HasPermission(config.Permission) && !player.IsAdmin && !string.IsNullOrEmpty(config.Permission))
            {
                pluginInstance.ReplyPlayer(player, "PetBuyNoPermission", config.Name);
                return;
            }

            if (pluginInstance.Database.GetPlayerPets(player.Id).Any(x => x.AnimalId == config.Id))
            {
                pluginInstance.ReplyPlayer(player, "PetBuyAlreadyHave", config.Name);
                return;
            }

            TaskDispatcher.QueueOnMainThread(() =>
            {
                if (UconomyHelper.GetPlayerBalance(player.Id) < config.Cost)
                {
                    pluginInstance.ReplyPlayer(player, "PetCantAfford", config.Name, config.Cost);
                    return;
                }

                UconomyHelper.IncreaseBalance(player.Id, config.Cost * -1);
                RunAsync(() =>
                {
                    pluginInstance.Database.AddPlayerPet(new PlayerPet()
                    {
                        AnimalId     = config.Id,
                        PlayerId     = player.Id,
                        PurchaseDate = DateTime.UtcNow
                    });
                });
                pluginInstance.ReplyPlayer(player, "PetBuySuccess", config.Name, config.Cost);
            });
        }
        private static bool TryGetPetConfig(IRocketPlayer caller, string value, out PetConfig config)
        {
            config = null;
            if (value == null)
            {
                pluginInstance.ReplyPlayer(caller, "PetNameRequired", value);
                return(false);
            }

            config = pluginInstance.Configuration.Instance.Pets.FirstOrDefault(x => x.Name.Equals(value, StringComparison.OrdinalIgnoreCase));
            if (config == null)
            {
                pluginInstance.ReplyPlayer(caller, "PetNotFound", value);
                return(false);
            }
            return(true);
        }
        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);
                }
            });
        }
Example #4
0
 public override int getFightUnitID()
 {
     return(PetConfig.get(id).fightUnitID);
 }
Example #5
0
 private static bool LoadPetMgr(Dictionary <string, PetConfig> Config, Dictionary <int, PetLevel> Level, Dictionary <int, PetSkillElementInfo> SkillElement, Dictionary <int, PetSkillInfo> Skill, Dictionary <int, PetSkillTemplateInfo> SkillTemplate, Dictionary <int, PetTemplateInfo> TemplateId)
 {
     using (PlayerBussiness playerBussiness = new PlayerBussiness())
     {
         PetConfig[]            allPetConfig            = playerBussiness.GetAllPetConfig();
         PetLevel[]             allPetLevel             = playerBussiness.GetAllPetLevel();
         PetSkillElementInfo[]  allPetSkillElementInfo  = playerBussiness.GetAllPetSkillElementInfo();
         PetSkillInfo[]         allPetSkillInfo         = playerBussiness.GetAllPetSkillInfo();
         PetSkillTemplateInfo[] allPetSkillTemplateInfo = playerBussiness.GetAllPetSkillTemplateInfo();
         PetTemplateInfo[]      allPetTemplateInfo      = playerBussiness.GetAllPetTemplateInfo();
         PetConfig[]            array = allPetConfig;
         for (int i = 0; i < array.Length; i++)
         {
             PetConfig petConfig = array[i];
             if (!Config.ContainsKey(petConfig.Name))
             {
                 Config.Add(petConfig.Name, petConfig);
             }
         }
         PetLevel[] array2 = allPetLevel;
         for (int j = 0; j < array2.Length; j++)
         {
             PetLevel petLevel = array2[j];
             if (!Level.ContainsKey(petLevel.Level))
             {
                 Level.Add(petLevel.Level, petLevel);
             }
         }
         PetSkillElementInfo[] array3 = allPetSkillElementInfo;
         for (int k = 0; k < array3.Length; k++)
         {
             PetSkillElementInfo petSkillElementInfo = array3[k];
             if (!SkillElement.ContainsKey(petSkillElementInfo.ID))
             {
                 SkillElement.Add(petSkillElementInfo.ID, petSkillElementInfo);
             }
         }
         PetSkillTemplateInfo[] array4 = allPetSkillTemplateInfo;
         for (int l = 0; l < array4.Length; l++)
         {
             PetSkillTemplateInfo petSkillTemplateInfo = array4[l];
             if (!SkillTemplate.ContainsKey(petSkillTemplateInfo.ID))
             {
                 SkillTemplate.Add(petSkillTemplateInfo.ID, petSkillTemplateInfo);
             }
         }
         PetTemplateInfo[] array5 = allPetTemplateInfo;
         for (int m = 0; m < array5.Length; m++)
         {
             PetTemplateInfo petTemplateInfo = array5[m];
             if (!TemplateId.ContainsKey(petTemplateInfo.ID))
             {
                 TemplateId.Add(petTemplateInfo.ID, petTemplateInfo);
             }
         }
         PetSkillInfo[] array6 = allPetSkillInfo;
         for (int n = 0; n < array6.Length; n++)
         {
             PetSkillInfo petSkillInfo = array6[n];
             if (!Skill.ContainsKey(petSkillInfo.ID))
             {
                 Skill.Add(petSkillInfo.ID, petSkillInfo);
             }
         }
     }
     return(true);
 }