/// <summary> /// 杂草增长 /// </summary> public static void Grow() { List <Slot> slots = new List <Slot> (); Weed weed = null; for (int i = 0; i < all.Count; i++) { weed = all[i]; for (int j = 0; j < Utils.straightSides.Length; j++) { Side side = Utils.straightSides[j]; if (weed.slot[side] && !weed.slot[side].Block) // && !(weed.slot[side].GetChip() && weed.slot[side].GetChip().chipType == "SugarChip")) { slots.Add(weed.slot[side]); } } } while (seed > 0) { if (slots.Count == 0) { return; } Slot target = slots[Random.Range(0, slots.Count)]; slots.Remove(target); if (target.GetChip()) { target.GetChip().HideChip(false); } Weed newWeed = FightMgr.Instance.LoadAndInstantiate(FightDefine.Prefab_Weed).GetComponent <Weed>(); newWeed.transform.position = target.transform.position; newWeed.name = "New_Weed"; newWeed.transform.SetParent(target.transform, false); target.SetBlock(newWeed); newWeed.slot = target; #if !FightTest MusicManager.Instance.PlaySoundEff("Music/WeedCreate"); #endif newWeed.Initialize(); seed--; } }
public bool OnUpdate() { if (!TargetSlot) { return(false); // Teleport is possible only if target is exist } if (!FightMgr.Instance.CanIGravity()) { return(false); // Teleport is possible only in case of mode "gravity" } if (!slot.GetChip()) { return(false); // Teleport is possible only if slot contains chip } if (!slot.GetChip().can_move) { return(false); // If chip can't be moved, then it can't be teleported } if (TargetSlot.GetChip()) { return(false); // Teleport is impossible if target slot already contains chip } if (slot.Block) { return(false); // Teleport is impossible, if the slot is blocked } if (TargetSlot.Block) { return(false); // Teleport is impossible, if the target slot is blocked } if (slot.GetChip().IsDrop) { return(true); //.transform.position != slot.transform.position) return; } if (slot.GetChip().hitting) { return(false); } if (lastTime + delay > Time.time) { return(true); // limit of frequency generation } lastTime = Time.time; AnimationMgr.Instance.TeleportChip(slot.GetChip(), TargetSlot); return(true); }
bool SlideRight() { slotGet = slot[ccw45side]; if (slotGet != null && // target slot must exist slotGet.gravity && // target slot must contain gravity (slotGet.slotGravity == null || (slotGet.slotGravity != null && (slotGet[slotGet.slotGravity.fallingDirection] == null || slotGet[slotGet.slotGravity.fallingDirection].Block != null || slotGet[slotGet.slotGravity.fallingDirection].GetShadow()))) && ((slot[gravityDirection] != null && slot[gravityDirection][ccw90side] != null) || (slot[ccw90side] != null && slot[ccw90side][gravityDirection] != null)) && // target slot should have a no-diagonal path that is either right->down or down->right slotGet.GetChip() == null && // target slot should not have a chip slotGet.GetShadow() && // target slot must have shadow otherwise it will be easier to fill it with a generator on top !slotGet.GetChipShadow()) { // target slot should not be shaded by another chip, otherwise it will be easier to fill it with this chip // chip.Slot.RemoveCard(); if (slotGet.slotGravity != null && slotGet[slotGet.slotGravity.fallingDirection] != null && slotGet[slotGet.slotGravity.fallingDirection].Block == null && (slot[slot.slotGravity.fallingDirection] != null && slot[slot.slotGravity.fallingDirection] != null && slot[slot.slotGravity.fallingDirection].Block == null)) { return(false); } else { slotGet.SetChip(chip, true); // transfer chip to target slot // chip.gameObject.SetActive(true); // Debug.Log("<color=orange>set chip slide right:</color>" + slot[ccw45side].name + ",localpos:" + chip.transform.localPosition + ",velocity:" + chip.velocity); return(true); } } return(false); }
// Shadow can also discard the other chips - it's a different kind of shadow. public bool GetChipShadow() { Side direction = slotGravity.fallingDirection; Slot s = nearSlot[(int)direction]; for (int i = 0; i < 40; i++) { if (!s) { return(false); } if (!s.gravity) { return(false); } if (!s.GetChip() || s.slotGravity.gravityDirection != direction) { direction = s.slotGravity.fallingDirection; s = s.nearSlot[(int)direction]; } else { return(true); } } return(false); }
public bool OnUpdate() { if (this.Slot == null) { return(false); } if (!FightMgr.Instance.enabled) { return(false); } if (!FightMgr.Instance.CanIGravity()) { return(false); // Generation is possible only in case of mode "gravity" } if (Slot.GetChip()) { return(false); // Generation is impossible, if slot already contains chip } if (Slot.Block != null) { return(false); // Generation is impossible, if the slot is blocked } if (lastTime + delay > Time.time) { return(true); // limit of frequency generation } lastTime = Time.time; // Vector3 spawnOffset = new Vector3( // Utils.SideOffsetX(Utils.MirrorSide(Slot.slotGravity.gravityDirection)), // Utils.SideOffsetY(Utils.MirrorSide(Slot.slotGravity.gravityDirection)), // 0) * 70f; // if (LevelProfile.CurrentLevelProfile.target == E_FieldTarget.SugarDrop && SessionAssistant.main.creatingSugarDropsCount > 0) { // if (SugarChip.live_count == 0 || SessionAssistant.main.GetResource() <= 0.4f + 0.6f * SessionAssistant.main.creatingSugarDropsCount / LevelProfile.CurrentLevelProfile.targetSugarDropsCount) { // SessionAssistant.main.creatingSugarDropsCount--; // FieldAssistant.main.GetSugarChip(slot.x, slot.y, transform.position + spawnOffset); // creating new sugar chip // return; // } // } Vector3 spawnOffset = Vector3.up * 70f; if (Random.value > Fight.LevelProfile.NewCurrentLevelProfile.StonePortion) { FightMgr.Instance.GetNewSimpleChip(Slot.Point.X, Slot.Point.Y, spawnOffset); // creating new chip } else { FightMgr.Instance.GetNewStone(Slot.Point.X, Slot.Point.Y, spawnOffset); // creating new stone } return(true); }
// Crush block function public void BlockCrush(int x, int y, bool radius, bool force = false) { BlockInterface b; Slot s; Card c; StoneChip sc; Side side; Slot slot = FightMgr.Instance.FindSlot(x, y); Transform parent = slot.transform; if (radius) { Card cardTemp = slot.GetChip(); E_CardType cardType = cardTemp == null ? E_CardType.None : cardTemp.CardType; for (int i = 0; i < Utils.straightSides.Length; i++) { side = Utils.straightSides[i]; b = null; s = null; c = null; sc = null; b = GetBlock(x + Utils.SideOffsetX(side), y + Utils.SideOffsetY(side)); if (b && b.CanBeCrushedByNearSlot()) { b.BlockCrush(force, parent.transform, false, cardType); } s = FightMgr.Instance.FindSlot(x + Utils.SideOffsetX(side), y + Utils.SideOffsetY(side)); if (s) { c = s.GetChip(); } if (c != null) { sc = c.GetComponent <StoneChip>(); } if (sc != null) { c.DestroyChip(); } } } b = GetBlock(x, y); if (b) { b.BlockCrush(force, parent, false, E_CardType.None); } }
/// <summary> /// 随机出一个木块 /// </summary> public void CreateOneBlock(Slot s) { if (s != null && s.GetChip() && !s.Block && !s.IsGenerator) { int x = s.Point.X; int y = s.Point.Y; s.GetChip().HideChip(false); field.blocks[x, y] = 2; GameObject o = FightMgr.Instance.LoadAndInstantiate(FightDefine.Prefab_Block);; o.name = "Block_" + x + "x" + y; // o.transform.parent = s.transform; o.transform.SetParent(s.transform, false); o.transform.position = s.transform.position; Block b = o.GetComponent <Block>(); s.SetBlock(b); b.slot = s; b.level = field.blocks[x, y]; b.Initialize(); } }
// Make a bomb in the specified location with the ability to transform simple chips in a bomb public Card AddPowerup(int x, int y, PowerUps powerup) { Slot slot = FightMgr.Instance.FindSlot(x, y); Card chip = slot.GetChip(); if (chip) { //DebugUtil.Debug("destroy card:" + chip.gameObject.name); if (chip.move) { chip.gravity = false; } GameObject.Destroy(chip.gameObject); } chip = GetNewBomb(slot.Point.X, slot.Point.Y, powerup, slot.transform.position); FightMgr.Instance.ListNewPowerUp.Add(chip); return(chip); }
/// <summary> /// 查找目标位置 /// </summary> /// <returns>The fly block target slots.</returns> public List <Slot> FindFlyBlockTargetSlots(int needCnt) { List <Slot> listAll = new List <Slot>(); List <Slot> listRtn = new List <Slot>(); Slot s = null; for (int i = 0; i < field.width; i++) { for (int j = 0; j < field.height; j++) { int id = field.GetChip(i, j); if (id > 0 && id != 9 && field.blocks[i, j] == 0) { s = FightMgr.Instance.FindSlot(i, j); if (s != null && s.GetChip() && !s.Block && !s.IsGenerator && !s.GetChip().IsLineCard&& !s.GetChip().move) { listAll.Add(s); } } } } //随机找符合的位置 while (needCnt > 0 && listAll.Count > 0) { int index = Random.Range(0, listAll.Count); listRtn.Add(listAll[index]); //先设值,防止快速播放 field.blocks[listAll[index].Point.X, listAll[index].Point.Y] = 2; listAll.RemoveAt(index); needCnt--; } return(listRtn); }
IEnumerator TeleportChipRoutine(Card chip, Slot target) { if (!chip.Slot) { yield break; } if (chip.destroying) { yield break; } if (target.GetChip() || !target.gravity) { yield break; } Vector3 scale_target = Vector3.zero; chip.can_move = false; target.SetChip(chip, true); scale_target.z = 1; while (chip != null && chip.transform.localScale.x > 0) { chip.transform.localScale = Vector3.MoveTowards(chip.transform.localScale, scale_target, Time.deltaTime * 8); yield return(0); } if (chip != null) { chip.transform.localPosition = Vector3.zero; } scale_target.x = 1; scale_target.y = 1; while (chip != null && chip.transform.localScale.x < 1) { chip.transform.localScale = Vector3.MoveTowards(chip.transform.localScale, scale_target, Time.deltaTime * 12); yield return(0); } if (chip != null && chip.Slot != null) { chip.IsDrop = false; chip.can_move = true; //重新计算 Solution solution = chip.Slot.MatchAnaliz(); if (solution != null && solution.count > 0) { FightMgr.Instance.ListSoution.Add(solution); // Debug.Log("end"); } } //Chip new_chip = Instantiate(chip.gameObject).GetComponent<Chip>(); //new_chip.parentSlot = null; //new_chip.transform.position = target.transform.position; //target.SetChip(new_chip); //chip.HideChip(false); }
// Gravity iteration public bool GravityReaction() { if (!FightMgr.Instance.CanIGravity()) { return(false); // Work is possible only in "Gravity" mode } chip = slot.GetChip(); if (chip == null) { return(false); // Work is possible only with the chips, otherwise nothing will move } if (!chip.can_move) { return(false); } if (chip == null) { return(false); } if (chip.IsDrop) { return(true); // Work is possible only if the chip is physically clearly in the slot } if (chip.hitting) { return(false); } // return false; slotGet = slot[gravityDirection]; if (slotGet == null || !slotGet.gravity) { return(false); // Work is possible only if there is another bottom slot } // provided that bottom neighbor doesn't contains chip, give him our chip if (slot[gravityDirection].GetChip() == null) { slot[gravityDirection].SetChip(chip, true); // chip.gameObject.SetActive(true); GravityReaction(); return(true); } bool rtn = false; // Otherwise, we try to give it to their neighbors from the bottom-left and bottom-right side if (Random.value > 0.5f) { // Direction priority is random if (SlideLeft()) { rtn = true; } else if (SlideRight()) { rtn = true; } } else { if (SlideRight()) { rtn = true; } else if (SlideLeft()) { rtn = true; } } return(rtn); }
private void OnMyPress(GameObject go, bool state) { // DebugUtil.Debug("OnMyPress:" + state + " go:" + go.name); EventDispatcher.TriggerEvent(UIMyFace.OnHideFaceEvent); if (_isStartMoving || FightMgr.Instance.IsIceBlcok || FightMgr.Instance.IsDoSkillToSlot) { return; } // if(state) // { // if(_listLineSlot == null) // _listLineSlot = new List<Slot>(); // else // _listLineSlot.Clear(); // // Slot slot = go.GetComponent<Slot>(); // Card card = LineMgr.Instance.IsCheckTypeOk(slot); // if(card != null) // LineMgr.Instance.CreateLine(slot.Point,card.CardType,Utils.straightSides[Random.Range(0,Utils.straightSides.Length)],ref _listLineSlot); // } // else // { // FightMgr.Instance.RemoveLineSlot(_listLineSlot); // LineMgr.Instance.RemoveLine(); // } if (FightMgr.Instance.limitationRoutineIsOver) { return; } if (_isPress == state) { return; } else { _isPress = state; } Slot sSel = go.GetComponent <Slot>(); if (sSel.IsBoss) { //选中boss位置 _isBossPosSel = true; // if(!state) // { // //显示技能选择面板 // FightMgr.Instance.ShowSkillPanel(true); // } } else { _isBossPosSel = false; if (state) { _isLineSlot = false; //按下 _selectedGoSlot = go; _cardFrom = sSel.GetChip(); if (_cardFrom != null) { _cardFrom.SetBorder(true); _isLineSlot = _cardFrom.IsLineCard; } hasMoved = false; } else if (!hasMoved) { //抬起 //没有移动过,释放 if (_cardFrom != null) { _cardFrom.SetBorder(false); } ClearCombinePowupEffect(); _lastSide = Side.Null; } else { if (_isLineSlot) { if (_isCombinePowup) { ClearCombinePowupEffect(); // if(FightMgr.Instance.movesCount > 0) // { FightMgr.Instance.swapEvent++; // FightMgr.Instance.movesCount -= 1; FightMgr.Instance.EventCounter(); //算普通攻击 FightMgr.Instance._continueMatchCount += LineMgr.Instance.TotalPowupCount; FightMgr.Instance.RemoveLineSlot(_listLineSlot); if (AfterMoveHandler != null) { AfterMoveHandler(go.GetComponent <Slot>()); } // } // else // { // ChangeCombinePowerupPos(); // FightMgr.Instance.ShowMsg(FightDefine.E_NoteMsgType.NoMoves); // } } else { if (_cardFrom != null) { _cardFrom.SetBorder(false); } // if(FightMgr.Instance.movesCount > 0) // { FightMgr.Instance.swapEvent++; // FightMgr.Instance.movesCount -= 1; FightMgr.Instance.EventCounter(); //算普通攻击 FightMgr.Instance._continueMatchCount += LineMgr.Instance.TotalPowupCount; FightMgr.Instance.RemoveLineSlot(_listLineSlot); if (AfterMoveHandler != null) { AfterMoveHandler(go.GetComponent <Slot>()); } // } // else // { // FightMgr.Instance.ShowMsg(FightDefine.E_NoteMsgType.NoMoves); // } } LineMgr.Instance.RemoveLine(); } _lastSide = Side.Null; } } }