mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-11-08 19:13:25 -08:00
[Refactor] Build arrow and attach commands in game/ instead of ArrowItem
This commit is contained in:
parent
ca6f561297
commit
8029310764
4 changed files with 88 additions and 51 deletions
|
|
@ -5,6 +5,7 @@
|
|||
#include "../../game_graphics/dialogs/dlg_create_token.h"
|
||||
#include "../../interface/deck_loader/loaded_deck.h"
|
||||
#include "../abstract_game.h"
|
||||
#include "../board/arrow_data.h"
|
||||
#include "../board/counter_state.h"
|
||||
#include "../game_event_handler.h"
|
||||
#include "../zones/card_zone_logic.h"
|
||||
|
|
@ -48,6 +49,7 @@
|
|||
#include <libcockatrice/card/relation/card_relation.h>
|
||||
#include <libcockatrice/protocol/pb/command_attach_card.pb.h>
|
||||
#include <libcockatrice/protocol/pb/command_change_zone_properties.pb.h>
|
||||
#include <libcockatrice/protocol/pb/command_create_arrow.pb.h>
|
||||
#include <libcockatrice/protocol/pb/command_create_token.pb.h>
|
||||
#include <libcockatrice/protocol/pb/command_draw_cards.pb.h>
|
||||
#include <libcockatrice/protocol/pb/command_dump_zone.pb.h>
|
||||
|
|
@ -66,6 +68,7 @@
|
|||
#include <libcockatrice/settings/card_override_settings.h>
|
||||
#include <libcockatrice/settings/interface_settings.h>
|
||||
#include <libcockatrice/utility/clamped_arithmetic.h>
|
||||
#include <libcockatrice/utility/color.h>
|
||||
#include <libcockatrice/utility/counter_limits.h>
|
||||
#include <libcockatrice/utility/expression.h>
|
||||
#include <libcockatrice/utility/zone_names.h>
|
||||
|
|
@ -174,6 +177,60 @@ void PlayerActions::playCardToTable(const CardItem *card, bool faceDown)
|
|||
sendGameCommand(cmd);
|
||||
}
|
||||
|
||||
void PlayerActions::attachCards(CardItem *startCard, const CardItem *targetCard)
|
||||
{
|
||||
if (targetCard->getAttachedTo() || targetCard->getZone()->getName() != ZoneNames::TABLE) {
|
||||
return;
|
||||
}
|
||||
|
||||
// move card onto table first if attaching from some other zone
|
||||
if (startCard->getZone()->getName() != ZoneNames::TABLE) {
|
||||
playCardToTable(startCard, false);
|
||||
}
|
||||
|
||||
Command_AttachCard cmd;
|
||||
cmd.set_start_zone(ZoneNames::TABLE);
|
||||
cmd.set_card_id(startCard->getId());
|
||||
cmd.set_target_player_id(targetCard->getZone()->getPlayer()->getPlayerInfo()->getId());
|
||||
cmd.set_target_zone(targetCard->getZone()->getName().toStdString());
|
||||
cmd.set_target_card_id(targetCard->getId());
|
||||
sendGameCommand(cmd);
|
||||
}
|
||||
|
||||
void PlayerActions::createArrow(CardItem *startCard, const ArrowData &arrow, int deleteInPhase)
|
||||
{
|
||||
Command_CreateArrow cmd;
|
||||
cmd.mutable_arrow_color()->CopyFrom(convertQColorToColor(arrow.color));
|
||||
cmd.set_start_player_id(arrow.startPlayerId);
|
||||
cmd.set_start_zone(arrow.startZone.toStdString());
|
||||
cmd.set_start_card_id(arrow.startCardId);
|
||||
cmd.set_target_player_id(arrow.targetPlayerId);
|
||||
|
||||
if (!arrow.isPlayerTargeted()) {
|
||||
cmd.set_target_zone(arrow.targetZone.toStdString());
|
||||
cmd.set_target_card_id(arrow.targetCardId);
|
||||
}
|
||||
|
||||
// if the card is in hand then it has just been moved to the stack or table as part of drawing the arrow
|
||||
if (arrow.startZone == ZoneNames::HAND) {
|
||||
CardInfoPtr ci = startCard->getCard().getCardPtr();
|
||||
bool playToStack = SettingsCache::instance().userInterface().getPlayToStack();
|
||||
if (ci && ((!playToStack && ci->getUiAttributes().tableRow == 3) ||
|
||||
(playToStack && ci->getUiAttributes().tableRow != 0 &&
|
||||
startCard->getZone()->getName() != ZoneNames::STACK))) {
|
||||
cmd.set_start_zone(ZoneNames::STACK);
|
||||
} else {
|
||||
cmd.set_start_zone(playToStack ? ZoneNames::STACK : ZoneNames::TABLE);
|
||||
}
|
||||
}
|
||||
|
||||
if (deleteInPhase != 0) {
|
||||
cmd.set_delete_in_phase(deleteInPhase);
|
||||
}
|
||||
|
||||
sendGameCommand(cmd);
|
||||
}
|
||||
|
||||
void PlayerActions::actViewLibrary()
|
||||
{
|
||||
emit requestZoneViewToggle(ZoneNames::DECK, -1);
|
||||
|
|
|
|||
|
|
@ -41,7 +41,7 @@ class CardZoneLogic;
|
|||
class Command_MoveCard;
|
||||
class PendingCommand;
|
||||
class PlayerLogic;
|
||||
|
||||
struct ArrowData;
|
||||
class PlayerActions : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
|
@ -86,6 +86,25 @@ public:
|
|||
*/
|
||||
void actToggleTapped(const QString &zoneName, const QList<CardItem *> &cards, bool tapped);
|
||||
|
||||
/**
|
||||
* @brief Attaches one card to another on the table on behalf of a view.
|
||||
* @param startCard Card being attached.
|
||||
* @param targetCard Card being attached to.
|
||||
*/
|
||||
void attachCards(CardItem *startCard, const CardItem *targetCard);
|
||||
|
||||
/**
|
||||
* @brief Draws an arrow from a card to another card or a player on behalf of a view.
|
||||
*
|
||||
* The view resolves the endpoints before playing the card out of hand, so the
|
||||
* arrow still records the zone the card started in.
|
||||
*
|
||||
* @param startCard Card the arrow starts from.
|
||||
* @param arrow Arrow endpoints and color, as resolved by the view.
|
||||
* @param deleteInPhase Phase the arrow expires in, 0 to keep it until removed.
|
||||
*/
|
||||
void createArrow(CardItem *startCard, const ArrowData &arrow, int deleteInPhase);
|
||||
|
||||
void moveOneCardUntil(CardItem *card);
|
||||
void stopMoveTopCardsUntil();
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue