public IEnumerator questRemovedAfterCompletion()
    {
        // Use the Assert class to test conditions.
        // yield to skip a frame

        var exampleQuest = new GameObject().AddComponent <Quest>(); //Create an example quest to test and assign some of its basic needs

        exampleQuest.questName       = "Test";
        exampleQuest.experienceAward = 20;
        exampleQuest.isComplete      = false;
        exampleQuest.itemReward      = "Wood";

        CollectObjective exampleObj = new CollectObjective(exampleQuest, "TESTITEM", "Collect a test item", false, 0, 1); //Example objective made for a quest, that asks for a tesitem to be picked up

        exampleQuest.objectives.Add(exampleObj);                                                                          //Add objective to quest

        var itemDatabase = new GameObject().AddComponent <ItemDatabase>();                                                //Creates item database and builds it to allow access to items

        itemDatabase.buildDatabase();                                                                                     //Build item database to allow access to items

        var inv = new GameObject().AddComponent <Inventory>();                                                            //Creates inventory object

        inv.addQuestTest(exampleQuest);                                                                                   //Calls inventory method to add quest

        inv.addTest("TESTITEM", itemDatabase);                                                                            //Adds one testitem to inventory, to complete quest

        exampleObj.itemPickedUp(itemDatabase.getItem("TESTITEM"));                                                        //Checks if item picked up is the one needed for quest

        exampleQuest.checkObjectivesTest();                                                                               //Check if all the objectives for the quest are complete

        yield return(null);                                                                                               //Waits a second

        Assert.IsTrue(exampleQuest.isComplete);                                                                           //Should return true indicating all objectives of the quest are completed
    }
Exemple #2
0
 /// <summary>
 /// 完成任务
 /// </summary>
 public bool CompleteTask(Task task)
 {
     if (!task)
     {
         return(false);
     }
     task = ResMgr.Instance.Load <Task>(task.TaskID);
     if (OnGoingTask != null && task.IsComplete)
     {
         cmpleteTask    = task;
         task.IsOngoing = false;
         OnGoingTask    = null;
         DoneTaskList.Add(task);
         GameDataMgr.Instance.CompleteTask(task);
         //如果该任务在中转站中,需要消除
         if (TaskGiverMgr.Instance.GiverTransferStation.ContainsKey(task.CmpltNpcID))
         {
             TaskGiverMgr.Instance.GiverTransferStation.Remove(task.CmpltNpcID);
         }
         foreach (Objective o in task.Objectives)
         {
             o.OnFinishThisEvent -= UpdateCollectObjectives;
             if (o is CollectObjective)
             {
                 CollectObjective co = o as CollectObjective;
                 GameDataMgr.Instance.RemoveTaskCoItem(co.ItemID, co.Amount);
                 GameDataMgr.Instance.playerInfo.OnGetItemEvent -= co.UpdateCollectAmountUp;
             }
             if (o is KillObjective)
             {
                 KillObjective ko = o as KillObjective;
                 LevelManager.Instance.OnDeathEvent -= ko.UpdateKillAmount;
             }
             if (o is TalkObjective)
             {
                 TalkObjective to = o as TalkObjective;
                 if (TaskGiverMgr.Instance.CmpDbTransferStation.ContainsKey(to.TalkerID))
                 {
                     TaskGiverMgr.Instance.CmpDbTransferStation.Remove(to.TalkerID);
                 }
                 TaskGiverMgr.Instance.OnTalkFinishEvent -= to.UpdateTalkStatus;
             }
         }
         //奖励
         if (task.OnCmpltDialog != null)
         {
             DialogMgr.Instance.rewardEvent += Reward;
         }
         else
         {
             Reward();
         }
         return(true);
     }
     return(false);
 }
Exemple #3
0
 /// <summary>
 /// 放弃任务
 /// </summary>
 /// <param name="quest">放弃的任务</param>
 /// <param name="loadMode">是否为读档模式</param>
 /// <returns></returns>
 public bool AbandonQuest(Quest quest, bool loadMode = false)
 {
     if (HasOngoingQuest(quest) && quest && quest.Abandonable)
     {
         quest.IsOngoing = false;
         QuestsOngoing.Remove(quest);
         foreach (Objective o in quest.ObjectiveInstances)
         {
             if (o is CollectObjective)
             {
                 CollectObjective co = o as CollectObjective;
                 TriggerManager.Instance.OnGetItemEvent  += co.UpdateCollectAmount;
                 TriggerManager.Instance.OnLoseItemEvent += co.UpdateCollectAmountDown;
             }
             if (o is KillObjective)
             {
                 KillObjective ko = o as KillObjective;
                 ko.CurrentAmount = 0;
                 TriggerManager.Instance.OnUnitDeathEvent -= ko.UpdateKillAmount;
             }
             if (o is TalkObjective)
             {
             }
             if (o is SubmitObjective)
             {
             }
             if (o is CustomObjective)
             {
                 CustomObjective cuo = o as CustomObjective;
                 cuo.CurrentAmount = 0;
                 TriggerManager.Instance.OnTriggerSetEvent -= cuo.UpdateTriggerState;
             }
         }
         if (!quest.SbmtOnOriginalNPC)
         {
         }
         if (QuestsOngoing.Count < 1)
         {
         }
         return(true);
     }
     else if (!quest.Abandonable)
     {
         PopoutController.CreatePopoutAlert("", "该任务无法放弃"
                                            , 50, true, PopoutController.PopoutWIndowAlertType.ConfirmMessage
                                            , null);
     }
     return(false);
 }
 public CollectObjectiveInstance(CollectObjective objective, MLQuestInstance instance)
     : base(instance, objective) =>
Exemple #5
0
    /// <summary>
    /// 接取任务
    /// </summary>
    /// <param name="quest">要接取的任务</param>
    /// <param name="loadMode">是否读档模式</param>
    /// <returns></returns>
    public bool AcceptQuest(Quest quest, bool loadMode = false)
    {
        if (!quest || !quest.IsValid)
        {
            //PopoutController.CreatePopoutMessage("无效任务", 25);
            Debug.Log("无效任务");
            return(false);
        }
        if (HasOngoingQuest(quest))
        {
            //PopoutController.CreatePopoutMessage("任务正在执行", 25);
            Debug.Log("任务正在执行");
            return(false);
        }

        if (quest.Group)
        {
        }

        foreach (Objective o in quest.ObjectiveInstances)
        {
            if (o is CollectObjective)
            {
                CollectObjective co = o as CollectObjective;
                TriggerManager.Instance.OnGetItemEvent  += co.UpdateCollectAmount;
                TriggerManager.Instance.OnLoseItemEvent += co.UpdateCollectAmountDown;
            }
            if (o is KillObjective)
            {
                KillObjective ko = o as KillObjective;
                TriggerManager.Instance.OnUnitDeathEvent += ko.UpdateKillAmount;
            }
            if (o is TalkObjective)
            {
            }
            if (o is SubmitObjective)
            {
            }
            if (o is CustomObjective)
            {
                CustomObjective cuo = o as CustomObjective;
                TriggerManager.Instance.OnTriggerSetEvent += cuo.UpdateTriggerState;
                if (cuo.CheckStateAtAcpt)
                {
                    TriggerManager.Instance.SetTrigger(cuo.TriggerName
                                                       , TriggerManager.Instance.GetTriggerState(cuo.TriggerName));
                }
            }
            o.OnStateChangeEvent += OnObjectiveStateChange;
        }
        quest.IsOngoing = true;
        QuestsOngoing.Add(quest);
        if (!quest.SbmtOnOriginalNPC)
        {
        }

        if (!loadMode)
        {
            PopoutController.CreatePopoutMessage("接取任务[" + quest.TITLE + "]", 50);
        }
        if (quest.ObjectiveInstances.Count > 0)
        {
            Objective firstObj = quest.ObjectiveInstances[0];
            //
        }
        return(true);
    }
Exemple #6
0
    /// <summary>
    /// 完成任务
    /// </summary>
    /// <param name="quest">完成的任务</param>
    /// <param name="loadMode">是否为读档模式</param>
    /// <returns></returns>
    public bool CompleteQuest(Quest quest, bool loadMode = false)
    {
        if (!quest)
        {
            return(false);
        }
        if (HasOngoingQuest(quest) && quest.IsComplete)
        {
            if (!loadMode)
            {
                foreach (ItemInfo rwi in quest.QuestItemReward.RewardItems)
                {
                    //if()
                }
                foreach (QuestItemReward.DictItemInfo dwi
                         in quest.QuestItemReward.DictRewardItems)
                {
                    //if()
                }

                List <Quest> questsReqThisQuestItem = new List <Quest>();
                foreach (Objective o in quest.ObjectiveInstances)
                {
                    if (o is CollectObjective)
                    {
                        CollectObjective co = o as CollectObjective;
                        questsReqThisQuestItem = QuestRequiredItem(co.Item
                                                                   , SDDataManager.Instance.GetItemAmount(co.Item.ID) - o.Amount)
                                                 .ToList();
                    }
                    if (questsReqThisQuestItem.Contains(quest) &&
                        questsReqThisQuestItem.Count > 1)
                    //需要道具的任务群包含该任务且数量多于一个,说明其他任务对该任务提交的道具存在依赖
                    {
                        PopoutController.CreatePopoutMessage
                            ("提交失败,其他任务对该任务提交物品有需求", 50);
                        return(false);
                    }
                }
            }
            quest.IsOngoing = false;
            QuestsOngoing.Remove(quest);
            RemoveQuestAgentByQuest(quest);
            //quest.current
            QuestsComplete.Add(quest);
            //
            foreach (Objective o in quest.ObjectiveInstances)
            {
                o.OnStateChangeEvent -= OnObjectiveStateChange;
                if (o is CollectObjective)
                {
                    CollectObjective co = o as CollectObjective;
                    TriggerManager.Instance.OnGetItemEvent  += co.UpdateCollectAmount;
                    TriggerManager.Instance.OnLoseItemEvent += co.UpdateCollectAmountDown;
                    if (!loadMode && co.LoseItemAtSbmt)
                    {
                        SDDataManager.Instance.LoseItem(co.Item.ID, o.Amount);
                    }
                }
                if (o is KillObjective)
                {
                    KillObjective ko = o as KillObjective;
                    TriggerManager.Instance.OnUnitDeathEvent -= ko.UpdateKillAmount;
                }
                if (o is TalkObjective)
                {
                }
                if (o is SubmitObjective)
                {
                }
                if (o is CustomObjective)
                {
                    CustomObjective cuo = o as CustomObjective;
                    TriggerManager.Instance.OnTriggerSetEvent -= cuo.UpdateTriggerState;
                }
            }
            if (!loadMode)
            {
                SDDataManager.Instance.AddCoin(quest.RewardCoin);
                SDDataManager.Instance.AddDamond(quest.RewardDamond);
                SDDataManager.Instance.AddJiancai(quest.RewardJianCai);

                float R = UnityEngine.Random.Range(0, 1);
                if (R <= quest.QuestItemReward.GetPossible)
                {
                    foreach (ItemInfo info in quest.QuestItemReward.RewardItems)
                    {
                        SDDataManager.Instance.AddItem(info.ItemID, info.Amount);
                    }
                    foreach (QuestItemReward.DictItemInfo INFO
                             in quest.QuestItemReward.DictRewardItems)
                    {
                        float _R = UnityEngine.Random.Range(0, 1);
                        if (_R <= INFO.Possibility)
                        {
                            SDDataManager.Instance.AddItem(INFO.ID, INFO.amount);
                        }
                    }
                }
                PopoutController.CreatePopoutMessage
                    ("完成任务 [" + quest.TITLE + "]", 50);
            }
            return(true);
        }
        return(false);
    }
Exemple #7
0
 /// <summary>
 /// 接受任务
 /// </summary>
 public bool AcceptTask(Task task)
 {
     if (!task)
     {
         return(false);
     }
     if (OnGoingTask != null)
     {
         return(false);
     }
     foreach (Objective o in task.Objectives)
     {
         if (o is CollectObjective)
         {
             CollectObjective co = o as CollectObjective;
             co.CurrentAmount = 0;
             GameDataMgr.Instance.playerInfo.OnGetItemEvent += co.UpdateCollectAmountUp;
             //获取时是否检查一遍背包以检测任务是否已可完成
             if (co.CheckBagAtAccept)
             {
                 int currentNum = GameDataMgr.Instance.playerInfo.hideList.Any(x => x.id == co.ItemID) ? GameDataMgr.Instance.playerInfo.hideList.Find(x => x.id == co.ItemID).num : 0;
                 co.UpdateCollectAmountUp(co.ItemID, currentNum);
             }
         }
         else if (o is KillObjective)
         {
             KillObjective ko = o as KillObjective;
             ko.CurrentAmount = 0;
             //检验是否为目的enermy的任务交给关卡管理器(它管理怪物生成和记录死亡的)
             LevelManager.Instance.OnDeathEvent += ko.UpdateKillAmount;
         }
         else if (o is TalkObjective)
         {
             TalkObjective to = o as TalkObjective;
             to.CurrentAmount = 0;
             if (TaskGiverMgr.Instance.AllTaskGiverInCurrentScene.ContainsKey(to.TalkerID))
             {
                 TaskGiverMgr.Instance.AllTaskGiverInCurrentScene[to.TalkerID].GetComponent <DialogListenTrigger>().SetDialogSp(to.TalkDb, true);
             }
             else if (!TaskGiverMgr.Instance.CmpDbTransferStation.ContainsKey(to.TalkerID))
             {
                 TaskGiverMgr.Instance.CmpDbTransferStation.Add(to.TalkerID, to.TalkDb);
             }
             //检验是否为目的NPC的任务交给NPC管理器(它管理NPC的读取)
             TaskGiverMgr.Instance.OnTalkFinishEvent += to.UpdateTalkStatus;
         }
         o.OnFinishThisEvent += UpdateCollectObjectives;
     }
     task.IsOngoing = true;
     OnGoingTask    = task;
     GameDataMgr.Instance.AcceptTask(task);
     //如果这个任务不是在原NPC处交任务的话
     if (!task.CmpltOnOriginalNpc)
     {
         //储存到中转站
         if (!TaskGiverMgr.Instance.GiverTransferStation.ContainsKey(task.CmpltNpcID))
         {
             TaskGiverMgr.Instance.GiverTransferStation.Add(task.CmpltNpcID, task);
         }
         //如果现在场景中就有这个NPC,把这个人物转交给那个NPC
         if (TaskGiverMgr.Instance.AllTaskGiverInCurrentScene.ContainsKey(task.CmpltNpcID))
         {
             TaskGiverMgr.Instance.AllTaskGiverInCurrentScene[task.CmpltNpcID].TransferTaskToThis(task);
         }
     }
     return(true);
 }