@@ -17,7 +17,7 @@ public class ImproverBot extends Bot {
1717 private float staminaThreshold ;
1818 private boolean improveActionFinished ;
1919 private boolean groundMode ;
20- private ToolSkill groundModeToolSkill ;
20+ private ToolSkill toolSkill = ToolSkill . UNKNOWN ;
2121
2222 @ SuppressWarnings ("ArraysAsListWithZeroOrOneArgument" )
2323 public ImproverBot () {
@@ -26,25 +26,30 @@ public ImproverBot() {
2626 registerInputHandler (InputKey .ls , input -> listAvailableSkills ());
2727 registerInputHandler (InputKey .g , this ::handleGroundModeChange );
2828 registerInputHandler (InputKey .ci , input -> changeInstrument ());
29+ registerInputHandler (InputKey .ss , this ::handleSkillChange );
2930
30- tools .add (new Tool (1201 , "carving knife" , true , new HashSet <>(Arrays .asList (ToolSkill .CARPENTRY ))));
31- tools .add (new Tool (741 , "mallet" , true , new HashSet <>(Arrays .asList (ToolSkill .CARPENTRY ))));
32- tools .add (new Tool (749 , "file" , true , new HashSet <>(Arrays .asList (ToolSkill .CARPENTRY ))));
33- tools .add (new Tool (602 , "pelt" , true , new HashSet <>(Arrays .asList (ToolSkill .CARPENTRY ))));
34- tools .add (new Tool (606 , "log" , false , new HashSet <>(Arrays .asList (ToolSkill .CARPENTRY ))));
31+ tools .add (new Tool (1201 , "carving knife" , true , false , new HashSet <>(Arrays .asList (ToolSkill .CARPENTRY ))));
32+ tools .add (new Tool (741 , "mallet" , true , false , new HashSet <>(Arrays .asList (ToolSkill .CARPENTRY , ToolSkill . LEATHERWORKING ))));
33+ tools .add (new Tool (749 , "file" , true , false , new HashSet <>(Arrays .asList (ToolSkill .CARPENTRY ))));
34+ tools .add (new Tool (602 , "pelt" , true , false , new HashSet <>(Arrays .asList (ToolSkill .CARPENTRY ))));
35+ tools .add (new Tool (606 , "log" , false , false , new HashSet <>(Arrays .asList (ToolSkill .CARPENTRY ))));
3536
36- tools .add (new Tool (1201 , "stone chisel" , true , new HashSet <>(Arrays .asList (ToolSkill .MASONRY ))));
37- tools .add (new Tool (610 , "shards" , false , new HashSet <>(Arrays .asList (ToolSkill .MASONRY ))));
37+ tools .add (new Tool (1201 , "stone chisel" , true , false , new HashSet <>(Arrays .asList (ToolSkill .MASONRY ))));
38+ tools .add (new Tool (610 , "shards" , false , false , new HashSet <>(Arrays .asList (ToolSkill .MASONRY ))));
3839
39- tools .add (new Tool (808 , "spatula" , true , new HashSet <>(Arrays .asList (ToolSkill .POTTERY ))));
40- tools .add (new Tool (802 , "clay shaper" , true , new HashSet <>(Arrays .asList (ToolSkill .POTTERY ))));
41- tools .add (new Tool (540 , "water" , false , new HashSet <>(Arrays .asList (ToolSkill .POTTERY , ToolSkill .TAILORING ))));
42- tools .add (new Tool (591 , "clay" , false , new HashSet <>(Arrays .asList (ToolSkill .POTTERY ))));
43- tools .add (new Tool (4 , "hand" , true , new HashSet <>(Arrays .asList (ToolSkill .POTTERY ))));
40+ tools .add (new Tool (808 , "spatula" , true , false , new HashSet <>(Arrays .asList (ToolSkill .POTTERY ))));
41+ tools .add (new Tool (802 , "clay shaper" , true , false , new HashSet <>(Arrays .asList (ToolSkill .POTTERY ))));
42+ tools .add (new Tool (540 , "water" , false , true , new HashSet <>(Arrays .asList (ToolSkill .POTTERY , ToolSkill .CLOTH_TAILORING ))));
43+ tools .add (new Tool (591 , "clay" , false , true , new HashSet <>(Arrays .asList (ToolSkill .POTTERY ))));
44+ tools .add (new Tool (4 , "hand" , true , false , new HashSet <>(Arrays .asList (ToolSkill .POTTERY ))));
4445
45- tools .add (new Tool (788 , "needle" , true , new HashSet <>(Arrays .asList (ToolSkill .TAILORING ))));
46- tools .add (new Tool (748 , "scissors" , true , new HashSet <>(Arrays .asList (ToolSkill .TAILORING ))));
47- tools .add (new Tool (620 , "string of cloth" , true , new HashSet <>(Arrays .asList (ToolSkill .TAILORING ))));
46+ tools .add (new Tool (788 , "needle" , true , false , new HashSet <>(Arrays .asList (ToolSkill .CLOTH_TAILORING , ToolSkill .LEATHERWORKING ))));
47+ tools .add (new Tool (748 , "scissors" , true , false , new HashSet <>(Arrays .asList (ToolSkill .CLOTH_TAILORING ))));
48+ tools .add (new Tool (620 , "string of cloth" , false , false , new HashSet <>(Arrays .asList (ToolSkill .CLOTH_TAILORING ))));
49+
50+ tools .add (new Tool (766 , "leather knife" , true , false , new HashSet <>(Arrays .asList (ToolSkill .LEATHERWORKING ))));
51+ tools .add (new Tool (754 , "awl" , true , false , new HashSet <>(Arrays .asList (ToolSkill .LEATHERWORKING ))));
52+ tools .add (new Tool (602 , "leather" , false , true , new HashSet <>(Arrays .asList (ToolSkill .LEATHERWORKING ))));
4853 }
4954
5055 @ Override
@@ -106,8 +111,7 @@ public void work() throws Exception{
106111 }
107112 improveActionFinished = false ;
108113 Mod .hud .sendAction (PlayerAction .REPAIR , pickableUnit .getId ());
109- for (Tool tool : getToolsBySkill (groundModeToolSkill ))
110- {
114+ for (Tool tool : getToolsBySkill (toolSkill )) {
111115 if (tool .itemId == 0 || !tool .fixed ) {
112116 boolean toolItemFound = assignItemForTool (tool );
113117 if (!toolItemFound )
@@ -134,6 +138,8 @@ public void work() throws Exception{
134138 }
135139
136140 private List <Tool > getToolsBySkill (ToolSkill toolSkill ) {
141+ if (toolSkill == null || toolSkill == ToolSkill .UNKNOWN )
142+ return tools ;
137143 List <Tool > toolsBySkill = new ArrayList <>();
138144 for (Tool tool : tools ) {
139145 if (tool .toolSkills .contains (toolSkill ))
@@ -145,7 +151,7 @@ private List<Tool> getToolsBySkill(ToolSkill toolSkill) {
145151 private Tool findToolForImprove (InventoryMetaItem item ) {
146152 if (item == null ) return null ;
147153 Tool returnTool = null ;
148- for (Tool tool : tools )
154+ for (Tool tool : getToolsBySkill ( toolSkill ) )
149155 if (tool .improveIconId == item .getImproveIconId ()) {
150156 if (tool .itemId == 0 ) {
151157 returnTool = tool ;
@@ -165,7 +171,13 @@ private void printShortToolInfo(InventoryMetaItem toolItem) {
165171 * @return true on success
166172 */
167173 private boolean assignItemForTool (Tool tool ) {
168- InventoryMetaItem toolItem = Utils .getInventoryItem (tool .name );
174+ InventoryMetaItem toolItem = null ;
175+ if (tool .exactName ) {
176+ Optional <InventoryMetaItem > toolOptionalItem = Utils .getInventoryItems (tool .name ).stream ().filter (item -> item .getBaseName ().equals (tool .name )).findFirst ();
177+ if (toolOptionalItem .isPresent ())
178+ toolItem = toolOptionalItem .get ();
179+ } else
180+ toolItem = Utils .getInventoryItem (tool .name );
169181 if (toolItem == null ) {
170182 Utils .consolePrint ("Can't find an item for a tool \" " + tool .name + "\" " );
171183 return false ;
@@ -188,7 +200,11 @@ private void registerEventProcessors() {
188200 || message .contains ("has some stains that must be washed away" )
189201 || message .contains ("has an open seam that must be backstitched with an iron needle to improve" )
190202 || message .contains ("has a seam that needs to be hidden by slipstitching with an iron needle" )
191- || message .contains ("has some excess cloth that needs to be cut away with a scissors" ),
203+ || message .contains ("has some excess cloth that needs to be cut away with a scissors" )
204+ || message .contains ("has some excess leather that needs to be cut away with a leather knife" )
205+ || message .contains ("needs some holes punched with an awl" )
206+ || message .contains ("has some holes and must be tailored with an iron needle to improve" )
207+ || message .contains ("in order to smooth out a quirk" ),
192208 () -> improveActionFinished = true );
193209 }
194210
@@ -221,25 +237,32 @@ private void listAvailableSkills() {
221237 }
222238 }
223239
240+ private void handleSkillChange (String [] input ) {
241+ if (input == null || input .length != 1 ) {
242+ printInputKeyUsageString (InputKey .ss );
243+ return ;
244+ }
245+ ToolSkill toolSkill = ToolSkill .getByAbbreviation (input [0 ]);
246+ if (toolSkill == ToolSkill .UNKNOWN ) {
247+ Utils .consolePrint ("Unknown skill abbreviation!" );
248+ } else {
249+ this .toolSkill = toolSkill ;
250+ Utils .consolePrint ("The skill was set to " + toolSkill .name ());
251+ }
252+ }
253+
224254 private void handleGroundModeChange (String input []) {
225- groundMode = !groundMode ;
226255 if (groundMode ) {
227- if (input == null || input .length != 1 ) {
228- printInputKeyUsageString (InputKey .g );
229- groundMode = false ;
230- return ;
231- }
232- ToolSkill toolSkill = ToolSkill .getByAbbreviation (input [0 ]);
256+ groundMode = false ;
257+ Utils .consolePrint ("Ground mode is off!" );
258+ } else {
233259 if (toolSkill == ToolSkill .UNKNOWN ) {
234- Utils .consolePrint ("Unknown skill abbreviation!" );
235- groundMode = false ;
260+ Utils .consolePrint ("Choose the skill first with \" " + InputKey .ss .name () + "\" key" );
236261 return ;
237262 }
238- groundModeToolSkill = toolSkill ;
263+ groundMode = true ;
239264 Utils .consolePrint ("Ground mode is on!" );
240265 }
241- else
242- Utils .consolePrint ("Ground mode is off!" );
243266 }
244267
245268 private void handleStaminaThresholdChange (String input []) {
@@ -283,7 +306,8 @@ enum InputKey {
283306 "threshold(float value between 0 and 1)" ),
284307 at ("Add new inventory(under mouse cursor). Selected items in this inventory will be improved." , "" ),
285308 ls ("List available improving skills" , "" ),
286- g ("Toggle the ground mode. Provide the skill abbreviation to use tools from that skill. You can list available skills using \" " + ls .name () + "\" key" , "skill_abbreviation" ),
309+ ss ("Set the skill. Only tools from that skill will be used. You can list available skills using \" " + ls .name () + "\" key" , "skill_abbreviation" ),
310+ g ("Toggle the ground mode. Set the skill first by \" " + ss .name () + "\" key" , "" ),
287311 ci ("Change previously chosen instrument by tool selected in player's inventory" , "" );
288312 public String description ;
289313
@@ -300,22 +324,30 @@ static class Tool{
300324 String name ;
301325 //items like water or stone will be searched in player's inventory on each use and will have this value set to false
302326 boolean fixed ;
327+ boolean exactName ;
303328 Set <ToolSkill > toolSkills ;
304329
305- Tool (int improveIconId , String name , boolean fixed , Set <ToolSkill > toolSkills ) {
330+ Tool (int improveIconId , String name , boolean fixed , boolean exactName , Set <ToolSkill > toolSkills ) {
306331 this .improveIconId = improveIconId ;
307332 this .name = name ;
308333 this .fixed = fixed ;
334+ this .exactName = exactName ;
309335 this .toolSkills = toolSkills ;
310336 }
337+
338+ @ Override
339+ public String toString () {
340+ return name ;
341+ }
311342 }
312343
313344 enum ToolSkill {
314345 UNKNOWN ("?" ),
315346 CARPENTRY ("c" ),
316347 MASONRY ("m" ),
317348 POTTERY ("p" ),
318- TAILORING ("t" );
349+ CLOTH_TAILORING ("ct" ),
350+ LEATHERWORKING ("l" );
319351
320352 String abbreviation ;
321353 ToolSkill (String abbreviation ) {
0 commit comments