Пример #1
0
        public bool split(bool bonus = false)
        {
            long tickDiff = DateTime.UtcNow.Ticks - runTimer;

            //I hope this code never runs
            if (tickDiff < 0)
            {
                reset(false);
                GameUtil.ShowNotification(CellNotificationType.MESSAGE, "Timer somehow became negative; run quit! Please report this!");
                return(false);
            }
            splits.Add(new TimeSpan(tickDiff));
            isBonus.Add(bonus);
            splitColor = SplitColors.WHITE; prevColor = SplitColors.WHITE; goldColor = SplitColors.WHITE;
            splitText  = ""; prevText = ""; goldText = "";

            TimeSpan s   = splits[splits.Count - 1];
            string   val = convert(s);

            int numDates = 0, numBonuses = 0;

            foreach (bool b in isBonus)
            {
                if (b)
                {
                    numBonuses++;
                }
                else
                {
                    numDates++;
                }
            }

            if (category != "")
            {
                //create the affection meter replacement text
                //time [+/-]
                if (comparisonDates.Count >= numDates && comparisonBonuses.Count >= numBonuses)
                {
                    TimeSpan elapsedC = GetTimeAt(numDates, numBonuses);
                    val += " [";
                    TimeSpan diff = s - elapsedC;
                    if (diff.TotalSeconds > 0)
                    {
                        val       += "+";
                        splitColor = SplitColors.RED;
                    }
                    else
                    {
                        val       += "-";
                        splitColor = SplitColors.BLUE;
                    }

                    val += convert(diff) + "]";

                    //create the this split text, which is just this split's diff minus the last split's diff
                    TimeSpan diff2;
                    if (splits.Count != 1)
                    {
                        TimeSpan s2 = splits[splits.Count - 2];
                        TimeSpan prevElapsedC;
                        if (bonus)
                        {
                            prevElapsedC = GetTimeAt(numDates, numBonuses - 1);
                        }
                        else
                        {
                            prevElapsedC = GetTimeAt(numDates - 1, numBonuses);
                        }
                        diff2 = s2 - prevElapsedC;
                        diff2 = diff - diff2;
                    }
                    else
                    {
                        diff2 = diff;
                    }
                    if (diff2.TotalSeconds > 0)
                    {
                        prevText += "+";
                        prevColor = SplitColors.RED;
                    }
                    else
                    {
                        prevText += "-";
                        prevColor = SplitColors.BLUE;
                    }
                    prevText += convert(diff2);
                }

                //create the gold diff text
                if (goldDates.Count >= numDates && goldBonuses.Count >= numBonuses)
                {
                    //get segment length
                    if (splits.Count > 1)
                    {
                        s = s - splits[splits.Count - 2];
                    }
                    TimeSpan diff;
                    if (bonus)
                    {
                        diff = s - goldBonuses[numBonuses - 1];
                    }
                    else
                    {
                        diff = s - goldDates[numDates - 1];
                    }
                    if (diff.TotalSeconds < 0)
                    {
                        //new gold
                        goldText  += "-";
                        splitColor = SplitColors.GOLD;
                        goldColor  = SplitColors.GOLD;
                        if (bonus)
                        {
                            goldBonuses[numBonuses - 1] = s;
                        }
                        else
                        {
                            goldDates[numDates - 1] = s;
                        }
                    }
                    else
                    {
                        goldText += "+";
                    }
                    goldText += convert(diff);
                }
                //no gold to compare with, or no category defined
                else
                {
                    if (splits.Count > 1)
                    {
                        s = s - splits[splits.Count - 2];
                    }
                    if (bonus)
                    {
                        goldBonuses.Add(s);
                    }
                    else
                    {
                        goldDates.Add(s);
                    }
                }
            }
            else //category == ""
            {
                //reset the timer for each split if we aren't in a category
                runTimer = DateTime.UtcNow.Ticks;
            }

            splitText = val;
            //Logger.LogMessage(splitText + " " + goldText);
            return(true);
        }