You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

212 lines
6.1 KiB

1 month ago
/*
Sog
2016 by zouwei
*/
using System;
using System.Collections.Generic;
using ProtoCSStruct;
using Sog;
namespace Rank
{
public struct DBRankOnePlayerStruct : IStructObject
{
public int m_objectID;
public int GetObjectID()
{
return m_objectID;
}
public void SetObjectID(int id)
{
m_objectID = id;
}
public bool IsNull()
{
return m_objectID == -1;
}
public DBRankPlayerInfo data;
}
public class RankDataRecord : Sog.Data.DataSeqSave
{
public int RankId;
public long BeginTime;
public bool NeedUpdate;
public long AwardTime; //当期排行榜发奖时间
public List<long> Data; //Uid rank
public long lastRankAwardTime; //上期排行榜结算时间,有些排行榜策划希望玩家手动领取奖励,当下次重置时才把没领的奖励邮件
public List<long> rewardGetUids;
public List<DBRankPlayerInfo> lastRankData;
public RankDataRecord(int rankId)
{
RankId = rankId;
BeginTime = 0;
NeedUpdate = false;
Data = new List<long>();
rewardGetUids = new List<long>();
lastRankData = new List<DBRankPlayerInfo>();
}
}
public class RealmRankInfo
{
public int m_realmId;
public bool m_loadDbDataSuccess;
public long m_serverStartTime;
public long m_lastLoadDbReqTime;
public long m_lastUpdateRankTime;
public Dictionary<int, RankDataOne> m_rankMap;
public RealmRankInfo(int realmId)
{
m_realmId = realmId;
m_loadDbDataSuccess = false;
m_rankMap = new Dictionary<int, RankDataOne>();
}
}
public class GlobalRankInfo
{
public bool m_loadDbDataSuccess;
public long m_serverStartTime;
public long m_lastLoadDbReqTime;
public long m_lastUpdateRankTime;
public RankDataOne rankOne = null;
public GlobalRankInfo( )
{
m_loadDbDataSuccess = false;
}
}
public class RankDataOne
{
public int RealmId;
public int RankID;
public RankDataRecord CurRecord;
public int SaveObjMax; //排行榜保存数量
public long CurRecordLimitScore; //排行榜上限制分数,下次tick需要进行排行
//public RankMainType MainType; //主类型 1.实时榜 2.纪录榜
// public int LinkRank; //关联榜
public RankDataInfoCache data;
public int hideRankTime; // 隐藏排行榜的时间, now >= hide时隐藏
public int closeRankTime; // 关闭排行榜的实际
public RankFlushType FlushType; //刷新类型
public RankReasonType reasonType;//上榜依据
public RankDataOne(int realmId, int rankId)
{
RealmId = realmId;
RankID = rankId;
RankConfigDesc desc = RankConfigDescMgr.Instance.GetConfig(rankId);
if (desc == null)
{
TraceLog.Error("RankData RankDataOne Init Error,rankId:{0}", rankId);
return;
}
data = new RankDataInfoCache(desc.CacheCount * 2);
SaveObjMax = desc.CacheCount;
FlushType = (RankFlushType)desc.refreshType;
reasonType = (RankReasonType)desc.reasonType;
}
public bool CheckSuccessLoad()
{
if(CurRecord == null)
{
return false;
}
return true;
}
}
public class WorldRankData : IServerDataObj
{
public override int GetDataType()
{
return RankDataObjType.RankInfoCache;
}
//禁止上榜玩家
public Dictionary<long, bool> m_forbitUidMap = new Dictionary<long, bool>();
//排行榜数据realmId-rankId-info
public Dictionary<int, RealmRankInfo> AllRank = new Dictionary<int, RealmRankInfo>();
//跨服榜rankId-info
public Dictionary<int, GlobalRankInfo> GlobalRank = new Dictionary<int, GlobalRankInfo>();
public bool TryGetRankDataOne(out RankDataOne dataOne, int realmId, int rankId)
{
dataOne = null;
if(AllRank.ContainsKey(realmId) && AllRank[realmId].m_rankMap.ContainsKey(rankId))
{
dataOne = AllRank[realmId].m_rankMap[rankId];
return true;
}
return false;
}
}
public class RankBriefDataOne
{
public long Uid;
public int Rank; //排名
public int Index; //序号
public long Score;
public long Time;
public int param;
public RankBriefDataOne(long uid, int rank, int index, long score, int param, long time)
{
this.Uid = uid;
this.Rank = rank;
this.Index = index;
this.Score = score;
this.Time = time;
this.param = param;
}
public int CompareTo(RankBriefDataOne other, bool isLess, bool isLess2)
{
int result = this.Score.CompareTo(other.Score);
//大值在前 乘-1
if (isLess == false)
{
result *= -1;
}
if(result == 0)
{//用param排序
result = this.param.CompareTo(other.param);
if (isLess2 == false)
{
result *= -1;
}
}
//时间早的在前
if (result == 0)
{
result = this.Time.CompareTo(other.Time);
}
//序号低的在前
if (result == 0)
{
result = this.Index.CompareTo(other.Index);
}
//都一样只能用Uid排了
if (result == 0)
{
result = this.Uid.CompareTo(other.Uid);
}
return result;
}
}
}