Esempio n. 1
0
        void HandleShortRightClick()
        {
            if (_selectedObjects.Count == 0)
            {
                return;
            }

            ITargetable t = null;
            //Test to see if the mouse is over a targetable object
            Fixture f = _physicsManager.World.TestPoint(_uiConversionService.MousePosToSimUnits());

            if (f != null)
            {
                //Need to store references to the actual objects in userdata to make this much prettier and simpler
                ShipBodyDataObject s = f.Body.UserData as ShipBodyDataObject;
                if (s != null && s.Ship is ITargetable)
                {
                    t = (ITargetable)s.Ship;
                }

                StructureBodyDataObject b = f.Body.UserData as StructureBodyDataObject;
                if (b != null && b.Structure is ITargetable)
                {
                    t = (ITargetable)b.Structure;
                }
            }

            if (t != null)
            {
                foreach (var s in _selectedObjects)
                {
                    ICommandable i = s.Value as ICommandable;
                    if (i != null)
                    {
                        i.AttackTarget(t);
                    }
                }
                return;
            }

            foreach (var s in _selectedObjects)
            {
                if (s.Value is Ship)
                {
                    Ship ship = (Ship)s.Value;
                    ship.Pilot.GoToPosition(_uiConversionService.MousePosToSimUnits());
                }
            }
        }
Esempio n. 2
0
 protected void SetPilot(Ship tempShip, bool IsBot)
 {
     if (!IsBot)
     {
         _playerShipManager.PlayerPilot = new PlayerPilot(tempShip);
         tempShip.Pilot = PlayerPilot;
         tempShip.SetUserData(new ShipBodyDataObject(BodyTypes.PlayerShip, tempShip.Id, tempShip));
     }
     else
     {
         var ud = new ShipBodyDataObject(BodyTypes.PlayerShip, tempShip.Id, tempShip);
         _playerShipManager.PlayerPilot = new NPCPilot(tempShip, ud);
         tempShip.IsLocalSim            = true;
         tempShip.Pilot = PlayerPilot;
         tempShip.SetUserData(ud);
     }
 }
Esempio n. 3
0
        /// <summary>
        /// Time between mouse down and mouse up is less than _shortClickTime
        /// </summary>
        void HandleShortLeftClick()
        {
            if (_selectedObjects.Count == 0)
            {
                _attack = false;
                return;
            }

            if (!_moveTo && !_attack && !_patrol)
            {
                ClearSelectedObjects();
            }
            else if (_attack)
            {
                _attack = false;
                ITargetable t = null;
                //Test to see if the mouse is over a targetable object
                Fixture f = _physicsManager.World.TestPoint(_uiConversionService.MousePosToSimUnits());

                if (f != null)
                {
                    //Need to store references to the actual objects in userdata to make this much prettier and simpler
                    ShipBodyDataObject s = f.Body.UserData as ShipBodyDataObject;
                    if (s != null && s.Ship is ITargetable)
                    {
                        t = s.Ship;
                    }

                    StructureBodyDataObject b = f.Body.UserData as StructureBodyDataObject;
                    if (b != null && b.Structure is ITargetable)
                    {
                        t = b.Structure;
                    }
                }

                if (t != null)
                {
                    foreach (var s in _selectedObjects)
                    {
                        var commandable = s.Value as ICommandable;

                        if (commandable != null)
                        {
                            commandable.AttackTarget(t);
                        }
                    }
                }
                else
                {
                    foreach (var s in _selectedObjects)
                    {
                        var commandable = s.Value as ICommandable;

                        if (commandable != null)
                        {
                            commandable.AttackToPosition(_uiConversionService.MousePosToSimUnits());
                        }
                    }
                }
            }
        }