/// <summary> /// 남은 Unit 중 움직이지 않은 Unit들을 반환 /// </summary> /// <param name="index"></param> /// <returns></returns> private List <Vector2> GetAttackingUnit(byte index) { List <Vector2> answer = new List <Vector2>(); foreach (Unit unit in players[index].units) { if (!unit.bMoving && unit.ID[0] == '0') { RemoteUnit remoteUnit = (RemoteUnit)unit; List <Vector2> waitedLst = Helper.GetMoving(remoteUnit.Pos, remoteUnit.attackDistance, remoteUnit.Direction, COLUMN, ROW); List <int> validatedLst = new List <int>(); for (int i = 0; i < waitedLst.Count; i++) { if (gameBoard[waitedLst[i].x, waitedLst[i].y].Key != index) { validatedLst.Add(i); } } if (validatedLst.Count != 0) { answer.Add(unit.Pos); } } } return(answer); }
/// <summary> /// 움직이지 않음 원거리 Unit들의 공격 /// 전송되는 Data /// 공격당한 Unit의 Data /// </summary> /// <param name="waitingUnitLst"></param> private void SendWaiting(List <Vector2> waitingUnitLst) { Console.WriteLine("Waiting Unit 좌표 = " + waitingUnitLst[0].x + ", " + waitingUnitLst[0].y); RemoteUnit attackingUnit = (RemoteUnit)gameBoard[waitingUnitLst[0].x, waitingUnitLst[0].y].Value; if (attackingUnit != null) { List <Vector2> waitedLst = Helper.GetMoving(attackingUnit.Pos, attackingUnit.attackDistance, attackingUnit.Direction, COLUMN, ROW); List <Vector2> validatedLst = new List <Vector2>(); for (int i = 0; i < waitedLst.Count; i++) { if (gameBoard[waitedLst[i].x, waitedLst[i].y].Key == (gameBoard[waitingUnitLst[0].x, waitingUnitLst[0].y].Key == 0 ? 1 : 0)) { validatedLst.Add(waitedLst[i]); } } // 공격할 적이 있는지 검사 if (validatedLst.Count > 0) { Random rnd = new Random(DateTime.Now.Millisecond); int targetIndex = rnd.Next(validatedLst.Count); Unit targetUnit = gameBoard[validatedLst[targetIndex].x, validatedLst[targetIndex].y].Value; attackingUnit.Wait(targetUnit); Packet waitedMsg = Packet.Create((short)PROTOCOL.WaitedUnit); waitedMsg.Push(attackingUnit.Pos.x); waitedMsg.Push(attackingUnit.Pos.y); waitedMsg.Push(attackingUnit.HP); waitedMsg.Push(targetUnit.Pos.x); waitedMsg.Push(targetUnit.Pos.y); waitedMsg.Push(targetUnit.HP); Broadcast(waitedMsg); Thread.Sleep(waitingTime); if (targetUnit.HP <= 0) { players[0].DestoyUnit(targetUnit.Pos); players[1].DestoyUnit(targetUnit.Pos); gameBoard[targetUnit.Pos.x, targetUnit.Pos.y] = EMPTY; } } } }