422 lines
7.9 KiB
C#
422 lines
7.9 KiB
C#
![]() |
// ***********************************************************************
|
|||
|
// Assembly : Unity
|
|||
|
// Author : Kimch
|
|||
|
// Created : 2017-10-24
|
|||
|
//
|
|||
|
// Last Modified By : Kimch
|
|||
|
// Last Modified On :
|
|||
|
// ***********************************************************************
|
|||
|
// <copyright file= "Mission" company=""></copyright>
|
|||
|
// <summary></summary>
|
|||
|
// ***********************************************************************
|
|||
|
using System;
|
|||
|
using UnityEngine;
|
|||
|
|
|||
|
namespace G
|
|||
|
{
|
|||
|
public class Mission : IComparable<Mission>
|
|||
|
{
|
|||
|
#region Enum
|
|||
|
|
|||
|
public enum Status : byte
|
|||
|
{
|
|||
|
None = 2,
|
|||
|
Complete = 1,
|
|||
|
Reward = 3,
|
|||
|
}
|
|||
|
|
|||
|
public enum Type
|
|||
|
{
|
|||
|
Daily = 1,
|
|||
|
Achievement = 2,
|
|||
|
}
|
|||
|
|
|||
|
#endregion
|
|||
|
|
|||
|
#region Field
|
|||
|
|
|||
|
public readonly ItemMission item;
|
|||
|
|
|||
|
private CodeStage.AntiCheat.ObscuredTypes.ObscuredInt _curValue;
|
|||
|
private CodeStage.AntiCheat.ObscuredTypes.ObscuredBool _rewarded;
|
|||
|
|
|||
|
private Item.ItemInfo[] _rewardInfos;
|
|||
|
|
|||
|
#endregion
|
|||
|
|
|||
|
#region Properties
|
|||
|
|
|||
|
/// <summary>
|
|||
|
///
|
|||
|
/// </summary>
|
|||
|
public int id => item.id;
|
|||
|
|
|||
|
/// <summary>
|
|||
|
///
|
|||
|
/// </summary>
|
|||
|
public string name
|
|||
|
{
|
|||
|
get { return KLocalization.GetLocalString(item.nameId); }
|
|||
|
}
|
|||
|
|
|||
|
/// <summary>
|
|||
|
///
|
|||
|
/// </summary>
|
|||
|
public string description
|
|||
|
{
|
|||
|
get
|
|||
|
{
|
|||
|
#if UNITY_EDITOR
|
|||
|
try
|
|||
|
{
|
|||
|
#endif
|
|||
|
if (item.descriptionId > 0)
|
|||
|
{
|
|||
|
var descriptionFormat = KLocalization.GetLocalString(item.descriptionId);
|
|||
|
|
|||
|
if (eventArg1 > 0)
|
|||
|
return string.Format(descriptionFormat, maxValue, eventArg1);
|
|||
|
else
|
|||
|
return string.Format(descriptionFormat, item.eventTarget);
|
|||
|
}
|
|||
|
return "";
|
|||
|
#if UNITY_EDITOR
|
|||
|
}
|
|||
|
catch (Exception ex)
|
|||
|
{
|
|||
|
Debug.LogException(ex);
|
|||
|
return $"任务 {item.id} 描述异常 {ex.Message}";
|
|||
|
}
|
|||
|
#endif
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
/// <summary>
|
|||
|
///
|
|||
|
/// </summary>
|
|||
|
public string missionText
|
|||
|
{
|
|||
|
get
|
|||
|
{
|
|||
|
#if UNITY_EDITOR
|
|||
|
try
|
|||
|
{
|
|||
|
#endif
|
|||
|
if (item.descriptionId > 0)
|
|||
|
{
|
|||
|
var descriptionFormat = KLocalization.GetLocalString(item.descriptionId);
|
|||
|
|
|||
|
if (eventArg1 > 0)
|
|||
|
return string.Format(descriptionFormat, maxValue, eventArg1) + $"({curValue}/{maxValue})";
|
|||
|
else
|
|||
|
return string.Format(descriptionFormat, maxValue) + $"({curValue}/{maxValue})";
|
|||
|
}
|
|||
|
return "";
|
|||
|
#if UNITY_EDITOR
|
|||
|
}
|
|||
|
catch (Exception ex)
|
|||
|
{
|
|||
|
Debug.LogException(ex);
|
|||
|
return item.id + " " + ex.Message;
|
|||
|
}
|
|||
|
#endif
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
/// <summary>
|
|||
|
/// 主线
|
|||
|
/// </summary>
|
|||
|
public string missionText2
|
|||
|
{
|
|||
|
get
|
|||
|
{
|
|||
|
#if UNITY_EDITOR
|
|||
|
try
|
|||
|
{
|
|||
|
#endif
|
|||
|
if (item.descriptionId > 0)
|
|||
|
{
|
|||
|
var descriptionFormat = KLocalization.GetLocalString(item.descriptionId);
|
|||
|
|
|||
|
if (eventArg1 > 0)
|
|||
|
return string.Format(descriptionFormat, maxValue, eventArg1) + $"<color=#5DFF61>({curValue}/{maxValue})";
|
|||
|
else
|
|||
|
return string.Format(descriptionFormat, maxValue) + $"<color=#5DFF61>({curValue}/{maxValue})";
|
|||
|
}
|
|||
|
return "";
|
|||
|
#if UNITY_EDITOR
|
|||
|
}
|
|||
|
catch (Exception ex)
|
|||
|
{
|
|||
|
Debug.LogException(ex);
|
|||
|
return item.id + " " + ex.Message;
|
|||
|
}
|
|||
|
#endif
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
/// <summary>
|
|||
|
/// 名字加数量
|
|||
|
/// </summary>
|
|||
|
public string rewardText
|
|||
|
{
|
|||
|
get
|
|||
|
{
|
|||
|
if (rewards != null && rewards.Length > 0)
|
|||
|
{
|
|||
|
var reward = rewards[0];
|
|||
|
return $"奖励:{reward.propItem.name}x{reward.count}";
|
|||
|
}
|
|||
|
return default;
|
|||
|
}
|
|||
|
}
|
|||
|
/// <summary>
|
|||
|
/// 数量
|
|||
|
/// </summary>
|
|||
|
public string rewardText2
|
|||
|
{
|
|||
|
get
|
|||
|
{
|
|||
|
if (rewards != null && rewards.Length > 0)
|
|||
|
{
|
|||
|
var reward = rewards[0];
|
|||
|
return $"x{reward.count}";
|
|||
|
}
|
|||
|
return default;
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
/// <summary>
|
|||
|
///
|
|||
|
/// </summary>
|
|||
|
public Item.ItemInfo[] rewards => _rewardInfos;
|
|||
|
|
|||
|
/// <summary>
|
|||
|
///
|
|||
|
/// </summary>
|
|||
|
public int eventId => item.eventId;
|
|||
|
|
|||
|
/// <summary>
|
|||
|
/// 参数1
|
|||
|
/// </summary>
|
|||
|
public int eventArg1 => item.eventArgs != null && item.eventArgs.Length > 0 ? item.eventArgs[0] : 0;
|
|||
|
/// <summary>
|
|||
|
/// 参数2
|
|||
|
/// </summary>
|
|||
|
public int eventArg2 => item.eventArgs != null && item.eventArgs.Length > 1 ? item.eventArgs[1] : 0;
|
|||
|
|
|||
|
/// <summary>
|
|||
|
///
|
|||
|
/// </summary>
|
|||
|
/// <param name="arg"></param>
|
|||
|
/// <returns></returns>
|
|||
|
public bool CheckEventArg1(int arg)
|
|||
|
{
|
|||
|
return item.eventArgs == null || item.eventArgs.Length == 0 || item.eventArgs[0] == arg;
|
|||
|
}
|
|||
|
|
|||
|
/// <summary>
|
|||
|
///
|
|||
|
/// </summary>
|
|||
|
/// <param name="arg"></param>
|
|||
|
/// <returns></returns>
|
|||
|
public bool OverEventArg1(int arg)
|
|||
|
{
|
|||
|
return item.eventArgs == null || item.eventArgs.Length == 0 || item.eventArgs[0] <= arg;
|
|||
|
}
|
|||
|
|
|||
|
/// <summary>
|
|||
|
///
|
|||
|
/// </summary>
|
|||
|
/// <param name="arg1"></param>
|
|||
|
/// <param name="arg2"></param>
|
|||
|
/// <returns></returns>
|
|||
|
public bool CheckEventArg2(int arg1, int arg2)
|
|||
|
{
|
|||
|
return item.eventArgs == null || item.eventArgs.Length == 0 || (item.eventArgs[0] == arg1 && (item.eventArgs.Length < 2 || item.eventArgs[1] == arg2));
|
|||
|
}
|
|||
|
|
|||
|
/// <summary>
|
|||
|
///
|
|||
|
/// </summary>
|
|||
|
/// <param name="arg1"></param>
|
|||
|
/// <param name="arg2"></param>
|
|||
|
/// <returns></returns>
|
|||
|
public bool OverEventArg2(int arg1, int arg2)
|
|||
|
{
|
|||
|
return item.eventArgs == null || item.eventArgs.Length == 0 || (item.eventArgs[0] <= arg1 && (item.eventArgs.Length < 2 || item.eventArgs[1] <= arg2));
|
|||
|
}
|
|||
|
|
|||
|
/// <summary>
|
|||
|
/// 前置任务
|
|||
|
/// </summary>
|
|||
|
public Mission prevMission
|
|||
|
{
|
|||
|
get { return MissionProxy.Instance.GetMission(item.prev); }
|
|||
|
}
|
|||
|
|
|||
|
/// <summary>
|
|||
|
/// 下个任务
|
|||
|
/// </summary>
|
|||
|
public Mission nextMission
|
|||
|
{
|
|||
|
get;
|
|||
|
set;
|
|||
|
}
|
|||
|
|
|||
|
/// <summary>
|
|||
|
///
|
|||
|
/// </summary>
|
|||
|
public Mission[] nextMissions
|
|||
|
{
|
|||
|
get;
|
|||
|
}
|
|||
|
|
|||
|
/// <summary>
|
|||
|
/// 必要条件
|
|||
|
/// </summary>
|
|||
|
public Mission requirementMission
|
|||
|
{
|
|||
|
get { return MissionProxy.Instance.GetMission(item.requirement); }
|
|||
|
}
|
|||
|
|
|||
|
/// <summary>
|
|||
|
/// 主任务
|
|||
|
/// </summary>
|
|||
|
public Mission mainMission
|
|||
|
{
|
|||
|
get { return item.id > 0 ? MissionProxy.Instance.GetMission(item.requirement) : default; }
|
|||
|
}
|
|||
|
|
|||
|
/// <summary>
|
|||
|
/// 最大值
|
|||
|
/// </summary>
|
|||
|
public int maxValue
|
|||
|
{
|
|||
|
get => item.eventTarget;
|
|||
|
}
|
|||
|
|
|||
|
/// <summary>
|
|||
|
/// 当前值
|
|||
|
/// </summary>
|
|||
|
public int curValue
|
|||
|
{
|
|||
|
get => _curValue;
|
|||
|
set
|
|||
|
{
|
|||
|
if (_curValue < maxValue && value > _curValue)
|
|||
|
{
|
|||
|
_curValue = value;
|
|||
|
if (_curValue >= maxValue)
|
|||
|
{
|
|||
|
MissionProxy.Instance.OnMissionCompleted(this);
|
|||
|
if (this.item.type == 6)
|
|||
|
{
|
|||
|
RewardProxy.Instance.GetRewards(rewards);
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
/// <summary>
|
|||
|
///
|
|||
|
/// </summary>
|
|||
|
public bool isCompleted
|
|||
|
{
|
|||
|
get { return _curValue >= maxValue; }
|
|||
|
}
|
|||
|
|
|||
|
/// <summary>
|
|||
|
/// 可以领取状态
|
|||
|
/// </summary>
|
|||
|
public bool isRewarding
|
|||
|
{
|
|||
|
get { return !_rewarded && isCompleted; }
|
|||
|
}
|
|||
|
|
|||
|
/// <summary>
|
|||
|
/// 已经领取
|
|||
|
/// </summary>
|
|||
|
public bool isRewarded
|
|||
|
{
|
|||
|
get { return _rewarded; }
|
|||
|
set { _rewarded = true; }
|
|||
|
}
|
|||
|
|
|||
|
/// <summary>
|
|||
|
///
|
|||
|
/// </summary>
|
|||
|
public bool isValid
|
|||
|
{
|
|||
|
get { return !this.isCompleted && (item.requirement == 0 || requirementMission.isCompleted); }
|
|||
|
}
|
|||
|
|
|||
|
/// <summary>
|
|||
|
/// 排序
|
|||
|
/// </summary>
|
|||
|
public int sortingOrder
|
|||
|
{
|
|||
|
get
|
|||
|
{
|
|||
|
if (isRewarded)
|
|||
|
{
|
|||
|
return 3;
|
|||
|
}
|
|||
|
if (isCompleted)
|
|||
|
{
|
|||
|
return 1;
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
return 2;
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
/// <summary>
|
|||
|
///
|
|||
|
/// </summary>
|
|||
|
public float progress
|
|||
|
{
|
|||
|
get { return curValue / Mathf.Max(1f, maxValue); }
|
|||
|
}
|
|||
|
|
|||
|
#endregion
|
|||
|
|
|||
|
#region Method
|
|||
|
|
|||
|
public Mission(ItemMission item)
|
|||
|
{
|
|||
|
this.item = item;
|
|||
|
_rewardInfos = Item.ItemInfo.FromArray(item.rewards);
|
|||
|
}
|
|||
|
|
|||
|
public void Set(int data)
|
|||
|
{
|
|||
|
GlobalUtils.SplitNumber824(data, out int status, out int value);
|
|||
|
_curValue = value;
|
|||
|
_rewarded = (status == 3);
|
|||
|
}
|
|||
|
|
|||
|
public int Get()
|
|||
|
{
|
|||
|
return GlobalUtils.CombineNumber824(isRewarded ? 3 : 0, _curValue);
|
|||
|
}
|
|||
|
|
|||
|
public void Reset()
|
|||
|
{
|
|||
|
_curValue = 0;
|
|||
|
_rewarded = false;
|
|||
|
}
|
|||
|
|
|||
|
public int CompareTo(Mission other)
|
|||
|
{
|
|||
|
var result = this.sortingOrder.CompareTo(other.sortingOrder);
|
|||
|
return result != 0 ? result : this.id.CompareTo(other.id);
|
|||
|
}
|
|||
|
|
|||
|
#endregion
|
|||
|
}
|
|||
|
}
|