using System.Collections;
|
using System.Collections.Generic;
|
using UnityEngine;
|
namespace Snxxz.UI
|
{
|
public class TaskFeedbackModel : Model
|
{
|
Dictionary<int, TaskFeedback> m_TaskFeedbacks = new Dictionary<int, TaskFeedback>();
|
|
ReikiRootModel reikiRootModel { get { return ModelCenter.Instance.GetModel<ReikiRootModel>(); } }
|
PackModel packModel { get { return ModelCenter.Instance.GetModel<PackModel>(); } }
|
TaskModel taskModel { get { return ModelCenter.Instance.GetModel<TaskModel>(); } }
|
|
public override void Init()
|
{
|
ParseConfig();
|
}
|
|
public override void UnInit()
|
{
|
}
|
|
void ParseConfig()
|
{
|
var configs = TaskFeedbackConfig.GetValues();
|
foreach (var config in configs)
|
{
|
if (config.type == 100)
|
{
|
continue;
|
}
|
|
var feedback = new TaskFeedback()
|
{
|
taskId = config.taskId,
|
type = (TaskFeedbackType)config.type,
|
};
|
|
switch (feedback.type)
|
{
|
case TaskFeedbackType.FightPower:
|
case TaskFeedbackType.ReikiPoint:
|
case TaskFeedbackType.Copper:
|
feedback.condition = int.Parse(config.condition);
|
break;
|
case TaskFeedbackType.SideTask:
|
{
|
var array = LitJson.JsonMapper.ToObject<int[][]>(config.condition);
|
if (array != null)
|
{
|
List<int[]> sideTasks = new List<int[]>(array.Length);
|
for (int i = 0; i < array.Length; i++)
|
{
|
sideTasks.Add(array[i]);
|
}
|
feedback.sideTasks = sideTasks;
|
}
|
}
|
break;
|
case TaskFeedbackType.Equip:
|
{
|
var array = LitJson.JsonMapper.ToObject<int[]>(config.condition);
|
feedback.equipCondition = array;
|
}
|
break;
|
}
|
|
m_TaskFeedbacks.Add(config.taskId, feedback);
|
}
|
}
|
|
public bool TryGetTaskFeedback(int taskId, out TaskFeedback feedback)
|
{
|
return m_TaskFeedbacks.TryGetValue(taskId, out feedback);
|
}
|
|
public void ExecuteTaskFeedback(int taskId)
|
{
|
TaskFeedback feedback;
|
if (TryGetTaskFeedback(taskId, out feedback))
|
{
|
var config = TaskFeedbackConfig.Get(taskId);
|
|
switch (feedback.type)
|
{
|
case TaskFeedbackType.FightPower:
|
case TaskFeedbackType.ReikiPoint:
|
case TaskFeedbackType.Guide:
|
case TaskFeedbackType.Equip:
|
{
|
int condition = 0;
|
if (IsSatisfyCondition(feedback, out condition))
|
{
|
if (config.succGuide != 0)
|
{
|
ExecuteGuide(config.succGuide);
|
}
|
}
|
else
|
{
|
if (!string.IsNullOrEmpty(config.remind))
|
{
|
SysNotifyMgr.Instance.ShowTip(config.remind);
|
}
|
if (config.failGuide != 0)
|
{
|
ExecuteGuide(config.succGuide);
|
}
|
}
|
}
|
break;
|
case TaskFeedbackType.SideTask:
|
{
|
int condition = 0;
|
if (IsSatisfyCondition(feedback, out condition))
|
{
|
if (config.succGuide != 0)
|
{
|
ExecuteGuide(config.succGuide);
|
}
|
}
|
else
|
{
|
var sideFeedbackConfig = TaskFeedbackConfig.Get(condition);
|
if (!string.IsNullOrEmpty(sideFeedbackConfig.remind))
|
{
|
SysNotifyMgr.Instance.ShowTip(sideFeedbackConfig.remind);
|
}
|
if (sideFeedbackConfig != null && sideFeedbackConfig.failGuide != 0)
|
{
|
ExecuteGuide(sideFeedbackConfig.failGuide);
|
}
|
}
|
}
|
break;
|
}
|
}
|
}
|
|
public void ExecuteGuide(int id)
|
{
|
var config = GuideConfig.Get(id);
|
if (config == null)
|
{
|
DebugEx.LogFormat("引导<color=#ff0000>{0}</color>未添加", id);
|
return;
|
}
|
switch ((GuideType)config.Type)
|
{
|
case GuideType.Functional:
|
FunctionalGuideCenter.Instance.StartGuide(id);
|
break;
|
default:
|
NewBieCenter.Instance.StartNewBieGuide(id);
|
break;
|
}
|
}
|
|
public bool IsSatisfyCondition(TaskFeedback feedback, out int condition)
|
{
|
condition = feedback.condition;
|
switch (feedback.type)
|
{
|
case TaskFeedbackType.FightPower:
|
return PlayerDatas.Instance.baseData.FightPoint >= feedback.condition;
|
case TaskFeedbackType.SideTask:
|
foreach (var taskId in taskModel.SideQuestsDic.Keys)
|
{
|
for (int i = 0; i < feedback.sideTasks.Count; i++)
|
{
|
if (taskId >= feedback.sideTasks[i][0]
|
&& taskId <= feedback.sideTasks[i][1])
|
{
|
condition = taskId;
|
return false;
|
}
|
}
|
}
|
return true;
|
case TaskFeedbackType.ReikiPoint:
|
return reikiRootModel.GetReikiRootTotalPoint() >= feedback.condition;
|
case TaskFeedbackType.Equip:
|
var items = packModel.GetItems(PackType.Item, new SinglePack.FilterParams()
|
{
|
levels = new List<int>() { feedback.equipCondition[0] },
|
qualitys = new List<int>() { feedback.equipCondition[1] },
|
});
|
return items != null && items.Count > 0;
|
case TaskFeedbackType.Copper:
|
return PlayerDatas.Instance.baseData.allCopper >= (ulong)feedback.condition;
|
case TaskFeedbackType.Guide:
|
return true;
|
}
|
return false;
|
}
|
}
|
|
public struct TaskFeedback
|
{
|
public int taskId;
|
public TaskFeedbackType type;
|
public int condition;
|
public List<int[]> sideTasks;
|
public int[] equipCondition;
|
}
|
|
public enum TaskFeedbackType
|
{
|
FightPower = 1,
|
SideTask = 2,
|
ReikiPoint = 3,
|
Equip = 4,
|
Copper = 5,
|
Guide = 6,
|
}
|
}
|