Exemple #1
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);
                }
            }
        }
        public override void OnNPCAtJob(BlockJobInstance blockJobInstance, ref NPC.NPCBase.NPCState state)
        {
            GeneratorJobWaterInstance instance = (GeneratorJobWaterInstance)blockJobInstance;

            //Colony owner = instance.Owner;
            state.JobIsDone = true;
            if (!CheckWater(instance))
            {
                state.SetCooldown(0.3);
                return;
            }

            if (instance.counter >= 10)
            {
                instance.counter         = 0;
                instance.ShouldTakeItems = true;
            }
            else
            {
                //Setup power info
                PowerManager.GetPower(blockJobInstance.Position, out int power);
                PowerManager.GetMaxPower(blockJobInstance.Position, out int maxpower);
                if (power != maxpower)
                {
                    state.SetIndicator(new Shared.IndicatorState(CraftingCooldown, ItemTypes.IndexLookup.GetIndex("electricity"), false, false));
                    PowerManager.GeneratePower(blockJobInstance.Position);
                    if (instance.IsCrafting == false)
                    {
                        instance.IsCrafting = true;
                        OnStartCrafting(blockJobInstance);
                    }
                    instance.counter++;
                }
                else
                {
                    state.SetCooldown(0.5);
                    if (instance.IsCrafting == true)
                    {
                        instance.IsCrafting = false;
                        OnStopCrafting(blockJobInstance);
                    }
                }
            }
        }