public static InputTask BlueprintFactory(InputMode mode, Func <Cell, Constructable> construct) { return(new InputTask(mode, (cells, selected) => { foreach (Cell cell in cells) { Blueprint blueprint = new Blueprint(cell.World, construct(cell)); if (blueprint != null && cell.World.ValidatePlacement(cell.X, cell.Y, blueprint)) { if (blueprint.Construct is Structure) { cell.StructureBlueprint = blueprint; } else if (blueprint.Construct is Floor) { cell.FloorBlueprint = blueprint; } ConstructionJob job = new ConstructionJob(cell, blueprint); cell.World.JobManager.AddJob(job); blueprint.job = job; } } }, (cell, spriteBatch) => { Blueprint preview = new Blueprint(cell.World, construct(cell)); bool validPlacement = cell.World.ValidatePlacement(cell.X, cell.Y, preview); preview.Draw(spriteBatch, cell.X, cell.Y, validPlacement ? Blueprint.BlueprintState.Preview : Blueprint.BlueprintState.Invalid); }, (cells) => { foreach (Cell cell in cells) { cell.CancelJobs(); } }, (cell) => { return cell.HasBlueprints; })); }
protected override void GetConstructionJob() //Looks for available const job and dequeus { base.GetConstructionJob(); if (Debugger._instance.constructionJobQueue.Count > 0) { owner.getSetHasJob = true; currConstJob = Debugger._instance.constructionJobQueue.Dequeue(); base.RequestPath(owner.transform.position, currConstJob.getSetMaterialForJob.getItemGameobject.transform.position); } //get path to material for job }
protected override void OnPathFinished() { base.OnPathFinished(); if (index == 0) //if at material { currConstJob.getSetMaterialForJob.PickUpPutDown(owner.transform); //pick up base.RequestPath(owner.transform.position, currConstJob.getJobsite); //get path to job site index++; } else if (index == 1) //if at job site { index = 0; Construct(currConstJob.getItemTocOnstruct); //construct thing currConstJob.getSetMaterialForJob.PickUpPutDown(null); //drop material UnityEngine.GameObject.Destroy(currConstJob.getSetMaterialForJob.getItemGameobject); //destroy material currConstJob = null; FinishJob(); //finish } }
private void RecieveInputTiles() { Debug.Log("Tiles selected to build on: " + currenTileList.Length); for (int i = 0; i < currenTileList.Length; i++) { if (Debugger._instance.construcatbleObjects.Length <= meterialIndex) { return; } else { //Debug.Log(currenTileList.Length); ConstructionJob newCJ = new ConstructionJob(currenTileList[i].gameObject.transform.position, MaterialType.Brick, new MaterialItem(Debugger._instance.construcatbleObjects[meterialIndex].gameObject, MaterialType.Brick), ConstrucatbleItem.Wall); Debugger._instance.constructionJobQueue.Enqueue(newCJ); } meterialIndex++; } currenTileList = null; }
public void DoJob(IIterationType iterationType, IAreaJob areaJob, ConstructionJob job, ref NPC.NPCBase.NPCState state) { if (iterationType == null || buildType == null || buildType.ItemIndex == 0) { AreaJobTracker.RemoveJob(areaJob); return; } int iMax = 4096; while (iMax-- > 0) { Vector3Int jobPosition = iterationType.CurrentPosition; ushort foundTypeIndex; if (World.TryGetTypeAt(jobPosition, out foundTypeIndex)) { if (foundTypeIndex == 0 || foundTypeIndex == BuiltinBlocks.Water) { Stockpile ownerStockPile = Stockpile.GetStockPile(areaJob.Owner); if (ownerStockPile.Contains(buildType.ItemIndex)) { if (ServerManager.TryChangeBlock(jobPosition, buildType.ItemIndex, areaJob.Owner, ServerManager.SetBlockFlags.DefaultAudio)) { if (--job.storedItems == 0) { state.JobIsDone = true; } ownerStockPile.TryRemove(buildType.ItemIndex); if (iterationType.MoveNext()) { state.SetIndicator(new Shared.IndicatorState(GetCooldown(), buildType.ItemIndex)); } else { // failed to find next position to do job at, self-destruct state.SetIndicator(new Shared.IndicatorState(5f, BuiltinBlocks.ErrorIdle)); AreaJobTracker.RemoveJob(areaJob); } return; } else { // shouldn't really happen, world not loaded (just checked) state.SetIndicator(new Shared.IndicatorState(5f, BuiltinBlocks.ErrorMissing, true, false)); } } else { // missing building item state.SetIndicator(new Shared.IndicatorState(Random.NextFloat(5f, 8f), buildType.ItemIndex, true, false)); } return; // either changed a block or set indicator, job done } else { // move iterator, not placing at non-air blocks if (iterationType.MoveNext()) { continue; // found non-air, try next loop } else { // failed to find next position to do job at, self-destruct state.SetIndicator(new Shared.IndicatorState(5f, BuiltinBlocks.ErrorIdle)); AreaJobTracker.RemoveJob(areaJob); return; } } // unreachable } else { state.SetIndicator(new Shared.IndicatorState(5f, BuiltinBlocks.ErrorMissing, true, false)); return; // end loop, wait for world to load } // unreachable } // reached loop count limit Assert.IsTrue(iMax <= 0); state.SetCooldown(1.0); }
public void DoJob(IIterationType iterationType, IAreaJob areaJob, ConstructionJob job, ref NPC.NPCBase.NPCState state) { if (iterationType == null) { AreaJobTracker.RemoveJob(areaJob); return; } int iMax = 4096; while (iMax-- > 0) { Vector3Int jobPosition = iterationType.CurrentPosition; if (!jobPosition.IsValid) { // failed to find next position to do job at, self-destruct state.SetIndicator(new Shared.IndicatorState(5f, BuiltinBlocks.ErrorIdle)); AreaJobTracker.RemoveJob(areaJob); return; } ushort foundTypeIndex; if (World.TryGetTypeAt(jobPosition, out foundTypeIndex)) { iterationType.MoveNext(); if (foundTypeIndex != 0) { ItemTypes.ItemType foundType = ItemTypes.GetType(foundTypeIndex); if (!foundType.IsDestructible) { continue; // skip this block, retry } if (ServerManager.TryChangeBlock(jobPosition, 0, areaJob.Owner, ServerManager.SetBlockFlags.DefaultAudio)) { float blockDestructionTime = GetCooldown(foundType.DestructionTime * 0.001f); GatherResults.Clear(); var itemList = foundType.OnRemoveItems; for (int i = 0; i < itemList.Count; i++) { GatherResults.Add(itemList[i]); } ModLoader.TriggerCallbacks(ModLoader.EModCallbackType.OnNPCGathered, job as NPC.IJob, jobPosition, GatherResults); InventoryItem toShow = ItemTypes.ItemTypeDrops.GetWeightedRandom(GatherResults); if (toShow.Amount > 0) { state.SetIndicator(new Shared.IndicatorState(blockDestructionTime, toShow.Type)); } else { state.SetCooldown(blockDestructionTime); } state.Inventory.Add(GatherResults); } else { state.SetIndicator(new Shared.IndicatorState(5f, BuiltinBlocks.ErrorMissing, true, false)); } return; // either changed a block or set indicator, job done } else { continue; // found air, try next loop } // unreachable } else { state.SetIndicator(new Shared.IndicatorState(5f, BuiltinBlocks.ErrorMissing, true, false)); return; // end loop, wait for world to load } // unreachable } // reached loop count limit Assert.IsTrue(iMax <= 0); state.SetCooldown(1.0); }