protected override void doWorkPart() { if (finished) { return; } if ((new Vector2(bee.transform.position.x - HexController.getInstance().tiles[buildTileIndexI][buildTileIndexJ].transform.position.x, bee.transform.position.z - HexController.getInstance().tiles[buildTileIndexI][buildTileIndexJ].transform.position.z)).magnitude > 0.300f) { this.doneProgress = 1.0f; if (this.doneProgress >= 1.0f) { this.doneProgress = 1.0f; this.finished = true; } return; } long elapsedMilliseconds = stopwatch.ElapsedMilliseconds; if (lastTimeStamp == -1) { lastTimeStamp = elapsedMilliseconds; } this.doneProgress += 0.00035f * (elapsedMilliseconds - lastTimeStamp); lastTimeStamp = elapsedMilliseconds; if (this.doneProgress >= 1.0f) { this.doneProgress = 1.0f; this.finished = true; Hive hive = HexController.getInstance().tiles[buildTileIndexI][buildTileIndexJ].GetComponent <HiveBuildTileController>().hive; hive.maxHoney += 1000; GameObject newHiveTile = GameObject.Instantiate(GameController.getInstance().hiveTilePrefab, HexController.getInstance().tiles[buildTileIndexI][buildTileIndexJ].transform.position, Quaternion.identity) as GameObject; newHiveTile.GetComponent <HiveTileController>().init(buildTileIndexI, buildTileIndexJ, hive); HexController.getInstance().tiles[buildTileIndexI][buildTileIndexJ].GetComponent <HiveBuildTileController>().progress = this.doneProgress; GameObject.Destroy(HexController.getInstance().tiles[buildTileIndexI][buildTileIndexJ].gameObject); HexController.getInstance().tiles[buildTileIndexI][buildTileIndexJ] = newHiveTile.GetComponent <HiveTileController>(); } try { HexController.getInstance().tiles[buildTileIndexI][buildTileIndexJ].GetComponent <HiveBuildTileController>().progress = this.doneProgress; }catch (Exception e) { } }
protected override void doWorkPart() { if (finished) { return; } if ((new Vector2(bee.transform.position.x - HexController.getInstance().tiles[buildTileIndexI][buildTileIndexJ].transform.position.x, bee.transform.position.z - HexController.getInstance().tiles[buildTileIndexI][buildTileIndexJ].transform.position.z)).magnitude > 5.000f) { this.doneProgress = 1.0f; if (this.doneProgress >= 1.0f) { this.doneProgress = 1.0f; this.finished = true; } return; } long elapsedMilliseconds = stopwatch.ElapsedMilliseconds; if (lastTimeStamp == -1) { lastTimeStamp = elapsedMilliseconds; } Hive hive = HexController.getInstance().tiles[buildTileIndexI][buildTileIndexJ].GetComponent <HiveTileController>().hive; int honeyTransfer = Mathf.RoundToInt(0.3f * (elapsedMilliseconds - lastTimeStamp)); lastTimeStamp = elapsedMilliseconds; hive.honey += honeyTransfer; bee.honey -= honeyTransfer; if (bee.honey < 0) { int diff = -bee.honey; bee.honey += diff; hive.honey -= diff; } if (hive.honey > hive.maxHoney) { int diff = hive.honey - hive.maxHoney; bee.honey += diff; hive.honey -= diff; } if (hive.honey == hive.maxHoney || bee.honey == 0) { this.doneProgress = 1.0f; this.finished = true; } }
public override void start() { try { this.doneProgress = HexController.getInstance().tiles[buildTileIndexI][buildTileIndexJ].GetComponent <HiveBuildTileController>().progress; } catch (Exception e) { bee.workQueue.Remove(this); GameController.getInstance().workQueueChangedFlag = true; if (started) { stop(); } return; } workerThread = new Thread(new ThreadStart(doWork)); workerThread.Name = "BuildWorkUnit Thread"; workerThread.Start(); started = true; }
protected override void doWorkPart() { if (firstFlower == null) { for (int i = -HexController.getInstance().numberOfVerticalTiles + 1; i < HexController.getInstance().numberOfVerticalTiles; i++) { if (firstFlower != null) { break; } for (int j = -HexController.getInstance().numberOfHorizontalTiles + 1; j < HexController.getInstance().numberOfHorizontalTiles; j++) { if (firstFlower != null) { break; } int indexI = i + HexController.getInstance().numberOfVerticalTiles - 1; int indexJ = j + HexController.getInstance().numberOfHorizontalTiles - 1; TileController tile = HexController.getInstance().tiles[indexI][indexJ]; if (tile is FlowerTileController && tile.getState() == TileController.TileState.Visible && ((FlowerTileController)tile).honey > 0) { firstFlower = (FlowerTileController)tile; } if (firstFlower != null) { break; } } if (firstFlower != null) { break; } } } if (firstFlower == null) { this.doneProgress = 1.0f; if (this.doneProgress >= 1.0f) { this.doneProgress = 1.0f; this.finished = true; } return; } endPosition = new Vector3(firstFlower.transform.position.x, endHeight, firstFlower.transform.position.z); if (!addedCollectWorkUnit) { this.bee.workQueue.Add(new CollectHoneyWorkUnit(this.bee, firstFlower.indexI, firstFlower.indexJ, false)); this.bee.workQueueChanged = true; addedCollectWorkUnit = true; } if (endPosition == startPosition) { this.doneProgress = 1.0f; if (this.doneProgress >= 1.0f) { this.doneProgress = 1.0f; this.finished = true; } return; } long elapsedMilliseconds = stopwatch.ElapsedMilliseconds; if (lastTimeStamp == -1) { lastTimeStamp = elapsedMilliseconds; } float speedMultiplier = (endPosition - startPosition).magnitude; this.doneProgress += 0.0035f * (elapsedMilliseconds - lastTimeStamp) / speedMultiplier; lastTimeStamp = elapsedMilliseconds; if (this.doneProgress >= 1.0f) { this.doneProgress = 1.0f; this.finished = true; } Vector3 newPosition = Vector3.Lerp(startPosition, endPosition, (float)doneProgress); try { bee.transform.position = newPosition; bee.transform.LookAt(new Vector3(endPosition.x, bee.transform.position.y, endPosition.z)); if (GameController.getInstance().state == GameController.GameState.BEE_SELECTED) { GameController.getInstance().visibilitiesChanged = true; } } catch (Exception e) { } }