/** * 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() { DB::table('ship_types')->delete(); ShipType::create(['name' => 'Explorer', 'description' => 'The most basic ship available. With limited cargo storage and no weapons.', 'slots' => 10, 'structure' => 100]); }