示例#1
0
        public override void OnNPCAtJob(ref NPCBase.NPCState state)
        {
            if (constructionArea != null && !constructionArea.IsValid)
            {
                constructionArea = null;
            }

            if (worldTypeChecked)
            {
                Vector3 pos = usedNPC.Position.Vector;
                if (worldType == BuiltinBlocks.ConstructionJobXP)
                {
                    usedNPC.LookAt(pos + Vector3.right);
                }
                else if (worldType == BuiltinBlocks.ConstructionJobXN)
                {
                    usedNPC.LookAt(pos + Vector3.left);
                }
                else if (worldType == BuiltinBlocks.ConstructionJobZP)
                {
                    usedNPC.LookAt(pos + Vector3.forward);
                }
                else if (worldType == BuiltinBlocks.ConstructionJobZN)
                {
                    usedNPC.LookAt(pos + Vector3.back);
                }
            }

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

                if (constructionArea == null)
                {
                    if (isAreaPresenceTestDone)
                    {
                        state.SetCooldown(0.5);
                        ServerManager.TryChangeBlock(position, 0);
                    }
                    else
                    {
                        state.SetIndicator(new Shared.IndicatorState(Random.NextFloat(3f, 5f), BuiltinBlocks.ErrorIdle));
                        isAreaPresenceTestDone = true;
                    }
                    return;
                }
            }

            Assert.IsNotNull(constructionArea);
            constructionArea.DoJob(this, ref state);
        }