// player click delegate public void OnClickDelegate(OnClick onClickScript) { if (this.animatedSuccess) { this.DestroyDiggable(); this.SpawnDiggable(); } else { iTween.StopByName(Constants.SHAKE_PUNCH_POSITION); iTween.StopByName(Constants.SHAKE_PUNCH_ROTATION); iTween.StopByName(Constants.SHAKE_PUNCH_SCALE); Vector3 deltaPosition = new Vector3(shakeDeltaPosition, shakeDeltaPosition, shakeDeltaPosition); iTween.ShakePosition(diggable.gameObject, iTween.Hash( "name", Constants.SHAKE_PUNCH_POSITION, "amount", deltaPosition, "time", shakeTime )); Vector3 deltaRotation = new Vector3(shakeDeltaRotation, shakeDeltaRotation, shakeDeltaRotation); iTween.ShakeRotation(diggable.gameObject, iTween.Hash( "name", Constants.SHAKE_PUNCH_ROTATION, "amount", deltaRotation, "time", shakeTime )); Vector3 deltaScale = new Vector3(shakeDeltaScale, shakeDeltaScale, shakeDeltaScale); iTween.ShakeScale(diggable.gameObject, iTween.Hash( "name", Constants.SHAKE_PUNCH_SCALE, "amount", deltaScale, "time", shakeTime )); diggable.value = diggable.value - player.clickStrength; diggable.value = Mathf.Clamp(diggable.value, 0.0f, float.MaxValue); if (diggable.value > 0.0f) { int seed = Random.Range(0, this.shovelSounds.Length); var digSoundFX = this.shovelSounds[seed]; diggable.PlaySoundFX(digSoundFX); } else { diggable.PlaySoundFX(this.successSound); var collider = diggable.GetComponent <Collider>(); collider.enabled = false; StartCoroutine("AnimateSuccessfulDig"); } } }
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; } } }
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 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; }
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; } } }