-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path---mode_item_generic.lua
More file actions
110 lines (92 loc) · 2.72 KB
/
---mode_item_generic.lua
File metadata and controls
110 lines (92 loc) · 2.72 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
---@diagnostic disable: undefined-global
require(GetScriptDirectory() .. "/utility")
local npcBot = GetBot();
-- Debugg
local function printObjectFields(object)
for key, value in pairs(object) do
if type(value) == "table" then
print(key .. ":")
printObjectFields(value) -- Рекурсивный вызов для таблиц
else
print(key .. ": " .. tostring(value)) -- Преобразование значения в строку
end
end
end
function GetMostExpensiveBackpackItem()
local expensiveItem = nil;
local maxCost = 0;
for i = 6, 8 do
local item = npcBot:GetItemInSlot(i);
local cost = GetItemCost(item:GetName());
if cost > maxCost and not string.find(item:GetName(), "ward")
then
expensiveItem = item;
maxCost = cost;
end
end
return expensiveItem;
end
function GetMostCheapestMainItem()
local cheapestItem = nil;
local minCost = 10000;
for i = 0, 5 do
local item = npcBot:GetItemInSlot(i);
local cost = GetItemCost(item:GetName());
if cost < minCost and not string.find(item:GetName(), "ward")
then
cheapestItem = item;
minCost = cost;
end
end
return cheapestItem;
end
function GetDesire()
--local itemList = GetDroppedItemList();
--print(printObjectFields(itemList))
if not utility.IsHero(npcBot) or utility.IsCloneMeepo(npcBot)
then
return BOT_MODE_DESIRE_NONE;
end
local emptyMainSlot = utility.GetEmptyMainItemSlot();
local emptyBackpackSlot = utility.GetEmptyBackpackItemSlot();
local cheapestMainItem = GetMostCheapestMainItem();
local expensiveBackpackItem = GetMostExpensiveBackpackItem();
index1 = nil;
index2 = nil;
if expensiveBackpackItem ~= nil and emptyMainSlot ~= nil
then
index1 = npcBot:FindItemSlot(expensiveBackpackItem:GetName());
index2 = emptyMainSlot;
npcBot:ActionImmediate_Chat("Хочу переложить в пустой слот: " .. index1 .. " и " .. index2, true);
return BOT_MODE_DESIRE_ABSOLUTE;
elseif expensiveBackpackItem ~= nil and cheapestMainItem ~= nil
then
if GetItemCost(expensiveBackpackItem:GetName()) > GetItemCost(cheapestMainItem:GetName())
then
index1 = npcBot:FindItemSlot(expensiveBackpackItem:GetName());
index2 = npcBot:FindItemSlot(cheapestMainItem:GetName());
npcBot:ActionImmediate_Chat("Хочу переложить: " .. index1 .. " и " .. index2, true);
return BOT_MODE_DESIRE_ABSOLUTE;
end
end
return BOT_ACTION_DESIRE_NONE;
end
function OnStart()
end
function OnEnd()
npcBot:SetTarget(nil);
index1 = nil;
index2 = nil;
end
function Think()
if utility.IsBusy(npcBot)
then
return;
end
if index1 ~= nil and index2 ~= nil
then
npcBot:ActionImmediate_Chat("Перекладываю вещи.", true);
npcBot:ActionImmediate_SwapItems(index1, index2);
return;
end
end