266 lines
6.0 KiB
C#
266 lines
6.0 KiB
C#
// ***********************************************************************
|
|
// Assembly : Game
|
|
// Author : Kimch
|
|
// Created : 2020-09-12
|
|
// Description :
|
|
// Last Modified By :
|
|
// Last Modified On :
|
|
// ***********************************************************************
|
|
// <copyright file= "KungfuProxy" company="KUNPO"></copyright>
|
|
// <summary></summary>
|
|
// ***********************************************************************
|
|
|
|
using CodeStage.AntiCheat.ObscuredTypes;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
|
|
namespace G
|
|
{
|
|
/// <summary>
|
|
/// 武学
|
|
/// </summary>
|
|
public class KungfuProxy : F.GameProxy
|
|
{
|
|
public class KungfuInfo
|
|
{
|
|
|
|
}
|
|
|
|
#region Field
|
|
|
|
private readonly List<ItemKungfu> _kungfuBooks = new List<ItemKungfu>();
|
|
|
|
#endregion
|
|
|
|
#region Method
|
|
|
|
public override void ReadArchive()
|
|
{
|
|
InitKungfus();
|
|
LoadKungfus();
|
|
}
|
|
|
|
private void InitKungfus()
|
|
{
|
|
var kungfuItems = ItemProxy.Instance.GetStaticItems<ItemKungfu>();
|
|
if (kungfuItems != null)
|
|
{
|
|
foreach (var item in kungfuItems)
|
|
{
|
|
item.Reset();
|
|
}
|
|
}
|
|
}
|
|
|
|
private const string ARCHIVE_KEY_V1 = "kungfus2";
|
|
private void LoadKungfus()
|
|
{
|
|
var dataList = ArchiveProxy.Instance.GetIntList(ARCHIVE_KEY_V1);
|
|
if (dataList != null && dataList.Count > 0)
|
|
{
|
|
for (int i = 0; i < dataList.Count; i++)
|
|
{
|
|
GlobalUtils.SplitNumber824(dataList[i], out int grade, out int id);
|
|
var kungfuItem = ItemProxy.Instance.GetStaticItem<ItemKungfu>(id);
|
|
if (kungfuItem != null)
|
|
{
|
|
kungfuItem.grade = grade;
|
|
}
|
|
}
|
|
}
|
|
UpdateAttributes(false);
|
|
}
|
|
|
|
private void SaveKungfus()
|
|
{
|
|
var dataList = ArchiveProxy.Instance.GetIntList(ARCHIVE_KEY_V1);
|
|
if (dataList != null)
|
|
{
|
|
dataList.Clear();
|
|
|
|
var kungfuBooks = GetKungfuBooks();
|
|
for (int i = 0; i < kungfuBooks.Count; i++)
|
|
{
|
|
var kungfuBook = kungfuBooks[i];
|
|
int grade = kungfuBook.grade;
|
|
if (grade > 0)
|
|
{
|
|
//等级不能超256
|
|
int status = GlobalUtils.CombineNumber824(grade, kungfuBook.id);
|
|
dataList.Add(status);
|
|
}
|
|
}
|
|
ArchiveProxy.Instance.SetIntList(ARCHIVE_KEY_V1, dataList);
|
|
}
|
|
}
|
|
|
|
public void UnlockKungfus(int levelId)
|
|
{
|
|
bool saveFlag = false;
|
|
var kungfuItems = ItemProxy.Instance.GetStaticItems<ItemKungfu>();
|
|
foreach (var kungfuItem in kungfuItems)
|
|
{
|
|
if (kungfuItem.unlockLevelId <= levelId)
|
|
{
|
|
if (kungfuItem.grade == 0)
|
|
{
|
|
kungfuItem.grade = 1;
|
|
saveFlag = true;
|
|
}
|
|
}
|
|
}
|
|
|
|
if (saveFlag)
|
|
{
|
|
UpdateAttributes(true);
|
|
SaveKungfus();
|
|
PostNotification(GlobalDefine.EVENT_KUNGFU_STUDY, type: "unlock");
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// (支持排序)
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public List<ItemKungfu> GetKungfuBooks()
|
|
{
|
|
_kungfuBooks.Clear();
|
|
_kungfuBooks.AddRange(ItemProxy.Instance.GetStaticItems<ItemKungfu>());
|
|
return _kungfuBooks;
|
|
}
|
|
|
|
public IReadOnlyList<ItemKungfuGroup> GetKungfuGroups()
|
|
{
|
|
return ItemProxy.Instance.GetStaticItems<ItemKungfuGroup>();
|
|
}
|
|
|
|
public ItemKungfuGroup GetKungfuGroupByIndex(int index)
|
|
{
|
|
var groups = ItemProxy.Instance.GetStaticItems<ItemKungfuGroup>();
|
|
if (index < groups.Count)
|
|
return groups[index];
|
|
else
|
|
return null;
|
|
}
|
|
|
|
public bool StudyBook(ItemKungfu book)
|
|
{
|
|
if (book != null)
|
|
{
|
|
var price = book.upgradePrice;
|
|
if (!MoneyProxy.Instance.CheckMoney(price))
|
|
{
|
|
UI.AdMoneyBox.ShowAdMoney(Item.Id.kCoin, true);
|
|
return false;
|
|
}
|
|
|
|
var success = book.AddGrade();
|
|
if (success)
|
|
{
|
|
MoneyProxy.Instance.CostMoney(price);
|
|
UpdateAttributes(true);
|
|
SaveKungfus();
|
|
MissionProxy.Instance.OnEvent(MissionProxy.武学升级次数);
|
|
PostNotification(GlobalDefine.EVENT_KUNGFU_STUDY, type: "study");
|
|
PostNotification(GlobalDefine.EVENT_MONEY_CHANGED);
|
|
}
|
|
return success;
|
|
}
|
|
return false;
|
|
}
|
|
|
|
public bool Study(ItemKungfuGroup group, ItemKungfu book)
|
|
{
|
|
if (book != null)
|
|
{
|
|
var prices = group.curUpgradeCost;
|
|
if (!MoneyProxy.Instance.CheckMoney(prices))
|
|
{
|
|
UI.AdMoneyBox.ShowAdMoney(Item.Id.kCoin, true);
|
|
return false;
|
|
}
|
|
|
|
var success = book.AddGrade();
|
|
if (success)
|
|
{
|
|
MoneyProxy.Instance.CostMoney(prices);
|
|
var old = PlayerProxy.Instance.combatValue;
|
|
UpdateAttributes(true);
|
|
SaveKungfus();
|
|
MissionProxy.Instance.OnEvent(MissionProxy.武学升级次数);
|
|
PostNotification(GlobalDefine.EVENT_KUNGFU_STUDY, type: "study");
|
|
PostNotification(GlobalDefine.EVENT_MONEY_CHANGED);
|
|
KStatistics.Instance.ReportEvent_SkillLevelUp(group.name, book.id.ToString(), book.name, book.grade - 1, book.grade, old, PlayerProxy.Instance.combatValue);
|
|
}
|
|
return true;
|
|
}
|
|
return false;
|
|
}
|
|
|
|
private void UpdateAttributes(bool sendNotification)
|
|
{
|
|
var results = F.ListPool<CombatAttribute>.Get();
|
|
var kungfus = ItemProxy.Instance.GetStaticItems<ItemKungfu>();
|
|
foreach (var kungfu in kungfus)
|
|
{
|
|
if (kungfu.grade > 0)
|
|
{
|
|
kungfu.GetAttributes(results);
|
|
}
|
|
}
|
|
PlayerProxy.Instance.UpdateKungfuCombatValue(results, sendNotification);
|
|
F.ListPool<CombatAttribute>.Release(results);
|
|
}
|
|
|
|
public ItemKungfu GetUnlockKungfuByLevel(int levelId)
|
|
{
|
|
var kungfus = ItemProxy.Instance.GetStaticItems<ItemKungfu>();
|
|
foreach (var kungfu in kungfus)
|
|
{
|
|
if (kungfu.unlockLevelId == levelId)
|
|
{
|
|
return kungfu;
|
|
}
|
|
}
|
|
return null;
|
|
}
|
|
|
|
public int GetRedPoint()
|
|
{
|
|
var groups = GetKungfuGroups();
|
|
foreach (var group in groups)
|
|
{
|
|
if (!group.isMaxGrade)
|
|
{
|
|
if (group.unlockLevel > LevelProxy.Instance.currentCompletedLevel)
|
|
return 0;
|
|
var price = group.curUpgradeCost;
|
|
if (MoneyProxy.Instance.CheckMoney(price))
|
|
{
|
|
return 1;
|
|
}
|
|
else
|
|
{
|
|
return 0;
|
|
}
|
|
}
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region Unity
|
|
|
|
public static KungfuProxy Instance;
|
|
|
|
// Use this for initialization
|
|
private void Awake()
|
|
{
|
|
Instance = this;
|
|
}
|
|
|
|
#endregion
|
|
}
|
|
}
|