コード例 #1
0
    Vector2 CalculateNewDirection()
    {
        Vector2 ret;

        if (neighbours.Length > 0)
        {
            //For each neighbour:
            //how much do we want to get closer to the neighbour?
            Vector2 sum = Vector2.zero;
            for (int i = 0; i < neighbours.Length; i++)
            {
                ArenaEntity e = neighbours[i];
                if (e != null)
                {
                    sum += VectorTo(e) * Assess(e);
                }
            }
            ret = sum;
        }
        else
        {
            //if (threats[0] != null)
            //{
            //    currentDestination = threats[0].transform.position;
            //}
            //else
            //{
            ret = ArenaController.controller.RandomPoint();
            //}
        }
        return(ret.normalized);
    }
コード例 #2
0
        public async Task <int> CreateArenaAsync(ArenaEntity entity)
        {
            await _repositoryWrapper.Arena.CreateAsync(entity);

            await _repositoryWrapper.Arena.SaveAsync();

            return(entity.Id);
        }
コード例 #3
0
 public void TakeDamage(int amount, ArenaEntity damager)
 {
     HP -= amount;
     if (HP <= 0)
     {
         alive = false;
         Debug.Log("Killed");
     }
     UpdateVisual();
 }
コード例 #4
0
 void OnTriggerEnter2D(Collider2D col)
 {
     if (col.tag == "Resource")
     {
         ArenaResource r = col.GetComponent <ArenaResource>();
         Consume(r);
     }
     else if (col.tag == "Navigators")
     {
         ArenaEntity e = col.GetComponent <ArenaEntity>();
         Fight((ArenaNavigator)e);
     }
 }
コード例 #5
0
    void ScanNearbyArea()
    {
        Collider2D[] colliders = Physics2D.OverlapCircleAll(transform.position, perception);

        foreach (Collider2D c in colliders)
        {
            if (c.tag == "Navigators" || c.tag == "Resources" && (c.gameObject != gameObject))
            {
                ArenaEntity entity = c.GetComponent <ArenaEntity>();
                float       value  = Assess(entity);

                for (int i = 0; i < neighbours.Length; i++)
                {
                    if ((neighbours[i] == null || Assess(neighbours[i]) < value) && entity != this)
                    {
                        neighbours[i] = entity;
                        break;
                    }
                }
            }

            /*
             * else if (c.tag == "Resource")
             * {
             *  //work out if we want to go for this resource.
             *  ArenaResource resource = c.GetComponent<ArenaResource>();
             *  float reward = resource.AssessValue();
             *  for (int i = 0; i < rewards.Length; i++)
             *  {
             *      if (rewards[i] == null || rewards[i].AssessValue() < value)
             *      {
             *          rewards[i] = resource;
             *          break;
             *      }
             *  }
             *
             * }
             */
        }
    }
コード例 #6
0
    // Update is called once per frame
    void Update()
    {
        if (Input.GetKeyDown(KeyCode.P))
        {
            pauseSim = !pauseSim;
        }

        foreach (ArenaEntity entity in entities)
        {
            entity.EnableUI(false);
            if (!pauseSim)
            {
                entity.UpdateEntity();
            }
        }
        Collider2D[] colliders = Physics2D.OverlapPointAll(Camera.main.ScreenToWorldPoint(Input.mousePosition));
        foreach (Collider2D c in colliders)
        {
            ArenaEntity entity = c.GetComponent <ArenaEntity>();
            entity.EnableUI(true);
        }
    }
コード例 #7
0
    float Assess(ArenaEntity entity)
    {
        //get value of entity
        float value = entity.Evaluate();

        //So here is where we involve some smarts about how
        //we behave.
        //Attack: if we are on high health
        //Heal: if we are on medium health
        //Low health: look for heals and go AWAY from threats.

        float healthPercent   = HP / (float)hpMax * 100.0f;
        float attackWeighting = 1.0f;
        float healWeighting   = 1.0f;

        if (healthPercent < 50)
        {
            attackWeighting = 0.5f;
        }
        else if (healthPercent < 25)
        {
            attackWeighting = -1.0f;
        }

        if (entity.tag == "Resources")
        {
            value *= healWeighting;
        }
        else if (entity.tag == "Navigators")
        {
            value *= attackWeighting;
        }

        //modulate by distance
        return(value * (1.0f - (Distance(entity) / perception)));
    }
コード例 #8
0
        public async Task UpdateArenaAsync(ArenaEntity entity)
        {
            _repositoryWrapper.Arena.Update(entity);

            await _repositoryWrapper.Arena.SaveAsync();
        }
コード例 #9
0
 public float BeConsumed(ArenaEntity entity)
 {
     Destroy(gameObject);
     ArenaController.controller.CreateResource();
     return(energy);
 }
コード例 #10
0
 public virtual Vector2 VectorTo(ArenaEntity entity)
 {
     return(entity.transform.position - transform.position);
 }
コード例 #11
0
 public virtual float Distance(ArenaEntity entity)
 {
     return(Vector2.Distance(transform.position, entity.transform.position));
 }