-
Notifications
You must be signed in to change notification settings - Fork 297
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
API: Added external api which returns gainExperience #1955
Changes from 9 commits
ca5c33d
f51b075
82a8fde
db08b60
db8e5df
5fba661
37dfd62
5ba867c
9daaf6d
0f5b2a2
b3bfce2
4b5171c
362edf2
5412b49
f7b737d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<!-- Do not edit this file. It is automatically generated by API Documenter. --> | ||
|
||
[Home](./index.md) > [bitburner](./bitburner.md) > [GangMemberExpGain](./bitburner.gangmemberexpgain.md) > [agiEXP](./bitburner.gangmemberexpgain.agiexp.md) | ||
|
||
## GangMemberExpGain.agiEXP property | ||
|
||
Agi EXP gain for a member after a given task | ||
|
||
**Signature:** | ||
|
||
```typescript | ||
agiEXP: number; | ||
``` |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<!-- Do not edit this file. It is automatically generated by API Documenter. --> | ||
|
||
[Home](./index.md) > [bitburner](./bitburner.md) > [GangMemberExpGain](./bitburner.gangmemberexpgain.md) > [chaEXP](./bitburner.gangmemberexpgain.chaexp.md) | ||
|
||
## GangMemberExpGain.chaEXP property | ||
|
||
Cha EXP gain for a member after a given task | ||
|
||
**Signature:** | ||
|
||
```typescript | ||
chaEXP: number; | ||
``` |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<!-- Do not edit this file. It is automatically generated by API Documenter. --> | ||
|
||
[Home](./index.md) > [bitburner](./bitburner.md) > [GangMemberExpGain](./bitburner.gangmemberexpgain.md) > [defEXP](./bitburner.gangmemberexpgain.defexp.md) | ||
|
||
## GangMemberExpGain.defEXP property | ||
|
||
Def EXP gain for a member after a given task | ||
|
||
**Signature:** | ||
|
||
```typescript | ||
defEXP: number; | ||
``` |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<!-- Do not edit this file. It is automatically generated by API Documenter. --> | ||
|
||
[Home](./index.md) > [bitburner](./bitburner.md) > [GangMemberExpGain](./bitburner.gangmemberexpgain.md) > [dexEXP](./bitburner.gangmemberexpgain.dexexp.md) | ||
|
||
## GangMemberExpGain.dexEXP property | ||
|
||
Dex EXP gain for a member after a given task | ||
|
||
**Signature:** | ||
|
||
```typescript | ||
dexEXP: number; | ||
``` |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<!-- Do not edit this file. It is automatically generated by API Documenter. --> | ||
|
||
[Home](./index.md) > [bitburner](./bitburner.md) > [GangMemberExpGain](./bitburner.gangmemberexpgain.md) > [hackEXP](./bitburner.gangmemberexpgain.hackexp.md) | ||
|
||
## GangMemberExpGain.hackEXP property | ||
|
||
Hack EXP gain for a member after a given task | ||
|
||
**Signature:** | ||
|
||
```typescript | ||
hackEXP: number; | ||
``` |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
<!-- Do not edit this file. It is automatically generated by API Documenter. --> | ||
|
||
[Home](./index.md) > [bitburner](./bitburner.md) > [GangMemberExpGain](./bitburner.gangmemberexpgain.md) | ||
|
||
## GangMemberExpGain interface | ||
|
||
|
||
**Signature:** | ||
|
||
```typescript | ||
interface GangMemberExpGain | ||
``` | ||
|
||
## Properties | ||
|
||
| Property | Modifiers | Type | Description | | ||
| --- | --- | --- | --- | | ||
| [agiEXP](./bitburner.gangmemberexpgain.agiexp.md) | | number | Agi EXP gain for a member after a given task | | ||
| [chaEXP](./bitburner.gangmemberexpgain.chaexp.md) | | number | Cha EXP gain for a member after a given task | | ||
| [defEXP](./bitburner.gangmemberexpgain.defexp.md) | | number | Def EXP gain for a member after a given task | | ||
| [dexEXP](./bitburner.gangmemberexpgain.dexexp.md) | | number | Dex EXP gain for a member after a given task | | ||
| [hackEXP](./bitburner.gangmemberexpgain.hackexp.md) | | number | Hack EXP gain for a member after a given task | | ||
| [strEXP](./bitburner.gangmemberexpgain.strexp.md) | | number | Str EXP gain for a member after a given task | | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<!-- Do not edit this file. It is automatically generated by API Documenter. --> | ||
|
||
[Home](./index.md) > [bitburner](./bitburner.md) > [GangMemberExpGain](./bitburner.gangmemberexpgain.md) > [strEXP](./bitburner.gangmemberexpgain.strexp.md) | ||
|
||
## GangMemberExpGain.strEXP property | ||
|
||
Str EXP gain for a member after a given task | ||
|
||
**Signature:** | ||
|
||
```typescript | ||
strEXP: number; | ||
``` |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<!-- Do not edit this file. It is automatically generated by API Documenter. --> | ||
|
||
[Home](./index.md) > [bitburner](./bitburner.md) > [GangMemberInfo](./bitburner.gangmemberinfo.md) > [expGain](./bitburner.gangmemberinfo.expgain.md) | ||
|
||
## GangMemberInfo.expGain property | ||
|
||
Per Cycle Exp object for each stat for this gang member returned as a object containing each stats value returns null in the even that the member does not have a given task. | ||
|
||
**Signature:** | ||
|
||
```typescript | ||
expGain: GangMemberExpGain | null; | ||
``` |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,6 +14,7 @@ import { | |
calculateAscensionMult, | ||
calculateAscensionPointsGain, | ||
} from "./formulas/formulas"; | ||
import { GangMemberExpGain } from "@nsdefs"; | ||
|
||
interface IMults { | ||
hack: number; | ||
|
@@ -147,43 +148,80 @@ export class GangMember { | |
}; | ||
} | ||
|
||
gainExperience(numCycles = 1): void { | ||
// Calculate our gain for each stat based on each modifier of member | ||
// if no task is assigned to that member we return null, other wise we | ||
// return an object containing our per-cycle gains for each stat. | ||
calculateExpGain(numCycles = 1): GangMemberExpGain | null { | ||
const task = this.getTask(); | ||
if (task === GangMemberTasks.Unassigned) return; | ||
if (task === GangMemberTasks.Unassigned) return null; | ||
|
||
const expValues = { | ||
hackEXP: 0, | ||
strEXP: 0, | ||
defEXP: 0, | ||
dexEXP: 0, | ||
agiEXP: 0, | ||
chaEXP: 0, | ||
}; | ||
|
||
const difficultyMult = Math.pow(task.difficulty, 0.9); | ||
const difficultyPerCycles = difficultyMult * numCycles; | ||
const weightDivisor = 1500; | ||
const expMult = this.expMult(); | ||
this.hack_exp += | ||
|
||
expValues.hackEXP += | ||
(task.hackWeight / weightDivisor) * | ||
difficultyPerCycles * | ||
expMult.hack * | ||
this.calculateAscensionMult(this.hack_asc_points); | ||
this.str_exp += | ||
|
||
expValues.strEXP += | ||
(task.strWeight / weightDivisor) * | ||
difficultyPerCycles * | ||
expMult.str * | ||
this.calculateAscensionMult(this.str_asc_points); | ||
this.def_exp += | ||
|
||
expValues.defEXP += | ||
(task.defWeight / weightDivisor) * | ||
difficultyPerCycles * | ||
expMult.def * | ||
this.calculateAscensionMult(this.def_asc_points); | ||
this.dex_exp += | ||
|
||
expValues.dexEXP += | ||
(task.dexWeight / weightDivisor) * | ||
difficultyPerCycles * | ||
expMult.dex * | ||
this.calculateAscensionMult(this.dex_asc_points); | ||
this.agi_exp += | ||
|
||
expValues.agiEXP += | ||
(task.agiWeight / weightDivisor) * | ||
difficultyPerCycles * | ||
expMult.agi * | ||
this.calculateAscensionMult(this.agi_asc_points); | ||
this.cha_exp += | ||
|
||
expValues.chaEXP += | ||
(task.chaWeight / weightDivisor) * | ||
difficultyPerCycles * | ||
expMult.cha * | ||
this.calculateAscensionMult(this.cha_asc_points); | ||
|
||
return expValues; | ||
} | ||
|
||
gainExperience(): void { | ||
// Do the calculations if our function returns null meaning no task is assigned | ||
// then we return otherwise we add our exp gains to our total values | ||
const gains = this.calculateExpGain(); | ||
if (gains === null) { | ||
return; | ||
} | ||
|
||
this.hack_exp += gains.hackEXP; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Here and everywhere: Name the fields consistently (should be Also in the external interface. We're not super consistent, but for stats underscores and lowercase is pretty consistently the style. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @d0sboots made those fixes for ya if there's anything else ya need me to do lmk, more than happy to do so. Thanks very much to you both for being so helpful. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This might seem nitpicky, but it's There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @d0sboots fixed it 👍 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Don't forget to rerun There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @d0sboots sorry about that! completely slipped my mind its updated now |
||
this.str_exp += gains.strEXP; | ||
this.def_exp += gains.defEXP; | ||
this.dex_exp += gains.dexEXP; | ||
this.agi_exp += gains.agiEXP; | ||
this.cha_exp += gains.chaEXP; | ||
} | ||
|
||
earnRespect(numCycles = 1, gang: Gang): number { | ||
|
Original file line number | Diff line number | Diff line change | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -1,5 +1,4 @@ | ||||||||||||||
/** All netscript definitions */ | ||||||||||||||
|
||||||||||||||
/** @public */ | ||||||||||||||
interface HP { | ||||||||||||||
current: number; | ||||||||||||||
|
@@ -918,6 +917,21 @@ interface GangTerritory { | |||||||||||||
/** Wanted gain impact on task scaling */ | ||||||||||||||
wanted: number; | ||||||||||||||
} | ||||||||||||||
/** @public */ | ||||||||||||||
interface GangMemberExpGain { | ||||||||||||||
/** Hack EXP gain for a member after a given task*/ | ||||||||||||||
hackEXP: number; | ||||||||||||||
/** Str EXP gain for a member after a given task*/ | ||||||||||||||
strEXP: number; | ||||||||||||||
/** Def EXP gain for a member after a given task*/ | ||||||||||||||
defEXP: number; | ||||||||||||||
/** Dex EXP gain for a member after a given task*/ | ||||||||||||||
dexEXP: number; | ||||||||||||||
/** Agi EXP gain for a member after a given task*/ | ||||||||||||||
agiEXP: number; | ||||||||||||||
/** Cha EXP gain for a member after a given task*/ | ||||||||||||||
chaEXP: number; | ||||||||||||||
} | ||||||||||||||
|
||||||||||||||
/** @public */ | ||||||||||||||
interface GangMemberInfo { | ||||||||||||||
|
@@ -1004,6 +1018,10 @@ interface GangMemberInfo { | |||||||||||||
wantedLevelGain: number; | ||||||||||||||
/** Per Cycle Income for this gang member */ | ||||||||||||||
moneyGain: number; | ||||||||||||||
/** Per Cycle Exp object for each stat for this gang member returned as a object containing each stats value | ||||||||||||||
* returns null in the even that the member does not have a given task. | ||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||
*/ | ||||||||||||||
expGain: GangMemberExpGain | null; | ||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You have to explain the case in which it's null in the documentation. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Okay, just to make sure that this will work out fine. I separated the functions. One function independently handles the calculation of the exp that should be gained by the member. These calculations were already made in the original gainExperience function, I merely moved to another function within the formulas. I created a second function which receives those calculations in the form of an object from functionA the values from this object are added to the member's values own values. However, I was struggling very much so to find a way to ensure that the API could receive this object without duplicating exp gain. I settled on creating a getter function which is a GangMember function which receives a NumCycles value that is 1 since we are trying to calculate the exp gain of a task per cycle. There is no duplicate code and the calculations only happen once now with each function having one independent job. Please let me know if this works out if not I can attempt to adjust it more. |
||||||||||||||
} | ||||||||||||||
|
||||||||||||||
/** @public */ | ||||||||||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This function needs to receive
numCycles
, then pass it tocalculateExpGain
. You have to build and test your change.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Made the change, ran the linter, formatter, and testing suite. Testing suite showed all tests were passed.