/// <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); }
/// <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); }