public override Activity Tick(Actor self) { if (moveDisablers.Any(d => d.MoveDisabled(self))) { return(this); } if (destination == mobile.toCell) { return(NextActivity); } if (path == null) { if (mobile.ticksBeforePathing > 0) { --mobile.ticksBeforePathing; return(this); } path = EvalPath(self, mobile); SanityCheckPath(mobile); } if (path.Count == 0) { destination = mobile.toCell; return(this); } destination = path[0]; var nextCell = PopPath(self, mobile); if (nextCell == null) { return(this); } var firstFacing = self.World.Map.FacingBetween(mobile.fromCell, nextCell.Value.First, mobile.Facing); if (firstFacing != mobile.Facing) { path.Add(nextCell.Value.First); return(Util.SequenceActivities(new Turn(self, firstFacing), this)); } else { mobile.SetLocation(mobile.fromCell, mobile.fromSubCell, nextCell.Value.First, nextCell.Value.Second); var move = new MoveFirstHalf( this, self.World.Map.CenterOfSubCell(mobile.fromCell, mobile.fromSubCell), Util.BetweenCells(self.World, mobile.fromCell, mobile.toCell) + (self.World.Map.OffsetOfSubCell(mobile.fromSubCell) + self.World.Map.OffsetOfSubCell(mobile.toSubCell)) / 2, mobile.Facing, mobile.Facing, 0); return(move); } }
public override Activity Tick(Actor self) { var mobile = self.Trait <Mobile>(); if (destination == mobile.toCell) { return(NextActivity); } if (path == null) { if (mobile.ticksBeforePathing > 0) { --mobile.ticksBeforePathing; return(this); } path = EvalPath(self, mobile); SanityCheckPath(mobile); } if (path.Count == 0) { destination = mobile.toCell; return(this); } destination = path[0]; var nextCell = PopPath(self, mobile); if (nextCell == null) { return(this); } var dir = nextCell.Value.First - mobile.fromCell; var firstFacing = Util.GetFacing(dir, mobile.Facing); if (firstFacing != mobile.Facing) { path.Add(nextCell.Value.First); return(Util.SequenceActivities(new Turn(firstFacing), this)); } else { mobile.SetLocation(mobile.fromCell, mobile.fromSubCell, nextCell.Value.First, nextCell.Value.Second); var move = new MoveFirstHalf( this, mobile.fromCell.CenterPosition + MobileInfo.SubCellOffsets[mobile.fromSubCell], Util.BetweenCells(mobile.fromCell, mobile.toCell) + (MobileInfo.SubCellOffsets[mobile.fromSubCell] + MobileInfo.SubCellOffsets[mobile.toSubCell]) / 2, mobile.Facing, mobile.Facing, 0); return(move); } }
protected override MovePart OnComplete(Actor self, Mobile mobile, Move parent) { var map = self.World.Map; var fromSubcellOffset = map.Grid.OffsetOfSubCell(mobile.FromSubCell); var toSubcellOffset = map.Grid.OffsetOfSubCell(mobile.ToSubCell); if (!IsCanceled || self.Location.Layer == CustomMovementLayerType.Tunnel) { var nextCell = parent.PopPath(self); if (nextCell != null) { if (IsTurn(mobile, nextCell.Value.First)) { var nextSubcellOffset = map.Grid.OffsetOfSubCell(nextCell.Value.Second); var ret = new MoveFirstHalf( Move, Util.BetweenCells(self.World, mobile.FromCell, mobile.ToCell) + (fromSubcellOffset + toSubcellOffset) / 2, Util.BetweenCells(self.World, mobile.ToCell, nextCell.Value.First) + (toSubcellOffset + nextSubcellOffset) / 2, mobile.Facing, Util.GetNearestFacing(mobile.Facing, map.FacingBetween(mobile.ToCell, nextCell.Value.First, mobile.Facing)), moveFraction - MoveFractionTotal ); mobile.FinishedMoving(self); mobile.SetLocation(mobile.ToCell, mobile.ToSubCell, nextCell.Value.First, nextCell.Value.Second); return(ret); } parent.path.Add(nextCell.Value.First); } } var toPos = mobile.ToCell.Layer == 0 ? map.CenterOfCell(mobile.ToCell) : self.World.GetCustomMovementLayers()[mobile.ToCell.Layer].CenterOfCell(mobile.ToCell); var ret2 = new MoveSecondHalf( Move, Util.BetweenCells(self.World, mobile.FromCell, mobile.ToCell) + (fromSubcellOffset + toSubcellOffset) / 2, toPos + toSubcellOffset, mobile.Facing, mobile.Facing, moveFraction - MoveFractionTotal ); mobile.EnteringCell(self); mobile.SetLocation(mobile.ToCell, mobile.ToSubCell, mobile.ToCell, mobile.ToSubCell); return(ret2); }
protected override MovePart OnComplete(Actor self, Mobile mobile, Move parent) { var fromSubcellOffset = self.World.Map.OffsetOfSubCell(mobile.FromSubCell); var toSubcellOffset = self.World.Map.OffsetOfSubCell(mobile.ToSubCell); var nextCell = parent.PopPath(self); if (nextCell != null) { if (IsTurn(mobile, nextCell.Value.First)) { var nextSubcellOffset = self.World.Map.OffsetOfSubCell(nextCell.Value.Second); var ret = new MoveFirstHalf( Move, Util.BetweenCells(self.World, mobile.FromCell, mobile.ToCell) + (fromSubcellOffset + toSubcellOffset) / 2, Util.BetweenCells(self.World, mobile.ToCell, nextCell.Value.First) + (toSubcellOffset + nextSubcellOffset) / 2, mobile.Facing, Util.GetNearestFacing(mobile.Facing, self.World.Map.FacingBetween(mobile.ToCell, nextCell.Value.First, mobile.Facing)), moveFraction - MoveFractionTotal); mobile.FinishedMoving(self); mobile.SetLocation(mobile.ToCell, mobile.ToSubCell, nextCell.Value.First, nextCell.Value.Second); return(ret); } parent.path.Add(nextCell.Value.First); } var ret2 = new MoveSecondHalf( Move, Util.BetweenCells(self.World, mobile.FromCell, mobile.ToCell) + (fromSubcellOffset + toSubcellOffset) / 2, self.World.Map.CenterOfCell(mobile.ToCell) + toSubcellOffset, mobile.Facing, mobile.Facing, moveFraction - MoveFractionTotal); mobile.EnteringCell(self); mobile.SetLocation(mobile.ToCell, mobile.ToSubCell, mobile.ToCell, mobile.ToSubCell); return(ret2); }
protected override MovePart OnComplete(Actor self, Mobile mobile, Move parent) { var fromSubcellOffset = MobileInfo.SubCellOffsets[mobile.fromSubCell]; var toSubcellOffset = MobileInfo.SubCellOffsets[mobile.toSubCell]; var nextCell = parent.PopPath(self, mobile); if (nextCell != null) { if (IsTurn(mobile, nextCell.Value.First)) { var nextSubcellOffset = MobileInfo.SubCellOffsets[nextCell.Value.Second]; var ret = new MoveFirstHalf( move, Util.BetweenCells(mobile.fromCell, mobile.toCell) + (fromSubcellOffset + toSubcellOffset) / 2, Util.BetweenCells(mobile.toCell, nextCell.Value.First) + (toSubcellOffset + nextSubcellOffset) / 2, mobile.Facing, Util.GetNearestFacing(mobile.Facing, Util.GetFacing(nextCell.Value.First - mobile.toCell, mobile.Facing)), moveFraction - moveFractionTotal); mobile.SetLocation(mobile.toCell, mobile.toSubCell, nextCell.Value.First, nextCell.Value.Second); return(ret); } parent.path.Add(nextCell.Value.First); } var ret2 = new MoveSecondHalf( move, Util.BetweenCells(mobile.fromCell, mobile.toCell) + (fromSubcellOffset + toSubcellOffset) / 2, mobile.toCell.CenterPosition + toSubcellOffset, mobile.Facing, mobile.Facing, moveFraction - moveFractionTotal); mobile.EnteringCell(self); mobile.SetLocation(mobile.toCell, mobile.toSubCell, mobile.toCell, mobile.toSubCell); return(ret2); }
public override Activity Tick(Actor self) { if (IsCanceled) { return(NextActivity); } if (mobile.IsTraitDisabled) { return(this); } if (destination == mobile.ToCell) { return(NextActivity); } if (path == null) { if (mobile.TicksBeforePathing > 0) { --mobile.TicksBeforePathing; return(this); } path = EvalPath(); SanityCheckPath(mobile); } if (path.Count == 0) { destination = mobile.ToCell; return(this); } destination = path[0]; var nextCell = PopPath(self); if (nextCell == null) { return(this); } var firstFacing = self.World.Map.FacingBetween(mobile.FromCell, nextCell.Value.First, mobile.Facing); if (firstFacing != mobile.Facing) { path.Add(nextCell.Value.First); return(ActivityUtils.SequenceActivities(new Turn(self, firstFacing), this)); } else { mobile.SetLocation(mobile.FromCell, mobile.FromSubCell, nextCell.Value.First, nextCell.Value.Second); var from = self.World.Map.CenterOfSubCell(mobile.FromCell, mobile.FromSubCell); var to = Util.BetweenCells(self.World, mobile.FromCell, mobile.ToCell) + (self.World.Map.Grid.OffsetOfSubCell(mobile.FromSubCell) + self.World.Map.Grid.OffsetOfSubCell(mobile.ToSubCell)) / 2; var move = new MoveFirstHalf( this, from, to, mobile.Facing, mobile.Facing, 0); return(move); } }
public override Activity Tick(Actor self) { // If the actor is inside a tunnel then we must let them move // all the way through before moving to the next activity if (IsCanceled && self.Location.Layer != CustomMovementLayerType.Tunnel) { return(NextActivity); } if (mobile.IsTraitDisabled) { return(this); } if (destination == mobile.ToCell) { return(NextActivity); } if (path == null) { if (mobile.TicksBeforePathing > 0) { --mobile.TicksBeforePathing; return(this); } path = EvalPath(); SanityCheckPath(mobile); } if (path.Count == 0) { destination = mobile.ToCell; return(this); } destination = path[0]; var nextCell = PopPath(self); if (nextCell == null) { return(this); } var firstFacing = self.World.Map.FacingBetween(mobile.FromCell, nextCell.Value.First, mobile.Facing); if (firstFacing != mobile.Facing) { path.Add(nextCell.Value.First); return(ActivityUtils.SequenceActivities(new Turn(self, firstFacing), this)); } else { mobile.SetLocation(mobile.FromCell, mobile.FromSubCell, nextCell.Value.First, nextCell.Value.Second); var map = self.World.Map; var from = (mobile.FromCell.Layer == 0 ? map.CenterOfCell(mobile.FromCell) : self.World.GetCustomMovementLayers()[mobile.FromCell.Layer].CenterOfCell(mobile.FromCell)) + map.Grid.OffsetOfSubCell(mobile.FromSubCell); var to = Util.BetweenCells(self.World, mobile.FromCell, mobile.ToCell) + (map.Grid.OffsetOfSubCell(mobile.FromSubCell) + map.Grid.OffsetOfSubCell(mobile.ToSubCell)) / 2; var move = new MoveFirstHalf( this, from, to, mobile.Facing, mobile.Facing, 0); return(move); } }
protected override MovePart OnComplete( Actor self, Mobile mobile, Move parent ) { var unit = self.traits.Get<Unit>(); var nextCell = parent.PopPath( self, mobile ); if( nextCell != null ) { if( ( nextCell - mobile.toCell ) != ( mobile.toCell - mobile.fromCell ) ) { var ret = new MoveFirstHalf( Util.BetweenCells( mobile.fromCell, mobile.toCell ), Util.BetweenCells( mobile.toCell, nextCell.Value ), unit.Facing, Util.GetNearestFacing( unit.Facing, Util.GetFacing( nextCell.Value - mobile.toCell, unit.Facing ) ), moveFraction - moveFractionTotal ); mobile.fromCell = mobile.toCell; mobile.toCell = nextCell.Value; return ret; } else parent.path.Add( nextCell.Value ); } var ret2 = new MoveSecondHalf( Util.BetweenCells( mobile.fromCell, mobile.toCell ), Util.CenterOfCell( mobile.toCell ), unit.Facing, unit.Facing, moveFraction - moveFractionTotal ); mobile.fromCell = mobile.toCell; return ret2; }