-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Change event to TURN_START and update merc role and ability speed acc…
…ording to tags
- Loading branch information
1 parent
2a8c870
commit 7f8b3b9
Showing
4 changed files
with
87 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
63 changes: 60 additions & 3 deletions
63
core/src/js/services/mercenaries/parser/mercenaries-turn-start-parser.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,73 @@ | ||
import { GameEvent } from '../../../models/game-event'; | ||
import { MercenariesBattleState } from '../../../models/mercenaries/mercenaries-battle-state'; | ||
import { MercenariesBattleState, MercenariesBattleTeam } from '../../../models/mercenaries/mercenaries-battle-state'; | ||
import { getHeroRole } from '../mercenaries-utils'; | ||
import { MercenariesParser } from './_mercenaries-parser'; | ||
import { GameTag, TagRole } from '@firestone-hs/reference-data'; | ||
|
||
export class MercenariesTurnStartParser implements MercenariesParser { | ||
public eventType = () => GameEvent.TURN_START; | ||
|
||
public applies = (battleState: MercenariesBattleState) => !!battleState; | ||
|
||
public async parse(battleState: MercenariesBattleState, event: GameEvent): Promise<MercenariesBattleState> { | ||
public async parse( | ||
battleState: MercenariesBattleState, | ||
event: GameEvent, | ||
): Promise<MercenariesBattleState> { | ||
|
||
if(event.additionalData?.playerBoard && event.additionalData?.playerLettuceAbilities){ | ||
var newPlayerTeam: MercenariesBattleTeam = battleState.playerTeam; | ||
|
||
for (var merc of event.additionalData?.playerBoard) { | ||
newPlayerTeam = newPlayerTeam.updateMercenary(merc.entityId, | ||
{ | ||
cardId: merc.cardId, | ||
role: getHeroRole(TagRole[merc?.tags?.find((tag) => tag.Name==GameTag.LETTUCE_ROLE)?.Value]), | ||
}); | ||
} | ||
|
||
for (var ability of event.additionalData?.playerLettuceAbilities) { | ||
newPlayerTeam = newPlayerTeam.updateAbility(ability.entityId, | ||
{ | ||
cardId: ability.cardId, | ||
speed: ability.tags?.find((tag) => tag.Name==GameTag.COST)?.Value, | ||
cooldownLeft: ability.tags?.find((tag) => tag.Name==GameTag.LETTUCE_CURRENT_COOLDOWN)?.Value, | ||
} | ||
) | ||
} | ||
} | ||
else { | ||
console.warn('[merc-game-state-update] player info not provided', event); | ||
} | ||
|
||
if(event.additionalData?.opponentBoard && event.additionalData?.opponentLettuceAbilities){ | ||
var newOpponentTeam: MercenariesBattleTeam = battleState.opponentTeam; | ||
|
||
for (var merc of event.additionalData?.opponentBoard) { | ||
newOpponentTeam = newOpponentTeam.updateMercenary(merc.entityId, | ||
{ | ||
cardId: merc.cardId, | ||
role: getHeroRole(TagRole[merc?.tags?.find((tag) => tag.Name==GameTag.LETTUCE_ROLE)?.Value]), | ||
}); | ||
} | ||
for (var ability of event.additionalData?.opponentLettuceAbilities) { | ||
newOpponentTeam = newOpponentTeam.updateAbility(ability.entityId, | ||
{ | ||
cardId: ability.cardId, | ||
speed: ability.tags?.find((tag) => tag.Name==GameTag.COST)?.Value, | ||
cooldownLeft: ability.tags?.find((tag) => tag.Name==GameTag.LETTUCE_CURRENT_COOLDOWN)?.Value, | ||
} | ||
) | ||
} | ||
} | ||
else { | ||
console.warn('[merc-game-state-update] opponent info not provided', event); | ||
} | ||
|
||
return battleState.update({ | ||
playerTeam: newPlayerTeam, | ||
opponentTeam: newOpponentTeam, | ||
currentTurn: event.additionalData.turnNumber, | ||
actionQueue: [], | ||
}); | ||
} as MercenariesBattleState); | ||
} | ||
} |