@@ -237,7 +237,22 @@ function heliofusionExoticizerController:new(
237237 event .push (" log_warning" , " Successfully went to Encode Fake Pattern state after a long Idle state" )
238238 end
239239
240- self :encodePattern (self .stateMachine .data .outputs )
240+ local success , outputsCount = self :encodePattern (self .stateMachine .data .outputs )
241+
242+ if success == false then
243+ self .stateMachine .data .errorMessage = " Found an unidentified object in the output subnet"
244+ self .stateMachine :setState (self .stateMachine .states .error )
245+ return
246+ end
247+
248+ local expectedCount = self .magmatterMode == true and 3 or 7
249+
250+ if outputsCount ~= expectedCount then
251+ self .stateMachine .data .errorMessage = " Number of objects (" .. outputsCount .. " ) doesn't match the expected (" .. expectedCount .. " )"
252+ self .stateMachine :setState (self .stateMachine .states .error )
253+ return
254+ end
255+
241256 self .stateMachine :setState (self .stateMachine .states .clearOutputAe )
242257 end
243258
@@ -354,6 +369,8 @@ function heliofusionExoticizerController:new(
354369
355370 --- Encode fake pattern with the right plasmas
356371 --- @param outputs table<string , OutputItem>
372+ --- @return boolean
373+ --- @return integer
357374 --- @private
358375 function obj :encodePattern (outputs )
359376 local index = 1
@@ -370,10 +387,16 @@ function heliofusionExoticizerController:new(
370387 count = value .count * (value .isLiquid == true and 1000 or 144 )
371388 end
372389
373- self .inputMeInterfaceProxy .setInterfacePatternInput (1 , self .database .address , self .plasmaList [value .label ].databaseIndex , count , index )
390+ if self .plasmaList [value .label ] ~= nil then
391+ self .inputMeInterfaceProxy .setInterfacePatternInput (1 , self .database .address , self .plasmaList [value .label ].databaseIndex , count , index )
392+ else
393+ return false , index - 1
394+ end
374395
375396 index = index + 1
376- end
397+ end
398+
399+ return true , index - 1
377400 end
378401
379402 --- Get items from output ae
@@ -390,13 +413,25 @@ function heliofusionExoticizerController:new(
390413
391414 for _ , value in pairs (items ) do
392415 local label = value .label :match (" Pile of%s(.+)%sDust" )
393- outputs [label ] = {label = label , count = value .size , isLiquid = false }
416+
417+ if label == nil then
418+ outputs [value .label ] = {label = value .label , count = value .size , isLiquid = false }
419+ else
420+ outputs [label ] = {label = label , count = value .size , isLiquid = false }
421+ end
422+
394423 count = count + 1
395424 end
396425
397426 for _ , value in pairs (liquids ) do
398427 local label = value .label :match (" ^(.-)%s?[Gg]?[Aa]?[Ss]?$" )
399- outputs [label ] = {label = label , count = value .amount , isLiquid = true }
428+
429+ if label == nil then
430+ outputs [value .label ] = {label = value .label , count = value .amount , isLiquid = true }
431+ else
432+ outputs [label ] = {label = label , count = value .amount , isLiquid = true }
433+ end
434+
400435 count = count + 1
401436 end
402437
0 commit comments