PHP code example of takpesar / fruitcraft

1. Go to this page and download the library: Download takpesar/fruitcraft library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

takpesar / fruitcraft example snippets




ak\FruitCraft\Client;

use Tak\FruitCraft\Errors;

# your restore key, you can get it from the game settings
$restore_key = 'fight123456789';

$passport = md5($restore_key);

$session_path = __DIR__.DIRECTORY_SEPARATOR.$passport.'.txt';

$client = new Client(passport : $passport);

# Save it to use it later for load the plyer and set the $client->player
if(file_exists($session_path)){
    $client->player = unserialize(file_get_contents($session_path));
} else {
    $player = $client->login($restore_key)->data;
    echo 'Sign in as '.$player->name , PHP_EOL;
}

file_put_contents($session_path,serialize($client->player));

# You are now ready to use the implemented methods :)
# for example ...

$heroes = $client->getheroes();

$ids = array_column($heroes,'base_card_id');

foreach($ids as $id){
    try {
        var_dump($client->player_fillpotion(amount : 50));
        var_dump($client->cards_potionize(hero_id : $id));
    } catch(Errors $e){
         if($e->getCode() === 400){
            # ERROR_CODE_{$X} : 400 #
            echo 'Error : ' , $client->geterrormessage($e->getValue()) , PHP_EOL;
         } else {
            echo 'Error : ' , strval($e) , PHP_EOL;
         }
    }
}