Esempio n. 1
0
        public static Ship mockShip()
        {
            SpacegameServer.Core.ShipBuild builder = new ShipBuild(Core.Instance);

            var hull = mockShipHull();

            hull.ShipHullsModulePositions.Add(Mock.mockShipHullsModulePosition(hull.id, 2, 3));
            hull.ShipHullGain = Mock.mockShipHullsGain(hull.id, crew: 3);
            Core.Instance.ShipHulls[hull.id] = hull;

            int newShipId = (int)Core.Instance.identities.shipLock.getNext();

            Field field = Mock.mockField();
            User  user  = Mock.MockUser(id: (int)Core.Instance.identities.allianceId.getNext());

            Core.Instance.users.TryAdd(user.id, user);
            int    userId    = user.id;
            Colony colony    = Mock.mockColony(ColonyUserId: userId);
            bool   fastBuild = false;

            ShipTemplate template = Mock.mockShipTemplate(shiphullid: hull.id, userid: userId);
            Module       crew     = Mock.mockModule();

            crew.moduleGain = Mock.mockModulesGain(crew.id, crew: 5);
            Core.Instance.Modules[crew.id] = crew;
            template.shipModules.Add(Mock.mockShipTemplateModules());

            Ship newShip = builder.buildShip(newShipId, template, field, user.id, colony, fastBuild);


            return(newShip);
        }
Esempio n. 2
0
        public void getCommNodeMessageTest()
        {
            instance.commNodes.First().Value.commNodeMessages.Clear();
            instance.identities.commNodeMessage.id = 0;

            //create user
            User user = Mock.mockGeneratedUser(instance);
            List <SpacegameServer.BC.XMLGroups.CommNode> commNodes = SpacegameServer.BC.XMLGroups.CommNodes.createKnownAndNearNodesList(user);

            var node = commNodes.First().node;

            //create ship
            SpacegameServer.Core.ShipBuild builder = new ShipBuild(instance);
            int          newShipId      = (int)instance.identities.shipLock.getNext();
            ShipTemplate template       = instance.shipTemplate.Where(e => e.Value.hullid == 1).First().Value;
            var          targetRegionId = GeometryIndex.calcRegionId(node.positionX, node.positionY);
            Field        field          = GeometryIndex.regions[targetRegionId].findOrCreateField(node.positionX, node.positionY);
            Colony       colony         = Mock.mockColony(ColonyUserId: user.id);
            Ship         newShip        = builder.buildShip(newShipId, template, field, user.id, colony, false);

            //add user to commNode
            node.checkAndAddUser(user, newShip);

            node.sendCommMessage(user, "head1", "body1");
            node.sendCommMessage(user, "head2", "body2");


            SpacegameServer.BC.BusinessConnector bc = new SpacegameServer.BC.BusinessConnector();
            string ret = bc.getCommNodeMessage(user.id, node.id, 0, 50);

            string expected = @"<messages>
  <message>
    <id>2</id>
    <commNodeId>" + node.id.ToString() + @"</commNodeId>
    <sender>" + user.id.ToString() + @"</sender>
    <headline>head2</headline>
    <messageBody>body2</messageBody>
    <sendingDate>2015-07-08T20:48:43.2544728Z</sendingDate>
    <newMessage>0</newMessage>
  </message>
  <message>
    <id>1</id>
    <commNodeId>" + node.id.ToString() + @"</commNodeId>
    <sender>1</sender>
    <headline>head1</headline>
    <messageBody>body1</messageBody>
    <sendingDate>2015-07-08T20:48:43.2464723Z</sendingDate>
    <newMessage>0</newMessage>
  </message>
</messages>";

            //sendingDate can't be tested, since it is set to Now()
            // so only the first few lines are compared
            ret      = String.Join("", ret.Split(new[] { '\r', '\n' }).Where((e, i) => i < 14));
            expected = String.Join("", expected.Split(new[] { '\r', '\n' }).Where((e, i) => i < 14));
            Assert.AreEqual(expected, ret);
        }
Esempio n. 3
0
        public static Ship CreateShipAtField(Core instance, User user, Field field)
        {
            SpacegameServer.Core.ShipBuild builder = new ShipBuild(instance);
            int          newShipId = (int)instance.identities.shipLock.getNext();
            ShipTemplate template  = instance.shipTemplate.Where(e => e.Value.hullid == 1).First().Value;

            Colony colony  = Mock.mockColony(ColonyUserId: user.id);
            Ship   newShip = builder.buildShip(newShipId, template, field, user.id, colony, false);

            return(newShip);
        }
Esempio n. 4
0
        private Ship createShipAtCommNode(User user, CommunicationNode node)
        {
            SpacegameServer.Core.ShipBuild builder = new ShipBuild(instance);
            int          newShipId = (int)instance.identities.shipLock.getNext();
            ShipTemplate template  = instance.shipTemplate.Where(e => e.Value.hullid == 1).First().Value;

            var    targetRegionId = GeometryIndex.calcRegionId(node.positionX, node.positionY);
            Field  field          = GeometryIndex.regions[targetRegionId].findOrCreateField(node.positionX, node.positionY);
            Colony colony         = Mock.mockColony(ColonyUserId: user.id);
            Ship   newShip        = builder.buildShip(newShipId, template, field, user.id, colony, false);

            return(newShip);
        }
Esempio n. 5
0
        public void buildShipTest()
        {
            SpacegameServer.Core.ShipBuild builder = new ShipBuild(Core.Instance);

            //mock Hull to be build
            ShipHull hull = null;

            if (Core.Instance.ShipHulls.Count() > 1 && Core.Instance.ShipHulls[1] != null)
            {
                hull = Core.Instance.ShipHulls[1];
            }
            else
            {
                hull = Mock.mockShipHull();
                hull.ShipHullsModulePositions.Add(Mock.mockShipHullsModulePosition(hull.id, 2, 3));
                hull.ShipHullGain = Mock.mockShipHullsGain(hull.id, crew: 3);
                Core.Instance.ShipHulls[hull.id] = hull;
            }


            int newShipId = (int)instance.identities.shipLock.getNext();

            Field field = Mock.mockField();
            User  user  = Mock.MockUser(id: (int)instance.identities.allianceId.getNext());

            instance.users.TryAdd(user.id, user);
            int    userId    = user.id;
            Colony colony    = Mock.mockColony(ColonyUserId: userId);
            bool   fastBuild = false;

            ShipTemplate template = Mock.mockShipTemplate(shiphullid: hull.id, userid: userId);
            Module       crew     = Mock.mockModule();

            crew.moduleGain = Mock.mockModulesGain(crew.id, crew: 5);
            Core.Instance.Modules[crew.id] = crew;
            template.shipModules.Add(Mock.mockShipTemplateModules());

            Ship newShip = builder.buildShip(newShipId, template, field, user.id, colony, fastBuild);

            Assert.AreEqual(newShip.id, newShipId);
            Assert.AreEqual(newShip.crew, hull.ShipHullGain.crew + crew.moduleGain.crew);
        }