Esempio n. 1
0
    public void OnReceiveTurn(Move[][] turn)
    {
        if (otherTurn == null)
        {
            otherTurn = turn;
            return;
        }
        Debug.Assert(otherTurn[0][0].piece.owner != turn[0][0].piece.owner); // just for checking, definitely will have error in the future
        TurnLog           turnLog        = new TurnLog();
        List <PhaseLog[]> tempPhasesList = new List <PhaseLog[]>();

        for (int i = 0; i < 3; i++)
        {
            Move[] otherMoves = otherTurn[0];
            Move[] moves      = turn[0];
            Move[] allMoves   = new Move[moves.Length + otherMoves.Length];
            moves.CopyTo(allMoves, 0);
            otherMoves.CopyTo(allMoves, moves.Length);
            PhaseLog[] phaseLogs = CalculateNextPhase(allMoves);
            tempPhasesList.Add(phaseLogs);
        }
        turnLog.phases = tempPhasesList.ToArray();
        otherTurn      = null;
        networkManager.SendTurnLog(turnLog);
    }
Esempio n. 2
0
 public BattleTurnEvent(TurnLog turnLog)
 {
     Actions = new BattleAction[turnLog.Actions.Count];
     for (var x = 0; x < turnLog.Actions.Count; x++)
     {
         Actions[x] = turnLog.Actions[x];
     }
 }
        public Task UpdateTurn(string playerId, [FromBody] TurnLog turnLog)
        {
            _logger.LogInformation("Turnlog");

            return(_hubContext
                   .Clients
                   .Group(playerId)
                   .SendAsync("newturn", turnLog));
        }
Esempio n. 4
0
 void OnReceiveTurnLog(TurnLog turnLog)
 {
     foreach (PhaseLog[] phaseLogs in turnLog.phases)
     {
         foreach (PhaseLog phaseLog in phaseLogs)
         {
             Debug.LogFormat("MPTester OnReceiveTurnLog UID {0}, CombatSq {1}, FinalSq {2}", phaseLog.piece.uid, phaseLog.moveLog.combatSquare, phaseLog.moveLog.finalSquare);
         }
     }
 }
Esempio n. 5
0
        private void CheckForCastlingAndMove(TurnLog turnLog, PieceMovement pieceMovement)
        {
            CastlingMovementSpecification castlingMovementSpecification = CastlingMovementSpecification.Create(this);

            if (castlingMovementSpecification.IsSatisfied(pieceMovement))
            {
                CastlingEvaluationResult castlingEvaluationResult = CastlingEvaluator.EvaluateCastling(this, pieceMovement);
                MovePiece(turnLog, PieceMovement.Create(castlingEvaluationResult.Rook, castlingEvaluationResult.From, castlingEvaluationResult.To));
            }
        }
Esempio n. 6
0
        private void MovePiece(TurnLog turnLog, PieceMovement pieceMovement)
        {
            Square originSquare      = GetSquare(pieceMovement.Piece);
            Square destinationSquare = GetSquare(pieceMovement.To.Id);

            destinationSquare.LandPiece(pieceMovement.Piece);
            originSquare.RemovePiece();

            pieceMovement.Piece.Moved();

            turnLog.AddEvent(TurnEvent.CreateMovedEvent(Position.Create(pieceMovement.From.Id), Position.Create(pieceMovement.To.Id)));
        }
Esempio n. 7
0
        public void Handle(TurnLog turnLog)
        {
            _game.CurrentTurnPlayer.LogMove(turnLog);

            if (turnLog.TurnEvents.Any(@event => @event.EventType == EventType.GameOver))
            {
                _game.GameOver(_game.CurrentTurnPlayer);
            }
            else
            {
                _game.SwitchTurn();
            }
        }
Esempio n. 8
0
    public void SendTurnLog(TurnLog turnLog)
    {
        if (!PhotonNetwork.IsMasterClient)
        {
            return; // only master can send turn logs
        }
        RaiseEventOptions raiseEventOptions = new RaiseEventOptions {
            Receivers = ReceiverGroup.All
        };
        SendOptions sendOptions = new SendOptions {
            Reliability = true
        };

        byte[] data = serializeObject(turnLog);
        PhotonNetwork.RaiseEvent(SEND_TURN_LOG_NEVENT, data, raiseEventOptions, sendOptions);
    }
Esempio n. 9
0
        public ActionResult Index(TurnLog TurnLog, EFPagingInfo <TurnLog> p)
        {
            if (!TurnLog.UId.IsNullOrEmpty())
            {
                p.SqlWhere.Add(f => f.UId == TurnLog.UId);
            }
            if (!TurnLog.TId.IsNullOrEmpty())
            {
                p.SqlWhere.Add(f => f.TId == TurnLog.TId);
            }
            p.OrderByList.Add("Id", "DESC");
            IPageOfItems <TurnLog> TurnLogList = Entity.Selects <TurnLog>(p);

            ViewBag.TurnLogList = TurnLogList;
            ViewBag.TurnLog     = TurnLog;
            return(View());
        }
Esempio n. 10
0
        private bool CheckForCapturing(TurnLog turnLog, PieceMovement pieceMovement)
        {
            bool   isGameOver        = false;
            Square destinationSquare = GetSquare(pieceMovement.To.Id);

            if (!destinationSquare.IsEmpty)
            {
                Piece removedPiece = destinationSquare.RemovePiece();
                turnLog.AddEvent(TurnEvent.CreateCapturedEvent(Position.Create(pieceMovement.To.Id)));
                if (removedPiece.Type == PieceType.King)
                {
                    isGameOver = true;
                }
            }

            return(isGameOver);
        }
        public void Take(int LId)
        {
            if (BasicUsers.Id.IsNullOrEmpty())
            {//未登录
                Response.Write("2");
                return;
            }
            TurnLog TurnLog = Entity.TurnLog.FirstOrDefault(n => n.Id == LId);

            if (TurnLog == null)
            {
                Response.Write("2");
                return;
            }
            if (TurnLog.UId != BasicUsers.Id)
            {
                Response.Write("2");
                return;
            }
            if (TurnLog.State != 1)
            {
                Response.Write("1");
                return;
            }
            TurnLog.TakeTime = DateTime.Now;
            TurnLog.State    = 2;
            //开始
            //获取用户信息
            if (BasicUsers != null)
            {
                //帐户变动记录
                int     USERSID  = BasicUsers.Id;
                string  TNUM     = TurnLog.Id.ToString();
                decimal PAYMONEY = TurnLog.Amoney;
                string  SP_Ret   = Entity.SP_UsersMoney(USERSID, TNUM, PAYMONEY, 7, "");
                if (SP_Ret != "3")
                {
                    Utils.WriteLog(string.Format("U{0},O{1},T{2}:{3}【{4}】", USERSID, TNUM, 7, PAYMONEY, SP_Ret), "SP_UsersMoney");
                }
            }
            //结束
            Response.Write("0");
        }
Esempio n. 12
0
        public bool HandleMove(PieceMovement pieceMovement)
        {
            if (!CanBeMovedToRequestedPosition(pieceMovement))
            {
                return(false);
            }

            TurnLog turnLog = TurnLog.Create(pieceMovement);

            bool isGameOver = CheckForCapturing(turnLog, pieceMovement);

            MovePiece(turnLog, pieceMovement);
            CheckForCastlingAndMove(turnLog, pieceMovement);

            if (isGameOver)
            {
                turnLog.AddEvent(TurnEvent.CreateGameOverEvent());
            }

            TurnEnded?.Invoke(turnLog);

            return(true);
        }
Esempio n. 13
0
    public void OnEvent(EventData photonEvent)
    {
        byte eventCode = photonEvent.Code;

        switch (eventCode)
        {
        case GAME_START_NEVENT:
            OnGameStart?.Invoke();
            break;

        case SEND_TURN_NEVENT:
            byte[]   data = (byte[])photonEvent.CustomData;
            Move[][] turn = (Move[][])deserializeData(data);
            OnReceiveTurn?.Invoke(turn);
            break;

        case SEND_TURN_LOG_NEVENT:
            byte[]  turnData = (byte[])photonEvent.CustomData;
            TurnLog turnLog  = (TurnLog)deserializeData(turnData);
            OnReceiveTurnLog?.Invoke(turnLog);
            break;
        }
    }
Esempio n. 14
0
 private MakeMoveResult(bool success, TurnLog turnLog)
 {
     Success = success;
     TurnLog = turnLog;
 }
Esempio n. 15
0
 internal static MakeMoveResult CreateSuccessResult(TurnLog turnLog) => new MakeMoveResult(true, turnLog);
Esempio n. 16
0
 public void LogMove(TurnLog turnLog)
 {
     TurnLogs.Add(turnLog);
 }
        public void Ajax(int TId)
        {
            try
            {
                System.Web.HttpContext.Current.Response.AddHeader("content-type", "application/json");
            }
            catch (Exception) { }
            Turntable Turntable = Entity.Turntable.FirstOrDefault(n => n.Id == TId);

            #region 活动状态
            if (Turntable == null)
            {
                Response.Write("{\"index\":\"-1\",\"state\":\"99\",\"times\":\"0\"}");
                return;
            }
            if (Turntable.State == 2)
            {//活动结束
                Response.Write("{\"index\":\"-1\",\"state\":\"3\",\"times\":\"0\"}");
                return;
            }
            if (Turntable.State != 1)
            {//状态异常
                Response.Write("{\"index\":\"-1\",\"state\":\"99\",\"times\":\"0\"}");
                return;
            }
            if (Turntable.STime > DateTime.Now)
            {//未开始
                Response.Write("{\"index\":\"-1\",\"state\":\"4\",\"times\":\"0\"}");
                return;
            }
            if (Turntable.ETime < DateTime.Now)
            {//已结束
                Response.Write("{\"index\":\"-1\",\"state\":\"3\",\"times\":\"0\"}");
                return;
            }
            #endregion
            if (BasicUsers.Id.IsNullOrEmpty())
            {//未登录
                Response.Write("{\"index\":\"-1\",\"state\":\"2\",\"times\":\"0\"}");
                return;
            }
            TurnUsers TurnUsers = Entity.TurnUsers.FirstOrDefault(n => n.UId == BasicUsers.Id);
            if (TurnUsers.Times == 0)
            {
                Response.Write("{\"index\":\"-1\",\"state\":\"1\",\"times\":\"0\"}");
                return;
            }
            //抽奖开始
            //获取奖品列表
            IList <TurnProc> List = Entity.TurnProc.Where(n => n.TId == TId).OrderBy(n => n.Id).ToList();
            int i = 1; int num = Turntable.BaseNum;
            int stnum = 0;
            foreach (var p in List)
            {//生成范围
                p.Index = i;
                num     = num - (p.Num - p.UNum);
                p.StNum = stnum;                    //不含
                p.EnNum = stnum + (p.Num - p.UNum); //含
                stnum   = p.EnNum;
                i++;
            }
            //添加谢谢参与项
            TurnProc Temp = new TurnProc();
            Temp.Id     = 0;
            Temp.TId    = 0;
            Temp.Name   = "谢谢参与";
            Temp.Amoney = 0;
            Temp.Num    = num;
            Temp.UNum   = 0;
            Temp.Index  = i;
            Temp.StNum  = stnum;
            Temp.EnNum  = stnum + num;
            List.Add(Temp);
            //生成随机数
            Random R   = new Random();
            int    Ran = R.Next(1, Turntable.BaseNum);
            //读取对应奖项
            TurnProc TurnProc = List.FirstOrDefault(n => n.StNum < Ran && n.EnNum >= Ran);
            if (TurnProc == null)
            {
                TurnProc = List.FirstOrNew(n => n.Id == 0);
            }
            //这里可以加一条规则,中奖超过多少次以后不再中奖~~
            TurnUsers.Times--;     //抽奖次数减少
            TurnUsers.UsedTimes++; //抽奖资料增加
            if (TurnProc.Id == 0)
            {                      //未中奖处理
            }
            else
            {                        //中奖处理
                TurnUsers.InTimes++; //中奖资料增加
                TurnProc.UNum++;     //奖品送出数量增加
            }
            //添加抽奖记录
            TurnLog TurnLog = new TurnLog();
            TurnLog.UId     = BasicUsers.Id;
            TurnLog.TId     = Turntable.Id;
            TurnLog.TPId    = TurnProc.Id;
            TurnLog.Name    = TurnProc.Name;
            TurnLog.Amoney  = TurnProc.Amoney;
            TurnLog.Num     = 1;
            TurnLog.State   = 1;
            TurnLog.AddTime = DateTime.Now;
            Entity.TurnLog.AddObject(TurnLog);
            Entity.SaveChanges();
            Response.Write("{\"index\":\"" + TurnProc.Index + "\",\"state\":\"0\",\"times\":\"" + TurnUsers.Times + "\",\"log\":\"" + TurnLog.Id + "\"}");
        }