private void SendMessage(int side, ELevelBallType type, Vector2 startPos, Vector2 dir, Vector2 hitPoint, bool isFlyout, float flyDistance) { Vector2 point = m_battleFieldObj.transform.InverseTransformPoint(hitPoint); Vector2 cellPoint = point; float speed = flyDistance / ConfigHelper.GetBubbleFlyDuration(); cellPoint.y = -cellPoint.y; if (GameCore.Instance.IsOfflineMode) { CmdFireBallResponse cmd = new CmdFireBallResponse(0, (int)type, startPos, dir, point, CellManager.GetCellID(cellPoint), m_lastBallId, speed, 0); ++m_lastBallId; m_battle.HandleBattleCommand(cmd); } else { ProtoCSBattleCommand proto = new ProtoCSBattleCommand(new CmdFireBall(side, (int)type, startPos, dir, point, CellManager.GetCellID(cellPoint), isFlyout, speed)); NetworkMgr.Instance.Send(proto); } }
public override void SetCommand(BattleCommand cmd) { base.SetCommand(cmd); m_cmd = cmd as CmdFireBallResponse; if (m_cmd.Result == 3) { return; } m_ball = BattleResource.Instance.GetBallResource((ELevelBallType)m_cmd.BallType); if (m_ball != null) { m_ball = GameObject.Instantiate(m_ball) as GameObject; m_ball.transform.position = m_cmd.StartPosition; m_ball.transform.SetParent(m_battleFieldObj.transform); m_ball.GetComponent <Collider2D>().enabled = false; } else { Debug.LogError("Can't Get Ball Resourcem, type:" + m_cmd.BallType); return; } if (m_cmd.Result == 0 || m_cmd.Result == 2) { m_collisionPoint = new Vector2(0, GlobalData.m_windowHight / 2); if (m_cmd.Side == 0) { m_collisionPoint.y = -m_collisionPoint.y; } m_collisionPoint = m_battleFieldObj.transform.InverseTransformPoint(m_collisionPoint); } else { m_collisionPoint = m_cmd.CollisionPoint; } m_dir = m_cmd.Dir; m_battleField.SetBallReady(m_cmd.Side); AudioMgr.PlayAudio(203); m_hasBouncedBack = false; m_isOver = false; }
public void HandleFireBall(CmdFireBall cmd) { ServerBubble bubble = new ServerBubble(NewBubbleId, (ELevelBallType)cmd.BallType, new List <GridPosition>() { cmd.DestGrid }); // 碰撞检测Here ResetVisitFlag(); List <ServerBubble> eraseBubbles = new List <ServerBubble>(); TryEraseBubble(bubble, bubble.Type, eraseBubbles); if (eraseBubbles.Count > 2) { // Send CmdFireBallResponse CmdFireBallResponse response = new CmdFireBallResponse(cmd.Side, (int)cmd.Type, cmd.StartPosition, cmd.Dir, cmd.CollisionPoint, cmd.DestGrid, bubble.Id, m_bubbleSpeed, 0); BattleServer.Instance.SendResponse(response); List <int> eraseIds = new List <int>(); for (int i = 0; i < eraseBubbles.Count; i++) { eraseIds.Add(eraseBubbles[i].Id); RemoveBubble(eraseBubbles[i]); } // Send CmdEraseBall CmdEraseBall command = new CmdEraseBall(cmd.Side, 0, eraseIds, bubble.Id); BattleServer.Instance.SendResponse(command); ResetVisitFlag(); List <ServerBubble> rootBubbles = GetRootBubbles(); for (int i = 0; i < rootBubbles.Count; i++) { VisitBubble(rootBubbles[i]); } List <ServerBubble> fallenBubbles = new List <ServerBubble>(); for (int i = 0; i < m_bubbleDic.Count; i++) { if (m_bubbleDic[i].isVisited == false) { fallenBubbles.Add(m_bubbleDic[i]); } } if (fallenBubbles.Count > 0) { List <int> fallenIds = new List <int>(); for (int i = 0; i < fallenBubbles.Count; i++) { fallenIds.Add(fallenBubbles[i].Id); RemoveBubble(fallenBubbles[i]); } // Send CmdFallBall CmdFallBall command1 = new CmdFallBall(cmd.Side, 0, eraseIds, bubble.Id); BattleServer.Instance.SendResponse(command1); } } else { AddBubble(bubble); CmdFireBallResponse response = new CmdFireBallResponse(cmd.Side, (int)cmd.Type, cmd.StartPosition, cmd.Dir, cmd.CollisionPoint, cmd.DestGrid, bubble.Id, m_bubbleSpeed, 1); BattleServer.Instance.SendResponse(response); } }