[PHP] pandaac Exporter

Discussion in 'Web-development' started by Chris, May 27, 2016.

  1. Chris

    Chris Inactive

    Joined:
    Aug 11, 2008
    Messages:
    2,628
    Likes Received:
    235
    Best Answers:
    2
    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.

    PHP:
    1. use pandaac\Exporter\Exporter;
    2. use pandaac\Exporter\Parsers\Monster;
    3.  
    4. try {
    5.  
    6.   $options = [
    7.     'health'        => true,
    8.     'look'          => true,
    9.     'targetchange'  => true,
    10.     'flags'         => true,
    11.     'attacks'       => true,
    12.     'defenses'      => true,
    13.     'elements'      => true,
    14.     'immunities'    => true,
    15.     'voices'        => true,
    16.     'summons'       => true,
    17.     'loot'          => true,
    18.   ];
    19.  
    20.   $demon = new Exporter(
    21.     './data/monster/Demons/demon.xml',
    22.     new Monster($options)
    23.   );
    24.  
    25.   $response = $demon->export()->toJson();
    26.  
    27. } catch (Exception $e) {
    28.   // Log errors...
    29. }
    and what it outputs (in JSON);
    Code (Text):
    1. {
    2.   "name": "Demon",
    3.   "nameDescription": "a demon",
    4.   "race": "fire",
    5.   "experience": 6000,
    6.   "speed": 280,
    7.   "health": {
    8.     "now": 8200,
    9.     "max": 8200
    10.   },
    11.   "look": {
    12.     "type": 35,
    13.     "corpse": 5995
    14.   },
    15.   "targetchange": {
    16.     "interval": 4000,
    17.     "chance": 20
    18.   },
    19.   "flags": {
    20.     "attackable": 1,
    21.     "hostile": 1,
    22.     "canpushitems": 1,
    23.     "canpushcreatures": 1,
    24.     "targetdistance": 1,
    25.     "staticattack": 70
    26.   },
    27.   "attacks": [
    28.     {
    29.       "name": "melee",
    30.       "interval": 2000,
    31.       "skill": 70,
    32.       "attack": 130,
    33.       "attributes": [
    34.  
    35.       ]
    36.     },
    37.     {
    38.       "name": "manadrain",
    39.       "interval": 2000,
    40.       "max": -120,
    41.       "chance": 10,
    42.       "range": 7,
    43.       "attributes": [
    44.  
    45.       ]
    46.     },
    47.     {
    48.       "name": "fire",
    49.       "interval": 2000,
    50.       "min": -150,
    51.       "max": -250,
    52.       "chance": 20,
    53.       "range": 7,
    54.       "radius": 7,
    55.       "target": 1,
    56.       "attributes": {
    57.         "shootEffect": "fire",
    58.         "areaEffect": "firearea"
    59.       }
    60.     },
    61.     {
    62.       "name": "firefield",
    63.       "interval": 2000,
    64.       "chance": 10,
    65.       "range": 7,
    66.       "radius": 1,
    67.       "target": 1,
    68.       "attributes": {
    69.         "shootEffect": "fire"
    70.       }
    71.     },
    72.     {
    73.       "name": "lifedrain",
    74.       "interval": 2000,
    75.       "min": -300,
    76.       "max": -490,
    77.       "chance": 10,
    78.       "attributes": {
    79.         "areaEffect": "purpleenergy"
    80.       }
    81.     },
    82.     {
    83.       "name": "energy strike",
    84.       "interval": 2000,
    85.       "min": -210,
    86.       "max": -300,
    87.       "chance": 10,
    88.       "range": 1,
    89.       "attributes": [
    90.  
    91.       ]
    92.     },
    93.     {
    94.       "name": "speed",
    95.       "interval": 2000,
    96.       "chance": 15,
    97.       "radius": 1,
    98.       "target": 1,
    99.       "speedchange": -700,
    100.       "duration": 30000,
    101.       "attributes": {
    102.         "areaEffect": "redshimmer"
    103.       }
    104.     }
    105.   ],
    106.   "defenses": {
    107.     "armor": 55,
    108.     "defense": 55,
    109.     "defenses": [
    110.       {
    111.         "name": "healing",
    112.         "interval": 2000,
    113.         "min": 180,
    114.         "max": 250,
    115.         "chance": 15,
    116.         "attributes": {
    117.           "areaEffect": "blueshimmer"
    118.         }
    119.       },
    120.       {
    121.         "name": "speed",
    122.         "interval": 2000,
    123.         "chance": 15,
    124.         "speedchange": 320,
    125.         "duration": 5000,
    126.         "attributes": {
    127.           "areaEffect": "redshimmer"
    128.         }
    129.       }
    130.     ]
    131.   },
    132.   "elements": {
    133.     "physical": 30,
    134.     "death": 30,
    135.     "energy": 50,
    136.     "earth": 40,
    137.     "ice": -10,
    138.     "holy": -10
    139.   },
    140.   "immunities": {
    141.     "fire": 1,
    142.     "drown": 1,
    143.     "lifedrain": 1,
    144.     "paralyze": 1,
    145.     "invisible": 1
    146.   },
    147.   "voices": {
    148.     "interval": 5000,
    149.     "chance": 10,
    150.     "sentences": [
    151.       "Your soul will be mine!",
    152.       "MUHAHAHAHA!",
    153.       "CHAMEK ATH UTHUL ARAK!",
    154.       "I SMELL FEEEEAAAAAR!",
    155.       "Your resistance is futile!"
    156.     ]
    157.   },
    158.   "summons": {
    159.     "maxSummons": 1,
    160.     "summons": [
    161.       {
    162.         "name": "fire elemental",
    163.         "interval": 2000,
    164.         "chance": 10
    165.       }
    166.     ]
    167.   },
    168.   "loot": [
    169.     {
    170.       "id": 2148,
    171.       "countmax": 100,
    172.       "chance": 60000,
    173.       "comment": "gold coin"
    174.     },
    175.     {
    176.       "id": 2148,
    177.       "countmax": 99,
    178.       "chance": 60000,
    179.       "comment": "gold coin"
    180.     },
    181.     {
    182.       "id": 2152,
    183.       "countmax": 6,
    184.       "chance": 100000,
    185.       "comment": "platinum coin"
    186.     },
    187.     {
    188.       "id": 2795,
    189.       "countmax": 6,
    190.       "chance": 20740,
    191.       "comment": "fire mushroom"
    192.     },
    193.     {
    194.       "id": 8473,
    195.       "countmax": 3,
    196.       "chance": 20000,
    197.       "comment": "ultimate health potion"
    198.     },
    199.     {
    200.       "id": 7590,
    201.       "countmax": 3,
    202.       "chance": 14285,
    203.       "comment": "great mana potion"
    204.     },
    205.     {
    206.       "id": 2387,
    207.       "chance": 14285,
    208.       "comment": "double axe"
    209.     },
    210.     {
    211.       "id": 2149,
    212.       "chance": 10000,
    213.       "comment": "small emerald"
    214.     },
    215.     {
    216.       "id": 7368,
    217.       "countmax": 5,
    218.       "chance": 5263,
    219.       "comment": "assassin star"
    220.     },
    221.     {
    222.       "id": 2432,
    223.       "chance": 3703,
    224.       "comment": "fire axe"
    225.     },
    226.     {
    227.       "id": 2151,
    228.       "chance": 3571,
    229.       "comment": "talon"
    230.     },
    231.     {
    232.       "id": 2176,
    233.       "chance": 2854,
    234.       "comment": "orb"
    235.     },
    236.     {
    237.       "id": 2393,
    238.       "chance": 2000,
    239.       "comment": "giant sword"
    240.     },
    241.     {
    242.       "id": 2418,
    243.       "chance": 1428,
    244.       "comment": "golden sickle"
    245.     },
    246.     {
    247.       "id": 2165,
    248.       "chance": 1333,
    249.       "comment": "stealth ring"
    250.     },
    251.     {
    252.       "id": 2462,
    253.       "chance": 1204,
    254.       "comment": "devil helmet"
    255.     },
    256.     {
    257.       "id": 1982,
    258.       "chance": 1190,
    259.       "comment": "purple tome"
    260.     },
    261.     {
    262.       "id": 2179,
    263.       "chance": 1010,
    264.       "comment": "gold ring"
    265.     },
    266.     {
    267.       "id": 2171,
    268.       "chance": 813,
    269.       "comment": "platinum amulet"
    270.     },
    271.     {
    272.       "id": 2396,
    273.       "chance": 666,
    274.       "comment": "ice rapier"
    275.     },
    276.     {
    277.       "id": 2520,
    278.       "chance": 649,
    279.       "comment": "demon shield"
    280.     },
    281.     {
    282.       "id": 2214,
    283.       "chance": 473,
    284.       "comment": "ring of healing"
    285.     },
    286.     {
    287.       "id": 5954,
    288.       "chance": 467,
    289.       "comment": "demon horn"
    290.     },
    291.     {
    292.       "id": 2470,
    293.       "chance": 413,
    294.       "comment": "golden legs"
    295.     },
    296.     {
    297.       "id": 2514,
    298.       "chance": 389,
    299.       "comment": "mastermind shield"
    300.     },
    301.     {
    302.       "id": 2164,
    303.       "chance": 170,
    304.       "comment": "might ring"
    305.     },
    306.     {
    307.       "id": 2472,
    308.       "chance": 70,
    309.       "comment": "magic plate armor"
    310.     },
    311.     {
    312.       "id": 7393,
    313.       "chance": 100,
    314.       "comment": "demon trophy"
    315.     },
    316.     {
    317.       "id": 7382,
    318.       "chance": 80,
    319.       "comment": "demonrage sword"
    320.     }
    321.   ]
    322. }
    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.
     
  2. Raggaer

    Raggaer Godly Member

    Joined:
    Jul 25, 2012
    Messages:
    1,291
    Likes Received:
    642
    Best Answers:
    5
    This deserves more love <3
     
    Omni Cloud and Chris like this.
  3. Omni Cloud

    Omni Cloud Banned User

    Joined:
    May 31, 2016
    Messages:
    312
    Likes Received:
    151
    Best Answers:
    0
    Maybe years ago something like this may have gotten more love but sadly if something is not plug and play then it is simply ignored by the vast majority of members.
     
    Raggaer likes this.

Share This Page

Loading...