/// <summary> /// Creates a new agent commander with the given parameters. /// </summary> /// <param name="teamID">Identifies how this commander interacts with other units.</param> /// <param name="grid">The grid that this commander will be placed on.</param> /// <param name="damageTable">Drives the AI behaviour of this agent.</param> /// <param name="controller">The cursor controller that this agent drives.</param> public AgentCommander(byte teamID, TileGrid grid, DamageTable damageTable, AgentCursorController controller) : base(teamID, grid, controller) { this.damageTable = damageTable; agentCursor = controller; thoughtTimer = new Timer(); }
/// <summary> /// Retrieves the unwrapped agent commander from the scene. /// </summary> /// <returns>The tile grid instance (with no notion of monobehaviour).</returns> public AgentCommander GetInstance(TileGrid grid, DamageTable damageTable) { // Create the new commander and add it to the grid. AgentCommander commander = new AgentCommander(teamID, grid, damageTable, controller.GetInstance(grid)) { ThoughtTime = thoughtTime }; grid.Commanders.Add(commander); // Destroy this script's Monobehaviour baggage, // and return the lightweight instance. Destroy(this); return(commander); }
private void Awake() { IDesignerParser parser = new UnitySceneParser(); grid = parser.GetFirstTileGrid(); damageTable = parser.GetFirstDamageTable(); parser.GetAllPreplacedActors(grid); Commander[] commanders = parser.GetAllPreplacedCommanders(grid, damageTable); FindObjectOfType <CommanderPanelManager>().InitializeCommanders(commanders); StartCoroutine(WaitInitThenStart()); }
public Commander[] GetAllPreplacedCommanders(TileGrid onGrid, DamageTable damageTable) { List <Commander> foundCommanders = new List <Commander>(); foreach (AgentCommanderInstance agentCommander in Object.FindObjectsOfType <AgentCommanderInstance>()) { foundCommanders.Add(agentCommander.GetInstance(onGrid, damageTable)); } foreach (PlayerCommanderInstance playerCommander in Object.FindObjectsOfType <PlayerCommanderInstance>()) { foundCommanders.Add(playerCommander.GetInstance(onGrid)); } return(foundCommanders.ToArray()); }
public static int GetFinalDamage(Unit a, Unit b, bool useRandom) { float h = a.health / 100f; // int d = a.damage; // float p = a.pen; // if (b.grouping == a.bonusCondition) // { // d += a.bonusDamage; // p += a.bonusPen; // } // float arm = Math.Max(b.armor - p, 0); float defenseBonus = GetDefenseBonus(b); float t = (100 - (defenseBonus * b.health / 10f)) / 100f; float r = (useRandom) ? UnityEngine.Random.Range(-2f, 2f) : 0; // return (int)Math.Round(r + h * (d / Math.Pow(2, b.armor / Math.Pow(2, p)))); return(Math.Max((int)Math.Round(r + t * h * (DamageTable.GetBaseDamage(a.type, b.type))), 1)); }
float CalculateDamage(float dmg, int dmgType) { if (subClass == _UnitSubClass.Tower) { float damage = dmg * DamageTable.GetModifier(armorType, dmgType); damage *= Mathf.Clamp(1 - (PerkManager.allTowerDefBuffModifier + dmgReducMod), 0, 1); damage = Mathf.Max(0, damage -= (PerkManager.allTowerDefBuffValue + dmgReducVal)); return(damage); } else { float damage = dmg * DamageTable.GetModifier(armorType, dmgType); damage *= Mathf.Clamp(1 + (dmgReducMod), 0, 1); damage = Mathf.Max(0, damage += (dmgReducVal)); return(damage); //~ return dmg*DamageTable.GetModifier(armorType, dmgType); } }
void DrawHoverInfo() { UnitTB selectedUnit = UnitControl.selectedUnit; #if hoverHP if (tileHovered.unit != null) { //draw hp and AP for unit UnitTB hUnit = tileHovered.unit; Camera camA = CameraControl.GetActiveCamera(); Vector3 screenPosA = camA.WorldToScreenPoint(hUnit.thisT.position); screenPosA.y = Screen.height - screenPosA.y; int startPosX = (int)(screenPosA.x - 40 / 2 + 7); int startPosY = (int)screenPosA.y + 5; styleA.fontSize = 20; styleA.normal.textColor = UI.colorH; styleA.alignment = TextAnchor.UpperCenter; GUI.Box(new Rect(startPosX - x_offset - 25, startPosY + y_offset, 140, 140), ""); GUI.Label(new Rect(startPosX - x_offset - 25, startPosY + y_offset, 140, 140), "\n HP:" + hUnit.HP + "/" + hUnit.GetFullHP() + "\n AP:" + hUnit.AP + "/" + hUnit.GetFullAP() + "\n Moves:" + hUnit.moveRemain + "\n Attacks:" + hUnit.attackRemain, styleA); } #endif if (tileHovered.attackableToSelected) { UnitTB unit = tileHovered.unit; int dmgMin = 0, dmgMax = 0; string hit = "", crit = ""; int dist = GridManager.Distance(tileHovered, selectedUnit.occupiedTile); int armorType = unit.armorType; int damageType = selectedUnit.damageType; float dmgModifier = DamageTable.GetModifier(armorType, damageType); if (dist == 1 && selectedUnit.attackMode != _AttackMode.Range) { dmgMin = (int)((float)selectedUnit.GetMeleeDamageMin() * dmgModifier); dmgMax = (int)((float)selectedUnit.GetMeleeDamageMax() * dmgModifier); hit = (selectedUnit.GetTotalHitChanceMelee(unit) * 100).ToString("f0") + "%"; crit = (selectedUnit.GetTotalCritChanceMelee(unit) * 100).ToString("f0") + "%"; } else { dmgMin = (int)((float)selectedUnit.GetRangeDamageMin() * dmgModifier); dmgMax = (int)((float)selectedUnit.GetRangeDamageMax() * dmgModifier); hit = (selectedUnit.GetTotalHitChanceRange(unit) * 100).ToString("f0") + "%"; crit = (selectedUnit.GetTotalCritChanceRange(unit) * 100).ToString("f0") + "%"; } string text = ""; text += hit + "chance to hit\n"; text += "Damage: " + dmgMin + "-" + dmgMax + "\n\n"; if (crit != "0%") { text += "Critical Chance: " + crit; } bool counter = false; if (GameControlTB.IsCounterAttackEnabled()) { if (dist >= unit.GetAttackRangeMin() && dist <= unit.GetAttackRangeMax() && unit.counterAttackRemain > 0) { counter = true; } } int cost = 0; if (GameControlTB.AttackAPCostRule() == _AttackAPCostRule.PerAttack) { cost = selectedUnit.APCostAttack; } GUIStyle style = new GUIStyle(); style.fontStyle = FontStyle.Bold; #if mousePos int width = 500; int w_offset = 50; int height = 160; int h_offset = 20; //get pos X and Y once every second to prevent flicker getMousePos(); /*for(int i=0; i<3; i++) GUI.Box(new Rect(posX-(width+w_offset)/2, posY-230, width+w_offset, height), ""); * * style.fontSize=20; style.normal.textColor=UI.colorH; style.alignment=TextAnchor.UpperCenter; * GUI.Label(new Rect(posX-width/2, posY-240, width, height), ability.name, style); * * style.fontSize=16; style.normal.textColor=UI.colorH; style.alignment=TextAnchor.UpperRight; * GUI.Label(new Rect(posX-width/2-5, posY-240, width, height), ability.cost+"AP", style); * * style.fontSize=16; style.normal.textColor=UI.colorN; style.alignment=TextAnchor.UpperCenter; style.wordWrap=true; * GUI.Label(new Rect(posX-width/2, posY-190, width, height), ability.desp, style); * * GUI.color=Color.white;*/ //for(int i=0; i<3; i++) GUI.Box(new Rect(posX-(width +w_offset)/2, posY, width+w_offset, height), ""); GUI.Box(new Rect(posX - (width / 2) / 2, Screen.height - posY + 40, width / 2, height - 20), ""); // to remove flicker comment out this line style.fontSize = 20; style.normal.textColor = UI.colorH; style.alignment = TextAnchor.UpperCenter; GUI.Label(new Rect(posX - (width) / 2, Screen.height - posY + 40 + h_offset, width, height), "Attack", style); if (cost > 0) { style.fontSize = 16; style.normal.textColor = UI.colorH; style.alignment = TextAnchor.UpperRight; GUI.Label(new Rect(posX - width / 2 - 5, Screen.height - posY + 50 + h_offset, width, height), cost + "AP", style); } //reposition to be at location of mouse style.fontSize = 16; style.normal.textColor = UI.colorN; style.alignment = TextAnchor.UpperCenter; style.wordWrap = true; GUI.Label(new Rect(posX - width / 2, Screen.height - posY + 60 + h_offset, width, height), text, style); if (counter) { style.fontSize = 14; style.normal.textColor = UI.colorH; style.wordWrap = false; GUI.Label(new Rect(posX - width / 2, Screen.height - posY + 40 + h_offset, width, height), "Target will counter attack", style); } #else int width = 500; int height = 160; for (int i = 0; i < 3; i++) { GUI.Box(new Rect(Screen.width / 2 - width / 2, Screen.height - 230, width, height), ""); } style.fontSize = 20; style.normal.textColor = UI.colorH; style.alignment = TextAnchor.UpperCenter; GUI.Label(new Rect(Screen.width / 2 - width / 2, Screen.height - 240, width, height), "Attack", style); if (cost > 0) { style.fontSize = 16; style.normal.textColor = UI.colorH; style.alignment = TextAnchor.UpperRight; GUI.Label(new Rect(Screen.width / 2 - width / 2 - 5, Screen.height - 220, width, height), cost + "AP", style); } //reposition to be at location of mouse style.fontSize = 16; style.normal.textColor = UI.colorN; style.alignment = TextAnchor.UpperCenter; style.wordWrap = true; GUI.Label(new Rect(Screen.width / 2 - width / 2, Screen.height - 190, width, height), text, style); if (counter) { style.fontSize = 14; style.normal.textColor = UI.colorH; style.wordWrap = false; GUI.Label(new Rect(Screen.width / 2 - width / 2, Screen.height - 120, width, height), "Target will counter attack", style); } #endif GUI.color = Color.white; } else { if (tileHovered.walkableToSelected && selectedUnit != null) { //Vector3 screenPos = cam.WorldToScreenPoint(tileHovered.pos); //hoverObject.transform.localPosition=screenPos+new Vector3(-40, 40, 0); List <Vector3> list = AStar.SearchWalkablePos(tileHovered, selectedUnit.occupiedTile); int dist = list.Count; string text = "Move: " + (dist * selectedUnit.APCostMove) + "AP"; //string text="Move: "+Random.Range(0, 9999)+"AP"; GUIContent cont = new GUIContent(text); GUI.color = Color.white; GUIStyle style = new GUIStyle(); style.fontStyle = FontStyle.Bold; style.fontSize = 16; style.normal.textColor = UI.colorN; style.alignment = TextAnchor.LowerRight; Camera cam = CameraControl.GetActiveCamera(); Vector3 screenPos = cam.WorldToScreenPoint(tileHovered.pos); screenPos.y = Screen.height - screenPos.y; float widthMin = 0; float widthMax = 0; style.CalcMinMaxWidth(cont, out widthMin, out widthMax); #if ibox #else GUI.Box(new Rect(screenPos.x - widthMax - 50, screenPos.y - 50, widthMax + 25, 22), ""); GUI.Label(new Rect(screenPos.x - widthMax - 50, screenPos.y - 50, widthMax + 25 - 4, 20), text, style); #endif } } }
/// <summary> ///Clear the damage table of all data. /// </summary> public void ClearDamageTable() { DamageTable.Reset(); }
/// <summary> /// Update the damage_table for this stand /// </summary> /// <param name="siteCounts"> /// The number of cohorts cut for each species at the site that was /// just harvested. /// </param> public void UpdateDamageTable(CohortCounts siteCounts) { DamageTable.IncrementCounts(siteCounts); }
private void Start() { TileGrid grid = gridInstance.GetInstance(); DamageTable table = damageTable.GetInstance(); phase.grid = grid; phase.damageTable = table; phase.Completed += () => { Debug.Log("Phase Complete"); }; switch (test) { case TestType.NonIntersectingMovement: TestNonIntersecting(); break; case TestType.EqualConfrontation: TestEqualConfrontation(); break; case TestType.EqualConfrontationThreeTeam: TestThreeTeam(); break; case TestType.FavoredConfrontation: TestFavored(); break; case TestType.HitPointAdvantage: TestHitPointAdvantage(); break; case TestType.UnitDefeated: TestUnitDefeated(); break; } phase.Begin(); void TestNonIntersecting() { CombatUnit soldierA = Instantiate(infantryPrefab).GetComponent <CombatUnitInstance>().GetInstance(grid); soldierA.Location = new Vector2Int(1, 1); soldierA.TeamID = 0; LinkedList <Vector2Int> soldierAPath = new LinkedList <Vector2Int>(); soldierAPath.AddLast(new Vector2Int(1, 1)); soldierAPath.AddLast(new Vector2Int(1, 2)); soldierAPath.AddLast(new Vector2Int(2, 2)); soldierAPath.AddLast(new Vector2Int(2, 3)); soldierAPath.AddLast(new Vector2Int(2, 4)); soldierA.MovePath = soldierAPath; CombatUnit soldierB = Instantiate(infantryPrefab).GetComponent <CombatUnitInstance>().GetInstance(grid); soldierB.Location = new Vector2Int(3, 4); soldierB.TeamID = 1; LinkedList <Vector2Int> soldierBPath = new LinkedList <Vector2Int>(); soldierBPath.AddLast(new Vector2Int(3, 4)); soldierBPath.AddLast(new Vector2Int(3, 3)); soldierBPath.AddLast(new Vector2Int(3, 2)); soldierBPath.AddLast(new Vector2Int(3, 1)); soldierB.MovePath = soldierBPath; } void TestEqualConfrontation() { CombatUnit soldierA = Instantiate(infantryPrefab).GetComponent <CombatUnitInstance>().GetInstance(grid); soldierA.Location = new Vector2Int(3, 1); soldierA.TeamID = 0; LinkedList <Vector2Int> soldierAPath = new LinkedList <Vector2Int>(); soldierAPath.AddLast(new Vector2Int(3, 1)); soldierAPath.AddLast(new Vector2Int(3, 2)); soldierAPath.AddLast(new Vector2Int(3, 3)); soldierAPath.AddLast(new Vector2Int(3, 4)); soldierA.MovePath = soldierAPath; CombatUnit soldierB = Instantiate(infantryPrefab).GetComponent <CombatUnitInstance>().GetInstance(grid); soldierB.Location = new Vector2Int(3, 5); soldierB.TeamID = 1; LinkedList <Vector2Int> soldierBPath = new LinkedList <Vector2Int>(); soldierBPath.AddLast(new Vector2Int(3, 5)); soldierBPath.AddLast(new Vector2Int(3, 4)); soldierBPath.AddLast(new Vector2Int(3, 3)); soldierBPath.AddLast(new Vector2Int(3, 2)); soldierB.MovePath = soldierBPath; } void TestHitPointAdvantage() { CombatUnit soldierA = Instantiate(infantryPrefab).GetComponent <CombatUnitInstance>().GetInstance(grid); soldierA.Location = new Vector2Int(3, 1); soldierA.TeamID = 0; LinkedList <Vector2Int> soldierAPath = new LinkedList <Vector2Int>(); soldierAPath.AddLast(new Vector2Int(3, 1)); soldierAPath.AddLast(new Vector2Int(3, 2)); soldierAPath.AddLast(new Vector2Int(3, 3)); soldierAPath.AddLast(new Vector2Int(3, 4)); soldierA.MovePath = soldierAPath; CombatUnit soldierB = Instantiate(infantryPrefab).GetComponent <CombatUnitInstance>().GetInstance(grid); soldierB.Location = new Vector2Int(3, 5); soldierB.TeamID = 1; LinkedList <Vector2Int> soldierBPath = new LinkedList <Vector2Int>(); soldierBPath.AddLast(new Vector2Int(3, 5)); soldierBPath.AddLast(new Vector2Int(3, 4)); soldierBPath.AddLast(new Vector2Int(3, 3)); soldierBPath.AddLast(new Vector2Int(3, 2)); soldierB.HitPoints = 0.5f; soldierB.MovePath = soldierBPath; } void TestThreeTeam() { CombatUnit soldierA = Instantiate(infantryPrefab).GetComponent <CombatUnitInstance>().GetInstance(grid); soldierA.Location = new Vector2Int(3, 1); soldierA.TeamID = 0; LinkedList <Vector2Int> soldierAPath = new LinkedList <Vector2Int>(); soldierAPath.AddLast(new Vector2Int(3, 1)); soldierAPath.AddLast(new Vector2Int(3, 2)); soldierAPath.AddLast(new Vector2Int(3, 3)); soldierAPath.AddLast(new Vector2Int(3, 4)); soldierA.MovePath = soldierAPath; CombatUnit soldierB = Instantiate(infantryPrefab).GetComponent <CombatUnitInstance>().GetInstance(grid); soldierB.Location = new Vector2Int(3, 5); soldierB.TeamID = 1; LinkedList <Vector2Int> soldierBPath = new LinkedList <Vector2Int>(); soldierBPath.AddLast(new Vector2Int(3, 5)); soldierBPath.AddLast(new Vector2Int(3, 4)); soldierBPath.AddLast(new Vector2Int(3, 3)); soldierBPath.AddLast(new Vector2Int(3, 2)); soldierB.MovePath = soldierBPath; CombatUnit soldierC = Instantiate(infantryPrefab).GetComponent <CombatUnitInstance>().GetInstance(grid); soldierC.Location = new Vector2Int(6, 5); soldierC.TeamID = 2; LinkedList <Vector2Int> soldierCPath = new LinkedList <Vector2Int>(); soldierCPath.AddLast(new Vector2Int(5, 3)); soldierCPath.AddLast(new Vector2Int(4, 3)); soldierCPath.AddLast(new Vector2Int(3, 3)); soldierCPath.AddLast(new Vector2Int(2, 3)); soldierC.MovePath = soldierCPath; } void TestFavored() { CombatUnit soldierA = Instantiate(infantryPrefab).GetComponent <CombatUnitInstance>().GetInstance(grid); soldierA.Location = new Vector2Int(3, 1); soldierA.TeamID = 0; LinkedList <Vector2Int> soldierAPath = new LinkedList <Vector2Int>(); soldierAPath.AddLast(new Vector2Int(3, 1)); soldierAPath.AddLast(new Vector2Int(3, 2)); soldierAPath.AddLast(new Vector2Int(3, 3)); soldierAPath.AddLast(new Vector2Int(3, 4)); soldierA.MovePath = soldierAPath; CombatUnit soldierB = Instantiate(infantryPrefab).GetComponent <CombatUnitInstance>().GetInstance(grid); soldierB.Location = new Vector2Int(3, 5); soldierB.TeamID = 0; LinkedList <Vector2Int> soldierBPath = new LinkedList <Vector2Int>(); soldierBPath.AddLast(new Vector2Int(3, 5)); soldierBPath.AddLast(new Vector2Int(3, 4)); soldierBPath.AddLast(new Vector2Int(3, 3)); soldierBPath.AddLast(new Vector2Int(3, 2)); soldierB.MovePath = soldierBPath; CombatUnit soldierC = Instantiate(infantryPrefab).GetComponent <CombatUnitInstance>().GetInstance(grid); soldierC.Location = new Vector2Int(6, 5); soldierC.TeamID = 1; LinkedList <Vector2Int> soldierCPath = new LinkedList <Vector2Int>(); soldierCPath.AddLast(new Vector2Int(5, 3)); soldierCPath.AddLast(new Vector2Int(4, 3)); soldierCPath.AddLast(new Vector2Int(3, 3)); soldierCPath.AddLast(new Vector2Int(2, 3)); soldierC.MovePath = soldierCPath; } void TestUnitDefeated() { CombatUnit soldierA = Instantiate(infantryPrefab).GetComponent <CombatUnitInstance>().GetInstance(grid); soldierA.Location = new Vector2Int(3, 1); soldierA.TeamID = 0; LinkedList <Vector2Int> soldierAPath = new LinkedList <Vector2Int>(); soldierAPath.AddLast(new Vector2Int(3, 1)); soldierAPath.AddLast(new Vector2Int(3, 2)); soldierAPath.AddLast(new Vector2Int(3, 3)); soldierAPath.AddLast(new Vector2Int(3, 4)); soldierA.MovePath = soldierAPath; CombatUnit soldierB = Instantiate(infantryPrefab).GetComponent <CombatUnitInstance>().GetInstance(grid); soldierB.Location = new Vector2Int(3, 5); soldierB.TeamID = 1; LinkedList <Vector2Int> soldierBPath = new LinkedList <Vector2Int>(); soldierBPath.AddLast(new Vector2Int(3, 5)); soldierBPath.AddLast(new Vector2Int(3, 4)); soldierBPath.AddLast(new Vector2Int(3, 3)); soldierBPath.AddLast(new Vector2Int(3, 2)); soldierB.HitPoints = 0.2f; soldierB.MovePath = soldierBPath; } }
private void OnEnable() { m_Table = target as DamageTable; }
private void Awake() { // TODO remove this it is jank! // Should be passed via constructor. damageTable = new UnitySceneParser().GetFirstDamageTable(); }