public void ComputeInfluenceBFS(AgentUnit unit, Vector2[,] influenceMap, UnitT targetType = UnitT.MELEE, bool considerUnit = false) { HashSet <Node> pending = new HashSet <Node>(); HashSet <Node> visited = new HashSet <Node>(); Node vert = Map.NodeFromPosition(unit.position); pending.Add(vert); // BFS for assigning influence for (int i = 1; i <= RadiusInfluenceMap; i++) { HashSet <Node> frontier = new HashSet <Node>(); foreach (Node p in pending) { if (visited.Contains(p)) { continue; } visited.Add(p); if (!considerUnit) { p.SetInfluence(unit.faction, unit.GetDropOff(1 + Util.HorizontalDist(p.worldPosition, unit.position)), influenceMap, InfluenceT.MAXIMUM); } else { float atkFactor = AgentUnit.atkTable[(int)unit.GetUnitType(), (int)targetType]; p.SetInfluence(unit.faction, atkFactor * unit.GetDropOff(1 + Util.HorizontalDist(p.worldPosition, unit.position)), influenceMap, InfluenceT.MAXIMUM); } frontier.UnionWith(Map.GetDirectNeighbours(p)); } pending = new HashSet <Node>(frontier); } }
public void Attack(AgentUnit unit) { float damage; if (Random.Range(0, 100) > 99f) { damage = attack * 5; } else { damage = attack * Random.Range(0.8f, 1.2f) * AgentUnit.atkTable[(int)agent.GetUnitType(), (int)unit.GetUnitType()]; } if (Map.projectile != null) { var newProjectile = GameObject.Instantiate(Map.projectile); newProjectile.transform.position = agent.position; newProjectile.GetComponent <Projectile>().SetTarget(unit); } else { Debug.Log("Falta el prefab del projectil para atacar"); } unit.militar.ReceiveAttack(agent, (int)Mathf.Round(damage)); }