1local context = G.botContext
2local Panels = context.Panels
3
4Panels.AttackLeaderTarget = function(parent)
5 local toAttack = nil
6 context.onMissle(function(missle)
7 if not context.storage.attackLeader or context.storage.attackLeader:len() == 0 then
8 return
9 end
10 local src = missle:getSource()
11 if src.z ~= context.posz() then
12 return
13 end
14 local from = g_map.getTile(src)
15 local to = g_map.getTile(missle:getDestination())
16 if not from or not to then
17 return
18 end
19 local fromCreatures = from:getCreatures()
20 local toCreatures = to:getCreatures()
21 if #fromCreatures ~= 1 or #toCreatures ~= 1 then
22 return
23 end
24 local c1 = fromCreatures[1]
25 if c1:getName():lower() == context.storage.attackLeader:lower() then
26 toAttack = toCreatures[1]
27 end
28 end)
29 context.macro(50, "Attack leader's target", nil, function()
30 if toAttack and context.storage.attackLeader:len() > 0 and toAttack ~= g_game.getAttackingCreature() then
31 g_game.attack(toAttack)
32 toAttack = nil
33 end
34 end, parent)
35 context.addTextEdit("attackLeader", context.storage.attackLeader or "player name", function(widget, text)
36 context.storage.attackLeader = text
37 end, parent)
38end
39
40
41Panels.LimitFloor = function(parent)
42 context.onPlayerPositionChange(function(pos)
43 if context.storage.limitFloor then
44 local gameMapPanel = modules.game_interface.getMapPanel()
45 if gameMapPanel then
46 gameMapPanel:lockVisibleFloor(pos.z)
47 end
48 end
49 end)
50
51 local switch = context.addSwitch("limitFloor", "Don't show higher floors", function(widget)
52 widget:setOn(not widget:isOn())
53 context.storage.limitFloor = widget:isOn()
54 local gameMapPanel = modules.game_interface.getMapPanel()
55 if gameMapPanel then
56 if context.storage.limitFloor then
57 gameMapPanel:lockVisibleFloor(context.posz())
58 else
59 gameMapPanel:unlockVisibleFloor()
60 end
61 end
62 end, parent)
63 switch:setOn(context.storage.limitFloor)
64end
65
66Panels.AntiPush = function(parent)
67 if not parent then
68 parent = context.panel
69 end
70
71 local panelName = "antiPushPanel"
72 local ui = g_ui.createWidget("ItemsPanel", parent)
73 ui:setId(panelName)
74
75 if not context.storage[panelName] then
76 context.storage[panelName] = {}
77 end
78
79 ui.title:setText("Anti push")
80 ui.title:setOn(context.storage[panelName].enabled)
81 ui.title.onClick = function(widget)
82 context.storage[panelName].enabled = not context.storage[panelName].enabled
83 widget:setOn(context.storage[panelName].enabled)
84 end
85
86 if type(context.storage[panelName].items) ~= 'table' then
87 context.storage[panelName].items = {3031, 3035, 0, 0, 0}
88 end
89
90 for i=1,5 do
91 ui.items:getChildByIndex(i).onItemChange = function(widget)
92 context.storage[panelName].items[i] = widget:getItemId()
93 end
94 ui.items:getChildByIndex(i):setItemId(context.storage[panelName].items[i])
95 end
96
97 context.macro(100, function()
98 if not context.storage[panelName].enabled then
99 return
100 end
101 local tile = g_map.getTile(context.player:getPosition())
102 if not tile then
103 return
104 end
105 local topItem = tile:getTopUseThing()
106 if topItem and topItem:isStackable() then
107 topItem = topItem:getId()
108 else
109 topItem = 0
110 end
111 local candidates = {}
112 for i, item in pairs(context.storage[panelName].items) do
113 if item >= 100 and item ~= topItem and context.findItem(item) then
114 table.insert(candidates, item)
115 end
116 end
117 if #candidates == 0 then
118 return
119 end
120 if type(context.storage[panelName].lastItem) ~= 'number' or context.storage[panelName].lastItem > #candidates then
121 context.storage[panelName].lastItem = 1
122 end
123 local item = context.findItem(candidates[context.storage[panelName].lastItem])
124 g_game.move(item, context.player:getPosition(), 1)
125 context.storage[panelName].lastItem = context.storage[panelName].lastItem + 1
126 end)
127end
128