Esempio n. 1
0
        public void getShips(SpacegameServer.Core.Core _core, int _shipId, SpacegameServer.Core.User _user)
        {
            int DefaultUser = 0;

            int shipId1 = (int)_core.identities.shipLock.getNext();

            SpacegameServer.Core.Ship Ship1;
            Ship1 = new SpacegameServer.Core.Ship(shipId1);

            Ship1.userid = DefaultUser;
            Ship1.posX   = 5000;
            Ship1.posY   = 5000;

            _core.ships[shipId1] = Ship1;
            _core.addShipToField(Ship1);
            ((SpacegameServer.Core.User)_core.users[DefaultUser]).ships.Add(Ship1);


            shipId1 = (int)_core.identities.shipLock.getNext();
            Ship1   = new SpacegameServer.Core.Ship(shipId1);

            Ship1.userid = DefaultUser;
            Ship1.posX   = 5001;
            Ship1.posY   = 5001;

            _core.ships[shipId1] = Ship1;
            _core.addShipToField(Ship1);
            ((SpacegameServer.Core.User)_core.users[DefaultUser]).ships.Add(Ship1);
        }
Esempio n. 2
0
        public void TestLockable()
        {
            SpacegameServer.Core.Core Instance = SpacegameServer.Core.Core.Instance;


            SpacegameServer.Core.User x = Mock.MockUserAndAdd(Instance);

            int shipId1 = (int)Instance.identities.shipLock.getNext();
            int shipId2 = (int)Instance.identities.shipLock.getNext();

            SpacegameServer.Core.Ship Ship1, Ship2;
            Ship1 = new SpacegameServer.Core.Ship(shipId1);
            Ship2 = new SpacegameServer.Core.Ship(shipId2);

            SpacegameServer.Core.Colony Colony1;
            Colony1 = new SpacegameServer.Core.Colony(1);

            //Object can only be locked once
            Assert.IsTrue(Ship1.setLock());
            Assert.IsFalse(Ship1.setLock());

            //LockAll of Ships can only be set once
            Assert.IsTrue(SpacegameServer.Core.Ship.setLockAll());
            Assert.IsFalse(SpacegameServer.Core.Ship.setLockAll());

            //ships can't be lcoked anymore, colonies can
            Assert.IsFalse(Ship1.setLock());
            Assert.IsFalse(Ship2.setLock());
            Assert.IsTrue(Colony1.setLock());
            Ship1.removeLock();
            Colony1.removeLock();

            //after removing LockAll, all is lockable again
            SpacegameServer.Core.Ship.removeLockAll();
            Assert.IsTrue(Ship1.setLock());
            Assert.IsTrue(Ship2.setLock());
            Assert.IsTrue(Colony1.setLock());
        }
Esempio n. 3
0
 public void colonize(SpacegameServer.Core.Ship _ship, string _newName, out int colonyId, out string xml)
 {
     xml = "<xml>createUserContact</xml>"; colonyId = 1;
 }
Esempio n. 4
0
 public bool writeMovement(SpacegameServer.Core.Ship _ship, SpacegameServer.Core.Ship _enemyship, int _direction)
 {
     return(true);
 }
Esempio n. 5
0
 public string combat(SpacegameServer.Core.Ship _ship, SpacegameServer.Core.Ship _defShip, SpacegameServer.Core.Field _destination, Tuple <byte, byte> _systemCoords)
 {
     return("<xml>createUserContact</xml>");
 }
Esempio n. 6
0
 public void saveShipTranscensionUsers(SpacegameServer.Core.Ship ship)
 {
 }
Esempio n. 7
0
 public void saveShipGoods(SpacegameServer.Core.Ship _ship)
 {
 }
Esempio n. 8
0
 public void saveShipModules(SpacegameServer.Core.Ship _ship)
 {
 }
Esempio n. 9
0
 public void saveShipname(SpacegameServer.Core.Ship _ship)
 {
 }
Esempio n. 10
0
 public Task deleteShip(SpacegameServer.Core.Ship _ship, object command)
 {
     return(Task.FromResult(0));
 }
Esempio n. 11
0
 public void insertShip(SpacegameServer.Core.Ship _ship)
 {
 }
Esempio n. 12
0
 public void getShipModules(SpacegameServer.Core.Core _core, SpacegameServer.Core.Ship _ship, bool _refresh = false)
 {
 }
Esempio n. 13
0
        public Ship StrongestEnemyOnField(Ship attackingShip, Tuple <byte, byte> SysCoords, int attackedShipId = 0)
        {
            CombatField CombatField = new SpacegameServer.Core.CombatField(this, SysCoords);

            var DefendingShips = this.ships.Where(ship => (ship.userid != attackingShip.userid &&
                                                           ((SysCoords != null && ship.systemX == SysCoords.Item1 && ship.systemY == SysCoords.Item2) ||
                                                            (SysCoords == null)) &&
                                                           UserRelations.IsLower(Core.Instance.userRelations.getRelation(attackingShip.userid, ship.userid), Relation.Neutral)));

            if (DefendingShips.Count() == 0 && attackedShipId != 0 && this.ships.Any(e => e.id == attackedShipId))
            {
                // the ship to attack is on the field. Add it to the DefendingShips, then add all other ships of this user or his alliance members, and all other ships from pact-members, as long as the pact is not also with the attacker
                var ShipToAttack    = this.ships.First(e => e.id == attackedShipId);
                var UserToAttack    = Core.Instance.users[ShipToAttack.userid];
                var UserThatAttacks = Core.Instance.users[attackingShip.userid];

                //Prepare Lists to get all other users that might defend the attcked ships
                var AttackerPacts = Core.Instance.userRelations.getAllContacts(UserThatAttacks, Relation.Pact);
                List <DiplomaticEntity> ExclusivePacts = new List <DiplomaticEntity>();
                List <User>             AllEnemyUsers  = new List <User>();

                if (UserToAttack.allianceId != 0 && UserThatAttacks.allianceId != UserToAttack.allianceId)
                {
                    AllEnemyUsers.AddRange(Core.Instance.alliances[UserToAttack.allianceId].getUsers());
                }
                else
                {
                    AllEnemyUsers.Add(UserToAttack);
                }

                //add pact-users that are not in a pact with the attacker
                foreach (var entry in Core.Instance.userRelations.getAllContacts(UserToAttack, Relation.Pact))
                {
                    if (AttackerPacts.Any(e => e.target == entry.target))
                    {
                        continue;
                    }

                    AllEnemyUsers.AddRange(entry.target.getUsers());
                }

                DefendingShips = this.ships.Where(
                    ship => AllEnemyUsers.Any(enemy => enemy.id == ship.userid) &&
                    ((SysCoords != null && ship.systemX == SysCoords.Item1 && ship.systemY == SysCoords.Item2) ||
                     (SysCoords == null))
                    );
            }

            //defensive pacts could provide additional defense unit at this point

            double BestRatio         = Double.MaxValue;
            Ship   BestDefenderSoFar = null;

            foreach (var Defender in DefendingShips)
            {
                if (BestDefenderSoFar == null)
                {
                    BestDefenderSoFar = Defender;
                }

                var ratio = Defender.AttackerDefenderRatio(attackingShip, CombatField);
                if (ratio < BestRatio)
                {
                    BestRatio         = ratio;
                    BestDefenderSoFar = Defender;
                }
            }

            return(BestDefenderSoFar);
        }
Esempio n. 14
0
        public void fieldCombat(List <Ship> ShipsFighting, User Attacker, Tuple <byte, byte> SysXY)
        {
            Core core = Core.Instance;
            //check attacker ships, find the one with the best combat ratio against any defender
            Ship AttackingShip = this.detectAttackingShip(Attacker, SysXY);

            if (AttackingShip == null)
            {
                return;
            }
            Ship Defender = this.StrongestEnemyOnField(AttackingShip, SysXY);

            if (Defender == null)
            {
                return;
            }

            //if Attacker has only non-Combatants and defender has combatants, destroy them and quit
            if (AttackingShip.attack == 0)
            {
                if (!ShipsFighting.Any(e => e.id == AttackingShip.id))
                {
                    ShipsFighting.Add(AttackingShip);
                }
                AttackingShip.destroy();
                this.fieldCombat(ShipsFighting, Attacker, SysXY);
                return;
            }

            if (Defender.attack == 0)
            {
                if (!ShipsFighting.Any(e => e.id == Defender.id))
                {
                    ShipsFighting.Add(Defender);
                }
                Defender.destroy();
                this.fieldCombat(ShipsFighting, Attacker, SysXY);
                return;
            }


            //let them fight
            if (!ShipsFighting.Any(e => e.id == AttackingShip.id))
            {
                ShipsFighting.Add(AttackingShip);
            }
            if (!ShipsFighting.Any(e => e.id == Defender.id))
            {
                ShipsFighting.Add(Defender);
            }
            Combat Combat = new Combat((int)Core.Instance.identities.combat.getNext());

            Combat.fight(AttackingShip, Defender, this);

            //save Combat and both ships
            Core.Instance.combats[Combat.CombatId] = Combat;
            Core.Instance.dataConnection.saveCombat(Combat);

            //continue with evaluation
            this.fieldCombat(ShipsFighting, Attacker, SysXY);
        }
Esempio n. 15
0
 public bool AddShip(Ship ship)
 {
     this.ships.Add(ship);
     ship.field = this;
     return(true);
 }