Пример #1
0
        public static string constructSpaceStation(int shipId, int userId)
        {
            SpacegameServer.Core.Core core = SpacegameServer.Core.Core.Instance;
            //moveShip
            SpacegameServer.Core.Ship ship = core.ships[shipId];
            SpacegameServer.Core.User user = core.users[userId];

            int newShipId = 0;

            var FinishedConstruction = ship.createSpaceStation(user, ref newShipId);

            //core.colonize(ship, user, newname, ref ret);
            //do the action
            //ship.colonize(user, newname, ref ret);

            //calc the xml result
            XMLGroups.MoveResultTree scan = new XMLGroups.MoveResultTree();
            scan.ships    = new List <Core.Ship>();
            scan.stars    = new List <Core.SystemMap>();
            scan.colonies = new List <Core.Colony>();
            if (FinishedConstruction)
            {
                core.getUserScans(ship.userid, core.ships[newShipId], ref scan.ships, ref scan.stars, ref scan.colonies);

                //ship.userid = -1;
                scan.ships.Add(ship);

                //if the scan range of the new base is 0, it is not included so add it to the result manually
                if (!scan.ships.Any(e => e.id == newShipId))
                {
                    scan.ships.Add(core.ships[newShipId]);
                }
            }

            string ret = "";

            BusinessConnector.Serialize <BC.XMLGroups.MoveResultTree>(scan, ref ret);

            return(ret);
        }
Пример #2
0
        public string getUserData()
        {
            /*
             * // Example of the output after serialization
             * <languages>
             * <language>
             * <id>0</id>
             * <shortName>en</shortName>
             * <longName>English</longName>
             * </language>
             * <language>
             * <id>1</id>
             * <shortName>de</shortName>
             * <longName>Deutsch</longName>
             * </language>
             * <language>
             * <id>2</id>
             * <shortName>fr</shortName>
             * <longName>Francais</longName>
             * </language>
             * </languages>
             * <messageHighestId>3</messageHighestId>
             * <unreadMessages>0</unreadMessages>
             * <maxServerEventId>2218</maxServerEventId>
             * <nextTurn>
             * <targetTime>2014-12-14T18:55:52.057</targetTime>
             * </nextTurn>
             *
             *
             * <map>
             * <staticMap>
             * <star>
             * <starId>23</starId>
             * <xpos>4999</xpos>
             * <ypos>5014</ypos>
             * <type>3</type>
             * <gif>RedSun_1.png</gif>
             * <name>Capella 457</name>
             * <size>24</size>
             * <ressourceId>4</ressourceId>
             * </star>
             * </staticMap>
             * <GalaxyMap>
             * <id>1</id>
             * <galaxyName>Starmap</galaxyName>
             * <objectId>1</objectId>
             * <size>10000</size>
             * </GalaxyMap>
             * </map>
             *
             *
             * <knownUsers>
             * <knownUser>
             * <id>6</id>
             * <username>Demo user 000006</username>
             * <currentRelation>1</currentRelation>
             * <targetRelation>1</targetRelation>
             * <otherUserRelationTowardsPlayer>1</otherUserRelationTowardsPlayer>
             * <allianceId>0</allianceId>
             * <popVicPoints>-1</popVicPoints>
             * <researchVicPoints>-1</researchVicPoints>
             * <goodsVicPoints>-1</goodsVicPoints>
             * <shipVicPoints>-1</shipVicPoints>
             * <overallVicPoints>1095</overallVicPoints>
             * <overallRank>3</overallRank>
             * </knownUser>
             *
             *
             * <allianceDiplomacy>
             * <allianceDetail>
             * <id>4</id>
             * <name>Heroes</name>
             * <allianceOwner>5</allianceOwner>
             * <overallVicPoints>1708</overallVicPoints>
             * <overallRank>1</overallRank>
             * </allianceDetail>
             * <allianceInvite>
             * <userId>1</userId>
             * <allianceId>4</allianceId>
             * </allianceInvite>
             * </allianceDiplomacy>
             *
             *
             *
             * <commNodes>
             * <commNode>
             * <id>286</id>
             * <owner>0</owner>
             * <name>Space Station</name>
             * <unformattedName>NoName</unformattedName>
             * <positionX>4960</positionX>
             * <positionY>4960</positionY>
             * <systemX>0</systemX>
             * <systemY>0</systemY>
             * <connectionType>0</connectionType>
             * <connectionId>1292</connectionId>
             * <activ>1</activ>
             * <visited>0</visited>
             * <readAccess>0</readAccess>
             * <writeAccess>0</writeAccess>
             * <adminRights>0</adminRights>
             * <informWhenNew>0</informWhenNew>
             * <lastReadMessage>0</lastReadMessage>
             * <messageCount>0</messageCount>
             * <messageUnReadCount>0</messageUnReadCount>
             * </commNode>
             * <commNode>
             * <id>287</id>
             * <owner>0</owner>
             * <name>Space Station</name>
             * <unformattedName>NoName</unformattedName>
             * <positionX>5000</positionX>
             * <positionY>4960</positionY>
             * <systemX>0</systemX>
             * <systemY>0</systemY>
             * <connectionType>0</connectionType>
             * <connectionId>1293</connectionId>
             * <activ>1</activ>
             * <visited>0</visited>
             * <readAccess>0</readAccess>
             * <writeAccess>0</writeAccess>
             * <adminRights>0</adminRights>
             * <informWhenNew>0</informWhenNew>
             * <lastReadMessage>0</lastReadMessage>
             * <messageCount>0</messageCount>
             * <messageUnReadCount>0</messageUnReadCount>
             * </commNode>
             *
             *
             *
             * <allowedBuildings>
             * <allowedBuilding>
             * <allowedBuildingId>3</allowedBuildingId>
             * </allowedBuilding>
             *
             *
             * <PlayerResearches>
             * <PlayerResearch>
             * <id>1</id>
             * <researchable>0</researchable>
             * <isCompleted>1</isCompleted>
             * <investedResearchpoints>3</investedResearchpoints>
             * <researchPriority>0</researchPriority>
             * </PlayerResearch>
             *
             *
             * <ShipTemplates>
             * <ShipTemplate>
             *
             *
             *
             * <Quests>
             * <Quest>
             *
             * <TradeOffers />
             *
             * <allowedModules>
             * <allowedModule>
             *
             * <Colonies>
             * <Colony>
             *
             *
             * <Labels>
             * <languageId>0</languageId>
             * <Label>
             * <id>1</id>
             * <label>Orange dwarf star</label>
             * </Label>
             *
             *
             *
             * <Colonies>
             * <Colony>
             *
             *
             *
             *
             *
             * SpacegameServer.Core.User user = (SpacegameServer.Core.User)Core.Core.Instance.users[userId];
             * if (user == null) return "";
             *
             * string temp = "";
             * BusinessConnector.Serialize<Core.User>(user, ref temp, true);
             */


            BC.XMLGroups.userData userData = new BC.XMLGroups.userData();

            if (!Core.Core.Instance.users.ContainsKey(this.userId))
            {
                return("<user></user>");
            }

            Core.User user = Core.Core.Instance.users[this.userId];

            userData.user       = user;
            userData.knownUsers = XMLGroups.UserContacts.createAllContacts(user);

            //userData.languageShortName = user.languageShortName;
            userData.languages = Core.Core.Instance.languages.Where(e => e != null).ToList();


            userData.messageHighestId = 0;
            userData.unreadMessages   = 0;


            if (Core.Core.Instance.messages.Values.Any(e => e.messageParticipants.Any(f => f.participant == this.userId)))
            {
                /*
                 * userData.messageHighestId = Core.Core.Instance.messages.Values.Where(e => e.messageParticipants.Any(f => f.participant == this.userId))
                 * .OrderByDescending(e => e.id).First().id;
                 */
                userData.messageHighestId = Core.Core.Instance.messages.Values.OrderByDescending(e => e.id).First().id;
                userData.unreadMessages   = Core.Core.Instance.messages.Values.Any(e => e.messageParticipants.Any(f => f.participant == this.userId && !f.read)) ? 1 : 0;
            }



            userData.maxServerEventId = (int)Core.Core.Instance.identities.galacticEvents.id;
            userData.allowedBuildings = XMLGroups.AllowedBuilding.createAllowedBuildings(user);
            userData.PlayerResearches = user.getPlayerResearch();
            userData.ShipHulls        = XMLGroups.AllowedShipHulls.createAllowedShipHulls(user);
            userData.ShipTemplates    = Core.Core.Instance.shipTemplate.Values.Where(e => e.userId == user.id).ToList();
            userData.Quests           = user.quests;
            userData.allowedModules   = XMLGroups.AllowedModule.createAllowedModules(user);

            userData.TradeOffers = new List <Core.TradeOffer>();

            /*
             *
             *
             *
             * userData.TradeOffers;
             */


            userData.allianceDiplomacy = XMLGroups.KnownAlliances.createAllianceContacts(user);
            userData.allianceRelations = XMLGroups.AllianceUserRelations.createAllianceUserRelations(user);
            userData.allianceInvites   = XMLGroups.AllianceInvites.createAllianceInvites(user);
            userData.ships             = new List <Core.Ship>();

            var allColonies = new List <Core.Colony>();

            userData.commNodes           = new XMLGroups.CommNodes();
            userData.commNodes.commNode  = XMLGroups.CommNodes.createKnownAndNearNodesList(user);
            userData.staticMap           = new XMLGroups.StaticMap();
            userData.staticMap.stars     = new List <Core.SystemMap>();
            userData.staticMap.GalaxyMap = core.GalaxyMap;
            core.getUserScans(userId, null, ref userData.ships, ref userData.staticMap.stars, ref allColonies);
            userData.Colonies = Core.Colony.userScanCopy(allColonies, user.id);
            List <Core.Ship> transcensions =
                (from ship in core.ships
                 where  ship.Value.shipTranscension != null
                 select ship.Value).ToList();

            userData.ships.AddRange(transcensions.Except(userData.ships));

            //int startingHours = 4 - (DateTime.Now.Hour  % 4 );
            //DateTime nextTurn = DateTime.Now.AddHours(startingHours);
            DateTime nextTurn = SpacegameServer.Core.Core.nextTurnDateTime(DateTime.Now);

            userData.targetTime           = nextTurn.ToString("yyyy-MM-ddTHH:mm:00");
            userData.unreadCombatMessages = core.combats.Any(e => e.Value.DefenderUserId == user.id && !e.Value.DefenderHasRead);

            userData.Labels = XMLGroups.Labels.GetLabels(user.language);

            string x = "";

            BusinessConnector.Serialize <BC.XMLGroups.userData>(userData, ref x, true);
            return(x);
        }
Пример #3
0
        public string moveShip()
        {
            //moveShip
            SpacegameServer.Core.Ship ship = core.ships[shipId];
            if (ship == null)
            {
                return("");
            }
            byte result = 0;

            //Todo: move kann auch occupyColony zurücksenden
            string combatLog = "";

            //SpacegameServer.Core.Classes.ShipMovement move = new SpacegameServer.Core.Classes.ShipMovement();
            Core.Combat Combat = null;
            ship.move(direction, userId, duration, ref result, ref combatLog, ref Combat, attackedShipId);

            if (Combat != null)
            {
                SpacegameServer.BC.XMLGroups.CombatMessages messages = new SpacegameServer.BC.XMLGroups.CombatMessages();
                messages.messages.Add(Combat);
                combatLog = new System.Web.Script.Serialization.JavaScriptSerializer().Serialize(messages);
            }
            //move.move(ship, direction, userId, duration, ref result, ref combatLog);

            /*
             * scanResult scan = new scanResult();
             * scan.ships.ship = new List<Core.Ship>();
             * scan.stars.star = new List<Core.StarMap>();
             * scan.colonies.colony = new List<Core.Colony>();
             *
             *
             * core.getUserScans(ship.userid, ship, ref scan.ships.ship, ref scan.stars.star, ref scan.colonies.colony);
             * scan.result = result;
             * scan.combatLog = combatLog;
             */
            BC.XMLGroups.MoveResultTree scan = new BC.XMLGroups.MoveResultTree();
            scan.ships    = new List <Core.Ship>();
            scan.stars    = new List <Core.SystemMap>();
            scan.colonies = new List <Core.Colony>();


            core.getUserScans(ship.userid, ship, ref scan.ships, ref scan.stars, ref scan.colonies);

            //user tried to move into an area that was neutral to him
            //fetch the system/colony that creatd the neutral area
            if (result == 31)
            {
                scan.ships    = new List <Core.Ship>();
                scan.stars    = new List <Core.SystemMap>();
                scan.colonies = new List <Core.Colony>();
                core.getAreaCreator(direction, ship.userid, ship, ref scan.ships, ref scan.stars, ref scan.colonies);
            }

            scan.result    = result;
            scan.combatLog = combatLog;


            string ret = "";

            //BusinessConnector.Serialize<SpacegameServer.Core.Ship>(ship, ref x);
            BusinessConnector.Serialize <BC.XMLGroups.MoveResultTree>(scan, ref ret);
            //fetch new data
            //ship
            //scanrange of ship
            //star
            //non user colonies + colonyStock



            //@combatLog
            //@output1 as result,


            //if statement breaks, just return info xml of ship
            return(ret);
        }
Пример #4
0
        public static BC.XMLGroups.MoveResultTree MoveFleet2(List <int> fleetIds, byte direction, int userId, int duration = 1, int attackedShipId = 0)
        {
            SpacegameServer.Core.Core   core = SpacegameServer.Core.Core.Instance;
            BC.XMLGroups.MoveResultTree scan = new BC.XMLGroups.MoveResultTree();
            scan.result = 0;

            List <Core.Ship> fleet = new List <Core.Ship>();

            foreach (var shipId in fleetIds)
            {
                if (!core.ships.ContainsKey(shipId))
                {
                    return(scan);
                }
                fleet.Add(core.ships[shipId]);
            }

            if (fleet.Count == 0)
            {
                return(scan);
            }

            byte result = 0;

            //Todo: move kann auch occupyColony zurücksenden
            string combatLog = "";

            //SpacegameServer.Core.Classes.ShipMovement move = new SpacegameServer.Core.Classes.ShipMovement();
            Core.Combat Combat = null;
            SpacegameServer.Core.Ship.MoveFleet(fleet, direction, userId, duration, ref result, ref combatLog, ref Combat, attackedShipId);

            if (Combat != null)
            {
                SpacegameServer.BC.XMLGroups.CombatMessages messages = new SpacegameServer.BC.XMLGroups.CombatMessages();
                messages.messages.Add(Combat);
                combatLog = new System.Web.Script.Serialization.JavaScriptSerializer().Serialize(messages);
            }
            //move.move(ship, direction, userId, duration, ref result, ref combatLog);

            /*
             * scanResult scan = new scanResult();
             * scan.ships.ship = new List<Core.Ship>();
             * scan.stars.star = new List<Core.StarMap>();
             * scan.colonies.colony = new List<Core.Colony>();
             *
             *
             * core.getUserScans(ship.userid, ship, ref scan.ships.ship, ref scan.stars.star, ref scan.colonies.colony);
             * scan.result = result;
             * scan.combatLog = combatLog;
             */

            scan.ships    = new List <Core.Ship>();
            scan.stars    = new List <Core.SystemMap>();
            scan.colonies = new List <Core.Colony>();

            var MaxScanrange = fleet.Select(s => s.scanRange).Max();
            var BestScanner  = fleet.First(e => e.scanRange == MaxScanrange);

            core.getUserScans(userId, BestScanner, ref scan.ships, ref scan.stars, ref scan.colonies);

            //user tried to move into an area that was neutral to him
            //fetch the system/colony that creatd the neutral area
            if (result == 31)
            {
                scan.ships    = new List <Core.Ship>();
                scan.stars    = new List <Core.SystemMap>();
                scan.colonies = new List <Core.Colony>();
                core.getAreaCreator(direction, userId, BestScanner, ref scan.ships, ref scan.stars, ref scan.colonies);
            }

            scan.result    = result;
            scan.combatLog = combatLog;



            return(scan);
        }