using System;
|
using System.Collections.Generic;
|
using System.Linq;
|
using System.Text;
|
using TableConfig;
|
using LitJson;
|
|
namespace Snxxz.UI
|
{
|
[XLua.Hotfix]
|
[XLua.LuaCallCSharp]
|
public class CrossServerModel : Model, IBeforePlayerDataInitialize, IAfterPlayerDataInitialize, IPlayerLoginOk
|
{
|
public string PkResultLocalSaveKey { get; private set; }
|
public List<PkResultInfo> localSaveResults { get; private set; }
|
|
public override void Init()
|
{
|
ParseFuncConfig();
|
}
|
|
public void OnBeforePlayerDataInitialize()
|
{
|
InitData();
|
}
|
|
public void OnAfterPlayerDataInitialize()
|
{
|
int playerId = (int)PlayerDatas.Instance.baseData.PlayerID;
|
PkResultLocalSaveKey = StringUtility.Contact("PkResultLocalSaveKey", playerId);
|
GetLocalSaveData();
|
}
|
|
public void OnPlayerLoginOk()
|
{
|
|
}
|
|
public override void UnInit()
|
{
|
|
}
|
|
private void InitData()
|
{
|
curWinRate = 0;
|
sumBattleNum = 0;
|
dayMatchNum = 0;
|
alreadyBuyNum = 0;
|
pkResultInfo = new PkResultInfo();
|
}
|
|
public bool TryGetMaxRank(out int upScore)
|
{
|
upScore = 0;
|
if (pkResultInfo == null) return false;
|
var arenaConfig = Config.Instance.Get<CrossServerArenaConfig>(pkResultInfo.DanLV);
|
if(arenaConfig != null)
|
{
|
upScore = arenaConfig.LVUpScore;
|
}
|
return upScore == 0;
|
}
|
|
public int GetBuyMatchNumPrice()
|
{
|
Equation.Instance.Clear();
|
Equation.Instance.AddKeyValue("buyCnt",alreadyBuyNum);
|
return Equation.Instance.Eval<int>(priceFormula);
|
}
|
|
public bool TryGetWinStreakScore(out int score)
|
{
|
score = 0;
|
if (pkResultInfo.WinStreak < 2) return false;
|
|
Equation.Instance.Clear();
|
Equation.Instance.AddKeyValue("cWinCount",pkResultInfo.WinStreak);
|
score = Equation.Instance.Eval<int>(winStreakScoreFormula);
|
return true;
|
}
|
|
public List<AwardType> sortDayAwardslist = new List<AwardType>();
|
public void SortDayAwardsList()
|
{
|
sortDayAwardslist.Clear();
|
sortDayAwardslist.AddRange(dayAwardTypelist);
|
sortDayAwardslist.Sort(CompareByCompleteProgress);
|
}
|
|
public int CompareByCompleteProgress(AwardType start,AwardType end)
|
{
|
int x = (int)start.progress;
|
int y = (int)end.progress;
|
if (x.CompareTo(y) != 0) return x.CompareTo(y);
|
|
x = dayAwardTypelist.IndexOf(start);
|
y = dayAwardTypelist.IndexOf(end);
|
if (x.CompareTo(y) != 0) return x.CompareTo(y);
|
|
return 0;
|
}
|
|
#region 表数据
|
public int freeMaxMatchNum { get; private set; } //每日免费匹配次数
|
public int buyMaxMatchNum { get; private set; } //每日可购买次数
|
public string priceFormula { get;private set;} //购买匹配次数需要价格公式
|
public string winStreakScoreFormula { get; private set; } //连胜积分公式
|
public List<AwardType> dayAwardTypelist { get; private set; }
|
private void ParseFuncConfig()
|
{
|
var CrossRealmPKAward = Config.Instance.Get<FuncConfigConfig>("CrossRealmPKAward");
|
var dayMatchAwardData = JsonMapper.ToObject(CrossRealmPKAward.Numerical1);
|
var dayWinAwardData = JsonMapper.ToObject(CrossRealmPKAward.Numerical2);
|
dayAwardTypelist = new List<AwardType>();
|
foreach (var num in dayWinAwardData.Keys)
|
{
|
int times = int.Parse(num);
|
var items = dayWinAwardData[num];
|
var awardType = new AwardType(times,1);
|
dayAwardTypelist.Add(awardType);
|
if (items.IsArray)
|
{
|
for(int i = 0; i < items.Count; i++)
|
{
|
var itemInfo = items[i];
|
if(itemInfo.IsArray && itemInfo.Count >= 3)
|
{
|
int id = 0;
|
int.TryParse(itemInfo[0].ToString(), out id);
|
int count = 0;
|
int.TryParse(itemInfo[1].ToString(), out count);
|
int isBind = 0;
|
int.TryParse(itemInfo[2].ToString(), out isBind);
|
AwardItem awardItem = new AwardItem(id, count, isBind);
|
awardType.SetAwardItems(awardItem);
|
}
|
}
|
}
|
}
|
|
foreach (var num in dayMatchAwardData.Keys)
|
{
|
int times = int.Parse(num);
|
var items = dayMatchAwardData[num];
|
var awardType = new AwardType(times,2);
|
dayAwardTypelist.Add(awardType);
|
if (items.IsArray)
|
{
|
for(int i = 0;i < items.Count; i++)
|
{
|
var itemInfo = items[i];
|
if (itemInfo.IsArray && itemInfo.Count >= 3)
|
{
|
int id = 0;
|
int.TryParse(itemInfo[0].ToString(), out id);
|
int count = 0;
|
int.TryParse(itemInfo[1].ToString(), out count);
|
int isBind = 0;
|
int.TryParse(itemInfo[2].ToString(), out isBind);
|
AwardItem awardItem = new AwardItem(id, count, isBind);
|
awardType.SetAwardItems(awardItem);
|
}
|
}
|
}
|
}
|
|
var CrossRealmPKMatchCount = Config.Instance.Get<FuncConfigConfig>("CrossRealmPKMatchCount");
|
freeMaxMatchNum = int.Parse(CrossRealmPKMatchCount.Numerical1);
|
buyMaxMatchNum = int.Parse(CrossRealmPKMatchCount.Numerical2);
|
priceFormula = CrossRealmPKMatchCount.Numerical3;
|
|
var CrossRealmPKScore = Config.Instance.Get<FuncConfigConfig>("CrossRealmPKScore");
|
winStreakScoreFormula = CrossRealmPKScore.Numerical3;
|
}
|
|
public class AwardType
|
{
|
public int type { get; private set; } //1 胜利奖励 2 匹配奖励
|
public int num { get; private set;}
|
public int curCompletedNum { get; private set; }
|
public CompleteProgress progress { get; private set;}
|
public bool IsReceived { get; set; }
|
public List<AwardItem> awardItems = new List<AwardItem>();
|
public AwardType(int _num,int _type)
|
{
|
type = _type;
|
num = _num;
|
curCompletedNum = 0;
|
IsReceived = false;
|
progress = CompleteProgress.Completed;
|
awardItems.Clear();
|
}
|
|
public void SetAwardItems(AwardItem awardItem)
|
{
|
awardItems.Add(awardItem);
|
}
|
|
public void SetCompletedNum(int completedNum)
|
{
|
curCompletedNum = completedNum;
|
if(IsReceived)
|
{
|
curCompletedNum = num;
|
progress = CompleteProgress.AlreadyReceived;
|
}
|
else
|
{
|
progress = curCompletedNum < num ? CompleteProgress.UnCompleted : CompleteProgress.Completed;
|
}
|
}
|
|
public enum CompleteProgress
|
{
|
Completed = 0, //已达成
|
UnCompleted = 1, //未达成
|
AlreadyReceived = 2, //已领取
|
}
|
}
|
|
public struct AwardItem
|
{
|
public int itemId;
|
public int itemCount;
|
public int isBind;
|
public AwardItem(int _id,int _count,int _isBind)
|
{
|
itemId = _id;
|
itemCount = _count;
|
isBind = _isBind;
|
}
|
}
|
#endregion
|
|
#region 协议
|
public int curWinRate { get; private set; } //当前胜率
|
public int sumBattleNum { get; private set; } //对战总场数
|
public int dayMatchNum { get; private set; } //今日匹配次数
|
public int alreadyBuyNum { get; private set;} //今日购买匹配次数
|
public PkResultInfo pkResultInfo { get; private set;}
|
public event Action UpdatePkResultEvent;
|
public void UpdatePKResultInfo(HC003_tagGCCrossRealmPKOverInfo pKOverInfo)
|
{
|
pkResultInfo = new PkResultInfo();
|
pkResultInfo.PkEndTime = pKOverInfo.TimeStr;
|
pkResultInfo.OverType = pKOverInfo.OverType;
|
pkResultInfo.WinnerID = (int)pKOverInfo.WinnerID;
|
pkResultInfo.RoundCount = pKOverInfo.RoundCount;
|
pkResultInfo.RoundWinnerIDs = pKOverInfo.RoundWinnerID;
|
pkResultInfo.AddScore = pKOverInfo.AddScore;
|
pkResultInfo.CurScore = pKOverInfo.Score;
|
pkResultInfo.DanLV = pKOverInfo.DanLV;
|
pkResultInfo.WinStreak = pKOverInfo.CWinCnt;
|
pkResultInfo.VsPlayerName = pKOverInfo.TagName;
|
SetPkInfoLocalSave(pkResultInfo);
|
if(UpdatePkResultEvent != null)
|
{
|
UpdatePkResultEvent();
|
}
|
}
|
|
public class PkResultInfo
|
{
|
public string PkEndTime; // 结算时间,格式 yyyy-MM-dd HH:mm:ss
|
|
public int OverType; // 0-正常,1-有人离线
|
|
public int WinnerID; // 胜方ID(本次战斗结束,不是回合结束)
|
|
public int RoundCount; // PK回合数
|
|
public uint[] RoundWinnerIDs; // 回合获胜ID列表
|
|
public int AddScore; // 本场加分
|
|
public int CurScore; // 当前积分
|
|
public int DanLV; // 当前段位
|
|
public int WinStreak; // 当前连胜数
|
|
public string VsPlayerName; //对手名字
|
}
|
|
public void GetWinAndFailNum(out int winNum,out int failNum)
|
{
|
winNum = 0;
|
failNum = 0;
|
int playerId = (int)PlayerDatas.Instance.baseData.PlayerID;
|
for(int i = 0; i < pkResultInfo.RoundCount; i++)
|
{
|
var winnerId = pkResultInfo.RoundWinnerIDs[i];
|
if(winnerId == playerId)
|
{
|
winNum += 1;
|
}
|
else
|
{
|
failNum += 1;
|
}
|
}
|
}
|
|
/// <summary>
|
/// 1 自己离线 2 对手离线
|
/// </summary>
|
/// <param name="type"></param>
|
/// <returns></returns>
|
public bool TryGetOffLine(out int type)
|
{
|
type = 0;
|
int playerId = (int)PlayerDatas.Instance.baseData.PlayerID;
|
if(pkResultInfo.OverType != 0)
|
{
|
type = playerId == pkResultInfo.WinnerID ? 2 : 1;
|
}
|
return pkResultInfo.OverType != 0;
|
}
|
|
/// <summary>
|
///0-取消匹配; 1-进行匹配
|
/// </summary>
|
/// <param name="type"></param>
|
public void SendCrossMatch(int type)
|
{
|
CC101_tagCMCrossRealmPKMatch match = new CC101_tagCMCrossRealmPKMatch();
|
match.Type = (byte)type;
|
GameNetSystem.Instance.SendInfo(match);
|
}
|
#endregion
|
|
#region 匹配记录
|
|
private void GetLocalSaveData()
|
{
|
localSaveResults = new List<PkResultInfo>();
|
string[] localJsons = LocalSave.GeStringArray(PkResultLocalSaveKey);
|
if(localJsons != null)
|
{
|
for(int i = 0; i < localJsons.Length; i++)
|
{
|
PkResultInfo resultInfo = JsonMapper.ToObject<PkResultInfo>(localJsons[i]);
|
localSaveResults.Add(resultInfo);
|
}
|
}
|
}
|
|
public void SetPkInfoLocalSave(PkResultInfo resultInfo)
|
{
|
if (localSaveResults.Count >= 30)
|
{
|
localSaveResults.RemoveAt(localSaveResults.Count - 1);
|
}
|
localSaveResults.Insert(0,resultInfo);
|
string[] localJsons = new string[localSaveResults.Count];
|
for(int i = 0; i < localJsons.Length; i++)
|
{
|
string json = JsonMapper.ToJson(localSaveResults[i]);
|
localJsons[i] = json;
|
}
|
LocalSave.SetStringArray(PkResultLocalSaveKey,localJsons);
|
}
|
|
#endregion
|
|
#region 红点
|
#endregion
|
|
}
|
}
|