static void AddResults(NPCInventory inv)
 {
     inv.Add(BuiltinBlocks.LogTemperate, 3);
     inv.Add(BuiltinBlocks.LeavesTemperate, 9);
     inv.Add(BuiltinBlocks.Sapling);
     if (Random.NextDouble() > 0.25)
     {
         inv.Add(BuiltinBlocks.Sapling);
     }
 }
Пример #2
0
 public static void Add(this NPCInventory inventory, IEnumerable <StoredItem> items)
 {
     foreach (var item in items)
     {
         inventory.Add(item);
     }
 }
Пример #3
0
 public static void Add(this NPCInventory inventory, IEnumerable <InventoryItem> items, int multiplier)
 {
     if (items != null)
     {
         foreach (var item in items)
         {
             inventory.Add(item * multiplier);
         }
     }
 }
        public override void OnNPCDoJob(ref NPCBase.NPCState state)
        {
            state.JobIsDone = true;
            usedNPC.LookAt(position.Vector);
            if (!state.Inventory.IsEmpty)
            {
                storedFuel += state.Inventory.TotalFuel;
                state.Inventory.ClearFuel();
                state.Inventory.Dump(blockInventory);
            }
            if (selectedRecipe != null)
            {
                if (recipesToCraft > 0 && selectedRecipe.IsPossible(usedNPC.Colony.UsedStockpile, blockInventory, storedFuel))
                {
                    storedFuel -= selectedRecipe.FuelPerCraft;
                    blockInventory.Remove(selectedRecipe.Requirements);
                    blockInventory.Add(selectedRecipe.Results);
                    recipesToCraft--;
                    OnLit();
                    state.SetIndicator(NPCIndicatorType.Crafted, TimeBetweenJobs, selectedRecipe.Results[0].Type);
                    state.JobIsDone = false;
                    return;
                }
                else
                {
                    recipesToCraft = 0;
                    selectedRecipe = null;
                    blockInventory.Dump(usedNPC.Inventory);
                    if (!state.Inventory.IsEmpty)
                    {
                        shouldTakeItems = true;
                    }
                    OverrideCooldown(0.1);
                }
            }
            else
            {
                var recipeMatch = Recipe.MatchRecipe(GetPossibleRecipes, usedNPC.Colony.UsedStockpile);
                switch (recipeMatch.MatchType)
                {
                case Recipe.RecipeMatchType.AllDone:
                case Recipe.RecipeMatchType.FoundMissingRequirements:
                    if (!state.Inventory.IsEmpty || !blockInventory.IsEmpty)
                    {
                        blockInventory.Dump(usedNPC.Inventory);
                        shouldTakeItems = true;
                    }
                    else
                    {
                        state.JobIsDone = false;
                        float cooldown = Random.NextFloat(8f, 16f);
                        if (recipeMatch.MatchType == Recipe.RecipeMatchType.AllDone)
                        {
                            state.SetIndicator(NPCIndicatorType.SuccessIdle, cooldown);
                        }
                        else
                        {
                            state.SetIndicator(NPCIndicatorType.MissingItem, cooldown, recipeMatch.FoundRecipe.FindMissingType(owner));
                        }
                        OverrideCooldown(cooldown);
                    }
                    break;

                case Recipe.RecipeMatchType.FoundCraftable:
                    blockInventory.Dump(usedNPC.Inventory);
                    selectedRecipe  = recipeMatch.FoundRecipe;
                    shouldTakeItems = true;
                    OverrideCooldown(0.5);
                    break;
                }
            }
            OnUnlit();
        }
Пример #5
0
        public override void OnNPCAtJob(ref NPCBase.NPCState state)
        {
            state.JobIsDone = true;
            usedNPC.LookAt(position.Vector);
            if (!state.Inventory.IsEmpty)
            {
                usedNPC.Inventory.Dump(blockInventory);
            }
            if (selectedRecipe != null)
            {
                if (recipesToCraft > 0 && selectedRecipe.IsPossible(usedNPC.Colony.UsedStockpile, blockInventory))
                {
                    blockInventory.Remove(selectedRecipe.Requirements);

                    craftingResults.Clear();
                    for (int i = 0; i < selectedRecipe.Results.Count; i++)
                    {
                        craftingResults.Add(selectedRecipe.Results[i]);
                    }
                    ModLoader.TriggerCallbacks(ModLoader.EModCallbackType.OnNPCCraftedRecipe, (IJob)this, selectedRecipe, craftingResults);

                    if (craftingResults.Count > 0)
                    {
                        blockInventory.Add(craftingResults);
                        ushort typeToShow;
                        typeToShow = craftingResults[0].Type;
                        if (craftingResults.Count > 1)
                        {
                            int totalTypes = 0;
                            for (int i = 0; i < craftingResults.Count; i++)
                            {
                                totalTypes += craftingResults[i].Amount;
                            }
                            totalTypes = Random.Next(0, totalTypes + 1);
                            for (int i = 0; i < craftingResults.Count; i++)
                            {
                                totalTypes -= craftingResults[i].Amount;
                                if (totalTypes <= 0)
                                {
                                    typeToShow = craftingResults[i].Type;
                                    break;
                                }
                            }
                        }

                        state.SetIndicator(new Shared.IndicatorState(CraftingCooldown, typeToShow));
                    }
                    else
                    {
                        state.SetIndicator(new Shared.IndicatorState(CraftingCooldown, NPCIndicatorType.None));
                    }

                    state.JobIsDone = false;
                    recipesToCraft--;
                    OnRecipeCrafted();
                }
                else
                {
                    selectedRecipe = null;
                    recipesToCraft = 0;
                    blockInventory.Dump(usedNPC.Inventory);
                    if (!state.Inventory.IsEmpty)
                    {
                        shouldTakeItems = true;
                    }
                    state.SetCooldown(0.1);
                    if (wasCrafting)
                    {
                        OnStopCrafting();
                    }
                }
            }
            else
            {
                var recipeMatch = Recipe.MatchRecipe <Recipe, IList <Recipe> >(GetPossibleRecipes, usedNPC.Colony.UsedStockpile);
                switch (recipeMatch.MatchType)
                {
                case Recipe.RecipeMatchType.AllDone:
                case Recipe.RecipeMatchType.FoundMissingRequirements:
                    if (!state.Inventory.IsEmpty || !blockInventory.IsEmpty)
                    {
                        blockInventory.Dump(usedNPC.Inventory);
                        shouldTakeItems = true;
                        state.SetCooldown(0.3);
                    }
                    else
                    {
                        state.JobIsDone = false;
                        float cooldown = Random.NextFloat(8f, 16f);
                        if (recipeMatch.MatchType == Recipe.RecipeMatchType.AllDone)
                        {
                            state.SetIndicator(new Shared.IndicatorState(cooldown, BlockTypes.Builtin.BuiltinBlocks.ErrorIdle));
                        }
                        else
                        {
                            state.SetIndicator(new Shared.IndicatorState(cooldown, recipeMatch.FoundRecipe.FindMissingType(owner), true, false));
                        }
                    }
                    break;

                case Recipe.RecipeMatchType.FoundCraftable:
                    blockInventory.Dump(usedNPC.Inventory);
                    selectedRecipe  = recipeMatch.FoundRecipe;
                    shouldTakeItems = true;
                    state.SetCooldown(0.3);
                    break;

                default:
                    Assert.IsTrue(false, "Unexpected RecipeMatchType: " + recipeMatch.MatchType);
                    break;
                }
                if (wasCrafting)
                {
                    OnStopCrafting();
                }
            }
        }
Пример #6
0
        public override void OnNPCAtJob(ref NPCBase.NPCState state)
        {
            state.JobIsDone = true;
            usedNPC.LookAt(position.Vector);
            if (!state.Inventory.IsEmpty)
            {
                usedNPC.Inventory.Dump(blockInventory);
            }
            if (selectedRecipe != null)
            {
                if (recipesToCraft > 0 && selectedRecipe.IsPossible(usedNPC.Colony.UsedStockpile, blockInventory))
                {
                    blockInventory.Remove(selectedRecipe.Requirements);
                    blockInventory.Add(selectedRecipe.Results);
                    state.SetIndicator(new Shared.IndicatorState(CraftingCooldown, selectedRecipe.Results[0].Type));
                    state.JobIsDone = false;
                    recipesToCraft--;
                    OnRecipeCrafted();
                }
                else
                {
                    selectedRecipe = null;
                    recipesToCraft = 0;
                    blockInventory.Dump(usedNPC.Inventory);
                    if (!state.Inventory.IsEmpty)
                    {
                        shouldTakeItems = true;
                    }
                    state.SetCooldown(0.1);
                    if (wasCrafting)
                    {
                        OnStopCrafting();
                    }
                }
            }
            else
            {
                var recipeMatch = Recipe.MatchRecipe <Recipe, IList <Recipe> >(GetPossibleRecipes, usedNPC.Colony.UsedStockpile);
                switch (recipeMatch.MatchType)
                {
                case Recipe.RecipeMatchType.AllDone:
                case Recipe.RecipeMatchType.FoundMissingRequirements:
                    if (!state.Inventory.IsEmpty || !blockInventory.IsEmpty)
                    {
                        blockInventory.Dump(usedNPC.Inventory);
                        shouldTakeItems = true;
                        state.SetCooldown(0.3);
                    }
                    else
                    {
                        state.JobIsDone = false;
                        float cooldown = Random.NextFloat(8f, 16f);
                        if (recipeMatch.MatchType == Recipe.RecipeMatchType.AllDone)
                        {
                            state.SetIndicator(new Shared.IndicatorState(cooldown, BlockTypes.Builtin.BuiltinBlocks.ErrorIdle));
                        }
                        else
                        {
                            state.SetIndicator(new Shared.IndicatorState(cooldown, recipeMatch.FoundRecipe.FindMissingType(owner), true, false));
                        }
                    }
                    break;

                case Recipe.RecipeMatchType.FoundCraftable:
                    blockInventory.Dump(usedNPC.Inventory);
                    selectedRecipe  = recipeMatch.FoundRecipe;
                    shouldTakeItems = true;
                    state.SetCooldown(0.3);
                    break;

                default:
                    Assert.IsTrue(false, "Unexpected RecipeMatchType: " + recipeMatch.MatchType);
                    break;
                }
                if (wasCrafting)
                {
                    OnStopCrafting();
                }
            }
        }
Пример #7
0
        public override void OnNPCAtJob(IAreaJob rawJob, ref Vector3Int positionSub, ref NPCBase.NPCState state, ref bool shouldDumpInventory)
        {
            BerryFarmerJob job = (BerryFarmerJob)rawJob;

            state.JobIsDone = true;
            if (positionSub.IsValid)
            {
                ushort type;
                if (job.placingMissingBush)
                {
                    if (job.UsedNPC.Colony.UsedStockpile.TryRemove(BuiltinBlocks.BerryBush))
                    {
                        job.placingMissingBush = false;
                        ServerManager.TryChangeBlock(job.bushLocation, BuiltinBlocks.BerryBush, rawJob.Owner, ServerManager.SetBlockFlags.DefaultAudio);
                        state.SetCooldown(2.0);
                    }
                    else
                    {
                        state.SetIndicator(new Shared.IndicatorState(Random.NextFloat(8f, 14f), BuiltinBlocks.BerryBush, true, false));
                    }
                }
                else if (job.removingOldBush)
                {
                    if (ServerManager.TryChangeBlock(job.bushLocation, 0, rawJob.Owner, ServerManager.SetBlockFlags.DefaultAudio))
                    {
                        job.UsedNPC.Colony.UsedStockpile.Add(BuiltinBlocks.BerryBush);
                        job.removingOldBush = false;
                    }
                    state.SetCooldown(2.0);
                }
                else if (World.TryGetTypeAt(positionSub, out type))
                {
                    if (type == 0)
                    {
                        job.checkMissingBushes = true;
                        state.SetCooldown(1.0, 4.0);
                    }
                    else if (type == BuiltinBlocks.BerryBush)
                    {
                        state.SetIndicator(new Shared.IndicatorState(8.5f, BuiltinBlocks.Berry));
                        NPCInventory inv = job.UsedNPC.Inventory;
                        inv.Add(BuiltinBlocks.Berry);
                        if (Random.Next(0, 10) >= 9)
                        {
                            inv.Add(BuiltinBlocks.BerryBush);
                        }
                    }
                    else
                    {
                        state.SetIndicator(new Shared.IndicatorState(Random.NextFloat(8f, 14f), BuiltinBlocks.ErrorMissing));
                    }
                }
                else
                {
                    state.SetCooldown(Random.NextFloat(3f, 6f));
                }
                positionSub = Vector3Int.invalidPos;
            }
            else
            {
                state.SetCooldown(10.0);
            }
        }
        public override void OnNPCDoJob(ref NPCBase.NPCState state)
        {
            state.JobIsDone = true;
            usedNPC.LookAt(position.Vector);
            if (!state.Inventory.IsEmpty)
            {
                usedNPC.Inventory.Dump(blockInventory);
            }
            if (selectedRecipe != null)
            {
                if (selectedRecipe.IsPossible(usedNPC.Colony.UsedStockpile, blockInventory))
                {
                    blockInventory.Take(selectedRecipe.Requirements);
                    blockInventory.Add(selectedRecipe.Results);
                    state.SetIndicator(NPCIndicatorType.Crafted, TimeBetweenJobs, selectedRecipe.Results[0].Type);
                    state.JobIsDone = false;
                }
                else
                {
                    selectedRecipe = null;
                    blockInventory.Dump(usedNPC.Inventory);
                    if (!state.Inventory.IsEmpty)
                    {
                        shouldTakeItems = true;
                    }
                    OverrideCooldown(0.1);
                }
            }
            else
            {
                var recipeMatch = Recipe.MatchRecipe(GetPossibleRecipes, usedNPC.Colony.UsedStockpile);
                switch (recipeMatch.MatchType)
                {
                case Recipe.RecipeMatchType.AllDone:
                case Recipe.RecipeMatchType.FoundMissingRequirements:
                    if (!state.Inventory.IsEmpty || !blockInventory.IsEmpty)
                    {
                        blockInventory.Dump(usedNPC.Inventory);
                        shouldTakeItems = true;
                    }
                    else
                    {
                        state.JobIsDone = false;
                        if (recipeMatch.MatchType == Recipe.RecipeMatchType.AllDone)
                        {
                            state.SetIndicator(NPCIndicatorType.SuccessIdle, 6f);
                        }
                        else
                        {
                            state.SetIndicator(NPCIndicatorType.MissingItem, 6f, recipeMatch.FoundRecipe.Requirements[0].Type);
                        }
                        OverrideCooldown(6.0);
                    }
                    break;

                case Recipe.RecipeMatchType.FoundCraftable:
                    blockInventory.Dump(usedNPC.Inventory);
                    selectedRecipe  = recipeMatch.FoundRecipe;
                    shouldTakeItems = true;
                    OverrideCooldown(0.5);
                    break;
                }
            }
        }