some chat functionality

This commit is contained in:
Eduardo Bart 2012-01-13 23:37:15 -02:00
parent aae784468b
commit 61aa710d1c
27 changed files with 345 additions and 146 deletions

View File

@ -1,18 +0,0 @@
MapEffects = {}
function MapEffects.init()
--[[
local box = createWidget('ComboBox', 'leftButtonsPanel')
box:addAnchor(AnchorLeft, 'prev', AnchorRight)
box:addAnchor(AnchorTop, 'parent', AnchorTop)
box:setMargin(6, 6)
box:addOption('Normal')
box:addOption('Bloom')
box:addOption('TV')
displayUI(box)
]]--
end
function MapEffects.terminate()
end

View File

@ -1,16 +0,0 @@
Module
name: mapeffects
description: Contains experimental shader effects for map
author: OTClient team
website: https://github.com/edubart/otclient
// console can be loaded after core
autoLoad: true
autoLoadPriority: 1000
onLoad: |
require 'mapeffects'
MapEffects.init()
onUnload: |
MapEffects.terminate()

View File

@ -5,7 +5,7 @@ Module
website: https://github.com/edubart/otclient website: https://github.com/edubart/otclient
autoLoad: true autoLoad: true
autoLoadPriority: 1000 autoLoadAntecedence: 1000
onLoad: | onLoad: |
require 'pingbar' require 'pingbar'

View File

@ -1,7 +1,7 @@
Module Module
name: playground name: playground
autoLoad: true autoLoad: true
autoLoadPriority: 1000 autoLoadAntecedence: 1000
onLoad: | onLoad: |
require 'playground' require 'playground'

View File

@ -5,7 +5,7 @@ Module
website: https://github.com/edubart/otclient website: https://github.com/edubart/otclient
autoLoad: true autoLoad: true
autoLoadPriority: 200 autoLoadAntecedence: 200
onLoad: | onLoad: |
require 'terminal' require 'terminal'

View File

@ -16,7 +16,7 @@ OptionCheckBox < CheckBox
MainWindow MainWindow
id: optionsWindow id: optionsWindow
text: Options text: Options
size: 286 230 size: 286 250
@onEnter: Options.hide() @onEnter: Options.hide()
@onEscape: Options.hide() @onEscape: Options.hide()
@ -58,9 +58,9 @@ MainWindow
id: showLevelsInConsole id: showLevelsInConsole
text: Show levels in console text: Show levels in console
//OptionCheckBox OptionCheckBox
// id: showPrivateMessagesInConsole id: showPrivateMessagesInConsole
// text: Show private messages in console text: Show private messages in console
Button Button
text: Ok text: Ok

@ -1 +1 @@
Subproject commit dd648e1431171bffe091b748744395780df7eba1 Subproject commit 9beb17daaeb170c127c39c5a5e4feb9d95ebed92

View File

@ -6,7 +6,7 @@ Module
// core must be loaded before other modules // core must be loaded before other modules
autoLoad: true autoLoad: true
autoLoadPriority: 10 autoLoadAntecedence: 10
// NOTE: order does matter // NOTE: order does matter
dependencies: dependencies:

Binary file not shown.

After

Width:  |  Height:  |  Size: 245 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 300 B

View File

@ -1,14 +1,14 @@
UITabBar = extends(UIWidget) UITabBar = extends(UIWidget)
-- private functions -- private functions
local function onTabClick(tabButton) local function onTabClick(tab)
tabButton.tabBar:selectTab(tabButton) tab.tabBar:selectTab(tab)
end end
local function tabBlink(tabButton) local function tabBlink(tab)
if not tabButton.blinking then return end if not tab.blinking then return end
tabButton:setOn(not tabButton:isOn()) tab:setOn(not tab:isOn())
scheduleEvent(function() tabBlink(tabButton) end, 500) scheduleEvent(function() tabBlink(tab) end, 500)
end end
-- public functions -- public functions
@ -31,44 +31,52 @@ function UITabBar:addTab(text, panel)
panel = createWidget(self:getStyleName() .. 'Panel') panel = createWidget(self:getStyleName() .. 'Panel')
end end
local tabButton = createWidget(self:getStyleName() .. 'Button', self) local tab = createWidget(self:getStyleName() .. 'Button', self)
tabButton.tabPanel = panel tab.tabPanel = panel
tabButton.tabBar = self tab.tabBar = self
tabButton:setText(text) tab:setText(text)
tabButton:setWidth(tabButton:getTextSize().width + tabButton:getPaddingLeft() + tabButton:getPaddingRight()) tab:setWidth(tab:getTextSize().width + tab:getPaddingLeft() + tab:getPaddingRight())
connect(tabButton, { onClick = onTabClick }) connect(tab, { onClick = onTabClick })
table.insert(self.tabs, tabButton) table.insert(self.tabs, tab)
if #self.tabs == 1 then if #self.tabs == 1 then
self:selectTab(tabButton) self:selectTab(tab)
end end
return tabButton return tab
end end
function UITabBar:selectTab(tabButton) function UITabBar:getTab(text)
if self.currentTabButton == tabButton then return end for k,tab in pairs(self.tabs) do
if tab:getText() == text then
return tab
end
end
end
function UITabBar:selectTab(tab)
if self.currentTab == tab then return end
if self.contentWidget then if self.contentWidget then
local selectedWidget = self.contentWidget:getFirstChild() local selectedWidget = self.contentWidget:getFirstChild()
if selectedWidget then if selectedWidget then
self.contentWidget:removeChild(selectedWidget) self.contentWidget:removeChild(selectedWidget)
end end
self.contentWidget:addChild(tabButton.tabPanel) self.contentWidget:addChild(tab.tabPanel)
tabButton.tabPanel:fill('parent') tab.tabPanel:fill('parent')
end end
if self.currentTabButton then if self.currentTab then
self.currentTabButton:setChecked(false) self.currentTab:setChecked(false)
end end
self.currentTabButton = tabButton self.currentTab = tab
tabButton:setChecked(true) tab:setChecked(true)
tabButton:setOn(false) tab:setOn(false)
tabButton.blinking = false tab.blinking = false
end end
function UITabBar:selectNextTab() function UITabBar:selectNextTab()
if self.currentTabButton == nil then return end if self.currentTab == nil then return end
local index = table.find(self.tabs, self.currentTabButton) local index = table.find(self.tabs, self.currentTab)
if index == nil then return end if index == nil then return end
local nextTab = self.tabs[index + 1] or self.tabs[1] local nextTab = self.tabs[index + 1] or self.tabs[1]
if not nextTab then return end if not nextTab then return end
@ -76,26 +84,30 @@ function UITabBar:selectNextTab()
end end
function UITabBar:selectPrevTab() function UITabBar:selectPrevTab()
if self.currentTabButton == nil then return end if self.currentTab == nil then return end
local index = table.find(self.tabs, self.currentTabButton) local index = table.find(self.tabs, self.currentTab)
if index == nil then return end if index == nil then return end
local prevTab = self.tabs[index - 1] or self.tabs[#self.tabs] local prevTab = self.tabs[index - 1] or self.tabs[#self.tabs]
if not prevTab then return end if not prevTab then return end
self:selectTab(prevTab) self:selectTab(prevTab)
end end
function UITabBar:blinkTab(tabButton) function UITabBar:blinkTab(tab)
if tabButton:isChecked() or tabButton.blinking then return end if tab:isChecked() or tab.blinking then return end
tabButton.blinking = true tab.blinking = true
tabBlink(tabButton) tabBlink(tab)
end end
function UITabBar:getTabPanel(tabButton) function UITabBar:getTabPanel(tab)
return tabButton.tabPanel return tab.tabPanel
end end
function UITabBar:getCurrentTabPanel() function UITabBar:getCurrentTabPanel()
if self.currentTabButton then if self.currentTab then
return self.currentTabButton.tabPanel return self.currentTab.tabPanel
end end
end end
function UITabBar:getCurrentTab()
return self.currentTab
end

View File

@ -133,7 +133,7 @@ function Game.createThingMenu(menuPosition, lookThing, useThing, creatureThing)
menu:addSeparator() menu:addSeparator()
if creatureThing:asLocalPlayer() then if creatureThing:asLocalPlayer() then
menu:addOption('Set Outfit', function() Game.openOutfitWindow() end) menu:addOption('Set Outfit', function() Game.requestOutfit() end)
if creatureThing:asPlayer():isPartyMember() --[[and not fighting]] then if creatureThing:asPlayer():isPartyMember() --[[and not fighting]] then
if creatureThing:asPlayer():isPartyLeader() then if creatureThing:asPlayer():isPartyLeader() then

View File

@ -0,0 +1,40 @@
ChannelListLabel < Label
font: verdana-11px-monochrome
background-color: alpha
text-offset: 2 0
focusable: true
$focus:
background-color: #ffffff22
color: #ffffff
MainWindow
id: channelsWindow
text: Channels
size: 250 208
@onEscape: self:destroy()
TextList
id: channelList
anchors.fill: parent
anchors.bottom: next.top
margin-bottom: 10
padding: 1
focusable: false
Button
id: buttonOpen
text: Open
width: 64
anchors.right: next.left
anchors.bottom: parent.bottom
margin-right: 10
@onClick: self:getParent():onEnter()
Button
id: buttonCancel
text: Cancel
width: 64
anchors.right: parent.right
anchors.bottom: parent.bottom
@onClick: self:getParent():destroy()

View File

@ -7,35 +7,51 @@ local SpeakTypes = {
yell = { color = '#FFFF00' }, yell = { color = '#FFFF00' },
monsterSay = { color = '#FE6500', hideInConsole = true}, monsterSay = { color = '#FE6500', hideInConsole = true},
monsterYell = { color = '#FE6500', hideInConsole = true}, monsterYell = { color = '#FE6500', hideInConsole = true},
npcToPlayer = { color = '#5FF7F7' }, npcToPlayer = { color = '#5FF7F7', private = true, npcChat = true },
channelYellow = { color = '#FFFF00' }, channelYellow = { color = '#FFFF00' },
channelWhite = { color = '#FFFFFF' }, channelWhite = { color = '#FFFFFF' },
channelRed = { color = '#F55E5E' }, channelRed = { color = '#F55E5E' },
channelOrange = { color = '#FE6500' }, channelOrange = { color = '#FE6500' },
private = { color = '#5FF7F7' }, private = { color = '#5FF7F7', private = true },
playerToNpc = { color = '#9F9DFD' }, playerToNpc = { color = '#9F9DFD', private = true, npcChat = true },
broadcast = { color = '#F55E5E' }, broadcast = { color = '#F55E5E', private = true },
privateRed = { color = '#F55E5E' } privateRed = { color = '#F55E5E', private = true }
} }
local consolePanel local consolePanel
local consoleBuffer local consoleBuffer
local consoleTabBar local consoleTabBar
local defaultChannelTab local consoleLineEdit
local serverLogTab local channels
local currentTab
-- private functions
function applyMessagePrefixies(name, level, message)
if name then
if Options.showLevelsInConsole and level > 0 then
message = name .. ' [' .. level .. ']: ' .. message
else
message = name .. ': ' .. message
end
end
return message
end
-- public functions -- public functions
function Console.create() function Console.create()
consolePanel = displayUI('console.otui', { parent = Game.gameBottomPanel } ) consolePanel = displayUI('console.otui', { parent = Game.gameBottomPanel } )
consoleLineEdit = consolePanel:getChildById('consoleLineEdit')
consoleBuffer = consolePanel:getChildById('consoleBuffer') consoleBuffer = consolePanel:getChildById('consoleBuffer')
consoleTabBar = consolePanel:getChildById('consoleTabBar') consoleTabBar = consolePanel:getChildById('consoleTabBar')
consoleTabBar:setContentWidget(consoleBuffer) consoleTabBar:setContentWidget(consoleBuffer)
defaultChannelTab = consoleTabBar:addTab('Default') channels = {}
serverLogTab = consoleTabBar:addTab('Server Log')
Console.addChannel('Default', 0)
Console.addTab('Server Log')
Hotkeys.bind('Tab', function() consoleTabBar:selectNextTab() end, consolePanel) Hotkeys.bind('Tab', function() consoleTabBar:selectNextTab() end, consolePanel)
Hotkeys.bind('Shift+Tab', function() consoleTabBar:selectPrevTab() end, consolePanel) Hotkeys.bind('Shift+Tab', function() consoleTabBar:selectPrevTab() end, consolePanel)
Hotkeys.bind('Enter', Console.sendCurrentMessage, consolePanel)
Hotkeys.bind('Return', Console.sendCurrentMessage, consolePanel)
end end
function Console.destroy() function Console.destroy()
@ -43,24 +59,84 @@ function Console.destroy()
consolePanel = nil consolePanel = nil
end end
function Console.addText(text, color, channelTab) function Console.addTab(name)
color = color or 'white' local tab = consoleTabBar:addTab(name)
consoleTabBar:selectTab(tab)
return tab
end
function Console.getTab(name)
return consoleTabBar:getTab(name)
end
function Console.getCurrentTab()
return consoleTabBar:getCurrentTab()
end
function Console.addChannel(name, id)
channels[id] = name
local tab = Console.addTab(name)
tab.channelId = id
return tab
end
function Console.addPrivateText(text, speaktype, name)
local privateTab = Console.getTab(name)
if privateTab == nil then
if Options.showPrivateMessagesInConsole then
privateTab = Console.getTab('Default')
else
privateTab = Console.addTab(name)
end
privateTab.npcChat = speaktype.npcChat
end
Console.addTabText(text, speaktype, privateTab)
end
function Console.addText(text, speaktype, tabName)
local tab = Console.getTab(tabName)
Console.addTabText(text, speaktype, tab)
end
function Console.addTabText(text, speaktype, tab)
if Options.showTimestampsInConsole then if Options.showTimestampsInConsole then
text = os.date('%H:%M') .. ' ' .. text text = os.date('%H:%M') .. ' ' .. text
end end
local label = createWidget('ConsoleLabel', consoleTabBar:getTabPanel(channelTab)) local label = createWidget('ConsoleLabel', consoleTabBar:getTabPanel(tab))
label:setText(text) label:setText(text)
label:setColor(color) label:setColor(speaktype.color)
consoleTabBar:blinkTab(channelTab) consoleTabBar:blinkTab(tab)
end end
function Console.addChannelMessage(text, color, channel) function Console.sendCurrentMessage()
if channel == 'Server Log' then local message = consoleLineEdit:getText()
Console.addText(text, color, serverLogTab) if #message == 0 then return end
elseif channel == 'Default' then consoleLineEdit:clearText()
Console.addText(text, color, defaultChannelTab)
local tab = Console.getCurrentTab()
local name = tab:getText()
if name == 'Server Log' then name = 'Default' end
local speaktypedesc = 'say'
if tab.npcChat then
speaktypedesc = 'playerToNpc'
end
if tab.channelId then
if tab.channelId ~= 0 then
speaktypedesc = 'channelYellow'
end
Game.talkChannel(speaktypedesc, tab.channelId, message)
return
else
local speaktype = SpeakTypes[speaktypedesc]
local player = Game.getLocalPlayer()
message = applyMessagePrefixies(player:getName(), player:getLevel(), message)
Console.addPrivateText(message, speaktype, name)
Game.talkPrivate(speaktypedesc, name, message)
end end
end end
@ -69,17 +145,44 @@ local function onCreatureSpeak(name, level, speaktypedesc, message, channelId, c
speaktype = SpeakTypes[speaktypedesc] speaktype = SpeakTypes[speaktypedesc]
if speaktype.hideInConsole then return end if speaktype.hideInConsole then return end
if name then message = applyMessagePrefixies(name, level, message)
if Options.showLevelsInConsole and level > 0 then
message = name .. ' [' .. level .. ']: ' .. message
else
message = name .. ': ' .. message
end
end
Console.addText(message, speaktype.color, defaultChannelTab) if speaktype.private then
Console.addPrivateText(message, speaktype, name)
else
Console.addText(message, speaktype, channels[channelId])
end
end
local function onOpenChannel(channelId, channelName)
Console.addChannel(channelName, channelId)
end
local function onChannelList(channelList)
local channelsWindow = displayUI('channelswindow.otui')
local channelListPanel = channelsWindow:getChildById('channelList')
channelsWindow.onEnter = function(self)
local selectedChannelLabel = channelListPanel:getFocusedChild()
if not selectedChannelLabel then return end
--Game.joinChannel(selectedChannelLabel.channelId)
--Console.addChannel(selectedChannelLabel:getText(), selectedChannelLabel .channelId)
channelsWindow:destroy()
end
for k,v in pairs(channelList) do
local channelId = v[1]
local channelName = v[2]
if channelId ~= 0 and #channelName > 0 then
local label = createWidget('ChannelListLabel', channelListPanel)
print(channelId, channelName)
label.channelId = channelId
label:setText(channelName)
end
end
end end
connect(Game, { onLogin = Console.create, connect(Game, { onLogin = Console.create,
onLogout = Console.destroy, onLogout = Console.destroy,
onCreatureSpeak = onCreatureSpeak}) onCreatureSpeak = onCreatureSpeak,
onChannelList = onChannelList,
onOpenChannel = onOpenChannel})

View File

@ -34,12 +34,29 @@ Panel
ConsoleButton ConsoleButton
id: nextChannelButton id: nextChannelButton
icon: /core_styles/icons/rightarrow.png icon: /core_styles/icons/rightarrow.png
anchors.right: parent.right anchors.right: next.left
anchors.top: parent.top anchors.top: parent.top
margin-right: 5 margin-right: 5
margin-top: 6 margin-top: 6
enabled: false enabled: false
ConsoleButton
id: closeChannelButton
icon: /core_styles/icons/closechannel.png
anchors.right: next.left
anchors.top: parent.top
margin-right: 5
margin-top: 6
ConsoleButton
id: channelsButton
icon: /core_styles/icons/channels.png
anchors.right: parent.right
anchors.top: parent.top
margin-right: 5
margin-top: 6
@onClick: Game.requestChannels()
Panel Panel
id: consoleBuffer id: consoleBuffer
anchors.top: prev.bottom anchors.top: prev.bottom

View File

@ -5,16 +5,16 @@ importStyle 'textmessage.otui'
-- private variables -- private variables
local MessageTypes = { local MessageTypes = {
consoleRed = { color = '#F55E5E', consoleChannel = 'Server Log' }, consoleRed = { color = '#F55E5E', consoleTab = 'Server Log' },
eventOrange = { color = '#FE6500', consoleChannel = 'Default' , windowLocation = 'center', consoleOption = 'showEventMessagesInConsole' }, eventOrange = { color = '#FE6500', consoleTab = 'Default' , windowLocation = 'center', consoleOption = 'showEventMessagesInConsole' },
consoleOrange = { color = '#FE6500', consoleChannel = 'Default' }, consoleOrange = { color = '#FE6500', consoleTab = 'Default' },
warning = { color = '#F55E5E', consoleChannel = 'Server Log', windowLocation = 'center' }, warning = { color = '#F55E5E', consoleTab = 'Server Log', windowLocation = 'center' },
eventAdvance = { color = '#FFFFFF', consoleChannel = 'Server Log', windowLocation = 'center', consoleOption = 'showEventMessagesInConsole' }, eventAdvance = { color = '#FFFFFF', consoleTab = 'Server Log', windowLocation = 'center', consoleOption = 'showEventMessagesInConsole' },
eventDefault = { color = '#FFFFFF', consoleChannel = 'Server Log', windowLocation = 'bottom', consoleOption = 'showEventMessagesInConsole' }, eventDefault = { color = '#FFFFFF', consoleTab = 'Server Log', windowLocation = 'bottom', consoleOption = 'showEventMessagesInConsole' },
statusDefault = { color = '#FFFFFF', consoleChannel = 'Server Log', windowLocation = 'bottom', consoleOption = 'showStatusMessagesInConsole' }, statusDefault = { color = '#FFFFFF', consoleTab = 'Server Log', windowLocation = 'bottom', consoleOption = 'showStatusMessagesInConsole' },
infoDescription = { color = '#00EB00', consoleChannel = 'Server Log', windowLocation = 'center', consoleOption = 'showInfoMessagesInConsole' }, infoDescription = { color = '#00EB00', consoleTab = 'Server Log', windowLocation = 'center', consoleOption = 'showInfoMessagesInConsole' },
statusSmall = { color = '#FFFFFF', windowLocation = 'bottom' }, statusSmall = { color = '#FFFFFF', windowLocation = 'bottom' },
consoleBlue = { color = '#9F9DFD', consoleChannel = 'Default' }, consoleBlue = { color = '#9F9DFD', consoleTab = 'Default' },
} }
local bottomLabelWidget local bottomLabelWidget
@ -26,9 +26,9 @@ local centerLabelHideEvent
local function displayMessage(msgtype, msg, time) local function displayMessage(msgtype, msg, time)
if not Game.isOnline() then return end if not Game.isOnline() then return end
if msgtype.consoleChannel ~= nil then if msgtype.consoleTab ~= nil then
if msgtype.consoleOption == nil or Options[msgtype.consoleOption] then if msgtype.consoleOption == nil or Options[msgtype.consoleOption] then
Console.addChannelMessage(msg, msgtype.color, msgtype.consoleChannel) Console.addText(msg, msgtype, msgtype.consoleTab)
end end
end end

View File

@ -39,7 +39,7 @@ void Module::discover(const OTMLNodePtr& moduleNode)
m_website = moduleNode->valueAt("website", none); m_website = moduleNode->valueAt("website", none);
m_version = moduleNode->valueAt("version", none); m_version = moduleNode->valueAt("version", none);
m_autoLoad = moduleNode->valueAt<bool>("autoLoad", false); m_autoLoad = moduleNode->valueAt<bool>("autoLoad", false);
m_autoLoadPriority = moduleNode->valueAt<int>("autoLoadPriority", 100); m_autoLoadAntecedence = moduleNode->valueAt<int>("autoLoadAntecedence", 100);
if(OTMLNodePtr node = moduleNode->get("dependencies")) { if(OTMLNodePtr node = moduleNode->get("dependencies")) {
for(const OTMLNodePtr& tmp : node->children()) for(const OTMLNodePtr& tmp : node->children())

View File

@ -44,12 +44,12 @@ public:
std::string getWebsite() { return m_website; } std::string getWebsite() { return m_website; }
std::string getVersion() { return m_version; } std::string getVersion() { return m_version; }
bool isAutoLoad() { return m_autoLoad; } bool isAutoLoad() { return m_autoLoad; }
int getAutoLoadPriority() { return m_autoLoadPriority; } int getAutoLoadAntecedence() { return m_autoLoadAntecedence; }
private: private:
Boolean<false> m_loaded; Boolean<false> m_loaded;
Boolean<false> m_autoLoad; Boolean<false> m_autoLoad;
int m_autoLoadPriority; int m_autoLoadAntecedence;
std::string m_name; std::string m_name;
std::string m_description; std::string m_description;
std::string m_author; std::string m_author;

View File

@ -37,17 +37,17 @@ void ModuleManager::discoverModules()
if(boost::ends_with(moduleFile, ".otmod")) { if(boost::ends_with(moduleFile, ".otmod")) {
ModulePtr module = discoverModule("/" + moduleDir + "/" + moduleFile); ModulePtr module = discoverModule("/" + moduleDir + "/" + moduleFile);
if(module && module->isAutoLoad()) if(module && module->isAutoLoad())
m_autoLoadModules.insert(make_pair(module->getAutoLoadPriority(), module)); m_autoLoadModules.insert(make_pair(module->getAutoLoadAntecedence(), module));
} }
} }
} }
} }
void ModuleManager::autoLoadModules(int maxPriority) void ModuleManager::autoLoadModules(int maxAntecedence)
{ {
for(auto& pair : m_autoLoadModules) { for(auto& pair : m_autoLoadModules) {
int priority = pair.first; int priority = pair.first;
if(priority > maxPriority) if(priority > maxAntecedence)
break; break;
ModulePtr module = pair.second; ModulePtr module = pair.second;
if(!module->isLoaded() && !module->load()) if(!module->isLoaded() && !module->load())

View File

@ -30,7 +30,7 @@ class ModuleManager
public: public:
void discoverModulesPath(); void discoverModulesPath();
void discoverModules(); void discoverModules();
void autoLoadModules(int maxPriority); void autoLoadModules(int maxAntecedence);
ModulePtr discoverModule(const std::string& moduleFile); ModulePtr discoverModule(const std::string& moduleFile);
void ensureModuleLoaded(const std::string& moduleName); void ensureModuleLoaded(const std::string& moduleName);
void unloadModules(); void unloadModules();

View File

@ -340,23 +340,23 @@ int Game::getThingStackpos(const ThingPtr& thing)
void Game::talk(const std::string& message) void Game::talk(const std::string& message)
{ {
talkChannel(1, 0, message); talkChannel("say", 0, message);
} }
void Game::talkChannel(int channelType, int channelId, const std::string& message) void Game::talkChannel(const std::string& speakTypeDesc, int channelId, const std::string& message)
{ {
if(!m_online || !checkBotProtection()) if(!m_online || !checkBotProtection())
return; return;
m_protocolGame->sendTalk(channelType, channelId, "", message); m_protocolGame->sendTalk(speakTypeDesc, channelId, "", message);
} }
void Game::talkPrivate(int channelType, const std::string& receiver, const std::string& message) void Game::talkPrivate(const std::string& speakTypeDesc, const std::string& receiver, const std::string& message)
{ {
if(!m_online || !checkBotProtection()) if(!m_online || !checkBotProtection())
return; return;
m_protocolGame->sendTalk(channelType, 0, receiver, message); m_protocolGame->sendTalk(speakTypeDesc, 0, receiver, message);
} }
void Game::partyInvite(int creatureId) void Game::partyInvite(int creatureId)
@ -408,7 +408,7 @@ void Game::partyShareExperience(bool active)
m_protocolGame->sendShareExperience(active, 0); m_protocolGame->sendShareExperience(active, 0);
} }
void Game::openOutfitWindow() void Game::requestOutfit()
{ {
if(!m_online || !checkBotProtection()) if(!m_online || !checkBotProtection())
return; return;
@ -416,6 +416,22 @@ void Game::openOutfitWindow()
m_protocolGame->sendGetOutfit(); m_protocolGame->sendGetOutfit();
} }
void Game::requestChannels()
{
if(!m_online || !checkBotProtection())
return;
m_protocolGame->sendGetChannels();
}
void Game::openChannel(int channelId)
{
if(!m_online || !checkBotProtection())
return;
m_protocolGame->sendOpenChannel(channelId);
}
void Game::setOutfit(const Outfit& outfit) void Game::setOutfit(const Outfit& outfit)
{ {
if(!m_online || !checkBotProtection()) if(!m_online || !checkBotProtection())

View File

@ -66,15 +66,17 @@ public:
void cancelFollow(); void cancelFollow();
void rotate(const ThingPtr& thing); void rotate(const ThingPtr& thing);
void talk(const std::string& message); void talk(const std::string& message);
void talkChannel(int channelType, int channelId, const std::string& message); void talkChannel(const std::string& speakTypeDesc, int channelId, const std::string& message);
void talkPrivate(int channelType, const std::string& receiver, const std::string& message); void talkPrivate(const std::string& speakTypeDesc, const std::string& receiver, const std::string& message);
void partyInvite(int creatureId); void partyInvite(int creatureId);
void partyJoin(int creatureId); void partyJoin(int creatureId);
void partyRevokeInvitation(int creatureId); void partyRevokeInvitation(int creatureId);
void partyPassLeadership(int creatureId); void partyPassLeadership(int creatureId);
void partyLeave(); void partyLeave();
void partyShareExperience(bool active); void partyShareExperience(bool active);
void openOutfitWindow(); void requestOutfit();
void requestChannels();
void openChannel(int channelId);
void setOutfit(const Outfit& outfit); void setOutfit(const Outfit& outfit);
void addVip(const std::string& name); void addVip(const std::string& name);
void removeVip(int playerId); void removeVip(int playerId);

View File

@ -55,6 +55,8 @@ public:
LocalPlayerPtr asLocalPlayer() { return std::static_pointer_cast<LocalPlayer>(shared_from_this()); } LocalPlayerPtr asLocalPlayer() { return std::static_pointer_cast<LocalPlayer>(shared_from_this()); }
double getLevel() { return getStatistic(Otc::Level); }
private: private:
bool m_canReportBugs; bool m_canReportBugs;
bool m_clientWalking; bool m_clientWalking;

View File

@ -145,6 +145,7 @@ void OTClient::registerLuaFunctions()
g_lua.registerClass<LocalPlayer, Player>(); g_lua.registerClass<LocalPlayer, Player>();
g_lua.bindClassMemberFunction<LocalPlayer>("getAttackingCreature", &LocalPlayer::getAttackingCreature); g_lua.bindClassMemberFunction<LocalPlayer>("getAttackingCreature", &LocalPlayer::getAttackingCreature);
g_lua.bindClassMemberFunction<LocalPlayer>("getFollowingCreature", &LocalPlayer::getFollowingCreature); g_lua.bindClassMemberFunction<LocalPlayer>("getFollowingCreature", &LocalPlayer::getFollowingCreature);
g_lua.bindClassMemberFunction<LocalPlayer>("getLevel", &LocalPlayer::getLevel);
g_lua.registerClass<Tile>(); g_lua.registerClass<Tile>();
g_lua.bindClassMemberFunction<Tile>("clean", &Tile::clean); g_lua.bindClassMemberFunction<Tile>("clean", &Tile::clean);
@ -177,7 +178,9 @@ void OTClient::registerLuaFunctions()
g_lua.bindClassStaticFunction<Game>("logout", std::bind(&Game::logout, &g_game, _1)); g_lua.bindClassStaticFunction<Game>("logout", std::bind(&Game::logout, &g_game, _1));
g_lua.bindClassStaticFunction<Game>("cancelLogin", std::bind(&Game::cancelLogin, &g_game)); g_lua.bindClassStaticFunction<Game>("cancelLogin", std::bind(&Game::cancelLogin, &g_game));
g_lua.bindClassStaticFunction<Game>("isOnline", std::bind(&Game::isOnline, &g_game)); g_lua.bindClassStaticFunction<Game>("isOnline", std::bind(&Game::isOnline, &g_game));
g_lua.bindClassStaticFunction<Game>("openOutfitWindow", std::bind(&Game::openOutfitWindow, &g_game)); g_lua.bindClassStaticFunction<Game>("requestOutfit", std::bind(&Game::requestOutfit, &g_game));
g_lua.bindClassStaticFunction<Game>("requestChannels", std::bind(&Game::requestChannels, &g_game));
g_lua.bindClassStaticFunction<Game>("openChannel", std::bind(&Game::openChannel, &g_game, _1));
g_lua.bindClassStaticFunction<Game>("setOutfit", std::bind(&Game::setOutfit, &g_game, _1)); g_lua.bindClassStaticFunction<Game>("setOutfit", std::bind(&Game::setOutfit, &g_game, _1));
g_lua.bindClassStaticFunction<Game>("look", std::bind(&Game::look, &g_game, _1)); g_lua.bindClassStaticFunction<Game>("look", std::bind(&Game::look, &g_game, _1));
g_lua.bindClassStaticFunction<Game>("open", std::bind(&Game::open, &g_game, _1, _2)); g_lua.bindClassStaticFunction<Game>("open", std::bind(&Game::open, &g_game, _1, _2));

View File

@ -336,6 +336,43 @@ namespace Proto {
} }
} }
inline int translateSpeakTypeDesc(const std::string& type) {
if(type == "say")
return Proto::SpeakSay;
else if(type == "whisper")
return Proto::SpeakWhisper;
else if(type == "yell")
return Proto::SpeakYell;
else if(type == "monsterSay")
return Proto::SpeakMonsterSay;
else if(type == "monsterYell")
return Proto::SpeakMonsterYell;
else if(type == "npcToPlayer")
return Proto::SpeakPrivateNpcToPlayer;
else if(type == "channelYellow")
return Proto::SpeakChannelYellow;
else if(type == "channelWhite")
return Proto::SpeakChannelWhite;
else if(type == "channelRed")
return Proto::SpeakChannelRed;
else if(type == "channelRed")
return Proto::SpeakChannelRed2;
else if(type == "channelOrange")
return Proto::SpeakChannelOrange;
else if(type == "private")
return Proto::SpeakPrivate;
else if(type == "playerToNpc")
return Proto::SpeakPrivatePlayerToNpc;
else if(type == "broadcast")
return Proto::SpeakBroadcast;
else if(type == "privateRed")
return Proto::SpeakPrivateRed;
else {
logError("unknown protocol speak type desc ", type);
return 0;
}
}
inline std::string translateTextMessageType(int type) { inline std::string translateTextMessageType(int type) {
switch(type) { switch(type) {
case Proto::MessageConsoleOrange: case Proto::MessageConsoleOrange:

View File

@ -73,7 +73,7 @@ public:
void sendTextWindow(uint windowTextId, const std::string& text); void sendTextWindow(uint windowTextId, const std::string& text);
void sendHouseWindow(int doorId, uint id, const std::string& text); void sendHouseWindow(int doorId, uint id, const std::string& text);
void sendLookAt(const Position& position, int thingId, int stackpos); void sendLookAt(const Position& position, int thingId, int stackpos);
void sendTalk(int channelType, int channelId, const std::string& receiver, const std::string& message); void sendTalk(const std::string& speakTypeDesc, int channelId, const std::string& receiver, const std::string& message);
void sendGetChannels(); void sendGetChannels();
void sendJoinChannel(int channelId); void sendJoinChannel(int channelId);
void sendLeaveChannel(int channelId); void sendLeaveChannel(int channelId);
@ -88,7 +88,7 @@ public:
void sendPassLeadership(uint creatureId); void sendPassLeadership(uint creatureId);
void sendLeaveParty(); void sendLeaveParty();
void sendShareExperience(bool active, int unknown); void sendShareExperience(bool active, int unknown);
void sendOpenChannel(); void sendOpenChannel(int channelId);
void sendInviteToChannel(const std::string& name); void sendInviteToChannel(const std::string& name);
void sendExcludeFromChannel(const std::string& name); void sendExcludeFromChannel(const std::string& name);
void sendCancel(); void sendCancel();

View File

@ -341,18 +341,18 @@ void ProtocolGame::sendLookAt(const Position& position, int thingId, int stackpo
send(oMsg); send(oMsg);
} }
void ProtocolGame::sendTalk(int channelType, int channelId, const std::string& receiver, const std::string& message) void ProtocolGame::sendTalk(const std::string& speakTypeDesc, int channelId, const std::string& receiver, const std::string& message)
{ {
if(message.length() > 255 || message.length() <= 0) if(message.length() > 255 || message.length() <= 0)
return; return;
int speakType = Proto::translateSpeakTypeDesc(speakTypeDesc);
OutputMessage oMsg; OutputMessage oMsg;
oMsg.addU8(Proto::ClientTalk); oMsg.addU8(Proto::ClientTalk);
oMsg.addU8(speakType);
assert(channelType >= 0); switch(speakType) {
oMsg.addU8(channelType);
switch(channelType) {
case Proto::SpeakPrivate: case Proto::SpeakPrivate:
case Proto::SpeakPrivateRed: case Proto::SpeakPrivateRed:
oMsg.addString(receiver); oMsg.addString(receiver);
@ -486,10 +486,11 @@ void ProtocolGame::sendShareExperience(bool active, int unknown)
send(oMsg); send(oMsg);
} }
void ProtocolGame::sendOpenChannel() void ProtocolGame::sendOpenChannel(int channelId)
{ {
OutputMessage oMsg; OutputMessage oMsg;
oMsg.addU8(Proto::ClientOpenChannel); oMsg.addU8(Proto::ClientOpenChannel);
oMsg.addU16(channelId);
send(oMsg); send(oMsg);
} }