private void DebugStuff() { RuleEvaluationInfo ri = default(RuleEvaluationInfo); if (Input.GetKeyDown(KeyCode.F)) { new HandRequest(GameManager.instance.match.player1Key).Start(PlayFirstCardFromHand); } else if (Input.GetKeyDown(KeyCode.D)) { ri = GameManager.instance.TrySendCommand(new Command <DrawCardCommandData>( CommandType.DrawCardFromDeck, new DrawCardCommandData( GameManager.instance.match.player1Key))); HandRequest handRequest = new HandRequest(GameManager.instance.match.player1Key); handRequest.Start(DebugHand); } if (ri != null && !ri.actionAllowed) { if (ri.cardInstance == null) { Debug.Log(ri.ruleDeniedMessage); } else { Debug.Log(ri.ruleDeniedMessage + "\n" + ri.cardInstance.ToString()); } } }
private void PlayFirstCardFromHand(List <ICardInstance> obj) { RuleEvaluationInfo ri = default(RuleEvaluationInfo); if (obj.Count == 0) { Debug.Log("request returned no cards in hand"); return; } Vector2Int position = new Vector2Int( UnityEngine.Random.Range(0, 5), UnityEngine.Random.Range(0, 5)); ri = GameManager.instance.TrySendCommand(new Command <PlayCardCommandData>( CommandType.PlayCard, new PlayCardCommandData( GameManager.instance.match.player1Key, obj[0], position))); if (ri != null && !ri.actionAllowed) { if (ri.cardInstance == null) { Debug.Log(ri.ruleDeniedMessage); } else { Debug.Log(ri.ruleDeniedMessage + "\n" + ri.cardInstance.ToString()); } } }
/// <summary> /// Checks if any rules forbid the command from being executed. /// /// Calls CommandPushed on each ICommandListener. /// Handle queue locking if needed. /// </summary> /// <param name="command"></param> /// <returns></returns> public RuleEvaluationInfo TrySendCommand(GameManager gm, ICommand command) { foreach (Rule rule in rules) { if (!rule.active) { continue; } RuleEvaluationInfo evaluationInfo = rule.IsCommandSendable(gm, command); if (!evaluationInfo.actionAllowed) { return(evaluationInfo); } } commandStack.Push(command); foreach (CommandBehaviour behaviour in registeredBehaviours[command.type]) { behaviour.OnSend(gm, command); } foreach (ICommandListener commandListener in commandListeners) { commandListener.CommandPushed(command); } return(new RuleEvaluationInfo(true)); }