Пример #1
0
    private void DefautKittySelection()
    {
        var        kitties       = KittyService.GetAll();
        bool       kittySelected = false;
        KittyModel kittyUnlocked = null;

        foreach (var kitty in kitties)
        {
            if (kitty.isSelected)
            {
                kittySelected = true;
            }
            if (kittyUnlocked == null && kitty.isUnlocked)
            {
                kittyUnlocked = kitty;
            }
        }
        if (!kittySelected)
        {
            if (kittyUnlocked != null)
            {
                // set first kitty found that's unlocked to selected status
                kittyUnlocked.isSelected = true;
            }
            else
            {
                // set random kitty to unlocked and selected
                int randomKittyIndex = Random.Range(0, kitties.Count);
                var randomKitty      = kitties[randomKittyIndex];
                randomKitty.isUnlocked = true;
                randomKitty.isSelected = true;
            }
        }
        KittyService.SaveMultiple(kitties);
    }
Пример #2
0
    private void KittyAccessoryStartupProcesses()
    {
        var kittyModels     = KittyService.GetAll();
        var accessoryModels = AccessoryService.GetAll();
        // create the kitty-accessory models if they don't yet exist
        var kittyAccessoriesToSave = new List <KittyAccessoryModel>();

        foreach (var kittyModel in kittyModels)
        {
            foreach (var accessoryModel in accessoryModels)
            {
                var kittyAccessoryModel =
                    KittyAccessoryService.GetModelByKittyAndAccessoryCombination(
                        kittyModel,
                        accessoryModel
                        );
                if (kittyAccessoryModel == null)
                {
                    kittyAccessoryModel = new KittyAccessoryModel(
                        kittyModel.id,
                        accessoryModel.id,
                        accessoryModel.accessoryGroup,
                        accessoryModel.accessorySubGroup,
                        false,
                        false
                        );
                    kittyAccessoriesToSave.Add(kittyAccessoryModel);
                }
            }
        }
        // insert kitty-accessories to be saved
        KittyAccessoryService.SaveMultiple(kittyAccessoriesToSave);
    }
Пример #3
0
    // chose, at random, one item among the
    // locked accessories and locked kitties for unlock
    private void UnlockRandomKittyOrAccessory()
    {
        // chance list for calculating selection of kitty or accessory for unlock
        var selectBetweenList = new List <int>();
        // gather objects
        var allKitties          = KittyService.GetAll();
        var selectedKitty       = KittyService.GetSelected();
        var accessoriesForKitty = AccessoryService.GetAccessoriesForKitty(selectedKitty);
        // filter for locked kitties and accessories
        var lockedKitties = new List <KittyModel>();

        foreach (var kitty in allKitties)
        {
            if (!kitty.isUnlocked)
            {
                lockedKitties.Add(kitty);
                selectBetweenList.Add(1);
            }
        }
        var lockedAccessoriesForKitty = new List <AccessoryModel>();

        foreach (var accessory in accessoriesForKitty)
        {
            var kittyAccessory = KittyAccessoryService.GetModelByKittyAndAccessoryCombination(
                selectedKitty,
                accessory
                );
            if (!kittyAccessory.isUnlocked)
            {
                lockedAccessoriesForKitty.Add(accessory);
                selectBetweenList.Add(2);
            }
        }
        // select whether kitty or accessory will be unlocked
        int randomSelectionIndex = Random.Range(0, selectBetweenList.Count);
        int selectedType         = selectBetweenList[randomSelectionIndex];

        if (selectedType == 1)
        {
            // unlock random locked kitty
            randomSelectionIndex               = Random.Range(0, lockedKitties.Count);
            this.unlockedKittyModel            = lockedKitties[randomSelectionIndex];
            this.unlockedKittyModel.isUnlocked = true;
            KittyService.Save(this.unlockedKittyModel);
        }
        else
        {
            // unlock random accessory for kitty
            randomSelectionIndex        = Random.Range(0, lockedAccessoriesForKitty.Count);
            this.unlockedAccessoryModel = lockedAccessoriesForKitty[randomSelectionIndex];
            var kittyAccessoryToUnlock = KittyAccessoryService.GetModelByKittyAndAccessoryCombination(
                selectedKitty,
                this.unlockedAccessoryModel
                );
            kittyAccessoryToUnlock.isUnlocked = true;
            KittyAccessoryService.Save(kittyAccessoryToUnlock);
        }
    }
Пример #4
0
 public static KittyModel GetSelected()
 {
     foreach (var model in KittyService.GetAll())
     {
         if (model.isSelected)
         {
             return(model);
         }
     }
     return(null);
 }
Пример #5
0
 public static KittyModel GetModelById(string id)
 {
     foreach (var model in KittyService.GetAll())
     {
         if (id == model.id)
         {
             return(model);
         }
     }
     return(null);
 }
Пример #6
0
    // UNITY HOOKS

    void Start()
    {
        List <KittyModel> kitties = KittyService.GetAll();
        bool viewAll = GameManager.instance.adminControl.showAllKittiesAndAccessories;

        Debug.Log("View all kitties: " + viewAll.ToString());
        foreach (var kittyModel in kitties)
        {
            if (kittyModel.isUnlocked || viewAll)
            {
                GameObject kittyScrollContentItem = Instantiate(
                    kittyScrollContentItemPrefab,
                    scrollContent.transform
                    );
                Sprite sprite = AssetService.GetSprite(kittyModel.thumbAssetAddress);
                var    script = kittyScrollContentItem.GetComponent <KittyScrollContentItemScript>();
                script.kittyImage.sprite = sprite;
                script.kittyModel        = kittyModel;
            }
        }
    }