Пример #1
0
        private void processViolationsRequest(ViolationsRequest req)
        {
            // Get an Owner object from the player ID of the request
            GridOwner.OWNER owner = GridOwner.ownerFromPlayerID(req.ReturnAddress);

            // Retrieve that owner's fleet
            FactionFleet fleet = GardenConquest.Core.StateTracker.
                                 getInstance().getFleet(owner.FleetID, owner.OwnerType);

            // Get the fleet's juicy description
            String body = fleet.violationsToString();

            // build the title
            String title = "";

            switch (owner.OwnerType)
            {
            case GridOwner.OWNER_TYPE.FACTION:
                title = "Your Faction's Fleet's Violations";
                break;

            case GridOwner.OWNER_TYPE.PLAYER:
                title = "Your Fleet Violations";
                break;
            }

            // send the response
            DialogResponse resp = new DialogResponse()
            {
                Body        = body,
                Title       = title,
                Destination = new List <long>()
                {
                    req.ReturnAddress
                },
                DestType = BaseResponse.DEST_TYPE.PLAYER
            };

            send(resp);
        }
Пример #2
0
        private void processFleetRequest(FleetRequest req)
        {
            // Get an Owner object from the palyer ID of the request
            GridOwner.OWNER owner = GridOwner.ownerFromPlayerID(req.ReturnAddress);

            // Retrieve that owner's fleet
            FactionFleet fleet = GardenConquest.Core.StateTracker
                                 .getInstance().getFleet(owner.FleetID, owner.OwnerType);

            FleetResponse resp = new FleetResponse()
            {
                Fleet       = fleet,
                Owner       = owner,
                Destination = new List <long>()
                {
                    req.ReturnAddress
                },
                DestType = BaseResponse.DEST_TYPE.PLAYER
            };

            send(resp);
        }
 public static long FleetID(this IMyPlayer player)
 {
     return(GridOwner.ownerFromPlayerID(player.PlayerID).FleetID);
 }
Пример #4
0
        public void eventPlacementViolation(GridEnforcer ge, GridEnforcer.VIOLATION_TYPE v)
        {
            log("hit", "eventGridViolation");

            // Check for players within the vicinity of the grid, since there's no
            // built-in way to tell who just placed the block
            List <long> players = ge.Grid.getPlayerIDsWithinPlacementRadius();

            if (players.Count <= 0)
            {
                return;
            }

            string message = "";

            if (v == GridEnforcer.VIOLATION_TYPE.TOTAL_BLOCKS)
            {
                message = "No more blocks allowed for this Class";
            }
            else if (v == GridEnforcer.VIOLATION_TYPE.BLOCK_TYPE)
            {
                message = "No more blocks of this type allowed for this Class";
            }
            else if (v == GridEnforcer.VIOLATION_TYPE.TOO_MANY_CLASSIFIERS)
            {
                message = "Only one Hull Classifier allowed";
            }
            else if (v == GridEnforcer.VIOLATION_TYPE.SHOULD_BE_STATIC)
            {
                message = "This classifier is only allowed on Stations";
            }
            else if (v == GridEnforcer.VIOLATION_TYPE.TOO_MANY_OF_CLASS)
            {
                // Hopefully the first person in the immediate vicinity is the
                // same ownertype as the person trying to place the block.
                // We could pass the owner of the block up with the violation,
                // but it would required more sophistication in the way we pass
                // violations in BlockAdded
                GridOwner.OWNER      localOwner = GridOwner.ownerFromPlayerID(players[0]);
                GridOwner.OWNER_TYPE owner_type = localOwner.OwnerType;

                if (owner_type == GridOwner.OWNER_TYPE.UNOWNED)
                {
                    message = "Take ownership of this grid or it will eventually be removed.";
                }
                else if (owner_type == GridOwner.OWNER_TYPE.PLAYER)
                {
                    message = "No more ships of this class allowed in this player's fleet. " +
                              "Try joining a faction.";
                }
                else if (owner_type == GridOwner.OWNER_TYPE.FACTION)
                {
                    message = "No more ships of this class allowed in this faction's fleet. ";
                }
            }

            log("Sending message", "eventPlacementViolation");
            NotificationResponse noti = new NotificationResponse()
            {
                NotificationText = message,
                Time             = Constants.NotificationMillis,
                Font             = MyFontEnum.Red,
                Destination      = players,
                DestType         = BaseResponse.DEST_TYPE.PLAYER
            };

            m_MailMan.send(noti);
        }
Пример #5
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);
            }
        }