PHP code example of luminoray / role-php

1. Go to this page and download the library: Download luminoray/role-php 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/ */

    

luminoray / role-php example snippets




interface iCharacter {
	public function __construct(iStatus $status);
	public function attack(iCharacter $target);
	public function skill($name, $level, iCharacter $target);
	public function __get($stat_prop);
}

class MY_Character extends LuminoRay\RolePHP\Character\Character {
	public function attack(LuminoRay\RolePHP\Character\iCharacter $target) {
		$damage = $this->attack - $target->defense;
		if ($damage > 0) {
			$new_health = $target->health - $damage;
		} else {
			$new_health = $target->health - 1;
		}
		$target->status->stat_set('health', $new_health, 0, 'greater_equal', 'set_constraint');
	}
	
	public function skill($name, $level, LuminoRay\RolePHP\Character\iCharacter $target) {
		echo ('Skills are not yet implemented.\n');
	}
}

interface iStatus {
	public function __construct(array $stat_array);
	public function stat_set($stat_prop, $value, $constraint, $compare, $fallback);
}

$player_array = array(
	'name' => 'LuminoRay',
	'health' => 20,
	'max_health' => 20,
	'attack' => 10,
	'defense' => 4
);

$enemy_array = array(
	'name' => 'Slime',
	'health' => 10,
	'max_health' => 10,
	'attack' => 7,
	'defense' => 2
);

$player_stats = new LuminoRay\RolePHP\Character\Status($player_array);
$enemy_array = new LuminoRay\RolePHP\Character\Status($enemy_array);

$player = new MY_Character($player_stats);
$enemy = new MY_Character($enemy_stats);

echo ("{$player->name} - {$player->health} / {$player->max_health} HP\n"); // LuminoRay - 20 / 20 HP
echo ("{$enemy->name} - {$enemy->health} / {$enemy->max_health} HP\n\n"); // Slime - 10 / 10 HP

$player->attack($enemy);
echo ("{$player->name} attacked {$enemy->name}!\n"); // LuminoRay attacked Slime!

echo ("{$player->name} - {$player->health} / {$player->max_health} HP\n"); // LuminoRay - 20 / 20 HP
echo ("{$enemy->name} - {$enemy->health} / {$enemy->max_health} HP\n\n"); // Slime - 2 / 10 HP

php composer.phar 

php composer.phar install

php composer.phar update