littlecubiclegames / quests
任务组件
Requires
- php: ^7.2||^8
- doctrine/orm: ^2.5
- roave/security-advisories: dev-master
- symfony/console: ^5.3
- symfony/workflow: ^5.3
Requires (Dev)
- friendsofphp/php-cs-fixer: ^2.0
- phpstan/phpstan: ^0.12
- phpstan/phpstan-deprecation-rules: ^0.12.6
- phpstan/phpstan-phpunit: ^0.12
- phpstan/phpstan-strict-rules: ^0.12
- phpunit/phpunit: ^8.0
- silex/silex: dev-t/symfony-53
This package is auto-updated.
Last update: 2024-09-16 02:05:24 UTC
README
任务系统
安装
composer require littlecubiclegames/quests
用法
如果您没有使用Silex,请查看ServiceProvider
以了解如何初始化所有服务和需要注册哪些事件监听器。您将需要实现LittleCubicleGames\Quests\Initialization\QuestBuilderInterface
,该接口将根据任务定义数据创建实体类。您可能还需要用您自己的持久化存储覆盖当前使用的ArrayStorage
。
在您的Silex应用程序内部,您可以
$app = new \Silex\Application(); $app->register(new \LittleCubicleGames\Quests\ServiceProvider(), [ 'cubicle.quests.quests' => [], // load your quests (see quest definition below) 'cubicle.quests.slots' => [], // if you use the `StaticSlotLoader` define your quest slots here (see slot definition below) 'cubicle.quests.initializer.questbuilder' => null, // define your QuestBuilder ]); // In your app during boot, fetch current user id and initialize the quests $userId = null; $app['cubicle.quests.initializer']->initialize($userId); // In your controller advance quests as desired $app[''cubicle.quests.advancer']->startQuest($questId, $userId);
任务组件
任务
任务可以有一系列需要在完成任务之前完成(例如,用户需要登录5次)的任务。一个任务可以包含多个任务。可以使用布尔运算符AND
和OR
来组合任务。这些运算符也可以嵌套(例如,用户需要登录5次或太阳在照耀)。
触发器
为了决定在另一个任务完成后启动哪个任务,可以定义触发条件。然后,将启动第一个符合所有触发条件的任务。
槽
使用槽,可以限制同时打开的任务数量。每个槽允许一个打开的任务。可以使用开始和结束日期限制任务的可访问性,这对于有限的事件可能很有用。槽与注册表相关联。
进度监听器
每次启动任务时,都会自动注册所有必要的跟踪进度的活动。这发生在任务启动时或请求期间,您可以通过ProgressListener::registerQuest(QuestInterface $quest)
注册从数据库存储加载的单独任务。随着进度变化而完成的任务将自动将状态更改为completed
状态。您可以使用QuestInitializer
手动注册所有任务。
任务完成守卫
IsCompletedListener
是一个守卫,确保任务只有在所有任务都完成后才能更改为completed
状态。
无奖励监听器
某些任务可能没有完成的奖励。这样的任务将自动从completed
状态更改为closed
状态。
奖励
任务可以有多个奖励。每个奖励类型都需要有一个实现CollectorInterface
的收集器。一个任务可以有多个奖励,可以使用MultipleRewards
类来组合。奖励本身只能包含一个类型。其余的一切都应根据收集器的需求进行定制。
日志
任务日志允许记录每个状态变化。它可以服务于两个目的
- 这使得调试过程更容易,因为我们知道事情发生的时间
- 它可以显示给用户作为任务活动日志
任务状态
可用
任务一旦离开任务池,就达到的初始状态。
进行中
任务已启动,用户正在完成所有任务。
完成
此任务中的任务已完成。
完成
任务已完成,如果有的话,奖励已被收集。用户完成了任务,它不应再显示。
拒绝
用户或系统决定取消或拒绝任务。用户已完成任务,不应再显示。
槽定义数据(使用静态槽加载器)
[ { "id": "some-id", "registry": "reference to the registry id", "start": "2017-01-01", "end": "2018-01-01" } ]
注意:开始和结束是可选的。
任务定义数据
{ "id": "some-id", "task": { "operator": "and", "children" : [ { "id": "task-id-1", "type": "finish-quests", "operator": "less-than", "value": 10 }, { "operator": "or", "children": [ { "id": "task-id-2", "type": "finish-quests", "operator": "less-than", "value": 5 }, { "id": "task-id-3", "type": "finish-quests", "operator": "equal-to", "value": 2 } ] } ] }, "rewards": [ { "type": "reward-type" } ] }