reaname and cleanup many stuff

This commit is contained in:
Eduardo Bart 2012-02-08 19:23:15 -02:00
parent d4ce3c5354
commit 175f97b98f
31 changed files with 1274 additions and 1001 deletions

View File

@ -28,8 +28,8 @@ local function tryLogin(charInfo, tries)
return return
end end
if Game.isOnline() then if g_game.isOnline() then
Game.safeLogout() g_game.safeLogout()
if tries == 1 then if tries == 1 then
loadBox = displayCancelBox('Please wait', 'Loggin out...') loadBox = displayCancelBox('Please wait', 'Loggin out...')
end end
@ -39,12 +39,12 @@ local function tryLogin(charInfo, tries)
CharacterList.destroyLoadBox() CharacterList.destroyLoadBox()
Game.loginWorld(EnterGame.account, EnterGame.password, charInfo.worldHost, charInfo.worldPort, charInfo.characterName) g_game.loginWorld(EnterGame.account, EnterGame.password, charInfo.worldHost, charInfo.worldPort, charInfo.characterName)
loadBox = displayCancelBox('Please wait', 'Connecting to game server...') loadBox = displayCancelBox('Please wait', 'Connecting to game server...')
connect(loadBox, { onCancel = function() connect(loadBox, { onCancel = function()
loadBox = nil loadBox = nil
Game.cancelLogin() g_game.cancelLogin()
CharacterList.show() CharacterList.show()
end }) end })
@ -110,7 +110,7 @@ end
function CharacterList.destroy() function CharacterList.destroy()
CharacterList.hide() CharacterList.hide()
if not Game.isOnline() then if not g_game.isOnline() then
EnterGame.show() EnterGame.show()
end end
end end

View File

@ -110,7 +110,7 @@ function EnterGame.hide()
end end
function EnterGame.openWindow() function EnterGame.openWindow()
if Game.isOnline() then if g_game.isOnline() then
CharacterList.show() CharacterList.show()
elseif not CharacterList.isVisible() then elseif not CharacterList.isVisible() then
EnterGame.show() EnterGame.show()

View File

@ -8,8 +8,8 @@ local gameButtonsPanel
-- private functions -- private functions
local function onLogout() local function onLogout()
if Game.isOnline() then if g_game.isOnline() then
Game.safeLogout() g_game.safeLogout()
else else
exit() exit()
end end
@ -25,7 +25,7 @@ function TopMenu.init()
TopMenu.addRightButton('logoutButton', 'Logout (Ctrl+Q)', '/core_styles/icons/logout.png', onLogout) TopMenu.addRightButton('logoutButton', 'Logout (Ctrl+Q)', '/core_styles/icons/logout.png', onLogout)
Keyboard.bindKeyDown('Ctrl+Q', onLogout) Keyboard.bindKeyDown('Ctrl+Q', onLogout)
connect(Game, { onGameStart = TopMenu.showGameButtons, connect(g_game, { onGameStart = TopMenu.showGameButtons,
onGameEnd = TopMenu.hideGameButtons }) onGameEnd = TopMenu.hideGameButtons })
end end
@ -37,7 +37,7 @@ function TopMenu.terminate()
topMenu:destroy() topMenu:destroy()
topMenu = nil topMenu = nil
disconnect(Game, { onGameStart = TopMenu.showGameButtons, disconnect(g_game, { onGameStart = TopMenu.showGameButtons,
onGameEnd = TopMenu.hideGameButtons }) onGameEnd = TopMenu.hideGameButtons })
TopMenu = nil TopMenu = nil

View File

@ -40,10 +40,10 @@ function UIItem:onDrop(widget, mousePos)
spinbox:setCurrentIndex(count) spinbox:setCurrentIndex(count)
local okButton = moveWindow:getChildById('buttonOk') local okButton = moveWindow:getChildById('buttonOk')
okButton.onClick = function() Game.move(widget.currentDragThing, pos, spinbox:getCurrentIndex()) okButton:getParent():destroy() widget.currentDragThing = nil end okButton.onClick = function() g_game.move(widget.currentDragThing, pos, spinbox:getCurrentIndex()) okButton:getParent():destroy() widget.currentDragThing = nil end
moveWindow.onEnter = okButton.onClick moveWindow.onEnter = okButton.onClick
else else
Game.move(widget.currentDragThing, pos, 1) g_game.move(widget.currentDragThing, pos, 1)
end end
self:setBorderWidth(0) self:setBorderWidth(0)
@ -70,6 +70,6 @@ function UIItem:onMouseRelease(mousePosition, mouseButton)
local item = self:getItem() local item = self:getItem()
if not item or not self:containsPoint(mousePosition) then return false end if not item or not self:containsPoint(mousePosition) then return false end
return Game.processMouseAction(mousePosition, mouseButton, nil, item, item, nil, item) return g_game.processMouseAction(mousePosition, mouseButton, nil, item, item, nil, item)
end end

View File

@ -8,7 +8,7 @@ local function onGameKeyPress(self, keyCode, keyboardModifiers)
CharacterList.show() CharacterList.show()
return true return true
elseif keyCode == KeyQ then elseif keyCode == KeyQ then
Game.safeLogout() g_game.safeLogout()
return true return true
end end
end end
@ -16,97 +16,97 @@ local function onGameKeyPress(self, keyCode, keyboardModifiers)
end end
local function onUseWithMouseRelease(self, mousePosition, mouseButton) local function onUseWithMouseRelease(self, mousePosition, mouseButton)
if Game.selectedThing == nil then return false end if g_game.selectedThing == nil then return false end
if mouseButton == MouseLeftButton then if mouseButton == MouseLeftButton then
local clickedWidget = Game.gameUi:recursiveGetChildByPos(mousePosition) local clickedWidget = g_game.gameUi:recursiveGetChildByPos(mousePosition)
if clickedWidget then if clickedWidget then
if clickedWidget:getClassName() == 'UIMap' then if clickedWidget:getClassName() == 'UIMap' then
local tile = clickedWidget:getTile(mousePosition) local tile = clickedWidget:getTile(mousePosition)
if tile then if tile then
Game.useWith(Game.selectedThing, tile:getTopMultiUseThing()) g_game.useWith(g_game.selectedThing, tile:getTopMultiUseThing())
end end
elseif clickedWidget:getClassName() == 'UIItem' and not clickedWidget:isVirtual() then elseif clickedWidget:getClassName() == 'UIItem' and not clickedWidget:isVirtual() then
Game.useWith(Game.selectedThing, clickedWidget:getItem()) g_game.useWith(g_game.selectedThing, clickedWidget:getItem())
end end
end end
end end
Game.selectedThing = nil g_game.selectedThing = nil
Mouse.restoreCursor() Mouse.restoreCursor()
self:ungrabMouse() self:ungrabMouse()
return true return true
end end
-- public functions -- public functions
function Game.startUseWith(thing) function g_game.startUseWith(thing)
Game.selectedThing = thing g_game.selectedThing = thing
m_mouseGrabberWidget:grabMouse() m_mouseGrabberWidget:grabMouse()
Mouse.setTargetCursor() Mouse.setTargetCursor()
end end
function Game.createInterface() function g_game.createInterface()
Background.hide() Background.hide()
CharacterList.destroyLoadBox() CharacterList.destroyLoadBox()
Game.gameUi = displayUI('game.otui') g_game.gameUi = displayUI('game.otui')
--Keyboard.bindKeyPress('Up', function() Game.walk(North) end) --Keyboard.bindKeyPress('Up', function() g_game.walk(North) end)
--Keyboard.bindKeyPress('Down', function() Game.walk(South) end) --Keyboard.bindKeyPress('Down', function() g_game.walk(South) end)
--Keyboard.bindKeyPress('Left', function() Game.walk(West) end) --Keyboard.bindKeyPress('Left', function() g_game.walk(West) end)
--Keyboard.bindKeyPress('Right', function() Game.walk(East) end) --Keyboard.bindKeyPress('Right', function() g_game.walk(East) end)
Keyboard.bindKeyPress('Ctrl+Shift+Up', function() Game.forceWalk(North) end) Keyboard.bindKeyPress('Ctrl+Shift+Up', function() g_game.forceWalk(North) end)
Keyboard.bindKeyPress('Ctrl+Shift+Down', function() Game.forceWalk(South) end) Keyboard.bindKeyPress('Ctrl+Shift+Down', function() g_game.forceWalk(South) end)
Keyboard.bindKeyPress('Ctrl+Shift+Left', function() Game.forceWalk(West) end) Keyboard.bindKeyPress('Ctrl+Shift+Left', function() g_game.forceWalk(West) end)
Keyboard.bindKeyPress('Ctrl+Shift+Right', function() Game.forceWalk(East) end) Keyboard.bindKeyPress('Ctrl+Shift+Right', function() g_game.forceWalk(East) end)
rootWidget:moveChildToIndex(Game.gameUi, 1) rootWidget:moveChildToIndex(g_game.gameUi, 1)
Game.gameMapPanel = Game.gameUi:getChildById('gameMapPanel') g_game.gameMapPanel = g_game.gameUi:getChildById('gameMapPanel')
Game.gameRightPanel = Game.gameUi:getChildById('gameRightPanel') g_game.gameRightPanel = g_game.gameUi:getChildById('gameRightPanel')
Game.gameBottomPanel = Game.gameUi:getChildById('gameBottomPanel') g_game.gameBottomPanel = g_game.gameUi:getChildById('gameBottomPanel')
m_mouseGrabberWidget = Game.gameUi:getChildById('mouseGrabber') m_mouseGrabberWidget = g_game.gameUi:getChildById('mouseGrabber')
connect(Game.gameUi, { onKeyPress = onGameKeyPress }) connect(g_game.gameUi, { onKeyPress = onGameKeyPress })
connect(m_mouseGrabberWidget, { onMouseRelease = onUseWithMouseRelease }) connect(m_mouseGrabberWidget, { onMouseRelease = onUseWithMouseRelease })
end end
function Game.destroyInterface() function g_game.destroyInterface()
if Game.gameUi then if g_game.gameUi then
Game.gameUi:destroy() g_game.gameUi:destroy()
Game.gameUi = nil g_game.gameUi = nil
end end
Background.show() Background.show()
CharacterList.show() CharacterList.show()
end end
function Game.show() function g_game.show()
Game.gameUi:show() g_game.gameUi:show()
Game.gameUi:focus() g_game.gameUi:focus()
Game.gameMapPanel:focus() g_game.gameMapPanel:focus()
end end
function Game.hide() function g_game.hide()
Game.gameUi:hide() g_game.gameUi:hide()
end end
-- hooked events -- hooked events
function Game.onLoginError(message) function g_game.onLoginError(message)
CharacterList.destroyLoadBox() CharacterList.destroyLoadBox()
local errorBox = displayErrorBox("Login Error", "Login error: " .. message) local errorBox = displayErrorBox("Login Error", "Login error: " .. message)
connect(errorBox, { onOk = CharacterList.show }) connect(errorBox, { onOk = CharacterList.show })
end end
function Game.onConnectionError(message) function g_game.onConnectionError(message)
CharacterList.destroyLoadBox() CharacterList.destroyLoadBox()
local errorBox = displayErrorBox("Login Error", "Connection error: " .. message) local errorBox = displayErrorBox("Login Error", "Connection error: " .. message)
connect(errorBox, { onOk = CharacterList.show }) connect(errorBox, { onOk = CharacterList.show })
end end
local function onApplicationClose() local function onApplicationClose()
if Game.isOnline() then if g_game.isOnline() then
Game.forceLogout() g_game.forceLogout()
else else
exit() exit()
end end
end end
setonclose(onApplicationClose) setonclose(onApplicationClose)
connect(Game, { onGameStart = Game.createInterface }, true) connect(g_game, { onGameStart = g_game.createInterface }, true)
connect(Game, { onGameEnd = Game.destroyInterface }) connect(g_game, { onGameEnd = g_game.destroyInterface })

View File

@ -36,10 +36,10 @@ function UIMap:onDrop(widget, mousePos)
spinbox:setCurrentIndex(count) spinbox:setCurrentIndex(count)
local okButton = moveWindow:getChildById('buttonOk') local okButton = moveWindow:getChildById('buttonOk')
okButton.onClick = function() Game.move(widget.currentDragThing, tile:getPosition(), spinbox:getCurrentIndex()) okButton:getParent():destroy() widget.currentDragThing = nil end okButton.onClick = function() g_game.move(widget.currentDragThing, tile:getPosition(), spinbox:getCurrentIndex()) okButton:getParent():destroy() widget.currentDragThing = nil end
moveWindow.onEnter = okButton.onClick moveWindow.onEnter = okButton.onClick
else else
Game.move(widget.currentDragThing, tile:getPosition(), 1) g_game.move(widget.currentDragThing, tile:getPosition(), 1)
end end
return true return true
@ -47,7 +47,7 @@ end
function UIMap:onMouseRelease(mousePosition, mouseButton) function UIMap:onMouseRelease(mousePosition, mouseButton)
local tile = self:getTile(mousePosition) local tile = self:getTile(mousePosition)
if tile and Game.processMouseAction(mousePosition, mouseButton, nil, tile:getTopLookThing(), tile:getTopUseThing(), tile:getTopCreature(), tile:getTopMultiUseThing()) then return true end if tile and g_game.processMouseAction(mousePosition, mouseButton, nil, tile:getTopLookThing(), tile:getTopUseThing(), tile:getTopCreature(), tile:getTopMultiUseThing()) then return true end
return false return false
end end

View File

@ -11,7 +11,7 @@ function Thing:getContainerId()
end end
-- public functions -- public functions
function Game.processMouseAction(menuPosition, mouseButton, autoWalk, lookThing, useThing, creatureThing, multiUseThing) function g_game.processMouseAction(menuPosition, mouseButton, autoWalk, lookThing, useThing, creatureThing, multiUseThing)
local keyboardModifiers = g_window.getKeyboardModifiers() local keyboardModifiers = g_window.getKeyboardModifiers()
if autoWalk and keyboardModifiers == KeyboardNoModifier and mouseButton == MouseLeftButton then if autoWalk and keyboardModifiers == KeyboardNoModifier and mouseButton == MouseLeftButton then
@ -21,60 +21,60 @@ function Game.processMouseAction(menuPosition, mouseButton, autoWalk, lookThing,
if not Options.classicControl then if not Options.classicControl then
if keyboardModifiers == KeyboardNoModifier and mouseButton == MouseRightButton then if keyboardModifiers == KeyboardNoModifier and mouseButton == MouseRightButton then
Game.createThingMenu(menuPosition, lookThing, useThing, creatureThing) g_game.createThingMenu(menuPosition, lookThing, useThing, creatureThing)
return true return true
elseif lookThing and keyboardModifiers == KeyboardShiftModifier and (mouseButton == MouseLeftButton or mouseButton == MouseRightButton) then elseif lookThing and keyboardModifiers == KeyboardShiftModifier and (mouseButton == MouseLeftButton or mouseButton == MouseRightButton) then
Game.look(lookThing) g_game.look(lookThing)
return true return true
elseif useThing and keyboardModifiers == KeyboardCtrlModifier and (mouseButton == MouseLeftButton or mouseButton == MouseRightButton) then elseif useThing and keyboardModifiers == KeyboardCtrlModifier and (mouseButton == MouseLeftButton or mouseButton == MouseRightButton) then
if useThing:isContainer() then if useThing:isContainer() then
if useThing:isInsideContainer() then if useThing:isInsideContainer() then
Game.open(useThing, useThing:getContainerId()) g_game.open(useThing, useThing:getContainerId())
return true return true
else else
Game.open(useThing, Containers.getFreeContainerId()) g_game.open(useThing, Containers.getFreeContainerId())
return true return true
end end
elseif useThing:isMultiUse() then elseif useThing:isMultiUse() then
Game.startUseWith(useThing) g_game.startUseWith(useThing)
return true return true
else else
Game.use(useThing) g_game.use(useThing)
return true return true
end end
return true return true
elseif creatureThing and keyboardModifiers == KeyboardAltModifier and (mouseButton == MouseLeftButton or mouseButton == MouseRightButton) then elseif creatureThing and keyboardModifiers == KeyboardAltModifier and (mouseButton == MouseLeftButton or mouseButton == MouseRightButton) then
Game.attack(creatureThing) g_game.attack(creatureThing)
return true return true
end end
else else
if multiUseThing and keyboardModifiers == KeyboardNoModifier and mouseButton == MouseRightButton then if multiUseThing and keyboardModifiers == KeyboardNoModifier and mouseButton == MouseRightButton then
if multiUseThing:asCreature() then if multiUseThing:asCreature() then
Game.attack(multiUseThing:asCreature()) g_game.attack(multiUseThing:asCreature())
return true return true
elseif multiUseThing:isContainer() then elseif multiUseThing:isContainer() then
if multiUseThing:isInsideContainer() then if multiUseThing:isInsideContainer() then
Game.open(multiUseThing, multiUseThing:getContainerId()) g_game.open(multiUseThing, multiUseThing:getContainerId())
return true return true
else else
Game.open(multiUseThing, Containers.getFreeContainerId()) g_game.open(multiUseThing, Containers.getFreeContainerId())
return true return true
end end
elseif multiUseThing:isMultiUse() then elseif multiUseThing:isMultiUse() then
Game.startUseWith(multiUseThing) g_game.startUseWith(multiUseThing)
return true return true
else else
Game.use(multiUseThing) g_game.use(multiUseThing)
end end
return true return true
elseif lookThing and keyboardModifiers == KeyboardShiftModifier and (mouseButton == MouseLeftButton or mouseButton == MouseRightButton) then elseif lookThing and keyboardModifiers == KeyboardShiftModifier and (mouseButton == MouseLeftButton or mouseButton == MouseRightButton) then
Game.look(lookThing) g_game.look(lookThing)
return true return true
elseif useThing and keyboardModifiers == KeyboardCtrlModifier and (mouseButton == MouseLeftButton or mouseButton == MouseRightButton) then elseif useThing and keyboardModifiers == KeyboardCtrlModifier and (mouseButton == MouseLeftButton or mouseButton == MouseRightButton) then
Game.createThingMenu(menuPosition, lookThing, useThing, creatureThing) g_game.createThingMenu(menuPosition, lookThing, useThing, creatureThing)
return true return true
elseif creatureThing and keyboardModifiers == KeyboardAltModifier and (mouseButton == MouseLeftButton or mouseButton == MouseRightButton) then elseif creatureThing and keyboardModifiers == KeyboardAltModifier and (mouseButton == MouseLeftButton or mouseButton == MouseRightButton) then
Game.attack(creatureThing) g_game.attack(creatureThing)
return true return true
end end
end end
@ -83,31 +83,31 @@ function Game.processMouseAction(menuPosition, mouseButton, autoWalk, lookThing,
end end
function Game.createThingMenu(menuPosition, lookThing, useThing, creatureThing) function g_game.createThingMenu(menuPosition, lookThing, useThing, creatureThing)
local menu = createWidget('PopupMenu') local menu = createWidget('PopupMenu')
if lookThing then if lookThing then
menu:addOption('Look', function() Game.look(lookThing) end) menu:addOption('Look', function() g_game.look(lookThing) end)
end end
if useThing then if useThing then
if useThing:isContainer() then if useThing:isContainer() then
if useThing:isInsideContainer() then if useThing:isInsideContainer() then
menu:addOption('Open', function() Game.open(useThing, useThing:getContainerId()) end) menu:addOption('Open', function() g_game.open(useThing, useThing:getContainerId()) end)
menu:addOption('Open in new window', function() Game.open(useThing, Containers.getFreeContainerId()) end) menu:addOption('Open in new window', function() g_game.open(useThing, Containers.getFreeContainerId()) end)
else else
menu:addOption('Open', function() Game.open(useThing, Containers.getFreeContainerId()) end) menu:addOption('Open', function() g_game.open(useThing, Containers.getFreeContainerId()) end)
end end
else else
if useThing:isMultiUse() then if useThing:isMultiUse() then
menu:addOption('Use with ...', function() Game.startUseWith(useThing) end) menu:addOption('Use with ...', function() g_game.startUseWith(useThing) end)
else else
menu:addOption('Use', function() Game.use(useThing) end) menu:addOption('Use', function() g_game.use(useThing) end)
end end
end end
if useThing:isRotateable() then if useThing:isRotateable() then
menu:addOption('Rotate', function() Game.rotate(useThing) end) menu:addOption('Rotate', function() g_game.rotate(useThing) end)
end end
end end
@ -123,38 +123,38 @@ function Game.createThingMenu(menuPosition, lookThing, useThing, creatureThing)
menu:addSeparator() menu:addSeparator()
if creatureThing:asLocalPlayer() then if creatureThing:asLocalPlayer() then
menu:addOption('Set Outfit', function() Game.requestOutfit() end) menu:addOption('Set Outfit', function() g_game.requestOutfit() end)
if creatureThing:asPlayer():isPartyMember() --[[and not fighting]] then if creatureThing:asPlayer():isPartyMember() --[[and not fighting]] then
if creatureThing:asPlayer():isPartyLeader() then if creatureThing:asPlayer():isPartyLeader() then
if creatureThing:asPlayer():isPartySharedExperienceActive() then if creatureThing:asPlayer():isPartySharedExperienceActive() then
menu:addOption('Disable Shared Experience', function() Game.partyShareExperience(false) end) menu:addOption('Disable Shared Experience', function() g_game.partyShareExperience(false) end)
else else
menu:addOption('Enable Shared Experience', function() Game.partyShareExperience(true) end) menu:addOption('Enable Shared Experience', function() g_game.partyShareExperience(true) end)
end end
end end
menu:addOption('Leave Party', function() Game.partyLeave() end) menu:addOption('Leave Party', function() g_game.partyLeave() end)
end end
else else
local localPlayer = Game.getLocalPlayer() local localPlayer = g_game.getLocalPlayer()
if localPlayer then if localPlayer then
if localPlayer:getAttackingCreature() ~= creatureThing then if g_game.getAttackingCreature() ~= creatureThing then
menu:addOption('Attack', function() Game.attack(creatureThing) end) menu:addOption('Attack', function() g_game.attack(creatureThing) end)
else else
menu:addOption('Stop Attack', function() Game.cancelAttack() end) menu:addOption('Stop Attack', function() g_game.cancelAttack() end)
end end
if localPlayer:getFollowingCreature() ~= creatureThing then if g_game.getFollowingCreature() ~= creatureThing then
menu:addOption('Follow', function() Game.follow(creatureThing) end) menu:addOption('Follow', function() g_game.follow(creatureThing) end)
else else
menu:addOption('Stop Follow', function() Game.cancelFollow() end) menu:addOption('Stop Follow', function() g_game.cancelFollow() end)
end end
if creatureThing:asPlayer() then if creatureThing:asPlayer() then
menu:addSeparator() menu:addSeparator()
menu:addOption('Message to ' .. creatureThing:getName(), function() print('message') end) menu:addOption('Message to ' .. creatureThing:getName(), function() print('message') end)
menu:addOption('Add to VIP list', function() Game.addVip(creatureThing:getName()) end) menu:addOption('Add to VIP list', function() g_game.addVip(creatureThing:getName()) end)
menu:addOption('Ignore ' .. creatureThing:getName(), function() print('ignore') end) menu:addOption('Ignore ' .. creatureThing:getName(), function() print('ignore') end)
local localPlayerShield = localPlayer:asCreature():getShield() local localPlayerShield = localPlayer:asCreature():getShield()
@ -162,21 +162,21 @@ function Game.createThingMenu(menuPosition, lookThing, useThing, creatureThing)
if localPlayerShield == ShieldNone or localPlayerShield == ShieldWhiteBlue then if localPlayerShield == ShieldNone or localPlayerShield == ShieldWhiteBlue then
if creatureShield == ShieldWhiteYellow then if creatureShield == ShieldWhiteYellow then
menu:addOption('Join ' .. creatureThing:getName() .. '\'s Party', function() Game.partyJoin(creatureThing:getId()) end) menu:addOption('Join ' .. creatureThing:getName() .. '\'s Party', function() g_game.partyJoin(creatureThing:getId()) end)
else else
menu:addOption('Invite to Party', function() Game.partyInvite(creatureThing:getId()) end) menu:addOption('Invite to Party', function() g_game.partyInvite(creatureThing:getId()) end)
end end
elseif localPlayerShield == ShieldWhiteYellow then elseif localPlayerShield == ShieldWhiteYellow then
if creatureShield == ShieldWhiteBlue then if creatureShield == ShieldWhiteBlue then
menu:addOption('Revoke ' .. creatureThing:getName() .. '\'s Invitation', function() Game.partyRevokeInvitation(creatureThing:getId()) end) menu:addOption('Revoke ' .. creatureThing:getName() .. '\'s Invitation', function() g_game.partyRevokeInvitation(creatureThing:getId()) end)
end end
elseif localPlayerShield == ShieldYellow or localPlayerShield == ShieldYellowSharedExp or localPlayerShield == ShieldYellowNoSharedExpBlink or localPlayerShield == ShieldYellowNoSharedExp then elseif localPlayerShield == ShieldYellow or localPlayerShield == ShieldYellowSharedExp or localPlayerShield == ShieldYellowNoSharedExpBlink or localPlayerShield == ShieldYellowNoSharedExp then
if creatureShield == ShieldWhiteBlue then if creatureShield == ShieldWhiteBlue then
menu:addOption('Revoke ' .. creatureThing:getName() .. '\'s Invitation', function() Game.partyRevokeInvitation(creatureThing:getId()) end) menu:addOption('Revoke ' .. creatureThing:getName() .. '\'s Invitation', function() g_game.partyRevokeInvitation(creatureThing:getId()) end)
elseif creatureShield == ShieldBlue or creatureShield == ShieldBlueSharedExp or creatureShield == ShieldBlueNoSharedExpBlink or creatureShield == ShieldBlueNoSharedExp then elseif creatureShield == ShieldBlue or creatureShield == ShieldBlueSharedExp or creatureShield == ShieldBlueNoSharedExpBlink or creatureShield == ShieldBlueNoSharedExp then
menu:addOption('Pass Leadership to ' .. creatureThing:getName(), function() Game.partyPassLeadership(creatureThing:getId()) end) menu:addOption('Pass Leadership to ' .. creatureThing:getName(), function() g_game.partyPassLeadership(creatureThing:getId()) end)
else else
menu:addOption('Invite to Party', function() Game.partyInvite(creatureThing:getId()) end) menu:addOption('Invite to Party', function() g_game.partyInvite(creatureThing:getId()) end)
end end
end end
end end

View File

@ -22,8 +22,8 @@ local function onFightModeChange(self, selectedFightButton)
else else
fightMode = FightDefensive fightMode = FightDefensive
end end
if Game.getFightMode ~= fightMode then if g_game.getFightMode ~= fightMode then
Game.setFightMode(fightMode) g_game.setFightMode(fightMode)
end end
end end
@ -34,15 +34,15 @@ local function onChaseModeChange(self, checked)
else else
chaseMode = DontChase chaseMode = DontChase
end end
if Game.getChaseMode() ~= chaseMode then if g_game.getChaseMode() ~= chaseMode then
Game.setChaseMode(chaseMode) g_game.setChaseMode(chaseMode)
end end
end end
local function onSafeFightChange(self, checked) local function onSafeFightChange(self, checked)
local safeFight = not checked local safeFight = not checked
if Game.isSafeFight() ~= safeFight then if g_game.isSafeFight() ~= safeFight then
Game.setSafeFight(not checked) g_game.setSafeFight(not checked)
end end
end end
@ -66,16 +66,16 @@ function CombatControls.init()
connect(fightModeRadioGroup, { onSelectionChange = onFightModeChange }) connect(fightModeRadioGroup, { onSelectionChange = onFightModeChange })
connect(chaseModeButton, { onCheckChange = onChaseModeChange }) connect(chaseModeButton, { onCheckChange = onChaseModeChange })
connect(safeFightButton, { onCheckChange = onSafeFightChange }) connect(safeFightButton, { onCheckChange = onSafeFightChange })
connect(Game, { onGameStart = CombatControls.online }) connect(g_game, { onGameStart = CombatControls.online })
connect(Game, { onGameEnd = CombatControls.offline }) connect(g_game, { onGameEnd = CombatControls.offline })
if Game.isOnline() then if g_game.isOnline() then
CombatControls.online() CombatControls.online()
end end
end end
function CombatControls.terminate() function CombatControls.terminate()
if Game.isOnline() then if g_game.isOnline() then
CombatControls.offline() CombatControls.offline()
end end
@ -94,17 +94,17 @@ function CombatControls.terminate()
combatControlsWindow:destroy() combatControlsWindow:destroy()
combatControlsWindow = nil combatControlsWindow = nil
disconnect(Game, { onGameStart = CombatControls.online }) disconnect(g_game, { onGameStart = CombatControls.online })
disconnect(Game, { onGameEnd = CombatControls.offline }) disconnect(g_game, { onGameEnd = CombatControls.offline })
CombatControls = nil CombatControls = nil
end end
function CombatControls.online() function CombatControls.online()
Game.gameRightPanel:addChild(combatControlsWindow) g_game.gameRightPanel:addChild(combatControlsWindow)
combatControlsWindow:setVisible(combatControlsButton:isOn()) combatControlsWindow:setVisible(combatControlsButton:isOn())
local fightMode = Game.getFightMode() local fightMode = g_game.getFightMode()
if fightMode == FightOffensive then if fightMode == FightOffensive then
fightModeRadioGroup:selectWidget(fightOffensiveBox) fightModeRadioGroup:selectWidget(fightOffensiveBox)
elseif fightMode == FightBalanced then elseif fightMode == FightBalanced then
@ -113,15 +113,15 @@ function CombatControls.online()
fightModeRadioGroup:selectWidget(fightDefensiveBox) fightModeRadioGroup:selectWidget(fightDefensiveBox)
end end
local chaseMode = Game.getChaseMode() local chaseMode = g_game.getChaseMode()
chaseModeButton:setChecked(chaseMode == ChaseOpponent) chaseModeButton:setChecked(chaseMode == ChaseOpponent)
local safeFight = Game.isSafeFight() local safeFight = g_game.isSafeFight()
safeFightButton:setChecked(not safeFight) safeFightButton:setChecked(not safeFight)
end end
function CombatControls.offline() function CombatControls.offline()
Game.gameRightPanel:removeChild(combatControlsWindow) g_game.gameRightPanel:removeChild(combatControlsWindow)
end end
function CombatControls.toggle() function CombatControls.toggle()

View File

@ -78,7 +78,7 @@ end
-- public functions -- public functions
function Console.create() function Console.create()
consolePanel = displayUI('console.otui', { parent = Game.gameBottomPanel } ) consolePanel = displayUI('console.otui', { parent = g_game.gameBottomPanel } )
consoleLineEdit = consolePanel:getChildById('consoleLineEdit') consoleLineEdit = consolePanel:getChildById('consoleLineEdit')
consoleBuffer = consolePanel:getChildById('consoleBuffer') consoleBuffer = consolePanel:getChildById('consoleBuffer')
consoleTabBar = consolePanel:getChildById('consoleTabBar') consoleTabBar = consolePanel:getChildById('consoleTabBar')
@ -100,7 +100,7 @@ function Console.create()
connect(consoleTabBar, { onTabChange = Console.onTabChange }) connect(consoleTabBar, { onTabChange = Console.onTabChange })
-- tibia like hotkeys -- tibia like hotkeys
Keyboard.bindKeyDown('Ctrl+O', Game.requestChannels) Keyboard.bindKeyDown('Ctrl+O', g_game.requestChannels)
Keyboard.bindKeyDown('Ctrl+E', Console.removeCurrentTab) Keyboard.bindKeyDown('Ctrl+E', Console.removeCurrentTab)
end end
@ -139,9 +139,9 @@ function Console.removeCurrentTab()
-- notificate the server that we are leaving the channel -- notificate the server that we are leaving the channel
if tab.channelId then if tab.channelId then
Game.leaveChannel(tab.channelId) g_game.leaveChannel(tab.channelId)
elseif tab:getText() == "NPCs" then elseif tab:getText() == "NPCs" then
Game.closeNpcChannel() g_game.closeNpcChannel()
end end
end end
@ -264,7 +264,7 @@ function Console.sendCurrentMessage()
speaktypedesc = 'channelYellow' speaktypedesc = 'channelYellow'
end end
Game.talkChannel(SpeakTypesSettings[speaktypedesc].speakType, tab.channelId, message) g_game.talkChannel(SpeakTypesSettings[speaktypedesc].speakType, tab.channelId, message)
return return
else else
local isPrivateCommand = false local isPrivateCommand = false
@ -280,8 +280,8 @@ function Console.sendCurrentMessage()
local speaktype = SpeakTypesSettings[speaktypedesc] local speaktype = SpeakTypesSettings[speaktypedesc]
local player = Game.getLocalPlayer() local player = g_game.getLocalPlayer()
Game.talkPrivate(speaktype.speakType, name, message) g_game.talkPrivate(speaktype.speakType, name, message)
message = applyMessagePrefixies(player:getName(), player:getLevel(), message) message = applyMessagePrefixies(player:getName(), player:getLevel(), message)
Console.addPrivateText(message, speaktype, name, isPrivateCommand) Console.addPrivateText(message, speaktype, name, isPrivateCommand)
@ -316,7 +316,7 @@ local function onCreatureSpeak(name, level, speaktype, message, channelId, creat
Console.addText(message, speaktype, channel) Console.addText(message, speaktype, channel)
else else
-- server sent a message on a channel that we are not aware of, must leave it -- server sent a message on a channel that we are not aware of, must leave it
Game.leaveChannel(channelId) g_game.leaveChannel(channelId)
end end
end end
end end
@ -336,11 +336,11 @@ local function doChannelListSubmit(channelsWindow)
local channelListPanel = channelsWindow:getChildById('channelList') local channelListPanel = channelsWindow:getChildById('channelList')
local openPrivateChannelWith = channelsWindow:getChildById('openPrivateChannelWith'):getText() local openPrivateChannelWith = channelsWindow:getChildById('openPrivateChannelWith'):getText()
if openPrivateChannelWith ~= '' then if openPrivateChannelWith ~= '' then
Game.openPrivateChannel(openPrivateChannelWith) g_game.openPrivateChannel(openPrivateChannelWith)
else else
local selectedChannelLabel = channelListPanel:getFocusedChild() local selectedChannelLabel = channelListPanel:getFocusedChild()
if not selectedChannelLabel then return end if not selectedChannelLabel then return end
Game.joinChannel(selectedChannelLabel.channelId) g_game.joinChannel(selectedChannelLabel.channelId)
end end
channelsWindow:destroy() channelsWindow:destroy()
end end
@ -365,7 +365,7 @@ local function onChannelList(channelList)
end end
end end
connect(Game, { onGameStart = Console.create, connect(g_game, { onGameStart = Console.create,
onGameEnd = Console.destroy, onGameEnd = Console.destroy,
onCreatureSpeak = onCreatureSpeak, onCreatureSpeak = onCreatureSpeak,
onChannelList = onChannelList, onChannelList = onChannelList,

View File

@ -57,7 +57,7 @@ Panel
anchors.top: parent.top anchors.top: parent.top
margin-right: 5 margin-right: 5
margin-top: 6 margin-top: 6
@onClick: Game.requestChannels() @onClick: g_game.requestChannels()
Panel Panel
id: consoleBuffer id: consoleBuffer

View File

@ -18,13 +18,13 @@ function Containers.getFreeContainerId()
end end
-- hooked events -- hooked events
function Containers.onContainerOpen(containerId, itemId, name, capacity, hasParent, items) function Containers.onOpenContainer(containerId, itemId, name, capacity, hasParent, items)
local container = m_containers[containerId] local container = m_containers[containerId]
if container then if container then
Game.gameRightPanel:removeChild(container) g_game.gameRightPanel:removeChild(container)
end end
container = displayUI('container.otui', { parent = Game.gameRightPanel }) container = displayUI('container.otui', { parent = g_game.gameRightPanel })
name = name:sub(1,1):upper() .. name:sub(2) name = name:sub(1,1):upper() .. name:sub(2)
container:setText(name) container:setText(name)
@ -57,7 +57,7 @@ end
function Containers.onContainerClose(containerId) function Containers.onContainerClose(containerId)
local container = m_containers[containerId] local container = m_containers[containerId]
if container then if container then
Game.gameRightPanel:removeChild(container) g_game.gameRightPanel:removeChild(container)
end end
m_containers[containerId] = nil m_containers[containerId] = nil
end end
@ -128,9 +128,9 @@ function Containers.onContainerRemoveItem(containerId, slot)
container.itemCount = container.itemCount - 1 container.itemCount = container.itemCount - 1
end end
connect(Game, { onGameStart = Containers.clean, connect(g_game, { onGameStart = Containers.clean,
onGameEnd = Containers.clean, onGameEnd = Containers.clean,
onContainerOpen = Containers.onContainerOpen, onOpenContainer = Containers.onOpenContainer,
onContainerClose = Containers.onContainerClose, onContainerClose = Containers.onContainerClose,
onContainerAddItem = Containers.onContainerAddItem, onContainerAddItem = Containers.onContainerAddItem,
onContainerUpdateItem = Containers.onContainerUpdateItem, onContainerUpdateItem = Containers.onContainerUpdateItem,

View File

@ -9,7 +9,7 @@ local manaLabel
-- public functions -- public functions
function HealthBar.create() function HealthBar.create()
healthBarWindow = displayUI('healthbar.otui', { parent = Game.gameRightPanel }) healthBarWindow = displayUI('healthbar.otui', { parent = g_game.gameRightPanel })
healthBarButton = TopMenu.addGameButton('healthBarButton', 'Healh Bar', 'healthbar.png', HealthBar.toggle) healthBarButton = TopMenu.addGameButton('healthBarButton', 'Healh Bar', 'healthbar.png', HealthBar.toggle)
healthBarButton:setOn(true) healthBarButton:setOn(true)
healthBar = healthBarWindow:getChildById('healthBar') healthBar = healthBarWindow:getChildById('healthBar')
@ -53,7 +53,7 @@ function HealthBar.onManaChange(mana, maxMana)
manaBar:setPercent(percent) manaBar:setPercent(percent)
end end
connect(Game, { onGameStart = HealthBar.create, connect(g_game, { onGameStart = HealthBar.create,
onGameEnd = HealthBar.destroy, onGameEnd = HealthBar.destroy,
onHealthChange = HealthBar.onHealthChange, onHealthChange = HealthBar.onHealthChange,
onManaChange = HealthBar.onManaChange }) onManaChange = HealthBar.onManaChange })

View File

@ -127,7 +127,7 @@ function HotkeysManager.toggle()
end end
function HotkeysManager.show() function HotkeysManager.show()
if Game.isOnline() then if g_game.isOnline() then
hotkeysWindow:grabKeyboard() hotkeysWindow:grabKeyboard()
hotkeysWindow:show() hotkeysWindow:show()
hotkeysWindow:lock() hotkeysWindow:lock()
@ -144,7 +144,7 @@ end
function HotkeysManager.onChooseItemMouseRelease(self, mousePosition, mouseButton) function HotkeysManager.onChooseItemMouseRelease(self, mousePosition, mouseButton)
local item = nil local item = nil
if mouseButton == MouseLeftButton then if mouseButton == MouseLeftButton then
local clickedWidget = Game.gameUi:recursiveGetChildByPos(mousePosition) local clickedWidget = g_game.gameUi:recursiveGetChildByPos(mousePosition)
if clickedWidget then if clickedWidget then
if clickedWidget:getClassName() == 'UIMap' then if clickedWidget:getClassName() == 'UIMap' then
local tile = clickedWidget:getTile(mousePosition) local tile = clickedWidget:getTile(mousePosition)
@ -285,25 +285,25 @@ function HotkeysManager.addKeyCombo(messageBox, keyCombo, keySettings)
end end
function HotkeysManager.call(keyCombo) function HotkeysManager.call(keyCombo)
if Game.isOnline() then if g_game.isOnline() then
local hotKey = hotkeyList[keyCombo] local hotKey = hotkeyList[keyCombo]
if hotKey.itemId == nil and hotKey.value ~= '' then if hotKey.itemId == nil and hotKey.value ~= '' then
if hotKey.autoSend then if hotKey.autoSend then
Game.talk(hotKey.value) g_game.talk(hotKey.value)
else else
Console.setLineEditText(hotKey.value) Console.setLineEditText(hotKey.value)
end end
elseif hotKey.itemId ~= nil then elseif hotKey.itemId ~= nil then
if hotKey.useType == HOTKEY_MANAGER_USEONSELF then if hotKey.useType == HOTKEY_MANAGER_USEONSELF then
Game.useInventoryItemWith(hotKey.itemId, Game.getLocalPlayer()) g_game.useInventoryItemWith(hotKey.itemId, g_game.getLocalPlayer())
elseif hotKey.useType == HOTKEY_MANAGER_USEONTARGET then elseif hotKey.useType == HOTKEY_MANAGER_USEONTARGET then
local attackingCreature = Game.getLocalPlayer():getAttackingCreature() local attackingCreature = g_game.getAttackingCreature()
if attackingCreature then if attackingCreature then
Game.useInventoryItemWith(hotKey.itemId, attackingCreature) g_game.useInventoryItemWith(hotKey.itemId, attackingCreature)
end end
elseif hotKey.useType == HOTKEY_MANAGER_USEWITH then elseif hotKey.useType == HOTKEY_MANAGER_USEWITH then
itemWidget:setItemId(hotKey.itemId) itemWidget:setItemId(hotKey.itemId)
Game.startUseWith(itemWidget:getItem()) g_game.startUseWith(itemWidget:getItem())
end end
end end
end end

View File

@ -6,7 +6,7 @@ local inventoryButton
-- public functions -- public functions
function Inventory.create() function Inventory.create()
inventoryWindow = displayUI('inventory.otui', { parent = Game.gameRightPanel }) inventoryWindow = displayUI('inventory.otui', { parent = g_game.gameRightPanel })
inventoryButton = TopMenu.addGameButton('inventoryButton', 'Inventory (Ctrl+I)', 'inventory.png', Inventory.toggle) inventoryButton = TopMenu.addGameButton('inventoryButton', 'Inventory (Ctrl+I)', 'inventory.png', Inventory.toggle)
inventoryButton:setOn(true) inventoryButton:setOn(true)
Keyboard.bindKeyDown('Ctrl+I', Inventory.toggle) Keyboard.bindKeyDown('Ctrl+I', Inventory.toggle)
@ -42,7 +42,7 @@ function Inventory.onSoulChange(soul)
widget:setText("Soul:\n" .. soul) widget:setText("Soul:\n" .. soul)
end end
connect(Game, { onGameStart = Inventory.create, connect(g_game, { onGameStart = Inventory.create,
onGameEnd = Inventory.destroy, onGameEnd = Inventory.destroy,
onInventoryChange = Inventory.onInventoryChange, onInventoryChange = Inventory.onInventoryChange,
onFreeCapacityChange = Inventory.onFreeCapacityChange, onFreeCapacityChange = Inventory.onFreeCapacityChange,

View File

@ -175,7 +175,7 @@ function Outfit.destroy()
end end
function Outfit.accept() function Outfit.accept()
Game.setOutfit(m_outfit) g_game.changeOutfit(m_outfit)
Outfit.destroy() Outfit.destroy()
end end
@ -198,5 +198,5 @@ function Outfit.previousType()
end end
-- hooked events -- hooked events
connect(Game, { onOpenOutfitWindow = Outfit.create, connect(g_game, { onOpenOutfitWindow = Outfit.create,
onGameEnd = Outfit.destroy }) onGameEnd = Outfit.destroy })

View File

@ -42,7 +42,7 @@ end
-- public functions -- public functions
function Skills.create() function Skills.create()
skillsWindow = displayUI('skills.otui', { parent = Game.gameRightPanel }) skillsWindow = displayUI('skills.otui', { parent = g_game.gameRightPanel })
skillsWindow:hide() skillsWindow:hide()
skillsButton = TopMenu.addGameButton('skillsButton', 'Skills (Ctrl+S)', '/core_styles/icons/skills.png', Skills.toggle) skillsButton = TopMenu.addGameButton('skillsButton', 'Skills (Ctrl+S)', '/core_styles/icons/skills.png', Skills.toggle)
Keyboard.bindKeyDown('Ctrl+S', Skills.toggle) Keyboard.bindKeyDown('Ctrl+S', Skills.toggle)
@ -122,7 +122,7 @@ function Skills.onSkillChange(id, level, percent)
setSkillPercent('skillId' .. id, percent, 'You have ' .. (100 - percent) .. ' percent to go') setSkillPercent('skillId' .. id, percent, 'You have ' .. (100 - percent) .. ' percent to go')
end end
connect(Game, { onGameStart = Skills.create, connect(g_game, { onGameStart = Skills.create,
onGameEnd = Skills.destroy, onGameEnd = Skills.destroy,
onExperienceChange = Skills.onExperienceChange, onExperienceChange = Skills.onExperienceChange,
onLevelChange = Skills.onLevelChange, onLevelChange = Skills.onLevelChange,

View File

@ -21,7 +21,7 @@ local centerLabel
-- private functions -- private functions
local function displayMessage(msgtype, msg, time) local function displayMessage(msgtype, msg, time)
if not Game.isOnline() then return end if not g_game.isOnline() then return end
if msgtype.consoleTab ~= nil then if msgtype.consoleTab ~= nil then
if msgtype.consoleOption == nil or Options[msgtype.consoleOption] then if msgtype.consoleOption == nil or Options[msgtype.consoleOption] then
@ -30,7 +30,7 @@ local function displayMessage(msgtype, msg, time)
end end
if msgtype.labelId then if msgtype.labelId then
local label = Game.gameMapPanel:recursiveGetChildById(msgtype.labelId) local label = g_game.gameMapPanel:recursiveGetChildById(msgtype.labelId)
label:setVisible(true) label:setVisible(true)
label:setText(msg) label:setText(msg)
@ -66,7 +66,7 @@ end
-- public functions -- public functions
function TextMessage.create() function TextMessage.create()
centerTextMessagePanel = createWidget('Panel', Game.gameMapPanel) centerTextMessagePanel = createWidget('Panel', g_game.gameMapPanel)
centerTextMessagePanel:setId('centerTextMessagePanel') centerTextMessagePanel:setId('centerTextMessagePanel')
local layout = UIVerticalLayout.create(centerTextMessagePanel) local layout = UIVerticalLayout.create(centerTextMessagePanel)
layout:setFitChildren(true) layout:setFitChildren(true)
@ -78,7 +78,7 @@ function TextMessage.create()
createTextMessageLabel('centerAdvance', centerTextMessagePanel) createTextMessageLabel('centerAdvance', centerTextMessagePanel)
createTextMessageLabel('centerInfo', centerTextMessagePanel) createTextMessageLabel('centerInfo', centerTextMessagePanel)
bottomStatusLabel = createTextMessageLabel('bottomStatus', Game.gameMapPanel) bottomStatusLabel = createTextMessageLabel('bottomStatus', g_game.gameMapPanel)
bottomStatusLabel:setHeight(16) bottomStatusLabel:setHeight(16)
bottomStatusLabel:addAnchor(AnchorBottom, 'parent', AnchorBottom) bottomStatusLabel:addAnchor(AnchorBottom, 'parent', AnchorBottom)
bottomStatusLabel:addAnchor(AnchorLeft, 'parent', AnchorLeft) bottomStatusLabel:addAnchor(AnchorLeft, 'parent', AnchorLeft)
@ -102,7 +102,7 @@ end
-- hooked events -- hooked events
local function onGameDeath() local function onGameDeath()
local advanceLabel = Game.gameMapPanel:recursiveGetChildById('centerAdvance') local advanceLabel = g_game.gameMapPanel:recursiveGetChildById('centerAdvance')
if advanceLabel:isVisible() then return end if advanceLabel:isVisible() then return end
TextMessage.displayEventAdvance('You are dead.') TextMessage.displayEventAdvance('You are dead.')
end end
@ -111,7 +111,7 @@ local function onGameTextMessage(msgtypedesc, msg)
TextMessage.display(msgtypedesc, msg) TextMessage.display(msgtypedesc, msg)
end end
connect(Game, { onGameStart = TextMessage.create, connect(g_game, { onGameStart = TextMessage.create,
onGameEnd = TextMessage.destroy, onGameEnd = TextMessage.destroy,
onDeath = onGameDeath, onDeath = onGameDeath,
onTextMessage = onGameTextMessage }) onTextMessage = onGameTextMessage })

View File

@ -7,7 +7,7 @@ local addVipWindow
-- public functions -- public functions
function VipList.create() function VipList.create()
vipWindow = displayUI('viplist.otui', { parent = Game.gameRightPanel }) vipWindow = displayUI('viplist.otui', { parent = g_game.gameRightPanel })
vipWindow:hide() vipWindow:hide()
vipButton = TopMenu.addGameButton('vipListButton', 'VIP list', 'viplist.png', VipList.toggle) vipButton = TopMenu.addGameButton('vipListButton', 'VIP list', 'viplist.png', VipList.toggle)
end end
@ -35,7 +35,7 @@ function VipList.destroyAddWindow()
end end
function VipList.addVip() function VipList.addVip()
Game.addVip(addVipWindow:getChildById('name'):getText()) g_game.addVip(addVipWindow:getChildById('name'):getText())
VipList.destroyAddWindow() VipList.destroyAddWindow()
end end
@ -56,7 +56,7 @@ function VipList.onAddVip(id, name, online)
label.vipOnline = online label.vipOnline = online
label:setPhantom(false) label:setPhantom(false)
connect(label, { onDoubleClick = function () Game.openPrivateChannel(label:getText()) return true end } ) connect(label, { onDoubleClick = function () g_game.openPrivateChannel(label:getText()) return true end } )
local nameLower = name:lower() local nameLower = name:lower()
local childrenCount = vipList:getChildCount() local childrenCount = vipList:getChildCount()
@ -114,7 +114,7 @@ function VipList.onVipListLabelMousePress(widget, mousePos, mouseButton)
local menu = createWidget('PopupMenu') local menu = createWidget('PopupMenu')
menu:addOption('Add new VIP', function() VipList.createAddWindow() end) menu:addOption('Add new VIP', function() VipList.createAddWindow() end)
menu:addOption('Remove ' .. widget:getText(), function() if widget then Game.removeVip(widget:getId():sub(4)) vipList:removeChild(widget) end end) menu:addOption('Remove ' .. widget:getText(), function() if widget then g_game.removeVip(widget:getId():sub(4)) vipList:removeChild(widget) end end)
menu:addSeparator() menu:addSeparator()
menu:addOption('Copy Name', function() g_window.setClipboardText(widget:getText()) end) menu:addOption('Copy Name', function() g_window.setClipboardText(widget:getText()) end)
menu:display(mousePos) menu:display(mousePos)
@ -123,7 +123,7 @@ function VipList.onVipListLabelMousePress(widget, mousePos, mouseButton)
end end
connect(Game, { onGameStart = VipList.create, connect(g_game, { onGameStart = VipList.create,
onGameEnd = VipList.destroy, onGameEnd = VipList.destroy,
onAddVip = VipList.onAddVip, onAddVip = VipList.onAddVip,
onVipStateChange = VipList.onVipStateChange }) onVipStateChange = VipList.onVipStateChange })

View File

@ -1,12 +1,12 @@
-- this file use loaded after everything is loaded and initialized -- this file use loaded after everything is loaded and initialized
-- you can place any custom user code here -- you can place any custom user code here
Keyboard.bindKeyDown('F1', function() Game.talk('exura gran') end) Keyboard.bindKeyDown('F1', function() g_game.talk('exura gran') end)
Keyboard.bindKeyDown('F2', function() Game.talk('exori mort') end) Keyboard.bindKeyDown('F2', function() g_game.talk('exori mort') end)
Keyboard.bindKeyDown('F3', function() Game.talk('exori frigo') end) Keyboard.bindKeyDown('F3', function() g_game.talk('exori frigo') end)
Keyboard.bindKeyDown('F4', function() Game.talk('exevo vis hur') end) Keyboard.bindKeyDown('F4', function() g_game.talk('exevo vis hur') end)
Keyboard.bindKeyDown('F5', function() Game.talk('utani gran hur') end) Keyboard.bindKeyDown('F5', function() g_game.talk('utani gran hur') end)
Keyboard.bindKeyDown('F6', function() Game.talk('exani tera') end) Keyboard.bindKeyDown('F6', function() g_game.talk('exani tera') end)
local function reload() local function reload()
dofile('otclientrc.lua') dofile('otclientrc.lua')

View File

@ -107,12 +107,19 @@ protected:
Outfit m_outfit; Outfit m_outfit;
Light m_light; Light m_light;
int m_speed; int m_speed;
uint8 m_skull, m_shield, m_emblem; uint8 m_skull;
TexturePtr m_skullTexture, m_shieldTexture, m_emblemTexture; uint8 m_shield;
bool m_showShieldTexture, m_shieldBlink; uint8 m_emblem;
TexturePtr m_skullTexture;
TexturePtr m_shieldTexture;
TexturePtr m_emblemTexture;
bool m_showShieldTexture;
bool m_shieldBlink;
bool m_passable; bool m_passable;
Color m_timedSquareColor, m_staticSquareColor; Color m_timedSquareColor;
bool m_showTimedSquare, m_showStaticSquare; Color m_staticSquareColor;
bool m_showTimedSquare;
bool m_showStaticSquare;
FontPtr m_informationFont; FontPtr m_informationFont;
Color m_informationColor; Color m_informationColor;

View File

@ -33,99 +33,117 @@
Game g_game; Game g_game;
void Game::loginWorld(const std::string& account, const std::string& password, const std::string& worldHost, int worldPort, const std::string& characterName) Game::Game()
{
resetGameStates();
}
void Game::resetGameStates()
{ {
m_dead = false; m_dead = false;
m_protocolGame = ProtocolGamePtr(new ProtocolGame); m_serverBeat = 50;
m_protocolGame->login(account, password, worldHost, (uint16)worldPort, characterName); m_fightMode = Otc::FightBalanced;
} m_chaseMode = Otc::DontChase;
m_safeFight = true;
void Game::cancelLogin() m_followingCreature = nullptr;
{ m_attackingCreature = nullptr;
if(m_protocolGame)
m_protocolGame->sendLogout();
processLogout();
}
void Game::forceLogout()
{
if(!isOnline())
return;
m_protocolGame->sendLogout();
processLogout();
}
void Game::safeLogout()
{
if(!isOnline())
return;
m_protocolGame->sendLogout();
}
void Game::processLoginError(const std::string& error)
{
g_lua.callGlobalField("Game", "onLoginError", error);
} }
void Game::processConnectionError(const boost::system::error_code& error) void Game::processConnectionError(const boost::system::error_code& error)
{ {
// connection errors only have meaning if we still have a protocol // connection errors only have meaning if we still have a protocol
if(m_protocolGame) { if(m_protocolGame) {
// eof = end of file, a clean disconnect
if(error != asio::error::eof) if(error != asio::error::eof)
g_lua.callGlobalField("Game", "onConnectionError", error.message()); g_lua.callGlobalField("g_game", "onConnectionError", error.message());
processLogout(); processDisconnect();
} }
} }
void Game::processGameStart(const LocalPlayerPtr& localPlayer, int serverBeat) void Game::processDisconnect()
{
m_localPlayer = localPlayer;
m_serverBeat = serverBeat;
// synchronize fight modes with the server
m_fightMode = Otc::FightBalanced;
m_chaseMode = Otc::DontChase;
m_safeFight = true;
m_protocolGame->sendFightTatics(m_fightMode, m_chaseMode, m_safeFight);
// NOTE: the entire map description and local player informations is not known yet
g_lua.callGlobalField("Game", "onGameStart");
}
void Game::processLogin()
{
if(!isOnline())
return;
g_lua.callGlobalField("Game", "onLogin", m_localPlayer);
}
void Game::processLogout()
{ {
if(isOnline()) { if(isOnline()) {
g_lua.callGlobalField("Game", "onLogout", m_localPlayer); // only process logout event if a previous the player is known
if(m_localPlayer->isKnown())
processLogout();
m_localPlayer = nullptr; m_localPlayer = nullptr;
g_lua.callGlobalField("Game", "onGameEnd"); processGameEnd();
} }
if(m_protocolGame) { if(m_protocolGame) {
m_protocolGame->disconnect(); m_protocolGame->disconnect();
m_protocolGame = nullptr; m_protocolGame = nullptr;
} }
//g_map.save();
} }
void Game::processDeath() void Game::processLoginError(const std::string& error)
{
g_lua.callGlobalField("g_game", "onLoginError", error);
}
void Game::processLoginAdvice(const std::string& message)
{
g_lua.callGlobalField("Game," "onLoginAdvice", message);
}
void Game::processLoginWait(const std::string& message, int time)
{
g_lua.callGlobalField("g_game", "onLoginWait", message, time);
}
void Game::processGameStart(const LocalPlayerPtr& localPlayer, int serverBeat)
{
// reset the new game state
resetGameStates();
m_localPlayer = localPlayer;
m_serverBeat = serverBeat;
// synchronize fight modes with the server
m_protocolGame->sendChangeFightModes(m_fightMode, m_chaseMode, m_safeFight);
// NOTE: the entire map description and local player informations is not known yet
g_lua.callGlobalField("g_game", "onGameStart");
}
void Game::processGameEnd()
{
g_lua.callGlobalField("g_game", "onGameEnd");
// reset game states
resetGameStates();
}
void Game::processLogin()
{
// the game could be offline if the login was canceled
if(!isOnline())
return;
// by now the local player must be known
g_lua.callGlobalField("g_game", "onLogin", m_localPlayer);
}
void Game::processLogout()
{
g_lua.callGlobalField("g_game", "onLogout", m_localPlayer);
}
void Game::processDeath(int penality)
{ {
m_dead = true; m_dead = true;
m_localPlayer->stopWalk(); m_localPlayer->stopWalk();
g_lua.callGlobalField("Game","onDeath");
g_lua.callGlobalField("g_game","onDeath", penality);
}
void Game::processPing()
{
m_protocolGame->sendPingResponse();
g_lua.callGlobalField("g_game", "onPing");
} }
void Game::processPlayerStats(double health, double maxHealth, void Game::processPlayerStats(double health, double maxHealth,
@ -139,7 +157,7 @@ void Game::processPlayerStats(double health, double maxHealth,
m_localPlayer->getMaxHealth() != maxHealth) { m_localPlayer->getMaxHealth() != maxHealth) {
m_localPlayer->setStatistic(Otc::Health, health); m_localPlayer->setStatistic(Otc::Health, health);
m_localPlayer->setStatistic(Otc::MaxHealth, maxHealth); m_localPlayer->setStatistic(Otc::MaxHealth, maxHealth);
g_lua.callGlobalField("Game", "onHealthChange", health, maxHealth); g_lua.callGlobalField("g_game", "onHealthChange", health, maxHealth);
// cannot walk while dying // cannot walk while dying
if(health == 0) { if(health == 0) {
@ -151,49 +169,49 @@ void Game::processPlayerStats(double health, double maxHealth,
if(m_localPlayer->getStatistic(Otc::FreeCapacity) != freeCapacity) { if(m_localPlayer->getStatistic(Otc::FreeCapacity) != freeCapacity) {
m_localPlayer->setStatistic(Otc::FreeCapacity, freeCapacity); m_localPlayer->setStatistic(Otc::FreeCapacity, freeCapacity);
g_lua.callGlobalField("Game", "onFreeCapacityChange", freeCapacity); g_lua.callGlobalField("g_game", "onFreeCapacityChange", freeCapacity);
} }
if(m_localPlayer->getStatistic(Otc::Experience) != experience) { if(m_localPlayer->getStatistic(Otc::Experience) != experience) {
m_localPlayer->setStatistic(Otc::Experience, experience); m_localPlayer->setStatistic(Otc::Experience, experience);
g_lua.callGlobalField("Game", "onExperienceChange", experience); g_lua.callGlobalField("g_game", "onExperienceChange", experience);
} }
if(m_localPlayer->getStatistic(Otc::Level) != level || if(m_localPlayer->getStatistic(Otc::Level) != level ||
m_localPlayer->getStatistic(Otc::LevelPercent) != levelPercent) { m_localPlayer->getStatistic(Otc::LevelPercent) != levelPercent) {
m_localPlayer->setStatistic(Otc::Level, level); m_localPlayer->setStatistic(Otc::Level, level);
m_localPlayer->setStatistic(Otc::LevelPercent, levelPercent); m_localPlayer->setStatistic(Otc::LevelPercent, levelPercent);
g_lua.callGlobalField("Game", "onLevelChange", level, levelPercent); g_lua.callGlobalField("g_game", "onLevelChange", level, levelPercent);
} }
if(m_localPlayer->getStatistic(Otc::Mana) != mana || if(m_localPlayer->getStatistic(Otc::Mana) != mana ||
m_localPlayer->getStatistic(Otc::MaxMana) != maxMana) { m_localPlayer->getStatistic(Otc::MaxMana) != maxMana) {
m_localPlayer->setStatistic(Otc::Mana, mana); m_localPlayer->setStatistic(Otc::Mana, mana);
m_localPlayer->setStatistic(Otc::MaxMana, maxMana); m_localPlayer->setStatistic(Otc::MaxMana, maxMana);
g_lua.callGlobalField("Game", "onManaChange", mana, maxMana); g_lua.callGlobalField("g_game", "onManaChange", mana, maxMana);
} }
if(m_localPlayer->getStatistic(Otc::MagicLevel) != magicLevel || if(m_localPlayer->getStatistic(Otc::MagicLevel) != magicLevel ||
m_localPlayer->getStatistic(Otc::MagicLevelPercent) != magicLevelPercent) { m_localPlayer->getStatistic(Otc::MagicLevelPercent) != magicLevelPercent) {
m_localPlayer->setStatistic(Otc::MagicLevel, magicLevel); m_localPlayer->setStatistic(Otc::MagicLevel, magicLevel);
m_localPlayer->setStatistic(Otc::MagicLevelPercent, magicLevelPercent); m_localPlayer->setStatistic(Otc::MagicLevelPercent, magicLevelPercent);
g_lua.callGlobalField("Game", "onMagicLevelChange", magicLevel, magicLevelPercent); g_lua.callGlobalField("g_game", "onMagicLevelChange", magicLevel, magicLevelPercent);
} }
if(m_localPlayer->getStatistic(Otc::Soul) != soul) { if(m_localPlayer->getStatistic(Otc::Soul) != soul) {
m_localPlayer->setStatistic(Otc::Soul, soul); m_localPlayer->setStatistic(Otc::Soul, soul);
g_lua.callGlobalField("Game", "onSoulChange", soul); g_lua.callGlobalField("g_game", "onSoulChange", soul);
} }
if(m_localPlayer->getStatistic(Otc::Stamina) != stamina) { if(m_localPlayer->getStatistic(Otc::Stamina) != stamina) {
m_localPlayer->setStatistic(Otc::Stamina, stamina); m_localPlayer->setStatistic(Otc::Stamina, stamina);
g_lua.callGlobalField("Game", "onStaminaChange", stamina); g_lua.callGlobalField("g_game", "onStaminaChange", stamina);
} }
} }
void Game::processTextMessage(const std::string& type, const std::string& message) void Game::processTextMessage(const std::string& type, const std::string& message)
{ {
g_lua.callGlobalField("Game","onTextMessage", type, message); g_lua.callGlobalField("g_game","onTextMessage", type, message);
} }
void Game::processCreatureSpeak(const std::string& name, int level, Otc::SpeakType type, const std::string& message, int channelId, const Position& creaturePos) void Game::processCreatureSpeak(const std::string& name, int level, Otc::SpeakType type, const std::string& message, int channelId, const Position& creaturePos)
@ -204,7 +222,12 @@ void Game::processCreatureSpeak(const std::string& name, int level, Otc::SpeakTy
g_map.addThing(staticText, creaturePos); g_map.addThing(staticText, creaturePos);
} }
g_lua.callGlobalField("Game", "onCreatureSpeak", name, level, type, message, channelId, creaturePos); g_lua.callGlobalField("g_game", "onCreatureSpeak", name, level, type, message, channelId, creaturePos);
}
void Game::processOpenContainer(int containerId, int itemId, const std::string& name, int capacity, bool hasParent, const std::vector< ItemPtr >& items)
{
g_lua.callGlobalField("g_game", "onOpenContainer", containerId, itemId, name, capacity, hasParent, items);
} }
void Game::processContainerAddItem(int containerId, const ItemPtr& item) void Game::processContainerAddItem(int containerId, const ItemPtr& item)
@ -212,7 +235,7 @@ void Game::processContainerAddItem(int containerId, const ItemPtr& item)
if(item) if(item)
item->setPosition(Position(65535, containerId + 0x40, 0)); item->setPosition(Position(65535, containerId + 0x40, 0));
g_lua.callGlobalField("Game", "onContainerAddItem", containerId, item); g_lua.callGlobalField("g_game", "onContainerAddItem", containerId, item);
} }
void Game::processInventoryChange(int slot, const ItemPtr& item) void Game::processInventoryChange(int slot, const ItemPtr& item)
@ -220,7 +243,7 @@ void Game::processInventoryChange(int slot, const ItemPtr& item)
if(item) if(item)
item->setPosition(Position(65535, slot, 0)); item->setPosition(Position(65535, slot, 0));
g_lua.callGlobalField("Game","onInventoryChange", slot, item); g_lua.callGlobalField("g_game","onInventoryChange", slot, item);
} }
void Game::processCreatureMove(const CreaturePtr& creature, const Position& oldPos, const Position& newPos) void Game::processCreatureMove(const CreaturePtr& creature, const Position& oldPos, const Position& newPos)
@ -235,14 +258,15 @@ void Game::processCreatureTeleport(const CreaturePtr& creature)
// stop walking on creature teleports // stop walking on creature teleports
creature->stopWalk(); creature->stopWalk();
// locks the walk for a while when teleporting
if(creature == m_localPlayer) if(creature == m_localPlayer)
m_localPlayer->lockWalk(); m_localPlayer->lockWalk();
} }
void Game::processAttackCancel() void Game::processAttackCancel()
{ {
if(m_localPlayer->isAttacking()) if(isAttacking())
m_localPlayer->setAttackingCreature(nullptr); setAttackingCreature(nullptr);
} }
void Game::processWalkCancel(Otc::Direction direction) void Game::processWalkCancel(Otc::Direction direction)
@ -250,12 +274,44 @@ void Game::processWalkCancel(Otc::Direction direction)
m_localPlayer->cancelWalk(direction); m_localPlayer->cancelWalk(direction);
} }
void Game::walk(Otc::Direction direction) void Game::loginWorld(const std::string& account, const std::string& password, const std::string& worldHost, int worldPort, const std::string& characterName)
{ {
if(!isOnline() || !m_localPlayer->isKnown() || isDead() || !checkBotProtection()) m_protocolGame = ProtocolGamePtr(new ProtocolGame);
m_protocolGame->login(account, password, worldHost, (uint16)worldPort, characterName);
}
void Game::cancelLogin()
{
// send logout even if the game has not started yet, to make sure that the player doesn't stay logged there
if(m_protocolGame)
m_protocolGame->sendLogout();
processDisconnect();
}
void Game::forceLogout()
{
if(!isOnline())
return; return;
if(m_localPlayer->isFollowing()) m_protocolGame->sendLogout();
processDisconnect();
}
void Game::safeLogout()
{
if(!isOnline())
return;
m_protocolGame->sendLogout();
}
void Game::walk(Otc::Direction direction)
{
if(!canPerformGameAction())
return;
if(isFollowing())
cancelFollow(); cancelFollow();
if(!m_localPlayer->canWalk(direction)) if(!m_localPlayer->canWalk(direction))
@ -271,9 +327,20 @@ void Game::walk(Otc::Direction direction)
forceWalk(direction); forceWalk(direction);
} }
void Game::walkPath(const std::vector<Otc::Direction>& dir)
{
if(!canPerformGameAction())
return;
if(isFollowing())
cancelFollow();
m_protocolGame->sendWalkPath(dir);
}
void Game::forceWalk(Otc::Direction direction) void Game::forceWalk(Otc::Direction direction)
{ {
if(!isOnline() || !checkBotProtection()) if(!canPerformGameAction())
return; return;
switch(direction) { switch(direction) {
@ -306,7 +373,7 @@ void Game::forceWalk(Otc::Direction direction)
void Game::turn(Otc::Direction direction) void Game::turn(Otc::Direction direction)
{ {
if(!isOnline()) if(!canPerformGameAction())
return; return;
switch(direction) { switch(direction) {
@ -325,25 +392,46 @@ void Game::turn(Otc::Direction direction)
} }
} }
void Game::look(const ThingPtr& thing) void Game::stop()
{ {
if(!isOnline() || !thing || !checkBotProtection()) if(!canPerformGameAction())
return; return;
m_protocolGame->sendLookAt(thing->getPosition(), thing->getId(), thing->getStackpos()); if(isFollowing())
cancelFollow();
m_protocolGame->sendStop();
} }
void Game::open(const ItemPtr& item, int containerId) void Game::look(const ThingPtr& thing)
{ {
if(!isOnline() || !item || !checkBotProtection()) if(!canPerformGameAction() || !thing)
return; return;
m_protocolGame->sendUseItem(item->getPosition(), item->getId(), item->getStackpos(), containerId); m_protocolGame->sendLook(thing->getPosition(), thing->getId(), thing->getStackpos());
}
void Game::move(const ThingPtr& thing, const Position& toPos, int count)
{
if(!canPerformGameAction() || !thing || thing->getPosition() == toPos || count <= 0)
return;
m_localPlayer->lockWalk();
m_protocolGame->sendMove(thing->getPosition(), thing->getId(), thing->getStackpos(), toPos, count);
}
void Game::rotate(const ThingPtr& thing)
{
if(!canPerformGameAction() || !thing)
return;
m_protocolGame->sendRotateItem(thing->getPosition(), thing->getId(), thing->getStackpos());
} }
void Game::use(const ThingPtr& thing) void Game::use(const ThingPtr& thing)
{ {
if(!isOnline() || !thing || !checkBotProtection()) if(!canPerformGameAction() || !thing)
return; return;
Position pos = thing->getPosition(); Position pos = thing->getPosition();
@ -357,7 +445,7 @@ void Game::use(const ThingPtr& thing)
void Game::useInventoryItem(int itemId) void Game::useInventoryItem(int itemId)
{ {
if(!isOnline() || !checkBotProtection()) if(!canPerformGameAction() || !g_thingsType.isValidItemId(itemId))
return; return;
Position pos = Position(0xFFFF, 0, 0); // means that is a item in inventory Position pos = Position(0xFFFF, 0, 0); // means that is a item in inventory
@ -368,7 +456,7 @@ void Game::useInventoryItem(int itemId)
void Game::useWith(const ItemPtr& item, const ThingPtr& toThing) void Game::useWith(const ItemPtr& item, const ThingPtr& toThing)
{ {
if(!isOnline() || !item || !toThing || !checkBotProtection()) if(!canPerformGameAction() || !item || !toThing)
return; return;
Position pos = item->getPosition(); Position pos = item->getPosition();
@ -380,12 +468,12 @@ void Game::useWith(const ItemPtr& item, const ThingPtr& toThing)
if(CreaturePtr creature = toThing->asCreature()) if(CreaturePtr creature = toThing->asCreature())
m_protocolGame->sendUseOnCreature(pos, item->getId(), item->getStackpos(), creature->getId()); m_protocolGame->sendUseOnCreature(pos, item->getId(), item->getStackpos(), creature->getId());
else else
m_protocolGame->sendUseItemEx(pos, item->getId(), item->getStackpos(), toThing->getPosition(), toThing->getId(), toThing->getStackpos()); m_protocolGame->sendUseItemWith(pos, item->getId(), item->getStackpos(), toThing->getPosition(), toThing->getId(), toThing->getStackpos());
} }
void Game::useInventoryItemWith(int itemId, const ThingPtr& toThing) void Game::useInventoryItemWith(int itemId, const ThingPtr& toThing)
{ {
if(!isOnline() || !toThing || !checkBotProtection()) if(!canPerformGameAction() || !toThing)
return; return;
m_localPlayer->lockWalk(); m_localPlayer->lockWalk();
@ -395,212 +483,207 @@ void Game::useInventoryItemWith(int itemId, const ThingPtr& toThing)
if(CreaturePtr creature = toThing->asCreature()) if(CreaturePtr creature = toThing->asCreature())
m_protocolGame->sendUseOnCreature(pos, itemId, 0, creature->getId()); m_protocolGame->sendUseOnCreature(pos, itemId, 0, creature->getId());
else else
m_protocolGame->sendUseItemEx(pos, itemId, 0, toThing->getPosition(), toThing->getId(), toThing->getStackpos()); m_protocolGame->sendUseItemWith(pos, itemId, 0, toThing->getPosition(), toThing->getId(), toThing->getStackpos());
} }
void Game::move(const ThingPtr& thing, const Position& toPos, int count) void Game::open(const ItemPtr& item, int containerId)
{ {
if(!isOnline() || !thing || !checkBotProtection() || thing->getPosition() == toPos || count <= 0) if(!canPerformGameAction() || !item)
return; return;
m_localPlayer->lockWalk(); m_protocolGame->sendUseItem(item->getPosition(), item->getId(), item->getStackpos(), containerId);
m_protocolGame->sendThrow(thing->getPosition(), thing->getId(), thing->getStackpos(), toPos, count);
} }
void Game::setChaseMode(Otc::ChaseModes chaseMode) void Game::upContainer(int containerId)
{ {
if(!isOnline() || !checkBotProtection()) if(!canPerformGameAction())
return; return;
m_protocolGame->sendUpContainer(containerId);
m_chaseMode = chaseMode;
m_protocolGame->sendFightTatics(m_fightMode, m_chaseMode, m_safeFight);
} }
void Game::setFightMode(Otc::FightModes fightMode) void Game::refreshContainer()
{ {
if(!isOnline() || !checkBotProtection()) if(!canPerformGameAction())
return; return;
m_protocolGame->sendRefreshContainer();
m_fightMode = fightMode;
m_protocolGame->sendFightTatics(m_fightMode, m_chaseMode, m_safeFight);
}
void Game::setSafeFight(bool on)
{
if(!isOnline() || !checkBotProtection())
return;
m_safeFight = on;
m_protocolGame->sendFightTatics(m_fightMode, m_chaseMode, m_safeFight);
} }
void Game::attack(const CreaturePtr& creature) void Game::attack(const CreaturePtr& creature)
{ {
if(!isOnline() || !creature || !checkBotProtection()) if(!canPerformGameAction() || creature == m_localPlayer || creature == m_attackingCreature)
return; return;
m_localPlayer->lockWalk(); m_localPlayer->lockWalk();
if(m_localPlayer->isFollowing()) if(creature && isFollowing())
cancelFollow(); cancelFollow();
m_localPlayer->setAttackingCreature(creature); setAttackingCreature(creature);
m_protocolGame->sendAttack(creature->getId()); m_protocolGame->sendAttack(creature ? creature->getId() : 0);
}
void Game::cancelAttack()
{
m_localPlayer->lockWalk();
m_localPlayer->setAttackingCreature(nullptr);
m_protocolGame->sendAttack(0);
} }
void Game::follow(const CreaturePtr& creature) void Game::follow(const CreaturePtr& creature)
{ {
if(!isOnline() || !creature || !checkBotProtection()) if(!canPerformGameAction() || creature == m_localPlayer || creature == m_followingCreature)
return; return;
if(m_localPlayer->isAttacking()) m_localPlayer->lockWalk();
if(creature && isAttacking())
cancelAttack(); cancelAttack();
m_localPlayer->setFollowingCreature(creature); setFollowingCreature(creature);
m_protocolGame->sendFollow(creature->getId()); m_protocolGame->sendFollow(creature ? creature->getId() : 0);
} }
void Game::cancelFollow() void Game::cancelAttackAndFollow()
{ {
if(!isOnline() || !checkBotProtection()) if(!canPerformGameAction())
return; return;
m_localPlayer->setFollowingCreature(nullptr); m_localPlayer->lockWalk();
m_protocolGame->sendFollow(0);
}
void Game::rotate(const ThingPtr& thing) setAttackingCreature(nullptr);
{ setFollowingCreature(nullptr);
if(!isOnline() || !thing || !checkBotProtection()) m_protocolGame->sendCancelAttackAndFollow();
return;
m_protocolGame->sendRotateItem(thing->getPosition(), thing->getId(), thing->getStackpos());
} }
void Game::talk(const std::string& message) void Game::talk(const std::string& message)
{ {
if(!canPerformGameAction() || message.empty())
return;
talkChannel(Otc::SpeakSay, 0, message); talkChannel(Otc::SpeakSay, 0, message);
} }
void Game::talkChannel(Otc::SpeakType speakType, int channelId, const std::string& message) void Game::talkChannel(Otc::SpeakType speakType, int channelId, const std::string& message)
{ {
if(!isOnline() || !checkBotProtection()) if(!canPerformGameAction() || message.empty())
return; return;
m_protocolGame->sendTalk(speakType, channelId, "", message); m_protocolGame->sendTalk(speakType, channelId, "", message);
} }
void Game::talkPrivate(Otc::SpeakType speakType, const std::string& receiver, const std::string& message) void Game::talkPrivate(Otc::SpeakType speakType, const std::string& receiver, const std::string& message)
{ {
if(!isOnline() || !checkBotProtection()) if(!canPerformGameAction() || receiver.empty() || message.empty())
return; return;
m_protocolGame->sendTalk(speakType, 0, receiver, message); m_protocolGame->sendTalk(speakType, 0, receiver, message);
} }
void Game::openPrivateChannel(const std::string& receiver) void Game::openPrivateChannel(const std::string& receiver)
{ {
if(!isOnline() || !checkBotProtection()) if(!canPerformGameAction() || receiver.empty())
return; return;
m_protocolGame->sendOpenPrivateChannel(receiver); m_protocolGame->sendOpenPrivateChannel(receiver);
} }
void Game::requestChannels() void Game::requestChannels()
{ {
if(!isOnline() || !checkBotProtection()) if(!canPerformGameAction())
return; return;
m_protocolGame->sendGetChannels(); m_protocolGame->sendRequestChannels();
} }
void Game::joinChannel(int channelId) void Game::joinChannel(int channelId)
{ {
if(!isOnline() || !checkBotProtection()) if(!canPerformGameAction())
return; return;
m_protocolGame->sendJoinChannel(channelId); m_protocolGame->sendJoinChannel(channelId);
} }
void Game::leaveChannel(int channelId) void Game::leaveChannel(int channelId)
{ {
if(!isOnline() || !checkBotProtection()) if(!canPerformGameAction())
return; return;
m_protocolGame->sendLeaveChannel(channelId); m_protocolGame->sendLeaveChannel(channelId);
} }
void Game::closeNpcChannel() void Game::closeNpcChannel()
{ {
if(!isOnline() || !checkBotProtection()) if(!canPerformGameAction())
return; return;
m_protocolGame->sendCloseNpcChannel(); m_protocolGame->sendCloseNpcChannel();
} }
void Game::openOwnChannel()
{
if(!canPerformGameAction())
return;
m_protocolGame->sendOpenOwnChannel();
}
void Game::inviteToOwnChannel(const std::string& name)
{
if(!canPerformGameAction() || name.empty())
return;
m_protocolGame->sendInviteToOwnChannel(name);
}
void Game::excludeFromOwnChannel(const std::string& name)
{
if(!canPerformGameAction() || name.empty())
return;
m_protocolGame->sendExcludeFromOwnChannel(name);
}
void Game::partyInvite(int creatureId) void Game::partyInvite(int creatureId)
{ {
if(!isOnline() || !checkBotProtection()) if(!canPerformGameAction())
return; return;
m_protocolGame->sendInviteToParty(creatureId); m_protocolGame->sendInviteToParty(creatureId);
} }
void Game::partyJoin(int creatureId) void Game::partyJoin(int creatureId)
{ {
if(!isOnline() || !checkBotProtection()) if(!canPerformGameAction())
return; return;
m_protocolGame->sendJoinParty(creatureId); m_protocolGame->sendJoinParty(creatureId);
} }
void Game::partyRevokeInvitation(int creatureId) void Game::partyRevokeInvitation(int creatureId)
{ {
if(!isOnline() || !checkBotProtection()) if(!canPerformGameAction())
return; return;
m_protocolGame->sendRevokeInvitation(creatureId); m_protocolGame->sendRevokeInvitation(creatureId);
} }
void Game::partyPassLeadership(int creatureId) void Game::partyPassLeadership(int creatureId)
{ {
if(!isOnline() || !checkBotProtection()) if(!canPerformGameAction())
return; return;
m_protocolGame->sendPassLeadership(creatureId); m_protocolGame->sendPassLeadership(creatureId);
} }
void Game::partyLeave() void Game::partyLeave()
{ {
if(!isOnline() || !checkBotProtection()) if(!canPerformGameAction())
return; return;
m_protocolGame->sendLeaveParty(); m_protocolGame->sendLeaveParty();
} }
void Game::partyShareExperience(bool active) void Game::partyShareExperience(bool active)
{ {
if(!isOnline() || !checkBotProtection()) if(!canPerformGameAction())
return; return;
m_protocolGame->sendShareExperience(active, 0); m_protocolGame->sendShareExperience(active, 0);
} }
void Game::requestOutfit() void Game::requestOutfit()
{ {
if(!isOnline() || !checkBotProtection()) if(!canPerformGameAction())
return; return;
m_protocolGame->sendGetOutfit(); m_protocolGame->sendRequestOutfit();
} }
void Game::setOutfit(const Outfit& outfit) void Game::changeOutfit(const Outfit& outfit)
{ {
if(!isOnline() || !checkBotProtection()) if(!canPerformGameAction())
return; return;
m_protocolGame->sendSetOutfit(outfit); m_protocolGame->sendChangeOutfit(outfit);
} }
void Game::addVip(const std::string& name) void Game::addVip(const std::string& name)
{ {
if(!isOnline() || name.empty() || !checkBotProtection()) if(!canPerformGameAction() || name.empty())
return; return;
m_protocolGame->sendAddVip(name); m_protocolGame->sendAddVip(name);
} }
@ -612,9 +695,38 @@ void Game::removeVip(int playerId)
m_protocolGame->sendRemoveVip(playerId); m_protocolGame->sendRemoveVip(playerId);
} }
void Game::setChaseMode(Otc::ChaseModes chaseMode)
{
if(!canPerformGameAction())
return;
m_chaseMode = chaseMode;
m_protocolGame->sendChangeFightModes(m_fightMode, m_chaseMode, m_safeFight);
}
void Game::setFightMode(Otc::FightModes fightMode)
{
if(!canPerformGameAction())
return;
m_fightMode = fightMode;
m_protocolGame->sendChangeFightModes(m_fightMode, m_chaseMode, m_safeFight);
}
void Game::setSafeFight(bool on)
{
if(!canPerformGameAction())
return;
m_safeFight = on;
m_protocolGame->sendChangeFightModes(m_fightMode, m_chaseMode, m_safeFight);
}
bool Game::checkBotProtection() bool Game::checkBotProtection()
{ {
#ifdef BOT_PROTECTION #ifdef BOT_PROTECTION
// accepts calls comming from a stacktrace containing only C++ functions,
// if the stacktrace contains a lua function, then only accept if the engine is processing an input event
if(g_lua.isInCppCallback() && !g_ui.isOnInputEvent()) { if(g_lua.isInCppCallback() && !g_ui.isOnInputEvent()) {
logError("caught a lua call to a bot protected game function, the call was canceled"); logError("caught a lua call to a bot protected game function, the call was canceled");
return false; return false;
@ -622,3 +734,45 @@ bool Game::checkBotProtection()
#endif #endif
return true; return true;
} }
bool Game::canPerformGameAction()
{
// we can only perform game actions if we meet these conditions:
// - the local player exists
// - the local player is known
// - the local player is not dead
// - we have a game protocol
// - the game protocol is connected
// - its not a bot action
return m_localPlayer && m_localPlayer->isKnown() && !m_dead && m_protocolGame && m_protocolGame->isConnected() && checkBotProtection();
}
void Game::setAttackingCreature(const CreaturePtr& creature)
{
if(m_attackingCreature) {
m_attackingCreature->hideStaticSquare();
m_attackingCreature = nullptr;
}
if(creature) {
creature->showStaticSquare(Fw::red);
m_attackingCreature = creature;
}
g_lua.callGlobalField("g_game", "onAttackingCreatureChange", creature);
}
void Game::setFollowingCreature(const CreaturePtr& creature)
{
if(m_followingCreature) {
m_followingCreature->hideStaticSquare();
m_followingCreature = nullptr;
}
if(creature) {
creature->showStaticSquare(Fw::green);
m_followingCreature = creature;
}
g_lua.callGlobalField("g_game", "onFollowingCreatureChange", creature);
}

View File

@ -32,20 +32,87 @@
class Game class Game
{ {
public: public:
void loginWorld(const std::string& account, Game();
const std::string& password,
const std::string& worldHost, int worldPort, private:
const std::string& characterName); void resetGameStates();
void cancelLogin();
void logout(bool force); protected:
void forceLogout();
void safeLogout(); /*
void processLoginError(const std::string& error); void parseMapDescription(InputMessage& msg);
void parseMapMoveNorth(InputMessage& msg);
void parseMapMoveEast(InputMessage& msg);
void parseMapMoveSouth(InputMessage& msg);
void parseMapMoveWest(InputMessage& msg);
void parseUpdateTile(InputMessage& msg);
void parseTileAddThing(InputMessage& msg);
void parseTileTransformThing(InputMessage& msg);
void parseTileRemoveThing(InputMessage& msg);
void parseCreatureMove(InputMessage& msg);
void parseOpenContainer(InputMessage& msg);
void parseCloseContainer(InputMessage& msg);
void parseContainerAddItem(InputMessage& msg);
void parseContainerUpdateItem(InputMessage& msg);
void parseContainerRemoveItem(InputMessage& msg);
void parseAddInventoryItem(InputMessage& msg);
void parseRemoveInventoryItem(InputMessage& msg);
void parseNpcOffer(InputMessage& msg);
void parsePlayerCash(InputMessage& msg);
void parseCloseShopWindow(InputMessage&);
void parseWorldLight(InputMessage& msg);
void parseMagicEffect(InputMessage& msg);
void parseAnimatedText(InputMessage& msg);
void parseDistanceMissile(InputMessage& msg);
void parseCreatureSquare(InputMessage& msg);
void parseCreatureHealth(InputMessage& msg);
void parseCreatureLight(InputMessage& msg);
void parseCreatureOutfit(InputMessage& msg);
void parseCreatureSpeed(InputMessage& msg);
void parseCreatureSkulls(InputMessage& msg);
void parseCreatureShields(InputMessage& msg);
void parseCreatureTurn(InputMessage& msg);
void parseItemTextWindow(InputMessage& msg);
void parseHouseTextWindow(InputMessage& msg);
void parsePlayerStats(InputMessage& msg);
void parsePlayerSkills(InputMessage& msg);
void parsePlayerIcons(InputMessage& msg);
void parsePlayerCancelAttack(InputMessage& msg);
void parseCreatureSpeak(InputMessage& msg);
void parseCloseChannel(InputMessage& msg);
void parseSafeTradeRequest(InputMessage& msg);
void parseSafeTradeClose(InputMessage&);
void parseTextMessage(InputMessage& msg);
void parseCancelWalk(InputMessage& msg);
void parseFloorChangeUp(InputMessage& msg);
void parseFloorChangeDown(InputMessage& msg);
void parseOutfitWindow(InputMessage& msg);
void parseShowTutorial(InputMessage& msg);
void parseAddMarker(InputMessage& msg);
*/
void processConnectionError(const boost::system::error_code& error); void processConnectionError(const boost::system::error_code& error);
void processGameStart(const LocalPlayerPtr& localPlayer, int serverBeat); void processDisconnect();
void processPing();
void processLoginError(const std::string& error);
void processLoginAdvice(const std::string& message);
void processLoginWait(const std::string& message, int time);
void processLogin(); void processLogin();
void processLogout(); void processLogout();
void processDeath();
void processGameStart(const LocalPlayerPtr& localPlayer, int serverBeat);
void processGameEnd();
void processDeath(int penality);
void processPlayerStats(double health, double maxHealth, void processPlayerStats(double health, double maxHealth,
double freeCapacity, double experience, double freeCapacity, double experience,
double level, double levelPercent, double level, double levelPercent,
@ -54,51 +121,84 @@ public:
double soul, double stamina); double soul, double stamina);
void processTextMessage(const std::string& type, const std::string& message); void processTextMessage(const std::string& type, const std::string& message);
void processCreatureSpeak(const std::string& name, int level, Otc::SpeakType type, const std::string& message, int channelId, const Position& creaturePos); void processCreatureSpeak(const std::string& name, int level, Otc::SpeakType type, const std::string& message, int channelId, const Position& creaturePos);
void processOpenContainer(int containerId, int itemId, const std::string& name, int capacity, bool hasParent, const std::vector<ItemPtr>& items);
void processContainerAddItem(int containerId, const ItemPtr& item); void processContainerAddItem(int containerId, const ItemPtr& item);
void processInventoryChange(int slot, const ItemPtr& item); void processInventoryChange(int slot, const ItemPtr& item);
void processCreatureMove(const CreaturePtr& creature, const Position& oldPos, const Position& newPos); void processCreatureMove(const CreaturePtr& creature, const Position& oldPos, const Position& newPos);
void processCreatureTeleport(const CreaturePtr& creature); void processCreatureTeleport(const CreaturePtr& creature);
void processAttackCancel(); void processAttackCancel();
void processWalkCancel(Otc::Direction direction); void processWalkCancel(Otc::Direction direction);
// processChannelList
// processOpenChannel
// processOpenPrivateChannel
// processOpenOwnPrivateChannel
// vip
// processVipList
// processVipLogin
// processVipLogout
// processQuestLog
// processQuestLine
friend class ProtocolGame;
friend class Map;
public:
// login related
void loginWorld(const std::string& account,
const std::string& password,
const std::string& worldHost, int worldPort,
const std::string& characterName);
void cancelLogin();
void forceLogout();
void safeLogout();
// walk related // walk related
void walk(Otc::Direction direction); void walk(Otc::Direction direction);
void walkPath(const std::vector<Otc::Direction>& dir);
void forceWalk(Otc::Direction direction); void forceWalk(Otc::Direction direction);
void turn(Otc::Direction direction); void turn(Otc::Direction direction);
void stop();
// item related // item related
void look(const ThingPtr& thing); void look(const ThingPtr& thing);
void open(const ItemPtr& item, int containerId); void move(const ThingPtr &thing, const Position& toPos, int count);
void rotate(const ThingPtr& thing);
void use(const ThingPtr& thing); void use(const ThingPtr& thing);
void useWith(const ItemPtr& fromThing, const ThingPtr& toThing); void useWith(const ItemPtr& fromThing, const ThingPtr& toThing);
void useInventoryItem(int itemId); void useInventoryItem(int itemId);
void useInventoryItemWith(int itemId, const ThingPtr& toThing); void useInventoryItemWith(int itemId, const ThingPtr& toThing);
void move(const ThingPtr &thing, const Position& toPos, int count);
// fight tatics related // container related
void setChaseMode(Otc::ChaseModes chaseMode); void open(const ItemPtr& item, int containerId);
void setFightMode(Otc::FightModes fightMode); void upContainer(int containerId);
void setSafeFight(bool on); void refreshContainer();
Otc::ChaseModes getChaseMode() { return m_chaseMode; }
Otc::FightModes getFightMode() { return m_fightMode; }
bool isSafeFight() { return m_safeFight; }
// attack/follow related // attack/follow related
void attack(const CreaturePtr& creature); void attack(const CreaturePtr& creature);
void cancelAttack(); void cancelAttack() { attack(nullptr); }
void follow(const CreaturePtr& creature); void follow(const CreaturePtr& creature);
void cancelFollow(); void cancelFollow() { follow(nullptr); }
void rotate(const ThingPtr& thing); void cancelAttackAndFollow();
// talk related // talk related
void talk(const std::string& message); void talk(const std::string& message);
void talkChannel(Otc::SpeakType speakType, int channelId, const std::string& message); void talkChannel(Otc::SpeakType speakType, int channelId, const std::string& message);
void talkPrivate(Otc::SpeakType speakType, const std::string& receiver, const std::string& message); void talkPrivate(Otc::SpeakType speakType, const std::string& receiver, const std::string& message);
// channel related
void openPrivateChannel(const std::string& receiver); void openPrivateChannel(const std::string& receiver);
void requestChannels(); void requestChannels();
void joinChannel(int channelId); void joinChannel(int channelId);
void leaveChannel(int channelId); void leaveChannel(int channelId);
void closeNpcChannel(); void closeNpcChannel();
void openOwnChannel();
void inviteToOwnChannel(const std::string& name);
void excludeFromOwnChannel(const std::string& name);
// party related // party related
void partyInvite(int creatureId); void partyInvite(int creatureId);
@ -110,30 +210,65 @@ public:
// outfit related // outfit related
void requestOutfit(); void requestOutfit();
void setOutfit(const Outfit& outfit); void changeOutfit(const Outfit& outfit);
// vip related // vip related
void addVip(const std::string& name); void addVip(const std::string& name);
void removeVip(int playerId); void removeVip(int playerId);
// fight modes related
void setChaseMode(Otc::ChaseModes chaseMode);
void setFightMode(Otc::FightModes fightMode);
void setSafeFight(bool on);
Otc::ChaseModes getChaseMode() { return m_chaseMode; }
Otc::FightModes getFightMode() { return m_fightMode; }
bool isSafeFight() { return m_safeFight; }
// npc trade related
//void inspectNpcTrade();
//void buyItem();
//void sellItem();
//void closeNpcTrade();
// player trade related
//void requestTrade();
//void inspectTrade();
//void acceptTrade();
//void rejectTrade();
// house window and editable items related
//void editText();
//void editList();
// questlog related
//void requestQuestLog();
//void requestQuestLogLine();
bool canPerformGameAction();
bool checkBotProtection(); bool checkBotProtection();
bool isOnline() { return !!m_localPlayer; } bool isOnline() { return !!m_localPlayer; }
bool isDead() { return m_dead; } bool isDead() { return m_dead; }
bool isAttacking() { return !!m_attackingCreature; }
bool isFollowing() { return !!m_followingCreature; }
void setServerBeat(int serverBeat) { m_serverBeat = serverBeat; } CreaturePtr getAttackingCreature() { return m_attackingCreature; }
CreaturePtr getFollowingCreature() { return m_followingCreature; }
int getServerBeat() { return m_serverBeat; } int getServerBeat() { return m_serverBeat; }
LocalPlayerPtr getLocalPlayer() { return m_localPlayer; } LocalPlayerPtr getLocalPlayer() { return m_localPlayer; }
ProtocolGamePtr getProtocolGame() { return m_protocolGame; } ProtocolGamePtr getProtocolGame() { return m_protocolGame; }
int getProtocolVersion() { return PROTOCOL; } int getProtocolVersion() { return PROTOCOL; }
private: private:
void setAttackingCreature(const CreaturePtr& creature);
void setFollowingCreature(const CreaturePtr& creature);
LocalPlayerPtr m_localPlayer; LocalPlayerPtr m_localPlayer;
CreaturePtr m_attackingCreature;
CreaturePtr m_followingCreature;
ProtocolGamePtr m_protocolGame; ProtocolGamePtr m_protocolGame;
bool m_dead; bool m_dead;
int m_serverBeat; int m_serverBeat;
Otc::FightModes m_fightMode; Otc::FightModes m_fightMode;
Otc::ChaseModes m_chaseMode; Otc::ChaseModes m_chaseMode;
bool m_safeFight; bool m_safeFight;

View File

@ -28,7 +28,6 @@
LocalPlayer::LocalPlayer() LocalPlayer::LocalPlayer()
{ {
m_preWalking = false; m_preWalking = false;
m_canReportBugs = false;
m_known = false; m_known = false;
m_walkLocked = false; m_walkLocked = false;
m_lastPrewalkDone = true; m_lastPrewalkDone = true;
@ -158,34 +157,4 @@ void LocalPlayer::terminateWalk()
m_preWalking = false; m_preWalking = false;
} }
void LocalPlayer::setAttackingCreature(const CreaturePtr& creature)
{
// clear current attacking creature
if(m_attackingCreature) {
m_attackingCreature->hideStaticSquare();
m_attackingCreature = nullptr;
}
// set the new attacking creature
if(creature) {
creature->showStaticSquare(Fw::red);
m_attackingCreature = creature;
}
g_lua.callGlobalField("Game", "onSetAttackingCreature", creature);
}
void LocalPlayer::setFollowingCreature(const CreaturePtr& creature)
{
// clear current following creature
if(m_followingCreature) {
m_followingCreature->hideStaticSquare();
m_followingCreature = nullptr;
}
// set the new attacking creature
if(creature) {
creature->showStaticSquare(Fw::green);
m_followingCreature = creature;
}
}

View File

@ -34,24 +34,16 @@ class LocalPlayer : public Player
public: public:
LocalPlayer(); LocalPlayer();
void setCanReportBugs(uint8 canReportBugs) { m_canReportBugs = (canReportBugs != 0); }
void setSkill(Otc::Skill skill, Otc::SkillType skillType, int value) { m_skills[skill][skillType] = value; } void setSkill(Otc::Skill skill, Otc::SkillType skillType, int value) { m_skills[skill][skillType] = value; }
void setStatistic(Otc::Statistic statistic, double value) { m_statistics[statistic] = value; } void setStatistic(Otc::Statistic statistic, double value) { m_statistics[statistic] = value; }
void setAttackingCreature(const CreaturePtr& creature);
void setFollowingCreature(const CreaturePtr& creature);
void setIcons(int icons) { m_icons = icons; } void setIcons(int icons) { m_icons = icons; }
void setKnown(bool known) { m_known = known; } void setKnown(bool known) { m_known = known; }
bool getCanReportBugs() { return m_canReportBugs; }
int getSkill(Otc::Skill skill, Otc::SkillType skillType) { return m_skills[skill][skillType]; } int getSkill(Otc::Skill skill, Otc::SkillType skillType) { return m_skills[skill][skillType]; }
double getStatistic(Otc::Statistic statistic) { return m_statistics[statistic]; } double getStatistic(Otc::Statistic statistic) { return m_statistics[statistic]; }
CreaturePtr getAttackingCreature() { return m_attackingCreature; }
CreaturePtr getFollowingCreature() { return m_followingCreature; }
int getIcons() { return m_icons; } int getIcons() { return m_icons; }
bool isKnown() { return m_known; } bool isKnown() { return m_known; }
bool isAttacking() { return m_attackingCreature != nullptr; }
bool isFollowing() { return m_followingCreature != nullptr; }
bool isPreWalking() { return m_preWalking; } bool isPreWalking() { return m_preWalking; }
void unlockWalk() { m_walkLocked = false; } void unlockWalk() { m_walkLocked = false; }
@ -90,10 +82,7 @@ private:
Position m_lastPrewalkDestionation; Position m_lastPrewalkDestionation;
Timer m_walkLockTimer; Timer m_walkLockTimer;
bool m_canReportBugs;
bool m_known; bool m_known;
CreaturePtr m_attackingCreature;
CreaturePtr m_followingCreature;
int m_icons; int m_icons;
int m_skills[Otc::LastSkill][Otc::LastSkillType]; int m_skills[Otc::LastSkill][Otc::LastSkillType];
double m_statistics[Otc::LastStatistic]; double m_statistics[Otc::LastStatistic];

View File

@ -175,9 +175,10 @@ bool Map::removeThing(const ThingPtr& thing)
return false; return false;
if(MissilePtr missile = thing->asMissile()) { if(MissilePtr missile = thing->asMissile()) {
auto it = std::find(m_floorMissiles[missile->getPosition().z].begin(), m_floorMissiles[missile->getPosition().z].end(), missile); int z = missile->getPosition().z;
if(it != m_floorMissiles[missile->getPosition().z].end()) { auto it = std::find(m_floorMissiles[z].begin(), m_floorMissiles[z].end(), missile);
m_floorMissiles[missile->getPosition().z].erase(it); if(it != m_floorMissiles[z].end()) {
m_floorMissiles[z].erase(it);
return true; return true;
} }
} else if(AnimatedTextPtr animatedText = thing->asAnimatedText()) { } else if(AnimatedTextPtr animatedText = thing->asAnimatedText()) {

View File

@ -51,6 +51,7 @@ public:
uint16 getFirstItemId() { return 100; } uint16 getFirstItemId() { return 100; }
uint16 getMaxItemid() { return m_things[Item].size() + 99; } uint16 getMaxItemid() { return m_things[Item].size() + 99; }
bool isValidItemId(int id) { return id >= getFirstItemId() && id <= getMaxItemid(); }
private: private:
uint32 m_signature; uint32 m_signature;

View File

@ -76,6 +76,71 @@ void OTClient::registerLuaFunctions()
g_lua.bindClassStaticFunction("g_map", "removeCreatureById", std::bind(&Map::removeCreatureById, &g_map, _1)); g_lua.bindClassStaticFunction("g_map", "removeCreatureById", std::bind(&Map::removeCreatureById, &g_map, _1));
g_lua.bindClassStaticFunction("g_map", "getSpectators", std::bind(&Map::getSpectators, &g_map, _1, _2)); g_lua.bindClassStaticFunction("g_map", "getSpectators", std::bind(&Map::getSpectators, &g_map, _1, _2));
g_lua.registerStaticClass("g_game");
g_lua.bindClassStaticFunction("g_game", "loginWorld", std::bind(&Game::loginWorld, &g_game, _1, _2, _3, _4, _5));
g_lua.bindClassStaticFunction("g_game", "cancelLogin", std::bind(&Game::cancelLogin, &g_game));
g_lua.bindClassStaticFunction("g_game", "forceLogout", std::bind(&Game::forceLogout, &g_game));
g_lua.bindClassStaticFunction("g_game", "safeLogout", std::bind(&Game::safeLogout, &g_game));
g_lua.bindClassStaticFunction("g_game", "walk", std::bind(&Game::walk, &g_game, _1));
g_lua.bindClassStaticFunction("g_game", "walkPath", std::bind(&Game::walkPath, &g_game, _1));
g_lua.bindClassStaticFunction("g_game", "forceWalk", std::bind(&Game::forceWalk, &g_game, _1));
g_lua.bindClassStaticFunction("g_game", "turn", std::bind(&Game::turn, &g_game, _1));
g_lua.bindClassStaticFunction("g_game", "stop", std::bind(&Game::stop, &g_game));
g_lua.bindClassStaticFunction("g_game", "look", std::bind(&Game::look, &g_game, _1));
g_lua.bindClassStaticFunction("g_game", "move", std::bind(&Game::move, &g_game, _1, _2, _3));
g_lua.bindClassStaticFunction("g_game", "rotate", std::bind(&Game::rotate, &g_game, _1));
g_lua.bindClassStaticFunction("g_game", "use", std::bind(&Game::use, &g_game, _1));
g_lua.bindClassStaticFunction("g_game", "useWith", std::bind(&Game::useWith, &g_game, _1, _2));
g_lua.bindClassStaticFunction("g_game", "useInventoryItem", std::bind(&Game::useInventoryItem, &g_game, _1));
g_lua.bindClassStaticFunction("g_game", "useInventoryItemWith", std::bind(&Game::useInventoryItemWith, &g_game, _1, _2));
g_lua.bindClassStaticFunction("g_game", "open", std::bind(&Game::open, &g_game, _1, _2));
g_lua.bindClassStaticFunction("g_game", "upContainer", std::bind(&Game::upContainer, &g_game, _1));
g_lua.bindClassStaticFunction("g_game", "refreshContainer", std::bind(&Game::refreshContainer, &g_game));
g_lua.bindClassStaticFunction("g_game", "attack", std::bind(&Game::attack, &g_game, _1));
g_lua.bindClassStaticFunction("g_game", "cancelAttack", std::bind(&Game::cancelAttack, &g_game));
g_lua.bindClassStaticFunction("g_game", "follow", std::bind(&Game::follow, &g_game, _1));
g_lua.bindClassStaticFunction("g_game", "cancelFollow", std::bind(&Game::cancelFollow, &g_game));
g_lua.bindClassStaticFunction("g_game", "cancelAttackAndFollow", std::bind(&Game::cancelAttackAndFollow, &g_game));
g_lua.bindClassStaticFunction("g_game", "talk", std::bind(&Game::talk, &g_game, _1));
g_lua.bindClassStaticFunction("g_game", "talkChannel", std::bind(&Game::talkChannel, &g_game, _1, _2, _3));
g_lua.bindClassStaticFunction("g_game", "talkPrivate", std::bind(&Game::talkPrivate, &g_game, _1, _2, _3));
g_lua.bindClassStaticFunction("g_game", "openPrivateChannel", std::bind(&Game::openPrivateChannel, &g_game, _1));
g_lua.bindClassStaticFunction("g_game", "requestChannels", std::bind(&Game::requestChannels, &g_game));
g_lua.bindClassStaticFunction("g_game", "joinChannel", std::bind(&Game::joinChannel, &g_game, _1));
g_lua.bindClassStaticFunction("g_game", "leaveChannel", std::bind(&Game::leaveChannel, &g_game, _1));
g_lua.bindClassStaticFunction("g_game", "closeNpcChannel", std::bind(&Game::closeNpcChannel, &g_game));
g_lua.bindClassStaticFunction("g_game", "openOwnChannel", std::bind(&Game::openOwnChannel, &g_game));
g_lua.bindClassStaticFunction("g_game", "inviteToOwnChannel", std::bind(&Game::inviteToOwnChannel, &g_game, _1));
g_lua.bindClassStaticFunction("g_game", "excludeFromOwnChannel", std::bind(&Game::excludeFromOwnChannel, &g_game, _1));
g_lua.bindClassStaticFunction("g_game", "partyInvite", std::bind(&Game::partyInvite, &g_game, _1));
g_lua.bindClassStaticFunction("g_game", "partyJoin", std::bind(&Game::partyJoin, &g_game, _1));
g_lua.bindClassStaticFunction("g_game", "partyRevokeInvitation", std::bind(&Game::partyRevokeInvitation, &g_game, _1));
g_lua.bindClassStaticFunction("g_game", "partyPassLeadership", std::bind(&Game::partyPassLeadership, &g_game, _1));
g_lua.bindClassStaticFunction("g_game", "partyLeave", std::bind(&Game::partyLeave, &g_game));
g_lua.bindClassStaticFunction("g_game", "partyShareExperience", std::bind(&Game::partyShareExperience, &g_game, _1));
g_lua.bindClassStaticFunction("g_game", "requestOutfit", std::bind(&Game::requestOutfit, &g_game));
g_lua.bindClassStaticFunction("g_game", "changeOutfit", std::bind(&Game::changeOutfit, &g_game, _1));
g_lua.bindClassStaticFunction("g_game", "addVip", std::bind(&Game::addVip, &g_game, _1));
g_lua.bindClassStaticFunction("g_game", "removeVip", std::bind(&Game::removeVip, &g_game, _1));
g_lua.bindClassStaticFunction("g_game", "setChaseMode", std::bind(&Game::setChaseMode, &g_game, _1));
g_lua.bindClassStaticFunction("g_game", "setFightMode", std::bind(&Game::setFightMode, &g_game, _1));
g_lua.bindClassStaticFunction("g_game", "setSafeFight", std::bind(&Game::setSafeFight, &g_game, _1));
g_lua.bindClassStaticFunction("g_game", "getChaseMode", std::bind(&Game::getChaseMode, &g_game));
g_lua.bindClassStaticFunction("g_game", "getFightMode", std::bind(&Game::getFightMode, &g_game));
g_lua.bindClassStaticFunction("g_game", "isSafeFight", std::bind(&Game::isSafeFight, &g_game));
g_lua.bindClassStaticFunction("g_game", "canPerformGameAction", std::bind(&Game::canPerformGameAction, &g_game));
g_lua.bindClassStaticFunction("g_game", "checkBotProtection", std::bind(&Game::checkBotProtection, &g_game));
g_lua.bindClassStaticFunction("g_game", "isOnline", std::bind(&Game::isOnline, &g_game));
g_lua.bindClassStaticFunction("g_game", "isDead", std::bind(&Game::isDead, &g_game));
g_lua.bindClassStaticFunction("g_game", "isAttacking", std::bind(&Game::isAttacking, &g_game));
g_lua.bindClassStaticFunction("g_game", "isFollowing", std::bind(&Game::isFollowing, &g_game));
g_lua.bindClassStaticFunction("g_game", "getAttackingCreature", std::bind(&Game::getAttackingCreature, &g_game));
g_lua.bindClassStaticFunction("g_game", "getFollowingCreature", std::bind(&Game::getFollowingCreature, &g_game));
g_lua.bindClassStaticFunction("g_game", "getServerBeat", std::bind(&Game::getServerBeat, &g_game));
g_lua.bindClassStaticFunction("g_game", "getLocalPlayer", std::bind(&Game::getLocalPlayer, &g_game));
g_lua.bindClassStaticFunction("g_game", "getProtocolGame", std::bind(&Game::getProtocolGame, &g_game));
g_lua.bindClassStaticFunction("g_game", "getProtocolVersion", std::bind(&Game::getProtocolVersion, &g_game));
g_lua.bindGlobalFunction("getOufitColor", Outfit::getColor); g_lua.bindGlobalFunction("getOufitColor", Outfit::getColor);
g_lua.registerClass<ProtocolLogin, Protocol>(); g_lua.registerClass<ProtocolLogin, Protocol>();
@ -148,8 +213,6 @@ void OTClient::registerLuaFunctions()
g_lua.registerClass<Npc, Creature>(); g_lua.registerClass<Npc, Creature>();
g_lua.registerClass<Monster, Creature>(); g_lua.registerClass<Monster, Creature>();
g_lua.registerClass<LocalPlayer, Player>(); g_lua.registerClass<LocalPlayer, Player>();
g_lua.bindClassMemberFunction<LocalPlayer>("getAttackingCreature", &LocalPlayer::getAttackingCreature);
g_lua.bindClassMemberFunction<LocalPlayer>("getFollowingCreature", &LocalPlayer::getFollowingCreature);
g_lua.bindClassMemberFunction<LocalPlayer>("getHealth", &LocalPlayer::getHealth); g_lua.bindClassMemberFunction<LocalPlayer>("getHealth", &LocalPlayer::getHealth);
g_lua.bindClassMemberFunction<LocalPlayer>("getMaxHealth", &LocalPlayer::getMaxHealth); g_lua.bindClassMemberFunction<LocalPlayer>("getMaxHealth", &LocalPlayer::getMaxHealth);
g_lua.bindClassMemberFunction<LocalPlayer>("getFreeCapacity", &LocalPlayer::getFreeCapacity); g_lua.bindClassMemberFunction<LocalPlayer>("getFreeCapacity", &LocalPlayer::getFreeCapacity);
@ -187,59 +250,6 @@ void OTClient::registerLuaFunctions()
g_lua.bindClassMemberFunction<Tile>("isEmpty", &Tile::isEmpty); g_lua.bindClassMemberFunction<Tile>("isEmpty", &Tile::isEmpty);
g_lua.bindClassMemberFunction<Tile>("isClickable", &Tile::isClickable); g_lua.bindClassMemberFunction<Tile>("isClickable", &Tile::isClickable);
g_lua.registerClass<Map>();
g_lua.registerClass<Game>();
g_lua.bindClassStaticFunction<Game>("loginWorld", std::bind(&Game::loginWorld, &g_game, _1, _2, _3, _4, _5));
g_lua.bindClassStaticFunction<Game>("safeLogout", std::bind(&Game::safeLogout, &g_game));
g_lua.bindClassStaticFunction<Game>("forceLogout", std::bind(&Game::forceLogout, &g_game));
g_lua.bindClassStaticFunction<Game>("cancelLogin", std::bind(&Game::cancelLogin, &g_game));
g_lua.bindClassStaticFunction<Game>("isOnline", std::bind(&Game::isOnline, &g_game));
g_lua.bindClassStaticFunction<Game>("requestOutfit", std::bind(&Game::requestOutfit, &g_game));
g_lua.bindClassStaticFunction<Game>("requestChannels", std::bind(&Game::requestChannels, &g_game));
g_lua.bindClassStaticFunction<Game>("joinChannel", std::bind(&Game::joinChannel, &g_game, _1));
g_lua.bindClassStaticFunction<Game>("leaveChannel", std::bind(&Game::leaveChannel, &g_game, _1));
g_lua.bindClassStaticFunction<Game>("closeNpcChannel", std::bind(&Game::closeNpcChannel, &g_game));
g_lua.bindClassStaticFunction<Game>("openPrivateChannel", std::bind(&Game::openPrivateChannel, &g_game, _1));
g_lua.bindClassStaticFunction<Game>("setOutfit", std::bind(&Game::setOutfit, &g_game, _1));
g_lua.bindClassStaticFunction<Game>("look", std::bind(&Game::look, &g_game, _1));
g_lua.bindClassStaticFunction<Game>("open", std::bind(&Game::open, &g_game, _1, _2));
g_lua.bindClassStaticFunction<Game>("use", std::bind(&Game::use, &g_game, _1));
g_lua.bindClassStaticFunction<Game>("useInventoryItem", std::bind(&Game::useInventoryItem, &g_game, _1));
g_lua.bindClassStaticFunction<Game>("useWith", std::bind(&Game::useWith, &g_game, _1, _2));
g_lua.bindClassStaticFunction<Game>("useInventoryItemWith", std::bind(&Game::useInventoryItemWith, &g_game, _1, _2));
g_lua.bindClassStaticFunction<Game>("move", std::bind(&Game::move, &g_game, _1, _2, _3));
g_lua.bindClassStaticFunction<Game>("turn", std::bind(&Game::turn, &g_game, _1));
g_lua.bindClassStaticFunction<Game>("walk", std::bind(&Game::walk, &g_game, _1));
g_lua.bindClassStaticFunction<Game>("forceWalk", std::bind(&Game::forceWalk, &g_game, _1));
g_lua.bindClassStaticFunction<Game>("setChaseMode", std::bind(&Game::setChaseMode, &g_game, _1));
g_lua.bindClassStaticFunction<Game>("setFightMode", std::bind(&Game::setFightMode, &g_game, _1));
g_lua.bindClassStaticFunction<Game>("setSafeFight", std::bind(&Game::setSafeFight, &g_game, _1));
g_lua.bindClassStaticFunction<Game>("getChaseMode", std::bind(&Game::getChaseMode, &g_game));
g_lua.bindClassStaticFunction<Game>("getFightMode", std::bind(&Game::getFightMode, &g_game));
g_lua.bindClassStaticFunction<Game>("isSafeFight", std::bind(&Game::isSafeFight, &g_game));
g_lua.bindClassStaticFunction<Game>("attack", std::bind(&Game::attack, &g_game, _1));
g_lua.bindClassStaticFunction<Game>("cancelAttack", std::bind(&Game::cancelAttack, &g_game));
g_lua.bindClassStaticFunction<Game>("follow", std::bind(&Game::follow, &g_game, _1));
g_lua.bindClassStaticFunction<Game>("cancelFollow", std::bind(&Game::cancelFollow, &g_game));
g_lua.bindClassStaticFunction<Game>("rotate", std::bind(&Game::rotate, &g_game, _1));
g_lua.bindClassStaticFunction<Game>("partyInvite", std::bind(&Game::partyInvite, &g_game, _1));
g_lua.bindClassStaticFunction<Game>("partyJoin", std::bind(&Game::partyJoin, &g_game, _1));
g_lua.bindClassStaticFunction<Game>("partyRevokeInvitation", std::bind(&Game::partyRevokeInvitation, &g_game, _1));
g_lua.bindClassStaticFunction<Game>("partyPassLeadership", std::bind(&Game::partyPassLeadership, &g_game, _1));
g_lua.bindClassStaticFunction<Game>("partyLeave", std::bind(&Game::partyLeave, &g_game));
g_lua.bindClassStaticFunction<Game>("partyShareExperience", std::bind(&Game::partyShareExperience, &g_game, _1));
g_lua.bindClassStaticFunction<Game>("addVip", std::bind(&Game::addVip, &g_game, _1));
g_lua.bindClassStaticFunction<Game>("removeVip", std::bind(&Game::removeVip, &g_game, _1));
g_lua.bindClassStaticFunction<Game>("talk", std::bind(&Game::talk, &g_game, _1));
g_lua.bindClassStaticFunction<Game>("talkChannel", std::bind(&Game::talkChannel, &g_game, _1, _2, _3));
g_lua.bindClassStaticFunction<Game>("talkPrivate", std::bind(&Game::talkPrivate, &g_game, _1, _2, _3));
g_lua.bindClassStaticFunction<Game>("getLocalPlayer", std::bind(&Game::getLocalPlayer, &g_game));
g_lua.bindClassStaticFunction<Game>("getProtocolVersion", std::bind(&Game::getProtocolVersion, &g_game));
g_lua.bindClassStaticFunction<Game>("getProtocolGame", std::bind(&Game::getProtocolGame, &g_game));
g_lua.registerClass<UIItem, UIWidget>(); g_lua.registerClass<UIItem, UIWidget>();
g_lua.bindClassStaticFunction<UIItem>("create", []{ return UIItemPtr(new UIItem); }); g_lua.bindClassStaticFunction<UIItem>("create", []{ return UIItemPtr(new UIItem); });
g_lua.bindClassMemberFunction<UIItem>("setItemId", &UIItem::setItemId); g_lua.bindClassMemberFunction<UIItem>("setItemId", &UIItem::setItemId);

View File

@ -54,7 +54,7 @@ namespace Proto {
#endif #endif
enum OsTypes { enum OsTypes {
OsWindow = 1, OsWindows = 1,
OsLinux = 2, OsLinux = 2,
OsMac = 3, OsMac = 3,
OsBrowser = 4 OsBrowser = 4
@ -75,13 +75,13 @@ namespace Proto {
GameServerLoginWait = 22, GameServerLoginWait = 22,
GameServerPing = 30, GameServerPing = 30,
GameServerChallange = 31, GameServerChallange = 31,
GameServerDead = 40, GameServerDeath = 40,
GameServerFullMap = 100, GameServerFullMap = 100,
GameServerMapTopRow = 101, GameServerMapTopRow = 101,
GameServerMapRightRow = 102, GameServerMapRightRow = 102,
GameServerMapBottomRow = 103, GameServerMapBottomRow = 103,
GameServerMapLeftRow = 104, GameServerMapLeftRow = 104,
GameServerTileData = 105, GameServerUpdateTile = 105,
GameServerCreateOnMap = 106, GameServerCreateOnMap = 106,
GameServerChangeOnMap = 107, GameServerChangeOnMap = 107,
GameServerDeleteOnMap = 108, GameServerDeleteOnMap = 108,
@ -130,15 +130,15 @@ namespace Proto {
GameServerRuleViolationLock = 177, // deprecated in last tibia GameServerRuleViolationLock = 177, // deprecated in last tibia
GameServerOpenOwnChannel = 178, GameServerOpenOwnChannel = 178,
GameServerCloseChannel = 179, GameServerCloseChannel = 179,
GameServerMessage = 180, GameServerTextMessage = 180,
GameServerSnapBack = 181, GameServerCancelWalk = 181,
GameServerWait = 182, GameServerWait = 182,
GameServerTopFloor = 190, GameServerFloorChangeUp = 190,
GameServerBottomFloor = 191, GameServerFloorChangeDown = 191,
GameServerOutfit = 200, GameServerOutfit = 200,
GameServerBuddyData = 210, GameServerVipAdd = 210,
GameServerBuddyLogin = 211, GameServerVipLogin = 211,
GameServerBuddyLogout = 212, GameServerVipLogout = 212,
GameServerTutorialHint = 220, GameServerTutorialHint = 220,
GameServerAutomapFlag = 221, GameServerAutomapFlag = 221,
GameServerQuestLog = 240, GameServerQuestLog = 240,
@ -151,48 +151,48 @@ namespace Proto {
enum ClientOpts { enum ClientOpts {
ClientEnterAccount = 1, ClientEnterAccount = 1,
ClientEnterGame = 10, ClientEnterGame = 10,
ClientQuitGame = 20, ClientLeaveGame = 20,
ClientPingBack = 30, ClientPingResponse = 30,
ClientGoPath = 100, ClientWalkPath = 100,
ClientGoNorth = 101, ClientWalkNorth = 101,
ClientGoEast = 102, ClientWalkEast = 102,
ClientGoSouth = 103, ClientWalkSouth = 103,
ClientGoWest = 104, ClientWalkWest = 104,
ClientStop = 105, ClientStop = 105,
ClientGoNorthEast = 106, ClientWalkNorthEast = 106,
ClientGoSouthEast = 107, ClientWalkSouthEast = 107,
ClientGoSouthWest = 108, ClientWalkSouthWest = 108,
ClientGoNorthWest = 109, ClientWalkNorthWest = 109,
ClientRotateNorth = 111, ClientTurnNorth = 111,
ClientRotateEast = 112, ClientTurnEast = 112,
ClientRotateSouth = 113, ClientTurnSouth = 113,
ClientRotateWest = 114, ClientTurnWest = 114,
ClientEquipObject = 119, //ClientEquipObject = 119,
ClientMoveObject = 120, ClientMove = 120,
ClientInspectNpcTrade = 121, ClientInspectNpcTrade = 121,
ClientBuyObject = 122, ClientBuyItem = 122,
ClientSellObject = 123, ClientSellItem = 123,
ClientCloseNpcTrade = 124, ClientCloseNpcTrade = 124,
ClientTradeObject = 125, ClientRequestTrade = 125,
ClientInspectTrade = 126, ClientInspectTrade = 126,
ClientAcceptTrade = 127, ClientAcceptTrade = 127,
ClientRejectTrade = 128, ClientRejectTrade = 128,
ClientUseObject = 130, ClientUseItem = 130,
ClientUseTwoObjects = 131, ClientUseItemWith = 131,
ClientUseOnCreature = 132, ClientUseOnCreature = 132,
ClientTurnObject = 133, ClientRotateItem = 133,
ClientCloseContainer = 135, ClientCloseContainer = 135,
ClientUpContainer = 136, ClientUpContainer = 136,
ClientEditText = 137, ClientEditText = 137,
ClientEditList = 138, ClientEditList = 138,
ClientLook = 140, ClientLook = 140,
ClientTalk = 150, ClientTalk = 150,
ClientGetChannels = 151, ClientRequestChannels = 151,
ClientJoinChannel = 152, ClientJoinChannel = 152,
ClientLeaveChannel = 153, ClientLeaveChannel = 153,
ClientOpenPrivateChannel = 154, ClientOpenPrivateChannel = 154,
ClientCloseNpcChannel = 158, ClientCloseNpcChannel = 158,
ClientSetTactics = 160, ClientChangeFightModes = 160,
ClientAttack = 161, ClientAttack = 161,
ClientFollow = 162, ClientFollow = 162,
ClientInviteToParty = 163, ClientInviteToParty = 163,
@ -202,22 +202,22 @@ namespace Proto {
ClientLeaveParty = 167, ClientLeaveParty = 167,
ClientShareExperience = 168, ClientShareExperience = 168,
ClientDisbandParty = 169, ClientDisbandParty = 169,
ClientOpenChannel = 170, ClientOpenOwnChannel = 170,
ClientInviteToChannel = 171, ClientInviteToOwnChannel = 171,
ClientExcludeFromChannel = 172, ClientExcludeFromOwnChannel = 172,
ClientCancel = 190, ClientCancelAttackAndFollow = 190,
ClientRefreshContainer = 202, ClientRefreshContainer = 202,
ClientGetOutfit = 210, ClientRequestOutfit = 210,
ClientSetOutfit = 211, ClientChangeOutfit = 211,
ClientMount = 212, //ClientMount = 212,
ClientAddBuddy = 220, ClientAddVip = 220,
ClientRemoveBuddy = 221, ClientRemoveVip = 221,
ClientBugReport = 230, //ClientBugReport = 230,
ClientErrorFileEntry = 232, //ClientErrorFileEntry = 232,
ClientGetQuestLog = 240, ClientRequestQuestLog = 240,
ClientGetQuestLine = 241, ClientRequestQuestLine = 241,
ClientRuleViolationReport = 242, //ClientRuleViolationReport = 242,
ClientGetObjectInfo = 243 //ClientGetObjectInfo = 243
}; };
enum ServerSpeakType { enum ServerSpeakType {

View File

@ -41,12 +41,13 @@ public:
void onError(const boost::system::error_code& error); void onError(const boost::system::error_code& error);
void sendLogout(); void sendLogout();
void sendPing(); void sendPingResponse();
void sendWalkPath(const std::vector<Otc::Direction>& path);
void sendWalkNorth(); void sendWalkNorth();
void sendWalkEast(); void sendWalkEast();
void sendWalkSouth(); void sendWalkSouth();
void sendWalkWest(); void sendWalkWest();
void sendStopAutowalk(); void sendStop();
void sendWalkNorthEast(); void sendWalkNorthEast();
void sendWalkSouthEast(); void sendWalkSouthEast();
void sendWalkSouthWest(); void sendWalkSouthWest();
@ -55,31 +56,31 @@ public:
void sendTurnEast(); void sendTurnEast();
void sendTurnSouth(); void sendTurnSouth();
void sendTurnWest(); void sendTurnWest();
void sendThrow(const Position& fromPos, int thingId, int stackpos, const Position& toPos, int count); void sendMove(const Position& fromPos, int thingId, int stackpos, const Position& toPos, int count);
void sendLookInShop(int thingId, int count); void sendInspectNpcTrade(int thingId, int count);
void sendPlayerPurchase(int thingId, int count, int amount, bool ignoreCapacity, bool buyWithBackpack); void sendBuyItem(int thingId, int count, int amount, bool ignoreCapacity, bool buyWithBackpack);
void sendPlayerSale(int thingId, int count, int amount, bool ignoreEquipped); void sendSellItem(int thingId, int count, int amount, bool ignoreEquipped);
void sendCloseShop(); void sendCloseNpcTrade();
void sendRequestTrade(const Position& pos, int thingId, int stackpos, uint playerId); void sendRequestTrade(const Position& pos, int thingId, int stackpos, uint playerId);
void sendLookInTrade(bool counterOffer, int index); void sendInspectTrade(bool counterOffer, int index);
void sendAcceptTrade(); void sendAcceptTrade();
void sendRejectTrade(); void sendRejectTrade();
void sendUseItem(const Position& position, int itemId, int stackpos, int index); void sendUseItem(const Position& position, int itemId, int stackpos, int index);
void sendUseItemEx(const Position& fromPos, int itemId, int fromStackpos, const Position& toPos, int toThingId, int toStackpos); void sendUseItemWith(const Position& fromPos, int itemId, int fromStackpos, const Position& toPos, int toThingId, int toStackpos);
void sendUseOnCreature(const Position& pos, int thingId, int stackpos, uint creatureId); void sendUseOnCreature(const Position& pos, int thingId, int stackpos, uint creatureId);
void sendRotateItem(const Position& pos, int thingId, int stackpos); void sendRotateItem(const Position& pos, int thingId, int stackpos);
void sendCloseContainer(int containerId); void sendCloseContainer(int containerId);
void sendUpContainer(int containerId); void sendUpContainer(int containerId);
void sendTextWindow(uint windowTextId, const std::string& text); void sendEditText(uint textId, const std::string& text);
void sendHouseWindow(int doorId, uint id, const std::string& text); void sendEditList(int listId, uint id, const std::string& text);
void sendLookAt(const Position& position, int thingId, int stackpos); void sendLook(const Position& position, int thingId, int stackpos);
void sendTalk(Otc::SpeakType speakType, int channelId, const std::string& receiver, const std::string& message); void sendTalk(Otc::SpeakType speakType, int channelId, const std::string& receiver, const std::string& message);
void sendGetChannels(); void sendRequestChannels();
void sendJoinChannel(int channelId); void sendJoinChannel(int channelId);
void sendLeaveChannel(int channelId); void sendLeaveChannel(int channelId);
void sendOpenPrivateChannel(const std::string& receiver); void sendOpenPrivateChannel(const std::string& receiver);
void sendCloseNpcChannel(); void sendCloseNpcChannel();
void sendFightTatics(Otc::FightModes fightMode, Otc::ChaseModes chaseMode, bool safeFight); void sendChangeFightModes(Otc::FightModes fightMode, Otc::ChaseModes chaseMode, bool safeFight);
void sendAttack(uint creatureId); void sendAttack(uint creatureId);
void sendFollow(uint creatureId); void sendFollow(uint creatureId);
void sendInviteToParty(uint creatureId); void sendInviteToParty(uint creatureId);
@ -88,17 +89,17 @@ public:
void sendPassLeadership(uint creatureId); void sendPassLeadership(uint creatureId);
void sendLeaveParty(); void sendLeaveParty();
void sendShareExperience(bool active, int unknown); void sendShareExperience(bool active, int unknown);
void sendOpenChannel(int channelId); void sendOpenOwnChannel();
void sendInviteToChannel(const std::string& name); void sendInviteToOwnChannel(const std::string& name);
void sendExcludeFromChannel(const std::string& name); void sendExcludeFromOwnChannel(const std::string& name);
void sendCancel(); void sendCancelAttackAndFollow();
void sendUpdateContainer(); void sendRefreshContainer();
void sendGetOutfit(); void sendRequestOutfit();
void sendSetOutfit(const Outfit& outfit); void sendChangeOutfit(const Outfit& outfit);
void sendAddVip(const std::string& name); void sendAddVip(const std::string& name);
void sendRemoveVip(uint playerId); void sendRemoveVip(uint playerId);
void sendGetQuestLog(); void sendRequestQuestLog();
void sendGetQuestLine(int questId); void sendRequestQuestLine(int questLine);
private: private:
void sendLoginPacket(uint timestamp, uint8 unknown); void sendLoginPacket(uint timestamp, uint8 unknown);
@ -109,16 +110,15 @@ private:
void parseInitGame(InputMessage& msg); void parseInitGame(InputMessage& msg);
void parseGMActions(InputMessage& msg); void parseGMActions(InputMessage& msg);
void parseLoginError(InputMessage& msg); void parseLoginError(InputMessage& msg);
void parseFYIMessage(InputMessage& msg); void parseLoginAdvice(InputMessage& msg);
void parseWaitList(InputMessage& msg); void parseLoginWait(InputMessage& msg);
void parsePing(InputMessage&); void parsePing(InputMessage&);
void parseDeath(InputMessage& msg); void parseDeath(InputMessage& msg);
void parseCanReportBugs(InputMessage& msg);
void parseMapDescription(InputMessage& msg); void parseMapDescription(InputMessage& msg);
void parseMoveNorth(InputMessage& msg); void parseMapMoveNorth(InputMessage& msg);
void parseMoveEast(InputMessage& msg); void parseMapMoveEast(InputMessage& msg);
void parseMoveSouth(InputMessage& msg); void parseMapMoveSouth(InputMessage& msg);
void parseMoveWest(InputMessage& msg); void parseMapMoveWest(InputMessage& msg);
void parseUpdateTile(InputMessage& msg); void parseUpdateTile(InputMessage& msg);
void parseTileAddThing(InputMessage& msg); void parseTileAddThing(InputMessage& msg);
void parseTileTransformThing(InputMessage& msg); void parseTileTransformThing(InputMessage& msg);
@ -131,7 +131,7 @@ private:
void parseContainerRemoveItem(InputMessage& msg); void parseContainerRemoveItem(InputMessage& msg);
void parseAddInventoryItem(InputMessage& msg); void parseAddInventoryItem(InputMessage& msg);
void parseRemoveInventoryItem(InputMessage& msg); void parseRemoveInventoryItem(InputMessage& msg);
void parseOpenShopWindow(InputMessage& msg); void parseNpcOffer(InputMessage& msg);
void parsePlayerCash(InputMessage& msg); void parsePlayerCash(InputMessage& msg);
void parseCloseShopWindow(InputMessage&); void parseCloseShopWindow(InputMessage&);
void parseWorldLight(InputMessage& msg); void parseWorldLight(InputMessage& msg);
@ -156,7 +156,7 @@ private:
void parseChannelList(InputMessage& msg); void parseChannelList(InputMessage& msg);
void parseOpenChannel(InputMessage& msg); void parseOpenChannel(InputMessage& msg);
void parseOpenPrivateChannel(InputMessage& msg); void parseOpenPrivateChannel(InputMessage& msg);
void parseCreateOwnPrivateChannel(InputMessage& msg); void parseOpenOwnPrivateChannel(InputMessage& msg);
void parseCloseChannel(InputMessage& msg); void parseCloseChannel(InputMessage& msg);
void parseSafeTradeRequest(InputMessage& msg); void parseSafeTradeRequest(InputMessage& msg);
void parseSafeTradeClose(InputMessage&); void parseSafeTradeClose(InputMessage&);
@ -164,14 +164,14 @@ private:
void parseCancelWalk(InputMessage& msg); void parseCancelWalk(InputMessage& msg);
void parseFloorChangeUp(InputMessage& msg); void parseFloorChangeUp(InputMessage& msg);
void parseFloorChangeDown(InputMessage& msg); void parseFloorChangeDown(InputMessage& msg);
void parseOutfitWindow(InputMessage& msg); void parseOutfit(InputMessage& msg);
void parseVipState(InputMessage& msg); void parseVipAdd(InputMessage& msg);
void parseVipLogin(InputMessage& msg); void parseVipLogin(InputMessage& msg);
void parseVipLogout(InputMessage& msg); void parseVipLogout(InputMessage& msg);
void parseShowTutorial(InputMessage& msg); void parseTutorialHint(InputMessage& msg);
void parseAddMarker(InputMessage& msg); void parseAutomapFlag(InputMessage& msg);
void parseQuestList(InputMessage& msg); void parseQuestLog(InputMessage& msg);
void parseQuestPartList(InputMessage& msg); void parseQuestLine(InputMessage& msg);
void setMapDescription(InputMessage& msg, int x, int y, int z, int width, int height); void setMapDescription(InputMessage& msg, int x, int y, int z, int width, int height);
void setFloorDescription(InputMessage& msg, int x, int y, int z, int width, int height, int offset, int* skipTiles); void setFloorDescription(InputMessage& msg, int x, int y, int z, int width, int height, int offset, int* skipTiles);

View File

@ -50,34 +50,34 @@ void ProtocolGame::parseMessage(InputMessage& msg)
parseLoginError(msg); parseLoginError(msg);
break; break;
case Proto::GameServerLoginAdvice: case Proto::GameServerLoginAdvice:
parseFYIMessage(msg); parseLoginAdvice(msg);
break; break;
case Proto::GameServerLoginWait: case Proto::GameServerLoginWait:
parseWaitList(msg); parseLoginWait(msg);
break; break;
case Proto::GameServerPing: case Proto::GameServerPing:
parsePing(msg); parsePing(msg);
break; break;
//case Proto::GameServerChallange: //case Proto::GameServerChallange:
case Proto::GameServerDead: case Proto::GameServerDeath:
parseDeath(msg); parseDeath(msg);
break; break;
case Proto::GameServerFullMap: case Proto::GameServerFullMap:
parseMapDescription(msg); parseMapDescription(msg);
break; break;
case Proto::GameServerMapTopRow: case Proto::GameServerMapTopRow:
parseMoveNorth(msg); parseMapMoveNorth(msg);
break; break;
case Proto::GameServerMapRightRow: case Proto::GameServerMapRightRow:
parseMoveEast(msg); parseMapMoveEast(msg);
break; break;
case Proto::GameServerMapBottomRow: case Proto::GameServerMapBottomRow:
parseMoveSouth(msg); parseMapMoveSouth(msg);
break; break;
case Proto::GameServerMapLeftRow: case Proto::GameServerMapLeftRow:
parseMoveWest(msg); parseMapMoveWest(msg);
break; break;
case Proto::GameServerTileData: case Proto::GameServerUpdateTile:
parseUpdateTile(msg); parseUpdateTile(msg);
break; break;
case Proto::GameServerCreateOnMap: case Proto::GameServerCreateOnMap:
@ -114,7 +114,7 @@ void ProtocolGame::parseMessage(InputMessage& msg)
parseRemoveInventoryItem(msg); parseRemoveInventoryItem(msg);
break; break;
case Proto::GameServerNpcOffer: case Proto::GameServerNpcOffer:
parseOpenShopWindow(msg); parseNpcOffer(msg);
break; break;
case Proto::GameServerPlayerGoods: case Proto::GameServerPlayerGoods:
parsePlayerCash(msg); parsePlayerCash(msg);
@ -210,47 +210,47 @@ void ProtocolGame::parseMessage(InputMessage& msg)
case Proto::GameServerRuleViolationLock: case Proto::GameServerRuleViolationLock:
break; break;
case Proto::GameServerOpenOwnChannel: case Proto::GameServerOpenOwnChannel:
parseCreateOwnPrivateChannel(msg); parseOpenOwnPrivateChannel(msg);
break; break;
case Proto::GameServerCloseChannel: case Proto::GameServerCloseChannel:
parseCloseChannel(msg); parseCloseChannel(msg);
break; break;
case Proto::GameServerMessage: case Proto::GameServerTextMessage:
parseTextMessage(msg); parseTextMessage(msg);
break; break;
case Proto::GameServerSnapBack: case Proto::GameServerCancelWalk:
parseCancelWalk(msg); parseCancelWalk(msg);
break; break;
//case Proto::GameServerWait: //case Proto::GameServerWait:
case Proto::GameServerTopFloor: case Proto::GameServerFloorChangeUp:
parseFloorChangeUp(msg); parseFloorChangeUp(msg);
break; break;
case Proto::GameServerBottomFloor: case Proto::GameServerFloorChangeDown:
parseFloorChangeDown(msg); parseFloorChangeDown(msg);
break; break;
case Proto::GameServerOutfit: case Proto::GameServerOutfit:
parseOutfitWindow(msg); parseOutfit(msg);
break; break;
case Proto::GameServerBuddyData: case Proto::GameServerVipAdd:
parseVipState(msg); parseVipAdd(msg);
break; break;
case Proto::GameServerBuddyLogin: case Proto::GameServerVipLogin:
parseVipLogin(msg); parseVipLogin(msg);
break; break;
case Proto::GameServerBuddyLogout: case Proto::GameServerVipLogout:
parseVipLogout(msg); parseVipLogout(msg);
break; break;
case Proto::GameServerTutorialHint: case Proto::GameServerTutorialHint:
parseShowTutorial(msg); parseTutorialHint(msg);
break; break;
case Proto::GameServerAutomapFlag: case Proto::GameServerAutomapFlag:
parseAddMarker(msg); parseAutomapFlag(msg);
break; break;
case Proto::GameServerQuestLog: case Proto::GameServerQuestLog:
parseQuestList(msg); parseQuestLog(msg);
break; break;
case Proto::GameServerQuestLine: case Proto::GameServerQuestLine:
parseQuestPartList(msg); parseQuestLine(msg);
break; break;
//case Proto::GameServerChannelEvent: //case Proto::GameServerChannelEvent:
//case Proto::GameServerObjectInfo: //case Proto::GameServerObjectInfo:
@ -269,16 +269,17 @@ void ProtocolGame::parseInitGame(InputMessage& msg)
{ {
uint playerId = msg.getU32(); uint playerId = msg.getU32();
int serverBeat = msg.getU16(); int serverBeat = msg.getU16();
int playerCanReportBugs = msg.getU8(); msg.getU8(); // can report bugs, ignored
m_localPlayer = LocalPlayerPtr(new LocalPlayer); m_localPlayer = LocalPlayerPtr(new LocalPlayer);
m_localPlayer->setId(playerId); m_localPlayer->setId(playerId);
m_localPlayer->setCanReportBugs(playerCanReportBugs);
g_game.processGameStart(m_localPlayer, serverBeat); g_game.processGameStart(m_localPlayer, serverBeat);
} }
void ProtocolGame::parseGMActions(InputMessage& msg) void ProtocolGame::parseGMActions(InputMessage& msg)
{ {
// not used
for(int i = 0; i < Proto::NumViolationReasons; ++i) for(int i = 0; i < Proto::NumViolationReasons; ++i)
msg.getU8(); msg.getU8();
} }
@ -286,31 +287,37 @@ void ProtocolGame::parseGMActions(InputMessage& msg)
void ProtocolGame::parseLoginError(InputMessage& msg) void ProtocolGame::parseLoginError(InputMessage& msg)
{ {
std::string error = msg.getString(); std::string error = msg.getString();
g_game.processLoginError(error); g_game.processLoginError(error);
} }
void ProtocolGame::parseFYIMessage(InputMessage& msg) void ProtocolGame::parseLoginAdvice(InputMessage& msg)
{ {
msg.getString(); // message std::string message = msg.getString();
g_game.processLoginAdvice(message);
} }
void ProtocolGame::parseWaitList(InputMessage& msg) void ProtocolGame::parseLoginWait(InputMessage& msg)
{ {
msg.getString(); // message std::string message = msg.getString();
msg.getU8();// + 1 // time int time = msg.getU8();
g_game.processLoginWait(message, time);
} }
void ProtocolGame::parsePing(InputMessage&) void ProtocolGame::parsePing(InputMessage&)
{ {
sendPing(); g_game.processPing();
} }
void ProtocolGame::parseDeath(InputMessage& msg) void ProtocolGame::parseDeath(InputMessage& msg)
{ {
int penality = 100;
#if PROTOCOL==862 #if PROTOCOL==862
msg.getU8(); // 100 is a fair death. < 100 is a unfair death. penality = msg.getU8();
#endif #endif
g_game.processDeath(); g_game.processDeath(penality);
} }
void ProtocolGame::parseMapDescription(InputMessage& msg) void ProtocolGame::parseMapDescription(InputMessage& msg)
@ -320,7 +327,7 @@ void ProtocolGame::parseMapDescription(InputMessage& msg)
setMapDescription(msg, pos.x - Otc::AWARE_X_LEFT_TILES, pos.y - Otc::AWARE_Y_TOP_TILES, pos.z, Otc::AWARE_X_TILES, Otc::AWARE_Y_TILES); setMapDescription(msg, pos.x - Otc::AWARE_X_LEFT_TILES, pos.y - Otc::AWARE_Y_TOP_TILES, pos.z, Otc::AWARE_X_TILES, Otc::AWARE_Y_TILES);
} }
void ProtocolGame::parseMoveNorth(InputMessage& msg) void ProtocolGame::parseMapMoveNorth(InputMessage& msg)
{ {
Position pos = g_map.getCentralPosition(); Position pos = g_map.getCentralPosition();
pos.y--; pos.y--;
@ -329,7 +336,7 @@ void ProtocolGame::parseMoveNorth(InputMessage& msg)
g_map.setCentralPosition(pos); g_map.setCentralPosition(pos);
} }
void ProtocolGame::parseMoveEast(InputMessage& msg) void ProtocolGame::parseMapMoveEast(InputMessage& msg)
{ {
Position pos = g_map.getCentralPosition(); Position pos = g_map.getCentralPosition();
pos.x++; pos.x++;
@ -338,7 +345,7 @@ void ProtocolGame::parseMoveEast(InputMessage& msg)
g_map.setCentralPosition(pos); g_map.setCentralPosition(pos);
} }
void ProtocolGame::parseMoveSouth(InputMessage& msg) void ProtocolGame::parseMapMoveSouth(InputMessage& msg)
{ {
Position pos = g_map.getCentralPosition(); Position pos = g_map.getCentralPosition();
pos.y++; pos.y++;
@ -347,7 +354,7 @@ void ProtocolGame::parseMoveSouth(InputMessage& msg)
g_map.setCentralPosition(pos); g_map.setCentralPosition(pos);
} }
void ProtocolGame::parseMoveWest(InputMessage& msg) void ProtocolGame::parseMapMoveWest(InputMessage& msg)
{ {
Position pos = g_map.getCentralPosition(); Position pos = g_map.getCentralPosition();
pos.x--; pos.x--;
@ -383,12 +390,12 @@ void ProtocolGame::parseTileTransformThing(InputMessage& msg)
int stackPos = msg.getU8(); int stackPos = msg.getU8();
int thingId = msg.getU16(); int thingId = msg.getU16();
assert(thingId != 0);
if(thingId == 0x0061 || thingId == 0x0062 || thingId == 0x0063) { if(thingId == 0x0061 || thingId == 0x0062 || thingId == 0x0063) {
parseCreatureTurn(msg); parseCreatureTurn(msg);
} else { } else {
ThingPtr thing = internalGetItem(msg, thingId); ThingPtr thing = internalGetItem(msg, thingId);
g_map.removeThingByPos(pos, stackPos); if(!g_map.removeThingByPos(pos, stackPos))
logTraceError("could not remove thing");
g_map.addThing(thing, pos, stackPos); g_map.addThing(thing, pos, stackPos);
} }
} }
@ -398,7 +405,8 @@ void ProtocolGame::parseTileRemoveThing(InputMessage& msg)
Position pos = parsePosition(msg); Position pos = parsePosition(msg);
int stackPos = msg.getU8(); int stackPos = msg.getU8();
g_map.removeThingByPos(pos, stackPos); if(!g_map.removeThingByPos(pos, stackPos))
logTraceError("could not remove thing");
} }
void ProtocolGame::parseCreatureMove(InputMessage& msg) void ProtocolGame::parseCreatureMove(InputMessage& msg)
@ -420,7 +428,8 @@ void ProtocolGame::parseCreatureMove(InputMessage& msg)
} }
// update map tiles // update map tiles
g_map.removeThing(thing); if(!g_map.removeThing(thing))
logTraceError("could not remove thing");
g_map.addThing(thing, newPos); g_map.addThing(thing, newPos);
g_game.processCreatureMove(creature, oldPos, newPos); g_game.processCreatureMove(creature, oldPos, newPos);
@ -435,20 +444,17 @@ void ProtocolGame::parseOpenContainer(InputMessage& msg)
bool hasParent = (msg.getU8() != 0); bool hasParent = (msg.getU8() != 0);
int itemCount = msg.getU8(); int itemCount = msg.getU8();
std::vector<ItemPtr> items; std::vector<ItemPtr> items(itemCount);
items.reserve(itemCount); for(int i = 0; i < itemCount; i++)
for(int i = 0; i < itemCount; i++) { items[i] = internalGetItem(msg);
ItemPtr item = internalGetItem(msg);
items.push_back(item);
}
g_lua.callGlobalField("Game", "onContainerOpen", containerId, itemId, name, capacity, hasParent, items); g_game.processOpenContainer(containerId, itemId, name, capacity, hasParent, items);
} }
void ProtocolGame::parseCloseContainer(InputMessage& msg) void ProtocolGame::parseCloseContainer(InputMessage& msg)
{ {
int containerId = msg.getU8(); int containerId = msg.getU8();
g_lua.callGlobalField("Game", "onContainerClose", containerId); g_lua.callGlobalField("g_game", "onContainerClose", containerId);
} }
void ProtocolGame::parseContainerAddItem(InputMessage& msg) void ProtocolGame::parseContainerAddItem(InputMessage& msg)
@ -463,14 +469,14 @@ void ProtocolGame::parseContainerUpdateItem(InputMessage& msg)
int containerId = msg.getU8(); int containerId = msg.getU8();
int slot = msg.getU8(); int slot = msg.getU8();
ItemPtr item = internalGetItem(msg); ItemPtr item = internalGetItem(msg);
g_lua.callGlobalField("Game", "onContainerUpdateItem", containerId, slot, item); g_lua.callGlobalField("g_game", "onContainerUpdateItem", containerId, slot, item);
} }
void ProtocolGame::parseContainerRemoveItem(InputMessage& msg) void ProtocolGame::parseContainerRemoveItem(InputMessage& msg)
{ {
int containerId = msg.getU8(); int containerId = msg.getU8();
int slot = msg.getU8(); int slot = msg.getU8();
g_lua.callGlobalField("Game", "onContainerRemoveItem", containerId, slot); g_lua.callGlobalField("g_game", "onContainerRemoveItem", containerId, slot);
} }
void ProtocolGame::parseAddInventoryItem(InputMessage& msg) void ProtocolGame::parseAddInventoryItem(InputMessage& msg)
@ -486,7 +492,7 @@ void ProtocolGame::parseRemoveInventoryItem(InputMessage& msg)
g_game.processInventoryChange(slot, ItemPtr()); g_game.processInventoryChange(slot, ItemPtr());
} }
void ProtocolGame::parseOpenShopWindow(InputMessage& msg) void ProtocolGame::parseNpcOffer(InputMessage& msg)
{ {
int listCount = msg.getU8(); int listCount = msg.getU8();
for(int i = 0; i < listCount; ++i) { for(int i = 0; i < listCount; ++i) {
@ -699,7 +705,7 @@ void ProtocolGame::parsePlayerSkills(InputMessage& msg)
m_localPlayer->setSkill((Otc::Skill)skill, (Otc::SkillType)skillType, values[skillType]); m_localPlayer->setSkill((Otc::Skill)skill, (Otc::SkillType)skillType, values[skillType]);
} }
g_lua.callGlobalField("Game", "onSkillChange", skill, values[Otc::SkillLevel], values[Otc::SkillPercent]); g_lua.callGlobalField("g_game", "onSkillChange", skill, values[Otc::SkillLevel], values[Otc::SkillPercent]);
} }
} }
@ -769,7 +775,7 @@ void ProtocolGame::parseChannelList(InputMessage& msg)
channelList.push_back(std::make_tuple(id, name)); channelList.push_back(std::make_tuple(id, name));
} }
g_lua.callGlobalField("Game", "onChannelList", channelList); g_lua.callGlobalField("g_game", "onChannelList", channelList);
} }
void ProtocolGame::parseOpenChannel(InputMessage& msg) void ProtocolGame::parseOpenChannel(InputMessage& msg)
@ -777,29 +783,29 @@ void ProtocolGame::parseOpenChannel(InputMessage& msg)
int channelId = msg.getU16(); int channelId = msg.getU16();
std::string name = msg.getString(); std::string name = msg.getString();
g_lua.callGlobalField("Game", "onOpenChannel", channelId, name); g_lua.callGlobalField("g_game", "onOpenChannel", channelId, name);
} }
void ProtocolGame::parseOpenPrivateChannel(InputMessage& msg) void ProtocolGame::parseOpenPrivateChannel(InputMessage& msg)
{ {
std::string name = msg.getString(); std::string name = msg.getString();
g_lua.callGlobalField("Game", "onOpenPrivateChannel", name); g_lua.callGlobalField("g_game", "onOpenPrivateChannel", name);
} }
void ProtocolGame::parseCreateOwnPrivateChannel(InputMessage& msg) void ProtocolGame::parseOpenOwnPrivateChannel(InputMessage& msg)
{ {
int id = msg.getU16(); // channel id int id = msg.getU16(); // channel id
std::string name = msg.getString(); // channel name std::string name = msg.getString(); // channel name
g_lua.callGlobalField("Game", "onOpenOwnPrivateChannel", id, name); g_lua.callGlobalField("g_game", "onOpenOwnPrivateChannel", id, name);
} }
void ProtocolGame::parseCloseChannel(InputMessage& msg) void ProtocolGame::parseCloseChannel(InputMessage& msg)
{ {
int id = msg.getU16(); // channel id int id = msg.getU16(); // channel id
g_lua.callGlobalField("Game", "onCloseChannel", id); g_lua.callGlobalField("g_game", "onCloseChannel", id);
} }
void ProtocolGame::parseTextMessage(InputMessage& msg) void ProtocolGame::parseTextMessage(InputMessage& msg)
@ -855,7 +861,7 @@ void ProtocolGame::parseFloorChangeDown(InputMessage& msg)
g_map.setCentralPosition(pos); g_map.setCentralPosition(pos);
} }
void ProtocolGame::parseOutfitWindow(InputMessage& msg) void ProtocolGame::parseOutfit(InputMessage& msg)
{ {
Outfit outfit = internalGetOutfit(msg); Outfit outfit = internalGetOutfit(msg);
@ -875,45 +881,45 @@ void ProtocolGame::parseOutfitWindow(InputMessage& msg)
creature->setDirection(Otc::South); creature->setDirection(Otc::South);
creature->setOutfit(outfit); creature->setOutfit(outfit);
g_lua.callGlobalField("Game", "onOpenOutfitWindow", creature, outfitList); g_lua.callGlobalField("g_game", "onOpenOutfitWindow", creature, outfitList);
} }
void ProtocolGame::parseVipState(InputMessage& msg) void ProtocolGame::parseVipAdd(InputMessage& msg)
{ {
uint id = msg.getU32(); uint id = msg.getU32();
std::string name = msg.getString(); std::string name = msg.getString();
bool online = msg.getU8() != 0; bool online = msg.getU8() != 0;
g_lua.callGlobalField("Game", "onAddVip", id, name, online); g_lua.callGlobalField("g_game", "onAddVip", id, name, online);
} }
void ProtocolGame::parseVipLogin(InputMessage& msg) void ProtocolGame::parseVipLogin(InputMessage& msg)
{ {
uint id = msg.getU32(); uint id = msg.getU32();
g_lua.callGlobalField("Game", "onVipStateChange", id, true); g_lua.callGlobalField("g_game", "onVipStateChange", id, true);
} }
void ProtocolGame::parseVipLogout(InputMessage& msg) void ProtocolGame::parseVipLogout(InputMessage& msg)
{ {
uint id = msg.getU32(); uint id = msg.getU32();
g_lua.callGlobalField("Game", "onVipStateChange", id, false); g_lua.callGlobalField("g_game", "onVipStateChange", id, false);
} }
void ProtocolGame::parseShowTutorial(InputMessage& msg) void ProtocolGame::parseTutorialHint(InputMessage& msg)
{ {
msg.getU8(); // tutorial id msg.getU8(); // tutorial id
} }
void ProtocolGame::parseAddMarker(InputMessage& msg) void ProtocolGame::parseAutomapFlag(InputMessage& msg)
{ {
parsePosition(msg); // position parsePosition(msg); // position
msg.getU8(); // icon msg.getU8(); // icon
msg.getString(); // message msg.getString(); // message
} }
void ProtocolGame::parseQuestList(InputMessage& msg) void ProtocolGame::parseQuestLog(InputMessage& msg)
{ {
int questsCount = msg.getU16(); int questsCount = msg.getU16();
for(int i = 0; i < questsCount; i++) { for(int i = 0; i < questsCount; i++) {
@ -923,7 +929,7 @@ void ProtocolGame::parseQuestList(InputMessage& msg)
} }
} }
void ProtocolGame::parseQuestPartList(InputMessage& msg) void ProtocolGame::parseQuestLine(InputMessage& msg)
{ {
msg.getU16(); // quest id msg.getU16(); // quest id
int missionCount = msg.getU8(); int missionCount = msg.getU8();

View File

@ -25,320 +25,333 @@
void ProtocolGame::sendLoginPacket(uint timestamp, uint8 unknown) void ProtocolGame::sendLoginPacket(uint timestamp, uint8 unknown)
{ {
OutputMessage oMsg; OutputMessage msg;
oMsg.addU8(Proto::ClientEnterGame); msg.addU8(Proto::ClientEnterGame);
oMsg.addU16(Proto::OsLinux);
oMsg.addU16(Proto::ClientVersion);
oMsg.addU8(0); // first RSA byte must be 0 #ifdef WIN32
msg.addU16(Proto::OsWindows);
#else
msg.addU16(Proto::OsLinux);
#endif
msg.addU16(Proto::ClientVersion);
msg.addU8(0); // first RSA byte must be 0
// xtea key // xtea key
generateXteaKey(); generateXteaKey();
oMsg.addU32(m_xteaKey[0]); msg.addU32(m_xteaKey[0]);
oMsg.addU32(m_xteaKey[1]); msg.addU32(m_xteaKey[1]);
oMsg.addU32(m_xteaKey[2]); msg.addU32(m_xteaKey[2]);
oMsg.addU32(m_xteaKey[3]); msg.addU32(m_xteaKey[3]);
oMsg.addU8(0); // is gm set? msg.addU8(0); // is gm set?
oMsg.addString(m_accountName); msg.addString(m_accountName);
oMsg.addString(m_characterName); msg.addString(m_characterName);
oMsg.addString(m_accountPassword); msg.addString(m_accountPassword);
oMsg.addU32(timestamp); msg.addU32(timestamp);
oMsg.addU8(unknown); msg.addU8(unknown);
// complete the 128 bytes for rsa encryption with zeros // complete the 128 bytes for rsa encryption with zeros
oMsg.addPaddingBytes(128 - (29 + m_accountName.length() + m_characterName.length() + m_accountPassword.length())); msg.addPaddingBytes(128 - (29 + m_accountName.length() + m_characterName.length() + m_accountPassword.length()));
// encrypt with RSA // encrypt with RSA
Rsa::encrypt((char*)oMsg.getBuffer() + 6 + oMsg.getMessageSize() - 128, 128, Proto::RSA); Rsa::encrypt((char*)msg.getBuffer() + 6 + msg.getMessageSize() - 128, 128, Proto::RSA);
send(oMsg); send(msg);
enableXteaEncryption(); enableXteaEncryption();
} }
void ProtocolGame::sendLogout() void ProtocolGame::sendLogout()
{ {
OutputMessage oMsg; OutputMessage msg;
oMsg.addU8(Proto::ClientQuitGame); msg.addU8(Proto::ClientLeaveGame);
send(oMsg); send(msg);
} }
void ProtocolGame::sendPing() void ProtocolGame::sendPingResponse()
{ {
OutputMessage oMsg; OutputMessage msg;
oMsg.addU8(Proto::ClientPingBack); msg.addU8(Proto::ClientPingResponse);
send(oMsg); send(msg);
} }
// autowalk void ProtocolGame::sendWalkPath(const std::vector<Otc::Direction>& path)
{
OutputMessage msg;
msg.addU8(path.size());
for(Otc::Direction dir : path)
msg.addU8(dir);
send(msg);
}
void ProtocolGame::sendWalkNorth() void ProtocolGame::sendWalkNorth()
{ {
OutputMessage oMsg; OutputMessage msg;
oMsg.addU8(Proto::ClientGoNorth); msg.addU8(Proto::ClientWalkNorth);
send(oMsg); send(msg);
} }
void ProtocolGame::sendWalkEast() void ProtocolGame::sendWalkEast()
{ {
OutputMessage oMsg; OutputMessage msg;
oMsg.addU8(Proto::ClientGoEast); msg.addU8(Proto::ClientWalkEast);
send(oMsg); send(msg);
} }
void ProtocolGame::sendWalkSouth() void ProtocolGame::sendWalkSouth()
{ {
OutputMessage oMsg; OutputMessage msg;
oMsg.addU8(Proto::ClientGoSouth); msg.addU8(Proto::ClientWalkSouth);
send(oMsg); send(msg);
} }
void ProtocolGame::sendWalkWest() void ProtocolGame::sendWalkWest()
{ {
OutputMessage oMsg; OutputMessage msg;
oMsg.addU8(Proto::ClientGoWest); msg.addU8(Proto::ClientWalkWest);
send(oMsg); send(msg);
} }
void ProtocolGame::sendStopAutowalk() void ProtocolGame::sendStop()
{ {
OutputMessage oMsg; OutputMessage msg;
oMsg.addU8(Proto::ClientStop); msg.addU8(Proto::ClientStop);
send(oMsg); send(msg);
} }
void ProtocolGame::sendWalkNorthEast() void ProtocolGame::sendWalkNorthEast()
{ {
OutputMessage oMsg; OutputMessage msg;
oMsg.addU8(Proto::ClientGoNorthEast); msg.addU8(Proto::ClientWalkNorthEast);
send(oMsg); send(msg);
} }
void ProtocolGame::sendWalkSouthEast() void ProtocolGame::sendWalkSouthEast()
{ {
OutputMessage oMsg; OutputMessage msg;
oMsg.addU8(Proto::ClientGoSouthEast); msg.addU8(Proto::ClientWalkSouthEast);
send(oMsg); send(msg);
} }
void ProtocolGame::sendWalkSouthWest() void ProtocolGame::sendWalkSouthWest()
{ {
OutputMessage oMsg; OutputMessage msg;
oMsg.addU8(Proto::ClientGoSouthWest); msg.addU8(Proto::ClientWalkSouthWest);
send(oMsg); send(msg);
} }
void ProtocolGame::sendWalkNorthWest() void ProtocolGame::sendWalkNorthWest()
{ {
OutputMessage oMsg; OutputMessage msg;
oMsg.addU8(Proto::ClientGoNorthWest); msg.addU8(Proto::ClientWalkNorthWest);
send(oMsg); send(msg);
} }
void ProtocolGame::sendTurnNorth() void ProtocolGame::sendTurnNorth()
{ {
OutputMessage oMsg; OutputMessage msg;
oMsg.addU8(Proto::ClientRotateNorth); msg.addU8(Proto::ClientTurnNorth);
send(oMsg); send(msg);
} }
void ProtocolGame::sendTurnEast() void ProtocolGame::sendTurnEast()
{ {
OutputMessage oMsg; OutputMessage msg;
oMsg.addU8(Proto::ClientRotateEast); msg.addU8(Proto::ClientTurnEast);
send(oMsg); send(msg);
} }
void ProtocolGame::sendTurnSouth() void ProtocolGame::sendTurnSouth()
{ {
OutputMessage oMsg; OutputMessage msg;
oMsg.addU8(Proto::ClientRotateSouth); msg.addU8(Proto::ClientTurnSouth);
send(oMsg); send(msg);
} }
void ProtocolGame::sendTurnWest() void ProtocolGame::sendTurnWest()
{ {
OutputMessage oMsg; OutputMessage msg;
oMsg.addU8(Proto::ClientRotateWest); msg.addU8(Proto::ClientTurnWest);
send(oMsg); send(msg);
} }
void ProtocolGame::sendThrow(const Position& fromPos, int thingId, int stackpos, const Position& toPos, int count) void ProtocolGame::sendMove(const Position& fromPos, int thingId, int stackpos, const Position& toPos, int count)
{ {
OutputMessage oMsg; OutputMessage msg;
oMsg.addU8(Proto::ClientMoveObject); msg.addU8(Proto::ClientMove);
addPosition(oMsg, fromPos); addPosition(msg, fromPos);
oMsg.addU16(thingId); msg.addU16(thingId);
oMsg.addU8(stackpos); msg.addU8(stackpos);
addPosition(oMsg, toPos); addPosition(msg, toPos);
oMsg.addU8(count); msg.addU8(count);
send(oMsg); send(msg);
} }
void ProtocolGame::sendLookInShop(int thingId, int count) void ProtocolGame::sendInspectNpcTrade(int thingId, int count)
{ {
OutputMessage oMsg; OutputMessage msg;
oMsg.addU8(Proto::ClientInspectNpcTrade); msg.addU8(Proto::ClientInspectNpcTrade);
oMsg.addU16(thingId); msg.addU16(thingId);
oMsg.addU8(count); msg.addU8(count);
send(oMsg); send(msg);
} }
void ProtocolGame::sendPlayerPurchase(int thingId, int count, int amount, bool ignoreCapacity, bool buyWithBackpack) void ProtocolGame::sendBuyItem(int thingId, int count, int amount, bool ignoreCapacity, bool buyWithBackpack)
{ {
OutputMessage oMsg; OutputMessage msg;
oMsg.addU8(Proto::ClientBuyObject); msg.addU8(Proto::ClientBuyItem);
oMsg.addU16(thingId); msg.addU16(thingId);
oMsg.addU8(count); msg.addU8(count);
oMsg.addU8(amount); msg.addU8(amount);
oMsg.addU8(ignoreCapacity ? 0x01 : 0x00); msg.addU8(ignoreCapacity ? 0x01 : 0x00);
oMsg.addU8(buyWithBackpack ? 0x01 : 0x00); msg.addU8(buyWithBackpack ? 0x01 : 0x00);
send(oMsg); send(msg);
} }
void ProtocolGame::sendPlayerSale(int thingId, int count, int amount, bool ignoreEquipped) void ProtocolGame::sendSellItem(int thingId, int count, int amount, bool ignoreEquipped)
{ {
OutputMessage oMsg; OutputMessage msg;
oMsg.addU8(Proto::ClientSellObject); msg.addU8(Proto::ClientSellItem);
oMsg.addU16(thingId); msg.addU16(thingId);
oMsg.addU8(count); msg.addU8(count);
oMsg.addU8(amount); msg.addU8(amount);
oMsg.addU8(ignoreEquipped ? 0x01 : 0x00); msg.addU8(ignoreEquipped ? 0x01 : 0x00);
send(oMsg); send(msg);
} }
void ProtocolGame::sendCloseShop() void ProtocolGame::sendCloseNpcTrade()
{ {
OutputMessage oMsg; OutputMessage msg;
oMsg.addU8(Proto::ClientCloseNpcTrade); msg.addU8(Proto::ClientCloseNpcTrade);
send(oMsg); send(msg);
} }
void ProtocolGame::sendRequestTrade(const Position& pos, int thingId, int stackpos, uint playerId) void ProtocolGame::sendRequestTrade(const Position& pos, int thingId, int stackpos, uint playerId)
{ {
OutputMessage oMsg; OutputMessage msg;
oMsg.addU8(Proto::ClientTradeObject); msg.addU8(Proto::ClientRequestTrade);
addPosition(oMsg, pos); addPosition(msg, pos);
oMsg.addU16(thingId); msg.addU16(thingId);
oMsg.addU8(stackpos); msg.addU8(stackpos);
oMsg.addU32(playerId); msg.addU32(playerId);
send(oMsg); send(msg);
} }
void ProtocolGame::sendLookInTrade(bool counterOffer, int index) void ProtocolGame::sendInspectTrade(bool counterOffer, int index)
{ {
OutputMessage oMsg; OutputMessage msg;
oMsg.addU8(Proto::ClientInspectTrade); msg.addU8(Proto::ClientInspectTrade);
oMsg.addU8(counterOffer ? 0x01 : 0x00); msg.addU8(counterOffer ? 0x01 : 0x00);
oMsg.addU8(index); msg.addU8(index);
send(oMsg); send(msg);
} }
void ProtocolGame::sendAcceptTrade() void ProtocolGame::sendAcceptTrade()
{ {
OutputMessage oMsg; OutputMessage msg;
oMsg.addU8(Proto::ClientAcceptTrade); msg.addU8(Proto::ClientAcceptTrade);
send(oMsg); send(msg);
} }
void ProtocolGame::sendRejectTrade() void ProtocolGame::sendRejectTrade()
{ {
OutputMessage oMsg; OutputMessage msg;
oMsg.addU8(Proto::ClientRejectTrade); msg.addU8(Proto::ClientRejectTrade);
send(oMsg); send(msg);
} }
void ProtocolGame::sendUseItem(const Position& position, int itemId, int stackpos, int index) void ProtocolGame::sendUseItem(const Position& position, int itemId, int stackpos, int index)
{ {
OutputMessage oMsg; OutputMessage msg;
oMsg.addU8(Proto::ClientUseObject); msg.addU8(Proto::ClientUseItem);
addPosition(oMsg, position); addPosition(msg, position);
oMsg.addU16(itemId); msg.addU16(itemId);
oMsg.addU8(stackpos); msg.addU8(stackpos);
oMsg.addU8(index); msg.addU8(index);
send(oMsg); send(msg);
} }
void ProtocolGame::sendUseItemEx(const Position& fromPos, int itemId, int fromStackpos, const Position& toPos, int toThingId, int toStackpos) void ProtocolGame::sendUseItemWith(const Position& fromPos, int itemId, int fromStackpos, const Position& toPos, int toThingId, int toStackpos)
{ {
OutputMessage oMsg; OutputMessage msg;
oMsg.addU8(Proto::ClientUseTwoObjects); msg.addU8(Proto::ClientUseItemWith);
addPosition(oMsg, fromPos); addPosition(msg, fromPos);
oMsg.addU16(itemId); msg.addU16(itemId);
oMsg.addU8(fromStackpos); msg.addU8(fromStackpos);
addPosition(oMsg, toPos); addPosition(msg, toPos);
oMsg.addU16(toThingId); msg.addU16(toThingId);
oMsg.addU8(toStackpos); msg.addU8(toStackpos);
send(oMsg); send(msg);
} }
void ProtocolGame::sendUseOnCreature(const Position& pos, int thingId, int stackpos, uint creatureId) void ProtocolGame::sendUseOnCreature(const Position& pos, int thingId, int stackpos, uint creatureId)
{ {
OutputMessage oMsg; OutputMessage msg;
oMsg.addU8(Proto::ClientUseOnCreature); msg.addU8(Proto::ClientUseOnCreature);
addPosition(oMsg, pos); addPosition(msg, pos);
oMsg.addU16(thingId); msg.addU16(thingId);
oMsg.addU8(stackpos); msg.addU8(stackpos);
oMsg.addU32(creatureId); msg.addU32(creatureId);
send(oMsg); send(msg);
} }
void ProtocolGame::sendRotateItem(const Position& pos, int thingId, int stackpos) void ProtocolGame::sendRotateItem(const Position& pos, int thingId, int stackpos)
{ {
OutputMessage oMsg; OutputMessage msg;
oMsg.addU8(Proto::ClientTurnObject); msg.addU8(Proto::ClientRotateItem);
addPosition(oMsg, pos); addPosition(msg, pos);
oMsg.addU16(thingId); msg.addU16(thingId);
oMsg.addU8(stackpos); msg.addU8(stackpos);
send(oMsg); send(msg);
} }
void ProtocolGame::sendCloseContainer(int containerId) void ProtocolGame::sendCloseContainer(int containerId)
{ {
OutputMessage oMsg; OutputMessage msg;
oMsg.addU8(Proto::ClientCloseContainer); msg.addU8(Proto::ClientCloseContainer);
oMsg.addU8(containerId); msg.addU8(containerId);
send(oMsg); send(msg);
} }
void ProtocolGame::sendUpContainer(int containerId) void ProtocolGame::sendUpContainer(int containerId)
{ {
OutputMessage oMsg; OutputMessage msg;
oMsg.addU8(Proto::ClientUpContainer); msg.addU8(Proto::ClientUpContainer);
oMsg.addU8(containerId); msg.addU8(containerId);
send(oMsg); send(msg);
} }
void ProtocolGame::sendTextWindow(uint windowTextId, const std::string& text) void ProtocolGame::sendEditText(uint textId, const std::string& text)
{ {
OutputMessage oMsg; OutputMessage msg;
oMsg.addU8(Proto::ClientEditText); msg.addU8(Proto::ClientEditText);
oMsg.addU32(windowTextId); msg.addU32(textId);
oMsg.addString(text); msg.addString(text);
send(oMsg); send(msg);
} }
void ProtocolGame::sendHouseWindow(int doorId, uint id, const std::string& text) void ProtocolGame::sendEditList(int listId, uint id, const std::string& text)
{ {
OutputMessage oMsg; OutputMessage msg;
oMsg.addU8(Proto::ClientEditList); msg.addU8(Proto::ClientEditList);
oMsg.addU8(doorId); msg.addU8(listId);
oMsg.addU32(id); msg.addU32(id);
oMsg.addString(text); msg.addString(text);
send(oMsg); send(msg);
} }
void ProtocolGame::sendLookAt(const Position& position, int thingId, int stackpos) void ProtocolGame::sendLook(const Position& position, int thingId, int stackpos)
{ {
OutputMessage oMsg; OutputMessage msg;
oMsg.addU8(Proto::ClientLook); msg.addU8(Proto::ClientLook);
addPosition(oMsg, position); addPosition(msg, position);
oMsg.addU16(thingId); msg.addU16(thingId);
oMsg.addU8(stackpos); msg.addU8(stackpos);
send(oMsg); send(msg);
} }
void ProtocolGame::sendTalk(Otc::SpeakType speakType, int channelId, const std::string& receiver, const std::string& message) void ProtocolGame::sendTalk(Otc::SpeakType speakType, int channelId, const std::string& receiver, const std::string& message)
@ -348,239 +361,227 @@ void ProtocolGame::sendTalk(Otc::SpeakType speakType, int channelId, const std::
int serverSpeakType = Proto::translateSpeakTypeToServer(speakType); int serverSpeakType = Proto::translateSpeakTypeToServer(speakType);
OutputMessage oMsg; OutputMessage msg;
oMsg.addU8(Proto::ClientTalk); msg.addU8(Proto::ClientTalk);
oMsg.addU8(serverSpeakType); msg.addU8(serverSpeakType);
switch(serverSpeakType) { switch(serverSpeakType) {
case Proto::ServerSpeakPrivate: case Proto::ServerSpeakPrivate:
case Proto::ServerSpeakPrivateRed: case Proto::ServerSpeakPrivateRed:
oMsg.addString(receiver); msg.addString(receiver);
break; break;
case Proto::ServerSpeakChannelYellow: case Proto::ServerSpeakChannelYellow:
case Proto::ServerSpeakChannelRed: case Proto::ServerSpeakChannelRed:
oMsg.addU16(channelId); msg.addU16(channelId);
break; break;
} }
oMsg.addString(message); msg.addString(message);
send(oMsg); send(msg);
} }
void ProtocolGame::sendGetChannels() void ProtocolGame::sendRequestChannels()
{ {
OutputMessage oMsg; OutputMessage msg;
oMsg.addU8(Proto::ClientGetChannels); msg.addU8(Proto::ClientRequestChannels);
send(oMsg); send(msg);
} }
void ProtocolGame::sendJoinChannel(int channelId) void ProtocolGame::sendJoinChannel(int channelId)
{ {
OutputMessage oMsg; OutputMessage msg;
oMsg.addU8(Proto::ClientJoinChannel); msg.addU8(Proto::ClientJoinChannel);
oMsg.addU16(channelId); msg.addU16(channelId);
send(oMsg); send(msg);
} }
void ProtocolGame::sendLeaveChannel(int channelId) void ProtocolGame::sendLeaveChannel(int channelId)
{ {
OutputMessage oMsg; OutputMessage msg;
oMsg.addU8(Proto::ClientLeaveChannel); msg.addU8(Proto::ClientLeaveChannel);
oMsg.addU16(channelId); msg.addU16(channelId);
send(oMsg); send(msg);
} }
void ProtocolGame::sendOpenPrivateChannel(const std::string& receiver) void ProtocolGame::sendOpenPrivateChannel(const std::string& receiver)
{ {
OutputMessage oMsg; OutputMessage msg;
oMsg.addU8(Proto::ClientOpenPrivateChannel); msg.addU8(Proto::ClientOpenPrivateChannel);
oMsg.addString(receiver); msg.addString(receiver);
send(oMsg); send(msg);
} }
// removed from game
// process report
// gm closes report
// cancel report
void ProtocolGame::sendCloseNpcChannel() void ProtocolGame::sendCloseNpcChannel()
{ {
OutputMessage oMsg; OutputMessage msg;
oMsg.addU8(Proto::ClientCloseNpcChannel); msg.addU8(Proto::ClientCloseNpcChannel);
send(oMsg); send(msg);
} }
void ProtocolGame::sendFightTatics(Otc::FightModes fightMode, Otc::ChaseModes chaseMode, bool safeFight) void ProtocolGame::sendChangeFightModes(Otc::FightModes fightMode, Otc::ChaseModes chaseMode, bool safeFight)
{ {
OutputMessage oMsg; OutputMessage msg;
oMsg.addU8(Proto::ClientSetTactics); msg.addU8(Proto::ClientChangeFightModes);
oMsg.addU8(fightMode); msg.addU8(fightMode);
oMsg.addU8(chaseMode); msg.addU8(chaseMode);
oMsg.addU8(safeFight ? 0x01: 0x00); msg.addU8(safeFight ? 0x01: 0x00);
send(oMsg); send(msg);
} }
void ProtocolGame::sendAttack(uint creatureId) void ProtocolGame::sendAttack(uint creatureId)
{ {
OutputMessage oMsg; OutputMessage msg;
oMsg.addU8(Proto::ClientAttack); msg.addU8(Proto::ClientAttack);
oMsg.addU32(creatureId); msg.addU32(creatureId);
oMsg.addU32(0); msg.addU32(0);
oMsg.addU32(0); msg.addU32(0);
send(oMsg); send(msg);
} }
void ProtocolGame::sendFollow(uint creatureId) void ProtocolGame::sendFollow(uint creatureId)
{ {
OutputMessage oMsg; OutputMessage msg;
oMsg.addU8(Proto::ClientFollow); msg.addU8(Proto::ClientFollow);
oMsg.addU32(creatureId); msg.addU32(creatureId);
send(oMsg); send(msg);
} }
void ProtocolGame::sendInviteToParty(uint creatureId) void ProtocolGame::sendInviteToParty(uint creatureId)
{ {
OutputMessage oMsg; OutputMessage msg;
oMsg.addU8(Proto::ClientInviteToParty); msg.addU8(Proto::ClientInviteToParty);
oMsg.addU32(creatureId); msg.addU32(creatureId);
send(oMsg); send(msg);
} }
void ProtocolGame::sendJoinParty(uint creatureId) void ProtocolGame::sendJoinParty(uint creatureId)
{ {
OutputMessage oMsg; OutputMessage msg;
oMsg.addU8(Proto::ClientJoinParty); msg.addU8(Proto::ClientJoinParty);
oMsg.addU32(creatureId); msg.addU32(creatureId);
send(oMsg); send(msg);
} }
void ProtocolGame::sendRevokeInvitation(uint creatureId) void ProtocolGame::sendRevokeInvitation(uint creatureId)
{ {
OutputMessage oMsg; OutputMessage msg;
oMsg.addU8(Proto::ClientRevokeInvitation); msg.addU8(Proto::ClientRevokeInvitation);
oMsg.addU32(creatureId); msg.addU32(creatureId);
send(oMsg); send(msg);
} }
void ProtocolGame::sendPassLeadership(uint creatureId) void ProtocolGame::sendPassLeadership(uint creatureId)
{ {
OutputMessage oMsg; OutputMessage msg;
oMsg.addU8(Proto::ClientPassLeadership); msg.addU8(Proto::ClientPassLeadership);
oMsg.addU32(creatureId); msg.addU32(creatureId);
send(oMsg); send(msg);
} }
void ProtocolGame::sendLeaveParty() void ProtocolGame::sendLeaveParty()
{ {
OutputMessage oMsg; OutputMessage msg;
oMsg.addU8(Proto::ClientLeaveParty); msg.addU8(Proto::ClientLeaveParty);
send(oMsg); send(msg);
} }
void ProtocolGame::sendShareExperience(bool active, int unknown) void ProtocolGame::sendShareExperience(bool active, int unknown)
{ {
OutputMessage oMsg; OutputMessage msg;
oMsg.addU8(Proto::ClientShareExperience); msg.addU8(Proto::ClientShareExperience);
oMsg.addU8(active ? 0x01 : 0x00); msg.addU8(active ? 0x01 : 0x00);
oMsg.addU8(unknown); msg.addU8(unknown);
send(oMsg); send(msg);
} }
void ProtocolGame::sendOpenChannel(int channelId) void ProtocolGame::sendOpenOwnChannel()
{ {
OutputMessage oMsg; OutputMessage msg;
oMsg.addU8(Proto::ClientOpenChannel); msg.addU8(Proto::ClientOpenOwnChannel);
oMsg.addU16(channelId); send(msg);
send(oMsg);
} }
void ProtocolGame::sendInviteToChannel(const std::string& name) void ProtocolGame::sendInviteToOwnChannel(const std::string& name)
{ {
OutputMessage oMsg; OutputMessage msg;
oMsg.addU8(Proto::ClientInviteToChannel); msg.addU8(Proto::ClientInviteToOwnChannel);
oMsg.addString(name); msg.addString(name);
send(oMsg); send(msg);
} }
void ProtocolGame::sendExcludeFromChannel(const std::string& name) void ProtocolGame::sendExcludeFromOwnChannel(const std::string& name)
{ {
OutputMessage oMsg; OutputMessage msg;
oMsg.addU8(Proto::ClientExcludeFromChannel); msg.addU8(Proto::ClientExcludeFromOwnChannel);
oMsg.addString(name); msg.addString(name);
send(oMsg); send(msg);
} }
void ProtocolGame::sendCancel() void ProtocolGame::sendCancelAttackAndFollow()
{ {
OutputMessage oMsg; OutputMessage msg;
oMsg.addU8(Proto::ClientCancel); msg.addU8(Proto::ClientCancelAttackAndFollow);
send(oMsg); send(msg);
} }
// update tile (not used) void ProtocolGame::sendRefreshContainer()
void ProtocolGame::sendUpdateContainer()
{ {
OutputMessage oMsg; OutputMessage msg;
oMsg.addU8(Proto::ClientRefreshContainer); msg.addU8(Proto::ClientRefreshContainer);
send(oMsg); send(msg);
} }
void ProtocolGame::sendGetOutfit() void ProtocolGame::sendRequestOutfit()
{ {
OutputMessage oMsg; OutputMessage msg;
oMsg.addU8(Proto::ClientGetOutfit); msg.addU8(Proto::ClientRequestOutfit);
send(oMsg); send(msg);
} }
void ProtocolGame::sendSetOutfit(const Outfit& outfit) void ProtocolGame::sendChangeOutfit(const Outfit& outfit)
{ {
OutputMessage oMsg; OutputMessage msg;
oMsg.addU8(Proto::ClientSetOutfit); msg.addU8(Proto::ClientChangeOutfit);
oMsg.addU16(outfit.getId()); msg.addU16(outfit.getId());
oMsg.addU8(outfit.getHead()); msg.addU8(outfit.getHead());
oMsg.addU8(outfit.getBody()); msg.addU8(outfit.getBody());
oMsg.addU8(outfit.getLegs()); msg.addU8(outfit.getLegs());
oMsg.addU8(outfit.getFeet()); msg.addU8(outfit.getFeet());
oMsg.addU8(outfit.getAddons()); msg.addU8(outfit.getAddons());
send(oMsg); send(msg);
} }
void ProtocolGame::sendAddVip(const std::string& name) void ProtocolGame::sendAddVip(const std::string& name)
{ {
OutputMessage oMsg; OutputMessage msg;
oMsg.addU8(Proto::ClientAddBuddy); msg.addU8(Proto::ClientAddVip);
oMsg.addString(name); msg.addString(name);
send(oMsg); send(msg);
} }
void ProtocolGame::sendRemoveVip(uint playerId) void ProtocolGame::sendRemoveVip(uint playerId)
{ {
OutputMessage oMsg; OutputMessage msg;
oMsg.addU8(Proto::ClientRemoveBuddy); msg.addU8(Proto::ClientRemoveVip);
oMsg.addU32(playerId); msg.addU32(playerId);
send(oMsg); send(msg);
} }
// bug report void ProtocolGame::sendRequestQuestLog()
// violation window
// debug assert
void ProtocolGame::sendGetQuestLog()
{ {
OutputMessage oMsg; OutputMessage msg;
oMsg.addU8(Proto::ClientGetQuestLog); msg.addU8(Proto::ClientRequestQuestLog);
send(oMsg); send(msg);
} }
void ProtocolGame::sendGetQuestLine(int questId) void ProtocolGame::sendRequestQuestLine(int questLine)
{ {
OutputMessage oMsg; OutputMessage msg;
oMsg.addU8(Proto::ClientGetQuestLine); msg.addU8(Proto::ClientRequestQuestLine);
oMsg.addU16(questId); msg.addU16(questLine);
send(oMsg); send(msg);
} }
void ProtocolGame::addPosition(OutputMessage& msg, const Position& position) void ProtocolGame::addPosition(OutputMessage& msg, const Position& position)