//called when the host is selected and valid tile is selected override public bool SelectValidTile(Tile t) { if (first == (SoulHost)t.Resident.GetComponent("SoulHost")) { first = null; return(true); } if (!first) { first = (SoulHost)t.Resident.GetComponent("SoulHost"); } else { Tile f = ((Unit)first.GetComponent("Unit")).CurrentTile; Tile s = t; Unit _first = f.Resident; Unit second = t.Resident; f.Resident = null; s.Resident = null; second.MoveToTile(f); second.ClickToTile(f); _first.MoveToTile(s); _first.ClickToTile(s); ((GameObject)Instantiate(Resources.Load("Prefabs/TurretBulletExplosion", typeof(GameObject)), s.transform.position, s.transform.rotation)).transform.parent = s.transform; ((GameObject)Instantiate(Resources.Load("Prefabs/TurretBulletExplosion", typeof(GameObject)), f.transform.position, f.transform.rotation)).transform.parent = f.transform; second.CurrentTile = f; _first.CurrentTile = s; f.Resident = second; s.Resident = _first; _first.Moved = false; second.Moved = false; s.audio.PlayOneShot(s.DigNoise); f.audio.PlayOneShot(f.DigNoise); second.Hover = false; Use(); } return(true); }
//called when the host is selected and valid tile is selected override public bool SelectValidTile(Tile t) { Soul s = (Soul)t.Resident.GetComponent("Soul"); Unit u = (Unit)t.Resident.GetComponent("Unit"); SoulHost sh = (SoulHost)t.Resident.GetComponent("SoulHost"); if (u.Player != GM.PlayerMan.CurrTurn) { sh.Stun(); //s.RemoveSouls(1); } else { s.AddSouls(1); } t.audio.PlayOneShot(t.DigNoise); Instantiate(Resources.Load("Prefabs/TurretBulletExplosion"), t.transform.position, t.transform.rotation); Use(); return(true); }
//Check the tutorial state and act accordingly void Update() { GM.FragMan.Building_Shrine.Gem = 1; SoulHost[] sh = (SoulHost[])Component.FindObjectsOfType(typeof(SoulHost)); Unit[] units = (Unit[])Component.FindObjectsOfType(typeof(Unit)); Soul[] souls = (Soul[])Component.FindObjectsOfType(typeof(Soul)); if (tState == States.EXPLAIN) { // start at showing all planes and explaining them GM.UnitMan.Deselect(); GM.PlaneMan.setDestPlane(0); GM.PlaneMan.viewAllPlanes = true; if (!firstUnit) { for (int i = 0; i < sh.Length; i++) { if (sh[i].getUnit().CurrentTile.transform.parent.tag == "LowPlane") { firstUnit = sh[i]; break; } } } // SELECT TUTORIAL // } else if (tState == States.SELECT) { //move on when a soul has been selected GM.PlaneMan.viewAllPlanes = false; GM.PlaneMan.setDestPlane(0); if (GM.UnitMan.getSelected() && GM.UnitMan.getSelected().Player == 0) { setState(States.MOVEMENT); } // MOVEMENT TUTORIAL // } else if (tState == States.MOVEMENT) { //continue when a soul has been moved GM.PlaneMan.setDestPlane(0); if (!GM.UnitMan.getSelected() || GM.UnitMan.getSelected().Player != 0) { setState(States.SELECT); } if (GM.UnitMan.getSelected() && GM.UnitMan.getSelected().isMoving()) { setState(States.ELEVATION); } //ELEVATION TUTORIAL // } else if (tState == States.ELEVATION) { //shows how elevation effects movement //creates a unit to be placed at the tile if (!ElevationTile.Resident) { GM.PlayerMan.CreateUnit(ElevationTile, GM.PlayerMan.instance_BasicSoul); } else { if (GM.UnitMan.getSelected() != ElevationTile.Resident) { GM.UnitMan.Select(ElevationTile.Resident); } ElevationTile.setHeight(0); for (int i = 0; i < ElevationTile._adjacentTiles.Length / 2; i++) { ElevationTile._adjacentTiles[i].setHeight(2); ElevationTile._adjacentTiles[i + 3].setHeight(-2); } //ElevationTile._adjacentTiles[0].setHeight(0); } } else if (tState == States.ELEVATION_LOW) { //shows how low tiles do not affect the movement of souls if (GM.UnitMan.getSelected() != ElevationTile.Resident) { GM.UnitMan.Select(ElevationTile.Resident); } ElevationTile.setHeight(0); for (int i = 0; i < ElevationTile._adjacentTiles.Length / 2; i++) { ElevationTile._adjacentTiles[i].setHeight(1); ElevationTile._adjacentTiles[i + 3].setHeight(-1); } //ElevationTile._adjacentTiles[0].setHeight(0); // DIGGING TUTORIAL // } else if (tState == States.DIGGING) { //continue once a tile has been dug into GM.PlaneMan.setDestPlane(0); if (GM.UnitMan.getSelected()) { firstUnit = GM.UnitMan.getSelected().GetComponent <SoulHost>(); } //if no item was found, create one if (firstUnit) { Tile t = firstUnit.GetComponent <Unit>().CurrentTile; if (t.getHeight() != t.ORIG_HEIGHT) { int fragCount = GM.FragMan.getFragCount(0) + GM.FragMan.CountGem(0); if (fragCount == 0) { Fragment f = FragmentManager.CreateFragment(t.PeekFragment()); GM.FragMan.Collect(f); t.CreateFragRemains(f); } setState(States.TURN_CHANGE); } } // TURN CHANGE TUTORIAL // } else if (tState == States.TURN_CHANGE) { //if the turn has been changed, move forward GM.PlaneMan.setDestPlane(0); if (GM.PlayerMan.CurrTurn != 0) { setState(States.SOUL_GENERATION); } // USE ITEMS TUTORIAL // } else if (tState == States.SOUL_GENERATION) { GM.PlaneMan.setDestPlane(0); } else if (tState == States.TILE_FLATTENING) { GM.PlaneMan.setDestPlane(0); } else if (tState == States.USE_ITEMS) { GM.PlaneMan.setDestPlane(0); //if an itme has been used, move forward if (GM.FragMan.getFragCount(0) < fragStartAmount) { setState(States.TILE_RICHNESS); } fragStartAmount = GM.FragMan.getFragCount(0); // COLLECT GEMS TUTORIAL // } else if (tState == States.TILE_RICHNESS) { GM.PlaneMan.setDestPlane(0); } else if (tState == States.COLLECT_GEMS) { GM.PlaneMan.setDestPlane(0); //if a soul can still be moved, do not reset their move and dig variables bool found = false; for (int i = 0; i < sh.Length; i++) { if (sh[i].getUnit() && sh[i].getUnit().Player == 0 && !sh[i].Dug) { found = true; break; } } //otherwise, if one cant be found, allow all souls to move and dig again if (!found) { for (int i = 0; i < sh.Length; i++) { sh[i].getUnit().Moved = false; sh[i].Dug = false; } } //once a gem has been found, move on if (GM.FragMan.CountGem(0) >= GM.FragMan.Building_Shrine.getGem()) { setState(States.RESOURCE_LIST); } // BUILD SHRINE TUTORIAL // } else if (tState == States.BUILD) { GM.PlaneMan.setDestPlane(0); //if a shrine has been built, move on if (Component.FindObjectsOfType(typeof(Shrine)).Length > 0) { MergeCount = souls.Length; setState(States.MERGING); } // MERGE TUTORIAL // } else if (tState == States.MERGING) { //once a soul has been merged, move on GM.PlaneMan.setDestPlane(0); int newCount = souls.Length; if (newCount < MergeCount) { setState(States.MERGE_FOUR); } MergeCount = newCount; // ASCEND TUTORIAL // } else if (tState == States.MERGE_FOUR) { //once a unit has been merged with four souls, move on GM.PlaneMan.setDestPlane(0); for (int i = 0; i < souls.Length; i++) { if (souls[i].Souls >= 4) { setState(States.MOVE_TO_GLOW); } } } else if (tState == States.MOVE_TO_GLOW) { //once a unit with four souls has been move to the ascend tiles around the shrine, continue on GM.PlaneMan.setDestPlane(0); for (int i = 0; i < sh.Length; i++) { if (sh[i].getSoul() && sh[i].getSoul().Souls >= 4) { if (sh[i].getUnit().CurrentTile.GetComponentInChildren(typeof(AscendLight))) { setState(States.ASCEND); } } sh[i].getUnit().Moved = false; sh[i].Dug = false; } } else if (tState == States.ASCEND) { GM.PlaneMan.setDestPlane(0); //once a soul has been ascended, move on for (int i = 0; i < units.Length; i++) { if (units[i].CurrentTile.transform.parent.tag == "MidPlane") { setState(States.POST_ASCEND); break; } } // GOAL TUTORIAL // } else if (tState == States.POST_ASCEND) { if (GM.FragMan.getSelected() && GM.FragMan.getSelected().GetType() == typeof(MakeBuilding) && ((MakeBuilding)GM.FragMan.getSelected()).GetBuilding().GetType() == typeof(Shrine)) { GM.FragMan.Deselect(); } GM.PlaneMan.setDestPlane(1); } else if (tState == States.EXPLAIN_STONE) { if (GM.FragMan.getSelected() && GM.FragMan.getSelected().GetType() == typeof(MakeBuilding) && ((MakeBuilding)GM.FragMan.getSelected()).GetBuilding().GetType() == typeof(Shrine)) { GM.FragMan.Deselect(); } GM.PlaneMan.setDestPlane(1); for (int i = 0; i < sh.Length; i++) { if (sh[i].Dug) { sh[i].getUnit().Moved = false; sh[i].Dug = false; } } if (GM.FragMan.CountStone(0) > 0) { setState(States.COLLECT_TREE); } } else if (tState == States.COLLECT_TREE) { if (GM.FragMan.getSelected() && GM.FragMan.getSelected().GetType() == typeof(MakeBuilding) && ((MakeBuilding)GM.FragMan.getSelected()).GetBuilding().GetType() == typeof(Shrine)) { GM.FragMan.Deselect(); } GM.PlaneMan.setDestPlane(1); //once some wood has been found, move on if (GM.FragMan.CountWood(0) != 0) { setState(States.EXPLAIN_TEMPLE); } //make sure all souls can move and dig always for (int i = 0; i < sh.Length; i++) { sh[i].getUnit().Moved = false; sh[i].Dug = false; } } else if (tState == States.EXPLAIN_TEMPLE) { //once a temple has been built, move on if (GM.FragMan.getSelected() && GM.FragMan.getSelected().GetType() == typeof(MakeBuilding) && ((MakeBuilding)GM.FragMan.getSelected()).GetBuilding().GetType() == typeof(Shrine)) { GM.FragMan.Deselect(); } if (Component.FindObjectOfType(typeof(Temple))) { setState(States.SCROLL); } GM.PlaneMan.setDestPlane(1); } else if (tState == States.SCROLL) { if (GM.PlaneMan.getDestPlane() == 2) { setState(States.WIN); } } else if (tState == States.WIN) { if (GM.PlayerMan.CheckWin() == 0) { setState(States.MAIN_MENU); } } }
//called when the unit is deselected - used to reset the host to before it is clicked on override public void Clear() { first = null; }
//draw the description and any needed buttons or arrows based on the required state void OnGUI() { //if the game is paused, do not draw the tutorial gui elements if (GM.Paused) { return; } //set the style for gui elements GUI.skin = GeneralManager.getStyle(); if (!arrowTex) { arrowTex = (Texture2D)Resources.Load("guiTex/arrow", typeof(Texture2D)); } GUI.depth = -1; GUIStyle gs = new GUIStyle(); gs.alignment = TextAnchor.UpperLeft; gs.normal.textColor = new Color(1, 1, 1, 1); gs.wordWrap = true; GUI.Box(new Rect(175, 10, 300, 200), ""); GUI.Label(new Rect(185, 10, 280, 200), Title); GUI.Label(new Rect(185, 10, 280, 200), "\n\n\t" + TutDesc, gs); if (tState == States.EXPLAIN) { //create the next button to move onto the next step if ( GUI.Button(new Rect(175, 215, 300, 50), "Next") ) { setState(States.SELECT); } } else if (tState == States.SELECT) { //point to the unit that should be selected if (firstUnit) { SoulHost u = (SoulHost)firstUnit.GetComponent("SoulHost"); Vector3 v = Camera.main.WorldToScreenPoint(u.transform.position); GUIUtility.RotateAroundPivot(180, new Vector2(v.x, Screen.height - v.y)); GUI.DrawTexture(new Rect(v.x - 95, Screen.height - v.y, 100, 100), arrowTex, ScaleMode.ScaleToFit); } } else if (tState == States.MOVEMENT) { } else if (tState == States.ELEVATION || tState == States.ELEVATION_LOW) { //point to the tile around with tiles have elevated drawArrow(ElevationTile.transform.position, new Vector2(100, 100), 90); } else if (tState == States.DIGGING) { //point to a unit in order to dig if (!GM.UnitMan.getSelected() && firstUnit) { SoulHost u = (SoulHost)firstUnit.GetComponent("SoulHost"); Vector3 v = Camera.main.WorldToScreenPoint(u.transform.position); GUIUtility.RotateAroundPivot(180, new Vector2(v.x, Screen.height - v.y)); GUI.DrawTexture(new Rect(v.x - 95, Screen.height - v.y, 100, 100), arrowTex, ScaleMode.ScaleToFit); } } else if (tState == States.TURN_CHANGE) { //point to the turn change arrow in the bottom right Vector2 v = new Vector2(Screen.width - 50, Screen.height - 125); GUIUtility.RotateAroundPivot(90, new Vector2(v.x, v.y)); GUI.DrawTexture(new Rect(v.x - 95, v.y, 150, 150), arrowTex, ScaleMode.ScaleToFit); } else if (tState == States.SOUL_GENERATION) { SoulWellTurnChange[] sw = (SoulWellTurnChange[])Component.FindObjectsOfType(typeof(SoulWellTurnChange)); //find the users soul well where units are generated for (int i = 0; i < sw.Length; i++) { Unit u = sw[i].GetComponent <Unit>(); if (u.Player == 0) { drawArrow(u.transform.position, new Vector2(100, 100), 90); Tile t = u.CurrentTile; int count = 0; //point to two souls that were generated around the soul well for (int j = 0; j < t._adjacentTiles.Length; j++) { if (t._adjacentTiles[j] && t._adjacentTiles[j].Resident) { drawArrow(t._adjacentTiles[j].Resident.transform.position + new Vector3(0, 3, 0), new Vector2(50, 50), 90); count++; if (count == 2) { break; } } } } } } else if (tState == States.USE_ITEMS) { //point the the items that the user has in the upper right Vector2 v = new Vector2(Screen.width - 100, 45); GUIUtility.RotateAroundPivot(0, new Vector2(v.x, v.y)); GUI.DrawTexture(new Rect(v.x - 95, v.y, 150, 150), arrowTex, ScaleMode.ScaleToFit); } else if (tState == States.TILE_RICHNESS) { //point to the most rich tiles in the world Tile[] tiles = (Tile[])Component.FindObjectsOfType(typeof(Tile)); for (int i = 0; i < tiles.Length; i++) { if (tiles[i].getRichness() == Tile.MAX_RICHNESS) { drawArrow(tiles[i].transform.position, new Vector2(50, 50), 90); } } } else if (tState == States.COLLECT_GEMS) { } else if (tState == States.RESOURCE_LIST) { //point to the list of resources in the upper right drawArrow(new Vector2(Screen.width - 105, Screen.height - 15), new Vector2(100, 100), 0); } else if (tState == States.BUILD) { //if the user needs to build, point to the build shrine button if (GM.FragMan.getSelected() && GM.FragMan.getSelected().GetType() != typeof(MakeBuilding) || !GM.FragMan.getSelected()) { Vector2 v = new Vector2(35, 80); GUIUtility.RotateAroundPivot(-75, new Vector2(v.x, v.y)); GUI.DrawTexture(new Rect(v.x - 95, v.y, 150, 150), arrowTex, ScaleMode.ScaleToFit); //if the user has already selected to build, point to the foundation tiels where shrines can be built } else if (GM.FragMan.getSelected() && GM.FragMan.getSelected().GetType() == typeof(MakeBuilding)) { for (int i = 0; i < FoundationTiles.Length; i++) { Tile t = FoundationTiles[i]; Vector3 v = Camera.main.WorldToScreenPoint(t.transform.position); GUIUtility.RotateAroundPivot(75, new Vector2(v.x, Screen.height - v.y)); GUI.DrawTexture(new Rect(v.x - 95, Screen.height - v.y, 100, 100), arrowTex, ScaleMode.ScaleToFit); GUIUtility.RotateAroundPivot(-75, new Vector2(v.x, Screen.height - v.y)); } } } else if (tState == States.MERGING || tState == States.MERGE_FOUR) { } else if (tState == States.MOVE_TO_GLOW) { Soul[] s = (Soul[])Component.FindObjectsOfType(typeof(Soul)); for (int i = 0; i < s.Length; i++) { // if there is a unit with four souls if (s[i].Souls >= 4) { Shrine sh = (Shrine)Component.FindObjectOfType(typeof(Shrine)); Unit u = (Unit)sh.GetComponent("Unit"); Tile t2 = u.CurrentTile; //point to highlighted tiles around the shrines in the scene for (int j = 0; j < t2._adjacentTiles.Length; j++) { Tile t = t2._adjacentTiles[j]; Vector3 v = Camera.main.WorldToScreenPoint(t.transform.position); v.y += 30; v.x -= 10; GUIUtility.RotateAroundPivot(75, new Vector2(v.x, Screen.height - v.y)); GUI.DrawTexture(new Rect(v.x, Screen.height - v.y, 30, 30), arrowTex, ScaleMode.ScaleToFit); GUIUtility.RotateAroundPivot(-75, new Vector2(v.x, Screen.height - v.y)); } return; } } } else if (tState == States.ASCEND) { //draw an arrow pointing to the turn change button in the bottom right drawArrow(new Vector2(Screen.width - 40, 65), new Vector2(100, 100), 90); } else if (tState == States.COLLECT_TREE) { //point to grown tress in the world to show what needs to be harvested TreeFragment[] t = (TreeFragment[])Component.FindObjectsOfType(typeof(TreeFragment)); for (int i = 0; i < t.Length; i++) { if (t[i].Growth >= TreeFragment.MAX_GROWTH) { drawArrow(t[i].transform.position + new Vector3(0, 10, 0), new Vector2(25, 25), 90); } } } else if (tState == States.EXPLAIN_TEMPLE) { // Point to the Build Temple button in the top left Vector2 v = new Vector2(35, 160); GUIUtility.RotateAroundPivot(-75, new Vector2(v.x, v.y)); GUI.DrawTexture(new Rect(v.x - 95, v.y, 150, 150), arrowTex, ScaleMode.ScaleToFit); } else if (tState == States.WIN) { // point to the soul vessel of the first player, idicating that he needs to merge to it SoulVessel[] sv = (SoulVessel[])Component.FindObjectsOfType(typeof(SoulVessel)); for (int i = 0; i < sv.Length; i++) { Unit u = (Unit)sv[i].GetComponent("Unit"); if (u.Player == 0) { drawArrow(u.transform.position + new Vector3(0, 12, 0), new Vector2(100, 100), 180); } } } else if (tState == States.MAIN_MENU) { //Draw buttons to go to advanced tutorial, or back to main menu if ( GUI.Button(new Rect(175, 215, 300, 50), "Main Menu") ) { Application.LoadLevel(0); } if ( GUI.Button(new Rect(175, 270, 300, 50), "Learn Advanced Tactics") ) { setState(States.ADVANCED_TACTIC); } } else if (tState == States.ADVANCED_TACTIC || tState == States.KILL_SOUL || tState == States.KILL_SHRINE ) { //point to the surrounding souls around the tile of interest Tile[] t = ElevationTile._adjacentTiles; bool selected = false; for (int i = 0; i < t.Length; i++) { if (t[i].Resident == GM.UnitMan.getSelected() && t[i].Resident != null) { selected = true; break; } } //if one of the units is already selected, do not point to it, and instead point to the center if (!selected) { for (int i = 0; i < t.Length; i++) { if (t[i].Resident) { drawArrow(t[i].transform.position + new Vector3(0, 3, 0), new Vector2(50, 50), 90); } } } else { drawArrow(ElevationTile.transform.position + new Vector3(0, 1, 0), new Vector2(100, 100), 90); } } else if (tState == States.END_ADVANCED) { if ( GUI.Button(new Rect(175, 215, 300, 50), "Main Menu") ) { Application.LoadLevel(0); } } //drawn if a next button is needed if (nextButton != -1) { if ( GUI.Button(new Rect(175, 215, 300, 50), "Next") ) { setState((States)nextButton); } } GUI.depth = 0; }