Ejemplo n.º 1
0
    private void OnUpdateActionPoint(SocketAsyncEventArgs args, byte[] bytes)
    {
        UpdateActionPoint input = UpdateActionPoint.Parser.ParseFrom(bytes);

        if (input.RoomId != RoomId)
        {
            return; // 不是自己房间的消息,略过
        }
        PlayerInfoInRoom piir = GetPlayerInRoom(input.OwnerId);

        if (piir == null)
        {
            ServerRoomManager.Instance.Log($"RoomLogic OnUpdateActionPoint Error - player not found! Id:{input.OwnerId}");
            return;
        }
        UpdateActionPointReply output = new UpdateActionPointReply()
        {
            RoomId         = input.RoomId,
            OwnerId        = input.OwnerId,
            Ret            = true,
            ActionPoint    = piir.ActionPoint,
            ActionPointMax = piir.ActionPointMax,
        };

        ServerRoomManager.Instance.SendMsg(args, ROOM_REPLY.UpdateActionPointReply, output.ToByteArray());
    }
Ejemplo n.º 2
0
    private void OnUpdateActionPointReply(byte[] bytes)
    {
        UpdateActionPointReply input = UpdateActionPointReply.Parser.ParseFrom(bytes);

        if (!input.Ret)
        {
            return;
        }
        if (input.OwnerId == GameRoomManager.Instance.CurrentPlayer.TokenId)
        {
            // 是我自己
            _txtActionPoint.text        = $"{input.ActionPoint}/{input.ActionPointMax}";
            _sliderActionPoint.minValue = 0;
            _sliderActionPoint.maxValue = input.ActionPointMax;
            _sliderActionPoint.value    = input.ActionPoint;

            GameRoomManager.Instance.CurrentPlayer.SetActionPoint(input.ActionPoint, input.ActionPointMax);
        }
        else
        {
            var pi = GameRoomManager.Instance.GetAiPlayer(input.OwnerId);
            if (pi != null)
            {
                pi.SetActionPoint(input.ActionPoint, input.ActionPointMax);
            }
        }
    }
Ejemplo n.º 3
0
        public void RestoreActionPoint(int points)
        {
            AddActionPoint(points);
            UpdateActionPointReply output = new UpdateActionPointReply()
            {
                RoomId         = RoomId,
                OwnerId        = Enter.TokenId,
                Ret            = true,
                ActionPoint    = ActionPoint,
                ActionPointMax = ActionPointMax,
            };

            ServerRoomManager.Instance.SendMsg(Args, ROOM_REPLY.UpdateActionPointReply, output.ToByteArray());
            Debug.Log($"PlayerInfo restoreActionPointOneTime - [{Enter.Account}] 恢复行动点数:{_ACTION_POINT_ADD} - 现在行动点数:{ActionPoint}/{ActionPointMax}");
        }
Ejemplo n.º 4
0
    private void OnTryCommand(SocketAsyncEventArgs args, byte[] bytes)
    {
        TryCommand input = TryCommand.Parser.ParseFrom(bytes);

        if (input.RoomId != RoomId)
        {
            return; // 不是自己房间的消息,略过
        }
        PlayerInfoInRoom piir = GetPlayerInRoom(input.OwnerId);

        if (piir == null)
        {
            string          msg    = "在服务器没有找到该玩家!";
            TryCommandReply output = new TryCommandReply()
            {
                RoomId  = input.RoomId,
                OwnerId = input.OwnerId,
                Ret     = false,
                ErrMsg  = msg,
            };
            ServerRoomManager.Instance.SendMsg(args, ROOM_REPLY.TryCommandReply, output.ToByteArray());
            ServerRoomManager.Instance.Log("RoomLogic OnTryCommand Error - " + msg + $" - Id:{input.OwnerId}");
            return;
        }

        var csv             = CsvDataManager.Instance.GetTable("command_id");
        int actionPointCost = csv.GetValueInt(input.CommandId, "ActionPointCost");

        if (actionPointCost > 0)
        {
            bool   ret = true;
            string msg = "";
            if (actionPointCost != input.ActionPointCost)
            { // 服务器校验一下
                msg = $"行动点数服务器与客户端不一致! {input.ActionPointCost} : {actionPointCost}";
                ret = false;
            }

            if (piir.ActionPoint < input.ActionPointCost)
            {
                msg = "行动点不足, 请稍后再试!";
                ret = false;
            }

            if (!ret)
            {
                TryCommandReply output = new TryCommandReply()
                {
                    RoomId  = input.RoomId,
                    OwnerId = input.OwnerId,
                    Ret     = false,
                    ErrMsg  = msg,
                };
                ServerRoomManager.Instance.SendMsg(args, ROOM_REPLY.TryCommandReply, output.ToByteArray());
                ServerRoomManager.Instance.Log("RoomLogic OnTryCommand Error - " + msg);
                return;
            }
            // 扣除行动点数
            piir.AddActionPoint(-input.ActionPointCost);
        }

        {
            // 行动点发生变化,要通知客户端
            UpdateActionPointReply output = new UpdateActionPointReply()
            {
                RoomId         = input.RoomId,
                OwnerId        = input.OwnerId,
                ActionPoint    = piir.ActionPoint,
                ActionPointMax = piir.ActionPointMax,
                Ret            = true,
            };
            ServerRoomManager.Instance.SendMsg(args, ROOM_REPLY.UpdateActionPointReply, output.ToByteArray());
            TryCommandReply output2 = new TryCommandReply()
            {
                RoomId  = input.RoomId,
                OwnerId = input.OwnerId,
                Ret     = true,
            };
            ServerRoomManager.Instance.SendMsg(args, ROOM_REPLY.TryCommandReply, output2.ToByteArray());
            ServerRoomManager.Instance.Log($"RoomLogic OnTryCommand OK - Permission granted! - CommandId:{input.CommandId} - ActionPointCost:{input.ActionPointCost}");
        }
    }