protected override void Execute() { TilePosition s = this.Source.PositionAs<TilePosition>(); TilePosition e = Target.PositionAs<TilePosition>(); AttackModule attmod = this.Source.Module<AttackModule>(); Vector v = new Vector(s.Point, e.Point); float dist = v.Distance; float attackrange = (int)attmod.AttackRange; if (!attmod.CanReachPoint(s.Point, e.Point)) return; int dmg = attmod.Damage; this.DamageOnResolve = dmg; int attackTime = attmod.AttackTime; this.Source.Raise(new UnitBeginAttackEvent(Source, Target, dmg, attackTime)); Action attackfun =delegate { this.RunAction(this.Source, new DealDamageToUnitAction(Target, dmg)); }; if (attackTime > 0) { var timerAction = this.Factory.CreateTimer(attackfun); timerAction.SetSingle(attackTime); this.RunAction(timerAction); } else attackfun(); }
protected override void Execute() { var unit = (UnitEntity)this.Source; TilePosition p = (TilePosition)this.World.GetEntityPosition(this.Source); Point currentPos = p.Point; if (usePoint) v = new Vector(currentPos, toward); Point newPos = currentPos + v; var preMove = new PreMoveEvent(unit, currentPos, newPos); this.Source.Raise(preMove); if (preMove.MoveStopped) { this.moveStopped = true; return; } this.Source.Raise(new BeginMoveEvent(unit, currentPos, newPos,this.duration)); if (duration != 0) { TimedAction t = this.Factory.CreateTimer(delegate { MoveUnit(currentPos, newPos); }); t.SetSingle(duration); this.RunAction(t); } else { MoveUnit(currentPos, newPos); } }
public Point CalculateEndPoint() { var curp = ((TilePosition)this.Source.Position).Point; var thep = v; if (usePoint) thep = new Vector(curp, toward); return curp + thep; }
public MoveAction(Vector v, int duration) { //ensure x and y is a under that is either 1, 0 or -1 int x = v.X > 1 ? 1 : (v.X < -1 ? -1 : v.X); int y = v.Y > 1 ? 1 : (v.Y < -1 ? -1 : v.Y); this.v = new Vector(x,y); this.duration = duration; }
private bool connectCorner(Point origin, Point destination) { Vector v = new Vector(origin, destination); var testt = walkAlongVector(v).ToArray(); foreach (Point[] ps in walkAlongVector(v)) { Point[] transp = ps.Select(p => origin + p).ToArray(); bool test = transp.All(p => grid[p.X, p.Y].IsVisionBlocking(owner)); if (transp.All(p => grid[p.X, p.Y].IsVisionBlocking(owner))) return false; } return true; }
public Point(Point p, Vector v) { x = p.X + v.X; y = p.Y + v.Y; }
private IEnumerable<IEnumerable<Point>> walkAlongVector(Vector v) { if (v.X == 0 || v.Y == 0) { for (int i = 0; i < Math.Max (Math.Abs(v.X), Math.Abs(v.Y)); i++) { Point[] retpoint = new Point[] { new Point (i, i) * v.Direction, new Point (i, i) * v.Direction - (new Point(1,1) - v.Direction.Abs) }; yield return retpoint; } } else { double linepiece; linepiece = Math.Abs (v.Y/(double) v.X); for (int i = 0; i < Math.Abs(v.X); i++) { int start = (int)Math.Floor (i*linepiece); int stop = (int)Math.Ceiling ((i + 1)*linepiece); for (int j = start; j < stop; j++) { int x = i, y = j; // if any of the vector's coordinates are negative, offsets change: if (v.X < 0) x = (-1 * x) - 1; if (v.Y < 0) y = (-1 * y) - 1; yield return new Point[] { new Point(x, y) }; } } } }
public void VectorPointAddition_AddPointToVector_NewPoint() { Point actual = new Vector(1, 1) + new Point(1, 1); Point expected = new Point(2, 2); Assert.AreEqual(expected, actual); }