Skip to content

Commit

Permalink
Added PvP Friend Healer (only spell currently)
Browse files Browse the repository at this point in the history
Some small bugfixes to walker and settings loading
  • Loading branch information
zygzagZ committed Mar 13, 2017
1 parent 92b3a2c commit 1aebca6
Show file tree
Hide file tree
Showing 11 changed files with 205 additions and 14 deletions.
2 changes: 1 addition & 1 deletion candybot.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 0 additions & 2 deletions classes/lootprocedure.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
13 changes: 13 additions & 0 deletions classes/moveprocedure.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -188,6 +199,8 @@ function MoveProcedure:clean()

self:stopTryMove()

self:highlightItem(self.thing, false)

if self.hooks then
disconnect(Container, self.hooks)
end
Expand Down
4 changes: 3 additions & 1 deletion classes/node.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
50 changes: 50 additions & 0 deletions modules/03-pvp/events/healer.lua
Original file line number Diff line number Diff line change
@@ -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
17 changes: 12 additions & 5 deletions modules/03-pvp/pvp.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -32,7 +33,6 @@ function PvpModule.init()
end

function PvpModule.terminate()
--CreatureList.terminate()
PvpModule.stop()

Panel:destroy()
Expand All @@ -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
Expand Down
110 changes: 109 additions & 1 deletion modules/03-pvp/pvp.otui
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,112 @@ Panel
!text: tr('Keep Target')
!tooltip: tr('Automatically attack creature previously attacked.')
anchors.left: parent.left
anchors.top: parent.top
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', ';'))
16 changes: 14 additions & 2 deletions modules/03-pvp/pvp_handler.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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 ]]
Expand All @@ -32,7 +38,8 @@ PvpModule.events = {
--[[ Register Listeners ]]

table.merge(PvpModule, {
keepTargetListener = 1
keepTargetListener = 1,
healerListener = 2
--
})

Expand All @@ -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 ]]
Expand Down
2 changes: 1 addition & 1 deletion modules/05-paths/paths.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
3 changes: 2 additions & 1 deletion modules/05-paths/paths.otui
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Binary file modified screenshots/3.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 1aebca6

Please sign in to comment.