Skip to content

Commit

Permalink
add prepareForGemShrine to type
Browse files Browse the repository at this point in the history
fix linting warnings
  • Loading branch information
icommitdesnet committed Jan 5, 2025
1 parent 2f4be13 commit 088c50e
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 23 deletions.
49 changes: 26 additions & 23 deletions d2bs/kolbot/libs/core/Town.js
Original file line number Diff line number Diff line change
Expand Up @@ -2174,24 +2174,28 @@ const Town = {
function pickitWantsUpgrade(unit) {
// Stub Object to let Pickit Check
function GemUnit(gem) {
this.itemType = gem["itemType"];
this.classid = gem["classid"];
this.type = gem["type"];
this.mode = gem["mode"];
this.gid = gem["gid"];
this.itemType = gem.itemType;
this.classid = gem.classid;
this.type = gem.type;
this.mode = gem.mode;
this.gid = gem.gid;
}
// eslint-disable-next-line no-unused-vars
GemUnit.prototype.getFlag = function (flag) {
return true;
}
};

let gem = new GemUnit(unit);
// lets upgrade the gem
gem.classid += 1;
return [Pickit.Result.WANTED, Pickit.Result.CUBING, Pickit.Result.RUNEWORD, Pickit.Result.CRAFTING].includes(Pickit.checkItem(gem).result)
return [
Pickit.Result.WANTED, Pickit.Result.CUBING,
Pickit.Result.RUNEWORD, Pickit.Result.CRAFTING
].includes(Pickit.checkItem(gem).result);
}

// do i have any gem worth upgrading
const haveUpGems = me.getItemsEx()
const haveUpGems = me.getItemsEx()
.filter(function (p) {
return isUpgradePossible(p) && pickitWantsUpgrade(p);
})
Expand All @@ -2202,50 +2206,49 @@ const Town = {
return false;
}
// we have gems that must not be upgraded in inventory
const isInventoryClean = me.getItemsEx()
const isInventoryClean = me.getItemsEx()
.filter(function (p) {
return p.isInInventory && isUpgradePossible(p) && !pickitWantsUpgrade(p);
})
.length === 0;

// we have gems that can be upgraded in inventory
const isInventoryValid = me.getItemsEx()
// we have gems that can be upgraded in inventory
const isInventoryValid = me.getItemsEx()
.filter(function (p) {
return p.isInInventory && isUpgradePossible(p) && pickitWantsUpgrade(p);
})
.length > 0;

// we already got good gems in inv and no bad games -> take shrine
if (isInventoryClean && isInventoryValid)
{
// we already got good gems in inv and no bad games -> take shrine
if (isInventoryClean && isInventoryValid) {
console.debug("Inventory looks good. lets take the shrine.");
return true;
}
// go to town
const preArea = me.area;
const preAct = me.act;
if (!me.inTown) {
// not an essential function -> handle thrown errors
try {
Town.goToTown();
} catch (e) {
return false;
}
// not an essential function -> handle thrown errors
try {
Town.goToTown();
} catch (e) {
return false;
}
}

// stash the bad gems first
!isInventoryClean && Town.stash();

// get any good gem. flawless first (by lvlreq)
let goodGems = me.getItemsEx()
let goodGems = me.getItemsEx()
.filter(function (p) {
return isUpgradePossible(p) && pickitWantsUpgrade(p);
return isUpgradePossible(p) && pickitWantsUpgrade(p);
})
.sort (function(a, b) {
return b.lvlreq - a.lvlreq;
});
if (goodGems.length) {
console.debug("get Gem: "+goodGems[0].fname);
console.debug("get Gem: " + goodGems[0].fname);
Town.openStash();
Storage.Inventory.MoveTo(goodGems.first()) && Item.logger("Inventoried", goodGems[0]);
}
Expand Down
1 change: 1 addition & 0 deletions d2bs/kolbot/sdk/types/Town.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ declare global {
function moveToSpot(spot?: string, allowTK?: boolean): boolean;
function goToTown(act?: 2 | 1 | 4 | 3 | 5, wpmenu?: boolean): boolean;
function visitTown(repair?: boolean): boolean;
function prepareForGemShrine(): boolean;
}
}
export {};

0 comments on commit 088c50e

Please sign in to comment.