예제 #1
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);
        }
예제 #2
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);
        }