From 93a58a719f30093eb1d9d97a5c5b8a09e204c03f Mon Sep 17 00:00:00 2001 From: Andrzej Kapolka Date: Thu, 21 Apr 2005 01:31:08 +0000 Subject: [PATCH] Increase turn durations when players manage not to time out. git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@3517 542714f4-19e9-0310-aa3c-eee0fc999fb1 --- .../server/TrickCardGameManagerDelegate.java | 43 ++++++++++++++++--- 1 file changed, 37 insertions(+), 6 deletions(-) diff --git a/src/java/com/threerings/parlor/card/trick/server/TrickCardGameManagerDelegate.java b/src/java/com/threerings/parlor/card/trick/server/TrickCardGameManagerDelegate.java index a63fe5fa9..6e89bdfaa 100644 --- a/src/java/com/threerings/parlor/card/trick/server/TrickCardGameManagerDelegate.java +++ b/src/java/com/threerings/parlor/card/trick/server/TrickCardGameManagerDelegate.java @@ -143,7 +143,8 @@ public class TrickCardGameManagerDelegate extends TurnGameManagerDelegate { super.startTurn(); - // schedule the timeout interval + // initialize the timeout flag and schedule the timeout interval + _turnTimedOut = false; _turnTimeoutInterval.schedule(_trickCardGame.getTurnDuration()); } @@ -153,6 +154,14 @@ public class TrickCardGameManagerDelegate extends TurnGameManagerDelegate // cancel the timeout interval _turnTimeoutInterval.cancel(); + // reduce or increase the turn duration scale + if (_turnTimedOut) { + reduceTurnDurationScale(_turnIdx); + + } else { + increaseTurnDurationScale(_turnIdx); + } + super.endTurn(); } @@ -268,6 +277,9 @@ public class TrickCardGameManagerDelegate extends TurnGameManagerDelegate throw new InvocationException("m.card_not_playable"); } + // since the player managed to avoid a timeout, increase turn duration + increaseTurnDurationScale(pidx); + // play the card playCard(pidx, card); } @@ -397,14 +409,10 @@ public class TrickCardGameManagerDelegate extends TurnGameManagerDelegate /** * Called when the current turn times out. Default implementation - * reduces the turn duration and plays a random playable card if in the - * trick-playing state. + * plays a random playable card if in the trick-playing state. */ protected void turnTimedOut () { - // reduce turn duration scale - reduceTurnDurationScale(_turnIdx); - if (_trickCardGame.getTrickState() == TrickCardGameObject.PLAYING_TRICK) { playCard(_turnIdx, pickRandomPlayableCard(_hands[_turnIdx])); @@ -424,6 +432,20 @@ public class TrickCardGameManagerDelegate extends TurnGameManagerDelegate } } + /** + * Increases the specified player's turn duration due to avoiding a + * time-out. + */ + protected void increaseTurnDurationScale (int pidx) + { + float oldScale = _trickCardGame.getTurnDurationScales()[pidx], + newScale = Math.min(oldScale + TURN_DURATION_SCALE_INCREASE, + 1.0f); + if (newScale != oldScale) { + _trickCardGame.setTurnDurationScalesAt(newScale, pidx); + } + } + /** * Returns a random playable card from the specified hand. */ @@ -577,10 +599,14 @@ public class TrickCardGameManagerDelegate extends TurnGameManagerDelegate /** The hands of each player. */ protected Hand[] _hands; + /** Whether or not the turn timed out. */ + protected boolean _turnTimedOut; + /** The all-purpose turn timeout interval. */ protected Interval _turnTimeoutInterval = new Interval(PresentsServer.omgr) { public void expired () { + _turnTimedOut = true; turnTimedOut(); } }; @@ -596,6 +622,11 @@ public class TrickCardGameManagerDelegate extends TurnGameManagerDelegate * out. */ protected static final float TURN_DURATION_SCALE_REDUCTION = 0.25f; + /** + * Increase turn duration scales by this amount each time the player + * manages not to time out. */ + protected static final float TURN_DURATION_SCALE_INCREASE = 0.5f; + /** Don't let turn duration scales get below this level. */ protected static final float MINIMUM_TURN_DURATION_SCALE = 0.1f; }