Added extra methods to support AIs.
git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@3506 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
@@ -176,12 +176,17 @@ public class CardGameManager extends GameManager
|
|||||||
int toPlayerIdx, Card[] cards)
|
int toPlayerIdx, Card[] cards)
|
||||||
{
|
{
|
||||||
// Notify the sender that the cards have been taken
|
// Notify the sender that the cards have been taken
|
||||||
CardGameSender.sentCardsToPlayer(getClientObject(fromPlayerIdx),
|
ClientObject fromClient = getClientObject(fromPlayerIdx);
|
||||||
toPlayerIdx, cards);
|
if (fromClient != null) {
|
||||||
|
CardGameSender.sentCardsToPlayer(fromClient, toPlayerIdx, cards);
|
||||||
|
}
|
||||||
|
|
||||||
// Notify the receiver with the cards
|
// Notify the receiver with the cards
|
||||||
CardGameSender.sendCardsFromPlayer(getClientObject(toPlayerIdx),
|
ClientObject toClient = getClientObject(toPlayerIdx);
|
||||||
fromPlayerIdx, cards);
|
if (toClient != null) {
|
||||||
|
CardGameSender.sendCardsFromPlayer(toClient, fromPlayerIdx,
|
||||||
|
cards);
|
||||||
|
}
|
||||||
|
|
||||||
// and everybody else in the room other than the sender and the
|
// and everybody else in the room other than the sender and the
|
||||||
// receiver with the number of cards sent
|
// receiver with the number of cards sent
|
||||||
@@ -203,14 +208,19 @@ public class CardGameManager extends GameManager
|
|||||||
{
|
{
|
||||||
// Send all removal notices
|
// Send all removal notices
|
||||||
for (int i = 0; i < _playerCount; i++) {
|
for (int i = 0; i < _playerCount; i++) {
|
||||||
CardGameSender.sentCardsToPlayer(getClientObject(i),
|
ClientObject fromClient = getClientObject(i);
|
||||||
toPlayerIndices[i], cards[i]);
|
if (fromClient != null) {
|
||||||
|
CardGameSender.sentCardsToPlayer(fromClient,
|
||||||
|
toPlayerIndices[i], cards[i]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Send all addition notices and notify everyone else
|
// Send all addition notices and notify everyone else
|
||||||
for (int i = 0; i < _playerCount; i++) {
|
for (int i = 0; i < _playerCount; i++) {
|
||||||
CardGameSender.sendCardsFromPlayer(
|
ClientObject toClient = getClientObject(toPlayerIndices[i]);
|
||||||
getClientObject(toPlayerIndices[i]), i, cards[i]);
|
if (toClient != null) {
|
||||||
|
CardGameSender.sendCardsFromPlayer(toClient, i, cards[i]);
|
||||||
|
}
|
||||||
notifyCardsTransferred(i, toPlayerIndices[i], cards[i].length);
|
notifyCardsTransferred(i, toPlayerIndices[i], cards[i].length);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -232,9 +242,12 @@ public class CardGameManager extends GameManager
|
|||||||
public void apply (OccupantInfo info) {
|
public void apply (OccupantInfo info) {
|
||||||
int oid = info.getBodyOid();
|
int oid = info.getBodyOid();
|
||||||
if (oid != senderOid && oid != receiverOid) {
|
if (oid != senderOid && oid != receiverOid) {
|
||||||
CardGameSender.cardsTransferredBetweenPlayers(
|
ClientObject client =
|
||||||
(ClientObject)PresentsServer.omgr.getObject(
|
(ClientObject)PresentsServer.omgr.getObject(oid);
|
||||||
oid), fromPlayerIdx, toPlayerIdx, cards);
|
if (client != null) {
|
||||||
|
CardGameSender.cardsTransferredBetweenPlayers(client,
|
||||||
|
fromPlayerIdx, toPlayerIdx, cards);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
+24
-11
@@ -197,8 +197,8 @@ public class TrickCardGameManagerDelegate extends TurnGameManagerDelegate
|
|||||||
/**
|
/**
|
||||||
* Processes a request to transfer a group of cards between players.
|
* Processes a request to transfer a group of cards between players.
|
||||||
* Default implementation verifies that the user's hand contains the
|
* Default implementation verifies that the user's hand contains the
|
||||||
* specified cards, then transfers the cards (letting everyone know
|
* specified cards, then calls {@link #sendCardsToPlayer(int, int,
|
||||||
* that the transfer has taken place).
|
* Card[])}.
|
||||||
*/
|
*/
|
||||||
public void sendCardsToPlayer (ClientObject client, int toidx,
|
public void sendCardsToPlayer (ClientObject client, int toidx,
|
||||||
Card[] cards)
|
Card[] cards)
|
||||||
@@ -215,6 +215,18 @@ public class TrickCardGameManagerDelegate extends TurnGameManagerDelegate
|
|||||||
throw new InvocationException("m.not_holding_card");
|
throw new InvocationException("m.not_holding_card");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// send the cards
|
||||||
|
sendCardsToPlayer(fromidx, toidx, cards);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sends cards between players without error checking. Default
|
||||||
|
* implementation transfers the cards between hands and notifies
|
||||||
|
* everyone of the transfer using {@link
|
||||||
|
* CardGameManager#transferCardsBetweenPlayers(int, int, Card[])}.
|
||||||
|
*/
|
||||||
|
protected void sendCardsToPlayer (int fromidx, int toidx, Card[] cards)
|
||||||
|
{
|
||||||
// remove from sending player's hand
|
// remove from sending player's hand
|
||||||
_hands[fromidx].removeAll(cards);
|
_hands[fromidx].removeAll(cards);
|
||||||
|
|
||||||
@@ -250,6 +262,15 @@ public class TrickCardGameManagerDelegate extends TurnGameManagerDelegate
|
|||||||
throw new InvocationException("m.card_not_playable");
|
throw new InvocationException("m.card_not_playable");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// play the card
|
||||||
|
playCard(pidx, card);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Plays a card for a player without error checking.
|
||||||
|
*/
|
||||||
|
protected void playCard (int pidx, Card card)
|
||||||
|
{
|
||||||
// play the card by removing it from the hand and adding it to the end
|
// play the card by removing it from the hand and adding it to the end
|
||||||
// of the cards played array
|
// of the cards played array
|
||||||
_hands[pidx].remove(card);
|
_hands[pidx].remove(card);
|
||||||
@@ -388,15 +409,7 @@ public class TrickCardGameManagerDelegate extends TurnGameManagerDelegate
|
|||||||
TrickCardGameObject.PLAYING_TRICK) {
|
TrickCardGameObject.PLAYING_TRICK) {
|
||||||
int pidx = _cardGame.getPlayerIndex(
|
int pidx = _cardGame.getPlayerIndex(
|
||||||
_trickCardGame.getTurnHolder());
|
_trickCardGame.getTurnHolder());
|
||||||
Card card = pickRandomPlayableCard(_hands[pidx]);
|
playCard(pidx, pickRandomPlayableCard(_hands[pidx]));
|
||||||
try {
|
|
||||||
playCard(_cgmgr.getClientObject(pidx), card);
|
|
||||||
|
|
||||||
} catch (InvocationException ie) {
|
|
||||||
Log.warning("Couldn't play card [card=" + card + ", hand=" +
|
|
||||||
_hands[pidx] + "].");
|
|
||||||
Log.logStackTrace(ie);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user