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
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, {
onGameStart = Exit.hide,

View File

@ -5,6 +5,7 @@ function UIComboBox.create()
local combobox = UIComboBox.internalCreate()
combobox.options = {}
combobox.currentIndex = -1
combobox.mouseScroll = true
return combobox
end
@ -76,6 +77,9 @@ function UIComboBox:onMousePress(mousePos, mouseButton)
end
function UIComboBox:onMouseWheel(mousePos, direction)
if not self.mouseScroll then
return false
end
if direction == MouseWheelUp and self.currentIndex > 1 then
self:setCurrentIndex(self.currentIndex - 1)
elseif direction == MouseWheelDown and self.currentIndex < #self.options then
@ -90,6 +94,19 @@ function UIComboBox:onStyleApply(styleName, styleNode)
self:addOption(option)
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
function UIComboBox:onOptionChange(optionText, optionData)

View File

@ -230,10 +230,10 @@ function onMouseRelease(self, mousePosition, mouseButton)
mouseWidget.cancelNextRelease = true
g_game.look(self.creature)
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)
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
g_game.cancelAttack()
else

View File

@ -78,7 +78,8 @@ function onSpellCooldown(iconId, duration)
local spellName = SpelllistSettings[modules.game_spelllist.getSpelllistProfile()].spellIcons[iconId]
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)
if not otcIconId and SpellIcons[SpellInfo[modules.game_spelllist.getSpelllistProfile()][spellName].icon] then
otcIconId = SpellIcons[SpellInfo[modules.game_spelllist.getSpelllistProfile()][spellName].icon][1]
@ -103,7 +104,8 @@ end
function onSpellGroupCooldown(groupId, duration)
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 progressRect = contentsPanel:getChildById('progressRect' .. SpellGroups[groupId])
if icon then

View File

@ -1,4 +1,5 @@
WALK_AUTO_REPEAT_DELAY = 150
WALK_STEPS_RETRY = 10
gameRootPanel = nil
gameMapPanel = nil
@ -27,9 +28,17 @@ arrowKeys = {
function init()
g_ui.importStyle('styles/countwindow.otui')
connect(g_game, { onGameStart = show,
onGameEnd = hide,
onLoginAdvice = onLoginAdvice }, true)
connect(g_game, {
onGameStart = show,
onGameEnd = hide,
onLoginAdvice = onLoginAdvice,
onWalk = onWalk,
}, true)
connect(LocalPlayer, {
onCancelWalk = onCancelWalk,
onPositionChange = onPositionChange
})
gameRootPanel = g_ui.displayUI('gameinterface.otui')
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+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('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:zoomOut() end, gameRootPanel, 250)
g_keyboard.bindKeyDown('Ctrl+Q', logout, gameRootPanel)
@ -184,6 +193,45 @@ function tryLogout()
anchor=AnchorHorizontalCenter}, yesCallback, noCallback)
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)
local rebindKey = false
local lastKey = arrowKeys[lastWalkDir]
@ -233,6 +281,7 @@ function smartWalk(defaultDir)
else
g_game.walk(dir)
end
cancelAutoWalkCheck() -- cancel the auto walker check
if rebindKey then
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
if autoWalkPos and keyboardModifiers == KeyboardNoModifier and mouseButton == MouseLeftButton then
local dirs = g_map.findPath(g_game.getLocalPlayer():getPosition(), autoWalkPos, 127, PathFindFlags.AllowNullTiles)
if #dirs == 0 then
modules.game_textmessage.displayStatusMessage(tr('There is no way.'))
return true
local player = g_game.getLocalPlayer()
if not player:autoWalk(autoWalkPos) then
return false
end
g_game.autoWalk(dirs)
return true
end

View File

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

View File

@ -16,7 +16,9 @@ PlayerStates = {
Cursed = 2048,
PartyBuff = 4096,
PzBlock = 8192,
Pz = 16384
Pz = 16384,
Bleeding = 32768,
Hungry = 65536
}
InventorySlotOther = 0
@ -96,3 +98,47 @@ function Player:dismount()
g_game.mount(false)
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
add_definitions(-DOTCLIENT)
option(BOT_PROTECTION "Enable bot protection" ON)
option(BOT_PROTECTION "Enable bot protection" OFF)
if(BOT_PROTECTION)
add_definitions(-DBOT_PROTECTION)
message(STATUS "Bot protection: ON")

View File

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

View File

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

View File

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

View File

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