Skip to content
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

Merged
merged 15 commits into from
Feb 20, 2025
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions markdown/bitburner.gangmemberexpgain.agiexp.md
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) &gt; [bitburner](./bitburner.md) &gt; [GangMemberExpGain](./bitburner.gangmemberexpgain.md) &gt; [agiEXP](./bitburner.gangmemberexpgain.agiexp.md)

## GangMemberExpGain.agiEXP property

Agi EXP gain for a member after a given task

**Signature:**

```typescript
agiEXP: number;
```
13 changes: 13 additions & 0 deletions markdown/bitburner.gangmemberexpgain.chaexp.md
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) &gt; [bitburner](./bitburner.md) &gt; [GangMemberExpGain](./bitburner.gangmemberexpgain.md) &gt; [chaEXP](./bitburner.gangmemberexpgain.chaexp.md)

## GangMemberExpGain.chaEXP property

Cha EXP gain for a member after a given task

**Signature:**

```typescript
chaEXP: number;
```
13 changes: 13 additions & 0 deletions markdown/bitburner.gangmemberexpgain.defexp.md
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) &gt; [bitburner](./bitburner.md) &gt; [GangMemberExpGain](./bitburner.gangmemberexpgain.md) &gt; [defEXP](./bitburner.gangmemberexpgain.defexp.md)

## GangMemberExpGain.defEXP property

Def EXP gain for a member after a given task

**Signature:**

```typescript
defEXP: number;
```
13 changes: 13 additions & 0 deletions markdown/bitburner.gangmemberexpgain.dexexp.md
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) &gt; [bitburner](./bitburner.md) &gt; [GangMemberExpGain](./bitburner.gangmemberexpgain.md) &gt; [dexEXP](./bitburner.gangmemberexpgain.dexexp.md)

## GangMemberExpGain.dexEXP property

Dex EXP gain for a member after a given task

**Signature:**

```typescript
dexEXP: number;
```
13 changes: 13 additions & 0 deletions markdown/bitburner.gangmemberexpgain.hackexp.md
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) &gt; [bitburner](./bitburner.md) &gt; [GangMemberExpGain](./bitburner.gangmemberexpgain.md) &gt; [hackEXP](./bitburner.gangmemberexpgain.hackexp.md)

## GangMemberExpGain.hackEXP property

Hack EXP gain for a member after a given task

**Signature:**

```typescript
hackEXP: number;
```
24 changes: 24 additions & 0 deletions markdown/bitburner.gangmemberexpgain.md
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) &gt; [bitburner](./bitburner.md) &gt; [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 |

13 changes: 13 additions & 0 deletions markdown/bitburner.gangmemberexpgain.strexp.md
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) &gt; [bitburner](./bitburner.md) &gt; [GangMemberExpGain](./bitburner.gangmemberexpgain.md) &gt; [strEXP](./bitburner.gangmemberexpgain.strexp.md)

## GangMemberExpGain.strEXP property

Str EXP gain for a member after a given task

**Signature:**

```typescript
strEXP: number;
```
13 changes: 13 additions & 0 deletions markdown/bitburner.gangmemberinfo.expgain.md
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) &gt; [bitburner](./bitburner.md) &gt; [GangMemberInfo](./bitburner.gangmemberinfo.md) &gt; [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;
```
1 change: 1 addition & 0 deletions markdown/bitburner.gangmemberinfo.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ interface GangMemberInfo
| [dex\_mult](./bitburner.gangmemberinfo.dex_mult.md) | | number | Dexterity multiplier from equipment |
| [dex](./bitburner.gangmemberinfo.dex.md) | | number | Dexterity skill level |
| [earnedRespect](./bitburner.gangmemberinfo.earnedrespect.md) | | number | Amount of Respect earned by member since they last Ascended |
| [expGain](./bitburner.gangmemberinfo.expgain.md) | | [GangMemberExpGain](./bitburner.gangmemberexpgain.md) \| null | 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. |
| [hack\_asc\_mult](./bitburner.gangmemberinfo.hack_asc_mult.md) | | number | Hack multiplier from ascensions |
| [hack\_asc\_points](./bitburner.gangmemberinfo.hack_asc_points.md) | | number | Total Hack Ascension points accumulated |
| [hack\_exp](./bitburner.gangmemberinfo.hack_exp.md) | | number | Current hack experience |
Expand Down
1 change: 1 addition & 0 deletions markdown/bitburner.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@
| [GangFormulas](./bitburner.gangformulas.md) | Gang formulas |
| [GangGenInfo](./bitburner.ganggeninfo.md) | Gang general info. |
| [GangMemberAscension](./bitburner.gangmemberascension.md) | |
| [GangMemberExpGain](./bitburner.gangmemberexpgain.md) | |
| [GangMemberInfo](./bitburner.gangmemberinfo.md) | |
| [GangMemberInstall](./bitburner.gangmemberinstall.md) | |
| [GangOtherInfoObject](./bitburner.gangotherinfoobject.md) | |
Expand Down
54 changes: 46 additions & 8 deletions src/Gang/GangMember.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {
calculateAscensionMult,
calculateAscensionPointsGain,
} from "./formulas/formulas";
import { GangMemberExpGain } from "@nsdefs";

interface IMults {
hack: number;
Expand Down Expand Up @@ -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 {
Copy link
Contributor

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 to calculateExpGain. You have to build and test your change.

Copy link
Contributor Author

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.

// 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;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here and everywhere: Name the fields consistently (should be hack_exp etc.)

Also in the external interface. We're not super consistent, but for stats underscores and lowercase is pretty consistently the style.

Copy link
Contributor Author

@AdamAndreatta AdamAndreatta Feb 18, 2025

Choose a reason for hiding this comment

The 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.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This might seem nitpicky, but it's hack_exp not hack_EXP.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@d0sboots fixed it 👍

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't forget to rerun npm doc

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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 {
Expand Down
1 change: 1 addition & 0 deletions src/NetscriptFunctions/Gang.ts
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@ export function NetscriptGang(): InternalAPI<IGang> {
respectGain: member.calculateRespectGain(gang),
wantedLevelGain: member.calculateWantedLevelGain(gang),
moneyGain: member.calculateMoneyGain(gang),
expGain: member.calculateExpGain(),
};
},
canRecruitMember: (ctx) => () => {
Expand Down
20 changes: 19 additions & 1 deletion src/ScriptEditor/NetscriptDefinitions.d.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
/** All netscript definitions */

/** @public */
interface HP {
current: number;
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
/** 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.
/**
* Per Cycle Exp object for each stat for this gang member.
*
* null in the event that the member does not have a given task.
  • The second part of the sentence was redundant and confusing IMO
  • In docs like this, you need a extra newline, otherwise it will all run together on one line when formatted. (Or, maybe that's what you want, but you will still want a period at the end of the prior sentence.)

*/
expGain: GangMemberExpGain | null;
Copy link
Contributor

Choose a reason for hiding this comment

The 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.

Copy link
Contributor Author

@AdamAndreatta AdamAndreatta Feb 12, 2025

Choose a reason for hiding this comment

The 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 */
Expand Down