public override void OnNPCAtJob(IAreaJob job, ref Vector3Int positionSub, ref NPCBase.NPCState state, ref bool shouldDumpInventory)
        {
            state.JobIsDone = true;
            Vector3Int min = job.Minimum;
            Vector3Int max = job.Maximum;

            if (positionSub.x == min.x || positionSub.x == max.x ||
                positionSub.z == min.z || positionSub.z == max.z ||
                (positionSub.x - (min.x + 1)) % 3 != 0 ||
                (positionSub.z - (min.z + 1)) % 3 != 0)
            {
                ushort type;
                if (World.TryGetTypeAt(positionSub.Add(1, 0, 1), out type))
                {
                    if (type == BuiltinBlocks.Sapling)
                    {
                        Server.GrowableBlocks.IGrowableBlock block;
                        if (Server.GrowableBlocks.GrowableBlockManager.TryGetGrowableBlock(positionSub.Add(1, 0, 1), out block))
                        {
                            state.SetCooldown(5.0);
                        }
                        else
                        {
                            ItemTypesServer.OnChange(positionSub.Add(1, 0, 1), 0, BuiltinBlocks.Sapling, null);
                            state.SetIndicator(NPCIndicatorType.Crafted, 2f, BuiltinBlocks.Sapling);
                            state.SetCooldown(0.2);
                        }
                    }
                }
            }
            else if (positionSub.IsValid)
            {
                ushort type;
                if (World.TryGetTypeAt(positionSub, out type))
                {
                    if (type == 0)
                    {
                        if (job.UsedNPC.Inventory.TryGetOneItem(BuiltinBlocks.Sapling) ||
                            job.UsedNPC.Colony.UsedStockpile.TryRemove(BuiltinBlocks.Sapling))
                        {
                            ServerManager.TryChangeBlock(positionSub, BuiltinBlocks.Sapling, ServerManager.SetBlockFlags.DefaultAudio);
                            state.SetCooldown(2.0);
                        }
                        else
                        {
                            state.SetIndicator(NPCIndicatorType.MissingItem, 2f, BuiltinBlocks.Sapling);
                        }
                    }
                    else if (type == BuiltinBlocks.LogTemperate)
                    {
                        if (ChopTree(positionSub))
                        {
                            state.SetIndicator(NPCIndicatorType.Crafted, 10f, BuiltinBlocks.LogTemperate);
                            ServerManager.SendAudio(positionSub.Vector, "woodDeleteHeavy");
                            AddResults(job.UsedNPC.Inventory);
                        }
                        else
                        {
                            state.SetCooldown(Random.NextFloat(3f, 6f));
                        }
                    }
                    else
                    {
                        state.SetCooldown(Random.NextFloat(8f, 16f));
                    }
                }
                else
                {
                    state.SetCooldown(Random.NextFloat(3f, 6f));
                }
            }
            else
            {
                state.SetCooldown(10.0);
            }
            positionSub = Vector3Int.invalidPos;
        }
Exemplo n.º 2
0
        public virtual void OnNPCAtJob(IAreaJob job, ref Vector3Int positionSub, ref NPCBase.NPCState state, ref bool shouldDumpInventory)
        {
            if (stages == null || stages.Length < 2)
            {
                state.SetCooldown(1.0);
                return;
            }
            state.JobIsDone = true;
            if (positionSub.IsValid)
            {
                ushort type;
                if (World.TryGetTypeAt(positionSub, out type))
                {
                    ushort typeSeeds = stages[0];
                    ushort typeFinal = stages[stages.Length - 1];
                    if (type == 0)
                    {
                        if (state.Inventory.TryGetOneItem(typeSeeds) ||
                            job.NPC.Colony.UsedStockpile.TryRemove(typeSeeds))
                        {
                            ushort typeBelow;
                            if (World.TryGetTypeAt(positionSub.Add(0, -1, 0), out typeBelow))
                            {
                                // check for fertile below
                                if (ItemTypes.GetType(typeBelow).IsFertile)
                                {
                                    ServerManager.TryChangeBlock(positionSub, typeSeeds, job.Owner, ServerManager.SetBlockFlags.DefaultAudio);
                                    state.SetCooldown(1.0);
                                    shouldDumpInventory = false;
                                }
                                else
                                {
                                    // not fertile below
                                    AreaJobTracker.RemoveJob(job);
                                    state.SetCooldown(2.0);
                                }
                            }
                            else
                            {
                                // didn't load this part of the world
                                state.SetCooldown(Random.NextFloat(3f, 6f));
                            }
                        }
                        else
                        {
                            state.SetIndicator(new Shared.IndicatorState(2f, typeSeeds, true, false));
                            shouldDumpInventory = state.Inventory.UsedCapacity > 0f;
                        }
                    }
                    else if (type == typeFinal)
                    {
                        if (ServerManager.TryChangeBlock(positionSub, 0, job.Owner, ServerManager.SetBlockFlags.DefaultAudio))
                        {
                            GatherResults.Clear();
                            var results = ItemTypes.GetType(typeFinal).OnRemoveItems;
                            for (int i = 0; i < results.Count; i++)
                            {
                                GatherResults.Add(results[i]);
                            }

                            ModLoader.TriggerCallbacks(ModLoader.EModCallbackType.OnNPCGathered, job as IJob, positionSub, GatherResults);

                            job.NPC.Inventory.Add(GatherResults);
                        }
                        state.SetCooldown(1.0);
                        shouldDumpInventory = false;
                    }
                    else
                    {
                        shouldDumpInventory = state.Inventory.UsedCapacity > 0f;

                        Server.GrowableBlocks.IGrowableBlock block;
                        if (Server.GrowableBlocks.GrowableBlockManager.TryGetGrowableBlock(positionSub, out block))
                        {
                            state.SetCooldown(5.0);
                        }
                        else
                        {
                            bool found = false;
                            for (int i = 0; i < stages.Length; i++)
                            {
                                if (stages[i] == type)
                                {
                                    ItemTypesServer.OnChange(positionSub, 0, type, null);
                                    state.SetIndicator(new Shared.IndicatorState(2f, type));
                                    state.SetCooldown(0.2);
                                    found = true;
                                    break;
                                }
                            }
                            if (!found)
                            {
                                state.SetCooldown(5.0);
                            }
                        }
                    }
                }
                else
                {
                    state.SetCooldown(Random.NextFloat(3f, 6f));
                }
                positionSub = Vector3Int.invalidPos;
            }
            else
            {
                state.SetCooldown(10.0);
            }
        }
Exemplo n.º 3
0
        public override void OnNPCAtJob(IAreaJob job, ref Vector3Int positionSub, ref NPCBase.NPCState state, ref bool shouldDumpInventory)
        {
            state.JobIsDone = true;
            Vector3Int min = job.Minimum;
            Vector3Int max = job.Maximum;

            if (positionSub.x == min.x || positionSub.x == max.x ||
                positionSub.z == min.z || positionSub.z == max.z ||
                (positionSub.x - (min.x + 1)) % 3 != 0 ||
                (positionSub.z - (min.z + 1)) % 3 != 0)
            {
                ushort type;
                if (World.TryGetTypeAt(positionSub.Add(1, 0, 1), out type))
                {
                    if (type == BuiltinBlocks.Sapling)
                    {
                        Server.GrowableBlocks.IGrowableBlock block;
                        if (Server.GrowableBlocks.GrowableBlockManager.TryGetGrowableBlock(positionSub.Add(1, 0, 1), out block))
                        {
                            state.SetCooldown(5.0);
                        }
                        else
                        {
                            ItemTypesServer.OnChange(positionSub.Add(1, 0, 1), 0, BuiltinBlocks.Sapling, null);
                            state.SetIndicator(new Shared.IndicatorState(2f, BuiltinBlocks.Sapling));
                            state.SetCooldown(0.2);
                        }
                    }
                    else
                    {
                        state.SetCooldown(1.0);                         // no sapling at sapling spot (shouldn't occur a lot, something changed between calculate sub position and this
                    }
                }
                else
                {
                    state.SetCooldown(4.0);                     // walked to sapling spot, not loaded
                }
            }
            else if (positionSub.IsValid)
            {
                ushort type;
                if (World.TryGetTypeAt(positionSub, out type))
                {
                    if (type == 0)
                    {
                        if (job.NPC.Inventory.TryGetOneItem(BuiltinBlocks.Sapling) ||
                            job.NPC.Colony.UsedStockpile.TryRemove(BuiltinBlocks.Sapling))
                        {
                            ServerManager.TryChangeBlock(positionSub, BuiltinBlocks.Sapling, job.Owner, ServerManager.SetBlockFlags.DefaultAudio);
                            state.SetCooldown(2.0);
                        }
                        else
                        {
                            state.SetIndicator(new Shared.IndicatorState(2f, BuiltinBlocks.Sapling));
                        }
                    }
                    else if (type == BuiltinBlocks.LogTemperate)
                    {
                        if (ChopTree(positionSub, job.Owner))
                        {
                            state.SetIndicator(new Shared.IndicatorState(10f, BuiltinBlocks.LogTemperate));
                            ServerManager.SendAudio(positionSub.Vector, "woodDeleteHeavy");

                            GatherResults.Clear();
                            GatherResults.Add(new ItemTypes.ItemTypeDrops(BuiltinBlocks.LogTemperate, 3, 1.0));
                            GatherResults.Add(new ItemTypes.ItemTypeDrops(BuiltinBlocks.LeavesTemperate, 9, 1.0));
                            GatherResults.Add(new ItemTypes.ItemTypeDrops(BuiltinBlocks.Sapling, 1, 1.0));
                            GatherResults.Add(new ItemTypes.ItemTypeDrops(BuiltinBlocks.Sapling, 1, 0.25));

                            ModLoader.TriggerCallbacks(ModLoader.EModCallbackType.OnNPCGathered, job as IJob, positionSub, GatherResults);

                            job.NPC.Inventory.Add(GatherResults);
                        }
                        else
                        {
                            state.SetCooldown(Random.NextFloat(3f, 6f));
                        }
                    }
                    else
                    {
                        state.SetCooldown(Random.NextFloat(8f, 16f));
                    }
                }
                else
                {
                    state.SetCooldown(Random.NextFloat(3f, 6f));
                }
            }
            else
            {
                state.SetCooldown(10.0);
            }
            positionSub = Vector3Int.invalidPos;
        }
        public override void OnNPCAtJob(IAreaJob job, ref Vector3Int positionSub, ref NPCBase.NPCState state, ref bool shouldDumpInventory)
        {
            state.JobIsDone = true;
            Vector3Int min = job.Minimum;
            Vector3Int max = job.Maximum;

            if (positionSub.x == min.x || positionSub.x == max.x ||
                positionSub.z == min.z || positionSub.z == max.z ||
                (positionSub.x - (min.x + 1)) % 3 != 0 ||
                (positionSub.z - (min.z + 1)) % 3 != 0)
            {
                ushort type;
                if (World.TryGetTypeAt(positionSub.Add(1, 0, 1), out type))
                {
                    if (type == saplingIndex)
                    {
                        Server.GrowableBlocks.IGrowableBlock block;
                        if (Server.GrowableBlocks.GrowableBlockManager.TryGetGrowableBlock(positionSub.Add(1, 0, 1), out block))
                        {
                            state.SetCooldown(5.0);
                        }
                        else
                        {
                            ItemTypesServer.OnChange(positionSub.Add(1, 0, 1), 0, saplingIndex, null);
                            state.SetIndicator(new Shared.IndicatorState(2f, saplingIndex));
                            state.SetCooldown(0.2);
                        }
                    }
                }
            }
            else if (positionSub.IsValid)
            {
                ushort type;
                if (World.TryGetTypeAt(positionSub, out type))
                {
                    if (type == 0)
                    {
                        if (job.NPC.Inventory.TryGetOneItem(saplingIndex) ||
                            job.NPC.Colony.UsedStockpile.TryRemove(saplingIndex))
                        {
                            ServerManager.TryChangeBlock(positionSub, saplingIndex, job.Owner, ServerManager.SetBlockFlags.DefaultAudio);
                            state.SetCooldown(2.0);
                        }
                        else
                        {
                            state.SetIndicator(new Shared.IndicatorState(2f, saplingIndex));
                        }
                    }
                    else if (type == logIndex)
                    {
                        if (ChopTree(positionSub, job.Owner))
                        {
                            state.SetIndicator(new Shared.IndicatorState(10f, logIndex));
                            ServerManager.SendAudio(positionSub.Vector, "woodDeleteHeavy");

                            GatherResults.Clear();
                            GatherResults.Add(new ItemTypes.ItemTypeDrops(logIndex, 3, 1.0));
                            GatherResults.Add(new ItemTypes.ItemTypeDrops(leaveIndex, 9, 1.0));
                            GatherResults.Add(new ItemTypes.ItemTypeDrops(saplingIndex, 1, 1.0));
                            GatherResults.Add(new ItemTypes.ItemTypeDrops(saplingIndex, 1, 0.25));
                            GatherResults.Add(new ItemTypes.ItemTypeDrops(fruitIndex, 2, 0.5));

                            ModLoader.TriggerCallbacks(ModLoader.EModCallbackType.OnNPCGathered, job as IJob, positionSub, GatherResults);

                            job.NPC.Inventory.Add(GatherResults);
                        }
                        else
                        {
                            state.SetCooldown(Random.NextFloat(3f, 6f));
                        }
                    }
                    else
                    {
                        state.SetCooldown(Random.NextFloat(8f, 16f));
                    }
                }
                else
                {
                    state.SetCooldown(Random.NextFloat(3f, 6f));
                }
            }
            else
            {
                state.SetCooldown(10.0);
            }
            positionSub = Vector3Int.invalidPos;
        }
        public virtual void OnNPCAtJob(IAreaJob job, ref Vector3Int positionSub, ref NPCBase.NPCState state, ref bool shouldDumpInventory)
        {
            if (stages == null || stages.Length < 2)
            {
                state.SetCooldown(1.0);
                return;
            }
            state.JobIsDone = true;
            if (positionSub.IsValid)
            {
                ushort type;
                if (World.TryGetTypeAt(positionSub, out type))
                {
                    ushort typeSeeds = stages[0];
                    ushort typeFinal = stages[stages.Length - 1];
                    if (type == 0)
                    {
                        if (state.Inventory.TryGetOneItem(typeSeeds) ||
                            job.UsedNPC.Colony.UsedStockpile.TryRemove(typeSeeds))
                        {
                            ServerManager.TryChangeBlock(positionSub, typeSeeds, job.Owner, ServerManager.SetBlockFlags.DefaultAudio);
                            state.SetCooldown(1.0);
                            shouldDumpInventory = false;
                        }
                        else
                        {
                            state.SetIndicator(new Shared.IndicatorState(2f, typeSeeds, true, false));
                            shouldDumpInventory = state.Inventory.UsedCapacity > 0f;
                        }
                    }
                    else if (type == typeFinal)
                    {
                        if (ServerManager.TryChangeBlock(positionSub, 0, job.Owner, ServerManager.SetBlockFlags.DefaultAudio))
                        {
                            job.UsedNPC.Inventory.Add(ItemTypes.GetType(typeFinal).OnRemoveItems);
                        }
                        state.SetCooldown(1.0);
                        shouldDumpInventory = false;
                    }
                    else
                    {
                        shouldDumpInventory = state.Inventory.UsedCapacity > 0f;

                        Server.GrowableBlocks.IGrowableBlock block;
                        if (Server.GrowableBlocks.GrowableBlockManager.TryGetGrowableBlock(positionSub, out block))
                        {
                            state.SetCooldown(5.0);
                        }
                        else
                        {
                            bool found = false;
                            for (int i = 0; i < stages.Length; i++)
                            {
                                if (stages[i] == type)
                                {
                                    ItemTypesServer.OnChange(positionSub, 0, type, null);
                                    state.SetIndicator(new Shared.IndicatorState(2f, type));
                                    state.SetCooldown(0.2);
                                    found = true;
                                    break;
                                }
                            }
                            if (!found)
                            {
                                state.SetCooldown(5.0);
                            }
                        }
                    }
                }
                else
                {
                    state.SetCooldown(Random.NextFloat(3f, 6f));
                }
                positionSub = Vector3Int.invalidPos;
            }
            else
            {
                state.SetCooldown(10.0);
            }
        }