public void Init(int troopsCount)
 {
     ClearExistingData();
     Target = new TargetComponent();
     CreateFormation(troopsCount);
     InstantiateTroops(troopsCount);
 }
        public void Execute(Entity entity, int index, ref Translation translation, [ReadOnly] ref TeamComponent team)
        {
            var f                = (noise.snoise(translation.Value) + 1.0f) * 0.5f;
            var randomIndex      = (int)math.round(f * TargetableEntities.Length);
            var targetableEntity = TargetableEntities[randomIndex];

            var validTarget = false;

            if (TeamsForEntity.Exists(targetableEntity))
            {
                validTarget = TeamsForEntity[targetableEntity].Value != team.Value;
            }
            else
            {
                validTarget = true;
            }

            if (validTarget)
            {
                Buffer.AddComponent <TargetComponent>(index, entity);
                var target = new TargetComponent();
                target.Value = targetableEntity;
                Buffer.SetComponent(index, entity, target);
            }
        }
Exemple #3
0
    void Update()
    {
        _target = GetComponent <TargetComponent>();

        if (_target == null)
        {
            var targetsArray = FindObjectsOfType <HPComponent>();
            foreach (HPComponent target in targetsArray)
            {
                if (target.gameObject == gameObject)
                {
                    continue;
                }
                if (target.gameObject.GetComponent <OwnerComponent>().Player == _side)
                {
                    continue;
                }
                _testDist = Vector3.Distance(target.gameObject.transform.position, gameObject.transform.position);
                if (_testDist <= AttackRange)
                {
                    var targetComponent = gameObject.AddComponent <TargetComponent>();
                    targetComponent.TargetObject = target.gameObject;
                }
            }
        }
        else
        {
            Debug.DrawLine(_target.gameObject.transform.position, gameObject.transform.position, Color.magenta);
        }
    }
 public EnemiesGroup(List <EnemyCreature> _enemies, Vector2 position)
 {
     enemies         = _enemies;
     Target          = new TargetComponent();
     Target.Position = position;
     formation       = new HordeFormation(enemies.Count);
     formation.CalculatePosition(position);
 }
        public override void BindToEntity(Entity source)
        {
            base.BindToEntity(source);
            cTarget = source.GetComponent <TargetComponent>();

            // Initialise values based on current orientation
            Quaternion q = CRotation.Orientation;

            currentYaw   = (float)Math.Asin(2 * q.X * q.Y + 2 * q.Z * q.W);
            currentPitch = -(float)Math.Atan2(2 * q.X * q.W - 2 * q.Y * q.Z, 1 - 2 * q.X * q.X - 2 * q.Z * q.Z);
        }
Exemple #6
0
        private void WriteCodeToComponent(object sender, GH_SolutionEventArgs e)
        {
            if (!ShouldContinue())
            {
                return;
            }
            if (!(sender is GH_Document doc))
            {
                return;
            }

            doc.SolutionEnd -= WriteCodeToComponent;
            WriteScriptToComponent(TargetComponent, FileNameSafe);
            TargetComponent.ExpireSolution(true);
            IsBusy = false;
        }
Exemple #7
0
        public void OnFileChanged(Object sender, FileSystemEventArgs e)
        {
            if (IsBusy)
            {
                return;
            }
            IsBusy = true;
            try
            {
                if (!ShouldContinue())
                {
                    Cleanup();
                    return;
                }

                // Visual studio will rename a file to a temp file,
                // Then write new contents to the original file
                // So here we check if a file that stopped existing, starts existing again..
                if (!File.Exists(FileNameSafe))
                {
                    Thread.Sleep(200);
                    if (!File.Exists(FileNameSafe))
                    {
                        Cleanup();
                        return;
                    }
                }

                // Modify the script at the end of the solution, rather than now
                // so we know for sure that nothing is in the middle of a
                // solution, and could botch up things.
                OnPingDocument().SolutionEnd += WriteCodeToComponent;

                OnPingDocument().ScheduleSolution(10, doc =>
                {
                    // expire the script in the next solution, so it will recompute.
                    TargetComponent.ExpireSolution(false);
                });
            }
            catch (Exception exp)
            {
                RhinoApp.WriteLine($"Error in filehandler:{exp.Message}\\n{exp.StackTrace}");
            }
        }
Exemple #8
0
    public override void Update(float deltaTime, uint tick)
    {
        //Run through our system logic here
        //Note, we do this for every entity
        for (int i = 0; i < _targetComponentArray.Length; i++)
        {
            //First, we need to make sure we're dealing with an active entity
            if (!_entityManager.IsEntityActive(i))
            {
                return;
            }

            if (!_targetComponentArray[i].IsActive)
            {
                //This entity does not have a target. Let's fix that

                //Lets assess potential targets
                //For now, this means looping through entities by team id and picking one that isn't our team

                _potentialTargetList.Clear();

                for (int t = 0; t < _teamComponentArray.Length; t++)
                {
                    //Skip ourselves ;) && Skip any entity that isn't active
                    if (t != i && _entityManager.IsEntityActive(t) && _teamComponentArray[i] != _teamComponentArray[t])
                    {
                        _potentialTargetList.Add(t);
                    }
                }

                //Now we should ideally have a magical list of potential targets. Let's pick one from that list
                if (_potentialTargetList.Count > 0)
                {
                    int targetIndex = _randomSystem.GetNext(0, _potentialTargetList.Count - 1);

                    ref TargetComponent targetComponent = ref _entityManager.AddComponentToEntity <TargetComponent>(i);
                    targetComponent.TargetId           = _potentialTargetList[targetIndex];
                    targetComponent.TargetAcquiredTick = tick;

                    _logger.Log(string.Format("Entity {0} found target Entity {1}. Acquired at tick {2}", i, _potentialTargetList[targetIndex], tick));
                }
            }
        }
Exemple #9
0
 public Unit(HealthComponent health, AttackComponent attack, MovementComponent movement, TargetComponent target, AiComponent ai,
             StatsComponent stats)
 {
     this.health   = health;
     this.attack   = attack;
     this.movement = movement;
     this.target   = target;
     this.ai       = ai;
     this.stats    = stats;
 }
Exemple #10
0
 private void OnDisable()
 {
     TargetComponent.DeregisterComponentUpdate(Targetting);
 }
Exemple #11
0
 private void OnEnable()
 {
     TargetComponent.RegisterComponentUpdate(Targetting);
 }
Exemple #12
0
        private void RegisterToTarget(ChangeColorOnTargetComponent self, TargetComponent target)
        {
            var renderer = self.GetComponent <Renderer>();

            renderer.material.color = Color.blue;
        }
Exemple #13
0
 /// <summary>
 /// Check for unhealthy situations where we would not like to continue
 /// If the component is locked, or the solution is locked
 /// </summary>
 /// <returns></returns>
 protected override bool ShouldContinue()
 {
     return(base.ShouldContinue() &&
            TargetComponent != null &&
            TargetComponent.OnPingDocument() == OnPingDocument());
 }
Exemple #14
0
    public Mesh ToUnityMesh(string meshName, TargetComponent target)
    {
        Mesh mesh = new Mesh();

        mesh.name         = meshName;
        mesh.subMeshCount = 3;

        List <WTriangle> allTriangles = new List <WTriangle>(bodyTris);

        if (capTris != null)
        {
            allTriangles.AddRange(capTris);
        }


        // 1. Set All Vertices
        int vertCount = allTriangles.Count * 3;

        Vector3[] vertices = new Vector3[vertCount];
        int       vertIdx  = 0;

        for (int i = 0; i < allTriangles.Count; i++)
        {
            WTriangle tri = allTriangles[i];
            vertices[vertIdx]     = tri.a;
            vertices[vertIdx + 1] = tri.b;
            vertices[vertIdx + 2] = tri.c;

            vertIdx += 3;
        }

        mesh.vertices = vertices;


        // 2. Set Body Triangle : Submesh 0
        int bodyArrLen = bodyTris.Count * 3;

        int[] bodyArr = new int[bodyArrLen];

        for (int i = 0; i < bodyArrLen; i += 3)
        {
            bodyArr[i]     = i;
            bodyArr[i + 1] = i + 1;
            bodyArr[i + 2] = i + 2;
        }

        mesh.SetTriangles(bodyArr, 0);

        // 3. Set Cap Triangle : Submesh 1
        int capStartIdx = bodyArrLen;

        int capArrLen = capTris.Count * 3;

        capArr = new int[capArrLen];

        for (int i = 0; i < capArr.Length; i += 3)
        {
            capArr[i]     = capStartIdx + i;
            capArr[i + 1] = capStartIdx + i + 1;
            capArr[i + 2] = capStartIdx + i + 2;
        }


        mesh.SetTriangles(capArr, 1);

        // 4. Finish
        mesh.RecalculateNormals();
        mesh.RecalculateBounds();

        return(mesh);
    }
 // Use this for initialization
 void Start()
 {
     target   = GameObject.FindObjectOfType <TargetComponent> ();
     fadeAnim = GetComponentInChildren <Animator> ();
     target.onTargetReached.AddListener(onTargetReached);
 }