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); }
public async Task <int> CreateArenaAsync(ArenaEntity entity) { await _repositoryWrapper.Arena.CreateAsync(entity); await _repositoryWrapper.Arena.SaveAsync(); return(entity.Id); }
public void TakeDamage(int amount, ArenaEntity damager) { HP -= amount; if (HP <= 0) { alive = false; Debug.Log("Killed"); } UpdateVisual(); }
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); } }
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; * } * } * * } */ } }
// 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); } }
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))); }
public async Task UpdateArenaAsync(ArenaEntity entity) { _repositoryWrapper.Arena.Update(entity); await _repositoryWrapper.Arena.SaveAsync(); }
public float BeConsumed(ArenaEntity entity) { Destroy(gameObject); ArenaController.controller.CreateResource(); return(energy); }
public virtual Vector2 VectorTo(ArenaEntity entity) { return(entity.transform.position - transform.position); }
public virtual float Distance(ArenaEntity entity) { return(Vector2.Distance(transform.position, entity.transform.position)); }