add animation for scrap

This commit is contained in:
Alberto Xamin 2023-01-25 15:56:12 +00:00
parent 7c36bd9014
commit 3815cc719f
5 changed files with 48 additions and 22 deletions

View File

@ -88,7 +88,7 @@ class Deck:
card = self.cards.pop(0) card = self.cards.pop(0)
if len(self.cards) == 0: if len(self.cards) == 0:
self.reshuffle() self.reshuffle()
if player is not None: if player is not None and self.game.replay_speed > 0:
G.sio.emit('card_drawn', room=self.game.name, data={'player': player.name, 'pile': 'deck'}) G.sio.emit('card_drawn', room=self.game.name, data={'player': player.name, 'pile': 'deck'})
player.hand.append(card) player.hand.append(card)
return card return card
@ -107,11 +107,13 @@ class Deck:
else: else:
return self.draw() return self.draw()
def scrap(self, card: cs.Card, ignore_event = False): def scrap(self, card: cs.Card, ignore_event = False, player=None):
if card.number == 42: return if card.number == 42: return
card.reset_card() card.reset_card()
if self.game.check_event(ce.MinieraAbbandonata) and not ignore_event: if self.game.check_event(ce.MinieraAbbandonata) and not ignore_event:
self.put_on_top(card) self.put_on_top(card)
else: else:
if player is not None and self.game.replay_speed > 0:
G.sio.emit('card_scrapped', room=self.game.name, data={'player': player.name, 'card':card.__dict__, 'pile': 'scrap'})
self.scrap_pile.append(card) self.scrap_pile.append(card)
self.game.notify_scrap_pile() self.game.notify_scrap_pile()

View File

@ -714,9 +714,9 @@ class Game:
# se lo sceriffo uccide il proprio vice # se lo sceriffo uccide il proprio vice
if player.attacker and player.attacker in self.players and isinstance(player.attacker.role, roles.Sheriff) and isinstance(player.role, roles.Vice): if player.attacker and player.attacker in self.players and isinstance(player.attacker.role, roles.Sheriff) and isinstance(player.role, roles.Vice):
for i in range(len(player.attacker.hand)): for i in range(len(player.attacker.hand)):
self.deck.scrap(player.attacker.hand.pop(), True) self.deck.scrap(player.attacker.hand.pop(), True, player=player.attacker)
for i in range(len(player.attacker.equipment)): for i in range(len(player.attacker.equipment)):
self.deck.scrap(player.attacker.equipment.pop(), True) self.deck.scrap(player.attacker.equipment.pop(), True, player=player.attacker)
for i in range(len(player.attacker.gold_rush_equipment)): for i in range(len(player.attacker.gold_rush_equipment)):
self.deck.shop_deck.append(player.attacker.gold_rush_equipment.pop()) self.deck.shop_deck.append(player.attacker.gold_rush_equipment.pop())
player.attacker.notify_self() player.attacker.notify_self()

View File

@ -616,7 +616,7 @@ class Player:
self.game.deck.draw(player=self) self.game.deck.draw(player=self)
self.game.deck.draw(player=self) self.game.deck.draw(player=self)
self.attacker = None self.attacker = None
self.game.deck.scrap(self.equipment.pop(i), True) self.game.deck.scrap(self.equipment.pop(i), True, player=self)
G.sio.emit('chat_message', room=self.game.name, data=f'_explode|{self.name}') G.sio.emit('chat_message', room=self.game.name, data=f'_explode|{self.name}')
self.heal_if_needed() self.heal_if_needed()
if self.character.check(self.game, chars.BartCassidy) and self.lives > 0: if self.character.check(self.game, chars.BartCassidy) and self.lives > 0:
@ -641,12 +641,12 @@ class Player:
G.sio.emit('chat_message', room=self.game.name, G.sio.emit('chat_message', room=self.game.name,
data=f'_flipped|{self.name}|{picked.name}|{picked.num_suit()}') data=f'_flipped|{self.name}|{picked.name}|{picked.num_suit()}')
if not picked.check_suit(self.game, [cs.Suit.HEARTS]) and pickable_cards == 0: if not picked.check_suit(self.game, [cs.Suit.HEARTS]) and pickable_cards == 0:
self.game.deck.scrap(self.equipment.pop(i), True) self.game.deck.scrap(self.equipment.pop(i), True, player=self)
G.sio.emit('chat_message', room=self.game.name, data=f'_prison_turn|{self.name}') G.sio.emit('chat_message', room=self.game.name, data=f'_prison_turn|{self.name}')
self.end_turn(forced=True) self.end_turn(forced=True)
return return
elif pickable_cards == 0: elif pickable_cards == 0:
self.game.deck.scrap(self.equipment.pop(i), True) self.game.deck.scrap(self.equipment.pop(i), True, player=self)
G.sio.emit('chat_message', room=self.game.name, data=f'_prison_free|{self.name}') G.sio.emit('chat_message', room=self.game.name, data=f'_prison_free|{self.name}')
break break
break break
@ -771,7 +771,7 @@ class Player:
if card.name != "Fantasma" or self.name != target.name: #se si uccide facendo panico su fantasma la carta non gli viene messa in mano if card.name != "Fantasma" or self.name != target.name: #se si uccide facendo panico su fantasma la carta non gli viene messa in mano
self.hand.append(card) self.hand.append(card)
else: else:
self.game.deck.scrap(card, True) self.game.deck.scrap(card, True, player=target)
if self.event_type != 'rissa' or len(self.rissa_targets) == 0: if self.event_type != 'rissa' or len(self.rissa_targets) == 0:
self.event_type = '' self.event_type = ''
self.target_p = '' self.target_p = ''
@ -793,7 +793,7 @@ class Player:
self.notify_self() self.notify_self()
elif self.choose_text == 'choose_sid_scrap': elif self.choose_text == 'choose_sid_scrap':
self.scrapped_cards += 1 self.scrapped_cards += 1
self.game.deck.scrap(self.hand.pop(card_index), True) self.game.deck.scrap(self.hand.pop(card_index), True, player=self)
if self.scrapped_cards == 2: if self.scrapped_cards == 2:
self.available_cards = [] self.available_cards = []
self.pending_action = self.previous_pending_action self.pending_action = self.previous_pending_action
@ -870,7 +870,7 @@ class Player:
self.notify_self() self.notify_self()
elif 'choose_tornado' in self.choose_text: elif 'choose_tornado' in self.choose_text:
if card_index <= len(self.available_cards): if card_index <= len(self.available_cards):
self.game.deck.scrap(self.hand.pop(card_index)) self.game.deck.scrap(self.hand.pop(card_index), player=self)
self.game.deck.draw(player=self) self.game.deck.draw(player=self)
self.game.deck.draw(player=self) self.game.deck.draw(player=self)
self.pending_action = PendingAction.WAIT self.pending_action = PendingAction.WAIT
@ -878,7 +878,7 @@ class Player:
self.notify_self() self.notify_self()
elif 'choose_poker' in self.choose_text: elif 'choose_poker' in self.choose_text:
if card_index <= len(self.available_cards): if card_index <= len(self.available_cards):
self.game.deck.scrap(self.hand.pop(card_index)) self.game.deck.scrap(self.hand.pop(card_index), player=self)
self.pending_action = PendingAction.WAIT self.pending_action = PendingAction.WAIT
self.game.responders_did_respond_resume_turn() self.game.responders_did_respond_resume_turn()
self.notify_self() self.notify_self()
@ -894,7 +894,7 @@ class Player:
elif 'choose_bandidos' in self.choose_text: elif 'choose_bandidos' in self.choose_text:
if card_index < len(self.hand): if card_index < len(self.hand):
self.available_cards.pop(card_index) self.available_cards.pop(card_index)
self.game.deck.scrap(self.hand.pop(card_index)) self.game.deck.scrap(self.hand.pop(card_index), player=self)
self.mancato_needed -= 1 self.mancato_needed -= 1
else: else:
self.lives -= 1 self.lives -= 1
@ -961,7 +961,7 @@ class Player:
if card_index == len(self.available_cards) - 1: if card_index == len(self.available_cards) - 1:
self.hand = [c for c in self.hand if c not in self.discarded_cards] self.hand = [c for c in self.hand if c not in self.discarded_cards]
for i in range(len(self.discarded_cards)): for i in range(len(self.discarded_cards)):
self.game.deck.scrap(self.discarded_cards[i], True) self.game.deck.scrap(self.discarded_cards[i], True, player=self)
self.game.deck.draw(player=self) self.game.deck.draw(player=self)
self.discarded_cards = [] self.discarded_cards = []
self.is_playing_ranch = False self.is_playing_ranch = False
@ -972,7 +972,7 @@ class Player:
elif self.game.dalton_on and self.game.check_event(ceh.IDalton): elif self.game.dalton_on and self.game.check_event(ceh.IDalton):
card = next(c for c in self.equipment if c == self.available_cards[card_index]) card = next(c for c in self.equipment if c == self.available_cards[card_index])
self.equipment.remove(card) self.equipment.remove(card)
self.game.deck.scrap(card, True) self.game.deck.scrap(card, True, player=self)
self.pending_action = PendingAction.WAIT self.pending_action = PendingAction.WAIT
self.notify_self() self.notify_self()
self.game.responders_did_respond_resume_turn() self.game.responders_did_respond_resume_turn()
@ -1216,7 +1216,7 @@ class Player:
self.game.deck.draw(True, player=self) self.game.deck.draw(True, player=self)
self.lives += 1 if not self.character.check(self.game, chd.TequilaJoe) else 2 self.lives += 1 if not self.character.check(self.game, chd.TequilaJoe) else 2
self.lives = min(self.lives, self.max_lives) self.lives = min(self.lives, self.max_lives)
self.game.deck.scrap(self.hand.pop(i), True) self.game.deck.scrap(self.hand.pop(i), True, player=self)
G.sio.emit('chat_message', room=self.game.name, G.sio.emit('chat_message', room=self.game.name,
data=f'_beer_save|{self.name}') data=f'_beer_save|{self.name}')
break break
@ -1243,7 +1243,7 @@ class Player:
self.attacker.notify_self() self.attacker.notify_self()
if len(self.hand) > 0 and any((isinstance(cd, tvosc.Shotgun) for cd in self.attacker.equipment)): if len(self.hand) > 0 and any((isinstance(cd, tvosc.Shotgun) for cd in self.attacker.equipment)):
c = self.hand.pop(randrange(0, len(self.hand))) c = self.hand.pop(randrange(0, len(self.hand)))
self.game.deck.scrap(c, True) self.game.deck.scrap(c, True, player=self)
G.sio.emit('chat_message', room=self.game.name, data=f'_shotgun_scrap|{self.name}|{c.name}') G.sio.emit('chat_message', room=self.game.name, data=f'_shotgun_scrap|{self.name}|{c.name}')
if self.attacker and 'gold_rush' in self.game.expansions: if self.attacker and 'gold_rush' in self.game.expansions:
if (isinstance(self.attacker, Player)): if (isinstance(self.attacker, Player)):
@ -1265,7 +1265,7 @@ class Player:
def take_no_damage_response(self): def take_no_damage_response(self):
if self.dmg_card_index is not None and self.dmg_card_index != -1 and self.game.check_event(ce.Rimbalzo): if self.dmg_card_index is not None and self.dmg_card_index != -1 and self.game.check_event(ce.Rimbalzo):
self.game.deck.scrap(self.equipment.pop(self.dmg_card_index)) self.game.deck.scrap(self.equipment.pop(self.dmg_card_index), player=self)
self.dmg_card_index = -1 self.dmg_card_index = -1
self.mancato_needed = 0 self.mancato_needed = 0
self.expected_response = [] self.expected_response = []
@ -1290,7 +1290,7 @@ class Player:
card.use_card(self) card.use_card(self)
print(f'{self.game.name}: {self.name} responded with {card.name}') print(f'{self.game.name}: {self.name} responded with {card.name}')
G.sio.emit('chat_message', room=self.game.name, data=f'_respond|{self.name}|{card.name}') G.sio.emit('chat_message', room=self.game.name, data=f'_respond|{self.name}|{card.name}')
self.game.deck.scrap(card, True) self.game.deck.scrap(card, True, player=self)
self.notify_self() self.notify_self()
self.mancato_needed -= 1 self.mancato_needed -= 1
if isinstance(card, tvosc.RitornoDiFiamma): if isinstance(card, tvosc.RitornoDiFiamma):
@ -1368,7 +1368,7 @@ class Player:
self.game.deck.draw(True, player=self) self.game.deck.draw(True, player=self)
self.game.deck.draw(True, player=self) self.game.deck.draw(True, player=self)
self.special_use_count += 1 self.special_use_count += 1
self.game.deck.scrap(card) self.game.deck.scrap(card, player=self)
self.notify_self() self.notify_self()
def special(self, data): def special(self, data):

View File

@ -22,7 +22,7 @@
<div class="card back" style="position:absolute; bottom:-1.5pt;right:-1.5pt;"/> <div class="card back" style="position:absolute; bottom:-1.5pt;right:-1.5pt;"/>
<card :card="card" :donotlocalize="true" :class="{back:true, pick:pending_action === 0, draw:pending_action === 1}" @click.native="action"/> <card :card="card" :donotlocalize="true" :class="{back:true, pick:pending_action === 0, draw:pending_action === 1}" @click.native="action"/>
</div> </div>
<div style="position:relative;"> <div style="position:relative;" id="actual-scrap">
<card v-if="previousScrap" :card="previousScrap" style="top: 1.5pt;right: -1.5pt;"/> <card v-if="previousScrap" :card="previousScrap" style="top: 1.5pt;right: -1.5pt;"/>
<card v-else :card="card" class="back" style="opacity:0"/> <card v-else :card="card" class="back" style="opacity:0"/>
<card v-if="lastScrap" :card="lastScrap" :key="lastScrap.name+lastScrap.number" class="last-scrap" @click.native="action('scrap')" <card v-if="lastScrap" :card="lastScrap" :key="lastScrap.name+lastScrap.number" class="last-scrap" @click.native="action('scrap')"

View File

@ -74,7 +74,7 @@
<Card v-if="startGameCard" key="_shuffle_players_" :donotlocalize="true" :card="shufflePlayersCard" @click.native="shufflePlayers" class="fistful-of-cards"/> <Card v-if="startGameCard" key="_shuffle_players_" :donotlocalize="true" :card="shufflePlayersCard" @click.native="shufflePlayers" class="fistful-of-cards"/>
</transition-group> </transition-group>
</div> </div>
<AnimatedCard v-for="c in cardsToAnimate" v-bind:key="c.card.name + c.startPosition" :card="c.card" :startPosition="c.startPosition" :endPosition="c.endPosition"/> <AnimatedCard v-for="c in cardsToAnimate" v-bind:key="c.key" :card="c.card" :startPosition="c.startPosition" :endPosition="c.endPosition"/>
<div v-if="started"> <div v-if="started">
<deck :endTurnAction="()=>{wantsToEndTurn = true}"/> <deck :endTurnAction="()=>{wantsToEndTurn = true}"/>
<player :isEndingTurn="wantsToEndTurn" :cancelEndingTurn="()=>{wantsToEndTurn = false}" :chooseCardFromPlayer="choose" :cancelChooseCardFromPlayer="()=>{hasToChoose=false}"/> <player :isEndingTurn="wantsToEndTurn" :cancelEndingTurn="()=>{wantsToEndTurn = false}" :chooseCardFromPlayer="choose" :cancelChooseCardFromPlayer="()=>{hasToChoose=false}"/>
@ -222,7 +222,6 @@ export default {
this.username = username this.username = username
}, },
card_drawn(data) { card_drawn(data) {
console.log('card_drawn'+data)
let decel = document.getElementById('actual-deck') let decel = document.getElementById('actual-deck')
if (!decel) if (!decel)
return return
@ -234,6 +233,7 @@ export default {
playerOffset.top -= 30 playerOffset.top -= 30
playerOffset.left += 10 playerOffset.left += 10
this.cardsToAnimate.push({ this.cardsToAnimate.push({
key: Math.random(),
card: { card: {
name: 'PewPew!', name: 'PewPew!',
icon: '💥', icon: '💥',
@ -244,6 +244,30 @@ export default {
this.cardsToAnimate.shift() this.cardsToAnimate.shift()
}, 900); }, 900);
}, },
card_scrapped(data) {
let decel = document.getElementById('actual-scrap')
if (!decel) {
console.log('card_scrapped no deck')
return
}
let decelOffset = cumulativeOffset(decel)
let phand = document.getElementById(`${data.player}-hand`)
if (!phand) {
console.log('card_scrapped no phand')
return
}
let playerOffset = cumulativeOffset(phand)
playerOffset.top -= 30
playerOffset.left += 10
console.log('card_scrapped'+decelOffset + ' '+ playerOffset)
this.cardsToAnimate.push({
key: data.card.name+data.card.number+data.player,
card: data.card, startPosition: playerOffset, endPosition: decelOffset
})
setTimeout(() => {
this.cardsToAnimate.shift()
}, 900);
},
mount_status() { mount_status() {
this.displayAdminStatus = true this.displayAdminStatus = true
}, },