299 lines
6.3 KiB
C#
299 lines
6.3 KiB
C#
// ***********************************************************************
|
|
// Assembly : Game
|
|
// Author : Kimch
|
|
// Created : 2020-09-14
|
|
// Description :
|
|
// Last Modified By :
|
|
// Last Modified On :
|
|
// ***********************************************************************
|
|
// <copyright file= "BusinessProxy" company="KUNPO"></copyright>
|
|
// <summary></summary>
|
|
// ***********************************************************************
|
|
|
|
using System.Collections.Generic;
|
|
using CodeStage.AntiCheat.ObscuredTypes;
|
|
using PureMVC.Interfaces;
|
|
using UnityEngine;
|
|
|
|
namespace G
|
|
{
|
|
/// <summary>
|
|
/// 产业
|
|
/// </summary>
|
|
public class BusinessProxy : F.GameProxy
|
|
{
|
|
public class BusinessInfo
|
|
{
|
|
public readonly ItemBusiness item;
|
|
public int id => item.id;
|
|
|
|
public ObscuredInt _timestamp;
|
|
public int timestamp
|
|
{
|
|
get { return _timestamp; }
|
|
set { _timestamp = value; }
|
|
}
|
|
|
|
/// <summary>
|
|
/// 2 运行 1 解锁 0 未解锁
|
|
/// </summary>
|
|
public int status
|
|
{
|
|
get
|
|
{
|
|
if (timestamp > 1)
|
|
return 2;
|
|
else
|
|
return timestamp;
|
|
}
|
|
}
|
|
|
|
public int accumS => Mathf.Clamp(Launch.Timestamp - timestamp, 1, totalS);
|
|
public int totalS => item.rewardTotalSeconds;
|
|
public int intervalS => item.rewardIntervalSeconds;
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
public bool isFullReward => accumS >= totalS;
|
|
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
public int beautyId => item.beauty;
|
|
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
public BeautyProxy.BeautyInfo beauty => BeautyProxy.Instance.GetBeauty(beautyId);
|
|
|
|
public BusinessInfo(ItemBusiness affairItem)
|
|
{
|
|
this.item = affairItem;
|
|
this.timestamp = 0;
|
|
}
|
|
|
|
public void Reset()
|
|
{
|
|
this.timestamp = 0;
|
|
}
|
|
|
|
public int GetRewards(List<Item.ItemInfo> rewards)
|
|
{
|
|
var oriRewards = item.rewardInfos;
|
|
|
|
float factor = 1f;
|
|
if (beauty != null)
|
|
{
|
|
factor += beauty.businessFactor * 0.01f;
|
|
}
|
|
|
|
int accum = accumS;
|
|
int interval = intervalS;
|
|
int time = accum / interval;
|
|
for (int i = 0; i < oriRewards.Length; i++)
|
|
{
|
|
var reward = oriRewards[i];
|
|
reward.count = (int)(reward.count * time * factor);
|
|
rewards.Add(reward);
|
|
}
|
|
if (accum < interval)
|
|
return -1;
|
|
else
|
|
return accum % interval == 0 ? 1 : 0;
|
|
}
|
|
}
|
|
|
|
#region Field
|
|
|
|
private readonly Dictionary<int, BusinessInfo> _businessInfos = new Dictionary<int, BusinessInfo>();
|
|
|
|
#endregion
|
|
|
|
#region Property
|
|
|
|
#endregion
|
|
|
|
#region Method
|
|
|
|
public IReadOnlyCollection<BusinessInfo> GetBusinessInfos()
|
|
{
|
|
SetBusiness();
|
|
return _businessInfos.Values;
|
|
}
|
|
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
/// <param name="businessInfo"></param>
|
|
/// <param name="callback"></param>
|
|
public void GetBusinessRewards(BusinessInfo businessInfo, Callback2 callback)
|
|
{
|
|
var results = F.ListPool<Item.ItemInfo>.Get();
|
|
int state = businessInfo.GetRewards(results);
|
|
if (state >= 0)
|
|
{
|
|
//int timestamp = Launch.Timestamp;
|
|
UI.AdRewardBox.ShowRewards(results, (error, message) =>
|
|
{
|
|
if (error == 0)
|
|
{
|
|
businessInfo.timestamp = Launch.Timestamp;
|
|
SaveBusiness();
|
|
MissionProxy.Instance.OnEvent(MissionProxy.处理江湖事件次数);
|
|
}
|
|
callback(error, message);
|
|
});
|
|
}
|
|
F.ListPool<Item.ItemInfo>.Release(results);
|
|
}
|
|
|
|
public bool UnlockBusiness(BusinessInfo business)
|
|
{
|
|
if (business.status == 1)
|
|
{
|
|
business.timestamp = 2;
|
|
SaveBusiness();
|
|
return true;
|
|
}
|
|
return false;
|
|
}
|
|
|
|
private void SetBusiness()
|
|
{
|
|
foreach (var businessInfo in _businessInfos.Values)
|
|
{
|
|
if (businessInfo.status == 0)
|
|
{
|
|
if (businessInfo.beautyId == 0)
|
|
{
|
|
businessInfo.timestamp = 2;
|
|
}
|
|
else if (BeautyProxy.Instance.GetBeauty(businessInfo.beautyId).isUnlock)
|
|
{
|
|
businessInfo.timestamp = 1;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
public int GetRedPoint()
|
|
{
|
|
if (_businessInfos.Count > 0)
|
|
{
|
|
int redFlag = 0;
|
|
foreach (var businessInfo in _businessInfos.Values)
|
|
{
|
|
if (businessInfo.status == 1)
|
|
{
|
|
redFlag = 1;
|
|
return redFlag;
|
|
}
|
|
if (businessInfo.status == 2 && businessInfo.isFullReward)
|
|
{
|
|
redFlag = 1;
|
|
return redFlag;
|
|
}
|
|
}
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
private const string ARCHIVE_KEY_V1 = "affairs";
|
|
|
|
private void LoadBusiness()
|
|
{
|
|
var dataList = ArchiveProxy.Instance.GetIntList(ARCHIVE_KEY_V1);
|
|
if (dataList != null && dataList.Count > 0)
|
|
{
|
|
int index = 0;
|
|
while (index < dataList.Count)
|
|
{
|
|
int bId = dataList.SafeGet(index++);
|
|
int status = dataList.SafeGet(index++);
|
|
if (_businessInfos.TryGetValue(bId, out var businessInfo))
|
|
{
|
|
businessInfo.timestamp = status;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
private void SaveBusiness()
|
|
{
|
|
var dataList = ArchiveProxy.Instance.GetIntList(ARCHIVE_KEY_V1);
|
|
if (dataList != null)
|
|
{
|
|
dataList.Clear();
|
|
foreach (var businessInfo in _businessInfos.Values)
|
|
{
|
|
if (businessInfo.status > 0)
|
|
{
|
|
dataList.Add(businessInfo.id);
|
|
dataList.Add(businessInfo.timestamp);
|
|
}
|
|
}
|
|
ArchiveProxy.Instance.SetIntList(ARCHIVE_KEY_V1, dataList);
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 处理过存档
|
|
/// </summary>
|
|
private void InitBusiness()
|
|
{
|
|
if (_businessInfos.Count == 0)
|
|
{
|
|
var businessItems = ItemProxy.Instance.GetStaticItems<ItemBusiness>();
|
|
if (businessItems != null)
|
|
for (int i = 0; i < businessItems.Count; i++)
|
|
{
|
|
var businessItem = businessItems[i];
|
|
_businessInfos.Add(businessItem.id, new BusinessInfo(businessItem));
|
|
}
|
|
}
|
|
else
|
|
{
|
|
foreach (var businessInfo in _businessInfos.Values)
|
|
{
|
|
businessInfo.Reset();
|
|
}
|
|
}
|
|
}
|
|
|
|
public override void ReadArchive()
|
|
{
|
|
InitBusiness();
|
|
LoadBusiness();
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region Unity & Proxy
|
|
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
public static BusinessProxy Instance
|
|
{
|
|
get { return GetInstance<BusinessProxy>(); }
|
|
}
|
|
|
|
static readonly int[] _ListNotificationInterests = new int[] {
|
|
GlobalDefine.EVENT_LEVEL_COMPLETED,
|
|
};
|
|
|
|
public override IList<int> ListNotificationInterests()
|
|
{
|
|
return _ListNotificationInterests;
|
|
}
|
|
|
|
public override void HandleNotification(INotification notification)
|
|
{
|
|
if (notification.Name == GlobalDefine.EVENT_MISSION_COMPLETED)
|
|
SetBusiness();
|
|
}
|
|
|
|
#endregion
|
|
}
|
|
}
|