298 lines
6.2 KiB
C#
298 lines
6.2 KiB
C#
![]() |
// ***********************************************************************
|
|||
|
// Assembly : Game
|
|||
|
// Author : Kimch
|
|||
|
// Created : 2020-09-12
|
|||
|
// Description :
|
|||
|
// Last Modified By :
|
|||
|
// Last Modified On :
|
|||
|
// ***********************************************************************
|
|||
|
// <copyright file= "BookProxy" company="KUNPO"></copyright>
|
|||
|
// <summary></summary>
|
|||
|
// ***********************************************************************
|
|||
|
|
|||
|
using System.Collections;
|
|||
|
using System.Collections.Generic;
|
|||
|
|
|||
|
namespace G
|
|||
|
{
|
|||
|
/// <summary>
|
|||
|
/// 文学
|
|||
|
/// </summary>
|
|||
|
public class BookProxy : F.GameProxy
|
|||
|
{
|
|||
|
#region Field
|
|||
|
IReadOnlyList<ItemBookGroup> _groups;
|
|||
|
#endregion
|
|||
|
|
|||
|
#region Property
|
|||
|
|
|||
|
#endregion
|
|||
|
|
|||
|
#region Method
|
|||
|
|
|||
|
private void InitBooks()
|
|||
|
{
|
|||
|
var books = ItemProxy.Instance.GetStaticItems<ItemBook>();
|
|||
|
if (books != null)
|
|||
|
{
|
|||
|
foreach (var item in books)
|
|||
|
{
|
|||
|
item.Reset();
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
var bookGroups = ItemProxy.Instance.GetStaticItems<ItemBookGroup>();
|
|||
|
if (bookGroups != null)
|
|||
|
{
|
|||
|
foreach (var item in bookGroups)
|
|||
|
{
|
|||
|
item.Reset();
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
private const string ARCHIVE_KEY_V1 = "book_v1";
|
|||
|
private void LoadBooks()
|
|||
|
{
|
|||
|
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 status, out int id);
|
|||
|
|
|||
|
var bookItem = ItemProxy.Instance.GetStaticItem<ItemBook>(id);
|
|||
|
if (bookItem != null)
|
|||
|
{
|
|||
|
bookItem.status = status;
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
UpdateAttributes(false);
|
|||
|
}
|
|||
|
|
|||
|
private void SaveBooks()
|
|||
|
{
|
|||
|
var dataList = ArchiveProxy.Instance.GetIntList(ARCHIVE_KEY_V1);
|
|||
|
if (dataList != null)
|
|||
|
{
|
|||
|
dataList.Clear();
|
|||
|
|
|||
|
var bookItems = ItemProxy.Instance.GetStaticItems<ItemBook>();
|
|||
|
foreach (var bookItem in bookItems)
|
|||
|
{
|
|||
|
int status = bookItem.status;
|
|||
|
if (status > 0)
|
|||
|
{
|
|||
|
//等级不能超256
|
|||
|
int saveStatus = GlobalUtils.CombineNumber824(status, bookItem.id);
|
|||
|
dataList.Add(saveStatus);
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
ArchiveProxy.Instance.SetIntList(ARCHIVE_KEY_V1, dataList);
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
/// <summary>
|
|||
|
///
|
|||
|
/// </summary>
|
|||
|
/// <returns></returns>
|
|||
|
public IReadOnlyList<ItemBook> GetBooks()
|
|||
|
{
|
|||
|
return ItemProxy.Instance.GetStaticItems<ItemBook>();
|
|||
|
}
|
|||
|
|
|||
|
/// <summary>
|
|||
|
///
|
|||
|
/// </summary>
|
|||
|
/// <param name="id"></param>
|
|||
|
/// <returns></returns>
|
|||
|
public ItemBook GetBook(int id)
|
|||
|
{
|
|||
|
return ItemProxy.Instance.GetStaticItem<ItemBook>(id);
|
|||
|
}
|
|||
|
|
|||
|
/// <summary>
|
|||
|
///
|
|||
|
/// </summary>
|
|||
|
/// <returns></returns>
|
|||
|
public IReadOnlyList<ItemBookGroup> GetBookGroups()
|
|||
|
{
|
|||
|
if (_groups == null)
|
|||
|
{
|
|||
|
_groups = ItemProxy.Instance.GetStaticItems<ItemBookGroup>();
|
|||
|
}
|
|||
|
return _groups ;
|
|||
|
}
|
|||
|
|
|||
|
/// <summary>
|
|||
|
///
|
|||
|
/// </summary>
|
|||
|
/// <param name="index"></param>
|
|||
|
/// <returns></returns>
|
|||
|
public ItemBookGroup GetBookGroupByChapter(int index)
|
|||
|
{
|
|||
|
return ItemProxy.Instance.GetStaticItem<ItemBookGroup>(index);
|
|||
|
}
|
|||
|
|
|||
|
public ItemBook DropBookByChapter(int chapterId)
|
|||
|
{
|
|||
|
var bookGroup = GetBookGroupByChapter(chapterId);
|
|||
|
if (bookGroup != null)
|
|||
|
{
|
|||
|
var dropRndId = bookGroup.drop[1];
|
|||
|
bool isDrop = RandomProxy.Instance.GetRandom(dropRndId);
|
|||
|
if (isDrop)
|
|||
|
{
|
|||
|
for (int i = 0; i < bookGroup.books.Length; i++)
|
|||
|
{
|
|||
|
var book = GetBook(bookGroup.books[i]);
|
|||
|
if (book != null && !book.isUnlock)
|
|||
|
{
|
|||
|
return book;
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
return null;
|
|||
|
}
|
|||
|
|
|||
|
/// <summary>
|
|||
|
///
|
|||
|
/// </summary>
|
|||
|
/// <param name="bookId"></param>
|
|||
|
/// <returns></returns>
|
|||
|
public bool UnlockBook(int bookId)
|
|||
|
{
|
|||
|
var book = GetBook(bookId);
|
|||
|
return UnlockBook(book);
|
|||
|
}
|
|||
|
|
|||
|
/// <summary>
|
|||
|
///
|
|||
|
/// </summary>
|
|||
|
/// <param name="book"></param>
|
|||
|
/// <returns></returns>
|
|||
|
public bool UnlockBook(ItemBook book)
|
|||
|
{
|
|||
|
if (book != null)
|
|||
|
{
|
|||
|
var success = book.Unlock();
|
|||
|
if (success)
|
|||
|
{
|
|||
|
SaveBooks();
|
|||
|
//MissionProxy.Instance.OnEvent(MissionProxy.武学升级次数);
|
|||
|
//PostNotification(GlobalDefine.EVENT_KUNGFU_STUDY, type: "study");
|
|||
|
}
|
|||
|
return success;
|
|||
|
}
|
|||
|
return false;
|
|||
|
}
|
|||
|
|
|||
|
/// <summary>
|
|||
|
///
|
|||
|
/// </summary>
|
|||
|
/// <param name="book"></param>
|
|||
|
/// <returns></returns>
|
|||
|
public bool ActiveBook(ItemBook book)
|
|||
|
{
|
|||
|
if (book != null)
|
|||
|
{
|
|||
|
var success = book.Active();
|
|||
|
if (success)
|
|||
|
{
|
|||
|
UpdateAttributes(true);
|
|||
|
SaveBooks();
|
|||
|
//MissionProxy.Instance.OnEvent(MissionProxy.武学升级次数);
|
|||
|
//PostNotification(GlobalDefine.EVENT_KUNGFU_STUDY, type: "study");
|
|||
|
}
|
|||
|
return success;
|
|||
|
}
|
|||
|
return false;
|
|||
|
}
|
|||
|
|
|||
|
/// <summary>
|
|||
|
///
|
|||
|
/// </summary>
|
|||
|
/// <param name="skill"></param>
|
|||
|
/// <param name="skillArgs"></param>
|
|||
|
public void GetGlobalMovesArgs(int skill, int[] skillArgs)
|
|||
|
{
|
|||
|
var books = GetBooks();
|
|||
|
foreach (var book in books)
|
|||
|
{
|
|||
|
if (book.skill == skill && book.isActive)
|
|||
|
{
|
|||
|
if (book.skillArgs != null)
|
|||
|
for (int i = book.skillArgs.Length - 1; i >= 0; i--)
|
|||
|
skillArgs[i] += book.skillArgs[i];
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
var booksGroups = GetBookGroups();
|
|||
|
foreach (var booksGroup in booksGroups)
|
|||
|
{
|
|||
|
if (booksGroup.skill == skill && booksGroup.isActive)
|
|||
|
{
|
|||
|
if (booksGroup.skillArgs != null)
|
|||
|
for (int i = booksGroup.skillArgs.Length - 1; i >= 0; i--)
|
|||
|
skillArgs[i] += booksGroup.skillArgs[i];
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
private void UpdateAttributes(bool sendNotification)
|
|||
|
{
|
|||
|
int combatValue = 0;
|
|||
|
|
|||
|
var bookItems = GetBooks();
|
|||
|
foreach (var bookItem in bookItems)
|
|||
|
{
|
|||
|
combatValue += bookItem.CalcCombatValue();
|
|||
|
}
|
|||
|
|
|||
|
var bookGroupItems = GetBookGroups();
|
|||
|
foreach (var bookGroupItem in bookGroupItems)
|
|||
|
{
|
|||
|
combatValue += bookGroupItem.CalcCombatValue();
|
|||
|
}
|
|||
|
|
|||
|
PlayerProxy.Instance.UpdateBookCombatValue(combatValue, sendNotification);
|
|||
|
}
|
|||
|
|
|||
|
private bool IsBoosClearUp()
|
|||
|
{
|
|||
|
var groups = GetBookGroups();
|
|||
|
foreach (var group in groups)
|
|||
|
{
|
|||
|
if (group.isClearUp)
|
|||
|
{
|
|||
|
return true;
|
|||
|
}
|
|||
|
}
|
|||
|
return false;
|
|||
|
}
|
|||
|
public int GetRedPoint()
|
|||
|
{
|
|||
|
if (IsBoosClearUp())
|
|||
|
return 1;
|
|||
|
return 0;
|
|||
|
}
|
|||
|
|
|||
|
#endregion
|
|||
|
|
|||
|
#region Proxy
|
|||
|
|
|||
|
public static BookProxy Instance => GetInstance<BookProxy>();
|
|||
|
|
|||
|
public override void ReadArchive()
|
|||
|
{
|
|||
|
InitBooks();
|
|||
|
LoadBooks();
|
|||
|
}
|
|||
|
|
|||
|
#endregion
|
|||
|
}
|
|||
|
}
|