예제 #1
0
        public static BaseRequest messageFromBytes(byte[] buffer)
        {
            VRage.ByteStream stream = new VRage.ByteStream(buffer, buffer.Length);
            TYPE t = (TYPE)stream.getUShort();
            stream.Seek(0, System.IO.SeekOrigin.Begin);

            BaseRequest msg = null;
            switch (t) {
                case TYPE.FLEET:
                    msg = new FleetRequest();
                    break;
                case TYPE.SETTINGS:
                    msg = new SettingsRequest();
                    break;
                case TYPE.VIOLATIONS:
                    msg = new ViolationsRequest();
                    break;
                case TYPE.DISOWN:
                    msg = new DisownRequest();
                    break;
                case TYPE.STOPGRID:
                    msg = new StopGridRequest();
                    break;
            }

            if (msg != null)
                msg.deserialize(stream);
            return msg;
        }
예제 #2
0
        public bool requestStopGrid(string shipClass, string ID)
        {
            log("Sending Stop Grid request", "requestStopGrid");
            try {
                HullClass.CLASS classID;
                int             localID = -1;

                // Check user's input for shipClass is valid
                if (!Enum.TryParse <HullClass.CLASS>(shipClass.ToUpper(), out classID))
                {
                    MyAPIGateway.Utilities.ShowNotification("Invalid Ship Class!", Constants.NotificationMillis, MyFontEnum.Red);
                    return(false);
                }
                // Check if user's input for index is valid
                if (!int.TryParse(ID, out localID) || localID < 1 || localID > m_SupportedGrids[(int)classID].Count + m_UnsupportedGrids[(int)classID].Count)
                {
                    MyAPIGateway.Utilities.ShowNotification("Invalid Index!", Constants.NotificationMillis, MyFontEnum.Red);
                    return(false);
                }

                long entityID;

                //Some logic to decide whether or not the choice is a supported or unsupported grid, and its entityID
                if (localID - 1 >= m_SupportedGrids[(int)classID].Count)
                {
                    entityID = m_UnsupportedGrids[(int)classID][localID - 1 - m_SupportedGrids[(int)classID].Count].shipID;
                }
                else
                {
                    entityID = m_SupportedGrids[(int)classID][localID - 1].shipID;
                }

                StopGridRequest req = new StopGridRequest();
                req.ReturnAddress = MyAPIGateway.Session.Player.PlayerID;
                req.EntityID      = entityID;
                send(req);
                return(true);
            }
            catch (Exception e) {
                log("Exception occured: " + e, "requestStopGrid");
                return(false);
            }
        }
예제 #3
0
        public static BaseRequest messageFromBytes(byte[] buffer)
        {
            VRage.ByteStream stream = new VRage.ByteStream(buffer, buffer.Length);
            TYPE             t      = (TYPE)stream.getUShort();

            stream.Seek(0, System.IO.SeekOrigin.Begin);

            BaseRequest msg = null;

            switch (t)
            {
            case TYPE.FLEET:
                msg = new FleetRequest();
                break;

            case TYPE.SETTINGS:
                msg = new SettingsRequest();
                break;

            case TYPE.VIOLATIONS:
                msg = new ViolationsRequest();
                break;

            case TYPE.DISOWN:
                msg = new DisownRequest();
                break;

            case TYPE.STOPGRID:
                msg = new StopGridRequest();
                break;
            }

            if (msg != null)
            {
                msg.deserialize(stream);
            }
            return(msg);
        }
예제 #4
0
        public bool requestStopGrid(string shipClass, string ID)
        {
            log("Sending Stop Grid request", "requestStopGrid");
            try {
                HullClass.CLASS classID;
                int localID = -1;

                // Check user's input for shipClass is valid
                if (!Enum.TryParse<HullClass.CLASS>(shipClass.ToUpper(), out classID)) {
                    MyAPIGateway.Utilities.ShowNotification("Invalid Ship Class!", Constants.NotificationMillis, MyFontEnum.Red);
                    return false;
                }
                // Check if user's input for index is valid
                if (!int.TryParse(ID, out localID) || localID < 1 || localID > m_SupportedGrids[(int)classID].Count + m_UnsupportedGrids[(int)classID].Count) {
                    MyAPIGateway.Utilities.ShowNotification("Invalid Index!", Constants.NotificationMillis, MyFontEnum.Red);
                    return false;
                }

                long entityID;

                //Some logic to decide whether or not the choice is a supported or unsupported grid, and its entityID
                if (localID - 1 >= m_SupportedGrids[(int)classID].Count ) {
                    entityID = m_UnsupportedGrids[(int)classID][localID - 1 - m_SupportedGrids[(int)classID].Count].shipID;
                } else {
                    entityID = m_SupportedGrids[(int)classID][localID - 1].shipID;
                }

                StopGridRequest req = new StopGridRequest();
                req.ReturnAddress = MyAPIGateway.Session.Player.PlayerID;
                req.EntityID = entityID;
                send(req);
                return true;
            }
            catch (Exception e) {
                log("Exception occured: " + e, "requestStopGrid");
                return false;
            }
        }
예제 #5
0
        private void processStopGridRequest(StopGridRequest req)
        {
            log("", "processStopGridRequest");
            IMyCubeGrid gridToStop = MyAPIGateway.Entities.GetEntityById(req.EntityID) as IMyCubeGrid;
            List<IMySlimBlock> fatBlocks = new List<IMySlimBlock>();

            // Get all thrusters, spaceballs, artificial masses, and cockpits
            Func<IMySlimBlock, bool> selectBlocks = b =>
                b.FatBlock != null && (b.FatBlock is IMyThrust || b.FatBlock is IMySpaceBall || b.FatBlock is InGame.IMyVirtualMass || b.FatBlock is InGame.IMyShipController);
            gridToStop.GetBlocks(fatBlocks, selectBlocks);

            // Can the player interact with this grid? If they can, stop the ship by enabling dampeners, turning off
            // space balls and artificial masses, and disable thruster override
            if (gridToStop.canInteractWith(req.ReturnAddress)) {
                foreach (IMySlimBlock block in fatBlocks) {
                    // Thruster
                    if (block.FatBlock is IMyThrust) {
                        Interfaces.TerminalPropertyExtensions.SetValueFloat(block.FatBlock as IMyTerminalBlock, "Override", 0);
                    }
                    // Spaceball
                    else if (block.FatBlock is IMySpaceBall) {
                        (block.FatBlock as InGame.IMyFunctionalBlock).RequestEnable(false);
                    }
                    // Artificial Mass
                    else if (block.FatBlock is InGame.IMyVirtualMass) {
                        (block.FatBlock as InGame.IMyFunctionalBlock).RequestEnable(false);
                    }
                    // Cockpit
                    else if (block.FatBlock is InGame.IMyShipController) {
                        Interfaces.TerminalPropertyExtensions.SetValueBool(block.FatBlock as InGame.IMyShipController, "DampenersOverride", true);
                    }
                }
                gridToStop.Physics.ClearSpeed();
            }
            // Player can't interact with grid, send error message
            else {
                GridOwner.OWNER owner = GridOwner.ownerFromPlayerID(req.ReturnAddress);
                string errorMessage = "";

                // Build text based on whether or not player is in faction
                switch (owner.OwnerType) {
                    case GridOwner.OWNER_TYPE.FACTION:
                        errorMessage = "Your faction does not have control of that ship's Main Cockpit!";
                        break;
                    case GridOwner.OWNER_TYPE.PLAYER:
                        errorMessage = "You do not have control of that ship's Main Cockpit!";
                        break;
                }

                NotificationResponse noti = new NotificationResponse() {
                    NotificationText = errorMessage,
                    Time = Constants.NotificationMillis,
                    Font = MyFontEnum.Red,
                    Destination = new List<long>() { req.ReturnAddress },
                    DestType = BaseResponse.DEST_TYPE.PLAYER
                };

                send(noti);
            }
        }
예제 #6
0
        private void processStopGridRequest(StopGridRequest req)
        {
            log("", "processStopGridRequest");
            IMyCubeGrid gridToStop = MyAPIGateway.Entities.GetEntityById(req.EntityID) as IMyCubeGrid;

            // @TODO: make it easy to find enforcers by entityId so we can provide
            // greater accuracy to our canInteractWith check
            //GridEnforcer enforcer = StateTracker.getInstance().

            // Can the player interact with this grid? If they can, stop the ship by enabling dampeners, turning off
            // space balls and artificial masses, and disable thruster override
            if (gridToStop.canInteractWith(req.ReturnAddress))
            {
                // Get all thrusters, spaceballs, artificial masses, and cockpits
                List <IMySlimBlock>       fatBlocks    = new List <IMySlimBlock>();
                Func <IMySlimBlock, bool> selectBlocks = b =>
                                                         b.FatBlock != null && (b.FatBlock is IMyThrust || b.FatBlock is IMySpaceBall || b.FatBlock is InGame.IMyVirtualMass || b.FatBlock is InGame.IMyShipController);
                gridToStop.GetBlocks(fatBlocks, selectBlocks);

                foreach (IMySlimBlock block in fatBlocks)
                {
                    // Thruster
                    if (block.FatBlock is IMyThrust)
                    {
                        Interfaces.TerminalPropertyExtensions.SetValueFloat(block.FatBlock as IMyTerminalBlock, "Override", 0);
                    }
                    // Spaceball
                    else if (block.FatBlock is IMySpaceBall)
                    {
                        (block.FatBlock as InGame.IMyFunctionalBlock).RequestEnable(false);
                    }
                    // Artificial Mass
                    else if (block.FatBlock is InGame.IMyVirtualMass)
                    {
                        (block.FatBlock as InGame.IMyFunctionalBlock).RequestEnable(false);
                    }
                    // Cockpit
                    else if (block.FatBlock is InGame.IMyShipController)
                    {
                        Interfaces.TerminalPropertyExtensions.SetValueBool(block.FatBlock as InGame.IMyShipController, "DampenersOverride", true);
                    }
                }
                gridToStop.Physics.ClearSpeed();
            }
            // Player can't interact with grid, send error message
            else
            {
                GridOwner.OWNER owner        = GridOwner.ownerFromPlayerID(req.ReturnAddress);
                string          errorMessage = "";

                // Build text based on whether or not player is in faction
                switch (owner.OwnerType)
                {
                case GridOwner.OWNER_TYPE.FACTION:
                    errorMessage = "Your faction does not have control of that ship's Main Cockpit!";
                    break;

                case GridOwner.OWNER_TYPE.PLAYER:
                    errorMessage = "You do not have control of that ship's Main Cockpit!";
                    break;
                }

                NotificationResponse noti = new NotificationResponse()
                {
                    NotificationText = errorMessage,
                    Time             = Constants.NotificationMillis,
                    Font             = MyFontEnum.Red,
                    Destination      = new List <long>()
                    {
                        req.ReturnAddress
                    },
                    DestType = BaseResponse.DEST_TYPE.PLAYER
                };

                send(noti);
            }
        }