public virtual void DoJob(ConstructionJobInstance job, ref NPCBase.NPCState state)
 {
     if (ConstructionType != null)
     {
         ConstructionType.DoJob(IterationType, this, job, ref state);
     }
 }
Esempio n. 2
0
        public virtual void OnNPCAtJob(BlockJobInstance blockJobInstance, ref NPCState state)
        {
            ConstructionJobInstance instance = (ConstructionJobInstance)blockJobInstance;

            if (BlockTypes.ContainsByReference(instance.BlockType, out int index))
            {
                Vector3 rotate = instance.NPC.Position.Vector;
                switch (index)
                {
                case 1:
                    rotate.x -= 1f;
                    break;

                case 2:
                    rotate.x += 1f;
                    break;

                case 3:
                    rotate.z -= 1f;
                    break;

                case 4:
                    rotate.z += 1f;
                    break;
                }
                instance.NPC.LookAt(rotate);
            }
            if (instance.ConstructionArea != null && !instance.ConstructionArea.IsValid)
            {
                instance.ConstructionArea = null;
            }

            if (instance.ConstructionArea == null)
            {
                if (AreaJobTracker.ExistingAreaAt(instance.Position.Add(-1, -1, -1), instance.Position.Add(1, 1, 1), out List <IAreaJob> jobs))
                {
                    for (int i = 0; i < jobs.Count; i++)
                    {
                        if (jobs[i] is ConstructionArea neighbourArea)
                        {
                            instance.ConstructionArea = neighbourArea;
                            break;
                        }
                    }
                    AreaJobTracker.AreaJobListPool.Return(jobs);
                }

                if (instance.ConstructionArea == null)
                {
                    if (instance.DidAreaPresenceTest)
                    {
                        state.SetCooldown(0.5);
                        ServerManager.TryChangeBlock(instance.Position, instance.BlockType, BuiltinBlocks.Types.air, instance.Owner);
                    }
                    else
                    {
                        state.SetIndicator(new Shared.IndicatorState(Random.NextFloat(3f, 5f), BuiltinBlocks.Indices.erroridle));
                        instance.DidAreaPresenceTest = true;
                    }
                    return;
                }
            }

            Assert.IsNotNull(instance.ConstructionArea);
            instance.ConstructionArea.DoJob(instance, ref state);
        }