-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathitems.lua
More file actions
135 lines (112 loc) · 3.47 KB
/
items.lua
File metadata and controls
135 lines (112 loc) · 3.47 KB
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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
local items = {}
function items.check_turn_in(trade, trade_check)
--create trade_return table == trade
--shallow copy
local trade_return = {};
for key, value in pairs(trade) do
trade_return[key] = value;
end
--for every item in trade_check check trade_return
--if item exists in trade_return then
--remove that item from trade_return
--else
--failure
for i = 1, 4 do
local key = "item" .. i;
if(trade_check[key] ~= nil and trade_check[key] ~= 0) then
local found = false;
for j = 1, 4 do
local inst = trade_return["item" .. j];
if(inst.valid and trade_check[key] == inst:GetID()) then
trade_return["item" .. j] = ItemInst();
found = true;
break;
end
end
if(not found) then
return false;
end
end
end
--convert our money into copper then check that we have enough then convert change back
local trade_check_money = 0;
local return_money = 0;
if(trade_check["platinum"] ~= nil and trade_check["platinum"] ~= 0) then
trade_check_money = trade_check_money + (trade_check["platinum"] * 1000);
end
if(trade_check["gold"] ~= nil and trade_check["gold"] ~= 0) then
trade_check_money = trade_check_money + (trade_check["gold"] * 100);
end
if(trade_check["silver"] ~= nil and trade_check["silver"] ~= 0) then
trade_check_money = trade_check_money + (trade_check["silver"] * 10);
end
if(trade_check["copper"] ~= nil and trade_check["copper"] ~= 0) then
trade_check_money = trade_check_money + trade_check["copper"];
end
return_money = return_money + trade_return["platinum"] * 1000 + trade_return["gold"] * 100;
return_money = return_money + trade_return["silver"] * 10 + trade_return["copper"];
if(return_money < trade_check_money) then
return false;
else
return_money = return_money - trade_check_money;
end
--replace trade with trade_return
trade.item1 = trade_return.item1;
trade.item2 = trade_return.item2;
trade.item3 = trade_return.item3;
trade.item4 = trade_return.item4;
trade.platinum = math.floor(return_money / 1000);
return_money = return_money - (trade.platinum * 1000);
trade.gold = math.floor(return_money / 100);
return_money = return_money - (trade.gold * 100);
trade.silver = math.floor(return_money / 10);
return_money = return_money - (trade.silver * 10);
trade.copper = return_money;
return true;
end
function items.return_items(npc, client, trade, text)
text = text or true;
local returned = false;
for i = 1, 4 do
local inst = trade["item" .. i];
if(inst.valid) then
if(eq.is_disc_tome(inst:GetID()) and npc:GetClass() > 19 and npc:GetClass() < 36) then
if(client:GetClass() == npc:GetClass() - 19) then
client:TrainDisc(inst:GetID());
else
npc:Say(string.format("You are not a member of my guild. I will not train you!"));
client:PushItemOnCursor(inst);
returned = true;
end
else
client:PushItemOnCursor(inst);
if(text == true) then
npc:Say(string.format("I have no need for this %s, you can have it back.", client:GetCleanName()));
end
returned = true;
end
end
end
local money = false;
if(trade.platinum ~= 0) then
returned = true;
money = true;
end
if(trade.gold ~= 0) then
returned = true;
money = true;
end
if(trade.silver ~= 0) then
returned = true;
money = true;
end
if(trade.copper ~= 0) then
returned = true;
money = true;
end
if(money == true) then
client:AddMoneyToPP(trade.copper, trade.silver, trade.gold, trade.platinum, true);
end
return returned;
end
return items;