169 lines
4.9 KiB
C#
169 lines
4.9 KiB
C#
//**********************************************//
|
|
//作者:#喻强#
|
|
//日期:#2018/02/23#
|
|
//简述:#单一属性结构#
|
|
//*********************************************//
|
|
using UnityEngine;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using Thousandto.Core.Base;
|
|
using Thousandto.Code.Global;
|
|
using MSG_RankList;
|
|
using Thousandto.Code.Center;
|
|
using Thousandto.Cfg.Data;
|
|
using Thousandto.Plugins.Common;
|
|
|
|
namespace Thousandto.Code.Logic
|
|
{
|
|
/// <summary>
|
|
/// 单一属性结构 用于解析字符串
|
|
/// </summary>
|
|
public class AttribuiteData
|
|
{
|
|
//属性名字
|
|
public string Name { get; set; }
|
|
|
|
//属性id
|
|
public int AttrId { get; set; }
|
|
//属性值
|
|
public int AttrValue { get; set; }
|
|
//下一等级增加值
|
|
public int NextAddUp { get; set; }
|
|
|
|
private string _attrValueStr;
|
|
private string _nextAddUpStr;
|
|
|
|
public string AttrValueStr
|
|
{
|
|
get
|
|
{
|
|
if(string.IsNullOrEmpty(_attrValueStr))
|
|
{
|
|
if (UsePercent)
|
|
{
|
|
_attrValueStr = string.Format("{0:f2}%", (AttrValue/(float)_division));
|
|
}
|
|
else
|
|
_attrValueStr = "" + AttrValue;
|
|
}
|
|
|
|
return _attrValueStr;
|
|
}
|
|
}
|
|
|
|
public string NextAddUpStr
|
|
{
|
|
get
|
|
{
|
|
if (string.IsNullOrEmpty(_nextAddUpStr))
|
|
{
|
|
if (UsePercent)
|
|
{
|
|
_nextAddUpStr = string.Format("{0:f2}%", (NextAddUp/(float)_division));
|
|
}
|
|
else
|
|
_nextAddUpStr = "" + NextAddUp;
|
|
}
|
|
|
|
return _nextAddUpStr;
|
|
}
|
|
}
|
|
|
|
public bool UsePercent = false;
|
|
|
|
private int _division = 1;
|
|
public int Division { get { return _division; } set { _division = value; } }
|
|
|
|
public static AttribuiteData Parse(string attrStr, bool usePercent = false, int division = 1)
|
|
{
|
|
if (string.IsNullOrEmpty(attrStr))
|
|
return null;
|
|
|
|
|
|
//1_3264_3264 (属性类型_属性值_下一等级增加值)
|
|
string[] strArray = attrStr.Split('_');
|
|
if (strArray.Length < 2)
|
|
return null;
|
|
|
|
AttribuiteData data = new AttribuiteData();
|
|
data.UsePercent = usePercent;
|
|
data.AttrId = int.Parse(strArray[0]);
|
|
data.Name = DeclareAttributeAdd.Get(data.AttrId).Name;
|
|
data.AttrValue = int.Parse(strArray[1]);
|
|
if(strArray.Length > 2)
|
|
data.NextAddUp = int.Parse(strArray[2]);
|
|
|
|
data._division = division;
|
|
|
|
return data;
|
|
}
|
|
public static AttribuiteData ParseWithThis(AttribuiteData socre)
|
|
{
|
|
if (socre == null)
|
|
return null;
|
|
|
|
AttribuiteData data = new AttribuiteData();
|
|
data.UsePercent = socre.UsePercent;
|
|
data.AttrId = socre.AttrId;
|
|
data.Name = socre.Name;
|
|
data.AttrValue = socre.AttrValue;
|
|
|
|
data._division = socre._division;
|
|
|
|
return data;
|
|
}
|
|
|
|
public static List<AttribuiteData> ParseList(string attrStr, bool usePercent = false, int division = 1)
|
|
{
|
|
if (string.IsNullOrEmpty(attrStr))
|
|
return null;
|
|
|
|
List<AttribuiteData> attrList = new List<AttribuiteData>();
|
|
var attrArray = attrStr.Split(';');
|
|
for(int i = 0; i < attrArray.Length; ++i)
|
|
{
|
|
var attrData = Parse(attrArray[i], usePercent, division);
|
|
if(attrData != null)
|
|
{
|
|
attrList.Add(attrData);
|
|
}
|
|
}
|
|
|
|
return attrList;
|
|
}
|
|
|
|
public static Dictionary<int, AttribuiteData> ParseListToDict(string attrStr, bool usePercent = false, int division = 1)
|
|
{
|
|
if (string.IsNullOrEmpty(attrStr))
|
|
return null;
|
|
|
|
Dictionary<int, AttribuiteData> attrDict = new Dictionary<int, AttribuiteData>();
|
|
var attrArray = attrStr.Split(';');
|
|
for (int i = 0; i < attrArray.Length; ++i)
|
|
{
|
|
var attrData = Parse(attrArray[i], usePercent, division);
|
|
if (attrData != null)
|
|
{
|
|
attrDict.Add(attrData.AttrId, attrData);
|
|
}
|
|
}
|
|
|
|
return attrDict;
|
|
}
|
|
|
|
//合并属性
|
|
public static void CombineAttribute(AttribuiteData souce, AttribuiteData append)
|
|
{
|
|
if (souce.AttrId != append.AttrId)
|
|
return;
|
|
|
|
souce.AttrValue += append.AttrValue;
|
|
souce.NextAddUp += append.NextAddUp;
|
|
|
|
//重置字符串
|
|
souce._attrValueStr = null;
|
|
souce._nextAddUpStr = null;
|
|
}
|
|
}
|
|
}
|