public void TryReadStructure_WithStructureToFindStructuresEmpty_LogsErrorReturnsFalse()
        {
            // Setup
            string filePath = Path.Combine(readerPath, "validConfiguration.xml");

            var calculationGroup = new CalculationGroup();

            var importer = new CalculationConfigurationImporter(filePath, calculationGroup);

            StructureBase structure = null;
            var valid = true;

            const string structureId = "someAwesomeId";
            const string calculationName = "name";

            // Call
            void Validate() => valid = importer.PublicTryReadStructure(
                                   structureId, calculationName, Enumerable.Empty<StructureBase>(), out structure);

            // Assert
            var expectedMessage = $"Het kunstwerk met ID '{structureId}' bestaat niet. Berekening '{calculationName}' is overgeslagen.";
            TestHelper.AssertLogMessageWithLevelIsGenerated(Validate, Tuple.Create(expectedMessage, LogLevelConstant.Error));
            Assert.IsFalse(valid);
            Assert.IsNull(structure);
        }
예제 #2
0
        private ResolverInfo ToArgumentInfo([NotNull] StructureBase argument)
        {
            var attribute = argument.GetType().GetCustomAttribute <ResolverAttribute>() !;

            return(new ResolverInfo
            {
                Instance = argument,
                Method = argument.GetType().GetMethod("ResolveAsync") !,
                Type = attribute.Type,
                DisplayName = attribute.DisplayName
            });
예제 #3
0
    public void AttackUpdate()
    {
        //Attack Enemy
        EnemyBase closestEnemy    = null;
        float     closestDistance = float.MaxValue;

        foreach (EnemyBase enemy in enemiesInRange)
        {
            if (Vector3.Distance(enemy.collider.bounds.center, collider.bounds.center) < closestDistance)
            {
                closestEnemy = enemy;
            }
        }
        if (closestEnemy != null)
        {
            attackTimer += Time.deltaTime;
            if (attackTimer >= rateOfAttack)
            {
                attackTimer = 0;
                GameManager.Instance.SpawnProjectile(bulletType, collider.bounds.center, closestEnemy.view.ViewID, damage, bulletSpeed, faction);
            }
            return;
        }

        //Attack Structure

        StructureBase closestStructure = null;

        closestDistance = float.MaxValue;
        foreach (StructureBase structure in structuresInRange)
        {
            if (Vector3.Distance(structure.collider.bounds.center, collider.bounds.center) < closestDistance)
            {
                closestStructure = structure;
            }
        }
        if (closestStructure != null)
        {
            attackTimer += Time.deltaTime;
            if (attackTimer >= rateOfAttack)
            {
                attackTimer = 0;
                GameManager.Instance.SpawnProjectile(bulletType, collider.bounds.center, closestStructure.view.ViewID, damage, bulletSpeed, faction);
            }
            return;
        }
    }
예제 #4
0
        protected IEnumerator InstanceMeshes(
            StructureTemplateGroup structureGroup,
            string childName,
            List <Renderer> renderers,
            List <Renderer> lodRenderers,
            float lodRatio)
        {
            renderers.Clear();
            if (lodRenderers != null)
            {
                lodRenderers.Clear();
            }

            StructurePiece        = StructureBase.CreateChild(childName);
            StructurePiece.parent = null;
            if (Mode == BuilderMode.Minor)
            {
                //minor structures have to set their own offsets
                StructurePiece.position = MinorParent.Position;
                StructurePiece.rotation = Quaternion.Euler(MinorParent.Rotation);
            }
            else
            {
                StructurePiece.ResetLocal();
            }
            StructurePiece.gameObject.layer = Globals.LayerNumSolidTerrain;            //TODO this may be unnecessary
            for (int i = 0; i < structureGroup.StaticStructureLayers.Count; i++)
            {
                StructureTemplate.InstantiateStructureLayer(structureGroup.StaticStructureLayers [i], StructurePiece);
            }

            StructurePiece.parent = StructureBase.transform;
            if (Mode == BuilderMode.Minor)
            {
                StructurePiece.localPosition = MinorParent.Position;
                StructurePiece.localRotation = Quaternion.Euler(MinorParent.Rotation);
            }
            else
            {
                StructurePiece.ResetLocal();
            }
            yield break;
        }
        /// <summary>
        /// Determines if the structure of a calculation is intersecting with the section reference line.
        /// </summary>
        /// <param name="calculationScenario">The calculation scenario containing the structure.</param>
        /// <param name="lineSegments">The line segments that define the reference line.</param>
        /// <returns><c>true</c> when intersecting. <c>false</c> otherwise.</returns>
        /// <exception cref="ArgumentNullException">Thrown when any parameter is <c>null</c>.</exception>
        /// <exception cref="InvalidOperationException">Thrown when <paramref name="lineSegments"/> contains no elements.</exception>
        public static bool IsStructureIntersectionWithReferenceLineInSection <TStructuresInput>(this StructuresCalculationScenario <TStructuresInput> calculationScenario,
                                                                                                IEnumerable <Segment2D> lineSegments)
            where TStructuresInput : IStructuresCalculationInput <StructureBase>, new()
        {
            if (calculationScenario == null)
            {
                throw new ArgumentNullException(nameof(calculationScenario));
            }

            if (lineSegments == null)
            {
                throw new ArgumentNullException(nameof(lineSegments));
            }

            StructureBase structure = calculationScenario.InputParameters.Structure;

            if (structure == null)
            {
                return(false);
            }

            return(lineSegments.Min(segment => segment.GetEuclideanDistanceToPoint(structure.Location)) <= 1);
        }
 public bool PublicTryReadStructure(string locationName, string calculationName, IEnumerable<StructureBase> structures, out StructureBase location)
 {
     return TryReadStructure(locationName, calculationName, structures, out location);
 }
예제 #7
0
    void DetectEnemiesInViewRange()
    {
        foreach (Transform child in transform.parent)
        {
            EnemyBase enemy = child.gameObject.GetComponent <EnemyBase>();
            if (!enemy)
            {
                continue;
            }
            if (child == transform)
            {
                continue;
            }
            if (enemy.faction == faction)
            {
                continue;
            }
            Vector3 enemyPos = enemy.collider.bounds.center;
            enemyPos.y = 0;
            Vector3 myPos = collider.bounds.center;
            myPos.y = 0;
            if (Vector3.Distance(enemyPos, myPos) <= (attackRange / 100) * GridGenerator.Instance.singleGridSize)
            {
                RaycastHit hitInfo;
                Physics.Linecast(collider.bounds.center, enemy.collider.bounds.center, out hitInfo);

                if (hitInfo.transform == enemy.transform && enemiesInRange.Exists(increment => increment == enemy) == false)
                {
                    enemiesInRange.Add(enemy);
                }
            }
            else
            {
                enemiesInRange.Remove(enemy);
            }

            if (Vector3.Distance(enemyPos, myPos) <= (vision / 100) * GridGenerator.Instance.singleGridSize)
            {
                if (enemy.enemiesThatCanSeeYou.Exists(increment => increment == this) == false)
                {
                    enemy.enemiesThatCanSeeYou.Add(this);
                }
            }
            else
            {
                enemy.enemiesThatCanSeeYou.Remove(this);
            }
        }

        // Handle seeing enemy's structures when in range
        foreach (Transform child in GameObject.Find("Environment").transform.Find("Structures"))
        {
            StructureBase building = child.gameObject.GetComponent <StructureBase>();

            if (!building)
            {
                continue;
            }
            if (building.faction == faction)
            {
                continue;
            }

            Vector3 buildingPos = building.collider.bounds.center;
            buildingPos.y = 0;
            Vector3 myPos = collider.bounds.center;
            myPos.y = 0;
            if (Vector3.Distance(buildingPos, myPos) <= (attackRange / 100) * GridGenerator.Instance.singleGridSize)
            {
                RaycastHit hitInfo;
                Physics.Linecast(collider.bounds.center, building.collider.bounds.center, out hitInfo);
                if (hitInfo.transform == building.transform && structuresInRange.Exists(increment => increment == building) == false)
                {
                    structuresInRange.Add(building);
                }
            }
            else
            {
                structuresInRange.Remove(building);
            }

            if (Vector3.Distance(building.collider.bounds.center, collider.bounds.center) <= (vision / 100) * GridGenerator.Instance.singleGridSize)
            {
                if (building.enemiesThatCanSeeYou.Exists(increment => increment == this) == false)
                {
                    building.enemiesThatCanSeeYou.Add(this);
                }
            }
            else
            {
                building.enemiesThatCanSeeYou.Remove(this);
            }
        }
    }
예제 #8
0
    void AttackUpdate()
    {
        closestEnemy     = null;
        closestStructure = null;
        bool       targetEntityInRange = false;
        RaycastHit hitInfo;

        if (targetEntity != null)
        {
            Physics.Linecast(collider.bounds.center, targetEntity.collider.bounds.center, out hitInfo);
            if (hitInfo.transform == targetEntity.transform && Vector3.Distance(targetEntity.collider.bounds.center, collider.bounds.center) <= (attackRange / 100) * GridGenerator.Instance.singleGridSize)
            {
                targetEntityInRange = true;
                Debug.Log("Target Enemy In Range!");
            }
            else
            {
                agent.isStopped = false;
                agent.SetDestination(targetEntity.transform.position);
                agent.speed = movement / 100;
                isAttacking = false;
                Debug.Log("Target Enemy Not In Range!");
            }
        }
        if (isAttacking)
        {
            if (closestEnemy == null && closestStructure == null && targetEntityInRange == false)
            {
                isAttacking = false;
                agent.speed = movement / 100;
            }
        }

        if (strategy != STRATEGY.ATTACK)
        {
            return;
        }

        if (targetEntityInRange == true)
        {
            isAttacking = true;
            agent.speed = 0;

            attackTimer += Time.deltaTime;
            if (attackTimer >= rateOfAttack)
            {
                attackTimer = 0;
                //DamageEnemy(closestEnemy);
                GameManager.Instance.SpawnProjectile(bulletType, collider.bounds.center, targetEntity.view.ViewID, damage, bulletSpeed, faction);
            }
            return;
        }

        //Attack Enemy

        float closestDistance = float.MaxValue;

        foreach (EnemyBase enemy in enemiesInRange)
        {
            if (Vector3.Distance(enemy.collider.bounds.center, collider.bounds.center) < closestDistance)
            {
                closestEnemy = enemy;
            }
        }
        if (closestEnemy != null)
        {
            isAttacking = true;
            agent.speed = 0;

            attackTimer += Time.deltaTime;
            if (attackTimer >= rateOfAttack)
            {
                attackTimer = 0;
                //DamageEnemy(closestEnemy);
                GameManager.Instance.SpawnProjectile(bulletType, collider.bounds.center, closestEnemy.view.ViewID, damage, bulletSpeed, faction);
            }
            return;
        }

        //Attack Structure

        closestDistance = float.MaxValue;
        foreach (StructureBase structure in structuresInRange)
        {
            if (Vector3.Distance(structure.collider.bounds.center, collider.bounds.center) < closestDistance)
            {
                closestStructure = structure;
            }
        }
        if (closestStructure != null)
        {
            isAttacking = true;
            //agent.isStopped = true;

            attackTimer += Time.deltaTime;
            if (attackTimer >= rateOfAttack)
            {
                attackTimer = 0;
                //DamageStructure(closestStructure);
                GameManager.Instance.SpawnProjectile(bulletType, collider.bounds.center, closestStructure.view.ViewID, damage, bulletSpeed, faction);
            }
            return;
        }
    }