예제 #1
0
    public float QuestProgressWithId(string id)
    {
        if (HasCompleteQuestWithID(id))
        {
            return(1f);                           //已完成
        }
        else if (!HasOngoingQuestWithID(id))
        {
            return(0f);                                //未开始
        }
        //
        Quest quest = QuestsOngoing.Find(x => x.ID == id);

        if (quest.ObjectiveInstances.Count > 0)
        {
            float current = 0;
            foreach (Objective o in quest.ObjectiveInstances)
            {
                float n = o.CurrentAmount * 1f / o.Amount;
                current += n;
            }
            return(current * (1f / quest.ObjectiveInstances.Count));
        }
        return(0f);
    }
예제 #2
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);
 }
예제 #3
0
 private IEnumerable <Quest> QuestRequiredItem(string itemId, int leftAmount)
 {
     return(QuestsOngoing.FindAll(x => x.RequiredItem(itemId, leftAmount)).AsEnumerable());
 }
예제 #4
0
 public bool HasOngoingQuestWithID(string questID)
 {
     return(QuestsOngoing.Exists(x => x.ID == questID));
 }
예제 #5
0
 /// <summary>
 /// 判断该任务是否处于进行中任务集合
 /// </summary>
 /// <param name="quest">该任务</param>
 /// <returns></returns>
 public bool HasOngoingQuest(Quest quest)
 {
     return(QuestsOngoing.Contains(quest));
 }
예제 #6
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);
    }
예제 #7
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);
    }