diff --git a/candybot.lua b/candybot.lua index f831ae1..df32897 100644 --- a/candybot.lua +++ b/candybot.lua @@ -166,7 +166,7 @@ function CandyBot.getWriteDir() end function CandyBot.getOptions() - local char = g_game.getCharacterName() + local char = g_game.getCharacterName() .. '@' .. tostring(G.host) .. ':' .. tostring(G.port) return CandyBot.options and CandyBot.options[char] or CandyBot.defaultOptions end diff --git a/classes/lootprocedure.lua b/classes/lootprocedure.lua index c13d99a..c4ec905 100644 --- a/classes/lootprocedure.lua +++ b/classes/lootprocedure.lua @@ -179,11 +179,9 @@ function LootProcedure:loot(container) -- it is most probably this container self:useContainer(cid) end if item:isContainer() then - print('opening bp... from container ' .. tostring(cid)) local proc = OpenProcedure.create(item, 10000) self:useContainer(cid) connect(proc, { onFinished = function(container) - print('opening bp... success! from container ' .. tostring(cid)) table.removevalue(self.openProc, proc) self:freeContainer(cid) self:loot(container) diff --git a/classes/moveprocedure.lua b/classes/moveprocedure.lua index 68f34bf..cc585a2 100644 --- a/classes/moveprocedure.lua +++ b/classes/moveprocedure.lua @@ -99,9 +99,20 @@ end function MoveProcedure:tryMove() self.count = math.min(self.thing:getCount(), self.count) + self:highlightItem(self.thing, true) g_game.move(self.thing, self.position, self.count) end +function MoveProcedure:highlightItem(item, enabled) + local pos = item:getPosition() + local container = g_game.getContainers()[pos.y-64] + if not container or not container.itemsPanel then return false end + local itemWidget = container.itemsPanel:getChildById('item' .. pos.z) + if itemWidget then + itemWidget:setBorderWidth(enabled and 1 or 0) + end +end + function MoveProcedure:onUpdateItem(container, slot, item, oldItem) if container:getId() == self.container:getId() and Position.equals(item:getPosition(), self.thing:getPosition()) then local countChange = oldItem:getCount() - item:getCount() @@ -188,6 +199,8 @@ function MoveProcedure:clean() self:stopTryMove() + self:highlightItem(self.thing, false) + if self.hooks then disconnect(Container, self.hooks) end diff --git a/classes/node.lua b/classes/node.lua index 55b3c18..8888fc3 100644 --- a/classes/node.lua +++ b/classes/node.lua @@ -153,8 +153,10 @@ end function Node:toString() if self:hasPosition() then return tostring(self.type) .. ':' .. tostring(self.pos.x) .. ':' .. tostring(self.pos.y) .. ':' .. tostring(self.pos.z) - else + elseif self.type == Node.SCRIPT then return tostring(self.type) .. ':' .. tostring(self.script) + elseif self.type == Node.LABEL then + return tostring(self.type) .. ':' .. tostring(self.text) end end diff --git a/modules/03-pvp/events/healer.lua b/modules/03-pvp/events/healer.lua new file mode 100644 index 0000000..12cabfe --- /dev/null +++ b/modules/03-pvp/events/healer.lua @@ -0,0 +1,50 @@ +--[[ + @Authors: zygzagZ + @Details: Friend healer event logic +]] + +PvpModule.Healer = {} +Healer = PvpModule.Healer + +-- Variables + +Healer.lastTarget = 0 + +-- Methods + +function Healer.init() + +end + +function Healer.terminate() + +end + +function Healer.connect() + connect(Player, { onHealthPercentChange = Healer.onHealthChange }) + addEvent(function() + local spec = g_map.getSpectators(g_game.getLocalPlayer():getPosition(), true) + for k, v in pairs(spec) do + if v:isPlayer() then + Healer.onHealthChange(v, v:getHealthPercent()) + end + end + end) +end + +function Healer.disconnect() + disconnect(Player, { onHealthPercentChange = Healer.onHealthChange }) +end + +function Healer.onHealthChange(friend, health) + local player = g_game.getLocalPlayer() + if table.contains(PvpModule.Friends, friend:getName()) then + if health <= CandyBot.getOption('HealerTreshold') then + if player:getHealthPercent() >= CandyBot.getOption('HealerSelfHealth') and player:getManaPercent() >= CandyBot.getOption('HealerSelfMana') then + if g_map.isSightClear(player:getPosition(), friend:getPosition()) then + g_game.talk(CandyBot.getOption('HealerSpell'):gsub("friend", friend:getName())) + end + end + end + end +end \ No newline at end of file diff --git a/modules/03-pvp/pvp.lua b/modules/03-pvp/pvp.lua index 29c0b42..33ff25a 100644 --- a/modules/03-pvp/pvp.lua +++ b/modules/03-pvp/pvp.lua @@ -8,21 +8,22 @@ PvpModule = {} -- load module events dofiles('events') -local Panel = { - -- -} +local Panel = nil +local UI = {} +PvpModule.Friends = {} function PvpModule.getPanel() return Panel end function PvpModule.setPanel(panel) Panel = panel end function PvpModule.init() - -- create tab local botTabBar = CandyBot.window:getChildById('botTabBar') local tab = botTabBar:addTab(tr('PvP')) local tabPanel = botTabBar:getTabPanel(tab) local tabBuffer = tabPanel:getChildById('tabBuffer') Panel = g_ui.loadUI('pvp.otui', tabBuffer) + + PvpModule.loadUI(Panel) PvpModule.parentUI = CandyBot.window @@ -32,7 +33,6 @@ function PvpModule.init() end function PvpModule.terminate() - --CreatureList.terminate() PvpModule.stop() Panel:destroy() @@ -43,9 +43,16 @@ end function PvpModule.loadUI(panel) UI = { KeepTarget = panel:recursiveGetChildById('KeepTarget'), + FriendsList = panel:recursiveGetChildById('FriendsListEdit') } end +function PvpModule.onNotify(key, state) + if key == 'FriendsList' then + UI.FriendsList:setText(state:gsub(';', '\n')) + PvpModule.Friends = string.split(state, ';') + end +end function PvpModule.onStopEvent(eventId) end diff --git a/modules/03-pvp/pvp.otui b/modules/03-pvp/pvp.otui index 2642685..94063fc 100644 --- a/modules/03-pvp/pvp.otui +++ b/modules/03-pvp/pvp.otui @@ -12,4 +12,112 @@ Panel !text: tr('Keep Target') !tooltip: tr('Automatically attack creature previously attacked.') anchors.left: parent.left - anchors.top: parent.top \ No newline at end of file + anchors.top: parent.top + + + HorizontalSeparator + anchors.left: parent.left + anchors.right: parent.right + anchors.top: prev.bottom + margin-top: 10 + + BotOptionCheckBox + id: Healer + width: 90 + !text: tr('Heal Friends') + anchors.left: parent.left + anchors.top: prev.bottom + margin-top: 10 + + Label + id: HealerTresholdLabel + !text: tr('On friend health lower than:') + anchors.right: parent.right + anchors.top: Healer.top + margin-left: 18 + + BotOptionHorizontalScrollBar + id: HealerTreshold + width: 150 + anchors.right: parent.right + anchors.top: HealerTresholdLabel.bottom + margin-top: 8 + mouse-scroll: false + show-value: true + symbol: % + minimum: 1 + maximum: 100 + + Label + id: HealerSelfHealthLabel + !text: tr('On self health higher than:') + anchors.right: parent.right + anchors.top: prev.bottom + margin-top: 10 + margin-left: 18 + + BotOptionHorizontalScrollBar + id: HealerSelfHealth + width: 150 + anchors.right: parent.right + anchors.top: HealerSelfHealthLabel.bottom + margin-top: 8 + mouse-scroll: false + show-value: true + symbol: % + minimum: 1 + maximum: 100 + + + Label + id: HealerSelfManaLabel + !text: tr('On self mana higher than:') + anchors.right: parent.right + anchors.top: prev.bottom + margin-top: 10 + margin-left: 18 + + BotOptionHorizontalScrollBar + id: HealerSelfMana + width: 150 + anchors.right: parent.right + anchors.top: HealerSelfManaLabel.bottom + margin-top: 8 + mouse-scroll: false + show-value: true + symbol: % + minimum: 1 + maximum: 100 + + Label + id: HealerSpellLabel + !text: tr('Healer spell:') + anchors.right: parent.right + anchors.top: prev.bottom + margin-top: 10 + margin-left: 18 + + BotOptionLineEdit + id: HealerSpell + anchors.top: prev.bottom + anchors.right: parent.right + margin-top: 8 + width: 150 + + Label + id: FriendsList + anchors.left: parent.left + anchors.top: Healer.bottom + margin-top: 15 + !text: tr('Friends List:') + + MultilineTextEdit + id: FriendsListEdit + anchors.left: parent.left + anchors.top: prev.bottom + height: 150 + width: 150 + margin-top: 10 + multiline: true + @onTextChange: | + CandyBot.changeOption('FriendsList', self:getText():gsub('\n', ';')) \ No newline at end of file diff --git a/modules/03-pvp/pvp_handler.lua b/modules/03-pvp/pvp_handler.lua index 50f84cc..2927356 100644 --- a/modules/03-pvp/pvp_handler.lua +++ b/modules/03-pvp/pvp_handler.lua @@ -17,7 +17,13 @@ PvpModule.dependencies = { --[[ Default Options ]] PvpModule.options = { - ['KeepTarget'] = false + ['KeepTarget'] = false, + ['Healer'] = false, + ['FriendsList'] = '', + ['HealerTreshold'] = 40, + ['HealerSelfHealth'] = 70, + ['HealerSelfMana'] = 40, + ['HealerSpell'] = 'exura sio "friend"' } --[[ Register Events ]] @@ -32,7 +38,8 @@ PvpModule.events = { --[[ Register Listeners ]] table.merge(PvpModule, { - keepTargetListener = 1 + keepTargetListener = 1, + healerListener = 2 -- }) @@ -42,6 +49,11 @@ PvpModule.listeners = { connect = PvpModule.KeepTarget.connect, disconnect = PvpModule.KeepTarget.disconnect }, + [PvpModule.healerListener] = { + option = "Healer", + connect = PvpModule.Healer.connect, + disconnect = PvpModule.Healer.disconnect + }, } --[[ Functions ]] diff --git a/modules/05-paths/paths.lua b/modules/05-paths/paths.lua index 568b9c9..d9f29bd 100644 --- a/modules/05-paths/paths.lua +++ b/modules/05-paths/paths.lua @@ -568,7 +568,7 @@ end -- local functions function writePath(path) local nodes = PathsModule.getNodes() - local content = ''..UI.RopeItem:getItemId()..':'..UI.ShovelItem:getItemId()..':'..UI.MacheteItem:getItemId()..';;' + local content = ''..UI.RopeItem:getItemId()..':'..UI.ShovelItem:getItemId()..':'..UI.MacheteItem:getItemId() for k,v in ipairs(nodes) do content = content .. ';;' .. v:toString() diff --git a/modules/05-paths/paths.otui b/modules/05-paths/paths.otui index 12bad0b..b5adf50 100644 --- a/modules/05-paths/paths.otui +++ b/modules/05-paths/paths.otui @@ -48,7 +48,8 @@ Panel anchors.left: prev.right anchors.top: AutoPath.bottom anchors.right: parent.right - margin-left: 6 + margin-top:8 + margin-left: 9 TextList id: PathList diff --git a/screenshots/3.png b/screenshots/3.png index 5ad92c5..71692ba 100644 Binary files a/screenshots/3.png and b/screenshots/3.png differ