Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Donald Haase
Cockatrice
Commits
9c527fb5
Commit
9c527fb5
authored
Jan 15, 2011
by
Max-Wilhelm Bruker
Browse files
Click to hide revealed cards; MultiMove function
parent
f07bb38e
Changes
28
Show whitespace changes
Inline
Side-by-side
common/protocol_items.cpp
View file @
9c527fb5
...
@@ -114,18 +114,6 @@ Command_DrawCards::Command_DrawCards(int _gameId, int _number)
...
@@ -114,18 +114,6 @@ Command_DrawCards::Command_DrawCards(int _gameId, int _number)
{
{
insertItem
(
new
SerializableItem_Int
(
"number"
,
_number
));
insertItem
(
new
SerializableItem_Int
(
"number"
,
_number
));
}
}
Command_MoveCard
::
Command_MoveCard
(
int
_gameId
,
const
QString
&
_startZone
,
int
_cardId
,
int
_targetPlayerId
,
const
QString
&
_targetZone
,
int
_x
,
int
_y
,
bool
_faceDown
,
bool
_tapped
)
:
GameCommand
(
"move_card"
,
_gameId
)
{
insertItem
(
new
SerializableItem_String
(
"start_zone"
,
_startZone
));
insertItem
(
new
SerializableItem_Int
(
"card_id"
,
_cardId
));
insertItem
(
new
SerializableItem_Int
(
"target_player_id"
,
_targetPlayerId
));
insertItem
(
new
SerializableItem_String
(
"target_zone"
,
_targetZone
));
insertItem
(
new
SerializableItem_Int
(
"x"
,
_x
));
insertItem
(
new
SerializableItem_Int
(
"y"
,
_y
));
insertItem
(
new
SerializableItem_Bool
(
"face_down"
,
_faceDown
));
insertItem
(
new
SerializableItem_Bool
(
"tapped"
,
_tapped
));
}
Command_FlipCard
::
Command_FlipCard
(
int
_gameId
,
const
QString
&
_zone
,
int
_cardId
,
bool
_faceDown
)
Command_FlipCard
::
Command_FlipCard
(
int
_gameId
,
const
QString
&
_zone
,
int
_cardId
,
bool
_faceDown
)
:
GameCommand
(
"flip_card"
,
_gameId
)
:
GameCommand
(
"flip_card"
,
_gameId
)
{
{
...
@@ -461,7 +449,6 @@ void ProtocolItem::initializeHashAuto()
...
@@ -461,7 +449,6 @@ void ProtocolItem::initializeHashAuto()
itemNameHash
.
insert
(
"cmdmulligan"
,
Command_Mulligan
::
newItem
);
itemNameHash
.
insert
(
"cmdmulligan"
,
Command_Mulligan
::
newItem
);
itemNameHash
.
insert
(
"cmdroll_die"
,
Command_RollDie
::
newItem
);
itemNameHash
.
insert
(
"cmdroll_die"
,
Command_RollDie
::
newItem
);
itemNameHash
.
insert
(
"cmddraw_cards"
,
Command_DrawCards
::
newItem
);
itemNameHash
.
insert
(
"cmddraw_cards"
,
Command_DrawCards
::
newItem
);
itemNameHash
.
insert
(
"cmdmove_card"
,
Command_MoveCard
::
newItem
);
itemNameHash
.
insert
(
"cmdflip_card"
,
Command_FlipCard
::
newItem
);
itemNameHash
.
insert
(
"cmdflip_card"
,
Command_FlipCard
::
newItem
);
itemNameHash
.
insert
(
"cmdattach_card"
,
Command_AttachCard
::
newItem
);
itemNameHash
.
insert
(
"cmdattach_card"
,
Command_AttachCard
::
newItem
);
itemNameHash
.
insert
(
"cmdcreate_token"
,
Command_CreateToken
::
newItem
);
itemNameHash
.
insert
(
"cmdcreate_token"
,
Command_CreateToken
::
newItem
);
...
...
common/protocol_items.dat
View file @
9c527fb5
...
@@ -20,7 +20,6 @@
...
@@ -20,7 +20,6 @@
2:mulligan
2:mulligan
2:roll_die:i,sides
2:roll_die:i,sides
2:draw_cards:i,number
2:draw_cards:i,number
2:move_card:s,start_zone:i,card_id:i,target_player_id:s,target_zone:i,x:i,y:b,face_down:b,tapped
2:flip_card:s,zone:i,card_id:b,face_down
2:flip_card:s,zone:i,card_id:b,face_down
2:attach_card:s,start_zone:i,card_id:i,target_player_id:s,target_zone:i,target_card_id
2:attach_card:s,start_zone:i,card_id:i,target_player_id:s,target_zone:i,target_card_id
2:create_token:s,zone:s,card_name:s,color:s,pt:s,annotation:b,destroy:i,x:i,y
2:create_token:s,zone:s,card_name:s,color:s,pt:s,annotation:b,destroy:i,x:i,y
...
...
common/protocol_items.h
View file @
9c527fb5
...
@@ -182,21 +182,6 @@ public:
...
@@ -182,21 +182,6 @@ public:
static
SerializableItem
*
newItem
()
{
return
new
Command_DrawCards
;
}
static
SerializableItem
*
newItem
()
{
return
new
Command_DrawCards
;
}
int
getItemId
()
const
{
return
ItemId_Command_DrawCards
;
}
int
getItemId
()
const
{
return
ItemId_Command_DrawCards
;
}
};
};
class
Command_MoveCard
:
public
GameCommand
{
Q_OBJECT
public:
Command_MoveCard
(
int
_gameId
=
-
1
,
const
QString
&
_startZone
=
QString
(),
int
_cardId
=
-
1
,
int
_targetPlayerId
=
-
1
,
const
QString
&
_targetZone
=
QString
(),
int
_x
=
-
1
,
int
_y
=
-
1
,
bool
_faceDown
=
false
,
bool
_tapped
=
false
);
QString
getStartZone
()
const
{
return
static_cast
<
SerializableItem_String
*>
(
itemMap
.
value
(
"start_zone"
))
->
getData
();
};
int
getCardId
()
const
{
return
static_cast
<
SerializableItem_Int
*>
(
itemMap
.
value
(
"card_id"
))
->
getData
();
};
int
getTargetPlayerId
()
const
{
return
static_cast
<
SerializableItem_Int
*>
(
itemMap
.
value
(
"target_player_id"
))
->
getData
();
};
QString
getTargetZone
()
const
{
return
static_cast
<
SerializableItem_String
*>
(
itemMap
.
value
(
"target_zone"
))
->
getData
();
};
int
getX
()
const
{
return
static_cast
<
SerializableItem_Int
*>
(
itemMap
.
value
(
"x"
))
->
getData
();
};
int
getY
()
const
{
return
static_cast
<
SerializableItem_Int
*>
(
itemMap
.
value
(
"y"
))
->
getData
();
};
bool
getFaceDown
()
const
{
return
static_cast
<
SerializableItem_Bool
*>
(
itemMap
.
value
(
"face_down"
))
->
getData
();
};
bool
getTapped
()
const
{
return
static_cast
<
SerializableItem_Bool
*>
(
itemMap
.
value
(
"tapped"
))
->
getData
();
};
static
SerializableItem
*
newItem
()
{
return
new
Command_MoveCard
;
}
int
getItemId
()
const
{
return
ItemId_Command_MoveCard
;
}
};
class
Command_FlipCard
:
public
GameCommand
{
class
Command_FlipCard
:
public
GameCommand
{
Q_OBJECT
Q_OBJECT
public:
public:
...
...
common/server_cardzone.cpp
View file @
9c527fb5
...
@@ -21,6 +21,8 @@
...
@@ -21,6 +21,8 @@
#include
"server_card.h"
#include
"server_card.h"
#include
"server_player.h"
#include
"server_player.h"
#include
"rng_abstract.h"
#include
"rng_abstract.h"
#include
<QSet>
#include
<QDebug>
Server_CardZone
::
Server_CardZone
(
Server_Player
*
_player
,
const
QString
&
_name
,
bool
_has_coords
,
ZoneType
_type
)
Server_CardZone
::
Server_CardZone
(
Server_Player
*
_player
,
const
QString
&
_name
,
bool
_has_coords
,
ZoneType
_type
)
:
player
(
_player
),
name
(
_name
),
has_coords
(
_has_coords
),
type
(
_type
),
cardsBeingLookedAt
(
0
)
:
player
(
_player
),
name
(
_name
),
has_coords
(
_has_coords
),
type
(
_type
),
cardsBeingLookedAt
(
0
)
...
@@ -29,7 +31,7 @@ Server_CardZone::Server_CardZone(Server_Player *_player, const QString &_name, b
...
@@ -29,7 +31,7 @@ Server_CardZone::Server_CardZone(Server_Player *_player, const QString &_name, b
Server_CardZone
::~
Server_CardZone
()
Server_CardZone
::~
Server_CardZone
()
{
{
qDebug
(
QString
(
"Server_CardZone destructor:
%1"
).
arg
(
name
).
toLatin1
())
;
qDebug
(
)
<<
"Server_CardZone destructor:
"
<<
name
;
clear
();
clear
();
}
}
...
@@ -41,6 +43,13 @@ void Server_CardZone::shuffle()
...
@@ -41,6 +43,13 @@ void Server_CardZone::shuffle()
cards
=
temp
;
cards
=
temp
;
}
}
int
Server_CardZone
::
removeCard
(
Server_Card
*
card
)
{
int
index
=
cards
.
indexOf
(
card
);
cards
.
removeAt
(
index
);
return
index
;
}
Server_Card
*
Server_CardZone
::
getCard
(
int
id
,
bool
remove
,
int
*
position
)
Server_Card
*
Server_CardZone
::
getCard
(
int
id
,
bool
remove
,
int
*
position
)
{
{
if
(
type
!=
HiddenZone
)
{
if
(
type
!=
HiddenZone
)
{
...
@@ -146,29 +155,37 @@ bool Server_CardZone::isColumnEmpty(int x, int y) const
...
@@ -146,29 +155,37 @@ bool Server_CardZone::isColumnEmpty(int x, int y) const
void
Server_CardZone
::
moveCard
(
CommandContainer
*
cont
,
QMap
<
int
,
Server_Card
*>
&
coordMap
,
Server_Card
*
card
,
int
x
,
int
y
)
void
Server_CardZone
::
moveCard
(
CommandContainer
*
cont
,
QMap
<
int
,
Server_Card
*>
&
coordMap
,
Server_Card
*
card
,
int
x
,
int
y
)
{
{
coordMap
.
remove
(
card
->
getX
());
coordMap
.
remove
(
card
->
getX
());
player
->
moveCard
(
cont
,
this
,
card
->
getId
(),
this
,
x
,
y
,
card
->
getFaceDown
(),
false
);
player
->
moveCard
(
cont
,
this
,
QList
<
int
>
()
<<
card
->
getId
(),
this
,
x
,
y
,
card
->
getFaceDown
(),
false
);
coordMap
.
insert
(
x
,
card
);
coordMap
.
insert
(
x
,
card
);
}
}
void
Server_CardZone
::
fixFreeSpaces
(
CommandContainer
*
cont
,
int
x
,
int
y
)
void
Server_CardZone
::
fixFreeSpaces
(
CommandContainer
*
cont
)
{
{
QMap
<
int
,
Server_Card
*>
coordMap
;
QMap
<
int
,
Server_Card
*>
coordMap
;
for
(
int
i
=
0
;
i
<
cards
.
size
();
++
i
)
QSet
<
int
>
placesToLook
;
if
(
cards
[
i
]
->
getY
()
==
y
)
for
(
int
i
=
0
;
i
<
cards
.
size
();
++
i
)
{
coordMap
.
insert
(
cards
[
i
]
->
getX
(),
cards
[
i
]);
coordMap
.
insert
(
cards
[
i
]
->
getY
()
*
10000
+
cards
[
i
]
->
getX
(),
cards
[
i
]);
placesToLook
.
insert
(
cards
[
i
]
->
getY
()
*
10000
+
(
cards
[
i
]
->
getX
()
/
3
)
*
3
);
}
int
baseX
=
(
x
/
3
)
*
3
;
QSetIterator
<
int
>
placeIterator
(
placesToLook
);
if
(
!
coordMap
.
contains
(
baseX
))
{
while
(
placeIterator
.
hasNext
())
{
if
(
coordMap
.
contains
(
baseX
+
1
))
int
foo
=
placeIterator
.
next
();
moveCard
(
cont
,
coordMap
,
coordMap
.
value
(
baseX
+
1
),
baseX
,
y
);
int
y
=
foo
/
10000
;
int
baseX
=
foo
-
y
*
10000
;
if
(
!
coordMap
.
contains
(
y
*
10000
+
baseX
))
{
if
(
coordMap
.
contains
(
y
*
10000
+
baseX
+
1
))
moveCard
(
cont
,
coordMap
,
coordMap
.
value
(
y
*
10000
+
baseX
+
1
),
baseX
,
y
);
else
if
(
coordMap
.
contains
(
baseX
+
2
))
{
else
if
(
coordMap
.
contains
(
baseX
+
2
))
{
moveCard
(
cont
,
coordMap
,
coordMap
.
value
(
baseX
+
2
),
baseX
,
y
);
moveCard
(
cont
,
coordMap
,
coordMap
.
value
(
y
*
10000
+
baseX
+
2
),
baseX
,
y
);
return
;
return
;
}
else
}
else
return
;
return
;
}
}
if
(
!
coordMap
.
contains
(
baseX
+
1
)
&&
coordMap
.
contains
(
baseX
+
2
))
if
(
!
coordMap
.
contains
(
y
*
10000
+
baseX
+
1
)
&&
coordMap
.
contains
(
y
*
10000
+
baseX
+
2
))
moveCard
(
cont
,
coordMap
,
coordMap
.
value
(
baseX
+
2
),
baseX
+
1
,
y
);
moveCard
(
cont
,
coordMap
,
coordMap
.
value
(
y
*
10000
+
baseX
+
2
),
baseX
+
1
,
y
);
}
}
}
void
Server_CardZone
::
insertCard
(
Server_Card
*
card
,
int
x
,
int
y
)
void
Server_CardZone
::
insertCard
(
Server_Card
*
card
,
int
x
,
int
y
)
...
...
common/server_cardzone.h
View file @
9c527fb5
...
@@ -40,6 +40,7 @@ public:
...
@@ -40,6 +40,7 @@ public:
Server_CardZone
(
Server_Player
*
_player
,
const
QString
&
_name
,
bool
_has_coords
,
ZoneType
_type
);
Server_CardZone
(
Server_Player
*
_player
,
const
QString
&
_name
,
bool
_has_coords
,
ZoneType
_type
);
~
Server_CardZone
();
~
Server_CardZone
();
int
removeCard
(
Server_Card
*
card
);
Server_Card
*
getCard
(
int
id
,
bool
remove
,
int
*
position
=
NULL
);
Server_Card
*
getCard
(
int
id
,
bool
remove
,
int
*
position
=
NULL
);
int
getCardsBeingLookedAt
()
const
{
return
cardsBeingLookedAt
;
}
int
getCardsBeingLookedAt
()
const
{
return
cardsBeingLookedAt
;
}
...
@@ -52,7 +53,7 @@ public:
...
@@ -52,7 +53,7 @@ public:
int
getFreeGridColumn
(
int
x
,
int
y
,
const
QString
&
cardName
)
const
;
int
getFreeGridColumn
(
int
x
,
int
y
,
const
QString
&
cardName
)
const
;
bool
isColumnEmpty
(
int
x
,
int
y
)
const
;
bool
isColumnEmpty
(
int
x
,
int
y
)
const
;
bool
isColumnStacked
(
int
x
,
int
y
)
const
;
bool
isColumnStacked
(
int
x
,
int
y
)
const
;
void
fixFreeSpaces
(
CommandContainer
*
cont
,
int
x
,
int
y
);
void
fixFreeSpaces
(
CommandContainer
*
cont
);
void
moveCard
(
CommandContainer
*
cont
,
QMap
<
int
,
Server_Card
*>
&
coordMap
,
Server_Card
*
card
,
int
x
,
int
y
);
void
moveCard
(
CommandContainer
*
cont
,
QMap
<
int
,
Server_Card
*>
&
coordMap
,
Server_Card
*
card
,
int
x
,
int
y
);
QList
<
Server_Card
*>
cards
;
QList
<
Server_Card
*>
cards
;
void
insertCard
(
Server_Card
*
card
,
int
x
,
int
y
);
void
insertCard
(
Server_Card
*
card
,
int
x
,
int
y
);
...
...
common/server_player.cpp
View file @
9c527fb5
...
@@ -8,6 +8,7 @@
...
@@ -8,6 +8,7 @@
#include
"protocol.h"
#include
"protocol.h"
#include
"protocol_items.h"
#include
"protocol_items.h"
#include
"decklist.h"
#include
"decklist.h"
#include
<QDebug>
Server_Player
::
Server_Player
(
Server_Game
*
_game
,
int
_playerId
,
ServerInfo_User
*
_userInfo
,
bool
_spectator
,
Server_ProtocolHandler
*
_handler
)
Server_Player
::
Server_Player
(
Server_Game
*
_game
,
int
_playerId
,
ServerInfo_User
*
_userInfo
,
bool
_spectator
,
Server_ProtocolHandler
*
_handler
)
:
game
(
_game
),
handler
(
_handler
),
userInfo
(
new
ServerInfo_User
(
_userInfo
)),
deck
(
0
),
playerId
(
_playerId
),
spectator
(
_spectator
),
nextCardId
(
0
),
readyStart
(
false
),
conceded
(
false
),
deckId
(
-
2
)
:
game
(
_game
),
handler
(
_handler
),
userInfo
(
new
ServerInfo_User
(
_userInfo
)),
deck
(
0
),
playerId
(
_playerId
),
spectator
(
_spectator
),
nextCardId
(
0
),
readyStart
(
false
),
conceded
(
false
),
deckId
(
-
2
)
...
@@ -198,7 +199,7 @@ bool Server_Player::deleteCounter(int counterId)
...
@@ -198,7 +199,7 @@ bool Server_Player::deleteCounter(int counterId)
return
true
;
return
true
;
}
}
ResponseCode
Server_Player
::
moveCard
(
CommandContainer
*
cont
,
const
QString
&
_startZone
,
int
_cardId
,
int
targetPlayerId
,
const
QString
&
_targetZone
,
int
x
,
int
y
,
bool
faceDown
,
bool
tapped
)
ResponseCode
Server_Player
::
moveCard
(
CommandContainer
*
cont
,
const
QString
&
_startZone
,
const
QList
<
int
>
&
_cardId
s
,
int
targetPlayerId
,
const
QString
&
_targetZone
,
int
x
,
int
y
,
bool
faceDown
,
bool
tapped
)
{
{
Server_CardZone
*
startzone
=
getZones
().
value
(
_startZone
);
Server_CardZone
*
startzone
=
getZones
().
value
(
_startZone
);
Server_Player
*
targetPlayer
=
game
->
getPlayers
().
value
(
targetPlayerId
);
Server_Player
*
targetPlayer
=
game
->
getPlayers
().
value
(
targetPlayerId
);
...
@@ -208,24 +209,70 @@ ResponseCode Server_Player::moveCard(CommandContainer *cont, const QString &_sta
...
@@ -208,24 +209,70 @@ ResponseCode Server_Player::moveCard(CommandContainer *cont, const QString &_sta
if
((
!
startzone
)
||
(
!
targetzone
))
if
((
!
startzone
)
||
(
!
targetzone
))
return
RespNameNotFound
;
return
RespNameNotFound
;
return
moveCard
(
cont
,
startzone
,
_cardId
,
targetzone
,
x
,
y
,
faceDown
,
tapped
);
return
moveCard
(
cont
,
startzone
,
_cardId
s
,
targetzone
,
x
,
y
,
faceDown
,
tapped
);
}
}
ResponseCode
Server_Player
::
moveCard
(
CommandContainer
*
cont
,
Server_CardZone
*
startzone
,
int
_cardId
,
Server_CardZone
*
targetzone
,
int
x
,
int
y
,
bool
faceDown
,
bool
tapped
)
class
Server_Player
::
MoveCardCompareFunctor
{
private:
int
x
;
public:
MoveCardCompareFunctor
(
int
_x
)
:
x
(
_x
)
{
}
inline
bool
operator
()(
QPair
<
Server_Card
*
,
int
>
a
,
QPair
<
Server_Card
*
,
int
>
b
)
{
if
(
a
.
second
<
x
)
{
if
(
b
.
second
>=
x
)
return
false
;
else
return
(
a
.
second
>
b
.
second
);
}
else
{
if
(
b
.
second
<
x
)
return
true
;
else
return
(
a
.
second
<
b
.
second
);
}
}
};
ResponseCode
Server_Player
::
moveCard
(
CommandContainer
*
cont
,
Server_CardZone
*
startzone
,
const
QList
<
int
>
&
_cardIds
,
Server_CardZone
*
targetzone
,
int
x
,
int
y
,
bool
faceDown
,
bool
tapped
)
{
{
// Disallow controller change between different zones.
// Disallow controller change between different zones.
if
((
startzone
->
getName
()
!=
targetzone
->
getName
())
&&
(
startzone
->
getPlayer
()
!=
targetzone
->
getPlayer
()))
if
((
startzone
->
getName
()
!=
targetzone
->
getName
())
&&
(
startzone
->
getPlayer
()
!=
targetzone
->
getPlayer
()))
return
RespContextError
;
return
RespContextError
;
int
position
=
-
1
;
if
(
!
targetzone
->
hasCoords
()
&&
(
x
==
-
1
))
Server_Card
*
card
=
startzone
->
getCard
(
_cardId
,
false
,
&
position
);
x
=
targetzone
->
cards
.
size
();
QList
<
QPair
<
Server_Card
*
,
int
>
>
cardsToMove
;
for
(
int
i
=
0
;
i
<
_cardIds
.
size
();
++
i
)
{
int
position
;
Server_Card
*
card
=
startzone
->
getCard
(
_cardIds
[
i
],
false
,
&
position
);
if
(
!
card
)
if
(
!
card
)
return
RespNameNotFound
;
return
RespNameNotFound
;
if
(
!
card
->
getAttachedCards
().
isEmpty
()
&&
!
targetzone
->
isColumnEmpty
(
x
,
y
))
if
(
!
card
->
getAttachedCards
().
isEmpty
()
&&
!
targetzone
->
isColumnEmpty
(
x
,
y
))
return
RespContextError
;
return
RespContextError
;
startzone
->
getCard
(
_cardId
,
true
);
cardsToMove
.
append
(
QPair
<
Server_Card
*
,
int
>
(
card
,
position
));
}
int
oldX
=
card
->
getX
(),
oldY
=
card
->
getY
();
MoveCardCompareFunctor
cmp
(
startzone
==
targetzone
?
-
1
:
x
);
qSort
(
cardsToMove
.
begin
(),
cardsToMove
.
end
(),
cmp
);
bool
secondHalf
=
false
;
int
xIndex
=
-
1
;
for
(
int
cardIndex
=
0
;
cardIndex
<
cardsToMove
.
size
();
++
cardIndex
)
{
Server_Card
*
card
=
cardsToMove
[
cardIndex
].
first
;
int
originalPosition
=
cardsToMove
[
cardIndex
].
second
;
int
position
=
startzone
->
removeCard
(
card
);
if
((
startzone
==
targetzone
)
&&
!
startzone
->
hasCoords
())
{
if
(
!
secondHalf
&&
(
originalPosition
<
x
))
{
xIndex
=
-
1
;
secondHalf
=
true
;
}
else
if
(
secondHalf
)
--
xIndex
;
else
++
xIndex
;
}
else
++
xIndex
;
int
newX
=
x
+
xIndex
;
// Attachment relationships can be retained when moving a card onto the opponent's table
// Attachment relationships can be retained when moving a card onto the opponent's table
if
(
startzone
->
getName
()
!=
targetzone
->
getName
())
{
if
(
startzone
->
getName
()
!=
targetzone
->
getName
())
{
...
@@ -258,24 +305,17 @@ ResponseCode Server_Player::moveCard(CommandContainer *cont, Server_CardZone *st
...
@@ -258,24 +305,17 @@ ResponseCode Server_Player::moveCard(CommandContainer *cont, Server_CardZone *st
if
(
card
->
getDestroyOnZoneChange
()
&&
(
startzone
!=
targetzone
))
{
if
(
card
->
getDestroyOnZoneChange
()
&&
(
startzone
!=
targetzone
))
{
cont
->
enqueueGameEventPrivate
(
new
Event_DestroyCard
(
getPlayerId
(),
startzone
->
getName
(),
card
->
getId
()),
game
->
getGameId
());
cont
->
enqueueGameEventPrivate
(
new
Event_DestroyCard
(
getPlayerId
(),
startzone
->
getName
(),
card
->
getId
()),
game
->
getGameId
());
cont
->
enqueueGameEventPublic
(
new
Event_DestroyCard
(
getPlayerId
(),
startzone
->
getName
(),
card
->
getId
()),
game
->
getGameId
());
cont
->
enqueueGameEventPublic
(
new
Event_DestroyCard
(
getPlayerId
(),
startzone
->
getName
(),
card
->
getId
()),
game
->
getGameId
());
if
(
startzone
->
hasCoords
())
startzone
->
fixFreeSpaces
(
cont
,
oldX
,
oldY
);
card
->
deleteLater
();
card
->
deleteLater
();
return
RespOk
;
}
else
{
}
if
(
!
targetzone
->
hasCoords
())
{
if
(
!
targetzone
->
hasCoords
())
{
y
=
0
;
y
=
0
;
if
(
x
==
-
1
)
x
=
targetzone
->
cards
.
size
();
card
->
resetState
();
card
->
resetState
();
}
else
}
else
x
=
targetzone
->
getFreeGridColumn
(
x
,
y
,
card
->
getName
());
newX
=
targetzone
->
getFreeGridColumn
(
newX
,
y
,
card
->
getName
());
targetzone
->
insertCard
(
card
,
x
,
y
);
targetzone
->
insertCard
(
card
,
newX
,
y
);
bool
targetBeingLookedAt
=
(
targetzone
->
getType
()
!=
HiddenZone
)
||
(
targetzone
->
getCardsBeingLookedAt
()
>
x
)
||
(
targetzone
->
getCardsBeingLookedAt
()
==
-
1
);
bool
targetBeingLookedAt
=
(
targetzone
->
getType
()
!=
HiddenZone
)
||
(
targetzone
->
getCardsBeingLookedAt
()
>
newX
)
||
(
targetzone
->
getCardsBeingLookedAt
()
==
-
1
);
bool
sourceBeingLookedAt
=
(
startzone
->
getType
()
!=
HiddenZone
)
||
(
startzone
->
getCardsBeingLookedAt
()
>
position
)
||
(
startzone
->
getCardsBeingLookedAt
()
==
-
1
);
bool
sourceBeingLookedAt
=
(
startzone
->
getType
()
!=
HiddenZone
)
||
(
startzone
->
getCardsBeingLookedAt
()
>
position
)
||
(
startzone
->
getCardsBeingLookedAt
()
==
-
1
);
bool
targetHiddenToPlayer
=
faceDown
||
!
targetBeingLookedAt
;
bool
targetHiddenToPlayer
=
faceDown
||
!
targetBeingLookedAt
;
...
@@ -306,8 +346,8 @@ ResponseCode Server_Player::moveCard(CommandContainer *cont, Server_CardZone *st
...
@@ -306,8 +346,8 @@ ResponseCode Server_Player::moveCard(CommandContainer *cont, Server_CardZone *st
int
privatePosition
=
-
1
;
int
privatePosition
=
-
1
;
if
(
startzone
->
getType
()
==
HiddenZone
)
if
(
startzone
->
getType
()
==
HiddenZone
)
privatePosition
=
position
;
privatePosition
=
position
;
cont
->
enqueueGameEventPrivate
(
new
Event_MoveCard
(
getPlayerId
(),
privateOldCardId
,
privateCardName
,
startzone
->
getName
(),
privatePosition
,
targetzone
->
getPlayer
()
->
getPlayerId
(),
targetzone
->
getName
(),
x
,
y
,
privateNewCardId
,
faceDown
),
game
->
getGameId
());
cont
->
enqueueGameEventPrivate
(
new
Event_MoveCard
(
getPlayerId
(),
privateOldCardId
,
privateCardName
,
startzone
->
getName
(),
privatePosition
,
targetzone
->
getPlayer
()
->
getPlayerId
(),
targetzone
->
getName
(),
newX
,
y
,
privateNewCardId
,
faceDown
),
game
->
getGameId
());
cont
->
enqueueGameEventOmniscient
(
new
Event_MoveCard
(
getPlayerId
(),
privateOldCardId
,
privateCardName
,
startzone
->
getName
(),
privatePosition
,
targetzone
->
getPlayer
()
->
getPlayerId
(),
targetzone
->
getName
(),
x
,
y
,
privateNewCardId
,
faceDown
),
game
->
getGameId
());
cont
->
enqueueGameEventOmniscient
(
new
Event_MoveCard
(
getPlayerId
(),
privateOldCardId
,
privateCardName
,
startzone
->
getName
(),
privatePosition
,
targetzone
->
getPlayer
()
->
getPlayerId
(),
targetzone
->
getName
(),
newX
,
y
,
privateNewCardId
,
faceDown
),
game
->
getGameId
());
// Other players do not get to see the start and/or target position of the card if the respective
// Other players do not get to see the start and/or target position of the card if the respective
// part of the zone is being looked at. The information is not needed anyway because in hidden zones,
// part of the zone is being looked at. The information is not needed anyway because in hidden zones,
...
@@ -317,19 +357,20 @@ ResponseCode Server_Player::moveCard(CommandContainer *cont, Server_CardZone *st
...
@@ -317,19 +357,20 @@ ResponseCode Server_Player::moveCard(CommandContainer *cont, Server_CardZone *st
||
(
startzone
->
getType
()
==
PublicZone
)
||
(
startzone
->
getType
()
==
PublicZone
)
)
)
position
=
-
1
;
position
=
-
1
;
if
((
targetzone
->
getType
()
==
HiddenZone
)
&&
((
targetzone
->
getCardsBeingLookedAt
()
>
x
)
||
(
targetzone
->
getCardsBeingLookedAt
()
==
-
1
)))
if
((
targetzone
->
getType
()
==
HiddenZone
)
&&
((
targetzone
->
getCardsBeingLookedAt
()
>
newX
)
||
(
targetzone
->
getCardsBeingLookedAt
()
==
-
1
)))
x
=
-
1
;
newX
=
-
1
;
if
((
startzone
->
getType
()
==
PublicZone
)
||
(
targetzone
->
getType
()
==
PublicZone
))
if
((
startzone
->
getType
()
==
PublicZone
)
||
(
targetzone
->
getType
()
==
PublicZone
))
cont
->
enqueueGameEventPublic
(
new
Event_MoveCard
(
getPlayerId
(),
oldCardId
,
publicCardName
,
startzone
->
getName
(),
position
,
targetzone
->
getPlayer
()
->
getPlayerId
(),
targetzone
->
getName
(),
x
,
y
,
card
->
getId
(),
faceDown
),
game
->
getGameId
());
cont
->
enqueueGameEventPublic
(
new
Event_MoveCard
(
getPlayerId
(),
oldCardId
,
publicCardName
,
startzone
->
getName
(),
position
,
targetzone
->
getPlayer
()
->
getPlayerId
(),
targetzone
->
getName
(),
newX
,
y
,
card
->
getId
(),
faceDown
),
game
->
getGameId
());
else
else
cont
->
enqueueGameEventPublic
(
new
Event_MoveCard
(
getPlayerId
(),
-
1
,
QString
(),
startzone
->
getName
(),
position
,
targetzone
->
getPlayer
()
->
getPlayerId
(),
targetzone
->
getName
(),
x
,
y
,
-
1
,
false
),
game
->
getGameId
());
cont
->
enqueueGameEventPublic
(
new
Event_MoveCard
(
getPlayerId
(),
-
1
,
QString
(),
startzone
->
getName
(),
position
,
targetzone
->
getPlayer
()
->
getPlayerId
(),
targetzone
->
getName
(),
newX
,
y
,
-
1
,
false
),
game
->
getGameId
());
if
(
tapped
)
if
(
tapped
)
setCardAttrHelper
(
cont
,
targetzone
->
getName
(),
card
->
getId
(),
"tapped"
,
"1"
);
setCardAttrHelper
(
cont
,
targetzone
->
getName
(),
card
->
getId
(),
"tapped"
,
"1"
);
}
}
if
(
startzone
->
hasCoords
())
if
(
startzone
->
hasCoords
())
startzone
->
fixFreeSpaces
(
cont
,
oldX
,
oldY
);
startzone
->
fixFreeSpaces
(
cont
);
return
RespOk
;
return
RespOk
;
}
}
...
@@ -342,7 +383,7 @@ void Server_Player::unattachCard(CommandContainer *cont, Server_Card *card)
...
@@ -342,7 +383,7 @@ void Server_Player::unattachCard(CommandContainer *cont, Server_Card *card)
cont
->
enqueueGameEventPrivate
(
new
Event_AttachCard
(
getPlayerId
(),
zone
->
getName
(),
card
->
getId
(),
-
1
,
QString
(),
-
1
),
game
->
getGameId
());
cont
->
enqueueGameEventPrivate
(
new
Event_AttachCard
(
getPlayerId
(),
zone
->
getName
(),
card
->
getId
(),
-
1
,
QString
(),
-
1
),
game
->
getGameId
());
cont
->
enqueueGameEventPublic
(
new
Event_AttachCard
(
getPlayerId
(),
zone
->
getName
(),
card
->
getId
(),
-
1
,
QString
(),
-
1
),
game
->
getGameId
());
cont
->
enqueueGameEventPublic
(
new
Event_AttachCard
(
getPlayerId
(),
zone
->
getName
(),
card
->
getId
(),
-
1
,
QString
(),
-
1
),
game
->
getGameId
());
moveCard
(
cont
,
zone
,
card
->
getId
(),
zone
,
-
1
,
card
->
getY
(),
card
->
getFaceDown
(),
card
->
getTapped
());
moveCard
(
cont
,
zone
,
QList
<
int
>
()
<<
card
->
getId
(),
zone
,
-
1
,
card
->
getY
(),
card
->
getFaceDown
(),
card
->
getTapped
());
}
}
ResponseCode
Server_Player
::
setCardAttrHelper
(
CommandContainer
*
cont
,
const
QString
&
zoneName
,
int
cardId
,
const
QString
&
attrName
,
const
QString
&
attrValue
)
ResponseCode
Server_Player
::
setCardAttrHelper
(
CommandContainer
*
cont
,
const
QString
&
zoneName
,
int
cardId
,
const
QString
&
attrName
,
const
QString
&
attrValue
)
...
...
common/server_player.h
View file @
9c527fb5
...
@@ -22,6 +22,7 @@ class CommandContainer;
...
@@ -22,6 +22,7 @@ class CommandContainer;
class
Server_Player
:
public
Server_ArrowTarget
{
class
Server_Player
:
public
Server_ArrowTarget
{
Q_OBJECT
Q_OBJECT
private:
private:
class
MoveCardCompareFunctor
;
Server_Game
*
game
;
Server_Game
*
game
;
Server_ProtocolHandler
*
handler
;
Server_ProtocolHandler
*
handler
;
ServerInfo_User
*
userInfo
;
ServerInfo_User
*
userInfo
;
...
@@ -74,8 +75,8 @@ public:
...
@@ -74,8 +75,8 @@ public:
void
clearZones
();
void
clearZones
();
void
setupZones
();
void
setupZones
();
ResponseCode
moveCard
(
CommandContainer
*
cont
,
const
QString
&
_startZone
,
int
_cardId
,
int
_targetPlayer
,
const
QString
&
_targetZone
,
int
_x
,
int
_y
,
bool
_faceDown
,
bool
_tapped
);
ResponseCode
moveCard
(
CommandContainer
*
cont
,
const
QString
&
_startZone
,
const
QList
<
int
>
&
_cardId
,
int
_targetPlayer
,
const
QString
&
_targetZone
,
int
_x
,
int
_y
,
bool
_faceDown
,
bool
_tapped
);
ResponseCode
moveCard
(
CommandContainer
*
cont
,
Server_CardZone
*
startzone
,
int
_cardId
,
Server_CardZone
*
targetzone
,
int
x
,
int
y
,
bool
faceDown
,
bool
tapped
);
ResponseCode
moveCard
(
CommandContainer
*
cont
,
Server_CardZone
*
startzone
,
const
QList
<
int
>
&
_cardId
,
Server_CardZone
*
targetzone
,
int
x
,
int
y
,
bool
faceDown
,
bool
tapped
);
void
unattachCard
(
CommandContainer
*
cont
,
Server_Card
*
card
);
void
unattachCard
(
CommandContainer
*
cont
,
Server_Card
*
card
);
ResponseCode
setCardAttrHelper
(
CommandContainer
*
cont
,
const
QString
&
zone
,
int
cardId
,
const
QString
&
attrName
,
const
QString
&
attrValue
);
ResponseCode
setCardAttrHelper
(
CommandContainer
*
cont
,
const
QString
&
zone
,
int
cardId
,
const
QString
&
attrName
,
const
QString
&
attrValue
);
...
...
common/server_protocolhandler.cpp
View file @
9c527fb5
...
@@ -483,7 +483,7 @@ ResponseCode Server_ProtocolHandler::cmdMulligan(Command_Mulligan * /*cmd*/, Com
...
@@ -483,7 +483,7 @@ ResponseCode Server_ProtocolHandler::cmdMulligan(Command_Mulligan * /*cmd*/, Com
Server_CardZone
*
deck
=
player
->
getZones
().
value
(
"deck"
);
Server_CardZone
*
deck
=
player
->
getZones
().
value
(
"deck"
);
while
(
!
hand
->
cards
.
isEmpty
())
while
(
!
hand
->
cards
.
isEmpty
())
player
->
moveCard
(
cont
,
hand
,
hand
->
cards
.
first
()
->
getId
(),
deck
,
0
,
0
,
false
,
false
);
player
->
moveCard
(
cont
,
hand
,
QList
<
int
>
()
<<
hand
->
cards
.
first
()
->
getId
(),
deck
,
0
,
0
,
false
,
false
);
deck
->
shuffle
();
deck
->
shuffle
();
cont
->
enqueueGameEventPrivate
(
new
Event_Shuffle
(
player
->
getPlayerId
()),
game
->
getGameId
());
cont
->
enqueueGameEventPrivate
(
new
Event_Shuffle
(
player
->
getPlayerId
()),
game
->
getGameId
());
...
@@ -546,7 +546,12 @@ ResponseCode Server_ProtocolHandler::cmdMoveCard(Command_MoveCard *cmd, CommandC
...
@@ -546,7 +546,12 @@ ResponseCode Server_ProtocolHandler::cmdMoveCard(Command_MoveCard *cmd, CommandC
if
(
!
game
->
getGameStarted
())
if
(
!
game
->
getGameStarted
())
return
RespGameNotStarted
;
return
RespGameNotStarted
;
return
player
->
moveCard
(
cont
,
cmd
->
getStartZone
(),
cmd
->
getCardId
(),
cmd
->
getTargetPlayerId
(),
cmd
->
getTargetZone
(),
cmd
->
getX
(),
cmd
->
getY
(),
cmd
->
getFaceDown
(),
cmd
->
getTapped
());
QList
<
int
>
cardIds
;
const
QList
<
CardId
*>
&
temp
=
cmd
->
getCardIds
();
for
(
int
i
=
0
;
i
<
temp
.
size
();
++
i
)
cardIds
.
append
(
temp
[
i
]
->
getData
());
return
player
->
moveCard
(
cont
,
cmd
->
getStartZone
(),
cardIds
,
cmd
->
getTargetPlayerId
(),
cmd
->
getTargetZone
(),
cmd
->
getX
(),
cmd
->
getY
(),
cmd
->
getFaceDown
(),
cmd
->
getTapped
());
}
}
ResponseCode
Server_ProtocolHandler
::
cmdFlipCard
(
Command_FlipCard
*
cmd
,
CommandContainer
*
cont
,
Server_Game
*
game
,
Server_Player
*
player
)
ResponseCode
Server_ProtocolHandler
::
cmdFlipCard
(
Command_FlipCard
*
cmd
,
CommandContainer
*
cont
,
Server_Game
*
game
,
Server_Player
*
player
)
...
@@ -646,7 +651,7 @@ ResponseCode Server_ProtocolHandler::cmdAttachCard(Command_AttachCard *cmd, Comm
...
@@ -646,7 +651,7 @@ ResponseCode Server_ProtocolHandler::cmdAttachCard(Command_AttachCard *cmd, Comm
player
->
unattachCard
(
cont
,
attachedList
[
i
]);
player
->
unattachCard
(
cont
,
attachedList
[
i
]);
if
(
targetzone
->
isColumnStacked
(
targetCard
->
getX
(),
targetCard
->
getY
()))
if
(
targetzone
->
isColumnStacked
(
targetCard
->
getX
(),
targetCard
->
getY
()))
targetPlayer
->
moveCard
(
cont
,
targetzone
,
targetCard
->
getId
(),
targetzone
,
targetzone
->
getFreeGridColumn
(
-
2
,
targetCard
->
getY
(),
targetCard
->
getName
()),
targetCard
->
getY
(),
targetCard
->
getFaceDown
(),
false
);
targetPlayer
->
moveCard
(
cont
,
targetzone
,
QList
<
int
>
()
<<
targetCard
->
getId
(),
targetzone
,
targetzone
->
getFreeGridColumn
(
-
2
,
targetCard
->
getY
(),
targetCard
->
getName
()),
targetCard
->
getY
(),
targetCard
->
getFaceDown
(),
false
);
card
->
setParentCard
(
targetCard
);
card
->
setParentCard
(
targetCard
);
card
->
setCoords
(
-
1
,
card
->
getY
());
card
->
setCoords
(
-
1
,
card
->
getY
());
...
...
Prev
1
2
Next
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment