Erikas Kontenis
Excellent OT User
Hello, i am using 0.2.10 tfs version and i would like to add in mounts.xml add health functions i made a noob part and i dont know what to do more i tried lots of different ways but still cant done it working.
this is my mounts.cpp i self edited it and compiled right without errors but this is only shit part i need function wich add and remove mounts when mounted dismounted.
this is lines wich i thinking should be edited.
player.cpp
i am in think this is most required part need just copy this and make something wich use changehealth, also in player.cpp is changespeed function, mayby need to do same function to changehealth ofcourse i tried but was shit for me...
and game.cpp
thanks.
Code:
//////////////////////////////////////////////////////////////////////
// OpenTibia - an opensource roleplaying game
//////////////////////////////////////////////////////////////////////
// Mounts
//////////////////////////////////////////////////////////////////////
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 2
// of the License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software Foundation,
// Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
//////////////////////////////////////////////////////////////////////
#include "mounts.h"
#include "tools.h"
Mount::Mount(uint8_t _id, uint16_t _clientId, std::string _name, int32_t _speed, int32_t _health)
{
id = _id;
clientId = _clientId;
name = _name;
speed = _speed;
health = _health;
}
bool Mount::isTamed(Player* player) const
{
if(!player)
return false;
if(player->isAccessPlayer())
return true;
uint8_t tmpId = id - 1;
int32_t value = 0;
if(!player->getStorageValue(PSTRG_MOUNTS_RANGE_START + (tmpId / 31), value))
return false;
//int32_t tmp = pow(2, tmpId % 31);
int32_t tmp = static_cast<int32_t>(pow(2, tmpId % 31));
return (tmp & value) == tmp;
}
Mounts::~Mounts()
{
for(MountsList::iterator it = mounts.begin(); it != mounts.end(); it++)
delete (*it);
mounts.clear();
}
bool Mounts::reload()
{
for(MountsList::iterator it = mounts.begin(); it != mounts.end(); it++)
delete (*it);
mounts.clear();
return loadFromXml();
}
bool Mounts::loadFromXml()
{
xmlDocPtr doc = xmlParseFile("data/XML/mounts.xml");
if(!doc)
return false;
xmlNodePtr root, p;
root = xmlDocGetRootElement(doc);
if(xmlStrcmp(root->name,(const xmlChar*)"mounts") != 0)
{
xmlFreeDoc(doc);
return false;
}
int32_t intValue;
std::string strValue;
p = root->children;
while(p)
{
if(xmlStrcmp(p->name, (const xmlChar*)"mount") == 0)
{
int8_t id = 0;
int16_t clientid = 0;
std::string name = "";
int32_t speed = 0;
int32_t health = 0;
if(readXMLInteger(p, "id", intValue))
id = intValue;
if(readXMLInteger(p, "clientid", intValue))
clientid = intValue;
if(readXMLString(p, "name", strValue))
name = strValue;
if(readXMLInteger(p, "speed", intValue))
speed = intValue;
if(readXMLInteger(p, "health", intValue))
health = intValue;
mounts.push_back(new Mount(id, clientid, name, speed, health));
}
p = p->next;
}
xmlFreeDoc(doc);
return true;
}
Mount* Mounts::getMountByID(uint8_t id)
{
for(MountsList::iterator it = mounts.begin(); it != mounts.end(); it++)
{
if((*it)->getID() == id)
return (*it);
}
return NULL;
}
Mount* Mounts::getMountByClientID(uint16_t clientId)
{
for(MountsList::iterator it = mounts.begin(); it != mounts.end(); it++)
{
if((*it)->getClientID() == clientId)
return (*it);
}
return NULL;
}
void Mounts::sendMountsList(Player* player, NetworkMessage_ptr msg)
{
MountsList tmp_list;
for(MountsList::const_iterator it = mounts.begin(); it != mounts.end(); it++)
{
if((*it)->isTamed(player))
tmp_list.push_back(*it);
}
msg->AddByte(tmp_list.size());
for(MountsList::const_iterator it = tmp_list.begin(); it != tmp_list.end(); it++)
{
msg->AddU16((*it)->getClientID());
msg->AddString((*it)->getName());
}
}
this is my mounts.cpp i self edited it and compiled right without errors but this is only shit part i need function wich add and remove mounts when mounted dismounted.
this is lines wich i thinking should be edited.
player.cpp
i am in think this is most required part need just copy this and make something wich use changehealth, also in player.cpp is changespeed function, mayby need to do same function to changehealth ofcourse i tried but was shit for me...
Code:
if(currentMount->getSpeed() != 0)
g_game.changeSpeed(this, currentMount->getSpeed());
Code:
bool Player::toggleMount(bool mount)
{
if(mount)
{
if(isMounted())
return false;
if(_tile->hasFlag(TILESTATE_PROTECTIONZONE))
{
sendCancelMessage(RET_ACTIONNOTPERMITTEDINPROTECTIONZONE);
return false;
}
if(!isPremium())
{
sendCancelMessage(RET_YOUNEEDPREMIUMACCOUNT);
return false;
}
uint8_t currentMountId = getCurrentMount();
if(currentMountId == 0)
{
sendOutfitWindow();
return false;
}
Mount* currentMount = Mounts::getInstance()->getMountByID(currentMountId);
if(!currentMount)
return false;
defaultOutfit.lookMount = currentMount->getClientID();
if(currentMount->getSpeed() != 0)
g_game.changeSpeed(this, currentMount->getSpeed());
g_game.internalCreatureChangeOutfit(this, defaultOutfit);
}
else
{
if(!isMounted())
return false;
dismount();
}
return true;
}
bool Player::tameMount(uint8_t mountId)
{
if(!Mounts::getInstance()->getMountByID(mountId))
return false;
mountId--;
int key = PSTRG_MOUNTS_RANGE_START + (mountId / 31);
int32_t value = 0;
if(getStorageValue(key, value))
value |= static_cast<int32_t>(pow(2, mountId % 31));
else
//value = pow(2, mountId % 31);
value = static_cast<int32_t>(pow(2, mountId % 31));
addStorageValue(key, value);
return true;
}
bool Player::untameMount(uint8_t mountId)
{
if(!Mounts::getInstance()->getMountByID(mountId))
return false;
mountId--;
int key = PSTRG_MOUNTS_RANGE_START + (mountId / 31);
int32_t value = 0;
if(!getStorageValue(key, value))
return true;
value ^= static_cast<int32_t>(pow(2, mountId % 31));
addStorageValue(key, value);
if(isMounted() && getCurrentMount() == (mountId + 1))
{
dismount();
setCurrentMount(0);
}
return true;
}
void Player::dismount()
{
Mount* mount = Mounts::getInstance()->getMountByID(getCurrentMount());
if(mount && mount->getSpeed() > 0)
g_game.changeSpeed(this, -mount->getSpeed());
defaultOutfit.lookMount = 0;
g_game.internalCreatureChangeOutfit(this, defaultOutfit);
}
and game.cpp
Code:
bool Game::playerChangeOutfit(uint32_t playerId, Outfit_t outfit)
{
Player* player = getPlayerByID(playerId);
if(!player || player->isRemoved())
return false;
if(outfit.lookMount != 0)
{
Mount* mount = Mounts::getInstance()->getMountByClientID(outfit.lookMount);
if(!mount || !mount->isTamed(player))
return false;
if(player->isMounted())
{
Mount* prevMount = Mounts::getInstance()->getMountByID(player->getCurrentMount());
if(prevMount)
changeSpeed(player, mount->getSpeed() - prevMount->getSpeed());
player->setCurrentMount(mount->getID());
}
else
{
player->setCurrentMount(mount->getID());
outfit.lookMount = 0;
}
}
else if(player->isMounted())
player->dismount();
if(player->canWear(outfit.lookType, outfit.lookAddons) && player->hasRequestedOutfit())
{
player->hasRequestedOutfit(false);
player->defaultOutfit = outfit;
if(player->hasCondition(CONDITION_OUTFIT))
return false;
internalCreatureChangeOutfit(player, outfit);
}
return true;
}
thanks.