Beispiel #1
0
 public override void OnNPCDoJob(ref NPCBase.NPCState state)
 {
     state.JobIsDone = true;
     usedNPC.LookAt(position.Vector);
     if (!state.Inventory.IsEmpty)
     {
         state.Inventory.Dump(blockInventory);
     }
     if (todoblocks.Count < 1)
     {
         blockInventory.Dump(usedNPC.Inventory);
         shouldTakeItems = true;
     }
     else
     {
         bool   placed       = false;
         ushort bluetype     = ItemTypes.IndexLookup.GetIndex(fullname);
         ushort scaffoldType = ItemTypes.IndexLookup.GetIndex(ScaffoldsModEntries.SCAFFOLD_ITEM_TYPE);
         string jobname      = fullname.Substring(0, fullname.Length - 2);
         for (int i = todoblocks.Count - 1; i >= 0; i--)
         {
             BlueprintTodoBlock todoblock    = todoblocks[i];
             Vector3Int         realPosition = todoblock.GetWorldPosition(jobname, position, bluetype);
             if (realPosition.y <= 0)
             {
                 todoblocks.RemoveAt(i);
                 continue;
             }
             ushort newType = ItemTypes.IndexLookup.GetIndex(todoblock.typename);
             ushort actualType;
             if (World.TryGetTypeAt(realPosition, out actualType) && actualType != newType)
             {
                 ushort baseType = ItemTypes.IndexLookup.GetIndex(TypeHelper.RotatableToBasetype(todoblock.typename));
                 if (newType == BlockTypes.Builtin.BuiltinBlocks.Air || blockInventory.TryGetOneItem(baseType))
                 {
                     todoblocks.RemoveAt(i);
                     if (ServerManager.TryChangeBlock(realPosition, newType, ServerManager.SetBlockFlags.DefaultAudio))
                     {
                         state.JobIsDone = true;
                         if (newType == BlockTypes.Builtin.BuiltinBlocks.Air)
                         {
                             OverrideCooldown(ConstructionModEntries.EXCAVATION_DELAY);
                             state.SetIndicator(NPCIndicatorType.MissingItem, ConstructionModEntries.EXCAVATION_DELAY, actualType);
                         }
                         else if (!blockInventory.IsEmpty && i > 0)
                         {
                             state.SetIndicator(NPCIndicatorType.Crafted, TimeBetweenJobs, ItemTypes.IndexLookup.GetIndex(todoblocks[i].typename));
                         }
                         if (actualType != BlockTypes.Builtin.BuiltinBlocks.Air && actualType != scaffoldType)
                         {
                             usedNPC.Inventory.Add(ItemTypes.RemovalItems(actualType));
                         }
                         placed = true;
                         break;
                     }
                 }
             }
             else
             {
                 todoblocks.RemoveAt(i);
             }
         }
         if (!placed)
         {
             blockInventory.Dump(usedNPC.Inventory);
             shouldTakeItems = true;
         }
     }
 }