Skip to content

Commit

Permalink
Merge pull request #715 from sporchia/v31.0.2
Browse files Browse the repository at this point in the history
V31.0.2
  • Loading branch information
sporchia authored Sep 30, 2019
2 parents 1e77ab0 + 64c8ad0 commit 824135a
Show file tree
Hide file tree
Showing 34 changed files with 2,154 additions and 2,061 deletions.
142 changes: 58 additions & 84 deletions app/Console/Commands/Distribution.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace ALttP\Console\Commands;

use ALttP\Boss;
use ALttP\Item;
use ALttP\Randomizer;
use ALttP\Services\PlaythroughService;
Expand All @@ -16,12 +17,18 @@ class Distribution extends Command
* @var string
*/
protected $signature = 'alttp:distribution {type} {thing} {iterations=1}'
. ' {--difficulty=normal : set difficulty}'
. ' {--logic=NoGlitches : set logic}'
. ' {--goal=ganon : set game goal}'
. ' {--variation=none : set game variation}'
. ' {--state=standard : set game state}'
. ' {--tournament : enable tournament mode}'
. ' {--weapons=randomized : set weapons mode}'
. ' {--glitches=none : set glitches}'
. ' {--crystals_ganon=7 : set ganon crystal requirement}'
. ' {--crystals_tower=7 : set ganon tower crystal requirement}'
. ' {--item_placement=advanced : set item placement rules}'
. ' {--dungeon_items=standard : set dungeon item placement}'
. ' {--accessibility=item : set item/location accessibility}'
. ' {--hints=off : set hints on or off}'
. ' {--item_pool=normal : set item pool}'
. ' {--item_functionality=normal : set item functionality}'
. ' {--csv= : file to write to}';

/**
Expand All @@ -33,14 +40,8 @@ class Distribution extends Command

/** @var string */
private $state;
/** @var string */
private $difficulty;
/** @var string */
private $logic;
/** @var string */
private $goal;
/** @var string */
private $variation;
/** @var array */
private $options;

/**
* Execute the console command.
Expand All @@ -49,23 +50,34 @@ class Distribution extends Command
*/
public function handle()
{
if (
!is_string($this->option('difficulty'))
|| !is_string($this->option('logic'))
|| !is_string($this->option('goal'))
|| !is_string($this->option('state'))
|| !is_string($this->option('variation'))
) {
$this->error('option not string');

return 101;
}

$this->difficulty = $this->option('difficulty');
$this->logic = $this->option('logic');
$this->goal = $this->option('goal');
$this->variation = $this->option('variation');
$logic = [
'none' => 'NoGlitches',
'overworld_glitches' => 'OverworldGlitches',
'major_glitches' => 'MajorGlitches',
'no_logic' => 'None',
][$this->option('glitches')];

$this->state = $this->option('state');
$this->options = [
'itemPlacement' => $this->option('item_placement'),
'dungeonItems' => $this->option('dungeon_items'),
'accessibility' => $this->option('accessibility'),
'goal' => $this->option('goal'),
'crystals.ganon' => $this->option('crystals_ganon'),
'crystals.tower' => $this->option('crystals_tower'),
'entrances' => 'none',
'mode.weapons' => $this->option('weapons'),
'tournament' => false,
'spoil.Hints' => $this->option('hints'),
'logic' => $logic,
'item.pool' => $this->option('item_pool'),
'item.functionality' => $this->option('item_functionality'),
'enemizer.bossShuffle' => 'none',
'enemizer.enemyShuffle' => 'none',
'enemizer.enemyDamage' => 'default',
'enemizer.enemyHealth' => 'default',
];

$locations = [];
switch ($this->argument('type')) {
Expand Down Expand Up @@ -129,6 +141,8 @@ public function handle()
}

for ($i = 0; $i < $this->argument('iterations'); $i++) {
Item::clearCache();
Boss::clearCache();
if (!is_callable($function)) {
continue;
}
Expand Down Expand Up @@ -184,32 +198,22 @@ public static function _assureColumnsExist($array): array

private function item($item_name, &$locations)
{
$world = World::factory($this->state, [
'difficulty' => $this->difficulty,
'logic' => $this->logic,
'goal' => $this->goal,
'variation' => $this->variation,
]);
$world = World::factory($this->state, $this->options);
$rand = new Randomizer([$world]);
$rand->randomize();
$item = Item::get($item_name, $world);

foreach ($world->getLocationsWithItem($item) as $location) {
if (!isset($locations[$location->getName()])) {
$locations[$location->getName()] = 0;
if (!isset($locations[(string) $location])) {
$locations[(string) $location] = 0;
}
$locations[$location->getName()]++;
$locations[(string) $location]++;
}
}

private function location($location_name, &$locations)
{
$world = World::factory($this->state, [
'difficulty' => $this->difficulty,
'logic' => $this->logic,
'goal' => $this->goal,
'variation' => $this->variation,
]);
$world = World::factory($this->state, $this->options);
$rand = new Randomizer([$world]);
$rand->randomize();

Expand All @@ -229,12 +233,7 @@ private function location($location_name, &$locations)

private function location_ordered($location_name, &$locations)
{
$world = World::factory($this->state, [
'difficulty' => $this->difficulty,
'logic' => $this->logic,
'goal' => $this->goal,
'variation' => $this->variation,
]);
$world = World::factory($this->state, $this->options);
$rand = new Randomizer([$world]);
$rand->randomize();

Expand All @@ -251,19 +250,14 @@ private function location_ordered($location_name, &$locations)

private function region($region_name, &$locations)
{
$world = World::factory($this->state, [
'difficulty' => $this->difficulty,
'logic' => $this->logic,
'goal' => $this->goal,
'variation' => $this->variation,
]);
$world = World::factory($this->state, $this->options);
$rand = new Randomizer([$world]);
$rand->randomize();

$region = $world->getRegion($region_name);

foreach ($region->getLocations() as $location) {
$location_name = $location->getName();
$location_name = (string) $location;
$item_name = $location->getItem()->getNiceName();
if (!isset($locations[$location_name][$item_name])) {
$locations[$location_name][$item_name] = 0;
Expand All @@ -274,18 +268,13 @@ private function region($region_name, &$locations)

private function required($unused, &$locations)
{
$world = World::factory($this->state, [
'difficulty' => $this->difficulty,
'logic' => $this->logic,
'goal' => $this->goal,
'variation' => $this->variation,
]);
$world = World::factory($this->state, $this->options);
$rand = new Randomizer([$world]);
$rand->randomize();

$required_locations = (new PlaythroughService)->getPlayThrough($world, false);
foreach ($required_locations as $location) {
$location_name = $location->getName();
$location_name = (string) $location;
$item = $location->getItem();
if (!$item) {
continue;
Expand All @@ -302,22 +291,17 @@ private function required($unused, &$locations)

private function required_ordered($unused, &$locations)
{
$world = World::factory($this->state, [
'difficulty' => $this->difficulty,
'logic' => $this->logic,
'goal' => $this->goal,
'variation' => $this->variation,
]);
$world = World::factory($this->state, $this->options);
$rand = new Randomizer([$world]);
$rand->randomize();

$required_locations = (new PlaythroughService)->getPlayThrough($world, false);
$required_locations_names = array_map(function ($location) {
return $location->getName();
return (string) $location;
}, $required_locations);

foreach ($world->getCollectableLocations() as $location) {
$location_name = $location->getName();
$location_name = (string) $location;
if (!in_array($location_name, $required_locations_names) || strpos($location->getItem()->getName(), 'Key') !== false) {
$locations[$location_name][] = '';
continue;
Expand All @@ -329,17 +313,12 @@ private function required_ordered($unused, &$locations)

private function full($unused, &$locations)
{
$world = World::factory($this->state, [
'difficulty' => $this->difficulty,
'logic' => $this->logic,
'goal' => $this->goal,
'variation' => $this->variation,
]);
$world = World::factory($this->state, $this->options);
$rand = new Randomizer([$world]);
$rand->randomize();

foreach ($world->getLocations() as $location) {
$location_name = $location->getName();
$location_name = (string) $location;
$item = $location->getItem();
if (!$item) {
continue;
Expand All @@ -356,17 +335,12 @@ private function full($unused, &$locations)

private function full_ordered($unused, &$locations)
{
$world = World::factory($this->state, [
'difficulty' => $this->difficulty,
'logic' => $this->logic,
'goal' => $this->goal,
'variation' => $this->variation,
]);
$world = World::factory($this->state, $this->options);
$rand = new Randomizer([$world]);
$rand->randomize();

foreach ($world->getLocations() as $location) {
$location_name = $location->getName();
$location_name = (string) $location;
$item = $location->getItem();
if (!$item) {
continue;
Expand Down
7 changes: 5 additions & 2 deletions app/Console/Commands/Randomize.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace ALttP\Console\Commands;

use ALttP\Boss;
use ALttP\Item;
use ALttP\Randomizer;
use ALttP\Rom;
Expand Down Expand Up @@ -42,8 +43,8 @@ class Randomize extends Command
. ' {--dungeon_items=standard : set dungeon item placement}'
. ' {--accessibility=item : set item/location accessibility}'
. ' {--hints=on : set hints on or off}'
. ' {--item_pool=on : set item pool}'
. ' {--item_functionality=on : set item functionality}';
. ' {--item_pool=normal : set item pool}'
. ' {--item_functionality=normal : set item functionality}';

/**
* The console command description.
Expand Down Expand Up @@ -107,6 +108,8 @@ public function handle()
$bulk = (int) ($this->option('bulk') ?? 1);

for ($i = 0; $i < $bulk; $i++) {
Item::clearCache();
Boss::clearCache();
$rom = new Rom($this->argument('input_file'));
$hash = $hasher->encode((int) (microtime(true) * 1000));

Expand Down
2 changes: 1 addition & 1 deletion app/Http/Controllers/CustomizerController.php
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ protected function prepSeed(Request $request, bool $save = false)
'crystals.tower' => $crystals_tower,
'entrances' => $request->input('entrances', 'none'),
'mode.weapons' => $request->input('weapons', 'randomized'),
'tournament' => $request->input('tournament', false),
'tournament' => $request->input('tournament', true),
'spoilers' => $request->input('spoilers', false),
'spoilers_ongen' => $request->input('spoilers_ongen', false),
'spoil.Hints' => $request->input('hints', 'on'),
Expand Down
4 changes: 2 additions & 2 deletions app/Http/Controllers/RandomizerController.php
Original file line number Diff line number Diff line change
Expand Up @@ -143,9 +143,9 @@ protected function prepSeed(CreateRandomizedGame $request)
$en->writeToRom($rom);
}

$patch = $rom->getWriteLog();
$rom->setTournamentType('standard');
$rom->setTournamentType($request->input('spoilers', false) ? 'none' : 'standard');
$rom->rummageTable();
$patch = $rom->getWriteLog();

if ($world->isEnemized()) {
$world->updateSeedRecordPatch($patch);
Expand Down
3 changes: 2 additions & 1 deletion app/Region/Standard/ThievesTown.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,8 @@ public function initalize()

$this->locations["Thieves' Town - Big Chest"]->setRequirements(function ($locations, $items) {
if ($locations["Thieves' Town - Big Chest"]->hasItem(Item::get('KeyD4', $this->world))) {
return $items->has('Hammer') && $items->has('BigKeyD4');
return $items->has('Hammer') && $items->has('BigKeyD4')
&& $this->world->config('accessibility') !== 'locations';
}

return $items->has('Hammer') && $items->has('KeyD4') && $items->has('BigKeyD4');
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@
"source": {
"url": "https://github.com/KevinCathcart/ALttPEntranceRandomizer",
"type": "git",
"reference": "tags/0.6.3-pre6"
"reference": "tags/0.6.3-pre7"
}
}
}
Expand Down
Loading

0 comments on commit 824135a

Please sign in to comment.