2021-10-07 07:36:59 +02:00
|
|
|
import { Fragment } from "./Fragment";
|
2021-09-25 23:21:50 +02:00
|
|
|
import { ActiveFragment } from "./ActiveFragment";
|
|
|
|
import { FragmentType } from "./FragmentType";
|
|
|
|
import { IStaneksGift } from "./IStaneksGift";
|
|
|
|
import { IPlayer } from "../PersonObjects/IPlayer";
|
|
|
|
import { Factions } from "../Faction/Factions";
|
|
|
|
import { CalculateEffect } from "./formulas/effect";
|
|
|
|
import { CalculateCharge } from "./formulas/charge";
|
2021-10-08 09:16:51 +02:00
|
|
|
import { StaneksGiftEvents } from "./StaneksGiftEvents";
|
2021-09-25 23:21:50 +02:00
|
|
|
import { Generic_fromJSON, Generic_toJSON, Reviver } from "../utils/JSONReviver";
|
2021-10-08 09:16:51 +02:00
|
|
|
import { CONSTANTS } from "../Constants";
|
|
|
|
import { StanekConstants } from "./data/Constants";
|
|
|
|
import { BitNodeMultipliers } from "../BitNode/BitNodeMultipliers";
|
|
|
|
import { Player } from "../Player";
|
2021-09-25 23:21:50 +02:00
|
|
|
|
|
|
|
export class StaneksGift implements IStaneksGift {
|
2021-10-08 09:16:51 +02:00
|
|
|
storedCycles = 0;
|
2021-09-25 23:21:50 +02:00
|
|
|
fragments: ActiveFragment[] = [];
|
|
|
|
|
2021-10-08 09:16:51 +02:00
|
|
|
baseSize(): number {
|
|
|
|
return StanekConstants.BaseSize + BitNodeMultipliers.StaneksGiftExtraSize + Player.sourceFileLvl(13);
|
|
|
|
}
|
|
|
|
|
2021-09-25 23:21:50 +02:00
|
|
|
width(): number {
|
2021-10-08 09:16:51 +02:00
|
|
|
return Math.floor(this.baseSize() / 2 + 1);
|
2021-09-25 23:21:50 +02:00
|
|
|
}
|
|
|
|
height(): number {
|
2021-10-08 09:16:51 +02:00
|
|
|
return Math.floor(this.baseSize() / 2 + 0.6);
|
2021-09-25 23:21:50 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
charge(worldX: number, worldY: number, ram: number): number {
|
|
|
|
const af = this.fragmentAt(worldX, worldY);
|
|
|
|
if (af === null) return 0;
|
|
|
|
|
2021-10-07 07:36:59 +02:00
|
|
|
const charge = CalculateCharge(ram);
|
|
|
|
af.charge += charge;
|
|
|
|
|
|
|
|
Factions["Church of the Machine God"].playerReputation += Math.log(ram) / Math.log(2);
|
|
|
|
|
|
|
|
return ram;
|
|
|
|
}
|
2021-09-25 23:21:50 +02:00
|
|
|
|
2021-10-08 09:16:51 +02:00
|
|
|
inBonus(): boolean {
|
|
|
|
return (this.storedCycles * CONSTANTS._idleSpeed) / 1000 > 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
process(p: IPlayer, numCycles = 1): void {
|
|
|
|
this.storedCycles += numCycles;
|
|
|
|
this.storedCycles -= 5;
|
|
|
|
this.storedCycles = Math.max(0, this.storedCycles);
|
2021-10-07 07:36:59 +02:00
|
|
|
this.updateMults(p);
|
2021-10-08 09:16:51 +02:00
|
|
|
StaneksGiftEvents.emit();
|
2021-10-07 07:36:59 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
effect(fragment: ActiveFragment): number {
|
|
|
|
// Find all the neighbooring cells
|
|
|
|
const cells = fragment.neighboors();
|
2021-09-25 23:21:50 +02:00
|
|
|
// find the neighbooring active fragments.
|
|
|
|
const maybeFragments = cells.map((n) => this.fragmentAt(n[0], n[1]));
|
|
|
|
|
|
|
|
// Filter out nulls with typescript "Type guard". Whatever
|
|
|
|
let neighboors = maybeFragments.filter((v: ActiveFragment | null): v is ActiveFragment => !!v);
|
|
|
|
|
2021-10-07 07:36:59 +02:00
|
|
|
neighboors = neighboors.filter((fragment) => fragment.fragment().type === FragmentType.Booster);
|
2021-09-25 23:21:50 +02:00
|
|
|
let boost = 1;
|
|
|
|
for (const neighboor of neighboors) {
|
2021-10-07 07:36:59 +02:00
|
|
|
boost *= neighboor.fragment().power;
|
2021-09-25 23:21:50 +02:00
|
|
|
}
|
|
|
|
|
2021-10-07 07:36:59 +02:00
|
|
|
return CalculateEffect(fragment.charge, fragment.fragment().power, boost);
|
2021-09-25 23:21:50 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
canPlace(x: number, y: number, fragment: Fragment): boolean {
|
|
|
|
if (x + fragment.width() > this.width()) return false;
|
|
|
|
if (y + fragment.height() > this.height()) return false;
|
|
|
|
if (this.count(fragment) >= fragment.limit) return false;
|
|
|
|
const newFrag = new ActiveFragment({ x: x, y: y, fragment: fragment });
|
|
|
|
for (const aFrag of this.fragments) {
|
|
|
|
if (aFrag.collide(newFrag)) return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
place(x: number, y: number, fragment: Fragment): boolean {
|
|
|
|
if (!this.canPlace(x, y, fragment)) return false;
|
|
|
|
this.fragments.push(new ActiveFragment({ x: x, y: y, fragment: fragment }));
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
fragmentAt(worldX: number, worldY: number): ActiveFragment | null {
|
|
|
|
for (const aFrag of this.fragments) {
|
|
|
|
if (aFrag.fullAt(worldX, worldY)) {
|
|
|
|
return aFrag;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
count(fragment: Fragment): number {
|
|
|
|
let amt = 0;
|
|
|
|
for (const aFrag of this.fragments) {
|
|
|
|
if (aFrag.fragment().id === fragment.id) amt++;
|
|
|
|
}
|
|
|
|
return amt;
|
|
|
|
}
|
|
|
|
|
|
|
|
deleteAt(worldX: number, worldY: number): boolean {
|
|
|
|
for (let i = 0; i < this.fragments.length; i++) {
|
|
|
|
if (this.fragments[i].fullAt(worldX, worldY)) {
|
|
|
|
this.fragments.splice(i, 1);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
clear(): void {
|
|
|
|
this.fragments = [];
|
|
|
|
}
|
|
|
|
|
|
|
|
updateMults(p: IPlayer): void {
|
|
|
|
p.reapplyAllAugmentations(true);
|
|
|
|
p.reapplyAllSourceFiles();
|
|
|
|
|
|
|
|
for (const aFrag of this.fragments) {
|
|
|
|
const fragment = aFrag.fragment();
|
2021-10-07 07:36:59 +02:00
|
|
|
|
|
|
|
const power = this.effect(aFrag);
|
2021-09-25 23:21:50 +02:00
|
|
|
switch (fragment.type) {
|
|
|
|
case FragmentType.HackingChance:
|
|
|
|
p.hacking_chance_mult *= power;
|
|
|
|
break;
|
|
|
|
case FragmentType.HackingSpeed:
|
|
|
|
p.hacking_speed_mult *= power;
|
|
|
|
break;
|
|
|
|
case FragmentType.HackingMoney:
|
|
|
|
p.hacking_money_mult *= power;
|
|
|
|
break;
|
|
|
|
case FragmentType.HackingGrow:
|
|
|
|
p.hacking_grow_mult *= power;
|
|
|
|
break;
|
|
|
|
case FragmentType.Hacking:
|
|
|
|
p.hacking_mult *= power;
|
|
|
|
p.hacking_exp_mult *= power;
|
|
|
|
break;
|
|
|
|
case FragmentType.Strength:
|
|
|
|
p.strength_mult *= power;
|
|
|
|
p.strength_exp_mult *= power;
|
|
|
|
break;
|
|
|
|
case FragmentType.Defense:
|
|
|
|
p.defense_mult *= power;
|
|
|
|
p.defense_exp_mult *= power;
|
|
|
|
break;
|
|
|
|
case FragmentType.Dexterity:
|
|
|
|
p.dexterity_mult *= power;
|
|
|
|
p.dexterity_exp_mult *= power;
|
|
|
|
break;
|
|
|
|
case FragmentType.Agility:
|
|
|
|
p.agility_mult *= power;
|
|
|
|
p.agility_exp_mult *= power;
|
|
|
|
break;
|
|
|
|
case FragmentType.Charisma:
|
|
|
|
p.charisma_mult *= power;
|
|
|
|
p.charisma_exp_mult *= power;
|
|
|
|
break;
|
|
|
|
case FragmentType.HacknetMoney:
|
|
|
|
p.hacknet_node_money_mult *= power;
|
|
|
|
break;
|
|
|
|
case FragmentType.HacknetCost:
|
|
|
|
p.hacknet_node_purchase_cost_mult *= power;
|
|
|
|
p.hacknet_node_ram_cost_mult *= power;
|
|
|
|
p.hacknet_node_core_cost_mult *= power;
|
|
|
|
p.hacknet_node_level_cost_mult *= power;
|
|
|
|
break;
|
|
|
|
case FragmentType.Rep:
|
|
|
|
p.company_rep_mult *= power;
|
|
|
|
p.faction_rep_mult *= power;
|
|
|
|
break;
|
|
|
|
case FragmentType.WorkMoney:
|
|
|
|
p.work_money_mult *= power;
|
|
|
|
break;
|
|
|
|
case FragmentType.Crime:
|
|
|
|
p.crime_success_mult *= power;
|
|
|
|
p.crime_money_mult *= power;
|
|
|
|
break;
|
|
|
|
case FragmentType.Bladeburner:
|
|
|
|
p.bladeburner_max_stamina_mult *= power;
|
|
|
|
p.bladeburner_stamina_gain_mult *= power;
|
|
|
|
p.bladeburner_analysis_mult *= power;
|
|
|
|
p.bladeburner_success_chance_mult *= power;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2021-10-13 07:24:30 +02:00
|
|
|
p.updateSkillLevels();
|
2021-09-25 23:21:50 +02:00
|
|
|
}
|
|
|
|
|
2021-10-08 09:16:51 +02:00
|
|
|
prestigeAugmentation(): void {
|
|
|
|
this.clear();
|
|
|
|
}
|
|
|
|
|
|
|
|
prestigeSourceFile(): void {
|
|
|
|
this.clear();
|
|
|
|
}
|
|
|
|
|
2021-09-25 23:21:50 +02:00
|
|
|
/**
|
|
|
|
* Serialize Staneks Gift to a JSON save state.
|
|
|
|
*/
|
|
|
|
toJSON(): any {
|
|
|
|
return Generic_toJSON("StaneksGift", this);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Initializes Staneks Gift from a JSON save state
|
|
|
|
*/
|
|
|
|
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
|
|
|
|
static fromJSON(value: any): StaneksGift {
|
|
|
|
return Generic_fromJSON(StaneksGift, value.data);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Reviver.constructors.StaneksGift = StaneksGift;
|