/** * Generate the starting ship for all players. * * @param User $player * * @return Ship */ public static function getStartingShip(User $player) { $ship = new Ship(['name' => self::randomShipName()]); // Start with an 'Explorer' class hip. $shipType = ShipType::whereName('Explorer')->first(); $ship->type()->associate($shipType); // Place it at a random star. $star = Star::findStartLocation(); $ship->location()->associate($star); // Give it to the player. $ship->owner()->associate($player); $ship->save(); // Add a jumpstore and a cargo item. $item = JumpStore::whereValue(1)->get()->random(); $ship->items()->attach($item, ['amount' => 1]); switch (mt_rand(0, 2)) { case 0: $item = BiologyCargo::whereValue(1)->get()->random(); break; case 1: $item = TechnologyCargo::whereValue(1)->get()->random(); break; case 2: $item = LuxuryCargo::whereValue(1)->get()->random(); break; } $ship->items()->attach($item, ['amount' => 1]); // Start with a bit of money and full energy. $ship->credits = 1000; $ship->energy = $ship->energy_capacity; $ship->structure = $shipType->structure; $ship->save(); return $ship; }
/** * Run the database seeds. * * @return void */ public function run() { // Clear out old items. DB::table('items')->delete(); // Create new ones. JumpStore::create(['name' => 'Shocking Watt Pack', 'description' => 'A simple basic jump energy store.', 'value' => 1]); BiologyCargo::create(['name' => 'Biology Cargo', 'description' => 'A simple cargo storage container filled with biologicals.', 'value' => 1]); TechnologyCargo::create(['name' => 'Technology Cargo', 'description' => 'A simple cargo storage container filled with high technology.', 'value' => 1]); LuxuryCargo::create(['name' => 'Luxury Cargo', 'description' => 'A simple cargo storage container filled with luxury items.', 'value' => 1]); }