IEnumerator LadybirdsMixRoutine(Chip secondary) { chip.busy = true; chip.destroyable = false; yield return(0); List <Chip> ladies = new List <Chip>(); int count = 3; if (secondary.chipType == "Ladybird") { count = 5; } if (chip.slot.jam) { chip.jamType = chip.slot.jam.type; } for (int i = 0; i <= count; i++) { Chip l = ContentAssistant.main.GetItem <Chip>("Ladybird" + Chip.chipTypes[Random.value > 0.5f ? chip.id : secondary.id]); l.destroyable = false; l.transform.position = chip.slot.transform.position; l.transform.localScale = Vector3.one; l.transform.SetParent(Slot.folder); l.transform.Find("LadybirdBody").rotation = Quaternion.Euler(0, 0, Random.Range(0f, 360f)); l.jamType = chip.jamType; if (secondary.chipType != "Ladybird") { l.GetComponent <Ladybird>().seed = secondary.chipType; } ladies.Add(l); } chip.Minimize(); SessionAssistant.main.EventCounter(); foreach (Chip l in ladies) { if (l == null) { continue; } Animation a = l.GetComponent <Animation>(); while (a.isPlaying) { yield return(0); } l.destroyable = true; l.jamType = chip.jamType; l.DestroyChip(); } chip.busy = false; chip.HideChip(false); }
// Crush block function public void BlockCrush(int2 coord, bool radius, bool force = false) { IBlock block = null; Slot slot = null; Chip chip = null; StoneChip stone = null; if (radius) { foreach (Side side in Utils.straightSides) { block = null; slot = null; chip = null; stone = null; slot = Slot.GetSlot(coord + side); if (!slot) { continue; } block = slot.block; if (block && block.CanBeCrushedByNearSlot()) { block.BlockCrush(force); } if (slot) { chip = slot.chip; } if (chip) { stone = chip.GetComponent <StoneChip>(); } if (stone) { chip.DestroyChip(); } } } slot = Slot.GetSlot(coord); if (slot) { block = slot.block; } if (block) { block.BlockCrush(force); } }
public void Crush(int2 coord) { Slot s = Slot.GetSlot(coord); FieldAssistant.main.BlockCrush(coord, false, true); if (s && s.chip) { Chip c = s.chip; c.SetScore(0.3f); c.DestroyChip(); } }
public static bool Crush(int2 coord) { Slot s = Slot.GetSlot(coord); FieldAssistant.main.BlockCrush(coord, false, true); if (s && s.chip) { Chip c = s.chip; c.SetScore(0.3f); c.DestroyChip(); AnimationAssistant.main.Explode(s.transform.position, 3, 20); } return(coord.IsItHit(0, 0, LevelProfile.main.width - 1, LevelProfile.main.height - 1)); }
public void Crush(int2 coord) { Slot s = Slot.GetSlot(coord); FieldAssistant.main.BlockCrush(coord, false, true); FieldAssistant.main.JellyCrush(coord); if (s) { Jam.JamIt(s, chip.jamType); } if (s && s.chip) { Chip c = s.chip; c.SetScore(0.3f); c.jamType = chip.jamType; c.DestroyChip(); } }
void Update() { if (chip.destroing) { return; } if (chip.move) { return; } if (!chip.parentSlot) { return; } if (chip.parentSlot.slot.sugarDropSlot) { chip.destroyable = true; SessionAssistant.main.targetSugarDropsCount--; chip.DestroyChip(); } }
// программа активации бомб IEnumerator CollapseAllPowerups() { yield return(StartCoroutine(Utils.WaitFor(CanIWait, 0.5f))); List <Chip> powerUp = FindPowerups(); while (powerUp.Count > 0) { powerUp = powerUp.FindAll(x => !x.destroying); if (powerUp.Count > 0) { EventCounter(); Chip pu = powerUp[Random.Range(0, powerUp.Count)]; pu.DestroyChip(); } yield return(StartCoroutine(Utils.WaitFor(CanIWait, 0.5f))); powerUp = FindPowerups(); } yield return(StartCoroutine(Utils.WaitFor(CanIWait, 0.5f))); }
// Implementation of solution. Destruction of the existing combination, addition score points and creation bombs. void MatchSolution(Solution solution) { EventCounter(); int sx = solution.x; int sy = solution.y; int x; int y; Chip chip = ((GameObject)GameObject.Find("Slot_" + sx + "x" + sy)).GetComponent <SlotForChip>().GetChip(); int width = FieldAssistant.main.field.width; int height = FieldAssistant.main.field.height; Slot s; GameObject j; GameObject o; Chip c; int puX = -1; int puY = -1; int puID = -1; if (!chip.IsMatcheble()) { return; } // T // T // LLXRR // B // B // Destruction of right chips (R) if (solution.h) { for (x = sx + 1; x < width; x++) { o = GameObject.Find("Slot_" + x + "x" + sy); if (!o) { break; } s = o.GetComponent <Slot>(); if (!s) { continue; } if (!s.GetChip()) { break; } c = s.GetChip(); if (c.id == chip.id) { if (!c.IsMatcheble()) { break; } if (c.movementID > puID) { puID = c.movementID; puX = x; puY = sy; } s.GetChip().SetScore(Mathf.Pow(2, solution.count - 3) / solution.count); if (!s.GetBlock()) { FieldAssistant.main.BlockCrush(x, sy, true); } s.GetChip().DestroyChip(); j = GameObject.Find("Jelly_" + x + "x" + sy); if (j) { j.SendMessage("JellyCrush", SendMessageOptions.DontRequireReceiver); } } else { break; } } } // Destruction of left chips (L) if (solution.h) { for (x = sx - 1; x >= 0; x--) { o = GameObject.Find("Slot_" + x + "x" + sy); if (!o) { break; } s = o.GetComponent <Slot>(); if (!s) { continue; } if (!s.GetChip()) { break; } c = s.GetChip(); if (c.id == chip.id) { if (!c.IsMatcheble()) { break; } if (c.movementID > puID) { puID = c.movementID; puX = x; puY = sy; } s.GetChip().SetScore(Mathf.Pow(2, solution.count - 3) / solution.count); if (!s.GetBlock()) { FieldAssistant.main.BlockCrush(x, sy, true); } s.GetChip().DestroyChip(); j = GameObject.Find("Jelly_" + x + "x" + sy); if (j) { j.SendMessage("JellyCrush", SendMessageOptions.DontRequireReceiver); } } else { break; } } } // Destruction of top chips (T) if (solution.v) { for (y = sy + 1; y < height; y++) { o = GameObject.Find("Slot_" + sx + "x" + y); if (!o) { break; } s = o.GetComponent <Slot>(); if (!s) { continue; } if (!s.GetChip()) { break; } c = s.GetChip(); if (c.id == chip.id) { if (!c.IsMatcheble()) { break; } if (c.movementID > puID) { puID = c.movementID; puX = sx; puY = y; } s.GetChip().SetScore(Mathf.Pow(2, solution.count - 3) / solution.count); if (!s.GetBlock()) { FieldAssistant.main.BlockCrush(sx, y, true); } s.GetChip().DestroyChip(); j = GameObject.Find("Jelly_" + sx + "x" + y); if (j) { j.SendMessage("JellyCrush", SendMessageOptions.DontRequireReceiver); } } else { break; } } } // Destruction of bottom chips (B) if (solution.v) { for (y = sy - 1; y >= 0; y--) { o = GameObject.Find("Slot_" + sx + "x" + y); if (!o) { break; } s = o.GetComponent <Slot>(); if (!s) { continue; } if (!s.GetChip()) { break; } c = s.GetChip(); if (c.id == chip.id) { if (!c.IsMatcheble()) { break; } if (c.movementID > puID) { puID = c.movementID; puX = sx; puY = y; } s.GetChip().SetScore(Mathf.Pow(2, solution.count - 3) / solution.count); if (!s.GetBlock()) { FieldAssistant.main.BlockCrush(sx, y, true); } s.GetChip().DestroyChip(); j = GameObject.Find("Jelly_" + sx + "x" + y); if (j) { j.SendMessage("JellyCrush", SendMessageOptions.DontRequireReceiver); } } else { break; } } } if (chip.movementID > puID) { puID = chip.movementID; puX = sx; puY = sy; } // Destruction of central chip (X) chip.SetScore(Mathf.Pow(2, solution.count - 3) / solution.count); if (!chip.parentSlot.slot.GetBlock()) { FieldAssistant.main.BlockCrush(sx, sy, true); } chip.DestroyChip(); j = GameObject.Find("Jelly_" + solution.x + "x" + solution.y); if (j) { j.SendMessage("JellyCrush", SendMessageOptions.DontRequireReceiver); } // Check for I5 model to create a color bomb // // I5 model // // X // X // X XXXXX // X // X // if (solution.count >= 5) { if ((solution.v && !solution.h) || (!solution.v && solution.h)) { FieldAssistant.main.GetNewColorBomb(puX, puY, FieldAssistant.main.GetSlot(puX, puY).transform.position, solution.id); return; } } // Check for I4 model to create a simple bomb // // I4 model // // X // X // X XXXX // X // if (solution.count >= 4) { if ((solution.v && !solution.h) || (!solution.v && solution.h)) { FieldAssistant.main.GetNewBomb(puX, puY, FieldAssistant.main.GetSlot(puX, puY).transform.position, solution.id); return; } } // Check for T4 model to create a cross bomb // // T4 model // // XXX X X X // X XXX X XXX // X X XXX X // if (solution.count >= 4) { if (solution.v && solution.h) { FieldAssistant.main.GetNewCrossBomb(puX, puY, FieldAssistant.main.GetSlot(puX, puY).transform.position, solution.id); return; } } // I3 model has the lowest priority. It does not create any bombs // // I3 model // // X // X XXX // X // }
IEnumerator LightningBranch(string powerup = "") { yield return(new WaitForSeconds(0.1f)); Slot currentSlot = chip.slot; Chip nextChip; Slot nextSlot; Lightning lightning = null; int iter = 10; int count = 10; List <Chip> branch = new List <Chip>(); while (true) { if (iter <= 0 || count <= 0) { break; } nextSlot = currentSlot.nearSlot.Values.Where(x => x != null).ToList().GetRandom(); if (!nextSlot) { iter--; continue; } nextChip = nextSlot.chip; if (!nextChip || nextChip.destroying) { iter--; continue; } if (!currentSlot.chip) { iter--; continue; } if (chips.Contains(nextChip) || branch.Contains(nextChip)) { iter--; continue; } chips.Add(nextChip); branch.Add(nextChip); int id = nextChip.id; if (lightning != null) { lightning.Remove(); } lightning = Lightning.CreateLightning(0, currentSlot.chip.transform, nextChip.transform, id == Mathf.Clamp(id, 0, 5) ? Chip.colors[id] : Color.white); count--; currentSlot.chip.SetScore(0.3f); currentSlot.chip.jamType = chip.jamType; currentSlot.chip.DestroyChip(); currentSlot = nextSlot; yield return(new WaitForSeconds(0.02f)); } if (powerup != "") { bool dontDestroy = powerup == "RainbowHeart" || powerup == "UltraColorBomb"; Chip pu = FieldAssistant.main.AddPowerup(currentSlot.coord, powerup); //if (!dontDestroy) // pu.can_move = false; pu.transform.localPosition = Vector3.zero; yield return(0); while (!dontDestroy && pu != null && pu.GetComponent <Animation>().isPlaying) { yield return(0); } if (pu != null && !dontDestroy) { SessionAssistant.main.EventCounter(); pu.jamType = chip.jamType; pu.DestroyChip(); } } if (lightning != null) { lightning.Remove(); if (currentSlot.chip) { currentSlot.chip.jamType = chip.jamType; currentSlot.chip.DestroyChip(); } } branchCount--; while (branchCount > 0) { yield return(0); } yield return(0); branchCount = -1; //yield return new WaitForSeconds(0.02f); //for (int i = 0; i < branch.Count; i++) { // yield return new WaitForSeconds(0.03f); // if (branch[i].destroing || !branch[i].parentSlot) // continue; // branch[i].SetScore(0.1f); // FieldAssistant.main.BlockCrush(branch[i].parentSlot.slot.x, branch[i].parentSlot.slot.y, true); // FieldAssistant.main.JellyCrush(branch[i].parentSlot.slot.x, branch[i].parentSlot.slot.y); // if (branch[i] != chip) // branch[i].DestroyChip(); //} //branchCount--; //while (branchCount > 0) // yield return 0; //branchCount = -1; }
public void CrushChip() { chip.DestroyChip(); chip = null; }
void MatchSolution(Solution solution) { // solution = FieldAssistant.main.GetSlot(solution.x, solution.y).GetComponent<SlotForChip>().MatchAnaliz(); // if (!solution) return; MatchingCounter(); int sx = solution.x; int sy = solution.y; int x; int y; Chip chip = ((GameObject)GameObject.Find("Slot_" + sx + "x" + sy)).GetComponent <SlotForChip>().GetChip(); int width = FieldAssistant.main.field.width; int height = FieldAssistant.main.field.height; Slot s; GameObject j; GameObject o; Chip c; int puX = -1; int puY = -1; int puID = -1; if (!chip.IsMatcheble()) { return; } if (solution.h) { for (x = sx + 1; x < width; x++) { o = GameObject.Find("Slot_" + x + "x" + sy); if (!o) { break; } s = o.GetComponent <Slot>(); if (!s) { continue; } if (!s.GetChip()) { break; } c = s.GetChip(); if (c.id == chip.id) { if (!c.IsMatcheble()) { break; } if (c.movementID > puID) { puID = c.movementID; puX = x; puY = sy; } s.GetChip().SetScore(Mathf.Pow(2, solution.count - 3) / solution.count); FieldAssistant.main.BlockCrush(x, sy, true); s.GetChip().DestroyChip(); j = GameObject.Find("Jelly_" + x + "x" + sy); if (j) { j.SendMessage("JellyCrush", SendMessageOptions.DontRequireReceiver); } } else { break; } } } if (solution.h) { for (x = sx - 1; x >= 0; x--) { o = GameObject.Find("Slot_" + x + "x" + sy); if (!o) { break; } s = o.GetComponent <Slot>(); if (!s) { continue; } if (!s.GetChip()) { break; } c = s.GetChip(); if (c.id == chip.id) { if (!c.IsMatcheble()) { break; } if (c.movementID > puID) { puID = c.movementID; puX = x; puY = sy; } s.GetChip().SetScore(Mathf.Pow(2, solution.count - 3) / solution.count); FieldAssistant.main.BlockCrush(x, sy, true); s.GetChip().DestroyChip(); j = GameObject.Find("Jelly_" + x + "x" + sy); if (j) { j.SendMessage("JellyCrush", SendMessageOptions.DontRequireReceiver); } } else { break; } } } if (solution.v) { for (y = sy + 1; y < height; y++) { o = GameObject.Find("Slot_" + sx + "x" + y); if (!o) { break; } s = o.GetComponent <Slot>(); if (!s) { continue; } if (!s.GetChip()) { break; } c = s.GetChip(); if (c.id == chip.id) { if (!c.IsMatcheble()) { break; } if (c.movementID > puID) { puID = c.movementID; puX = sx; puY = y; } s.GetChip().SetScore(Mathf.Pow(2, solution.count - 3) / solution.count); FieldAssistant.main.BlockCrush(sx, y, true); s.GetChip().DestroyChip(); j = GameObject.Find("Jelly_" + sx + "x" + y); if (j) { j.SendMessage("JellyCrush", SendMessageOptions.DontRequireReceiver); } } else { break; } } } if (solution.v) { for (y = sy - 1; y >= 0; y--) { o = GameObject.Find("Slot_" + sx + "x" + y); if (!o) { break; } s = o.GetComponent <Slot>(); if (!s) { continue; } if (!s.GetChip()) { break; } c = s.GetChip(); if (c.id == chip.id) { if (!c.IsMatcheble()) { break; } if (c.movementID > puID) { puID = c.movementID; puX = sx; puY = y; } s.GetChip().SetScore(Mathf.Pow(2, solution.count - 3) / solution.count); FieldAssistant.main.BlockCrush(sx, y, true); s.GetChip().DestroyChip(); j = GameObject.Find("Jelly_" + sx + "x" + y); if (j) { j.SendMessage("JellyCrush", SendMessageOptions.DontRequireReceiver); } } else { break; } } } if (chip.movementID > puID) { puID = chip.movementID; puX = sx; puY = sy; } chip.SetScore(Mathf.Pow(2, solution.count - 3) / solution.count); FieldAssistant.main.BlockCrush(sx, sy, true); chip.DestroyChip(); j = GameObject.Find("Jelly_" + solution.x + "x" + solution.y); if (j) { j.SendMessage("JellyCrush", SendMessageOptions.DontRequireReceiver); } // I5 analiz if (solution.count >= 5) { if ((solution.v && !solution.h) || (!solution.v && solution.h)) { FieldAssistant.main.GetNewColorBomb(puX, puY, FieldAssistant.main.GetSlot(puX, puY).transform.position, solution.id); return; } } // I4 analiz if (solution.count >= 4) { if ((solution.v && !solution.h) || (!solution.v && solution.h)) { FieldAssistant.main.GetNewBomb(puX, puY, FieldAssistant.main.GetSlot(puX, puY).transform.position, solution.id); return; } } // T4 analiz if (solution.count >= 4) { if (solution.v && solution.h) { FieldAssistant.main.GetNewCrossBomb(puX, puY, FieldAssistant.main.GetSlot(puX, puY).transform.position, solution.id); return; } } }