void RefreshStory(int choice) { // Store this for later bool useCascades = (currentItem.choices[choice].cascades != null); // In the event the story branches based on the player having an item, like a key, // perform the branch. if (currentItem.choices[choice].UseItemBranch) { // Does the inventory contain the item? if (inventory.Contains(currentItem.choices[choice].ItemBranch.RequiredItem)) { // If it's consumable, remove it. if (currentItem.choices[choice].ItemBranch.ConsumeItem) { inventory.Remove(currentItem.choices[choice].ItemBranch.RequiredItem); } // Advance to next story item because player had inventory item. currentItem = currentItem.choices[choice].ItemBranch.withItem; } else { // Player did not have inventory item. currentItem = currentItem.choices[choice].ItemBranch.withoutItem; } } else { // No item branching if we're here. if (useCascades) { // If this branch has cascades, we should increment the cascade value. // Cache it first HistoryCascade cascades = currentItem.choices[choice].cascades; cascades.clickCounter++; // Bounds checking so it never exceeds sizeof(cascades.clickCounter) if (cascades.clickCounter >= cascades.historyCascades.Length) { cascades.clickCounter = cascades.historyCascades.Length - 1; } // Jump to the next story bit currentItem = cascades.historyCascades[cascades.clickCounter]; } else { // No cascades, simply proceed to the next one. currentItem = currentItem.choices[choice].pointsTo; } } // Set up the UI to reflect the change. SetupElements(); }
// Start the story over. public void StartOver() { currentItem = startingItem; // Reset all tracked history cascades to prevent nullreferences. foreach (HistoryCascade cascade in cascadesToReset) { cascade.clickCounter = 0; } // Clear history. storyHistory.Clear(); SetupElements(); }