Exemple #1
0
        private static MapDistance _getResult(MapAdress source, MapAdress target, bool calcMotherFleet, bool hasPremium)
        {
            var md = new MapDistance(source, target, calcMotherFleet);

            md.CalcAndSetSecond(GetMod(hasPremium) * 0.1);
            return(md);
        }
        public MapDistance(MapAdress source, MapAdress target, bool calcMotherFleet)
        {
            Source = source;
            Target = target;

            _galaxyRange = Math.Abs(Source.Galaxy - Target.Galaxy);
            if (Math.Abs(_galaxyRange) > 1)
            {
                if (Source.GalaxyPosition == null || Target.GalaxyPosition == null)
                {
                    throw new Exception(Error.InputDataIncorrect);
                }
                _galaxyRange  = Vector3.CalcDistance(Source.GalaxyPosition, Target.GalaxyPosition);
                _calcByGalaxy = true;
                return;
            }

            _sectorRange = Math.Abs(Source.Sector - Target.Sector);
            if (Math.Abs(_sectorRange) > 1)
            {
                if (Source.SectorPosition == null || Target.SectorPosition == null)
                {
                    throw new Exception(Error.InputDataIncorrect);
                }
                _sectorRange  = Vector3.CalcDistance(Source.SectorPosition, Target.SectorPosition);
                _calcBySector = true;
                return;
            }


            if (calcMotherFleet && Source.System == Target.System)
            {
                if (Target.PlanetPosition == null)
                {
                    throw new Exception(Error.InputDataIncorrect);
                }
                _calcByPlanet = true;
                const int motherRange = 25;
                _planetRange = motherRange - Target.PlanetPosition.X;
                if (_planetRange < 5)
                {
                    _planetRange = 5;
                }
                return;
            }
            if (Source.System == Target.System)
            {
                if (Source.PlanetPosition == null || Target.PlanetPosition == null)
                {
                    throw new Exception(Error.InputDataIncorrect);
                }
                _calcByPlanet = true;
                _planetRange  = Vector3.CalcDistance(Source.PlanetPosition, Target.PlanetPosition);
                return;
            }

            if (Source.SystemPosition == null || Target.SystemPosition == null)
            {
                throw new Exception(Error.InputDataIncorrect);
            }
            _systemRange  = Vector3.CalcDistance(Source.SystemPosition, Target.SystemPosition);
            _calcBySystem = true;
        }