Plug-in system for Latikai's client

Forum for game modifications and custom clients.

Re: Plug-in system for Latikai's client

Postby Chrumps » Thu Apr 20, 2017 8:26 am

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);
        }
    }
}
Chrumps
 
Posts: 594
Joined: Wed Apr 09, 2014 9:51 pm
Location: Poland

Re: Plug-in system for Latikai's client

Postby Kandarim » Thu Apr 20, 2017 9:37 am

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.
I have neither the crayons nor the time to explain it to you.
JC wrote:I'm not fully committed to being wrong on that yet.
User avatar
Kandarim
Customer
 
Posts: 5321
Joined: Mon Jan 21, 2013 4:18 pm

Re: Plug-in system for Latikai's client

Postby Chrumps » Thu Apr 20, 2017 10:08 am

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)
Last edited by Chrumps on Thu Apr 20, 2017 10:25 am, edited 1 time in total.
Chrumps
 
Posts: 594
Joined: Wed Apr 09, 2014 9:51 pm
Location: Poland

Re: Plug-in system for Latikai's client

Postby Kandarim » Thu Apr 20, 2017 10:22 am

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.
I have neither the crayons nor the time to explain it to you.
JC wrote:I'm not fully committed to being wrong on that yet.
User avatar
Kandarim
Customer
 
Posts: 5321
Joined: Mon Jan 21, 2013 4:18 pm

Re: Plug-in system for Latikai's client

Postby Chrumps » Thu Apr 20, 2017 10:26 am

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.
Chrumps
 
Posts: 594
Joined: Wed Apr 09, 2014 9:51 pm
Location: Poland

Re: Plug-in system for Latikai's client

Postby Nsuidara » Thu Apr 20, 2017 11:03 am

and where plugin ?:P
\(*o*)\ Praying in the Marp Church may reduce the time for update /(*o*)/
User avatar
Nsuidara
Customer
 
Posts: 1995
Joined: Fri Aug 17, 2012 11:50 pm
Location: Poland

Re: Plug-in system for Latikai's client

Postby Kandarim » Thu Apr 20, 2017 11:10 am

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 :)
I have neither the crayons nor the time to explain it to you.
JC wrote:I'm not fully committed to being wrong on that yet.
User avatar
Kandarim
Customer
 
Posts: 5321
Joined: Mon Jan 21, 2013 4:18 pm

Re: Plug-in system for Latikai's client

Postby Chrumps » Thu Apr 20, 2017 1:05 pm

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 ;).
Attachments
FuelFillerPlugin.7z
(7.06 KiB) Downloaded 559 times
Chrumps
 
Posts: 594
Joined: Wed Apr 09, 2014 9:51 pm
Location: Poland

Re: Plug-in system for Latikai's client

Postby Kandarim » Thu Apr 20, 2017 1:22 pm

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);
I have neither the crayons nor the time to explain it to you.
JC wrote:I'm not fully committed to being wrong on that yet.
User avatar
Kandarim
Customer
 
Posts: 5321
Joined: Mon Jan 21, 2013 4:18 pm

Re: Plug-in system for Latikai's client

Postby Heffernan » Thu Apr 20, 2017 3:08 pm

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?
User avatar
Heffernan
 
Posts: 8564
Joined: Mon Sep 08, 2014 3:07 pm
Location: Marps Closet

PreviousNext

Return to Artifice & Arcana

Who is online

Users browsing this forum: No registered users and 5 guests

cron