コード例 #1
0
        /// <summary>
        /// (Cross-Game compatable) Return how much cash this bloon would give if popped by <paramref name="layersPopped"/> number of layers
        /// </summary>
        /// <param name="layersPopped">How many layers of bloons to pop, ignoring layer health. If less than 0, calculates for the entire bloon</param>
        public static int GetTotalCash(this BloonModel bloonModel, int layersPopped = -1)
        {
            if (layersPopped == 0)
            {
                return(0);
            }

            var cashValue = SessionData.Instance.bloonPopValues;
            var children  = bloonModel.GetChildBloonModels(InGame.instance?.GetSimulation());

            if ((layersPopped >= 0) || !cashValue.TryGetValue(bloonModel.GetBaseID(), out int bloonCash))
            {
                bloonCash = 1;
                foreach (BloonModel child in children)
                {
                    bloonCash += child.GetTotalCash(layersPopped - 1);
                }
                if (layersPopped < 0)
                {
                    cashValue.Add(bloonModel.GetBaseID(), bloonCash);
                }
            }

            return(bloonCash);
        }