public TileType(string name, string displayName, bool isPassable, bool isTransparent, object appearance, string debugCharacter = "", bool isWall = false, string alternateAction = null) { Name = name; this.DisplayName = displayName; IsPassable = isPassable; IsTransparent = isTransparent; if (appearance is Glyph) { Appearance = appearance as Glyph; } if (appearance is string) { Appearance = new Glyph(appearance as string); } if (appearance == null) { if (!string.IsNullOrEmpty(DebugCharacter)) { Appearance = new Glyph(DebugCharacter); } else { Appearance = new Glyph("?"); } } IsWall = isWall; if (debugCharacter == "") { DebugCharacter = name[0].ToString(); } else { DebugCharacter = debugCharacter; } AlternateActionTemplate = alternateAction; if (alternateAction != null) { switch (alternateAction) { case "LevelUp": { AlternateAction = new LevelUpAction(); break; } case "LevelDown": { AlternateAction = new LevelDownAction(); break; } } } }
private void _elementalSideEffect(Actor defender, Action action, int damage) { // Apply any element-specific effects. //switch (Element.Name) //{ // case ElementFactory.Instance.none: // // No effect. // break; // case ElementFactory.Instance.air: // // TODO: Teleport. // break; // case ElementFactory.Instance.earth: // // TODO: Cuts? // break; // case ElementFactory.Instance.fire: // action.AddAction(new BurnAction(damage), defender); // break; // case ElementFactory.Instance.water: // // TODO: Push back. // break; // case ElementFactory.Instance.acid: // // TODO: Destroy items. // break; // case ElementFactory.Instance.cold: // action.AddAction(new FreezeAction(damage), defender); // break; // case ElementFactory.Instance.lightning: // // TODO: Break glass. Recharge some items? // break; // case ElementFactory.Instance.poison: // action.AddAction(new PoisonAction(damage), defender); // break; // case ElementFactory.Instance.dark: // // TODO: Blind. // break; // case ElementFactory.Instance.light: // action.AddAction(new DazzleAction(damage), defender); // break; // case ElementFactory.Instance.spirit: // // TODO: Drain experience. // break; //} }
public bool PerformAttack(Action action, Actor attacker, Actor defender, bool?canMiss) { if (canMiss == null) { canMiss = true; } var attackNoun = Noun ?? attacker; // See if the attack hits. if (canMiss.Value) { var dodge = defender.Dodge + StrikeBonus; var strike = Rng.Instance.Inclusive(1, 100); // There's always at least a 5% chance of missing and a 5% chance of // hitting, regardless of all modifiers. strike = strike.Clamp(5, 95); if (strike < dodge) { action.Log("{1} miss[es] {2}.", attackNoun, defender); return(false); } } // Roll for damage. var damage = _rollDamage(); if (damage == 0) { // Armor cancelled out all damage. action.Log("{1} do[es] no damage to {2}.", attackNoun, defender); return(true); } attacker.OnDamage(action, defender, damage); if (defender.TakeDamage(action, damage, attackNoun, attacker)) { return(true); } if (Resistance == 0) { _elementalSideEffect(defender, action, damage); } // TODO: Pass in and use element. action.AddEvent(EventType.Hit, defender, damage.ToString()); action.Log("{1} " + Verb + " {2}.", attackNoun, defender); return(true); }
/// Performs a melee [attack] from [attacker] to [defender] in the course of /// [action]. /// /// Returns `true` if the attack connected. public bool Perform(Action action, Actor attacker, Actor defender, bool canMiss = true) { var attack = defender.Defend(this); return(attack.PerformAttack(action, attacker, defender, canMiss)); }
public AIChoice(double score, string description, Action createAction) { Score = score; Description = description; CreateAction = createAction; }
/// <summary> /// The return is to exit the Game /// </summary> /// <returns></returns> public override bool HandleInput() { var originalColor = Console.ForegroundColor; Console.ForegroundColor = ConsoleColor.Black; var inputs = Inputs.Instance; var lastInput = GetPlayerInput(); Console.ForegroundColor = originalColor; var exitGameLoop = false; Action action = null; //--------------------------------------------------------------------------------------------------------------------------------------------------------------------------- // Player Actions. //--------------------------------------------------------------------------------------------------------------------------------------------------------------------------- if (lastInput == inputs.forfeit) { var dialog = new ForfeitDialog(_gameState.Game); dialog.Process(); var result = dialog.DialogResult; if (result == ForfeitDialogResult.Yes) { ScreenResult = new ScreenTransitionResult { FromScreen = ScreenType.InGame, ToScreen = ScreenType.MainMenu, Result = null }; Storage.Heroes.RemoveAll(x => x.Name == _gameState.Game.Hero.Name); Storage.Save(); exitGameLoop = true; } } // Input.forfeit, else if (lastInput == inputs.quit) { var dialog = new ConfirmDialog("Are you sure you want to quit the game?"); dialog.Process(); var result = dialog.DialogResult; if (result == ConfirmDialogResult.Yes) { ScreenResult = new ScreenTransitionResult { FromScreen = ScreenType.InGame, ToScreen = ScreenType.MainMenu, Result = null }; Storage.Update(_gameState); Storage.Save(); exitGameLoop = true; } } // Input.quit, else if (lastInput == inputs.closeDoor) { // See how many adjacent open doors there are. var doors = new List <VectorBase>(); foreach (var direction in Direction.All) { var pos = _gameState.Game.Hero.Position + direction; if (_gameState.Game.CurrentStage[pos].Type.ClosesTo != null) { doors.Add(pos); } } if (doors.Count == 0) { _gameState.Game.Log.Error("You are not next to an open door."); } else if (doors.Count == 1) { _gameState.Game.Hero.SetNextAction(new CloseDoorAction(doors[0])); } else { var closeDoorDialog = new CloseDoorDialog(_gameState.Game); closeDoorDialog.Process(); } } // Input.closeDoor, else if (lastInput == inputs.drop) { ShowItemDialog(ItemDialogUsage.Drop); } // Input.drop, else if (lastInput == inputs.use) { ShowItemDialog(ItemDialogUsage.Use); } // Input.use, else if (lastInput == inputs.pickUp) { var items = _gameState.Game.CurrentStage.itemsAt(_gameState.Game.Hero.Position); if (items.Count > 1) { // Show item dialog if there are multiple things to pick up. ShowItemDialog(ItemDialogUsage.PickUp); } else { // Otherwise attempt to pick up any available item. _gameState.Game.Hero.SetNextAction(new PickUpAction(items.Count - 1)); } } // Input.pickUp, else if (lastInput == inputs.swap) { if (_gameState.Game.Hero.Inventory.lastUnequipped == -1) { _gameState.Game.Log.Error("You aren't holding an unequipped item to swap."); } else { action = new EquipAction(ItemLocations.Inventory, _gameState.Game.Hero.Inventory.lastUnequipped); } } // Input.swap, else if (lastInput == inputs.toss) { ShowItemDialog(ItemDialogUsage.Toss); } // Input.toss, else if (lastInput == inputs.selectCommand) { var commands = _gameState.Game.Hero.HeroClass.Commands.Where(cmd => cmd.CanUse(_gameState.Game)); if (!commands.Any()) { _gameState.Game.Log.Error("You don't have any commands you can perform."); } else { Command commandToProcess = null; if (commands.Count() > 1) { var dialog = new SelectCommandDialog(_gameState.Game); dialog.Process(); commandToProcess = dialog.DialogResult; } else { commandToProcess = commands.First(); } if (commandToProcess is TargetCommand) { var targetCommand = commandToProcess as TargetCommand; // If we still have a visible target, use it. if (_gameState.Game.Target != null && _gameState.Game.Target.IsAlive && _gameState.Game.CurrentStage[_gameState.Game.Target.Position].Visible) { _gameState.Game.Hero.SetNextAction(targetCommand.GetTargetAction(_gameState.Game, _gameState.Game.Target.Position)); } else { // No current target, so ask for one. var targetDialog = new TargetDialog(targetCommand.GetRange(_gameState.Game), (target) => _gameState.Game.Hero.SetNextAction(targetCommand.GetTargetAction(_gameState.Game, target)), _gameState.Game); targetDialog.Process(); } } else if (commandToProcess is DirectionCommand) { var directionCommand = commandToProcess as DirectionCommand; var directionDialog = new DirectionDialog(directionCommand, _gameState.Game); directionDialog.Process(); } else { throw new NotImplementedException(); } } } // Input.selectCommand, else if (lastInput == inputs.stats) { ShowHeroStatisticsDialog(); } // Input.HeroStatistics, else if (lastInput.Key == ConsoleKey.Z) { ShowStorageDialog(); } // Storage else if (lastInput.Key == ConsoleKey.Oem3) { ShowConsoleDialog(); } // Storage //--------------------------------------------------------------------------------------------------------------------------------------------------------------------------- // Running Options //--------------------------------------------------------------------------------------------------------------------------------------------------------------------------- else if (lastInput == inputs.runNW) { _gameState.Game.Hero.Run(Direction.NorthWest); } // Input.runNW, else if (lastInput == inputs.runN) { _gameState.Game.Hero.Run(Direction.North); } // Input.runN, else if (lastInput == inputs.runNE) { _gameState.Game.Hero.Run(Direction.NorthEast); } // Input.runNE, else if (lastInput == inputs.runW) { _gameState.Game.Hero.Run(Direction.West); } // Input.runW, else if (lastInput == inputs.runE) { _gameState.Game.Hero.Run(Direction.East); } // Input.runE, SemiColon else if (lastInput == inputs.runSW) { _gameState.Game.Hero.Run(Direction.SouthWest); } // Input.runSW, else if (lastInput == inputs.runS) { _gameState.Game.Hero.Run(Direction.South); } // Input.runS, else if (lastInput == inputs.runSE) { _gameState.Game.Hero.Run(Direction.SouthEast); } // Input.runSE, Slash (FWD) //--------------------------------------------------------------------------------------------------------------------------------------------------------------------------- // Firing Options //--------------------------------------------------------------------------------------------------------------------------------------------------------------------------- else if (lastInput == inputs.fireNW) { FireTowards(Direction.NorthWest); } // Input.fireNW, else if (lastInput == inputs.fireN) { FireTowards(Direction.North); } // Input.fireN, else if (lastInput == inputs.fireNE) { FireTowards(Direction.NorthEast); } // Input.fireNE, else if (lastInput == inputs.fireW) { FireTowards(Direction.West); } // Input.fireW, else if (lastInput == inputs.fireE) { FireTowards(Direction.East); } // Input.fireE, else if (lastInput == inputs.fireSW) { FireTowards(Direction.SouthWest); } // Input.fireSW, else if (lastInput == inputs.fireS) { FireTowards(Direction.South); } // Input.fireS, else if (lastInput == inputs.fireSE) { FireTowards(Direction.SouthEast); } // Input.fireSE, //--------------------------------------------------------------------------------------------------------------------------------------------------------------------------- // directions. //--------------------------------------------------------------------------------------------------------------------------------------------------------------------------- else if (lastInput == inputs.nw) { action = new WalkAction(Direction.NorthWest); } // Input.nw, else if (lastInput == inputs.n) { action = new WalkAction(Direction.North); } // Input.n, else if (lastInput == inputs.ne) { action = new WalkAction(Direction.NorthEast); } // Input.ne, else if (lastInput == inputs.w) { action = new WalkAction(Direction.West); } // Input.w, else if (lastInput == inputs.rest) { action = new RestAction(); } // Input.l, else if (lastInput == inputs.e) { action = new WalkAction(Direction.East); } // Input.e, else if (lastInput == inputs.sw) { action = new WalkAction(Direction.SouthWest); } // Input.sw, else if (lastInput == inputs.s) { action = new WalkAction(Direction.South); } // Input.s, else if (lastInput == inputs.se) { action = new WalkAction(Direction.SouthEast); } // Input.se, //Check if we have a non-zero value for horizontal or vertical if (action != null) { //UnityEngine.Debugger.Log("Adding action for Hero"); GameState.Instance.Game.Hero.SetNextAction(action); } return(exitGameLoop); }