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); }
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)); }
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); }
protected override void setSprite(DogDescriptor dog) { this.dogInfo = dog; dogImage.sprite = dog.WorldSprite; dog.SubscribeToBeginScouting(handleScoutingBegun); dog.SubscribeToDoneScouting(handleScoutingDone); }
DogSpriteDisplayTool addDogToView(DogDescriptor dog) { DogSpriteDisplayTool display = Instantiate(displayPrefab); display.Display(dog); display.transform.SetParent(viewParent); display.transform.localScale = Vector3.one; return(display); }
void removeFromRoom(DogDescriptor dog, PPScene room) { List <DogDescriptor> inRoom; if (WorldDogs.TryGetValue(room, out inRoom)) { inRoom.Remove(dog); } }
// 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; } }
public override void Init(DogDescriptor dog) { base.Init(dog); nameText.text = dog.Name; if (this.dog) { initDogScouting(this.dog, onResume: false); } }
public virtual void ClearSlot() { this.dog = null; this.dogInfo = null; if (this.dogImage) { this.dogImage.sprite = null; } enable(false); }
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); } }
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)); }
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); }
CurrencyType defaultRandomType(DogDescriptor dog, DogFoodData food) { return(new WeightedRandomBuffer <CurrencyType>( new CurrencyType[] { CurrencyType.Coins, CurrencyType.DogFood, CurrencyType.SpecialGift }, getWeights(food, hasSpecialization: false)).GetRandom()); }
public override void Give() { if (hasDogToRedeem) { dataController.Adopt(dogToRedeem); EventController.Event( PPEvent.DogRedeemedFromScouting, new DogFactory(hideGameObjects: true).Create(dogToRedeem)); dogToRedeem = null; } }
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 }); } }
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)); } }
public CurrencyData GetGiftFromDog(DogDescriptor dog) { CurrencyData gift; if (tryGetExistingGift(dog, out gift)) { return(gift); } else { return(generateGift(dog)); } }
// 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); } }
public Sprite GetDogWorldSprite(DogDescriptor dog) { string spriteName = getWorldSpriteName(dog); Sprite sprite; if (dog == null || !spriteDatabase.TryGetSprite(spriteName, out sprite)) { return(DefaultSprite); } else { return(sprite); } }
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; }
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(); } }
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); }
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(); } }
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); } }
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); }
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); }
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); } }
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); } }
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); } }
// 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); }