/// <summary> /// Adjusts anchor offsets for a new parent anchor and updates the sprite's anchor infomation. /// </summary> /// <param name="sprite"></param> /// <param name="newParent"></param> public static void adjustAnchorForNewParent( this IPositionable sprite, IPositionable newParent ) { // Get anchor info UIAnchorInfo anchorInfo = sprite.anchorInfo; // Get parent anchors Vector3 oldParentAnchorPosition = parentAnchorPosition( anchorInfo.ParentUIObject, anchorInfo.ParentUIyAnchor, anchorInfo.ParentUIxAnchor ); Vector3 newParentAnchorPosition = parentAnchorPosition( newParent, anchorInfo.ParentUIyAnchor, anchorInfo.ParentUIxAnchor ); Vector3 diffAnchor = newParentAnchorPosition - oldParentAnchorPosition; // Adjust for sprite anchor offset diffAnchor.x -= UIRelative.xAnchorAdjustment( anchorInfo.UIxAnchor, sprite.width, anchorInfo.OriginInCenter ); diffAnchor.y += UIRelative.yAnchorAdjustment( anchorInfo.UIyAnchor, sprite.height, anchorInfo.OriginInCenter ); // Adjust parent anchor offsets if ( anchorInfo.UIPrecision == UIPrecision.Percentage ) { anchorInfo.OffsetX += UIRelative.xPercentTo( anchorInfo.UIxAnchor, diffAnchor.x ); anchorInfo.OffsetY -= UIRelative.yPercentTo( anchorInfo.UIyAnchor, diffAnchor.y ); } else { anchorInfo.OffsetX += UIRelative.xPixelsTo( anchorInfo.UIxAnchor, diffAnchor.x ); anchorInfo.OffsetY -= UIRelative.yPixelsTo( anchorInfo.UIyAnchor, diffAnchor.y ); } // Update parent anchorInfo.ParentUIObject = newParent; // Set update anchor info sprite.anchorInfo = anchorInfo; }
internal IList <Segment> CreateSegmentsImpl(IPositionable startNode, IPositionable endNode, object type, Vector start_dir, Vector end_dir, IPositionable middle_pos) { NetOptions options = NetOptionsUtil.Ensure(type); CreateSegmentMessage msg = new CreateSegmentMessage() { start_node_id = startNode is Node ? (ushort)((Node)startNode).id : (ushort)0, end_node_id = endNode is Node ? (ushort)((Node)endNode).id : (ushort)0, start_postition = startNode is Node ? null : startNode.position, end_postition = endNode is Node ? null : endNode.position, net_options = options, start_dir = start_dir, end_dir = end_dir, control_point = middle_pos?.position, auto_split = true }; PythonList <Segment> shell = new PythonList <Segment>(); var handle = ClientHandler.Instance.RemoteCall(Contracts.CreateSegments, msg, (ret, error) => { if (error != null) { shell.AssignData(null, error); return(null); } NetSegmentListMessage raw = ret as NetSegmentListMessage; shell.AssignData(raw.list.Select((item) => ObjectStorage.Instance.Segments.SaveData(item)).ToList()); return(null); }); shell.CacheFunc = () => { ClientHandler.Instance.WaitOnHandle(handle); }; return(shell); }
internal Segment CreateSegmentImpl(IPositionable startNode, IPositionable endNode, object type, Vector start_dir, Vector end_dir, IPositionable middle_pos) { NetOptions options = NetOptionsUtil.Ensure(type); CreateSegmentMessage msg = new CreateSegmentMessage() { start_node_id = startNode is Node ? (ushort)((Node)startNode).id : (ushort)0, end_node_id = endNode is Node ? (ushort)((Node)endNode).id : (ushort)0, start_postition = startNode is Node ? null : startNode.position, end_postition = endNode is Node ? null : endNode.position, net_options = options, start_dir = start_dir, end_dir = end_dir, control_point = middle_pos?.position }; Segment shell = ObjectStorage.Instance.Segments.CreateShell(); ClientHandler.Instance.RemoteCall(Contracts.CreateSegment, msg, (ret, error) => { if (error != null) { shell.AssignData(null, error); return(null); } NetSegmentData data = (NetSegmentData)ret; ObjectStorage.Instance.Segments.AddDataToDictionary(data); shell.AssignData(data); return(null); }); return(shell); }
/// <summary> /// IEnumerator that yields until a selection was made. /// </summary> /// <param name="mode"></param> /// <param name="entityToPosition"></param> /// <param name="setInteractive"></param> /// <param name="abortable"></param> /// <param name="mode"></param> /// <returns></returns> private IEnumerator WaitForSelection(IPositionable entityToPosition, bool setInteractive = true, bool abortable = true, int mode = 0) { Game.StopSkipping(); Aborted = false; Enabled = true; Visible = true; SelectionMade = false; bool previousWorldInteractive = World.Interactive; if (setInteractive) { World.Interactive = true; } entityToPosition.BeginPosition(mode); while (!SelectionMade && !Aborted) { SetPosition(entityToPosition, mode); yield return(0); } SetPosition(entityToPosition, mode); entityToPosition.EndPosition(mode); if (setInteractive) { World.Interactive = previousWorldInteractive; } Enabled = false; Visible = false; }
protected SinglePointTileContainmantManager(GameState game, IPositionable subject) { this.game = game; this.subject = subject; this.Update(); }
public Attack(Actor self, Target target, bool allowMovement, bool forceAttack) { this.target = target; this.forceAttack = forceAttack; attackTraits = self.TraitsImplementing <AttackFrontal>().ToArray(); revealsShroud = self.TraitsImplementing <RevealsShroud>().ToArray(); facing = self.Trait <IFacing>(); positionable = self.Trait <IPositionable>(); move = allowMovement ? self.TraitOrDefault <IMove>() : null; // The target may become hidden between the initial order request and the first tick (e.g. if queued) // Moving to any position (even if quite stale) is still better than immediately giving up if ((target.Type == TargetType.Actor && target.Actor.CanBeViewedByPlayer(self.Owner)) || target.Type == TargetType.FrozenActor || target.Type == TargetType.Terrain) { lastVisibleTarget = Target.FromPos(target.CenterPosition); lastVisibleMaximumRange = attackTraits.Where(x => !x.IsTraitDisabled) .Min(x => x.GetMaximumRangeVersusTarget(target)); if (target.Type == TargetType.Actor) { lastVisibleOwner = target.Actor.Owner; lastVisibleTargetTypes = target.Actor.GetEnabledTargetTypes(); } else if (target.Type == TargetType.FrozenActor) { lastVisibleOwner = target.FrozenActor.Owner; lastVisibleTargetTypes = target.FrozenActor.TargetTypes; } } }
/// <summary> /// Verifies <paramref name="action"/> is executed after setting the position of /// <paramref name="positionable"/> to <paramref name="temporalPosition"/> and then /// gets restored to <paramref name="originalPosition"/>. /// </summary> /// /// <remarks> /// This should be called within a <see cref="Received.InOrder(Action)"/> block. /// </remarks> /// /// <param name="positionable">The posibionable to verify.</param> /// <param name="originalPosition">The expected original position.</param> /// <param name="temporalPosition">The expected temporal position.</param> /// <param name="action">The action to be executed.</param> public static void VerifyDoAtPosition(this IPositionable positionable, long originalPosition, long temporalPosition, Action action) { positionable.GetPosition(); positionable.SetPosition(temporalPosition); action.Invoke(); positionable.SetPosition(originalPosition); }
/// <summary> /// Refreshes the sprite's position according to its anchor information. /// </summary> /// <param name="sprite"></param> public static void refreshPosition(this IPositionable sprite) { // Get sprite depth var depth = sprite.position.z; // Get anchor info var anchorInfo = sprite.anchorInfo; // Get parent anchor position var position = parentAnchorPosition(anchorInfo.ParentUIObject, anchorInfo.ParentUIyAnchor, anchorInfo.ParentUIxAnchor); // Add position offset if (anchorInfo.UIPrecision == UIPrecision.Percentage) { position.x += UIRelative.xPercentFrom(anchorInfo.UIxAnchor, parentWidth(anchorInfo.ParentUIObject), anchorInfo.OffsetX); position.y -= UIRelative.yPercentFrom(anchorInfo.UIyAnchor, parentHeight(anchorInfo.ParentUIObject), anchorInfo.OffsetY); } else { position.x += UIRelative.xPixelsFrom(anchorInfo.UIxAnchor, anchorInfo.OffsetX); position.y -= UIRelative.yPixelsFrom(anchorInfo.UIyAnchor, anchorInfo.OffsetY); } // Adjust for anchor offset position.x -= UIRelative.xAnchorAdjustment(anchorInfo.UIxAnchor, sprite.width, anchorInfo.OriginUIxAnchor); position.y += UIRelative.yAnchorAdjustment(anchorInfo.UIyAnchor, sprite.height, anchorInfo.OriginUIyAnchor); // Set depth position.z = depth; // Set new position sprite.position = position; }
/// <summary> /// Returns anchor position for a given parent and fallback to Screen if parent is null. /// </summary> /// <param name="sprite">Provided parent</param> /// <param name="yAnchor">Vertical anchor</param> /// <param name="xAnchor">Horizontal anchor</param> /// <returns>Adjusted anchor position</returns> private static Vector3 parentAnchorPosition(IPositionable sprite, UIyAnchor yAnchor, UIxAnchor xAnchor) { Vector3 position; float width, height; UIxAnchor originUIxAnchor = UIxAnchor.Left; UIyAnchor originUIyAnchor = UIyAnchor.Top; // Determine correct parent values if (sprite == null) { position = Vector3.zero; width = Screen.width; height = Screen.height; } else { position = sprite.position; width = sprite.width; height = sprite.height; originUIxAnchor = sprite.anchorInfo.OriginUIxAnchor; originUIyAnchor = sprite.anchorInfo.OriginUIyAnchor; } // Adjust anchor offset position.x += UIRelative.xAnchorAdjustment(xAnchor, width, originUIxAnchor); position.y -= UIRelative.yAnchorAdjustment(yAnchor, height, originUIyAnchor); return(position); }
public void CollidedWith(IPositionable @object) { if (HasTimeout() || !(@object is Monster)) return; _life--; _timeOutFrom = DateTime.Now; }
/// <summary> /// Refreshes the sprite's anchoring offsets according to its parent and position. /// </summary> /// <param name="sprite"></param> public static void refreshAnchorInformation(this IPositionable sprite) { // Get anchor info UIAnchorInfo anchorInfo = sprite.anchorInfo; // Get anchor positions Vector3 parentPosition = parentAnchorPosition(anchorInfo.ParentUIObject, anchorInfo.ParentUIyAnchor, anchorInfo.ParentUIxAnchor); Vector3 diffAnchor = sprite.position - parentPosition; // Adjust for sprite anchor offset diffAnchor.x += UIRelative.xAnchorAdjustment(anchorInfo.UIxAnchor, sprite.width, anchorInfo.OriginUIxAnchor); diffAnchor.y -= UIRelative.yAnchorAdjustment(anchorInfo.UIyAnchor, sprite.height, anchorInfo.OriginUIyAnchor); // Adjust parent anchor offsets if (anchorInfo.UIPrecision == UIPrecision.Percentage) { anchorInfo.OffsetX = UIRelative.xPercentTo(anchorInfo.UIxAnchor, parentWidth(anchorInfo.ParentUIObject), diffAnchor.x); anchorInfo.OffsetY = -UIRelative.yPercentTo(anchorInfo.UIyAnchor, parentHeight(anchorInfo.ParentUIObject), diffAnchor.y); } else { anchorInfo.OffsetX = UIRelative.xPixelsTo(anchorInfo.UIxAnchor, diffAnchor.x); anchorInfo.OffsetY = -UIRelative.yPixelsTo(anchorInfo.UIyAnchor, diffAnchor.y); } // Set update anchor info sprite.anchorInfo = anchorInfo; }
public FallDown(Actor self, WPos dropPosition, int fallRate, Actor ignoreActor = null) { pos = self.TraitOrDefault<IPositionable>(); IsInterruptible = false; fallVector = new WVec(0, 0, fallRate); this.dropPosition = dropPosition; }
public void run() { isRunning = true; cts = new CancellationTokenSource(); CancellationToken token = cts.Token; taskExecute = Task.Factory.StartNew(() => { do { foreach (var command in commands) { if (executionSettings.humanMouseMove && command is IPositionable) { IPositionable pos = command as IPositionable; if (moveTo(pos.x, pos.y, command.delay.TotalMilliseconds)) { break; } } else if (cts.Token.WaitHandle.WaitOne(command.delay)) { break; } command.execute(); } } while (executionSettings.loop); isRunning = false; onFinish?.Invoke(); }, token); }
public void LoadLevel(string path) { using (StreamReader sr = new StreamReader(path)) { m_n = Convert.ToInt32(sr.ReadLine()); m_m = Convert.ToInt32(sr.ReadLine()); while (!sr.EndOfStream) { string type = sr.ReadLine(); ISerializable unit; switch (type) { case "floor": unit = new Floor(); break; case "wall": unit = new Wall(); break; case "tank": unit = new Tank(); break; default: unit = new Floor(); break; } unit.Load(sr); IPositionable positionOfUnit = unit as IPositionable; m_field[positionOfUnit.Position.X, positionOfUnit.Position.Y] = positionOfUnit; } } }
public FallDown(Actor self, WPos currentPosition, int fallRate) { pos = self.TraitOrDefault <IPositionable>(); IsInterruptible = false; fallVector = new WVec(0, 0, fallRate); this.currentPosition = currentPosition; }
public static CMap Create(IMapLoader loader) { Int32 width = loader.GetWidth(); Int32 height = loader.GetHeight(); var map = new CMap(width, height); for (var x = 0; x < map.Width; x++) { for (var y = 0; y < map.Height; y++) { var position = new SPoint(x, y); ICell cell = loader.GetCell(position); map.SetCell(cell); IPositionable unit = loader.GetUnit(position); if (unit != null) { unit.SetMap(map); unit.SetPosition(new SPoint(x, y)); //map.Spawn(unit, position.X, position.Y); } } } return(map); }
public Parachutable(ActorInitializer init, ParachutableInfo info) { this.self = init.self; this.info = info; positionable = self.TraitOrDefault <IPositionable>(); }
public PositionableSphere(IPositionable positionable, Sphere sphere) { EnsureArg.IsNotNull(positionable, nameof(positionable)); Positionable = positionable; Sphere = sphere; }
public Element(EntityId id, IHitable hitable, IScatterable scatterable, IPositionable positionable) { Id = id; Hitable = hitable; Scatterable = scatterable; Positionable = positionable; }
public Parachute(Actor self) { pos = self.TraitOrDefault <IPositionable>(); fallVector = new WVec(0, 0, self.Info.TraitInfo <ParachutableInfo>().FallRate); IsInterruptible = false; }
public FallDown(Actor self, WPos dropPosition, int fallRate, Actor ignoreActor = null) { pos = self.TraitOrDefault <IPositionable>(); IsInterruptible = false; fallVector = new WVec(0, 0, fallRate); this.dropPosition = dropPosition; }
public Node create_node(IPositionable position, object prefab) { if (!(prefab is string) && !(prefab is NetPrefab)) { throw new Exception("Prefab must be string or NetPrefab"); } CreateNodeMessage msg = new CreateNodeMessage() { Position = position.position, Type = prefab is NetPrefab ? ((NetPrefab)prefab).name : (string)prefab }; Node shell = ObjectStorage.Instance.Nodes.CreateShell(); client.RemoteCall(Contracts.CreateNode, msg, (ret, error) => { if (error != null) { shell.AssignData(null, error); return(null); } NetNodeData data = (NetNodeData)ret; ObjectStorage.Instance.Nodes.AddDataToDictionary(data); shell.AssignData(data); return(null); }); return(shell); }
/// <summary> /// Immediately finish any transition, and copy current target information /// to its equivalent 'old' field /// </summary> private void FinishTransition() { oldTarget = target; oldTargetPos = targetPos; transitionPos = Vector2.Zero; transitionRemaining = 0; }
/// <summary> /// Gets the type of the property whose name we can obtain at compile-time. /// </summary> /// <param name="baseType">The base object type</param> /// <param name="propertyExpressionPositionable">The position of the property name expression</param> /// <param name="propertyName">The resolved property name</param> private TypeSymbol GetNamedPropertyType(ObjectType baseType, IPositionable propertyExpressionPositionable, string propertyName) { if (baseType.TypeKind == TypeKind.Any) { // all properties of "any" type are of type "any" return(LanguageConstants.Any); } // is there a declared property with this name var declaredProperty = baseType.Properties.TryGetValue(propertyName); if (declaredProperty != null) { if (declaredProperty.Flags.HasFlag(TypePropertyFlags.WriteOnly)) { return(new ErrorTypeSymbol(DiagnosticBuilder.ForPosition(propertyExpressionPositionable).WriteOnlyProperty(baseType, propertyName))); } // there is - return its type return(declaredProperty.Type); } // the property is not declared // check additional properties if (baseType.AdditionalPropertiesType != null) { // yes - return the additional property type return(baseType.AdditionalPropertiesType); } return(new ErrorTypeSymbol(DiagnosticBuilder.ForPosition(propertyExpressionPositionable).UnknownProperty(baseType, propertyName))); }
/// <summary> /// Lock the camera onto the specified target. /// </summary> /// <param name="target">The GameplayObject to follow or "lock on" to</param> /// <param name="immediate">If the lock is not immediate, the last transition position is saved and the transition finishes from transition position to the new target</param> public void LockTarget(IPositionable target, bool immediate) { if (immediate) { // End the transition, set the pos as the current vector lock FinishTransition(); mode = CameraMode.LockedTarget; this.target = target; } else { switch (mode) { case CameraMode.LockedPos: oldTargetPos = targetPos; break; case CameraMode.LockedTarget: oldTargetPos = target.GetPosition(); break; case CameraMode.TtTTransition: case CameraMode.TtVTransition: case CameraMode.VtTTransition: case CameraMode.VtVTransition: oldTargetPos = transitionPos; break; } //Complete the transition from its current position this.target = target; mode = CameraMode.VtTTransition; } isTransformDirty = true; }
private void UpdateActiveObjectStatus(object xiObject) { string lStatus = ""; Chunk lChunk = xiObject as Chunk; if (lChunk != null) { lStatus += lChunk.Name + " - "; } IPositionable lPos = xiObject as IPositionable; if (lPos != null) { lStatus += string.Format(" Pos: ({0},{1},{2})", lPos.OriginPosition.X, lPos.OriginPosition.Y, lPos.OriginPosition.Z); } IRotatable lRot = xiObject as IRotatable; if (lRot != null) { lStatus += string.Format(" Rot: ({0},{1},{2})", lRot.RotationVector.X, lRot.RotationVector.Y, lRot.RotationVector.Z); } mMainForm.ThreeDeeEditorStatusLabel.Text = lStatus; }
public Parachutable(ActorInitializer init, ParachutableInfo info) { this.self = init.self; this.info = info; positionable = self.TraitOrDefault<IPositionable>(); }
/// <summary> /// Very much like LockTarget(target, immediate) except it allows a specification of duration. /// </summary> /// <param name="target">The GameplayObject to follow or "lock on" to</param> /// <param name="duration">Amount of time for the transition from last target or pos, or transition position (depending on last mode)</param> /// <param name="immediate">If the lock is not immediate, the last transition position is saved and the transition finishes from transition position to the new target</param> public void TransitionTo(IPositionable target, float duration, bool immediate) { LockTarget(target, immediate); if (!immediate) { transitionRemaining = transitionTime = duration; } }
/// <summary> /// Calculates the distance between this instance and another IPositionable object /// </summary> /// <param name="p">IPositionable object</param> /// <returns>Vector3 that represents the distance vector between two IPositionable objects</returns> public virtual Vector3 Distance(IPositionable p) { if (p == null) { throw new ArgumentNullException(); } return(this.Position - p.Position); }
private void PathToImpl(IPositionable last_position, IPositionable endNode, object options, Vector start_dir, Vector end_dir, Vector middle_pos) { last_segments = api._netLogic.CreateSegmentsImpl(last_position, endNode, options, start_dir, end_dir, middle_pos); segments = segments.Concat(last_segments).ToList(); first_node = first_node ?? last_segments.First().start_node; last_node = last_segments.Last().end_node; this.last_position = last_node; }
public void CollidedWith(IPositionable @object) { var goodGuy = @object as GoodGuy; if (goodGuy != null) { goodGuy.CollidedWith(this); } }
public Drag(Actor self, WPos start, WPos end, int length) { positionable = self.Trait <IPositionable>(); movement = self.TraitOrDefault <IMove>(); disableable = movement as IDisabledTrait; this.start = start; this.end = end; this.length = length; }
public void SetCameraTarget(IPositionable target, bool fix = false) { _cameraTarget = target; if (fix) { _targetPosition = target.worldPosition; } }
public static Matrix CreateTransformation(IPositionable positionable) { return Matrix.CreateTranslation(-new Vector3(positionable.Origin, 0)) * Matrix.CreateScale(new Vector3(positionable.Scale, 1)) * Matrix.CreateRotationZ(MathHelper.ToRadians(positionable.Rotation)) * Matrix.CreateTranslation(new Vector3(positionable.Origin, 0)) * Matrix.CreateTranslation(new Vector3(positionable.RenderingOffset, 0)); }
public Drag(Actor self, WPos start, WPos end, int length) { positionable = self.Trait<IPositionable>(); movement = self.TraitOrDefault<IMove>(); moveDisablers = self.TraitsImplementing<IDisableMove>().ToArray(); this.start = start; this.end = end; this.length = length; }
public Boolean SetUnit(IPositionable unit, SPoint point) { //TODO: Check cell on free space ICell cell = GetCell(point); cell.Unit = unit; MapUpdated?.Invoke(this, EventArgs.Empty); return(true); }
public Drag(Actor self, WPos start, WPos end, int length) { positionable = self.Trait <IPositionable>(); movement = self.TraitOrDefault <IMove>(); moveDisablers = self.TraitsImplementing <IDisableMove>(); this.start = start; this.end = end; this.length = length; }
public Drag(Actor self, WPos start, WPos end, int length) { positionable = self.Trait<IPositionable>(); movement = self.TraitOrDefault<IMove>(); disableable = movement as IDisabledTrait; this.start = start; this.end = end; this.length = length; }
public Parachute(Actor self, WPos dropPosition) { um = self.TraitOrDefault<UpgradeManager>(); pos = self.TraitOrDefault<IPositionable>(); // Parachutable trait is a prerequisite for running this activity para = self.Info.Traits.Get<ParachutableInfo>(); fallVector = new WVec(0, 0, para.FallRate); this.dropPosition = dropPosition; }
public SwallowActor(Actor self, Target target, WeaponInfo weapon) { this.target = target; this.weapon = weapon; sandworm = self.Trait<Sandworm>(); positionable = self.Trait<Mobile>(); swallow = self.Trait<AttackSwallow>(); manager = self.Trait<UpgradeManager>(); radarPings = self.World.WorldActor.TraitOrDefault<RadarPings>(); }
public Parachute(Actor self, WPos dropPosition, Actor ignoreActor = null) { pos = self.TraitOrDefault<IPositionable>(); ignore = ignoreActor; // Parachutable trait is a prerequisite for running this activity para = self.Info.TraitInfo<ParachutableInfo>(); fallVector = new WVec(0, 0, para.FallRate); this.dropPosition = dropPosition; IsInterruptible = false; }
public bool Equal(IPositionable unit) { if (unit is Floor && unit != null) { if (unit.Position == m_position) { return true; } } return false; //return (tank.Position == m_position) ? true : false; }
public Attack(Actor self, Target target, bool allowMovement, bool forceAttack) { Target = target; this.forceAttack = forceAttack; attack = self.Trait<AttackBase>(); facing = self.Trait<IFacing>(); positionable = self.Trait<IPositionable>(); move = allowMovement ? self.TraitOrDefault<IMove>() : null; }
public Attack(Actor self, Target target, WDist minRange, WDist maxRange, bool allowMovement) { Target = target; this.minRange = minRange; this.maxRange = maxRange; attack = self.Trait<AttackBase>(); facing = self.Trait<IFacing>(); positionable = self.Trait<IPositionable>(); move = allowMovement ? self.TraitOrDefault<IMove>() : null; }
public DeliverUnit(Actor self) { carryall = self.Trait<Carryall>(); this.self = self; cargo = carryall.Carrying; movement = self.Trait<IMove>(); carryable = cargo.Trait<Carryable>(); aircraft = self.Trait<Aircraft>(); positionable = cargo.Trait<IPositionable>(); cargoFacing = cargo.Trait<IFacing>(); selfFacing = self.Trait<IFacing>(); state = State.Transport; }
public DeliverUnit(Actor self, CPos destination) { this.self = self; this.destination = destination; carryallFacing = self.Trait<IFacing>(); carryall = self.Trait<Carryall>(); body = self.Trait<BodyOrientation>(); carryable = carryall.Carryable.Trait<Carryable>(); positionable = carryall.Carryable.Trait<IPositionable>(); carryableFacing = carryall.Carryable.Trait<IFacing>(); state = State.Transport; }
public SwallowActor(Actor self, Target target, WeaponInfo weapon) { this.target = target; this.weapon = weapon; sandworm = self.Trait<Sandworm>(); positionable = self.Trait<Mobile>(); swallow = self.Trait<AttackSwallow>(); renderUnit = self.Trait<RenderUnit>(); radarPings = self.World.WorldActor.TraitOrDefault<RadarPings>(); countdown = swallow.Info.AttackTime; renderUnit.DefaultAnimation.ReplaceAnim("burrowed"); stance = AttackState.Burrowed; location = target.Actor.Location; }
public SwallowActor(Actor self, Target target, WeaponInfo weapon) { this.target = target; this.weapon = weapon; sandworm = self.Trait<Sandworm>(); positionable = self.Trait<Mobile>(); swallow = self.Trait<AttackSwallow>(); withSpriteBody = self.Trait<WithSpriteBody>(); radarPings = self.World.WorldActor.TraitOrDefault<RadarPings>(); countdown = swallow.Info.AttackTime; withSpriteBody.DefaultAnimation.ReplaceAnim(sandworm.Info.BurrowedSequence); stance = AttackState.Burrowed; location = target.Actor.Location; }
private bool OnBorder(IPositionable unit) { if (((unit.Position.X >= 0 && unit.Position.X <= m_n) && (unit.Position.Y == 0 || unit.Position.Y == m_m)) || ((unit.Position.Y >= 1 && unit.Position.Y <= m_m - 1) && (unit.Position.X == 0 || unit.Position.X == m_n))) { return true; } return false; //if (m_walls.Exist(unit)) //{ // if ((unit.Position.X == 0 || unit.Position.X == (m_level.N - 1) * WIDTH) && (unit.Position.Y >= 0 || unit.Position.Y <= (m_level.M - 1) * HEIGHT) || // (unit.Position.Y == 0 || unit.Position.Y == (m_level.M - 1) * Height) && (unit.Position.X >= 0 || unit.Position.X <= (m_level.N - 1) * WIDTH)) // { // return true; // } //} //return false; }
/// <summary> /// Calculates the distance between this instance and another IPositionable object /// </summary> /// <param name="p">IPositionable object</param> /// <returns>Vector3 that represents the distance vector between two IPositionable objects</returns> public Vector3 Distance(IPositionable p) { if (p == null) return null; if (p is Ray) return Distance((Ray)p); Vector3 difference = p.Position - this.position; double proy = Vector3.Dot(director, difference); Vector3 a = this.position + proy * director; return p.Position - a; }
/// <summary> /// Checks if this instance of Ray contains the point provided by the IPositionable instance /// </summary> /// <param name="position">IPositionable object to check contention with</param> /// <returns>true if the IPositionable object provided is inside this instance, false otherwise</returns> public bool Contains(IPositionable position) { throw new Exception("The method or operation is not implemented."); }
/// <summary> /// Returns width of parent or screen if parent is null /// </summary> /// <param name="sprite">Provided parent</param> /// <returns>Width of parent (or screen)</returns> private static float parentWidth(IPositionable sprite) { return (sprite == null) ? Screen.width : sprite.width; }
private bool NeedsResolveMap(IPositionable player) { Check.NullArgument<IPositionable>(player, "player"); var map = player.CurrentMap; var loc = player.GlobalTileLocation; if (map == null) return true; var maprect = new Rectangle(map.MapLocation.IntX, map.MapLocation.IntY, map.Map.MapSize.IntX, map.Map.MapSize.IntY); return (!maprect.Contains(loc.IntX, loc.IntY)); }
/// <summary> /// Calculates the distance between this instance and another IPositionable object /// </summary> /// <param name="p">IPositionable object</param> /// <returns>Vector3 that represents the distance vector between two IPositionable objects</returns> public virtual Vector3 Distance(IPositionable p) { if (p == null) throw new ArgumentNullException(); return this.Position - p.Position; }
/// <summary> /// Returns height of parent or screen if parent is null /// </summary> /// <param name="sprite">Provided parent</param> /// <returns>Height of parent (or screen)</returns> private static float parentHeight(IPositionable sprite) { return (sprite == null) ? Screen.height : sprite.height; }
public void SetFocus(IPositionable focus) { _focus = focus; }
/// <summary> /// Returns anchor position for a given parent and fallback to Screen if parent is null. /// </summary> /// <param name="sprite">Provided parent</param> /// <param name="yAnchor">Vertical anchor</param> /// <param name="xAnchor">Horizontal anchor</param> /// <returns>Adjusted anchor position</returns> private static Vector3 parentAnchorPosition( IPositionable sprite, UIyAnchor yAnchor, UIxAnchor xAnchor ) { Vector3 position; float width, height; UIxAnchor originUIxAnchor = UIxAnchor.Left; UIyAnchor originUIyAnchor = UIyAnchor.Top; // Determine correct parent values if (sprite == null) { position = Vector3.zero; width = Screen.width; height = Screen.height; } else { position = sprite.position; width = sprite.width; height = sprite.height; originUIxAnchor = sprite.anchorInfo.OriginUIxAnchor; originUIyAnchor = sprite.anchorInfo.OriginUIyAnchor; } // Adjust anchor offset position.x += UIRelative.xAnchorAdjustment(xAnchor, width, originUIxAnchor); position.y -= UIRelative.yAnchorAdjustment(yAnchor, height, originUIyAnchor); return position; }
private bool ResolvePositionableCurrentMap(IPositionable player) { if (!this.NeedsResolveMap(player)) return true; player.CurrentMap = null; bool found = false; World currentworld = this.context.WorldManager.GetWorld(player.WorldName); foreach(MapHeader header in currentworld.Maps.Values) { Rectangle rect = (header.MapLocation).ToRect(header.Map.MapSize.ToPoint()); if(rect.Contains(player.GlobalTileLocation.ToPoint())) { player.CurrentMap = header; found = true; } } return found; }
/// <summary> /// Checks if this instance of IIntersectable contains the provided IPositionable instance /// </summary> /// <param name="position">IPositionable object to check contention with</param> /// <returns>true if the IPositionable object provided is inside this instance, false otherwise</returns> public virtual bool Contains(IPositionable position) { throw new NotImplementedException(); //Matrix homogeneous; //homogeneous = Homogeneous; //for (int i = 0; i < 7; ++i) // Vertexes[i] = (Vector3)(homogeneous * (Vector)Vertexes[i]); }