Beispiel #1
0
 public void RemoveBubble(ServerBubble bubble)
 {
     m_bubbleDic.Remove(bubble.Id);
     for (int i = 0; i < bubble.TakenGrids.Count; i++)
     {
         m_gridBubbleDic.Remove(bubble.TakenGrids[i]);
     }
 }
Beispiel #2
0
 public void AddBubble(ServerBubble bubble)
 {
     m_bubbleDic.Add(bubble.Id, bubble);
     for (int i = 0; i < bubble.TakenGrids.Count; i++)
     {
         m_gridBubbleDic.Add(bubble.TakenGrids[i], bubble);
     }
 }
Beispiel #3
0
        public void InitLevel(int levelId)
        {
            Clear();

            LevelMapData data = LevelConfig.Instance.GetLevelMapData(levelId);

            foreach (var ballData in data.balls)
            {
                ServerBubble bubble = new ServerBubble(ballData.id, (ELevelBallType)ballData.type, ballData.grids);
                AddBubble(bubble);
            }

            m_nextId = data.maxBallId + 1;
            m_minCol = data.minCol;
        }
Beispiel #4
0
 private void VisitBubble(ServerBubble bubble)
 {
     if (!bubble.isVisited)
     {
         bubble.isVisited = true;
         for (int i = 0; i < bubble.NeighborGrids.Count; i++)
         {
             ServerBubble neighbor = GetBubbleByGrid(bubble.NeighborGrids[i]);
             if (neighbor != null)
             {
                 VisitBubble(neighbor);
             }
         }
     }
 }
Beispiel #5
0
 public void TryEraseBubble(ServerBubble bubble, ELevelBallType type, List <ServerBubble> eraseBubbles)
 {
     for (int i = 0; i < bubble.NeighborGrids.Count; i++)
     {
         ServerBubble neighbor = GetBubbleByGrid(bubble.NeighborGrids[i]);
         if (neighbor != null && neighbor.isVisited == false)
         {
             neighbor.isVisited = true;
             if (neighbor.CanErase(type))
             {
                 eraseBubbles.Add(neighbor);
                 TryEraseBubble(neighbor, type, eraseBubbles);
             }
         }
     }
 }
Beispiel #6
0
        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);
            }
        }