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)
|
||||
{
|
||||
// Notify the sender that the cards have been taken
|
||||
CardGameSender.sentCardsToPlayer(getClientObject(fromPlayerIdx),
|
||||
toPlayerIdx, cards);
|
||||
ClientObject fromClient = getClientObject(fromPlayerIdx);
|
||||
if (fromClient != null) {
|
||||
CardGameSender.sentCardsToPlayer(fromClient, toPlayerIdx, cards);
|
||||
}
|
||||
|
||||
// Notify the receiver with the cards
|
||||
CardGameSender.sendCardsFromPlayer(getClientObject(toPlayerIdx),
|
||||
fromPlayerIdx, cards);
|
||||
ClientObject toClient = getClientObject(toPlayerIdx);
|
||||
if (toClient != null) {
|
||||
CardGameSender.sendCardsFromPlayer(toClient, fromPlayerIdx,
|
||||
cards);
|
||||
}
|
||||
|
||||
// and everybody else in the room other than the sender and the
|
||||
// receiver with the number of cards sent
|
||||
@@ -203,14 +208,19 @@ public class CardGameManager extends GameManager
|
||||
{
|
||||
// Send all removal notices
|
||||
for (int i = 0; i < _playerCount; i++) {
|
||||
CardGameSender.sentCardsToPlayer(getClientObject(i),
|
||||
toPlayerIndices[i], cards[i]);
|
||||
ClientObject fromClient = getClientObject(i);
|
||||
if (fromClient != null) {
|
||||
CardGameSender.sentCardsToPlayer(fromClient,
|
||||
toPlayerIndices[i], cards[i]);
|
||||
}
|
||||
}
|
||||
|
||||
// Send all addition notices and notify everyone else
|
||||
for (int i = 0; i < _playerCount; i++) {
|
||||
CardGameSender.sendCardsFromPlayer(
|
||||
getClientObject(toPlayerIndices[i]), i, cards[i]);
|
||||
ClientObject toClient = getClientObject(toPlayerIndices[i]);
|
||||
if (toClient != null) {
|
||||
CardGameSender.sendCardsFromPlayer(toClient, i, cards[i]);
|
||||
}
|
||||
notifyCardsTransferred(i, toPlayerIndices[i], cards[i].length);
|
||||
}
|
||||
}
|
||||
@@ -232,9 +242,12 @@ public class CardGameManager extends GameManager
|
||||
public void apply (OccupantInfo info) {
|
||||
int oid = info.getBodyOid();
|
||||
if (oid != senderOid && oid != receiverOid) {
|
||||
CardGameSender.cardsTransferredBetweenPlayers(
|
||||
(ClientObject)PresentsServer.omgr.getObject(
|
||||
oid), fromPlayerIdx, toPlayerIdx, cards);
|
||||
ClientObject client =
|
||||
(ClientObject)PresentsServer.omgr.getObject(oid);
|
||||
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.
|
||||
* Default implementation verifies that the user's hand contains the
|
||||
* specified cards, then transfers the cards (letting everyone know
|
||||
* that the transfer has taken place).
|
||||
* specified cards, then calls {@link #sendCardsToPlayer(int, int,
|
||||
* Card[])}.
|
||||
*/
|
||||
public void sendCardsToPlayer (ClientObject client, int toidx,
|
||||
Card[] cards)
|
||||
@@ -215,6 +215,18 @@ public class TrickCardGameManagerDelegate extends TurnGameManagerDelegate
|
||||
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
|
||||
_hands[fromidx].removeAll(cards);
|
||||
|
||||
@@ -250,6 +262,15 @@ public class TrickCardGameManagerDelegate extends TurnGameManagerDelegate
|
||||
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
|
||||
// of the cards played array
|
||||
_hands[pidx].remove(card);
|
||||
@@ -388,15 +409,7 @@ public class TrickCardGameManagerDelegate extends TurnGameManagerDelegate
|
||||
TrickCardGameObject.PLAYING_TRICK) {
|
||||
int pidx = _cardGame.getPlayerIndex(
|
||||
_trickCardGame.getTurnHolder());
|
||||
Card card = 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);
|
||||
}
|
||||
playCard(pidx, pickRandomPlayableCard(_hands[pidx]));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user