From 70f78007d2e211b93c780660a835e454f02580ac Mon Sep 17 00:00:00 2001 From: Sascha Grossenbacher Date: 2008年12月16日 22:51:38 +0100 Subject: [PATCH 1/6] test change --- tests/characterTest.php | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/characterTest.php b/tests/characterTest.php index cd5c134..a0d3e4a 100644 --- a/tests/characterTest.php +++ b/tests/characterTest.php @@ -49,6 +49,7 @@ /** * Description for include */ + include '../init.php'; Language::setLanguage('German'); Logger::addListener('StdOut'); From b8ca76f464f93821ef727e31215879242de07545 Mon Sep 17 00:00:00 2001 From: Sascha Grossenbacher Date: 2009年9月25日 13:48:11 +0200 Subject: [PATCH 2/6] added interpreter --- nbproject/private/config.properties | 0 nbproject/private/private.properties | 1 + nbproject/private/private.xml | 4 ++++ tests/.characterTest.php.swp | Bin 0 -> 12288 bytes 4 files changed, 5 insertions(+) create mode 100644 nbproject/private/config.properties create mode 100644 nbproject/private/private.xml create mode 100644 tests/.characterTest.php.swp diff --git a/nbproject/private/config.properties b/nbproject/private/config.properties new file mode 100644 index 0000000..e69de29 diff --git a/nbproject/private/private.properties b/nbproject/private/private.properties index 749786d..c049026 100644 --- a/nbproject/private/private.properties +++ b/nbproject/private/private.properties @@ -1,5 +1,6 @@ copy.src.files=false copy.src.target=/var/www/dnd index.file=tests/characterTest.php +interpreter=/usr/bin/php53 run.as=SCRIPT url=http://localhost/dnd/ diff --git a/nbproject/private/private.xml b/nbproject/private/private.xml new file mode 100644 index 0000000..c1f155a --- /dev/null +++ b/nbproject/private/private.xml @@ -0,0 +1,4 @@ + + + + diff --git a/tests/.characterTest.php.swp b/tests/.characterTest.php.swp new file mode 100644 index 0000000000000000000000000000000000000000..da2afd1125def36295654669142a8cec93bf8f9a GIT binary patch literal 12288 zcmeHNO^@V88LmM1CLw@0fH+i!71Oin>D~_nq-Qf(PrIhulBeC+?wOsi(#maDcbjqB zEq}~tkOC(T1R=p87bGMiaY7sbB@&S$&LDB%03kwL;1_TLDS*WDmfbTwv)Ki$xJ0t0 zXWCtUKc9N*Ew`q|*Y=G){-xFphU+QDezDd!9{9g^Eb}sd=Fx+PU&XkH^I|if zh4InC3mz!^jnZIym?mG7N4abVanR0XmS=7FNj*Q8sf(|z#cc6FBlUxtftrCwWZ(&Q z^TzdSr2M(Hr}-y8F?vKhwOY+U%|OjS%|OjS%|OjS%|OjS&A_{nfqd~8`z8W^PZhjf zeLi;Sv-(ANU?{3fuvn1=fJK-_O{az$?Iuz*m6|@M+*vz+3M_zQA{Z z5D>uAz`q}7>`%a(z)yi6051YVU>kT6_%pbC10YU+Nxarq&A|Vgf#C)cK^CeJf0iU!=`NNh{63dufJ&G@4ドルSH_Q_Cz?V;L7=6e!!v3^SQ) z<1h;iq^!wi*|?jbul1i7prxsi3sg*cR{#~8T$xowVf5DygT_BADP zz4>671H(}=Hy$FRi#tl@=0jw<)&_~B>+eXPa}-7qxI-X9xJX@GB4#Nd2Kva>23>JEo27u} z_D$jTjjn@SCgF63LtmTQWx2Si7sfJBqGyRzGDzX9o-zO32#GhSZq%L3?(UYhE>=Dy zZO@lVkZ$hkCtf;Pm4V$JioetGf}p!Rh1OW#QHzPlD4)U*t&zq9ドルZ;j;G^y8D=@r zN=yb;Q9kzKY2i&_7n)}ErLo?V>D-G+KaBmT2qa%`wc1!c>d@Qz7GwNs8{oRk{4`wT zVG{F6lJZKNwXa@fEWk>>7s!cMMESiuoXf8#vAhRIjdf9^$wIbYDALfMksnrMlIyW9 z;wiYjs}|zcrNOgha^C}DS!S1qiODS%gO6;1+jH|+b!GUsGbw3x;j-mKrZV<@y=spsemobv(ys~w2a?%1hah4rrfi!1ezayp!$=c&a*sq*gjmpxt z-*I$qmIBJ4pDa#Osxp4#+O;opM;(vky)*$w@!0c`nUeF0e1<8bh~7bj-ztwmpn8>u zI`_h;-D@)yxE%pR@ zy-It>aSeCm3f{9U-602#u=kCwfHxBykrXU8L5{06@tmxPJ7RBWYW5)wP(F_M$_OS6 z&8$dtRx)TJW|t2vN_5X~5uIzH3tlaWF!0c_9lj$J52oO|uu0tNhAoICV{m@gHFWsV zOmH_8UHDUmG(Oa9*XWKA6CaLjOs>F837BxYre^F3y+zCqEL9FJclw%XsygUe!$aHX z^+CtM0Q{8+t^}&245VuyaFi69xN8W-%bu{YAtIcrj)-*3lbRhQK`E|jm?&pW%?ITq z?hI|3JfwKPO-i+z^)t@M2$j=WMZ+A`!#;@6`Oe{`B>I-A3$RI{s5-0YB{P#WnR6UQ z&Ultga`b!2PeQE7BInsc`r#z>`63OmLQm2#N9X1Xbmb8HXcDVMG51dSSaLMZfLfM} zgCs>Cfx-f&lU&kgQ22Sq1DS@$G9b6l@PULIbT|Cr)Es#-QTMkjyQd9|7c?s2Z63qW zQY0gp5Qh9D&eL#QU`Ni#TG=P(Somq^MHzWK4g&;4sVMaTyN=RWhOJVLFiJLIF9^#X zi&rD1FiD~)ISJz_hpHcW*f(fjDUBt5F_&@fsSO7j?L_smXVAV^9c8324r33^2;0(} z&kOiVWl4xsw!Cq2ED^x6S;k3@CaMbfQ9@Kxa(^7ivFzjUgl)8nBgYHGe+z;NLd`hl zJ~$^fpLzKuo>obO(p=^pnwyK1VE+oJR*0D@A{tpCDQlLqMio~T;yekc4i(+y(vBjo z_LdB6W->)lQR3uo*dOxcCU>(MGZUJ|m3M^YM#{^bl=K{ILiq(DdXbofkyLLHx1OhC G_WuDUB{$;$ literal 0 HcmV?d00001 From 0be1862503c5dbadfe21c497e86c2f4a57140719 Mon Sep 17 00:00:00 2001 From: Sascha Grossenbacher Date: 2009年9月25日 15:01:50 +0200 Subject: [PATCH 3/6] CS-Fix --- .project | 32 ++++++++++++++++++++++++++++++++ tests/characterTest.php | 2 +- 2 files changed, 33 insertions(+), 1 deletion(-) create mode 100644 .project diff --git a/.project b/.project new file mode 100644 index 0000000..f73ee75 --- /dev/null +++ b/.project @@ -0,0 +1,32 @@ + + + DnDEngine + + + + + + org.eclipse.wst.validation.validationbuilder + + + + + org.eclipse.dltk.core.scriptbuilder + + + + + org.eclipse.php.core.PhpIncrementalProjectBuilder + + + + + org.eclipse.php.core.ValidationManagerWrapper + + + + + + org.eclipse.php.core.PHPNature + + diff --git a/tests/characterTest.php b/tests/characterTest.php index a0d3e4a..f3b6faf 100644 --- a/tests/characterTest.php +++ b/tests/characterTest.php @@ -69,7 +69,7 @@ Constants\Abilities::DEX => 13, Constants\Abilities::WIS => 12, Constants\Abilities::CHA => 11, - Constants\Abilities::INT => 10 + Constants\Abilities::INT => 10, )); $berdir->setAbilityScore($standardArray); $berdir->build(); From cc25a41e137c755a3e42d15b44dbb2cca3cc0352 Mon Sep 17 00:00:00 2001 From: Sascha Grossenbacher Date: 2011年2月21日 14:07:47 +0100 Subject: [PATCH 4/6] Rolling Score, Dices and other changes. --- .project | 32 ------ ...AbilityGenerator.php => AbilityHelper.php} | 17 ++- DnDEngine/Character.php | 2 +- DnDEngine/Dice/Dice.php | 84 ++++++++++++++ DnDEngine/Exception/PrerequisitesNotMet.php | 29 +++++ DnDEngine/Feats/Powerattack.php | 2 +- DnDEngine/Game.php | 15 +++ DnDEngine/GeneratorHelper/RollingScore.php | 103 ++++++++++++++++++ .../{Standardarray.php => StandardArray.php} | 0 DnDEngine/Level.php | 2 +- DnDEngine/interfaces/iDice.php | 22 ++++ nbproject/project.properties | 3 +- tests/characterTest.php | 7 +- 13 files changed, 278 insertions(+), 40 deletions(-) delete mode 100644 .project rename DnDEngine/{AbilityGenerator.php => AbilityHelper.php} (86%) create mode 100644 DnDEngine/Dice/Dice.php create mode 100644 DnDEngine/Exception/PrerequisitesNotMet.php create mode 100644 DnDEngine/GeneratorHelper/RollingScore.php rename DnDEngine/GeneratorHelper/{Standardarray.php => StandardArray.php} (100%) create mode 100644 DnDEngine/interfaces/iDice.php diff --git a/.project b/.project deleted file mode 100644 index f73ee75..0000000 --- a/.project +++ /dev/null @@ -1,32 +0,0 @@ - - - DnDEngine - - - - - - org.eclipse.wst.validation.validationbuilder - - - - - org.eclipse.dltk.core.scriptbuilder - - - - - org.eclipse.php.core.PhpIncrementalProjectBuilder - - - - - org.eclipse.php.core.ValidationManagerWrapper - - - - - - org.eclipse.php.core.PHPNature - - diff --git a/DnDEngine/AbilityGenerator.php b/DnDEngine/AbilityHelper.php similarity index 86% rename from DnDEngine/AbilityGenerator.php rename to DnDEngine/AbilityHelper.php index badc3f8..52ef28a 100644 --- a/DnDEngine/AbilityGenerator.php +++ b/DnDEngine/AbilityHelper.php @@ -43,7 +43,7 @@ /** * PHP Template. */ -class AbilityGenerator +class AbilityHelper { /** * Short description for function @@ -54,10 +54,21 @@ class AbilityGenerator * @return object Return description (if any) ... * @access public */ - public static function factory($type) + public static function factoryGenerator($type) { - $class = __NAMESPACE__ . '\\GeneratorHelper_' . ucfirst(strtolower($type)); + $class = __NAMESPACE__ . '\\GeneratorHelper_' . ucfirst($type); return new $class(); } + + public static function getAbilities() { + return array( + Constants\Abilities::STR, + Constants\Abilities::CON, + Constants\Abilities::DEX, + Constants\Abilities::WIS, + Constants\Abilities::INT, + Constants\Abilities::CHA, + ); + } } ?> diff --git a/DnDEngine/Character.php b/DnDEngine/Character.php index d50031e..36da8cc 100644 --- a/DnDEngine/Character.php +++ b/DnDEngine/Character.php @@ -534,7 +534,7 @@ public function addFeat(iFeat $feat) $feat->getName() )); if ($feat->isActive()) { - if (!isset($this->activeFeats[$feat->getName() ])) { + if (!isset($this->activeFeats[$feat->getName()])) { $this->activeFeats[$feat->getName() ] = $feat; } } else { diff --git a/DnDEngine/Dice/Dice.php b/DnDEngine/Dice/Dice.php new file mode 100644 index 0000000..557e00a --- /dev/null +++ b/DnDEngine/Dice/Dice.php @@ -0,0 +1,84 @@ +sides = $sides; + } + if (!is_null($repeat)) { + $this->repeat = $repeat; + } + if (!is_null($modifier)) { + $this->modifier = $modifier; + } + $result = $this->doRoll(); + $this->reset(); + return $result; + } + + public function reset() { + $this->sides = 20; + $this->modifier = 0; + $this->repeat = 1; + $this->keep = NULL; + $this->use = iDice::USE_HIGH; + } + + public function rollAndKeepSettings() { + return $this->doRoll(); + } + + private function doRoll() { + + $results = array(); + for ($i = 0; $i < $this->repeat; $i++) { + $results[] = rand(1, $this->sides); + } + + if (!is_null($this->keep)) { + switch ($this->use) { + case iDice::USE_HIGH: + sort($results); + break; + case iDice::USE_LOW: + rsort($results); + break; + } + for ($i = $this->repeat; $i <= $this->keep; $i--) { + array_shift($results); + } + } + return array_sum($results) + $this->modifier; + } + + public function setSides($sides) { + $this->sides = $sides; + } + + public function setModifier($modifier) { + $this->modifier = $modifier; + } + + public function setRepeat($repeat) { + $this->repeat = $repeat; + } + + public function setKeep($keep, $use = iDice::USE_HIGH) { + $this->keep = $keep; + $this->use = $use; + } +} +?> diff --git a/DnDEngine/Exception/PrerequisitesNotMet.php b/DnDEngine/Exception/PrerequisitesNotMet.php new file mode 100644 index 0000000..998d432 --- /dev/null +++ b/DnDEngine/Exception/PrerequisitesNotMet.php @@ -0,0 +1,29 @@ +t('Prerequisites not met for %s, requires %s.', array($char->getName(), $prerequisites))); + } + +} + +?> diff --git a/DnDEngine/Feats/Powerattack.php b/DnDEngine/Feats/Powerattack.php index b22a792..928c2cf 100644 --- a/DnDEngine/Feats/Powerattack.php +++ b/DnDEngine/Feats/Powerattack.php @@ -100,7 +100,7 @@ public function arePrerequisitesMet(C $char) */ public function getPrerequisites() { - return Language::singleton()->t('15 Strength'); + return L::singleton()->t('15 Strength'); } /** * Short description for function diff --git a/DnDEngine/Game.php b/DnDEngine/Game.php index 270c47d..5c39e10 100644 --- a/DnDEngine/Game.php +++ b/DnDEngine/Game.php @@ -77,6 +77,9 @@ class Game * @static */ protected static $characters = array(); + + protected static $dice = NULL; + /** * Short description for function * @@ -110,5 +113,17 @@ public static function addCharacter($charname) $char = new Character($charname); return self::$characters[$charname] = $char; } + + public static function setDice(interfaces\iDice $dice) { + self::$dice = $dice; + } + + /** + * + * @return interfaces\iDice + */ + public static function getDice() { + return self::$dice; + } } ?> \ No newline at end of file diff --git a/DnDEngine/GeneratorHelper/RollingScore.php b/DnDEngine/GeneratorHelper/RollingScore.php new file mode 100644 index 0000000..ce55d55 --- /dev/null +++ b/DnDEngine/GeneratorHelper/RollingScore.php @@ -0,0 +1,103 @@ + nor the names of its contributors + * may be used to endorse or promote products derived + * from this software without specific prior written permission. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * @category DnDEngine + * @package GeneratorHelper_StandardArray + * @author Sascha Grossenbacher + * @copyright 2008 Sascha Grossenbacher + * @license http://www.opensource.org/licenses/bsd-license.php The BSD License + * @version SVN: $Id:$ + * @link http://pear.php.net/package/GeneratorHelper_StandardArray + * @see References to other sections (if any)... + */ + +namespace DnDEngine; +use DnDEngine\Constants; +/** + * Short description for class + * + * Long description (if any) ... + * + * @category DnDEngine + * @package GeneratorHelper_StandardArray + * @author Sascha Grossenbacher + * @copyright 2008 Sascha Grossenbacher + * @license http://www.opensource.org/licenses/bsd-license.php The BSD License + * @version Release: @package_version@ + * @link http://pear.php.net/package/GeneratorHelper_StandardArray + * @see References to other sections (if any)... + */ +class GeneratorHelper_RollingScore +{ + /** + * Description for protected + * @var unknown + * @access protected + */ + protected $abilities; + /** + * Short description for function + * + * Long description (if any) ... + * + * @param array $abilities Parameter description (if any) ... + * @return void + * @access public + */ + public function rollAbilities() + { + $dice = Game::getDice(); + $dice->setSides(6); + $dice->setRepeat(4); + $dice->setKeep(3); + foreach (AbilityHelper::getAbilities() as $ability) { + $this->abilities[$ability] = $dice->rollandKeepSettings(); + } + $dice->reset(); + } + /** + * Short description for function + * + * Long description (if any) ... + * + * @return unknown Return description (if any) ... + * @access public + * @throws Exception_AbilitiesNotSet Exception description (if any) ... + */ + function getAbilities() + { + if (count($this->abilities) !== 6) { + throw new Exception_AbilitiesNotSet(); + } + return $this->abilities; + } +} +?> \ No newline at end of file diff --git a/DnDEngine/GeneratorHelper/Standardarray.php b/DnDEngine/GeneratorHelper/StandardArray.php similarity index 100% rename from DnDEngine/GeneratorHelper/Standardarray.php rename to DnDEngine/GeneratorHelper/StandardArray.php diff --git a/DnDEngine/Level.php b/DnDEngine/Level.php index 85220b8..85fea07 100644 --- a/DnDEngine/Level.php +++ b/DnDEngine/Level.php @@ -198,7 +198,7 @@ public function chooseFeat(iFeat $feat) throw new Exception_NotAviableAtThisLevel($feat); } if (!$feat->arePrerequisitesMet($this->char)) { - throw new Exception_PrerequitesNotMet($feat->getPrerequisites() , $char); + throw new Exception\PrerequisitesNotMet($feat->getPrerequisites() , $this->char); } $this->gain[self::FEAT]--; if ($this->gain[self::FEAT] == 0) { diff --git a/DnDEngine/interfaces/iDice.php b/DnDEngine/interfaces/iDice.php new file mode 100644 index 0000000..2bc4718 --- /dev/null +++ b/DnDEngine/interfaces/iDice.php @@ -0,0 +1,22 @@ + diff --git a/nbproject/project.properties b/nbproject/project.properties index e9417de..024c098 100644 --- a/nbproject/project.properties +++ b/nbproject/project.properties @@ -1,6 +1,7 @@ include.path=${php.global.include.path} +php.version=PHP_53 source.encoding=UTF-8 src.dir=. tags.asp=false -tags.short=true +tags.short=false web.root=. diff --git a/tests/characterTest.php b/tests/characterTest.php index f3b6faf..35bd06f 100644 --- a/tests/characterTest.php +++ b/tests/characterTest.php @@ -62,7 +62,7 @@ Constants\Skills::ENDURANCE, Constants\Skills::STREETWISE )); -$standardArray = AbilityGenerator::factory('StandardArray'); +$standardArray = AbilityHelper::factoryGenerator('StandardArray'); $standardArray->assignAbilities(array( Constants\Abilities::STR => 16, Constants\Abilities::CON => 14, @@ -72,11 +72,16 @@ Constants\Abilities::INT => 10, )); $berdir->setAbilityScore($standardArray); +// $rollScore = AbilityHelper::factoryGenerator('RollingScore'); +// $rollScore->rollAbilities(); +// $berdir->setAbilityScore($rollScore); $berdir->build(); + $level = new Level($berdir); $level->chooseFeat(new Feats\Powerattack()); $level->finish(); $berdir->activateFeat(Feats\Powerattack::Name); $berdir->deactivateFeat(Feats\Powerattack::Name); Logger::debug($berdir->dump()); + ?> From 41dc43355170043c3b01075422a17d9d2b1edbbc Mon Sep 17 00:00:00 2001 From: Sascha Grossenbacher Date: 2011年2月23日 00:03:08 +0100 Subject: [PATCH 5/6] Started working on ability and skill Checks, started encounter handling. --- DnDEngine/Character.php | 52 +++++++++++++++++++++++++++++++--- DnDEngine/Constants/Common.php | 10 +++++++ DnDEngine/Constants/Skills.php | 2 ++ DnDEngine/Dice/Dice.php | 8 ++++-- DnDEngine/Game.php | 13 +++++++++ tests/characterTest.php | 34 ++++++++++++++++++++++ 6 files changed, 113 insertions(+), 6 deletions(-) diff --git a/DnDEngine/Character.php b/DnDEngine/Character.php index 36da8cc..838e455 100644 --- a/DnDEngine/Character.php +++ b/DnDEngine/Character.php @@ -45,7 +45,7 @@ /** * PHP Template. */ -class Character +class Character implements interfaces\iBeing { /** * Description for protected @@ -106,13 +106,13 @@ class Character * @var unknown * @access protected */ - protected $alignment; + protected $alignment = Constants\Common::ALIGNMENT_NONE; /** * Description for protected * @var unknown * @access protected */ - protected $iniative; + protected $initiative; /** * Description for protected * @var unknown @@ -172,7 +172,7 @@ class Character * @var integer * @access protected */ - protected $actionPoints = 0; + protected $actionPoints = 1; /** * Description for protected * @var integer @@ -793,6 +793,50 @@ public function getEquipment($name) } return new Equipment_None(); } + + + public function rollInitiative() { + $this->initiative = $this->checkAbility(Constants\Abilities::DEX); + Logger::debug('Character %s rolls initiative of %s.', array( + $this->getName(), + DisplayHelper::displayInt($this->initiative), + )); + } + + public function getInitiative() { + return $this->getInitiative(); + } + + public function checkAbility($ability) { + $modifier = floor($this->getLevel() / 2) + $this->getAbilityModifier($ability); + + $dice = Game::getDice(); + return (int)$dice->roll(20, 1, $modifier); + } + + public function checkSkill($skill, $take10 = FALSE) { + // @todo Improve according to page 178 in Players Handbook. + $modifier = floor($this->getLevel() / 2) + $this->getSkill($skill); + if ($take10) { + return $modifier + 10; + } + else { + $dice = Game::getDice(); + return $dice->roll(20, 1, $modifier); + } + } + + public function getAbilityModifier($ability) { + return (int)floor(($this->getAbility($ability) - 10) / 2); + } + + public function getSkill($skill) { + if (isset($this->skills[$skill])) { + return $this->skills[$skill]; + } + return 0; + } + /** * Short description for function * diff --git a/DnDEngine/Constants/Common.php b/DnDEngine/Constants/Common.php index d472f18..432b3b0 100644 --- a/DnDEngine/Constants/Common.php +++ b/DnDEngine/Constants/Common.php @@ -137,5 +137,15 @@ class Common * Description for const */ const WEAPON_TWOHAND = 'Two-Hand weapon'; + + const ALIGNMENT_GOOD = 'Good'; + + const ALIGNMENT_LAWFUL = 'Lawful Good'; + + const ALIGNMENT_EVIL = 'Evil'; + + const ALIGNMENT_CHAOTIC = 'Chaotic Evil'; + + const ALIGNMENT_NONE = 'Unaligned'; } ?> diff --git a/DnDEngine/Constants/Skills.php b/DnDEngine/Constants/Skills.php index f55609f..9dde636 100644 --- a/DnDEngine/Constants/Skills.php +++ b/DnDEngine/Constants/Skills.php @@ -73,5 +73,7 @@ class Skills * Description for const */ const STREETWISE = 'Streetwise'; + + const PERCEPTION = 'Perception'; } ?> diff --git a/DnDEngine/Dice/Dice.php b/DnDEngine/Dice/Dice.php index 557e00a..3329f68 100644 --- a/DnDEngine/Dice/Dice.php +++ b/DnDEngine/Dice/Dice.php @@ -6,6 +6,7 @@ namespace DnDEngine\Dice; use DnDEngine\interfaces\iDice; +use DnDEngine\Logger; class Dice implements iDice { private $sides = 20; @@ -45,7 +46,8 @@ private function doRoll() { $results = array(); for ($i = 0; $i < $this->repeat; $i++) { - $results[] = rand(1, $this->sides); + $results[] = $roll = rand(1, $this->sides); + Logger::debug('Rolled %d', array($roll)); } if (!is_null($this->keep)) { @@ -61,7 +63,9 @@ private function doRoll() { array_shift($results); } } - return array_sum($results) + $this->modifier; + $result = array_sum($results) + $this->modifier; + Logger::info('Roll result for %dd%d + %d: %d', array($this->repeat, $this->sides, $this->modifier, $result)); + return $result; } public function setSides($sides) { diff --git a/DnDEngine/Game.php b/DnDEngine/Game.php index 5c39e10..93798dd 100644 --- a/DnDEngine/Game.php +++ b/DnDEngine/Game.php @@ -123,7 +123,20 @@ public static function setDice(interfaces\iDice $dice) { * @return interfaces\iDice */ public static function getDice() { + if (is_null(self::$dice)) { + self::$dice = new Dice\Dice(); + } return self::$dice; } + + public static function startEncounter() { + $encounter = new Encounter(); + foreach (self::$characters as $character) { + $encounter->addBeing($character); + } + return $encounter; + } + + } ?> \ No newline at end of file diff --git a/tests/characterTest.php b/tests/characterTest.php index 35bd06f..3645725 100644 --- a/tests/characterTest.php +++ b/tests/characterTest.php @@ -82,6 +82,40 @@ $level->finish(); $berdir->activateFeat(Feats\Powerattack::Name); $berdir->deactivateFeat(Feats\Powerattack::Name); +$berdir->rollInitiative(); Logger::debug($berdir->dump()); + +$curunair = Game::addCharacter('Curunair'); +$curunair->setRace(new Race\Dwarf()); +$fighter = $curunair->setClass(new Classes\Fighter()); +$fighter->chooseTrainedSkill(array( + Constants\Skills::ATHLETHICS, + Constants\Skills::ENDURANCE, + Constants\Skills::STREETWISE +)); +$standardArray = AbilityHelper::factoryGenerator('StandardArray'); +$standardArray->assignAbilities(array( + Constants\Abilities::STR => 16, + Constants\Abilities::CON => 14, + Constants\Abilities::DEX => 13, + Constants\Abilities::WIS => 12, + Constants\Abilities::CHA => 11, + Constants\Abilities::INT => 10, +)); +$curunair->setAbilityScore($standardArray); +// $rollScore = AbilityHelper::factoryGenerator('RollingScore'); +// $rollScore->rollAbilities(); +// $berdir->setAbilityScore($rollScore); +$curunair->build(); + +$level = new Level($curunair); +$level->chooseFeat(new Feats\Powerattack()); +$level->finish(); +$curunair->rollInitiative(); +Logger::debug($curunair->dump()); + +$encounter = Game::startEncounter(); +$encounter->start(); + ?> From 399b2fdb0b63462961c47ad0503e05a37013a5ba Mon Sep 17 00:00:00 2001 From: Sascha Grossenbacher Date: 2011年2月28日 21:44:25 +0100 Subject: [PATCH 6/6] Started working on encounter --- DnDEngine/Encounter.php | 45 +++++++++++++++++++++++++++++++++ DnDEngine/interfaces/iBeing.php | 18 +++++++++++++ 2 files changed, 63 insertions(+) create mode 100644 DnDEngine/Encounter.php create mode 100644 DnDEngine/interfaces/iBeing.php diff --git a/DnDEngine/Encounter.php b/DnDEngine/Encounter.php new file mode 100644 index 0000000..7fc9708 --- /dev/null +++ b/DnDEngine/Encounter.php @@ -0,0 +1,45 @@ +involved[] = $being; + } + + public function start() { + Logger::info('Starting an encounter with the following beings:'); + foreach ($this->involved as $being) { + Logger::info(' - %s (Perception: %s, Hitpoints %s)', array( + $being->getName(), + DisplayHelper::displayInt($being->checkSkill(C\Skills::PERCEPTION, TRUE)), + DisplayHelper::displayInt($being->getHitpoints()), + )); + } + + $this->state = Encounter::STATE_ACTIVE; + } +} + +?> diff --git a/DnDEngine/interfaces/iBeing.php b/DnDEngine/interfaces/iBeing.php new file mode 100644 index 0000000..2a67ecd --- /dev/null +++ b/DnDEngine/interfaces/iBeing.php @@ -0,0 +1,18 @@ +

AltStyle によって変換されたページ (->オリジナル) /