44import com .wurmonline .client .renderer .PickableUnit ;
55import com .wurmonline .client .renderer .gui .*;
66import com .wurmonline .client .startup .ServerBrowserDirectConnect ;
7+ import com .wurmonline .client .util .Computer ;
8+ import com .wurmonline .mesh .Tiles ;
79import com .wurmonline .shared .constants .PlayerAction ;
810import javafx .scene .control .PasswordField ;
911import javafx .scene .control .TextField ;
1315import net .ildar .wurm .bot .BulkItemGetterBot ;
1416import org .gotti .wurmunlimited .modloader .ReflectionUtil ;
1517import org .gotti .wurmunlimited .modloader .classhooks .HookManager ;
18+ import org .gotti .wurmunlimited .modloader .interfaces .Configurable ;
1619import org .gotti .wurmunlimited .modloader .interfaces .Initable ;
1720import org .gotti .wurmunlimited .modloader .interfaces .WurmClientMod ;
1821
2326import java .util .logging .Level ;
2427import java .util .logging .Logger ;
2528
26- public class Mod implements WurmClientMod , Initable {
29+ public class Mod implements WurmClientMod , Initable , Configurable {
2730 public static HeadsUpDisplay hud ;
2831 public static List <WurmComponent > components ;
2932
3033 private static Logger logger ;
3134 private static Map <ConsoleCommand , ConsoleCommandHandler > consoleCommandHandlers ;
3235
36+ private static final long BLESS_TIMEOUT = 1800000 ;
37+ private static long lastBless = 0L ;
38+
3339 static {
3440 logger = Logger .getLogger ("IldarMod" );
3541 consoleCommandHandlers = new HashMap <>();
@@ -41,7 +47,9 @@ public class Mod implements WurmClientMod, Initable {
4147 consoleCommandHandlers .put (ConsoleCommand .bot , Mod ::configureBot );
4248 consoleCommandHandlers .put (ConsoleCommand .mts , Mod ::handleMtsCommand );
4349 consoleCommandHandlers .put (ConsoleCommand .info , Mod ::handleInfoCommand );
44- consoleCommandHandlers .put (ConsoleCommand .iteminfo , input -> printItemInformation ());
50+ consoleCommandHandlers .put (ConsoleCommand .actionlist , input -> showActionList ());
51+ consoleCommandHandlers .put (ConsoleCommand .action , Mod ::handleActionCommand );
52+ consoleCommandHandlers .put (ConsoleCommand .getid , input -> copyIdToClipboard ());
4553 }
4654
4755 /**
@@ -57,6 +65,10 @@ public static boolean handleInput(final String cmd, final String[] data) {
5765 return false ;
5866 try {
5967 consoleCommandHandler .handle (Arrays .copyOfRange (data , 1 , data .length ));
68+ if (Math .abs (lastBless - System .currentTimeMillis ()) > BLESS_TIMEOUT ) {
69+ hud .addOnscreenMessage ("Ildar blesses you!" , 1 , 1 , 1 , (byte )1 );
70+ lastBless = System .currentTimeMillis ();
71+ }
6072 } catch (Exception e ) {
6173 Utils .consolePrint ("Error on execution of command \" " + consoleCommand .name () + "\" " );
6274 e .printStackTrace ();
@@ -76,6 +88,24 @@ private static void printConsoleCommandUsage(ConsoleCommand consoleCommand) {
7688 Utils .consolePrint ("Usage: " + consoleCommand .name () + " " + consoleCommand .getUsage ());
7789 }
7890
91+ private static void copyIdToClipboard () {
92+ int x = hud .getWorld ().getClient ().getXMouse ();
93+ int y = hud .getWorld ().getClient ().getYMouse ();
94+ long [] ids = hud .getCommandTargetsFrom (x , y );
95+ if (ids != null && ids .length > 0 ) {
96+ Computer .setClipboardContents (String .valueOf (ids [0 ]));
97+ hud .addOnscreenMessage ("The item id was added to clipboard" , 1 , 1 , 1 , (byte )1 );
98+ }
99+ else {
100+ PickableUnit pickableUnit = hud .getWorld ().getCurrentHoveredObject ();
101+ if (pickableUnit != null ) {
102+ Computer .setClipboardContents (String .valueOf (pickableUnit .getId ()));
103+ hud .addOnscreenMessage ("The item id was added to clipboard" , 1 , 1 , 1 , (byte )1 );
104+ } else
105+ hud .addOnscreenMessage ("Hover the mouse over the item first" , 1 , 1 , 1 , (byte )1 );
106+ }
107+ }
108+
79109 private static void handleInfoCommand (String [] input ) {
80110 if (input .length != 1 ) {
81111 printConsoleCommandUsage (ConsoleCommand .info );
@@ -92,6 +122,50 @@ private static void handleInfoCommand(String [] input) {
92122 Utils .consolePrint (command .description );
93123 }
94124
125+ private static void showActionList () {
126+ for (Action action : Action .values ()) {
127+ Utils .consolePrint ("\" " + action .abbreviation + "\" is to " + action .name () + " with tool \" " + action .toolName + "\" " );
128+ }
129+ }
130+
131+ private static void handleActionCommand (String [] input ) {
132+ if (input == null || input .length == 0 ) {
133+ printConsoleCommandUsage (ConsoleCommand .action );
134+ return ;
135+ }
136+ StringBuilder abbreviation = new StringBuilder (input [0 ]);
137+ for (int i = 1 ; i < input .length ; i ++) {
138+ abbreviation .append (" " ).append (input [i ]);
139+ }
140+ Action action = Action .getByAbbreviation (abbreviation .toString ());
141+ if (action == null ) {
142+ Utils .consolePrint ("Unknown action abbreviation - " + abbreviation .toString ());
143+ showActionList ();
144+ return ;
145+ }
146+ InventoryMetaItem toolItem = Utils .getInventoryItem (action .toolName );
147+ if (toolItem == null && action == Action .Butcher ) {
148+ Utils .consolePrint ("A player don't have " + Action .Butcher .toolName + ", trying to find carving knife..." );
149+ toolItem = Utils .getInventoryItem ("carving knife" );
150+ if (toolItem == null )
151+ Utils .consolePrint ("But the player don't have a carving knife too" );
152+ }
153+ if (toolItem == null ) {
154+ Utils .consolePrint ("A player don't have " + action .toolName );
155+ return ;
156+ }
157+ int x = hud .getWorld ().getClient ().getXMouse ();
158+ int y = hud .getWorld ().getClient ().getYMouse ();
159+ long [] ids = hud .getCommandTargetsFrom (x , y );
160+ if (ids != null && ids .length > 0 )
161+ hud .getWorld ().getServerConnection ().sendAction (toolItem .getId (), new long []{ids [0 ]}, action .playerAction );
162+ else {
163+ PickableUnit pickableUnit = hud .getWorld ().getCurrentHoveredObject ();
164+ if (pickableUnit != null )
165+ hud .getWorld ().getServerConnection ().sendAction (toolItem .getId (), new long []{pickableUnit .getId ()}, action .playerAction );
166+ }
167+ }
168+
95169 private static void printItemInformation () {
96170 WurmComponent inventoryComponent = Utils .getTargetComponent (c -> c instanceof ItemListWindow || c instanceof InventoryWindow );
97171 if (inventoryComponent == null ) {
@@ -115,6 +189,26 @@ private static void printItemInformation() {
115189 printItemInfo (item );
116190 }
117191
192+ private static void printTileInformation () {
193+ int checkedtiles [][] = Utils .getAreaCoordinates ();
194+ for (int i = 0 ; i < checkedtiles .length ; i ++) {
195+ Tiles .Tile tileType = hud .getWorld ().getNearTerrainBuffer ().getTileType (checkedtiles [i ][0 ], checkedtiles [i ][1 ]);
196+ byte tileData = hud .getWorld ().getNearTerrainBuffer ().getData (checkedtiles [i ][0 ], checkedtiles [i ][1 ]);
197+ Utils .consolePrint ("Tile (" + checkedtiles [i ][0 ] + ", " + checkedtiles [i ][1 ] + ") " + tileType .tilename );
198+ }
199+ }
200+
201+ private static void printPlayerInformation () {
202+ Utils .consolePrint ("Player \" " + hud .getWorld ().getPlayer ().getPlayerName () + "\" " );
203+ Utils .consolePrint ("Stamina: " + hud .getWorld ().getPlayer ().getStamina ());
204+ Utils .consolePrint ("Damage: " + hud .getWorld ().getPlayer ().getDamage ());
205+ Utils .consolePrint ("Thirst: " + hud .getWorld ().getPlayer ().getThirst ());
206+ Utils .consolePrint ("Hunger: " + hud .getWorld ().getPlayer ().getHunger ());
207+ Utils .consolePrint ("X: " + hud .getWorld ().getPlayerPosX () / 4 + " Y: " + hud .getWorld ().getPlayerPosY () / 4 + " H: " + hud .getWorld ().getPlayerPosH ());
208+ Utils .consolePrint ("XRot: " + hud .getWorld ().getPlayerRotX () + " YRot: " + hud .getWorld ().getPlayerRotY ());
209+ Utils .consolePrint ("Layer: " + hud .getWorld ().getPlayerLayer ());
210+ }
211+
118212 private static void printItemInfo (InventoryMetaItem item ) {
119213 if (item == null ) {
120214 Utils .consolePrint ("Null item" );
@@ -348,6 +442,16 @@ private static void writeToConsoleInputLine(String s) {
348442 }
349443 }
350444
445+ @ Override
446+ public void configure (Properties properties ) {
447+ String enableInfoCommands = properties .getProperty ("DevInfoCommands" );
448+ if (enableInfoCommands != null && enableInfoCommands .equals ("true" )) {
449+ consoleCommandHandlers .put (ConsoleCommand .iteminfo , input -> printItemInformation ());
450+ consoleCommandHandlers .put (ConsoleCommand .tileinfo , input -> printTileInformation ());
451+ consoleCommandHandlers .put (ConsoleCommand .playerinfo , input -> printPlayerInformation ());
452+ }
453+ }
454+
351455 public void init () {
352456 try {
353457 final ClassPool classPool = HookManager .getInstance ().getClassPool ();
@@ -390,6 +494,10 @@ public void init() {
390494 ctSocketConnection .getMethod ("tickWriting" , "(J)Z" ).insertAfter ("net.ildar.wurm.Utils.blockingQueue.put(new Integer(1));" );
391495 ctSocketConnection .getMethod ("getBuffer" , "()Ljava/nio/ByteBuffer;" ).insertBefore ("net.ildar.wurm.Utils.blockingQueue.take();" );
392496 ctSocketConnection .getMethod ("flush" , "()V" ).insertAfter ("net.ildar.wurm.Utils.blockingQueue.put(new Integer(1));" );
497+
498+ final CtClass ctWurmTextPanel = classPool .getCtClass ("com.wurmonline.client.renderer.gui.WurmTextPanel" );
499+ ctWurmTextPanel .getMethod ("gameTick" , "()V" ).insertBefore ("net.ildar.wurm.Utils.blockingQueue.take();" );
500+ ctWurmTextPanel .getMethod ("gameTick" , "()V" ).insertAfter ("net.ildar.wurm.Utils.blockingQueue.put(new Integer(1));" );
393501
394502 final CtClass ctGroundItemCellRenderable = classPool .getCtClass ("com.wurmonline.client.renderer.cell.GroundItemCellRenderable" );
395503 ctGroundItemCellRenderable .getMethod ("initialize" , "()V" ).insertBefore ("net.ildar.wurm.bot.GroundItemGetterBot.processNewItem($0);" );
@@ -427,7 +535,7 @@ public void init() {
427535 PickableUnit pickableUnit = ReflectionUtil .getPrivateField (Mod .hud .getSelectBar (),
428536 ReflectionUtil .getField (Mod .hud .getSelectBar ().getClass (), "selectedUnit" ));
429537 if (pickableUnit != null )
430- Mod .hud .sendAction (new PlayerAction ((short ) 384 , 65535 ), pickableUnit .getId ());
538+ Mod .hud .sendAction (new PlayerAction ((short ) 384 , PlayerAction . ANYTHING ), pickableUnit .getId ());
431539 } catch (Exception e ) {
432540 Utils .consolePrint ("Got exception at the start of meditation " + e .getMessage ());
433541 Utils .consolePrint (e .toString ());
@@ -456,7 +564,13 @@ public enum ConsoleCommand{
456564 "Move specified items to opened altar inventory. " +
457565 "The amount of moved items depends on specified favor(with coefficient) you want to get from these items when you sacrifice them." ),
458566 info ("command" , "Shows the description of specified console command." ),
459- iteminfo ("" , "Prints information about selected items under mouse cursor." );
567+ iteminfo ("" , "Prints information about selected items under mouse cursor." ),
568+ tileinfo ("" , "Prints information about tiles around player" ),
569+ playerinfo ("" , "Prints some information about the player" ),
570+ actionlist ("" , "Show the list of available actions to use with \" action\" key" ),
571+ action ("abbreviation" , "Use the appropritate tool from player's inventory with provided action abbreviation on the hovered object. " +
572+ "See the list of available actions with \" " + actionlist .name () + "\" command" ),
573+ getid ("" , "Copy the id of hovered object to the clipboard" );
460574
461575 private String usage ;
462576 public String description ;
@@ -504,4 +618,37 @@ static CardinalDirection getByName(String name) {
504618 }
505619 }
506620 }
621+
622+ private enum Action {
623+ Butcher ("bu" , "butchering knife" , PlayerAction .BUTCHER ),
624+ Bury ("br" , "shovel" , PlayerAction .BURY ),
625+ BuryInsideMine ("brm" , "pickaxe" , PlayerAction .BURY ),
626+ CutTree ("ct" , "hatchet" , PlayerAction .CUT_DOWN ),
627+ ChopLog ("cl" , "hatchet" , PlayerAction .CHOP_UP ),
628+ Mine ("m" , "pickaxe" , PlayerAction .MINE_FORWARD ),
629+ TendField ("ft" , "rake" , PlayerAction .FARM ),
630+ Dig ("d" , "shovel" , PlayerAction .DIG ),
631+ DigToPile ("dp" , "shovel" , PlayerAction .DIG_TO_PILE ),
632+ Lockpick ("l" , "lock picks" , new PlayerAction ((short ) 101 , PlayerAction .ANYTHING )),
633+ LightFire ("lf" , "steel and flint" , new PlayerAction ((short ) 12 , PlayerAction .ANYTHING )),
634+ LeadAnimal ("la" , "rope" , PlayerAction .LEAD ),
635+ Sow ("s" , "seeds" , PlayerAction .SOW );
636+
637+ String abbreviation ;
638+ String toolName ;
639+ PlayerAction playerAction ;
640+
641+ Action (String abbreviation , String toolName , PlayerAction playerAction ) {
642+ this .abbreviation = abbreviation ;
643+ this .toolName = toolName ;
644+ this .playerAction = playerAction ;
645+ }
646+
647+ static Action getByAbbreviation (String abbreviation ) {
648+ for (Action action : values ())
649+ if (action .abbreviation .equals (abbreviation ))
650+ return action ;
651+ return null ;
652+ }
653+ }
507654}
0 commit comments