Erevius
It Was A Good Day
Mam problem, gdyż na 7.6 avesta, gracze bez voc mogą siebie nawzajem atakować. Czy jest taka możliwość aby do vocation.xml dodać attackable="no" do tego silnika? Oczywiście chodzi mi tu o edycje source. btw, moje vocation.cpp i vocation.h:
vocation.cpp:
vocation.h:
Proszę o pomoc!
vocation.cpp:
Code:
//////////////////////////////////////////////////////////////////////
// OpenTibia - an opensource roleplaying game
//////////////////////////////////////////////////////////////////////
//
//////////////////////////////////////////////////////////////////////
// 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 "otpch.h"
#include "definitions.h"
#include "vocation.h"
#include <iostream>
#include <libxml/xmlmemory.h>
#include <libxml/parser.h>
#include <cmath>
#include "tools.h"
Vocations::Vocations()
{
//
}
Vocations::~Vocations()
{
for(VocationsMap::iterator it = vocationsMap.begin(); it != vocationsMap.end(); ++it){
delete it->second;
}
vocationsMap.clear();
}
bool Vocations::loadFromXml(const std::string& datadir)
{
std::string filename = datadir + "XML/vocations.xml";
xmlDocPtr doc = xmlParseFile(filename.c_str());
if(doc){
xmlNodePtr root, p;
root = xmlDocGetRootElement(doc);
if(xmlStrcmp(root->name,(const xmlChar*)"vocations") != 0){
xmlFreeDoc(doc);
return false;
}
p = root->children;
while(p){
std::string str;
int intVal;
float floatVal;
if(xmlStrcmp(p->name, (const xmlChar*)"vocation") == 0){
Vocation* voc = new Vocation();
uint32_t voc_id;
xmlNodePtr skillNode;
if(readXMLInteger(p, "id", intVal)){
voc_id = intVal;
if(readXMLString(p, "name", str)){
voc->name = str;
}
if(readXMLString(p, "description", str)){
voc->description = str;
}
if(readXMLInteger(p, "gaincap", intVal)){
voc->gainCap = intVal;
}
if(readXMLInteger(p, "gainhp", intVal)){
voc->gainHP = intVal;
}
if(readXMLInteger(p, "gainmana", intVal)){
voc->gainMana = intVal;
}
if(readXMLInteger(p, "gainhpticks", intVal)){
voc->gainHealthTicks = intVal;
}
if(readXMLInteger(p, "gainhpamount", intVal)){
voc->gainHealthAmount = intVal;
}
if(readXMLInteger(p, "gainmanaticks", intVal)){
voc->gainManaTicks = intVal;
}
if(readXMLInteger(p, "gainmanaamount", intVal)){
voc->gainManaAmount = intVal;
}
if(readXMLInteger(p, "maxsoul", intVal)){
voc->maxSoul = intVal;
}
if(readXMLInteger(p, "gainsoulticks", intVal)){
voc->gainSoulTicks = intVal;
}
if(readXMLFloat(p, "manamultiplier", floatVal)){
voc->manaMultiplier = floatVal;
}
if(readXMLInteger(p, "attackspeed", intVal)){
voc->attackSpeed = intVal;
}
skillNode = p->children;
while(skillNode){
if(xmlStrcmp(skillNode->name, (const xmlChar*)"skill") == 0){
uint32_t skill_id;
if(readXMLInteger(skillNode, "id", intVal)){
skill_id = intVal;
if(skill_id < SKILL_FIRST || skill_id > SKILL_LAST){
std::cout << "No valid skill id. " << skill_id << std::endl;
}
else{
if(readXMLFloat(skillNode, "multiplier", floatVal)){
voc->skillMultipliers[skill_id] = floatVal;
}
}
}
else{
std::cout << "Missing skill id." << std::endl;
}
}
else if(xmlStrcmp(skillNode->name, (const xmlChar*)"formula") == 0) {
if(readXMLFloat(skillNode, "meleeDamage", floatVal)) {
voc->meleeDamageMultiplier = floatVal;
}
if(readXMLFloat(skillNode, "distDamage", floatVal) || readXMLFloat(skillNode, "distanceDamage", floatVal)) {
voc->distDamageMultiplier = floatVal;
}
if(readXMLFloat(skillNode, "defense", floatVal)) {
voc->defenseMultiplier = floatVal;
}
if(readXMLFloat(skillNode, "armor", floatVal)) {
voc->armorMultiplier = floatVal;
}
}
skillNode = skillNode->next;
}
//std::cout << "Voc id: " << voc_id << std::endl;
//voc->debugVocation();
vocationsMap[voc_id] = voc;
}
else{
std::cout << "Missing vocation id." << std::endl;
}
}
p = p->next;
}
xmlFreeDoc(doc);
}
return true;
}
Vocation* Vocations::getVocation(uint32_t vocId)
{
VocationsMap::iterator it = vocationsMap.find(vocId);
if(it != vocationsMap.end()){
return it->second;
}
else{
std::cout << "Warning: [Vocations::getVocation] Vocation " << vocId << " not found." << std::endl;
return &def_voc;
}
}
int32_t Vocations::getVocationId(const std::string& name)
{
for(VocationsMap::iterator it = vocationsMap.begin(); it != vocationsMap.end(); ++it){
if(strcasecmp(it->second->name.c_str(), name.c_str()) == 0){
return it->first;
}
}
return -1;
}
uint32_t Vocation::skillBase[SKILL_LAST + 1] = { 50, 50, 50, 50, 30, 100, 20 };
Vocation::Vocation()
{
name = "none";
gainHealthTicks = 6;
gainHealthAmount = 1;
gainManaTicks = 6;
gainManaAmount = 1;
gainCap = 5;
gainMana = 5;
gainHP = 5;
maxSoul = 100;
gainSoulTicks = 120;
manaMultiplier = 4.0;
attackSpeed = 2000;
meleeDamageMultiplier = 1.0;
distDamageMultiplier = 1.0;
defenseMultiplier = 1.0;
armorMultiplier = 1.0;
skillMultipliers[0] = 1.5f;
skillMultipliers[1] = 2.0f;
skillMultipliers[2] = 2.0f;
skillMultipliers[3] = 2.0f;
skillMultipliers[4] = 2.0f;
skillMultipliers[5] = 1.5f;
skillMultipliers[6] = 1.1f;
}
Vocation::~Vocation()
{
cacheMana.clear();
for(int i = SKILL_FIRST; i < SKILL_LAST; ++i){
cacheSkill[i].clear();
}
}
uint32_t Vocation::getReqSkillTries(int skill, int level)
{
if(skill < SKILL_FIRST || skill > SKILL_LAST){
return 0;
}
cacheMap& skillMap = cacheSkill[skill];
cacheMap::iterator it = skillMap.find(level);
if(it != cacheSkill[skill].end()){
return it->second;
}
uint32_t tries = (unsigned int)(skillBase[skill] * pow((float)skillMultipliers[skill], (float)(level - 11)));
skillMap[level] = tries;
return tries;
}
uint32_t Vocation::getReqMana(int magLevel)
{
cacheMap::iterator it = cacheMana.find(magLevel);
if(it != cacheMana.end()){
return it->second;
}
uint32_t reqMana = (uint32_t)(1600*pow(manaMultiplier, magLevel-1));
/*if(reqMana % 20 < 10){
reqMana = reqMana - (reqMana % 20);
}
else{
reqMana = reqMana - (reqMana % 20) + 20;
}*/
cacheMana[magLevel] = reqMana;
return reqMana;
}
void Vocation::debugVocation()
{
std::cout << "name: " << name << std::endl;
std::cout << "gain cap: " << gainCap << " hp: " << gainHP << " mana: " << gainMana << std::endl;
std::cout << "gain time: Health(" << gainHealthTicks << " ticks, +" << gainHealthAmount << "). Mana(" <<
gainManaTicks << " ticks, +" << gainManaAmount << ")" << std::endl;
std::cout << "mana multiplier: " << manaMultiplier << std::endl;
for(int i = SKILL_FIRST; i < SKILL_LAST; ++i){
std::cout << "Skill id: " << i << " multiplier: " << skillMultipliers[i] << std::endl;
}
}
vocation.h:
Code:
//////////////////////////////////////////////////////////////////////
// OpenTibia - an opensource roleplaying game
//////////////////////////////////////////////////////////////////////
//
//////////////////////////////////////////////////////////////////////
// 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.
//////////////////////////////////////////////////////////////////////
#ifndef __OTSERV_VOCATION_H__
#define __OTSERV_VOCATION_H__
#include "enums.h"
#include <string>
#include <map>
class Vocation
{
public:
~Vocation();
const std::string& getVocName() const {return name;}
const std::string& getVocDescription() const {return description;}
uint32_t getReqSkillTries(int skill, int level);
uint32_t getReqMana(int magLevel);
uint32_t getHPGain() const {return gainHP;};
uint32_t getManaGain() const {return gainMana;};
uint32_t getCapGain() const {return gainCap;};
uint32_t getAttackSpeed() const {return attackSpeed;};
uint32_t getManaGainTicks() const {return gainManaTicks;};
uint32_t getManaGainAmount() const {return gainManaAmount;};
uint32_t getHealthGainTicks() const {return gainHealthTicks;};
uint32_t getHealthGainAmount() const {return gainHealthAmount;};
uint16_t getSoulMax() const {return maxSoul;};
uint16_t getSoulGainTicks() const {return gainSoulTicks;};
float meleeDamageMultiplier, distDamageMultiplier, defenseMultiplier, armorMultiplier;
void debugVocation();
protected:
friend class Vocations;
Vocation();
std::string name;
std::string description;
uint32_t gainHealthTicks;
uint32_t gainHealthAmount;
uint32_t gainManaTicks;
uint32_t gainManaAmount;
uint32_t attackSpeed;
uint32_t gainCap;
uint32_t gainMana;
uint32_t gainHP;
uint16_t maxSoul;
uint16_t gainSoulTicks;
static uint32_t skillBase[SKILL_LAST + 1];
float skillMultipliers[SKILL_LAST + 1];
float manaMultiplier;
typedef std::map<uint32_t, uint32_t> cacheMap;
cacheMap cacheMana;
cacheMap cacheSkill[SKILL_LAST + 1];
};
class Vocations
{
public:
Vocations();
~Vocations();
bool loadFromXml(const std::string& datadir);
Vocation* getVocation(uint32_t vocId);
int32_t getVocationId(const std::string& name);
private:
typedef std::map<uint32_t, Vocation*> VocationsMap;
VocationsMap vocationsMap;
Vocation def_voc;
};
#endif
Proszę o pomoc!