/// <summary>
 /// Increments the count of number of times an item was purchased "number" times in a match, with average purchase time.
 /// </summary>
 public void Increment(ItemPurchaseInformation purchase)
 {
     PerMatchCounts.AddOrUpdate(purchase.Number,
         id => new ItemPurchaseTrackerData(ItemId, id, purchase),
         (id, tracker) => { tracker.Increment(purchase); return tracker; }
     );
 }
        public void Increment(ItemPurchaseInformation purchase)
        {
            double lerpValue = (double)Count / (double)(Count + 1);
            AveragePurchaseTimeSeconds = (AveragePurchaseTimeSeconds * lerpValue) + (purchase.GameState.Timestamp.TotalSeconds * (1.0 - lerpValue));
            ++Count;
            Kills += purchase.GameState.TotalKills;
            TowerKills += purchase.GameState.TotalTowerKills;
            InnerTowerKills += purchase.GameState.TotalTowerKillsByType(TowerType.InnerTurret);
            BaseTowerKills += purchase.GameState.TotalTowerKillsByType(TowerType.BaseTurret);

            if (purchase.BuildsInto != null)
            {
                var buildsIntoKey = new ItemPurchaseKey(purchase.BuildsInto);
                if (BuiltInto.ContainsKey(buildsIntoKey))
                {
                    ++BuiltInto[buildsIntoKey];
                }
                else
                {
                    BuiltInto[buildsIntoKey] = 1;
                }
            }

            if (purchase.FinalBuildItem != null)
            {
                var finalBuildKey = new ItemPurchaseKey(purchase.FinalBuildItem);
                if (FinalBuildItem.ContainsKey(finalBuildKey))
                {
                    ++FinalBuildItem[finalBuildKey];
                }
                else
                {
                    FinalBuildItem[finalBuildKey] = 1;
                }
            }
        }
 public ItemPurchaseKey(ItemPurchaseInformation purchase)
 {
     ItemId = purchase.ItemId;
     Number = purchase.Number;
 }
        public ItemPurchaseTrackerData(int itemId, int number, ItemPurchaseInformation purchase)
        {
            ItemId = itemId;
            Number = number;
            Count = 1;
            AveragePurchaseTimeSeconds = purchase.GameState.Timestamp.TotalSeconds;
            Kills = purchase.GameState.TotalKills;
            TowerKills = purchase.GameState.TotalTowerKills;
            InnerTowerKills = purchase.GameState.TotalTowerKillsByType(TowerType.InnerTurret);
            BaseTowerKills = purchase.GameState.TotalTowerKillsByType(TowerType.BaseTurret);

            if (purchase.BuildsInto != null)
                BuiltInto.Add(new ItemPurchaseKey(purchase.BuildsInto), 1);

            var finalItem = purchase.FinalBuildItem;
            if (finalItem != null)
                FinalBuildItem.Add(new ItemPurchaseKey(finalItem), 1);
        }