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
end
if Game.isOnline() then
Game.safeLogout()
if g_game.isOnline() then
g_game.safeLogout()
if tries == 1 then
loadBox = displayCancelBox('Please wait', 'Loggin out...')
end
@ -39,12 +39,12 @@ local function tryLogin(charInfo, tries)
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...')
connect(loadBox, { onCancel = function()
loadBox = nil
Game.cancelLogin()
g_game.cancelLogin()
CharacterList.show()
end })
@ -110,7 +110,7 @@ end
function CharacterList.destroy()
CharacterList.hide()
if not Game.isOnline() then
if not g_game.isOnline() then
EnterGame.show()
end
end

View File

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

View File

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

View File

@ -40,10 +40,10 @@ function UIItem:onDrop(widget, mousePos)
spinbox:setCurrentIndex(count)
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
else
Game.move(widget.currentDragThing, pos, 1)
g_game.move(widget.currentDragThing, pos, 1)
end
self:setBorderWidth(0)
@ -70,6 +70,6 @@ function UIItem:onMouseRelease(mousePosition, mouseButton)
local item = self:getItem()
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

View File

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

View File

@ -36,10 +36,10 @@ function UIMap:onDrop(widget, mousePos)
spinbox:setCurrentIndex(count)
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
else
Game.move(widget.currentDragThing, tile:getPosition(), 1)
g_game.move(widget.currentDragThing, tile:getPosition(), 1)
end
return true
@ -47,7 +47,7 @@ end
function UIMap:onMouseRelease(mousePosition, mouseButton)
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
end

View File

@ -11,7 +11,7 @@ function Thing:getContainerId()
end
-- 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()
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 keyboardModifiers == KeyboardNoModifier and mouseButton == MouseRightButton then
Game.createThingMenu(menuPosition, lookThing, useThing, creatureThing)
g_game.createThingMenu(menuPosition, lookThing, useThing, creatureThing)
return true
elseif lookThing and keyboardModifiers == KeyboardShiftModifier and (mouseButton == MouseLeftButton or mouseButton == MouseRightButton) then
Game.look(lookThing)
g_game.look(lookThing)
return true
elseif useThing and keyboardModifiers == KeyboardCtrlModifier and (mouseButton == MouseLeftButton or mouseButton == MouseRightButton) then
if useThing:isContainer() then
if useThing:isInsideContainer() then
Game.open(useThing, useThing:getContainerId())
g_game.open(useThing, useThing:getContainerId())
return true
else
Game.open(useThing, Containers.getFreeContainerId())
g_game.open(useThing, Containers.getFreeContainerId())
return true
end
elseif useThing:isMultiUse() then
Game.startUseWith(useThing)
g_game.startUseWith(useThing)
return true
else
Game.use(useThing)
g_game.use(useThing)
return true
end
return true
elseif creatureThing and keyboardModifiers == KeyboardAltModifier and (mouseButton == MouseLeftButton or mouseButton == MouseRightButton) then
Game.attack(creatureThing)
g_game.attack(creatureThing)
return true
end
else
if multiUseThing and keyboardModifiers == KeyboardNoModifier and mouseButton == MouseRightButton then
if multiUseThing:asCreature() then
Game.attack(multiUseThing:asCreature())
g_game.attack(multiUseThing:asCreature())
return true
elseif multiUseThing:isContainer() then
if multiUseThing:isInsideContainer() then
Game.open(multiUseThing, multiUseThing:getContainerId())
g_game.open(multiUseThing, multiUseThing:getContainerId())
return true
else
Game.open(multiUseThing, Containers.getFreeContainerId())
g_game.open(multiUseThing, Containers.getFreeContainerId())
return true
end
elseif multiUseThing:isMultiUse() then
Game.startUseWith(multiUseThing)
g_game.startUseWith(multiUseThing)
return true
else
Game.use(multiUseThing)
g_game.use(multiUseThing)
end
return true
elseif lookThing and keyboardModifiers == KeyboardShiftModifier and (mouseButton == MouseLeftButton or mouseButton == MouseRightButton) then
Game.look(lookThing)
g_game.look(lookThing)
return true
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
elseif creatureThing and keyboardModifiers == KeyboardAltModifier and (mouseButton == MouseLeftButton or mouseButton == MouseRightButton) then
Game.attack(creatureThing)
g_game.attack(creatureThing)
return true
end
end
@ -83,31 +83,31 @@ function Game.processMouseAction(menuPosition, mouseButton, autoWalk, lookThing,
end
function Game.createThingMenu(menuPosition, lookThing, useThing, creatureThing)
function g_game.createThingMenu(menuPosition, lookThing, useThing, creatureThing)
local menu = createWidget('PopupMenu')
if lookThing then
menu:addOption('Look', function() Game.look(lookThing) end)
menu:addOption('Look', function() g_game.look(lookThing) end)
end
if useThing then
if useThing:isContainer() then
if useThing:isInsideContainer() then
menu:addOption('Open', function() Game.open(useThing, useThing:getContainerId()) end)
menu:addOption('Open in new window', function() Game.open(useThing, Containers.getFreeContainerId()) end)
menu:addOption('Open', function() g_game.open(useThing, useThing:getContainerId()) end)
menu:addOption('Open in new window', function() g_game.open(useThing, Containers.getFreeContainerId()) end)
else
menu:addOption('Open', function() Game.open(useThing, Containers.getFreeContainerId()) end)
menu:addOption('Open', function() g_game.open(useThing, Containers.getFreeContainerId()) end)
end
else
if useThing:isMultiUse() then
menu:addOption('Use with ...', function() Game.startUseWith(useThing) end)
menu:addOption('Use with ...', function() g_game.startUseWith(useThing) end)
else
menu:addOption('Use', function() Game.use(useThing) end)
menu:addOption('Use', function() g_game.use(useThing) end)
end
end
if useThing:isRotateable() then
menu:addOption('Rotate', function() Game.rotate(useThing) end)
menu:addOption('Rotate', function() g_game.rotate(useThing) end)
end
end
@ -123,38 +123,38 @@ function Game.createThingMenu(menuPosition, lookThing, useThing, creatureThing)
menu:addSeparator()
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():isPartyLeader() 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
menu:addOption('Enable Shared Experience', function() Game.partyShareExperience(true) end)
menu:addOption('Enable Shared Experience', function() g_game.partyShareExperience(true) end)
end
end
menu:addOption('Leave Party', function() Game.partyLeave() end)
menu:addOption('Leave Party', function() g_game.partyLeave() end)
end
else
local localPlayer = Game.getLocalPlayer()
local localPlayer = g_game.getLocalPlayer()
if localPlayer then
if localPlayer:getAttackingCreature() ~= creatureThing then
menu:addOption('Attack', function() Game.attack(creatureThing) end)
if g_game.getAttackingCreature() ~= creatureThing then
menu:addOption('Attack', function() g_game.attack(creatureThing) end)
else
menu:addOption('Stop Attack', function() Game.cancelAttack() end)
menu:addOption('Stop Attack', function() g_game.cancelAttack() end)
end
if localPlayer:getFollowingCreature() ~= creatureThing then
menu:addOption('Follow', function() Game.follow(creatureThing) end)
if g_game.getFollowingCreature() ~= creatureThing then
menu:addOption('Follow', function() g_game.follow(creatureThing) end)
else
menu:addOption('Stop Follow', function() Game.cancelFollow() end)
menu:addOption('Stop Follow', function() g_game.cancelFollow() end)
end
if creatureThing:asPlayer() then
menu:addSeparator()
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)
local localPlayerShield = localPlayer:asCreature():getShield()
@ -162,21 +162,21 @@ function Game.createThingMenu(menuPosition, lookThing, useThing, creatureThing)
if localPlayerShield == ShieldNone or localPlayerShield == ShieldWhiteBlue 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
menu:addOption('Invite to Party', function() Game.partyInvite(creatureThing:getId()) end)
menu:addOption('Invite to Party', function() g_game.partyInvite(creatureThing:getId()) end)
end
elseif localPlayerShield == ShieldWhiteYellow 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
elseif localPlayerShield == ShieldYellow or localPlayerShield == ShieldYellowSharedExp or localPlayerShield == ShieldYellowNoSharedExpBlink or localPlayerShield == ShieldYellowNoSharedExp 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
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
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

View File

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

View File

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

View File

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

View File

@ -18,13 +18,13 @@ function Containers.getFreeContainerId()
end
-- 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]
if container then
Game.gameRightPanel:removeChild(container)
g_game.gameRightPanel:removeChild(container)
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)
container:setText(name)
@ -57,7 +57,7 @@ end
function Containers.onContainerClose(containerId)
local container = m_containers[containerId]
if container then
Game.gameRightPanel:removeChild(container)
g_game.gameRightPanel:removeChild(container)
end
m_containers[containerId] = nil
end
@ -128,9 +128,9 @@ function Containers.onContainerRemoveItem(containerId, slot)
container.itemCount = container.itemCount - 1
end
connect(Game, { onGameStart = Containers.clean,
connect(g_game, { onGameStart = Containers.clean,
onGameEnd = Containers.clean,
onContainerOpen = Containers.onContainerOpen,
onOpenContainer = Containers.onOpenContainer,
onContainerClose = Containers.onContainerClose,
onContainerAddItem = Containers.onContainerAddItem,
onContainerUpdateItem = Containers.onContainerUpdateItem,

View File

@ -9,7 +9,7 @@ local manaLabel
-- public functions
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:setOn(true)
healthBar = healthBarWindow:getChildById('healthBar')
@ -53,7 +53,7 @@ function HealthBar.onManaChange(mana, maxMana)
manaBar:setPercent(percent)
end
connect(Game, { onGameStart = HealthBar.create,
connect(g_game, { onGameStart = HealthBar.create,
onGameEnd = HealthBar.destroy,
onHealthChange = HealthBar.onHealthChange,
onManaChange = HealthBar.onManaChange })

View File

@ -35,11 +35,11 @@ local hotkeyColors = {
-- public functions
function HotkeysManager.init()
hotkeysWindow = displayUI('hotkeys_manager.otui')
hotkeysWindow:setVisible(false)
hotkeysButton = TopMenu.addButton('hotkeysButton', 'Hotkeys (Ctrl+K)', '/game_hotkeys/icon.png', HotkeysManager.toggle)
Keyboard.bindKeyDown('Ctrl+K', HotkeysManager.toggle)
currentHotkeysList = hotkeysWindow:getChildById('currentHotkeys')
currentItemPreview = hotkeysWindow:getChildById('itemPreview')
addHotkey = hotkeysWindow:getChildById('addHotkey')
@ -52,52 +52,52 @@ function HotkeysManager.init()
useOnSelf = hotkeysWindow:getChildById('useOnSelf')
useOnTarget = hotkeysWindow:getChildById('useOnTarget')
useWith = hotkeysWindow:getChildById('useWith')
itemWidget = createWidget('UIItem')
itemWidget:setVirtual(true)
itemWidget:setVisible(false)
itemWidget:setFocusable(false)
itemWidget:setFocusable(false)
connect(currentHotkeysList, { onChildFocusChange = function (self, focusedChild) HotkeysManager.checkSelectedHotkey(focusedChild) end } )
hotkeysManagerLoaded = true
HotkeysManager.load()
end
function HotkeysManager.load()
local hotkeySettings = Settings.getNode('HotkeysManager')
if hotkeySettings ~= nil then
for i, v in pairs(hotkeySettings) do
for i, v in pairs(hotkeySettings) do
HotkeysManager.addKeyCombo(nil, v.keyCombo, v)
end
end
end
end
function HotkeysManager.save()
local hotkeySettings = {}
local hotkeySettings = {}
for i = 1, currentHotkeysList:getChildCount() do
local child = currentHotkeysList:getChildByIndex(i)
table.insert(hotkeySettings, {keyCombo = child.keyCombo,
autoSend = child.autoSend,
itemId = child.itemId,
table.insert(hotkeySettings, {keyCombo = child.keyCombo,
autoSend = child.autoSend,
itemId = child.itemId,
useType = child.useType,
value = child.value})
value = child.value})
end
Settings.setNode('HotkeysManager', hotkeySettings)
end
function HotkeysManager.terminate()
function HotkeysManager.terminate()
hotkeysManagerLoaded = false
Keyboard.unbindKeyDown('Ctrl+K')
HotkeysManager.save()
currentHotkeysList = nil
hotkeyLabelSelectedOnList = nil
currentItemPreview = nil
hotkeyList = {}
addHotkey = nil
removeHotkey = nil
@ -109,7 +109,7 @@ function HotkeysManager.terminate()
useOnSelf = nil
useOnTarget = nil
useWith = nil
itemWidget:destroy()
itemWidget = nil
hotkeysWindow:destroy()
@ -127,14 +127,14 @@ function HotkeysManager.toggle()
end
function HotkeysManager.show()
if Game.isOnline() then
if g_game.isOnline() then
hotkeysWindow:grabKeyboard()
hotkeysWindow:show()
hotkeysWindow:lock()
end
end
function HotkeysManager.hide()
function HotkeysManager.hide()
hotkeysWindow:ungrabKeyboard()
hotkeysWindow:unlock()
hotkeysWindow:hide()
@ -144,13 +144,13 @@ end
function HotkeysManager.onChooseItemMouseRelease(self, mousePosition, mouseButton)
local item = nil
if mouseButton == MouseLeftButton then
local clickedWidget = Game.gameUi:recursiveGetChildByPos(mousePosition)
local clickedWidget = g_game.gameUi:recursiveGetChildByPos(mousePosition)
if clickedWidget then
if clickedWidget:getClassName() == 'UIMap' then
local tile = clickedWidget:getTile(mousePosition)
if tile then
local thing = tile:getTopMoveThing()
if thing then
if thing then
item = thing:asItem()
end
end
@ -165,9 +165,9 @@ function HotkeysManager.onChooseItemMouseRelease(self, mousePosition, mouseButto
hotkeyLabelSelectedOnList.itemId = item:getId()
HotkeysManager.changeUseType(HOTKEY_MANAGER_USEONSELF)
HotkeysManager.checkSelectedHotkey(hotkeyLabelSelectedOnList)
HotkeysManager:show()
HotkeysManager:show()
end
Mouse.restoreCursor()
self:ungrabMouse()
self:destroy()
@ -182,23 +182,23 @@ function HotkeysManager.startChooseItem()
mouseGrabberWidget:grabMouse()
Mouse.setTargetCursor()
HotkeysManager:hide()
end
function HotkeysManager.clearObject()
hotkeyLabelSelectedOnList.itemId = nil
hotkeyLabelSelectedOnList.itemId = nil
currentItemPreview:clearItem()
HotkeysManager.changeUseType(HOTKEY_MANAGER_USEONSELF)
HotkeysManager.sendAutomatically(false)
hotkeyLabelSelectedOnList:setText(hotkeyLabelSelectedOnList.keyCombo .. ': ')
HotkeysManager.checkSelectedHotkey(hotkeyLabelSelectedOnList)
end
function HotkeysManager.addHotkey()
local widget
messageBox = createWidget('MainWindow', hotkeysWindow)
messageBox:grabKeyboard()
messageBox:setId('assignWindow')
@ -206,13 +206,13 @@ function HotkeysManager.addHotkey()
messageBox:setWidth(420)
messageBox:setHeight(140)
messageBox:setDragable(false)
widget = createWidget('Label', messageBox)
widget:setText('Please, press the key you wish to add onto your hotkeys manager')
widget:resizeToText()
widget:addAnchor(AnchorHorizontalCenter, 'parent', AnchorHorizontalCenter)
widget:addAnchor(AnchorTop, 'parent', AnchorTop)
widget = createWidget('Label', messageBox)
widget:setId('comboPreview')
widget:setText('Current hotkey to add: None')
@ -221,18 +221,18 @@ function HotkeysManager.addHotkey()
widget:addAnchor(AnchorHorizontalCenter, 'parent', AnchorHorizontalCenter)
widget:addAnchor(AnchorTop, 'prev', AnchorBottom)
widget:setMarginTop(20)
widget = createWidget('Button', messageBox)
widget:setId('cancelButton')
widget:setText('Cancel')
widget:setWidth(64)
widget:addAnchor(AnchorBottom, 'parent', AnchorBottom)
widget:addAnchor(AnchorRight, 'parent', AnchorRight)
widget.onClick = function (self)
messageBox = nil
self:getParent():destroy()
widget.onClick = function (self)
messageBox = nil
self:getParent():destroy()
end
widget = createWidget('Button', messageBox)
widget:setId('addButton')
widget:setText('Add')
@ -241,11 +241,11 @@ function HotkeysManager.addHotkey()
widget:addAnchor(AnchorBottom, 'cancelButton', AnchorBottom)
widget:addAnchor(AnchorRight, 'cancelButton', AnchorLeft)
widget:setMarginRight(10)
widget.onClick = function (self)
widget.onClick = function (self)
messageBox = nil
HotkeysManager.addKeyCombo(self:getParent(), self:getParent():getChildById('comboPreview').keyCombo)
end
connect(messageBox, { onKeyDown = HotkeysManager.hotkeyCapture }, true)
end
@ -257,7 +257,7 @@ function HotkeysManager.addKeyCombo(messageBox, keyCombo, keySettings)
label:setColor(hotkeyColors.text)
label:setText(keyCombo..': ')
if keySettings then
hotkeyLabelSelectedOnList = label
hotkeyLabelSelectedOnList = label
label.keyCombo = keyCombo
HotkeysManager.sendAutomatically(keySettings.autoSend)
label.itemId = keySettings.itemId
@ -271,40 +271,40 @@ function HotkeysManager.addKeyCombo(messageBox, keyCombo, keySettings)
label.useType = HOTKEY_MANAGER_USEONSELF
label.value = ''
end
HotkeysManager.checkSelectedHotkey(label)
hotkeyList[keyCombo] = label
Keyboard.bindKeyPress(keyCombo, function () HotkeysManager.call(keyCombo) end, nil, 350)
end
if messageBox then
messageBox:destroy()
messageBox = nil
end
end
end
function HotkeysManager.call(keyCombo)
if Game.isOnline() then
if g_game.isOnline() then
local hotKey = hotkeyList[keyCombo]
if hotKey.itemId == nil and hotKey.value ~= '' then
if hotKey.autoSend then
Game.talk(hotKey.value)
g_game.talk(hotKey.value)
else
Console.setLineEditText(hotKey.value)
end
elseif hotKey.itemId ~= nil 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
local attackingCreature = Game.getLocalPlayer():getAttackingCreature()
local attackingCreature = g_game.getAttackingCreature()
if attackingCreature then
Game.useInventoryItemWith(hotKey.itemId, attackingCreature)
g_game.useInventoryItemWith(hotKey.itemId, attackingCreature)
end
elseif hotKey.useType == HOTKEY_MANAGER_USEWITH then
elseif hotKey.useType == HOTKEY_MANAGER_USEWITH then
itemWidget:setItemId(hotKey.itemId)
Game.startUseWith(itemWidget:getItem())
end
g_game.startUseWith(itemWidget:getItem())
end
end
end
end
@ -312,23 +312,23 @@ end
function HotkeysManager.checkSelectedHotkey(focused)
if hotkeysManagerLoaded then
hotkeyLabelSelectedOnList = focused
if hotkeyLabelSelectedOnList ~= nil then
if hotkeyLabelSelectedOnList ~= nil then
removeHotkey:enable()
if hotkeyLabelSelectedOnList.itemId == nil then
hotkeyText:enable()
hotKeyTextLabel:enable()
hotkeyText:setText(hotkeyLabelSelectedOnList.value)
if hotkeyLabelSelectedOnList.value ~= '' then
if hotkeyLabelSelectedOnList.value ~= '' then
sendAutomatically:enable()
else
sendAutomatically:disable()
end
selectObjectButton:enable()
clearObjectButton:disable()
clearObjectButton:disable()
currentItemPreview:setItemId(0)
else
@ -336,20 +336,20 @@ function HotkeysManager.checkSelectedHotkey(focused)
hotkeyText:disable()
hotKeyTextLabel:disable()
sendAutomatically:disable()
selectObjectButton:disable()
clearObjectButton:enable()
currentItemPreview:setItemId(hotkeyLabelSelectedOnList.itemId)
currentItemPreview:setItemId(hotkeyLabelSelectedOnList.itemId)
end
HotkeysManager.changeUseType(hotkeyLabelSelectedOnList.useType)
HotkeysManager.changeUseType(hotkeyLabelSelectedOnList.useType)
else
hotkeyText:clearText()
removeHotkey:disable()
hotkeyText:disable()
sendAutomatically:disable()
sendAutomatically:setChecked(false)
currentItemPreview:setItemId(0)
selectObjectButton:disable()
clearObjectButton:disable()
@ -359,25 +359,25 @@ function HotkeysManager.checkSelectedHotkey(focused)
useOnSelf:setChecked(false)
useOnTarget:setChecked(false)
useWith:setChecked(false)
end
end
end
end
end
function HotkeysManager.changeUseType(useType, checked)
if checked == nil or checked then
hotkeyLabelSelectedOnList.useType = useType
hotkeyLabelSelectedOnList.useType = useType
if hotkeyLabelSelectedOnList.itemId ~= nil and currentItemPreview:getItem():isMultiUse() then
useOnSelf:enable()
useOnTarget:enable()
useWith:enable()
if useType == HOTKEY_MANAGER_USEONSELF then
hotkeyLabelSelectedOnList:setText(hotkeyLabelSelectedOnList.keyCombo .. ': (use object on yourself)')
hotkeyLabelSelectedOnList:setColor(hotkeyColors.itemUseSelf)
useOnSelf:setChecked(true)
useOnTarget:setChecked(false)
useWith:setChecked(false)
elseif useType == HOTKEY_MANAGER_USEONTARGET then
elseif useType == HOTKEY_MANAGER_USEONTARGET then
hotkeyLabelSelectedOnList:setText(hotkeyLabelSelectedOnList.keyCombo .. ': (use object on target)')
hotkeyLabelSelectedOnList:setColor(hotkeyColors.itemUseTarget)
useOnSelf:setChecked(false)
@ -386,7 +386,7 @@ function HotkeysManager.changeUseType(useType, checked)
elseif useType == HOTKEY_MANAGER_USEWITH then
hotkeyLabelSelectedOnList:setText(hotkeyLabelSelectedOnList.keyCombo .. ': (use object with crosshair)')
hotkeyLabelSelectedOnList:setColor(hotkeyColors.itemUseWith)
useOnSelf:setChecked(false)
useOnTarget:setChecked(false)
useWith:setChecked(true)
@ -395,18 +395,18 @@ function HotkeysManager.changeUseType(useType, checked)
useOnSelf:disable()
useOnTarget:disable()
useWith:disable()
hotkeyLabelSelectedOnList:setText(hotkeyLabelSelectedOnList.keyCombo .. ': (use object)')
hotkeyLabelSelectedOnList:setColor(hotkeyColors.itemUse)
useOnSelf:setChecked(false)
useOnTarget:setChecked(false)
useWith:setChecked(false)
else
else
useOnSelf:disable()
useOnTarget:disable()
useWith:disable()
useOnSelf:setChecked(false)
useOnTarget:setChecked(false)
useWith:setChecked(false)
@ -422,11 +422,11 @@ function HotkeysManager.removeHotkey()
end
end
function HotkeysManager.onHotkeyTextChange(id, value)
function HotkeysManager.onHotkeyTextChange(id, value)
if hotkeyLabelSelectedOnList ~= nil and hotkeyLabelSelectedOnList.keyCombo ~= nil then
hotkeyLabelSelectedOnList:setText(hotkeyLabelSelectedOnList.keyCombo .. ': ' .. value)
hotkeyLabelSelectedOnList.value = value
if value ~= '' then
sendAutomatically:enable()
else
@ -452,6 +452,6 @@ function HotkeysManager.hotkeyCapture(widget, keyCode, keyboardModifiers)
comboPreview.keyCombo = keyCombo
comboPreview:resizeToText()
hotkeysWindow:getChildById('assignWindow'):getChildById('addButton'):enable()
return true
end

View File

@ -6,7 +6,7 @@ local inventoryButton
-- public functions
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:setOn(true)
Keyboard.bindKeyDown('Ctrl+I', Inventory.toggle)
@ -42,7 +42,7 @@ function Inventory.onSoulChange(soul)
widget:setText("Soul:\n" .. soul)
end
connect(Game, { onGameStart = Inventory.create,
connect(g_game, { onGameStart = Inventory.create,
onGameEnd = Inventory.destroy,
onInventoryChange = Inventory.onInventoryChange,
onFreeCapacityChange = Inventory.onFreeCapacityChange,

View File

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

View File

@ -42,7 +42,7 @@ end
-- public functions
function Skills.create()
skillsWindow = displayUI('skills.otui', { parent = Game.gameRightPanel })
skillsWindow = displayUI('skills.otui', { parent = g_game.gameRightPanel })
skillsWindow:hide()
skillsButton = TopMenu.addGameButton('skillsButton', 'Skills (Ctrl+S)', '/core_styles/icons/skills.png', 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')
end
connect(Game, { onGameStart = Skills.create,
connect(g_game, { onGameStart = Skills.create,
onGameEnd = Skills.destroy,
onExperienceChange = Skills.onExperienceChange,
onLevelChange = Skills.onLevelChange,

View File

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

View File

@ -7,7 +7,7 @@ local addVipWindow
-- public functions
function VipList.create()
vipWindow = displayUI('viplist.otui', { parent = Game.gameRightPanel })
vipWindow = displayUI('viplist.otui', { parent = g_game.gameRightPanel })
vipWindow:hide()
vipButton = TopMenu.addGameButton('vipListButton', 'VIP list', 'viplist.png', VipList.toggle)
end
@ -35,7 +35,7 @@ function VipList.destroyAddWindow()
end
function VipList.addVip()
Game.addVip(addVipWindow:getChildById('name'):getText())
g_game.addVip(addVipWindow:getChildById('name'):getText())
VipList.destroyAddWindow()
end
@ -56,7 +56,7 @@ function VipList.onAddVip(id, name, online)
label.vipOnline = online
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 childrenCount = vipList:getChildCount()
@ -114,7 +114,7 @@ function VipList.onVipListLabelMousePress(widget, mousePos, mouseButton)
local menu = createWidget('PopupMenu')
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:addOption('Copy Name', function() g_window.setClipboardText(widget:getText()) end)
menu:display(mousePos)
@ -123,7 +123,7 @@ function VipList.onVipListLabelMousePress(widget, mousePos, mouseButton)
end
connect(Game, { onGameStart = VipList.create,
connect(g_game, { onGameStart = VipList.create,
onGameEnd = VipList.destroy,
onAddVip = VipList.onAddVip,
onVipStateChange = VipList.onVipStateChange })

View File

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

View File

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

View File

@ -33,99 +33,117 @@
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_protocolGame = ProtocolGamePtr(new ProtocolGame);
m_protocolGame->login(account, password, worldHost, (uint16)worldPort, characterName);
}
void Game::cancelLogin()
{
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);
m_serverBeat = 50;
m_fightMode = Otc::FightBalanced;
m_chaseMode = Otc::DontChase;
m_safeFight = true;
m_followingCreature = nullptr;
m_attackingCreature = nullptr;
}
void Game::processConnectionError(const boost::system::error_code& error)
{
// connection errors only have meaning if we still have a protocol
if(m_protocolGame) {
// eof = end of file, a clean disconnect
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)
{
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()
void Game::processDisconnect()
{
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;
g_lua.callGlobalField("Game", "onGameEnd");
processGameEnd();
}
if(m_protocolGame) {
m_protocolGame->disconnect();
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_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,
@ -139,7 +157,7 @@ void Game::processPlayerStats(double health, double maxHealth,
m_localPlayer->getMaxHealth() != maxHealth) {
m_localPlayer->setStatistic(Otc::Health, health);
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
if(health == 0) {
@ -151,49 +169,49 @@ void Game::processPlayerStats(double health, double maxHealth,
if(m_localPlayer->getStatistic(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) {
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 ||
m_localPlayer->getStatistic(Otc::LevelPercent) != levelPercent) {
m_localPlayer->setStatistic(Otc::Level, level);
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 ||
m_localPlayer->getStatistic(Otc::MaxMana) != maxMana) {
m_localPlayer->setStatistic(Otc::Mana, mana);
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 ||
m_localPlayer->getStatistic(Otc::MagicLevelPercent) != magicLevelPercent) {
m_localPlayer->setStatistic(Otc::MagicLevel, magicLevel);
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) {
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) {
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)
{
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)
@ -204,7 +222,12 @@ void Game::processCreatureSpeak(const std::string& name, int level, Otc::SpeakTy
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)
@ -212,7 +235,7 @@ void Game::processContainerAddItem(int containerId, const ItemPtr& item)
if(item)
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)
@ -220,7 +243,7 @@ void Game::processInventoryChange(int slot, const ItemPtr& item)
if(item)
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)
@ -235,14 +258,15 @@ void Game::processCreatureTeleport(const CreaturePtr& creature)
// stop walking on creature teleports
creature->stopWalk();
// locks the walk for a while when teleporting
if(creature == m_localPlayer)
m_localPlayer->lockWalk();
}
void Game::processAttackCancel()
{
if(m_localPlayer->isAttacking())
m_localPlayer->setAttackingCreature(nullptr);
if(isAttacking())
setAttackingCreature(nullptr);
}
void Game::processWalkCancel(Otc::Direction direction)
@ -250,12 +274,44 @@ void Game::processWalkCancel(Otc::Direction 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;
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();
if(!m_localPlayer->canWalk(direction))
@ -271,9 +327,20 @@ void Game::walk(Otc::Direction 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)
{
if(!isOnline() || !checkBotProtection())
if(!canPerformGameAction())
return;
switch(direction) {
@ -306,7 +373,7 @@ void Game::forceWalk(Otc::Direction direction)
void Game::turn(Otc::Direction direction)
{
if(!isOnline())
if(!canPerformGameAction())
return;
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;
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;
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)
{
if(!isOnline() || !thing || !checkBotProtection())
if(!canPerformGameAction() || !thing)
return;
Position pos = thing->getPosition();
@ -357,7 +445,7 @@ void Game::use(const ThingPtr& thing)
void Game::useInventoryItem(int itemId)
{
if(!isOnline() || !checkBotProtection())
if(!canPerformGameAction() || !g_thingsType.isValidItemId(itemId))
return;
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)
{
if(!isOnline() || !item || !toThing || !checkBotProtection())
if(!canPerformGameAction() || !item || !toThing)
return;
Position pos = item->getPosition();
@ -380,12 +468,12 @@ void Game::useWith(const ItemPtr& item, const ThingPtr& toThing)
if(CreaturePtr creature = toThing->asCreature())
m_protocolGame->sendUseOnCreature(pos, item->getId(), item->getStackpos(), creature->getId());
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)
{
if(!isOnline() || !toThing || !checkBotProtection())
if(!canPerformGameAction() || !toThing)
return;
m_localPlayer->lockWalk();
@ -395,212 +483,207 @@ void Game::useInventoryItemWith(int itemId, const ThingPtr& toThing)
if(CreaturePtr creature = toThing->asCreature())
m_protocolGame->sendUseOnCreature(pos, itemId, 0, creature->getId());
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;
m_localPlayer->lockWalk();
m_protocolGame->sendThrow(thing->getPosition(), thing->getId(), thing->getStackpos(), toPos, count);
m_protocolGame->sendUseItem(item->getPosition(), item->getId(), item->getStackpos(), containerId);
}
void Game::setChaseMode(Otc::ChaseModes chaseMode)
void Game::upContainer(int containerId)
{
if(!isOnline() || !checkBotProtection())
if(!canPerformGameAction())
return;
m_chaseMode = chaseMode;
m_protocolGame->sendFightTatics(m_fightMode, m_chaseMode, m_safeFight);
m_protocolGame->sendUpContainer(containerId);
}
void Game::setFightMode(Otc::FightModes fightMode)
void Game::refreshContainer()
{
if(!isOnline() || !checkBotProtection())
if(!canPerformGameAction())
return;
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);
m_protocolGame->sendRefreshContainer();
}
void Game::attack(const CreaturePtr& creature)
{
if(!isOnline() || !creature || !checkBotProtection())
if(!canPerformGameAction() || creature == m_localPlayer || creature == m_attackingCreature)
return;
m_localPlayer->lockWalk();
if(m_localPlayer->isFollowing())
if(creature && isFollowing())
cancelFollow();
m_localPlayer->setAttackingCreature(creature);
m_protocolGame->sendAttack(creature->getId());
}
void Game::cancelAttack()
{
m_localPlayer->lockWalk();
m_localPlayer->setAttackingCreature(nullptr);
m_protocolGame->sendAttack(0);
setAttackingCreature(creature);
m_protocolGame->sendAttack(creature ? creature->getId() : 0);
}
void Game::follow(const CreaturePtr& creature)
{
if(!isOnline() || !creature || !checkBotProtection())
if(!canPerformGameAction() || creature == m_localPlayer || creature == m_followingCreature)
return;
if(m_localPlayer->isAttacking())
m_localPlayer->lockWalk();
if(creature && isAttacking())
cancelAttack();
m_localPlayer->setFollowingCreature(creature);
m_protocolGame->sendFollow(creature->getId());
setFollowingCreature(creature);
m_protocolGame->sendFollow(creature ? creature->getId() : 0);
}
void Game::cancelFollow()
void Game::cancelAttackAndFollow()
{
if(!isOnline() || !checkBotProtection())
if(!canPerformGameAction())
return;
m_localPlayer->setFollowingCreature(nullptr);
m_protocolGame->sendFollow(0);
}
m_localPlayer->lockWalk();
void Game::rotate(const ThingPtr& thing)
{
if(!isOnline() || !thing || !checkBotProtection())
return;
m_protocolGame->sendRotateItem(thing->getPosition(), thing->getId(), thing->getStackpos());
setAttackingCreature(nullptr);
setFollowingCreature(nullptr);
m_protocolGame->sendCancelAttackAndFollow();
}
void Game::talk(const std::string& message)
{
if(!canPerformGameAction() || message.empty())
return;
talkChannel(Otc::SpeakSay, 0, message);
}
void Game::talkChannel(Otc::SpeakType speakType, int channelId, const std::string& message)
{
if(!isOnline() || !checkBotProtection())
if(!canPerformGameAction() || message.empty())
return;
m_protocolGame->sendTalk(speakType, channelId, "", 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;
m_protocolGame->sendTalk(speakType, 0, receiver, message);
}
void Game::openPrivateChannel(const std::string& receiver)
{
if(!isOnline() || !checkBotProtection())
if(!canPerformGameAction() || receiver.empty())
return;
m_protocolGame->sendOpenPrivateChannel(receiver);
}
void Game::requestChannels()
{
if(!isOnline() || !checkBotProtection())
if(!canPerformGameAction())
return;
m_protocolGame->sendGetChannels();
m_protocolGame->sendRequestChannels();
}
void Game::joinChannel(int channelId)
{
if(!isOnline() || !checkBotProtection())
if(!canPerformGameAction())
return;
m_protocolGame->sendJoinChannel(channelId);
}
void Game::leaveChannel(int channelId)
{
if(!isOnline() || !checkBotProtection())
if(!canPerformGameAction())
return;
m_protocolGame->sendLeaveChannel(channelId);
}
void Game::closeNpcChannel()
{
if(!isOnline() || !checkBotProtection())
if(!canPerformGameAction())
return;
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)
{
if(!isOnline() || !checkBotProtection())
if(!canPerformGameAction())
return;
m_protocolGame->sendInviteToParty(creatureId);
}
void Game::partyJoin(int creatureId)
{
if(!isOnline() || !checkBotProtection())
if(!canPerformGameAction())
return;
m_protocolGame->sendJoinParty(creatureId);
}
void Game::partyRevokeInvitation(int creatureId)
{
if(!isOnline() || !checkBotProtection())
if(!canPerformGameAction())
return;
m_protocolGame->sendRevokeInvitation(creatureId);
}
void Game::partyPassLeadership(int creatureId)
{
if(!isOnline() || !checkBotProtection())
if(!canPerformGameAction())
return;
m_protocolGame->sendPassLeadership(creatureId);
}
void Game::partyLeave()
{
if(!isOnline() || !checkBotProtection())
if(!canPerformGameAction())
return;
m_protocolGame->sendLeaveParty();
}
void Game::partyShareExperience(bool active)
{
if(!isOnline() || !checkBotProtection())
if(!canPerformGameAction())
return;
m_protocolGame->sendShareExperience(active, 0);
}
void Game::requestOutfit()
{
if(!isOnline() || !checkBotProtection())
if(!canPerformGameAction())
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;
m_protocolGame->sendSetOutfit(outfit);
m_protocolGame->sendChangeOutfit(outfit);
}
void Game::addVip(const std::string& name)
{
if(!isOnline() || name.empty() || !checkBotProtection())
if(!canPerformGameAction() || name.empty())
return;
m_protocolGame->sendAddVip(name);
}
@ -612,9 +695,38 @@ void Game::removeVip(int 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()
{
#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()) {
logError("caught a lua call to a bot protected game function, the call was canceled");
return false;
@ -622,3 +734,45 @@ bool Game::checkBotProtection()
#endif
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
{
public:
void loginWorld(const std::string& account,
const std::string& password,
const std::string& worldHost, int worldPort,
const std::string& characterName);
void cancelLogin();
void logout(bool force);
void forceLogout();
void safeLogout();
void processLoginError(const std::string& error);
Game();
private:
void resetGameStates();
protected:
/*
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 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 processLogout();
void processDeath();
void processGameStart(const LocalPlayerPtr& localPlayer, int serverBeat);
void processGameEnd();
void processDeath(int penality);
void processPlayerStats(double health, double maxHealth,
double freeCapacity, double experience,
double level, double levelPercent,
@ -54,51 +121,84 @@ public:
double soul, double stamina);
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 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 processInventoryChange(int slot, const ItemPtr& item);
void processCreatureMove(const CreaturePtr& creature, const Position& oldPos, const Position& newPos);
void processCreatureTeleport(const CreaturePtr& creature);
void processAttackCancel();
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
void walk(Otc::Direction direction);
void walkPath(const std::vector<Otc::Direction>& dir);
void forceWalk(Otc::Direction direction);
void turn(Otc::Direction direction);
void stop();
// item related
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 useWith(const ItemPtr& fromThing, const ThingPtr& toThing);
void useInventoryItem(int itemId);
void useInventoryItemWith(int itemId, const ThingPtr& toThing);
void move(const ThingPtr &thing, const Position& toPos, int count);
// fight tatics 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; }
// container related
void open(const ItemPtr& item, int containerId);
void upContainer(int containerId);
void refreshContainer();
// attack/follow related
void attack(const CreaturePtr& creature);
void cancelAttack();
void cancelAttack() { attack(nullptr); }
void follow(const CreaturePtr& creature);
void cancelFollow();
void rotate(const ThingPtr& thing);
void cancelFollow() { follow(nullptr); }
void cancelAttackAndFollow();
// talk related
void talk(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);
// channel related
void openPrivateChannel(const std::string& receiver);
void requestChannels();
void joinChannel(int channelId);
void leaveChannel(int channelId);
void closeNpcChannel();
void openOwnChannel();
void inviteToOwnChannel(const std::string& name);
void excludeFromOwnChannel(const std::string& name);
// party related
void partyInvite(int creatureId);
@ -110,30 +210,65 @@ public:
// outfit related
void requestOutfit();
void setOutfit(const Outfit& outfit);
void changeOutfit(const Outfit& outfit);
// vip related
void addVip(const std::string& name);
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 isOnline() { return !!m_localPlayer; }
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; }
LocalPlayerPtr getLocalPlayer() { return m_localPlayer; }
ProtocolGamePtr getProtocolGame() { return m_protocolGame; }
int getProtocolVersion() { return PROTOCOL; }
private:
void setAttackingCreature(const CreaturePtr& creature);
void setFollowingCreature(const CreaturePtr& creature);
LocalPlayerPtr m_localPlayer;
CreaturePtr m_attackingCreature;
CreaturePtr m_followingCreature;
ProtocolGamePtr m_protocolGame;
bool m_dead;
int m_serverBeat;
Otc::FightModes m_fightMode;
Otc::ChaseModes m_chaseMode;
bool m_safeFight;

View File

@ -28,7 +28,6 @@
LocalPlayer::LocalPlayer()
{
m_preWalking = false;
m_canReportBugs = false;
m_known = false;
m_walkLocked = false;
m_lastPrewalkDone = true;
@ -158,34 +157,4 @@ void LocalPlayer::terminateWalk()
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:
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 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 setKnown(bool known) { m_known = known; }
bool getCanReportBugs() { return m_canReportBugs; }
int getSkill(Otc::Skill skill, Otc::SkillType skillType) { return m_skills[skill][skillType]; }
double getStatistic(Otc::Statistic statistic) { return m_statistics[statistic]; }
CreaturePtr getAttackingCreature() { return m_attackingCreature; }
CreaturePtr getFollowingCreature() { return m_followingCreature; }
int getIcons() { return m_icons; }
bool isKnown() { return m_known; }
bool isAttacking() { return m_attackingCreature != nullptr; }
bool isFollowing() { return m_followingCreature != nullptr; }
bool isPreWalking() { return m_preWalking; }
void unlockWalk() { m_walkLocked = false; }
@ -90,10 +82,7 @@ private:
Position m_lastPrewalkDestionation;
Timer m_walkLockTimer;
bool m_canReportBugs;
bool m_known;
CreaturePtr m_attackingCreature;
CreaturePtr m_followingCreature;
int m_icons;
int m_skills[Otc::LastSkill][Otc::LastSkillType];
double m_statistics[Otc::LastStatistic];

View File

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

View File

@ -51,6 +51,7 @@ public:
uint16 getFirstItemId() { return 100; }
uint16 getMaxItemid() { return m_things[Item].size() + 99; }
bool isValidItemId(int id) { return id >= getFirstItemId() && id <= getMaxItemid(); }
private:
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", "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.registerClass<ProtocolLogin, Protocol>();
@ -148,8 +213,6 @@ void OTClient::registerLuaFunctions()
g_lua.registerClass<Npc, Creature>();
g_lua.registerClass<Monster, Creature>();
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>("getMaxHealth", &LocalPlayer::getMaxHealth);
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>("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.bindClassStaticFunction<UIItem>("create", []{ return UIItemPtr(new UIItem); });
g_lua.bindClassMemberFunction<UIItem>("setItemId", &UIItem::setItemId);

View File

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

View File

@ -41,12 +41,13 @@ public:
void onError(const boost::system::error_code& error);
void sendLogout();
void sendPing();
void sendPingResponse();
void sendWalkPath(const std::vector<Otc::Direction>& path);
void sendWalkNorth();
void sendWalkEast();
void sendWalkSouth();
void sendWalkWest();
void sendStopAutowalk();
void sendStop();
void sendWalkNorthEast();
void sendWalkSouthEast();
void sendWalkSouthWest();
@ -55,31 +56,31 @@ public:
void sendTurnEast();
void sendTurnSouth();
void sendTurnWest();
void sendThrow(const Position& fromPos, int thingId, int stackpos, const Position& toPos, int count);
void sendLookInShop(int thingId, int count);
void sendPlayerPurchase(int thingId, int count, int amount, bool ignoreCapacity, bool buyWithBackpack);
void sendPlayerSale(int thingId, int count, int amount, bool ignoreEquipped);
void sendCloseShop();
void sendMove(const Position& fromPos, int thingId, int stackpos, const Position& toPos, int count);
void sendInspectNpcTrade(int thingId, int count);
void sendBuyItem(int thingId, int count, int amount, bool ignoreCapacity, bool buyWithBackpack);
void sendSellItem(int thingId, int count, int amount, bool ignoreEquipped);
void sendCloseNpcTrade();
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 sendRejectTrade();
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 sendRotateItem(const Position& pos, int thingId, int stackpos);
void sendCloseContainer(int containerId);
void sendUpContainer(int containerId);
void sendTextWindow(uint windowTextId, const std::string& text);
void sendHouseWindow(int doorId, uint id, const std::string& text);
void sendLookAt(const Position& position, int thingId, int stackpos);
void sendEditText(uint textId, const std::string& text);
void sendEditList(int listId, uint id, const std::string& text);
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 sendGetChannels();
void sendRequestChannels();
void sendJoinChannel(int channelId);
void sendLeaveChannel(int channelId);
void sendOpenPrivateChannel(const std::string& receiver);
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 sendFollow(uint creatureId);
void sendInviteToParty(uint creatureId);
@ -88,17 +89,17 @@ public:
void sendPassLeadership(uint creatureId);
void sendLeaveParty();
void sendShareExperience(bool active, int unknown);
void sendOpenChannel(int channelId);
void sendInviteToChannel(const std::string& name);
void sendExcludeFromChannel(const std::string& name);
void sendCancel();
void sendUpdateContainer();
void sendGetOutfit();
void sendSetOutfit(const Outfit& outfit);
void sendOpenOwnChannel();
void sendInviteToOwnChannel(const std::string& name);
void sendExcludeFromOwnChannel(const std::string& name);
void sendCancelAttackAndFollow();
void sendRefreshContainer();
void sendRequestOutfit();
void sendChangeOutfit(const Outfit& outfit);
void sendAddVip(const std::string& name);
void sendRemoveVip(uint playerId);
void sendGetQuestLog();
void sendGetQuestLine(int questId);
void sendRequestQuestLog();
void sendRequestQuestLine(int questLine);
private:
void sendLoginPacket(uint timestamp, uint8 unknown);
@ -109,16 +110,15 @@ private:
void parseInitGame(InputMessage& msg);
void parseGMActions(InputMessage& msg);
void parseLoginError(InputMessage& msg);
void parseFYIMessage(InputMessage& msg);
void parseWaitList(InputMessage& msg);
void parseLoginAdvice(InputMessage& msg);
void parseLoginWait(InputMessage& msg);
void parsePing(InputMessage&);
void parseDeath(InputMessage& msg);
void parseCanReportBugs(InputMessage& msg);
void parseMapDescription(InputMessage& msg);
void parseMoveNorth(InputMessage& msg);
void parseMoveEast(InputMessage& msg);
void parseMoveSouth(InputMessage& msg);
void parseMoveWest(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);
@ -131,7 +131,7 @@ private:
void parseContainerRemoveItem(InputMessage& msg);
void parseAddInventoryItem(InputMessage& msg);
void parseRemoveInventoryItem(InputMessage& msg);
void parseOpenShopWindow(InputMessage& msg);
void parseNpcOffer(InputMessage& msg);
void parsePlayerCash(InputMessage& msg);
void parseCloseShopWindow(InputMessage&);
void parseWorldLight(InputMessage& msg);
@ -156,7 +156,7 @@ private:
void parseChannelList(InputMessage& msg);
void parseOpenChannel(InputMessage& msg);
void parseOpenPrivateChannel(InputMessage& msg);
void parseCreateOwnPrivateChannel(InputMessage& msg);
void parseOpenOwnPrivateChannel(InputMessage& msg);
void parseCloseChannel(InputMessage& msg);
void parseSafeTradeRequest(InputMessage& msg);
void parseSafeTradeClose(InputMessage&);
@ -164,14 +164,14 @@ private:
void parseCancelWalk(InputMessage& msg);
void parseFloorChangeUp(InputMessage& msg);
void parseFloorChangeDown(InputMessage& msg);
void parseOutfitWindow(InputMessage& msg);
void parseVipState(InputMessage& msg);
void parseOutfit(InputMessage& msg);
void parseVipAdd(InputMessage& msg);
void parseVipLogin(InputMessage& msg);
void parseVipLogout(InputMessage& msg);
void parseShowTutorial(InputMessage& msg);
void parseAddMarker(InputMessage& msg);
void parseQuestList(InputMessage& msg);
void parseQuestPartList(InputMessage& msg);
void parseTutorialHint(InputMessage& msg);
void parseAutomapFlag(InputMessage& msg);
void parseQuestLog(InputMessage& msg);
void parseQuestLine(InputMessage& msg);
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);

View File

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

View File

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