Exemple #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);
        }
Exemple #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);
 }
Exemple #4
0
        public void eventCleanupTimerEnd(GridEnforcer ge, DerelictTimer.COMPLETION c)
        {
            //log("start", "eventCleanupTimerEnd", Logger.severity.TRACE);
            if (ge == null)
            {
                return;
            }

            //log("grid exists, getting owner", "eventCleanupTimerEnd", Logger.severity.TRACE);
            GridOwner owner = ge.Owner;

            //log("grid exists, getting owner type", "eventCleanupTimerEnd", Logger.severity.TRACE);
            GridOwner.OWNER_TYPE owner_type = owner.OwnerType;
            //log("grid exists, getting faction", "eventCleanupTimerEnd", Logger.severity.TRACE);
            long gridFactionID = ge.Owner.FactionID;

            //log("determining destinations", "eventCleanupTimerEnd", Logger.severity.TRACE);
            BaseResponse.DEST_TYPE destType     = BaseResponse.DEST_TYPE.NONE;
            List <long>            Destinations = new List <long>();
            string message = "";

            if (owner_type == GridOwner.OWNER_TYPE.FACTION)
            {
                destType = BaseResponse.DEST_TYPE.FACTION;
                Destinations.Add(gridFactionID);
                message += "Your faction's ";
            }
            else if (owner_type == GridOwner.OWNER_TYPE.PLAYER)
            {
                destType = BaseResponse.DEST_TYPE.PLAYER;
                Destinations.Add(ge.Owner.PlayerID);
                message += "Your ";
            }
            else
            {
                List <long> nearbyPlayers = ge.Grid.getPlayerIDsWithinPlacementRadius();
                if (nearbyPlayers.Count > 0)
                {
                    destType     = BaseResponse.DEST_TYPE.PLAYER;
                    Destinations = nearbyPlayers;
                    message     += "Nearby ";
                }
                else
                {
                    return;
                }
            }

            log("building message", "eventCleanupTimerEnd", Logger.severity.TRACE);
            MyFontEnum font = MyFontEnum.Red;

            if (c == DerelictTimer.COMPLETION.CANCELLED)
            {
                message += "grid " + ge.Grid.DisplayName + " is now within limits.";
                font     = MyFontEnum.Green;
            }
            else if (c == DerelictTimer.COMPLETION.ELAPSED)
            {
                message += "grid " + ge.Grid.DisplayName +
                           " had some of its offending blocks removed.";
                font = MyFontEnum.Red;
            }

            log("Sending message", "eventDerelictEnd");
            NotificationResponse noti = new NotificationResponse()
            {
                NotificationText = message,
                Time             = Constants.NotificationMillis,
                Font             = font,
                Destination      = Destinations,
                DestType         = destType
            };

            m_MailMan.send(noti);
        }
Exemple #5
0
        public void eventCleanupTimerStart(GridEnforcer ge, int secondsRemaining)
        {
            if (ge == null)
            {
                return;
            }

            GridOwner owner = ge.Owner;

            GridOwner.OWNER_TYPE owner_type = owner.OwnerType;
            long gridFactionID = ge.Owner.FactionID;

            BaseResponse.DEST_TYPE destType     = BaseResponse.DEST_TYPE.NONE;
            List <long>            Destinations = new List <long>();
            string message = "";

            if (owner_type == GridOwner.OWNER_TYPE.FACTION)
            {
                destType = BaseResponse.DEST_TYPE.FACTION;
                Destinations.Add(gridFactionID);
                message += "Your faction's ";
            }
            else if (owner_type == GridOwner.OWNER_TYPE.PLAYER)
            {
                destType = BaseResponse.DEST_TYPE.PLAYER;
                Destinations.Add(ge.Owner.PlayerID);
                message += "Your ";
            }
            else
            {
                List <long> nearbyPlayers = ge.Grid.getPlayerIDsWithinPlacementRadius();
                if (nearbyPlayers.Count > 0)
                {
                    destType     = BaseResponse.DEST_TYPE.PLAYER;
                    Destinations = nearbyPlayers;
                    message     += "Nearby ";
                }
                else
                {
                    return;
                }
            }
            log("msg details built", "eventCleanupTimerStart", Logger.severity.TRACE);

            // build notification
            message += "grid " + ge.Grid.DisplayName +
                       " will have some of its offending blocks removed in " +
                       Utility.prettySeconds(secondsRemaining);

            log("msg built, building noti", "eventDerelictStart");
            NotificationResponse noti = new NotificationResponse()
            {
                NotificationText = message,
                Time             = Constants.NotificationMillis,
                Font             = MyFontEnum.Red,
                Destination      = Destinations,
                DestType         = destType
            };

            log("notification built, sending message", "eventDerelictStart");
            m_MailMan.send(noti);
            log("Msg sent", "eventDerelictStart");
        }
Exemple #6
0
        public void eventCleanupViolation(GridEnforcer ge, List <GridEnforcer.VIOLATION> violations)
        {
            log("Start", "eventCleanupViolation");
            if (ge == null)
            {
                return;
            }

            log("Determine destination", "eventCleanupViolation");
            GridOwner owner = ge.Owner;

            GridOwner.OWNER_TYPE owner_type = owner.OwnerType;
            long gridFactionID = ge.Owner.FactionID;

            BaseResponse.DEST_TYPE destType     = BaseResponse.DEST_TYPE.NONE;
            List <long>            Destinations = new List <long>();
            string message = "";

            if (owner_type == GridOwner.OWNER_TYPE.FACTION)
            {
                destType = BaseResponse.DEST_TYPE.FACTION;
                Destinations.Add(gridFactionID);
                message += "Your faction's ";
            }
            else if (owner_type == GridOwner.OWNER_TYPE.PLAYER)
            {
                destType = BaseResponse.DEST_TYPE.PLAYER;
                Destinations.Add(ge.Owner.PlayerID);
                message += "Your ";
            }
            else
            {
                List <long> nearbyPlayers = ge.Grid.getPlayerIDsWithinPlacementRadius();
                if (nearbyPlayers.Count > 0)
                {
                    destType     = BaseResponse.DEST_TYPE.PLAYER;
                    Destinations = nearbyPlayers;
                    message     += "Nearby unowned ";
                }
                else
                {
                    return;
                }
            }

            message += "grid '" + ge.Grid.DisplayName + "' ";

            log("Build violations message", "eventCleanupViolation");
            if (violations != null)
            {
                message += "is violating: ";

                foreach (GridEnforcer.VIOLATION violation in violations)
                {
                    message += violation.Name + ": " + violation.Count + "/" +
                               violation.Limit + " ";
                }

                message += " and ";
            }

            log("Build time message", "eventCleanupViolation");
            int secondsUntilCleanup = ge.TimeUntilCleanup;

            message += "will have some blocks removed in " +
                       Utility.prettySeconds(secondsUntilCleanup);

            // send
            log("Sending message", "eventDerelictStart");
            NotificationResponse noti = new NotificationResponse()
            {
                NotificationText = message,
                Time             = Constants.NotificationMillis,
                Font             = MyFontEnum.Red,
                Destination      = Destinations,
                DestType         = destType
            };

            m_MailMan.send(noti);
        }
Exemple #7
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);
        }
Exemple #8
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);
            }
        }