Beispiel #1
0
        /// <summary>
        /// Given a direction, will produce the next index from the specified one
        /// </summary>
        public static int GetNextIndex(this StepCountPointerDirection direction, int currentIndex)
        {
            int newIndex = currentIndex;

            switch (direction)
            {
            case StepCountPointerDirection.Down:
                newIndex--;
                if (newIndex == -1)
                {
                    newIndex = 255;                     // Wrap integer to within 0-255
                }
                break;

            case StepCountPointerDirection.Up:
                newIndex++;
                if (newIndex > 255)
                {
                    newIndex = 0;                     // Wrap integer to within 0-255
                }
                break;
            }

            return(newIndex);
        }
Beispiel #2
0
        private void CalculateStepCount()
        {
            Encounters.Clear();

            int traverseIndex       = 0;                         // An index to track where we are in the traversal.  i.e., down or up.
            int encounterTableIndex = Const.EncounterStartPoint; // An index to track where we are in the encounter hex table.
            int battleGroupIndex    = 0;                         // An index to track where we are in the battle group
            int stepsSinceLastEnc   = 0;

            // Loop through the users supplied zones + steps
            foreach (StepModel step in Steps.Where(s => s.IsValid))
            {
                if (step.PowerCycle)
                {
                    // User specified this was a power cycle, reset our indexes and continue our loop
                    traverseIndex       = 0;
                    encounterTableIndex = Const.EncounterStartPoint;
                    battleGroupIndex    = 0;
                    stepsSinceLastEnc   = 0;
                    if (!string.IsNullOrWhiteSpace(step.Comments))
                    {
                        Encounters.Add(new EncounterModel(ZoneType.NotApplicable, "(Power Cycle)", null, null, null, step.Comments));
                    }
                    continue;
                }

                int encountersFound = Encounters.Count;
                // Go through every step in our zone
                for (int i = 1; i <= step.Steps; i++)
                {
                    encounterTableIndex = Const.StepCountDirectionPattern[traverseIndex].GetNextIndex(encounterTableIndex);
                    stepsSinceLastEnc++;

                    if (encounterTableIndex == 0)
                    {
                        traverseIndex++;
                        if (traverseIndex > Const.StepCountDirectionPattern.Length - 1)
                        {
                            // Repeat our direction again by resetting to 0
                            traverseIndex = 0;
                        }
                    }

                    // Find the encounter theshhold at this index.  Compare it to the zones threshold
                    if (Const.EncounterTable[encounterTableIndex] < step.Zone.Threshhold)
                    {
                        // Battle!  Find the group
                        Encounters.Add(new EncounterModel(step.Zone.Type, step.Zone.Name, step.Zone.ZoneEncounters[Const.RandomBattleGroup[battleGroupIndex] - 1], Const.RandomBattleGroup[battleGroupIndex], stepsSinceLastEnc, step.Comments));

                        // Move up to the next battle group
                        battleGroupIndex++;
                        if (battleGroupIndex > 255)
                        {
                            battleGroupIndex = 0;
                        }
                        stepsSinceLastEnc = 0;
                    }
                }

                if (encountersFound == Encounters.Count && !string.IsNullOrWhiteSpace(step.Comments))
                {
                    // There are no encounters within this StepModel, but the user provided a comment.  Add this into the result screen (dummy encounter)
                    Encounters.Add(new EncounterModel(step.Zone?.Type ?? ZoneType.NotApplicable, step.ZoneDisplay, null, null, null, step.Comments));
                }
            }

            CurrentDirection = Const.StepCountDirectionPattern[traverseIndex];
            CurrentIndex     = encounterTableIndex.ToString("X");
            CurrentRng       = Const.EncounterTable[encounterTableIndex].ToString("X");
            NextBattleGroup  = Const.RandomBattleGroup[battleGroupIndex];

            // Calculate when the next encounter will occur
            if (FocusedSteps?.Zone != null)
            {
                StepCountPointerDirection direction = CurrentDirection;
                for (int i = 1; i < int.MaxValue; i++)
                {
                    encounterTableIndex = direction.GetNextIndex(encounterTableIndex);

                    if (encounterTableIndex == 0)
                    {
                        traverseIndex++;
                        if (traverseIndex > Const.StepCountDirectionPattern.Length - 1)
                        {
                            // Repeat our direction again by resetting to 0
                            traverseIndex = 0;
                        }
                    }

                    if (Const.EncounterTable[encounterTableIndex] < FocusedSteps.Zone.Threshhold)
                    {
                        // We found the battle
                        StepsTillNextEnc = i;
                        break;
                    }
                }
            }
        }