public void ShowHoverTextOnHoveredItem(KSelectable hover_obj, HoverTextDrawer drawer, SelectToolHoverTextCard hover_text_card)
    {
        bool flag = false;

        foreach (Chore.Precondition.Context succeededContext in preconditionSnapshot.succeededContexts)
        {
            Chore.Precondition.Context current = succeededContext;
            if (current.chore.showAvailabilityInHoverText && !current.chore.target.isNull && !((UnityEngine.Object)current.chore.target.gameObject != (UnityEngine.Object)hover_obj.gameObject))
            {
                if (!flag)
                {
                    drawer.NewLine(26);
                    drawer.DrawText(DUPLICANTS.CHORES.PRECONDITIONS.HEADER.ToString().Replace("{Selected}", this.GetProperName()), hover_text_card.Styles_BodyText.Standard);
                    flag = true;
                }
                ShowHoverTextOnHoveredItem(current, hover_obj, drawer, hover_text_card);
            }
        }
        foreach (Chore.Precondition.Context failedContext in preconditionSnapshot.failedContexts)
        {
            Chore.Precondition.Context current2 = failedContext;
            if (current2.chore.showAvailabilityInHoverText && !current2.chore.target.isNull && !((UnityEngine.Object)current2.chore.target.gameObject != (UnityEngine.Object)hover_obj.gameObject))
            {
                if (!flag)
                {
                    drawer.NewLine(26);
                    drawer.DrawText(DUPLICANTS.CHORES.PRECONDITIONS.HEADER.ToString().Replace("{Selected}", this.GetProperName()), hover_text_card.Styles_BodyText.Standard);
                    flag = true;
                }
                ShowHoverTextOnHoveredItem(current2, hover_obj, drawer, hover_text_card);
            }
        }
    }
Пример #2
0
        /// <summary>
        /// Checks to see if a Duplicant can start a new task.
        /// </summary>
        /// <param name="context">The context related to the chore in question.</param>
        /// <param name="targetChore">The current work chore.</param>
        /// <returns>true if new chores can be started, or false otherwise.</returns>
        private static bool CheckStartNew(ref Chore.Precondition.Context context,
                                          object targetChore)
        {
            var  alertManager  = VignetteManager.Instance.Get();
            var  state         = context.consumerState;
            var  driver        = state.choreDriver;
            var  scheduleBlock = state.scheduleBlock;
            bool start         = true;

            // Bypass on red/yellow alert, only evaluate condition during Finish Tasks blocks,
            // allow the current chore to continue, or new work chores to be evaluated if the
            // current chore is compulsory like emotes
            if (!alertManager.IsRedAlert() && !alertManager.IsYellowAlert() && scheduleBlock !=
                null && scheduleBlock.GroupId == FinishTask.Id)
            {
                var currentChore = driver.GetCurrentChore();
                // If the current chore is this chore, remember that
                if (targetChore != null && currentChore == targetChore)
                {
                }
                start = currentChore != null && (currentChore == context.chore || currentChore.
                                                 masterPriority.priority_class == PriorityScreen.PriorityClass.compulsory);
            }
            return(start);
        }
Пример #3
0
        private static bool ShouldChoreBeWorked(Chore.Precondition.Context context)
        {
            var learnLevel     = context.consumerState.gameObject.GetComponent <AttributeLevels>().GetAttributeLevel("Learning").GetLevel();
            var attributeRange = GetAttributeRange(context.chore);

            return(learnLevel >= attributeRange.Item1 && learnLevel <= attributeRange.Item2);
        }
    public void SetChore(Chore.Precondition.Context context)
    {
        Chore currentChore = base.smi.GetCurrentChore();

        if (currentChore != context.chore)
        {
            StopChore();
            if (context.chore.IsValid())
            {
                context.chore.PrepareChore(ref context);
                this.context = context;
                base.smi.sm.nextChore.Set(context.chore, base.smi);
            }
            else
            {
                string text  = "Null";
                string text2 = "Null";
                if (currentChore != null)
                {
                    text = currentChore.GetType().Name;
                }
                if (context.chore != null)
                {
                    text2 = context.chore.GetType().Name;
                }
                string obj = "Stopping chore " + text + " to start " + text2 + " but stopping the first chore cancelled the second one.";
                Debug.LogWarning(obj);
            }
        }
    }
Пример #5
0
        /// <summary>
        /// Checks to see if a Duplicant can start a new task.
        /// </summary>
        /// <param name="context">The context related to the chore in question.</param>
        /// <param name="targetChore">The current work chore.</param>
        /// <returns>true if new chores can be started, or false otherwise.</returns>
        private static bool CheckStartNew(ref Chore.Precondition.Context context,
                                          object targetChore)
        {
            var  state = context.consumerState;
            var  driver = state.choreDriver;
            var  scheduleBlock = state.scheduleBlock;
            var  alertStatus = ClusterManager.Instance.GetWorld(driver.GetMyWorldId());
            bool start = true, normal = !alertStatus.IsYellowAlert() && !alertStatus.
                                        IsRedAlert();

            // Bypass on red/yellow alert, only evaluate condition during Finish Tasks blocks,
            // allow the current chore to continue, or new work chores to be evaluated if the
            // current chore is compulsory like emotes
            if (normal && scheduleBlock != null && scheduleBlock.GroupId == FinishTask.Id)
            {
                var currentChore = driver.GetCurrentChore();
                var detector     = driver.GetComponent <FinishChoreDetector>();
                // Allow the task that the Duplicant initially was doing to continue even if
                // temporarily interrupted
                var savedChore = (detector == null) ? null : (detector.IsAcquiringChore ?
                                                              currentChore : detector.TaskToFinish);
                start = currentChore != null && (currentChore == context.chore || currentChore.
                                                 masterPriority.priority_class == PriorityScreen.PriorityClass.compulsory ||
                                                 savedChore == context.chore);
            }
            return(start);
        }
    private static string TooltipForChore(Chore.Precondition.Context context, ChoreConsumer choreConsumer)
    {
        bool   flag = context.chore.masterPriority.priority_class == PriorityScreen.PriorityClass.basic || context.chore.masterPriority.priority_class == PriorityScreen.PriorityClass.high;
        string text;

        switch (context.chore.masterPriority.priority_class)
        {
        case PriorityScreen.PriorityClass.idle:
            text = UI.UISIDESCREENS.MINIONTODOSIDESCREEN.TOOLTIP_IDLE;
            break;

        case PriorityScreen.PriorityClass.personalNeeds:
            text = UI.UISIDESCREENS.MINIONTODOSIDESCREEN.TOOLTIP_PERSONAL;
            break;

        case PriorityScreen.PriorityClass.topPriority:
            text = UI.UISIDESCREENS.MINIONTODOSIDESCREEN.TOOLTIP_EMERGENCY;
            break;

        case PriorityScreen.PriorityClass.compulsory:
            text = UI.UISIDESCREENS.MINIONTODOSIDESCREEN.TOOLTIP_COMPULSORY;
            break;

        default:
            text = UI.UISIDESCREENS.MINIONTODOSIDESCREEN.TOOLTIP_NORMAL;
            break;
        }
        float num  = 0f;
        int   num2 = (int)context.chore.masterPriority.priority_class * 100;

        num += (float)num2;
        int num3 = flag ? choreConsumer.GetPersonalPriority(context.chore.choreType) : 0;

        num += (float)(num3 * 10);
        int num4 = flag ? context.chore.masterPriority.priority_value : 0;

        num += (float)num4;
        float num5 = (float)context.priority / 10000f;

        num += num5;
        text = text.Replace("{Description}", (!((Object)context.chore.driver == (Object)choreConsumer.choreDriver)) ? UI.UISIDESCREENS.MINIONTODOSIDESCREEN.TOOLTIP_DESC_INACTIVE : UI.UISIDESCREENS.MINIONTODOSIDESCREEN.TOOLTIP_DESC_ACTIVE);
        text = text.Replace("{IdleDescription}", (!((Object)context.chore.driver == (Object)choreConsumer.choreDriver)) ? UI.UISIDESCREENS.MINIONTODOSIDESCREEN.TOOLTIP_IDLEDESC_INACTIVE : UI.UISIDESCREENS.MINIONTODOSIDESCREEN.TOOLTIP_IDLEDESC_ACTIVE);
        string     newValue   = GameUtil.ChoreGroupsForChoreType(context.chore.choreType);
        ChoreGroup choreGroup = BestPriorityGroup(context, choreConsumer);

        text = text.Replace("{Name}", choreConsumer.name);
        text = text.Replace("{Errand}", GameUtil.GetChoreName(context.chore, context.data));
        text = text.Replace("{Groups}", newValue);
        text = text.Replace("{BestGroup}", (choreGroup == null) ? context.chore.choreType.Name : choreGroup.Name);
        text = text.Replace("{ClassPriority}", num2.ToString());
        string text2 = text;

        JobsTableScreen.PriorityInfo priorityInfo = JobsTableScreen.priorityInfo[num3];
        text = text2.Replace("{PersonalPriority}", priorityInfo.name.text);
        text = text.Replace("{PersonalPriorityValue}", (num3 * 10).ToString());
        text = text.Replace("{Building}", context.chore.gameObject.GetProperName());
        text = text.Replace("{BuildingPriority}", num4.ToString());
        text = text.Replace("{TypePriority}", num5.ToString());
        return(text.Replace("{TotalPriority}", num.ToString()));
    }
Пример #7
0
 public static void Postfix(MinionTodoChoreEntry __instance, Chore.Precondition.Context context)
 {
     if (context.chore.masterPriority.priority_class == PriorityZero.PriorityZeroClass)
     {
         __instance.priorityIcon.sprite = PriorityZero.ZeroPrioritySprite;
         __instance.priorityLabel.text  = "0";
     }
 }
Пример #8
0
    private static bool CanPreemptCB(Chore.Precondition.Context context)
    {
        Worker component = context.chore.driver.GetComponent <Worker>();
        float  num       = Db.Get().AttributeConverters.ResearchSpeed.Lookup(component).Evaluate();
        Worker worker    = context.consumerState.worker;
        float  num2      = Db.Get().AttributeConverters.ResearchSpeed.Lookup(worker).Evaluate();

        return(num2 > num);
    }
Пример #9
0
 /// <summary>
 /// Adds a sweep chore to the chore list, but fixes the interrupt priority to
 /// TopPriority if necessary.
 /// </summary>
 /// <param name="chores">The chore list where the chore will be placed.</param>
 /// <param name="toAdd">The sweep chore to add.</param>
 private static void AddAndFixPriority(List <Chore.Precondition.Context> chores,
                                       Chore.Precondition.Context toAdd)
 {
     if (toAdd.masterPriority.priority_class == PriorityScreen.PriorityClass.
         topPriority && TOP_PRIORITY_IRQ > 0)
     {
         toAdd.interruptPriority = TOP_PRIORITY_IRQ;
     }
     chores.Add(toAdd);
 }
Пример #10
0
    private static string TooltipForDupe(Chore.Precondition.Context context, ChoreConsumer choreConsumer, int rank)
    {
        bool   flag             = context.IsPotentialSuccess();
        string text             = (!flag) ? UI.DETAILTABS.BUILDING_CHORES.DUPE_TOOLTIP_FAILED : UI.DETAILTABS.BUILDING_CHORES.DUPE_TOOLTIP_SUCCEEDED;
        float  num              = 0f;
        int    personalPriority = choreConsumer.GetPersonalPriority(context.chore.choreType);

        num += (float)(personalPriority * 10);
        int priority_value = context.chore.masterPriority.priority_value;

        num += (float)priority_value;
        float num2 = (float)context.priority / 10000f;

        num += num2;
        text = text.Replace("{Description}", (!((Object)context.chore.driver == (Object)choreConsumer.choreDriver)) ? UI.DETAILTABS.BUILDING_CHORES.DUPE_TOOLTIP_DESC_INACTIVE : UI.DETAILTABS.BUILDING_CHORES.DUPE_TOOLTIP_DESC_ACTIVE);
        string newValue  = GameUtil.ChoreGroupsForChoreType(context.chore.choreType);
        string newValue2 = UI.UISIDESCREENS.MINIONTODOSIDESCREEN.TOOLTIP_NA.text;

        if (flag && context.chore.choreType.groups.Length > 0)
        {
            ChoreGroup choreGroup = context.chore.choreType.groups[0];
            for (int i = 1; i < context.chore.choreType.groups.Length; i++)
            {
                if (choreConsumer.GetPersonalPriority(choreGroup) < choreConsumer.GetPersonalPriority(context.chore.choreType.groups[i]))
                {
                    choreGroup = context.chore.choreType.groups[i];
                }
            }
            newValue2 = choreGroup.Name;
        }
        text = text.Replace("{Name}", choreConsumer.name);
        text = text.Replace("{Errand}", GameUtil.GetChoreName(context.chore, context.data));
        if (flag)
        {
            text = text.Replace("{Rank}", rank.ToString());
            text = text.Replace("{Groups}", newValue);
            text = text.Replace("{BestGroup}", newValue2);
            string text2 = text;
            JobsTableScreen.PriorityInfo priorityInfo = JobsTableScreen.priorityInfo[personalPriority];
            text = text2.Replace("{PersonalPriority}", priorityInfo.name.text);
            text = text.Replace("{PersonalPriorityValue}", (personalPriority * 10).ToString());
            text = text.Replace("{Building}", context.chore.gameObject.GetProperName());
            text = text.Replace("{BuildingPriority}", priority_value.ToString());
            text = text.Replace("{TypePriority}", num2.ToString());
            return(text.Replace("{TotalPriority}", num.ToString()));
        }
        string text3 = text;

        Chore.PreconditionInstance preconditionInstance = context.chore.GetPreconditions()[context.failedPreconditionId];
        return(text3.Replace("{FailedPrecondition}", preconditionInstance.description));
    }
    public void Apply(Chore.Precondition.Context context)
    {
        ChoreConsumer consumer = context.consumerState.consumer;

        if (targetChore != context.chore || !object.ReferenceEquals(context.chore.target, lastChoreTarget) || !(context.chore.masterPriority == lastPrioritySetting))
        {
            targetChore         = context.chore;
            lastChoreTarget     = context.chore.target;
            lastPrioritySetting = context.chore.masterPriority;
            string choreName = GameUtil.GetChoreName(context.chore, context.data);
            string text      = GameUtil.ChoreGroupsForChoreType(context.chore.choreType);
            string text2     = UI.UISIDESCREENS.MINIONTODOSIDESCREEN.CHORE_TARGET;
            text2 = text2.Replace("{Target}", (!((Object)context.chore.target.gameObject == (Object)consumer.gameObject)) ? context.chore.target.gameObject.GetProperName() : UI.UISIDESCREENS.MINIONTODOSIDESCREEN.SELF_LABEL.text);
            if (text != null)
            {
                text2 = text2.Replace("{Groups}", text);
            }
            string     text3      = (context.chore.masterPriority.priority_class != 0) ? string.Empty : context.chore.masterPriority.priority_value.ToString();
            Sprite     sprite     = (context.chore.masterPriority.priority_class != 0) ? null : prioritySprites[context.chore.masterPriority.priority_value - 1];
            ChoreGroup choreGroup = BestPriorityGroup(context, consumer);
            icon.sprite = ((choreGroup == null) ? null : Assets.GetSprite(choreGroup.sprite));
            label.SetText(choreName);
            subLabel.SetText(text2);
            priorityLabel.SetText(text3);
            priorityIcon.sprite = sprite;
            moreLabel.text      = string.Empty;
            GetComponent <ToolTip>().SetSimpleTooltip(TooltipForChore(context, consumer));
            KButton componentInChildren = GetComponentInChildren <KButton>();
            componentInChildren.ClearOnClick();
            if ((Object)componentInChildren.bgImage != (Object)null)
            {
                componentInChildren.bgImage.colorStyleSetting = ((!((Object)context.chore.driver == (Object)consumer.choreDriver)) ? buttonColorSettingStandard : buttonColorSettingCurrent);
                componentInChildren.bgImage.ApplyColorStyleSetting();
            }
            GameObject gameObject = context.chore.target.gameObject;
            componentInChildren.ClearOnPointerEvents();
            componentInChildren.GetComponentInChildren <KButton>().onClick += delegate
            {
                if (context.chore != null && !context.chore.target.isNull)
                {
                    Vector3 position  = context.chore.target.gameObject.transform.position;
                    float   x         = position.x;
                    Vector3 position2 = context.chore.target.gameObject.transform.position;
                    float   y         = position2.y + 1f;
                    Vector3 position3 = CameraController.Instance.transform.position;
                    Vector3 pos       = new Vector3(x, y, position3.z);
                    CameraController.Instance.SetTargetPos(pos, 10f, true);
                }
            };
        }
    }
Пример #12
0
        /// <summary>
        /// Checks to see if a Duplicant can do a chore based on workshop profiles.
        /// </summary>
        /// <param name="context">The context including the Duplicant attempting the chore.</param>
        /// <param name="data">The workshop profile list.</param>
        /// <returns>true if the Duplicant can use the building, or false otherwise.</returns>
        private static bool IsAllowed(ref Chore.Precondition.Context context, object data)
        {
            bool allow  = true;
            var  worker = context.consumerState?.worker;

            if (data is WorkshopProfile profile && profile != null && worker != null)
            {
                var prefabID = context.consumerState.prefabid;
                if (prefabID != null)
                {
                    allow = profile.IsAllowed(prefabID.InstanceID);
                }
            }
            return(allow);
        }
    private static ChoreGroup BestPriorityGroup(Chore.Precondition.Context context, ChoreConsumer choreConsumer)
    {
        ChoreGroup choreGroup = null;

        if (context.chore.choreType.groups.Length > 0)
        {
            choreGroup = context.chore.choreType.groups[0];
            for (int i = 1; i < context.chore.choreType.groups.Length; i++)
            {
                if (choreConsumer.GetPersonalPriority(choreGroup) < choreConsumer.GetPersonalPriority(context.chore.choreType.groups[i]))
                {
                    choreGroup = context.chore.choreType.groups[i];
                }
            }
        }
        return(choreGroup);
    }
 private void UpdateChores()
 {
     if (!GetComponent <KPrefabID>().HasTag(GameTags.PreventChoreInterruption))
     {
         Chore.Precondition.Context context = default(Chore.Precondition.Context);
         if (FindBetterChore(ref context))
         {
             if (this.HasTag(GameTags.PerformingWorkRequest))
             {
                 Trigger(1485595942, null);
             }
             else
             {
                 GetComponent <ChoreDriver>().SetChore(context);
             }
         }
     }
 }
    public void CollectChores(ChoreConsumerState consumer_state, List <Chore.Precondition.Context> succeeded, List <Chore.Precondition.Context> failed_contexts)
    {
        ChoreType transport        = Db.Get().ChoreTypes.Transport;
        int       personalPriority = consumer_state.consumer.GetPersonalPriority(transport);
        int       priority         = (!Game.Instance.advancedPersonalPriorities) ? transport.priority : transport.explicitPriority;

        CollectSortedClearables(consumer_state.navigator, markedClearables, sortedClearables);
        bool flag = false;

        foreach (SortedClearable sortedClearable in sortedClearables)
        {
            SortedClearable            current        = sortedClearable;
            Pickupable                 pickupable     = current.pickupable;
            PrioritySetting            masterPriority = current.masterPriority;
            Chore.Precondition.Context item           = default(Chore.Precondition.Context);
            item.personalPriority = personalPriority;
            KPrefabID kPrefabID = pickupable.KPrefabID;
            kPrefabID.UpdateTagBits();
            foreach (GlobalChoreProvider.Fetch fetch in GlobalChoreProvider.Instance.fetches)
            {
                GlobalChoreProvider.Fetch current2 = fetch;
                if (kPrefabID.HasAnyTags_AssumeLaundered(ref current2.chore.tagBits))
                {
                    item.Set(current2.chore, consumer_state, false, pickupable);
                    item.choreTypeForPermission = transport;
                    item.RunPreconditions();
                    if (item.IsSuccess())
                    {
                        item.masterPriority    = masterPriority;
                        item.priority          = priority;
                        item.interruptPriority = transport.interruptPriority;
                        succeeded.Add(item);
                        flag = true;
                        break;
                    }
                }
            }
            if (flag)
            {
                break;
            }
        }
    }
    private bool ChooseChore(ref Chore.Precondition.Context out_context, List <Chore.Precondition.Context> succeeded_contexts)
    {
        if (succeeded_contexts.Count == 0)
        {
            return(false);
        }
        Chore currentChore = choreDriver.GetCurrentChore();

        if (currentChore == null)
        {
            for (int num = succeeded_contexts.Count - 1; num >= 0; num--)
            {
                Chore.Precondition.Context context = succeeded_contexts[num];
                if (context.IsSuccess())
                {
                    out_context = context;
                    return(true);
                }
            }
        }
        else
        {
            int interruptPriority = Db.Get().ChoreTypes.TopPriority.interruptPriority;
            int num2 = (currentChore.masterPriority.priority_class != PriorityScreen.PriorityClass.topPriority) ? currentChore.choreType.interruptPriority : interruptPriority;
            for (int num3 = succeeded_contexts.Count - 1; num3 >= 0; num3--)
            {
                Chore.Precondition.Context context2 = succeeded_contexts[num3];
                if (context2.IsSuccess())
                {
                    int num4 = (context2.masterPriority.priority_class != PriorityScreen.PriorityClass.topPriority) ? context2.interruptPriority : interruptPriority;
                    if (num4 > num2 && !currentChore.choreType.interruptExclusion.Overlaps(context2.chore.choreType.tags))
                    {
                        out_context = context2;
                        return(true);
                    }
                }
            }
        }
        return(false);
    }
 public void ShowHoverTextOnHoveredItem(Chore.Precondition.Context context, KSelectable hover_obj, HoverTextDrawer drawer, SelectToolHoverTextCard hover_text_card)
 {
     if (!context.chore.target.isNull && !((UnityEngine.Object)context.chore.target.gameObject != (UnityEngine.Object)hover_obj.gameObject))
     {
         drawer.NewLine(26);
         drawer.AddIndent(36);
         drawer.DrawText(context.chore.choreType.Name, hover_text_card.Styles_BodyText.Standard);
         if (!context.IsSuccess())
         {
             Chore.PreconditionInstance preconditionInstance = context.chore.GetPreconditions()[context.failedPreconditionId];
             string text = preconditionInstance.description;
             if (string.IsNullOrEmpty(text))
             {
                 text = preconditionInstance.id;
             }
             if ((UnityEngine.Object)context.chore.driver != (UnityEngine.Object)null)
             {
                 text = text.Replace("{Assignee}", context.chore.driver.GetProperName());
             }
             text = text.Replace("{Selected}", this.GetProperName());
             drawer.DrawText(" (" + text + ")", hover_text_card.Styles_BodyText.Standard);
         }
     }
 }
    public bool FindNextChore(ref Chore.Precondition.Context out_context)
    {
        if (debug)
        {
            int num = 0;
            num++;
        }
        preconditionSnapshot.Clear();
        consumerState.Refresh();
        if (consumerState.hasSolidTransferArm)
        {
            Debug.Assert(stationaryReach > 0);
            CellOffset offset  = Grid.GetOffset(Grid.PosToCell(this));
            Extents    extents = new Extents(offset.x, offset.y, stationaryReach);
            ListPool <ScenePartitionerEntry, ChoreConsumer> .PooledList pooledList = ListPool <ScenePartitionerEntry, ChoreConsumer> .Allocate();

            GameScenePartitioner.Instance.GatherEntries(extents, GameScenePartitioner.Instance.fetchChoreLayer, pooledList);
            foreach (ScenePartitionerEntry item in pooledList)
            {
                if (item.obj == null)
                {
                    DebugUtil.Assert(false, "FindNextChore found an entry that was null");
                }
                else
                {
                    FetchChore fetchChore = item.obj as FetchChore;
                    if (fetchChore == null)
                    {
                        DebugUtil.Assert(false, "FindNextChore found an entry that wasn't a FetchChore");
                    }
                    else if (fetchChore.target == null)
                    {
                        DebugUtil.Assert(false, "FindNextChore found an entry with a null target");
                    }
                    else if (fetchChore.isNull)
                    {
                        Debug.LogWarning("FindNextChore found an entry that isNull");
                    }
                    else
                    {
                        int cell = Grid.PosToCell(fetchChore.gameObject);
                        if (consumerState.solidTransferArm.IsCellReachable(cell))
                        {
                            fetchChore.CollectChoresFromGlobalChoreProvider(consumerState, preconditionSnapshot.succeededContexts, preconditionSnapshot.failedContexts, false);
                        }
                    }
                }
            }
            pooledList.Recycle();
        }
        else
        {
            for (int i = 0; i < providers.Count; i++)
            {
                ChoreProvider choreProvider = providers[i];
                choreProvider.CollectChores(consumerState, preconditionSnapshot.succeededContexts, preconditionSnapshot.failedContexts);
            }
        }
        preconditionSnapshot.succeededContexts.Sort();
        List <Chore.Precondition.Context> succeededContexts = preconditionSnapshot.succeededContexts;
        bool flag = ChooseChore(ref out_context, succeededContexts);

        if (flag)
        {
            preconditionSnapshot.CopyTo(lastSuccessfulPreconditionSnapshot);
        }
        return(flag);
    }
Пример #19
0
    private void PopulateElements(object data = null)
    {
        refreshHandle.ClearScheduler();
        refreshHandle = UIScheduler.Instance.Schedule("RefreshToDoList", 0.1f, PopulateElements, null, null);
        ListPool <Chore.Precondition.Context, BuildingChoresPanel> .PooledList pooledList = ListPool <Chore.Precondition.Context, BuildingChoresPanel> .Allocate();

        ChoreConsumer.PreconditionSnapshot lastPreconditionSnapshot = choreConsumer.GetLastPreconditionSnapshot();
        if (lastPreconditionSnapshot.doFailedContextsNeedSorting)
        {
            lastPreconditionSnapshot.failedContexts.Sort();
            lastPreconditionSnapshot.doFailedContextsNeedSorting = false;
        }
        pooledList.AddRange(lastPreconditionSnapshot.failedContexts);
        pooledList.AddRange(lastPreconditionSnapshot.succeededContexts);
        Chore.Precondition.Context choreB = default(Chore.Precondition.Context);
        MinionTodoChoreEntry       minionTodoChoreEntry = null;
        int         num       = 0;
        Schedulable component = DetailsScreen.Instance.target.GetComponent <Schedulable>();
        string      arg       = string.Empty;
        Schedule    schedule  = component.GetSchedule();

        if (schedule != null)
        {
            ScheduleBlock block = schedule.GetBlock(Schedule.GetBlockIdx());
            arg = block.name;
        }
        currentScheduleBlockLabel.SetText(string.Format(UI.UISIDESCREENS.MINIONTODOSIDESCREEN.CURRENT_SCHEDULE_BLOCK, arg));
        choreTargets.Clear();
        bool flag = false;

        activeChoreEntries = 0;
        for (int num2 = pooledList.Count - 1; num2 >= 0; num2--)
        {
            Chore.Precondition.Context context = pooledList[num2];
            if (context.chore != null)
            {
                Chore.Precondition.Context context2 = pooledList[num2];
                if (!context2.chore.target.isNull)
                {
                    Chore.Precondition.Context context3 = pooledList[num2];
                    if (!((UnityEngine.Object)context3.chore.target.gameObject == (UnityEngine.Object)null) && pooledList[num2].IsPotentialSuccess())
                    {
                        Chore.Precondition.Context context4 = pooledList[num2];
                        if ((UnityEngine.Object)context4.chore.driver == (UnityEngine.Object)choreConsumer.choreDriver)
                        {
                            currentTask.Apply(pooledList[num2]);
                            minionTodoChoreEntry = currentTask;
                            choreB = pooledList[num2];
                            num    = 0;
                            flag   = true;
                        }
                        else if (!flag && activeChoreEntries != 0 && GameUtil.AreChoresUIMergeable(pooledList[num2], choreB))
                        {
                            num++;
                            minionTodoChoreEntry.SetMoreAmount(num);
                        }
                        else
                        {
                            ChoreConsumer obj = choreConsumer;
                            Chore.Precondition.Context context5            = pooledList[num2];
                            HierarchyReferences        hierarchyReferences = PriorityGroupForPriority(obj, context5.chore);
                            MinionTodoChoreEntry       choreEntry          = GetChoreEntry(hierarchyReferences.GetReference <RectTransform>("EntriesContainer"));
                            choreEntry.Apply(pooledList[num2]);
                            minionTodoChoreEntry = choreEntry;
                            choreB = pooledList[num2];
                            num    = 0;
                            flag   = false;
                        }
                    }
                }
            }
        }
        pooledList.Recycle();
        for (int num3 = choreEntries.Count - 1; num3 >= activeChoreEntries; num3--)
        {
            choreEntries[num3].gameObject.SetActive(false);
        }
        foreach (Tuple <PriorityScreen.PriorityClass, int, HierarchyReferences> priorityGroup in priorityGroups)
        {
            RectTransform reference = priorityGroup.third.GetReference <RectTransform>("EntriesContainer");
            priorityGroup.third.gameObject.SetActive(reference.childCount > 0);
        }
    }
    private void AddChoreEntry(Chore chore)
    {
        HierarchyReferences choreEntry = GetChoreEntry(GameUtil.GetChoreName(chore, null), chore.choreType, choreGroup.GetReference <RectTransform>("EntriesContainer"));
        FetchChore          fetchChore = chore as FetchChore;

        ListPool <Chore.Precondition.Context, BuildingChoresPanel> .PooledList pooledList = ListPool <Chore.Precondition.Context, BuildingChoresPanel> .Allocate();

        foreach (MinionIdentity item in Components.LiveMinionIdentities.Items)
        {
            pooledList.Clear();
            ChoreConsumer component = item.GetComponent <ChoreConsumer>();
            Chore.Precondition.Context         context = default(Chore.Precondition.Context);
            ChoreConsumer.PreconditionSnapshot lastPreconditionSnapshot = component.GetLastPreconditionSnapshot();
            if (lastPreconditionSnapshot.doFailedContextsNeedSorting)
            {
                lastPreconditionSnapshot.failedContexts.Sort();
                lastPreconditionSnapshot.doFailedContextsNeedSorting = false;
            }
            pooledList.AddRange(lastPreconditionSnapshot.failedContexts);
            pooledList.AddRange(lastPreconditionSnapshot.succeededContexts);
            int num  = -1;
            int num2 = 0;
            for (int num3 = pooledList.Count - 1; num3 >= 0; num3--)
            {
                Chore.Precondition.Context context2 = pooledList[num3];
                if ((UnityEngine.Object)context2.chore.driver != (UnityEngine.Object)null)
                {
                    Chore.Precondition.Context context3 = pooledList[num3];
                    if ((UnityEngine.Object)context3.chore.driver != (UnityEngine.Object)component.choreDriver)
                    {
                        continue;
                    }
                }
                bool flag = pooledList[num3].IsPotentialSuccess();
                if (flag)
                {
                    num2++;
                }
                Chore.Precondition.Context context4       = pooledList[num3];
                FetchAreaChore             fetchAreaChore = context4.chore as FetchAreaChore;
                Chore.Precondition.Context context5       = pooledList[num3];
                if (context5.chore == chore || (fetchChore != null && fetchAreaChore != null && fetchAreaChore.smi.SameDestination(fetchChore)))
                {
                    num     = ((!flag) ? 2147483647 : num2);
                    context = pooledList[num3];
                    break;
                }
            }
            if (num >= 0)
            {
                DupeEntryDatas.Add(new DupeEntryData
                {
                    consumer         = component,
                    context          = context,
                    personalPriority = component.GetPersonalPriority(chore.choreType),
                    rank             = num
                });
            }
        }
        pooledList.Recycle();
        DupeEntryDatas.Sort();
        foreach (DupeEntryData dupeEntryData in DupeEntryDatas)
        {
            GetDupeEntry(dupeEntryData, choreEntry.GetReference <RectTransform>("DupeContainer"));
        }
        DupeEntryDatas.Clear();
    }
 private bool FindBetterChore(ref Chore.Precondition.Context context)
 {
     return(GetComponent <ChoreConsumer>().FindNextChore(ref context));
 }