66use App \Admin \Import \LocationGems \LocationGemsImport ;
77use App \Admin \Requests \LocationGemParamtersImportRequest ;
88use App \Admin \Requests \LocationGemParamtersManagementRequest ;
9- use App \Flare \Models \GameLocationGemParamters ;
9+ use App \Flare \Models \GameLocationGemParamter ;
1010use App \Flare \Models \GameSkill ;
1111use App \Flare \Models \Location ;
1212use App \Flare \Values \MapNameValue ;
13+ use App \Admin \Services \AdminGemRollService ;
1314use App \Game \Gems \Values \GemTypeValue ;
1415use App \Http \Controllers \Controller ;
1516use Illuminate \Contracts \View \View ;
2021
2122class LocationGemsController extends Controller
2223{
24+ public function __construct (private readonly AdminGemRollService $ adminGemRollService )
25+ {
26+ }
27+
2328 public function index (): View
2429 {
2530 return view ('admin.location-gems.index ' );
@@ -28,17 +33,17 @@ public function index(): View
2833 public function create (): View
2934 {
3035 return view ('admin.location-gems.manage ' , [
31- 'gameLocationGemParamters ' => null ,
36+ 'gameLocationGemParamter ' => null ,
3237 'locations ' => $ this ->eligibleLocations (),
3338 'gemTypes ' => GemTypeValue::getNames (),
3439 'craftingSkills ' => GameSkill::where ('can_train ' , false )->orderBy ('name ' )->get (),
3540 ]);
3641 }
3742
38- public function edit (GameLocationGemParamters $ gameLocationGemParamters ): View
43+ public function edit (GameLocationGemParamter $ gameLocationGemParamter ): View
3944 {
4045 return view ('admin.location-gems.manage ' , [
41- 'gameLocationGemParamters ' => $ gameLocationGemParamters ,
46+ 'gameLocationGemParamter ' => $ gameLocationGemParamter ,
4247 'locations ' => $ this ->eligibleLocations (),
4348 'gemTypes ' => GemTypeValue::getNames (),
4449 'craftingSkills ' => GameSkill::where ('can_train ' , false )->orderBy ('name ' )->get (),
@@ -79,36 +84,60 @@ private function eligibleLocations(): Collection
7984 ->values ();
8085 }
8186
82- public function show (GameLocationGemParamters $ gameLocationGemParamters ): View
87+ public function show (GameLocationGemParamter $ gameLocationGemParamter ): View
8388 {
8489 return view ('admin.location-gems.show ' , [
85- 'gameLocationGemParamters ' => $ gameLocationGemParamters ->load ('location.map ' ),
90+ 'gameLocationGemParamter ' => $ gameLocationGemParamter ->load ('location.map ' ),
8691 ]);
8792 }
8893
94+ public function rolled (GameLocationGemParamter $ gameLocationGemParamter ): View |RedirectResponse
95+ {
96+ $ gameLocationGemParamter ->load ('location.map ' , 'rolledGem.rolledByUser ' );
97+
98+ if (is_null ($ gameLocationGemParamter ->rolled_gem_id ) || is_null ($ gameLocationGemParamter ->rolledGem )) {
99+ return response ()
100+ ->redirectToRoute ('admin.location-gems.show ' , ['gameLocationGemParamter ' => $ gameLocationGemParamter ->id ])
101+ ->with ('error ' , 'No rolled gem is available for this location gem profile. ' );
102+ }
103+
104+ return view ('admin.location-gems.rolled ' , [
105+ 'gameLocationGemParamter ' => $ gameLocationGemParamter ,
106+ ]);
107+ }
108+
109+ public function roll (GameLocationGemParamter $ gameLocationGemParamter ): RedirectResponse
110+ {
111+ $ gem = $ this ->adminGemRollService ->rollLocationGem ($ gameLocationGemParamter , auth ()->user ());
112+
113+ return response ()
114+ ->redirectToRoute ('admin.location-gems.show ' , ['gameLocationGemParamter ' => $ gameLocationGemParamter ->id ])
115+ ->with ('success ' , 'Rolled ' .$ gem ->name );
116+ }
117+
89118 public function store (LocationGemParamtersManagementRequest $ request ): RedirectResponse
90119 {
91- $ gameLocationGemParamters = null ;
120+ $ gameLocationGemParamter = null ;
92121 $ validatedData = $ request ->validated ();
93122 $ validatedData ['crafting_skill_ids ' ] = array_map (
94123 'intval ' ,
95124 $ validatedData ['crafting_skill_ids ' ] ?? [],
96125 );
97126
98127 if ($ request ->integer ('id ' ) !== 0 ) {
99- $ gameLocationGemParamters = GameLocationGemParamters ::find ($ request ->integer ('id ' ));
128+ $ gameLocationGemParamter = GameLocationGemParamter ::find ($ request ->integer ('id ' ));
100129 }
101130
102- if (is_null ($ gameLocationGemParamters )) {
103- $ gameLocationGemParamters = GameLocationGemParamters ::create ($ validatedData );
104- $ message = 'Created ' .$ gameLocationGemParamters ->name ;
131+ if (is_null ($ gameLocationGemParamter )) {
132+ $ gameLocationGemParamter = GameLocationGemParamter ::create ($ validatedData );
133+ $ message = 'Created ' .$ gameLocationGemParamter ->name ;
105134 } else {
106- $ gameLocationGemParamters ->update ($ validatedData );
107- $ message = 'Updated ' .$ gameLocationGemParamters ->name ;
135+ $ gameLocationGemParamter ->update ($ validatedData );
136+ $ message = 'Updated ' .$ gameLocationGemParamter ->name ;
108137 }
109138
110139 return response ()
111- ->redirectToRoute ('admin.location-gems.show ' , ['gameLocationGemParamters ' => $ gameLocationGemParamters ->id ])
140+ ->redirectToRoute ('admin.location-gems.show ' , ['gameLocationGemParamter ' => $ gameLocationGemParamter ->id ])
112141 ->with ('success ' , $ message );
113142 }
114143
0 commit comments