|
402 | 402 | ([state side eid cards {:keys [accessed cause cause-card keep-server-alive game-trash suppress-checkpoint] :as args}] |
403 | 403 | (if (empty? (filter identity cards)) |
404 | 404 | (effect-completed state side eid) |
405 | | - (wait-for (prevent-trash state side (make-eid state eid) cards args) |
406 | | - (let [trashlist async-result |
407 | | - _ (update-current-ice-to-trash state trashlist) |
408 | | - trash-event (get-trash-event side game-trash) |
409 | | - ;; No card should end up in the opponent's discard pile, so instead |
410 | | - ;; of using `side`, we use the card's `:side`. |
411 | | - move-card (fn [card] |
412 | | - (move state (to-keyword (:side card)) card :discard {:keep-server-alive keep-server-alive})) |
413 | | - ;; If the trashed card is installed, update all of the indicies |
414 | | - ;; of the other installed cards in the same location |
415 | | - update-indicies (fn [card] |
416 | | - (when (installed? card) |
417 | | - (update-installed-card-indices state side (:zone card)))) |
418 | | - ;; Perform the move of the cards from their current location to |
419 | | - ;; the discard. At the same time, gather their `:trash-effect`s |
420 | | - ;; to be used in the simult event later. |
421 | | - moved-cards (reduce |
422 | | - (fn [acc card] |
423 | | - (if-let [card (get-card? state card)] |
424 | | - (let [_ (set-duration-on-trash-events state card trash-event) |
425 | | - moved-card (move-card card) |
426 | | - trash-effect (get-trash-effect state side eid card args)] |
427 | | - (update-indicies card) |
428 | | - (conj acc [moved-card trash-effect])) |
429 | | - acc)) |
430 | | - [] |
431 | | - trashlist)] |
432 | | - (swap! state update-in [:trash :trash-list] dissoc eid) |
433 | | - (when (and side (seq (remove #{side} (map #(to-keyword (:side %)) trashlist)))) |
434 | | - (swap! state assoc-in [side :register :trashed-card] true)) |
435 | | - ;; Pseudo-shuffle archives. Keeps seen cards in play order and shuffles unseen cards. |
436 | | - (swap! state assoc-in [:corp :discard] |
437 | | - (vec (sort-by #(if (:seen %) -1 1) (get-in @state [:corp :discard])))) |
438 | | - (let [eid (make-result eid (mapv first moved-cards))] |
439 | | - (doseq [[card trash-effect] moved-cards |
440 | | - :when trash-effect] |
441 | | - (register-pending-event state trash-event card trash-effect)) |
442 | | - (doseq [trashed-card trashlist] |
443 | | - (queue-event state trash-event {:card trashed-card |
444 | | - :cause cause |
445 | | - :cause-card (trim-cause-card cause-card) |
446 | | - :accessed accessed})) |
447 | | - (if suppress-checkpoint |
448 | | - (effect-completed state nil eid) |
449 | | - (checkpoint state nil eid {:duration trash-event})))))))) |
| 405 | + (wait-for |
| 406 | + (prevent-trash state side (make-eid state eid) cards args) |
| 407 | + (let [trashlist async-result |
| 408 | + _ (update-current-ice-to-trash state trashlist)] |
| 409 | + (wait-for |
| 410 | + (trigger-event-sync state side :pre-trash-interrupt trashlist) |
| 411 | + (let [trash-event (get-trash-event side game-trash) |
| 412 | + ;; No card should end up in the opponent's discard pile, so instead |
| 413 | + ;; of using `side`, we use the card's `:side`. |
| 414 | + move-card (fn [card] |
| 415 | + (move state (to-keyword (:side card)) card :discard {:keep-server-alive keep-server-alive})) |
| 416 | + ;; If the trashed card is installed, update all of the indicies |
| 417 | + ;; of the other installed cards in the same location |
| 418 | + update-indicies (fn [card] |
| 419 | + (when (installed? card) |
| 420 | + (update-installed-card-indices state side (:zone card)))) |
| 421 | + ;; Perform the move of the cards from their current location to |
| 422 | + ;; the discard. At the same time, gather their `:trash-effect`s |
| 423 | + ;; to be used in the simult event later. |
| 424 | + moved-cards (reduce |
| 425 | + (fn [acc card] |
| 426 | + (if-let [card (get-card? state card)] |
| 427 | + (let [_ (set-duration-on-trash-events state card trash-event) |
| 428 | + moved-card (move-card card) |
| 429 | + trash-effect (get-trash-effect state side eid card args)] |
| 430 | + (update-indicies card) |
| 431 | + (conj acc {:moved-card moved-card |
| 432 | + :trash-effect trash-effect |
| 433 | + :old-card card})) |
| 434 | + (conj acc {:old-card card}))) |
| 435 | + [] |
| 436 | + trashlist)] |
| 437 | + (swap! state update-in [:trash :trash-list] dissoc eid) |
| 438 | + (when (and side (seq (remove #{side} (map #(to-keyword (:side %)) trashlist)))) |
| 439 | + (swap! state assoc-in [side :register :trashed-card] true)) |
| 440 | + ;; Pseudo-shuffle archives. Keeps seen cards in play order and shuffles unseen cards. |
| 441 | + (swap! state assoc-in [:corp :discard] |
| 442 | + (vec (sort-by #(if (:seen %) -1 1) (get-in @state [:corp :discard])))) |
| 443 | + (let [eid (make-result eid (vec (keep :moved-card moved-cards)))] |
| 444 | + (doseq [{:keys [moved-card trash-effect]} moved-cards |
| 445 | + :when trash-effect] |
| 446 | + (register-pending-event state trash-event moved-card trash-effect)) |
| 447 | + (doseq [{:keys [old-card moved-card]} moved-cards] |
| 448 | + (queue-event state trash-event {:card old-card |
| 449 | + :moved-card moved-card |
| 450 | + :cause cause |
| 451 | + :cause-card (trim-cause-card cause-card) |
| 452 | + :accessed accessed})) |
| 453 | + (if suppress-checkpoint |
| 454 | + (effect-completed state nil eid) |
| 455 | + (checkpoint state nil eid {:duration trash-event})))))))))) |
450 | 456 |
|
451 | 457 | (defmethod engine/move* :trash-cards [state side eid _action cards args] |
452 | 458 | (trash-cards state side eid cards args)) |
|
0 commit comments