Survivalcraft API 1.8.2.3 v1.8.2.3
Survivalcraft 2.4
载入中...
搜索中...
未找到
ComponentFurnitureInventory.cs
浏览该文件的文档.
1using Engine;
4
5namespace Game {
8
9 public List<int> m_slots = [];
10
11 public const int m_largeNumber = 0x1fffffff;
12
13 public int PageIndex { get; set; }
14
15 public FurnitureSet FurnitureSet { get; set; }
16
18
19 public int ActiveSlotIndex {
20 get => -1;
21 set { }
22 }
23
24 public int SlotsCount => m_slots.Count;
25
26 public int VisibleSlotsCount {
27 get => SlotsCount;
28 set { }
29 }
30
31 public virtual void FillSlots() {
32 m_subsystemFurnitureBlockBehavior.GarbageCollectDesigns();
33 m_slots.Clear();
34 for (int i = 0; i < FurnitureDesign.maxDesign; i++) {
36 if (design != null) {
37 int num = (from f in design.ListChain() select f.Index).Min();
38 if (design.Index == num) {
40 int item = Terrain.MakeBlockValue(227, 0, data);
41 m_slots.Add(item);
42 }
43 }
44 }
45 }
46
47 public virtual void ClearSlots() {
48 m_slots.Clear();
49 }
50
51 public override void Load(ValuesDictionary valuesDictionary, IdToEntityMap idToEntityMap) {
53 string furnitureSetName = valuesDictionary.GetValue<string>("FurnitureSet");
54 FurnitureSet = m_subsystemFurnitureBlockBehavior.FurnitureSets.FirstOrDefault(f => f.Name == furnitureSetName);
55 }
56
57 public override void Save(ValuesDictionary valuesDictionary, EntityToIdMap entityToIdMap) {
58 valuesDictionary.SetValue("FurnitureSet", FurnitureSet != null ? FurnitureSet.Name : string.Empty);
59 }
60
61 public virtual int GetSlotValue(int slotIndex) {
62 if (slotIndex >= 0
63 && slotIndex < m_slots.Count) {
64 return m_slots[slotIndex];
65 }
66 return 0;
67 }
68
69 public virtual int GetSlotCount(int slotIndex) {
70 if (slotIndex >= 0
71 && slotIndex < m_slots.Count) {
72 if (m_slots[slotIndex] == 0) {
73 return 0;
74 }
75 return m_largeNumber;
76 }
77 return 0;
78 }
79
80 public virtual int GetSlotCapacity(int slotIndex, int value) => m_largeNumber << 1;
81
82 public virtual int GetSlotProcessCapacity(int slotIndex, int value) {
83 int slotCount = GetSlotCount(slotIndex);
84 int slotValue = GetSlotValue(slotIndex);
85 if (slotCount > 0
86 && slotValue != 0) {
87 SubsystemBlockBehavior[] blockBehaviors = Project.FindSubsystem<SubsystemBlockBehaviors>(true)
88 .GetBlockBehaviors(Terrain.ExtractContents(slotValue));
89 for (int i = 0; i < blockBehaviors.Length; i++) {
90 int processInventoryItemCapacity = blockBehaviors[i].GetProcessInventoryItemCapacity(this, slotIndex, value);
91 if (processInventoryItemCapacity > 0) {
92 return processInventoryItemCapacity;
93 }
94 }
95 }
96 return m_largeNumber;
97 }
98
99 public virtual void AddSlotItems(int slotIndex, int value, int count) { }
100
101 public virtual void ProcessSlotItems(int slotIndex, int value, int count, int processCount, out int processedValue, out int processedCount) {
102 int slotCount = GetSlotCount(slotIndex);
103 int slotValue = GetSlotValue(slotIndex);
104 if (slotCount > 0
105 && slotValue != 0) {
106 SubsystemBlockBehavior[] blockBehaviors = Project.FindSubsystem<SubsystemBlockBehaviors>(true)
107 .GetBlockBehaviors(Terrain.ExtractContents(slotValue));
108 foreach (SubsystemBlockBehavior subsystemBlockBehavior in blockBehaviors) {
109 int processInventoryItemCapacity = subsystemBlockBehavior.GetProcessInventoryItemCapacity(this, slotIndex, value);
110 if (processInventoryItemCapacity > 0) {
111 subsystemBlockBehavior.ProcessInventoryItem(
112 this,
113 slotIndex,
114 value,
115 count,
116 MathUtils.Min(processInventoryItemCapacity, processCount),
117 out processedValue,
118 out processedCount
119 );
120 return;
121 }
122 }
123 }
124 processedValue = 0;
125 processedCount = 0;
126 }
127
128 public virtual int RemoveSlotItems(int slotIndex, int count) => 1;
129
130 public virtual void DropAllItems(Vector3 position) { }
131 }
132}
static int Min(int x1, int x2)
override void Save(ValuesDictionary valuesDictionary, EntityToIdMap entityToIdMap)
virtual void ProcessSlotItems(int slotIndex, int value, int count, int processCount, out int processedValue, out int processedCount)
virtual void AddSlotItems(int slotIndex, int value, int count)
virtual int GetSlotProcessCapacity(int slotIndex, int value)
SubsystemFurnitureBlockBehavior m_subsystemFurnitureBlockBehavior
virtual int GetSlotCapacity(int slotIndex, int value)
override void Load(ValuesDictionary valuesDictionary, IdToEntityMap idToEntityMap)
virtual int RemoveSlotItems(int slotIndex, int count)
实际移除的数量
static int SetDesignIndex(int data, int designIndex, int shadowStrengthFactor, bool isLightEmitter)
List< FurnitureDesign > ListChain()
virtual void ProcessInventoryItem(IInventory inventory, int slotIndex, int value, int count, int processCount, out int processedValue, out int processedCount)
virtual int GetProcessInventoryItemCapacity(IInventory inventory, int slotIndex, int value)
static int ExtractContents(int value)
static int MakeBlockValue(int contents)
ValuesDictionary ValuesDictionary