public CutTask(MotionComponent motionComponent, Vector2Int targetPosition, ICuttable cuttable) { AddCommand(new MoveCommand(motionComponent, targetPosition)); AddCommand(new RotateToCommand(motionComponent, Utils.NodeAt((cuttable as StaticObject).Position))); AddCommand(new WaitCommand(1f)); AddCommand(new CutCommand(cuttable)); }
public BuildTask(ConstructionPlan plan, MotionComponent motionComponent, Vector2Int targetPosition) { this.AddCommand(new MoveCommand(motionComponent, targetPosition)); this.AddCommand(new RotateToCommand(motionComponent, Utils.NodeAt(plan.Position))); this.AddCommand(new WaitCommand(1f)); this.AddCommand(new BuildCommand(plan)); }
public string[] GetPresetPositionList() { // load the existed preset using (SqliteDb db = new SqliteDb()) { return(db.GetPresetPositionNames(MotionComponent.GetHashCode())); } }
public HaulTask(Item item, Vector2Int destinationPosition, MotionComponent motionComponent, InventoryComponent inventory) { Node itemNode = Utils.NodeAt(item.Position); Node humanNode = Utils.NodeAt(motionComponent.GridPosition); Node destinationNode = Utils.NodeAt(destinationPosition); AddCommand(new MoveCommand(motionComponent, SearchEngine.FindNodeNear(itemNode, humanNode).Position)); AddCommand(new PickCommand(item, inventory)); AddCommand(new MoveCommand(motionComponent, SearchEngine.FindNodeNear(destinationNode, SearchEngine.FindNodeNear(itemNode, humanNode)).Position)); AddCommand(new DropCommand(item, inventory, destinationPosition)); }
public HaulToItemHolderTask(Item item, IItemHolder itemHolder, MotionComponent motionComponent, InventoryComponent inventory) { Node itemNode = Utils.NodeAt(item.Position); Node humanNode = Utils.NodeAt(motionComponent.GridPosition); Node destinationNode = Utils.NodeAt((itemHolder as StaticObject).Position); AddCommand(new MoveCommand(motionComponent, SearchEngine.FindNodeNear(itemNode, humanNode).Position)); AddCommand(new PickCommand(item, inventory)); AddCommand(new MoveCommand(motionComponent, SearchEngine.FindNodeNear(destinationNode, SearchEngine.FindNodeNear(itemNode, humanNode)).Position)); AddCommand(new DropIntoCommand(item, inventory, itemHolder)); }
public override void OnCollision(CollidableEntity other) { base.OnCollision(other); if (other is Projectile p && p.MovingUp) { this.Collection.Get <GroundCannon>().Get <ScoreComponent>().Score += 100; MotionComponent motion = this.Get <MotionComponent>(); motion.Velocity *= -1.1f; //reverse and speed up this.Position = new Vector2(-this.MaxPos * System.Math.Sign(motion.Velocity.X), this.Position.Y); } }
private EntityDataPacket CreateEntityStatePacket(Entity e) { EntityDataPacket p = new EntityDataPacket(); TransformComponent position = e.GetComponent <TransformComponent>(); p.EntityId = e.EntityId; p.PositionX = position.Position.X; p.PositionY = position.Position.Y; p.Rotation = position.Rotation; MotionComponent motion = e.GetComponent <MotionComponent>(); if (motion != null) { p.VelocityX = motion.Velocity.X; p.VelocityY = motion.Velocity.Y; p.AngularVelocity = motion.AngularVelocity; } return(p); }
protected virtual void InitializeMotionComponent(Vector2Int position) { MotionComponent = new MotionComponent(Data.movementSpeed, position, gameObject); MotionComponent.OnGridPositionChange += HandleGridPosition; Components.Add(MotionComponent); }
public MoveCommand(MotionComponent motionComponent, Vector2Int destination) { _motionComponent = motionComponent; _destination = destination; }
public void Dispose() { AllLightsOff(); MotionComponent?.Dispose(); }
public void Reset() { AllLightsOff(); TiltController?.Reset(); MotionComponent?.Stop(); }
public RotateToCommand(MotionComponent motionComponent, Node destinationNode) { _motionComponent = motionComponent; _destinationNode = destinationNode; }
public override int GetHashCode() { return(MotionComponent.GetHashCode()); }
public void SavePresetPosition(string Name) { try { PresetPosition pos = new PresetPosition() { Name = Name, MotionComponentHashCode = MotionComponent.GetHashCode(), Items = new PresetPositionItem[AxisControlCollection.Count] }; for (int i = 0; i < AxisControlCollection.Count; i++) { pos.Items[i] = AxisControlCollection[i].PresetAggregation; } using (SqliteDb db = new SqliteDb()) { // check if the preset exists if (db.ReadPresetPosition(pos.MotionComponentHashCode, Name, out PresetPosition preset)) { if (preset == null) { // save the preset position db.SavePresetPosition(pos); Messenger.Default.Send <NotificationMessage <string> >(new NotificationMessage <string>( this, string.Format("The preset position saved successfully."), "NOTIFY")); } else { // overwrite Messenger.Default.Send <NotificationMessageAction <MessageBoxResult> >(new NotificationMessageAction <MessageBoxResult>( this, "AskForOverwrite", (ret) => { if (ret == MessageBoxResult.Yes) { // overwrite the current preset position if (db.DeletePresetPosition(pos.MotionComponentHashCode, pos.Name)) { // save the preset position db.SavePresetPosition(pos); Messenger.Default.Send <NotificationMessage <string> >(new NotificationMessage <string>( this, string.Format("The preset position saved successfully."), "NOTIFY")); } else { Messenger.Default.Send <NotificationMessage <string> >(new NotificationMessage <string>( this, string.Format("Unable to delete the preset position, {0}", db.LastError), "ERROR")); } } } )); } } else { // error while reading preset position from database Messenger.Default.Send <NotificationMessage <string> >(new NotificationMessage <string>( this, string.Format("Unable to check the existence of the preset position, {0}", db.LastError), "ERROR")); } } } catch (Exception ex) { Messenger.Default.Send <NotificationMessage <string> >(new NotificationMessage <string>( this, string.Format("Unable to save the preset position, {0}", ex.Message), "ERROR")); } }
public MoveTask(MotionComponent motionComponent, Vector2Int destination) { AddCommand(new MoveCommand(motionComponent, destination)); }