/// <summary> /// Method for evaluating the attack command. /// </summary> /// <param name="req">Attack Command</param> /// <param name="rules">Rules for evaluating the command.</param> /// <param name="player">Player requesting the attack command.</param> /// <param name="time">Current game time.</param> /// <returns>Queue of translated commands resulting from the evaluation.</returns> private Queue <Command> evaluateAttack(Command req, RuleBook rules, Player player, TimeSpan time) { Queue <Command> retval = new Queue <Command>(); // Decorate the command to get the required functionallity. // Probably a better solution. Suggestions welcome. Command attack = new AttackDecorator(req); // Get the target of the attack. ActiveGameObject targ = (ActiveGameObject)GameObjectFactory.The.getGameObject(attack.Target); if (targ == null) { // TODO: flush the unit's queue of commands. Signifies the attack is over / target is dead. } // Unit the command is acting on. Unit unit = (Unit)GameObjectFactory.The.getGameObject(attack.Actor); // Pathfind to the target. List <Vector2> waypoints = _explorer.GetPath(unit.getPosition(), targ.getPosition(), _map); Engine engine = unit.Engine; // Time To Destination. // Note for attack commands we only used the first waypoint. float ttd = engine.timeToReach(waypoints[0]); float curt = time.Ticks; retval.Enqueue(new MoveDecorator(req.Actor, (UInt16)targ.getPosition().X, (UInt16)targ.getPosition().Y, curt + ttd, new Command())); // TODO: push an attack on as well. return(retval); }
private static void TestDecorators() { Card soldier = new Card("Soldier", 25, 20); soldier = new AttackDecorator(soldier, "Sword", 15); soldier = new AttackDecorator(soldier, "Amulet", 5); soldier = new DefenseDecorator(soldier, "Helmet", 10); soldier = new DefenseDecorator(soldier, "Heavy Armor", 45); Console.WriteLine($"Final Stats: {soldier.Attack} / {soldier.Defense}"); }
private void AddDecoratedCard() { Console.WriteLine("\n\nAdding a decorated card:"); Card decoratedCard = new Card("Soldier", 10, 15); decoratedCard = new AttackDecorator(decoratedCard, "Sword", 15); decoratedCard = new AttackDecorator(decoratedCard, "Amulet", 5); decoratedCard = new DefenseDecorator(decoratedCard, "Helmet", 10); decoratedCard = new DefenseDecorator(decoratedCard, "Heavy Armor", 45); _player.Cards.Add(decoratedCard); Console.WriteLine($"{decoratedCard.Name}\t\t({decoratedCard.Attack}/{decoratedCard.Defense})"); }