More fixes and edits!

* Fixed a bug with client_exit module button appearing on full reload.
* Fixed the battle window to work properly now (left click: attack, right click: menu).
* Added auto walk checker for more accurate aut walking:
  - It will always find the path now, except in rare occasions gets stuck running back and forward
  - Re-calculates path every 10 steps and also when you hit an object that cancels your step.
  - Right now this is just a temporary method.
  - Cancels the checker when you move or press escape (has to be done client-side).
* Added a new setting to UIComboBox class 'mouse-scroll' to enable/disable mouse wheel scrolling.
* Added support for no ping in cooldowns.
* Added missing PlayerStates (hungry and bleeding).
This commit is contained in:
BeniS 2013-01-08 06:17:01 +13:00
parent fddbafebd3
commit bb139955dc
12 changed files with 139 additions and 24 deletions

View File

@ -4,7 +4,9 @@ local exitWindow
local exitButton local exitButton
function Exit.init() function Exit.init()
exitButton = TopMenu.addRightButton('exitButton', tr('Exit Client'), 'exit.png', Exit.tryExit) if not g_game.isOnline() then
exitButton = TopMenu.addRightButton('exitButton', tr('Exit Client'), 'exit.png', Exit.tryExit)
end
connect(g_game, { connect(g_game, {
onGameStart = Exit.hide, onGameStart = Exit.hide,

View File

@ -5,6 +5,7 @@ function UIComboBox.create()
local combobox = UIComboBox.internalCreate() local combobox = UIComboBox.internalCreate()
combobox.options = {} combobox.options = {}
combobox.currentIndex = -1 combobox.currentIndex = -1
combobox.mouseScroll = true
return combobox return combobox
end end
@ -76,6 +77,9 @@ function UIComboBox:onMousePress(mousePos, mouseButton)
end end
function UIComboBox:onMouseWheel(mousePos, direction) function UIComboBox:onMouseWheel(mousePos, direction)
if not self.mouseScroll then
return false
end
if direction == MouseWheelUp and self.currentIndex > 1 then if direction == MouseWheelUp and self.currentIndex > 1 then
self:setCurrentIndex(self.currentIndex - 1) self:setCurrentIndex(self.currentIndex - 1)
elseif direction == MouseWheelDown and self.currentIndex < #self.options then elseif direction == MouseWheelDown and self.currentIndex < #self.options then
@ -90,6 +94,19 @@ function UIComboBox:onStyleApply(styleName, styleNode)
self:addOption(option) self:addOption(option)
end end
end end
for name,value in pairs(styleNode) do
if name == 'mouse-scroll' then
self.mouseScroll = value
end
end
end
function UIComboBox:setMouseScroll(scroll)
self.mouseScroll = scroll
end
function UIComboBox:canMouseScroll()
return self.mouseScroll
end end
function UIComboBox:onOptionChange(optionText, optionData) function UIComboBox:onOptionChange(optionText, optionData)

View File

@ -230,10 +230,10 @@ function onMouseRelease(self, mousePosition, mouseButton)
mouseWidget.cancelNextRelease = true mouseWidget.cancelNextRelease = true
g_game.look(self.creature) g_game.look(self.creature)
return true return true
elseif mouseButton == MouseRightButton and g_keyboard.isCtrlPressed() and not g_mouse.isPressed(MouseLeftButton) then elseif mouseButton == MouseRightButton and not g_mouse.isPressed(MouseLeftButton) then
modules.game_interface.createThingMenu(mousePosition, nil, nil, self.creature) modules.game_interface.createThingMenu(mousePosition, nil, nil, self.creature)
return true return true
elseif mouseButton == MouseRightButton and not g_mouse.isPressed(MouseLeftButton) then elseif mouseButton == MouseLeftButton and not g_mouse.isPressed(MouseRightButton) then
if self.isTarget then if self.isTarget then
g_game.cancelAttack() g_game.cancelAttack()
else else

View File

@ -78,7 +78,8 @@ function onSpellCooldown(iconId, duration)
local spellName = SpelllistSettings[modules.game_spelllist.getSpelllistProfile()].spellIcons[iconId] local spellName = SpelllistSettings[modules.game_spelllist.getSpelllistProfile()].spellIcons[iconId]
if not spellName then return end if not spellName then return end
local duration = duration - (g_game.getPing()/2) local ping = g_game.getPing()
if ping > 0 then local duration = duration - (ping/2) end
local otcIconId = tonumber(SpellInfo[modules.game_spelllist.getSpelllistProfile()][spellName].icon) local otcIconId = tonumber(SpellInfo[modules.game_spelllist.getSpelllistProfile()][spellName].icon)
if not otcIconId and SpellIcons[SpellInfo[modules.game_spelllist.getSpelllistProfile()][spellName].icon] then if not otcIconId and SpellIcons[SpellInfo[modules.game_spelllist.getSpelllistProfile()][spellName].icon] then
otcIconId = SpellIcons[SpellInfo[modules.game_spelllist.getSpelllistProfile()][spellName].icon][1] otcIconId = SpellIcons[SpellInfo[modules.game_spelllist.getSpelllistProfile()][spellName].icon][1]
@ -103,7 +104,8 @@ end
function onSpellGroupCooldown(groupId, duration) function onSpellGroupCooldown(groupId, duration)
if not SpellGroups[groupId] then return end if not SpellGroups[groupId] then return end
local duration = duration - (g_game.getPing()/2) local ping = g_game.getPing()
if ping > 0 then local duration = duration - (ping/2) end
local icon = contentsPanel:getChildById('groupIcon' .. SpellGroups[groupId]) local icon = contentsPanel:getChildById('groupIcon' .. SpellGroups[groupId])
local progressRect = contentsPanel:getChildById('progressRect' .. SpellGroups[groupId]) local progressRect = contentsPanel:getChildById('progressRect' .. SpellGroups[groupId])
if icon then if icon then

View File

@ -1,4 +1,5 @@
WALK_AUTO_REPEAT_DELAY = 150 WALK_AUTO_REPEAT_DELAY = 150
WALK_STEPS_RETRY = 10
gameRootPanel = nil gameRootPanel = nil
gameMapPanel = nil gameMapPanel = nil
@ -27,9 +28,17 @@ arrowKeys = {
function init() function init()
g_ui.importStyle('styles/countwindow.otui') g_ui.importStyle('styles/countwindow.otui')
connect(g_game, { onGameStart = show, connect(g_game, {
onGameEnd = hide, onGameStart = show,
onLoginAdvice = onLoginAdvice }, true) onGameEnd = hide,
onLoginAdvice = onLoginAdvice,
onWalk = onWalk,
}, true)
connect(LocalPlayer, {
onCancelWalk = onCancelWalk,
onPositionChange = onPositionChange
})
gameRootPanel = g_ui.displayUI('gameinterface.otui') gameRootPanel = g_ui.displayUI('gameinterface.otui')
gameRootPanel:hide() gameRootPanel:hide()
@ -83,7 +92,7 @@ function bindKeys()
g_keyboard.bindKeyPress('Ctrl+Numpad6', function() g_game.turn(East) end, gameRootPanel, WALK_AUTO_REPEAT_DELAY) g_keyboard.bindKeyPress('Ctrl+Numpad6', function() g_game.turn(East) end, gameRootPanel, WALK_AUTO_REPEAT_DELAY)
g_keyboard.bindKeyPress('Ctrl+Numpad2', function() g_game.turn(South) end, gameRootPanel, WALK_AUTO_REPEAT_DELAY) g_keyboard.bindKeyPress('Ctrl+Numpad2', function() g_game.turn(South) end, gameRootPanel, WALK_AUTO_REPEAT_DELAY)
g_keyboard.bindKeyPress('Ctrl+Numpad4', function() g_game.turn(West) end, gameRootPanel, WALK_AUTO_REPEAT_DELAY) g_keyboard.bindKeyPress('Ctrl+Numpad4', function() g_game.turn(West) end, gameRootPanel, WALK_AUTO_REPEAT_DELAY)
g_keyboard.bindKeyPress('Escape', function() g_game.cancelAttackAndFollow() end, gameRootPanel, WALK_AUTO_REPEAT_DELAY) g_keyboard.bindKeyPress('Escape', function() cancelAutoWalkCheck() g_game.cancelAttackAndFollow() end, gameRootPanel, WALK_AUTO_REPEAT_DELAY)
g_keyboard.bindKeyPress('Ctrl+=', function() gameMapPanel:zoomIn() end, gameRootPanel, 250) g_keyboard.bindKeyPress('Ctrl+=', function() gameMapPanel:zoomIn() end, gameRootPanel, 250)
g_keyboard.bindKeyPress('Ctrl+-', function() gameMapPanel:zoomOut() end, gameRootPanel, 250) g_keyboard.bindKeyPress('Ctrl+-', function() gameMapPanel:zoomOut() end, gameRootPanel, 250)
g_keyboard.bindKeyDown('Ctrl+Q', logout, gameRootPanel) g_keyboard.bindKeyDown('Ctrl+Q', logout, gameRootPanel)
@ -184,6 +193,45 @@ function tryLogout()
anchor=AnchorHorizontalCenter}, yesCallback, noCallback) anchor=AnchorHorizontalCenter}, yesCallback, noCallback)
end end
function onWalk(dir)
cancelAutoWalkCheck()
end
function onPositionChange(newPos, oldPos)
checkAutoWalking()
end
function onCancelWalk(dir)
checkAutoWalking(true)
end
function checkAutoWalking(stepCancelled)
local stepCancelled = stepCancelled or false
local player = g_game.getLocalPlayer()
if not player:isAutoWalking() then
player:clearWalkSteps()
end
local lastDestination = player:getLastDestination()
if not lastDestination then
return -- auto walk has been cancelled
end
player:setWalkStep(lastDestination)
local playerPos = player:getPosition()
local walkSteps = player:getWalkSteps(lastDestination)
if (not table.empty(walkSteps) and #walkSteps >= WALK_STEPS_RETRY) or stepCancelled then
if lastDestination then player:autoWalk(lastDestination) end
end
end
function cancelAutoWalkCheck()
local player = g_game.getLocalPlayer()
player:setLastDestination(nil) -- cancel retries
player:clearWalkSteps()
end
function smartWalk(defaultDir) function smartWalk(defaultDir)
local rebindKey = false local rebindKey = false
local lastKey = arrowKeys[lastWalkDir] local lastKey = arrowKeys[lastWalkDir]
@ -233,6 +281,7 @@ function smartWalk(defaultDir)
else else
g_game.walk(dir) g_game.walk(dir)
end end
cancelAutoWalkCheck() -- cancel the auto walker check
if rebindKey then if rebindKey then
g_keyboard.bindKeyPress(lastKey, function() smartWalk(lastWalkDir) end, gameRootPanel, WALK_AUTO_REPEAT_DELAY) g_keyboard.bindKeyPress(lastKey, function() smartWalk(lastWalkDir) end, gameRootPanel, WALK_AUTO_REPEAT_DELAY)
@ -517,12 +566,10 @@ function processMouseAction(menuPosition, mouseButton, autoWalkPos, lookThing, u
end end
if autoWalkPos and keyboardModifiers == KeyboardNoModifier and mouseButton == MouseLeftButton then if autoWalkPos and keyboardModifiers == KeyboardNoModifier and mouseButton == MouseLeftButton then
local dirs = g_map.findPath(g_game.getLocalPlayer():getPosition(), autoWalkPos, 127, PathFindFlags.AllowNullTiles) local player = g_game.getLocalPlayer()
if #dirs == 0 then if not player:autoWalk(autoWalkPos) then
modules.game_textmessage.displayStatusMessage(tr('There is no way.')) return false
return true
end end
g_game.autoWalk(dirs)
return true return true
end end

View File

@ -382,12 +382,8 @@ function onMinimapMouseRelease(self, mousePosition, mouseButton)
end end
local pos = self:getPosition(mousePosition) local pos = self:getPosition(mousePosition)
if pos and mouseButton == MouseLeftButton and self:isPressed() then if pos and mouseButton == MouseLeftButton and self:isPressed() then
local dirs = g_map.findPath(g_game.getLocalPlayer():getPosition(), pos, 127, PathFindFlags.AllowNullTiles) local player = g_game.getLocalPlayer()
if #dirs == 0 then if not player:autoWalk(pos) then return false end
modules.game_textmessage.displayStatusMessage(tr('There is no way.'))
return true
end
g_game.autoWalk(dirs)
return true return true
end end
return false return false

View File

@ -16,7 +16,9 @@ PlayerStates = {
Cursed = 2048, Cursed = 2048,
PartyBuff = 4096, PartyBuff = 4096,
PzBlock = 8192, PzBlock = 8192,
Pz = 16384 Pz = 16384,
Bleeding = 32768,
Hungry = 65536
} }
InventorySlotOther = 0 InventorySlotOther = 0
@ -96,3 +98,47 @@ function Player:dismount()
g_game.mount(false) g_game.mount(false)
end end
end end
function Player:getLastDestination()
return self.lastDestination
end
function Player:setLastDestination(destination)
self.lastDestination = destination
end
function Player:getWalkSteps(destination)
if not self.walkSteps or not destination then
return nil
end
return self.walkSteps[destination]
end
function Player:setWalkStep(destination)
if not self.walkSteps then
self.walkSteps = {}
end
if destination then
if not self.walkSteps[destination] then
self.walkSteps[destination] = {}
end
table.insert(self.walkSteps[destination], true)
end
end
function Player:clearWalkSteps()
self.walkSteps = {}
end
function Player:autoWalk(destination)
self:clearWalkSteps()
self:setLastDestination(destination)
local dirs = g_map.findPath(self:getPosition(), destination, 127, PathFindFlags.AllowNullTiles)
if #dirs == 0 then
modules.game_textmessage.displayStatusMessage(tr('There is no way.'))
return false
end
g_game.autoWalk(dirs)
return true
end

View File

@ -5,7 +5,7 @@ endif(${CMAKE_MAJOR_VERSION} EQUAL 2 AND ${CMAKE_MINOR_VERSION} EQUAL 6)
# otclient options # otclient options
add_definitions(-DOTCLIENT) add_definitions(-DOTCLIENT)
option(BOT_PROTECTION "Enable bot protection" ON) option(BOT_PROTECTION "Enable bot protection" OFF)
if(BOT_PROTECTION) if(BOT_PROTECTION)
add_definitions(-DBOT_PROTECTION) add_definitions(-DBOT_PROTECTION)
message(STATUS "Bot protection: ON") message(STATUS "Bot protection: ON")

View File

@ -255,7 +255,9 @@ namespace Otc
IconCursed = 2048, IconCursed = 2048,
IconPartyBuff = 4096, IconPartyBuff = 4096,
IconPzBlock = 8192, IconPzBlock = 8192,
IconPz = 16384 IconPz = 16384,
IconBleeding = 32768,
IconHungry = 65536
}; };
enum MessageMode { enum MessageMode {

View File

@ -158,7 +158,7 @@ void Game::processGameStart()
m_protocolGame->sendPing(); m_protocolGame->sendPing();
disableBotCall(); disableBotCall();
} }
}, 4000); }, 3000);
} }
} }

View File

@ -160,6 +160,8 @@ void LocalPlayer::cancelWalk(Otc::Direction direction)
// turn to the cancel direction // turn to the cancel direction
if(direction != Otc::InvalidDirection) if(direction != Otc::InvalidDirection)
setDirection(direction); setDirection(direction);
callLuaField("onCancelWalk", direction);
} }
void LocalPlayer::stopWalk() void LocalPlayer::stopWalk()

View File

@ -458,6 +458,7 @@ void OTClient::registerLuaFunctions()
g_lua.bindClassMemberFunction<LocalPlayer>("isKnown", &LocalPlayer::isKnown); g_lua.bindClassMemberFunction<LocalPlayer>("isKnown", &LocalPlayer::isKnown);
g_lua.bindClassMemberFunction<LocalPlayer>("isPreWalking", &LocalPlayer::isPreWalking); g_lua.bindClassMemberFunction<LocalPlayer>("isPreWalking", &LocalPlayer::isPreWalking);
g_lua.bindClassMemberFunction<LocalPlayer>("hasSight", &LocalPlayer::hasSight); g_lua.bindClassMemberFunction<LocalPlayer>("hasSight", &LocalPlayer::hasSight);
g_lua.bindClassMemberFunction<LocalPlayer>("isAutoWalking", &LocalPlayer::isAutoWalking);
g_lua.registerClass<Tile>(); g_lua.registerClass<Tile>();
g_lua.bindClassMemberFunction<Tile>("clean", &Tile::clean); g_lua.bindClassMemberFunction<Tile>("clean", &Tile::clean);