Skip to content

feat: remove /vnw abuse - #228

Merged
BalaM314 merged 6 commits into
Fish-Community:masterfrom
FishyNavi:master
Jul 4, 2026
Merged

feat: remove /vnw abuse#228
BalaM314 merged 6 commits into
Fish-Community:masterfrom
FishyNavi:master

Conversation

@FishyNavi

Copy link
Copy Markdown
Contributor

Fix the issue #139 by adding new requirement to /vnw command that checks if thwere are units from previous waves.

@FishyNavi FishyNavi closed this Jul 3, 2026
@FishyNavi FishyNavi reopened this Jul 3, 2026
@FishyNavi

Copy link
Copy Markdown
Contributor Author

i have no idea of what to do here

@FishyNavi FishyNavi closed this Jul 4, 2026
import { PermType } from "/frameworks/commands/perm";
import type { FishCommandHandlerData } from "/frameworks/commands/types";
import { FishPlayer } from "/players";
import { formatModeName } from "/utils";

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

obsolete import

Comment thread src/index.ts Outdated
fishState.startTime = Date.now();
});

Events.on(EventType.UnitDestroyEvent, (e) => vnwCondition.removeUnit(e));

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Instead of keeping a list of alive enemy units and updating it whenever a unit dies, you can just keep a list of enemy units and check if anything in the list is still alive. This is more performant because the operation is only done if you use /vnw, instead of every single time a unit dies.

Comment thread src/utils.ts Outdated
vnwCondition.waveUnits.splice(index,1);
},
onWaveStart(){
Groups.unit.each((unit) => {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Instead of using Groups.unit and filtering to units on the enemy team, you can directly get a list of enemy units with (team).data().units

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Make sure to copy() it, we don't want our list to change when new enemy units appear

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

copying (team).data().units didn't work, because it seemed to be empty on wave start event, resulting in logic letting skip 2 waves.

Comment thread src/utils.ts Outdated

},
check(){
if (this.waveUnits.length==0) return true;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Use waveUnits.some(u => !u.dead)

Comment thread src/utils.ts Outdated
this.waveUnits.push(unitId);
},
removeUnit(e:EventType){
const index = vnwCondition.waveUnits.indexOf(e.unit.id);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This operation is O(n) due to the data structure chosen, resulting in O(n^2) time complexity if you spawn a bunch of units and then kill them all. (it will be noticeably slow when the waves are sending hundreds of units) A Set would be better here.

But you can just remove this method entirely instead per previous comment

Comment thread src/utils.ts Outdated
addUnit(unitId:number){
this.waveUnits.push(unitId);
},
removeUnit(e:EventType){

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

EventType is an event type, like "WaveEvent". This method is supposed to accept event instances. You're looking for Event. For some reason I named it MEvent.

You can delete this method instead per previous comment

Comment thread src/utils.ts Outdated
export const vnwCondition = {
waveUnits: [] as Unit[],
onWaveStart(){
let units = Groups.unit.copy(new Seq())

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
let units = Groups.unit.copy(new Seq())
this.waveUnits = Vars.state.rules.waveTeam.data().units.toArray();

you can use toArray() to copy it and get an array, or copy() to copy it and get a Seq. Either is fine.

Comment thread src/index.ts Outdated
fishState.startTime = Date.now();
});

Events.on(EventType.WaveEvent, () => vnwCondition.onWaveStart());

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This still needs to only run in survival.

Suggested change
Events.on(EventType.WaveEvent, () => vnwCondition.onWaveStart());
+if(Gamemode.survival())
Events.on(EventType.WaveEvent, () => vnwCondition.onWaveStart());

@BalaM314
BalaM314 merged commit a11ecad into Fish-Community:master Jul 4, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants