Beispiel #1
0
        public async Task QuarryAdd(QuarryModel model)
        {
            QuarryEntity entity = await this.AddEntity <QuarryEntity, QuarryModel>(model, false);

            // adding colours ids
            model.ColourIds.ForEach(cId => this.DbContext.QuarryMaterialColours.Add(new QuarryMaterialColourEntity()
            {
                Quarry = entity, MaterialColourId = cId
            }));

            // adding Yard
            this.DbContext.Yards.Add(new YardEntity()
            {
                YardName = model.QuarryName + " Yard", Location = model.Location, Quarry = entity
            });

            await this.DbContext.SaveChangesAsync();
        }
Beispiel #2
0
        public async void QuarryAdd()
        {
            // Arrange
            this.QuarryDbContext.MaterialColours.AddRange(
                new MaterialColourEntity()
            {
                MaterialColourId = 1, ColourName = "White", CompanyId = 1, DeletedInd = false
            },
                new MaterialColourEntity()
            {
                MaterialColourId = 2, ColourName = "Smoky", CompanyId = 1, DeletedInd = false
            });

            await this.SaveChangesAsync(this.QuarryDbContext);

            QuarryModel model = new QuarryModel()
            {
                QuarryId = 0, QuarryName = "QM1", ColourIds = new List <int>()
                {
                    1, 2
                }
            };

            // Act
            AjaxModel <NTModel> ajaxModel = await this.Controller.QuarryAdd(model);

            // Assert
            QuarryEntity quarryEntity = this.QuarryDbContext.Quarries.Last();

            Assert.Equal(quarryEntity.QuarryName, "QM1");

            YardEntity yardEntity = this.QuarryDbContext.Yards.Last();

            Assert.Equal(yardEntity.YardName, "QM1 Yard");

            List <QuarryMaterialColourEntity> quarryColours = this.QuarryDbContext.QuarryMaterialColours.ToList();

            Assert.Equal(quarryColours.Count, 2);
            Assert.Equal(quarryColours[1].MaterialColourId, 2);

            Assert.Equal(ajaxModel.Message, QuarryMessages.QuarrySaveSuccess);
        }
Beispiel #3
0
        public async void QuarryDelete()
        {
            // Arrange
            this.QuarryDbContext.Quarries.AddRange(
                new QuarryEntity()
            {
                QuarryId = 1, QuarryName = "QM1", CompanyId = 1, DeletedInd = false
            },
                new QuarryEntity()
            {
                QuarryId = 2, QuarryName = "QM2", CompanyId = 1, DeletedInd = false
            });

            this.QuarryDbContext.Yards.AddRange(
                new YardEntity()
            {
                YardId = 1, YardName = "QM1 Yard", QuarryId = 1, CompanyId = 1, DeletedInd = false
            },
                new YardEntity()
            {
                YardId = 2, YardName = "QM2 Yard", QuarryId = 2, CompanyId = 1, DeletedInd = false
            });

            await this.SaveChangesAsync(this.QuarryDbContext);

            // Act
            AjaxModel <NTModel> ajaxModel = await this.Controller.QuarryDelete(2);

            // Assert
            QuarryEntity quarryEntity = this.QuarryDbContext.Quarries.Where(e => e.QuarryId == 2).First();

            Assert.Equal(quarryEntity.DeletedInd, true);

            YardEntity yardEntity = this.QuarryDbContext.Yards.Where(e => e.QuarryId == 2).First();

            Assert.Equal(yardEntity.DeletedInd, true);

            Assert.Equal(ajaxModel.Message, QuarryMessages.QuarryDeleteSuccess);
        }
Beispiel #4
0
    // Find quarry
    public override bool checkProceduralPrecondition(GameObject agent)
    {
        Stonecutter stonecutter = (Stonecutter)agent.GetComponent(typeof(Stonecutter));

        if (stonecutter.actualQuarry != null)
        {
            targetQuarry = stonecutter.actualQuarry;
            if (targetQuarry != null)
            {
                target = targetQuarry.gameObject;
            }
        }
        else
        {
            float localRadius = numTry * radius;
            numTry++;
            Collider2D[] colliders       = Physics2D.OverlapCircleAll(agent.transform.position, localRadius);
            Collider2D   closestCollider = null;
            float        closestDist     = 0;

            if (colliders == null)
            {
                return(false);
            }
            foreach (Collider2D hit in colliders)
            {
                if (hit.tag != "Quarry")
                {
                    continue;
                }

                QuarryEntity quarry = (QuarryEntity)hit.gameObject.GetComponent(typeof(QuarryEntity));
                if (quarry.full)
                {
                    continue;
                }
                if (closestCollider == null)
                {
                    closestCollider = hit;
                    closestDist     = (closestCollider.gameObject.transform.position - agent.transform.position).magnitude;
                }
                else
                {
                    float dist = (hit.gameObject.transform.position - agent.transform.position).magnitude;
                    if (dist < closestDist)
                    {
                        // we found a closer one, use it
                        closestCollider = hit;
                        closestDist     = dist;
                    }
                }
                Debug.DrawLine(closestCollider.gameObject.transform.position, agent.transform.position, Color.gray, 3, false);
            }

            bool isClosest = closestCollider != null;
            if (isClosest)
            {
                targetQuarry = (QuarryEntity)closestCollider.gameObject.GetComponent(typeof(QuarryEntity));
                target       = targetQuarry.gameObject;
                numTry       = 1;
            }
        }

        return(targetQuarry != null);
    }
Beispiel #5
0
 public override void reset()
 {
     mined        = false;
     targetQuarry = null;
     startTime    = 0;
 }