Beispiel #1
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();
 }
Beispiel #2
0
        if (is_null($item)) {
            continue;
        }
        // Don't show combat-only items.
        if ($item->useLocation == ItemUse::CombatOnly) {
            continue;
        }
        $output .= "{$fragment->displayString}, ";
    }
    $output = rtrim($output, ", ") . "\n";
    echo $output;
    StateManager::ChangeState($charData, GameStates::UsingItem);
});
// Check your inventory.
$adventuring->commands[] = new InputFragment("inventory", function ($charData, $mapData) {
    $inventory = lazyGetInventory($charData);
    $itemStr = $inventory->getContentsAsString();
    if (!is_null($itemStr)) {
        $itemStr = rtrim($itemStr, "\n") . ", ";
    }
    $itemStr .= "{$charData->gold} GP";
    echo $itemStr . "\n";
});
// Get the character's spells
$adventuring->commands[] = new InputFragment("book", function ($charData, $mapData) {
    if (empty($charData->spellbook)) {
        echo "You don't have any spells in your spellbook.\n";
        return;
    }
    $spells = "";
    global $spellcasting;
Beispiel #3
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();
 }