• There is NO official Otland's Discord server and NO official Otland's server list. The Otland's Staff does not manage any Discord server or server list. Moderators or administrator of any Discord server or server lists have NO connection to the Otland's Staff. Do not get scammed!

Script to help you with your raids.xml

gudan garam

Advanced OT User
Joined
Feb 13, 2011
Messages
353
Solutions
17
Reaction score
173
Location
São Paulo.
Hello otland people.

So, I'm working on a server project right now and my actual task is to setup the server raids. After reading the sources on the raids system I came up with a complex, elaborate, very hard to compreend php script that took me days without sleep to write.

What you need to do: You feed it your raids.xml content and input the amount of days you want to run the test for.

What the script will do for you: It will, based on your raids, tell you how many times each raid would have ran (i dont know past english basic gramar) after the amount of days you put (ordered from least to most runned raid, srsly mind blowing). Cool right?

The only thing you need to change is the xml and the number of days you want to run the test for. You can run it on your shell or command line, or, as I did on PHPTESTER - Test PHP code online (http://phptester.net/).

Here:

PHP:
<?php
// Only change XMLSTRING and days variables.
// Margins higher than 1440 don't make sense.

$days = 180; // ONLY CHANGE THIS

$XMLSTRING ='
<raids>
<raid name="Zulazza the Corruptor"         file="Zulazza the Corruptor.xml"         interval2="30000"         margin="60"         /> 
<raid name="Apocalypse"                 file="Apocalypse.xml"                     interval2="45000"         margin="60"         /> 
<raid name="Morgaroth"                     file="Morgaroth.xml"                     interval2="25000"         margin="60"         /> 
<raid name="RatsThais"                     file="ratsthais.xml"                     interval2="5000"         margin="30"         /> 
<raid name="OrcsThais"                     file="OrcsThais.xml"                     interval2="11000"         margin="30"         /> 
<raid name="Barbarian"                    file="Barbarian.xml"                     interval2="8000"         margin="30"         /> 
<raid name="Demodras"                    file="Demodras.xml"                     interval2="12000"         margin="30"         /> 
<raid name="Ferumbras"                    file="Ferumbras.xml"                     interval2="35000"         margin="60"         /> 
<raid name="Ghazbaran"                    file="Ghazbaran.xml"                     interval2="22000"         margin="60"         /> 
<raid name="Horned Fox"                 file="horned.xml"                         interval2="9000"         margin="30"         /> 
<raid name="Necropharus"                file="Necropharus.xml"                     interval2="8000"         margin="30"         /> 
<raid name="Nomads"                     file="nomads.xml"                         interval2="7000"         margin="30"         /> 
<raid name="Orshabaal"                     file="Orshabaal.xml"                     interval2="19000"         margin="60"         /> 
<raid name="Pirates"                     file="Pirates.xml"                         interval2="13000"         margin="30"         /> 
<raid name="Quaras"                     file="quaras.xml"                         interval2="11000"         margin="30"         /> 
<raid name="Scarabs"                     file="Scarabs.xml"                         interval2="5000"         margin="30"         /> 
<raid name="Old Widow"                     file="The Old Widow.xml"                 interval2="9000"         margin="30"         />
<raid name="Undead Army"                 file="undead army.xml"                     interval2="7000"         margin="30"         />
<raid name="Undead Darashia"             file="undead darashia.xml"                 interval2="7500"         margin="30"         />
<raid name="Sir the Ancient One"         file="Arachir the Ancient One.xml"         interval2="9000"         margin="30"         /> 
</raids>
';


// DON'T CHANGE ANYTHING BELOW THIS LINE IF YOU DON'T WANT, IF YOU WANT TO CHANGE, THEN DO IT THIS IS JUST A COMMENT, I CAN'T OBLIGATE YOU TO DO ANYTHING

$xml = simplexml_load_string($XMLSTRING, "SimpleXMLElement", LIBXML_NOCDATA);
$raidsFromXml = json_decode(json_encode($xml), 1)['raid'];
$raids = [];
foreach($raidsFromXml as $raidxml) {
    if (!array_key_exists('name', $raidxml['@attributes'])) {
        echo ' no name <br> ' . PHP_EOL;
        continue;
    }
    if (!array_key_exists('margin', $raidxml['@attributes'])) {
        echo ' no margin <br> ' . PHP_EOL;
        continue;
    }
    if (!array_key_exists('interval2', $raidxml['@attributes'])) {
        echo ' no interval2 <br> ' . PHP_EOL;
        continue;
    }

    $raids[] = [
        "name" =>  $raidxml['@attributes']['name'],
        "interval" => $raidxml['@attributes']['interval2'],
        "margin" => $raidxml['@attributes']['margin'],
        "repeat" => array_key_exists('repeat', $raidxml['@attributes']) ? $raidxml['@attributes']['repeat'] : false,
        "done" => false, // don't touch
        "times" => 0 // don't touch
    ];
}

// DO NOT CHANGE THIS VARIABLES
$MAX_RAND_RANGE = 10000000;
$CHECK_RAIDS_INTERVAL = 60;
$mins = 1435; // how many times Raids::checkRaids runs in a day. (once every minute) removed 5 minutes for serversave
$lastRaid = [0,0]; // day, min

for ($d = 1; $d < $days; $d++) 
{
    // Reload raids every server save;
    foreach($raids as $kk => $rs) {
        $raids[$kk]['done'] = false;
    }
    
    for($min = 1; $min < $mins; $min++) { // minutes
        foreach($raids as $k => $raid) {
            if (!$raid['done']){
                if ($lastRaid[0] == 0 
                   || $lastRaid[0] < $d 
                   || $lastRaid[0] == $d && ($min >= $lastRaid[1] + $raid['margin'])) {
                    
                    $interval = $raid['interval'] * 60;
                    $name = $raid['name'];
                    if ((($MAX_RAND_RANGE * $CHECK_RAIDS_INTERVAL) / $interval) >= random_int(0, $MAX_RAND_RANGE)) {
                        $raids[$k]['times'] += 1;
                        $lastRaid = [$d, $min];
                        
                        if ($raid['repeat'] == false) {
                            $raids[$k]['done'] = true;    
                        }
                    }
                } 
            }
        }
        
    }
}

$sort = array_column($raids, 'times');

array_multisort($sort, SORT_ASC, $raids);


foreach($raids as $raid) {
    echo "Raid {$raid['name']} happened {$raid['times']} times in $days days. <br>" . PHP_EOL;
    echo "<br>" . PHP_EOL;
}

This is an example output:
raids.png
Notes to you guys tring to figure out the sweet spot on interval2 and margin on your servers:

When you add a raid to your XML, expect it to change (sometimes a lot) the trigger of other raids. (Think of each raid as competitors against each other, the more competitors the less winners in %, also)
I've seen datapacks everywhere with numbers that would make a Ferumbras raid happen almost every day (IDK if its on purpose, I hope not).
The numbers I left on my script's xml example are very high but they make more sense then with I saw on the internet (at least for me). (I hope i didn't get this completely wrong)

Fast explanation of the raid system:

Every 60 seconds, it loops through your raids, gets a random number between 0 and 10000000, checks if that is lower than (600000000 / interval2) if that is true, AND, the last raid was at least "margin" minutes ago, it will run the raid. So, I'd put a standard margin for simple raids and a little bit higher for rare bosses (like my xml sample, it uses 30 and 60 as margins only) and only adjust the interval2 field.

If someone here that understands the raid system better than me and thinks my script is wrong just tell me and I'll try to fix. It uses the same logic as TFS 1.3 (actual) raid system, the only thing different, obviously, is it uses a php function to generate a random number, where as TFS uses a C++ one. (random numbers I excpect)

Already wrote too much, sorry.
 
Last edited:

Similar threads

Back
Top