312 lines
9.9 KiB
C#
312 lines
9.9 KiB
C#
![]() |
// ***********************************************************************
|
|||
|
// Assembly : Game
|
|||
|
// Author : Kimch
|
|||
|
// Created : 2021-01-03
|
|||
|
// Description :
|
|||
|
// Last Modified By :
|
|||
|
// Last Modified On :
|
|||
|
// ***********************************************************************
|
|||
|
// <copyright file= "RankingProxy" company="Kunpo"></copyright>
|
|||
|
// <summary></summary>
|
|||
|
// ***********************************************************************
|
|||
|
|
|||
|
using F;
|
|||
|
using F.Network;
|
|||
|
using System.Collections;
|
|||
|
using System.Collections.Generic;
|
|||
|
using UnityEngine;
|
|||
|
|
|||
|
namespace G
|
|||
|
{
|
|||
|
/// <summary>
|
|||
|
/// 排行榜
|
|||
|
/// </summary>
|
|||
|
public class RankingProxy : F.GameProxy
|
|||
|
{
|
|||
|
#if UNITY_IOS
|
|||
|
public static int ENDLESS_RANKING_ID = 1;
|
|||
|
public static int PET_RANKING_ID = 2;
|
|||
|
public static int BATTLE_RANKING_ID = 3;
|
|||
|
public static int RICH_RANKING_ID = 4;
|
|||
|
public static int SWORD_RANKING_ID = 5;
|
|||
|
#elif UNITY_ANDROID
|
|||
|
public static int ENDLESS_RANKING_ID = 101;
|
|||
|
public static int PET_RANKING_ID = 102;
|
|||
|
public static int BATTLE_RANKING_ID = 103;
|
|||
|
public static int RICH_RANKING_ID = 104;
|
|||
|
public static int SWORD_RANKING_ID = 105;
|
|||
|
#else
|
|||
|
public static int ENDLESS_RANKING_ID = 201;
|
|||
|
public static int PET_RANKING_ID = 202;
|
|||
|
public static int BATTLE_RANKING_ID = 203;
|
|||
|
public static int RICH_RANKING_ID = 204;
|
|||
|
public static int SWORD_RANKING_ID = 205;
|
|||
|
#endif
|
|||
|
|
|||
|
public class RankingInfo
|
|||
|
{
|
|||
|
/// <summary>
|
|||
|
///
|
|||
|
/// </summary>
|
|||
|
public string userId;
|
|||
|
/// <summary>
|
|||
|
/// 排名
|
|||
|
/// </summary>
|
|||
|
public int ranking;
|
|||
|
/// <summary>
|
|||
|
/// 值
|
|||
|
/// </summary>
|
|||
|
public int value;
|
|||
|
|
|||
|
/// <summary>
|
|||
|
/// 名字
|
|||
|
/// </summary>
|
|||
|
public string name;
|
|||
|
/// <summary>
|
|||
|
/// 签名
|
|||
|
/// </summary>
|
|||
|
public string signature;
|
|||
|
/// <summary>
|
|||
|
/// 头像
|
|||
|
/// </summary>
|
|||
|
public string avatar;
|
|||
|
|
|||
|
public bool isMy;
|
|||
|
|
|||
|
public string userKey
|
|||
|
{
|
|||
|
get { return name + ",0," + avatar; }
|
|||
|
set
|
|||
|
{
|
|||
|
if (string.IsNullOrEmpty(value))
|
|||
|
return;
|
|||
|
var splits = value.Split(',');
|
|||
|
if (splits != null && splits.Length >= 2)
|
|||
|
{
|
|||
|
name = splits[0];
|
|||
|
signature = splits[1];
|
|||
|
if (splits.Length >= 3)
|
|||
|
{
|
|||
|
avatar = splits[2];
|
|||
|
}
|
|||
|
isMy = userId == UserProxy.AccountID;
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
#region Field
|
|||
|
|
|||
|
private readonly Dictionary<int, List<RankingInfo>> _rankingInfos = new Dictionary<int, List<RankingInfo>>();
|
|||
|
private readonly RankingInfo _myRankingInfo = new RankingInfo();
|
|||
|
|
|||
|
#endregion
|
|||
|
|
|||
|
#region Property
|
|||
|
|
|||
|
#endregion
|
|||
|
|
|||
|
#region Method
|
|||
|
|
|||
|
public RankingInfo GetMyRankingInfo(int id)
|
|||
|
{
|
|||
|
_myRankingInfo.isMy = true;
|
|||
|
_myRankingInfo.userId = UserProxy.AccountID;
|
|||
|
_myRankingInfo.name = PlayerProxy.Instance.nickName;
|
|||
|
_myRankingInfo.avatar = PlayerProxy.Instance.headURL;
|
|||
|
_myRankingInfo.ranking = 1000;
|
|||
|
|
|||
|
if (id == ENDLESS_RANKING_ID)
|
|||
|
{
|
|||
|
_myRankingInfo.value = LevelProxy.Instance.highestEndlessStage;
|
|||
|
}
|
|||
|
else if (id == PET_RANKING_ID)
|
|||
|
{
|
|||
|
_myRankingInfo.value = PetProxy.Instance.GetPetCombatValue();
|
|||
|
}
|
|||
|
else if (id == BATTLE_RANKING_ID)
|
|||
|
{
|
|||
|
_myRankingInfo.value = PlayerProxy.Instance.combatValue;
|
|||
|
}
|
|||
|
else if (id == RICH_RANKING_ID)
|
|||
|
{
|
|||
|
_myRankingInfo.value = MoneyProxy.Instance.coin;
|
|||
|
}
|
|||
|
else if (id == SWORD_RANKING_ID)
|
|||
|
{
|
|||
|
_myRankingInfo.value = SwordProxy.Instance.swordLevel;
|
|||
|
}
|
|||
|
|
|||
|
return _myRankingInfo;
|
|||
|
}
|
|||
|
|
|||
|
public IList<RankingInfo> GetRankingInfos(int id)
|
|||
|
{
|
|||
|
return _rankingInfos[id];
|
|||
|
}
|
|||
|
|
|||
|
public RankingInfo UpdateMy(int id, int score)
|
|||
|
{
|
|||
|
var userInfo = ArchiveProxy.Instance.userInfo;
|
|||
|
if (userInfo != null && userInfo.god_rank)
|
|||
|
{
|
|||
|
ENDLESS_RANKING_ID = 1001;
|
|||
|
PET_RANKING_ID = 1002;
|
|||
|
BATTLE_RANKING_ID = 1003;
|
|||
|
RICH_RANKING_ID = 1004;
|
|||
|
SWORD_RANKING_ID = 1005;
|
|||
|
}
|
|||
|
|
|||
|
_myRankingInfo.isMy = true;
|
|||
|
_myRankingInfo.userId = UserProxy.AccountID;
|
|||
|
_myRankingInfo.name = PlayerProxy.Instance.nickName;
|
|||
|
_myRankingInfo.avatar = PlayerProxy.Instance.headURL;
|
|||
|
_myRankingInfo.ranking = 1000;
|
|||
|
_myRankingInfo.value = score;
|
|||
|
return _myRankingInfo;
|
|||
|
}
|
|||
|
|
|||
|
/// <summary>
|
|||
|
///
|
|||
|
/// </summary>
|
|||
|
/// <param name="score"></param>
|
|||
|
public void UploadEndless(int score)
|
|||
|
{
|
|||
|
var rankingInfo = UpdateMy(ENDLESS_RANKING_ID, score);
|
|||
|
ServerProxy.Instance.UploadScore(ENDLESS_RANKING_ID, score, rankingInfo.userKey);
|
|||
|
}
|
|||
|
/// <summary>
|
|||
|
///
|
|||
|
/// </summary>
|
|||
|
/// <param name="score"></param>
|
|||
|
public void UploadPetRanking(int score)
|
|||
|
{
|
|||
|
var rankingInfo = UpdateMy(PET_RANKING_ID, score);
|
|||
|
ServerProxy.Instance.UploadScore(PET_RANKING_ID, rankingInfo.value, rankingInfo.userKey);
|
|||
|
}
|
|||
|
/// <summary>
|
|||
|
///
|
|||
|
/// </summary>
|
|||
|
/// <param name="score"></param>
|
|||
|
public void UploadBattleRanking(int score)
|
|||
|
{
|
|||
|
var rankingInfo = UpdateMy(BATTLE_RANKING_ID, score);
|
|||
|
ServerProxy.Instance.UploadScore(BATTLE_RANKING_ID, rankingInfo.value, rankingInfo.userKey);
|
|||
|
}
|
|||
|
/// <summary>
|
|||
|
///
|
|||
|
/// </summary>
|
|||
|
/// <param name="score"></param>
|
|||
|
public void UploadRichRanking(int score)
|
|||
|
{
|
|||
|
var rankingInfo = UpdateMy(RICH_RANKING_ID, score);
|
|||
|
ServerProxy.Instance.UploadScore(RICH_RANKING_ID, rankingInfo.value, rankingInfo.userKey);
|
|||
|
}
|
|||
|
|
|||
|
public void UploadSwordRanking(int score)
|
|||
|
{
|
|||
|
var rankingInfo = UpdateMy(SWORD_RANKING_ID, score);
|
|||
|
ServerProxy.Instance.UploadScore(SWORD_RANKING_ID, rankingInfo.value, rankingInfo.userKey);
|
|||
|
}
|
|||
|
|
|||
|
IList<object> _allRankingData;
|
|||
|
public void UploadAllRanking()
|
|||
|
{
|
|||
|
if (_allRankingData == null)
|
|||
|
{
|
|||
|
_allRankingData = new List<object>();
|
|||
|
_allRankingData.Add(new Dictionary<string, object>());
|
|||
|
_allRankingData.Add(new Dictionary<string, object>());
|
|||
|
_allRankingData.Add(new Dictionary<string, object>());
|
|||
|
_allRankingData.Add(new Dictionary<string, object>());
|
|||
|
}
|
|||
|
|
|||
|
var rankingInfo = UpdateMy(PET_RANKING_ID, PetProxy.Instance.combatValue);
|
|||
|
var dict = _allRankingData[0] as Dictionary<string, object>;
|
|||
|
dict["rank_id"] = PET_RANKING_ID;
|
|||
|
dict["score"] = rankingInfo.value;
|
|||
|
|
|||
|
rankingInfo = UpdateMy(BATTLE_RANKING_ID, PlayerProxy.Instance.combatValue);
|
|||
|
dict = _allRankingData[1] as Dictionary<string, object>;
|
|||
|
dict["rank_id"] = BATTLE_RANKING_ID;
|
|||
|
dict["score"] = rankingInfo.value;
|
|||
|
|
|||
|
rankingInfo = UpdateMy(RICH_RANKING_ID, MoneyProxy.Instance.coin);
|
|||
|
dict = _allRankingData[2] as Dictionary<string, object>;
|
|||
|
dict["rank_id"] = RICH_RANKING_ID;
|
|||
|
dict["score"] = rankingInfo.value;
|
|||
|
|
|||
|
rankingInfo = UpdateMy(SWORD_RANKING_ID, SwordProxy.Instance.swordLevel);
|
|||
|
dict = _allRankingData[3] as Dictionary<string, object>;
|
|||
|
dict["rank_id"] = SWORD_RANKING_ID;
|
|||
|
dict["score"] = rankingInfo.value;
|
|||
|
|
|||
|
ServerProxy.Instance.UploadScore(_allRankingData, rankingInfo.userKey);
|
|||
|
}
|
|||
|
|
|||
|
public override void Recv(IPacket packet)
|
|||
|
{
|
|||
|
if (!_rankingInfos.TryGetValue(packet.id, out var rankings))
|
|||
|
{
|
|||
|
rankings = new List<RankingInfo>();
|
|||
|
_rankingInfos.Add(packet.id, rankings);
|
|||
|
}
|
|||
|
|
|||
|
int maxValue = int.MaxValue;
|
|||
|
switch (packet.id)
|
|||
|
{
|
|||
|
case 1:
|
|||
|
case 101:
|
|||
|
maxValue = 200;
|
|||
|
break;
|
|||
|
case 2:
|
|||
|
case 102:
|
|||
|
maxValue = 10000000;
|
|||
|
break;
|
|||
|
case 3:
|
|||
|
case 103:
|
|||
|
maxValue = 20000000;
|
|||
|
break;
|
|||
|
case 5:
|
|||
|
case 105:
|
|||
|
maxValue = 1000;
|
|||
|
break;
|
|||
|
}
|
|||
|
|
|||
|
rankings.Clear();
|
|||
|
if (packet.data is IList<object> list)
|
|||
|
for (int i = 0; i < list.Count; i++)
|
|||
|
{
|
|||
|
var listData = list.GetDictionary(i);
|
|||
|
|
|||
|
var uid = listData.GetString("uid");
|
|||
|
var score = listData.GetInt("score");
|
|||
|
var user_key = listData.GetString("user_key");
|
|||
|
|
|||
|
var rankingInfo = new RankingInfo
|
|||
|
{
|
|||
|
userId = uid,
|
|||
|
value = Mathf.Min(maxValue, score),
|
|||
|
ranking = i + 1,
|
|||
|
userKey = user_key,
|
|||
|
};
|
|||
|
rankings.Add(rankingInfo);
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
#endregion
|
|||
|
|
|||
|
#region Unity
|
|||
|
|
|||
|
public static RankingProxy Instance;
|
|||
|
|
|||
|
// Use this for initialization
|
|||
|
private void Awake()
|
|||
|
{
|
|||
|
Instance = this;
|
|||
|
}
|
|||
|
|
|||
|
#endregion
|
|||
|
}
|
|||
|
}
|