Exemple #1
0
        public override void OnNPCAtStockpile(ref NPCBase.NPCState state)
        {
            if (state.Inventory.IsEmpty)
            {
                Assert.IsTrue(shouldTakeItems);
            }
            else
            {
                state.Inventory.Dump(usedNPC.Colony.UsedStockpile);
            }
            state.SetCooldown(0.5);
            state.JobIsDone = true;
            if (shouldTakeItems)
            {
                shouldTakeItems = false;

                ScienceManagerPlayer scienceManager;
                if (!ScienceManager.TryGetPlayerManager(owner, out scienceManager))
                {
                    return;
                }

                ResearchProgress active = scienceManager.ActiveResearch;
                if (active.research != null && !active.IsCompleted)
                {
                    var requirements = active.research.GetScienceRequirements();
                    if (Stockpile.GetStockPile(owner).TryRemove(requirements))
                    {
                        state.Inventory.Add(requirements);
                    }
                }
            }
        }
Exemple #2
0
        public override void OnNPCAtJob(ref NPCBase.NPCState state)
        {
            usedNPC.LookAt(position.Vector);
            ScienceManagerPlayer scienceManager;

            if (!ScienceManager.TryGetPlayerManager(owner, out scienceManager))
            {
                state.SetIndicator(new Shared.IndicatorState(6f, BuiltinBlocks.ErrorIdle));
                state.JobIsDone = false;
                return;
            }
            ResearchProgress active = scienceManager.ActiveResearch;

            if (state.Inventory.IsEmpty)
            {
                if (active.research != null && !active.IsCompleted)
                {
                    // no items, but valid research -> try to get items
                    IList <InventoryItem> requirements = active.research.GetScienceRequirements();
                    Stockpile             stockpile    = Stockpile.GetStockPile(owner);
                    if (Stockpile.GetStockPile(owner).Contains(requirements))
                    {
                        shouldTakeItems = true;
                        state.SetCooldown(0.3);
                        state.JobIsDone = true;
                    }
                    else
                    {
                        ushort missing = 0;
                        for (int i = 0; i < requirements.Count; i++)
                        {
                            if (!stockpile.Contains(requirements[i]))
                            {
                                missing = requirements[i].Type;
                                break;
                            }
                        }
                        float cooldown = Random.NextFloat(8f, 16f);
                        state.SetIndicator(new Shared.IndicatorState(cooldown, missing, true, false));
                        state.JobIsDone = false;
                    }
                }
                else
                {
                    float cooldown = Random.NextFloat(8f, 16f);
                    // no items, no research -> wait for research
                    state.SetIndicator(new Shared.IndicatorState(cooldown, BuiltinBlocks.ErrorIdle));
                    state.JobIsDone = false;
                }
            }
            else
            {
                if (active.research == null || active.IsCompleted)
                {
                    // items, but no valid research -> go dump items
                    shouldTakeItems = true;
                    state.SetCooldown(0.3);
                    state.JobIsDone = true;
                }
                else
                {
                    // items, valid research -> try progress
                    IResearchable         researchable = active.research;
                    IList <InventoryItem> requirements = researchable.GetScienceRequirements();
                    if (state.Inventory.TryRemove(requirements))
                    {
                        int recycled = 0;
                        for (int i = 0; i < requirements.Count; i++)
                        {
                            ushort type = requirements[i].Type;
                            if (type == BuiltinBlocks.ScienceBagLife ||
                                type == BuiltinBlocks.ScienceBagBasic ||
                                type == BuiltinBlocks.ScienceBagMilitary)
                            {
                                recycled += requirements[i].Amount;
                            }
                        }
                        for (int i = recycled; i > 0; i--)
                        {
                            if (Random.NextDouble() > RECYCLE_CHANCE)
                            {
                                recycled--;
                            }
                        }
                        state.Inventory.Add(BuiltinBlocks.LinenBag, recycled);
                        scienceManager.AddActiveResearchProgress(1);
                        state.SetIndicator(new Shared.IndicatorState(CraftingCooldown, NPCIndicatorType.Science));
                    }
                    else
                    {
                        state.SetCooldown(0.3);
                    }
                    shouldTakeItems = true;
                    state.JobIsDone = true;
                }
            }
        }