1. Go to this page and download the library: Download codryn/phpturntracker 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/ */
codryn / phpturntracker example snippets
use Codryn\PHPTurnTracker\Encounter;
use Codryn\PHPTurnTracker\Actor;
use Codryn\PHPTurnTracker\TimelineProfile;
use Codryn\PHPTurnTracker\TurnOrderType;
// 1. Create a timeline profile for your RPG system
$profile = new TimelineProfile(
type: TurnOrderType::ROUND_INDIVIDUAL,
minInitiative: 1,
maxInitiative: 30
);
// 2. Create an encounter
$encounter = new Encounter($profile);
// 3. Add participants
$encounter->addActor(new Actor('fighter', 'Conan', 18));
$encounter->addActor(new Actor('wizard', 'Gandalf', 15));
$encounter->addActor(new Actor('orc', 'Orc Warrior', 12));
// 4. Start combat
$encounter->start();
// 5. Run turns
while ($encounter->isActive()) {
$current = $encounter->getCurrentActor();
echo "It's {$current->getName()}'s turn! (Round {$encounter->getCurrentRound()})\n";
// ... resolve actor's actions ...
$encounter->advanceTurn();
}
$profile = new TimelineProfile(
type: TurnOrderType::SLOT,
slotConfiguration: [
['type' => 'PC', 'initiative' => 3],
['type' => 'NPC', 'initiative' => 2],
['type' => 'PC', 'initiative' => 2],
['type' => 'NPC', 'initiative' => 1]
]
);
// Any PC can fill PC slots, any NPC can fill NPC slots
// Players choose which character acts in each slot
$profile = new TimelineProfile(
type: TurnOrderType::POPCORN,
allowRepeatPopcorn: false // Can't designate someone who already acted
);
$encounter->start();
// Current actor designates who goes next
$encounter->designateNext('hero2');
$profile = new TimelineProfile(
type: TurnOrderType::ROUND_SIDE
);
$encounter->addActor(new Actor('fighter', 'Fighter', 15, ['side' => 'players']));
$encounter->addActor(new Actor('cleric', 'Cleric', 12, ['side' => 'players']));
$encounter->addActor(new Actor('goblin1', 'Goblin', 10, ['side' => 'monsters']));
// All players act, then all monsters act
// Check current round/pass
$round = $encounter->getCurrentRound();
$pass = $encounter->getCurrentPass(); // For pass-based systems
// Query actor status
$acted = $encounter->getActedActors();
$waiting = $encounter->getUnactedActors();
// Check if encounter is active
if ($encounter->isActive()) {
// Combat ongoing
}
use Codryn\PHPTurnTracker\State\EncounterSnapshot;
// Capture current state
$snapshot = $encounter->getState();
// Serialize to JSON for storage
$json = $snapshot->toJson();
file_put_contents('encounter_state.json', $json);
// Later: Load and restore state
$json = file_get_contents('encounter_state.json');
$snapshot = EncounterSnapshot::fromJsonString($json);
$newEncounter = new Encounter(new TimelineProfile(TurnOrderType::ROUND_INDIVIDUAL));
$newEncounter->restoreState($snapshot);
// Continue from exact same state
$encounter->advanceTurn();
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.