You've already forked taptap2024_GJ_chidouren
init
This commit is contained in:
204
Assets/Scripts/System/Account/AccountGameData.cs
Normal file
204
Assets/Scripts/System/Account/AccountGameData.cs
Normal file
@@ -0,0 +1,204 @@
|
||||
using System;
|
||||
using System.AchieveSystem;
|
||||
using System.Collections.Generic;
|
||||
using System.Game.Account;
|
||||
using System.OfflineSystem;
|
||||
using System.RandomPool;
|
||||
using FJson;
|
||||
using FJson.Core;
|
||||
using Framework.Audio;
|
||||
using Framework.Save;
|
||||
using Framework.Utils;
|
||||
using Game;
|
||||
using Game.Data;
|
||||
using Script.Core.Utils.Extend;
|
||||
using Unity.Mathematics;
|
||||
using UnityEngine;
|
||||
|
||||
public class AccountGameData
|
||||
{
|
||||
public string OfflineMgrTime;
|
||||
|
||||
//---------------------------------------------持久化数据---------------------------------------------
|
||||
//------------------通用数据----------------------
|
||||
public ENumber64 Currency; //当前货币
|
||||
public PeriodicityNumber CurHangUpLevelCount; //挂机系统广告升级次数 每日重置
|
||||
public List<int> InitCardIds; //初始卡牌牌库
|
||||
|
||||
|
||||
public int HangLevel; //挂机等级
|
||||
public List<AwardOfflineDuration> OnlineAwardDurationList; //当前玩家的累计挂机记录
|
||||
public OfflineTimeHandler OnlineAwardDuration; //在线挂机奖励时长
|
||||
|
||||
|
||||
public AchievementData AchievementData; //成就系统数据
|
||||
|
||||
//------------------通用数据----------------------
|
||||
|
||||
|
||||
//---------------------------------------------动态数据,非持久化数据---------------------------------------------
|
||||
public long GetMaxOnlineDuration => 10 * this.HangLevel + 10;
|
||||
public long GetMaxOfflineDuration => 60 * this.HangLevel + 60;
|
||||
|
||||
|
||||
public long GoldCurrency => this.Currency.Read;
|
||||
|
||||
public void NullCheck()
|
||||
{
|
||||
var isUpdate = false;
|
||||
|
||||
|
||||
if (this.Currency == null)
|
||||
{
|
||||
this.Currency = new ENumber64();
|
||||
}
|
||||
|
||||
if (AchievementData == null)
|
||||
{
|
||||
this.AchievementData = new AchievementData();
|
||||
}
|
||||
|
||||
if (this.OnlineAwardDurationList == null)
|
||||
{
|
||||
this.OnlineAwardDurationList = new List<AwardOfflineDuration>();
|
||||
}
|
||||
|
||||
if (this.CurHangUpLevelCount == null)
|
||||
{
|
||||
this.CurHangUpLevelCount = new PeriodicityNumber(GameConstConfig.Instance.MaxHangUpLevelAdCount);
|
||||
isUpdate = true;
|
||||
}
|
||||
|
||||
if (this.InitCardIds == null)
|
||||
{
|
||||
this.InitCardIds = new List<int>();
|
||||
}
|
||||
|
||||
if (isUpdate)
|
||||
{
|
||||
Account.Instance.Save(SaveData.Game);
|
||||
}
|
||||
}
|
||||
|
||||
public void UpdateCurrentTime(long curTime = 0)
|
||||
{
|
||||
this.OnlineAwardDuration = OfflineMgr.Instance.CreateTimeHandler(0);
|
||||
|
||||
var systemTime = curTime.GetDateTime13();
|
||||
this.CurHangUpLevelCount.CheckTime(systemTime, GameConstConfig.Instance.MaxHangUpLevelAdCount);
|
||||
}
|
||||
|
||||
public bool IsNull()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
public void OverlyCurrency(long gameLogicCurCoin, bool hasShow = true)
|
||||
{
|
||||
this.Currency.Add(gameLogicCurCoin);
|
||||
AudioManager.Instance.PlaySoundEffect(SeAudio.Gaming_GetCoin);
|
||||
if (hasShow)
|
||||
{
|
||||
EventManager.Instance.SendEvent(GameEventCode.Update_Price);
|
||||
}
|
||||
|
||||
Account.Instance.Save(SaveData.Game);
|
||||
}
|
||||
|
||||
|
||||
#region 挂机类
|
||||
|
||||
/// <summary>
|
||||
/// 更新挂机收益日志
|
||||
/// </summary>
|
||||
public void RefreshOfflineAwardLog()
|
||||
{
|
||||
int level = this.HangLevel;
|
||||
var duration = this.OnlineAwardDuration.CurDuration / 60f;
|
||||
this.OnlineAwardDurationList.Add(new AwardOfflineDuration(level, duration));
|
||||
//更新计时器
|
||||
this.OnlineAwardDuration = OfflineMgr.Instance.CreateTimeHandler(0);
|
||||
Account.Instance.Save(SaveData.Game);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 累计挂机时长(会计算最大领取奖励) 单位:分
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public double GetCurTotalOnlineDuration()
|
||||
{
|
||||
double duration = 0;
|
||||
foreach (var value in this.OnlineAwardDurationList)
|
||||
{
|
||||
duration += value.Duration;
|
||||
}
|
||||
|
||||
duration += this.OnlineAwardDuration.CurDuration / 60f;
|
||||
|
||||
return Math.Min(duration, this.GetMaxOnlineDuration);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 累计在线挂机奖励(会计算最大领取奖励)
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public double GetCurTotalOnlineAward()
|
||||
{
|
||||
double maxOnlineDuration = this.GetMaxOnlineDuration;
|
||||
double award = 0;
|
||||
foreach (var value in this.OnlineAwardDurationList)
|
||||
{
|
||||
if (maxOnlineDuration <= 0)
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
var duration = value.Duration;
|
||||
award += OnlineAward(value.GamePart, Math.Min(duration, maxOnlineDuration), value.ExtOffset);
|
||||
maxOnlineDuration = Math.Max(0, maxOnlineDuration - duration);
|
||||
}
|
||||
|
||||
if (maxOnlineDuration > 0)
|
||||
{
|
||||
var curDuration = (long)(this.OnlineAwardDuration.CurDuration / 60f); //向下取整
|
||||
award += OnlineAward(this.HangLevel, Math.Min(curDuration, maxOnlineDuration));
|
||||
}
|
||||
|
||||
return award;
|
||||
}
|
||||
|
||||
public bool HasEquipInitCard(int cardId)
|
||||
{
|
||||
return this.InitCardIds.Contains(cardId);
|
||||
}
|
||||
|
||||
public void AddInitCard(int cardId)
|
||||
{
|
||||
if (!this.InitCardIds.Contains(cardId))
|
||||
{
|
||||
this.InitCardIds.Add(cardId);
|
||||
Account.Instance.Save(SaveData.Game);
|
||||
}
|
||||
}
|
||||
|
||||
public long OnlineAward(float level, double duration, float extOffset = 0) =>
|
||||
(long)((OnlineAwardUnit(level) * duration) * (1 + extOffset));
|
||||
|
||||
/// <summary>
|
||||
/// 挂机每分钟收益
|
||||
/// </summary>
|
||||
/// <param name="level"></param>
|
||||
/// <returns></returns>
|
||||
public double OnlineAwardUnit(float level)
|
||||
{
|
||||
level *= 0.2f;
|
||||
// var rofHangUpRow = RofManagerConfig.Instance.RofCatInfoTable.GetDataByRow (Mathf.Min (math.max((int)level - 1 , 0),
|
||||
// RofManagerConfig.Instance.RofCatInfoTable.RowNum - 1));
|
||||
var unitExp = ((level * 20 + 30) / 30) + 1 * (0.01f + math.max(0, level - 10) * 0.1f);
|
||||
return unitExp;
|
||||
}
|
||||
|
||||
public double OfflineAwardUnit() => OnlineAwardUnit(this.HangLevel) * 0.1f;
|
||||
|
||||
#endregion
|
||||
}
|
||||
Reference in New Issue
Block a user