예제 #1
0
        public void TestSetDiplomaticEntityState()
        {
            //Empty relations
            UserRelations relations = instance.userRelations;

            User u1 = Mock.MockUser(id: (int)instance.identities.allianceId.getNext());

            instance.users.TryAdd(u1.id, u1);
            User u2 = Mock.MockUser(id: (int)instance.identities.allianceId.getNext());

            instance.users.TryAdd(u2.id, u2);

            relations.setDiplomaticEntityState(u1, u2, Relation.Neutral);
            Assert.AreEqual(relations.getUserRelationsForUser(u1)[0].Value, Relation.Neutral);
            Assert.AreEqual(relations.getRelation(u1, u2), Relation.Neutral);

            relations.setDiplomaticEntityState(u2, u1, Relation.Neutral);
            Assert.AreEqual(relations.getUserRelationsForUser(u2)[0].Value, Relation.Neutral);

            //set an existing erlation to a new value -> proposal
            relations.setDiplomaticEntityState(u1, u2, Relation.Trade);
            //the overall relation keeps on 1 (proposal)
            Assert.AreEqual(relations.getUserRelationsForUser(u1)[0].Value, Relation.Neutral);
            Assert.AreEqual(relations.getUserRelationsForUser(u2)[0].Value, Relation.Neutral);
            Assert.AreEqual(relations.getRelation(u1, u2), Relation.Neutral);

            //set an existing erlation to a new value 1 -> 3 -> accept + proposal
            relations.setDiplomaticEntityState(u2, u1, Relation.Pact);
            //the overall relation is now 2
            Assert.AreEqual(relations.getUserRelationsForUser(u1)[0].Value, Relation.Trade);
            Assert.AreEqual(relations.getUserRelationsForUser(u2)[0].Value, Relation.Trade);
            Assert.AreEqual(relations.getRelation(u1, u2), Relation.Trade);
        }
예제 #2
0
        public void LeaveDuringWarAgainstAllianceTest()
        {
            //when joining, a user is not only member of the new alliance, but does also share diplomatic relationship:
            User user1 = Mock.MockUserAndAdd(instance); //Alliance 1
            User user2 = Mock.MockUserAndAdd(instance); //Alliance 2 Relation.War

            User user3 = Mock.MockUserAndAdd(instance); //Alliance 1 , will eave the alliance
            User user4 = Mock.MockUserAndAdd(instance); //Alliance 2 ,



            Alliance.createAlliance(user1, "alliance1");
            Alliance alliance1 = instance.alliances[user1.allianceId];

            Alliance.createAlliance(user2, "alliance2");
            Alliance alliance2 = instance.alliances[user2.allianceId];

            //invite user3
            Alliance.inviteTo(user1, user3);

            //JOIN
            Alliance.joinCheck(user3, alliance1.id);

            //invite user4
            Alliance.inviteTo(user2, user4);

            //JOIN
            Alliance.joinCheck(user4, alliance2.id);


            UserRelations relations = instance.userRelations;

            // set to War:
            //relations.setDiplomaticEntityState(alliance1, alliance2, Relation.War);
            List <SpacegameServer.Core.DiplomaticRelation> changes = new List <DiplomaticRelation>();

            relations.trySetRelation(user1.id, alliance2.id, alliance2.diplomaticType, Relation.War, changes);
            Assert.AreEqual(Relation.War, relations.getRelation(alliance1, alliance2));

            //leave alliance
            Alliance.leaveCheck(user3, user3, user3.allianceId);
            Assert.AreEqual(user3.allianceId, 0);

            foreach (var targetRelation in Core.Instance.userRelations.getAllDiplomatics(user3, 1))
            {
                if (targetRelation.target.id == user2.id)
                {
                    Assert.AreEqual((int)Relation.War, targetRelation.relation);
                }
                if (targetRelation.target.id == user4.id)
                {
                    Assert.AreEqual((int)Relation.War, targetRelation.relation);
                }
            }
        }
예제 #3
0
        public void joinCheckTest()
        {
            //when joining, a user is not only member of the new alliance, but does also share diplomatic relationship:
            User user1 = Mock.MockUserAndAdd(instance); //Alliance 1
            User user2 = Mock.MockUserAndAdd(instance); //Alliance 2 Relation.War
            User user3 = Mock.MockUserAndAdd(instance); //Alliance 3 Relation.Hostile
            User user4 = Mock.MockUserAndAdd(instance); //Alliance 4 Relation.Trade
            User user5 = Mock.MockUserAndAdd(instance); //Alliance 5 Relation.Trade, Relation.Pact proposed
            User user6 = Mock.MockUserAndAdd(instance);
            User user7 = Mock.MockUserAndAdd(instance);
            User user8 = Mock.MockUserAndAdd(instance);
            User user9 = Mock.MockUserAndAdd(instance);

            //the
            User userToInvite = Mock.MockUserAndAdd(instance);

            //some users that only userToInvite has relations to:
            User user10 = Mock.MockUserAndAdd(instance);
            User user11 = Mock.MockUserAndAdd(instance);


            Alliance.createAlliance(user1, "alliance1");
            Alliance alliance1 = instance.alliances[user1.allianceId];

            Alliance.createAlliance(user2, "alliance2");
            Alliance alliance2 = instance.alliances[user2.allianceId];

            Alliance.createAlliance(user3, "alliance3");
            Alliance alliance3 = instance.alliances[user3.allianceId];

            Alliance.createAlliance(user4, "alliance4");
            Alliance alliance4 = instance.alliances[user4.allianceId];

            Alliance.createAlliance(user5, "alliance5");
            Alliance alliance5 = instance.alliances[user5.allianceId];

            //set relations from user1 to all others, including userToInvite
            UserRelations relations = instance.userRelations;

            //to ALliances
            relations.setDiplomaticEntityState(alliance1, alliance2, Relation.War);
            Assert.AreEqual(Relation.War, relations.getRelation(alliance1, alliance2));

            relations.setDiplomaticEntityState(alliance1, alliance3, Relation.Hostile);
            Assert.AreEqual(Relation.Hostile, relations.getRelation(alliance1, alliance3));

            relations.setDiplomaticEntityState(alliance1, alliance4, Relation.Trade);
            relations.setDiplomaticEntityState(alliance4, alliance1, Relation.Trade);
            Assert.AreEqual(Relation.Trade, relations.getRelation(alliance1, alliance4));

            relations.setDiplomaticEntityState(alliance1, alliance5, Relation.Pact);
            relations.setDiplomaticEntityState(alliance5, alliance1, Relation.Trade);
            Assert.AreEqual(Relation.Trade, relations.getRelation(alliance1, alliance4));

            //to Users
            relations.setDiplomaticEntityState(alliance1, user6, Relation.War);
            Assert.AreEqual(Relation.War, relations.getRelation(alliance1, user6));

            relations.setDiplomaticEntityState(alliance1, user7, Relation.Hostile);
            Assert.AreEqual(Relation.Hostile, relations.getRelation(alliance1, user7));

            relations.setDiplomaticEntityState(alliance1, user8, Relation.Trade);
            Assert.AreEqual(Relation.Neutral, relations.getRelation(alliance1, user8));

            relations.setDiplomaticEntityState(alliance1, user9, Relation.Trade);
            relations.setDiplomaticEntityState(user9, alliance1, Relation.Trade);
            Assert.AreEqual(Relation.Trade, relations.getRelation(alliance1, user9));

            relations.setDiplomaticEntityState(alliance1, userToInvite, Relation.Trade);
            relations.setDiplomaticEntityState(userToInvite, alliance1, Relation.Trade);
            Assert.AreEqual(Relation.Trade, relations.getRelation(alliance1, userToInvite));



            //set some userToInvite relations:
            relations.setDiplomaticEntityState(userToInvite, alliance3, Relation.Trade);
            relations.setDiplomaticEntityState(alliance3, userToInvite, Relation.Trade);
            Assert.AreEqual(Relation.Trade, relations.getRelation(userToInvite, alliance3));

            relations.setDiplomaticEntityState(userToInvite, alliance4, Relation.Hostile);
            relations.setDiplomaticEntityState(alliance4, userToInvite, Relation.Hostile);
            Assert.AreEqual(Relation.Hostile, relations.getRelation(userToInvite, alliance4));


            relations.setDiplomaticEntityState(userToInvite, user7, Relation.Trade);
            relations.setDiplomaticEntityState(user7, userToInvite, Relation.Trade);
            Assert.AreEqual(Relation.Trade, relations.getRelation(userToInvite, user7));

            relations.setDiplomaticEntityState(userToInvite, user9, Relation.Hostile);
            relations.setDiplomaticEntityState(user9, userToInvite, Relation.Hostile);
            Assert.AreEqual(Relation.Hostile, relations.getRelation(userToInvite, user9));



            //invite userToInvite
            Alliance.inviteTo(user1, userToInvite);

            //JOIN
            Alliance.joinCheck(userToInvite, alliance1.id);

            //check that new user is in alliance
            Assert.AreEqual(2, alliance1.members.Count);
            Assert.AreEqual(alliance1.id, userToInvite.allianceId);

            //check that new user has all relations set to the correct value


            // to alliances
            Assert.AreEqual(Relation.War, relations.getRelation(userToInvite, alliance2));
            Assert.AreEqual(Relation.Hostile, relations.getRelation(userToInvite, alliance3));
            Assert.AreEqual(Relation.Trade, relations.getRelation(userToInvite, alliance4));
            Assert.AreEqual(Relation.Trade, relations.getRelation(userToInvite, alliance4));

            //to Users
            Assert.AreEqual(Relation.War, relations.getRelation(userToInvite, user6));
            Assert.AreEqual(Relation.Hostile, relations.getRelation(userToInvite, user7));
            Assert.AreEqual(Relation.Neutral, relations.getRelation(userToInvite, user8));
            Assert.AreEqual(Relation.Trade, relations.getRelation(userToInvite, user9));
        }
예제 #4
0
        public void testTrySetRelation()
        {
            UserRelations relations = instance.userRelations;

            //newRelations is used by businessconnector to get all changes and make an xml of them
            //System.Collections.Generic.List<DiplomaticRelation> newRelations = new System.Collections.Generic.List<DiplomaticRelation>();

            User u3 = Mock.MockUser(id: (int)instance.identities.allianceId.getNext());

            instance.users.TryAdd(u3.id, u3);
            User u4 = Mock.MockUser(id: (int)instance.identities.allianceId.getNext());

            instance.users.TryAdd(u4.id, u4);
            User u5 = Mock.MockUser(id: (int)instance.identities.allianceId.getNext());

            instance.users.TryAdd(u5.id, u5);
            User u6 = Mock.MockUser(id: (int)instance.identities.allianceId.getNext());

            instance.users.TryAdd(u6.id, u6);
            //relations.setDiplomaticEntityState(u3, u4, Relation.Neutral);
            //relations.setDiplomaticEntityState(u4, u3, Relation.Neutral);
            relations.setDiplomaticEntityState(u3, u4, Relation.Trade);
            relations.setDiplomaticEntityState(u4, u3, Relation.Pact);

            System.Collections.Generic.List <SpacegameServer.Core.DiplomaticRelation> changes = new System.Collections.Generic.List <SpacegameServer.Core.DiplomaticRelation>();

            //cancel tradeTraty (2) -> set to 1 (neutral)
            relations.trySetRelation(u3.id, u4.id, u4.diplomaticType, Relation.Neutral, changes);
            Assert.AreEqual(Relation.Neutral, relations.getRelation(u3, u4), "(u3, u4) != 1");
            Assert.AreEqual(Relation.Neutral, relations.getRelation(u4, u3), "(u4, u3) != 1");

            //offer new pact
            relations.trySetRelation(u3.id, u4.id, u4.diplomaticType, Relation.Pact, changes);
            Assert.AreEqual(Relation.Neutral, relations.getRelation(u3, u4));
            Assert.AreEqual(Relation.Neutral, relations.getRelation(u4, u3));

            //accept trade
            relations.trySetRelation(u4.id, u3.id, u3.diplomaticType, Relation.Trade, changes);
            Assert.AreEqual(Relation.Trade, relations.getRelation(u3, u4));
            Assert.AreEqual(Relation.Trade, relations.getRelation(u4, u3));

            //test with alliances and more users:

            Assert.IsTrue(Alliance.createAlliance(u3, "a1"));
            Alliance a1 = instance.alliances[u3.allianceId];

            Alliance.inviteTo(u3, u4);
            Assert.IsTrue(Alliance.joinCheck(u4, a1.id));


            Assert.IsTrue(Alliance.createAlliance(u5, "a2"));
            Alliance a2 = instance.alliances[u5.allianceId];

            relations.setDiplomaticEntityState(u5, u6, Relation.Neutral);
            Alliance.inviteTo(u5, u6);
            Assert.IsTrue(Alliance.joinCheck(u6, a2.id));

            //check for diplomatic rights:
            Assert.IsFalse(relations.trySetRelation(u6.id, a1.id, a1.diplomaticType, Relation.Trade, changes));

            //check for missing contact
            a2.getMemberRight(u6).diplomaticAdmin = true;
            //Assert.IsFalse(relations.trySetRelation(u5.id, a1.id, a1.diplomaticType, Relation.Trade, changes));

            //rights are ok, contact is ok:
            relations.setDiplomaticEntityState(u3, u5, Relation.Neutral);
            relations.setDiplomaticEntityState(u5, u3, Relation.Neutral);

            //check that relations can only be sent to the uppermost group:
            Assert.IsFalse(relations.trySetRelation(u5.id, u3.id, u3.diplomaticType, Relation.Pact, changes));

            //now the work can be done: a1 proposes 2 to a1
            Assert.IsTrue(relations.trySetRelation(u5.id, a1.id, a1.diplomaticType, Relation.Trade, changes));

            //add all other users:

            /*
             * relations.setDiplomaticEntityState(u3, u6, Relation.Neutral);
             * relations.setDiplomaticEntityState(u6, u3, Relation.Neutral);
             * relations.setDiplomaticEntityState(u4, u5, Relation.Neutral);
             * relations.setDiplomaticEntityState(u5, u4, Relation.Neutral);
             * relations.setDiplomaticEntityState(u4, u6, Relation.Neutral);
             * relations.setDiplomaticEntityState(u6, u4, Relation.Neutral);
             */

            //a1 declares war
            a1.getMemberRight(u3).diplomaticAdmin = true;
            relations.trySetRelation(u3.id, a2.id, a2.diplomaticType, Relation.War, changes);
            Assert.AreEqual(Relation.War, relations.getRelation(a1, a2));
            Assert.AreEqual(Relation.War, relations.getRelation(u3, u5));
            Assert.AreEqual(Relation.War, relations.getRelation(u4, u5));
            Assert.AreEqual(Relation.War, relations.getRelation(u3, u6));
            Assert.AreEqual(Relation.War, relations.getRelation(u4, u6));
            Assert.AreEqual(Relation.War, relations.getRelation(a2, a1), "a2, a1 -> 0");
            Assert.AreEqual(Relation.War, relations.getRelation(u5, u3), "(u5, u3) -> 0");
            Assert.AreEqual(Relation.War, relations.getRelation(u5, u4), "(u5, u4) -> 0");
            Assert.AreEqual(Relation.War, relations.getRelation(u6, u3), "(u6, u3) -> 0");
            Assert.AreEqual(Relation.War, relations.getRelation(u6, u4), "(u6, u4) -> 0");

            //proposal: 4
            relations.trySetRelation(u3.id, a2.id, a2.diplomaticType, Relation.Pact, changes);
            Assert.AreEqual(Relation.War, relations.getRelation(a1, a2));
            Assert.AreEqual(Relation.War, relations.getRelation(u3, u5));
            Assert.AreEqual(Relation.War, relations.getRelation(u4, u5));
            Assert.AreEqual(Relation.War, relations.getRelation(u3, u6));
            Assert.AreEqual(Relation.War, relations.getRelation(u4, u6));

            //accepted 2
            relations.trySetRelation(u5.id, a1.id, a1.diplomaticType, Relation.Trade, changes);
            Assert.AreEqual(Relation.Trade, relations.getRelation(a1, a2), " a1, a2 -> 2");
            Assert.AreEqual(Relation.Trade, relations.getRelation(u3, u5), " u3, u5 -> 2");
            Assert.AreEqual(Relation.Trade, relations.getRelation(u4, u5), " u4, u5-> 2");
            Assert.AreEqual(Relation.Trade, relations.getRelation(u3, u6), " u3, u6 -> 2");
            Assert.AreEqual(Relation.Trade, relations.getRelation(u4, u6), " u4, u6 -> 2");
            Assert.AreEqual(Relation.Trade, relations.getRelation(a2, a1), "a2, a1 -> 2");
            Assert.AreEqual(Relation.Trade, relations.getRelation(u5, u3), "(u5, u3) -> 2");
            Assert.AreEqual(Relation.Trade, relations.getRelation(u5, u4), "(u5, u4) -> 2");
            Assert.AreEqual(Relation.Trade, relations.getRelation(u6, u3), "(u6, u3) -> 2");
            Assert.AreEqual(Relation.Trade, relations.getRelation(u6, u4), "(u6, u4) -> 2");

            relations.trySetRelation(u5.id, a1.id, a1.diplomaticType, Relation.Pact, changes);
            Assert.AreEqual(Relation.Pact, relations.getRelation(a1, a2));
            Assert.AreEqual(Relation.Pact, relations.getRelation(u3, u5));
            Assert.AreEqual(Relation.Pact, relations.getRelation(u4, u5));
            Assert.AreEqual(Relation.Pact, relations.getRelation(u3, u6));
            Assert.AreEqual(Relation.Pact, relations.getRelation(u4, u6));

            //test between user and alliance:
            User u7 = Mock.MockUser(id: (int)instance.identities.allianceId.getNext());

            instance.users.TryAdd(u7.id, u7);
            User u8 = Mock.MockUser(id: (int)instance.identities.allianceId.getNext());

            instance.users.TryAdd(u8.id, u8);
            relations.setDiplomaticEntityState(u7, u3, Relation.Neutral);
            relations.setDiplomaticEntityState(u3, u7, Relation.Neutral);
            relations.setDiplomaticEntityState(u8, u5, Relation.Neutral);
            relations.setDiplomaticEntityState(u5, u8, Relation.Neutral);

            relations.trySetRelation(u7.id, a1.id, a1.diplomaticType, Relation.Trade, changes);
            Assert.AreEqual(Relation.Neutral, relations.getRelation(a1, u7));
            Assert.AreEqual(Relation.Neutral, relations.getRelation(u7, a1));

            //alliance(-Member) to user
            relations.trySetRelation(u5.id, u8.id, u8.diplomaticType, Relation.Trade, changes);
            Assert.AreEqual(Relation.Neutral, relations.getRelation(u5, u8));
            Assert.AreEqual(Relation.Neutral, relations.getRelation(u8, u5));
        }