示例#1
0
    /// <summary>
    /// Plans the days events. Call when entering a new day.
    /// </summary>
    /// <param name="gameFlagsArg"></param>
    /// <param name="todaysDayArg"></param>
    /// <param name="canHcontentBeViewedArg"></param>
    /// <param name="maxNumEventsToPlanArg"></param>
    public void PlanTodaysEvents(GameFlags gameFlagsArg, DayOfWeek todaysDayArg,
                                 bool canHcontentBeViewedArg, int maxNumEventsToPlanArg)
    {
        // set no events as currently active
        todaysEvents = new List <HavenLocationEvent>();

        // load all haven location event templates
        HavenLocationEventTemplate[] allLoadedLocEventTemplates = AssetRefMethods.LoadAllBundleAssetHavenLocationEventTemplates();

        // get all haven locatione events from loaded templates
        List <HavenLocationEvent> allLoadedLocEvents = new List <HavenLocationEvent>();

        foreach (HavenLocationEventTemplate iterTemp in allLoadedLocEventTemplates)
        {
            allLoadedLocEvents.Add(new HavenLocationEvent(iterTemp));
        }

        // get all location events that can potentially be used today
        List <HavenLocationEvent> allPotentialLocEvents = GetAllPotentialEventsForToday(
            allLoadedLocEvents, gameFlagsArg, todaysDayArg, canHcontentBeViewedArg);

        // get a random number of events that should be placed
        int randNumOfEvents = UnityEngine.Random.Range(0, maxNumEventsToPlanArg);

        // initialize vars for upcoming loop
        List <HavenLocationEvent> currentPotentialLocEvents;
        int randomIndex;
        HavenLocationEvent selectedEvent;

        // loop for as many events as should be retrieved
        for (int i = 0; i < randNumOfEvents; i++)
        {
            // reset the list of currently potential events
            currentPotentialLocEvents = new List <HavenLocationEvent>();

            /// loop through all potential events. NOTE: Need to re-screen potential events to
            /// ensure that they do not colfict with the previously set events
            foreach (HavenLocationEvent iterEvent in allPotentialLocEvents)
            {
                // if iterating event is already active
                if (IsEventActive(iterEvent))
                {
                    // skip to next loop iteration
                    continue;
                }

                // if char associated with iterating event is already used in an active event
                if (ActiveEventsUsingCharacter(iterEvent.GetAppropriateAssociatedCharacterId()))
                {
                    // skip to next loop iteration
                    continue;
                }

                // if location of iterating event is already being used by an active event
                if (ActiveEventsUsingLocation(iterEvent.locatedSpot))
                {
                    // skip to next loop iteration
                    continue;
                }

                // add iterating event to currently potential events
                currentPotentialLocEvents.Add(iterEvent);
            }

            // if there is no available events that could be used
            if (currentPotentialLocEvents.Count == 0)
            {
                // print warning to console
                Debug.LogWarning("Problem in PlanTodaysEvents(). Not any more potential events to use!");

                // DONT continue code
                return;
            }

            // get random index from event list
            randomIndex = UnityEngine.Random.Range(0, currentPotentialLocEvents.Count);

            // get the randomly chosen event
            selectedEvent = new HavenLocationEvent(currentPotentialLocEvents[randomIndex]);

            // add selected event to today's active events
            todaysEvents.Add(selectedEvent);
            // denote that selected event has been used for the week
            eventsUsedInCurrentWeek.Add(selectedEvent);
        }
    }