44
55use App \Flare \Models \FactionLoyaltyNpcTask ;
66use App \Flare \Models \Item ;
7+ use App \Flare \Values \MapNameValue ;
8+ use App \Game \Character \CharacterInventory \Values \ItemType ;
79use Illuminate \Console \Command ;
810
911class FixFactionLoyaltyCraftingTasks extends Command
@@ -37,20 +39,69 @@ public function handle()
3739 private function fixInvalidItemsOnFactionLoyaltyTask (FactionLoyaltyNpcTask $ factionLoyaltyNpcTask ): void {
3840 $ tasks = $ factionLoyaltyNpcTask ->fame_tasks ;
3941
42+ $ types = [
43+ 'weapon ' ,
44+ 'ring ' ,
45+ 'armour ' ,
46+ 'spell ' ,
47+ ];
48+
4049
4150 foreach ($ tasks as $ index => $ task ) {
4251 if ($ task ['type ' ] === 'bounty ' ) {
4352 continue ;
4453 }
4554
55+ if ($ task ['type ' ] === 'weapon ' ) {
56+ $ this ->info ('Found an invalid type: Weapon, replacing ... ' );
57+
58+ if (is_null ($ factionLoyaltyNpcTask ->factionLoyaltyNpc ) || is_null ($ factionLoyaltyNpcTask ->factionLoyalty )) {
59+ continue ;
60+ }
61+
62+ $ gameMapName = $ factionLoyaltyNpcTask ->factionLoyaltyNpc ->npc ->gameMap ->name ;
63+
64+ $ item = $ this ->getItemForCraftingTask ($ types [rand (0 , count ($ types ) - 1 )], $ gameMapName );
65+
66+ $ task ['item_id ' ] = $ item ->id ;
67+ $ task ['item_name ' ] = $ item ->name ;
68+ $ task ['type ' ] = $ item ->type ;
69+
70+ $ tasks [$ index ] = $ task ;
71+
72+ $ this ->info ('Replaced weapon type ' );
73+
74+ continue ;
75+ }
76+
4677 $ doesItemExist = Item::where ('id ' , $ task ['item_id ' ])->exists ();
4778
4879 if (!$ doesItemExist ) {
4980 $ this ->info ('Item: ' . $ task ['item_name ' ] . ' does not exist for id: ' . $ task ['item_id ' ] . '. Starting replacement ' );
5081
51- $ foundItemByName = Item::where ('name ' , $ task ['item_name ' ])->first ();
82+ $ item = Item::where ('name ' , $ task ['item_name ' ])
83+ ->doesntHave ('itemSuffix ' )
84+ ->doesntHave ('itemPrefix ' )
85+ ->doesntHave ('appliedHolyStacks ' )
86+ ->doesntHave ('sockets ' )
87+ ->whereNotIn ('type ' , ['quest ' , 'alchemy ' , 'trinket ' , 'artifact ' ])
88+ ->whereNull ('specialty_type ' )
89+ ->first ();
90+
91+ if (is_null ($ item )) {
5292
53- $ task ['item_id ' ] = $ foundItemByName ->id ;
93+ if (is_null ($ factionLoyaltyNpcTask ->factionLoyaltyNpc ) || is_null ($ factionLoyaltyNpcTask ->factionLoyalty )) {
94+ continue ;
95+ }
96+
97+ $ gameMapName = $ factionLoyaltyNpcTask ->factionLoyaltyNpc ->npc ->gameMap ->name ;
98+
99+ $ item = $ this ->getItemForCraftingTask ($ types [rand (0 , count ($ types ) - 1 )], $ gameMapName );
100+ }
101+
102+ $ task ['item_id ' ] = $ item ->id ;
103+ $ task ['item_name ' ] = $ item ->name ;
104+ $ task ['type ' ] = $ item ->type ;
54105
55106 $ tasks [$ index ] = $ task ;
56107
@@ -62,4 +113,43 @@ private function fixInvalidItemsOnFactionLoyaltyTask(FactionLoyaltyNpcTask $fact
62113 'fame_tasks ' => $ tasks ,
63114 ]);
64115 }
116+
117+ private function getItemForCraftingTask (string $ type , string $ gamMapName ): Item
118+ {
119+
120+ $ gameMapValue = new MapNameValue ($ gamMapName );
121+
122+ $ item = Item::inRandomOrder ()->doesntHave ('itemSuffix ' )
123+ ->doesntHave ('itemPrefix ' )
124+ ->doesntHave ('appliedHolyStacks ' )
125+ ->doesntHave ('sockets ' )
126+ ->whereNotIn ('type ' , ['quest ' , 'alchemy ' , 'trinket ' , 'artifact ' ])
127+ ->whereNull ('specialty_type ' );
128+
129+ if ($ gameMapValue ->isSurface () || $ gameMapValue ->isTheIcePlane () || $ gameMapValue ->isDelusionalMemories ()) {
130+ $ item ->where ('skill_level_required ' , '<= ' , 50 );
131+ }
132+
133+ if ($ gameMapValue ->isLabyrinth ()) {
134+ $ item ->where ('skill_level_required ' , '<= ' , 150 );
135+ }
136+
137+ if ($ gameMapValue ->isDungeons ()) {
138+ $ item ->where ('skill_level_required ' , '<= ' , 240 );
139+ }
140+
141+ if ($ gameMapValue ->isHell ()) {
142+ $ item ->where ('skill_level_required ' , '<= ' , 300 );
143+ }
144+
145+ if ($ gameMapValue ->isPurgatory ()) {
146+ $ item ->where ('skill_level_required ' , '<= ' , 350 );
147+ }
148+
149+ if ($ gameMapValue ->isTwistedMemories ()) {
150+ $ item ->where ('skill_level_required ' , '<= ' , 370 );
151+ }
152+
153+ return $ item ->where ('crafting_type ' , $ type )->first ();
154+ }
65155}
0 commit comments