1
0
Fork 0
mirror of https://github.com/em-squared/5e-drs.git synced 2025-10-29 20:54:19 +00:00

support des alliés dans le calculateur de rencontres

This commit is contained in:
Maxime Moraine 2021-05-03 16:27:59 +02:00
parent 5dcd1ceb7c
commit 9b9a54b134
2 changed files with 96 additions and 32 deletions

View file

@ -47,9 +47,12 @@ export default {
state.creatures = []
},
addCreature: (state, payload) => {
payload.qty = 1
state.creatures.push(payload)
state.creatures.sort((a, b) => { return sortByString(a.title, b.title) })
// payload.qty = 1
let c = Object.assign({}, payload)
c.ally = false
state.creatures.push(c)
c = null
// state.creatures.sort((a, b) => { return sortByString(a.title, b.title) })
},
updateCreatures: (state, payload) => {
let creatureIndex = getResourceIndexInLibrary(payload, state.creatures)
@ -58,9 +61,13 @@ export default {
}
},
removeCreature: (state, payload) => {
let creatureIndex = getResourceIndexInLibrary(payload, state.creatures)
if (creatureIndex >= 0) {
state.creatures.splice(creatureIndex, 1)
if (payload >= 0) {
state.creatures.splice(payload, 1)
}
},
switchCampCreature: (state, payload) => {
if (payload >= 0) {
state.creatures[payload].ally = !state.creatures[payload].ally
}
},
setCreatureQty: (state, payload) => {

View file

@ -24,13 +24,14 @@
></v-progress-linear>
<span class="subtitle-2">PX : </span>{{ totalXP }} ({{ Math.floor(totalXP / pc) }} par PJ)
</div>
<v-row class="d-flex align-center my-0" v-for="c in creatures">
<v-row class="d-flex align-center my-0" v-for="(c, idx) in creatures">
<v-col class="px-0 py-1">
<div class="subtitle-2">{{c.title}}</div>
<!-- <div><span class="subtitle-2">ID : </span>{{c.frontmatter.challenge}}</div> -->
</v-col>
<v-col class="px-0 py-1">
<v-btn dense icon small @click="removeCreatureInEncounter(c)">
<v-switch :value="c.ally" label="Allié" dense class="ma-0 d-inline-block" @click="switchCampCreatureInEncounter(idx)" color="accent"></v-switch>
<v-btn dense icon small @click="removeCreatureInEncounter(idx)">
<v-icon color="red">mdi-delete</v-icon>
</v-btn>
</v-col>
@ -58,6 +59,8 @@ export default {
panels: [0],
challenges: CHALLENGES,
encounterLevels: ENCOUNTERLEVELS,
totalPC: 0,
totalXP: 0,
}
},
@ -66,9 +69,9 @@ export default {
creatures: state => state.encounterCalculator.creatures,
}),
...mapGetters({
totalPC: 'encounterCalculator/totalPC',
}),
// ...mapGetters({
// totalPC: 'encounterCalculator/totalPC',
// }),
pc: {
get () {
@ -110,25 +113,30 @@ export default {
return {label, color}
},
totalPC () {
let pc = 0
for (let c of this.creatures) {
pc += getPCbyChallenge(Number(c.frontmatter.challenge))
}
return pc
},
// totalPC () {
// let pc = 0
// for (let c of this.creatures) {
// if (c.ally) {
// pc -= getPCbyChallenge(Number(c.frontmatter.challenge))
// } else {
// pc += getPCbyChallenge(Number(c.frontmatter.challenge))
// }
// console.log(c)
// }
// return pc
// },
totalXP () {
let xp = 0
for (let c of this.creatures) {
if (c.frontmatter.challenge == 0) {
xp += 10
} else {
xp += stats.challenges[c.frontmatter.challenge].xp
}
}
return xp
},
// totalXP () {
// let xp = 0
// for (let c of this.creatures) {
// if (c.frontmatter.challenge == 0) {
// xp += 10
// } else {
// xp += stats.challenges[c.frontmatter.challenge].xp
// }
// }
// return xp
// },
challengeForGroup () {
let level = this.encounterLevels[this.encounterLevels.findIndex((item) => { return item.level == this.level })]
@ -146,13 +154,62 @@ export default {
},
methods: {
removeCreatureInEncounter (creature) {
this.$store.commit('encounterCalculator/removeCreature', creature)
removeCreatureInEncounter (idx) {
this.$store.commit('encounterCalculator/removeCreature', idx)
},
switchCampCreatureInEncounter (idx) {
this.$store.commit('encounterCalculator/switchCampCreature', idx)
this.setTotalPC()
this.setTotalXP()
},
setTotalPC () {
let pc = 0
for (let c of this.creatures) {
if (c.ally) {
pc -= getPCbyChallenge(Number(c.frontmatter.challenge))
} else {
pc += getPCbyChallenge(Number(c.frontmatter.challenge))
}
// console.log(c)
}
this.totalPC = pc
},
setTotalXP () {
let xp = 0
for (let c of this.creatures) {
if (c.frontmatter.challenge == 0) {
if (c.ally) {
xp -= 10
} else {
xp += 10
}
} else {
if (c.ally) {
xp -= stats.challenges[c.frontmatter.challenge].xp
} else {
xp += stats.challenges[c.frontmatter.challenge].xp
}
}
}
if (xp < 0) {
xp = 0
}
this.totalXP = xp
},
},
mounted () {
},
watch: {
creatures () {
this.setTotalPC()
this.setTotalXP()
}
}
}
</script>