public async Task InitAsyncDetail()
        {
            Utils utils = new Utils();
            MaterialDetailFirebaseHelper detailFirebase = new MaterialDetailFirebaseHelper();

            listMatrialView.ItemsSource = await detailbaseHelper.GetAllMaterialDetail();

            try
            {
                Models.MaterialDetail detailObject = await detailbaseHelper.GetDetailById(this.detail_id);

                if (detailObject != null)
                {
                    MaterialSourceFirebaseHelper sourceFirebase = new MaterialSourceFirebaseHelper();
                    MaterialSource sourceObject = await sourceFirebase.GetMaterialSourceByID(utils.convertObject(detailObject.MaterialID));

                    MaterialFirebaseHelper headerFirebase  = new MaterialFirebaseHelper();
                    ProductFirebaseHelper  productFirebase = new ProductFirebaseHelper();
                    MaterialHeader         headerObject    = await headerFirebase.GetMaterial(new Guid(detailObject.HeaderID));

                    Models.Product productObject = await productFirebase.GetProduct(new Guid(headerObject.ProductID));

                    Lbl_FoodLabel.Text          = productObject.NameEn;
                    Lbl_UnitDisplay.Text        = detailObject.UnitName;
                    Entry_Quantity.Text         = detailObject.Quantity + "";
                    listMatrialView.ItemsSource = null;
                    Lbl_MaterialLabel.Text      = sourceObject.NameEn;
                }
            }
            catch (Exception ee) { }
        }
        public async Task <MaterialSource> GetMaterialSourceByNameEn(string nameEn)
        {
            MaterialSource returnValue = new MaterialSource();

            try
            {
                List <MaterialSource> listSource = await GetAllMaterialSource();

                if (listSource != null)
                {
                    for (int i = 0; i < listSource.Count; i++)
                    {
                        MaterialSource source = listSource[i];
                        if (source.NameEn != null && source.NameEn.Equals(nameEn))
                        {
                            returnValue = source;
                            break;
                        }
                    }
                }
            }
            catch (Exception ee)
            {
                string error_str = ee.Message;
                returnValue = null;
            }

            return(returnValue);
        }
        public async Task <Models.MaterialSource> GetMaterialSourceByID(string gID)
        {
            MaterialSource returnValue = new MaterialSource();
            Utils          utils       = new Utils();

            try
            {
                List <MaterialSource> listSource = await GetAllMaterialSource();

                if (listSource != null)
                {
                    for (int i = 0; i < listSource.Count; i++)
                    {
                        MaterialSource source = listSource[i];
                        if (source.ID != null && utils.convertObject(source.ID).Equals(gID))
                        {
                            returnValue = source;
                            break;
                        }
                    }
                }
            }
            catch (Exception ee)
            {
                string error_str = ee.Message;
                returnValue = null;
            }

            return(returnValue);
        }
Ejemplo n.º 4
0
    public override void Execute()
    {
        if (!this.isActive || !this.building.constructed)
        {
            return;
        }

        Tile tile = GameController.map.tiles[(int)this.building.position.y, (int)this.building.position.x];

        if (tile.mapComponent != null && tile.mapComponent.GetType() == typeof(MaterialSource))
        {
            MaterialSource materialSource = (MaterialSource)tile.mapComponent;

            materialSource.quantity -= this.building.producedPerTime;

            if (materialSource.quantity <= 0)
            {
                GameController.players[this.building.idPlayer].baseMaterials[this.baseMaterial.idType] += (int)materialSource.quantity;
                GameController.players[this.building.idPlayer].resourcesCount += (int)materialSource.quantity;

                this.building.Destroy();
                GameController.players[this.building.idPlayer].RemoveProperty(this.building);
                GameController.instance.GetComponent <GameController>().DestroySource(materialSource);

                this.isActive = false;
            }
        }

        GameController.players[this.building.idPlayer].baseMaterials[this.baseMaterial.idType] += this.building.producedPerTime;
        GameController.players[this.building.idPlayer].resourcesCount += this.building.producedPerTime;

        GameController.instance.GetComponent <GameController>().DrawInfoMaterials();
    }
Ejemplo n.º 5
0
 public DetailsLayer(IConverter <Vector2Int, Vector3> coordinateConverter, MaterialSource materialSource,
                     IEnumerable <string> raycastLayers)
 {
     _coordinateConverter = coordinateConverter;
     _materialSource      = materialSource;
     _raycastMask         = LayerMask.GetMask(raycastLayers.ToArray());
 }
Ejemplo n.º 6
0
 public bool SendSelectedWorkerTo(MaterialSource mat)
 {
     if (SelectedWorker != null)
     {
         return(SelectedWorker.AssignResource(mat));
     }
     return(false);
 }
Ejemplo n.º 7
0
    public void Destroy()
    {
        GameController gameController = GameController.instance.GetComponent <GameController>();
        Map            map            = GameController.map;

        int i, j;

        for (i = (int)this.position.y; i < (int)(this.position.y + this.size.y); i++)
        {
            for (j = (int)this.position.x; j < (int)(this.position.x + this.size.x); j++)
            {
                if (map.tiles[i, j].mapComponent == null)
                {
                    map.tiles[i, j].isWalkable = true;
                    map.tiles[i, j].canBuild   = true;
                }
                else
                {
                    if (map.tiles[i, j].mapComponent.GetType() == typeof(MaterialSource))
                    {
                        MaterialSource ms = (MaterialSource)map.tiles[i, j].mapComponent;
                        ms.canBuild = true;
                    }
                }
            }
        }

        for (i = (int)this.position.y - 1; i < ((int)this.position.y + (int)this.size.x + 1); i++)
        {
            for (j = (int)this.position.x - 1; j < ((int)this.position.x + (int)this.size.y + 1); j++)
            {
                if (gameController.CheckCanBuild(i, j))
                {
                    map.tiles[i, j].isWalkable = true;
                    map.tiles[i, j].canBuild   = true;
                }
            }
        }

        foreach (Order order in GameController.players[this.idPlayer].orders)
        {
            if (order.GetType() == typeof(ProduceMaterialOrder))
            {
                ProduceMaterialOrder PMO = (ProduceMaterialOrder)order;

                if (PMO.building == this)
                {
                    PMO.isActive = false;
                    break;
                }
            }
        }

        gameController.objectName = null;
        GameController.players[this.idPlayer].RemoveProperty(this);
        gameController.DestroyGameObject(this.model);
        gameController.DrawViewContent();
    }
Ejemplo n.º 8
0
            public override bool Equals(object obj)
            {
                MaterialSource source = obj as MaterialSource;

                if (source != null)
                {
                    return(string.Equals(Material, source.Material, StringComparison.CurrentCultureIgnoreCase));
                }

                return(false);
            }
Ejemplo n.º 9
0
 public override void ResetState()
 {
     Source              = null;
     Destination         = null;
     CurrentState        = WorkerEggState.Unassigned;
     Victim              = null;
     selectingForHarvest = false;
     Longtouch.gameObject.SetActive(false);
     DeselectWorker();
     UpdateUI();
 }
Ejemplo n.º 10
0
        private void lboxAutoComplete_DoubleClick(object sender, EventArgs e)
        {
            MaterialSource source = lboxAutoComplete.SelectedItem as MaterialSource;

            if (source != null)
            {
                MaterialPermitItem item = Document.AddItem();
                item.Material     = source.Material;
                item.MaterialUnit = source.MaterialUnit;

                bsItemList.Position = bsItemList.IndexOf(item);
                dgvItemList.Select();
            }
        }
Ejemplo n.º 11
0
    public bool AssignResource(MaterialSource mats)
    {
        // If we assign to a new resource, go from any state to Harvesting
        if (CanAssignToResource() && mats != Source)
        {
            Debug.Log(string.Format("Worker {0} assigned to resource {1}", gameObject.name, mats.gameObject.name));
            if (Victim != null)
            {
                Victim = null;
            }
            Source = mats;
            DoPantryHarvest();
            return(true);
        }

        return(false);
    }
Ejemplo n.º 12
0
    public void ModifyTiles()
    {
        int pos, posX, posY;
        int i = (int)position.y;
        int j = (int)position.x;

        Map map = GameController.map;

        for (posX = 0; posX < this.size.x; posX++)
        {
            for (posY = 0; posY < this.size.y; posY++)
            {
                map.tiles[(i + posX), (j + posY)].isWalkable = false;
                map.tiles[(i + posX), (j + posY)].canBuild   = false;

                if (map.tiles[(i + posX), (j + posY)].mapComponent != null && map.tiles[(i + posX), (j + posY)].mapComponent.GetType() == typeof(MaterialSource))
                {
                    MaterialSource ms = (MaterialSource)map.tiles[(i + posX), (j + posY)].mapComponent;

                    ms.canBuild = false;
                }
            }
        }

        for (pos = 0; pos <= this.size.x + 1; pos++)
        {
            map.tiles[(i - 1), (j + pos - 1)].canBuild = false;
            map.tiles[(i + (int)this.size.y), (j + pos - 1)].canBuild = false;
        }

        for (pos = 0; pos < this.size.y; pos++)
        {
            map.tiles[(i + pos), (j - 1)].canBuild = false;
            map.tiles[(i + pos), (j + (int)this.size.x)].canBuild = false;
        }
    }
Ejemplo n.º 13
0
    public bool AddBuilding(Map map, BuildingDao buildingDao, Vector2 position)
    {
        if (position.x > 0 && position.x < (map.width - 1) && position.y > 0 && position.y < (map.height - 1))
        {
            int pos;
            int i = (int)position.y;
            int j = (int)position.x;

            if (!buildingDao.constructed && this.fog.tiles[i, j].unknown)
            {
                return(false);
            }

            if (buildingDao.requireds.Count > 0)
            {
                int requiredNumber = 0;

                foreach (string required in buildingDao.requireds)
                {
                    if (map.tiles[i, j].mapComponent != null)
                    {
                        if (map.tiles[i, j].mapComponent.GetType() == typeof(MaterialSource))
                        {
                            MaterialSource ms = (MaterialSource)map.tiles[i, j].mapComponent;

                            if (!ms.canBuild)
                            {
                                return(false);
                            }
                        }

                        if (map.tiles[i, j].mapComponent.name.CompareTo(required) == 0)
                        {
                            requiredNumber++;
                        }
                    }
                }

                if (requiredNumber != buildingDao.requireds.Count)
                {
                    return(false);
                }
            }
            else
            {
                // Check CanBuild Vertically
                for (pos = 0; pos < buildingDao.size.y; pos++)
                {
                    if (!map.tiles[(i + pos), j].canBuild)
                    {
                        return(false);
                    }
                }

                // Check CanBuild Horizontally
                for (pos = 0; pos < buildingDao.size.y; pos++)
                {
                    if (!map.tiles[i, (j + pos)].canBuild)
                    {
                        return(false);
                    }
                }

                int wSize = Mathf.Abs((int)buildingDao.size.x) + 2;
                int hSize = Mathf.Abs((int)buildingDao.size.y) + 2;

                // Check IsWalkable Vertically
                for (pos = 0; pos < hSize; pos++)
                {
                    if (!map.tiles[(pos + i - 1), (j - 1)].isWalkable || !map.tiles[(pos + i - 1), (j + (int)buildingDao.size.x)].isWalkable)
                    {
                        return(false);
                    }
                }

                // Check IsWalkable Horizontally
                for (pos = 0; pos < wSize; pos++)
                {
                    if (!map.tiles[(i - 1), (pos + j - 1)].isWalkable || !map.tiles[(i + (int)buildingDao.size.y), (pos + j - 1)].isWalkable)
                    {
                        return(false);
                    }
                }
            }

            if (CheckCosts(buildingDao.cost))
            {
                DiscountCosts(buildingDao.cost);

                Building building = buildingDao.Instantiate();

                building.idPlayer      = this.id;
                building.position      = position;
                building.creationPoint = new Vector2(position.x - 1.0f, position.y - 1.0f);

                this.buildings.Add(building.id, building);

                building.ModifyTiles();
                building.RemoveFog();

                if (building.constructed)
                {
                    building.life = building.lifeTotal;
                }

                building.Draw();

                return(true);
            }
        }

        return(false);
    }
Ejemplo n.º 14
0
        async void OnSaveButtonClicked(object sender, EventArgs e)
        {
            bool valid = true;

            if (valid && this.Entry_Quantity.Text.Trim().Length == 0)
            {
                valid = false;
                await DisplayAlert("Error", "กรุณาระบุ Cost", "OK");
            }

            if (valid && this.Entry_Quantity.Text.Trim().Length > 0)
            {
                try
                {
                    decimal.Parse(this.Entry_Quantity.Text.Trim());
                }
                catch (Exception ee) {
                    valid = false;
                    await DisplayAlert("Error", "กรุณาระบุ จำนวน ให้ถูกต้อง", "OK");
                }
            }


            if (picker.SelectedIndex < 0)
            {
                valid = false;
                await DisplayAlert("Error", "กรุณาระบุ หน่วย", "OK");
            }

            int    selectedIndex = picker.SelectedIndex;
            string unitType      = "";

            if (selectedIndex != -1)
            {
                unitType = (string)picker.ItemsSource[selectedIndex];
            }


            string         mat_select = listAllMaterial.SelectedItem.ToString();
            MaterialSource mSource    = await sourcefirebaseHelper.GetMaterialSourceByNameEn(mat_select);


            if (valid)
            {
                if (bt_Confirm.Text.Equals("Confirm Update"))
                {
                    //Update
                    await detailFirebaseHelper.UpdateMaterial(this.guid_id, this.mHeader_id, mSource.ID, unitType, decimal.Parse(this.Entry_Quantity.Text.Trim()));
                    await DisplayAlert("Complete", "Update Complete", "OK");

                    bt_Confirm.Text = "Confirm";

                    await Navigation.PushAsync(new ListMaterialAdmin());
                }
                else
                {
                    //Insert
                    await detailFirebaseHelper.AddMaterialDetail(this.mHeader_id, mSource.ID, unitType, decimal.Parse(this.Entry_Quantity.Text.Trim()));

                    await DisplayAlert("Complete", "Insert Complete", "OK");

                    bt_Confirm.Text = "Confirm";

                    await Navigation.PushAsync(new ListMaterialAdmin());
                }        //end if
            }            //end if
        }