Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
leanmendoza committed Aug 12, 2024
1 parent 4ef8a96 commit d714621
Show file tree
Hide file tree
Showing 13 changed files with 220 additions and 164 deletions.
2 changes: 1 addition & 1 deletion scene/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
"dependencies": {
"@dcl-sdk/utils": "^1.2.8",
"@dcl/asset-packs": "^1.19.0",
"@dcl/js-runtime": "7.5.6",
"@dcl/js-runtime": "7.5.7-10236853633.commit-23b945d",
"@dcl/sdk": "7.5.6",
"@dcl/sdk-commands": "7.5.6",
"dcl-npc-toolkit": "^1.2.2",
Expand Down
33 changes: 5 additions & 28 deletions scene/src/enemies/MonsterMob.ts
Original file line number Diff line number Diff line change
Expand Up @@ -200,29 +200,6 @@ export class MonsterMob extends GenericMonster {
)
}

setupAttackTriggerBox(): void {
this.attackTrigger = entityController.addEntity()
Transform.create(this.attackTrigger, { parent: this.entity })
MeshRenderer.setBox(this.attackTrigger)
VisibilityComponent.create(this.attackTrigger, { visible: false })
utils.triggers.addTrigger(
this.attackTrigger,
1,
1,
[{ type: 'box', scale: Vector3.create(8, 2, 8) }],
() => {
this.createHealthBar()
this.handleAttack()
},
() => {
console.log('im out')
if (this.healthBar != null)
entityController.removeEntity(this.healthBar)
if (this.label != null) entityController.removeEntity(this.label)
}
)
}

setDistance(distance: number): void {
pointerEventsSystem.onPointerDown(
{
Expand Down Expand Up @@ -343,9 +320,9 @@ export class MonsterMob extends GenericMonster {
}
const roundedAttack = Math.floor(enemyAttack)
this.attackPlayer(roundedAttack)
monsterModifiers.activeSkills.forEach((skill) =>
monsterModifiers.activeSkills.forEach((skill) => {
skill(false, false, enemyAttack, this)
)
})
}

setupAttackHandler(): void {
Expand Down Expand Up @@ -405,9 +382,9 @@ export class MonsterMob extends GenericMonster {
// `MISSED`
// )

monsterModifiers.activeSkills.forEach((skill) =>
skill(isCriticalAttack, true, reduceHealthBy)
)
monsterModifiers.activeSkills.forEach((skill) => {
skill(isCriticalAttack, true, reduceHealthBy, this)
})
} else {
const player = Player.getInstance()
const mainHUD = player.gameController.uiController.mainHud
Expand Down
6 changes: 2 additions & 4 deletions scene/src/enemies/hardDungeons/DungeonBossHelp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export default class Minion extends MonsterMob {
})
this.initMonster()
this.loadTransformation()
this.topOffSet = 2.25
this.setTopOffset(2.25)
this.dropRate = -1
}

Expand Down Expand Up @@ -59,11 +59,9 @@ export default class Minion extends MonsterMob {
create(): void {}

removeEntity(): void {
super.cleanup()
entityController.removeEntity(this.rangeAttackTrigger)
entityController.removeEntity(this.engageAttackTrigger)
entityController.removeEntity(this.attackTrigger)
entityController.removeEntity(this.healthBar)
entityController.removeEntity(this.label)
entityController.removeEntity(this.entity)
}
}
10 changes: 5 additions & 5 deletions scene/src/enemies/monster.ts
Original file line number Diff line number Diff line change
Expand Up @@ -376,9 +376,9 @@ export class MonsterOligar extends GenericMonster {
// `MISSED`
// )

monsterModifiers.activeSkills.forEach((skill) =>
skill(isCriticalAttack, true, reduceHealthBy)
)
monsterModifiers.activeSkills.forEach((skill) => {
skill(isCriticalAttack, true, reduceHealthBy, this)
})
} else {
// Monster attacks
const defPercent = player.getDefensePercent()
Expand All @@ -405,9 +405,9 @@ export class MonsterOligar extends GenericMonster {
// `${roundedAttack}`
// )

monsterModifiers.activeSkills.forEach((skill) =>
monsterModifiers.activeSkills.forEach((skill) => {
skill(false, false, enemyAttack, this)
)
})
}
}

Expand Down
21 changes: 12 additions & 9 deletions scene/src/enemies/monsterGeneric.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ import { currentlyAttackingMontserList } from './splashAttack'
import { Character } from './character'

export abstract class GenericMonster extends Character {
public attackTrigger!: Entity
public healthBar!: Entity
public label!: Entity
public topOffSet?: number
private attackTrigger: Entity | null = null
private healthBar: Entity | null = null
private label: Entity | null = null
private topOffSet?: number

constructor(
attack: number,
Expand Down Expand Up @@ -60,11 +60,11 @@ export abstract class GenericMonster extends Character {
}

updateHealthBar(): void {
if (this.healthBar !== undefined) {
if (this.healthBar !== null) {
Transform.getMutable(this.healthBar).scale.x = 1 * this.getHealthScaled()
}

if (this.label !== undefined) {
if (this.label !== null) {
TextShape.getMutable(this.label).text = `${this.health}`
}
}
Expand Down Expand Up @@ -107,15 +107,18 @@ export abstract class GenericMonster extends Character {
abstract performAttack(damage: number, isCriticalAttack: boolean): void

cleanup(): void {
if (this.attackTrigger !== undefined) {
if (this.attackTrigger !== null) {
entityController.removeEntity(this.attackTrigger)
}
if (this.healthBar !== undefined) {
if (this.healthBar !== null) {
entityController.removeEntity(this.healthBar)
}
if (this.label !== undefined) {
if (this.label !== null) {
entityController.removeEntity(this.label)
}
this.attackTrigger = null
this.healthBar = null
this.label = null
}

setTopOffset(offset: number): void {
Expand Down
10 changes: 5 additions & 5 deletions scene/src/enemies/monsterHealer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -333,9 +333,9 @@ export class MonsterHealer extends GenericMonster {
console.log('Monster has no skills')
}

monsterModifiers.activeSkills.forEach((skill) =>
skill(isCriticalAttack, true, reduceHealthBy)
)
monsterModifiers.activeSkills.forEach((skill) => {
skill(isCriticalAttack, true, reduceHealthBy, this)
})
} else {
// Monster attacks
const defPercent = player.getDefensePercent()
Expand All @@ -362,9 +362,9 @@ export class MonsterHealer extends GenericMonster {
// `${roundedAttack}`
// )

monsterModifiers.activeSkills.forEach((skill) =>
monsterModifiers.activeSkills.forEach((skill) => {
skill(false, false, enemyAttack, this)
)
})
}
}

Expand Down
10 changes: 5 additions & 5 deletions scene/src/enemies/monsterMage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -322,9 +322,9 @@ export class MonsterMage extends GenericMonster {
console.log('Monster has no skills')
}

monsterModifiers.activeSkills.forEach((skill) =>
skill(isCriticalAttack, true, reduceHealthBy)
)
monsterModifiers.activeSkills.forEach((skill) => {
skill(isCriticalAttack, true, reduceHealthBy, this)
})
} else {
// Monster attacks
const defPercent = player.getDefensePercent()
Expand All @@ -351,9 +351,9 @@ export class MonsterMage extends GenericMonster {
// `${roundedAttack}`
// )

monsterModifiers.activeSkills.forEach((skill) =>
monsterModifiers.activeSkills.forEach((skill) => {
skill(false, false, enemyAttack, this)
)
})
}
}

Expand Down
10 changes: 5 additions & 5 deletions scene/src/enemies/monsterMeat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -337,9 +337,9 @@ export class MonsterMeat extends GenericMonster {
// `MISSED`
// )

monsterModifiers.activeSkills.forEach((skill) =>
skill(isCriticalAttack, true, reduceHealthBy)
)
monsterModifiers.activeSkills.forEach((skill) => {
skill(isCriticalAttack, true, reduceHealthBy, this)
})
} else {
// Monster attacks
const defPercent = player.getDefensePercent()
Expand Down Expand Up @@ -367,9 +367,9 @@ export class MonsterMeat extends GenericMonster {
// `${roundedAttack}`
// )

monsterModifiers.activeSkills.forEach((skill) =>
monsterModifiers.activeSkills.forEach((skill) => {
skill(false, false, enemyAttack, this)
)
})
}
}

Expand Down
10 changes: 5 additions & 5 deletions scene/src/enemies/monsterMobAuto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -367,9 +367,9 @@ export class MonsterMobAuto extends GenericMonster {
// `MISSED`
// )

monsterModifiers.activeSkills.forEach((skill) =>
skill(isCriticalAttack, true, reduceHealthBy)
)
monsterModifiers.activeSkills.forEach((skill) => {
skill(isCriticalAttack, true, reduceHealthBy, this)
})
} else {
// Monster attacks
const defPercent = player.getDefensePercent()
Expand Down Expand Up @@ -397,9 +397,9 @@ export class MonsterMobAuto extends GenericMonster {
// `${roundedAttack}`
// )

monsterModifiers.activeSkills.forEach((skill) =>
monsterModifiers.activeSkills.forEach((skill) => {
skill(false, false, enemyAttack, this)
)
})
}
}

Expand Down
10 changes: 5 additions & 5 deletions scene/src/enemies/monsterPoison.ts
Original file line number Diff line number Diff line change
Expand Up @@ -281,9 +281,9 @@ export class MonsterPoison extends GenericMonster {
}
const roundedAttack = Math.floor(enemyAttack)
this.attackPlayer(roundedAttack)
monsterModifiers.activeSkills.forEach((skill) =>
monsterModifiers.activeSkills.forEach((skill) => {
skill(false, false, enemyAttack, this)
)
})
}

setupAttackHandler(): void {
Expand Down Expand Up @@ -341,9 +341,9 @@ export class MonsterPoison extends GenericMonster {
// `MISSED`
// )

monsterModifiers.activeSkills.forEach((skill) =>
skill(isCriticalAttack, true, reduceHealthBy)
)
monsterModifiers.activeSkills.forEach((skill) => {
skill(isCriticalAttack, true, reduceHealthBy, this)
})
}
}
)
Expand Down
19 changes: 15 additions & 4 deletions scene/src/enemies/skillEffects.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,13 @@
import * as utils from '@dcl-sdk/utils'
import { type GenericMonster } from './monsterGeneric'

type MonsterSkillFunction = (
isCriticalAttack: boolean,
isPlayerAttack: boolean,
attackAmount: number,
monster: GenericMonster
) => void

class MonsterModifiers {
public attackBuff: number = 0
public luckBuff: number = 0
Expand All @@ -7,8 +16,7 @@ class MonsterModifiers {
public critDamageBuff: number = 0
public canActivateSkill!: boolean

// eslint-disable-next-line @typescript-eslint/consistent-generic-constructors, @typescript-eslint/ban-types
public activeSkills: Map<string, Function> = new Map()
public activeSkills = new Map<string, MonsterSkillFunction>()

getAtkBuff(): number {
return this.attackBuff
Expand Down Expand Up @@ -50,8 +58,11 @@ class MonsterModifiers {
this.critRateBuff += value
}

// eslint-disable-next-line @typescript-eslint/ban-types
addActiveSkill(activeTime: number, skillName: string, skill: Function): void {
addActiveSkill(
activeTime: number,
skillName: string,
skill: MonsterSkillFunction
): void {
this.activeSkills.set(skillName, skill)

utils.timers.setTimeout(() => {
Expand Down
Loading

0 comments on commit d714621

Please sign in to comment.