Example #1
0
    public void UpdateUI()
    {
        //Debug.Log(questHolder.TalkerName);
        bool hasObjective = questHolder.GetData <TalkerData>().objectivesTalkToThis.FindAll(x => x.AllPrevComplete && !x.IsComplete).Count > 0 ||
                            questHolder.GetData <TalkerData>().objectivesSubmitToThis.FindAll(x => x.AllPrevComplete && !x.IsComplete).Count > 0;

        if (questHolder.QuestInstances.Count < 1 && !hasObjective)
        {
            if (icon.enabled)
            {
                icon.enabled = false;
            }
            mapIcon.Hide();
            conditionShow = false;
            return;
        }
        //Debug.Log("enter");
        if (hasObjective)//该NPC身上有未完成的任务目标
        {
            icon.overrideSprite = accepted;
            mapIcon.iconImage.overrideSprite = accepted;
            conditionShow = true;
            return;
        }
        foreach (var quest in questHolder.QuestInstances)
        {
            if (!quest.IsComplete && !quest.InProgress && MiscFuntion.CheckCondition(quest.Model.AcceptCondition))//只要有一个没接取
            {
                icon.overrideSprite = notAccepted;
                mapIcon.iconImage.overrideSprite = notAccepted;
                conditionShow = true;
                return;
            }
            else if (quest.IsComplete && quest.InProgress)//只要有一个完成
            {
                icon.overrideSprite = complete;
                mapIcon.iconImage.overrideSprite = complete;
                conditionShow = true;
                return;
            }
        }
        conditionShow = false;
    }
Example #2
0
    private void HandlingQuestOptions()
    {
        var cmpltQuests = new List <QuestData>();
        var norQuests   = new List <QuestData>();

        foreach (var quest in currentTalker.QuestInstances)
        {
            if (MiscFuntion.CheckCondition(quest.Model.AcceptCondition) && !quest.IsFinished)
            {
                if (quest.IsComplete)
                {
                    cmpltQuests.Add(quest);
                }
                else
                {
                    norQuests.Add(quest);
                }
            }
        }
        buttonDatas.Clear();
        foreach (var quest in cmpltQuests)
        {
            buttonDatas.Add(new ButtonWithTextData(quest.Model.Title + "(完成)", delegate
            {
                currentQuest = quest;
                CurrentType  = DialogueType.Quest;
                ShowButtons(false, false, false, false);
                StartDialogue(quest.Model.CompleteDialogue);
            }));
        }
        foreach (var quest in norQuests)
        {
            buttonDatas.Add(new ButtonWithTextData(quest.Model.Title + (quest.InProgress ? "(进行中)" : string.Empty), delegate
            {
                currentQuest = quest;
                CurrentType  = DialogueType.Quest;
                ShowButtons(false, false, false, false);
                StartDialogue(quest.InProgress ? quest.Model.OngoingDialogue : quest.Model.BeginDialogue);
            }));
        }
        RefreshOptionUI();
    }
Example #3
0
 private void StartTalking(Talker talker)
 {
     currentTalker = talker;
     CurrentType   = DialogueType.Normal;
     ShowButtons(talker.GetData <TalkerData>().Info.CanDEV_RLAT, talker.GetData <TalkerData>().Info.IsVendor, talker.GetData <TalkerData>().Info.IsWarehouseAgent, talker.QuestInstances.FindAll(q => !q.IsFinished && MiscFuntion.CheckCondition(q.Model.AcceptCondition)).Count > 0);
     HideQuestDescription();
     StartDialogue(talker.DefaultDialogue);
     talker.OnTalkBegin();
 }
Example #4
0
    private readonly List <QuestData> questsFinished = new List <QuestData>();//分开存储完成任务可减少不必要的检索开销

    #region 任务处理相关
    /// <summary>
    /// 接取任务
    /// </summary>
    /// <param name="quest">要接取的任务</param>
    public bool AcceptQuest(QuestData quest)
    {
        if (!quest || !IsQuestValid(quest.Model))
        {
            MessageManager.Instance.New("无效任务");
            return(false);
        }
        if (!MiscFuntion.CheckCondition(quest.Model.AcceptCondition) && !SaveManager.Instance.IsLoading)
        {
            MessageManager.Instance.New("未满足任务接取条件");
            return(false);
        }
        if (HasOngoingQuest(quest))
        {
            MessageManager.Instance.New("已经在执行");
            return(false);
        }
        ObjectiveData currentObjective = quest.Objectives[0];

        for (int i = 0; i < quest.Objectives.Count; i++)
        {
            var o = quest.Objectives[i];
            o.OnStateChangeEvent += OnObjectiveStateChange;
            if (o is CollectObjectiveData co)
            {
                BackpackManager.Instance.Inventory.OnItemAmountChanged += co.UpdateCollectAmount;
                if (o.AllPrevComplete)
                {
                    if (co.Model.CheckBagAtStart && !SaveManager.Instance.IsLoading)
                    {
                        co.CurrentAmount = BackpackManager.Instance.GetAmount(co.Model.ItemToCollect);
                    }
                    else if (!co.Model.CheckBagAtStart && !SaveManager.Instance.IsLoading)
                    {
                        co.amountWhenStart = BackpackManager.Instance.GetAmount(co.Model.ItemToCollect);
                    }
                }
            }
            if (o is KillObjectiveData ko)
            {
                switch (ko.Model.KillType)
                {
                case KillObjectiveType.Specific:
                    GameManager.Enemies[ko.Model.Enemy.ID].ForEach(e => e.OnDeathEvent += ko.UpdateKillAmount);
                    break;

                case KillObjectiveType.Race:
                    foreach (List <Enemy> enemies in GameManager.Enemies.Values.Where(x => x.Count > 0 && x[0].Info.Race && x[0].Info.Race == ko.Model.Race))
                    {
                        enemies.ForEach(e => e.OnDeathEvent += ko.UpdateKillAmount);
                    }
                    break;

                case KillObjectiveType.Group:
                    foreach (List <Enemy> enemies in GameManager.Enemies.Values.Where(x => x.Count > 0 && ko.Model.Group.Contains(x[0].Info.ID)))
                    {
                        enemies.ForEach(e => e.OnDeathEvent += ko.UpdateKillAmount);
                    }
                    break;

                case KillObjectiveType.Any:
                    foreach (List <Enemy> enemies in GameManager.Enemies.Select(x => x.Value))
                    {
                        enemies.ForEach(e => e.OnDeathEvent += ko.UpdateKillAmount);
                    }
                    break;
                }
            }
            if (o is TalkObjectiveData to)
            {
                if (!o.IsComplete)
                {
                    var talker = DialogueManager.Instance.Talkers[to.Model.NPCToTalk.ID];
                    talker.objectivesTalkToThis.Add(to);
                    o.OnStateChangeEvent += talker.TryRemoveObjective;
                }
            }
            if (o is MoveObjectiveData mo)
            {
                mo.targetPoint = CheckPointManager.Instance.CreateCheckPoint(mo.Model.AuxiliaryPos, mo.UpdateMoveState);
            }
            if (o is SubmitObjectiveData so)
            {
                if (!o.IsComplete)
                {
                    var talker = DialogueManager.Instance.Talkers[so.Model.NPCToSubmit.ID];
                    talker.objectivesSubmitToThis.Add(so);
                    o.OnStateChangeEvent += talker.TryRemoveObjective;
                }
            }
            if (o is TriggerObjectiveData cuo)
            {
                TriggerManager.Instance.RegisterTriggerEvent(cuo.UpdateTriggerState);
                var state = TriggerManager.Instance.GetTriggerState(cuo.Model.TriggerName);
                if (cuo.Model.CheckStateAtAcpt && state != TriggerState.NotExist)
                {
                    TriggerManager.Instance.SetTrigger(cuo.Model.TriggerName, state == TriggerState.On);
                }
            }
        }
        quest.InProgress = true;
        questsInProgress.Add(quest);
        if (quest.Model.NPCToSubmit)
        {
            DialogueManager.Instance.Talkers[quest.Model.NPCToSubmit.ID].TransferQuestToThis(quest);
        }
        if (!SaveManager.Instance.IsLoading)
        {
            MessageManager.Instance.New($"接取了任务 [{quest.Model.Title}]");
        }
        quest.latestHandleDays = TimeManager.Instance.Days;
        CreateObjectiveMapIcon(quest.Objectives[0]);
        NotifyCenter.PostNotify(QuestStateChanged, quest, false);
        return(true);
    }