zxl
/
CTT
forked from Cal/CTT
1
0
Fork 0
CTT/Server/Hotfix/Game/System/User/PlayerDataSystem.cs

350 lines
14 KiB
C#
Raw Normal View History

2021-04-08 20:09:59 +08:00
using Cal.DataTable;
using ET.EventType;
using System;
using System.Collections.Generic;
using System.Text;
namespace ET
{
public class PlayerDataAwakeSystem : AwakeSystem<PlayerData>
{
public override void Awake(PlayerData self)
{
self.familyBossKeys = 2;
self.questAnswerCard = 1;
self.buyEnergyCount = 0;
self.currManulEquipMapLayer = 0;
self.manulEquipMakeCount = 4;
self.personalScord = 0;
self.personalPvpCount = 0;
self.epicManulMakeCount = 0;
self.bossEnergy = 10;
self.mapCoinCount = 10;
}
}
public class PlayerDataDestroySystem : DestroySystem<PlayerData>
{
public override void Destroy(PlayerData self)
{
self.BattleExpSpeed = 1f;
self.IdleExpSpeed = 1f;
self.buyEnergyCount = 0;
self.MainStoryRecordId = 0;
self.epicManulMakeCount = 0;
self.trialAndBossLayer = 1010101;
self.trialLayer = 10101;
self.MarketLeastTime = 0L;
self.MarketDiscount = 0f;
self.MarketPeriod = 0;
self.ForbidExp = false;
self.IsBattleIdle = false;
self.LastOnlineTime = 0L;
self.OnlineTime = 0;
self.OnlineRewardId = 0;
self.CharacterPointKV = default(KeyValuePair<int, int>);
self.SkillPointKV = default(KeyValuePair<int, int>);
self.hpAutoFullCapatial = default(KeyValuePair<int, int>);
self.mpAutoFullCapatial = default(KeyValuePair<int, int>);
self.mainstoryAITime = 0L;
self.mainstoryVIPAITime = 0L;
}
}
public static class PlayerDataSystem
{
public class UpdatePer1DayOfMonthEvent_UpdateData : AEvent<UpdatePer1DayOfMonth>
{
public override async ETTask Run(UpdatePer1DayOfMonth args)
{
Log.Info("刷新PlayerData");
List<PlayerData> list = await DBComponent.Instance.QueryJson<PlayerData>("{}");
for (int i = 0; i < list.Count; i++)
{
try
{
PlayerData data = list[i];
Unit unit = MapUnitComponent.Instance.Get(data.Id);
if ((bool)unit)
{
PlayerData _data = unit.GetComponent<PlayerData>();
if (!_data)
{
_data = data;
unit.RemoveComponent<PlayerData>();
unit.AddComponent(data);
}
data = _data;
}
InitData(data);
await DBComponent.Instance.Save(data);
}
catch (Exception e)
{
Log.Error(e);
}
}
await ETTask.CompletedTask;
}
}
private static void InitData(PlayerData data)
{
data.familyBossKeys = 2;
data.questAnswerCard = 1;
data.buyEnergyCount = 0;
data.manulEquipMakeCount = 4;
data.bossEnergy = 10;
data.mapCoinCount = 10;
data.trialLayer = 10101;
data.trialAndBossLayer = 1010101;
data.OnlineTime = 0;
data.OnlineRewardId = 0;
2021-04-11 19:50:39 +08:00
DayOfWeek now = DateTime.Now.DayOfWeek;
2021-04-08 20:09:59 +08:00
if (now == DayOfWeek.Saturday || now == DayOfWeek.Sunday)
data.mainstoryAITime += 4 * 60 * 60 * 1000;
else
data.mainstoryAITime += 2 * 60 * 60 * 1000;
}
public static bool HasMainstoryAITime(this PlayerData self)
{
return self.mainstoryAITime >= 2000;
}
public static bool HasMainstoryVIPAITime(this PlayerData self)
{
return self.mainstoryVIPAITime >= 2000;
}
public static void UpdateMinstoryRecord(this PlayerData self, int sceneId)
{
self.MainStoryRecordId = sceneId;
}
public static bool CanEnterMianStory(this PlayerData self, int sceneId)
{
if (sceneId - self.MainStoryRecordId > 1)
{
return false;
}
return true;
}
public static string GetTrialLayer(this PlayerData self, int sceneId, out int mapId)
{
mapId = 80;
if (self.trialAndBossLayer == 0)
{
//1 01 01 -> 1 01 00 01
self.trialAndBossLayer = self.trialLayer / 100 * 100 * 100 + self.trialLayer % 100;
}
List<TrialCopy> listByLevel = TrialCopyCategory.Instance.GetListByLevel(sceneId);
if (listByLevel == null)
{
return "系统错误";
}
switch (sceneId)
{
case Sys_SceneId.Scene_Challenge:
mapId = self.trialAndBossLayer / 1000000;
break;
case Sys_SceneId.Scene_Challenge_Middle:
mapId = self.trialAndBossLayer / 10000 % 100;
break;
case Sys_SceneId.Scene_Challenge_Hard:
mapId = self.trialAndBossLayer / 100 % 100;
break;
case Sys_SceneId.Scene_PersonalBoss:
mapId = self.trialAndBossLayer / 1 % 100;
break;
}
if (mapId >= listByLevel.Count)
{
return "已通关,明日再来";
}
mapId = listByLevel[mapId - 1].MapId;
return null;
}
public static async ETTask UpdateTrialCopy(this PlayerData self, int sceneId)
{
ChangeMap a;
try
{
List<TrialCopy> list = TrialCopyCategory.Instance.GetListByLevel(sceneId);
UnitScene unitScene2 = self.Parent.GetComponent<UnitScene>();
int mapId = 0;
switch (sceneId)
{
case Sys_SceneId.Scene_Challenge:
mapId = self.trialAndBossLayer / 1000000;
mapId++;
if (unitScene2.MapId != list[mapId - 2].MapId)
{
Log.Error($"【严重错误】玩家 Id={self?.Id} {mapId} {unitScene2?.MapId}通过记录增加数大于1 ");
mapId = list.Count;
}
self.trialAndBossLayer = mapId * 1000000 + self.trialAndBossLayer % 1000000;
break;
case Sys_SceneId.Scene_Challenge_Middle:
mapId = self.trialAndBossLayer / 10000 % 100;
mapId++;
if (unitScene2.MapId != list[mapId - 2].MapId)
{
Log.Error($"【严重错误】玩家 Id={self?.Id} {mapId} {unitScene2?.MapId}通过记录增加数大于1 ");
mapId = list.Count;
}
self.trialAndBossLayer = self.trialAndBossLayer / 1000000 * 1000000 + mapId * 10000 + self.trialAndBossLayer % 10000;
break;
case Sys_SceneId.Scene_Challenge_Hard:
mapId = self.trialAndBossLayer / 100 % 100;
mapId++;
if (unitScene2.MapId != list[mapId - 2].MapId)
{
Log.Error($"【严重错误】玩家 Id={self?.Id} {mapId} {unitScene2?.MapId}通过记录增加数大于1 ");
mapId = list.Count;
}
self.trialAndBossLayer = self.trialAndBossLayer / 10000 * 10000 + mapId* 100 + self.trialAndBossLayer % 100;
break;
case Sys_SceneId.Scene_PersonalBoss:
mapId = self.trialAndBossLayer /1% 100;
mapId++;
if (unitScene2.MapId != list[mapId - 2].MapId)
{
Log.Error($"【严重错误】玩家 Id={self?.Id} {mapId} {unitScene2?.MapId}通过记录增加数大于1 ");
mapId = list.Count;
}
self.trialAndBossLayer = self.trialAndBossLayer / 100 * 100 + mapId;
break;
}
if (mapId == list.Count)
{
await Game.EventSystem.Publish(new BackMainCity
{
unit = self.GetParent<Unit>(),
isForce = true
});
}
else
{
EventSystem eventSystem = Game.EventSystem;
a = new ChangeMap
{
unit = self.GetParent<Unit>(),
mapId = unitScene2.MapId + 1
};
await eventSystem.Publish(a);
}
}
catch (Exception e)
{
Log.Error(e);
UnitScene unitScene = self.Parent.GetComponent<UnitScene>();
EventSystem eventSystem2 = Game.EventSystem;
a = new ChangeMap
{
unit = self.GetParent<Unit>(),
mapId = unitScene.MapId + 1
};
await eventSystem2.Publish(a);
}
}
public static int UpdateDrop(this PlayerData self, int id)
{
try
{
2021-04-11 19:50:39 +08:00
if (!self.dropDic.TryGetValue(id, out KeyValuePair<int, int> value))
2021-04-08 20:09:59 +08:00
{
SonAdvancedSet sonAdvancedSet = SonAdvancedSetCategory.Instance.Get(id, canError: false);
if (sonAdvancedSet != null)
{
int value2 = RandomHelper.RandomNumber(sonAdvancedSet.MinAdCount, sonAdvancedSet.MaxAdCount + 1);
value = (self.dropDic[id] = KeyValuePair.Create(0, value2));
}
return id;
}
2021-04-11 19:50:39 +08:00
value.Deconstruct(out int key, out int value3);
2021-04-08 20:09:59 +08:00
key++;
if (key >= value3)
{
self.dropDic.Remove(id);
SonAdvancedSet sonAdvancedSet2 = SonAdvancedSetCategory.Instance.Get(id, canError: false);
if (sonAdvancedSet2 != null)
{
id = sonAdvancedSet2.Adsubset;
}
}
else
{
self.dropDic[id] = KeyValuePair.Create(key, value3);
}
UnitHelper.SaveComponenet(self).Coroutine();
}
catch (Exception e)
{
Log.Error(e);
}
return id;
}
public static bool UpdateEpicManulCount(this PlayerData self)
{
if (self.epicManulMakeCount == 0)
{
GenerateEpicManulCount(self);
}
self.epicManulMakeCount--;
if (self.epicManulMakeCount <= 0)
{
GenerateEpicManulCount(self);
return true;
}
return false;
}
public static void GenerateEpicManulCount(this PlayerData self)
{
self.epicManulMakeCount = ConstDefine.EpicMaxManulCountArr.RandomArray_Len2();
}
public static void UpdateOnlineTime(this PlayerData self, long now)
{
self.OnlineTime += 60000;
self.GetOnlineReward(now).Coroutine();
}
private static async ETVoid GetOnlineReward(this PlayerData self, long now)
{
int id = OnlineRewardComponent.instance.GetRewardTime(TimeSpan.FromMilliseconds(self.OnlineTime));
if (id == 0)
{
Log.Error("id == 0 when get the reward of onlineTime");
}
else if (id > self.OnlineRewardId)
{
self.OnlineRewardId = id;
OnlineRewardBase onlineRewardBase = DataTableHelper.Get<OnlineRewardBase>(id);
Unit unit = self.GetParent<Unit>();
for (int i = onlineRewardBase.OnlineRewardsArr.Length - 1; i >= 0; i--)
{
OnlineRewardBase.OnlineRewards reward = onlineRewardBase.OnlineRewardsArr[i];
Mail mail = new Mail
{
Id = Game.IdGenerater.GenerateId(),
Content = "在线拿大奖咯!",
RemainTime = now + (long)TimeSpan.FromDays(1.0).TotalMilliseconds,
SenderName = "系统",
State = MailState.UnReceive,
Title = "在线奖励"
};
mail.RewordArr.Add(new MailItem
{
ItemId = reward.OnlineRewards_Id,
Count = reward.OnlineRewards_Count,
IsHasItem = false,
IsLock = true
});
await MailComponent.Instance.AddMail(unit.Id, mail);
}
}
}
}
}