bind lua functions for questlog/npc trade/trade/channels/text edit/list edit/containers

This commit is contained in:
Eduardo Bart 2012-02-09 01:45:19 -02:00
parent 55fbb5f1a6
commit a8c9980a5c
16 changed files with 679 additions and 365 deletions

5
TODO
View File

@ -28,7 +28,7 @@ use hardware buffer
use indices use indices
fix opacity and cached framebuffers conflict fix opacity and cached framebuffers conflict
map zoom rendering could be optimized using framebuffer caches map zoom rendering could be optimized using framebuffer caches
make low/medium/high settings for economizing graphics memory thus allowing client smoothily in smartphones make low/medium/high settings for economizing graphics memory thus allowing to run the client smoothily in smartphones
== Lua == Lua
make possible to bind non LuaObject derived classes on lua engine (for usage with Point,Rect,Color,Size) make possible to bind non LuaObject derived classes on lua engine (for usage with Point,Rect,Color,Size)
@ -41,7 +41,6 @@ port to MacOs and iphone
multiline rich text widget multiline rich text widget
move layout proprieties to widget style move layout proprieties to widget style
multiline text editor widget multiline text editor widget
rework UIMessageBox, UIToolTip and UIInputBox
fix style inheretance using a style translator fix style inheretance using a style translator
find a way to add new widgets without focusing them find a way to add new widgets without focusing them
review UI/style loader and make more error prone with more warnings review UI/style loader and make more error prone with more warnings
@ -57,7 +56,6 @@ cache or preload otui files to avoid freezes because of hd reading
change Align/Anchors lua API from enum to text change Align/Anchors lua API from enum to text
== Client == Client
make possible to reload modules
fix modules recursivity, it makes client crash fix modules recursivity, it makes client crash
implement left panel with dragging windows implement left panel with dragging windows
clean sprites cache periodically clean sprites cache periodically
@ -79,4 +77,3 @@ edit texts
trade window trade window
shop window shop window
battle window battle window
hotkeys window

View File

@ -54,7 +54,7 @@ function Containers.onOpenContainer(containerId, itemId, name, capacity, hasPare
m_containers[containerId] = container m_containers[containerId] = container
end end
function Containers.onContainerClose(containerId) function Containers.onCloseContainer(containerId)
local container = m_containers[containerId] local container = m_containers[containerId]
if container then if container then
g_game.gameRightPanel:removeChild(container) g_game.gameRightPanel:removeChild(container)
@ -131,7 +131,7 @@ end
connect(g_game, { onGameStart = Containers.clean, connect(g_game, { onGameStart = Containers.clean,
onGameEnd = Containers.clean, onGameEnd = Containers.clean,
onOpenContainer = Containers.onOpenContainer, onOpenContainer = Containers.onOpenContainer,
onContainerClose = Containers.onContainerClose, onCloseContainer = Containers.onCloseContainer,
onContainerAddItem = Containers.onContainerAddItem, onContainerAddItem = Containers.onContainerAddItem,
onContainerUpdateItem = Containers.onContainerUpdateItem, onContainerUpdateItem = Containers.onContainerUpdateItem,
onContainerRemoveItem = Containers.onContainerRemoveItem }) onContainerRemoveItem = Containers.onContainerRemoveItem })

View File

@ -36,12 +36,12 @@ function HealthBar.toggle()
end end
-- hooked events -- hooked events
function HealthBar.onHealthChange(health, maxHealth) function HealthBar.onHealthChange(localPlayer, health, maxHealth)
healthLabel:setText(health .. ' / ' .. maxHealth) healthLabel:setText(health .. ' / ' .. maxHealth)
healthBar:setPercent(health / maxHealth * 100) healthBar:setPercent(health / maxHealth * 100)
end end
function HealthBar.onManaChange(mana, maxMana) function HealthBar.onManaChange(localPlayer, mana, maxMana)
manaLabel:setText(mana .. ' / ' .. maxMana) manaLabel:setText(mana .. ' / ' .. maxMana)
local percent local percent
@ -54,6 +54,6 @@ function HealthBar.onManaChange(mana, maxMana)
end end
connect(g_game, { onGameStart = HealthBar.create, connect(g_game, { onGameStart = HealthBar.create,
onGameEnd = HealthBar.destroy, onGameEnd = HealthBar.destroy })
onHealthChange = HealthBar.onHealthChange, connect(LocalPlayer, { onHealthChange = HealthBar.onHealthChange,
onManaChange = HealthBar.onManaChange }) onManaChange = HealthBar.onManaChange })

View File

@ -75,32 +75,32 @@ function Skills.onSkillButtonClick(button)
end end
-- hooked events -- hooked events
function Skills.onExperienceChange(value) function Skills.onExperienceChange(localPlayer, value)
setSkillValue('experience', getNumberString(value)) setSkillValue('experience', getNumberString(value))
end end
function Skills.onLevelChange(value, percent) function Skills.onLevelChange(localPlayer, value, percent)
setSkillValue('level', getNumberString(value)) setSkillValue('level', getNumberString(value))
setSkillPercent('level', percent, 'You have ' .. (100 - percent) .. ' percent to go') setSkillPercent('level', percent, 'You have ' .. (100 - percent) .. ' percent to go')
end end
function Skills.onHealthChange(health, maxHealth) function Skills.onHealthChange(localPlayer, health, maxHealth)
setSkillValue('health', getNumberString(health)) setSkillValue('health', getNumberString(health))
end end
function Skills.onManaChange(mana, maxMana) function Skills.onManaChange(localPlayer, mana, maxMana)
setSkillValue('mana', getNumberString(mana)) setSkillValue('mana', getNumberString(mana))
end end
function Skills.onSoulChange(soul) function Skills.onSoulChange(localPlayer, soul)
setSkillValue('soul', soul) setSkillValue('soul', soul)
end end
function Skills.onFreeCapacityChange(freeCapacity) function Skills.onFreeCapacityChange(localPlayer, freeCapacity)
setSkillValue('capacity', freeCapacity) setSkillValue('capacity', freeCapacity)
end end
function Skills.onStaminaChange(stamina) function Skills.onStaminaChange(localPlayer, stamina)
local hours = math.floor(stamina / 60) local hours = math.floor(stamina / 60)
local minutes = stamina % 60 local minutes = stamina % 60
if minutes < 10 then if minutes < 10 then
@ -112,18 +112,20 @@ function Skills.onStaminaChange(stamina)
setSkillPercent('stamina', percent, 'You have ' .. percent .. ' percent') setSkillPercent('stamina', percent, 'You have ' .. percent .. ' percent')
end end
function Skills.onMagicLevelChange(value, percent) function Skills.onMagicLevelChange(localPlayer, value, percent)
setSkillValue('magiclevel', value) setSkillValue('magiclevel', value)
setSkillPercent('magiclevel', percent, 'You have ' .. (100 - percent) .. ' percent to go') setSkillPercent('magiclevel', percent, 'You have ' .. (100 - percent) .. ' percent to go')
end end
function Skills.onSkillChange(id, level, percent) function Skills.onSkillChange(localPlayer, id, level, percent)
setSkillValue('skillId' .. id, level) setSkillValue('skillId' .. id, level)
setSkillPercent('skillId' .. id, percent, 'You have ' .. (100 - percent) .. ' percent to go') setSkillPercent('skillId' .. id, percent, 'You have ' .. (100 - percent) .. ' percent to go')
end end
connect(g_game, { onGameStart = Skills.create, connect(g_game, { onGameStart = Skills.create,
onGameEnd = Skills.destroy, onGameEnd = Skills.destroy })
connect(LocalPlayer, {
onExperienceChange = Skills.onExperienceChange, onExperienceChange = Skills.onExperienceChange,
onLevelChange = Skills.onLevelChange, onLevelChange = Skills.onLevelChange,
onHealthChange = Skills.onHealthChange, onHealthChange = Skills.onHealthChange,

View File

@ -154,12 +154,6 @@ namespace Otc
LastSkill LastSkill
}; };
enum SkillType {
SkillLevel = 0,
SkillPercent,
LastSkillType
};
enum Direction { enum Direction {
North = 0, North = 0,
East, East,
@ -246,7 +240,7 @@ namespace Otc
EmblemBlue EmblemBlue
}; };
enum PlayerIcons { enum PlayerStates {
IconNone = 0, IconNone = 0,
IconPoison = 1, IconPoison = 1,
IconBurn = 2, IconBurn = 2,

View File

@ -38,9 +38,9 @@ public:
}; };
Creature(); Creature();
virtual ~Creature() { }
virtual void draw(const Point& dest, float scaleFactor, bool animate); virtual void draw(const Point& dest, float scaleFactor, bool animate);
void internalDrawOutfit(const Point& dest, float scaleFactor, bool animateWalk, bool animateIdle, Otc::Direction direction); void internalDrawOutfit(const Point& dest, float scaleFactor, bool animateWalk, bool animateIdle, Otc::Direction direction);
void drawOutfit(const Rect& destRect, bool resize); void drawOutfit(const Rect& destRect, bool resize);
void drawInformation(const Point& point, bool useGray, const Rect& parentRect); void drawInformation(const Point& point, bool useGray, const Rect& parentRect);

View File

@ -146,69 +146,6 @@ void Game::processPing()
g_lua.callGlobalField("g_game", "onPing"); g_lua.callGlobalField("g_game", "onPing");
} }
void Game::processPlayerStats(double health, double maxHealth,
double freeCapacity, double experience,
double level, double levelPercent,
double mana, double maxMana,
double magicLevel, double magicLevelPercent,
double soul, double stamina)
{
if(m_localPlayer->getHealth() != health ||
m_localPlayer->getMaxHealth() != maxHealth) {
m_localPlayer->setStatistic(Otc::Health, health);
m_localPlayer->setStatistic(Otc::MaxHealth, maxHealth);
g_lua.callGlobalField("g_game", "onHealthChange", health, maxHealth);
// cannot walk while dying
if(health == 0) {
if(m_localPlayer->isPreWalking())
m_localPlayer->stopWalk();
m_localPlayer->lockWalk();
}
}
if(m_localPlayer->getStatistic(Otc::FreeCapacity) != freeCapacity) {
m_localPlayer->setStatistic(Otc::FreeCapacity, freeCapacity);
g_lua.callGlobalField("g_game", "onFreeCapacityChange", freeCapacity);
}
if(m_localPlayer->getStatistic(Otc::Experience) != experience) {
m_localPlayer->setStatistic(Otc::Experience, experience);
g_lua.callGlobalField("g_game", "onExperienceChange", experience);
}
if(m_localPlayer->getStatistic(Otc::Level) != level ||
m_localPlayer->getStatistic(Otc::LevelPercent) != levelPercent) {
m_localPlayer->setStatistic(Otc::Level, level);
m_localPlayer->setStatistic(Otc::LevelPercent, levelPercent);
g_lua.callGlobalField("g_game", "onLevelChange", level, levelPercent);
}
if(m_localPlayer->getStatistic(Otc::Mana) != mana ||
m_localPlayer->getStatistic(Otc::MaxMana) != maxMana) {
m_localPlayer->setStatistic(Otc::Mana, mana);
m_localPlayer->setStatistic(Otc::MaxMana, maxMana);
g_lua.callGlobalField("g_game", "onManaChange", mana, maxMana);
}
if(m_localPlayer->getStatistic(Otc::MagicLevel) != magicLevel ||
m_localPlayer->getStatistic(Otc::MagicLevelPercent) != magicLevelPercent) {
m_localPlayer->setStatistic(Otc::MagicLevel, magicLevel);
m_localPlayer->setStatistic(Otc::MagicLevelPercent, magicLevelPercent);
g_lua.callGlobalField("g_game", "onMagicLevelChange", magicLevel, magicLevelPercent);
}
if(m_localPlayer->getStatistic(Otc::Soul) != soul) {
m_localPlayer->setStatistic(Otc::Soul, soul);
g_lua.callGlobalField("g_game", "onSoulChange", soul);
}
if(m_localPlayer->getStatistic(Otc::Stamina) != stamina) {
m_localPlayer->setStatistic(Otc::Stamina, stamina);
g_lua.callGlobalField("g_game", "onStaminaChange", stamina);
}
}
void Game::processTextMessage(const std::string& type, const std::string& message) void Game::processTextMessage(const std::string& type, const std::string& message)
{ {
g_lua.callGlobalField("g_game","onTextMessage", type, message); g_lua.callGlobalField("g_game","onTextMessage", type, message);
@ -230,12 +167,27 @@ void Game::processOpenContainer(int containerId, int itemId, const std::string&
g_lua.callGlobalField("g_game", "onOpenContainer", containerId, itemId, name, capacity, hasParent, items); g_lua.callGlobalField("g_game", "onOpenContainer", containerId, itemId, name, capacity, hasParent, items);
} }
void Game::processCloseContainer(int containerId)
{
g_lua.callGlobalField("g_game", "onCloseContainer", containerId);
}
void Game::processContainerAddItem(int containerId, const ItemPtr& item) void Game::processContainerAddItem(int containerId, const ItemPtr& item)
{ {
item->setPosition(Position(65535, containerId + 0x40, 0)); item->setPosition(Position(65535, containerId + 0x40, 0));
g_lua.callGlobalField("g_game", "onContainerAddItem", containerId, item); g_lua.callGlobalField("g_game", "onContainerAddItem", containerId, item);
} }
void Game::processContainerUpdateItem(int containerId, int slot, const ItemPtr& item)
{
g_lua.callGlobalField("g_game", "onContainerUpdateItem", containerId, slot, item);
}
void Game::processContainerRemoveItem(int containerId, int slot)
{
g_lua.callGlobalField("g_game", "onContainerRemoveItem", containerId, slot);
}
void Game::processInventoryChange(int slot, const ItemPtr& item) void Game::processInventoryChange(int slot, const ItemPtr& item)
{ {
if(item) if(item)
@ -261,6 +213,95 @@ void Game::processCreatureTeleport(const CreaturePtr& creature)
m_localPlayer->lockWalk(); m_localPlayer->lockWalk();
} }
void Game::processChannelList(const std::vector<std::tuple<int, std::string>>& channelList)
{
g_lua.callGlobalField("g_game", "onChannelList", channelList);
}
void Game::processOpenChannel(int channelId, const std::string& name)
{
g_lua.callGlobalField("g_game", "onOpenChannel", channelId, name);
}
void Game::processOpenPrivateChannel(const std::string& name)
{
g_lua.callGlobalField("g_game", "onOpenPrivateChannel", name);
}
void Game::processOpenOwnPrivateChannel(int channelId, const std::string& name)
{
g_lua.callGlobalField("g_game", "onOpenOwnPrivateChannel", channelId, name);
}
void Game::processCloseChannel(int channelId)
{
g_lua.callGlobalField("g_game", "onCloseChannel", channelId);
}
void Game::processVipAdd(uint id, const std::string& name, bool online)
{
g_lua.callGlobalField("g_game", "onAddVip", id, name, online);
}
void Game::processVipStateChange(uint id, bool online)
{
g_lua.callGlobalField("g_game", "onVipStateChange", id, online);
}
void Game::processOpenOutfitWindow(const Outfit& currentOufit, const std::vector<std::tuple<int, std::string, int>>& outfitList)
{
CreaturePtr virtualCreature = CreaturePtr(new Creature);
virtualCreature->setDirection(Otc::South);
virtualCreature->setOutfit(currentOufit);
g_lua.callGlobalField("g_game", "onOpenOutfitWindow", virtualCreature, outfitList);
}
void Game::processOpenNpcTrade(const std::vector<std::tuple<ItemPtr, std::string, int, int, int>>& items)
{
g_lua.callGlobalField("g_game", "onOpenNpcTrade", items);
}
void Game::processPlayerGoods(int money, const std::vector<std::tuple<ItemPtr, int>>& goods)
{
g_lua.callGlobalField("g_game", "onPlayerGoods", goods);
}
void Game::processCloseNpcTrade()
{
g_lua.callGlobalField("g_game", "onCloseNpcTrade");
}
void Game::processOpenTrade(const std::string& name, const std::vector<ItemPtr>& items)
{
g_lua.callGlobalField("g_game", "onOpenTrade", name, items);
}
void Game::processCloseTrade()
{
g_lua.callGlobalField("g_game", "onCloseTrade");
}
void Game::processEditText(int id, int itemId, int maxLength, const std::string& text, const std::string& writter, const std::string& date)
{
g_lua.callGlobalField("g_game", "onEditText", id, itemId, maxLength, text, writter, date);
}
void Game::processEditList(int listId, int id, const std::string& text)
{
g_lua.callGlobalField("g_game", "onEditList", listId, id, text);
}
void Game::processQuestLog(const std::vector<std::tuple<int, std::string, bool>>& questList)
{
g_lua.callGlobalField("g_game", "onQuestLog", questList);
}
void Game::processQuestLine(int questId, const std::vector<std::tuple<std::string, std::string>>& questMissions)
{
g_lua.callGlobalField("g_game", "onQuestLine", questId, questMissions);
}
void Game::processAttackCancel() void Game::processAttackCancel()
{ {
if(isAttacking()) if(isAttacking())
@ -688,7 +729,7 @@ void Game::addVip(const std::string& name)
void Game::removeVip(int playerId) void Game::removeVip(int playerId)
{ {
if(!isOnline() || !checkBotProtection()) if(!canPerformGameAction())
return; return;
m_protocolGame->sendRemoveVip(playerId); m_protocolGame->sendRemoveVip(playerId);
} }
@ -715,11 +756,95 @@ void Game::setSafeFight(bool on)
{ {
if(!canPerformGameAction()) if(!canPerformGameAction())
return; return;
m_safeFight = on; m_safeFight = on;
m_protocolGame->sendChangeFightModes(m_fightMode, m_chaseMode, m_safeFight); m_protocolGame->sendChangeFightModes(m_fightMode, m_chaseMode, m_safeFight);
} }
void Game::inspectNpcTrade(const ItemPtr& item)
{
if(!canPerformGameAction() || !item)
return;
m_protocolGame->sendInspectNpcTrade(item->getId(), item->getCount());
}
void Game::buyItem(const ItemPtr& item, int amount, bool ignoreCapacity, bool buyWithBackpack)
{
if(!canPerformGameAction() || !item)
return;
m_protocolGame->sendBuyItem(item->getId(), item->getCount(), amount, ignoreCapacity, buyWithBackpack);
}
void Game::sellItem(const ItemPtr& item, int amount, bool ignoreEquipped)
{
if(!canPerformGameAction() || !item)
return;
m_protocolGame->sendSellItem(item->getId(), item->getCount(), amount, ignoreEquipped);
}
void Game::closeNpcTrade()
{
if(!canPerformGameAction())
return;
m_protocolGame->sendCloseNpcTrade();
}
void Game::requestTrade(const ItemPtr& item, const CreaturePtr& creature)
{
if(!canPerformGameAction())
return;
m_protocolGame->sendRequestTrade(item->getPosition(), item->getId(), item->getStackpos(), creature->getId());
}
void Game::inspectTrade(bool counterOffer, int index)
{
if(!canPerformGameAction())
return;
m_protocolGame->sendInspectTrade(counterOffer, index);
}
void Game::acceptTrade()
{
if(!canPerformGameAction())
return;
m_protocolGame->sendAcceptTrade();
}
void Game::rejectTrade()
{
if(!canPerformGameAction())
return;
m_protocolGame->sendRejectTrade();
}
void Game::editText(uint id, const std::string& text)
{
if(!canPerformGameAction())
return;
m_protocolGame->sendEditText(id, text);
}
void Game::editList(int listId, uint id, const std::string& text)
{
if(!canPerformGameAction())
return;
m_protocolGame->sendEditList(listId, id, text);
}
void Game::requestQuestLog()
{
if(!canPerformGameAction())
return;
m_protocolGame->sendRequestQuestLog();
}
void Game::requestQuestLine(int questId)
{
if(!canPerformGameAction())
return;
m_protocolGame->sendRequestQuestLine(questId);
}
bool Game::checkBotProtection() bool Game::checkBotProtection()
{ {
#ifdef BOT_PROTECTION #ifdef BOT_PROTECTION

View File

@ -38,66 +38,6 @@ private:
void resetGameStates(); void resetGameStates();
protected: protected:
/*
void parseMapDescription(InputMessage& msg);
void parseMapMoveNorth(InputMessage& msg);
void parseMapMoveEast(InputMessage& msg);
void parseMapMoveSouth(InputMessage& msg);
void parseMapMoveWest(InputMessage& msg);
void parseUpdateTile(InputMessage& msg);
void parseTileAddThing(InputMessage& msg);
void parseTileTransformThing(InputMessage& msg);
void parseTileRemoveThing(InputMessage& msg);
void parseCreatureMove(InputMessage& msg);
void parseOpenContainer(InputMessage& msg);
void parseCloseContainer(InputMessage& msg);
void parseContainerAddItem(InputMessage& msg);
void parseContainerUpdateItem(InputMessage& msg);
void parseContainerRemoveItem(InputMessage& msg);
void parseAddInventoryItem(InputMessage& msg);
void parseRemoveInventoryItem(InputMessage& msg);
void parseNpcOffer(InputMessage& msg);
void parsePlayerCash(InputMessage& msg);
void parseCloseShopWindow(InputMessage&);
void parseWorldLight(InputMessage& msg);
void parseMagicEffect(InputMessage& msg);
void parseAnimatedText(InputMessage& msg);
void parseDistanceMissile(InputMessage& msg);
void parseCreatureSquare(InputMessage& msg);
void parseCreatureHealth(InputMessage& msg);
void parseCreatureLight(InputMessage& msg);
void parseCreatureOutfit(InputMessage& msg);
void parseCreatureSpeed(InputMessage& msg);
void parseCreatureSkulls(InputMessage& msg);
void parseCreatureShields(InputMessage& msg);
void parseCreatureTurn(InputMessage& msg);
void parseItemTextWindow(InputMessage& msg);
void parseHouseTextWindow(InputMessage& msg);
void parsePlayerStats(InputMessage& msg);
void parsePlayerSkills(InputMessage& msg);
void parsePlayerIcons(InputMessage& msg);
void parsePlayerCancelAttack(InputMessage& msg);
void parseCreatureSpeak(InputMessage& msg);
void parseCloseChannel(InputMessage& msg);
void parseSafeTradeRequest(InputMessage& msg);
void parseSafeTradeClose(InputMessage&);
void parseTextMessage(InputMessage& msg);
void parseCancelWalk(InputMessage& msg);
void parseFloorChangeUp(InputMessage& msg);
void parseFloorChangeDown(InputMessage& msg);
void parseOutfitWindow(InputMessage& msg);
void parseShowTutorial(InputMessage& msg);
void parseAddMarker(InputMessage& msg);
*/
void processConnectionError(const boost::system::error_code& error); void processConnectionError(const boost::system::error_code& error);
void processDisconnect(); void processDisconnect();
void processPing(); void processPing();
@ -119,11 +59,6 @@ protected:
double mana, double maxMana, double mana, double maxMana,
double magicLevel, double magicLevelPercent, double magicLevel, double magicLevelPercent,
double soul, double stamina); double soul, double stamina);
void processTextMessage(const std::string& type, const std::string& message);
void processCreatureSpeak(const std::string& name, int level, Otc::SpeakType type, const std::string& message, int channelId, const Position& creaturePos);
void processOpenContainer(int containerId, int itemId, const std::string& name, int capacity, bool hasParent, const std::vector<ItemPtr>& items);
void processContainerAddItem(int containerId, const ItemPtr& item);
void processInventoryChange(int slot, const ItemPtr& item); void processInventoryChange(int slot, const ItemPtr& item);
void processCreatureMove(const CreaturePtr& creature, const Position& oldPos, const Position& newPos); void processCreatureMove(const CreaturePtr& creature, const Position& oldPos, const Position& newPos);
@ -131,18 +66,47 @@ protected:
void processAttackCancel(); void processAttackCancel();
void processWalkCancel(Otc::Direction direction); void processWalkCancel(Otc::Direction direction);
// processChannelList // message related
// processOpenChannel void processTextMessage(const std::string& type, const std::string& message);
// processOpenPrivateChannel void processCreatureSpeak(const std::string& name, int level, Otc::SpeakType type, const std::string& message, int channelId, const Position& creaturePos);
// processOpenOwnPrivateChannel
// vip // container related
// processVipList void processOpenContainer(int containerId, int itemId, const std::string& name, int capacity, bool hasParent, const std::vector<ItemPtr>& items);
// processVipLogin void processCloseContainer(int containerId);
// processVipLogout void processContainerAddItem(int containerId, const ItemPtr& item);
void processContainerUpdateItem(int containerId, int slot, const ItemPtr& item);
void processContainerRemoveItem(int containerId, int slot);
// processQuestLog // channel related
// processQuestLine void processChannelList(const std::vector<std::tuple<int, std::string>>& channelList);
void processOpenChannel(int channelId, const std::string& name);
void processOpenPrivateChannel(const std::string& name);
void processOpenOwnPrivateChannel(int channelId, const std::string& name);
void processCloseChannel(int channelId);
// vip related
void processVipAdd(uint id, const std::string& name, bool online);
void processVipStateChange(uint id, bool online);
// outfit
void processOpenOutfitWindow(const Outfit& currentOufit, const std::vector<std::tuple<int, std::string, int>>& outfitList);
// npc trade
void processOpenNpcTrade(const std::vector<std::tuple<ItemPtr, std::string, int, int, int>>& items);
void processPlayerGoods(int money, const std::vector<std::tuple<ItemPtr, int>>& goods);
void processCloseNpcTrade();
// player trade
void processOpenTrade(const std::string& name, const std::vector<ItemPtr>& items);
void processCloseTrade();
// edit text/list
void processEditText(int id, int itemId, int maxLength, const std::string& text, const std::string& writter, const std::string& date);
void processEditList(int listId, int id, const std::string& text);
// questlog
void processQuestLog(const std::vector<std::tuple<int, std::string, bool>>& questList);
void processQuestLine(int questId, const std::vector<std::tuple<std::string, std::string>>& questMissions);
friend class ProtocolGame; friend class ProtocolGame;
friend class Map; friend class Map;
@ -225,24 +189,24 @@ public:
bool isSafeFight() { return m_safeFight; } bool isSafeFight() { return m_safeFight; }
// npc trade related // npc trade related
//void inspectNpcTrade(); void inspectNpcTrade(const ItemPtr& item);
//void buyItem(); void buyItem(const ItemPtr& item, int amount, bool ignoreCapacity, bool buyWithBackpack);
//void sellItem(); void sellItem(const ItemPtr& item, int amount, bool ignoreEquipped);
//void closeNpcTrade(); void closeNpcTrade();
// player trade related // player trade related
//void requestTrade(); void requestTrade(const ItemPtr& item, const CreaturePtr& creature);
//void inspectTrade(); void inspectTrade(bool counterOffer, int index);
//void acceptTrade(); void acceptTrade();
//void rejectTrade(); void rejectTrade();
// house window and editable items related // house window and editable items related
//void editText(); void editText(uint id, const std::string& text);
//void editList(); void editList(int listId, uint id, const std::string& text);
// questlog related // questlog related
//void requestQuestLog(); void requestQuestLog();
//void requestQuestLogLine(); void requestQuestLine(int questId);
bool canPerformGameAction(); bool canPerformGameAction();
bool checkBotProtection(); bool checkBotProtection();

View File

@ -39,12 +39,11 @@ Item::Item() : Thing()
ItemPtr Item::create(int id) ItemPtr Item::create(int id)
{ {
if(id < g_thingsType.getFirstItemId() || id > g_thingsType.getMaxItemid()) {
logTraceError("invalid item id ", id);
return nullptr;
}
ItemPtr item = ItemPtr(new Item); ItemPtr item = ItemPtr(new Item);
item->setId(id); if(id < g_thingsType.getFirstItemId() || id > g_thingsType.getMaxItemid())
logTraceError("invalid item id ", id);
else
item->setId(id);
return item; return item;
} }

View File

@ -28,13 +28,26 @@
LocalPlayer::LocalPlayer() LocalPlayer::LocalPlayer()
{ {
m_preWalking = false; m_preWalking = false;
m_known = false;
m_walkLocked = false; m_walkLocked = false;
m_lastPrewalkDone = true; m_lastPrewalkDone = true;
m_icons = 0; m_known = false;
m_states = 0;
for(int i = 0; i < Otc::LastStatistic; ++i) m_skillsLevel.fill(-1);
m_statistics[i] = -1; // sets an invalid value to ensure lua event will be sent m_skillsLevelPercent.fill(-1);
m_health = -1;
m_maxHealth = -1;
m_freeCapacity = -1;
m_experience = -1;
m_level = -1;
m_levelPercent = -1;
m_mana = -1;
m_maxMana = -1;
m_magicLevel = -1;
m_magicLevelPercent = -1;
m_soul = -1;
m_stamina = -1;
} }
void LocalPlayer::lockWalk() void LocalPlayer::lockWalk()
@ -47,6 +60,28 @@ void LocalPlayer::lockWalk()
m_walkLockTimer.restart(); m_walkLockTimer.restart();
} }
bool LocalPlayer::canWalk(Otc::Direction direction)
{
// prewalk has a timeout, because for some reason that I don't know yet the server sometimes doesn't answer the prewalk
bool prewalkTimeouted = m_walking && m_preWalking && m_walkTimer.ticksElapsed() >= m_walkInterval + PREWALK_TIMEOUT;
// cannot walk while already walking
if(m_walking && !prewalkTimeouted)
return false;
// avoid doing more walks than wanted when receiving a lot of walks from server
if(!m_lastPrewalkDone && m_preWalking && !prewalkTimeouted)
return false;
// cannot walk while locked
if(m_walkLocked && m_walkLockTimer.ticksElapsed() <= WALK_LOCK_INTERVAL)
return false;
else
m_walkLocked = false;
return true;
}
void LocalPlayer::walk(const Position& oldPos, const Position& newPos) void LocalPlayer::walk(const Position& oldPos, const Position& newPos)
{ {
Otc::Direction direction = oldPos.getDirectionFromPosition(newPos); Otc::Direction direction = oldPos.getDirectionFromPosition(newPos);
@ -76,28 +111,6 @@ void LocalPlayer::preWalk(Otc::Direction direction)
Creature::walk(m_position, newPos); Creature::walk(m_position, newPos);
} }
bool LocalPlayer::canWalk(Otc::Direction direction)
{
// prewalk has a timeout, because for some reason that I don't know yet the server sometimes doesn't answer the prewalk
bool prewalkTimeouted = m_walking && m_preWalking && m_walkTimer.ticksElapsed() >= m_walkInterval + PREWALK_TIMEOUT;
// cannot walk while already walking
if(m_walking && !prewalkTimeouted)
return false;
// avoid doing more walks than wanted when receiving a lot of walks from server
if(!m_lastPrewalkDone && m_preWalking && !prewalkTimeouted)
return false;
// cannot walk while locked
if(m_walkLocked && m_walkLockTimer.ticksElapsed() <= WALK_LOCK_INTERVAL)
return false;
else
m_walkLocked = false;
return true;
}
void LocalPlayer::cancelWalk(Otc::Direction direction) void LocalPlayer::cancelWalk(Otc::Direction direction)
{ {
// only cancel client side walks // only cancel client side walks
@ -156,3 +169,120 @@ void LocalPlayer::terminateWalk()
Creature::terminateWalk(); Creature::terminateWalk();
m_preWalking = false; m_preWalking = false;
} }
void LocalPlayer::setStates(int states)
{
if(m_states != states) {
int oldStates = m_states;
m_states = states;
callLuaField("onStatesChange", states, oldStates);
}
}
void LocalPlayer::setSkill(Otc::Skill skill, int level, int levelPercent)
{
int oldLevel = m_skillsLevel[skill];
int oldLevelPercent = m_skillsLevelPercent[skill];
if(level != oldLevel && levelPercent != oldLevelPercent) {
m_skillsLevel[skill] = level;
m_skillsLevelPercent[skill] = levelPercent;
callLuaField("onSkillChange", skill, level, levelPercent, oldLevel, oldLevelPercent);
}
}
void LocalPlayer::setHealth(double health, double maxHealth)
{
if(m_health != health || m_maxHealth != maxHealth) {
double oldHealth = m_health;
double oldMaxHealth = m_maxHealth;
m_health = health;
m_maxHealth = maxHealth;
callLuaField("onHealthChange", health, maxHealth, oldHealth, oldMaxHealth);
// cannot walk while dying
if(health == 0) {
if(isPreWalking())
stopWalk();
lockWalk();
}
}
}
void LocalPlayer::setFreeCapacity(double freeCapacity)
{
if(m_freeCapacity != freeCapacity) {
double oldFreeCapacity = m_freeCapacity;
m_freeCapacity = freeCapacity;
callLuaField("onFreeCapacityChange", freeCapacity, oldFreeCapacity);
}
}
void LocalPlayer::setExperience(double experience)
{
if(m_experience != experience) {
double oldExperience = m_experience;
m_experience = experience;
callLuaField("onExperienceChange", experience, oldExperience);
}
}
void LocalPlayer::setLevel(double level, double levelPercent)
{
if(m_level != level || m_levelPercent != m_levelPercent) {
double oldLevel = m_level;
double oldLevelPercent = m_levelPercent;
m_level = level;
m_levelPercent = levelPercent;
callLuaField("onLevelChange", level, levelPercent, oldLevel, oldLevelPercent);
}
}
void LocalPlayer::setMana(double mana, double maxMana)
{
if(m_mana != mana || m_maxMana != maxMana) {
double oldMana = m_mana;
double oldMaxMana;
m_mana = mana;
m_maxMana = maxMana;
callLuaField("onManaChange", mana, maxMana, oldMana, oldMaxMana);
}
}
void LocalPlayer::setMagicLevel(double magicLevel, double magicLevelPercent)
{
if(m_magicLevel != magicLevel || m_magicLevelPercent != magicLevelPercent) {
double oldMagicLevel = m_magicLevel;
double oldMagicLevelPercent = m_magicLevelPercent;
m_magicLevel = magicLevel;
m_magicLevelPercent = magicLevelPercent;
callLuaField("onMagicLevelChange", magicLevel, magicLevelPercent, oldMagicLevel, oldMagicLevelPercent);
}
}
void LocalPlayer::setSoul(double soul)
{
if(m_soul != soul) {
double oldSoul = m_soul;
m_soul = soul;
callLuaField("onSoulChange", soul, oldSoul);
}
}
void LocalPlayer::setStamina(double stamina)
{
if(m_stamina != stamina) {
double oldStamina = m_stamina;
m_stamina = stamina;
callLuaField("onStaminaChange", stamina, oldStamina);
}
}

View File

@ -31,43 +31,54 @@ class LocalPlayer : public Player
WALK_LOCK_INTERVAL = 250, WALK_LOCK_INTERVAL = 250,
PREWALK_TIMEOUT = 1000 PREWALK_TIMEOUT = 1000
}; };
public: public:
LocalPlayer(); LocalPlayer();
void setSkill(Otc::Skill skill, Otc::SkillType skillType, int value) { m_skills[skill][skillType] = value; } void unlockWalk() { m_walkLocked = false; }
void setStatistic(Otc::Statistic statistic, double value) { m_statistics[statistic] = value; } void lockWalk();
void setIcons(int icons) { m_icons = icons; } bool canWalk(Otc::Direction direction);
void setStates(int states);
void setSkill(Otc::Skill skill, int level, int levelPercent);
void setHealth(double health, double maxHealth);
void setFreeCapacity(double freeCapacity);
void setExperience(double experience);
void setLevel(double level, double levelPercent);
void setMana(double mana, double maxMana);
void setMagicLevel(double magicLevel, double magicLevelPercent);
void setSoul(double soul);
void setStamina(double stamina);
void setKnown(bool known) { m_known = known; } void setKnown(bool known) { m_known = known; }
int getSkill(Otc::Skill skill, Otc::SkillType skillType) { return m_skills[skill][skillType]; } int getStates() { return m_states; }
double getStatistic(Otc::Statistic statistic) { return m_statistics[statistic]; } int getSkillLevel(Otc::Skill skill) { return m_skillsLevel[skill]; }
int getIcons() { return m_icons; } int getSkillLevelPercent(Otc::Skill skill) { return m_skillsLevelPercent[skill]; }
double getHealth() { return m_health; }
double getMaxHealth() { return m_maxHealth; }
double getFreeCapacity() { return m_freeCapacity; }
double getExperience() { return m_experience; }
double getLevel() { return m_level; }
double getLevelPercent() { return m_levelPercent; }
double getMana() { return m_mana; }
double getMaxMana() { return m_maxMana; }
double getMagicLevel() { return m_magicLevel; }
double getMagicLevelPercent() { return m_magicLevelPercent; }
double getSoul() { return m_soul; }
double getStamina() { return m_stamina; }
bool isKnown() { return m_known; } bool isKnown() { return m_known; }
bool isPreWalking() { return m_preWalking; } bool isPreWalking() { return m_preWalking; }
void unlockWalk() { m_walkLocked = false; } LocalPlayerPtr asLocalPlayer() { return std::static_pointer_cast<LocalPlayer>(shared_from_this()); }
void lockWalk();
protected:
void walk(const Position& oldPos, const Position& newPos); void walk(const Position& oldPos, const Position& newPos);
void preWalk(Otc::Direction direction); void preWalk(Otc::Direction direction);
bool canWalk(Otc::Direction direction);
void cancelWalk(Otc::Direction direction = Otc::InvalidDirection); void cancelWalk(Otc::Direction direction = Otc::InvalidDirection);
void stopWalk(); void stopWalk();
LocalPlayerPtr asLocalPlayer() { return std::static_pointer_cast<LocalPlayer>(shared_from_this()); } friend class Game;
double getHealth() { return getStatistic(Otc::Health); }
double getMaxHealth() { return getStatistic(Otc::MaxHealth); }
double getFreeCapacity() { return getStatistic(Otc::FreeCapacity); }
double getExperience() { return getStatistic(Otc::Experience); }
double getLevel() { return getStatistic(Otc::Level); }
double getLevelPercent() { return getStatistic(Otc::LevelPercent); }
double getMana() { return getStatistic(Otc::Mana); }
double getMaxMana() { return getStatistic(Otc::MaxMana); }
double getMagicLevel() { return getStatistic(Otc::MagicLevel); }
double getMagicLevelPercent() { return getStatistic(Otc::MagicLevelPercent); }
double getSoul() { return getStatistic(Otc::Soul); }
double getStamina() { return getStatistic(Otc::Stamina); }
protected: protected:
void updateWalkOffset(int totalPixelsWalked); void updateWalkOffset(int totalPixelsWalked);
@ -82,10 +93,24 @@ private:
Position m_lastPrewalkDestionation; Position m_lastPrewalkDestionation;
Timer m_walkLockTimer; Timer m_walkLockTimer;
std::array<int, Otc::LastSkill> m_skillsLevel;
std::array<int, Otc::LastSkill> m_skillsLevelPercent;
bool m_known; bool m_known;
int m_icons; int m_states;
int m_skills[Otc::LastSkill][Otc::LastSkillType];
double m_statistics[Otc::LastStatistic]; double m_health;
double m_maxHealth;
double m_freeCapacity;
double m_experience;
double m_level;
double m_levelPercent;
double m_mana;
double m_maxMana;
double m_magicLevel;
double m_magicLevelPercent;
double m_soul;
double m_stamina;
}; };
#endif #endif

View File

@ -128,6 +128,18 @@ void OTClient::registerLuaFunctions()
g_lua.bindClassStaticFunction("g_game", "getChaseMode", std::bind(&Game::getChaseMode, &g_game)); g_lua.bindClassStaticFunction("g_game", "getChaseMode", std::bind(&Game::getChaseMode, &g_game));
g_lua.bindClassStaticFunction("g_game", "getFightMode", std::bind(&Game::getFightMode, &g_game)); g_lua.bindClassStaticFunction("g_game", "getFightMode", std::bind(&Game::getFightMode, &g_game));
g_lua.bindClassStaticFunction("g_game", "isSafeFight", std::bind(&Game::isSafeFight, &g_game)); g_lua.bindClassStaticFunction("g_game", "isSafeFight", std::bind(&Game::isSafeFight, &g_game));
g_lua.bindClassStaticFunction("g_game", "inspectNpcTrade", std::bind(&Game::inspectNpcTrade, &g_game, _1));
g_lua.bindClassStaticFunction("g_game", "buyItem", std::bind(&Game::buyItem, &g_game, _1, _2, _3, _4));
g_lua.bindClassStaticFunction("g_game", "sellItem", std::bind(&Game::sellItem, &g_game, _1, _2, _3));
g_lua.bindClassStaticFunction("g_game", "closeNpcTrade", std::bind(&Game::closeNpcTrade, &g_game));
g_lua.bindClassStaticFunction("g_game", "requestTrade", std::bind(&Game::requestTrade, &g_game, _1, _2));
g_lua.bindClassStaticFunction("g_game", "inspectTrade", std::bind(&Game::inspectTrade, &g_game, _1, _2));
g_lua.bindClassStaticFunction("g_game", "acceptTrade", std::bind(&Game::acceptTrade, &g_game));
g_lua.bindClassStaticFunction("g_game", "rejectTrade", std::bind(&Game::rejectTrade, &g_game));
g_lua.bindClassStaticFunction("g_game", "editText", std::bind(&Game::editText, &g_game, _1, _2));
g_lua.bindClassStaticFunction("g_game", "editList", std::bind(&Game::editList, &g_game, _1, _2, _3));
g_lua.bindClassStaticFunction("g_game", "requestQuestLog", std::bind(&Game::requestQuestLog, &g_game));
g_lua.bindClassStaticFunction("g_game", "requestQuestLine", std::bind(&Game::requestQuestLine, &g_game, _1));
g_lua.bindClassStaticFunction("g_game", "canPerformGameAction", std::bind(&Game::canPerformGameAction, &g_game)); g_lua.bindClassStaticFunction("g_game", "canPerformGameAction", std::bind(&Game::canPerformGameAction, &g_game));
g_lua.bindClassStaticFunction("g_game", "checkBotProtection", std::bind(&Game::checkBotProtection, &g_game)); g_lua.bindClassStaticFunction("g_game", "checkBotProtection", std::bind(&Game::checkBotProtection, &g_game));
g_lua.bindClassStaticFunction("g_game", "isOnline", std::bind(&Game::isOnline, &g_game)); g_lua.bindClassStaticFunction("g_game", "isOnline", std::bind(&Game::isOnline, &g_game));
@ -212,7 +224,25 @@ void OTClient::registerLuaFunctions()
g_lua.bindClassMemberFunction<Creature>("isWalking", &Creature::isWalking); g_lua.bindClassMemberFunction<Creature>("isWalking", &Creature::isWalking);
g_lua.registerClass<Npc, Creature>(); g_lua.registerClass<Npc, Creature>();
g_lua.registerClass<Monster, Creature>(); g_lua.registerClass<Monster, Creature>();
g_lua.registerClass<LocalPlayer, Player>(); g_lua.registerClass<LocalPlayer, Player>();
g_lua.bindClassMemberFunction<LocalPlayer>("unlockWalk", &LocalPlayer::unlockWalk);
g_lua.bindClassMemberFunction<LocalPlayer>("lockWalk", &LocalPlayer::lockWalk);
g_lua.bindClassMemberFunction<LocalPlayer>("canWalk", &LocalPlayer::canWalk);
g_lua.bindClassMemberFunction<LocalPlayer>("setStates", &LocalPlayer::setStates);
g_lua.bindClassMemberFunction<LocalPlayer>("setSkill", &LocalPlayer::setSkill);
g_lua.bindClassMemberFunction<LocalPlayer>("setHealth", &LocalPlayer::setHealth);
g_lua.bindClassMemberFunction<LocalPlayer>("setFreeCapacity", &LocalPlayer::setFreeCapacity);
g_lua.bindClassMemberFunction<LocalPlayer>("setExperience", &LocalPlayer::setExperience);
g_lua.bindClassMemberFunction<LocalPlayer>("setLevel", &LocalPlayer::setLevel);
g_lua.bindClassMemberFunction<LocalPlayer>("setMana", &LocalPlayer::setMana);
g_lua.bindClassMemberFunction<LocalPlayer>("setMagicLevel", &LocalPlayer::setMagicLevel);
g_lua.bindClassMemberFunction<LocalPlayer>("setSoul", &LocalPlayer::setSoul);
g_lua.bindClassMemberFunction<LocalPlayer>("setStamina", &LocalPlayer::setStamina);
g_lua.bindClassMemberFunction<LocalPlayer>("setKnown", &LocalPlayer::setKnown);
g_lua.bindClassMemberFunction<LocalPlayer>("getStates", &LocalPlayer::getStates);
g_lua.bindClassMemberFunction<LocalPlayer>("getSkillLevel", &LocalPlayer::getSkillLevel);
g_lua.bindClassMemberFunction<LocalPlayer>("getSkillLevelPercent", &LocalPlayer::getSkillLevelPercent);
g_lua.bindClassMemberFunction<LocalPlayer>("getHealth", &LocalPlayer::getHealth); g_lua.bindClassMemberFunction<LocalPlayer>("getHealth", &LocalPlayer::getHealth);
g_lua.bindClassMemberFunction<LocalPlayer>("getMaxHealth", &LocalPlayer::getMaxHealth); g_lua.bindClassMemberFunction<LocalPlayer>("getMaxHealth", &LocalPlayer::getMaxHealth);
g_lua.bindClassMemberFunction<LocalPlayer>("getFreeCapacity", &LocalPlayer::getFreeCapacity); g_lua.bindClassMemberFunction<LocalPlayer>("getFreeCapacity", &LocalPlayer::getFreeCapacity);
@ -225,6 +255,9 @@ void OTClient::registerLuaFunctions()
g_lua.bindClassMemberFunction<LocalPlayer>("getMagicLevelPercent", &LocalPlayer::getMagicLevelPercent); g_lua.bindClassMemberFunction<LocalPlayer>("getMagicLevelPercent", &LocalPlayer::getMagicLevelPercent);
g_lua.bindClassMemberFunction<LocalPlayer>("getSoul", &LocalPlayer::getSoul); g_lua.bindClassMemberFunction<LocalPlayer>("getSoul", &LocalPlayer::getSoul);
g_lua.bindClassMemberFunction<LocalPlayer>("getStamina", &LocalPlayer::getStamina); g_lua.bindClassMemberFunction<LocalPlayer>("getStamina", &LocalPlayer::getStamina);
g_lua.bindClassMemberFunction<LocalPlayer>("isKnown", &LocalPlayer::isKnown);
g_lua.bindClassMemberFunction<LocalPlayer>("isPreWalking", &LocalPlayer::isPreWalking);
g_lua.bindClassMemberFunction<LocalPlayer>("asLocalPlayer", &LocalPlayer::asLocalPlayer);
g_lua.registerClass<Tile>(); g_lua.registerClass<Tile>();
g_lua.bindClassMemberFunction<Tile>("clean", &Tile::clean); g_lua.bindClassMemberFunction<Tile>("clean", &Tile::clean);

View File

@ -93,11 +93,11 @@ namespace Proto {
GameServerDeleteInContainer = 114, GameServerDeleteInContainer = 114,
GameServerSetInventory = 120, GameServerSetInventory = 120,
GameServerDeleteInventory = 121, GameServerDeleteInventory = 121,
GameServerNpcOffer = 122, GameServerOpenNpcTrade = 122,
GameServerPlayerGoods = 123, GameServerPlayerGoods = 123,
GameServerCloseNpcTrade = 124, GameServerCloseNpcTrade = 124,
GameServerOwnOffer = 125, GameServerOwnTrade = 125,
GameServerCounterOffer = 126, GameServerCounterTrade = 126,
GameServerCloseTrade = 127, GameServerCloseTrade = 127,
GameServerAmbient = 130, GameServerAmbient = 130,
GameServerGraphicalEffect = 131, GameServerGraphicalEffect = 131,
@ -135,7 +135,7 @@ namespace Proto {
GameServerWait = 182, GameServerWait = 182,
GameServerFloorChangeUp = 190, GameServerFloorChangeUp = 190,
GameServerFloorChangeDown = 191, GameServerFloorChangeDown = 191,
GameServerOutfit = 200, GameServerChooseOutfit = 200,
GameServerVipAdd = 210, GameServerVipAdd = 210,
GameServerVipLogin = 211, GameServerVipLogin = 211,
GameServerVipLogout = 212, GameServerVipLogout = 212,

View File

@ -56,10 +56,10 @@ public:
void sendTurnEast(); void sendTurnEast();
void sendTurnSouth(); void sendTurnSouth();
void sendTurnWest(); void sendTurnWest();
void sendMove(const Position& fromPos, int thingId, int stackpos, const Position& toPos, int count); void sendMove(const Position& fromPos, int itemId, int stackpos, const Position& toPos, int count);
void sendInspectNpcTrade(int thingId, int count); void sendInspectNpcTrade(int itemId, int count);
void sendBuyItem(int thingId, int count, int amount, bool ignoreCapacity, bool buyWithBackpack); void sendBuyItem(int itemId, int count, int amount, bool ignoreCapacity, bool buyWithBackpack);
void sendSellItem(int thingId, int count, int amount, bool ignoreEquipped); void sendSellItem(int itemId, int count, int amount, bool ignoreEquipped);
void sendCloseNpcTrade(); void sendCloseNpcTrade();
void sendRequestTrade(const Position& pos, int thingId, int stackpos, uint playerId); void sendRequestTrade(const Position& pos, int thingId, int stackpos, uint playerId);
void sendInspectTrade(bool counterOffer, int index); void sendInspectTrade(bool counterOffer, int index);
@ -71,7 +71,7 @@ public:
void sendRotateItem(const Position& pos, int thingId, int stackpos); void sendRotateItem(const Position& pos, int thingId, int stackpos);
void sendCloseContainer(int containerId); void sendCloseContainer(int containerId);
void sendUpContainer(int containerId); void sendUpContainer(int containerId);
void sendEditText(uint textId, const std::string& text); void sendEditText(uint id, const std::string& text);
void sendEditList(int listId, uint id, const std::string& text); void sendEditList(int listId, uint id, const std::string& text);
void sendLook(const Position& position, int thingId, int stackpos); void sendLook(const Position& position, int thingId, int stackpos);
void sendTalk(Otc::SpeakType speakType, int channelId, const std::string& receiver, const std::string& message); void sendTalk(Otc::SpeakType speakType, int channelId, const std::string& receiver, const std::string& message);
@ -99,7 +99,7 @@ public:
void sendAddVip(const std::string& name); void sendAddVip(const std::string& name);
void sendRemoveVip(uint playerId); void sendRemoveVip(uint playerId);
void sendRequestQuestLog(); void sendRequestQuestLog();
void sendRequestQuestLine(int questLine); void sendRequestQuestLine(int questId);
private: private:
void sendLoginPacket(uint timestamp, uint8 unknown); void sendLoginPacket(uint timestamp, uint8 unknown);
@ -131,14 +131,14 @@ private:
void parseContainerRemoveItem(InputMessage& msg); void parseContainerRemoveItem(InputMessage& msg);
void parseAddInventoryItem(InputMessage& msg); void parseAddInventoryItem(InputMessage& msg);
void parseRemoveInventoryItem(InputMessage& msg); void parseRemoveInventoryItem(InputMessage& msg);
void parseNpcOffer(InputMessage& msg); void parseOpenNpcTrade(InputMessage& msg);
void parsePlayerCash(InputMessage& msg); void parsePlayerGoods(InputMessage& msg);
void parseCloseShopWindow(InputMessage&); void parseCloseNpcTrade(InputMessage&);
void parseWorldLight(InputMessage& msg); void parseWorldLight(InputMessage& msg);
void parseMagicEffect(InputMessage& msg); void parseMagicEffect(InputMessage& msg);
void parseAnimatedText(InputMessage& msg); void parseAnimatedText(InputMessage& msg);
void parseDistanceMissile(InputMessage& msg); void parseDistanceMissile(InputMessage& msg);
void parseCreatureSquare(InputMessage& msg); void parseCreatureMark(InputMessage& msg);
void parseCreatureHealth(InputMessage& msg); void parseCreatureHealth(InputMessage& msg);
void parseCreatureLight(InputMessage& msg); void parseCreatureLight(InputMessage& msg);
void parseCreatureOutfit(InputMessage& msg); void parseCreatureOutfit(InputMessage& msg);
@ -146,11 +146,11 @@ private:
void parseCreatureSkulls(InputMessage& msg); void parseCreatureSkulls(InputMessage& msg);
void parseCreatureShields(InputMessage& msg); void parseCreatureShields(InputMessage& msg);
void parseCreatureTurn(InputMessage& msg); void parseCreatureTurn(InputMessage& msg);
void parseItemTextWindow(InputMessage& msg); void parseEditText(InputMessage& msg);
void parseHouseTextWindow(InputMessage& msg); void parseEditList(InputMessage& msg);
void parsePlayerStats(InputMessage& msg); void parsePlayerStats(InputMessage& msg);
void parsePlayerSkills(InputMessage& msg); void parsePlayerSkills(InputMessage& msg);
void parsePlayerIcons(InputMessage& msg); void parsePlayerState(InputMessage& msg);
void parsePlayerCancelAttack(InputMessage& msg); void parsePlayerCancelAttack(InputMessage& msg);
void parseCreatureSpeak(InputMessage& msg); void parseCreatureSpeak(InputMessage& msg);
void parseChannelList(InputMessage& msg); void parseChannelList(InputMessage& msg);
@ -158,13 +158,13 @@ private:
void parseOpenPrivateChannel(InputMessage& msg); void parseOpenPrivateChannel(InputMessage& msg);
void parseOpenOwnPrivateChannel(InputMessage& msg); void parseOpenOwnPrivateChannel(InputMessage& msg);
void parseCloseChannel(InputMessage& msg); void parseCloseChannel(InputMessage& msg);
void parseSafeTradeRequest(InputMessage& msg); void parseOpenTrade(InputMessage& msg);
void parseSafeTradeClose(InputMessage&); void parseCloseTrade(InputMessage&);
void parseTextMessage(InputMessage& msg); void parseTextMessage(InputMessage& msg);
void parseCancelWalk(InputMessage& msg); void parseCancelWalk(InputMessage& msg);
void parseFloorChangeUp(InputMessage& msg); void parseFloorChangeUp(InputMessage& msg);
void parseFloorChangeDown(InputMessage& msg); void parseFloorChangeDown(InputMessage& msg);
void parseOutfit(InputMessage& msg); void parseOpenOutfitWindow(InputMessage& msg);
void parseVipAdd(InputMessage& msg); void parseVipAdd(InputMessage& msg);
void parseVipLogin(InputMessage& msg); void parseVipLogin(InputMessage& msg);
void parseVipLogout(InputMessage& msg); void parseVipLogout(InputMessage& msg);

View File

@ -113,23 +113,23 @@ void ProtocolGame::parseMessage(InputMessage& msg)
case Proto::GameServerDeleteInventory: case Proto::GameServerDeleteInventory:
parseRemoveInventoryItem(msg); parseRemoveInventoryItem(msg);
break; break;
case Proto::GameServerNpcOffer: case Proto::GameServerOpenNpcTrade:
parseNpcOffer(msg); parseOpenNpcTrade(msg);
break; break;
case Proto::GameServerPlayerGoods: case Proto::GameServerPlayerGoods:
parsePlayerCash(msg); parsePlayerGoods(msg);
break; break;
case Proto::GameServerCloseNpcTrade: case Proto::GameServerCloseNpcTrade:
parseCloseShopWindow(msg); parseCloseNpcTrade(msg);
break; break;
case Proto::GameServerOwnOffer: case Proto::GameServerOwnTrade:
parseSafeTradeRequest(msg); parseOpenTrade(msg);
break; break;
case Proto::GameServerCounterOffer: case Proto::GameServerCounterTrade:
parseSafeTradeRequest(msg); parseOpenTrade(msg);
break; break;
case Proto::GameServerCloseTrade: case Proto::GameServerCloseTrade:
parseSafeTradeClose(msg); parseCloseTrade(msg);
break; break;
case Proto::GameServerAmbient: case Proto::GameServerAmbient:
parseWorldLight(msg); parseWorldLight(msg);
@ -144,7 +144,7 @@ void ProtocolGame::parseMessage(InputMessage& msg)
parseDistanceMissile(msg); parseDistanceMissile(msg);
break; break;
case Proto::GameServerMarkCreature: case Proto::GameServerMarkCreature:
parseCreatureSquare(msg); parseCreatureMark(msg);
break; break;
//case Proto::GameServerTrappers //case Proto::GameServerTrappers
case Proto::GameServerCreatureHealth: case Proto::GameServerCreatureHealth:
@ -167,10 +167,10 @@ void ProtocolGame::parseMessage(InputMessage& msg)
break; break;
// case Proto::GameServerCreatureUnpass // case Proto::GameServerCreatureUnpass
case Proto::GameServerEditText: case Proto::GameServerEditText:
parseItemTextWindow(msg); parseEditText(msg);
break; break;
case Proto::GameServerEditList: case Proto::GameServerEditList:
parseHouseTextWindow(msg); parseEditList(msg);
break; break;
case Proto::GameServerPlayerData: case Proto::GameServerPlayerData:
parsePlayerStats(msg); parsePlayerStats(msg);
@ -179,7 +179,7 @@ void ProtocolGame::parseMessage(InputMessage& msg)
parsePlayerSkills(msg); parsePlayerSkills(msg);
break; break;
case Proto::GameServerPlayerState: case Proto::GameServerPlayerState:
parsePlayerIcons(msg); parsePlayerState(msg);
break; break;
case Proto::GameServerClearTarget: case Proto::GameServerClearTarget:
parsePlayerCancelAttack(msg); parsePlayerCancelAttack(msg);
@ -228,8 +228,8 @@ void ProtocolGame::parseMessage(InputMessage& msg)
case Proto::GameServerFloorChangeDown: case Proto::GameServerFloorChangeDown:
parseFloorChangeDown(msg); parseFloorChangeDown(msg);
break; break;
case Proto::GameServerOutfit: case Proto::GameServerChooseOutfit:
parseOutfit(msg); parseOpenOutfitWindow(msg);
break; break;
case Proto::GameServerVipAdd: case Proto::GameServerVipAdd:
parseVipAdd(msg); parseVipAdd(msg);
@ -454,7 +454,7 @@ void ProtocolGame::parseOpenContainer(InputMessage& msg)
void ProtocolGame::parseCloseContainer(InputMessage& msg) void ProtocolGame::parseCloseContainer(InputMessage& msg)
{ {
int containerId = msg.getU8(); int containerId = msg.getU8();
g_lua.callGlobalField("g_game", "onContainerClose", containerId); g_game.processCloseContainer(containerId);
} }
void ProtocolGame::parseContainerAddItem(InputMessage& msg) void ProtocolGame::parseContainerAddItem(InputMessage& msg)
@ -469,14 +469,14 @@ void ProtocolGame::parseContainerUpdateItem(InputMessage& msg)
int containerId = msg.getU8(); int containerId = msg.getU8();
int slot = msg.getU8(); int slot = msg.getU8();
ItemPtr item = internalGetItem(msg); ItemPtr item = internalGetItem(msg);
g_lua.callGlobalField("g_game", "onContainerUpdateItem", containerId, slot, item); g_game.processContainerUpdateItem(containerId, slot, item);
} }
void ProtocolGame::parseContainerRemoveItem(InputMessage& msg) void ProtocolGame::parseContainerRemoveItem(InputMessage& msg)
{ {
int containerId = msg.getU8(); int containerId = msg.getU8();
int slot = msg.getU8(); int slot = msg.getU8();
g_lua.callGlobalField("g_game", "onContainerRemoveItem", containerId, slot); g_game.processContainerRemoveItem(containerId, slot);
} }
void ProtocolGame::parseAddInventoryItem(InputMessage& msg) void ProtocolGame::parseAddInventoryItem(InputMessage& msg)
@ -492,45 +492,65 @@ void ProtocolGame::parseRemoveInventoryItem(InputMessage& msg)
g_game.processInventoryChange(slot, ItemPtr()); g_game.processInventoryChange(slot, ItemPtr());
} }
void ProtocolGame::parseNpcOffer(InputMessage& msg) void ProtocolGame::parseOpenNpcTrade(InputMessage& msg)
{ {
std::vector<std::tuple<ItemPtr, std::string, int, int, int>> items;
int listCount = msg.getU8(); int listCount = msg.getU8();
for(int i = 0; i < listCount; ++i) { for(int i = 0; i < listCount; ++i) {
msg.getU16(); // item id int itemId = msg.getU16();
msg.getU8(); // runecharges int countOrSubType = msg.getU8();
msg.getString(); // item name
msg.getU32(); // weight ItemPtr item = Item::create(itemId);
msg.getU32(); // buy price if(item->isStackable() || item->isFluidContainer() || item->isFluid())
msg.getU32(); // sell price item->setCountOrSubType(countOrSubType);
std::string name = msg.getString();
int weight = msg.getU32();
int buyPrice = msg.getU32();
int sellPrice = msg.getU32();
items.push_back(std::make_tuple(item, name, weight, buyPrice, sellPrice));
} }
g_game.processOpenNpcTrade(items);
} }
void ProtocolGame::parsePlayerCash(InputMessage& msg) void ProtocolGame::parsePlayerGoods(InputMessage& msg)
{ {
msg.getU32(); std::vector<std::tuple<ItemPtr, int>> goods;
int money = msg.getU32();
int size = msg.getU8(); int size = msg.getU8();
for(int i = 0; i < size; i++) { for(int i = 0; i < size; i++) {
msg.getU16(); // itemid int itemId = msg.getU16();
msg.getU8(); // runecharges int count = msg.getU8();
goods.push_back(std::make_tuple(Item::create(itemId), count));
} }
g_game.processPlayerGoods(money, goods);
} }
void ProtocolGame::parseCloseShopWindow(InputMessage&) void ProtocolGame::parseCloseNpcTrade(InputMessage&)
{ {
g_game.processCloseNpcTrade();
} }
void ProtocolGame::parseSafeTradeRequest(InputMessage& msg) void ProtocolGame::parseOpenTrade(InputMessage& msg)
{ {
msg.getString(); // name std::string name = msg.getString();
int count = msg.getU8(); int count = msg.getU8();
std::vector<ItemPtr> items(count);
for(int i = 0; i < count; i++) for(int i = 0; i < count; i++)
internalGetItem(msg); items[i] = internalGetItem(msg);
g_game.processOpenTrade(name, items);
} }
void ProtocolGame::parseSafeTradeClose(InputMessage&) void ProtocolGame::parseCloseTrade(InputMessage&)
{ {
g_game.processCloseTrade();
} }
void ProtocolGame::parseWorldLight(InputMessage& msg) void ProtocolGame::parseWorldLight(InputMessage& msg)
@ -549,7 +569,6 @@ void ProtocolGame::parseMagicEffect(InputMessage& msg)
EffectPtr effect = EffectPtr(new Effect()); EffectPtr effect = EffectPtr(new Effect());
effect->setId(effectId); effect->setId(effectId);
g_map.addThing(effect, pos); g_map.addThing(effect, pos);
} }
@ -562,7 +581,6 @@ void ProtocolGame::parseAnimatedText(InputMessage& msg)
AnimatedTextPtr animatedText = AnimatedTextPtr(new AnimatedText); AnimatedTextPtr animatedText = AnimatedTextPtr(new AnimatedText);
animatedText->setColor(color); animatedText->setColor(color);
animatedText->setText(text); animatedText->setText(text);
g_map.addThing(animatedText, position); g_map.addThing(animatedText, position);
} }
@ -578,7 +596,7 @@ void ProtocolGame::parseDistanceMissile(InputMessage& msg)
g_map.addThing(missile, fromPos); g_map.addThing(missile, fromPos);
} }
void ProtocolGame::parseCreatureSquare(InputMessage& msg) void ProtocolGame::parseCreatureMark(InputMessage& msg)
{ {
uint id = msg.getU32(); uint id = msg.getU32();
int color = msg.getU8(); int color = msg.getU8();
@ -586,6 +604,8 @@ void ProtocolGame::parseCreatureSquare(InputMessage& msg)
CreaturePtr creature = g_map.getCreatureById(id); CreaturePtr creature = g_map.getCreatureById(id);
if(creature) if(creature)
creature->addTimedSquare(color); creature->addTimedSquare(color);
else
logTraceError("could not get greature");
} }
void ProtocolGame::parseCreatureHealth(InputMessage& msg) void ProtocolGame::parseCreatureHealth(InputMessage& msg)
@ -596,6 +616,8 @@ void ProtocolGame::parseCreatureHealth(InputMessage& msg)
CreaturePtr creature = g_map.getCreatureById(id); CreaturePtr creature = g_map.getCreatureById(id);
if(creature) if(creature)
creature->setHealthPercent(healthPercent); creature->setHealthPercent(healthPercent);
else
logTraceError("could not get greature");
} }
void ProtocolGame::parseCreatureLight(InputMessage& msg) void ProtocolGame::parseCreatureLight(InputMessage& msg)
@ -609,6 +631,8 @@ void ProtocolGame::parseCreatureLight(InputMessage& msg)
CreaturePtr creature = g_map.getCreatureById(id); CreaturePtr creature = g_map.getCreatureById(id);
if(creature) if(creature)
creature->setLight(light); creature->setLight(light);
else
logTraceError("could not get greature");
} }
void ProtocolGame::parseCreatureOutfit(InputMessage& msg) void ProtocolGame::parseCreatureOutfit(InputMessage& msg)
@ -619,6 +643,8 @@ void ProtocolGame::parseCreatureOutfit(InputMessage& msg)
CreaturePtr creature = g_map.getCreatureById(id); CreaturePtr creature = g_map.getCreatureById(id);
if(creature) if(creature)
creature->setOutfit(outfit); creature->setOutfit(outfit);
else
logTraceError("could not get greature");
} }
void ProtocolGame::parseCreatureSpeed(InputMessage& msg) void ProtocolGame::parseCreatureSpeed(InputMessage& msg)
@ -629,6 +655,8 @@ void ProtocolGame::parseCreatureSpeed(InputMessage& msg)
CreaturePtr creature = g_map.getCreatureById(id); CreaturePtr creature = g_map.getCreatureById(id);
if(creature) if(creature)
creature->setSpeed(speed); creature->setSpeed(speed);
else
logTraceError("could not get greature");
} }
void ProtocolGame::parseCreatureSkulls(InputMessage& msg) void ProtocolGame::parseCreatureSkulls(InputMessage& msg)
@ -639,6 +667,8 @@ void ProtocolGame::parseCreatureSkulls(InputMessage& msg)
CreaturePtr creature = g_map.getCreatureById(id); CreaturePtr creature = g_map.getCreatureById(id);
if(creature) if(creature)
creature->setSkull(skull); creature->setSkull(skull);
else
logTraceError("could not get greature");
} }
void ProtocolGame::parseCreatureShields(InputMessage& msg) void ProtocolGame::parseCreatureShields(InputMessage& msg)
@ -649,6 +679,8 @@ void ProtocolGame::parseCreatureShields(InputMessage& msg)
CreaturePtr creature = g_map.getCreatureById(id); CreaturePtr creature = g_map.getCreatureById(id);
if(creature) if(creature)
creature->setShield(shield); creature->setShield(shield);
else
logTraceError("could not get greature");
} }
void ProtocolGame::parseCreatureTurn(InputMessage& msg) void ProtocolGame::parseCreatureTurn(InputMessage& msg)
@ -659,23 +691,29 @@ void ProtocolGame::parseCreatureTurn(InputMessage& msg)
CreaturePtr creature = g_map.getCreatureById(id); CreaturePtr creature = g_map.getCreatureById(id);
if(creature) if(creature)
creature->turn(direction); creature->turn(direction);
else
logTraceError("could not get greature");
} }
void ProtocolGame::parseItemTextWindow(InputMessage& msg) void ProtocolGame::parseEditText(InputMessage& msg)
{ {
msg.getU32(); // windowId int id = msg.getU32();
msg.getU16(); // itemid int itemId = msg.getU16();
msg.getU16(); // max length int maxLength = msg.getU16();
msg.getString(); // text std::string text = msg.getString();
msg.getString(); // writter std::string writter = msg.getString();
msg.getString(); // date std::string date = msg.getString();
g_game.processEditText(id, itemId, maxLength, text, writter, date);
} }
void ProtocolGame::parseHouseTextWindow(InputMessage& msg) void ProtocolGame::parseEditList(InputMessage& msg)
{ {
msg.getU8(); // unknown int listId = msg.getU8();
msg.getU32(); // windowId int id = msg.getU32();
msg.getString(); // text const std::string& text = msg.getString();
g_game.processEditList(listId, id, text);
} }
void ProtocolGame::parsePlayerStats(InputMessage& msg) void ProtocolGame::parsePlayerStats(InputMessage& msg)
@ -693,26 +731,30 @@ void ProtocolGame::parsePlayerStats(InputMessage& msg)
double soul = msg.getU8(); double soul = msg.getU8();
double stamina = msg.getU16(); double stamina = msg.getU16();
g_game.processPlayerStats(health, maxHealth, freeCapacity, experience, level, levelPercent, mana, maxMana, magicLevel, magicLevelPercent, soul, stamina); m_localPlayer->setHealth(health, maxHealth);
m_localPlayer->setFreeCapacity(freeCapacity);
m_localPlayer->setExperience(experience);
m_localPlayer->setLevel(level, levelPercent);
m_localPlayer->setMana(mana, maxMana);
m_localPlayer->setMagicLevel(magicLevel, magicLevelPercent);
m_localPlayer->setSoul(soul);
m_localPlayer->setStamina(stamina);
} }
void ProtocolGame::parsePlayerSkills(InputMessage& msg) void ProtocolGame::parsePlayerSkills(InputMessage& msg)
{ {
for(int skill = 0; skill < Otc::LastSkill; skill++) { for(int skill = 0; skill < Otc::LastSkill; skill++) {
int values[Otc::LastSkillType]; int level = msg.getU8();
for(int skillType = 0; skillType < Otc::LastSkillType; skillType++) { int levelPercent = msg.getU8();
values[skillType] = msg.getU8();
m_localPlayer->setSkill((Otc::Skill)skill, (Otc::SkillType)skillType, values[skillType]);
}
g_lua.callGlobalField("g_game", "onSkillChange", skill, values[Otc::SkillLevel], values[Otc::SkillPercent]); m_localPlayer->setSkill((Otc::Skill)skill, level, levelPercent);
} }
} }
void ProtocolGame::parsePlayerIcons(InputMessage& msg) void ProtocolGame::parsePlayerState(InputMessage& msg)
{ {
int icons = msg.getU16(); int states = msg.getU16();
m_localPlayer->setIcons((Otc::PlayerIcons)icons); m_localPlayer->setStates((Otc::PlayerStates)states);
} }
void ProtocolGame::parsePlayerCancelAttack(InputMessage& msg) void ProtocolGame::parsePlayerCancelAttack(InputMessage& msg)
@ -768,14 +810,14 @@ void ProtocolGame::parseCreatureSpeak(InputMessage& msg)
void ProtocolGame::parseChannelList(InputMessage& msg) void ProtocolGame::parseChannelList(InputMessage& msg)
{ {
int count = msg.getU8(); int count = msg.getU8();
std::vector<std::tuple<int, std::string> > channelList(count); std::vector<std::tuple<int, std::string>> channelList(count);
for(int i = 0; i < count; i++) { for(int i = 0; i < count; i++) {
int id = msg.getU16(); int id = msg.getU16();
std::string name = msg.getString(); std::string name = msg.getString();
channelList.push_back(std::make_tuple(id, name)); channelList.push_back(std::make_tuple(id, name));
} }
g_lua.callGlobalField("g_game", "onChannelList", channelList); g_game.processChannelList(channelList);
} }
void ProtocolGame::parseOpenChannel(InputMessage& msg) void ProtocolGame::parseOpenChannel(InputMessage& msg)
@ -783,29 +825,29 @@ void ProtocolGame::parseOpenChannel(InputMessage& msg)
int channelId = msg.getU16(); int channelId = msg.getU16();
std::string name = msg.getString(); std::string name = msg.getString();
g_lua.callGlobalField("g_game", "onOpenChannel", channelId, name); g_game.processOpenChannel(channelId, name);
} }
void ProtocolGame::parseOpenPrivateChannel(InputMessage& msg) void ProtocolGame::parseOpenPrivateChannel(InputMessage& msg)
{ {
std::string name = msg.getString(); std::string name = msg.getString();
g_lua.callGlobalField("g_game", "onOpenPrivateChannel", name); g_game.processOpenPrivateChannel(name);
} }
void ProtocolGame::parseOpenOwnPrivateChannel(InputMessage& msg) void ProtocolGame::parseOpenOwnPrivateChannel(InputMessage& msg)
{ {
int id = msg.getU16(); // channel id int channelId = msg.getU16();
std::string name = msg.getString(); // channel name std::string name = msg.getString();
g_lua.callGlobalField("g_game", "onOpenOwnPrivateChannel", id, name); g_game.processOpenOwnPrivateChannel(channelId, name);
} }
void ProtocolGame::parseCloseChannel(InputMessage& msg) void ProtocolGame::parseCloseChannel(InputMessage& msg)
{ {
int id = msg.getU16(); // channel id int channelId = msg.getU16();
g_lua.callGlobalField("g_game", "onCloseChannel", id); g_game.processCloseChannel(channelId);
} }
void ProtocolGame::parseTextMessage(InputMessage& msg) void ProtocolGame::parseTextMessage(InputMessage& msg)
@ -861,27 +903,21 @@ void ProtocolGame::parseFloorChangeDown(InputMessage& msg)
g_map.setCentralPosition(pos); g_map.setCentralPosition(pos);
} }
void ProtocolGame::parseOutfit(InputMessage& msg) void ProtocolGame::parseOpenOutfitWindow(InputMessage& msg)
{ {
Outfit outfit = internalGetOutfit(msg); Outfit currentOutfit = internalGetOutfit(msg);
typedef std::tuple<int, std::string, int> OutfitInfo; std::vector<std::tuple<int, std::string, int>> outfitList;
std::vector<OutfitInfo> outfitList; int outfitCount = msg.getU8();
uint8 outfitCount = msg.getU8();
for(int i = 0; i < outfitCount; i++) { for(int i = 0; i < outfitCount; i++) {
uint16 outfitId = msg.getU16(); int outfitId = msg.getU16();
std::string outfitName = msg.getString(); std::string outfitName = msg.getString();
uint8 outfitAddons = msg.getU8(); int outfitAddons = msg.getU8();
outfitList.push_back(OutfitInfo(outfitId, outfitName, outfitAddons)); outfitList.push_back(std::make_tuple(outfitId, outfitName, outfitAddons));
} }
CreaturePtr creature = CreaturePtr(new Creature); g_game.processOpenOutfitWindow(currentOutfit, outfitList);
creature->setDirection(Otc::South);
creature->setOutfit(outfit);
g_lua.callGlobalField("g_game", "onOpenOutfitWindow", creature, outfitList);
} }
void ProtocolGame::parseVipAdd(InputMessage& msg) void ProtocolGame::parseVipAdd(InputMessage& msg)
@ -890,30 +926,30 @@ void ProtocolGame::parseVipAdd(InputMessage& msg)
std::string name = msg.getString(); std::string name = msg.getString();
bool online = msg.getU8() != 0; bool online = msg.getU8() != 0;
g_lua.callGlobalField("g_game", "onAddVip", id, name, online); g_game.processVipAdd(id, name, online);
} }
void ProtocolGame::parseVipLogin(InputMessage& msg) void ProtocolGame::parseVipLogin(InputMessage& msg)
{ {
uint id = msg.getU32(); uint id = msg.getU32();
g_game.processVipStateChange(id, true);
g_lua.callGlobalField("g_game", "onVipStateChange", id, true);
} }
void ProtocolGame::parseVipLogout(InputMessage& msg) void ProtocolGame::parseVipLogout(InputMessage& msg)
{ {
uint id = msg.getU32(); uint id = msg.getU32();
g_game.processVipStateChange(id, false);
g_lua.callGlobalField("g_game", "onVipStateChange", id, false);
} }
void ProtocolGame::parseTutorialHint(InputMessage& msg) void ProtocolGame::parseTutorialHint(InputMessage& msg)
{ {
// ignored
msg.getU8(); // tutorial id msg.getU8(); // tutorial id
} }
void ProtocolGame::parseAutomapFlag(InputMessage& msg) void ProtocolGame::parseAutomapFlag(InputMessage& msg)
{ {
// ignored
parsePosition(msg); // position parsePosition(msg); // position
msg.getU8(); // icon msg.getU8(); // icon
msg.getString(); // message msg.getString(); // message
@ -921,22 +957,30 @@ void ProtocolGame::parseAutomapFlag(InputMessage& msg)
void ProtocolGame::parseQuestLog(InputMessage& msg) void ProtocolGame::parseQuestLog(InputMessage& msg)
{ {
std::vector<std::tuple<int, std::string, bool>> questList;
int questsCount = msg.getU16(); int questsCount = msg.getU16();
for(int i = 0; i < questsCount; i++) { for(int i = 0; i < questsCount; i++) {
msg.getU16(); // quest id int id = msg.getU16();
msg.getString(); // quest name std::string name = msg.getString();
msg.getU8(); // quest state bool completed = msg.getU8();
questList.push_back(std::make_tuple(id, name, completed));
} }
g_game.processQuestLog(questList);
} }
void ProtocolGame::parseQuestLine(InputMessage& msg) void ProtocolGame::parseQuestLine(InputMessage& msg)
{ {
msg.getU16(); // quest id std::vector<std::tuple<std::string, std::string>> questMissions;
int questId = msg.getU16();
int missionCount = msg.getU8(); int missionCount = msg.getU8();
for(int i = 0; i < missionCount; i++) { for(int i = 0; i < missionCount; i++) {
msg.getString(); // quest name std::string missionName = msg.getString();
msg.getString(); // quest description std::string missionDescrition = msg.getString();
questMissions.push_back(std::make_tuple(missionName, missionDescrition));
} }
g_game.processQuestLine(questId, questMissions);
} }
void ProtocolGame::setMapDescription(InputMessage& msg, int32 x, int32 y, int32 z, int32 width, int32 height) void ProtocolGame::setMapDescription(InputMessage& msg, int32 x, int32 y, int32 z, int32 width, int32 height)
@ -1085,7 +1129,7 @@ ThingPtr ProtocolGame::internalGetThing(InputMessage& msg)
g_map.addCreature(creature); g_map.addCreature(creature);
} }
uint8 healthPercent = msg.getU8(); int healthPercent = msg.getU8();
Otc::Direction direction = (Otc::Direction)msg.getU8(); Otc::Direction direction = (Otc::Direction)msg.getU8();
Outfit outfit = internalGetOutfit(msg); Outfit outfit = internalGetOutfit(msg);
@ -1097,8 +1141,9 @@ ThingPtr ProtocolGame::internalGetThing(InputMessage& msg)
int skull = msg.getU8(); int skull = msg.getU8();
int shield = msg.getU8(); int shield = msg.getU8();
// emblem is sent only when the creature is not known
int emblem = -1; int emblem = -1;
if(thingId == 0x0061) // emblem is sent only in packet type 0x61 if(thingId == 0x0061)
emblem = msg.getU8(); emblem = msg.getU8();
bool passable = (msg.getU8() == 0); bool passable = (msg.getU8() == 0);

View File

@ -191,20 +191,20 @@ void ProtocolGame::sendMove(const Position& fromPos, int thingId, int stackpos,
send(msg); send(msg);
} }
void ProtocolGame::sendInspectNpcTrade(int thingId, int count) void ProtocolGame::sendInspectNpcTrade(int itemId, int count)
{ {
OutputMessage msg; OutputMessage msg;
msg.addU8(Proto::ClientInspectNpcTrade); msg.addU8(Proto::ClientInspectNpcTrade);
msg.addU16(thingId); msg.addU16(itemId);
msg.addU8(count); msg.addU8(count);
send(msg); send(msg);
} }
void ProtocolGame::sendBuyItem(int thingId, int count, int amount, bool ignoreCapacity, bool buyWithBackpack) void ProtocolGame::sendBuyItem(int itemId, int count, int amount, bool ignoreCapacity, bool buyWithBackpack)
{ {
OutputMessage msg; OutputMessage msg;
msg.addU8(Proto::ClientBuyItem); msg.addU8(Proto::ClientBuyItem);
msg.addU16(thingId); msg.addU16(itemId);
msg.addU8(count); msg.addU8(count);
msg.addU8(amount); msg.addU8(amount);
msg.addU8(ignoreCapacity ? 0x01 : 0x00); msg.addU8(ignoreCapacity ? 0x01 : 0x00);
@ -212,11 +212,11 @@ void ProtocolGame::sendBuyItem(int thingId, int count, int amount, bool ignoreCa
send(msg); send(msg);
} }
void ProtocolGame::sendSellItem(int thingId, int count, int amount, bool ignoreEquipped) void ProtocolGame::sendSellItem(int itemId, int count, int amount, bool ignoreEquipped)
{ {
OutputMessage msg; OutputMessage msg;
msg.addU8(Proto::ClientSellItem); msg.addU8(Proto::ClientSellItem);
msg.addU16(thingId); msg.addU16(itemId);
msg.addU8(count); msg.addU8(count);
msg.addU8(amount); msg.addU8(amount);
msg.addU8(ignoreEquipped ? 0x01 : 0x00); msg.addU8(ignoreEquipped ? 0x01 : 0x00);
@ -230,14 +230,14 @@ void ProtocolGame::sendCloseNpcTrade()
send(msg); send(msg);
} }
void ProtocolGame::sendRequestTrade(const Position& pos, int thingId, int stackpos, uint playerId) void ProtocolGame::sendRequestTrade(const Position& pos, int thingId, int stackpos, uint creatureId)
{ {
OutputMessage msg; OutputMessage msg;
msg.addU8(Proto::ClientRequestTrade); msg.addU8(Proto::ClientRequestTrade);
addPosition(msg, pos); addPosition(msg, pos);
msg.addU16(thingId); msg.addU16(thingId);
msg.addU8(stackpos); msg.addU8(stackpos);
msg.addU32(playerId); msg.addU32(creatureId);
send(msg); send(msg);
} }
@ -325,11 +325,11 @@ void ProtocolGame::sendUpContainer(int containerId)
send(msg); send(msg);
} }
void ProtocolGame::sendEditText(uint textId, const std::string& text) void ProtocolGame::sendEditText(uint id, const std::string& text)
{ {
OutputMessage msg; OutputMessage msg;
msg.addU8(Proto::ClientEditText); msg.addU8(Proto::ClientEditText);
msg.addU32(textId); msg.addU32(id);
msg.addString(text); msg.addString(text);
send(msg); send(msg);
} }
@ -576,11 +576,11 @@ void ProtocolGame::sendRequestQuestLog()
send(msg); send(msg);
} }
void ProtocolGame::sendRequestQuestLine(int questLine) void ProtocolGame::sendRequestQuestLine(int questId)
{ {
OutputMessage msg; OutputMessage msg;
msg.addU8(Proto::ClientRequestQuestLine); msg.addU8(Proto::ClientRequestQuestLine);
msg.addU16(questLine); msg.addU16(questId);
send(msg); send(msg);
} }