//Returns a random decoration that has not yet been unlocked by the player, using a weighting system to make certain decorations rarer. //Decorations are only awarded one colour/material at a time, so weighting is adjusted based on how many materials are available to unlock for each decoration base. public TankDecorationDefinition SelectRandomLockedDecoration() { if (m_TempList == null) { m_TempList = new List <TankDecorationDefinition>(); } else { m_TempList.Clear(); } int weightTotal = 0; int librarySize = GetNumberOfDefinitions(); PlayerDataManager playerdata = PlayerDataManager.s_Instance; for (int i = 0; i < librarySize; i++) { if (playerdata.DecorationHasLockedColours(i)) { TankDecorationDefinition nextItem = TankDecorationLibrary.s_Instance.GetDecorationForIndex(i); m_TempList.Add(nextItem); weightTotal += (nextItem.selectionWeighting * nextItem.availableMaterials.Length); } } return(m_TempList.WeightedSelection(weightTotal, d => (d.selectionWeighting * d.availableMaterials.Length))); }
//Returns the array index for a given TankDecorationDefinition. public int GetIndexForDecoration(TankDecorationDefinition item) { for (int i = 0; i < m_TankDecorations.Length; i++) { if (m_TankDecorations[i].id == item.id) { return(i); } } return(-1); }