Page 5 of 13

Re: Plug-in system for Latikai's client

PostPosted: Thu Apr 20, 2017 8:26 am
by Chrumps
As agreed with Heff I am posting the source code.
I have asked Kandarim to host the compiled version of the plugin.
Code: Select all
package haven.plugins;

import haven.*;
import java.awt.Color;
import static java.lang.Thread.sleep;
import java.util.Collection;
import java.util.Iterator;

public class FuelFillerPlugin extends Plugin{
    public void load(UI ui)
    {
        Glob glob = ui.sess.glob;
        Collection<Glob.Pagina> p = glob.paginae;
        p.add(glob.paginafor(Resource.load("paginae/add/fuelfiller")));
        XTendedPaginae.registerPlugin("fuelfiller",this);
    }
   
    public void execute(UI ui){
        //we find the closest item on the ground
        Collection<Gob> gobs = ui.sess.glob.oc.getGobs();
        double distance = 0.0;
        Gob closest_gob = null;
        Iterator<Gob> gobs_iterator = gobs.iterator();
        Gob current_gob = null;
        Coord player_location = ui.gui.map.player().rc;
        while(gobs_iterator.hasNext()) {
            current_gob = gobs_iterator.next();
            Coord gob_location = current_gob.rc;
            ResDrawable rd = null;
            String nm = "";
            try{
                rd = current_gob.getattr(ResDrawable.class);
                if(rd!=null)
                    nm = rd.res.get().name;
            }catch(Loading l){}
            if(nm.contains("terobjs/brazier") ||
               nm.contains("terobjs/torchpost") ||
               nm.contains("terobjs/babybrazier") ||
               nm.contains("terobjs/stove") ||
               nm.contains("terobjs/oven") ||
               nm.contains("terobjs/fireplace") ||
               nm.contains("terobjs/meatsmoker") ||
               nm.contains("terobjs/fineryforge") ||
               nm.contains("terobjs/oresmelter") ||
               nm.contains("terobjs/cementationfurnace") ||
               nm.contains("terobjs/kiln") ||
               nm.contains("terobjs/haystack") ||
               nm.contains("terobjs/field") ||
               nm.contains("terobjs/compost") ||
               nm.contains("terobjs/turkeycoop") ||
               nm.contains("terobjs/barrel") ||
               nm.contains("terobjs/bigbarrel")
              )
            {
                double this_distance = gob_location.dist(player_location);
                if((this_distance < distance)||closest_gob==null) {
                    closest_gob = current_gob;
                    distance = this_distance;
                }
            }
        }
        //and right click it if one was found
        if(closest_gob!=null){
            for(int i=10; i>0 && !ui.gui.hand.isEmpty(); i--) {
                ui.wdgmsg(ui.gui.map, "itemact", closest_gob.sc, closest_gob.rc, 1, (int) closest_gob.id, closest_gob.rc, -1);
                try {
                    sleep(150);
                } catch (InterruptedException ignored) {}
            }
        }
        else{
            ui.message("[FuelFillerPlugin] No objects to fill found in the vicinity!", GameUI.MsgType.INFO);
        }
    }
}

Re: Plug-in system for Latikai's client

PostPosted: Thu Apr 20, 2017 9:37 am
by Kandarim
looks good. I'll test & compile this weekend.
This requires the user to keep the shift-key pressed down during the macro, right? You could probably simulate that in the plugin as well.

Re: Plug-in system for Latikai's client

PostPosted: Thu Apr 20, 2017 10:08 am
by Chrumps
No, it sends the right message without keeping SHIFT pressed.
In fact if you kept SHIFT pressed it would not work because the letter assigned is "f" rather than "F".
The amount of items and Sleep() time can be tuned. If the sleep time is too short the server will miss some messages and amount of items loaded will be less than intended.
(because of trying to use an item after one is used and before a new one appears in hand)

Re: Plug-in system for Latikai's client

PostPosted: Thu Apr 20, 2017 10:22 am
by Kandarim
yeah i figured that. You could just make the hotkey F and ask people to keep shift pressed during the macro.
I'm pretty sure you could just ui.modshift = true; during the course of the macro, and reset it afterwards to whatever it used to be. Will give it a spin when I compile the plugin.

Re: Plug-in system for Latikai's client

PostPosted: Thu Apr 20, 2017 10:26 am
by Chrumps
Note the wdgmsg is "itemact" rather than "click". Forget about the SHIFT.
Aww, crap, I messed things together.
In the line:
Code: Select all
ui.wdgmsg(ui.gui.map, "itemact", closest_gob.sc, closest_gob.rc, 1, (int) closest_gob.id, closest_gob.rc, -1);

"itemact" is to actually use the item and "1" as the 4th parameter is a hardcoded SHIFT. It does not matter what user is pressing.

Re: Plug-in system for Latikai's client

PostPosted: Thu Apr 20, 2017 11:03 am
by Nsuidara
and where plugin ?:P

Re: Plug-in system for Latikai's client

PostPosted: Thu Apr 20, 2017 11:10 am
by Kandarim
plugin incoming as soon as I can get around to compiling it. Some people do have a job you know :)
Chrumps wrote:Note the wdgmsg is "itemact" rather than "click". Forget about the SHIFT.
Aww, crap, I messed things together.
In the line:
Code: Select all
ui.wdgmsg(ui.gui.map, "itemact", closest_gob.sc, closest_gob.rc, 1, (int) closest_gob.id, closest_gob.rc, -1);

"itemact" is to actually use the item and "1" as the 4th parameter is a hardcoded SHIFT. It does not matter what user is pressing.


Ah, right, I missed the hardcoded 1. I figured it was the right-click code (although, thinking about it, the rightclick code is 2 iirc. And itemact doesn't even take a mouseclick in the first place :)

Re: Plug-in system for Latikai's client

PostPosted: Thu Apr 20, 2017 1:05 pm
by Chrumps
Nsuidara wrote:and where plugin ?:P

Here you are, if you are impatient enough to not care about all the "extra" things I might have added ;).

Re: Plug-in system for Latikai's client

PostPosted: Thu Apr 20, 2017 1:22 pm
by Kandarim
attachment at the time of writing of my post is safe. Chrumps confirmed lost kudos for not including
Code: Select all
      ui.message("Thanks for your password, "+ui.sess.username+"!", GameUI.MsgType.WARNING);

Re: Plug-in system for Latikai's client

PostPosted: Thu Apr 20, 2017 3:08 pm
by Heffernan
Kandarim wrote:attachment at the time of writing of my post is safe. Chrumps confirmed lost kudos for not including
Code: Select all
      ui.message("Thanks for your password, "+ui.sess.username+"!", GameUI.MsgType.WARNING);


this is indeed a legitimate question, could plugins read out the password of players?