private void OnDiggableReachabilityChanged(object data) { if (!IsReplacementTile) { int diggable_count = 0; int unreachable_count = 0; building.RunOnArea(delegate(int offset_cell) { Diggable diggable = Diggable.GetDiggable(offset_cell); if ((UnityEngine.Object)diggable != (UnityEngine.Object)null) { diggable_count++; if (!diggable.GetComponent <KPrefabID>().HasTag(GameTags.Reachable)) { unreachable_count++; } } }); bool flag = unreachable_count > 0 && unreachable_count == diggable_count; if (flag != hasUnreachableDigs) { if (flag) { GetComponent <KSelectable>().AddStatusItem(Db.Get().BuildingStatusItems.ConstructableDigUnreachable, null); } else { GetComponent <KSelectable>().RemoveStatusItem(Db.Get().BuildingStatusItems.ConstructableDigUnreachable, false); } hasUnreachableDigs = flag; } } }
public bool StartDigging() { StopDigging(); Diggable closest = null; float closestDist = Mathf.Infinity; foreach (var target in _inRange) { float newDist = Vector3.Distance(transform.position, target.transform.position); if (newDist < closestDist) { closest = target; closestDist = newDist; } } if (closest != null) { _target = closest; _target.StartDigging(this); return(true); } return(false); }
/// <summary> /// Finds the dig errand which caused the specified cell to fall. Returns null if this /// cell fell due to other reasons. /// /// If multiple dig errands caused this cell to fall, an arbitrary one is returned. /// </summary> /// <param name="cell">The cell which is falling.</param> /// <returns>The causing dig errand.</returns> public Diggable FindDigErrand(int cell) { var destroyed = ListPool <Diggable, FallFromDigging> .Allocate(); Diggable cause = null; foreach (var pair in fallingCells) { var key = pair.Key; if (key == null) { // Diggable was destroyed destroyed.Add(key); } else if (pair.Value.Contains(cell)) { cause = key; } } // Clean up destroyed dig errands, there should normally be none so this is very // low performance impact foreach (var key in destroyed) { fallingCells.Remove(key); } destroyed.Recycle(); return(cause); }
public void DestroyDiggable() { if (diggable != null) { Destroy(diggable.gameObject); } diggable = null; }
public void StopDigging() { if (_target != null) { _target.StopDigging(); } _target = null; }
public void Initialize(Diggable diggable) { this.diggable = diggable; zones = new DiggableZone[diggable.width * diggable.height]; DiggableZone originalZone = new DiggableZone(Vector2.zero, new Vector2(diggable.width, diggable.height), diggable); originalZone.Update(); }
public DiggableZone(Vector2 coordinates, Vector2 size, Diggable diggable) { this.rect = new Rect(coordinates.x, coordinates.y, size.x, size.y); this.diggable = diggable; diggable.zoneManager.SetZones(rect, this); smallestZone = size.x <= 1 && size.y <= 1; SetCollider(); }
public void OutOfRange(Diggable target) { _inRange.Remove(target); if (_target == target) { StopDigging(); } }
/// <summary> /// Applied after OnSolidChanged runs. /// </summary> internal static void Postfix(bool ___isDigComplete, Diggable __instance) { if (___isDigComplete) { #if DEBUG PUtil.LogDebug("Tile dug: " + Grid.PosToCell(__instance)); #endif Game.Instance?.Trigger(DigNTiles.DigComplete, __instance); } }
/// <summary> /// Stops tracking falling objects caused by a destroyed dig errand. /// </summary> /// <param name="instance">The dig errand which was just retired.</param> public void UntrackDiggable(Diggable instance) { if (fallingCells.Remove(instance)) { var xy = Grid.PosToXY(instance.transform.GetPosition()); #if DEBUG PUtil.LogDebug("Stopped tracking cell ({0:D},{1:D})".F(xy.X, xy.Y)); #endif } }
private void OnPriorityChanged(PrioritySetting priority) { building.RunOnArea(delegate(int cell) { Diggable diggable = Diggable.GetDiggable(cell); if ((UnityEngine.Object)diggable != (UnityEngine.Object)null) { diggable.GetComponent <Prioritizable>().SetMasterPriority(priority); } }); }
public override void UpdateHoverElements(List <KSelectable> selected) { int num = Grid.PosToCell(Camera.main.ScreenToWorldPoint(KInputManager.GetMousePos())); if (Grid.IsValidCell(num)) { HoverTextScreen instance = HoverTextScreen.Instance; HoverTextDrawer hoverTextDrawer = instance.BeginDrawing(); hoverTextDrawer.BeginShadowBar(false); if (Grid.IsVisible(num)) { DrawTitle(instance, hoverTextDrawer); DrawInstructions(HoverTextScreen.Instance, hoverTextDrawer); Element element = Grid.Element[num]; bool flag = false; if (Grid.Solid[num] && Diggable.IsDiggable(num)) { flag = true; } if (flag) { hoverTextDrawer.NewLine(26); hoverTextDrawer.DrawText(element.nameUpperCase, Styles_Title.Standard); hoverTextDrawer.NewLine(26); hoverTextDrawer.DrawIcon(instance.GetSprite("dash"), 18); hoverTextDrawer.DrawText(element.GetMaterialCategoryTag().ProperName(), Styles_BodyText.Standard); hoverTextDrawer.NewLine(26); hoverTextDrawer.DrawIcon(instance.GetSprite("dash"), 18); string[] array = WorldInspector.MassStringsReadOnly(num); hoverTextDrawer.DrawText(array[0], Styles_Values.Property.Standard); hoverTextDrawer.DrawText(array[1], Styles_Values.Property_Decimal.Standard); hoverTextDrawer.DrawText(array[2], Styles_Values.Property.Standard); hoverTextDrawer.DrawText(array[3], Styles_Values.Property.Standard); hoverTextDrawer.NewLine(26); hoverTextDrawer.DrawIcon(instance.GetSprite("dash"), 18); hoverTextDrawer.DrawText(GameUtil.GetHardnessString(Grid.Element[num], true), Styles_BodyText.Standard); } } else { hoverTextDrawer.DrawIcon(instance.GetSprite("iconWarning"), 18); hoverTextDrawer.DrawText(UI.TOOLS.GENERIC.UNKNOWN, Styles_BodyText.Standard); } hoverTextDrawer.EndShadowBar(); hoverTextDrawer.EndDrawing(); } }
// Use this for initialization void Start() { float x1 = transform.position.x; float y1 = transform.position.y; Collider2D[] hits = Physics2D.OverlapCircleAll(new Vector2(x1, y1), radius); foreach (Collider2D hit in hits) { Diggable dig = hit.GetComponent <Diggable>(); if (dig) { dig.ApplyHit(damage); } } Destroy(gameObject, lifetime); }
public GameObject CreatePrefab() { GameObject gameObject = CreatePrefab(ID, MISC.PLACERS.DIGPLACER.NAME, Assets.instance.digPlacerAssets.materials[0]); Diggable diggable = gameObject.AddOrGet <Diggable>(); diggable.workTime = 5f; diggable.synchronizeAnims = false; diggable.workAnims = new HashedString[2] { "place", "release" }; diggable.materials = Assets.instance.digPlacerAssets.materials; diggable.materialDisplay = gameObject.GetComponentInChildren <MeshRenderer>(true); gameObject.AddOrGet <CancellableDig>(); return(gameObject); }
public void SpawnDiggable() { this.animatedSuccess = false; this.DestroyDiggable(); GameObject diggableGO = ground.SpawnDiggable(); diggable = diggableGO.GetComponent <Diggable>(); UnityEngine.Assertions.Assert.IsNotNull(diggable); var onClick = diggable.GetComponent <OnClick>(); UnityEngine.Assertions.Assert.IsNotNull(onClick); onClick.theDelegate = OnClickDelegate; }
/// <summary> /// Applied to Diggable to cancel the chore if neutronium digging is not allowed. /// </summary> internal static bool PrefixSolidChanged(Diggable __instance) { GameObject go; bool cont = true; if (__instance != null && (go = __instance.gameObject) != null) { int cell = Grid.PosToCell(go); Element element; // Immediately cancel dig chores placed on 255 hardness items if (Grid.IsValidCell(cell) && (element = Grid.Element[cell]) != null && element.hardness > 254) { go.Trigger((int)GameHashes.Cancel, null); cont = false; } } return(cont); }
public void UpdateDig(float dt) { if (HasDigCell && rotation_complete) { Diggable.DoDigTick(dig_cell, dt); float percentComplete = Grid.Damage[dig_cell]; mining_sounds.SetPercentComplete(percentComplete); Vector3 a = Grid.CellToPosCCC(dig_cell, Grid.SceneLayer.FXFront2); a.z = 0f; Vector3 position = arm_go.transform.GetPosition(); position.z = 0f; float sqrMagnitude = (a - position).sqrMagnitude; arm_anim_ctrl.GetBatchInstanceData().SetClipRadius(position.x, position.y, sqrMagnitude, true); if (!ValidDigCell(dig_cell)) { dig_cell = Grid.InvalidCell; rotation_complete = false; } } }
/// <summary> /// Starts tracking falling objects caused by a processed dig errand. /// </summary> /// <param name="instance">The dig errand which just finished a cell.</param> public void TrackDiggable(Diggable instance) { int cell = Grid.PosToCell(instance); if (!Grid.Solid[cell] && !fallingCells.ContainsKey(instance)) { var temp = ListPool <int, FallFromDigging> .Allocate(); // If there are any falling cells, add to list GetFallingCells(cell, temp); if (temp.Count > 0) { #if DEBUG var xy = Grid.CellToXY(cell); PUtil.LogDebug("Tracking cell ({0:D},{1:D}): {2:D} fallables".F(xy.X, xy.Y, temp.Count)); #endif fallingCells.Add(instance, new HashSet <int>(temp)); } temp.Recycle(); } }
public override void OnMouseMove(Vector3 cursorPos) { base.OnMouseMove(cursorPos); if (!Dragging) { return; } var selectedCells = new List <int>(); Grid.PosToXY(downPos, out int x, out int y); Grid.PosToXY(cursorPos, out int x2, out int y2); if (x2 < x) { Util.Swap(ref x, ref x2); } if (y2 < y) { Util.Swap(ref y, ref y2); } for (int i = y; i <= y2; i++) { for (int j = x; j <= x2; j++) { int cell = Grid.XYToCell(j, i); if (Grid.IsValidCell(cell) && Grid.IsVisible(cell) && (Diggable.IsDiggable(cell) || Grid.IsLiquid(cell) || Grid.IsGas(cell)) /* && Grid.IsSolidCell(cell)*/) { selectedCells.Add(cell); } } } ElementInspector.UpdateElementData(selectedCells); }
/// <summary> /// Applied before InstantlyFinish runs. /// </summary> internal static bool Prefix(Diggable __instance, Worker worker, ref bool __result) { bool cont = true; if (__instance != null) { int cell = Grid.PosToCell(__instance); Element element; // Complete by removing the cell instantaneously if (Grid.IsValidCell(cell) && (element = Grid.Element[cell]) != null && element.hardness > 254) { if (worker != null) { // Give some experience worker.Work(1.0f); } SimMessages.Dig(cell); __result = true; cont = false; } } return(cont); }
protected override void OnCleanUp() { if (IsReplacementTile && building.Def.isKAnimTile) { int cell = Grid.PosToCell(base.transform.GetPosition()); GameObject gameObject = Grid.Objects[cell, (int)building.Def.ReplacementLayer]; if ((UnityEngine.Object)gameObject == (UnityEngine.Object)base.gameObject && (UnityEngine.Object)gameObject.GetComponent <SimCellOccupier>() != (UnityEngine.Object)null) { World.Instance.blockTileRenderer.RemoveBlock(building.Def, IsReplacementTile, SimHashes.Void, cell); } } GameScenePartitioner.Instance.Free(ref solidPartitionerEntry); GameScenePartitioner.Instance.Free(ref digPartitionerEntry); GameScenePartitioner.Instance.Free(ref ladderParititonerEntry); SaveLoadRoot component = GetComponent <SaveLoadRoot>(); if ((UnityEngine.Object)component != (UnityEngine.Object)null) { SaveLoader.Instance.saveManager.Unregister(component); } if (fetchList != null) { fetchList.Cancel("Constructable destroyed"); } UnmarkArea(); int[] placementCells = building.PlacementCells; foreach (int cell2 in placementCells) { Diggable diggable = Diggable.GetDiggable(cell2); if ((UnityEngine.Object)diggable != (UnityEngine.Object)null) { diggable.gameObject.DeleteObject(); } } base.OnCleanUp(); }
public void CreateHitEffect() { Worker worker = base.sm.worker.Get <Worker>(base.smi); Workable workable = base.sm.workable.Get <Workable>(base.smi); if (!((UnityEngine.Object)worker == (UnityEngine.Object)null) && !((UnityEngine.Object)workable == (UnityEngine.Object)null)) { if (Grid.PosToCell(workable) != Grid.PosToCell(worker)) { worker.Trigger(-673283254, null); } Diggable diggable = workable as Diggable; if ((bool)diggable) { Element targetElement = diggable.GetTargetElement(); worker.Trigger(-1762453998, targetElement); } if (!((UnityEngine.Object)hitEffectPrefab == (UnityEngine.Object)null)) { if ((UnityEngine.Object)hitEffect != (UnityEngine.Object)null) { DestroyHitEffect(); } AnimEventHandler component = worker.GetComponent <AnimEventHandler>(); Vector3 targetPoint = workable.GetTargetPoint(); component.SetTargetPos(targetPoint); hitEffect = GameUtil.KInstantiate(hitEffectPrefab, targetPoint, Grid.SceneLayer.FXFront2, null, 0); KBatchedAnimController component2 = hitEffect.GetComponent <KBatchedAnimController>(); hitEffect.SetActive(true); component2.sceneLayer = Grid.SceneLayer.FXFront2; component2.enabled = false; component2.enabled = true; component.UpdateWorkTarget(workable.GetTargetPoint()); } } }
internal static void Postfix(Diggable __instance) { FallingSandManager.Instance.UntrackDiggable(__instance); }
private void PlaceDiggables() { if (waitForFetchesBeforeDigging && fetchList != null && !hasLadderNearby) { OnDiggableReachabilityChanged(null); } else { bool digs_complete = true; if (!solidPartitionerEntry.IsValid()) { Extents validPlacementExtents = building.GetValidPlacementExtents(); solidPartitionerEntry = GameScenePartitioner.Instance.Add("Constructable.OnFetchListComplete", base.gameObject, validPlacementExtents, GameScenePartitioner.Instance.solidChangedLayer, OnSolidChangedOrDigDestroyed); digPartitionerEntry = GameScenePartitioner.Instance.Add("Constructable.OnFetchListComplete", base.gameObject, validPlacementExtents, GameScenePartitioner.Instance.digDestroyedLayer, OnSolidChangedOrDigDestroyed); } if (!IsReplacementTile) { building.RunOnArea(delegate(int offset_cell) { PrioritySetting masterPriority = GetComponent <Prioritizable>().GetMasterPriority(); if (Diggable.IsDiggable(offset_cell)) { digs_complete = false; Diggable diggable = Diggable.GetDiggable(offset_cell); if ((UnityEngine.Object)diggable == (UnityEngine.Object)null) { diggable = GameUtil.KInstantiate(Assets.GetPrefab(new Tag("DigPlacer")), Grid.SceneLayer.Move, null, 0).GetComponent <Diggable>(); diggable.gameObject.SetActive(true); diggable.transform.SetPosition(Grid.CellToPosCBC(offset_cell, Grid.SceneLayer.Move)); diggable.Subscribe(-1432940121, OnDiggableReachabilityChanged); Grid.Objects[offset_cell, 7] = diggable.gameObject; } else { diggable.Unsubscribe(-1432940121, OnDiggableReachabilityChanged); diggable.Subscribe(-1432940121, OnDiggableReachabilityChanged); } diggable.choreTypeIdHash = Db.Get().ChoreTypes.BuildDig.IdHash; diggable.GetComponent <Prioritizable>().SetMasterPriority(masterPriority); RenderUtil.EnableRenderer(diggable.transform, false); SaveLoadRoot component = diggable.GetComponent <SaveLoadRoot>(); if ((UnityEngine.Object)component != (UnityEngine.Object)null) { UnityEngine.Object.Destroy(component); } } }); OnDiggableReachabilityChanged(null); } bool flag = building.Def.IsValidBuildLocation(base.gameObject, base.transform.GetPosition(), building.Orientation); if (flag) { notifier.Remove(invalidLocation); } else { notifier.Add(invalidLocation, string.Empty); } GetComponent <KSelectable>().ToggleStatusItem(Db.Get().BuildingStatusItems.InvalidBuildingLocation, !flag, this); bool flag2 = digs_complete && flag && fetchList == null; if (flag2 && buildChore == null) { buildChore = new WorkChore <Constructable>(Db.Get().ChoreTypes.Build, this, null, true, UpdateBuildState, UpdateBuildState, UpdateBuildState, true, null, false, true, null, true, true, true, PriorityScreen.PriorityClass.basic, 5, false, true); UpdateBuildState(buildChore); } else if (!flag2 && buildChore != null) { buildChore.Cancel("Need to dig"); buildChore = null; } } }
void Update() { Debug.DrawRay(transform.position, lastDirection, Color.blue); bool digPressed = Input.GetButtonDown(digButtonName); if (digPressed) { float x1 = transform.position.x; float y1 = transform.position.y; RaycastHit2D[] hits = Physics2D.CircleCastAll(new Vector2(x1, y1), 0.3f, new Vector2(lastDirection.x, lastDirection.y), digDistance); foreach (RaycastHit2D hit in hits) { if (hit.collider) { Diggable dig = hit.collider.GetComponent <Diggable>(); if (dig) { dig.ApplyHit(digStrength); break; } } } } if (Input.GetButtonDown(power0ButtonName)) { if (activePowers[0] != null) { activePowers[0].OnButtonDown(); } } if (Input.GetButtonUp(power0ButtonName)) { if (activePowers[0] != null) { activePowers[0].OnButtonUp(); } } if (Input.GetButtonDown(power1ButtonName)) { if (activePowers[1] != null) { activePowers[1].OnButtonDown(); } } if (Input.GetButtonUp(power1ButtonName)) { if (activePowers[1] != null) { activePowers[1].OnButtonUp(); } } bool gemsUpdated = false; for (int matrix_row = 0; matrix_row < 4; ++matrix_row) { for (int matrix_col = 0; matrix_col < 4; ++matrix_col) { if (Input.GetButtonDown(matrixButtonNames[matrix_row][matrix_col])) { if (matrix_row == 3) { // Wild gems! if (gemCount[4] > matrix_col) { if (ActivatePower(PowerColor.Wild, matrix_col)) { gemCount[4]--; gemsUpdated = true; } } } else if (matrix_col == 0) { // Blue gems if (gemCount[0] > matrix_row) { if (ActivatePower(PowerColor.Blue, matrix_row)) { gemCount[0]--; gemsUpdated = true; } } } else if (matrix_col == 1) { // Red gems if (gemCount[1] > matrix_row) { if (ActivatePower(PowerColor.Red, matrix_row)) { gemCount[1]--; gemsUpdated = true; } } } else if (matrix_col == 2) { // Yellow gems if (gemCount[2] > matrix_row) { if (ActivatePower(PowerColor.Yellow, matrix_row)) { gemCount[2]--; gemsUpdated = true; } } } else if (matrix_col == 3) { // Green gems if (gemCount[3] > matrix_row) { if (ActivatePower(PowerColor.Green, matrix_row)) { gemCount[3]--; gemsUpdated = true; } } } } } } if (gemsUpdated) { UpdateGemLeds(); } UpdateButtonColors(); }
public void InRange(Diggable target) { _inRange.Add(target); }
private void DrawTextCard() { int cell = Grid.PosToCell(Camera.main.ScreenToWorldPoint(KInputManager.GetMousePos())); if (!Grid.IsValidCell(cell)) { return; } HoverTextScreen screen = HoverTextScreen.Instance; Sprite dash = screen.GetSprite("dash"); HoverTextDrawer txt = screen.BeginDrawing(); txt.BeginShadowBar(); if (!Grid.IsVisible(cell)) { txt.DrawIcon(screen.GetSprite("iconWarning")); txt.DrawText(UI.TOOLS.GENERIC.UNKNOWN, Styles_BodyText.Standard); } else { DrawTitle(screen, txt); DrawInstructions(screen, txt); var standard = Styles_BodyText.Standard; if (!InspectTool.Instance.Dragging) { var element = ElementInfo.FromCellNumber(cell); txt.NewLine(); txt.DrawText(element.NameUppercase, ToolTitleTextStyle); txt.NewLine(); txt.DrawIcon(dash); txt.DrawText(element.Category, standard); txt.NewLine(); txt.DrawIcon(dash); string[] array = WorldInspector.MassStringsReadOnly(cell); txt.DrawText(array[0], Styles_Values.Property.Standard); txt.DrawText(array[1], Styles_Values.Property_Decimal.Standard); txt.DrawText(array[2], Styles_Values.Property.Standard); txt.DrawText(array[3], Styles_Values.Property.Standard); txt.NewLine(); txt.DrawIcon(dash); txt.DrawText(GameUtil.GetFormattedTemperature(element.Temperature), standard); txt.NewLine(); txt.DrawIcon(dash); txt.DrawText(element.GetFormattedTotalRelativeHeat(InspectToolSettings.Instance.RelativeTemp), standard); if (Grid.Solid[cell] && Diggable.IsDiggable(cell)) { txt.NewLine(); txt.DrawIcon(dash); txt.DrawText(GameUtil.GetHardnessString(Grid.Element[cell]), standard); } } else { txt.NewLine(); txt.DrawText(((string)InspectToolStrings.HOVER_TEXT_TITLE).ToUpper(), ToolTitleTextStyle); var elements = ElementInspector.ElementData; if (elements != null && elements.Length > 0) { foreach (var e in elements) { txt.NewLine(); txt.DrawIcon(dash); txt.DrawText(e, standard); } } else { txt.NewLine(); txt.DrawText(InspectToolStrings.HOVER_TEXT_NO_ELEMENTS, standard); } } } txt.EndShadowBar(); txt.EndDrawing(); }