Skip to content

Commit

Permalink
Sleeves and others stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
benbernard committed Oct 30, 2019
1 parent fd92cd1 commit be19754
Show file tree
Hide file tree
Showing 8 changed files with 165 additions and 18 deletions.
4 changes: 4 additions & 0 deletions netrun/bernard/bank-io.js
Expand Up @@ -35,6 +35,10 @@ class ThisScript extends BaseScript {
await this.printAllWallets();
} else if (action === "all" || action === "infos") {
await this.printAllWallets();
} else if (action === "balance") {
let response = await bank.balanceAccounts();
this.tlog(`Balance response: ${JSON.stringify(response)}`);
await this.printAllWallets();
} else if (action === "clear" || action === "infos") {
let response = await bank.clear();
this.tlog(`Clear response: ${JSON.stringify(response)}`);
Expand Down
14 changes: 13 additions & 1 deletion netrun/bernard/bank.js
Expand Up @@ -97,6 +97,8 @@ export class BankScript extends BaseScript {
} else if (type === BankMessaging.CLEAR) {
this.initializeState();
return this.messaging.sendResponse(req, {success: true});
} else if (type === BankMessaging.BALANCE_ACCOUNTS) {
this.balanceAccounts(req);
} else {
this.tlog(`Bank received unknown message type: ${type}`);
}
Expand Down Expand Up @@ -212,6 +214,16 @@ export class BankScript extends BaseScript {
return this.messaging.sendResponse(req, {success});
}

balanceAccounts(req) {
for (let wallet of this.wallets) {
wallet.amount = 0;
}
this.state.allocatedMoney = 0;
this.saveState();
this.update();
return this.messaging.sendResponse(req, {success: true});
}

deposit(req) {
let wallet = this.wallet(req.data.wallet);
let amount = req.data.amount;
Expand Down Expand Up @@ -349,7 +361,7 @@ export class BankScript extends BaseScript {
setup() {
this.disableLogging("sleep", "getServerMoneyAvailable", "getHackingLevel");

if (this.ns.fileExists(BANK_INFO_FILE, "home")) {
if (this.ns.fileExists(BANK_INFO_FILE)) {
let contents = this.ns.read(BANK_INFO_FILE);
this.state = JSON.parse(contents);
}
Expand Down
38 changes: 25 additions & 13 deletions netrun/bernard/clown-car.js
Expand Up @@ -42,9 +42,9 @@ class ThisScript extends TK.Script {
this.targetUpdateTime = 0;

this.chances = {
[Request.HACK]: 0.05,
[Request.GROW]: 0.475,
[Request.WEAKEN]: 0.475,
[Request.HACK]: 0.17,
[Request.GROW]: 0.38,
[Request.WEAKEN]: 0.45,
};
}

Expand Down Expand Up @@ -343,7 +343,10 @@ class ThisScript extends TK.Script {
}

async createPrepAttacks(now) {
for (let target of await this.serversToAttack()) {
let servers = await this.serversToAttack();
let anyReady = servers.some(s => this.readyToAttack(s));

for (let target of servers) {
if (this.threadManager.availableThreads() < 10) return;
if (this.preppingServers.has(target.name)) continue;
if (this.readyToAttack(target)) continue;
Expand All @@ -352,7 +355,8 @@ class ThisScript extends TK.Script {
(sum, a) => sum + a.threads,
0
);
let maxPrepThreads = this.threadManager.maxThreads() * 0.25;
let maxPrepThreads = Math.floor(this.threadManager.maxThreads() * 0.25);
if (!anyReady) maxPrepThreads = this.threadManager.maxThreads();
let maxCurrentPrepThreads = maxPrepThreads - prepThreads;

if (maxCurrentPrepThreads <= 10) return;
Expand Down Expand Up @@ -573,7 +577,7 @@ class PodAttack extends NSObject {
this.parent = parent;

if (this.parent) {
this.startTime = this.parent.startTime + 2000;
this.startTime = this.parent.startTime + 5000;
} else {
this.startTime = startTime;
}
Expand Down Expand Up @@ -651,10 +655,18 @@ class PodAttack extends NSObject {
}

if (attackThreads + weakenThreads > this.availableThreads()) {
throw new Error(
`Computed too many attack/weaken threads: ${attackThreads +
weakenThreads} have: ${this.threadManager.availableThreads()}`
);
if (attackThreads + weakenThreads - this.availableThreads() <= 1) {
if (attackThreads > 1) {
attackThreads -= 1;
} else {
weakenThreads -= 1;
}
} else {
throw new Error(
`Computed too many attack/weaken threads: ${attackThreads +
weakenThreads} have: ${this.availableThreads()}`
);
}
}

return {
Expand Down Expand Up @@ -837,7 +849,7 @@ class PodAttack extends NSObject {
}

startWeakenGrowTime() {
return this.startTime + 1000;
return this.startTime + 4000;
}

startWeakenHackTime() {
Expand All @@ -853,15 +865,15 @@ class PodAttack extends NSObject {
}

startHackTime() {
return this.endWeakenHackTime() - this.hackTime - 500;
return this.endWeakenHackTime() - this.hackTime - 2000;
}

endHackTime() {
return this.startHackTime() + this.hackTime;
}

startGrowTime() {
return this.endWeakenGrowTime() - this.growTime - 500;
return this.endWeakenGrowTime() - this.growTime - 2000;
}

endGrowTime() {
Expand Down
9 changes: 7 additions & 2 deletions netrun/bernard/gangs.js
Expand Up @@ -17,7 +17,9 @@ export const TASKS = {
ARMS: "Traffick Illegal Arms",
};

const ASCENDED_STRENGTH_MULT = 100;
const ASCENDED_STRENGTH_MULT = 48;
const ASCENDED_STR = 4000;
// const ASCENDED_STRENGTH_MULT = 20;

export class Gang extends GangNSObject {
constructor(ns, es) {
Expand Down Expand Up @@ -111,7 +113,10 @@ export class Member extends GangNSObject {
}

fullyAscended() {
return this.info.strengthAscensionMult >= ASCENDED_STRENGTH_MULT;
return (
this.info.strengthAscensionMult >= ASCENDED_STRENGTH_MULT ||
this.info.strength >= ASCENDED_STR
);
}

ascensionsNeeded() {
Expand Down
4 changes: 2 additions & 2 deletions netrun/bernard/manage-gang.js
Expand Up @@ -2,7 +2,7 @@ import * as TK from "./tk.js";
import {EquipmentSet, Gang, TASKS} from "./gangs.js";
import {BankMessaging} from "./messaging.js";

let EXCLUDED_NAMES = ["Madeline"];
let EXCLUDED_NAMES = ["Member-nph4w2vrs4afberagod6t"];

class ThisScript extends TK.Script {
async perform() {
Expand All @@ -16,7 +16,7 @@ class ThisScript extends TK.Script {
await this.recruitNewMembers();
await this.buyEquipment();
await this.ascendMembers();
await this.setTasks();
// await this.setTasks();

await this.sleep(5000);
}
Expand Down
5 changes: 5 additions & 0 deletions netrun/bernard/messaging.js
Expand Up @@ -143,6 +143,10 @@ export class BankMessaging extends Messaging {
return this.sendAndWait({type: BankMessaging.CLEAR});
}

balanceAccounts() {
return this.sendAndWait({type: BankMessaging.BALANCE_ACCOUNTS});
}

withdraw(wallet, amount) {
return this.sendAndWait({
type: BankMessaging.WITHDRAW,
Expand All @@ -163,3 +167,4 @@ BankMessaging.CLEAR = "clear";
BankMessaging.STOCK_BUY = "stock_buy";
BankMessaging.SELL_STOCKS = "sell_stocks";
BankMessaging.WITHDRAW = "withdraw";
BankMessaging.BALANCE_ACCOUNTS = "balance_accounts";
52 changes: 52 additions & 0 deletions netrun/bernard/sleeve-io.js
@@ -0,0 +1,52 @@
import * as TK from "./tk.js";
import {Sleeve} from "./sleeves.js";
import {_, json} from "./utils.js";
import {canonicalStat} from "./gameConstants.js";

class ThisScript extends TK.Script {
async perform() {
let sleeves = Sleeve.getSleeves(this.ns);
this.sleeves = sleeves;
let mode = this.pullFirstArg() || "train";

if (mode === "train") {
let target = this.pullFirstArg() || 50;
let stats = ["str", "def", "dex", "agi"].map(canonicalStat);
await this.train(stats, target);
} else if (mode === "murder") {
this.crime("Homicide");
} else if (mode === "hack") {
this.hack();
}
}

hack() {
for (let sleeve of this.sleeves) {
sleeve.train("hacking");
}
}

crime(crime) {
for (let sleeve of this.sleeves) {
sleeve.commitCrime(crime);
}
}

async train(stats, target = 20) {
for (let stat of stats) {
for (let sleeve of this.sleeves) {
sleeve.train(stat);
}

while (true) {
if (this.sleeves.every(s => s.hasStatAt(stat, target))) {
break;
}

await this.sleep(5000);
}
}
}
}

export let main = ThisScript.runner();
57 changes: 57 additions & 0 deletions netrun/bernard/sleeves.js
@@ -0,0 +1,57 @@
import {NSObject} from "./baseScript.js";
import {_, json} from "./utils.js";
import {canonicalStat} from "./gameConstants.js";

const GYM_NAME = "Powerhouse Gym";

export class Sleeve extends NSObject {
constructor(ns, num) {
super(ns);
this.num = num;
}

get s() {
return this.ns.sleeve;
}

sync() {
return this.s.synchronize(this.num);
}

shock() {
return this.s.setToShockRecovery(this.num);
}

buyableAugs() {
return this.s.getSleevePurchasableAugs(this.num);
}

static getSleeves(ns) {
let sleeves = [];
for (let i = 0; i < ns.sleeve.getNumSleeves(); i++) {
sleeves.push(new Sleeve(ns, i));
}
return sleeves;
}

train(inputStat) {
let stat = canonicalStat(inputStat);
if (stat === "hacking") {
this.s.setToUniversityCourse(
this.num,
"Rothman University",
"Algorithms"
);
} else {
this.s.setToGymWorkout(this.num, GYM_NAME, stat);
}
}

hasStatAt(stat, target) {
return this.s.getSleeveStats(this.num)[stat] >= target;
}

commitCrime(crime) {
return this.s.setToCommitCrime(this.num, crime);
}
}

0 comments on commit be19754

Please sign in to comment.