Skip to content

Commit

Permalink
Add feature to give monsters random damage and health
Browse files Browse the repository at this point in the history
  • Loading branch information
oskarrough committed Dec 17, 2020
1 parent 271b528 commit ff7fbbe
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 3 deletions.
8 changes: 8 additions & 0 deletions public/content/dungeon-encounters.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import Dungeon, {MonsterRoom, Monster} from '../game/dungeon.js'
import gsap from '../web_modules/gsap.js'

// This file contains ready-to-use dungeons filled with rooms and exciting monsters.

Expand Down Expand Up @@ -41,10 +42,17 @@ const CultistMonster = () =>
intents: [{weak: 1}, {damage: 6}],
})

const RandomMonster = () =>
Monster({
random: 2,
hp: 36,
intents: [{damage: 5}, {damage: 10}, {damage: 5}],
})
export const createSimpleDungeon = () => {
return Dungeon({
rooms: [
MonsterRoom(Monster({hp: 18, intents})),
MonsterRoom(RandomMonster()),
MonsterRoom(Monster({intents}), ScalingMonster()),
MonsterRoom(STSMonster()),
MonsterRoom(CultistMonster()),
Expand Down
3 changes: 1 addition & 2 deletions public/game/actions.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import produce from '../web_modules/immer.js'
import {createCard} from './cards.js'
import {shuffle, getTargets, getCurrRoom /*, range*/} from './utils.js'
import {shuffle, getTargets, getCurrRoom} from './utils.js'
import powers from './powers.js'
import {createSimpleDungeon} from '../content/dungeon-encounters.js'

Expand Down Expand Up @@ -281,7 +281,6 @@ function takeMonsterTurn(state) {
if (intent.damage) {
let amount = intent.damage
if (monster.powers.weak) amount = powers.weak.use(amount)
// amount = shuffle(range(5, monster.damage - 2))[0]
const newHp = removeHealth(draft, {target: 'player', amount}).player.currentHealth
draft.player.currentHealth = newHp
}
Expand Down
16 changes: 15 additions & 1 deletion public/game/dungeon.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import {uuid} from './utils.js'
import {shuffle, range} from './utils.js'

// A dungeon is where the adventure starts.
export default function Dungeon(props) {
Expand Down Expand Up @@ -30,14 +31,27 @@ export function MonsterRoom(...monsters) {
// A monster has health, probably some damage and a list of intents.
// Intents are cycled through as the monster plays its turn.
export function Monster(props = {}) {
let intents = props.intents

// By setting props.random to a number, all damage intents will be randomized with this range.
if (typeof props.random === 'number') {
intents = props.intents.map((intent) => {
if (intent.damage) {
let newDamage = shuffle(range(5, intent.damage - props.random))[0]
intent.damage = newDamage
}
return intent
})
}

return {
id: uuid(),
maxHealth: props.hp || 42,
currentHealth: props.currentHealth || props.hp || 42,
damage: props.damage || 5,
block: props.block || 0,
powers: props.powers || {},
intents: props.intents || [],
intents: intents || [],
nextIntent: 0,
}
}

0 comments on commit ff7fbbe

Please sign in to comment.