3232 <button class =" btn btn-primary btn-lg me-3 mt-2" @click =" next()" >
3333 {{t('action.next')}}
3434 </button >
35- <button class =" btn btn-outline-secondary btn-sm mt-2" @click =" reset()" >
36- {{t('action.reset')}}
37- </button >
3835
3936 <div class =" draftedCards" >
40- <div v-if =" playerTechs.length > 0" class =" mt-3" >
41- <TechCardsPlayerDraft :navigationState =" navigationState " :playerTechs =" playerTechs " />
37+ <div v-if =" techDraftStep. playerTechs.length > 0" class =" mt-3" >
38+ <TechCardsPlayerDraft :navigationState =" navigationState " :playerTechs =" techDraftStep . playerTechs " />
4239 </div >
4340
44- <div v-if =" botTechs.length > 0" class =" mt-3" >
41+ <div v-if =" techDraftStep. botTechs.length > 0" class =" mt-3" >
4542 <h5 >{{t('phaseADrafting.botDraft')}}</h5 >
4643 <div class =" techs" >
4744 <div class =" techRow" >
48- <TechCard v-for =" tech of botTechs " :key =" tech " :navigationState =" navigationState " :tech =" tech " class="techCard disabled"/>
45+ <TechCard v-for =" tech of techDraftStep . botTechs " :key =" tech " :navigationState =" navigationState " :tech =" tech " class="techCard disabled"/>
4946 </div >
5047 </div >
5148 </div >
5249 </div >
53-
5450</template >
5551
5652<script lang="ts">
5753import { defineComponent , ref } from ' vue'
5854import { useI18n } from ' vue-i18n'
59- import { useStateStore } from ' @/store/state'
55+ import { TechDraftStep , useStateStore } from ' @/store/state'
6056import NavigationState from ' @/util/NavigationState'
6157import TechCardSelection from ' @/services/TechCardSelection'
6258import Tech from ' @/services/enum/Tech'
@@ -67,6 +63,7 @@ import TechCard from './TechCard.vue'
6763import AppIcon from ' ../structure/AppIcon.vue'
6864import TechCardsPlayerDraft from ' ./TechCardsPlayerDraft.vue'
6965import { useRouter } from ' vue-router'
66+ import { cloneDeep } from ' lodash'
7067
7168export default defineComponent ({
7269 name: ' TechCardDraft' ,
@@ -81,11 +78,18 @@ export default defineComponent({
8178 const router = useRouter ()
8279
8380 const roundData = state .rounds .find (item => item .round == props .navigationState .round )!
84- const botTechs = ref (roundData .botTechs ?? [])
85- const playerTechs = ref (roundData .playerTechs ?? [])
86- const playerSpecialActions = ref (roundData .playerSpecialActions ?? 0 )
81+ const lastTechDraftStep = props .navigationState .lastDraftStep
82+ const techDraftStep = ref ({
83+ round: props .navigationState .round ,
84+ step: props .navigationState .draftingStep ,
85+ nextStartPlayer: lastTechDraftStep ?.nextStartPlayer ,
86+ nextArchitectPlayer: lastTechDraftStep ?.nextArchitectPlayer ,
87+ botTechs: cloneDeep (lastTechDraftStep ?.botTechs ?? []),
88+ playerTechs: cloneDeep (lastTechDraftStep ?.playerTechs ?? []),
89+ playerSpecialActions: lastTechDraftStep ?.playerSpecialActions ?? 0
90+ } as TechDraftStep )
8791
88- return { t , state , router , roundData , botTechs , playerTechs , playerSpecialActions }
92+ return { t , state , router , roundData , techDraftStep }
8993 },
9094 props: {
9195 navigationState: {
@@ -108,22 +112,22 @@ export default defineComponent({
108112 return this .navigationState .techCardSelection
109113 },
110114 botMarkerPlaced() : number {
111- return this .botTechs .length
115+ return this .techDraftStep . botTechs .length
112116 },
113117 playerMarkerPlaced() : number {
114- return this .playerTechs .length + this .playerSpecialActions
118+ return this .techDraftStep . playerTechs .length + this . techDraftStep .playerSpecialActions
115119 },
116120 draftingCompleted() : boolean {
117121 return this .botMarkerPlaced == 4 && this .playerMarkerPlaced == 4
118122 },
119123 playerIncomeTotal() : number {
120- return this .playerTechs .map (tech => this .techCardSelection .getIncome (tech )).filter (value => value < 5 ).reduce ((a ,b ) => a + b , 0 )
124+ return this .techDraftStep . playerTechs .map (tech => this .techCardSelection .getIncome (tech )).filter (value => value < 5 ).reduce ((a ,b ) => a + b , 0 )
121125 },
122126 playerIncomeLockedTotal() : number {
123- return this .playerTechs .map (tech => this .techCardSelection .getIncome (tech )).filter (value => value == 5 ).reduce ((a ,b ) => a + b , 0 )
127+ return this .techDraftStep . playerTechs .map (tech => this .techCardSelection .getIncome (tech )).filter (value => value == 5 ).reduce ((a ,b ) => a + b , 0 )
124128 },
125129 botRound8Army() : boolean {
126- return this .navigationState .round == 8 && this .botTechs .includes (Tech .ARMY )
130+ return this .navigationState .round == 8 && this .techDraftStep . botTechs .includes (Tech .ARMY )
127131 }
128132 },
129133 methods: {
@@ -145,21 +149,15 @@ export default defineComponent({
145149 await new Promise (resolve => setTimeout (resolve , 400 ))
146150 this .removeAnimation = false
147151 this .navigationState .techCardSelection .remove (tech )
148- this .persist ()
149152 },
150153 async nextTurn() {
151154 if (this .draftingCompleted ) {
152155 return
153156 }
154- if (this .botMarkerPlaced < this . playerMarkerPlaced ) {
157+ if (this .roundData . startPlayer == Player . BOT ) {
155158 await this .nextTurnBot ()
156- }
157- else if (this .playerMarkerPlaced < this .botMarkerPlaced ) {
158159 await this .nextTurnPlayer ()
159160 }
160- else if (this .roundData .startPlayer == Player .BOT ) {
161- await this .nextTurnBot ()
162- }
163161 else {
164162 await this .nextTurnPlayer ()
165163 }
@@ -169,15 +167,14 @@ export default defineComponent({
169167 const draftingRowCard = botCards .draftingRow .draw ()
170168 const draftingPriorityCard = botCards .draftingPriority .draw ()
171169 const tech = techCardSelection .determineTech (draftingRowCard , draftingPriorityCard , prosperityCards .current .flat ())
172- this .botTechs .push (tech )
170+ this .techDraftStep . botTechs .push (tech )
173171 if (tech == Tech .ARMY ) {
174- this .roundData .nextStartPlayer = Player .BOT
172+ this .techDraftStep .nextStartPlayer = Player .BOT
175173 }
176174 if (tech == Tech .ENGINEERING ) {
177- this .roundData .nextArchitectPlayer = Player .BOT
175+ this .techDraftStep .nextArchitectPlayer = Player .BOT
178176 }
179177 await this .remove (tech )
180- await this .nextTurn ()
181178 },
182179 async nextTurnPlayer() {
183180 this .playerTurn = true
@@ -191,48 +188,37 @@ export default defineComponent({
191188 return
192189 }
193190 this .playerTurn = false
194- this .playerTechs .push (t )
195- this .roundData .playerTechs = this .playerTechs
191+ this .techDraftStep .playerTechs .push (t )
196192 if (t == Tech .ARMY ) {
197- this .roundData .nextStartPlayer = Player .PLAYER
193+ this .techDraftStep .nextStartPlayer = Player .PLAYER
198194 }
199195 if (t == Tech .ENGINEERING ) {
200- this .roundData .nextArchitectPlayer = Player .PLAYER
196+ this .techDraftStep .nextArchitectPlayer = Player .PLAYER
201197 }
202198 await this .remove (t )
203- await this .nextTurn ()
204- },
205- async reset() {
206- this .techCardSelection .reset ()
207- this .navigationState .botCards .draftingRow .reset ()
208- this .navigationState .botCards .draftingPriority .reset ()
209- this .roundData .nextStartPlayer = undefined
210- this .roundData .nextArchitectPlayer = undefined
211- this .roundData .playerTechs = undefined
212-
213- this .botTechs = []
214- this .playerTechs = []
215- this .playerSpecialActions = 0
216-
217- this .persist ()
218- await this .nextTurn ()
199+ await this .playerTurnCompleted ()
219200 },
220201 async next() {
221202 if (this .draftingCompleted ) {
222203 this .router .push (this .nextButtonRouteTo )
223204 }
224205 else {
225- this .playerSpecialActions ++
206+ this .techDraftStep . playerSpecialActions ++
226207 this .playerTurn = false
227- this .persist ()
228- await this .nextTurn ()
208+ await this .playerTurnCompleted ()
209+ }
210+ },
211+ async playerTurnCompleted() {
212+ // if player was first player, execute bot turn before going to next step
213+ if (this .roundData .startPlayer == Player .PLAYER ) {
214+ await this .nextTurnBot ()
229215 }
216+ this .persistAndNextStep ()
230217 },
231- persist() : void {
232- this .roundData .techCardSelection = this .techCardSelection .toPersistence ()
233- this .roundData .botTechs = this .botTechs
234- this .roundData .playerTechs = this .playerTechs
235- this .roundData .playerSpecialActions = this .playerSpecialActions
218+ persistAndNextStep() : void {
219+ this .techDraftStep .techCardSelection = this .techCardSelection .toPersistence ()
220+ this .state .storeTechDraftStep (this .techDraftStep )
221+ this .router .push (` /round/${this .navigationState .round }/drafting/${this .techDraftStep .step + 1 } ` )
236222 }
237223 },
238224 mounted() {
0 commit comments