37
37
import mage .players .Player ;
38
38
import mage .players .PlayerImpl ;
39
39
import mage .players .PlayerList ;
40
+ import mage .players .net .UserData ;
40
41
import mage .target .Target ;
41
42
import mage .target .TargetAmount ;
42
43
import mage .target .TargetCard ;
@@ -93,7 +94,7 @@ public class HumanPlayer extends PlayerImpl {
93
94
// * - GAME thread: open response for income command and wait (go to sleep by response.wait)
94
95
// * - CALL thread: on closed response - waiting open status of player's response object (if it's too long then cancel the answer)
95
96
// * - CALL thread: on opened response - save answer to player's response object and notify GAME thread about it by response.notifyAll
96
- // * - GAME thread: on nofify from response - check new answer value and process it (if it bad then repeat and wait the next one);
97
+ // * - GAME thread: on notify from response - check new answer value and process it (if it bad then repeat and wait the next one);
97
98
private transient Boolean responseOpenedForAnswer = false ; // GAME thread waiting new answer
98
99
private transient long responseLastWaitingThreadId = 0 ;
99
100
private final transient PlayerResponse response = new PlayerResponse ();
@@ -1159,25 +1160,27 @@ public boolean priority(Game game) {
1159
1160
// TODO: change pass and other states like passedUntilStackResolved for controlling player, not for "this"
1160
1161
// TODO: check and change all "this" to controling player calls, many bugs with hand, mana, skips - https://github.com/magefree/mage/issues/2088
1161
1162
// TODO: use controlling player in all choose dialogs (and canRespond too, what's with take control of player AI?!)
1163
+ UserData controllingUserData = this .userData ;
1162
1164
if (canRespond ()) {
1163
- HumanPlayer controllingPlayer = this ;
1164
- if (isGameUnderControl ()) { // TODO: must be ! to get real controlling player
1165
+ if (!isGameUnderControl ()) {
1165
1166
Player player = game .getPlayer (getTurnControlledBy ());
1166
1167
if (player instanceof HumanPlayer ) {
1167
- controllingPlayer = (HumanPlayer ) player ;
1168
+ controllingUserData = player .getUserData ();
1169
+ } else {
1170
+ // TODO: add computer opponent here?!
1168
1171
}
1169
1172
}
1170
1173
1171
1174
// TODO: check that all skips and stops used from real controlling player
1172
1175
// like holdingPriority (is it a bug here?)
1173
1176
if (getJustActivatedType () != null && !holdingPriority ) {
1174
- if (controllingPlayer . getUserData () .isPassPriorityCast ()
1177
+ if (controllingUserData .isPassPriorityCast ()
1175
1178
&& getJustActivatedType () == AbilityType .SPELL ) {
1176
1179
setJustActivatedType (null );
1177
1180
pass (game );
1178
1181
return false ;
1179
1182
}
1180
- if (controllingPlayer . getUserData () .isPassPriorityActivation ()
1183
+ if (controllingUserData .isPassPriorityActivation ()
1181
1184
&& getJustActivatedType ().isNonManaActivatedAbility ()) {
1182
1185
setJustActivatedType (null );
1183
1186
pass (game );
@@ -1252,7 +1255,7 @@ && getJustActivatedType().isNonManaActivatedAbility()) {
1252
1255
// it's main step
1253
1256
if (!skippedAtLeastOnce
1254
1257
|| (!playerId .equals (game .getActivePlayerId ())
1255
- && !controllingPlayer . getUserData () .getUserSkipPrioritySteps ().isStopOnAllMainPhases ())) {
1258
+ && !controllingUserData .getUserSkipPrioritySteps ().isStopOnAllMainPhases ())) {
1256
1259
skippedAtLeastOnce = true ;
1257
1260
if (passWithManaPoolCheck (game )) {
1258
1261
return false ;
@@ -1274,8 +1277,7 @@ && getJustActivatedType().isNonManaActivatedAbility()) {
1274
1277
// it's end of turn step
1275
1278
if (!skippedAtLeastOnce
1276
1279
|| (playerId .equals (game .getActivePlayerId ())
1277
- && !controllingPlayer
1278
- .getUserData ()
1280
+ && !controllingUserData
1279
1281
.getUserSkipPrioritySteps ()
1280
1282
.isStopOnAllEndPhases ())) {
1281
1283
skippedAtLeastOnce = true ;
@@ -1295,7 +1297,7 @@ && getJustActivatedType().isNonManaActivatedAbility()) {
1295
1297
}
1296
1298
1297
1299
if (!dontCheckPassStep
1298
- && checkPassStep (game , controllingPlayer )) {
1300
+ && checkPassStep (game , controllingUserData )) {
1299
1301
if (passWithManaPoolCheck (game )) {
1300
1302
return false ;
1301
1303
}
@@ -1308,8 +1310,7 @@ && checkPassStep(game, controllingPlayer)) {
1308
1310
if (passedUntilStackResolved ) {
1309
1311
if (haveNewObjectsOnStack
1310
1312
&& (playerId .equals (game .getActivePlayerId ())
1311
- && controllingPlayer
1312
- .getUserData ()
1313
+ && controllingUserData
1313
1314
.getUserSkipPrioritySteps ()
1314
1315
.isStopOnStackNewObjects ())) {
1315
1316
// new objects on stack -- disable "pass until stack resolved"
@@ -1433,17 +1434,17 @@ private UUID getFixedResponseUUID(Game game) {
1433
1434
return response .getUUID ();
1434
1435
}
1435
1436
1436
- private boolean checkPassStep (Game game , HumanPlayer controllingPlayer ) {
1437
+ private boolean checkPassStep (Game game , UserData controllingUserData ) {
1437
1438
try {
1438
1439
1439
1440
if (playerId .equals (game .getActivePlayerId ())) {
1440
- return !controllingPlayer . getUserData () .getUserSkipPrioritySteps ().getYourTurn ().isPhaseStepSet (game .getTurnStepType ());
1441
+ return !controllingUserData .getUserSkipPrioritySteps ().getYourTurn ().isPhaseStepSet (game .getTurnStepType ());
1441
1442
} else {
1442
- return !controllingPlayer . getUserData () .getUserSkipPrioritySteps ().getOpponentTurn ().isPhaseStepSet (game .getTurnStepType ());
1443
+ return !controllingUserData .getUserSkipPrioritySteps ().getOpponentTurn ().isPhaseStepSet (game .getTurnStepType ());
1443
1444
}
1444
1445
} catch (NullPointerException ex ) {
1445
- if (controllingPlayer . getUserData () != null ) {
1446
- if (controllingPlayer . getUserData () .getUserSkipPrioritySteps () != null ) {
1446
+ if (controllingUserData != null ) {
1447
+ if (controllingUserData .getUserSkipPrioritySteps () != null ) {
1447
1448
if (game .getStep () != null ) {
1448
1449
if (game .getTurnStepType () == null ) {
1449
1450
logger .error ("game.getTurnStepType() == null" );
@@ -2929,19 +2930,8 @@ private void setTriggerAutoOrder(PlayerAction playerAction, Game game, Object da
2929
2930
protected boolean passWithManaPoolCheck (Game game ) {
2930
2931
if (userData .confirmEmptyManaPool ()
2931
2932
&& game .getStack ().isEmpty () && getManaPool ().count () > 0 && getManaPool ().canLostManaOnEmpty ()) {
2932
- String activePlayerText ;
2933
- if (game .isActivePlayer (playerId )) {
2934
- activePlayerText = "Your turn" ;
2935
- } else {
2936
- activePlayerText = game .getPlayer (game .getActivePlayerId ()).getName () + "'s turn" ;
2937
- }
2938
- String priorityPlayerText = "" ;
2939
- if (!isGameUnderControl ()) {
2940
- priorityPlayerText = " / priority " + game .getPlayer (game .getPriorityPlayerId ()).getName ();
2941
- }
2942
- // TODO: chooseUse and other dialogs must be under controlling player
2943
- if (!chooseUse (Outcome .Detriment , GameLog .getPlayerConfirmColoredText ("You still have mana in your mana pool and it will be lose. Pass anyway?" )
2944
- + GameLog .getSmallSecondLineText (activePlayerText + " / " + game .getTurnStepType ().toString () + priorityPlayerText ), null , game )) {
2933
+ String message = GameLog .getPlayerConfirmColoredText ("You still have mana in your mana pool and it will be lose. Pass anyway?" );
2934
+ if (!chooseUse (Outcome .Detriment , message , null , game )) {
2945
2935
sendPlayerAction (PlayerAction .PASS_PRIORITY_CANCEL_ALL_ACTIONS , game , null );
2946
2936
return false ;
2947
2937
}
0 commit comments