public void OptionSelected(DefendCommand defendCommand) { combatState = CombatState.ResolvingCombat; defendCommandPanel.SetActive(false); dialogText.text += "\n" + defender.name + " tries to " + defendCommand.Name() + "!"; // do calculations float baseToHit = .75f; float baseToDodge = defendCommand.SuccessRate; Debug.Log(baseToHit - baseToDodge); float toHitAdjusted = Mathf.Clamp(baseToHit - baseToDodge, MinToHitChance, MaxToHitChance); dialogText.text += "\n Total chance to hit is " + toHitAdjusted; float rand = Random.Range(0f, 1); dialogText.text += "\n " + attacker.name + " rolled a " + rand; if (rand <= toHitAdjusted) { dialogText.text += "\n " + attacker.name + " Hit!"; } else { dialogText.text += "\n " + defender.name + " " + defendCommand.Verbed() + " the attack!"; } // resolve counter attacks // calculate damage, if any // resolve final results (forced movements, saving throws, status inflictions, etc) // continue with turn attacker.CombatResolved(); combatState = CombatState.Done; }
public override void TurnOnGUI() { float buttonHeight = 50; float buttonWidth = 150; Rect buttonRect = new Rect(0, Screen.height - buttonHeight * 7, buttonWidth, buttonHeight); ICharacterActionCommand cmd; //move button if (GUI.Button(buttonRect, "Move")) { if (!_isMoving) { GameManager.instance.removeTileHighlights(); _isMoving = true; _isAttacking = false; _hasPerformedAtLeastOneMove = true; _isDefending = false; _isRotating = false; cmd = new MoveCommand(null, null); _cmdManager.CommandStack.Push(cmd); ((MoveCommand)cmd).Execute(); GameManager.instance.highlightTilesAt(gridPosition, Color.blue, movementPerActionPoint, false); } else { _isMoving = false; _isAttacking = false; _hasPerformedAtLeastOneMove = false; _isDefending = false; _isRotating = false; //GameManager.instance.removeTileHighlights(); } } //attack/heal button buttonRect = new Rect(0, Screen.height - buttonHeight * 6, buttonWidth, buttonHeight); if (GUI.Button(buttonRect, "Attack")) { if (!_isAttacking) { //GameManager.instance.removeTileHighlights(); _isMoving = false; _isAttacking = true; _hasPerformedAtLeastOneMove = true; _isDefending = false; _isRotating = false; cmd = new AttackCommand(null); _cmdManager.CommandStack.Push(cmd); ((AttackCommand)cmd).Execute(); //GameManager.instance.highlightTilesAt(gridPosition, Color.red, attackRange); } else { _isMoving = true; _isAttacking = false; _hasPerformedAtLeastOneMove = true; _isDefending = false; _isRotating = false; //GameManager.instance.removeTileHighlights(); } } //defend button buttonRect = new Rect(0, Screen.height - buttonHeight * 5, buttonWidth, buttonHeight); if (GUI.Button(buttonRect, "Defend")) { if (!_isDefending) { //GameManager.instance.removeTileHighlights(); _isMoving = false; _isAttacking = false; _hasPerformedAtLeastOneMove = true; _isDefending = true; _isRotating = false; cmd = new DefendCommand(null); _cmdManager.CommandStack.Push(cmd); ((DefendCommand)cmd).Execute(this); //GameManager.instance.highlightTilesAt(gridPosition, Color.red, attackRange); } else { _isMoving = false; _isAttacking = false; _isDefending = false; _isRotating = false; //GameManager.instance.removeTileHighlights(); } } //rotate button buttonRect = new Rect(0, Screen.height - buttonHeight * 4, buttonWidth, buttonHeight); if (GUI.Button(buttonRect, "Rotate")) { if (!_isRotating) { //GameManager.instance.removeTileHighlights(); _isMoving = false; _isAttacking = true; _hasPerformedAtLeastOneMove = false; _isDefending = false; _isRotating = true; cmd = new RotateCommand(null); _cmdManager.CommandStack.Push(cmd); ((RotateCommand)cmd).Execute(); //GameManager.instance.highlightTilesAt(gridPosition, Color.red, attackRange); } else { _isMoving = true; _isAttacking = false; _hasPerformedAtLeastOneMove = true; _isDefending = false; _isRotating = false; //GameManager.instance.removeTileHighlights(); } } //undo button buttonRect = new Rect(0, Screen.height - buttonHeight * 3, buttonWidth, buttonHeight); if (GUI.Button(buttonRect, "Undo")) { if (_hasPerformedAtLeastOneMove) { _cmdManager.Undo(this, _cmdManager.LastCharacterAttacked); if (_cmdManager.CommandStack.Count == 0) _hasPerformedAtLeastOneMove = false; } } //skip button buttonRect = new Rect(0, Screen.height - buttonHeight * 2, buttonWidth, buttonHeight); if (GUI.Button(buttonRect, "Skip")) { GameManager.instance.GoToNextCharacter(); } //end turn button buttonRect = new Rect(0, Screen.height - buttonHeight * 1, buttonWidth, buttonHeight); if (GUI.Button(buttonRect, "End Turn")) { GameManager.instance.GoToNextCharacter(); } base.TurnOnGUI(); }
public override void TurnOnGUI() { float buttonHeight = 50; float buttonWidth = 150; Rect buttonRect = new Rect(0, Screen.height - buttonHeight * 7, buttonWidth, buttonHeight); ICharacterActionCommand cmd; //move button if (GUI.Button(buttonRect, "Move")) { if (!_isMoving) { GameManager.instance.removeTileHighlights(); _isMoving = true; _isAttacking = false; _hasPerformedAtLeastOneMove = true; _isDefending = false; _isRotating = false; cmd = new MoveCommand(null, null); _cmdManager.CommandStack.Push(cmd); ((MoveCommand)cmd).Execute(); GameManager.instance.highlightTilesAt(gridPosition, Color.blue, movementPerActionPoint, false); } else { _isMoving = false; _isAttacking = false; _hasPerformedAtLeastOneMove = false; _isDefending = false; _isRotating = false; //GameManager.instance.removeTileHighlights(); } } //attack/heal button buttonRect = new Rect(0, Screen.height - buttonHeight * 6, buttonWidth, buttonHeight); if (GUI.Button(buttonRect, "Attack")) { if (!_isAttacking) { //GameManager.instance.removeTileHighlights(); _isMoving = false; _isAttacking = true; _hasPerformedAtLeastOneMove = true; _isDefending = false; _isRotating = false; cmd = new AttackCommand(null); _cmdManager.CommandStack.Push(cmd); ((AttackCommand)cmd).Execute(); //GameManager.instance.highlightTilesAt(gridPosition, Color.red, attackRange); } else { _isMoving = true; _isAttacking = false; _hasPerformedAtLeastOneMove = true; _isDefending = false; _isRotating = false; //GameManager.instance.removeTileHighlights(); } } //defend button buttonRect = new Rect(0, Screen.height - buttonHeight * 5, buttonWidth, buttonHeight); if (GUI.Button(buttonRect, "Defend")) { if (!_isDefending) { //GameManager.instance.removeTileHighlights(); _isMoving = false; _isAttacking = false; _hasPerformedAtLeastOneMove = true; _isDefending = true; _isRotating = false; cmd = new DefendCommand(null); _cmdManager.CommandStack.Push(cmd); ((DefendCommand)cmd).Execute(this); //GameManager.instance.highlightTilesAt(gridPosition, Color.red, attackRange); } else { _isMoving = false; _isAttacking = false; _isDefending = false; _isRotating = false; //GameManager.instance.removeTileHighlights(); } } //rotate button buttonRect = new Rect(0, Screen.height - buttonHeight * 4, buttonWidth, buttonHeight); if (GUI.Button(buttonRect, "Rotate")) { if (!_isRotating) { //GameManager.instance.removeTileHighlights(); _isMoving = false; _isAttacking = true; _hasPerformedAtLeastOneMove = false; _isDefending = false; _isRotating = true; cmd = new RotateCommand(null); _cmdManager.CommandStack.Push(cmd); ((RotateCommand)cmd).Execute(); //GameManager.instance.highlightTilesAt(gridPosition, Color.red, attackRange); } else { _isMoving = true; _isAttacking = false; _hasPerformedAtLeastOneMove = true; _isDefending = false; _isRotating = false; //GameManager.instance.removeTileHighlights(); } } //undo button buttonRect = new Rect(0, Screen.height - buttonHeight * 3, buttonWidth, buttonHeight); if (GUI.Button(buttonRect, "Undo")) { if (_hasPerformedAtLeastOneMove) { _cmdManager.Undo(this, _cmdManager.LastCharacterAttacked); if (_cmdManager.CommandStack.Count == 0) { _hasPerformedAtLeastOneMove = false; } } } //skip button buttonRect = new Rect(0, Screen.height - buttonHeight * 2, buttonWidth, buttonHeight); if (GUI.Button(buttonRect, "Skip")) { GameManager.instance.GoToNextCharacter(); } //end turn button buttonRect = new Rect(0, Screen.height - buttonHeight * 1, buttonWidth, buttonHeight); if (GUI.Button(buttonRect, "End Turn")) { GameManager.instance.GoToNextCharacter(); } base.TurnOnGUI(); }
private void OpenDialog(Point cellClicked, Point screenPosition) { game.GameState = MizJam1Game.GameStates.OpenDialog; dialog = new UIMenu(screenPosition, new Point(500, 500), true) { SpaceBetweenChildren = 5, Vertical = true }; Unit enemy; bool attackDirectly = false; if ((enemy = GetUnit(cellClicked)) != null && enemy.Enemy) { UIImage attack = new UIImage(game.Dialogs[MizJam1Game.Actions.Attack], game.SelectedDialogs[MizJam1Game.Actions.Attack]); Point moveTarget = threatenedPositions[cellClicked].From; MoveUnitCommand moveUnit = new MoveUnitCommand(this, SelectedUnit.Position, moveTarget); MoveAndAttackCommand moveAndAttackCommand = new MoveAndAttackCommand(moveUnit, this, SelectedUnit, enemy); attack.AddCommand(moveAndAttackCommand); dialog.AddChild(attack); attackDirectly = true; } if (!attackDirectly) { foreach (var threat in threatenedPositions) { if ((enemy = GetUnit(threat.Key)) != null && enemy.Enemy) { UIImage attackSelect = new UIImage(game.Dialogs[MizJam1Game.Actions.Attack], game.SelectedDialogs[MizJam1Game.Actions.Attack]); SelectAttackCommand selectAttackCommand = new SelectAttackCommand(this); attackSelect.AddCommand(selectAttackCommand); dialog.AddChild(attackSelect); break; } } } if (cellClicked == SelectedUnit.Position) { UIImage defend = new UIImage(game.Dialogs[MizJam1Game.Actions.Defend], game.SelectedDialogs[MizJam1Game.Actions.Defend]); DefendCommand defendCommand = new DefendCommand(this, SelectedUnit.Position); defend.AddCommand(defendCommand); dialog.AddChild(defend); } MoveUnitCommand moveCommand = null; if (canGoPositions.Contains(cellClicked)) { UIImage move = new UIImage(game.Dialogs[MizJam1Game.Actions.Move], game.SelectedDialogs[MizJam1Game.Actions.Move]); moveCommand = new MoveUnitCommand(this, SelectedUnit.Position, cellClicked); move.AddCommand(moveCommand); dialog.AddChild(move); canGoPositions = new HashSet <Point>() { cellClicked }; } if (!attackDirectly) { UIImage reroll = new UIImage(game.Dialogs[MizJam1Game.Actions.Reroll], game.SelectedDialogs[MizJam1Game.Actions.Reroll]); if (moveCommand == null) { moveCommand = new MoveUnitCommand(this, SelectedUnit.Position, SelectedUnit.Position); } ICommand rerollCommand = new MoveAndRerollCommand(moveCommand, this, SelectedUnit); reroll.AddCommand(rerollCommand); dialog.AddChild(reroll); } if (cellClicked == SelectedUnit.Position) { UIImage wait = new UIImage(game.Dialogs[MizJam1Game.Actions.Wait], game.SelectedDialogs[MizJam1Game.Actions.Wait]); WaitCommand waitCommand = new WaitCommand(this, cellClicked); wait.AddCommand(waitCommand); dialog.AddChild(wait); } UIImage cancel = new UIImage(game.Dialogs[MizJam1Game.Actions.Cancel], game.SelectedDialogs[MizJam1Game.Actions.Cancel]); ICommand cancelCommand = new CancelCommand(this); cancel.AddCommand(cancelCommand); dialog.AddChild(cancel); dialog.SetScale(3); if (dialog.Position.X + dialog.Size.X > 1500) { dialog.Position = new Point(screenPosition.X - dialog.Size.X, dialog.Position.Y); } if (dialog.Position.Y + dialog.Size.Y > 1080) { dialog.Position = new Point(dialog.Position.X, screenPosition.Y - dialog.Size.Y); } }
private void Awake() { Command = new DefendCommand(GetComponentInParent <IDefend>()); }