Ejemplo n.º 1
0
 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);
     }
 }
Ejemplo n.º 2
0
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;
}