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 string buildShip() { SpacegameServer.Core.Core core = SpacegameServer.Core.Core.Instance; //moveShip SpacegameServer.Core.User user = core.users[userId]; SpacegameServer.Core.ShipBuild builder = new Core.ShipBuild(core); string retValue = ""; int newShipId = 0; //builder.build(shipTemplateId, userId, colonyId, fastBuild, ref retValue); Core.ShipBuildErrorCode errorCode = 0; int errorValue = 0; if (builder.build2(shipTemplateId, userId, colonyId, fastBuild, ref newShipId, ref errorCode, ref errorValue)) { SpacegameServer.BC.XMLGroups.shipBuild built = new SpacegameServer.BC.XMLGroups.shipBuild(); built.Colonies = new List <Core.Colony>(); built.Colonies.Add(core.colonies[colonyId]); built.ship = core.ships[newShipId]; BusinessConnector.Serialize <SpacegameServer.BC.XMLGroups.shipBuild>(built, ref retValue, true); } else { retValue = "<error><errorCode>" + ((int)errorCode).ToString() + "</errorCode>" + "<errorValue>" + errorValue.ToString() + "</errorValue></error>"; } return(retValue); }
public static string buildBuilding(int userId, int colonyId, int tileNr, short buildingId) { string xml = ""; SpacegameServer.Core.Core core = SpacegameServer.Core.Core.Instance; //moveShip SpacegameServer.Core.User user = core.users[userId]; int newBuildingId = -1; SpacegameServer.Core.ColonyBuildingActions.build(userId, colonyId, tileNr, buildingId, ref newBuildingId); if (newBuildingId == -1) { xml = @"<buildResult> <result>0</result> </buildResult>"; return(xml); } Core.ColonyBuilding newBuilding = core.colonyBuildings[newBuildingId]; SpacegameServer.BC.XMLGroups.ColonyBuildings buildResult = new XMLGroups.ColonyBuildings(newBuilding); BusinessConnector.Serialize <SpacegameServer.BC.XMLGroups.ColonyBuildings>(buildResult, ref xml, true); return(xml); }
public void getAreaCreator(byte _direction, int _userId, Ship _ship, ref List <Ship> _ships, ref List <SpacegameServer.Core.SystemMap> _stars, ref List <SpacegameServer.Core.Colony> _colonies, Colony scanningColony = null) { var starXY = getDestinationField(_ship, _direction); if (_userId < 0) { return; } SpacegameServer.Core.User user = (SpacegameServer.Core.User)users[_userId]; if (user == null) { return; } //fetch an area of radius 7 around the target field //check all colonies inside it. Every colony that has the targetfield inside it's border range is returned... //List<Field> neigbouringFields = new List<Field>(); //GeometryIndex.getFields(_ship.field, 7, neigbouringFields); //int targetRegionId = GeometryIndex.calcRegionId(starXY.Key, starXY.Value); //var targetField = GeometryIndex.regions[targetRegionId].findOrCreateField(starXY.Key, starXY.Value); int targetRegionId = GeometryIndex.calcRegionId(starXY.Key, starXY.Value); var targetField = GeometryIndex.regions[targetRegionId].findOrCreateField(starXY.Key, starXY.Value); //fetch all colonies affecting the targetField _colonies = Core.Instance.colonies.Where(colony => targetField.InfluencedBy.Any(influencer => influencer == colony.Value)).Select(colKeyValue => colKeyValue.Value).ToList(); //fetch the star each colony is positioned foreach (int fieldId in (_colonies.Select(colony => colony.field.id))) { Field currentField = ((Field)GeometryIndex.allFields[fieldId]); if (currentField.starId != null) { int starId = (int)currentField.starId; SystemMap star = stars[starId]; _stars.Add(star); //if scan is determined for a single ship, check if that user already kwos the systems scanned: if ((_ship != null) && !user.knownStars.Contains(starId)) { user.knownStars.Add(starId); UserStarMap newStar = new UserStarMap(user.id, starId); List <AsyncInsertable> newKnownStar = new List <AsyncInsertable>(); newKnownStar.Add(newStar); dataConnection.insertAsyncTransaction(newKnownStar); } } } return; }
public static string buildModules(int userId, int colonyId) { SpacegameServer.Core.Core core = SpacegameServer.Core.Core.Instance; //moveShip SpacegameServer.Core.User user = core.users[userId]; string retValue = ""; SpacegameServer.Core.Modules.build(userId, colonyId, ref retValue); //ToDo: eventually the xml will be generated here: return(retValue); }
public static void delete(int userId, int templateId) { SpacegameServer.Core.Core core = SpacegameServer.Core.Core.Instance; SpacegameServer.Core.User user = core.users[userId]; if (core.shipTemplate.ContainsKey(templateId)) //if(core.shipTemplate.ElementAtOrDefault(templateId) != null) { SpacegameServer.Core.ShipTemplate template = core.shipTemplate[templateId]; if (template.userId != userId) { return; } SpacegameServer.Core.ShipTemplate.delete(template); } }
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 CommNode createAllianceCommNode(SpacegameServer.Core.User user) { CommNode xmlNode = new CommNode(); Core.CommunicationNode node = Core.CommunicationNode.GetAllianceNode(user); xmlNode.node = node; if (node.commNodeUsers.ContainsKey(user.id)) { xmlNode.commNodeUser = node.commNodeUsers[user.id]; } xmlNode.visited = true; xmlNode.messageUnReadCount = xmlNode.visited ? node.commNodeMessages.Count(e => e.Key > node.commNodeUsers[user.id].lastReadMessage) : 0; return(xmlNode); }
/* * * * Research of "Space Travel" allows shipyard and scout hull * -> Returns the two follow up researhces with "researchable" set * -> Returns old quests (which is wrong) + current quest (which might be set to completed) + 2 new quests (which will be loaded and shown) * * <ResearchDone> * <Researches> * <PlayerResearch> * <id>501</id> * <label>585</label> * <descriptionLabel>585</descriptionLabel> * <objectimageUrl>1.gif</objectimageUrl> * <cost>15</cost> * <researchable>1</researchable> * <isCompleted>0</isCompleted> * <investedResearchpoints>0</investedResearchpoints> * <researchPriority>0</researchPriority> * </PlayerResearch> * <PlayerResearch> * <id>4002</id> * <label>553</label> * <descriptionLabel>558</descriptionLabel> * <objectimageUrl>1.gif</objectimageUrl> * <cost>11</cost> * <researchable>1</researchable> * <isCompleted>0</isCompleted> * <investedResearchpoints>0</investedResearchpoints> * <researchPriority>0</researchPriority> * </PlayerResearch> * </Researches> * <Quest> * <userId>1400</userId> * <questId>1</questId> * <isRead>1</isRead> * <isCompleted>1</isCompleted> * <hasScript>1</hasScript> * <script>Welcome.js</script> * <label>103</label> * </Quest> * <Quest> * <userId>1400</userId> * <questId>2</questId> * <isRead>1</isRead> * <isCompleted>1</isCompleted> * <hasScript>1</hasScript> * <script>ShortOverview.js</script> * <label>104</label> * </Quest> * <Quest> * <userId>1400</userId> * <questId>3</questId> * <isRead>1</isRead> * <isCompleted>0</isCompleted> * <hasScript>1</hasScript> * <script>Movement.js</script> * <label>116</label> * </Quest> * <Quest> * <userId>1400</userId> * <questId>21</questId> * <isRead>0</isRead> * <isCompleted>0</isCompleted> * <hasScript>1</hasScript> * <script>ShipModulePlant.js</script> * <label>254</label> * </Quest> * <Quest> * <userId>1400</userId> * <questId>22</questId> * <isRead>0</isRead> * <isCompleted>0</isCompleted> * <hasScript>1</hasScript> * <script>Spaceport.js</script> * <label>112</label> * </Quest> * <allowedBuildings> * <allowedBuilding> * <allowedBuildingId>17</allowedBuildingId> * </allowedBuilding> * </allowedBuildings> * <ShipHulls> * <ShipHull> * <shipHullId>1</shipHullId> * </ShipHull> * </ShipHulls> * <allowedModules /> * </ResearchDone> * * */ /* * * <ResearchDone> * <Researches> * <PlayerResearch> * <id>501</id> * <researchable>1</researchable> * <isCompleted>1</isCompleted> * <investedResearchpoints>0</investedResearchpoints> * <researchPriority>0</researchPriority> * </PlayerResearch> * <PlayerResearch> * <id>4002</id> * <researchable>1</researchable> * <isCompleted>1</isCompleted> * <investedResearchpoints>0</investedResearchpoints> * <researchPriority>0</researchPriority> * </PlayerResearch> * </Researches> * <Quest> * <UserQuest> * <userId>1</userId> * <questId>21</questId> * <isRead>false</isRead> * <isCompleted>false</isCompleted> * <hasScript>1</hasScript> * <script>ShipModulePlant.js</script> * <label>254</label> * </UserQuest> * <UserQuest> * <userId>1</userId> * <questId>22</questId> * <isRead>false</isRead> * <isCompleted>false</isCompleted> * <hasScript>1</hasScript> * <script>Spaceport.js</script> * <label>112</label> * </UserQuest> * </Quest> * <allowedBuildings> * <allowedBuilding> * <allowedBuildingId>17</allowedBuildingId> * </allowedBuilding> * </allowedBuildings> * <ShipHulls> * <ShipHull> * <shipHullId>1</shipHullId> * </ShipHull> * </ShipHulls> * </ResearchDone> * * */ public string doResearch2(int researchId) { SpacegameServer.Core.User user = core.users[this.userId]; List <SpacegameServer.Core.UserQuest> NewQuests = new List <SpacegameServer.Core.UserQuest>(); user.doResearch2(researchId, ref NewQuests); string ret = ""; //fetch all things now available by the new research var AllNewItems = Core.ResearchQuestPrerequisite.AvailableQRB(user, 1, researchId); SpacegameServer.BC.XMLGroups.ResearchDone ResearchDone = SpacegameServer.BC.XMLGroups.ResearchDone.createResearchDone(user, AllNewItems, ref NewQuests); BusinessConnector.Serialize <SpacegameServer.BC.XMLGroups.ResearchDone>(ResearchDone, ref ret, true); return(ret); }
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 string setQuestComplete(int userId, int questId) { string xml = ""; SpacegameServer.Core.User user = core.users[userId]; if (user.quests.Any(e => e.questId == questId && e.isCompleted)) { return(xml); } Core.UserQuest.completeQuest(user, questId); BC.XMLGroups.Quests Quests = new XMLGroups.Quests(); Quests.Quest = user.quests; Quests.allowedBuildings = new List <XMLGroups.AllowedBuilding>(); BusinessConnector.Serialize <BC.XMLGroups.Quests>(Quests, ref xml, true); //gib alle unfertigen(neuen) Quests raus und die aktuell beendete. ToDo: könnte eingeschränkt werden auf die gerade fertiggestellten.ToDo2: auch die neuen Gebäude rausgeben, und die neue Forschung //und neue gebäude return(xml); }
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 ChooseSpecialization(string[] researchs) { SpacegameServer.Core.User user = core.users[this.userId]; List <SpacegameServer.Core.UserQuest> NewQuests = new List <SpacegameServer.Core.UserQuest>(); List <SpacegameServer.Core.Research> researchIds = new List <SpacegameServer.Core.Research>(); //check that all researchs are Id of spececializationResearchs foreach (var entry in researchs) { if (entry == "") { continue; } int result; if (!Int32.TryParse(entry, out result)) { return(""); } if (!SpacegameServer.Core.Core.Instance.Researchs.sparseContainsIndex(result)) { return(""); } var Research = Core.Core.Instance.Researchs[result]; if (Research.researchType != 10) { return(""); } researchIds.Add(Research); } if (!user.ChooseSpecialization(researchIds)) { return(""); } string ret = ""; //create a list of all possible follow-up researches. These might not fulfill other requirements... List <Core.ResearchQuestPrerequisite> AllNewResearchs = Core.Core.Instance.ResearchQuestPrerequisites.Where(e => e.SourceType == 1 && researchIds.Any(rId => rId.id == e.SourceId) && e.TargetType == 1).ToList(); // Prüfe Vorbedingungen (andere Forschungen, Quests, Rohstoffe) ob diese Forschung erlaubt ist List <Core.ResearchQuestPrerequisite> FilteredNewResearchs = new List <Core.ResearchQuestPrerequisite>(); foreach (Core.ResearchQuestPrerequisite Follower in AllNewResearchs) { Core.Research TargetResearch = Core.Core.Instance.Researchs[Follower.TargetId]; if (!user.canResearch(TargetResearch)) { continue; } FilteredNewResearchs.Add(Follower); } SpacegameServer.BC.XMLGroups.ResearchDone ResearchDone = SpacegameServer.BC.XMLGroups.ResearchDone.createResearchDone(user, FilteredNewResearchs, ref NewQuests); BusinessConnector.Serialize <SpacegameServer.BC.XMLGroups.ResearchDone>(ResearchDone, ref ret, true); return(ret); }
public void userNewTurn() { SpacegameServer.Core.TurnSummary ts = new SpacegameServer.Core.TurnSummary(core); SpacegameServer.Core.User user = core.users[userId]; ts.calc(user); }
public User(int _userId, Core.User user = null) { userId = _userId; core = SpacegameServer.Core.Core.Instance; this.user = user; }
public static string createUpdate(int userId, string templateXml) { /* * <?xml version="1.0" encoding="utf-8" ?> * <ShipTemplate> * <ShipTemplateId>1</ShipTemplateId> * <ShipTemplateHullId>1</ShipTemplateHullId> * <name>testName</name> * <shipHullsImage>1</shipHullsImage> * <gif>scout.png</gif> * <modulePositions> * <modulePosition> * <posX>3</posX> * <posY>3</posY> * <moduleId>1</moduleId> * </modulePosition> * <modulePosition> * <posX>2</posX> * <posY>3</posY> * <moduleId>2</moduleId> * </modulePosition> * </modulePositions> * </ShipTemplate> */ SpacegameServer.Core.Core core = SpacegameServer.Core.Core.Instance; SpacegameServer.Core.User user = core.users[userId]; XmlDocument doc = new XmlDocument(); doc.LoadXml(templateXml); string templateIdString = doc.DocumentElement.SelectSingleNode("/ShipTemplate/ShipTemplateId").InnerText; int templateId; if (!Int32.TryParse(templateIdString, out templateId)) { return(""); } SpacegameServer.Core.ShipTemplate newTemplate = null; SpacegameServer.Core.ShipTemplate oldTemplate = null; if (!SpacegameServer.Core.ShipTemplate.createUpdate(templateXml, userId, ref newTemplate, ref oldTemplate)) { return(""); } //calc the xml result SpacegameServer.BC.XMLGroups.ShipTemplates ShipTemplate = new SpacegameServer.BC.XMLGroups.ShipTemplates(); ShipTemplate.ShipTemplate.Add(newTemplate); if (oldTemplate != null) { ShipTemplate.ShipTemplate.Add(oldTemplate); } string ret = ""; BusinessConnector.Serialize <SpacegameServer.BC.XMLGroups.ShipTemplates>(ShipTemplate, ref ret); return(ret); }
public static bool createUpdate(string xml, int userId, ref SpacegameServer.Core.ShipTemplate template, ref SpacegameServer.Core.ShipTemplate oldTemplate) { /* * <?xml version="1.0" encoding="utf-8" ?> * <ShipTemplate> * <ShipTemplateId>1</ShipTemplateId> * <ShipTemplateHullId>1</ShipTemplateHullId> * <name>testName</name> * <gif>scout.png</gif> * <shipHullsImage>1</shipHullsImage> * <modulePositions> * <modulePosition> * <posX>3</posX> * <posY>3</posY> * <moduleId>1</moduleId> * </modulePosition> * <modulePosition> * <posX>2</posX> * <posY>3</posY> * <moduleId>2</moduleId> * </modulePosition> * </modulePositions> * </ShipTemplate> */ Core core = Core.Instance; List <Lockable> elementsToLock = new List <Lockable>(2); SpacegameServer.Core.User user = core.users[userId]; XmlDocument doc = new XmlDocument(); doc.LoadXml(xml); string templateIdString = doc.DocumentElement.SelectSingleNode("/ShipTemplate/ShipTemplateId").InnerText; int templateId; if (!Int32.TryParse(templateIdString, out templateId)) { return(false); } string templateHullIdString = doc.DocumentElement.SelectSingleNode("/ShipTemplate/ShipTemplateHullId").InnerText; byte templateHullId; if (!System.Byte.TryParse(templateHullIdString, out templateHullId)) { return(false); } string shipHullsImageString = doc.DocumentElement.SelectSingleNode("/ShipTemplate/shipHullsImage").InnerText; int shipHullsImage; if (!Int32.TryParse(shipHullsImageString, out shipHullsImage)) { return(false); } if (templateId != -1) { template = core.shipTemplate[templateId]; if (template.userId != userId) { return(false); } if (template.amountbuilt > 0) { oldTemplate = template; int newTemplateId = (int)SpacegameServer.Core.Core.Instance.identities.templateLock.getNext(); template = new SpacegameServer.Core.ShipTemplate(newTemplateId); } } else { int newTemplateId = (int)SpacegameServer.Core.Core.Instance.identities.templateLock.getNext(); template = new SpacegameServer.Core.ShipTemplate(newTemplateId); template.userId = userId; template.gif = "Dummy"; } template.name = doc.DocumentElement.SelectSingleNode("/ShipTemplate/name").InnerText; template.hullid = templateHullId; template.shipHullsImage = shipHullsImage; elementsToLock.Add(template); if (oldTemplate != null) { elementsToLock.Add(oldTemplate); } if (!LockingManager.lockAllOrSleep(elementsToLock)) { return(false); } try { template.shipModules.Clear(); System.Xml.XmlNodeList modules = doc.DocumentElement.SelectNodes("/ShipTemplate/modulePositions/modulePosition"); foreach (System.Xml.XmlNode node in modules) { string posXS = node.SelectSingleNode("posX").InnerText; //or loop through its children as well string posYS = node.SelectSingleNode("posY").InnerText; //or loop through its children as well string moduleIdS = node.SelectSingleNode("moduleId").InnerText; //or loop through its children as well byte posX, posY; short moduleId; if (!(Byte.TryParse(posXS, out posX) && Byte.TryParse(posYS, out posY) && Int16.TryParse(moduleIdS, out moduleId))) { LockingManager.unlockAll(elementsToLock); return(false); } ShipTemplateModules newModule = new ShipTemplateModules(); newModule.posX = posX; newModule.posY = posY; newModule.moduleId = moduleId; newModule.shiptemplateid = template.id; template.shipModules.Add(newModule); } StatisticsCalculator.calc(template, Core.Instance); template.isConstructable = template.energy >= 0 && template.crew >= 0; if (!core.shipTemplate.ContainsKey(template.id)) { core.shipTemplate[template.id] = template; } //save newTemplate and oldTemplate List <AsyncSaveable> elementsToSave = new List <AsyncSaveable>(); elementsToSave.Add(template); if (oldTemplate != null) { oldTemplate.obsolete = true; elementsToSave.Add(oldTemplate); } core.dataConnection.saveAsync(elementsToSave); } catch (Exception ex) { core.writeExceptionToLog(ex); } finally { LockingManager.unlockAll(elementsToLock); } return(true); }
public Message(Core.User user) { this.user = user; core = SpacegameServer.Core.Core.Instance; }
public static CommNode createCommNode(SpacegameServer.Core.CommunicationNode node, SpacegameServer.Core.User user) { CommNode xmlNode = new CommNode(); xmlNode.node = node; SpacegameServer.Core.CommNodeUser commNodeUser = node.commNodeUsers.ContainsKey(user.id) ? node.commNodeUsers[user.id] : new SpacegameServer.Core.CommNodeUser(user.id, node.id); xmlNode.commNodeUser = commNodeUser; xmlNode.visited = node.commNodeUsers.ContainsKey(user.id); xmlNode.messageUnReadCount = xmlNode.visited ? node.commNodeMessages.Count(e => e.Key > commNodeUser.lastReadMessage) : 0; return(xmlNode); }
public List <Field> getUserScannedFields(int _userId, Ship _ship, Colony scanningColony = null) { List <Field> scanned = new List <Field>(); if (_userId < 0) { return(scanned); } SpacegameServer.Core.User user = (SpacegameServer.Core.User)users[_userId]; if (user == null) { return(scanned); } //make a list with unique fields, only the scanner with the greates scanrange is needed Dictionary <Int32, KeyValuePair <Field, byte> > fieldScans = new Dictionary <int, KeyValuePair <Field, byte> >(); if (_ship != null || scanningColony != null) { if (_ship != null) { fieldScans[_ship.field.id] = new KeyValuePair <Field, byte>(_ship.field, _ship.scanRange); } if (scanningColony != null) { fieldScans[scanningColony.field.id] = new KeyValuePair <Field, byte>(scanningColony.field, scanningColony.scanRange); } } else { for (int i = 0; i < user.ships.Count; i++) { Ship currentShip = user.ships[i]; KeyValuePair <Field, byte> val; if (fieldScans.TryGetValue(user.ships[i].field.id, out val)) { if (val.Value < currentShip.scanRange) { fieldScans[currentShip.field.id] = new KeyValuePair <Field, byte>(currentShip.field, currentShip.scanRange); } } else { fieldScans[currentShip.field.id] = new KeyValuePair <Field, byte>(currentShip.field, currentShip.scanRange); } } for (int i = 0; i < user.colonies.Count; i++) { Colony currentColony = user.colonies[i]; KeyValuePair <Field, byte> val; if (fieldScans.TryGetValue(currentColony.field.id, out val)) { if (val.Value < currentColony.scanRange) { fieldScans[currentColony.field.id] = new KeyValuePair <Field, byte>(currentColony.field, currentColony.scanRange); } } else { fieldScans[currentColony.field.id] = new KeyValuePair <Field, byte>(currentColony.field, currentColony.scanRange); } } } //find all neighbouring fields of the scanners //use the regions to accomplish this List <int> scannedFields = new List <int>(); foreach (KeyValuePair <Int32, KeyValuePair <Field, byte> > scanner in fieldScans) { scanner.Value.Key.getScanRange(scanner.Value.Value, scannedFields); } //detect all ships, stars and colonies on the fields scanned foreach (int fieldId in (scannedFields.Distinct())) { scanned.Add((Field)GeometryIndex.allFields[fieldId]); } return(scanned); }
public void getUserScans(int _userId, Ship _ship, ref List <Ship> _ships, ref List <SpacegameServer.Core.SystemMap> _stars, ref List <SpacegameServer.Core.Colony> _colonies, Colony scanningColony = null) { if (_userId < 0) { return; } SpacegameServer.Core.User user = (SpacegameServer.Core.User)users[_userId]; if (user == null) { return; } //during startup, add all colonies of stars known to the user if (_ship == null && scanningColony == null) { _colonies = Core.Instance.stars.Where(star => user.knownStars.Any(known => known == star.Value.id)) .SelectMany(star => star.Value.planets) .Where(planet => planet.colony != null) .Select(planet => planet.colony).ToList(); /*foreach (int starId in user.knownStars) * { * if (Core.Instance.stars[starId].planets.Any(planet => planet.colony != null)) * { * _colonies = Core.Instance.stars[starId].planets.Where(planet => planet.colony != null).Select(planet => planet.colony).ToList(); * } * } */ } //make a list with unique fields, only the scanner with the greates scanrange is needed Dictionary <Int32, KeyValuePair <Field, byte> > fieldScans = new Dictionary <int, KeyValuePair <Field, byte> >(); if (_ship != null || scanningColony != null) { if (_ship != null) { fieldScans[_ship.field.id] = new KeyValuePair <Field, byte>(_ship.field, _ship.scanRange); } if (scanningColony != null) { fieldScans[scanningColony.field.id] = new KeyValuePair <Field, byte>(scanningColony.field, scanningColony.scanRange); } } else { for (int i = 0; i < user.ships.Count; i++) { Ship currentShip = user.ships[i]; KeyValuePair <Field, byte> val; if (fieldScans.TryGetValue(user.ships[i].field.id, out val)) { if (val.Value < currentShip.scanRange) { fieldScans[currentShip.field.id] = new KeyValuePair <Field, byte>(currentShip.field, currentShip.scanRange); } } else { fieldScans[currentShip.field.id] = new KeyValuePair <Field, byte>(currentShip.field, currentShip.scanRange); } } for (int i = 0; i < user.colonies.Count; i++) { Colony currentColony = user.colonies[i]; KeyValuePair <Field, byte> val; if (fieldScans.TryGetValue(currentColony.field.id, out val)) { if (val.Value < currentColony.scanRange) { fieldScans[currentColony.field.id] = new KeyValuePair <Field, byte>(currentColony.field, currentColony.scanRange); } } else { fieldScans[currentColony.field.id] = new KeyValuePair <Field, byte>(currentColony.field, currentColony.scanRange); } } } //find all neighbouring fields of the scanners //use the regions to accomplish this List <int> scannedFields = new List <int>(); foreach (KeyValuePair <Int32, KeyValuePair <Field, byte> > scanner in fieldScans) { scanner.Value.Key.getScanRange(scanner.Value.Value, scannedFields); } //detect all ships, stars and colonies on the fields scanned foreach (int fieldId in (scannedFields.Distinct())) { Field currentField = ((Field)GeometryIndex.allFields[fieldId]); foreach (Ship ship in currentField.ships) { _ships.Add(ship); } _ships = _ships.OrderBy(o => o.id).ToList(); if (currentField.starId != null) { int starId = (int)currentField.starId; SystemMap star = stars[starId]; _stars.Add(star); foreach (Colony colony in currentField.colonies) { if (!_colonies.Any(c => c == colony)) { _colonies.Add(colony); } } //if scan is determined for a single ship, check if that user already kwos the systems scanned: if ((_ship != null) && !user.knownStars.Contains(starId)) { user.knownStars.Add(starId); UserStarMap newStar = new UserStarMap(user.id, starId); List <AsyncInsertable> newKnownStar = new List <AsyncInsertable>(); newKnownStar.Add(newStar); dataConnection.insertAsyncTransaction(newKnownStar); } } } //add usermap and transcensionStars to the list of known stars: if (_ship == null && scanningColony == null) { foreach (int starId in user.knownStars) { if (!_stars.Exists(x => x.id == starId)) { _stars.Add(this.stars[starId]); } } List <Ship> transcensions = (from ship in this.ships where ship.Value.shipTranscension != null select ship.Value).ToList(); foreach (Ship transc in transcensions) { if (transc.systemId == 0) { continue; } if (!_stars.Exists(x => x.id == transc.systemId)) { _stars.Add(this.stars[transc.systemId]); } } } return; }
public CommNode(Core.CommunicationNode node, Core.User user) { this.node = node; this.user = user; core = SpacegameServer.Core.Core.Instance; }
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); }