Ejemplo n.º 1
0
    private static void HandleFinalizeTrade(GameSession session)
    {
        TradeInventory tradeInventory = session.Player.TradeInventory;
        Player         otherPlayer    = tradeInventory.OtherPlayer;

        if (!otherPlayer.Session.Connected())
        {
            HandleCloseTrade(session);
            return;
        }

        TradeInventory otherPlayerTradeInventory = tradeInventory.OtherPlayer?.TradeInventory;

        if (otherPlayerTradeInventory is null)
        {
            return;
        }

        if (!otherPlayerTradeInventory.IsLocked && !tradeInventory.IsLocked)
        {
            return;
        }

        session.Send(TradePacket.FinalizeTrade(true));
        otherPlayer.Session.Send(TradePacket.FinalizeTrade(false));

        // Trade items
        GetSumMesos(session.Player, -tradeInventory.Mesos, otherPlayerTradeInventory.Mesos);
        otherPlayerTradeInventory.SendItems(session.Player, true);
        GetSumMesos(otherPlayer, -otherPlayerTradeInventory.Mesos, tradeInventory.Mesos);
        tradeInventory.SendItems(otherPlayer, true);

        session.Send(TradePacket.TradeStatus(true));
        otherPlayer.Session?.Send(TradePacket.TradeStatus(true));

        session.Player.TradeInventory = null;
        otherPlayer.TradeInventory    = null;
    }
Ejemplo n.º 2
0
    private static void HandleCloseTrade(GameSession session)
    {
        TradeInventory tradeInventory = session.Player.TradeInventory;

        if (tradeInventory is null)
        {
            return;
        }

        Player otherPlayer = tradeInventory.OtherPlayer;

        // Return items back to player's inventory
        tradeInventory.SendItems(session.Player, false);
        tradeInventory = null;

        if (otherPlayer?.TradeInventory is null)
        {
            return;
        }

        session.Send(TradePacket.TradeStatus(false));
        otherPlayer.Session?.Send(TradePacket.TradeStatus(false));
    }