Esempio n. 1
0
        public override string ToString()
        {
            StringBuilder sBuilder = new StringBuilder();

            if (this.Sector != null)
            {
                sBuilder.AppendFormat("{0}.{1}", Base36.Encode((long)this.Sector.IndexX), Base36.Encode((long)this.Sector.IndexY));
            }
            if (this.StarSystem != null)
            {
                sBuilder.AppendFormat(".{0}", Base36.Encode((long)this.StarSystem.SysNum));
            }
            if (this.SystemBody != null)
            {
                sBuilder.AppendFormat(".{0}", Base36.Encode((long)this.SystemBody.SystemBodyId));
            }
            if (this.PlanetSector != null)
            {
                sBuilder.AppendFormat(".{0}", this.PlanetSector);
            }
            if (this.Zone != null)
            {
                sBuilder.AppendFormat(".{0}", this.Zone);
            }

            return(sBuilder.ToString());
        }
Esempio n. 2
0
 public override string ToString()
 {
     return(string.Format(
                "{0}.{1}:{2}.{3}.{4}",
                Base36.Encode((long)this._sectorIndexX),
                Base36.Encode((long)this._sectorIndexY),
                Base36.Encode((long)this._sectorLocation.X),
                Base36.Encode((long)this._sectorLocation.Y),
                Base36.Encode((long)this._sectorLocation.Z)
                ));
 }
Esempio n. 3
0
        public GameLocation(string locationCode, bool isBase36)
        {
            string[] tokens = locationCode.Split('.');

            this.Sector     = null;
            this.StarSystem = null;
            this.SystemBody = null;

            if (tokens.Length >= 2)
            {
                uint sX = 0, sY = 0;

                if (isBase36)
                {
                    sX = (uint)Base36.Decode(tokens[0]);
                    sY = (uint)Base36.Decode(tokens[1]);
                }
                else
                {
                    uint.TryParse(tokens[0], out sX);
                    uint.TryParse(tokens[1], out sY);
                }

                this.Sector = new Sector(sX, sY);
            }

            if (tokens.Length >= 3)
            {
                int systemNum;

                if (isBase36)
                {
                    systemNum = (int)Base36.Decode(tokens[2]);
                }
                else
                {
                    int.TryParse(tokens[2], out systemNum);
                }

                if (this.Sector.Systems.Count > systemNum)
                {
                    this.StarSystem = this.Sector.Systems[systemNum];
                }
                else
                {
                    this.StarSystem = StarSystem.GetStarSystem(this.Sector, systemNum);
                }
            }

            if (tokens.Length >= 4)
            {
                int systemBodyId;

                if (isBase36)
                {
                    systemBodyId = (int)Base36.Decode(tokens[3]);
                }
                else
                {
                    int.TryParse(tokens[3], out systemBodyId);
                }

                if (this.StarSystem.SystemBodies.Length > systemBodyId)
                {
                    this.SystemBody = this.StarSystem.SystemBodies[systemBodyId];
                }
                else
                {
                    this.SystemBody = new SystemBody(StarSystem, systemBodyId);
                }
            }

            if (tokens.Length >= 5)
            {
                this.PlanetSector = tokens[4];
            }

            if (tokens.Length >= 6)
            {
                this.Zone = tokens[5];
            }
        }
Esempio n. 4
0
        public static bool TryParse(string value, out Coords coords, bool isBase36)
        {
            string[] mainTokens = value.Split(new char[] { ':' }, StringSplitOptions.RemoveEmptyEntries);

            uint sectorIndexX = 0;
            uint sectorIndexY = 0;
            int  sX = 0, sY = 0, sZ = 0;

            coords = new Coords(0, 0, 0, 0, 0);

            if (mainTokens.Length == 0)
            {
                return(false);
            }

            string[] sectorTokens = mainTokens[0].Split('.');

            if (sectorTokens.Length != 2)
            {
                return(false);
            }
            else
            {
                if (isBase36)
                {
                    sectorIndexX = (uint)Base36.Decode(sectorTokens[0]);
                }
                else if (!uint.TryParse(sectorTokens[0], out sectorIndexX))
                {
                    return(false);
                }

                if (isBase36)
                {
                    sectorIndexY = (uint)Base36.Decode(sectorTokens[1]);
                }
                else if (!uint.TryParse(sectorTokens[1], out sectorIndexY))
                {
                    return(false);
                }
            }

            if (mainTokens.Length > 1)
            {
                string[] systemTokens = mainTokens[1].Split('.');
                if (systemTokens.Length >= 3)
                {
                    if (isBase36)
                    {
                        sX = (int)Base36.Decode(systemTokens[0]);
                    }
                    else if (!int.TryParse(systemTokens[0], out sX))
                    {
                        return(false);
                    }
                    if (isBase36)
                    {
                        sY = (int)Base36.Decode(systemTokens[1]);
                    }
                    else if (!int.TryParse(systemTokens[1], out sY))
                    {
                        return(false);
                    }
                    if (isBase36)
                    {
                        sZ = (int)Base36.Decode(systemTokens[2]);
                    }
                    else if (!int.TryParse(systemTokens[2], out sZ))
                    {
                        return(false);
                    }
                }
            }

            coords = new Coords(sectorIndexX, sectorIndexY, sX, sY, sZ);
            return(true);
        }