388 lines
9.7 KiB
C#
388 lines
9.7 KiB
C#
// ***********************************************************************
|
|
// Assembly : Unity
|
|
// Author : Kimch
|
|
// Created :
|
|
//
|
|
// Last Modified By : Kimch
|
|
// Last Modified On :
|
|
// ***********************************************************************
|
|
// <copyright file= "KTutorialGroup" company=""></copyright>
|
|
// <summary></summary>
|
|
// ***********************************************************************
|
|
namespace G
|
|
{
|
|
using System.Collections.Generic;
|
|
|
|
public sealed class TutorialGroup
|
|
{
|
|
public enum Status
|
|
{
|
|
kNone = 0,
|
|
kStart = 1,//已经开始
|
|
kFinish = 2,
|
|
}
|
|
|
|
#region Field
|
|
|
|
private readonly ItemTutorialGroup _item;
|
|
|
|
private List<TutorialStage> _stages;
|
|
private List<TutorialCondition> _conditions;
|
|
|
|
#endregion
|
|
|
|
#region Property
|
|
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
public int id => _item.id;
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
public int priority => _item.priority;
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
public int[] conditionIds => _item.conditions;
|
|
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
public string text => _item.text;
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
public int status
|
|
{
|
|
get;
|
|
private set;
|
|
}
|
|
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
public bool completed
|
|
{
|
|
get { return status == (int)Status.kFinish; }
|
|
set { status = (int)Status.kFinish; }
|
|
}
|
|
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
public TutorialStage currStage
|
|
{
|
|
get;
|
|
private set;
|
|
}
|
|
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
public TutorialStage nextStage
|
|
{
|
|
get { return currStage != null ? GetNextStage(currStage.step) : null; }
|
|
}
|
|
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
public List<TutorialStage> stages
|
|
{
|
|
get
|
|
{
|
|
if (_stages == null)
|
|
{
|
|
_stages = new List<TutorialStage>();
|
|
TutorialProxy.Instance.GetAllStages(id, _stages);
|
|
_stages.Sort((a, b) => a.step.CompareTo(b.step));
|
|
}
|
|
return _stages;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
public List<TutorialCondition> conditions
|
|
{
|
|
get
|
|
{
|
|
if (_conditions == null)
|
|
{
|
|
var conditionIds = this.conditionIds;
|
|
if (conditionIds != null)
|
|
{
|
|
_conditions = new List<TutorialCondition>(conditionIds.Length);
|
|
foreach (var conditionId in conditionIds)
|
|
{
|
|
var condition = TutorialProxy.Instance.GetCondition(conditionId);
|
|
_conditions.Add(condition);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
_conditions = new List<TutorialCondition>(0);
|
|
}
|
|
}
|
|
return _conditions;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 无效
|
|
/// </summary>
|
|
public bool invalid
|
|
{
|
|
get
|
|
{
|
|
if (_item.invalid > 0)
|
|
{
|
|
var mission = MissionProxy.Instance.GetMission(_item.invalid);
|
|
if (mission != null && mission.isCompleted)
|
|
return true;
|
|
}
|
|
return false;
|
|
}
|
|
}
|
|
|
|
#endregion
|
|
|
|
public TutorialGroup(ItemTutorialGroup item)
|
|
{
|
|
_item = item;
|
|
}
|
|
|
|
#region Method
|
|
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
/// <param name="stageId"></param>
|
|
public void SetCompletedStageId(int stageId)
|
|
{
|
|
if (stageId > 0)
|
|
{
|
|
var tmpStages = this.stages;
|
|
if (tmpStages != null && tmpStages.Count > 0)
|
|
{
|
|
for (int i = 0; i < tmpStages.Count; i++)
|
|
{
|
|
tmpStages[i].completed = true;
|
|
if (tmpStages[i].id == stageId)
|
|
break;
|
|
}
|
|
|
|
if (tmpStages[tmpStages.Count - 1].completed)
|
|
{
|
|
completed = true;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public int GetCompletedStageId()
|
|
{
|
|
var tmpStages = this.stages;
|
|
if (tmpStages != null && tmpStages.Count > 0)
|
|
{
|
|
if (!tmpStages[0].completed)
|
|
return 0;
|
|
//
|
|
int i = tmpStages.Count - 1;
|
|
if (tmpStages[i].completed)
|
|
{
|
|
return tmpStages[i].id;
|
|
}
|
|
//
|
|
for (i = i - 1; i > 0; i--)
|
|
{
|
|
if (tmpStages[i].completed)
|
|
return tmpStages[i].id;
|
|
}
|
|
|
|
return tmpStages[0].id;
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 检查
|
|
/// </summary>
|
|
/// <param name="type"></param>
|
|
/// <returns></returns>
|
|
public bool CheckCondition(int type, int target)
|
|
{
|
|
if (this.invalid)
|
|
return false;
|
|
|
|
if (conditions != null)
|
|
foreach (var condition in conditions)
|
|
{
|
|
if (!((condition.type == 10 || condition.type == 9 || condition.type == type) && condition.GetResult(target)))
|
|
return false;
|
|
}
|
|
return true;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 触发
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public bool Trigger()
|
|
{
|
|
var activeS = GetValidStage();
|
|
if (activeS != null)
|
|
{
|
|
activeS.Start();
|
|
currStage = activeS;
|
|
return true;
|
|
}
|
|
return false;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 完成当前步
|
|
/// </summary>
|
|
public void CompleteStep()
|
|
{
|
|
if (currStage != null)
|
|
{
|
|
currStage.Finish();
|
|
if (!HasNext())
|
|
{
|
|
currStage = null;
|
|
Complete();
|
|
}
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public bool HasNext()
|
|
{
|
|
return currStage != null ? currStage.step < stages.Count : false;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 强制完成
|
|
/// </summary>
|
|
public void Complete()
|
|
{
|
|
this.status = (int)Status.kFinish;
|
|
}
|
|
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
/// <param name="step"></param>
|
|
/// <returns></returns>
|
|
public TutorialStage GetStage(int step)
|
|
{
|
|
if (step > 0 && step <= stages.Count)
|
|
{
|
|
return stages[step - 1];
|
|
}
|
|
return null;
|
|
}
|
|
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
/// <param name="step"></param>
|
|
/// <returns></returns>
|
|
public TutorialStage GetNextStage(int step)
|
|
{
|
|
if (step > 0 && step < stages.Count)
|
|
{
|
|
return stages[step];
|
|
}
|
|
return null;
|
|
}
|
|
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public TutorialStage GetValidStage()
|
|
{
|
|
int validIndex = 0;
|
|
var tmpStages = stages;
|
|
for (int i = tmpStages.Count - 1; i >= 0; i--)
|
|
{
|
|
var tmpStage = tmpStages[i];
|
|
if (tmpStage.isKey && tmpStage.completed)
|
|
{
|
|
validIndex = i + 1;
|
|
break;
|
|
}
|
|
}
|
|
|
|
if (validIndex < tmpStages.Count)
|
|
{
|
|
return tmpStages[validIndex];
|
|
}
|
|
else
|
|
{
|
|
completed = true;
|
|
return null;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public bool HasValidStage()
|
|
{
|
|
if (!completed)
|
|
{
|
|
foreach (var item in stages)
|
|
{
|
|
if (item.isKey && !item.started)
|
|
{
|
|
return true;
|
|
}
|
|
}
|
|
}
|
|
return false;
|
|
}
|
|
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
internal void OnUpdate()
|
|
{
|
|
if (currStage != null)
|
|
{
|
|
if (currStage.completed)
|
|
{
|
|
currStage = nextStage;
|
|
if (currStage != null)
|
|
{
|
|
currStage.Start();
|
|
}
|
|
else
|
|
{
|
|
currStage = null;
|
|
Complete();
|
|
}
|
|
}
|
|
else if (currStage.started)
|
|
{
|
|
currStage.OnUpdate();
|
|
}
|
|
}
|
|
}
|
|
|
|
#endregion
|
|
}
|
|
}
|