Survivalcraft API 1.8.2.3 v1.8.2.3
Survivalcraft 2.4
载入中...
搜索中...
未找到
ComponentCraftingTable.cs
浏览该文件的文档.
1using System.Globalization;
2using Engine;
5
6namespace Game {
9
10 public string[] m_matchedIngredients = new string[9];
11
13 public int RemainsSlotIndex => SlotsCount - 1;
14
16
18
20 public int ResultSlotIndex => SlotsCount - 2;
21
23
24 public virtual void Update(float dt) {
27 }
30 }
31
32 public override int GetSlotCapacity(int slotIndex, int value) {
33 if (slotIndex < SlotsCount - 2) {
34 return base.GetSlotCapacity(slotIndex, value);
35 }
36 return 0;
37 }
38
39 public override void AddSlotItems(int slotIndex, int value, int count) {
40 int oldCount = GetSlotCount(slotIndex);
41 base.AddSlotItems(slotIndex, value, count);
42 if (oldCount == 0) {
44 }
46 m_slots[ResultSlotIndex].Count = 0;
47 }
48
49 public override int RemoveSlotItems(int slotIndex, int count) {
50 int num = 0;
51 int[] originalCount = new int[SlotsCount - 2];
52 for (int i = 0; i < originalCount.Length; i++) {
53 originalCount[i] = GetSlotCount(i);
54 }
55 if (slotIndex == ResultSlotIndex) {
56 if (m_matchedRecipe != null) {
57 if (m_matchedRecipe.RemainsValue != 0
58 && m_matchedRecipe.RemainsCount > 0) {
59 if (m_slots[RemainsSlotIndex].Count == 0
60 || m_slots[RemainsSlotIndex].Value == m_matchedRecipe.RemainsValue) {
62 .GetMaxStacking(m_matchedRecipe.RemainsValue)
64 count = MathUtils.Min(count, num2 / m_matchedRecipe.RemainsCount * m_matchedRecipe.ResultCount);
65 }
66 else {
67 count = 0;
68 }
69 }
70 count = count / m_matchedRecipe.ResultCount * m_matchedRecipe.ResultCount;
71 num = base.RemoveSlotItems(slotIndex, count);
72 if (num > 0) {
73 for (int i = 0; i < 9; i++) {
74 if (!string.IsNullOrEmpty(m_matchedIngredients[i])) {
75 int index = i % 3 + m_craftingGridSize * (i / 3);
76 m_slots[index].Count = MathUtils.Max(m_slots[index].Count - num / m_matchedRecipe.ResultCount, 0);
77 }
78 }
79 if (m_matchedRecipe.RemainsValue != 0
80 && m_matchedRecipe.RemainsCount > 0) {
81 m_slots[RemainsSlotIndex].Value = m_matchedRecipe.RemainsValue;
82 m_slots[RemainsSlotIndex].Count += num / m_matchedRecipe.ResultCount * m_matchedRecipe.RemainsCount;
83 }
84 ComponentPlayer componentPlayer = FindInteractingPlayer();
85 if (componentPlayer != null
86 && componentPlayer.PlayerStats != null) {
87 componentPlayer.PlayerStats.ItemsCrafted += num;
88 }
89 }
90 }
91 }
92 else {
93 num = base.RemoveSlotItems(slotIndex, count);
94 }
97 m_slots[ResultSlotIndex].Count = 0;
98 }
99 for (int i = 0; i < originalCount.Length; i++) {
100 if (originalCount[i] > 0
101 && GetSlotCount(i) == 0) {
103 }
104 }
105 return num;
106 }
107
108 public override void DropAllItems(Vector3 position) {
109 for (int i = 0; i < SlotsCount; i++) {
110 if (i != ResultSlotIndex) {
112 this,
113 i,
114 position,
115 m_random.Float(5f, 10f)
116 * Vector3.Normalize(new Vector3(m_random.Float(-1f, 1f), m_random.Float(1f, 2f), m_random.Float(-1f, 1f)))
117 );
118 }
119 }
120 }
121
122 public override void Load(ValuesDictionary valuesDictionary, IdToEntityMap idToEntityMap) {
123 base.Load(valuesDictionary, idToEntityMap);
124 m_craftingGridSize = (int)MathF.Sqrt(SlotsCount - 2);
126 }
127
128 public virtual void UpdateCraftingResult(bool recipeRefindNeeded) {
129 int num = int.MaxValue;
130 for (int i = 0; i < m_craftingGridSize; i++) {
131 for (int j = 0; j < m_craftingGridSize; j++) {
132 int num2 = i + j * 3;
133 int slotIndex = i + j * m_craftingGridSize;
134 int slotValue = GetSlotValue(slotIndex);
135 int num3 = Terrain.ExtractContents(slotValue);
136 int num4 = Terrain.ExtractData(slotValue);
137 int slotCount = GetSlotCount(slotIndex);
138 if (slotCount > 0) {
139 Block block = BlocksManager.Blocks[num3];
140 m_matchedIngredients[num2] = $"{block.GetCraftingId(slotValue)}:{num4.ToString(CultureInfo.InvariantCulture)}";
141 num = MathUtils.Min(num, slotCount);
142 }
143 else {
144 m_matchedIngredients[num2] = null;
145 }
146 }
147 }
148 ComponentPlayer componentPlayer = FindInteractingPlayer();
149 float playerLevel = componentPlayer?.PlayerData.Level ?? 1f;
150 CraftingRecipe craftingRecipe;
151 if (recipeRefindNeeded) {
153 Project.FindSubsystem<SubsystemTerrain>(true),
155 0f,
156 playerLevel
157 );
158 }
159 else {
160 craftingRecipe = m_matchedRecipe;
161 }
162 if (craftingRecipe != null
163 && craftingRecipe.ResultValue != 0) {
164 m_matchedRecipe = craftingRecipe;
165 m_slots[ResultSlotIndex].Value = craftingRecipe.ResultValue;
166 m_slots[ResultSlotIndex].Count = craftingRecipe.ResultCount * num;
167 }
168 else {
169 m_matchedRecipe = null;
170 m_slots[ResultSlotIndex].Value = 0;
171 m_slots[ResultSlotIndex].Count = 0;
172 }
173 if (craftingRecipe != null
174 && !string.IsNullOrEmpty(craftingRecipe.Message)) {
175 string message = craftingRecipe.Message;
176 if (message.StartsWith('[')
177 && message.EndsWith(']')) {
178 message = LanguageControl.Get("CRMessage", message.Substring(1, message.Length - 2));
179 }
180 componentPlayer?.ComponentGui.DisplaySmallMessage(message, Color.White, true, true);
181 }
182 }
183 }
184}
static int Min(int x1, int x2)
static int Max(int x1, int x2)
virtual int GetMaxStacking(int value)
override int GetSlotCapacity(int slotIndex, int value)
override int RemoveSlotItems(int slotIndex, int count)
实际移除的数量
override void DropAllItems(Vector3 position)
override void Load(ValuesDictionary valuesDictionary, IdToEntityMap idToEntityMap)
override void AddSlotItems(int slotIndex, int value, int count)
virtual void UpdateCraftingResult(bool recipeRefindNeeded)
virtual void DisplaySmallMessage(string text, Color color, bool blinking, bool playNotificationSound)
virtual int GetSlotCount(int slotIndex)
static void DropSlotItems(IInventory inventory, int slotIndex, Vector3 position, Vector3 velocity)
virtual int GetSlotValue(int slotIndex)
static CraftingRecipe FindMatchingRecipe(SubsystemTerrain terrain, string[] ingredients, float heatLevel, float playerLevel)
static string Get(string className, int key)
获取在当前语言类名键对应的字符串
static int ExtractContents(int value)
static int ExtractData(int value)
ValuesDictionary ValuesDictionary
static Color White
static Vector3 Normalize(Vector3 v)