/// <summary>
        /// Will calculate a sample alias from a given parent id and parent alias.
        /// </summary>
        /// <param name="parentID"></param>
        /// <param name="parentAlias"></param>
        /// <returns></returns>
        public string CalculateMineralAlias(string parentID, string parentAlias)
        {
            //Querying with Linq
            List <object>         MineralTableRaw    = dAccess.ReadTable(mineralModel.GetType(), null);
            IEnumerable <Mineral> mineralTable       = MineralTableRaw.Cast <Mineral>(); //Cast to proper list type
            IEnumerable <string>  mineralParentEarth = from e in mineralTable where e.MineralParentID == parentID orderby e.MineralIDName descending select e.MineralIDName;

            int    newID               = 1; //Incrementing step
            string newAlias            = string.Empty;
            string finaleMineralString = parentAlias;

            //Detect last sample number and add 1 to it.
            if (mineralParentEarth.Count() > 0 && mineralParentEarth.ElementAt(0) != null)
            {
                string lastAlias        = mineralParentEarth.ToList()[0].ToString(); //Select first element since the list has been sorted in descending order
                string lastNumberString = lastAlias.Substring(lastAlias.Length - 2); //Sample only has two digits id in the alias

                newID = Convert.ToInt16(lastNumberString) + newID;

                //Find a non existing name
                bool breaker = true;
                while (breaker)
                {
                    //Padd current ID with 0 if needed
                    if (newID < 10)
                    {
                        newAlias = "0" + newID;
                    }
                    else
                    {
                        newAlias = newID.ToString();
                    }

                    finaleMineralString = parentAlias + newAlias;

                    //Find existing
                    IEnumerable <Mineral> existingSamples = from s in mineralTable where s.MineralParentID == parentID && s.MineralIDName == finaleMineralString select s;
                    if (existingSamples.Count() == 0 || existingSamples == null)
                    {
                        breaker = false;
                    }

                    newID++;
                }
            }
            else
            {
                finaleMineralString = parentAlias + "0" + newID;
            }

            return(finaleMineralString);
        }
Exemplo n.º 2
0
    private void OnTriggerStay2D(Collider2D other)
    {
        if (_clawstate == ClawState.Spinning || _clawstate == ClawState.Firing)
        {
            // break walls
            Tilemap map = other.GetComponentInParent <Tilemap>();
            if (map != null)
            {
                Vector3 drillTip = other.ClosestPoint(_hitbox.bounds.center);
                //Vector3Int cell = Vector3Int.RoundToInt(drillTip);

                // new Vector3(_hitbox.bounds.center.x, _hitbox.bounds.max.y, _hitbox.bounds.center.z);

                if (_drillTimeout > drill_timeout)
                {
                    _drillTimeout = 0.0;
                    Vector3Int tilePos = map.WorldToCell(drillTip);
                    TileBase   tile    = map.GetTile(tilePos);

                    if (tile == true && tile != undrillable_tile)
                    {
                        _audioSourceDig.Play();
                        //_pathfinding.Scan();
                        //_pathfinding.ScanAsync();
                        //_pathfinding.UpdateGraphs(_pathfinding.graph);
                        //Pathfinding.AstarPathEditor.MenuScan();
                        map.GetComponentInParent <DestroyTile>().KillTile(tilePos, drillTip);
                    }
                }
                else if (_particleTimeout > particle_freq)
                {
                    _particleTimeout = 0.0;
                    map.GetComponentInParent <DestroyTile>().ParticleDrop(drillTip);
                    _audioSourceDig.Play();
                }
            }

            // harvest minerals
            Mineral min = other.GetComponent <Mineral>();
            if (min != null && min.GetType() == typeof(Mineral))
            {
                _audioSourceDig.Play();
                inventory.mineral_count += min.getValue();
                // particle system will play then destroy object
                other.GetComponent <BoxCollider2D>().enabled = false;
                other.GetComponent <ParticleSystem>().Play();
                other.GetComponent <SpriteRenderer>().enabled = false;
                // in the meantime, destroy the mineral so we can't double-mine it
                Destroy(min);
            }
        }
    }
Exemplo n.º 3
0
        /// <summary>
        /// Draws tiles based on their mapped bitmap
        /// </summary>
        public void DrawWorldBitmaps()
        {
            int size = Escapade.GetWorld().Size;

            for (int x = 0; x < Escapade.GetWorld().Width; x++)
            {
                for (int y = 0; y < Escapade.GetWorld().Height; y++)
                {
                    if (Escapade.GetWorld().Map [x, y].Type == TileType.Rock)
                    {
                        SwinGame.DrawBitmap(_maskmap [Escapade.GetWorld().Map [x, y].Mask], x * size, y * size);
                        Mineral m = Escapade.GetWorld().Map [x, y].Mineral;
                        if (m != null)
                        {
                            string mineralBitmap = "overlay_" + m.GetType().ToString().ToLower().Split('.').Last();
                            SwinGame.DrawBitmap(_bitmaps [mineralBitmap], x * size, y * size);
                        }
                    }
                }
            }
        }
Exemplo n.º 4
0
        public void CalculateResidual(string newMode = "")
        {
            // Language localization using Resource.resw
            var    loadLocalization = Windows.ApplicationModel.Resources.ResourceLoader.GetForCurrentView();
            string Prefix           = loadLocalization.GetString("MineralDialogResidualPrefix");
            string MiddleFix        = loadLocalization.GetString("MineralDialogResidualMiddlefix");
            string Suffix           = loadLocalization.GetString("MineralDialogResidualSuffix");

            List <object>         mineralTableRaw = accessData.ReadTable(mineralModel.GetType(), null);
            IEnumerable <Mineral> mineralTable    = mineralTableRaw.Cast <Mineral>(); //Cast to proper list type

            //Get a list of related mineral from selected earthmat
            string parentID = existingDataDetailMineral.ParentID;

            //Find proper parent id (request could come from a mineral or an earthmat selection)
            if (existingDataDetailMineral.ParentTableName == Dictionaries.DatabaseLiterals.TableStation)
            {
                parentID = existingDataDetailMineral.GenericID;
            }
            IEnumerable <Mineral> mineralParentEarth = from e in mineralTable where e.MineralParentID == parentID select e;

            if (_mineralResidualModes.Count == 0 && (mineralParentEarth.Count() != 0 || mineralParentEarth != null))
            {
                foreach (Mineral mns in mineralParentEarth)
                {
                    _minerals.Add(mns.MineralName);

                    int  currentPercentage = 0;
                    bool currentModeParsed = int.TryParse(mns.MineralMode, out currentPercentage);

                    if (currentModeParsed)
                    {
                        if (mns.MineralID == existingDataDetailMineral.GenericID)
                        {
                            if (newMode != string.Empty)
                            {
                                currentModeParsed = int.TryParse(newMode, out currentPercentage);
                            }

                            if (currentModeParsed)
                            {
                                _mineralResidualModes[mns.MineralID] = currentPercentage;
                            }
                        }
                        else
                        {
                            if (currentModeParsed)
                            {
                                _mineralResidualModes[mns.MineralID] = currentPercentage;
                            }
                        }
                    }
                }

                if (_mineralResidualModes.Count() == 0)
                {
                    int  currentPercentage = 0;
                    bool currentModeParsed = int.TryParse(newMode, out currentPercentage);
                    _mineralResidualModes[existingDataDetailMineral.GenericID] = currentPercentage;
                }
            }
            else
            {
                int  currentPercentage = 0;
                bool currentModeParsed = int.TryParse(newMode, out currentPercentage);
                _mineralResidualModes[existingDataDetailMineral.GenericID] = currentPercentage;
            }


            //Calculate total percentage
            int _mineralResidualMode = 0;

            foreach (KeyValuePair <string, int> modes in _mineralResidualModes)
            {
                _mineralResidualMode = _mineralResidualMode + modes.Value;
            }
            _mineralResidualText = Prefix + _mineralResidualMode.ToString() + MiddleFix + _mineralResidualModes.Count().ToString() + Suffix;
            RaisePropertyChanged("MineralResidualText");
        }