/// <summary> /// Method for evaluating Move Commands. /// </summary> /// <param name="req">Move Command being evaluated.</param> /// <param name="rules">RuleBook for evaluating the command.</param> /// <param name="player">Player who requested the move.</param> /// <param name="time">Current game time.</param> /// <returns>Queue of translated commands resulting from the evaluation.</returns> private Queue <Command> evaluateMove(Command req, RuleBook rules, Player player, TimeSpan time) { Queue <Command> retval = new Queue <Command>(); // Decorate the command to get the required functionality. // Probably a better way to do this... Command move = new MoveDecorator(req); // Unit the command was acting on. ActiveGameObject unit = (ActiveGameObject)GameObjectFactory.The.getGameObject(move.Actor); Vector2 origin = unit.getPosition(); Vector2 dest = new Vector2((long)move.X, (long)move.Y); List <Vector2> waypoints = _explorer.GetPath(origin, dest, _map); // Check that next waypoint is valid. Depending on implimentaiton of PathFinder, this may not be nessisary. if (waypoints.Count > 0 && _map.hasUnitsInPath(origin, waypoints[0])) { Command deny = new DenyDecorator(req.Actor, time.Ticks, new Command()); retval.Enqueue(deny); // TODO: trigger request denied event. return(retval); } Engine engine = ((Unit)unit).Engine; // Build Move Commands out of waypoints. foreach (Vector2 p in waypoints) { float ttd = engine.timeToReach(dest); float curt = time.Ticks; retval.Enqueue(new MoveDecorator(req.Actor, (UInt16)p.X, (UInt16)p.Y, curt + ttd, new Command())); } return(retval); }
protected virtual void handleMoveCommand(Command moveCommand) { MoveDecorator mov = new MoveDecorator(moveCommand); Vector2 position = new Vector2((float)mov.X, (float)mov.Y); Unit u = (Unit)GameObjectFactory.The.getGameObject(mov.UnitID); u.forceFinishAction(); u.moveTo(position); }