/// <summary> /// Returns the sprite for this, of the correct colour /// </summary> /// <returns><see cref="Sprite"/></returns> public override Sprite GetItemSprite() { //* if the bee has not change in any way dont rebuild the sprite as that takes time if (previousBeeType == beeType && itemSprite != null) { return(itemSprite); } previousBeeType = beeType; //* set the correct sprite and colour if (beeType == BeeType.QUEEN) { //* avoids the crown, black body, yellow body, and both colours of the wings Color[] colorsToAvoid = { new Color(0, 0, 0), new Color(232f, 200f, 42f, 255f) / 255f, new Color(232f, 213f, 106f, 255f) / 255f, new Color(156f, 146f, 130f, 255f) / 255f, new Color(225f, 223f, 219f, 255f) / 255f }; return(itemSprite = SpriteDictionary.GetSprite("Queen").ColourSprite(BeeDictionaries.GetBeeColour((BeeSpecies)(queenBee?.queen.pSpecies)), coloursToAvoid: colorsToAvoid)); } else if (beeType == BeeType.PRINCESS) { //* avoids the tiara, black body, yellow body, and both colours of the wings Color[] colorsToAvoid = { new Color(0, 0, 0), new Color(191f, 195f, 45f, 255f) / 255f, new Color(191f, 195f, 44f, 255f) / 255f, new Color(156f, 146f, 130f, 255f) / 255f, new Color(225f, 223f, 219f, 255f) / 255f, new Color(232f, 200, 42, 255f) / 255f }; return(itemSprite = SpriteDictionary.GetSprite("Princess").ColourSprite(BeeDictionaries.GetBeeColour((BeeSpecies)(normalBee?.pSpecies)), coloursToAvoid: colorsToAvoid)); } else { //* avoids the block body, yellow body, and both wing colours Color[] colorsToAvoid = { new Color(0, 0, 0), new Color(156f, 146f, 130f, 255f) / 255f, new Color(225f, 223f, 219f, 255f) / 255f, new Color(232f, 200, 42, 255f) / 255f }; return(itemSprite = SpriteDictionary.GetSprite("Drone").ColourSprite(BeeDictionaries.GetBeeColour((BeeSpecies)normalBee?.pSpecies), coloursToAvoid: colorsToAvoid)); } }
public override GameObject GetGameObject() { var go = PrefabDictionary.GetPrefab("Bee"); go.GetComponent <SetBeeGOColours>().colour = BeeDictionaries.GetBeeColour(normalBee?.pSpecies ?? queenBee.queen.pSpecies); go.GetComponent <SetBeeGOColours>().beeType = beeType; return(go); }
/// <summary> /// Returns a <see cref="BeeSpecies"/> depending on the given <see cref="BeeSpecies"/> /// </summary> /// <param name="s1">First <see cref="BeeSpecies"/></param> /// <param name="s2">Second <see cref="BeeSpecies"/></param> /// <returns>A new <see cref="BeeSpecies"/></returns> private BeeSpecies CombineSpecies(BeeSpecies s1, BeeSpecies s2) { BeeSpecies[] possibleSpecies = BeeDictionaries.GetCombinations(s1, s2); float[] weights = possibleSpecies.Length > 2 ? BeeDictionaries.GetWeights(possibleSpecies) : new float[] { 0.5f, 0.5f }; var randomNum = Rand(weights); var weightsSum = 0f; //* when the number generated is less than the current sum of the weights return that bee for (int i = 0; i < weights.Length; i++) { if (randomNum <= weightsSum) { return(possibleSpecies[i]); } weightsSum += weights[i]; } //* if for some reason the weights cannot work return the first bee in the combination list return(possibleSpecies[0]); }
/// <summary> /// Will make new <see cref="Bee"/>/<see cref="Item"/>s from the given <see cref="BeeType.QUEEN"/> <see cref="Bee"/> /// </summary> /// <param name="queen">The <see cref="BeeType.QUEEN"/> to make the new <see cref="Bee"/>s from</param> /// <param name="inventory"><see cref="Inventory.Inventory"/> to put the new Bees/Items into</param> /// <remarks> /// Inventory is passed by reference to make it easier to modify the inventory. However is not necessarily needed as a <see cref="class"/> array is being passed so a reference would be created anyway however so <see cref="ref"/> is their more for clarity due to the function modifying the invetory directly /// </remarks> public void MakeBees(Bee queen, ref Item[] inventory) { Item[] producedItems = new Item[9]; //* will always return a new princess and drone producedItems[0] = MakeBee(BeeType.PRINCESS, queen.queenBee); producedItems[1] = MakeBee(BeeType.DRONE, queen.queenBee); var repeats = UnityEngine.Random.Range(0, queen.queenBee.queen.pFertility); //* produces as many other children as the bee stats will allow for (int i = 0; i < repeats; i++) { producedItems[i + 2] = MakeBee(queen.queenBee.queen.pFertility > 6 ? (BeeType)UnityEngine.Random.Range(1, 3) : BeeType.DRONE, queen.queenBee); if (producedItems[i + 2] is Bee b && b.beeType != BeeType.PRINCESS) { producedItems[i + 2].itemStackCount = UnityEngine.Random.Range(1, (int)queen.queenBee.queen.pFertility + 1); } } //* gets the produced items var beeProduce = BeeDictionaries.GetBeeProduce(queen.queenBee.queen.pSpecies); //* changes the stack count of the produced items to the correct number for (int i = 0; i < beeProduce.Length; i++) { beeProduce[i].itemStackCount += UnityEngine.Random.Range(1, (int)queen.queenBee.queen.sProdSpeed + 1); } //* adds the items that the bee species produces into the produced item array for (int i = (int)queen.queenBee.queen.pFertility + 2, prod = 0; prod < beeProduce.Length; i++, prod++) { producedItems[i] = beeProduce[prod]; } //* puts the items into the inventory for (int i = 0; i < 9; i++) { if (inventory[i + 2] != null) { //* if the slot has the same item in it and it won't be more than the max stack count but the new item into it if (producedItems[i] == inventory[i + 2] && inventory[i + 2].itemStackCount + 1 <= inventory[i + 2].maxStackCount) { inventory[i + 2].itemStackCount++; } else { //* otherwise find a new slot to put the item into for (int j = i; j < (9 - i); j++) { if (inventory[j + 2] == null) { inventory[j + 2] = producedItems[i]; break; } else if (producedItems[i] == inventory[j + 2] && inventory[j + 2].itemStackCount + 1 <= inventory[j + 2].maxStackCount) { inventory[j + 2].itemStackCount++; break; } } } } //* if the slot is empty put the item into it else { inventory[i + 2] = producedItems[i]; } } }