Esempio n. 1
0
 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));
 }
Esempio n. 2
0
 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()));
     }
 }
Esempio n. 4
0
    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));
    }
Esempio n. 6
0
        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);
            }
        }
Esempio n. 7
0
        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);
        }
Esempio n. 8
0
 protected virtual void InitializeMotionComponent(Vector2Int position)
 {
     MotionComponent = new MotionComponent(Data.movementSpeed, position, gameObject);
     MotionComponent.OnGridPositionChange += HandleGridPosition;
     Components.Add(MotionComponent);
 }
Esempio n. 9
0
 public MoveCommand(MotionComponent motionComponent, Vector2Int destination)
 {
     _motionComponent = motionComponent;
     _destination     = destination;
 }
Esempio n. 10
0
 public void Dispose()
 {
     AllLightsOff();
     MotionComponent?.Dispose();
 }
Esempio n. 11
0
 public void Reset()
 {
     AllLightsOff();
     TiltController?.Reset();
     MotionComponent?.Stop();
 }
Esempio n. 12
0
 public RotateToCommand(MotionComponent motionComponent, Node destinationNode)
 {
     _motionComponent = motionComponent;
     _destinationNode = destinationNode;
 }
Esempio n. 13
0
 public override int GetHashCode()
 {
     return(MotionComponent.GetHashCode());
 }
Esempio n. 14
0
        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"));
            }
        }
Esempio n. 15
0
 public MoveTask(MotionComponent motionComponent, Vector2Int destination)
 {
     AddCommand(new MoveCommand(motionComponent, destination));
 }