Ejemplo n.º 1
0
        public override void CalculateSubPosition(IAreaJob rawJob, ref Vector3Int positionSub)
        {
            BerryFarmerJob job = (BerryFarmerJob)rawJob;

            Vector3Int min = job.Minimum;
            Vector3Int max = job.Maximum;

            if (job.checkMissingBushes && job.NPC.Colony.UsedStockpile.Contains(BuiltinBlocks.BerryBush))
            {
                // remove legacy positions
                for (int x = min.x + 1; x <= max.x; x += 2)
                {
                    for (int z = min.z; z <= max.z; z += 2)
                    {
                        ushort     type;
                        Vector3Int possiblePositionSub = new Vector3Int(x, min.y, z);
                        if (!World.TryGetTypeAt(possiblePositionSub, out type))
                        {
                            return;
                        }
                        if (type == BuiltinBlocks.BerryBush)
                        {
                            job.removingOldBush = true;
                            job.bushLocation    = possiblePositionSub;
                            positionSub         = Server.AI.AIManager.ClosestPosition(job.bushLocation, job.NPC.Position);
                            return;
                        }
                    }
                }
                // place new positions
                for (int x = min.x; x <= max.x; x += 2)
                {
                    for (int z = min.z; z <= max.z; z += 2)
                    {
                        ushort     type;
                        Vector3Int possiblePositionSub = new Vector3Int(x, min.y, z);
                        if (!World.TryGetTypeAt(possiblePositionSub, out type))
                        {
                            return;
                        }
                        if (type == 0)
                        {
                            job.placingMissingBush = true;
                            job.bushLocation       = possiblePositionSub;
                            positionSub            = Server.AI.AIManager.ClosestPositionNotAt(job.bushLocation, job.NPC.Position);
                            return;
                        }
                    }
                }
                job.checkMissingBushes = false;
            }

            positionSub    = min;
            positionSub.x += Random.Next(0, (max.x - min.x) / 2 + 1) * 2;
            positionSub.z += Random.Next(0, (max.z - min.z) / 2 + 1) * 2;
        }
Ejemplo n.º 2
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.NPC.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.NPC.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)
                    {
                        GatherResults.Clear();
                        GatherResults.Add(new ItemTypes.ItemTypeDrops(BuiltinBlocks.Berry, 1, 1.0));
                        GatherResults.Add(new ItemTypes.ItemTypeDrops(BuiltinBlocks.BerryBush, 1, 0.1));

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

                        InventoryItem toShow = ItemTypes.ItemTypeDrops.GetWeightedRandom(GatherResults);
                        if (toShow.Amount > 0)
                        {
                            state.SetIndicator(new Shared.IndicatorState(8.5f, toShow.Type));
                        }
                        else
                        {
                            state.SetCooldown(8.5);
                        }

                        job.NPC.Inventory.Add(GatherResults);
                    }
                    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);
            }
        }
Ejemplo n.º 3
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);
            }
        }