コード例 #1
0
        public virtual void OnNPCAtStockpile(BlockJobInstance blockJobInstance, ref NPCBase.NPCState state)
        {
            GeneratorJobInstance instance = (GeneratorJobInstance)blockJobInstance;

            if (state.Inventory.IsEmpty == false)
            {
                state.Inventory.Dump(blockJobInstance.Owner.Stockpile);
                state.SetCooldown(0.3);
            }
            state.JobIsDone = true;
            if (instance.ShouldTakeItems == false)
            {
                return;
            }
            instance.ShouldTakeItems = false;

            if (state.Inventory.IsEmpty)
            {
                //Repeat till inventory is full!
                //Check if EnergyItem exists in the stockpile
                if (blockJobInstance.Owner.Stockpile.TryRemove(EnergyItem.Type, EnergyItem.Amount * 5))
                {
                    //Take item and increase wait counter
                    state.Inventory.Add(EnergyItem.Type, EnergyItem.Amount * 5);
                }
            }
            //Make NPC wait 1 second
            state.SetCooldown(1);
        }
コード例 #2
0
        public void OnGoalChanged(BlockJobInstance instanceBlock, NPCBase.NPCGoal goalOld, NPCBase.NPCGoal goalNew)
        {
            GeneratorJobInstance instance = (GeneratorJobInstance)instanceBlock;

            if (goalOld == NPCBase.NPCGoal.Job && instance.IsCrafting)
            {
                instance.IsCrafting = false;
                OnStopCrafting(instance);
            }
        }
コード例 #3
0
        public virtual void OnNPCAtJob(BlockJobInstance blockJobInstance, ref NPCBase.NPCState state)
        {
            GeneratorJobInstance instance = (GeneratorJobInstance)blockJobInstance;

            NPCLookAtJobBlock(blockJobInstance);
            state.JobIsDone = true;
            //Make sure NPC actually has items
            if (state.Inventory.IsEmpty == false)
            {
                //Setup power info
                int power, maxpower;
                PowerManager.GetPower(blockJobInstance.Position, out power);
                PowerManager.GetMaxPower(blockJobInstance.Position, out maxpower);

                //Make sure generator needs power so resources are not wasted
                if (power != maxpower)
                {
                    //Remove EnergyItem from inventory
                    state.Inventory.Remove(EnergyItem);
                    state.SetIndicator(new Shared.IndicatorState(CraftingCooldown, ItemTypes.IndexLookup.GetIndex("electricity"), false, false));

                    //Generate power!
                    PowerManager.GeneratePower(blockJobInstance.Position);
                    if (instance.IsCrafting == false)
                    {
                        instance.IsCrafting = true;
                        OnStartCrafting(instance);
                    }
                }
                else
                {
                    if (instance.IsCrafting == true)
                    {
                        OnStopCrafting(instance);
                    }
                    state.SetIndicator(new Shared.IndicatorState(0.3f, ItemTypes.IndexLookup.GetIndex("electricity"), false, true));
                }
            }
            else
            {
                //Go get the needed items
                blockJobInstance.ShouldTakeItems = true;
                state.SetCooldown(0.3);
                if (instance.IsCrafting == true)
                {
                    OnStopCrafting(instance);
                }
            }
        }