OhhLoz / Harvester

A QoL FoundryVTT module to improve the harvesting and looting experience.
GNU General Public License v3.0
2 stars 2 forks source link

Request: Integration with Item Piles #23

Closed adunis closed 5 months ago

adunis commented 10 months ago

It would be cool if after using Harvest or Loot on a target it would make the enemy a container if you have Item Piles installed.

This is a similiar macro that does the same and also generates some money on the target (currently I added the macro to the ' Loot' feature)


  let hasItemPiles = 1;  

 let imgPath = "D:\Program Files\Foundry Virtual Tabletop\resources\app\public\icons\commodities\currency\coins-stitched-pouch-brown.webp";  

 for(let c of game.user.targets){

   const theTarget = args[0].targets[0];
       if (!theTarget) return false;

       // does not work on undead/constructs
       let invalid = ["beast", "construct", "monstrosity", "abberation"].some(type => (theTarget?.actor.system.details.type?.value || "").toLowerCase().includes(type));
       if (invalid) {
           ui.notifications.warn("You can't loot beasts, constructs, monstrosities, abberation ")
           return false;
       }

   if (c.actor.data.data.details.level > 0) {
     console.log("XXXXX__//  ",c.data.name,"is a PC   \\\\__XXXXX");
     continue;
   } else {
     let tokActor = c.actor;

    const rand = new Roll("1d100").evaluate({async: false});

     console.log("_________________________________________________________")
     console.log("!!!",tokActor.data.name," Random Roll: ",rand.total);

     ///////// Coins /////////
    async function rollCoins(PP, GP, SP, CP) {    
         let currency = tokActor.data.data.currency;

         let rollCP = await new Roll(CP).roll({async:true});
         let rollSP = await new Roll(SP).roll({async:true});
         let rollGP = await new Roll(GP).roll({async:true});
         let rollPP = await new Roll(PP).roll({async:true});

         let actorCP = currency.cp + rollCP.total;
         let actorSP = currency.sp + rollSP.total;
         let actorGP = currency.gp + rollGP.total;
         let actorPP = currency.pp + rollPP.total;

        await tokActor.update({"data.currency.cp": currency.cp + rollCP.total, "data.currency.sp": currency.sp + rollSP.total, "data.currency.gp": currency.gp + rollGP.total, "data.currency.pp": currency.pp + rollPP.total});

         await console.log('>>>',tokActor.data.name,'Coins Added>>   CP:',rollCP.total,' // SP:',rollSP.total,' // GP:',rollGP.total,' // PP:',rollPP.total,' // ',);
     }

     if(rand.total<26){
         console.log(">>> No coins found")                 //Nothing

    } else if (rand.total>26 && rand.total<56){
         await rollCoins("0","0","0","1d10");              //6CP avg
     } else if (rand.total>55 && rand.total<80){
         await rollCoins("0","0","4d3","1d14+11");         //1GP avg
     } else if (rand.total>79 && rand.total<90){
         await rollCoins("0","2d3","2d10+10","1d21+39");   //5GP avg
     } else if (rand.total>89 && rand.total<95){
         await rollCoins("0","1d6+4","7d5","1d21+59");     //10GP avg
     } else if (rand.total>94 && rand.total<98){
        await rollCoins("0","1d10+5","15d6","50d3");      //20GP avg
     } else if (rand.total>97 && rand.total<100){
         await rollCoins("1d3","10d3+3","15d6","40d4");    //50GP avg
     } else {
         await rollCoins("3d3","24d2","10d6","25d6");      //100GP avg
     }

     if (c.actor.data.data.details.level > 0) {
        break;
     } else {   
         if (hasItemPiles === 1){
             ItemPiles.API.turnTokensIntoItemPiles(c);
         }
     }
   }
 }
OhhLoz commented 10 months ago

I did originally want to add compatibility with Item Piles but it sort of fell by the wayside. I'd love to add compatibility as its such a great module. I'll see what I can do. Thanks for the suggestion & code sample!

Oh-My-God-What commented 9 months ago

I second this. Its a great module but with big battles it seems to being the pace of the game down when we got to find all the bodies and loot them. then make sure its getting split evenly. The harvest isnt much of an issue but looting has started too.

I would love if there's a way to make it to so when you use the Loot feature, it takes the coins and adds them to the inventory of an Item Pile actor. That way we can have it go to an Item Pile chest, everyone can loot whoever they find, and once done we can go to the chest and just split the gold. Makes it easy for everyone if that is possible!

ctbritt commented 7 months ago

I've got a pull request in that integrates item piles but only in a specific play style.

OhhLoz commented 5 months ago

Should be fixed in 1.8.0 release