Esempio n. 1
0
    public DogDescriptor[] GetInOrderDogList(
        int count,
        bool skipAdopted,
        int startIndex     = 0,
        int maxMasterIndex = int.MaxValue)
    {
        DogDescriptor[] dogList             = new DogDescriptor[count];
        int             endIndex            = startIndex + count - ZERO_INDEX_OFFSET;
        int             indexInMasterDogArr = startIndex;

        for (int i = startIndex; i <= endIndex; i++)
        {
            if (ArrayUtil.InRange(this.dogs, indexInMasterDogArr))
            {
                do
                {
                    if (indexInMasterDogArr < maxMasterIndex)
                    {
                        dogList[i] = this.dogs[indexInMasterDogArr];
                    }
                    else
                    {
                        dogList[i] = DogDescriptor.Default();
                    }
                }while(skipAdopted &&
                       ArrayUtil.InRange(this.dogs, indexInMasterDogArr) &&
                       dataController.CheckIsAdopted(this.dogs[indexInMasterDogArr++]));
            }
            else
            {
                dogList[i] = DogDescriptor.Default();
            }
        }
        return(dogList);
    }
Esempio n. 2
0
    WeightedRandomBuffer <CurrencyData> getDogSpecialGiftChances(DogDescriptor dog)
    {
        float affectionFraction;

        /*
         * Affection determines whether dog can return souvenir
         * IF dog already hsa souvenir, assume affection is 0
         * (no chance of returning souvenir)
         */
        if (eligibleForSouvenir(dog))
        {
            affectionFraction = dog.FractionOfMaxAffection;
        }
        else
        {
            affectionFraction = k.NONE_VALUE;
        }
        CurrencyData[] specialGiftOptions = giftFactory.CreateGroup(tuning.SpecialGiftTypes);
        float[]        specialGiftOdds    = new float[specialGiftOptions.Length];
        for (int i = 0; i < specialGiftOdds.Length; i++)
        {
            specialGiftOdds[i] = Mathf.Lerp(
                tuning.SpecialGiftMinAffectionChances[i],
                tuning.SpecialGiftMaxAffectionChances[i],
                affectionFraction);
            // Check to prevent a DogVoucher from being given out if all dogs have already been adopted:
            if (specialGiftOptions[i] is DogVoucherData && dataController.AllDogsAdopted(DogDatabase.GetInstance))
            {
                specialGiftOdds[i] = k.NONE_VALUE;
            }
        }
        return(new WeightedRandomBuffer <CurrencyData>(specialGiftOptions, specialGiftOdds));
    }
Esempio n. 3
0
    Dog[] chooseDogs(int numOfOpenSpots)
    {
        DogFactory factory = new DogFactory(hideGameObjects: true);

        Dog[]           dogs      = new Dog[numOfOpenSpots];
        DogDescriptor[] inRoom    = dataController.DogsInRoom(this.room);
        DogDescriptor[] available = dataController.AvailableDogs;
        for (int i = 0; i < numOfOpenSpots; i++)
        {
            int indexInAvailable = i - inRoom.Length;
            if (ArrayUtil.InRange(inRoom, i))
            {
                dogs[i] = factory.Create(inRoom[i]);
            }
            else if (ArrayUtil.InRange(available, indexInAvailable))
            {
                DogDescriptor availableDog = available[indexInAvailable];
                dogs[i] = factory.Create(availableDog);
                dataController.EnterRoom(availableDog, this.room);
            }
            else
            {
                dogs[i] = factory.Create(DogDescriptor.Default());
            }
        }
        return(dogs);
    }
Esempio n. 4
0
 protected override void setSprite(DogDescriptor dog)
 {
     this.dogInfo    = dog;
     dogImage.sprite = dog.WorldSprite;
     dog.SubscribeToBeginScouting(handleScoutingBegun);
     dog.SubscribeToDoneScouting(handleScoutingDone);
 }
Esempio n. 5
0
    DogSpriteDisplayTool addDogToView(DogDescriptor dog)
    {
        DogSpriteDisplayTool display = Instantiate(displayPrefab);

        display.Display(dog);
        display.transform.SetParent(viewParent);
        display.transform.localScale = Vector3.one;
        return(display);
    }
Esempio n. 6
0
    void removeFromRoom(DogDescriptor dog, PPScene room)
    {
        List <DogDescriptor> inRoom;

        if (WorldDogs.TryGetValue(room, out inRoom))
        {
            inRoom.Remove(dog);
        }
    }
Esempio n. 7
0
 // Sets the dog and background sprites of this Dog Slot.
 void setSlot(DogDescriptor dog, Sprite backgroundSprite = null)
 {
     setSprite(dog);
     enable(true);
     if (backgroundImage)
     {
         backgroundImage.sprite = backgroundSprite;
     }
 }
Esempio n. 8
0
 public override void Init(DogDescriptor dog)
 {
     base.Init(dog);
     nameText.text = dog.Name;
     if (this.dog)
     {
         initDogScouting(this.dog, onResume: false);
     }
 }
Esempio n. 9
0
 public virtual void ClearSlot()
 {
     this.dog     = null;
     this.dogInfo = null;
     if (this.dogImage)
     {
         this.dogImage.sprite = null;
     }
     enable(false);
 }
Esempio n. 10
0
 void handleDogGiftCollected(Dog dog, bool resendOutToScout)
 {
     if (gameController)
     {
         DogDescriptor dogInfo = dog.Info;
         CurrencyData  reward  = gameController.GetGift(dogInfo);
         GiftReport    report  = new GiftReport(dogInfo, reward);
         createGiftReportUI(report);
     }
 }
Esempio n. 11
0
 WeightedRandomBuffer <CurrencyType> getRandomizerBySpecialization(DogDescriptor dog, DogFoodData food, CurrencyType specialization)
 {
     CurrencyType[] currencies = new CurrencyType[]
     {
         specialization,
         getSecondary(specialization),
         CurrencyType.SpecialGift,
     };
     float[] weights = getWeights(food, hasSpecialization: true);
     return(new WeightedRandomBuffer <CurrencyType>(currencies, weights));
 }
Esempio n. 12
0
    void addDogToRoom(DogDescriptor dog, PPScene room)
    {
        List <DogDescriptor> inRoom;

        if (!WorldDogs.TryGetValue(room, out inRoom))
        {
            inRoom = new List <DogDescriptor>();
            WorldDogs.Add(room, inRoom);
        }
        inRoom.Add(dog);
    }
Esempio n. 13
0
 CurrencyType defaultRandomType(DogDescriptor dog, DogFoodData food)
 {
     return(new WeightedRandomBuffer <CurrencyType>(
                new CurrencyType[]
     {
         CurrencyType.Coins,
         CurrencyType.DogFood,
         CurrencyType.SpecialGift
     },
                getWeights(food, hasSpecialization: false)).GetRandom());
 }
Esempio n. 14
0
 public override void Give()
 {
     if (hasDogToRedeem)
     {
         dataController.Adopt(dogToRedeem);
         EventController.Event(
             PPEvent.DogRedeemedFromScouting,
             new DogFactory(hideGameObjects: true).Create(dogToRedeem));
         dogToRedeem = null;
     }
 }
Esempio n. 15
0
 static object[] getPropertyValues(DogDescriptor dog, bool includeScoutingInfo = false)
 {
     if (includeScoutingInfo)
     {
         return(new object[] { dog.Name, string.Format("{0} {1}", dog.TotalTimeToReturn, k.SECONDS) });
     }
     else
     {
         return(new object[] { dog.Name });
     }
 }
Esempio n. 16
0
 public override bool Equals(object obj)
 {
     if (obj is DogDescriptor)
     {
         DogDescriptor other = obj as DogDescriptor;
         return(this.name == other.name && this.breed == other.breed && this.age == other.age);
     }
     else
     {
         return(base.Equals(obj));
     }
 }
Esempio n. 17
0
    public CurrencyData GetGiftFromDog(DogDescriptor dog)
    {
        CurrencyData gift;

        if (tryGetExistingGift(dog, out gift))
        {
            return(gift);
        }
        else
        {
            return(generateGift(dog));
        }
    }
Esempio n. 18
0
 // Initializes this Dog Slot by setting component references and displaying its sprites.
 public virtual void Init(DogDescriptor dog)
 {
     this.dogInfo = dog;
     setSlot(this.dogInfo);
     if (this.dogInfo.IsLinkedToDog)
     {
         this.dog = dogInfo.PeekDogLink;
     }
     else
     {
         this.dog = new DogFactory(hideGameObjects: true).Create(this.dogInfo);
     }
 }
Esempio n. 19
0
    public Sprite GetDogWorldSprite(DogDescriptor dog)
    {
        string spriteName = getWorldSpriteName(dog);
        Sprite sprite;

        if (dog == null || !spriteDatabase.TryGetSprite(spriteName, out sprite))
        {
            return(DefaultSprite);
        }
        else
        {
            return(sprite);
        }
    }
Esempio n. 20
0
    public void Display(DogDescriptor dog)
    {
        this.Dog = dog;
        this.nameDisplay.text          = string.Format("{0}: {1}", k.NAME, dog.Name);
        this.breedDisplay.text         = string.Format("{0}: {1}", k.BREED, dog.Breed.Breed);
        this.colorDisplay.text         = string.Format("{0}: {1}", k.Color, dog.Color);
        this.dogProfilePortrait.sprite = dog.Portrait;
        this.dogWorldSprite.sprite     = dog.WorldSprite;

        SouvenirData souvenir = dog.Souvenir;

        this.souvenirDisplay.sprite   = souvenir.Icon;
        this.souvenirNameDisplay.text = souvenir.DisplayName;
        this.souvenirDescDisplay.text = souvenir.Description;
    }
Esempio n. 21
0
    public override void Init(DogDescriptor dog)
    {
        base.Init(dog);
        if (nameTag)
        {
            nameTag.Init(this, this.dog);
        }
        checkReferences();
        DogAI behaviour = GetComponent <DogAI>();

        if (behaviour)
        {
            behaviour.RestartDecisionRoutine();
        }
    }
Esempio n. 22
0
    public static DogDescriptor Default()
    {
        DogDescriptor descriptor = new DogDescriptor(DogDatabase.GetInstance);

        descriptor.name        = string.Empty;
        descriptor.age         = 0;
        descriptor.breed       = string.Empty;
        descriptor.color       = BLACK_HEX;
        descriptor.description = new string[]
        {
            string.Empty, string.Empty
        };
        descriptor.EmptyDescriptor = true;
        descriptor.TimesScouted    = 0;
        return(descriptor);
    }
Esempio n. 23
0
    public override void Init(DogDescriptor dog)
    {
        base.Init(dog);

        checkReferences();
        priceTag.Set(dog.CostToAdopt);
        priceTag.SetNonPurchasable(tuning.AdoptedText, tuning.NonPurchasableTextColor, tuning.NonPurchasableBackgroundColor);

        if (checkAdopted())
        {
            ShowAdopt();
        }
        else
        {
            ShowDefault();
        }
    }
Esempio n. 24
0
 public bool TryAdoptDog(DogDescriptor dog)
 {
     if (dataController.CheckIsAdopted(dog))
     {
         // Trying to adopt a dog that is already adopted
         return(false);
     }
     else
     {
         if (CanAfford(CurrencyType.Coins, dog.CostToAdopt))
         {
             AdoptDog(dog);
             return(true);
         }
         return(false);
     }
 }
Esempio n. 25
0
    public DogDescriptor RandomDog(bool mustBeUnadopted)
    {
        DogDescriptor dog;

        if (dataController.AllDogsAdopted(this) && mustBeUnadopted)
        {
            dog = DogDescriptor.Default();
        }
        else
        {
            do
            {
                dog = randomizer.GetRandom();
            }while(mustBeUnadopted && dataController.CheckIsAdopted(dog));
        }
        return(dog);
    }
Esempio n. 26
0
    public override Dog Create(params object[] args)
    {
        DogDescriptor info = args[0] as DogDescriptor;
        // MonoBehaviours must be assigned to GameObjects:
        GameObject dogObject = new GameObject();

        if (this.hideGameObjects)
        {
            dogObject.hideFlags = HideFlags.HideInHierarchy | HideFlags.HideInInspector;
        }
        Dog dog = dogObject.AddComponent <Dog>();

        dog.Set(info);
        PPTimer scoutingTimer = new PPTimer(dog.TotalTimeToReturn, STANDARD_TIME_STEP_SEC);

        dog.GiveTimer(scoutingTimer);
        return(dog);
    }
Esempio n. 27
0
    CurrencyData generateGift(DogDescriptor dog)
    {
    #if UNITY_EDITOR
        // CHEAT: Returns the souvenir first for testing purposes:
        if (alwaysReturnSouvenirFirst && !dog.SouvenirCollected)
        {
            return(dog.Souvenir);
        }
        else if (alwaysReturnSpecialGift)
        {
            return(getSpecialGift(dog));
        }
    #endif

        DogFoodData food = dog.DigestFood();
        if (food == null)
        {
            food = dataController.DogFood;
        }
        CurrencyType specialization = dog.Breed.ISpecialization;
        int          amount         = randomAmount();
        CurrencyType type;
        if (specialization == CurrencyType.None)
        {
            type = defaultRandomType(dog, food);
        }
        else
        {
            type = getRandomizerBySpecialization(dog, food, specialization).GetRandom();
        }
        if (type == CurrencyType.SpecialGift)
        {
            return(getSpecialGift(dog));
        }
        else
        {
            CurrencyData gift = giftFactory.Create(type, amount);
            if (food.AmountMod != k.NONE_VALUE)
            {
                gift.MultiplyBy(food.AmountMod);
            }
            return(gift);
        }
    }
Esempio n. 28
0
    CurrencyData getSpecialGift(DogDescriptor dog)
    {
        CurrencyData specialGift = getDogSpecialGiftChances(dog).GetRandom();

        if (specialGift is SouvenirData)
        {
            // Need to return the specific souvenir the dog owns
            return(dog.Souvenir);
        }
        else
        {
            SpecialGiftData gift = specialGift as SpecialGiftData;
            (gift as SpecialGiftData).SetFinder(dog);
            if (!checkSpecialGiftCanBeUsed(gift))
            {
                // Set to a default currency if the SpecialGift cannot be used
                specialGift = giftFactory.Create(defaultReturnChances.GetRandom(), randomAmount());
            }
            return(specialGift);
        }
    }
Esempio n. 29
0
 bool tryGetExistingGift(DogDescriptor info, out CurrencyData gift)
 {
     if (info.IsLinkedToDog)
     {
         Dog dog = info.PeekDogLink;
         if (dog.HasRedeemableGift)
         {
             gift = dog.PeekAtGift;
             return(true);
         }
         else
         {
             gift = null;
             return(false);
         }
     }
     else
     {
         gift = null;
         return(false);
     }
 }
Esempio n. 30
0
    // Excludes already adopted dogs
    protected DogDescriptor[] getDailyRandomDogListFromBuffer(
        RandomBuffer <DogDescriptor> buffer,
        int count,
        int startIndex = 0)
    {
        buffer.Refresh();
        DogDescriptor[] fullSequence = buffer.GetRandom(dogs.Length);
        DogDescriptor[] candidates   = ArrayUtil.GetRange(fullSequence, startIndex, count);
        // Allows for faster lookup versus O(n) to check array
        HashSet <DogDescriptor> currentCandidates = new HashSet <DogDescriptor>(candidates);
        // -1 for zero offset
        int currentIndex  = startIndex + count - ZERO_INDEX_OFFSET;
        int totalDogCount = fullSequence.Length;

        for (int i = 0; i < candidates.Length; i++)
        {
            while (currentIndex < totalDogCount && dataController.CheckIsAdopted(candidates[i]))
            {
                if (!dataController.CheckIsAdopted(fullSequence[currentIndex]))
                {
                    if (!currentCandidates.Contains(fullSequence[currentIndex]))
                    {
                        // Remove the old dog from the Hash (because it's invalid)
                        currentCandidates.Remove(candidates[i]);
                        candidates[i] = fullSequence[currentIndex];
                        // Update the Hash w/ the new dog
                        currentCandidates.Add(candidates[i]);
                    }
                }
                currentIndex++;
            }
            currentIndex++;
            if (currentIndex >= totalDogCount && dataController.CheckIsAdopted(candidates[i]))
            {
                candidates[i] = DogDescriptor.Default();
            }
        }
        return(candidates);
    }