Skip to content

Instantly share code, notes, and snippets.

@victorysoftworks
Created July 8, 2021 04:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save victorysoftworks/8836bf8f73abbf62dcbefd72a7b838f4 to your computer and use it in GitHub Desktop.
Save victorysoftworks/8836bf8f73abbf62dcbefd72a7b838f4 to your computer and use it in GitHub Desktop.
class CorrodableComponent extends Component {
constructor(durability) {
super(Priority.Normal)
this.durability = {
max: durability,
current: durability
}
}
handle(event) {
if (event.type === 'corrode') {
this.corrode(event.params.amount)
} else if (event.type === 'repair') {
this.repair()
}
}
corrode(amount) {
this.durability.current -= amount
if (this.durability.current <= 0) {
this.owner.destroy()
}
}
repair() {
this.durability.current = this.durability.max
}
query(query) {
if (query.for === 'corroded') {
query.result = this.durability.current < this.durability.max
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment