feat: remove /vnw abuse - #228
Conversation
|
i have no idea of what to do here |
| import { PermType } from "/frameworks/commands/perm"; | ||
| import type { FishCommandHandlerData } from "/frameworks/commands/types"; | ||
| import { FishPlayer } from "/players"; | ||
| import { formatModeName } from "/utils"; |
| fishState.startTime = Date.now(); | ||
| }); | ||
|
|
||
| Events.on(EventType.UnitDestroyEvent, (e) => vnwCondition.removeUnit(e)); |
There was a problem hiding this comment.
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.
| vnwCondition.waveUnits.splice(index,1); | ||
| }, | ||
| onWaveStart(){ | ||
| Groups.unit.each((unit) => { |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Make sure to copy() it, we don't want our list to change when new enemy units appear
There was a problem hiding this comment.
copying (team).data().units didn't work, because it seemed to be empty on wave start event, resulting in logic letting skip 2 waves.
|
|
||
| }, | ||
| check(){ | ||
| if (this.waveUnits.length==0) return true; |
There was a problem hiding this comment.
Use waveUnits.some(u => !u.dead)
| this.waveUnits.push(unitId); | ||
| }, | ||
| removeUnit(e:EventType){ | ||
| const index = vnwCondition.waveUnits.indexOf(e.unit.id); |
There was a problem hiding this comment.
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
| addUnit(unitId:number){ | ||
| this.waveUnits.push(unitId); | ||
| }, | ||
| removeUnit(e:EventType){ |
There was a problem hiding this comment.
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
| export const vnwCondition = { | ||
| waveUnits: [] as Unit[], | ||
| onWaveStart(){ | ||
| let units = Groups.unit.copy(new Seq()) |
There was a problem hiding this comment.
| 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.
| fishState.startTime = Date.now(); | ||
| }); | ||
|
|
||
| Events.on(EventType.WaveEvent, () => vnwCondition.onWaveStart()); |
There was a problem hiding this comment.
This still needs to only run in survival.
| Events.on(EventType.WaveEvent, () => vnwCondition.onWaveStart()); | |
| +if(Gamemode.survival()) | |
| Events.on(EventType.WaveEvent, () => vnwCondition.onWaveStart()); |
Fix the issue #139 by adding new requirement to /vnw command that checks if thwere are units from previous waves.