public void DestroyPackage() { SoundBase.Instance.GetComponent <AudioSource> ().PlayOneShot(SoundBase.Instance.destroyPackage); List <Item> itemsList = LevelManager.THIS.GetItemsAround(square); foreach (Item item in itemsList) { if (item != null) { if (item != null) { if (item.currentType != ItemsTypes.BOMB && item.currentType != ItemsTypes.INGREDIENT) { item.DestroyItem(true, "destroy_package"); } } } } SoundBase.Instance.GetComponent <AudioSource> ().PlayOneShot(SoundBase.Instance.explosion); currentType = ItemsTypes.NONE; DestroyItem(true); }
public static Skill getSkillById(ItemsTypes itemsTypes) { Skill ret = new Skill(); ret.magicid = 1; // Test //itemsTypes = ItemsTypes.HORIZONTAL_STRIPPED; if (ItemsTypes.NONE == itemsTypes) { ret.magicid = 1; } else if (ItemsTypes.VERTICAL_STRIPPED == itemsTypes) { ret.magicid = 2; } else if (ItemsTypes.HORIZONTAL_STRIPPED == itemsTypes) { ret.magicid = 3; } else if (ItemsTypes.PACKAGE == itemsTypes) { ret.magicid = 4; } else if (ItemsTypes.BOMB == itemsTypes) { ret.magicid = 5; } else if (ItemsTypes.INGREDIENT == itemsTypes) { ret.magicid = 6; } return(ret); }
public List <Item> Get(ItemsTypes itemType) { return(itemDal.Get(itemType)); }
IEnumerator ChangeTypeCor() { if (nextType == ItemsTypes.HORIZONTAL_STRIPPED) { StripeEffect(nextType); anim.SetTrigger("appear"); SoundBase.Instance.PlaySound(SoundBase.Instance.appearStipedColorBomb); } else if (nextType == ItemsTypes.VERTICAL_STRIPPED) { StripeEffect(nextType); anim.SetTrigger("appear"); SoundBase.Instance.PlaySound(SoundBase.Instance.appearStipedColorBomb); } else if (nextType == ItemsTypes.PACKAGE) { anim.SetTrigger("appear"); SoundBase.Instance.PlaySound(SoundBase.Instance.appearStipedColorBomb); } else if (nextType == ItemsTypes.CHOCOBOMB) { anim.SetTrigger("appear"); SoundBase.Instance.PlaySound(SoundBase.Instance.appearStipedColorBomb); color = 555; } else if (nextType == ItemsTypes.BOMB) { anim.SetTrigger("appear"); SoundBase.Instance.PlaySound(SoundBase.Instance.appearStipedColorBomb); xScale /= 2f; yScale /= 2f; transform.localScale /= 1.5f; } while (!appeared) { yield return(new WaitForFixedUpdate()); } // sprRenderer.transform.localScale = Vector3.one; if (nextType == ItemsTypes.NONE) { yield break; } // sprRenderer.enabled = true; // if (nextType == ItemsTypes.HORIZONTAL_STRIPPED) // sprRenderer.sprite = stripedItems[color].horizontal; // else if (nextType == ItemsTypes.VERTICAL_STRIPPED) // sprRenderer.sprite = stripedItems[color].vertical; if (nextType == ItemsTypes.PACKAGE) { sprRenderer.sprite = packageItems [color]; } else if (nextType == ItemsTypes.CHOCOBOMB) { sprRenderer.sprite = ChocoBombItems [0]; } else if (nextType == ItemsTypes.BOMB) { sprRenderer.sprite = bombItems [color]; SetupBomb(); } // square.DestroyBlock(); debugType = nextType; currentType = nextType; nextType = ItemsTypes.NONE; }
private void CreateMarmaladeWithType(ItemsTypes itemsType) { CreateMarmalade(itemsType); }
IEnumerator Switching() { if (switchDirection != Vector3.zero && neighborSquare != null) { bool backMove = false; LevelManager.THIS.DragBlocked = true; neighborSquare.item = this; square.item = switchItem; int matchesHere = neighborSquare.FindMatchesAround().Count; int matchesInThisItem = matchesHere; int matchesInNeithborItem = square.FindMatchesAround().Count; bool thisItemHaveMatch = false; if (matchesInThisItem >= 4) { thisItemHaveMatch = true; } if (matchesInNeithborItem >= 4) { thisItemHaveMatch = false; } int matchesHereOneColor = matchesHere; matchesHere += matchesInNeithborItem; if ((this.currentType == ItemsTypes.BOMB || switchItem.currentType == ItemsTypes.BOMB) && (this.currentType != ItemsTypes.INGREDIENT && switchItem.currentType != ItemsTypes.INGREDIENT)) { matchesHere++; } if (this.currentType > 0 && switchItem.currentType > 0) { matchesHere++; } if (this.currentType == ItemsTypes.INGREDIENT && switchItem.currentType == ItemsTypes.INGREDIENT) { matchesHere = 0; } float startTime = Time.time; Vector3 startPos = transform.position; float speed = 5; float distCovered = 0; while (distCovered < 1) { distCovered = (Time.time - startTime) * speed; transform.position = Vector3.Lerp(startPos, neighborSquare.transform.position + Vector3.back * 0.3f, distCovered); switchItem.transform.position = Vector3.Lerp(neighborSquare.transform.position + Vector3.back * 0.2f, startPos, distCovered); yield return(new WaitForFixedUpdate()); } if (matchesHere <= 0 && matchesInNeithborItem <= 0 && LevelManager.THIS.ActivatedBoost.type != BoostType.Hand || ((this.currentType == ItemsTypes.BOMB || switchItem.currentType == ItemsTypes.BOMB) && (this.currentType == ItemsTypes.INGREDIENT || switchItem.currentType == ItemsTypes.INGREDIENT) && (matchesHere + matchesInNeithborItem <= 2)) || (((int)this.currentType >= 1 || (int)switchItem.currentType >= 1) && (this.currentType == ItemsTypes.INGREDIENT || switchItem.currentType == ItemsTypes.INGREDIENT) && (matchesHere + matchesInNeithborItem <= 2))) //1.6.1 { neighborSquare.item = switchItem; square.item = this; backMove = true; SoundBase.Instance.GetComponent <AudioSource> ().PlayOneShot(SoundBase.Instance.wrongMatch); } else { if (LevelManager.THIS.ActivatedBoost.type != BoostType.Hand) { if (LevelManager.Instance.limitType == LIMIT.MOVES) { LevelManager.THIS.Limit--; } LevelManager.THIS.moveID++; } if (LevelManager.THIS.ActivatedBoost.type == BoostType.Hand) { LevelManager.THIS.ActivatedBoost = null; } switchItem.square = square; this.square = neighborSquare; LevelManager.THIS.lastDraggedItem = this; LevelManager.THIS.lastSwitchedItem = switchItem; if (matchesHereOneColor == 4 || matchesInNeithborItem == 4) { if (thisItemHaveMatch) { SetStrippedExtra(startPos - neighborSquare.transform.position); } else { LevelManager.THIS.lastDraggedItem = switchItem; LevelManager.THIS.lastSwitchedItem = this; switchItem.SetStrippedExtra(startPos - square.transform.position); if (matchesInThisItem == 4) { SetStrippedExtra(startPos - neighborSquare.transform.position); } } } if (matchesHere >= 5) { if (thisItemHaveMatch && matchesHereOneColor >= 5) { NextType = ItemsTypes.BOMB; } else if (!thisItemHaveMatch && matchesInNeithborItem >= 5) { LevelManager.THIS.lastDraggedItem = switchItem; LevelManager.THIS.lastSwitchedItem = this; switchItem.NextType = ItemsTypes.BOMB; if (matchesInThisItem >= 5) { NextType = ItemsTypes.BOMB; } } } if (this.currentType != ItemsTypes.INGREDIENT && switchItem.currentType != ItemsTypes.INGREDIENT) { CheckChocoBomb(this, switchItem); if (this.currentType != ItemsTypes.BOMB || switchItem.currentType != ItemsTypes.BOMB) { CheckChocoBomb(switchItem, this); } } if ((this.currentType == ItemsTypes.HORIZONTAL_STRIPPED || this.currentType == ItemsTypes.VERTICAL_STRIPPED) && (switchItem.currentType == ItemsTypes.HORIZONTAL_STRIPPED || switchItem.currentType == ItemsTypes.VERTICAL_STRIPPED)) { //1.6 switchItem.currentType = ItemsTypes.NONE; //2.0 switchItem.nextType = ItemsTypes.NONE; //2.0 switchItem.debugType = ItemsTypes.NONE; //2.0 DestroyHorizontal(); DestroyVertical(); // switchItem.DestroyItem (); } CheckPackageAndStripped(this, switchItem); CheckPackageAndStripped(switchItem, this); CheckPackageAndPackage(this, switchItem); CheckPackageAndPackage(switchItem, this); if (this.currentType != ItemsTypes.BOMB || switchItem.currentType != ItemsTypes.BOMB) { LevelManager.THIS.FindMatches(); } } //Debug.Break(); //yield return new WaitForSeconds(2); startTime = Time.time; distCovered = 0; while (distCovered < 1 && backMove) { distCovered = (Time.time - startTime) * speed; transform.position = Vector3.Lerp(neighborSquare.transform.position + Vector3.back * 0.3f, startPos, distCovered); switchItem.transform.position = Vector3.Lerp(startPos, neighborSquare.transform.position + Vector3.back * 0.2f, distCovered); yield return(new WaitForFixedUpdate()); } if (backMove) { LevelManager.THIS.DragBlocked = false; } } ResetDrag(); }
public void GenColor(int exceptColor = -1, bool onlyNONEType = false) { int row = square.row; int col = square.col; List <int> remainColors = new List <int> (); for (int i = 0; i < LevelManager.Instance.colorLimit; i++) { bool canGen = true; if (col > 1) { Square neighbor = LevelManager.Instance.GetSquare(row, col - 1); if (neighbor != null) { if (neighbor.item != null) { if (neighbor.CanGoInto() && neighbor.item.color == i) { canGen = false; } } } } if (col < LevelManager.Instance.maxCols - 1) { Square neighbor = LevelManager.Instance.GetSquare(row, col + 1); if (neighbor != null) { if (neighbor.item != null) { if (neighbor.CanGoOut() && neighbor.item.color == i) { canGen = false; } } } } if (row < LevelManager.Instance.maxRows) { Square neighbor = LevelManager.Instance.GetSquare(row + 1, col); if (neighbor != null) { if (neighbor.item != null) { if (neighbor.CanGoOut() && neighbor.item.color == i) { canGen = false; } } } } if (canGen && i != exceptColor) { remainColors.Add(i); } } // print(remainColors.Count); int randColor = UnityEngine.Random.Range(0, LevelManager.Instance.colorLimit); if (remainColors.Count > 0) { randColor = remainColors [UnityEngine.Random.Range(0, remainColors.Count)]; } if (exceptColor == randColor) { randColor = (randColor++) % items.Length; } LevelManager.THIS.lastRandColor = randColor; sprRenderer.sprite = items [randColor]; if (NextType == ItemsTypes.HORIZONTAL_STRIPPED) { sprRenderer.sprite = stripedItems [color].horizontal; } else if (NextType == ItemsTypes.VERTICAL_STRIPPED) { sprRenderer.sprite = stripedItems [color].vertical; } else if (NextType == ItemsTypes.PACKAGE) { sprRenderer.sprite = packageItems [color]; } else if (NextType == ItemsTypes.BOMB) { sprRenderer.sprite = bombItems [0]; } else if ((LevelManager.THIS.target == Target.INGREDIENT && (LevelManager.THIS.ingrTarget [0] == Ingredients.Ingredient1 || LevelManager.THIS.ingrTarget [0] == Ingredients.Ingredient2)) && UnityEngine.Random.Range(0, LevelManager.THIS.Limit) == 0 && square.row + 1 < LevelManager.THIS.maxRows && !onlyNONEType && LevelManager.THIS.GetIngredients(0).Count < LevelManager.THIS.ingrCountTarget [0]) { int i = 0; if (LevelManager.THIS.ingrTarget [i] == (Ingredients)i + 1 && LevelManager.THIS.ingrCountTarget [i] > 0) { if (LevelManager.THIS.GetIngredients(i).Count < LevelManager.THIS.ingrCountTarget [i]) { StartCoroutine(FallingCor(square, true)); color = 1000 + (int)LevelManager.THIS.ingrTarget [i]; currentType = ItemsTypes.INGREDIENT; sprRenderer.sprite = ingredientItems [i]; name = "ingredient_" + color; } } } else if ((LevelManager.THIS.target == Target.INGREDIENT && (LevelManager.THIS.ingrTarget [1] == Ingredients.Ingredient1 || LevelManager.THIS.ingrTarget [1] == Ingredients.Ingredient2)) && UnityEngine.Random.Range(0, LevelManager.THIS.Limit) == 0 && square.row + 1 < LevelManager.THIS.maxRows && !onlyNONEType && LevelManager.THIS.GetIngredients(1).Count < LevelManager.THIS.ingrCountTarget [1]) { int i = 1; if (LevelManager.THIS.ingrTarget [i] == (Ingredients)i + 1 && LevelManager.THIS.ingrCountTarget [i] > 0) { if (LevelManager.THIS.GetIngredients(i).Count < LevelManager.THIS.ingrCountTarget [i]) { StartCoroutine(FallingCor(square, true)); color = 1000 + (int)LevelManager.THIS.ingrTarget [i]; currentType = ItemsTypes.INGREDIENT; sprRenderer.sprite = ingredientItems [i]; name = "ingredient_" + color; } } } else { StartCoroutine(FallingCor(square, true)); color = Array.IndexOf(items, sprRenderer.sprite); } }
IEnumerator ChangeTypeCor() { //Disable all effects for (int i = 0; i < transform.childCount; i++) { GameObject effect = transform.GetChild(i).gameObject; if (effect.name.StartsWith("EF")) { effect.SetActive(false); } } if (NextType == ItemsTypes.HORIZONTAL_STRIPPED) { anim.SetTrigger("appear"); SoundBase.Instance.GetComponent <AudioSource>().PlayOneShot(SoundBase.Instance.appearStipedColorBomb); transform.FindChild("EF_LightningStrikeTall").gameObject.SetActive(true); transform.FindChild("EF_Horizontal").gameObject.SetActive(true); } else if (NextType == ItemsTypes.VERTICAL_STRIPPED) { anim.SetTrigger("appear"); SoundBase.Instance.GetComponent <AudioSource>().PlayOneShot(SoundBase.Instance.appearStipedColorBomb); transform.FindChild("EF_LightningStrikeTall").gameObject.SetActive(true); transform.FindChild("EF_Vertical").gameObject.SetActive(true); } else if (NextType == ItemsTypes.PACKAGE) { anim.SetTrigger("appear"); SoundBase.Instance.GetComponent <AudioSource>().PlayOneShot(SoundBase.Instance.appearPackage); transform.FindChild("EF_SwordHitBlueCritical").gameObject.SetActive(true); } else if (NextType == ItemsTypes.BOMB) { anim.SetTrigger("appear"); SoundBase.Instance.GetComponent <AudioSource>().PlayOneShot(SoundBase.Instance.appearStipedColorBomb); color = 555; } while (!appeared) { yield return(new WaitForFixedUpdate()); } if (NextType == ItemsTypes.NONE) { yield break; } // sprRenderer.enabled = true; if (NextType == ItemsTypes.HORIZONTAL_STRIPPED) { sprRenderer.sprite = stripedItems[color].horizontal; } else if (NextType == ItemsTypes.VERTICAL_STRIPPED) { sprRenderer.sprite = stripedItems[color].vertical; } else if (NextType == ItemsTypes.PACKAGE) { sprRenderer.sprite = packageItems[color]; } else if (NextType == ItemsTypes.BOMB) { sprRenderer.sprite = bombItems[0]; } // square.DestroyBlock(); debugType = NextType; currentType = NextType; NextType = ItemsTypes.NONE; }
IEnumerator Switching() { if (switchDirection != Vector3.zero && neighborSquare != null) { bool backMove = false; LevelManager.THIS.DragBlocked = true; neighborSquare.item = this; square.item = switchItem; int matchesHere = neighborSquare.FindMatchesAround().Count; int matchesInThisItem = matchesHere; int matchesInNeithborItem = square.FindMatchesAround().Count; bool thisItemHaveMatch = false; if (matchesInThisItem >= 4) { thisItemHaveMatch = true; } if (matchesInNeithborItem >= 4) { thisItemHaveMatch = false; } int matchesHereOneColor = matchesHere; matchesHere += matchesInNeithborItem; if ((this.currentType == ItemsTypes.BOMB || switchItem.currentType == ItemsTypes.BOMB) && (this.currentType != ItemsTypes.INGREDIENT && switchItem.currentType != ItemsTypes.INGREDIENT)) { matchesHere++; } if (this.currentType > 0 && switchItem.currentType > 0) { matchesHere++; } if (this.currentType == ItemsTypes.INGREDIENT && switchItem.currentType == ItemsTypes.INGREDIENT) { matchesHere = 0; } float startTime = Time.time; Vector3 startPos = transform.position; float speed = 5; float distCovered = 0; while (distCovered < 1) { distCovered = (Time.time - startTime) * speed; transform.position = Vector3.Lerp(startPos, neighborSquare.transform.position + Vector3.back * 0.3f, distCovered); switchItem.transform.position = Vector3.Lerp(neighborSquare.transform.position + Vector3.back * 0.2f, startPos, distCovered); yield return(new WaitForFixedUpdate()); } if (matchesHere <= 0 && matchesInNeithborItem <= 0 && LevelManager.THIS.ActivatedBoost.type != BoostType.Hand || ((this.currentType == ItemsTypes.BOMB || switchItem.currentType == ItemsTypes.BOMB) && (this.currentType == ItemsTypes.INGREDIENT || switchItem.currentType == ItemsTypes.INGREDIENT) && (matchesHere + matchesInNeithborItem <= 2)) || ((this.currentType == ItemsTypes.PACKAGE || switchItem.currentType == ItemsTypes.PACKAGE) && (this.currentType == ItemsTypes.INGREDIENT || switchItem.currentType == ItemsTypes.INGREDIENT) && (matchesHere + matchesInNeithborItem <= 2))) { neighborSquare.item = switchItem; square.item = this; backMove = true; SoundBase.Instance.GetComponent <AudioSource>().PlayOneShot(SoundBase.Instance.wrongMatch); } else { if (LevelManager.THIS.ActivatedBoost.type != BoostType.Hand) { if (LevelManager.Instance.limitType == LIMIT.MOVES) { LevelManager.THIS.Limit--; } LevelManager.THIS.moveID++; //Льоша ридачив if (!((this.currentType != ItemsTypes.NONE) && (switchItem.currentType != ItemsTypes.NONE))) { _waving = true; yield return(new WaitForSeconds(0.05f)); GameObject[] items = GameObject.FindGameObjectsWithTag("Item"); for (int i = 0; i < items.Length; i++) { if (items[i] != null) { items[i].GetComponent <Item>().WaitForWave = true; Vector2 center = new Vector2(transform.localPosition.x, transform.localPosition.y); items[i].GetComponent <WaveHelper>().AddCenter(center); } } yield return(new WaitForSeconds(_scaleTimeAnimation)); _waving = false; } //!!!!!!!!!!!!!!!!!!!!!!!!!!!!! } if (LevelManager.THIS.ActivatedBoost.type == BoostType.Hand) { LevelManager.THIS.ActivatedBoost = null; } switchItem.square = square; this.square = neighborSquare; LevelManager.THIS.lastDraggedItem = this; LevelManager.THIS.lastSwitchedItem = switchItem; if (matchesHereOneColor == 4 || matchesInNeithborItem == 4) { if (thisItemHaveMatch) { SetStrippedExtra(startPos - neighborSquare.transform.position); } else { LevelManager.THIS.lastDraggedItem = switchItem; LevelManager.THIS.lastSwitchedItem = this; switchItem.SetStrippedExtra(startPos - square.transform.position); if (matchesInThisItem == 4) { SetStrippedExtra(startPos - neighborSquare.transform.position); } } } if (matchesHere >= 5) { if (thisItemHaveMatch && matchesHereOneColor >= 5) { NextType = ItemsTypes.BOMB; } else if (!thisItemHaveMatch && matchesInNeithborItem >= 5) { LevelManager.THIS.lastDraggedItem = switchItem; LevelManager.THIS.lastSwitchedItem = this; switchItem.NextType = ItemsTypes.BOMB; if (matchesInThisItem >= 5) { NextType = ItemsTypes.BOMB; } } } if (this.currentType != ItemsTypes.INGREDIENT && switchItem.currentType != ItemsTypes.INGREDIENT) { CheckChocoBomb(this, switchItem); if (this.currentType != ItemsTypes.BOMB || switchItem.currentType != ItemsTypes.BOMB) { CheckChocoBomb(switchItem, this); } } if ((this.currentType == ItemsTypes.HORIZONTAL_STRIPPED || this.currentType == ItemsTypes.VERTICAL_STRIPPED) && (switchItem.currentType == ItemsTypes.HORIZONTAL_STRIPPED || switchItem.currentType == ItemsTypes.VERTICAL_STRIPPED)) { DestroyHorizontal(); switchItem.DestroyVertical(); } CheckPackageAndStripped(this, switchItem); CheckPackageAndStripped(switchItem, this); CheckPackageAndPackage(this, switchItem); CheckPackageAndPackage(switchItem, this); if (this.currentType != ItemsTypes.BOMB || switchItem.currentType != ItemsTypes.BOMB) { LevelManager.THIS.FindMatches(); } } //Debug.Break(); //yield return new WaitForSeconds(2); startTime = Time.time; distCovered = 0; while (distCovered < 1 && backMove) { distCovered = (Time.time - startTime) * speed; transform.position = Vector3.Lerp(neighborSquare.transform.position + Vector3.back * 0.3f, startPos, distCovered); switchItem.transform.position = Vector3.Lerp(startPos, neighborSquare.transform.position + Vector3.back * 0.2f, distCovered); yield return(new WaitForFixedUpdate()); } if (backMove) { LevelManager.THIS.DragBlocked = false; } } ResetDrag(); }
/// <summary> /// Generate new item /// </summary> /// <returns>The item.</returns> /// <param name="falling">If set to <c>true</c> prepare for falling animation.</param> public Item GenItem(bool falling = true, ItemsTypes itemType = ItemsTypes.NONE, int color = -1) { if (IsNone() && !CanGoInto()) { return(null); } GameObject item = null; if (itemType == ItemsTypes.NONE) { if (LevelManager.THIS.collectIngredients && !IsObstacle()) { item = GetIngredientItem(); } if (!item) { item = ObjectPooler.Instance.GetPooledObject("Item"); } } else { item = ObjectPooler.Instance.GetPooledObject(itemType.ToString()); item?.GetComponent <Item>().anim?.SetTrigger("bonus_appear"); } if (item == null) { Debug.LogError("there is no " + itemType + " in pool "); } item.transform.localScale = Vector2.one * 0.42f; Item itemComponent = item.GetComponent <Item>(); itemComponent.square = this; // item.GetComponent<IColorableComponent>().RandomizeColor(); IColorableComponent colorableComponent = item.GetComponent <IColorableComponent>(); if (color == -1) { itemComponent.GenColor(); } else if (colorableComponent != null) { colorableComponent.SetColor(color); } itemComponent.field = field; itemComponent.needFall = falling; if (!falling) { item.transform.position = (Vector3)((Vector2)transform.position) + Vector3.back * 0.2f; } if (LevelManager.THIS.gameStatus != GameState.Playing && LevelManager.THIS.gameStatus != GameState.Tutorial) { Item = itemComponent; } else if (!IsHaveFallingItemsAbove()) { Item = itemComponent; } // this.item.falling = falling; if (falling) { Vector3 startPos = GetReverseDirection(); item.transform.position = transform.position + startPos * field.squareHeight + Vector3.back * 0.2f; itemComponent.JustCreatedItem = true; } if (LevelManager.THIS.DebugSettings.DestroyLog) { DebugLogKeeper.Log(name + " gen item " + item.name + " pos " + item.transform.position, DebugLogKeeper.LogType.Destroying); } itemComponent.needFall = falling; // if ((!nextSquare?.IsFree() ?? false) || Item == itemComponent) itemComponent.StartFallingTo(itemComponent.GenerateWaypoints(this)); // itemComponent.StartFalling(); return(itemComponent); }
public ItemsTypes GetBonusCombine(Combine combine, out ItemTemplate[] foundItems, ItemsTypes prioritiseItem = ItemsTypes.NONE) { if (bonusCombinesPatterns.Count < bonusCombineListCount) { FillPatterns(); } foundItems = null; var matrix = ConvertCombine(combine); var compare = SimplifyArray(matrix).matrix.ToArray(); Show2DArray(compare.ToArray(), "compare origin"); var baseNodePosition = GetBaseNode(compare); var types = new List <ItemsTypes>(); foreach (var typePattern in bonusCombinesPatterns) { foreach (var m in typePattern.matrices) { var pattern = m.DeepCopy().matrix; if (pattern.Any(i => i.position.x > 0 && i.position.y > 0)) { var offset = baseNodePosition - m.nodeItem; pattern = pattern.ForEachY(i => i.position += offset).ToList(); } Show2DArray(pattern.ToArray(), "pattern "); if (!IsCombineFound(compare, pattern.ToArray(), typePattern, ref types, out foundItems)) { continue; } Show2DArray(compare.ToArray(), "compare found"); Show2DArray(pattern.ToArray(), "pattern found"); ItemsTypes itemsTypes = GetCombineType(prioritiseItem, types); if (_debugSettings.BonusCombinesShowLog) { DebugLogKeeper.Log(itemsTypes + " detected", DebugLogKeeper.LogType.BonusAppearance); } return(itemsTypes); } } var type = GetCombineType(prioritiseItem, types); // Debug.Log(type + " detected"); return(type); }
public void GenColor(int exceptColor = -1, bool onlyNONEType = false) { int row = square.row; int col = square.col; List <int> remainColors = new List <int>(); for (int i = 0; i < LevelManager.Instance.colorLimit; i++) { bool canGen = true; if (col > 1) { Square neighbor = LevelManager.Instance.GetSquare(row, col - 1); if (neighbor != null) { if (neighbor.item != null) { if (neighbor.CanGoInto() && neighbor.item.color == i) { canGen = false; } } } } if (col < LevelManager.Instance.maxCols - 1) { Square neighbor = LevelManager.Instance.GetSquare(row, col + 1); if (neighbor != null) { if (neighbor.item != null) { if (neighbor.CanGoOut() && neighbor.item.color == i) { canGen = false; } } } } if (row < LevelManager.Instance.maxRows) { Square neighbor = LevelManager.Instance.GetSquare(row + 1, col); if (neighbor != null) { if (neighbor.item != null) { if (neighbor.CanGoOut() && neighbor.item.color == i) { canGen = false; } } } } if (canGen && i != exceptColor) { remainColors.Add(i); } } // print(remainColors.Count); int randColor = Random.Range(0, LevelManager.Instance.colorLimit); if (remainColors.Count > 0) { randColor = remainColors[Random.Range(0, remainColors.Count)]; } if (exceptColor == randColor) { randColor = (randColor++) % items.Length; } LevelManager.THIS.lastRandColor = randColor; sprRenderer.sprite = items[randColor]; if (NextType == ItemsTypes.HORIZONTAL_STRIPPED) { sprRenderer.sprite = stripedItems[color].horizontal; } else if (NextType == ItemsTypes.VERTICAL_STRIPPED) { sprRenderer.sprite = stripedItems[color].vertical; } else if (NextType == ItemsTypes.PACKAGE) { sprRenderer.sprite = packageItems[color]; } else if (NextType == ItemsTypes.BOMB) { sprRenderer.sprite = bombItems[0]; } else { var ingredients = LevelManager.THIS.targetObject.Where(i => i.type == Target.INGREDIENT).ToArray(); if (ingredients.Any()) { foreach (var targetObject in ingredients) { if (Random.Range(0, LevelManager.THIS.Limit) == 0 && square.row + 1 < LevelManager.THIS.maxRows && !onlyNONEType && !targetObject.Done() && LevelManager.THIS.GetIngredients(targetObject.icon.name).Count < targetObject.targetCount) { StartCoroutine(FallingCor(square, true)); color = 1000; currentType = ItemsTypes.INGREDIENT; sprRenderer.sprite = targetObject.icon; name = "ingredient_" + color; } else { StartCoroutine(FallingCor(square, true)); color = Array.IndexOf(items, sprRenderer.sprite); } } } else { StartCoroutine(FallingCor(square, true)); color = Array.IndexOf(items, sprRenderer.sprite); } } if (prefabs.Length > 0) { sprRenderer.enabled = false; for (int i = 0; i < transform.childCount; i++) { if (transform.GetChild(i).name != "Sprite") { Destroy(transform.GetChild(i)); } } GameObject obj = Instantiate(prefabs[color]); obj.transform.SetParent(transform); obj.transform.localPosition = Vector3.zero; } }
public List <Combine> GetCombines(FieldBoard field, out List <Combine> allFoundCombines, ItemsTypes _prioritiseItem = ItemsTypes.NONE) { prioritiseItem = _prioritiseItem; maxCols = field.fieldData.maxCols; maxRows = field.fieldData.maxRows; //combines.Clear(); match3Combines.Clear(); tempCombinesPredict.Clear(); dic.Clear(); var color = -1; var combine = new Combine(); vChecking = false; //Horrizontal searching for (var row = 0; row < maxRows; row++) { color = -1; for (var col = 0; col < maxCols; col++) { var square = field.GetSquare(col, row); if (IsSquareNotNull(square)) { CheckMatches(square.Item, color, ref combine); color = square.Item.color; } } } vChecking = true; //Vertical searching for (var col = 0; col < maxCols; col++) { color = -1; for (var row = 0; row < maxRows; row++) { var square = field.GetSquare(col, row); if (IsSquareNotNull(square) && !square.Item.falling && !square.Item.destroying) { // if(match3Combines.Any(i=>i.items.Any(x=>x ==square.item))) continue; CheckMatches(square.Item, color, ref combine); color = square.Item.color; } } } allFoundCombines = match3Combines; // Debug.Log (" test combines detected " + tempCombines.Count); return(CheckCombines(dic, match3Combines)); }
public List <Combine> GetCombines(FieldBoard field, ItemsTypes _prioritiseItem = ItemsTypes.NONE) { List <Combine> allFoundCombines; return(GetCombines(field, out allFoundCombines, _prioritiseItem)); }
public List <Combine> CheckCombines(Dictionary <Item, Combine> d, List <Combine> foundCombines) { var combines = new List <Combine>(); var countedCombines = new List <Combine>(); prioritiseItem = ItemsTypes.NONE; //find and merge cross combines (+) foreach (var comb in foundCombines) { if (foundCombines.Count >= 2) { foreach (var item in comb.items) { var newComb = FindCombineInDic(item, d); if (comb != newComb && countedCombines.IndexOf(newComb) < 0 && countedCombines.IndexOf(comb) < 0 && IsCombineMatchThree(newComb)) { countedCombines.Add(newComb); countedCombines.Add(comb); var mergedCombine = MergeCombines(comb, newComb); combines.Add(mergedCombine); foreach (var item_ in comb.items) { d[item_] = mergedCombine; } foreach (var item_ in newComb.items) { d[item_] = mergedCombine; } break; } } } } //find simple combines (3,4,5) foreach (var comb in foundCombines) { if (combines.IndexOf(comb) < 0 /*&& IsCombineMatchThree(comb)*/ && countedCombines.IndexOf(comb) < 0 && comb.items.Any()) { ItemTemplate[] foundBonusCombine; comb.nextType = SetNextItemType(comb, out foundBonusCombine); if (comb.nextType != ItemsTypes.NONE) { comb.items = foundBonusCombine.Where(i => i.item).Select(i => i.itemRef).ToList(); combines.Add(comb); } else if (IsCombineMatchThree(comb)) { if (comb.hCount > comb.vCount) { var items = comb.items.GroupBy(i => i.square.row).OrderByDescending(i => i.Count()).First().ToList(); /*if (comb.nextType == ItemsTypes.NONE) */ comb.items = items; if (items.Count < 3) { return(combines); } } else if (comb.hCount < comb.vCount) { var items = comb.items.GroupBy(i => i.square.col).OrderByDescending(i => i.Count()).First().ToList(); /*if (comb.nextType == ItemsTypes.NONE)*/ comb.items = items; if (items.Count < 3) { return(combines); } } else { var items = comb.items.GroupBy(i => i.square.row).OrderByDescending(i => i.Count()).First().ToList(); /*if (comb.nextType == ItemsTypes.NONE)*/ comb.items = items; if (items.Count < 3) { items = comb.items.GroupBy(i => i.square.col).OrderByDescending(i => i.Count()).First() .ToList(); /*if (comb.nextType == ItemsTypes.NONE)*/ comb.items = items; } if (items.Count < 3) { return(combines); } } combines.Add(comb); } } } return(combines); }