Beispiel #1
0
    private void OnUpdateRes(SocketAsyncEventArgs args, byte[] bytes)
    {
        UpdateRes input = UpdateRes.Parser.ParseFrom(bytes);

        if (input.RoomId != RoomId)
        {
            return; // 不是自己房间的消息,略过
        }
        // 注意: piir不见得是自己, 可能是任何玩家
        PlayerInfoInRoom piir = GetPlayerInRoom(input.OwnerId);

        if (piir == null)
        {
            ServerRoomManager.Instance.Log($"RoomLogic OnUpdateRes Error - player not found! Id:{input.OwnerId}");
            return;
        }
        UpdateResReply output = new UpdateResReply()
        {
            RoomId  = input.RoomId,
            OwnerId = input.OwnerId,
            Ret     = true,
            Wood    = piir.Wood,
            Food    = piir.Food,
            Iron    = piir.Iron,
        };

        ServerRoomManager.Instance.SendMsg(args, ROOM_REPLY.UpdateResReply, output.ToByteArray());
    }
Beispiel #2
0
    private void OnHarvestStop(SocketAsyncEventArgs args, byte[] bytes)
    {
        HarvestStop input = HarvestStop.Parser.ParseFrom(bytes);

        if (input.RoomId != RoomId)
        {
            return; // 不是自己房间的消息,略过
        }
        if (input.CellIndex == 0)
        {
            Debug.LogError("RoomLogic OnHarvestStop Error - Actor position is lost!");
        }
        // 修改地图上的资源数据
        var hr = ResManager.GetRes(input.CellIndex);

        if (hr == null)
        {
            hr = new ResInfo();
            ResManager.AddRes(input.CellIndex, hr);
        }

        hr.SetAmount((ResInfo.RESOURCE_TYPE)input.ResType, input.ResRemain);

        // 修改玩家身上的资源数据
        PlayerInfoInRoom piir = GetPlayerInRoom(input.OwnerId);

        if (piir == null)
        {
            ServerRoomManager.Instance.Log($"RoomLogic OnHarvestStop Error - player not found in server! Id:{input.OwnerId}");
            return;
        }

        switch ((ResInfo.RESOURCE_TYPE)input.ResType)
        {
        case ResInfo.RESOURCE_TYPE.WOOD:
            piir.AddWood(input.ResHarvest);
            break;

        case ResInfo.RESOURCE_TYPE.FOOD:
            piir.AddFood(input.ResHarvest);
            break;

        case ResInfo.RESOURCE_TYPE.IRON:
            piir.AddIron(input.ResHarvest);
            break;
        }

        HarvestStopReply output = new HarvestStopReply()
        {
            RoomId     = input.RoomId,
            OwnerId    = input.OwnerId,
            ActorId    = input.ActorId,
            CellIndex  = input.CellIndex,
            ResType    = input.ResType,
            ResRemain  = input.ResRemain,
            ResHarvest = input.ResHarvest,
            Ret        = true,
        };

        BroadcastMsg(ROOM_REPLY.HarvestStopReply, output.ToByteArray());

        // 发送给客户端刷新玩家身上的资源数量
        UpdateResReply output2 = new UpdateResReply()
        {
            RoomId  = input.RoomId,
            OwnerId = input.OwnerId,
            Ret     = true,
            Wood    = piir.Wood,
            Food    = piir.Food,
            Iron    = piir.Iron,
        };

        ServerRoomManager.Instance.SendMsg(args, ROOM_REPLY.UpdateResReply, output2.ToByteArray());
    }