// *********************************************************************** // Assembly : Game // Author : Kimch // Created : 2020-09-12 // Description : // Last Modified By : // Last Modified On : // *********************************************************************** // // // *********************************************************************** using System.Collections; using System.Collections.Generic; namespace G { /// /// 文学 /// public class BookProxy : F.GameProxy { #region Field IReadOnlyList _groups; #endregion #region Property #endregion #region Method private void InitBooks() { var books = ItemProxy.Instance.GetStaticItems(); if (books != null) { foreach (var item in books) { item.Reset(); } } var bookGroups = ItemProxy.Instance.GetStaticItems(); 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(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(); 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); } } /// /// /// /// public IReadOnlyList GetBooks() { return ItemProxy.Instance.GetStaticItems(); } /// /// /// /// /// public ItemBook GetBook(int id) { return ItemProxy.Instance.GetStaticItem(id); } /// /// /// /// public IReadOnlyList GetBookGroups() { if (_groups == null) { _groups = ItemProxy.Instance.GetStaticItems(); } return _groups ; } /// /// /// /// /// public ItemBookGroup GetBookGroupByChapter(int index) { return ItemProxy.Instance.GetStaticItem(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; } /// /// /// /// /// public bool UnlockBook(int bookId) { var book = GetBook(bookId); return UnlockBook(book); } /// /// /// /// /// 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; } /// /// /// /// /// 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; } /// /// /// /// /// 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(); public override void ReadArchive() { InitBooks(); LoadBooks(); } #endregion } }