Skip to content
This repository has been archived by the owner on Nov 3, 2024. It is now read-only.

Commit

Permalink
feat: make stress test bots swap weapons
Browse files Browse the repository at this point in the history
  • Loading branch information
leia-uwu committed Sep 12, 2024
1 parent 339a2cf commit d33dd20
Showing 1 changed file with 39 additions and 1 deletion.
40 changes: 39 additions & 1 deletion server/src/stressTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,14 @@ import { EmotesDefs } from "../../shared/defs/gameObjects/emoteDefs";
import { MeleeDefs } from "../../shared/defs/gameObjects/meleeDefs";
import { OutfitDefs } from "../../shared/defs/gameObjects/outfitDefs";
import { UnlockDefs } from "../../shared/defs/gameObjects/unlockDefs";
import { GameConfig } from "../../shared/gameConfig";
import { GameConfig, type Input } from "../../shared/gameConfig";
import * as net from "../../shared/net/net";
import {
type ObjectData,
ObjectType,
type ObjectsPartialData,
} from "../../shared/net/objectSerializeFns";
import type { LocalData } from "../../shared/net/updateMsg";
import { util } from "../../shared/utils/util";
import { v2 } from "../../shared/utils/v2";
import type { FindGameResponse } from "./gameServer";
Expand Down Expand Up @@ -146,6 +147,10 @@ class Bot {

data: string;

inputs: Input[] = [];

weapons: LocalData["weapons"] = [];

constructor(id: number, res: FindGameResponse["res"][0]) {
this.id = id;

Expand Down Expand Up @@ -200,6 +205,10 @@ class Bot {
const msg = new net.UpdateMsg();
msg.deserialize(stream, this.objectCreator);

if (msg.activePlayerData.weapsDirty) {
this.weapons = msg.activePlayerData.weapons;
}

// Delete objects
for (let i = 0; i < msg.delObjIds.length; i++) {
this.objectCreator.deleteObj(msg.delObjIds[i]);
Expand Down Expand Up @@ -319,6 +328,11 @@ class Bot {
inputPacket.addInput(GameConfig.Input.Interact);
}

for (const input of this.inputs) {
inputPacket.addInput(input);
}
this.inputs.length = 0;

this.sendMsg(net.MsgType.Input, inputPacket);

if (this.emote) {
Expand Down Expand Up @@ -369,6 +383,30 @@ class Bot {
this.moving.right = true;
break;
}

if (Math.random() < 0.1) {
const weaps = this.weapons.filter((weap) => weap.type !== "");
const slot = this.weapons.indexOf(weaps[util.randomInt(0, weaps.length - 1)]);

let input = null;
switch (slot) {
case 0:
input = GameConfig.Input.EquipPrimary;
break;
case 1:
input = GameConfig.Input.EquipSecondary;
break;
case 2:
input = GameConfig.Input.EquipMelee;
break;
case 3:
input = GameConfig.Input.EquipThrowable;
break;
}
if (input) {
this.inputs.push(input);
}
}
}
}

Expand Down

0 comments on commit d33dd20

Please sign in to comment.