Esempio n. 1
0
 public function generateInputFragments($charData, $dynData)
 {
     $precision = "precision";
     if (isStatLevelAvailable($precision, $dynData) && canAffordStat($precision, $dynData)) {
         $this->commands[] = new InputFragment($precision, function ($charData, $mapData, $dynData) use($precision) {
             increaseStatRank($precision, $dynData, $charData);
         });
     }
     $endurance = "endurance";
     if (isStatLevelAvailable($endurance, $dynData) && canAffordStat($endurance, $dynData)) {
         $this->commands[] = new InputFragment($endurance, function ($charData, $mapData, $dynData) use($endurance) {
             increaseStatRank($endurance, $dynData, $charData);
         });
     }
     $reflexes = "reflexes";
     if (isStatLevelAvailable($reflexes, $dynData) && canAffordStat($reflexes, $dynData)) {
         $this->commands[] = new InputFragment($reflexes, function ($charData, $mapData, $dynData) use($reflexes) {
             increaseStatRank($reflexes, $dynData, $charData);
         });
     }
     $strength = "strength";
     if (isStatLevelAvailable($strength, $dynData) && canAffordStat($strength, $dynData)) {
         $this->commands[] = new InputFragment($strength, function ($charData, $mapData, $dynData) use($strength) {
             increaseStatRank($strength, $dynData, $charData);
         });
     }
     $oddness = "oddness";
     if (isStatLevelAvailable($oddness, $dynData) && canAffordStat($oddness, $dynData)) {
         $this->commands[] = new InputFragment($oddness, function ($charData, $mapData, $dynData) use($oddness) {
             increaseStatRank($oddness, $dynData, $charData);
         });
     }
     $nerve = "nerve";
     if (isStatLevelAvailable($nerve, $dynData) && canAffordStat($nerve, $dynData)) {
         $this->commands[] = new InputFragment($nerve, function ($charData, $mapData, $dynData) use($nerve) {
             increaseStatRank($nerve, $dynData, $charData);
         });
     }
     $acuity = "acuity";
     if (isStatLevelAvailable($acuity, $dynData) && canAffordStat($acuity, $dynData)) {
         $this->commands[] = new InputFragment($acuity, function ($charData, $mapData, $dynData) use($acuity) {
             increaseStatRank($acuity, $dynData, $charData);
         });
     }
     // Add unique identifiers to commands.
     $allocator = new UIDAllocator($this->commands);
     $allocator->Allocate();
 }
Esempio n. 2
0
// Check the status of the rest
$resting->commands[] = new InputFragment("check", function ($charData, $mapData) {
    global $traitMap;
    $isPray = $traitMap->ClassHasTrait($charData, TraitName::Pray);
    $restEnd = $charData->restEnd;
    $date = new DateTime();
    $date->setTimestamp($restEnd);
    $status = "You will wake up at " . $date->format("H:i") . ". To wake up now enter 'wake'. (" . getCurrentStats($charData) . ")\n";
    if ($isPray) {
        $status = "You will stop praying at " . $date->format("H:i") . ". To stop now, enter 'wake'. (" . getCurrentStats($charData, false, true) . ")\n";
    }
    echo $status;
});
$resting->commands[] = new InputFragment("wake", function ($charData, $mapData) {
    global $traitMap;
    $isPray = $traitMap->ClassHasTrait($charData, TraitName::Pray);
    $restString = "";
    if (!$isPray) {
        $restString = "You wake up, ready to start the new day. (" . getCurrentStats($charData, true, $isPray) . ")";
    } else {
        $restString = "You stand up, feeling thoroughly refreshed. (" . getCurrentStats($charData, true, $isPray) . ")";
    }
    echo $restString . "\n";
    $charData->restStart = 0;
    $charData->restEnd = 0;
    StateManager::ChangeState($charData, GameStates::Adventuring);
});
// Add unique identifiers to commands.
$allocator = new UIDAllocator($resting->commands);
$allocator->Allocate();
Esempio n. 3
0
 public function generateInputFragments(&$charData, $nonCombat = false)
 {
     $inventory = lazyGetInventory($charData);
     $inventoryItems = $inventory->items;
     // We only want one InputFragment per item TYPE.
     $dedupedNames = [];
     foreach ($inventoryItems as $itemName) {
         $item = findItem($itemName);
         if (is_null($item)) {
             echo "ERROR: Bad item in inventory ({$itemName})!\n";
             exit(14);
         }
         $useLocation = $item->useLocation;
         if ($nonCombat && $useLocation == ItemUse::CombatOnly) {
             continue;
         }
         if (!$nonCombat && $useLocation == ItemUse::NonCombatOnly) {
             continue;
         }
         if ($this->deDupeItemFragments($itemName, $dedupedNames)) {
             continue;
         }
         $this->commands[] = new InputFragment($itemName, function ($charData, $mapData) use($itemName, $nonCombat) {
             global $usingItem;
             return $usingItem->useItem($itemName, $charData, $mapData, $nonCombat);
         });
     }
     $this->commands[] = new InputFragment("cancel", function ($charData, $mapData) use($nonCombat) {
         echo $nonCombat . "\n\n";
         if (!$nonCombat) {
             echo "You close your bag, and go back to the fight.\n";
             StateManager::ChangeState($charData, GameStates::Combat);
         } else {
             echo "Deciding against using an item, you go back to Adventuring.\n";
             StateManager::ChangeState($charData, GameStates::Adventuring);
         }
     });
     // Add unique identifiers to commands.
     $allocator = new UIDAllocator($this->commands);
     $allocator->Allocate();
 }
Esempio n. 4
0
function addShopFragmentIfNeeded($charData, $mapData)
{
    global $adventuring;
    $currentRoom = $mapData->map->GetRoom($mapData->playerX, $mapData->playerY);
    if (is_null($currentRoom)) {
        return;
    }
    $containsShop = isset($currentRoom->occupant) && get_class($currentRoom->occupant) == "Shop";
    if ($containsShop) {
        $adventuring->commands[] = new InputFragment("browse shop", function ($charData, $mapData) use($currentRoom) {
            $shop = $currentRoom->occupant;
            if ($shop->isEmpty()) {
                echo "\"Sorry, I'm all sold out right now!\"\n";
                return;
            }
            global $shopping;
            $shopStr = $shopping->getShopString($shop, $charData, $mapData);
            echo $shopStr;
            StateManager::ChangeState($charData, GameStates::Shopping);
        });
        $allocator = new UIDAllocator($adventuring->commands);
        $allocator->Allocate();
    }
}
Esempio n. 5
0
 public function generateInputFragments($charData, $outOfCombat = false)
 {
     $spellList = $charData->spellbook;
     $spellNum = 1;
     foreach ($spellList as $spellName) {
         // Can only cast heal spells.
         if ($outOfCombat) {
             $spell = $this->findSpellOrAbility($spellName, $charData);
             if (!$spell->isHeal) {
                 continue;
             }
         }
         $this->commands[] = new InputFragment($spellName, function ($charData, $mapData, $dynData) use($spellName, $outOfCombat) {
             $this->castSpell($spellName, $charData, $mapData, $dynData, $outOfCombat);
         });
         ++$spellNum;
     }
     $this->commands[] = new InputFragment("cancel", function ($charData, $mapData) use($outOfCombat) {
         if (!$outOfCombat) {
             echo "You decide against casting a spell, and go back to the fight.\n";
             StateManager::ChangeState($charData, GameStates::Combat);
         } else {
             echo "You decide not to cast a spell, and go back to Adventuring.\n";
             StateManager::ChangeState($charData, GameStates::Adventuring);
         }
     });
     // Add unique identifiers to commands.
     $allocator = new UIDAllocator($this->commands);
     $allocator->Allocate();
 }
Esempio n. 6
0
 public function generateInputFragments(&$charData, &$mapData, $justItems = false)
 {
     // To be in here, we need to have a shop at our current location.
     $room = $mapData->map->GetRoom($mapData->playerX, $mapData->playerY);
     $shop = $room->occupant;
     if (!$justItems) {
         $this->commands[] = new InputFragment("check stock", function ($charData, $mapData) use($shop) {
             global $shopping;
             $shopStr = $shopping->getShopString($shop, $charData, $mapData);
             echo $shopStr;
         });
     }
     if (!$justItems) {
         $this->commands[] = new InputFragment("leave", function ($charData, $mapData) {
             echo "\"Maybe next time, eh?\", the shopkeeper drawls at you as you walk away.\n";
             StateManager::ChangeState($charData, GameStates::Adventuring);
         });
     }
     if (!$justItems) {
         $this->commands[] = new InputFragment("equipment", function ($charData, $mapData) {
             global $adventuring;
             $equipment = $adventuring->getEquippedItemsStr($charData);
             echo $equipment . "\n";
         });
     }
     foreach ($shop->stock as $itemName => $quantity) {
         $item = findItem($itemName);
         $this->commands[] = new InputFragment($itemName, function ($charData, $mapData) use($item, $itemName, $shop, $room) {
             global $shopping;
             if (!$shopping->canAffordItem($charData, $item->getCost($charData))) {
                 return;
             }
             // Remove item from shop.
             $shop->removeStockItem($itemName);
             // Add item to player inventory, and deduct gold.
             $inventory = lazyGetInventory($charData);
             $inventory->addItem($item);
             $shopping->takeMoney($item, $shop, $charData, $room);
         });
     }
     foreach ($shop->equipment as $equipment) {
         $this->commands[] = new InputFragment($equipment->name, function ($charData, $mapData) use($equipment, $shop, $room) {
             global $shopping;
             if (!$shopping->canAffordItem($charData, $equipment->getCost($charData))) {
                 return;
             }
             $equipString = "You equip your new {$equipment->name} immediately";
             $isBarbarian = strcasecmp($charData->class, "Barbarian") == 0;
             if ($equipment->type == ShopEquipment::Weapon) {
                 $weapon1Better = $charData->weaponVal >= $equipment->level;
                 $weapon2Better = $charData->weapon2Val >= $equipment->level;
                 if (!$isBarbarian && $weapon1Better || $isBarbarian && $weapon1Better && $weapon2Better) {
                     echo "\"No point buying my wares if you've got better yourself!\"\n";
                     return;
                 }
                 // Bloody complicated Barbarians
                 if ($isBarbarian) {
                     // Going in the off-hand
                     if ($weapon1Better) {
                         $charData->weapon2 = $equipment->name;
                         $charData->weapon2Val = $equipment->level;
                     } else {
                         $equipString .= ", moving your {$charData->weapon} to your off-hand";
                         $charData->weapon2 = $charData->weapon;
                         $charData->weapon2Val = $charData->weaponVal;
                         $charData->weapon = $equipment->name;
                         $charData->weaponVal = $equipment->level;
                     }
                 } else {
                     $charData->weapon = $equipment->name;
                     $charData->weaponVal = $equipment->level;
                 }
             } else {
                 if ($equipment->type == ShopEquipment::Armour) {
                     $armourBetter = $charData->armourVal >= $equipment->level;
                     if ($isBarbarian) {
                         echo "\"Not sure you'd know what to do with that!\"\n";
                         return;
                     } else {
                         if ($armourBetter) {
                             echo "\"No point buying my wares if you've got better yourself!\"\n";
                             return;
                         }
                     }
                     $charData->armour = $equipment->name;
                     $charData->armourVal = $equipment->level;
                 }
             }
             $equipString .= ". ";
             // Remove equipment from shop.
             $shop->removeEquipment($equipment->name);
             $shopping->takeMoney($equipment, $shop, $charData, $room, $equipString);
         });
     }
     // Add unique identifiers to commands.
     $allocator = new UIDAllocator($this->commands);
     $allocator->Allocate();
 }