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" >
4037 <div v-if =" playerTechs.length > 0" class =" mt-3" >
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,21 @@ 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 = roundData .techDraftSteps ?.find (item => item .step == props .navigationState .draftingStep - 1 )
82+ const botTechs = ref (lastTechDraftStep ?.botTechs ?? [])
83+ const playerTechs = ref (lastTechDraftStep ?.playerTechs ?? [])
84+ const playerSpecialActions = ref (lastTechDraftStep ?.playerSpecialActions ?? 0 )
85+ const techDraftStep = ref ({
86+ round: props .navigationState .round ,
87+ step: props .navigationState .draftingStep ,
88+ nextStartPlayer: lastTechDraftStep ?.nextStartPlayer ,
89+ nextArchitectPlayer: lastTechDraftStep ?.nextArchitectPlayer ,
90+ botTechs: cloneDeep (lastTechDraftStep ?.botTechs ?? []),
91+ playerTechs: cloneDeep (lastTechDraftStep ?.playerTechs ?? []),
92+ playerSpecialActions: lastTechDraftStep ?.playerSpecialActions ?? 0
93+ } as TechDraftStep )
8794
88- return { t , state , router , roundData , botTechs , playerTechs , playerSpecialActions }
95+ return { t , state , router , roundData , techDraftStep , botTechs , playerTechs , playerSpecialActions }
8996 },
9097 props: {
9198 navigationState: {
@@ -145,21 +152,22 @@ export default defineComponent({
145152 await new Promise (resolve => setTimeout (resolve , 400 ))
146153 this .removeAnimation = false
147154 this .navigationState .techCardSelection .remove (tech )
148- this .persist ()
149155 },
150156 async nextTurn() {
151157 if (this .draftingCompleted ) {
152158 return
153159 }
154160 if (this .botMarkerPlaced < this .playerMarkerPlaced ) {
155161 await this .nextTurnBot ()
162+ await this .nextTurn ()
156163 }
157164 else if (this .playerMarkerPlaced < this .botMarkerPlaced ) {
158165 await this .nextTurnPlayer ()
159166 }
160167 else if (this .roundData .startPlayer == Player .BOT ) {
161168 await this .nextTurnBot ()
162- }
169+ await this .nextTurn ()
170+ }
163171 else {
164172 await this .nextTurnPlayer ()
165173 }
@@ -171,13 +179,12 @@ export default defineComponent({
171179 const tech = techCardSelection .determineTech (draftingRowCard , draftingPriorityCard , prosperityCards .current .flat ())
172180 this .botTechs .push (tech )
173181 if (tech == Tech .ARMY ) {
174- this .roundData .nextStartPlayer = Player .BOT
182+ this .techDraftStep .nextStartPlayer = Player .BOT
175183 }
176184 if (tech == Tech .ENGINEERING ) {
177- this .roundData .nextArchitectPlayer = Player .BOT
185+ this .techDraftStep .nextArchitectPlayer = Player .BOT
178186 }
179187 await this .remove (tech )
180- await this .nextTurn ()
181188 },
182189 async nextTurnPlayer() {
183190 this .playerTurn = true
@@ -192,30 +199,15 @@ export default defineComponent({
192199 }
193200 this .playerTurn = false
194201 this .playerTechs .push (t )
195- this .roundData .playerTechs = this .playerTechs
202+ this .techDraftStep .playerTechs = this .playerTechs
196203 if (t == Tech .ARMY ) {
197- this .roundData .nextStartPlayer = Player .PLAYER
204+ this .techDraftStep .nextStartPlayer = Player .PLAYER
198205 }
199206 if (t == Tech .ENGINEERING ) {
200- this .roundData .nextArchitectPlayer = Player .PLAYER
207+ this .techDraftStep .nextArchitectPlayer = Player .PLAYER
201208 }
202209 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 ()
210+ await this .playerTurnCompleted ()
219211 },
220212 async next() {
221213 if (this .draftingCompleted ) {
@@ -224,15 +216,23 @@ export default defineComponent({
224216 else {
225217 this .playerSpecialActions ++
226218 this .playerTurn = false
227- this .persist ()
228- await this .nextTurn ()
219+ await this .playerTurnCompleted ()
220+ }
221+ },
222+ async playerTurnCompleted() {
223+ // if player was first player, execute bot turn before going to next step
224+ if (this .roundData .startPlayer == Player .PLAYER ) {
225+ await this .nextTurnBot ()
229226 }
227+ this .persistAndNextStep ()
230228 },
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
229+ persistAndNextStep() : void {
230+ this .techDraftStep .techCardSelection = this .techCardSelection .toPersistence ()
231+ this .techDraftStep .botTechs = this .botTechs
232+ this .techDraftStep .playerTechs = this .playerTechs
233+ this .techDraftStep .playerSpecialActions = this .playerSpecialActions
234+ this .state .storeTechDraftStep (this .techDraftStep )
235+ this .router .push (` /round/${this .navigationState .round }/drafting/${this .techDraftStep .step + 1 } ` )
236236 }
237237 },
238238 mounted() {
0 commit comments