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.
 
 
 
 
 
 

147 lines
4.9 KiB

using System.Collections.Generic;
using ProtoCSStruct;
using Sog;
namespace Game
{
internal class SystemUnlockEvent
{
public static void OnRoleEnter(PlayerOnGame player)
{
//每次登录的时候做一次全检测
CheckUnlockSystem(player, false);
CSSystemUnlockInfoLoadSyn syn = new CSSystemUnlockInfoLoadSyn();
for (int i = 0; i < player.RoleData.SysUnlockData.SysUnlockDataOne.Count; i++)
{
syn.IdList.Add(player.RoleData.SysUnlockData.SysUnlockDataOne[i].SysID);
}
player.SendToClient((int)CSGameMsgID.SystemUnlockInfoLoadSyn, ref syn);
}
public static void OnPlayerBorn(PlayerOnGame player)
{
CheckUnlockSystem(player);
}
public static void OnNewDay(PlayerOnGame player, bool notifyClient)
{
CheckUnlockSystem(player);
}
public static void OnMissionComplete(PlayerOnGame player, QuestEXDesc desc)
{
CheckUnlockSystem(player);
}
public static void OnLevelChange(PlayerOnGame player)
{
CheckUnlockSystem(player, true);
}
public static void CheckUnlockSystem(PlayerOnGame player, bool sendMsg = true)
{
List<int> tempList = new List<int>();
foreach (var desc in UnlockSystemDescMgr.Instance.ItemTable.Values)
{
var cond = desc.unlockCondition;
//if (GameServerUtils.GetServerConfig().isAudit == 1)
//{
// cond = desc.auditUnlockCondition;
//}
if (cond.Length < 2)
continue;
if (IsUnlockCondition(player, cond) && IsUnlockConditionExt(player, desc))
{
var openDay = GameServerUtils.GetOpenDay(player.RealmID);
if (desc.serverDay > 0 && desc.serverDay > openDay)
{
continue;
}
bool unlock = false;
for (int i = 0; i < player.RoleData.SysUnlockData.SysUnlockDataOne.Count; i++)
{
if (player.RoleData.SysUnlockData.SysUnlockDataOne[i].SysID == desc.id)
{
unlock = true;
break;
}
}
if (!unlock)
{
DBSysUnlockDataOne unlockData = new DBSysUnlockDataOne();
unlockData.SysID = desc.id;
unlockData.SysUnlockTime = GameServerUtils.GetTimeSecond();
player.RoleData.SysUnlockData.SysUnlockDataOne.Add(unlockData);
tempList.Add(desc.id);
GameServerUtils.GetEventHandlerMgr().TriggerSystemUnlock(player, desc.id);
}
}
}
if (tempList.Count > 0 && sendMsg)
{
SendSyn(tempList, player);
}
}
public static void OnUseGM(PlayerOnGame player)
{
CheckUnlockSystem(player);
}
public static void SendSyn(List<int> list, PlayerOnGame player)
{
CSSystemUnlockInfoChangeSyn syn = new CSSystemUnlockInfoChangeSyn();
foreach (var var in list)
{
syn.IdList.Add(var);
}
player.SendToClient((int)CSGameMsgID.SystemUnlockInfoChangeSyn, ref syn);
}
private static bool IsUnlockCondition(PlayerOnGame player, IReadOnlyList<int> conduction)
{
var battleId = player.RoleData.ChapterData.BattleId;
var level = player.GetLevel();
if (conduction == null || conduction.Count < 2)
{
return false; //没有配置就不解锁
}
if (conduction[0] == 0 && conduction[1] == 0)
{
return true;
}
return battleId >= conduction[0] && level >= conduction[1];
}
private static bool IsUnlockConditionExt(PlayerOnGame player, UnlockSystemDesc desc)
{
var pass = true;
if (desc.unlockPayMoney > 0)
{
pass = player.RoleData.PayData.TotalPayMoney/100 >= desc.unlockPayMoney;
}
if (desc.unlockBorn > 0)
{
var timeSecond = player.RoleData.BornTime;
if (timeSecond == 0)
{
timeSecond = GameServerUtils.GetTimeSecond();
}
var day = AppTime.GetDayElapse(GameServerUtils.GetTimeSecond(), timeSecond) + 1;
pass = pass || (day >= desc.unlockBorn);
}
return pass;
}
}
}