//Forms an open meld that matches the potential meld. Cannot be used for shouminkan. public void FormOpenMeld(PotentialMeld meld, int accessKey = 0) { if ((accessKey != _accessKey) && _accessKey != 0) { return; } TileID discardID = Kawa.MostRecentDiscard.Query(); List <Tile> with = new List <Tile>(); int start = 0; Meld.MeldType type = Meld.MeldType.Minkou; if (meld.Type == Meld.MeldType.Kantsu) { start = Tiles.IndexOf(discardID); with.Add(Tiles[start]); with.Add(Tiles[start + 1]); with.Add(Tiles[start + 2]); with.Add(Tiles[start + 3]); if (meld.Completed) { type = Meld.MeldType.Ankan; } else { type = Meld.MeldType.Daiminkan; } } else if (meld.Type == Meld.MeldType.Koutsu) { start = Tiles.IndexOf(discardID); with.Add(Tiles[start]); with.Add(Tiles[start + 1]); with.Add(Tiles[start + 2]); type = Meld.MeldType.Minkou; } else if (meld.Type == Meld.MeldType.Shuntsu) { //Use the self-sorting property of PotentialMeld to get the first ID PotentialMeld completed = new PotentialMeld(meld.IDs); completed.Add(discardID); with.Add(Tiles[Tiles.IndexOf(completed.IDs[0])]); with.Add(Tiles[Tiles.IndexOf(completed.IDs[1])]); with.Add(Tiles[Tiles.IndexOf(completed.IDs[2])]); type = Meld.MeldType.Minjun; } //All the tiles are found, now form the open meld Tiles.OpenTiles(with, _accessKey); OpenMeld open = new OpenMeld(type, with, PlayerNumber); OpenMelds.Add(open); EventManager.FlagEvent("Hand " + PlayerNumber + " Open Meld"); }
//Updates the meld list after an open meld private void CheckOpenMeld() { OpenMeld latest = hand.OpenMelds[hand.OpenMelds.Count - 1]; //Find all the melds that used any of its tiles and remove them. int i = 0; for (i = 0; i < latest.Count; i++) { RemoveUsedInMelds(latest.IDs[i]); } //Find the index where this meld went i = FindWouldBeLocationInClosed(latest.IDs[0]); //Check around this spot to add back any potential melds that are still valid CheckAround(i); }
//Arranges the most recently declared open meld and moves the draw area to accomodate private void UpdateLatestOpenMeldArrangement() { OpenMeld latest = hand.OpenMelds[hand.OpenMelds.Count - 1]; float position = GetTotalOpenMeldWidth() - (0.5f * latest.Width); GameObject container = new GameObject(); OpenMeld.ArrangeOpenMeldGroup(ref container, latest); switch (Orientation) { case TileOrientation.Bottom: container.transform.SetPositionAndRotation( (new Vector3(-position, 0f) + OpenMeldArea.transform.position), Quaternion.AngleAxis(0f, Vector3.forward)); DrawArea.transform.Translate(new Vector3(-latest.Width * Constants.DRAW_POSITION_ADJUST_MULT, 0f)); break; case TileOrientation.Right: container.transform.SetPositionAndRotation( (new Vector3(0f, -position) + OpenMeldArea.transform.position), Quaternion.AngleAxis(90f, Vector3.forward)); DrawArea.transform.Translate(new Vector3(-latest.Width * Constants.DRAW_POSITION_ADJUST_MULT, 0f)); break; case TileOrientation.Top: container.transform.SetPositionAndRotation( (new Vector3(position, 0f) + OpenMeldArea.transform.position), Quaternion.AngleAxis(180f, Vector3.forward)); DrawArea.transform.Translate(new Vector3(-latest.Width * Constants.DRAW_POSITION_ADJUST_MULT, 0f)); break; case TileOrientation.Left: container.transform.SetPositionAndRotation( (new Vector3(0f, position) + OpenMeldArea.transform.position), Quaternion.AngleAxis(270f, Vector3.forward)); DrawArea.transform.Translate(new Vector3(-latest.Width * Constants.DRAW_POSITION_ADJUST_MULT, 0f)); break; case TileOrientation.Player: //TODO: what to do about Player orientation? break; } }
//Arranges an open meld within the transform of the container public static void ArrangeOpenMeldGroup(ref GameObject container, OpenMeld meld) { Debug.Log("ArrangeOpenMeldGroup: arranging " + meld.ConvertToPotentialMeld()); meld.PlayerNumber = meld.PlayerNumber; int i = 0; List <TileRenderer> tr = new List <TileRenderer>(); for (i = 0; i < meld.Count; i++) { meld.Tiles[i].transform.parent = container.transform; tr.Add(meld.Tiles[i].Renderer); } TileRenderer low = null; TileRenderer mid = null; TileRenderer high = null; Tile a = null; Tile b = null; Tile c = null; TileRenderer stolen = null; switch (meld.Type) { case MeldType.Ankan: tr[0].Orientation = TileOrientation.Bottom; tr[1].Orientation = TileOrientation.Bottom; tr[2].Orientation = TileOrientation.Bottom; tr[3].Orientation = TileOrientation.Bottom; tr[0].LowerRight = new Vector2(0.5f * meld.Width, 0f); tr[1].LowerRight = tr[0].LowerLeft; tr[2].LowerRight = tr[1].LowerLeft; tr[3].LowerRight = tr[2].LowerLeft; meld.Tiles[1].GetComponent <Tile>().SetVisibility(TileVisibility.FaceDown); meld.Tiles[2].GetComponent <Tile>().SetVisibility(TileVisibility.FaceDown); break; case MeldType.Minjun: for (i = 0; i < 3; i++) { if (meld.Tiles[i].GetComponent <Tile>().StolenDiscard) { stolen = meld.Tiles[i].GetComponent <TileRenderer>(); } else if (a == null) { a = meld.Tiles[i]; } else { b = meld.Tiles[i]; } } if (a.GetComponent <Tile>().Query() < b.GetComponent <Tile>().Query()) { low = a.GetComponent <TileRenderer>(); high = b.GetComponent <TileRenderer>(); } else { low = b.GetComponent <TileRenderer>(); high = a.GetComponent <TileRenderer>(); } //Always stolen from left (kamicha) stolen.Orientation = TileOrientation.Right; low.Orientation = TileOrientation.Bottom; high.Orientation = TileOrientation.Bottom; high.LowerRight = new Vector2(0.5f * meld.Width, 0f); low.LowerRight = high.LowerLeft; stolen.LowerRight = low.LowerLeft; break; case MeldType.Minkou: for (i = 0; i < 3; i++) { if (meld.Tiles[i].GetComponent <Tile>().StolenDiscard) { stolen = meld.Tiles[i].GetComponent <TileRenderer>(); } else if (a == null) { a = meld.Tiles[i]; } else { b = meld.Tiles[i]; } } low = a.GetComponent <TileRenderer>(); high = b.GetComponent <TileRenderer>(); low.Orientation = TileOrientation.Bottom; high.Orientation = TileOrientation.Bottom; stolen.Orientation = TileOrientation.Right; if ((meld.StolenFrom - meld.PlayerNumber + 4) % 4 == 1) { //Stole from right (shimocha) stolen.LowerRight = new Vector2(0.5f * meld.Width, 0f); low.LowerRight = stolen.LowerLeft; high.LowerRight = low.LowerLeft; } else if ((meld.StolenFrom - meld.PlayerNumber + 4) % 4 == 2) { //stolen from across (toimen) low.LowerRight = new Vector2(0.5f * meld.Width, 0f); stolen.LowerRight = low.LowerLeft; high.LowerRight = stolen.LowerLeft; } else if ((meld.StolenFrom - meld.PlayerNumber + 4) % 4 == 3) { //stolen from left (kamicha) low.LowerRight = new Vector2(0.5f * meld.Width, 0f); high.LowerRight = low.LowerLeft; stolen.LowerRight = high.LowerLeft; } break; case MeldType.Daiminkan: for (i = 0; i < 4; i++) { if (meld.Tiles[i].GetComponent <Tile>().StolenDiscard) { stolen = meld.Tiles[i].GetComponent <TileRenderer>(); } else if (a == null) { a = meld.Tiles[i]; } else if (b == null) { b = meld.Tiles[i]; } else { c = meld.Tiles[i]; } } low = a.Renderer; high = b.Renderer; mid = c.Renderer; low.Orientation = TileOrientation.Bottom; high.Orientation = TileOrientation.Bottom; mid.Orientation = TileOrientation.Right; stolen.Orientation = TileOrientation.Right; if ((meld.StolenFrom - meld.PlayerNumber + 4) % 4 == 1) { //Stole from right (shimocha) stolen.Orientation = TileOrientation.Left; stolen.LowerRight = new Vector2(0.5f * meld.Width, 0f); low.LowerRight = stolen.LowerLeft; high.LowerRight = low.LowerLeft; mid.LowerRight = stolen.UpperRight; } else if ((meld.StolenFrom - meld.PlayerNumber + 4) % 4 == 2) { //stolen from across (toimen) low.LowerRight = new Vector2(0.5f * meld.Width, 0f); stolen.LowerRight = low.LowerLeft; high.LowerRight = stolen.LowerLeft; mid.LowerRight = stolen.UpperRight; } else if ((meld.StolenFrom - meld.PlayerNumber + 4) % 4 == 3) { //stolen from left (kamicha) low.LowerRight = new Vector2(0.5f * meld.Width, 0f); high.LowerRight = low.LowerLeft; stolen.LowerRight = high.LowerLeft; mid.LowerRight = stolen.UpperRight; } break; case MeldType.Shouminkan: for (i = 0; i < 4; i++) { if (meld.Tiles[i].GetComponent <Tile>().StolenDiscard) { stolen = meld.Tiles[i].Renderer; } else if (a == null) { a = meld.Tiles[i]; } else if (b == null) { b = meld.Tiles[i]; } else { c = meld.Tiles[i]; } } low = a.Renderer; high = b.Renderer; mid = c.Renderer; low.Orientation = TileOrientation.Bottom; mid.Orientation = TileOrientation.Bottom; high.Orientation = TileOrientation.Bottom; stolen.Orientation = TileOrientation.Right; if ((meld.StolenFrom - meld.PlayerNumber + 4) % 4 == 1) { //Stole from right (shimocha) stolen.Orientation = TileOrientation.Left; stolen.LowerRight = new Vector2(0.5f * meld.Width, 0f); low.LowerRight = stolen.LowerLeft; high.LowerRight = low.LowerLeft; mid.LowerRight = high.LowerLeft; } else if ((meld.StolenFrom - meld.PlayerNumber + 4) % 4 == 2) { //stolen from across (toimen) low.LowerRight = new Vector2(0.5f * meld.Width, 0f); stolen.LowerRight = low.LowerLeft; high.LowerRight = stolen.LowerLeft; mid.LowerRight = high.LowerLeft; } else if ((meld.StolenFrom - meld.PlayerNumber + 4) % 4 == 3) { //stolen from left (kamicha) low.LowerRight = new Vector2(0.5f * meld.Width, 0f); mid.LowerRight = low.LowerLeft; high.LowerRight = mid.LowerLeft; stolen.LowerRight = high.LowerLeft; } break; } }