Beispiel #1
0
    public void BackToMaintown()
    {
        CGExitInstance exitInstance = new CGExitInstance();

        exitInstance.AccountId = Game.DataManager.AccountData.Uid;
        exitInstance.PlayerId  = Game.DataManager.MyPlayer.Data.ID;
        exitInstance.Reason    = 2;
        Game.NetworkManager.SendToLobby(MessageId_Send.CGExitInstance, exitInstance);
    }
Beispiel #2
0
 private void OnPlayerDead(ulong playerId)
 {
     if (playerId == MyMapPlayer.Data.Id)
     {
         CGExitInstance exitInstance = new CGExitInstance();
         exitInstance.AccountId = Game.DataManager.AccountData.Uid;
         exitInstance.PlayerId  = Game.DataManager.MyPlayer.Data.ID;
         exitInstance.Reason    = 1;
         Game.NetworkManager.SendToLobby(MessageId_Send.CGExitInstance, exitInstance);
     }
 }
Beispiel #3
0
    public override void Handle(object sender, IMessage packet)
    {
        base.Handle(sender, packet);
        CGExitInstance data = packet as CGExitInstance;
        //处理完数据和逻辑后,发送消息通知客户端
        PBAccountData      accountData      = GetSavedData <PBAccountData>(ACCOUNT_DATA_KEY);
        PBMapPlayerData    mapPlayerData    = GetSavedData <PBMapPlayerData>(MAP_PLAYER_DATA_KEY);
        PBPlayerData       playerData       = GetSavedData <PBPlayerData>(PLAYER_DATA_KEY);
        PBPlayerDetailData playerDetailData = GetSavedData <PBPlayerDetailData>(PLAYER_DETAIL_DATA_KEY);

        if (data.AccountId != accountData.Uid)
        {
            return;
        }
        if (data.PlayerId != playerData.PlayerId)
        {
            return;
        }

        AddExp(playerData, mapPlayerData.AddedExp);
        playerDetailData.Items.Clear();
        playerDetailData.Items.Add(mapPlayerData.Items);
        playerData.Gold += mapPlayerData.PlayerData.Gold;
        playerData.Food += mapPlayerData.PlayerData.Food;
        playerDetailData.Cards.Add(mapPlayerData.RewardCards);
        playerDetailData.Items.Add(mapPlayerData.RewardItems);

        SaveData(MAP_PLAYER_DATA_KEY, null);
        SaveData(PLAYER_DATA_KEY, playerData);
        SaveData(PLAYER_DETAIL_DATA_KEY, playerDetailData);

        GCExitInstance exitInstance = new GCExitInstance();

        exitInstance.AccountId = accountData.Uid;
        exitInstance.PlayerId  = playerData.PlayerId;
        exitInstance.Reason    = data.Reason;
        exitInstance.Gold      = mapPlayerData.PlayerData.Gold;
        exitInstance.Food      = mapPlayerData.PlayerData.Food;
        exitInstance.Cards.Add(mapPlayerData.RewardCards);
        exitInstance.Items.Add(mapPlayerData.RewardItems);

        SendToClient(MessageId_Receive.GCExitInstance, exitInstance);
        GCUpdatePlayerData updatePlayerData = new GCUpdatePlayerData();

        updatePlayerData.AccountData      = accountData;
        updatePlayerData.PlayerData       = playerData;
        updatePlayerData.PlayerDetailData = playerDetailData;
        SendToClient(MessageId_Receive.GCUpdatePlayerData, updatePlayerData);
    }
Beispiel #4
0
    public override void Handle(object sender, IMessage packet)
    {
        base.Handle(sender, packet);
        CGMapPlayerMove data = packet as CGMapPlayerMove;
        //处理完数据和逻辑后,发送消息通知客户端
        GCMapPlayerMove mapPlayerMove = new GCMapPlayerMove();
        PBMapPlayerData mapPlayerData = GetSavedData <PBMapPlayerData>(MAP_PLAYER_DATA_KEY);
        PBMapLayerData  mapLayerData  = GetSavedData <PBMapLayerData>(MAP_LAYER_DATA_KEY);

        mapPlayerMove.PlayerId = mapPlayerData.PlayerData.PlayerId;
        int distance = System.Math.Abs(data.TargetX - mapPlayerData.PlayerPosX) + System.Math.Abs(data.TargetY - mapPlayerData.PlayerPosY);

        if (distance != 1)
        {
            mapPlayerMove.Result = 1;
            SendToClient(MessageId_Receive.GCMapPlayerMove, mapPlayerMove);
            return;
        }
        //位置更新
        mapPlayerData.PlayerPosX = data.TargetX;
        mapPlayerData.PlayerPosY = data.TargetY;
        mapPlayerMove.X          = data.TargetX;
        mapPlayerMove.Y          = data.TargetY;
        //食物血量
        if (mapPlayerData.PlayerData.Food > 0)
        {
            mapPlayerData.PlayerData.Food--;
            mapPlayerData.PlayerData.Hp = Math.Min(mapPlayerData.PlayerData.Hp + 1, mapPlayerData.PlayerData.MaxHp);
        }
        else
        {
            mapPlayerData.PlayerData.Hp--;
            mapPlayerData.PlayerData.Food = 0;
            if (mapPlayerData.PlayerData.Hp <= 0)
            {
                CGExitInstanceHandler exitInstanceHandler = new CGExitInstanceHandler();
                CGExitInstance        exitInstance        = new CGExitInstance();
                exitInstance.AccountId = GetSavedData <PBAccountData>(ACCOUNT_DATA_KEY).Uid;
                exitInstance.PlayerId  = mapPlayerData.PlayerData.PlayerId;
                exitInstance.Reason    = 1;
                exitInstanceHandler.Handle(this, exitInstance);
                return;
            }
        }


        //卡片地图的逻辑触发
        if (mapLayerData.PointState[data.TargetY * mapLayerData.Width + data.TargetX] == 0)
        {
            mapLayerData.PointState[data.TargetY * mapLayerData.Width + data.TargetX] = 1;
        }
        //保存
        SaveData(MAP_PLAYER_DATA_KEY, mapPlayerData);


        mapPlayerMove.Result = 0;
        SendToClient(MessageId_Receive.GCMapPlayerMove, mapPlayerMove);
        GCUpdateMapPlayerData updateMapPlayerData = new GCUpdateMapPlayerData();

        updateMapPlayerData.PlayerId      = mapPlayerData.PlayerData.PlayerId;
        updateMapPlayerData.MapPlayerData = mapPlayerData;
        SendToClient(MessageId_Receive.GCUpdateMapPlayerData, updateMapPlayerData);
    }