Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add artifact distribution and use action handlers #8

Open
Arachnid opened this issue Aug 17, 2021 · 3 comments
Open

Add artifact distribution and use action handlers #8

Arachnid opened this issue Aug 17, 2021 · 3 comments
Labels
enhancement New feature or request

Comments

@Arachnid
Copy link
Owner

No description provided.

@Arachnid Arachnid added the enhancement New feature or request label Aug 17, 2021
@solsticesolutions
Copy link

solsticesolutions commented Aug 19, 2021

Are you familiar with this artifact withdrawal script?

Sends and even captures rips for artifact withdrawals. In the event it can't find a rip, it sends artifacts to a nearby larger planet.

Sorry I can't attribute the script to anyone in particular it was posted in df discord a month ago:

// for Dark Forest v0.6 Round 2
// added better code for acquiring new RIP
// Auto transport artifacts to space time rip and withdraw them.  Deactive if need be.
// If no suitable RIP, try acquire an unowned one.
// Still no RIP, transport to a higher level planet nearby (presumably having better range).

// Good for peace time havesting artifacts to your wallet.
// Known issues: 
  // there is bug with df.getArtifactWithId, sometimes it will return undefined even with a valid artifactId
  // does not budget for energy when transporting multiple arts on the same planet (could cause fail due to not enough energy to transport)
  //does not check for max 6 ARTs allowed on a given planet

////////////////////////////////
// How to use:
// autoProcessArtifacts()  : review actions but dont do

//console.log(df, ui);

//class Plugin {

autoProcessArtifacts(false,2550,2)

function autoProcessArtifacts(reviewonly=true,targetnumber=5, minPlanetLevel=2) {
  let planets =
    df.getMyPlanets()
      .filter((p) => df.getLocationOfPlanet(p.locationId))
      .filter((p) => p.heldArtifactIds)
      .filter((p) => p.heldArtifactIds.length > 0)
      .filter((p) => p.planetLevel >= minPlanetLevel)
      .sort((b,a) => a.planetLevel - b.planetLevel)
      .slice(0, targetnumber)

  planets.forEach((p) => {
    let arts = p.heldArtifactIds;
    console.log(`working on L${p.planetLevel} planet [${arts.length}]ARTs. ${p.locationId}`);

    for (let i = 0; i < arts.length; ++i) {
      if (!df.getArtifactWithId(arts[i])) {
        console.log(" --artifact not found:", arts[i]);
        break;
      }

    if (isArtifactActivated(df.getArtifactWithId(arts[i]))) {  //TODO: check for time
        console.log(` --artifact is activated; deactivating now ${arts[i]}`);
        if (!reviewonly) df.deactivateArtifact(p.locationId, arts[i]);
        break;
      }

    if ((p.planetType == 3) && (p.planetLevel >(df.getArtifactWithId(arts[i]).rarity))  // art at RIP
      ){
        console.log(" -- withdrawing", p.locationId, arts[i], df.getArtifactWithId(arts[i]).rarity);
        if (!reviewonly) df.withdrawArtifact(p.locationId, arts[i]);
        break;
      }
      //do transport
      if (!reviewonly) transportART2(p.locationId, arts[i], 90);
    }
  })
}

function transportART2(srcId, artId, maxRangePct = 50, tgtId = "", targetList) {
  const myART = df.getArtifactWithId(artId);
  if (!myART) { console.log(" --invalid ART"); return }

  const source = df.getPlanetWithId(srcId);

  if (source.owner != df.account) { console.log(" --Dont Own planet"); return }

  //#1, try send to a RIP
  if (tgtId === "") {
    let targetList = df.getMyPlanets()
      .filter((p) => df.getLocationOfPlanet(p.locationId))
      .filter((p) => p.planetType == 3)  //only to RIP
      .filter((p) => p.planetLevel > myART.rarity)
      .filter((p) => (df.getDist(srcId, p.locationId) < df.getMaxMoveDist(srcId, maxRangePct)))
      .filter((p) => p.locationId !== srcId)
      .sort((a, b) => { return df.getDist(srcId, a.locationId) - df.getDist(srcId, b.locationId) })

    if (targetList.length > 0) {
      tgtId = targetList[0].locationId;
      console.log(`  --Found L${targetList[0].planetLevel} RIP ${tgtId}`);
    }
  } else {
    let targetList = [];
  }

    //#2, try acquire a RIP
  if (tgtId === "") {
      let targetList = Array.from(df.getAllPlanets())
        .filter((p) => df.getLocationOfPlanet(p.locationId))
        .filter((p) => p.owner == "0x0000000000000000000000000000000000000000")  
        .filter((p) => p.planetType == 3)  //only to RIP
        .filter((p) => p.planetLevel > myART.rarity)
        .filter((p) => (0.9*source.energy) > //0.9 hard coded for peach time transporting
          (df.getEnergyNeededForMove(srcId, p.locationId, (p.energy*(p.defense/100)+ 0.01*p.energy)))) 
        .sort((a, b) => { return df.getDist(srcId, a.locationId) - df.getDist(srcId, b.locationId) })
  
      if (targetList.length > 0) {
        tgtId = targetList[0].locationId;
          console.log(`  --Found an unowned L${targetList[0].planetLevel} RIP ${tgtId}`);
        }
    } else {
      let targetList = [];
  }
  
  //#3 if no RIP, send to a higher level planet nearby
  if (tgtId === "") {
    console.log(` --No space RIP nearby... `);

    targetList = df.getMyPlanets()
      .filter((p) => df.getLocationOfPlanet(p.locationId))
      .filter((p) => p.planetLevel > source.planetLevel)  
      .filter((p) => (df.getDist(srcId, p.locationId) < df.getMaxMoveDist(srcId, maxRangePct)))
      .filter((p) => p.locationId !== srcId)
      .sort((a, b) => { return df.getDist(srcId, a.locationId) - df.getDist(srcId, a.locationId) })
    if (targetList.length > 0) {
      tgtId = targetList[0].locationId;
    }
  }

  if (tgtId !== "") {
    const target = df.getPlanetWithId(tgtId);
    let FORCES = Math.ceil(df.getEnergyNeededForMove(srcId, tgtId,10));

    if(target.owner=="0x0000000000000000000000000000000000000000") {  //override if attacking
      FORCES = Math.ceil(df.getEnergyNeededForMove(srcId, tgtId, ((target.energy*(target.defense/100))+ 0.15*target.energy)));
      if(FORCES < source.energy * 0.98)
        FORCES = Math.ceil(df.getEnergyNeededForMove(srcId, tgtId, ((target.energy*(target.defense/100))+ 0.10*target.energy)));
      if(FORCES < source.energy * 0.98)
        FORCES = Math.ceil(df.getEnergyNeededForMove(srcId, tgtId, ((target.energy*(target.defense/100))+ 0.05*target.energy)));
      if(FORCES < source.energy * 0.98)
        FORCES = Math.ceil(df.getEnergyNeededForMove(srcId, tgtId, ((target.energy*(target.defense/100))+ 0.01*target.energy)));
    }

    let silverTOSEND = 0;

    if (FORCES < source.energy * 0.98) {
      df.terminal.current.println(`  --Sending ART to L${target.planetLevel} ${tgtId}`);
      console.log(`  --Sending ART to L${target.planetLevel} ${tgtId}`);
      df.move(srcId, tgtId, FORCES, silverTOSEND, artId);
    }
  } else {
    df.terminal.current.println("nothing to do");
    console.log(`  --nothing to do: ui.centerLocationId(${srcId})`);

    return "nothing to do";
  }
  return "ART";
}

function isArtifactActivated(artifact) {
  if (artifact === undefined) {
    return false;
  }
  return artifact.lastActivated > artifact.lastDeactivated;
}

//destroy() {}
//}
//export default Plugin;


@Arachnid
Copy link
Owner Author

Definitely a worthwhile strategy if nothing else presents itself! It'd be nice if it understood how to assign and use artefacts in the game, though. A few ideas that occur:

  • Activating the most powerful Photon Cannon on the most powerful Quasar.
  • Assigning normal artefacts in order of rarity to planets in order of score.
  • Using bloom filters to fill quasars.

@solsticesolutions
Copy link

solsticesolutions commented Aug 19, 2021 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants