2022-11-06 23:27:04 +01:00
import { BitNodeMultipliers } from "../BitNode/BitNodeMultipliers" ;
import { Crime } from "../Crime/Crime" ;
import { newWorkStats , scaleWorkStats , WorkStats , multWorkStats } from "./WorkStats" ;
2022-11-09 13:26:26 +01:00
import { Person as IPerson } from "../ScriptEditor/NetscriptDefinitions" ;
2022-11-06 23:27:04 +01:00
import { CONSTANTS } from "../Constants" ;
2022-11-20 14:37:11 +01:00
import { FactionWorkType , GymType } from "../utils/enums" ;
2022-11-06 23:27:04 +01:00
import {
getFactionFieldWorkRepGain ,
getFactionSecurityWorkRepGain ,
getHackingWorkRepGain ,
} from "../PersonObjects/formulas/reputation" ;
import { Locations } from "../Locations/Locations" ;
import { Location } from "../Locations/Location" ;
import { Player } from "@player" ;
import { Class , Classes , ClassType } from "./ClassWork" ;
import { Server } from "../Server/Server" ;
import { GetServer } from "../Server/AllServers" ;
import { serverMetadata } from "../Server/data/servers" ;
2022-11-20 18:07:22 +01:00
import { LocationName } from "../utils/enums" ;
2022-11-06 23:27:04 +01:00
import { Company } from "../Company/Company" ;
import { CompanyPosition } from "../Company/CompanyPosition" ;
2022-11-20 14:37:11 +01:00
import { checkEnum } from "../utils/helpers/enum" ;
2022-11-06 23:27:04 +01:00
const gameCPS = 1000 / CONSTANTS . _idleSpeed ; // 5 cycles per second
export const FactionWorkStats : Record < FactionWorkType , WorkStats > = {
2022-11-20 14:37:11 +01:00
[ FactionWorkType . hacking ] : newWorkStats ( { hackExp : 15 } ) ,
[ FactionWorkType . field ] : newWorkStats ( {
2022-11-06 23:27:04 +01:00
hackExp : 10 ,
strExp : 10 ,
defExp : 10 ,
dexExp : 10 ,
agiExp : 10 ,
chaExp : 10 ,
} ) ,
2022-11-20 14:37:11 +01:00
[ FactionWorkType . security ] : newWorkStats ( {
2022-11-06 23:27:04 +01:00
hackExp : 5 ,
strExp : 15 ,
defExp : 15 ,
dexExp : 15 ,
agiExp : 15 ,
} ) ,
} ;
2022-11-09 13:26:26 +01:00
export function calculateCrimeWorkStats ( person : IPerson , crime : Crime ) : WorkStats {
2022-11-06 23:27:04 +01:00
const gains = scaleWorkStats (
multWorkStats (
//Todo: rework crime and workstats interfaces to use the same naming convention for exp values, then we can just make a workStats directly from a crime.
newWorkStats ( {
money : crime.money ,
hackExp : crime.hacking_exp ,
strExp : crime.strength_exp ,
defExp : crime.defense_exp ,
dexExp : crime.dexterity_exp ,
agiExp : crime.agility_exp ,
chaExp : crime.charisma_exp ,
intExp : crime.intelligence_exp ,
} ) ,
person . mults ,
person . mults . crime_money * BitNodeMultipliers . CrimeMoney ,
) ,
BitNodeMultipliers . CrimeExpGain ,
false ,
) ;
return gains ;
}
2022-11-11 03:56:46 +01:00
/** @returns faction rep rate per cycle */
2022-11-09 13:26:26 +01:00
export const calculateFactionRep = ( person : IPerson , type : FactionWorkType , favor : number ) : number = > {
2022-11-06 23:27:04 +01:00
const repFormulas = {
2022-11-20 14:37:11 +01:00
[ FactionWorkType . hacking ] : getHackingWorkRepGain ,
[ FactionWorkType . field ] : getFactionFieldWorkRepGain ,
[ FactionWorkType . security ] : getFactionSecurityWorkRepGain ,
2022-11-06 23:27:04 +01:00
} ;
return repFormulas [ type ] ( person , favor ) ;
} ;
2022-11-11 03:56:46 +01:00
/** @returns per-cycle WorkStats */
2022-11-09 13:26:26 +01:00
export function calculateFactionExp ( person : IPerson , type : FactionWorkType ) : WorkStats {
2022-11-06 23:27:04 +01:00
return scaleWorkStats (
multWorkStats ( FactionWorkStats [ type ] , person . mults ) ,
BitNodeMultipliers . FactionWorkExpGain / gameCPS ,
) ;
}
/** Calculate cost for a class */
export function calculateCost ( classs : Class , location : Location ) : number {
const serverMeta = serverMetadata . find ( ( s ) = > s . specialName === location . name ) ;
const server = GetServer ( serverMeta ? serverMeta . hostname : "" ) ;
const discount = ( server as Server ) . backdoorInstalled ? 0.9 : 1 ;
return classs . earnings . money * location . costMult * discount ;
}
2022-11-11 03:56:46 +01:00
/** @returns per-cycle WorkStats */
2022-11-09 13:26:26 +01:00
export function calculateClassEarnings ( person : IPerson , type : ClassType , locationName : LocationName ) : WorkStats {
2022-11-06 23:27:04 +01:00
const hashManager = Player . hashManager ;
const classs = Classes [ type ] ;
const location = Locations [ locationName ] ;
2022-11-20 14:37:11 +01:00
const hashMult = checkEnum ( GymType , type ) ? hashManager . getTrainingMult ( ) : hashManager . getStudyMult ( ) ;
2022-11-06 23:27:04 +01:00
const earnings = multWorkStats (
scaleWorkStats ( classs . earnings , ( location . expMult / gameCPS ) * hashMult , false ) ,
person . mults ,
) ;
earnings . money = calculateCost ( classs , location ) / gameCPS ;
return earnings ;
}
2022-11-11 03:56:46 +01:00
/** @returns per-cycle WorkStats */
2022-11-06 23:27:04 +01:00
export const calculateCompanyWorkStats = (
2022-11-09 13:26:26 +01:00
worker : IPerson ,
2022-11-06 23:27:04 +01:00
company : Company ,
companyPosition : CompanyPosition ,
favor : number ,
) : WorkStats = > {
// If player has SF-11, calculate salary multiplier from favor
const favorMult = isNaN ( favor ) ? 1 : 1 + favor / 100 ;
const bn11Mult = Player . sourceFileLvl ( 11 ) > 0 ? favorMult : 1 ;
const gains = scaleWorkStats (
multWorkStats (
{
money : companyPosition.baseSalary * company . salaryMultiplier * bn11Mult * BitNodeMultipliers . CompanyWorkMoney ,
hackExp : companyPosition.hackingExpGain ,
strExp : companyPosition.strengthExpGain ,
defExp : companyPosition.defenseExpGain ,
dexExp : companyPosition.dexterityExpGain ,
agiExp : companyPosition.agilityExpGain ,
chaExp : companyPosition.charismaExpGain ,
} ,
worker . mults ,
worker . mults . work_money ,
) ,
company . expMultiplier * BitNodeMultipliers . CompanyWorkExpGain ,
false ,
) ;
const jobPerformance = companyPosition . calculateJobPerformance ( worker ) ;
gains . reputation = jobPerformance * worker . mults . company_rep * favorMult ;
return gains ;
} ;