Skip to content

Commit

Permalink
include scrap adjustment and improvement
Browse files Browse the repository at this point in the history
  • Loading branch information
idinium96 committed Jul 26, 2020
1 parent 06f43e5 commit cfb1a07
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 42 deletions.
59 changes: 35 additions & 24 deletions src/classes/Commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -418,7 +418,9 @@ export = class Commands {
}

private autoKeysCommand(steamID: SteamID): void {
if ((this.bot.handler as MyHandler).getAutokeysEnabled() === false) {
const autokeys = (this.bot.handler as MyHandler).getUserAutokeys();

if (autokeys.enabled === false) {
this.bot.sendMessage(steamID, `This feature is disabled.`);
return;
}
Expand All @@ -427,12 +429,7 @@ export = class Commands {
const currKey = pure.key;
const currRef = pure.refTotalInScrap;

const user = (this.bot.handler as MyHandler).getUserAutokeysSettings();

const autokeysStatus = (this.bot.handler as MyHandler).getAutokeysStatus();
const isBuyingKeys = (this.bot.handler as MyHandler).getAutokeysBuyingStatus();
const enableKeyBanking = (this.bot.handler as MyHandler).getAutokeysBankingEnabled();
const isBankingKeys = (this.bot.handler as MyHandler).getAutokeysBankingStatus();
const keyPrices = this.bot.pricelist.getKeyPrices();

const keyBlMin = ` X`;
const keyAbMax = ` X`;
Expand All @@ -448,40 +445,54 @@ export = class Commands {
const refsLine = `Refs ————|—————————|————▶`;
const xAxisRef = ` min max`;
const keysPosition =
currKey < user.minKeys
currKey < autokeys.minKeys
? keyBlMin
: currKey > user.maxKeys
: currKey > autokeys.maxKeys
? keyAbMax
: currKey > user.minKeys && currKey < user.maxKeys
: currKey > autokeys.minKeys && currKey < autokeys.maxKeys
? keyAtBet
: currKey === user.minKeys
: currKey === autokeys.minKeys
? keyAtMin
: currKey === user.maxKeys
: currKey === autokeys.maxKeys
? keyAtMax
: '';
const refsPosition =
currRef < user.minRef
currRef < autokeys.minRef
? refBlMin
: currRef > user.maxRef
: currRef > autokeys.maxRef
? refAbMax
: currRef > user.minRef && currRef < user.maxRef
: currRef > autokeys.minRef && currRef < autokeys.maxRef
? refAtBet
: currRef === user.minRef
: currRef === autokeys.minRef
? refAtMin
: currRef === user.maxRef
: currRef === autokeys.maxRef
? refAtMax
: '';
const summary = `\n• ${user.minKeys}${pluralize('key', currKey)}(${currKey}) ≤ ${
user.maxKeys
}\n• ${Currencies.toRefined(user.minRef)} < ${pluralize(
const summary = `\n• ${autokeys.minKeys}${pluralize('key', currKey)}(${currKey}) ≤ ${
autokeys.maxKeys
}\n• ${Currencies.toRefined(autokeys.minRef)} < ${pluralize(
'ref',
Currencies.toRefined(currRef)
)}(${Currencies.toRefined(currRef)}) < ${Currencies.toRefined(user.maxRef)}`;
)}(${Currencies.toRefined(currRef)}) < ${Currencies.toRefined(autokeys.maxRef)}`;

let reply = `Your current AutoKeys settings:\n${summary}\n\nDiagram:\n${keysPosition}\n${keysLine}\n${refsPosition}\n${refsLine}\n${xAxisRef}\n`;
reply += `\n Auto-banking: ${enableKeyBanking ? 'enabled' : 'disabled'}`;
reply += `\nAutokeys status: ${
autokeysStatus ? (isBankingKeys ? 'banking' : isBuyingKeys ? 'buying' : 'selling') : 'not active'
reply += `\n Key price: ${keyPrices.buy.metal + '/' + keyPrices.sell}`;
reply += `\nScrap Adjustment: ${autokeys.scrapAdjustmentEnabled ? 'Enabled ✅' : 'Disabled ❌'}`;
reply += `\n Auto-banking: ${autokeys.bankingEnabled ? 'Enabled ✅' : 'Disabled ❌'}`;
reply += `\n Autokeys status: ${
autokeys.status
? autokeys.isBanking
? 'Banking' + (autokeys.scrapAdjustmentEnabled ? ' (default price)' : '')
: autokeys.isBuying
? 'Buying for ' +
Currencies.toRefined(keyPrices.buy.toValue() + autokeys.scrapAdjustmentValue).toString() +
' ref' +
(autokeys.scrapAdjustmentEnabled ? ' (+' + autokeys.scrapAdjustmentValue + ' scrap)' : '')
: 'Selling for ' +
Currencies.toRefined(keyPrices.sell.toValue() - autokeys.scrapAdjustmentValue).toString() +
' ref' +
(autokeys.scrapAdjustmentEnabled ? ' (-' + autokeys.scrapAdjustmentValue + ' scrap)' : '')
: 'Not active'
}`;
/*
// X
Expand Down
39 changes: 21 additions & 18 deletions src/classes/MyHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -243,32 +243,35 @@ export = class MyHandler extends Handler {
return this.autokeysEnabled;
}

getUserAutokeysSettings(): { minKeys: number; maxKeys: number; minRef: number; maxRef: number } {
getUserAutokeys(): {
enabled: boolean;
status: boolean;
minKeys: number;
maxKeys: number;
minRef: number;
maxRef: number;
isBuying: boolean;
bankingEnabled: boolean;
isBanking: boolean;
scrapAdjustmentEnabled: boolean;
scrapAdjustmentValue: number;
} {
const settings = {
enabled: this.autokeysEnabled,
status: this.checkAutokeysStatus,
minKeys: this.userMinKeys,
maxKeys: this.userMaxKeys,
minRef: this.userMinReftoScrap,
maxRef: this.userMaxReftoScrap
maxRef: this.userMaxReftoScrap,
isBuying: this.isBuyingKeys,
bankingEnabled: this.keyBankingEnabled,
isBanking: this.isBankingKeys,
scrapAdjustmentEnabled: !this.isUsingAutoPrice,
scrapAdjustmentValue: this.scrapAdjustmentValue
};
return settings;
}

getAutokeysStatus(): boolean {
return this.checkAutokeysStatus;
}

getAutokeysBuyingStatus(): boolean {
return this.isBuyingKeys;
}

getAutokeysBankingEnabled(): boolean {
return this.keyBankingEnabled;
}

getAutokeysBankingStatus(): boolean {
return this.isBankingKeys;
}

onRun(): Promise<{
loginAttempts?: number[];
pricelist?: EntryData[];
Expand Down

0 comments on commit cfb1a07

Please sign in to comment.