BlueRoseNote/05-SDHGame/Inventory & Synthesis文档.md

51 lines
2.3 KiB
Markdown
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

---
title: Inventory & Synthesis文档
date: 2022-08-12 14:18:31
excerpt:
tags:
- SDHGame
rating: ⭐
---
# 目录
- [[#Inventory]]
- [[#数据结构]]
- [[#物品类型]]
- [[#如何添加一个物品]
- [[#Synthesis]]
# Inventory
使用Lyra的 **Entry - Instance - Definition - Fragment**结构以及FFastArraySerializer/FFastArraySerializerItem网络同步结构。并针对一些设计做出改动。可以参考:https://zhuanlan.zhihu.com/p/552480961
## 数据结构
- URPGInventoryComponent
- FRPGItemList & FRPGItemEntry解决网络同步问题用结构。其中`FRPGItemEntry存储StackNum堆叠数量信息`
- URPGItemInstance物品实例以及存储动态数据。
- URPGItemDefinition物品定义以及存储静态数据。
- `TObjectPtr<URPGItemTypeFragment>`类型Fragment
- `TArray<TObjectPtr<URPGItemFragment>>`物品其他信息Fragment
主要的物品操作逻辑位于URPGInventoryComponent。
## 物品类型
记录物品类型以及类型对应的行为 & 动作。存储于`URPGItemDefinition`中的`TObjectPtr<URPGItemTypeFragment> ItemTypeFragments`可在构建URPGItemDefinition资产时挂载对应的URPGItemTypeFragment。Fragment逻辑位于Inventory/Item/RPGItemTypeFragment.h & cpp中。
- CanBeUse消耗品或者可以被使用的物品。
- Weapon武器。可以附带词条以及镶嵌物。
- Equip装备。可以附带词条以及镶嵌物。
- Material材料。用于合成各种东西的材料或者为卖钱道具。
- Token凭证。钥匙、信物各种钱。
- Attachable镶嵌物。宝石、附魔之类东西。
- Formulas已经学会的配方。
## 如何添加一个物品
相关物品定义位于Items目录下。
1. 新建一个父类为RPGItemDefinition的蓝图类。前缀为ID_XXXX。
2. 按照物品类型选择ItemTypeFragments并且填入相关信息即可。
PS. Formulas类除了定义物品信息之外还需要定义父类为RPGSynthesisDefinition的配方类明明方式为ID_XXXX_SD。
# Synthesis
合成逻辑也位于URPGInventoryComponent主要函数为
- SynthesisItem():合成物品。
- SynthesisItems()合成N个物品。
- ConsumeItemsByDefinition():消耗物品。
- GetSynthesisNums():计算可以可成的物品数量。
- GetSynthesisNumsByDefinition():计算可以可成的物品数量。