public static string Repair(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]; Core.Colony colony = null; var IsRepaired = ship.Repair(user, ref colony); //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>(); scan.ships.Add(ship); scan.colonies.Add(colony); string ret = ""; BusinessConnector.Serialize <BC.XMLGroups.MoveResultTree>(scan, ref ret); return(ret); }
public void ShipSetFleetState(int shipId, int?fleetId) { try { User user = _game.UserHandler.GetUser(Context.ConnectionId); int UserId = user.RegistrationTicket.UserId; if (!SpacegameServer.Core.Core.Instance.ships.ContainsKey(shipId)) { return; } SpacegameServer.Core.Ship Ship = SpacegameServer.Core.Core.Instance.ships[shipId]; if (Ship.userid != UserId) { return; } Ship.FleetId = fleetId; var toSave = new List <SpacegameServer.AsyncSaveable>(); toSave.Add(Ship); SpacegameServer.Core.Core.Instance.dataConnection.saveAsync(toSave); } catch (Exception ex) { SpacegameServer.Core.Core.Instance.writeExceptionToLog(ex); } }
public string rename() { SpacegameServer.Core.Core core = SpacegameServer.Core.Core.Instance; //moveShip SpacegameServer.Core.Ship ship = core.ships[shipId]; SpacegameServer.Core.User user = core.users[userId]; if (ship.userid != userId) { return(""); } ship.rename(newname); return(""); }
public static string selfdestruct(int _userId, int _shipId) { SpacegameServer.Core.Core core = SpacegameServer.Core.Core.Instance; SpacegameServer.Core.Ship ship = core.ships[_shipId]; if (ship.userid != _userId) { return(""); } if (ship.isTranscension()) { return(""); } ship.selfDestruct(); return(""); }
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); }
public static string transcensionAdd(int shipId, int userId) { SpacegameServer.Core.Core core = SpacegameServer.Core.Core.Instance; //break if the elements if ((!core.ships.ContainsKey(shipId)) || (!core.users.ContainsKey(userId))) { return(""); } //moveShip SpacegameServer.Core.Ship ship = core.ships[shipId]; SpacegameServer.Core.User user = core.users[userId]; int stationId; ship.transcensionAdd(user, out stationId); //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>(); ship.userid = -1; scan.ships.Add(ship); if (stationId != 0 && core.ships.ContainsKey(stationId)) { scan.ships.Add(core.ships[stationId]); } string ret = ""; BusinessConnector.Serialize <BC.XMLGroups.MoveResultTree>(scan, ref ret); return(ret); }
public static string refit(int userId, string refitXml) { SpacegameServer.Core.Core core = SpacegameServer.Core.Core.Instance; SpacegameServer.Core.User user = core.users[userId]; XmlDocument doc = new XmlDocument(); doc.LoadXml(refitXml); string shipString = doc.DocumentElement.SelectSingleNode("/Ship/ShipId").InnerText; int shipId; if (!Int32.TryParse(shipString, out shipId)) { return(""); } SpacegameServer.Core.Ship ship = core.ships[shipId]; if (!ship.refit(refitXml)) { return(""); } //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>(); scan.ships.Add(ship); string ret = ""; BusinessConnector.Serialize <BC.XMLGroups.MoveResultTree>(scan, ref ret); return(ret); }
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); }
public string colonize() { SpacegameServer.Core.Core core = SpacegameServer.Core.Core.Instance; //fetch user and ship objects SpacegameServer.Core.Ship ship = core.ships[shipId]; SpacegameServer.Core.User user = core.users[userId]; //create result data sctructure string ret = ""; XMLGroups.MoveResultTree scan = new XMLGroups.MoveResultTree(); scan.ships = new List <Core.Ship>(); scan.stars = new List <Core.SystemMap>(); scan.colonies = new List <Core.Colony>(); //fetch planet if (!core.stars.ContainsKey((int)ship.systemid)) { return(ret); } Core.SolarSystemInstance planet = core.stars[(int)ship.systemid].getPlanet(ship.getSystemCoords()); if (planet == null) { return(ret); } if (!user.CanColonize(planet)) { return(ret); } //var MajorColony = //create Colony Core.Colony newColony = null; if (!ship.colonize(user, newname, ref scan.ships, ref newColony, planet)) { return(ret); } scan.ships.Add(ship); string shipRet = ""; /* * BusinessConnector.Serialize<List<SpacegameServer.Core.Ship>>(scan.ships, ref shipRet, true); * //shipRet += ret; * * // remove </ArrayOfShip> , add ret , add </ArrayOfShip> * shipRet = shipRet.Substring(0, shipRet.Length - "</ArrayOfShip>".Length); * shipRet = shipRet + ret + "</ArrayOfShip>"; */ SpacegameServer.BC.XMLGroups.Colonize response = new XMLGroups.Colonize(); response.respCode = 1; response.Colony = newColony; response.ships = scan.ships; //response.planet = planet; response.ColonyPlanet = new XMLGroups.ColonyPlanet(planet.id, planet, planet.surfaceFields); //response.planet2 = new XMLGroups.ColonyPlanets(); //response.planet2 //response.planets.AddRange(core.planets.Where(e => e.Value.colonyId == colonyId).Select(e => new XMLGroups.ColonyPlanet(e.Value.id, e.Value, e.Value.surfaceFields))); BusinessConnector.Serialize <SpacegameServer.BC.XMLGroups.Colonize>(response, ref shipRet, true); return(shipRet); }
public void ShipHarvest(int shipId, bool harvest) { try { User user = _game.UserHandler.GetUser(Context.ConnectionId); int UserId = user.RegistrationTicket.UserId; if (!SpacegameServer.Core.Core.Instance.ships.ContainsKey(shipId)) { return; } SpacegameServer.Core.Ship Ship = SpacegameServer.Core.Core.Instance.ships[shipId]; //check user if (Ship.userid != UserId) { return; } //check nebula if (Ship.field.starId != null) { int starId = (int)Ship.field.starId; SpacegameServer.Core.SystemMap star = SpacegameServer.Core.Core.Instance.stars[starId]; if (!(star.objectid > 4999 && star.objectid < 5005)) { return; } } //check that the gravity generator exists on ship bool moduleExists = false; foreach (var module in Ship.shipModules) { if (SpacegameServer.Core.Core.Instance.Modules[module.moduleId].moduleGain.special == 4) { moduleExists = true; } } if (!moduleExists) { return; } //check that this will be the only ship harvesting if (harvest) { if (Ship.field.ships.Any(e => e.Harvesting)) { return; } } //set value and save Ship.Harvesting = harvest; var toSave = new List <SpacegameServer.AsyncSaveable>(); toSave.Add(Ship); SpacegameServer.Core.Core.Instance.dataConnection.saveAsync(toSave); } catch (Exception ex) { SpacegameServer.Core.Core.Instance.writeExceptionToLog(ex); } }
public object FetchShip(int shipId, int scannerId, int scannerType) { try { User user = _game.UserHandler.GetUser(Context.ConnectionId); int UserId = user.RegistrationTicket.UserId; if (!SpacegameServer.Core.Core.Instance.ships.ContainsKey(shipId)) { return new { } } ; SpacegameServer.Core.Ship Ship = SpacegameServer.Core.Core.Instance.ships[shipId]; //take care that the ships is either seen by the user, or did belong to the user before having been destroyed var CanSeeCheck = false; if (scannerType == 0) { if (!SpacegameServer.Core.Core.Instance.ships.ContainsKey(scannerId)) { return new { } } ; SpacegameServer.Core.Ship ScanShip = SpacegameServer.Core.Core.Instance.ships[scannerId]; if (Ship.FormerOwner == UserId) { CanSeeCheck = true; } else { CanSeeCheck = ScanShip.ScansPosition(new Tuple <int, int>(Ship.posX, Ship.posY)); } } if (scannerType == 1) { if (!SpacegameServer.Core.Core.Instance.colonies.ContainsKey(scannerId)) { return new { } } ; SpacegameServer.Core.Colony ScanColony = SpacegameServer.Core.Core.Instance.colonies[scannerId]; CanSeeCheck = ScanColony.ScansPosition(new Tuple <int, int>(Ship.posX, Ship.posY)); } if (!CanSeeCheck) { return new { } } ; string ShipJSON = _game.bc.getShip(UserId, shipId); return(new { Ship = ShipJSON }); } catch (Exception ex) { SpacegameServer.Core.Core.Instance.writeExceptionToLog(ex); } return(new { }); //return new { Ship = _game.bc.getShipData(user.RegistrationTicket.UserId, shipId) }; }