Back to Home

ESO Lua File v100029

ingame/tradewindow/tradewindow.lua

[◄ back to folders ]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
--Trade Manager Prototype
--This is the public interface to the trading system
ZO_TradeManager = ZO_Object:Subclass()
--
--Trade Manager functions
--
function ZO_TradeManager:New(...)
    local manager = ZO_Object.New(self)
    manager:Initialize(...)
    return manager
end
function ZO_TradeManager:Initialize()
    self.target = nil
    self.state = TRADE_STATE_IDLE
    local function OnPlayerActivated()
        TradeCancel() -- Make sure any trades from reloadui are cancelled
        EVENT_MANAGER:UnregisterForEvent("TradeSystem", EVENT_PLAYER_ACTIVATED)
    end
    EVENT_MANAGER:RegisterForEvent("TradeSystem", EVENT_PLAYER_ACTIVATED, OnPlayerActivated)
end
function ZO_TradeManager:InitiateTrade(displayName)
    --can't invite someone if you're trading
    if(self.state == TRADE_STATE_TRADING) then
        ZO_AlertEvent(EVENT_TRADE_ELEVATION_FAILED, TRADE_ACTION_RESULT_YOU_ARE_BUSY)
        return
    end
    if IsConsoleUI() then
        local function TradeInviteCallback(success)
            if success then
                TradeInviteByName(displayName)
            end
        end
        ZO_ConsoleAttemptInteractOrError(TradeInviteCallback, displayName, ZO_PLAYER_CONSOLE_INFO_REQUEST_DONT_BLOCK, ZO_CONSOLE_CAN_COMMUNICATE_ERROR_ALERT, ZO_ID_REQUEST_TYPE_DISPLAY_NAME, displayName)
    else
        if IsIgnored(displayName) then
            ZO_Alert(UI_ALERT_CATEGORY_ALERT, nil, SI_GROUP_ALERT_INVITE_PLAYER_BLOCKED)
            return
        end
        TradeInviteByName(displayName)
    end    
end
function ZO_TradeManager:CancelTradeInvite()
end
function ZO_TradeManager:AddItemToTrade(bagId, slotIndex)
    TradeAddItem(bagId, slotIndex)
end
--status functions
function ZO_TradeManager:IsTrading()
    return self.state == TRADE_STATE_TRADING
end
function ZO_TradeManager:IsWaiting()
    return self.state == TRADE_STATE_INVITE_WAITING
end
function ZO_TradeManager:IsConsidering()
    return self.state == TRADE_STATE_INVITE_CONSIDERING
end
function ZO_TradeManager:IsIdle()
    return self.state == TRADE_STATE_IDLE
end
function ZO_TradeManager:CanTradeItem(itemData)
    local bagId, slotIndex = itemData.bagId, itemData.slotIndex
    if IsItemBound(bagId, slotIndex) or itemData.stolen or itemData.isPlayerLocked then
        return false
    end
            
    if IsItemBoPAndTradeable(bagId, slotIndex) and not IsDisplayNameInItemBoPAccountTable(bagId, slotIndex, self.partnerUndecoratedDisplayName) then
        return false
    end
    return true
end
TRADE_WINDOW = ZO_TradeManager:New()