- Joined
- Aug 11, 2008
- Messages
- 2,628
- Solutions
- 2
- Reaction score
- 240
As a developer, working with XML files can often be very cumbersome, especially if they're of a larger size. SimpleXML may work fine for smaller files, or the occasional use, but when you want to parse larger XML files, or at a more frequent basis, it just doesn't cut it and as far as I am aware, there hasn't really been any open source tools specifically designed to tackle the Open Tibia server XML files at a decent pace. Thus, I decided to create my own exporter to convert these files into PHP arrays and/or JSON objects.
I don't know how many of you would benefit from this, but I thought I may as well share it and see what happens. I'm sure I've missed a couple of vital files, or attributes within the files themselves, so feel free to point out any error you may encounter.
https://github.com/pandaac/exporter
As of right now, the parsers that I've managed to develop are; Commands, Groups, Items, Monster, Monsters, Mounts, Outfits, Quests, Spells, Stages & Vocations. You may find all of the examples (and their respective example output) on the GitHub repository wiki, but as to give you a small sample, here's an example of how to parse the demon.xml file.
and what it outputs (in JSON);
I hope this may benefit at least some of you, whether you're developing an AAC or a simple tool of sorts.
PS. It is very much recommended to cache the result in some form or another.
PSS. It is also worth noting that the current version only officially supports The Forgotten Server 1.1.
I don't know how many of you would benefit from this, but I thought I may as well share it and see what happens. I'm sure I've missed a couple of vital files, or attributes within the files themselves, so feel free to point out any error you may encounter.
https://github.com/pandaac/exporter
As of right now, the parsers that I've managed to develop are; Commands, Groups, Items, Monster, Monsters, Mounts, Outfits, Quests, Spells, Stages & Vocations. You may find all of the examples (and their respective example output) on the GitHub repository wiki, but as to give you a small sample, here's an example of how to parse the demon.xml file.
PHP:
use pandaac\Exporter\Exporter;
use pandaac\Exporter\Parsers\Monster;
try {
$options = [
'health' => true,
'look' => true,
'targetchange' => true,
'flags' => true,
'attacks' => true,
'defenses' => true,
'elements' => true,
'immunities' => true,
'voices' => true,
'summons' => true,
'loot' => true,
];
$demon = new Exporter(
'./data/monster/Demons/demon.xml',
new Monster($options)
);
$response = $demon->export()->toJson();
} catch (Exception $e) {
// Log errors...
}
Code:
{
"name": "Demon",
"nameDescription": "a demon",
"race": "fire",
"experience": 6000,
"speed": 280,
"health": {
"now": 8200,
"max": 8200
},
"look": {
"type": 35,
"corpse": 5995
},
"targetchange": {
"interval": 4000,
"chance": 20
},
"flags": {
"attackable": 1,
"hostile": 1,
"canpushitems": 1,
"canpushcreatures": 1,
"targetdistance": 1,
"staticattack": 70
},
"attacks": [
{
"name": "melee",
"interval": 2000,
"skill": 70,
"attack": 130,
"attributes": [
]
},
{
"name": "manadrain",
"interval": 2000,
"max": -120,
"chance": 10,
"range": 7,
"attributes": [
]
},
{
"name": "fire",
"interval": 2000,
"min": -150,
"max": -250,
"chance": 20,
"range": 7,
"radius": 7,
"target": 1,
"attributes": {
"shootEffect": "fire",
"areaEffect": "firearea"
}
},
{
"name": "firefield",
"interval": 2000,
"chance": 10,
"range": 7,
"radius": 1,
"target": 1,
"attributes": {
"shootEffect": "fire"
}
},
{
"name": "lifedrain",
"interval": 2000,
"min": -300,
"max": -490,
"chance": 10,
"attributes": {
"areaEffect": "purpleenergy"
}
},
{
"name": "energy strike",
"interval": 2000,
"min": -210,
"max": -300,
"chance": 10,
"range": 1,
"attributes": [
]
},
{
"name": "speed",
"interval": 2000,
"chance": 15,
"radius": 1,
"target": 1,
"speedchange": -700,
"duration": 30000,
"attributes": {
"areaEffect": "redshimmer"
}
}
],
"defenses": {
"armor": 55,
"defense": 55,
"defenses": [
{
"name": "healing",
"interval": 2000,
"min": 180,
"max": 250,
"chance": 15,
"attributes": {
"areaEffect": "blueshimmer"
}
},
{
"name": "speed",
"interval": 2000,
"chance": 15,
"speedchange": 320,
"duration": 5000,
"attributes": {
"areaEffect": "redshimmer"
}
}
]
},
"elements": {
"physical": 30,
"death": 30,
"energy": 50,
"earth": 40,
"ice": -10,
"holy": -10
},
"immunities": {
"fire": 1,
"drown": 1,
"lifedrain": 1,
"paralyze": 1,
"invisible": 1
},
"voices": {
"interval": 5000,
"chance": 10,
"sentences": [
"Your soul will be mine!",
"MUHAHAHAHA!",
"CHAMEK ATH UTHUL ARAK!",
"I SMELL FEEEEAAAAAR!",
"Your resistance is futile!"
]
},
"summons": {
"maxSummons": 1,
"summons": [
{
"name": "fire elemental",
"interval": 2000,
"chance": 10
}
]
},
"loot": [
{
"id": 2148,
"countmax": 100,
"chance": 60000,
"comment": "gold coin"
},
{
"id": 2148,
"countmax": 99,
"chance": 60000,
"comment": "gold coin"
},
{
"id": 2152,
"countmax": 6,
"chance": 100000,
"comment": "platinum coin"
},
{
"id": 2795,
"countmax": 6,
"chance": 20740,
"comment": "fire mushroom"
},
{
"id": 8473,
"countmax": 3,
"chance": 20000,
"comment": "ultimate health potion"
},
{
"id": 7590,
"countmax": 3,
"chance": 14285,
"comment": "great mana potion"
},
{
"id": 2387,
"chance": 14285,
"comment": "double axe"
},
{
"id": 2149,
"chance": 10000,
"comment": "small emerald"
},
{
"id": 7368,
"countmax": 5,
"chance": 5263,
"comment": "assassin star"
},
{
"id": 2432,
"chance": 3703,
"comment": "fire axe"
},
{
"id": 2151,
"chance": 3571,
"comment": "talon"
},
{
"id": 2176,
"chance": 2854,
"comment": "orb"
},
{
"id": 2393,
"chance": 2000,
"comment": "giant sword"
},
{
"id": 2418,
"chance": 1428,
"comment": "golden sickle"
},
{
"id": 2165,
"chance": 1333,
"comment": "stealth ring"
},
{
"id": 2462,
"chance": 1204,
"comment": "devil helmet"
},
{
"id": 1982,
"chance": 1190,
"comment": "purple tome"
},
{
"id": 2179,
"chance": 1010,
"comment": "gold ring"
},
{
"id": 2171,
"chance": 813,
"comment": "platinum amulet"
},
{
"id": 2396,
"chance": 666,
"comment": "ice rapier"
},
{
"id": 2520,
"chance": 649,
"comment": "demon shield"
},
{
"id": 2214,
"chance": 473,
"comment": "ring of healing"
},
{
"id": 5954,
"chance": 467,
"comment": "demon horn"
},
{
"id": 2470,
"chance": 413,
"comment": "golden legs"
},
{
"id": 2514,
"chance": 389,
"comment": "mastermind shield"
},
{
"id": 2164,
"chance": 170,
"comment": "might ring"
},
{
"id": 2472,
"chance": 70,
"comment": "magic plate armor"
},
{
"id": 7393,
"chance": 100,
"comment": "demon trophy"
},
{
"id": 7382,
"chance": 80,
"comment": "demonrage sword"
}
]
}
PS. It is very much recommended to cache the result in some form or another.
PSS. It is also worth noting that the current version only officially supports The Forgotten Server 1.1.