Search by

vipertecpro / game3d-economy

vipertecpro

Wallet, lives, entitlements and a store interface for game3d games, with a clearly labelled demo store and simulated rewarded ads.

Package info

github.com/vipertecpro/game3d-economy

pkg:composer/vipertecpro/game3d-economy

Statistics

Installs: 0

Dependents: 0

Suggesters: 0

Stars: 0

Open Issues: 0

v0.1.0 2026-11-28 16:06 UTC

This package is auto-updated.

Last update: 2026-11-28 20:03:28 UTC


README

Latest version Tests PHP game3d Platforms Licence Downloads

An add-on for game3d, a paid plugin for NativePHP Mobile sold at https://vipertecpro.com/products/game3d-engine (Android only). This add-on is free and MIT, and needs game3d to run. It is an independent project, not made or endorsed by NativePHP.

A game's economy for games made with game3d: a wallet, lives that refill on the clock, things owned (earned or bought), a store interface and rewarded ads. PHP only, MIT. It saves through game3d-save, in its own slot.

use Vipertecpro\Game3dEconomy\{Economy, GrantSource};

$economy = app(Economy::class);
$economy->wallet()->spend('coins', 120);
$economy->lives()->configure(5, 1800)->lose();
$economy->entitlements()->grant('hero.ninja', GrantSource::Earned);

$result = $economy->store()->purchase('coins_500');   // Pending: show $result->sheet
$economy->complete($economy->store()->confirm($result->sheet->token));

Products come from config('game3d-economy.products'): consumable products give coins, entitlement products give a flag, and subscription products give a flag for a number of days.

Install

This add-on needs a game3d licence. From your dashboard at vipertecpro.com, add the game3d Composer repository and key (the two composer config commands shown there), then:

composer require vipertecpro/game3d-economy

game3d-save is installed with it.

  • Demo store: FakeStore charges nothing. Every sheet it opens is labelled "Demo store, no money is charged".
  • Demo ads: SimulatedAds stands in for rewarded ads, labelled "Simulated ad".
  • Release builds: game3d:doctor --release warns while either demo is active.
  • Real stores and ads: bind your own Store and AdProvider.
  • Lives: they refill on wall-clock time, so a refill goes on while the game is closed. A clock set back gains nothing; a clock set forward does gain lives (check against a server where that matters).
  • Owned flags: a flag both earned and bought stays owned after a refund.
  • Lost saves: if the economy's save is damaged, or loaded from its backup (perhaps one change behind), wasLost() says so, so the game can offer a restore. A save from a newer version of the game is read and never written over.
  • Purchases: each completed transaction is granted once. A subscription's flag lasts until the subscription ends. Open store and ad sheets are saved, so they can be finished in a later request.
  • Events: purchased and rewarded go to whatever onEvent() is given.

Testing

The tests need game3d ^2.1, which is not public, so they run where a licensed copy is installed: add the game3d repository as in Install, then run composer install and vendor/bin/pest.