Browse Source

reaname and cleanup many stuff

Eduardo Bart 9 years ago
parent
commit
175f97b98f

+ 5
- 5
modules/client_entergame/characterlist.lua View File

@@ -28,8 +28,8 @@ local function tryLogin(charInfo, tries)
28 28
     return
29 29
   end
30 30
 
31
-  if Game.isOnline() then
32
-    Game.safeLogout()
31
+  if g_game.isOnline() then
32
+    g_game.safeLogout()
33 33
     if tries == 1 then
34 34
       loadBox = displayCancelBox('Please wait', 'Loggin out...')
35 35
     end
@@ -39,12 +39,12 @@ local function tryLogin(charInfo, tries)
39 39
 
40 40
   CharacterList.destroyLoadBox()
41 41
 
42
-  Game.loginWorld(EnterGame.account, EnterGame.password, charInfo.worldHost, charInfo.worldPort, charInfo.characterName)
42
+  g_game.loginWorld(EnterGame.account, EnterGame.password, charInfo.worldHost, charInfo.worldPort, charInfo.characterName)
43 43
 
44 44
   loadBox = displayCancelBox('Please wait', 'Connecting to game server...')
45 45
   connect(loadBox, { onCancel = function()
46 46
                                   loadBox = nil
47
-                                  Game.cancelLogin()
47
+                                  g_game.cancelLogin()
48 48
                                   CharacterList.show()
49 49
                                 end })
50 50
 
@@ -110,7 +110,7 @@ end
110 110
 
111 111
 function CharacterList.destroy()
112 112
   CharacterList.hide()
113
-  if not Game.isOnline() then
113
+  if not g_game.isOnline() then
114 114
     EnterGame.show()
115 115
   end
116 116
 end

+ 1
- 1
modules/client_entergame/entergame.lua View File

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

+ 4
- 4
modules/client_topmenu/topmenu.lua View File

@@ -8,8 +8,8 @@ local gameButtonsPanel
8 8
 
9 9
 -- private functions
10 10
 local function onLogout()
11
-  if Game.isOnline() then
12
-    Game.safeLogout()
11
+  if g_game.isOnline() then
12
+    g_game.safeLogout()
13 13
   else
14 14
     exit()
15 15
   end
@@ -25,7 +25,7 @@ function TopMenu.init()
25 25
   TopMenu.addRightButton('logoutButton', 'Logout (Ctrl+Q)', '/core_styles/icons/logout.png', onLogout)
26 26
   Keyboard.bindKeyDown('Ctrl+Q', onLogout)
27 27
 
28
-  connect(Game, { onGameStart = TopMenu.showGameButtons,
28
+  connect(g_game, { onGameStart = TopMenu.showGameButtons,
29 29
                   onGameEnd = TopMenu.hideGameButtons })
30 30
 end
31 31
 
@@ -37,7 +37,7 @@ function TopMenu.terminate()
37 37
   topMenu:destroy()
38 38
   topMenu = nil
39 39
 
40
-  disconnect(Game, { onGameStart = TopMenu.showGameButtons,
40
+  disconnect(g_game, { onGameStart = TopMenu.showGameButtons,
41 41
                      onGameEnd = TopMenu.hideGameButtons })
42 42
 
43 43
   TopMenu = nil

+ 3
- 3
modules/core_widgets/uiitem.lua View File

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

+ 40
- 40
modules/game/game.lua View File

@@ -8,7 +8,7 @@ local function onGameKeyPress(self, keyCode, keyboardModifiers)
8 8
       CharacterList.show()
9 9
       return true
10 10
     elseif keyCode == KeyQ then
11
-      Game.safeLogout()
11
+      g_game.safeLogout()
12 12
       return true
13 13
     end
14 14
   end
@@ -16,97 +16,97 @@ local function onGameKeyPress(self, keyCode, keyboardModifiers)
16 16
 end
17 17
 
18 18
 local function onUseWithMouseRelease(self, mousePosition, mouseButton)
19
-  if Game.selectedThing == nil then return false end
19
+  if g_game.selectedThing == nil then return false end
20 20
   if mouseButton == MouseLeftButton then
21
-    local clickedWidget = Game.gameUi:recursiveGetChildByPos(mousePosition)
21
+    local clickedWidget = g_game.gameUi:recursiveGetChildByPos(mousePosition)
22 22
     if clickedWidget then
23 23
       if clickedWidget:getClassName() == 'UIMap' then
24 24
         local tile = clickedWidget:getTile(mousePosition)
25 25
         if tile then
26
-          Game.useWith(Game.selectedThing, tile:getTopMultiUseThing())
26
+          g_game.useWith(g_game.selectedThing, tile:getTopMultiUseThing())
27 27
         end
28 28
       elseif clickedWidget:getClassName() == 'UIItem' and not clickedWidget:isVirtual() then
29
-        Game.useWith(Game.selectedThing, clickedWidget:getItem())
29
+        g_game.useWith(g_game.selectedThing, clickedWidget:getItem())
30 30
       end
31 31
     end
32 32
   end
33
-  Game.selectedThing = nil
33
+  g_game.selectedThing = nil
34 34
   Mouse.restoreCursor()
35 35
   self:ungrabMouse()
36 36
   return true
37 37
 end
38 38
 
39 39
 -- public functions
40
-function Game.startUseWith(thing)
41
-  Game.selectedThing = thing
40
+function g_game.startUseWith(thing)
41
+  g_game.selectedThing = thing
42 42
   m_mouseGrabberWidget:grabMouse()
43 43
   Mouse.setTargetCursor()
44 44
 end
45 45
 
46
-function Game.createInterface()
46
+function g_game.createInterface()
47 47
   Background.hide()
48 48
   CharacterList.destroyLoadBox()
49
-  Game.gameUi = displayUI('game.otui')
49
+  g_game.gameUi = displayUI('game.otui')
50 50
 
51
-  --Keyboard.bindKeyPress('Up', function() Game.walk(North) end)
52
-  --Keyboard.bindKeyPress('Down', function() Game.walk(South) end)
53
-  --Keyboard.bindKeyPress('Left', function() Game.walk(West) end)
54
-  --Keyboard.bindKeyPress('Right', function() Game.walk(East) end)
51
+  --Keyboard.bindKeyPress('Up', function() g_game.walk(North) end)
52
+  --Keyboard.bindKeyPress('Down', function() g_game.walk(South) end)
53
+  --Keyboard.bindKeyPress('Left', function() g_game.walk(West) end)
54
+  --Keyboard.bindKeyPress('Right', function() g_game.walk(East) end)
55 55
 
56
-  Keyboard.bindKeyPress('Ctrl+Shift+Up', function() Game.forceWalk(North) end)
57
-  Keyboard.bindKeyPress('Ctrl+Shift+Down', function() Game.forceWalk(South) end)
58
-  Keyboard.bindKeyPress('Ctrl+Shift+Left', function() Game.forceWalk(West) end)
59
-  Keyboard.bindKeyPress('Ctrl+Shift+Right', function() Game.forceWalk(East) end)
56
+  Keyboard.bindKeyPress('Ctrl+Shift+Up', function() g_game.forceWalk(North) end)
57
+  Keyboard.bindKeyPress('Ctrl+Shift+Down', function() g_game.forceWalk(South) end)
58
+  Keyboard.bindKeyPress('Ctrl+Shift+Left', function() g_game.forceWalk(West) end)
59
+  Keyboard.bindKeyPress('Ctrl+Shift+Right', function() g_game.forceWalk(East) end)
60 60
 
61
-  rootWidget:moveChildToIndex(Game.gameUi, 1)
62
-  Game.gameMapPanel = Game.gameUi:getChildById('gameMapPanel')
63
-  Game.gameRightPanel = Game.gameUi:getChildById('gameRightPanel')
64
-  Game.gameBottomPanel = Game.gameUi:getChildById('gameBottomPanel')
65
-  m_mouseGrabberWidget = Game.gameUi:getChildById('mouseGrabber')
66
-  connect(Game.gameUi, { onKeyPress = onGameKeyPress })
61
+  rootWidget:moveChildToIndex(g_game.gameUi, 1)
62
+  g_game.gameMapPanel = g_game.gameUi:getChildById('gameMapPanel')
63
+  g_game.gameRightPanel = g_game.gameUi:getChildById('gameRightPanel')
64
+  g_game.gameBottomPanel = g_game.gameUi:getChildById('gameBottomPanel')
65
+  m_mouseGrabberWidget = g_game.gameUi:getChildById('mouseGrabber')
66
+  connect(g_game.gameUi, { onKeyPress = onGameKeyPress })
67 67
   connect(m_mouseGrabberWidget, { onMouseRelease = onUseWithMouseRelease })
68 68
 end
69 69
 
70
-function Game.destroyInterface()
71
-  if Game.gameUi then
72
-    Game.gameUi:destroy()
73
-    Game.gameUi = nil
70
+function g_game.destroyInterface()
71
+  if g_game.gameUi then
72
+    g_game.gameUi:destroy()
73
+    g_game.gameUi = nil
74 74
   end
75 75
   Background.show()
76 76
   CharacterList.show()
77 77
 end
78 78
 
79
-function Game.show()
80
-  Game.gameUi:show()
81
-  Game.gameUi:focus()
82
-  Game.gameMapPanel:focus()
79
+function g_game.show()
80
+  g_game.gameUi:show()
81
+  g_game.gameUi:focus()
82
+  g_game.gameMapPanel:focus()
83 83
 end
84 84
 
85
-function Game.hide()
86
-  Game.gameUi:hide()
85
+function g_game.hide()
86
+  g_game.gameUi:hide()
87 87
 end
88 88
 
89 89
 -- hooked events
90
-function Game.onLoginError(message)
90
+function g_game.onLoginError(message)
91 91
   CharacterList.destroyLoadBox()
92 92
   local errorBox = displayErrorBox("Login Error", "Login error: " .. message)
93 93
   connect(errorBox, { onOk = CharacterList.show })
94 94
 end
95 95
 
96
-function Game.onConnectionError(message)
96
+function g_game.onConnectionError(message)
97 97
   CharacterList.destroyLoadBox()
98 98
   local errorBox = displayErrorBox("Login Error", "Connection error: " .. message)
99 99
   connect(errorBox, { onOk = CharacterList.show })
100 100
 end
101 101
 
102 102
 local function onApplicationClose()
103
-  if Game.isOnline() then
104
-    Game.forceLogout()
103
+  if g_game.isOnline() then
104
+    g_game.forceLogout()
105 105
   else
106 106
     exit()
107 107
   end
108 108
 end
109 109
 
110 110
 setonclose(onApplicationClose)
111
-connect(Game, { onGameStart = Game.createInterface }, true)
112
-connect(Game, { onGameEnd = Game.destroyInterface })
111
+connect(g_game, { onGameStart = g_game.createInterface }, true)
112
+connect(g_game, { onGameEnd = g_game.destroyInterface })

+ 3
- 3
modules/game/map.lua View File

@@ -36,10 +36,10 @@ function UIMap:onDrop(widget, mousePos)
36 36
     spinbox:setCurrentIndex(count)
37 37
 
38 38
     local okButton = moveWindow:getChildById('buttonOk')
39
-    okButton.onClick = function() Game.move(widget.currentDragThing, tile:getPosition(), spinbox:getCurrentIndex()) okButton:getParent():destroy() widget.currentDragThing = nil end
39
+    okButton.onClick = function() g_game.move(widget.currentDragThing, tile:getPosition(), spinbox:getCurrentIndex()) okButton:getParent():destroy() widget.currentDragThing = nil end
40 40
     moveWindow.onEnter = okButton.onClick
41 41
   else
42
-    Game.move(widget.currentDragThing, tile:getPosition(), 1)
42
+    g_game.move(widget.currentDragThing, tile:getPosition(), 1)
43 43
   end
44 44
 
45 45
   return true
@@ -47,7 +47,7 @@ end
47 47
 
48 48
 function UIMap:onMouseRelease(mousePosition, mouseButton)
49 49
   local tile = self:getTile(mousePosition)
50
-  if tile and Game.processMouseAction(mousePosition, mouseButton, nil, tile:getTopLookThing(), tile:getTopUseThing(), tile:getTopCreature(), tile:getTopMultiUseThing()) then return true end
50
+  if tile and g_game.processMouseAction(mousePosition, mouseButton, nil, tile:getTopLookThing(), tile:getTopUseThing(), tile:getTopCreature(), tile:getTopMultiUseThing()) then return true end
51 51
   return false
52 52
 end
53 53
 

+ 42
- 42
modules/game/thing.lua View File

@@ -11,7 +11,7 @@ function Thing:getContainerId()
11 11
 end
12 12
 
13 13
 -- public functions
14
-function Game.processMouseAction(menuPosition, mouseButton, autoWalk, lookThing, useThing, creatureThing, multiUseThing)
14
+function g_game.processMouseAction(menuPosition, mouseButton, autoWalk, lookThing, useThing, creatureThing, multiUseThing)
15 15
   local keyboardModifiers = g_window.getKeyboardModifiers()
16 16
 
17 17
   if autoWalk and keyboardModifiers == KeyboardNoModifier and mouseButton == MouseLeftButton then
@@ -21,60 +21,60 @@ function Game.processMouseAction(menuPosition, mouseButton, autoWalk, lookThing,
21 21
 
22 22
   if not Options.classicControl then
23 23
     if keyboardModifiers == KeyboardNoModifier and mouseButton == MouseRightButton then
24
-      Game.createThingMenu(menuPosition, lookThing, useThing, creatureThing)
24
+      g_game.createThingMenu(menuPosition, lookThing, useThing, creatureThing)
25 25
       return true
26 26
     elseif lookThing and keyboardModifiers == KeyboardShiftModifier and (mouseButton == MouseLeftButton or mouseButton == MouseRightButton) then
27
-      Game.look(lookThing)
27
+      g_game.look(lookThing)
28 28
       return true
29 29
     elseif useThing and keyboardModifiers == KeyboardCtrlModifier and (mouseButton == MouseLeftButton or mouseButton == MouseRightButton) then
30 30
       if useThing:isContainer() then
31 31
         if useThing:isInsideContainer() then
32
-          Game.open(useThing, useThing:getContainerId())
32
+          g_game.open(useThing, useThing:getContainerId())
33 33
           return true
34 34
         else
35
-          Game.open(useThing, Containers.getFreeContainerId())
35
+          g_game.open(useThing, Containers.getFreeContainerId())
36 36
         return true
37 37
         end
38 38
       elseif useThing:isMultiUse() then
39
-        Game.startUseWith(useThing)
39
+        g_game.startUseWith(useThing)
40 40
         return true
41 41
       else
42
-        Game.use(useThing)
42
+        g_game.use(useThing)
43 43
         return true
44 44
       end
45 45
       return true
46 46
     elseif creatureThing and keyboardModifiers == KeyboardAltModifier and (mouseButton == MouseLeftButton or mouseButton == MouseRightButton) then
47
-      Game.attack(creatureThing)
47
+      g_game.attack(creatureThing)
48 48
       return true
49 49
     end
50 50
   else
51 51
     if multiUseThing and keyboardModifiers == KeyboardNoModifier and mouseButton == MouseRightButton then
52 52
       if multiUseThing:asCreature() then
53
-        Game.attack(multiUseThing:asCreature())
53
+        g_game.attack(multiUseThing:asCreature())
54 54
         return true
55 55
       elseif multiUseThing:isContainer() then
56 56
         if multiUseThing:isInsideContainer() then
57
-          Game.open(multiUseThing, multiUseThing:getContainerId())
57
+          g_game.open(multiUseThing, multiUseThing:getContainerId())
58 58
           return true
59 59
         else
60
-          Game.open(multiUseThing, Containers.getFreeContainerId())
60
+          g_game.open(multiUseThing, Containers.getFreeContainerId())
61 61
           return true
62 62
         end
63 63
       elseif multiUseThing:isMultiUse() then
64
-        Game.startUseWith(multiUseThing)
64
+        g_game.startUseWith(multiUseThing)
65 65
         return true
66 66
       else
67
-        Game.use(multiUseThing)
67
+        g_game.use(multiUseThing)
68 68
       end
69 69
       return true
70 70
     elseif lookThing and keyboardModifiers == KeyboardShiftModifier and (mouseButton == MouseLeftButton or mouseButton == MouseRightButton) then
71
-      Game.look(lookThing)
71
+      g_game.look(lookThing)
72 72
       return true
73 73
     elseif useThing and keyboardModifiers == KeyboardCtrlModifier and (mouseButton == MouseLeftButton or mouseButton == MouseRightButton) then
74
-      Game.createThingMenu(menuPosition, lookThing, useThing, creatureThing)
74
+      g_game.createThingMenu(menuPosition, lookThing, useThing, creatureThing)
75 75
       return true
76 76
     elseif creatureThing and keyboardModifiers == KeyboardAltModifier and (mouseButton == MouseLeftButton or mouseButton == MouseRightButton) then
77
-      Game.attack(creatureThing)
77
+      g_game.attack(creatureThing)
78 78
       return true
79 79
     end
80 80
   end
@@ -83,31 +83,31 @@ function Game.processMouseAction(menuPosition, mouseButton, autoWalk, lookThing,
83 83
 end
84 84
 
85 85
 
86
-function Game.createThingMenu(menuPosition, lookThing, useThing, creatureThing)
86
+function g_game.createThingMenu(menuPosition, lookThing, useThing, creatureThing)
87 87
   local menu = createWidget('PopupMenu')
88 88
 
89 89
   if lookThing then
90
-    menu:addOption('Look', function() Game.look(lookThing) end)
90
+    menu:addOption('Look', function() g_game.look(lookThing) end)
91 91
   end
92 92
 
93 93
   if useThing then
94 94
     if useThing:isContainer() then
95 95
       if useThing:isInsideContainer() then
96
-        menu:addOption('Open', function() Game.open(useThing, useThing:getContainerId()) end)
97
-        menu:addOption('Open in new window', function() Game.open(useThing, Containers.getFreeContainerId()) end)
96
+        menu:addOption('Open', function() g_game.open(useThing, useThing:getContainerId()) end)
97
+        menu:addOption('Open in new window', function() g_game.open(useThing, Containers.getFreeContainerId()) end)
98 98
       else
99
-        menu:addOption('Open', function() Game.open(useThing, Containers.getFreeContainerId()) end)
99
+        menu:addOption('Open', function() g_game.open(useThing, Containers.getFreeContainerId()) end)
100 100
       end
101 101
     else
102 102
       if useThing:isMultiUse() then
103
-        menu:addOption('Use with ...', function() Game.startUseWith(useThing) end)
103
+        menu:addOption('Use with ...', function() g_game.startUseWith(useThing) end)
104 104
       else
105
-        menu:addOption('Use', function() Game.use(useThing) end)
105
+        menu:addOption('Use', function() g_game.use(useThing) end)
106 106
       end
107 107
     end
108 108
 
109 109
     if useThing:isRotateable() then
110
-      menu:addOption('Rotate', function() Game.rotate(useThing) end)
110
+      menu:addOption('Rotate', function() g_game.rotate(useThing) end)
111 111
     end
112 112
 
113 113
   end
@@ -123,38 +123,38 @@ function Game.createThingMenu(menuPosition, lookThing, useThing, creatureThing)
123 123
     menu:addSeparator()
124 124
 
125 125
     if creatureThing:asLocalPlayer() then
126
-      menu:addOption('Set Outfit', function() Game.requestOutfit() end)
126
+      menu:addOption('Set Outfit', function() g_game.requestOutfit() end)
127 127
 
128 128
       if creatureThing:asPlayer():isPartyMember() --[[and not fighting]] then
129 129
         if creatureThing:asPlayer():isPartyLeader() then
130 130
           if creatureThing:asPlayer():isPartySharedExperienceActive() then
131
-            menu:addOption('Disable Shared Experience', function() Game.partyShareExperience(false) end)
131
+            menu:addOption('Disable Shared Experience', function() g_game.partyShareExperience(false) end)
132 132
           else
133
-            menu:addOption('Enable Shared Experience', function() Game.partyShareExperience(true) end)
133
+            menu:addOption('Enable Shared Experience', function() g_game.partyShareExperience(true) end)
134 134
           end
135 135
         end
136
-        menu:addOption('Leave Party', function() Game.partyLeave() end)
136
+        menu:addOption('Leave Party', function() g_game.partyLeave() end)
137 137
       end
138 138
 
139 139
     else
140
-      local localPlayer = Game.getLocalPlayer()
140
+      local localPlayer = g_game.getLocalPlayer()
141 141
       if localPlayer then
142
-        if localPlayer:getAttackingCreature() ~= creatureThing then
143
-          menu:addOption('Attack', function() Game.attack(creatureThing) end)
142
+        if g_game.getAttackingCreature() ~= creatureThing then
143
+          menu:addOption('Attack', function() g_game.attack(creatureThing) end)
144 144
         else
145
-          menu:addOption('Stop Attack', function() Game.cancelAttack() end)
145
+          menu:addOption('Stop Attack', function() g_game.cancelAttack() end)
146 146
         end
147 147
 
148
-        if localPlayer:getFollowingCreature() ~= creatureThing then
149
-          menu:addOption('Follow', function() Game.follow(creatureThing) end)
148
+        if g_game.getFollowingCreature() ~= creatureThing then
149
+          menu:addOption('Follow', function() g_game.follow(creatureThing) end)
150 150
         else
151
-          menu:addOption('Stop Follow', function() Game.cancelFollow() end)
151
+          menu:addOption('Stop Follow', function() g_game.cancelFollow() end)
152 152
         end
153 153
 
154 154
         if creatureThing:asPlayer() then
155 155
           menu:addSeparator()
156 156
           menu:addOption('Message to ' .. creatureThing:getName(), function() print('message') end)
157
-          menu:addOption('Add to VIP list', function() Game.addVip(creatureThing:getName()) end)
157
+          menu:addOption('Add to VIP list', function() g_game.addVip(creatureThing:getName()) end)
158 158
           menu:addOption('Ignore ' .. creatureThing:getName(), function() print('ignore') end)
159 159
 
160 160
           local localPlayerShield = localPlayer:asCreature():getShield()
@@ -162,21 +162,21 @@ function Game.createThingMenu(menuPosition, lookThing, useThing, creatureThing)
162 162
 
163 163
           if localPlayerShield == ShieldNone or localPlayerShield == ShieldWhiteBlue then
164 164
             if creatureShield == ShieldWhiteYellow then
165
-              menu:addOption('Join ' .. creatureThing:getName() .. '\'s Party', function() Game.partyJoin(creatureThing:getId()) end)
165
+              menu:addOption('Join ' .. creatureThing:getName() .. '\'s Party', function() g_game.partyJoin(creatureThing:getId()) end)
166 166
             else
167
-              menu:addOption('Invite to Party', function() Game.partyInvite(creatureThing:getId()) end)
167
+              menu:addOption('Invite to Party', function() g_game.partyInvite(creatureThing:getId()) end)
168 168
             end
169 169
           elseif localPlayerShield == ShieldWhiteYellow then
170 170
             if creatureShield == ShieldWhiteBlue then
171
-              menu:addOption('Revoke ' .. creatureThing:getName() .. '\'s Invitation', function() Game.partyRevokeInvitation(creatureThing:getId()) end)
171
+              menu:addOption('Revoke ' .. creatureThing:getName() .. '\'s Invitation', function() g_game.partyRevokeInvitation(creatureThing:getId()) end)
172 172
             end
173 173
           elseif localPlayerShield == ShieldYellow or localPlayerShield == ShieldYellowSharedExp or localPlayerShield == ShieldYellowNoSharedExpBlink or localPlayerShield == ShieldYellowNoSharedExp then
174 174
             if creatureShield == ShieldWhiteBlue then
175
-              menu:addOption('Revoke ' .. creatureThing:getName() .. '\'s Invitation', function() Game.partyRevokeInvitation(creatureThing:getId()) end)
175
+              menu:addOption('Revoke ' .. creatureThing:getName() .. '\'s Invitation', function() g_game.partyRevokeInvitation(creatureThing:getId()) end)
176 176
             elseif creatureShield == ShieldBlue or creatureShield == ShieldBlueSharedExp or creatureShield == ShieldBlueNoSharedExpBlink or creatureShield == ShieldBlueNoSharedExp then
177
-              menu:addOption('Pass Leadership to ' .. creatureThing:getName(), function() Game.partyPassLeadership(creatureThing:getId()) end)
177
+              menu:addOption('Pass Leadership to ' .. creatureThing:getName(), function() g_game.partyPassLeadership(creatureThing:getId()) end)
178 178
             else
179
-              menu:addOption('Invite to Party', function() Game.partyInvite(creatureThing:getId()) end)
179
+              menu:addOption('Invite to Party', function() g_game.partyInvite(creatureThing:getId()) end)
180 180
             end
181 181
           end
182 182
         end

+ 17
- 17
modules/game_combatcontrols/combatcontrols.lua View File

@@ -22,8 +22,8 @@ local function onFightModeChange(self, selectedFightButton)
22 22
   else
23 23
     fightMode = FightDefensive
24 24
   end
25
-  if Game.getFightMode ~= fightMode then
26
-    Game.setFightMode(fightMode)
25
+  if g_game.getFightMode ~= fightMode then
26
+    g_game.setFightMode(fightMode)
27 27
   end
28 28
 end
29 29
 
@@ -34,15 +34,15 @@ local function onChaseModeChange(self, checked)
34 34
   else
35 35
     chaseMode = DontChase
36 36
   end
37
-  if Game.getChaseMode() ~= chaseMode then
38
-    Game.setChaseMode(chaseMode)
37
+  if g_game.getChaseMode() ~= chaseMode then
38
+    g_game.setChaseMode(chaseMode)
39 39
   end
40 40
 end
41 41
 
42 42
 local function onSafeFightChange(self, checked)
43 43
   local safeFight = not checked
44
-  if Game.isSafeFight() ~= safeFight then
45
-    Game.setSafeFight(not checked)
44
+  if g_game.isSafeFight() ~= safeFight then
45
+    g_game.setSafeFight(not checked)
46 46
   end
47 47
 end
48 48
 
@@ -66,16 +66,16 @@ function CombatControls.init()
66 66
   connect(fightModeRadioGroup, { onSelectionChange = onFightModeChange })
67 67
   connect(chaseModeButton, { onCheckChange = onChaseModeChange })
68 68
   connect(safeFightButton, { onCheckChange = onSafeFightChange })
69
-  connect(Game, { onGameStart = CombatControls.online })
70
-  connect(Game, { onGameEnd = CombatControls.offline })
69
+  connect(g_game, { onGameStart = CombatControls.online })
70
+  connect(g_game, { onGameEnd = CombatControls.offline })
71 71
 
72
-  if Game.isOnline() then
72
+  if g_game.isOnline() then
73 73
     CombatControls.online()
74 74
   end
75 75
 end
76 76
 
77 77
 function CombatControls.terminate()
78
-  if Game.isOnline() then
78
+  if g_game.isOnline() then
79 79
     CombatControls.offline()
80 80
   end
81 81
 
@@ -94,17 +94,17 @@ function CombatControls.terminate()
94 94
   combatControlsWindow:destroy()
95 95
   combatControlsWindow = nil
96 96
 
97
-  disconnect(Game, { onGameStart = CombatControls.online })
98
-  disconnect(Game, { onGameEnd = CombatControls.offline })
97
+  disconnect(g_game, { onGameStart = CombatControls.online })
98
+  disconnect(g_game, { onGameEnd = CombatControls.offline })
99 99
 
100 100
   CombatControls = nil
101 101
 end
102 102
 
103 103
 function CombatControls.online()
104
-  Game.gameRightPanel:addChild(combatControlsWindow)
104
+  g_game.gameRightPanel:addChild(combatControlsWindow)
105 105
   combatControlsWindow:setVisible(combatControlsButton:isOn())
106 106
 
107
-  local fightMode = Game.getFightMode()
107
+  local fightMode = g_game.getFightMode()
108 108
   if fightMode == FightOffensive then
109 109
     fightModeRadioGroup:selectWidget(fightOffensiveBox)
110 110
   elseif fightMode == FightBalanced then
@@ -113,15 +113,15 @@ function CombatControls.online()
113 113
     fightModeRadioGroup:selectWidget(fightDefensiveBox)
114 114
   end
115 115
 
116
-  local chaseMode = Game.getChaseMode()
116
+  local chaseMode = g_game.getChaseMode()
117 117
   chaseModeButton:setChecked(chaseMode == ChaseOpponent)
118 118
 
119
-  local safeFight = Game.isSafeFight()
119
+  local safeFight = g_game.isSafeFight()
120 120
   safeFightButton:setChecked(not safeFight)
121 121
 end
122 122
 
123 123
 function CombatControls.offline()
124
-  Game.gameRightPanel:removeChild(combatControlsWindow)
124
+  g_game.gameRightPanel:removeChild(combatControlsWindow)
125 125
 end
126 126
 
127 127
 function CombatControls.toggle()

+ 11
- 11
modules/game_console/console.lua View File

@@ -78,7 +78,7 @@ end
78 78
 
79 79
 -- public functions
80 80
 function Console.create()
81
-  consolePanel = displayUI('console.otui', { parent = Game.gameBottomPanel } )
81
+  consolePanel = displayUI('console.otui', { parent = g_game.gameBottomPanel } )
82 82
   consoleLineEdit = consolePanel:getChildById('consoleLineEdit')
83 83
   consoleBuffer = consolePanel:getChildById('consoleBuffer')
84 84
   consoleTabBar = consolePanel:getChildById('consoleTabBar')
@@ -100,7 +100,7 @@ function Console.create()
100 100
   connect(consoleTabBar, { onTabChange = Console.onTabChange })
101 101
 
102 102
   -- tibia like hotkeys
103
-  Keyboard.bindKeyDown('Ctrl+O', Game.requestChannels)
103
+  Keyboard.bindKeyDown('Ctrl+O', g_game.requestChannels)
104 104
   Keyboard.bindKeyDown('Ctrl+E', Console.removeCurrentTab)
105 105
 end
106 106
 
@@ -139,9 +139,9 @@ function Console.removeCurrentTab()
139 139
 
140 140
   -- notificate the server that we are leaving the channel
141 141
   if tab.channelId then
142
-    Game.leaveChannel(tab.channelId)
142
+    g_game.leaveChannel(tab.channelId)
143 143
   elseif tab:getText() == "NPCs" then
144
-    Game.closeNpcChannel()
144
+    g_game.closeNpcChannel()
145 145
   end
146 146
 end
147 147
 
@@ -264,7 +264,7 @@ function Console.sendCurrentMessage()
264 264
       speaktypedesc = 'channelYellow'
265 265
     end
266 266
 
267
-    Game.talkChannel(SpeakTypesSettings[speaktypedesc].speakType, tab.channelId, message)
267
+    g_game.talkChannel(SpeakTypesSettings[speaktypedesc].speakType, tab.channelId, message)
268 268
     return
269 269
   else
270 270
     local isPrivateCommand = false
@@ -280,8 +280,8 @@ function Console.sendCurrentMessage()
280 280
 
281 281
 
282 282
     local speaktype = SpeakTypesSettings[speaktypedesc]
283
-    local player = Game.getLocalPlayer()
284
-    Game.talkPrivate(speaktype.speakType, name, message)
283
+    local player = g_game.getLocalPlayer()
284
+    g_game.talkPrivate(speaktype.speakType, name, message)
285 285
 
286 286
     message = applyMessagePrefixies(player:getName(), player:getLevel(), message)
287 287
     Console.addPrivateText(message, speaktype, name, isPrivateCommand)
@@ -316,7 +316,7 @@ local function onCreatureSpeak(name, level, speaktype, message, channelId, creat
316 316
       Console.addText(message, speaktype, channel)
317 317
     else
318 318
       -- server sent a message on a channel that we are not aware of, must leave it
319
-      Game.leaveChannel(channelId)
319
+      g_game.leaveChannel(channelId)
320 320
     end
321 321
   end
322 322
 end
@@ -336,11 +336,11 @@ local function doChannelListSubmit(channelsWindow)
336 336
   local channelListPanel = channelsWindow:getChildById('channelList')
337 337
   local openPrivateChannelWith = channelsWindow:getChildById('openPrivateChannelWith'):getText()
338 338
   if openPrivateChannelWith ~= '' then
339
-    Game.openPrivateChannel(openPrivateChannelWith)
339
+    g_game.openPrivateChannel(openPrivateChannelWith)
340 340
   else
341 341
     local selectedChannelLabel = channelListPanel:getFocusedChild()
342 342
     if not selectedChannelLabel then return end
343
-    Game.joinChannel(selectedChannelLabel.channelId)
343
+    g_game.joinChannel(selectedChannelLabel.channelId)
344 344
   end
345 345
   channelsWindow:destroy()
346 346
 end
@@ -365,7 +365,7 @@ local function onChannelList(channelList)
365 365
   end
366 366
 end
367 367
 
368
-connect(Game, { onGameStart = Console.create,
368
+connect(g_game, { onGameStart = Console.create,
369 369
                 onGameEnd = Console.destroy,
370 370
                 onCreatureSpeak = onCreatureSpeak,
371 371
                 onChannelList = onChannelList,

+ 1
- 1
modules/game_console/console.otui View File

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

+ 6
- 6
modules/game_containers/containers.lua View File

@@ -18,13 +18,13 @@ function Containers.getFreeContainerId()
18 18
 end
19 19
 
20 20
 -- hooked events
21
-function Containers.onContainerOpen(containerId, itemId, name, capacity, hasParent, items)
21
+function Containers.onOpenContainer(containerId, itemId, name, capacity, hasParent, items)
22 22
   local container = m_containers[containerId]
23 23
   if container then
24
-    Game.gameRightPanel:removeChild(container)
24
+    g_game.gameRightPanel:removeChild(container)
25 25
   end
26 26
 
27
-  container = displayUI('container.otui', { parent = Game.gameRightPanel })
27
+  container = displayUI('container.otui', { parent = g_game.gameRightPanel })
28 28
   name = name:sub(1,1):upper() .. name:sub(2)
29 29
   container:setText(name)
30 30
 
@@ -57,7 +57,7 @@ end
57 57
 function Containers.onContainerClose(containerId)
58 58
   local container = m_containers[containerId]
59 59
   if container then
60
-    Game.gameRightPanel:removeChild(container)
60
+    g_game.gameRightPanel:removeChild(container)
61 61
   end
62 62
   m_containers[containerId] = nil
63 63
 end
@@ -128,9 +128,9 @@ function Containers.onContainerRemoveItem(containerId, slot)
128 128
   container.itemCount = container.itemCount - 1
129 129
 end
130 130
 
131
-connect(Game, { onGameStart = Containers.clean,
131
+connect(g_game, { onGameStart = Containers.clean,
132 132
                 onGameEnd = Containers.clean,
133
-                onContainerOpen = Containers.onContainerOpen,
133
+                onOpenContainer = Containers.onOpenContainer,
134 134
                 onContainerClose = Containers.onContainerClose,
135 135
                 onContainerAddItem = Containers.onContainerAddItem,
136 136
                 onContainerUpdateItem = Containers.onContainerUpdateItem,

+ 2
- 2
modules/game_healthbar/healthbar.lua View File

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

+ 76
- 76
modules/game_hotkeys/hotkeys_manager.lua View File

@@ -35,11 +35,11 @@ local hotkeyColors = {
35 35
 -- public functions
36 36
 function HotkeysManager.init()
37 37
   hotkeysWindow = displayUI('hotkeys_manager.otui')
38
-  
38
+
39 39
   hotkeysWindow:setVisible(false)
40 40
   hotkeysButton = TopMenu.addButton('hotkeysButton', 'Hotkeys (Ctrl+K)', '/game_hotkeys/icon.png', HotkeysManager.toggle)
41 41
   Keyboard.bindKeyDown('Ctrl+K', HotkeysManager.toggle)
42
-  
42
+
43 43
   currentHotkeysList = hotkeysWindow:getChildById('currentHotkeys')
44 44
   currentItemPreview = hotkeysWindow:getChildById('itemPreview')
45 45
   addHotkey = hotkeysWindow:getChildById('addHotkey')
@@ -52,52 +52,52 @@ function HotkeysManager.init()
52 52
   useOnSelf = hotkeysWindow:getChildById('useOnSelf')
53 53
   useOnTarget = hotkeysWindow:getChildById('useOnTarget')
54 54
   useWith = hotkeysWindow:getChildById('useWith')
55
-  
55
+
56 56
   itemWidget = createWidget('UIItem')
57 57
   itemWidget:setVirtual(true)
58 58
   itemWidget:setVisible(false)
59
-  itemWidget:setFocusable(false) 
60
-  
59
+  itemWidget:setFocusable(false)
60
+
61 61
   connect(currentHotkeysList, { onChildFocusChange = function (self, focusedChild) HotkeysManager.checkSelectedHotkey(focusedChild) end } )
62
-  
62
+
63 63
   hotkeysManagerLoaded = true
64
-  
64
+
65 65
   HotkeysManager.load()
66 66
 end
67 67
 
68 68
 function HotkeysManager.load()
69 69
   local hotkeySettings = Settings.getNode('HotkeysManager')
70
-  
70
+
71 71
   if hotkeySettings ~= nil then
72
-    for i, v in pairs(hotkeySettings) do 
72
+    for i, v in pairs(hotkeySettings) do
73 73
       HotkeysManager.addKeyCombo(nil, v.keyCombo, v)
74
-    end    
74
+    end
75 75
   end
76 76
 end
77 77
 
78 78
 function HotkeysManager.save()
79
-  local hotkeySettings = {} 
79
+  local hotkeySettings = {}
80 80
   for i = 1, currentHotkeysList:getChildCount() do
81 81
     local child = currentHotkeysList:getChildByIndex(i)
82
-    table.insert(hotkeySettings, {keyCombo = child.keyCombo, 
83
-                                  autoSend = child.autoSend, 
84
-                                  itemId = child.itemId, 
82
+    table.insert(hotkeySettings, {keyCombo = child.keyCombo,
83
+                                  autoSend = child.autoSend,
84
+                                  itemId = child.itemId,
85 85
                                   useType = child.useType,
86
-                                  value = child.value})                                  
86
+                                  value = child.value})
87 87
   end
88 88
   Settings.setNode('HotkeysManager', hotkeySettings)
89 89
 end
90 90
 
91
-function HotkeysManager.terminate()	 
91
+function HotkeysManager.terminate()
92 92
   hotkeysManagerLoaded = false
93
-  
93
+
94 94
   Keyboard.unbindKeyDown('Ctrl+K')
95 95
   HotkeysManager.save()
96
-  
96
+
97 97
   currentHotkeysList = nil
98 98
   hotkeyLabelSelectedOnList = nil
99 99
   currentItemPreview = nil
100
-  
100
+
101 101
   hotkeyList = {}
102 102
   addHotkey = nil
103 103
   removeHotkey = nil
@@ -109,7 +109,7 @@ function HotkeysManager.terminate()
109 109
   useOnSelf = nil
110 110
   useOnTarget = nil
111 111
   useWith = nil
112
-  
112
+
113 113
   itemWidget:destroy()
114 114
   itemWidget = nil
115 115
   hotkeysWindow:destroy()
@@ -127,14 +127,14 @@ function HotkeysManager.toggle()
127 127
 end
128 128
 
129 129
 function HotkeysManager.show()
130
-  if Game.isOnline() then
130
+  if g_game.isOnline() then
131 131
     hotkeysWindow:grabKeyboard()
132 132
     hotkeysWindow:show()
133 133
     hotkeysWindow:lock()
134 134
   end
135 135
 end
136 136
 
137
-function HotkeysManager.hide()  
137
+function HotkeysManager.hide()
138 138
   hotkeysWindow:ungrabKeyboard()
139 139
   hotkeysWindow:unlock()
140 140
   hotkeysWindow:hide()
@@ -144,13 +144,13 @@ end
144 144
 function HotkeysManager.onChooseItemMouseRelease(self, mousePosition, mouseButton)
145 145
   local item = nil
146 146
   if mouseButton == MouseLeftButton then
147
-    local clickedWidget = Game.gameUi:recursiveGetChildByPos(mousePosition)
147
+    local clickedWidget = g_game.gameUi:recursiveGetChildByPos(mousePosition)
148 148
     if clickedWidget then
149 149
       if clickedWidget:getClassName() == 'UIMap' then
150 150
         local tile = clickedWidget:getTile(mousePosition)
151 151
         if tile then
152 152
           local thing = tile:getTopMoveThing()
153
-          if thing then 
153
+          if thing then
154 154
             item = thing:asItem()
155 155
           end
156 156
         end
@@ -165,9 +165,9 @@ function HotkeysManager.onChooseItemMouseRelease(self, mousePosition, mouseButto
165 165
     hotkeyLabelSelectedOnList.itemId = item:getId()
166 166
     HotkeysManager.changeUseType(HOTKEY_MANAGER_USEONSELF)
167 167
     HotkeysManager.checkSelectedHotkey(hotkeyLabelSelectedOnList)
168
-    HotkeysManager:show()    
168
+    HotkeysManager:show()
169 169
   end
170
-  
170
+
171 171
   Mouse.restoreCursor()
172 172
   self:ungrabMouse()
173 173
   self:destroy()
@@ -182,23 +182,23 @@ function HotkeysManager.startChooseItem()
182 182
 
183 183
   mouseGrabberWidget:grabMouse()
184 184
   Mouse.setTargetCursor()
185
-  
185
+
186 186
   HotkeysManager:hide()
187 187
 end
188 188
 
189 189
 function HotkeysManager.clearObject()
190
-  hotkeyLabelSelectedOnList.itemId = nil  
190
+  hotkeyLabelSelectedOnList.itemId = nil
191 191
   currentItemPreview:clearItem()
192 192
   HotkeysManager.changeUseType(HOTKEY_MANAGER_USEONSELF)
193 193
   HotkeysManager.sendAutomatically(false)
194 194
   hotkeyLabelSelectedOnList:setText(hotkeyLabelSelectedOnList.keyCombo .. ': ')
195
-  
195
+
196 196
   HotkeysManager.checkSelectedHotkey(hotkeyLabelSelectedOnList)
197 197
 end
198 198
 
199 199
 function HotkeysManager.addHotkey()
200 200
   local widget
201
-  
201
+
202 202
   messageBox = createWidget('MainWindow', hotkeysWindow)
203 203
   messageBox:grabKeyboard()
204 204
   messageBox:setId('assignWindow')
@@ -206,13 +206,13 @@ function HotkeysManager.addHotkey()
206 206
   messageBox:setWidth(420)
207 207
   messageBox:setHeight(140)
208 208
   messageBox:setDragable(false)
209
-  
209
+
210 210
   widget = createWidget('Label', messageBox)
211 211
   widget:setText('Please, press the key you wish to add onto your hotkeys manager')
212 212
   widget:resizeToText()
213 213
   widget:addAnchor(AnchorHorizontalCenter, 'parent', AnchorHorizontalCenter)
214 214
   widget:addAnchor(AnchorTop, 'parent', AnchorTop)
215
-  
215
+
216 216
   widget = createWidget('Label', messageBox)
217 217
   widget:setId('comboPreview')
218 218
   widget:setText('Current hotkey to add: None')
@@ -221,18 +221,18 @@ function HotkeysManager.addHotkey()
221 221
   widget:addAnchor(AnchorHorizontalCenter, 'parent', AnchorHorizontalCenter)
222 222
   widget:addAnchor(AnchorTop, 'prev', AnchorBottom)
223 223
   widget:setMarginTop(20)
224
-  
224
+
225 225
   widget = createWidget('Button', messageBox)
226 226
   widget:setId('cancelButton')
227 227
   widget:setText('Cancel')
228 228
   widget:setWidth(64)
229 229
   widget:addAnchor(AnchorBottom, 'parent', AnchorBottom)
230 230
   widget:addAnchor(AnchorRight, 'parent', AnchorRight)
231
-  widget.onClick =  function (self) 
232
-                      messageBox = nil 
233
-                      self:getParent():destroy() 
231
+  widget.onClick =  function (self)
232
+                      messageBox = nil
233
+                      self:getParent():destroy()
234 234
                     end
235
-  
235
+
236 236
   widget = createWidget('Button', messageBox)
237 237
   widget:setId('addButton')
238 238
   widget:setText('Add')
@@ -241,11 +241,11 @@ function HotkeysManager.addHotkey()
241 241
   widget:addAnchor(AnchorBottom, 'cancelButton', AnchorBottom)
242 242
   widget:addAnchor(AnchorRight, 'cancelButton', AnchorLeft)
243 243
   widget:setMarginRight(10)
244
-  widget.onClick =  function (self) 
244
+  widget.onClick =  function (self)
245 245
                       messageBox = nil
246 246
                       HotkeysManager.addKeyCombo(self:getParent(), self:getParent():getChildById('comboPreview').keyCombo)
247 247
                     end
248
-  
248
+
249 249
   connect(messageBox, { onKeyDown = HotkeysManager.hotkeyCapture }, true)
250 250
 end
251 251
 
@@ -257,7 +257,7 @@ function HotkeysManager.addKeyCombo(messageBox, keyCombo, keySettings)
257 257
     label:setColor(hotkeyColors.text)
258 258
     label:setText(keyCombo..': ')
259 259
     if keySettings then
260
-      hotkeyLabelSelectedOnList = label      
260
+      hotkeyLabelSelectedOnList = label
261 261
       label.keyCombo = keyCombo
262 262
       HotkeysManager.sendAutomatically(keySettings.autoSend)
263 263
       label.itemId = keySettings.itemId
@@ -271,40 +271,40 @@ function HotkeysManager.addKeyCombo(messageBox, keyCombo, keySettings)
271 271
       label.useType = HOTKEY_MANAGER_USEONSELF
272 272
       label.value = ''
273 273
     end
274
-    
274
+
275 275
     HotkeysManager.checkSelectedHotkey(label)
276
-    
276
+
277 277
     hotkeyList[keyCombo] = label
278 278
     Keyboard.bindKeyPress(keyCombo, function () HotkeysManager.call(keyCombo) end, nil, 350)
279 279
   end
280
-  
280
+
281 281
   if messageBox then
282 282
     messageBox:destroy()
283 283
     messageBox = nil
284
-  end  
284
+  end
285 285
 end
286 286
 
287 287
 function HotkeysManager.call(keyCombo)
288
-  if Game.isOnline() then
288
+  if g_game.isOnline() then
289 289
     local hotKey = hotkeyList[keyCombo]
290 290
     if hotKey.itemId == nil and hotKey.value ~= '' then
291 291
       if hotKey.autoSend then
292
-        Game.talk(hotKey.value)
292
+        g_game.talk(hotKey.value)
293 293
       else
294 294
         Console.setLineEditText(hotKey.value)
295 295
       end
296 296
     elseif hotKey.itemId ~= nil then
297 297
       if hotKey.useType == HOTKEY_MANAGER_USEONSELF then
298
-        Game.useInventoryItemWith(hotKey.itemId, Game.getLocalPlayer())
298
+        g_game.useInventoryItemWith(hotKey.itemId, g_game.getLocalPlayer())
299 299
       elseif hotKey.useType == HOTKEY_MANAGER_USEONTARGET then
300
-        local attackingCreature = Game.getLocalPlayer():getAttackingCreature()
300
+        local attackingCreature = g_game.getAttackingCreature()
301 301
         if attackingCreature then
302
-          Game.useInventoryItemWith(hotKey.itemId, attackingCreature)
302
+          g_game.useInventoryItemWith(hotKey.itemId, attackingCreature)
303 303
         end
304
-      elseif hotKey.useType == HOTKEY_MANAGER_USEWITH then      
304
+      elseif hotKey.useType == HOTKEY_MANAGER_USEWITH then
305 305
         itemWidget:setItemId(hotKey.itemId)
306
-        Game.startUseWith(itemWidget:getItem())
307
-      end    
306
+        g_game.startUseWith(itemWidget:getItem())
307
+      end
308 308
     end
309 309
   end
310 310
 end
@@ -312,23 +312,23 @@ end
312 312
 function HotkeysManager.checkSelectedHotkey(focused)
313 313
   if hotkeysManagerLoaded then
314 314
     hotkeyLabelSelectedOnList = focused
315
-    
316
-    if hotkeyLabelSelectedOnList ~= nil then    
315
+
316
+    if hotkeyLabelSelectedOnList ~= nil then
317 317
       removeHotkey:enable()
318 318
 
319 319
       if hotkeyLabelSelectedOnList.itemId == nil then
320 320
         hotkeyText:enable()
321 321
         hotKeyTextLabel:enable()
322 322
         hotkeyText:setText(hotkeyLabelSelectedOnList.value)
323
-        
324
-        if hotkeyLabelSelectedOnList.value ~= '' then      
323
+
324
+        if hotkeyLabelSelectedOnList.value ~= '' then
325 325
           sendAutomatically:enable()
326 326
         else
327 327
           sendAutomatically:disable()
328 328
         end
329
-      
329
+
330 330
         selectObjectButton:enable()
331
-        clearObjectButton:disable()    
331
+        clearObjectButton:disable()
332 332
 
333 333
         currentItemPreview:setItemId(0)
334 334
       else
@@ -336,20 +336,20 @@ function HotkeysManager.checkSelectedHotkey(focused)
336 336
         hotkeyText:disable()
337 337
         hotKeyTextLabel:disable()
338 338
         sendAutomatically:disable()
339
-        
339
+
340 340
         selectObjectButton:disable()
341 341
         clearObjectButton:enable()
342
-        
343
-        currentItemPreview:setItemId(hotkeyLabelSelectedOnList.itemId)     
342
+
343
+        currentItemPreview:setItemId(hotkeyLabelSelectedOnList.itemId)
344 344
       end
345
-      HotkeysManager.changeUseType(hotkeyLabelSelectedOnList.useType)   
345
+      HotkeysManager.changeUseType(hotkeyLabelSelectedOnList.useType)
346 346
     else
347 347
       hotkeyText:clearText()
348 348
       removeHotkey:disable()
349 349
       hotkeyText:disable()
350 350
       sendAutomatically:disable()
351 351
       sendAutomatically:setChecked(false)
352
-      
352
+
353 353
       currentItemPreview:setItemId(0)
354 354
       selectObjectButton:disable()
355 355
       clearObjectButton:disable()
@@ -359,25 +359,25 @@ function HotkeysManager.checkSelectedHotkey(focused)
359 359
       useOnSelf:setChecked(false)
360 360
       useOnTarget:setChecked(false)
361 361
       useWith:setChecked(false)
362
-    end 
363
-  end  
362
+    end
363
+  end
364 364
 end
365 365
 
366 366
 function HotkeysManager.changeUseType(useType, checked)
367 367
   if checked == nil or checked then
368
-    hotkeyLabelSelectedOnList.useType = useType 
368
+    hotkeyLabelSelectedOnList.useType = useType
369 369
     if hotkeyLabelSelectedOnList.itemId ~= nil and currentItemPreview:getItem():isMultiUse() then
370 370
       useOnSelf:enable()
371 371
       useOnTarget:enable()
372 372
       useWith:enable()
373
-      
373
+
374 374
       if useType == HOTKEY_MANAGER_USEONSELF then
375 375
         hotkeyLabelSelectedOnList:setText(hotkeyLabelSelectedOnList.keyCombo .. ': (use object on yourself)')
376 376
         hotkeyLabelSelectedOnList:setColor(hotkeyColors.itemUseSelf)
377 377
         useOnSelf:setChecked(true)
378 378
         useOnTarget:setChecked(false)
379 379
         useWith:setChecked(false)
380
-      elseif useType == HOTKEY_MANAGER_USEONTARGET then  
380
+      elseif useType == HOTKEY_MANAGER_USEONTARGET then
381 381
         hotkeyLabelSelectedOnList:setText(hotkeyLabelSelectedOnList.keyCombo .. ': (use object on target)')
382 382
         hotkeyLabelSelectedOnList:setColor(hotkeyColors.itemUseTarget)
383 383
         useOnSelf:setChecked(false)
@@ -386,7 +386,7 @@ function HotkeysManager.changeUseType(useType, checked)
386 386
       elseif useType == HOTKEY_MANAGER_USEWITH then
387 387
         hotkeyLabelSelectedOnList:setText(hotkeyLabelSelectedOnList.keyCombo .. ': (use object with crosshair)')
388 388
         hotkeyLabelSelectedOnList:setColor(hotkeyColors.itemUseWith)
389
-        
389
+
390 390
         useOnSelf:setChecked(false)
391 391
         useOnTarget:setChecked(false)
392 392
         useWith:setChecked(true)
@@ -395,18 +395,18 @@ function HotkeysManager.changeUseType(useType, checked)
395 395
       useOnSelf:disable()
396 396
       useOnTarget:disable()
397 397
       useWith:disable()
398
-      
398
+
399 399
       hotkeyLabelSelectedOnList:setText(hotkeyLabelSelectedOnList.keyCombo .. ': (use object)')
400 400
       hotkeyLabelSelectedOnList:setColor(hotkeyColors.itemUse)
401
-      
401
+
402 402
       useOnSelf:setChecked(false)
403 403
       useOnTarget:setChecked(false)
404 404
       useWith:setChecked(false)
405
-    else    
405
+    else
406 406
       useOnSelf:disable()
407 407
       useOnTarget:disable()
408 408
       useWith:disable()
409
-      
409
+
410 410
       useOnSelf:setChecked(false)
411 411
       useOnTarget:setChecked(false)
412 412
       useWith:setChecked(false)
@@ -422,11 +422,11 @@ function HotkeysManager.removeHotkey()
422 422
   end
423 423
 end
424 424
 
425
-function HotkeysManager.onHotkeyTextChange(id, value)  
425
+function HotkeysManager.onHotkeyTextChange(id, value)
426 426
   if hotkeyLabelSelectedOnList ~= nil and hotkeyLabelSelectedOnList.keyCombo ~= nil then
427 427
     hotkeyLabelSelectedOnList:setText(hotkeyLabelSelectedOnList.keyCombo .. ': ' .. value)
428 428
     hotkeyLabelSelectedOnList.value = value
429
-    
429
+
430 430
     if value ~= '' then
431 431
       sendAutomatically:enable()
432 432
     else
@@ -452,6 +452,6 @@ function HotkeysManager.hotkeyCapture(widget, keyCode, keyboardModifiers)
452 452
   comboPreview.keyCombo = keyCombo
453 453
   comboPreview:resizeToText()
454 454
   hotkeysWindow:getChildById('assignWindow'):getChildById('addButton'):enable()
455
-  
455
+
456 456
   return true
457 457
 end

+ 2
- 2
modules/game_inventory/inventory.lua View File

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

+ 2
- 2
modules/game_outfit/outfit.lua View File

@@ -175,7 +175,7 @@ function Outfit.destroy()
175 175
 end
176 176
 
177 177
 function Outfit.accept()
178
-  Game.setOutfit(m_outfit)
178
+  g_game.changeOutfit(m_outfit)
179 179
   Outfit.destroy()
180 180
 end
181 181
 
@@ -198,5 +198,5 @@ function Outfit.previousType()
198 198
 end
199 199
 
200 200
 -- hooked events
201
-connect(Game, { onOpenOutfitWindow = Outfit.create,
201
+connect(g_game, { onOpenOutfitWindow = Outfit.create,
202 202
                 onGameEnd = Outfit.destroy })

+ 2
- 2
modules/game_skills/skills.lua View File

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

+ 6
- 6
modules/game_textmessage/textmessage.lua View File

@@ -21,7 +21,7 @@ local centerLabel
21 21
 
22 22
 -- private functions
23 23
 local function displayMessage(msgtype, msg, time)
24
-  if not Game.isOnline() then return end
24
+  if not g_game.isOnline() then return end
25 25
 
26 26
   if msgtype.consoleTab ~= nil then
27 27
     if msgtype.consoleOption == nil or Options[msgtype.consoleOption] then
@@ -30,7 +30,7 @@ local function displayMessage(msgtype, msg, time)
30 30
   end
31 31
 
32 32
   if msgtype.labelId  then
33
-    local label = Game.gameMapPanel:recursiveGetChildById(msgtype.labelId)
33
+    local label = g_game.gameMapPanel:recursiveGetChildById(msgtype.labelId)
34 34
 
35 35
     label:setVisible(true)
36 36
     label:setText(msg)
@@ -66,7 +66,7 @@ end
66 66
 -- public functions
67 67
 
68 68
 function TextMessage.create()
69
-  centerTextMessagePanel = createWidget('Panel', Game.gameMapPanel)
69
+  centerTextMessagePanel = createWidget('Panel', g_game.gameMapPanel)
70 70
   centerTextMessagePanel:setId('centerTextMessagePanel')
71 71
   local layout = UIVerticalLayout.create(centerTextMessagePanel)
72 72
   layout:setFitChildren(true)
@@ -78,7 +78,7 @@ function TextMessage.create()
78 78
   createTextMessageLabel('centerAdvance', centerTextMessagePanel)
79 79
   createTextMessageLabel('centerInfo', centerTextMessagePanel)
80 80
 
81
-  bottomStatusLabel = createTextMessageLabel('bottomStatus', Game.gameMapPanel)
81
+  bottomStatusLabel = createTextMessageLabel('bottomStatus', g_game.gameMapPanel)
82 82
   bottomStatusLabel:setHeight(16)
83 83
   bottomStatusLabel:addAnchor(AnchorBottom, 'parent', AnchorBottom)
84 84
   bottomStatusLabel:addAnchor(AnchorLeft, 'parent', AnchorLeft)
@@ -102,7 +102,7 @@ end
102 102
 
103 103
 -- hooked events
104 104
 local function onGameDeath()
105
-  local advanceLabel = Game.gameMapPanel:recursiveGetChildById('centerAdvance')
105
+  local advanceLabel = g_game.gameMapPanel:recursiveGetChildById('centerAdvance')
106 106
   if advanceLabel:isVisible() then return end
107 107
   TextMessage.displayEventAdvance('You are dead.')
108 108
 end
@@ -111,7 +111,7 @@ local function onGameTextMessage(msgtypedesc, msg)
111 111
   TextMessage.display(msgtypedesc, msg)
112 112
 end
113 113
 
114
-connect(Game, { onGameStart = TextMessage.create,
114
+connect(g_game, { onGameStart = TextMessage.create,
115 115
                 onGameEnd = TextMessage.destroy,
116 116
                 onDeath = onGameDeath,
117 117
                 onTextMessage = onGameTextMessage })

+ 5
- 5
modules/game_viplist/viplist.lua View File

@@ -7,7 +7,7 @@ local addVipWindow
7 7
 
8 8
 -- public functions
9 9
 function VipList.create()
10
-  vipWindow = displayUI('viplist.otui', { parent = Game.gameRightPanel })
10
+  vipWindow = displayUI('viplist.otui', { parent = g_game.gameRightPanel })
11 11
   vipWindow:hide()
12 12
   vipButton = TopMenu.addGameButton('vipListButton', 'VIP list', 'viplist.png', VipList.toggle)
13 13
 end
@@ -35,7 +35,7 @@ function VipList.destroyAddWindow()
35 35
 end
36 36
 
37 37
 function VipList.addVip()
38
-  Game.addVip(addVipWindow:getChildById('name'):getText())
38
+  g_game.addVip(addVipWindow:getChildById('name'):getText())
39 39
   VipList.destroyAddWindow()
40 40
 end
41 41
 
@@ -56,7 +56,7 @@ function VipList.onAddVip(id, name, online)
56 56
   label.vipOnline = online
57 57
 
58 58
   label:setPhantom(false)
59
-  connect(label, { onDoubleClick = function () Game.openPrivateChannel(label:getText()) return true end } )
59
+  connect(label, { onDoubleClick = function () g_game.openPrivateChannel(label:getText()) return true end } )
60 60
 
61 61
   local nameLower = name:lower()
62 62
   local childrenCount = vipList:getChildCount()
@@ -114,7 +114,7 @@ function VipList.onVipListLabelMousePress(widget, mousePos, mouseButton)
114 114
 
115 115
   local menu = createWidget('PopupMenu')
116 116
   menu:addOption('Add new VIP', function() VipList.createAddWindow() end)
117
-  menu:addOption('Remove ' .. widget:getText(), function() if widget then Game.removeVip(widget:getId():sub(4)) vipList:removeChild(widget) end end)
117
+  menu:addOption('Remove ' .. widget:getText(), function() if widget then g_game.removeVip(widget:getId():sub(4)) vipList:removeChild(widget) end end)
118 118
   menu:addSeparator()
119 119
   menu:addOption('Copy Name', function() g_window.setClipboardText(widget:getText()) end)
120 120
   menu:display(mousePos)
@@ -123,7 +123,7 @@ function VipList.onVipListLabelMousePress(widget, mousePos, mouseButton)
123 123
 end
124 124
 
125 125
 
126
-connect(Game, { onGameStart = VipList.create,
126
+connect(g_game, { onGameStart = VipList.create,
127 127
                 onGameEnd = VipList.destroy,
128 128
                 onAddVip = VipList.onAddVip,
129 129
                 onVipStateChange = VipList.onVipStateChange })

+ 6
- 6
modules/otclientrc.lua View File

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

+ 12
- 5
src/otclient/core/creature.h View File

@@ -107,12 +107,19 @@ protected:
107 107
     Outfit m_outfit;
108 108
     Light m_light;
109 109
     int m_speed;
110
-    uint8 m_skull, m_shield, m_emblem;
111
-    TexturePtr m_skullTexture, m_shieldTexture, m_emblemTexture;
112
-    bool m_showShieldTexture, m_shieldBlink;
110
+    uint8 m_skull;
111
+    uint8 m_shield;
112
+    uint8 m_emblem;
113
+    TexturePtr m_skullTexture;
114
+    TexturePtr m_shieldTexture;
115
+    TexturePtr m_emblemTexture;
116
+    bool m_showShieldTexture;
117
+    bool m_shieldBlink;
113 118
     bool m_passable;
114
-    Color m_timedSquareColor, m_staticSquareColor;
115
-    bool m_showTimedSquare, m_showStaticSquare;
119
+    Color m_timedSquareColor;
120
+    Color m_staticSquareColor;
121
+    bool m_showTimedSquare;
122
+    bool m_showStaticSquare;
116 123
 
117 124
     FontPtr m_informationFont;
118 125
     Color m_informationColor;

+ 302
- 148
src/otclient/core/game.cpp View File

@@ -33,99 +33,117 @@
33 33
 
34 34
 Game g_game;
35 35
 
36
-void Game::loginWorld(const std::string& account, const std::string& password, const std::string& worldHost, int worldPort, const std::string& characterName)
36
+Game::Game()
37 37
 {
38
-    m_dead = false;
39
-    m_protocolGame = ProtocolGamePtr(new ProtocolGame);
40
-    m_protocolGame->login(account, password, worldHost, (uint16)worldPort, characterName);
38
+    resetGameStates();
41 39
 }
42 40
 
43
-void Game::cancelLogin()
41
+void Game::resetGameStates()
44 42
 {
45
-    if(m_protocolGame)
46
-        m_protocolGame->sendLogout();
47
-    processLogout();
43
+    m_dead = false;
44
+    m_serverBeat = 50;
45
+    m_fightMode = Otc::FightBalanced;
46
+    m_chaseMode = Otc::DontChase;
47
+    m_safeFight = true;
48
+    m_followingCreature = nullptr;
49
+    m_attackingCreature = nullptr;
48 50
 }
49 51
 
50
-void Game::forceLogout()
52
+void Game::processConnectionError(const boost::system::error_code& error)
51 53
 {
52
-    if(!isOnline())
53
-        return;
54
+    // connection errors only have meaning if we still have a protocol
55
+    if(m_protocolGame) {
56
+        // eof = end of file, a clean disconnect
57
+        if(error != asio::error::eof)
58
+            g_lua.callGlobalField("g_game", "onConnectionError", error.message());
54 59
 
55
-    m_protocolGame->sendLogout();
56
-    processLogout();
60
+        processDisconnect();
61
+    }
57 62
 }
58 63
 
59
-void Game::safeLogout()
64
+void Game::processDisconnect()
60 65
 {
61
-    if(!isOnline())
62
-        return;
66
+    if(isOnline()) {
67
+        // only process logout event if a previous the player is known
68
+        if(m_localPlayer->isKnown())
69
+            processLogout();
63 70
 
64
-    m_protocolGame->sendLogout();
71
+        m_localPlayer = nullptr;
72
+
73
+        processGameEnd();
74
+    }
75
+
76
+    if(m_protocolGame) {
77
+        m_protocolGame->disconnect();
78
+        m_protocolGame = nullptr;
79
+    }
65 80
 }
66 81
 
67 82
 void Game::processLoginError(const std::string& error)
68 83
 {
69
-    g_lua.callGlobalField("Game", "onLoginError", error);
84
+    g_lua.callGlobalField("g_game", "onLoginError", error);
70 85
 }
71 86
 
72
-void Game::processConnectionError(const boost::system::error_code& error)
87
+void Game::processLoginAdvice(const std::string& message)
73 88
 {
74
-    // connection errors only have meaning if we still have a protocol
75
-    if(m_protocolGame) {
76
-        if(error != asio::error::eof)
77
-            g_lua.callGlobalField("Game", "onConnectionError", error.message());
89
+    g_lua.callGlobalField("Game," "onLoginAdvice", message);
90
+}
78 91
 
79
-        processLogout();
80
-    }
92
+void Game::processLoginWait(const std::string& message, int time)
93
+{
94
+    g_lua.callGlobalField("g_game", "onLoginWait", message, time);
81 95
 }
82 96
 
83 97
 void Game::processGameStart(const LocalPlayerPtr& localPlayer, int serverBeat)
84 98
 {
99
+    // reset the new game state
100
+    resetGameStates();
101
+
85 102
     m_localPlayer = localPlayer;
86 103
     m_serverBeat = serverBeat;
87 104
 
88 105
     // synchronize fight modes with the server
89
-    m_fightMode = Otc::FightBalanced;
90
-    m_chaseMode = Otc::DontChase;
91
-    m_safeFight = true;
92
-    m_protocolGame->sendFightTatics(m_fightMode, m_chaseMode, m_safeFight);
106
+    m_protocolGame->sendChangeFightModes(m_fightMode, m_chaseMode, m_safeFight);
93 107
 
94 108
     // NOTE: the entire map description and local player informations is not known yet
95
-    g_lua.callGlobalField("Game", "onGameStart");
109
+    g_lua.callGlobalField("g_game", "onGameStart");
110
+}
111
+
112
+void Game::processGameEnd()
113
+{
114
+    g_lua.callGlobalField("g_game", "onGameEnd");
115
+
116
+    // reset game states
117
+    resetGameStates();
96 118
 }
97 119
 
98 120
 void Game::processLogin()
99 121
 {
122
+    // the game could be offline if the login was canceled
100 123
     if(!isOnline())
101 124
         return;
102 125
 
103
-    g_lua.callGlobalField("Game", "onLogin", m_localPlayer);
126
+    // by now the local player must be known
127
+    g_lua.callGlobalField("g_game", "onLogin", m_localPlayer);
104 128
 }
105 129
 
106 130
 void Game::processLogout()
107 131
 {
108
-    if(isOnline()) {
109
-        g_lua.callGlobalField("Game", "onLogout", m_localPlayer);
110
-
111
-        m_localPlayer = nullptr;
112
-
113
-        g_lua.callGlobalField("Game", "onGameEnd");
114
-    }
115
-
116
-    if(m_protocolGame) {
117
-        m_protocolGame->disconnect();
118
-        m_protocolGame = nullptr;
119
-    }
120
-
121
-    //g_map.save();
132
+    g_lua.callGlobalField("g_game", "onLogout", m_localPlayer);
122 133
 }
123 134
 
124
-void Game::processDeath()
135
+void Game::processDeath(int penality)
125 136
 {
126 137
     m_dead = true;
127 138
     m_localPlayer->stopWalk();
128
-    g_lua.callGlobalField("Game","onDeath");
139
+
140
+    g_lua.callGlobalField("g_game","onDeath", penality);
141
+}
142
+
143
+void Game::processPing()
144
+{
145
+    m_protocolGame->sendPingResponse();
146
+    g_lua.callGlobalField("g_game", "onPing");
129 147
 }
130 148
 
131 149
 void Game::processPlayerStats(double health, double maxHealth,
@@ -139,7 +157,7 @@ void Game::processPlayerStats(double health, double maxHealth,
139 157
        m_localPlayer->getMaxHealth() != maxHealth) {
140 158
         m_localPlayer->setStatistic(Otc::Health, health);
141 159
         m_localPlayer->setStatistic(Otc::MaxHealth, maxHealth);
142
-        g_lua.callGlobalField("Game", "onHealthChange", health, maxHealth);
160
+        g_lua.callGlobalField("g_game", "onHealthChange", health, maxHealth);
143 161
 
144 162
         // cannot walk while dying
145 163
         if(health == 0) {
@@ -151,49 +169,49 @@ void Game::processPlayerStats(double health, double maxHealth,
151 169
 
152 170
     if(m_localPlayer->getStatistic(Otc::FreeCapacity) != freeCapacity) {
153 171
         m_localPlayer->setStatistic(Otc::FreeCapacity, freeCapacity);
154
-        g_lua.callGlobalField("Game", "onFreeCapacityChange", freeCapacity);
172
+        g_lua.callGlobalField("g_game", "onFreeCapacityChange", freeCapacity);
155 173
     }
156 174
 
157 175
     if(m_localPlayer->getStatistic(Otc::Experience) != experience) {
158 176
         m_localPlayer->setStatistic(Otc::Experience, experience);
159
-        g_lua.callGlobalField("Game", "onExperienceChange", experience);
177
+        g_lua.callGlobalField("g_game", "onExperienceChange", experience);
160 178
     }
161 179
 
162 180
     if(m_localPlayer->getStatistic(Otc::Level) != level ||
163 181
        m_localPlayer->getStatistic(Otc::LevelPercent) != levelPercent) {
164 182
         m_localPlayer->setStatistic(Otc::Level, level);
165 183
         m_localPlayer->setStatistic(Otc::LevelPercent, levelPercent);
166
-        g_lua.callGlobalField("Game", "onLevelChange", level, levelPercent);
184
+        g_lua.callGlobalField("g_game", "onLevelChange", level, levelPercent);
167 185
     }
168 186
 
169 187
     if(m_localPlayer->getStatistic(Otc::Mana) != mana ||
170 188
        m_localPlayer->getStatistic(Otc::MaxMana) != maxMana) {
171 189
         m_localPlayer->setStatistic(Otc::Mana, mana);
172 190
         m_localPlayer->setStatistic(Otc::MaxMana, maxMana);
173
-        g_lua.callGlobalField("Game", "onManaChange", mana, maxMana);
191
+        g_lua.callGlobalField("g_game", "onManaChange", mana, maxMana);
174 192
     }
175 193
 
176 194
     if(m_localPlayer->getStatistic(Otc::MagicLevel) != magicLevel ||
177 195
        m_localPlayer->getStatistic(Otc::MagicLevelPercent) != magicLevelPercent) {
178 196
         m_localPlayer->setStatistic(Otc::MagicLevel, magicLevel);
179 197
         m_localPlayer->setStatistic(Otc::MagicLevelPercent, magicLevelPercent);
180
-        g_lua.callGlobalField("Game", "onMagicLevelChange", magicLevel, magicLevelPercent);
198
+        g_lua.callGlobalField("g_game", "onMagicLevelChange", magicLevel, magicLevelPercent);
181 199
     }
182 200
 
183 201
     if(m_localPlayer->getStatistic(Otc::Soul) != soul) {
184 202
         m_localPlayer->setStatistic(Otc::Soul, soul);
185
-        g_lua.callGlobalField("Game", "onSoulChange", soul);
203
+        g_lua.callGlobalField("g_game", "onSoulChange", soul);
186 204
     }
187 205
 
188 206
     if(m_localPlayer->getStatistic(Otc::Stamina) != stamina) {
189 207
         m_localPlayer->setStatistic(Otc::Stamina, stamina);
190
-        g_lua.callGlobalField("Game", "onStaminaChange", stamina);
208
+        g_lua.callGlobalField("g_game", "onStaminaChange", stamina);
191 209
     }
192 210
 }
193 211
 
194 212
 void Game::processTextMessage(const std::string& type, const std::string& message)
195 213
 {
196
-    g_lua.callGlobalField("Game","onTextMessage", type, message);
214
+    g_lua.callGlobalField("g_game","onTextMessage", type, message);
197 215
 }
198 216
 
199 217
 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
204 222
         g_map.addThing(staticText, creaturePos);
205 223
     }
206 224
 
207
-    g_lua.callGlobalField("Game", "onCreatureSpeak", name, level, type, message, channelId, creaturePos);
225
+    g_lua.callGlobalField("g_game", "onCreatureSpeak", name, level, type, message, channelId, creaturePos);
226
+}
227
+
228
+void Game::processOpenContainer(int containerId, int itemId, const std::string& name, int capacity, bool hasParent, const std::vector< ItemPtr >& items)
229
+{
230
+    g_lua.callGlobalField("g_game", "onOpenContainer", containerId, itemId, name, capacity, hasParent, items);
208 231
 }
209 232
 
210 233
 void Game::processContainerAddItem(int containerId, const ItemPtr& item)
@@ -212,7 +235,7 @@ void Game::processContainerAddItem(int containerId, const ItemPtr& item)
212 235
     if(item)
213 236
         item->setPosition(Position(65535, containerId + 0x40, 0));
214 237
 
215
-    g_lua.callGlobalField("Game", "onContainerAddItem", containerId, item);
238
+    g_lua.callGlobalField("g_game", "onContainerAddItem", containerId, item);
216 239
 }
217 240
 
218 241
 void Game::processInventoryChange(int slot, const ItemPtr& item)
@@ -220,7 +243,7 @@ void Game::processInventoryChange(int slot, const ItemPtr& item)
220 243
     if(item)
221 244
         item->setPosition(Position(65535, slot, 0));
222 245
 
223
-    g_lua.callGlobalField("Game","onInventoryChange", slot, item);
246
+    g_lua.callGlobalField("g_game","onInventoryChange", slot, item);
224 247
 }
225 248
 
226 249
 void Game::processCreatureMove(const CreaturePtr& creature, const Position& oldPos, const Position& newPos)
@@ -235,14 +258,15 @@ void Game::processCreatureTeleport(const CreaturePtr& creature)
235 258
     // stop walking on creature teleports
236 259
     creature->stopWalk();
237 260
 
261
+    // locks the walk for a while when teleporting
238 262
     if(creature == m_localPlayer)
239 263
         m_localPlayer->lockWalk();
240 264
 }
241 265
 
242 266
 void Game::processAttackCancel()
243 267
 {
244
-    if(m_localPlayer->isAttacking())
245
-        m_localPlayer->setAttackingCreature(nullptr);
268
+    if(isAttacking())
269
+        setAttackingCreature(nullptr);
246 270
 }
247 271
 
248 272
 void Game::processWalkCancel(Otc::Direction direction)
@@ -250,12 +274,44 @@ void Game::processWalkCancel(Otc::Direction direction)
250 274
     m_localPlayer->cancelWalk(direction);
251 275
 }
252 276
 
277
+void Game::loginWorld(const std::string& account, const std::string& password, const std::string& worldHost, int worldPort, const std::string& characterName)
278
+{
279
+    m_protocolGame = ProtocolGamePtr(new ProtocolGame);
280
+    m_protocolGame->login(account, password, worldHost, (uint16)worldPort, characterName);
281
+}
282
+
283
+void Game::cancelLogin()
284
+{
285
+    // send logout even if the game has not started yet, to make sure that the player doesn't stay logged there
286
+    if(m_protocolGame)
287
+        m_protocolGame->sendLogout();
288
+
289
+    processDisconnect();
290
+}
291
+
292
+void Game::forceLogout()
293
+{
294
+    if(!isOnline())
295
+        return;
296
+
297
+    m_protocolGame->sendLogout();
298
+    processDisconnect();
299
+}
300
+
301
+void Game::safeLogout()
302
+{
303
+    if(!isOnline())
304
+        return;
305
+
306
+    m_protocolGame->sendLogout();
307
+}
308
+
253 309
 void Game::walk(Otc::Direction direction)
254 310
 {
255
-    if(!isOnline() || !m_localPlayer->isKnown() || isDead() || !checkBotProtection())
311
+    if(!canPerformGameAction())
256 312
         return;
257 313
 
258
-    if(m_localPlayer->isFollowing())
314
+    if(isFollowing())
259 315
         cancelFollow();
260 316
 
261 317
     if(!m_localPlayer->canWalk(direction))
@@ -271,9 +327,20 @@ void Game::walk(Otc::Direction direction)
271 327
     forceWalk(direction);
272 328
 }
273 329
 
330
+void Game::walkPath(const std::vector<Otc::Direction>& dir)
331
+{
332
+    if(!canPerformGameAction())
333
+        return;
334
+
335
+    if(isFollowing())
336
+        cancelFollow();
337
+
338
+    m_protocolGame->sendWalkPath(dir);
339
+}
340
+
274 341
 void Game::forceWalk(Otc::Direction direction)
275 342
 {
276
-    if(!isOnline() || !checkBotProtection())
343
+    if(!canPerformGameAction())
277 344
         return;
278 345
 
279 346
     switch(direction) {
@@ -306,7 +373,7 @@ void Game::forceWalk(Otc::Direction direction)
306 373
 
307 374
 void Game::turn(Otc::Direction direction)
308 375
 {
309
-    if(!isOnline())
376
+    if(!canPerformGameAction())
310 377
         return;
311 378
 
312 379
     switch(direction) {
@@ -325,25 +392,46 @@ void Game::turn(Otc::Direction direction)
325 392
     }
326 393
 }
327 394
 
395
+void Game::stop()
396
+{
397
+    if(!canPerformGameAction())
398
+        return;
399
+
400
+    if(isFollowing())
401
+        cancelFollow();
402
+
403
+    m_protocolGame->sendStop();
404
+}
405
+
328 406
 void Game::look(const ThingPtr& thing)
329 407
 {
330
-    if(!isOnline() || !thing || !checkBotProtection())
408
+    if(!canPerformGameAction() || !thing)
331 409
         return;
332 410
 
333
-    m_protocolGame->sendLookAt(thing->getPosition(), thing->getId(), thing->getStackpos());
411
+    m_protocolGame->sendLook(thing->getPosition(), thing->getId(), thing->getStackpos());
334 412
 }
335 413
 
336
-void Game::open(const ItemPtr& item, int containerId)
414
+void Game::move(const ThingPtr& thing, const Position& toPos, int count)
337 415
 {
338
-    if(!isOnline() || !item || !checkBotProtection())
416
+    if(!canPerformGameAction() || !thing || thing->getPosition() == toPos || count <= 0)
339 417
         return;
340 418
 
341
-    m_protocolGame->sendUseItem(item->getPosition(), item->getId(), item->getStackpos(), containerId);
419
+    m_localPlayer->lockWalk();
420
+
421
+    m_protocolGame->sendMove(thing->getPosition(), thing->getId(), thing->getStackpos(), toPos, count);
422
+}
423
+
424
+void Game::rotate(const ThingPtr& thing)
425
+{
426
+    if(!canPerformGameAction() || !thing)
427
+        return;
428
+
429
+    m_protocolGame->sendRotateItem(thing->getPosition(), thing->getId(), thing->getStackpos());
342 430
 }
343 431
 
344 432
 void Game::use(const ThingPtr& thing)
345 433
 {
346
-    if(!isOnline() || !thing || !checkBotProtection())
434
+    if(!canPerformGameAction() || !thing)
347 435
         return;
348 436
 
349 437
     Position pos = thing->getPosition();
@@ -357,7 +445,7 @@ void Game::use(const ThingPtr& thing)
357 445
 
358 446
 void Game::useInventoryItem(int itemId)
359 447
 {
360
-    if(!isOnline() || !checkBotProtection())
448
+    if(!canPerformGameAction() || !g_thingsType.isValidItemId(itemId))
361 449
         return;
362 450
 
363 451
     Position pos = Position(0xFFFF, 0, 0); // means that is a item in inventory
@@ -368,7 +456,7 @@ void Game::useInventoryItem(int itemId)
368 456
 
369 457
 void Game::useWith(const ItemPtr& item, const ThingPtr& toThing)
370 458
 {
371
-    if(!isOnline() || !item || !toThing || !checkBotProtection())
459
+    if(!canPerformGameAction() || !item || !toThing)
372 460
         return;
373 461
 
374 462
     Position pos = item->getPosition();
@@ -380,12 +468,12 @@ void Game::useWith(const ItemPtr& item, const ThingPtr& toThing)
380 468
     if(CreaturePtr creature = toThing->asCreature())
381 469
         m_protocolGame->sendUseOnCreature(pos, item->getId(), item->getStackpos(), creature->getId());
382 470
     else
383
-        m_protocolGame->sendUseItemEx(pos, item->getId(), item->getStackpos(), toThing->getPosition(), toThing->getId(), toThing->getStackpos());
471
+        m_protocolGame->sendUseItemWith(pos, item->getId(), item->getStackpos(), toThing->getPosition(), toThing->getId(), toThing->getStackpos());
384 472
 }
385 473
 
386 474
 void Game::useInventoryItemWith(int itemId, const ThingPtr& toThing)
387 475
 {
388
-    if(!isOnline() || !toThing || !checkBotProtection())
476
+    if(!canPerformGameAction() || !toThing)
389 477
         return;
390 478
 
391 479
     m_localPlayer->lockWalk();
@@ -395,212 +483,207 @@ void Game::useInventoryItemWith(int itemId, const ThingPtr& toThing)
395 483
     if(CreaturePtr creature = toThing->asCreature())
396 484
         m_protocolGame->sendUseOnCreature(pos, itemId, 0, creature->getId());
397 485
     else
398
-        m_protocolGame->sendUseItemEx(pos, itemId, 0, toThing->getPosition(), toThing->getId(), toThing->getStackpos());
486
+        m_protocolGame->sendUseItemWith(pos, itemId, 0, toThing->getPosition(), toThing->getId(), toThing->getStackpos());
399 487
 }
400 488
 
401
-void Game::move(const ThingPtr& thing, const Position& toPos, int count)
489
+void Game::open(const ItemPtr& item, int containerId)
402 490
 {
403
-    if(!isOnline() || !thing || !checkBotProtection() || thing->getPosition() == toPos || count <= 0)
491
+    if(!canPerformGameAction() || !item)
404 492
         return;
405 493
 
406
-    m_localPlayer->lockWalk();
407
-
408
-    m_protocolGame->sendThrow(thing->getPosition(), thing->getId(), thing->getStackpos(), toPos, count);
494
+    m_protocolGame->sendUseItem(item->getPosition(), item->getId(), item->getStackpos(), containerId);
409 495
 }
410 496
 
411
-void Game::setChaseMode(Otc::ChaseModes chaseMode)
497
+void Game::upContainer(int containerId)
412 498
 {
413
-    if(!isOnline() || !checkBotProtection())
499
+    if(!canPerformGameAction())
414 500
         return;
415
-
416
-    m_chaseMode = chaseMode;
417
-    m_protocolGame->sendFightTatics(m_fightMode, m_chaseMode, m_safeFight);
501
+    m_protocolGame->sendUpContainer(containerId);
418 502
 }
419 503
 
420
-void Game::setFightMode(Otc::FightModes fightMode)
504
+void Game::refreshContainer()
421 505
 {
422
-    if(!isOnline() || !checkBotProtection())
506
+    if(!canPerformGameAction())
423 507
         return;
424
-
425
-    m_fightMode = fightMode;
426
-    m_protocolGame->sendFightTatics(m_fightMode, m_chaseMode, m_safeFight);
427
-}
428
-
429
-void Game::setSafeFight(bool on)
430
-{
431
-    if(!isOnline() || !checkBotProtection())
432
-        return;
433
-
434
-    m_safeFight = on;
435
-    m_protocolGame->sendFightTatics(m_fightMode, m_chaseMode, m_safeFight);
508
+    m_protocolGame->sendRefreshContainer();
436 509
 }
437 510
 
438 511
 void Game::attack(const CreaturePtr& creature)
439 512
 {
440
-    if(!isOnline() || !creature || !checkBotProtection())
513
+    if(!canPerformGameAction() || creature == m_localPlayer || creature == m_attackingCreature)
441 514
         return;
442 515
 
443 516
     m_localPlayer->lockWalk();
444 517
 
445
-    if(m_localPlayer->isFollowing())
518
+    if(creature && isFollowing())
446 519
         cancelFollow();
447 520
 
448
-    m_localPlayer->setAttackingCreature(creature);
449
-    m_protocolGame->sendAttack(creature->getId());
450
-}
451
-
452
-void Game::cancelAttack()
453
-{
454
-    m_localPlayer->lockWalk();
455
-
456
-    m_localPlayer->setAttackingCreature(nullptr);
457
-    m_protocolGame->sendAttack(0);
521
+    setAttackingCreature(creature);
522
+    m_protocolGame->sendAttack(creature ? creature->getId() : 0);
458 523
 }
459 524
 
460 525
 void Game::follow(const CreaturePtr& creature)
461 526
 {
462
-    if(!isOnline() || !creature || !checkBotProtection())
527
+    if(!canPerformGameAction() || creature == m_localPlayer || creature == m_followingCreature)
463 528
         return;
464 529
 
465
-    if(m_localPlayer->isAttacking())
530
+    m_localPlayer->lockWalk();
531
+
532
+    if(creature && isAttacking())
466 533
         cancelAttack();
467 534
 
468
-    m_localPlayer->setFollowingCreature(creature);
469
-    m_protocolGame->sendFollow(creature->getId());
535
+    setFollowingCreature(creature);
536
+    m_protocolGame->sendFollow(creature ? creature->getId() : 0);
470 537
 }
471 538
 
472
-void Game::cancelFollow()
539
+void Game::cancelAttackAndFollow()
473 540
 {
474
-    if(!isOnline() || !checkBotProtection())
541
+    if(!canPerformGameAction())
475 542
         return;
476 543
 
477
-    m_localPlayer->setFollowingCreature(nullptr);
478
-    m_protocolGame->sendFollow(0);
479
-}
480
-
481
-void Game::rotate(const ThingPtr& thing)
482
-{
483
-    if(!isOnline() || !thing || !checkBotProtection())
484
-        return;
544
+    m_localPlayer->lockWalk();
485 545
 
486
-    m_protocolGame->sendRotateItem(thing->getPosition(), thing->getId(), thing->getStackpos());
546
+    setAttackingCreature(nullptr);
547
+    setFollowingCreature(nullptr);
548
+    m_protocolGame->sendCancelAttackAndFollow();
487 549
 }
488 550
 
489 551
 void Game::talk(const std::string& message)
490 552
 {
553
+    if(!canPerformGameAction() || message.empty())
554
+        return;
491 555
     talkChannel(Otc::SpeakSay, 0, message);
492 556
 }
493 557
 
494 558
 void Game::talkChannel(Otc::SpeakType speakType, int channelId, const std::string& message)
495 559
 {
496
-    if(!isOnline() || !checkBotProtection())
560
+    if(!canPerformGameAction() || message.empty())
497 561
         return;
498 562
     m_protocolGame->sendTalk(speakType, channelId, "", message);
499 563
 }
500 564
 
501 565
 void Game::talkPrivate(Otc::SpeakType speakType, const std::string& receiver, const std::string& message)
502 566
 {
503
-    if(!isOnline() || !checkBotProtection())
567
+    if(!canPerformGameAction() || receiver.empty() || message.empty())
504 568
         return;
505 569
     m_protocolGame->sendTalk(speakType, 0, receiver, message);
506 570
 }
507 571
 
508 572
 void Game::openPrivateChannel(const std::string& receiver)
509 573
 {
510
-    if(!isOnline() || !checkBotProtection())
574
+    if(!canPerformGameAction() || receiver.empty())
511 575
         return;
512 576
     m_protocolGame->sendOpenPrivateChannel(receiver);
513 577
 }
514 578
 
515 579
 void Game::requestChannels()
516 580
 {
517
-    if(!isOnline() || !checkBotProtection())
581
+    if(!canPerformGameAction())
518 582
         return;
519
-    m_protocolGame->sendGetChannels();
583
+    m_protocolGame->sendRequestChannels();
520 584
 }
521 585
 
522 586
 void Game::joinChannel(int channelId)
523 587
 {
524
-    if(!isOnline() || !checkBotProtection())
588
+    if(!canPerformGameAction())
525 589
         return;
526 590
     m_protocolGame->sendJoinChannel(channelId);
527 591
 }
528 592
 
529 593
 void Game::leaveChannel(int channelId)
530 594
 {
531
-    if(!isOnline() || !checkBotProtection())
595
+    if(!canPerformGameAction())
532 596
         return;
533 597
     m_protocolGame->sendLeaveChannel(channelId);
534 598
 }
535 599
 
536 600
 void Game::closeNpcChannel()
537 601
 {
538
-    if(!isOnline() || !checkBotProtection())
602
+    if(!canPerformGameAction())
539 603
         return;
540 604
     m_protocolGame->sendCloseNpcChannel();
541 605
 }
542 606
 
607
+void Game::openOwnChannel()
608
+{
609
+    if(!canPerformGameAction())
610
+        return;
611
+    m_protocolGame->sendOpenOwnChannel();
612
+}
613
+
614
+void Game::inviteToOwnChannel(const std::string& name)
615
+{
616
+    if(!canPerformGameAction() || name.empty())
617
+        return;
618
+    m_protocolGame->sendInviteToOwnChannel(name);
619
+}
620
+
621
+void Game::excludeFromOwnChannel(const std::string& name)
622
+{
623
+    if(!canPerformGameAction() || name.empty())
624
+        return;
625
+    m_protocolGame->sendExcludeFromOwnChannel(name);
626
+}
543 627
 
544 628
 void Game::partyInvite(int creatureId)
545 629
 {
546
-    if(!isOnline() || !checkBotProtection())
630
+    if(!canPerformGameAction())
547 631
         return;
548 632
     m_protocolGame->sendInviteToParty(creatureId);
549 633
 }
550 634
 
551 635
 void Game::partyJoin(int creatureId)
552 636
 {
553
-    if(!isOnline() || !checkBotProtection())
637
+    if(!canPerformGameAction())
554 638
         return;
555 639
     m_protocolGame->sendJoinParty(creatureId);
556 640
 }
557 641
 
558 642
 void Game::partyRevokeInvitation(int creatureId)
559 643
 {
560
-    if(!isOnline() || !checkBotProtection())
644
+    if(!canPerformGameAction())
561 645
         return;
562 646
     m_protocolGame->sendRevokeInvitation(creatureId);
563 647
 }
564 648
 
565
-
566 649
 void Game::partyPassLeadership(int creatureId)
567 650
 {
568
-    if(!isOnline() || !checkBotProtection())
651
+    if(!canPerformGameAction())
569 652
         return;
570 653
     m_protocolGame->sendPassLeadership(creatureId);
571 654
 }
572 655
 
573 656
 void Game::partyLeave()
574 657
 {
575
-    if(!isOnline() || !checkBotProtection())
658
+    if(!canPerformGameAction())
576 659
         return;
577 660
     m_protocolGame->sendLeaveParty();
578 661
 }
579 662
 
580 663
 void Game::partyShareExperience(bool active)
581 664
 {
582
-    if(!isOnline() || !checkBotProtection())
665
+    if(!canPerformGameAction())
583 666
         return;
584 667
     m_protocolGame->sendShareExperience(active, 0);
585 668
 }
586 669
 
587 670
 void Game::requestOutfit()
588 671
 {
589
-    if(!isOnline() || !checkBotProtection())
672
+    if(!canPerformGameAction())
590 673
         return;
591
-    m_protocolGame->sendGetOutfit();
674
+    m_protocolGame->sendRequestOutfit();
592 675
 }
593 676
 
594
-void Game::setOutfit(const Outfit& outfit)
677
+void Game::changeOutfit(const Outfit& outfit)
595 678
 {
596
-    if(!isOnline() || !checkBotProtection())
679
+    if(!canPerformGameAction())
597 680
         return;
598
-    m_protocolGame->sendSetOutfit(outfit);
681
+    m_protocolGame->sendChangeOutfit(outfit);
599 682
 }
600 683
 
601 684
 void Game::addVip(const std::string& name)
602 685
 {
603
-    if(!isOnline() || name.empty() || !checkBotProtection())
686
+    if(!canPerformGameAction() || name.empty())
604 687
         return;
605 688
     m_protocolGame->sendAddVip(name);
606 689
 }
@@ -612,9 +695,38 @@ void Game::removeVip(int playerId)
612 695
     m_protocolGame->sendRemoveVip(playerId);
613 696
 }
614 697
 
698
+void Game::setChaseMode(Otc::ChaseModes chaseMode)
699
+{
700
+    if(!canPerformGameAction())
701
+        return;
702
+
703
+    m_chaseMode = chaseMode;
704
+    m_protocolGame->sendChangeFightModes(m_fightMode, m_chaseMode, m_safeFight);
705
+}
706
+
707
+void Game::setFightMode(Otc::FightModes fightMode)
708
+{
709
+    if(!canPerformGameAction())
710
+        return;
711
+
712
+    m_fightMode = fightMode;
713
+    m_protocolGame->sendChangeFightModes(m_fightMode, m_chaseMode, m_safeFight);
714
+}
715
+
716
+void Game::setSafeFight(bool on)
717
+{
718
+    if(!canPerformGameAction())
719
+        return;
720
+
721
+    m_safeFight = on;
722
+    m_protocolGame->sendChangeFightModes(m_fightMode, m_chaseMode, m_safeFight);
723
+}
724
+
615 725
 bool Game::checkBotProtection()
616 726
 {
617 727
 #ifdef BOT_PROTECTION
728
+    // accepts calls comming from a stacktrace containing only C++ functions,
729
+    // if the stacktrace contains a lua function, then only accept if the engine is processing an input event
618 730
     if(g_lua.isInCppCallback() && !g_ui.isOnInputEvent()) {
619 731
         logError("caught a lua call to a bot protected game function, the call was canceled");
620 732
         return false;
@@ -622,3 +734,45 @@ bool Game::checkBotProtection()
622 734
 #endif
623 735
     return true;
624 736
 }
737
+
738
+bool Game::canPerformGameAction()
739
+{
740
+    // we can only perform game actions if we meet these conditions:
741
+    // - the local player exists
742
+    // - the local player is known
743
+    // - the local player is not dead
744
+    // - we have a game protocol
745
+    // - the game protocol is connected
746
+    // - its not a bot action
747
+    return m_localPlayer && m_localPlayer->isKnown() && !m_dead && m_protocolGame && m_protocolGame->isConnected() && checkBotProtection();
748
+}
749
+
750
+void Game::setAttackingCreature(const CreaturePtr& creature)
751
+{
752
+    if(m_attackingCreature) {
753
+        m_attackingCreature->hideStaticSquare();
754
+        m_attackingCreature = nullptr;
755
+    }
756
+
757
+    if(creature) {
758
+        creature->showStaticSquare(Fw::red);
759
+        m_attackingCreature = creature;
760
+    }
761
+
762
+    g_lua.callGlobalField("g_game", "onAttackingCreatureChange", creature);
763
+}
764
+
765
+void Game::setFollowingCreature(const CreaturePtr& creature)
766
+{
767
+    if(m_followingCreature) {
768
+        m_followingCreature->hideStaticSquare();
769
+        m_followingCreature = nullptr;
770
+    }
771
+
772
+    if(creature) {
773
+        creature->showStaticSquare(Fw::green);
774
+        m_followingCreature = creature;
775
+    }
776
+
777
+    g_lua.callGlobalField("g_game", "onFollowingCreatureChange", creature);
778
+}

+ 162
- 27
src/otclient/core/game.h View File

@@ -32,20 +32,87 @@
32 32
 class Game
33 33
 {
34 34
 public:
35
-    void loginWorld(const std::string& account,
36
-                    const std::string& password,
37
-                    const std::string& worldHost, int worldPort,
38
-                    const std::string& characterName);
39
-    void cancelLogin();
40
-    void logout(bool force);
41
-    void forceLogout();
42
-    void safeLogout();
43
-    void processLoginError(const std::string& error);
35
+    Game();
36
+
37
+private:
38
+    void resetGameStates();
39
+
40
+protected:
41
+
42
+    /*
43
+    void parseMapDescription(InputMessage& msg);
44
+    void parseMapMoveNorth(InputMessage& msg);
45
+    void parseMapMoveEast(InputMessage& msg);
46
+    void parseMapMoveSouth(InputMessage& msg);
47
+    void parseMapMoveWest(InputMessage& msg);
48
+    void parseUpdateTile(InputMessage& msg);
49
+    void parseTileAddThing(InputMessage& msg);
50
+    void parseTileTransformThing(InputMessage& msg);
51
+    void parseTileRemoveThing(InputMessage& msg);
52
+    void parseCreatureMove(InputMessage& msg);
53
+
54
+    void parseOpenContainer(InputMessage& msg);
55
+    void parseCloseContainer(InputMessage& msg);
56
+    void parseContainerAddItem(InputMessage& msg);
57
+    void parseContainerUpdateItem(InputMessage& msg);
58
+    void parseContainerRemoveItem(InputMessage& msg);
59
+
60
+    void parseAddInventoryItem(InputMessage& msg);
61
+    void parseRemoveInventoryItem(InputMessage& msg);
62
+
63
+    void parseNpcOffer(InputMessage& msg);
64
+    void parsePlayerCash(InputMessage& msg);
65
+    void parseCloseShopWindow(InputMessage&);
66
+
67
+    void parseWorldLight(InputMessage& msg);
68
+
69
+    void parseMagicEffect(InputMessage& msg);
70
+    void parseAnimatedText(InputMessage& msg);
71
+    void parseDistanceMissile(InputMessage& msg);
72
+
73
+    void parseCreatureSquare(InputMessage& msg);
74
+    void parseCreatureHealth(InputMessage& msg);
75
+    void parseCreatureLight(InputMessage& msg);
76
+    void parseCreatureOutfit(InputMessage& msg);
77
+    void parseCreatureSpeed(InputMessage& msg);
78
+    void parseCreatureSkulls(InputMessage& msg);
79
+    void parseCreatureShields(InputMessage& msg);
80
+    void parseCreatureTurn(InputMessage& msg);
81
+
82
+    void parseItemTextWindow(InputMessage& msg);
83
+    void parseHouseTextWindow(InputMessage& msg);
84
+    void parsePlayerStats(InputMessage& msg);
85
+    void parsePlayerSkills(InputMessage& msg);
86
+    void parsePlayerIcons(InputMessage& msg);
87
+    void parsePlayerCancelAttack(InputMessage& msg);
88
+    void parseCreatureSpeak(InputMessage& msg);
89
+    void parseCloseChannel(InputMessage& msg);
90
+    void parseSafeTradeRequest(InputMessage& msg);
91
+    void parseSafeTradeClose(InputMessage&);
92
+    void parseTextMessage(InputMessage& msg);
93
+    void parseCancelWalk(InputMessage& msg);
94
+    void parseFloorChangeUp(InputMessage& msg);
95
+    void parseFloorChangeDown(InputMessage& msg);
96
+    void parseOutfitWindow(InputMessage& msg);
97
+    void parseShowTutorial(InputMessage& msg);
98
+    void parseAddMarker(InputMessage& msg);
99
+    */
100
+
44 101
     void processConnectionError(const boost::system::error_code& error);
45
-    void processGameStart(const LocalPlayerPtr& localPlayer, int serverBeat);
102
+    void processDisconnect();
103
+    void processPing();
104
+
105
+    void processLoginError(const std::string& error);
106
+    void processLoginAdvice(const std::string& message);
107
+    void processLoginWait(const std::string& message, int time);
108
+
46 109
     void processLogin();
47 110
     void processLogout();
48
-    void processDeath();
111
+
112
+    void processGameStart(const LocalPlayerPtr& localPlayer, int serverBeat);
113
+    void processGameEnd();
114
+    void processDeath(int penality);
115
+
49 116
     void processPlayerStats(double health, double maxHealth,
50 117
                             double freeCapacity, double experience,
51 118
                             double level, double levelPercent,
@@ -54,51 +121,84 @@ public:
54 121
                             double soul, double stamina);
55 122
     void processTextMessage(const std::string& type, const std::string& message);
56 123
     void processCreatureSpeak(const std::string& name, int level, Otc::SpeakType type, const std::string& message, int channelId, const Position& creaturePos);
124
+
125
+    void processOpenContainer(int containerId, int itemId, const std::string& name, int capacity, bool hasParent, const std::vector<ItemPtr>& items);
57 126
     void processContainerAddItem(int containerId, const ItemPtr& item);
127
+
58 128
     void processInventoryChange(int slot, const ItemPtr& item);
59 129
     void processCreatureMove(const CreaturePtr& creature, const Position& oldPos, const Position& newPos);
60 130
     void processCreatureTeleport(const CreaturePtr& creature);
61 131
     void processAttackCancel();
62 132
     void processWalkCancel(Otc::Direction direction);
63 133
 
134
+    // processChannelList
135
+    // processOpenChannel
136
+    // processOpenPrivateChannel
137
+    // processOpenOwnPrivateChannel
138
+
139
+    // vip
140
+    // processVipList
141
+    // processVipLogin
142
+    // processVipLogout
143
+
144
+    // processQuestLog
145
+    // processQuestLine
146
+
147
+    friend class ProtocolGame;
148
+    friend class Map;
149
+
150
+public:
151
+    // login related
152
+    void loginWorld(const std::string& account,
153
+                    const std::string& password,
154
+                    const std::string& worldHost, int worldPort,
155
+                    const std::string& characterName);
156
+    void cancelLogin();
157
+    void forceLogout();
158
+    void safeLogout();
159
+
64 160
     // walk related
65 161
     void walk(Otc::Direction direction);
162
+    void walkPath(const std::vector<Otc::Direction>& dir);
66 163
     void forceWalk(Otc::Direction direction);
67 164
     void turn(Otc::Direction direction);
165
+    void stop();
68 166
 
69 167
     // item related
70 168
     void look(const ThingPtr& thing);
71
-    void open(const ItemPtr& item, int containerId);
169
+    void move(const ThingPtr &thing, const Position& toPos, int count);
170
+    void rotate(const ThingPtr& thing);
72 171
     void use(const ThingPtr& thing);
73 172
     void useWith(const ItemPtr& fromThing, const ThingPtr& toThing);
74 173
     void useInventoryItem(int itemId);
75 174
     void useInventoryItemWith(int itemId, const ThingPtr& toThing);
76
-    void move(const ThingPtr &thing, const Position& toPos, int count);
77 175
 
78
-    // fight tatics related
79
-    void setChaseMode(Otc::ChaseModes chaseMode);
80
-    void setFightMode(Otc::FightModes fightMode);
81
-    void setSafeFight(bool on);
82
-    Otc::ChaseModes getChaseMode() { return m_chaseMode; }
83
-    Otc::FightModes getFightMode() { return m_fightMode; }
84
-    bool isSafeFight() { return m_safeFight; }
176
+    // container related
177
+    void open(const ItemPtr& item, int containerId);
178
+    void upContainer(int containerId);
179
+    void refreshContainer();
85 180
 
86 181
     // attack/follow related
87 182
     void attack(const CreaturePtr& creature);
88
-    void cancelAttack();
183
+    void cancelAttack() { attack(nullptr); }
89 184
     void follow(const CreaturePtr& creature);
90
-    void cancelFollow();
91
-    void rotate(const ThingPtr& thing);
185
+    void cancelFollow() { follow(nullptr); }
186
+    void cancelAttackAndFollow();
92 187
 
93 188
     // talk related
94 189
     void talk(const std::string& message);
95 190
     void talkChannel(Otc::SpeakType speakType, int channelId, const std::string& message);
96 191
     void talkPrivate(Otc::SpeakType speakType, const std::string& receiver, const std::string& message);
192
+
193
+    // channel related
97 194
     void openPrivateChannel(const std::string& receiver);
98 195
     void requestChannels();
99 196
     void joinChannel(int channelId);
100 197
     void leaveChannel(int channelId);
101 198
     void closeNpcChannel();
199
+    void openOwnChannel();
200
+    void inviteToOwnChannel(const std::string& name);
201
+    void excludeFromOwnChannel(const std::string& name);
102 202
 
103 203
     // party related
104 204
     void partyInvite(int creatureId);
@@ -110,30 +210,65 @@ public:
110 210
 
111 211
     // outfit related
112 212
     void requestOutfit();
113
-    void setOutfit(const Outfit& outfit);
213
+    void changeOutfit(const Outfit& outfit);
114 214
 
115 215
     // vip related
116 216
     void addVip(const std::string& name);
117 217
     void removeVip(int playerId);
118 218
 
219
+    // fight modes related
220
+    void setChaseMode(Otc::ChaseModes chaseMode);
221
+    void setFightMode(Otc::FightModes fightMode);
222
+    void setSafeFight(bool on);
223
+    Otc::ChaseModes getChaseMode() { return m_chaseMode; }
224
+    Otc::FightModes getFightMode() { return m_fightMode; }
225
+    bool isSafeFight() { return m_safeFight; }
226
+
227
+    // npc trade related
228
+    //void inspectNpcTrade();
229
+    //void buyItem();
230
+    //void sellItem();
231
+    //void closeNpcTrade();
232
+
233
+    // player trade related
234
+    //void requestTrade();
235
+    //void inspectTrade();
236
+    //void acceptTrade();
237
+    //void rejectTrade();
238
+
239
+    // house window and editable items related
240
+    //void editText();
241
+    //void editList();
242
+
243
+    // questlog related
244
+    //void requestQuestLog();
245
+    //void requestQuestLogLine();
246
+
247
+    bool canPerformGameAction();
119 248
     bool checkBotProtection();
120 249
 
121 250
     bool isOnline() { return !!m_localPlayer; }
122 251
     bool isDead() { return m_dead; }
252
+    bool isAttacking() { return !!m_attackingCreature; }
253
+    bool isFollowing() { return !!m_followingCreature; }
123 254
 
124
-    void setServerBeat(int serverBeat) { m_serverBeat = serverBeat; }
255
+    CreaturePtr getAttackingCreature() { return m_attackingCreature; }
256
+    CreaturePtr getFollowingCreature() {