private static function GetSingleLine($filePath, $overriddenMin = -1, $overriddenMax = -1) { $lines = NameGenerator::GetLinesFromFile($filePath); $min = 0; $max = count($lines) - 1; if ($overriddenMin > 0 && $overriddenMax > 0) { // Use overridden values, but stay in bounds. $min = min($max, $overriddenMin); $max = min($overriddenMax, $max); } $idx = rand($min, $max); $line = $lines[$idx]; $line = rtrim($line); return $line; }
/** * @test * @expectedException Fiche\Domain\Service\Exceptions\ValueIsTooShort */ public function tooShortEmailShouldThrownError() { new Email(NameGenerator::correct(Email::EMAIL_MIN_LENGTH - 1)); }
private function InitRandomEquipment($playerLevel, $distance) { // e.g. 0 at 0 distance, 10 at max distance $mapHalfSize = floor(ProcGen::GetMapSize() / 2); // 50 $boundary = floor($mapHalfSize / 10); // 10 $distanceFactor = floor($distance / $boundary); // NB: Can spawn both armour AND weapon. // Weapon $oneInHundred = rand(1, 100); if (true || $oneInHundred > 50) { $weaponName = NameGenerator::Weapon($playerLevel); $randomFactor = rand(-2, 2); $weaponLvl = rand($playerLevel, $playerLevel + $distanceFactor + $randomFactor); $weaponLvl = max(1, $weaponLvl); $this->addEquipment($weaponName, $weaponLvl, ShopEquipment::Weapon); } // Armour $oneInHundred = rand(1, 100); if ($oneInHundred > 50) { $armourName = NameGenerator::Armour($playerLevel); $randomFactor = rand(-2, 2); $armourLvl = rand($playerLevel, $playerLevel + $distanceFactor + $randomFactor); $armourLvl = max(1, $armourLvl); $this->addEquipment($armourName, $armourLvl, ShopEquipment::Armour); } }
function moveToRoom($x, $y, $xDelta, $yDelta, $mapData, $charData, $moveText) { global $procGen; $newX = $x + $xDelta; $newY = $y + $yDelta; if (!checkBounds($newX, $newY)) { echo "Looks like there's nothing that way...\n"; return; } // Cache the current position, for running away. $mapData->lastPlayerX = $mapData->playerX; $mapData->lastPlayerY = $mapData->playerY; $mapData->playerX = $newX; $mapData->playerY = $newY; $room = $mapData->map->GetRoom($newX, $newY); $seenBefore = isset($room); if (!$seenBefore) { $room = $procGen->GenerateRoomForMap($mapData->map, $mapData->playerX, $mapData->playerY, $charData->level); } $containsMonster = isset($room->occupant) && get_class($room->occupant) == "Monster"; $containsShop = isset($room->occupant) && get_class($room->occupant) == "Shop"; if ($containsMonster) { $monster = $room->occupant; $monsterName = $monster->name; $article = NameGenerator::GetArticle($monsterName); $connedName = $monster->getConnedNameStr($charData->level); if (!$seenBefore) { $moveText .= "and encounter a Level {$monster->level} {$connedName}! It attacks!\n"; // Combat! StateManager::ChangeState($charData, GameStates::Combat); } else { $moveText .= "and encounter the Level {$monster->level} {$connedName} again! It attacks again!\n"; // Combat! StateManager::ChangeState($charData, GameStates::Combat); } } else { if ($containsShop) { $moveText .= "and discover a small shop. \"Feel free to br(o)wse!\", the shopkeeper yells.\n"; } else { $moveText .= "but this room appears to be empty.\n"; } } echo $moveText; }
<?php include 'NameGenerator.class.php'; $gender = 'boy'; $request = 'His'; if (rand(0, 100) > 50) { $gender = 'girl'; } if ($gender == 'girl') { $request = 'Her'; } $baby = new NameGenerator($gender); echo 'Your baby is a ' . $gender . '<br>' . $request . ' name is ' . $baby->generate_name($gender) . '.<br>';
/** * @test * @expectedException Fiche\Domain\Service\Exceptions\ValueIsTooLong */ public function tooLongValueShouldThrownError() { new $this->className(NameGenerator::greaterThan($this->maxLength)); }
function giveLoot($monster, &$charData) { $textOutput = ""; $monsterLevel = $monster->level; $chanceInSix = rand(1, 6); // 5,6: Weapon if ($chanceInSix >= 5) { $textOutput = giveWeapon($monster, $charData); } else { if ($chanceInSix >= 3) { //--------------------------------------- // Barbarian trait: :D // global $traitMap; $isBarbarian = $traitMap->ClassHasTrait($charData, TraitName::DualWield); //--------------------------------------- if (!$isBarbarian) { $armourName = NameGenerator::Armour($monsterLevel); $armourLvl = lootLevel($monsterLevel); $currentAmrVal = $charData->armourVal; // Only equip armour that is better. if ($armourLvl > $currentAmrVal) { $textOutput = "The monster was armoured! You steal the {$armourName} and equip it immediately! "; $charData->armour = $armourName; $charData->armourVal = $armourLvl; } else { $textOutput = giveGold($monster, $charData); } } else { $textOutput = giveWeapon($monster, $charData); } } else { // Check if we CAN award a spell. global $spellDrops; $currentSpells = $charData->spellbook; $possibleSpells = array(); foreach ($spellDrops as $dropSpell) { if (!in_array($dropSpell, $currentSpells)) { $possibleSpells[] = $dropSpell; } } $canAwardSpell = !empty($possibleSpells); if ($canAwardSpell) { $spellIdx = rand(0, count($possibleSpells) - 1); $newSpell = $possibleSpells[$spellIdx]; $textOutput = "You find a scroll of {$newSpell} on the body! Lucky you! "; $charData->spellbook[] = $newSpell; } else { $textOutput = giveGold($monster, $charData); } } } return $textOutput; }
public function getMapName() { return NameGenerator::generateMapName($this->getSeedNumeric($this->ov->getPostSeed()) + $this->ov->getPostSlider2Value() * 10 + $this->ov->getPostSlider4Value() * 10 + 14); }