From e714f9e149bdce76ac75a129759d73c144a10687 Mon Sep 17 00:00:00 2001 From: Henrique Santiago Date: Tue, 10 Jan 2012 21:38:32 -0200 Subject: [PATCH] party improvements, still need to fix shared exp --- modules/game/game.otmod | 1 + modules/game/player.lua | 31 +++++++++++++++++++++ modules/game/thing.lua | 51 ++++++++++++++++++++++++++++------- src/otclient/const.h | 20 +++++++------- src/otclient/core/game.cpp | 43 ++++++++++++++++++++++++++++- src/otclient/core/game.h | 7 ++++- src/otclient/luafunctions.cpp | 10 ++++++- 7 files changed, 141 insertions(+), 22 deletions(-) create mode 100644 modules/game/player.lua diff --git a/modules/game/game.otmod b/modules/game/game.otmod index 20688767..a21ac83e 100644 --- a/modules/game/game.otmod +++ b/modules/game/game.otmod @@ -17,4 +17,5 @@ Module require 'game' require 'thing' require 'creature' + require 'player' require 'map' diff --git a/modules/game/player.lua b/modules/game/player.lua new file mode 100644 index 00000000..845d36f1 --- /dev/null +++ b/modules/game/player.lua @@ -0,0 +1,31 @@ +function Player:isPartyLeader() + local shield = self:getShield() + return (shield == ShieldWhiteYellow or + shield == ShieldYellow or + shield == ShieldYellowSharedExp or + shield == ShieldYellowNoSharedExpBlink or + shield == ShieldYellowNoSharedExp) +end + +function Player:isPartyMember() + local shield = self:getShield() + return (shield == ShieldWhiteYellow or + shield == ShieldYellow or + shield == ShieldYellowSharedExp or + shield == ShieldYellowNoSharedExpBlink or + shield == ShieldYellowNoSharedExp or + shield == ShieldBlueSharedExp or + shield == ShieldBlueNoSharedExpBlink or + shield == ShieldBlueNoSharedExp or + shield == ShieldBlue) +end + +function Player:isPartySharedExperienceActive() + local shield = self:getShield() + return (shield == ShieldYellowSharedExp or + shield == ShieldYellowNoSharedExpBlink or + shield == ShieldYellowNoSharedExp or + shield == ShieldBlueSharedExp or + shield == ShieldBlueNoSharedExpBlink or + shield == ShieldBlueNoSharedExp) +end diff --git a/modules/game/thing.lua b/modules/game/thing.lua index d1c7ad7e..8c4864f9 100644 --- a/modules/game/thing.lua +++ b/modules/game/thing.lua @@ -94,6 +94,18 @@ function Game.createThingMenu(menuPosition, lookThing, useThing, creatureThing) if creatureThing:asLocalPlayer() then menu:addOption('Set Outfit', function() Game.openOutfitWindow() end) + + if creatureThing:asPlayer():isPartyMember() --[[and not fighting]] then + if creatureThing:asPlayer():isPartyLeader() then + if creatureThing:asPlayer():isPartySharedExperienceActive() then + menu:addOption('Disable Shared Experience', function() Game.partyShareExperience(false) end) + else + menu:addOption('Enable Shared Experience', function() Game.partyShareExperience(true) end) + end + end + menu:addOption('Leave Party', function() Game.partyLeave() end) + end + else local localPlayer = Game.getLocalPlayer() if localPlayer then @@ -108,16 +120,37 @@ function Game.createThingMenu(menuPosition, lookThing, useThing, creatureThing) else menu:addOption('Stop Follow', function() Game.cancelFollow() end) end + + if creatureThing:asPlayer() then + menu:addSeparator() + menu:addOption('Message to ' .. creatureThing:getName(), function() print('message') end) + menu:addOption('Add to VIP list', function() Game.addVip(creatureThing:getName()) end) + menu:addOption('Ignore ' .. creatureThing:getName(), function() print('ignore') end) + + local localPlayerShield = localPlayer:asCreature():getShield() + local creatureShield = creatureThing:getShield() + + if localPlayerShield == ShieldNone or localPlayerShield == ShieldWhiteBlue then + if creatureShield == ShieldWhiteYellow then + menu:addOption('Join ' .. creatureThing:getName() .. '\'s Party', function() Game.partyJoin(creatureThing:getId()) end) + else + menu:addOption('Invite to Party', function() Game.partyInvite(creatureThing:getId()) end) + end + elseif localPlayerShield == ShieldWhiteYellow then + if creatureShield == ShieldWhiteBlue then + menu:addOption('Revoke ' .. creatureThing:getName() .. '\'s Invitation', function() Game.partyRevokeInvitation(creatureThing:getId()) end) + end + elseif localPlayerShield == ShieldYellow or localPlayerShield == ShieldYellowSharedExp or localPlayerShield == ShieldYellowNoSharedExpBlink or localPlayerShield == ShieldYellowNoSharedExp then + if creatureShield == ShieldWhiteBlue then + menu:addOption('Revoke ' .. creatureThing:getName() .. '\'s Invitation', function() Game.partyRevokeInvitation(creatureThing:getId()) end) + elseif creatureShield == ShieldBlue or creatureShield == ShieldBlueSharedExp or creatureShield == ShieldBlueNoSharedExpBlink or creatureShield == ShieldBlueNoSharedExp then + menu:addOption('Pass Leadership to ' .. creatureThing:getName(), function() Game.partyPassLeadership(creatureThing:getId()) end) + else + menu:addOption('Invite to Party', function() Game.partyInvite(creatureThing:getId()) end) + end + end + end end - - if creatureThing:asPlayer() then - menu:addSeparator() - menu:addOption('Message to ' .. creatureThing:getName(), function() print('message') end) - menu:addOption('Add to VIP list', function() Game.addVip(creatureThing:getName()) end) - menu:addOption('Ignore ' .. creatureThing:getName(), function() print('ignore') end) - menu:addOption('Invite to Party', function() Game.inviteToParty(creatureThing:getId()) end) - end - end menu:addSeparator() diff --git a/src/otclient/const.h b/src/otclient/const.h index 1c178788..99732735 100644 --- a/src/otclient/const.h +++ b/src/otclient/const.h @@ -174,16 +174,16 @@ namespace Otc enum PlayerShields { ShieldNone = 0, - ShieldWhiteYellow, - ShieldWhiteBlue, - ShieldBlue, - ShieldYellow, - ShieldBlueSharedExp, - ShieldYellowSharedExp, - ShieldBlueNoSharedExpBlink, - ShieldYellowNoSharedExpBlink, - ShieldBlueNoSharedExp, - ShieldYellowNoSharedExp + ShieldWhiteYellow, // 1 party leader + ShieldWhiteBlue, // 2 party member + ShieldBlue, // 3 party member sexp off + ShieldYellow, // 4 party leader sexp off + ShieldBlueSharedExp, // 5 party member sexp on + ShieldYellowSharedExp, // 6 // party leader sexp on + ShieldBlueNoSharedExpBlink, // 7 party member sexp inactive guilty + ShieldYellowNoSharedExpBlink, // 8 // party leader sexp inactive guilty + ShieldBlueNoSharedExp, // 9 party member sexp inactive innocent + ShieldYellowNoSharedExp // 10 party leader sexp inactive innocent }; enum PlayerEmblems { diff --git a/src/otclient/core/game.cpp b/src/otclient/core/game.cpp index 5e879831..8c3e1777 100644 --- a/src/otclient/core/game.cpp +++ b/src/otclient/core/game.cpp @@ -333,7 +333,7 @@ void Game::talkPrivate(int channelType, const std::string& receiver, const std:: m_protocolGame->sendTalk(channelType, 0, receiver, message); } -void Game::inviteToParty(int creatureId) +void Game::partyInvite(int creatureId) { if(!m_online || !checkBotProtection()) return; @@ -341,6 +341,47 @@ void Game::inviteToParty(int creatureId) m_protocolGame->sendInviteToParty(creatureId); } +void Game::partyJoin(int creatureId) +{ + if(!m_online || !checkBotProtection()) + return; + + m_protocolGame->sendJoinParty(creatureId); +} + +void Game::partyRevokeInvitation(int creatureId) +{ + if(!m_online || !checkBotProtection()) + return; + + m_protocolGame->sendRevokeInvitation(creatureId); +} + + +void Game::partyPassLeadership(int creatureId) +{ + if(!m_online || !checkBotProtection()) + return; + + m_protocolGame->sendPassLeadership(creatureId); +} + +void Game::partyLeave() +{ + if(!m_online || !checkBotProtection()) + return; + + m_protocolGame->sendLeaveParty(); +} + +void Game::partyShareExperience(bool active) +{ + if(!m_online || !checkBotProtection()) + return; + + m_protocolGame->sendShareExperience(active, 0); +} + void Game::openOutfitWindow() { if(!m_online || !checkBotProtection()) diff --git a/src/otclient/core/game.h b/src/otclient/core/game.h index ee377611..4e1a1bc9 100644 --- a/src/otclient/core/game.h +++ b/src/otclient/core/game.h @@ -65,7 +65,12 @@ public: void talk(const std::string& message); void talkChannel(int channelType, int channelId, const std::string& message); void talkPrivate(int channelType, const std::string& receiver, const std::string& message); - void inviteToParty(int creatureId); + void partyInvite(int creatureId); + void partyJoin(int creatureId); + void partyRevokeInvitation(int creatureId); + void partyPassLeadership(int creatureId); + void partyLeave(); + void partyShareExperience(bool active); void openOutfitWindow(); void setOutfit(const Outfit& outfit); void addVip(const std::string& name); diff --git a/src/otclient/luafunctions.cpp b/src/otclient/luafunctions.cpp index 99621f35..a13d4f8b 100644 --- a/src/otclient/luafunctions.cpp +++ b/src/otclient/luafunctions.cpp @@ -122,6 +122,7 @@ void OTClient::registerLuaFunctions() g_lua.registerClass(); g_lua.bindClassMemberFunction("getName", &Creature::getName); + g_lua.bindClassMemberFunction("getShield", &Creature::getShield); g_lua.bindClassMemberFunction("setOutfit", &Creature::setOutfit); g_lua.bindClassMemberFunction("getOutfit", &Creature::getOutfit); g_lua.bindClassMemberFunction("setSkullTexture", &Creature::setSkullTexture); @@ -183,7 +184,14 @@ void OTClient::registerLuaFunctions() g_lua.bindClassStaticFunction("follow", std::bind(&Game::follow, &g_game, _1)); g_lua.bindClassStaticFunction("cancelFollow", std::bind(&Game::cancelFollow, &g_game)); g_lua.bindClassStaticFunction("rotate", std::bind(&Game::rotate, &g_game, _1)); - g_lua.bindClassStaticFunction("inviteToParty", std::bind(&Game::inviteToParty, &g_game, _1)); + + g_lua.bindClassStaticFunction("partyInvite", std::bind(&Game::partyInvite, &g_game, _1)); + g_lua.bindClassStaticFunction("partyJoin", std::bind(&Game::partyJoin, &g_game, _1)); + g_lua.bindClassStaticFunction("partyRevokeInvitation", std::bind(&Game::partyRevokeInvitation, &g_game, _1)); + g_lua.bindClassStaticFunction("partyPassLeadership", std::bind(&Game::partyPassLeadership, &g_game, _1)); + g_lua.bindClassStaticFunction("partyLeave", std::bind(&Game::partyLeave, &g_game)); + g_lua.bindClassStaticFunction("partyShareExperience", std::bind(&Game::partyShareExperience, &g_game, _1)); + g_lua.bindClassStaticFunction("addVip", std::bind(&Game::addVip, &g_game, _1)); g_lua.bindClassStaticFunction("removeVip", std::bind(&Game::removeVip, &g_game, _1)); g_lua.bindClassStaticFunction("talk", std::bind(&Game::talk, &g_game, _1));