codryn/phpdice 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

codryn/phpdice

最新稳定版本:0.2.1

Composer 安装命令:

composer require codryn/phpdice

包简介

A comprehensive PHP library for parsing and rolling dice expressions for tabletop RPG systems

README 文档

README

A comprehensive PHP library for parsing and rolling dice expressions for tabletop RPG systems.

Features

  • Universal Dice Notation: Support for all major RPG systems (D&D 5e, Pathfinder, Shadowrun, World of Darkness, FATE, Savage Worlds, etc.)
  • Advanced Mechanics: Advantage/disadvantage, success counting, rerolls, exploding dice, critical detection, DC comparisons
  • Statistical Analysis: Pre-calculated min/max/expected values for any expression
  • Placeholder Variables: Character sheet integration with $variable$ syntax
  • Complex Arithmetic: Full expression evaluation with operator precedence and parentheses
  • Error Handling: Clear, specific error messages with location information
  • High Performance: Parse <100ms, Roll <50ms for complex expressions
  • Type Safe: Full PHP 8.0+ type declarations and strict mode
  • Well Tested: 235+ tests with comprehensive coverage

Requirements

  • PHP 8.0 or higher

Installation

composer require phpdice/phpdice

Quick Start and Usage

<?php
require 'vendor/autoload.php';

use PHPDice\PHPDice;

// Create instance
$dice = new PHPDice();

// Roll dice directly
$result = $dice->roll("3d6");

echo "Rolled: " . $result->total . "\n";
echo "Dice: " . implode(", ", $result->diceValues) . "\n";

// Example output:
// Rolled: 14
// Dice: 5, 6, 3

See docs/quickstart.md for a 10-minute tutorial.

Dice Expressions

See docs/expressions.md for all supported dice expressions.

Game System Support

System Example Features
D&D 5e 1d20+5 >= 15 crit 20 Advantage, modifiers, comparisons, criticals
Pathfinder 3d6+2 Basic dice, modifiers
Shadowrun 5e 12d6 reroll ==1 >=5 Success counting, rerolls
World of Darkness 10d10 >=8 Success counting
FATE 4dF+2 Fudge dice, modifiers
Savage Worlds 1d6 explode + 1d8 explode Exploding dice
Call of Cthulhu d% Percentile dice

API Overview

See docs/api.md for complete reference.

Documentation

Development

See CONTRIBUTING.md for development guidelines.

Performance

PHPDice is optimized for real-time use:

  • Parsing: <100ms for complex expressions
  • Rolling: <50ms for typical rolls
  • Memory: <1MB per operation

Tips for best performance:

  • Reuse parsed DiceExpression objects for repeated rolls
  • Set reasonable explosion/reroll limits (default 100 is safe)
  • Use getStatistics() for probability analysis instead of Monte Carlo simulation

License

MIT License - see LICENSE file for details.

Contributing

Contributions are welcome! See CONTRIBUTING.md for:

  • Development workflow
  • Coding standards
  • Testing requirements
  • Pull request process

Changelog

See CHANGELOG.md for version history and migration guides.

Support

Credits

Developed with adherence to:

  • PSR-12 coding standards
  • PHPStan level 9 strict analysis
  • Test-Driven Development (TDD)
  • Comprehensive documentation

Built for the tabletop RPG community 🎲

统计信息

  • 总下载量: 10
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2026-01-06