public override void Attack(IFightable atackDestination) { if (Nearby(_playerPosition, _attackRange)) { atackDestination.TakeAHit(random.Next(15, _maxAttackPower + 1)); } }
public Combat(IFightable goodguy, IFightable badguy) { friend = goodguy; enemy = badguy; friendStatus = friend.GetStatus(); enemyStatus = enemy.GetStatus(); }
public static string GetAttackResult(IFightable fighterA, IFightable fighterB) { fighterA.Attack(out int atkValue, out string atkDescription); // hämtar attacken och värdet av den fighterB.Defence(out int defValue); // hämtar försvars värdet. int damage = atkValue - defValue; if (damage < 0) { damage = 0; } Console.WriteLine($"{atkDescription} and deals {damage} damage"); fighterB.Health -= damage; if (fighterB.Health <= 0) { return("Fight Over"); } Console.WriteLine("Press any key to continue..."); Console.ReadLine(); Console.Clear(); return("keep fighting"); }
public void Attack(IFightable target) { // 射撃音再生 MasterAudio.PlaySound("Blaster_001"); target.Damage(Status); }
private static void CheckIfDead(IFightable attacker, IFightable target) { if (target.Health <= 0) { target.Die(attacker); attacker.Kill(target); } }
private static void DamageWeapon(IFightable attacker) { if (attacker is Player player) { int chanceOfDamage = 70;// percentile if (Utilities.PassPercentileRoll(chanceOfDamage)) { player.CurrentWeapon.DecrDurability(1, player); } } }
public GuiObject BuildCombatWindow(IFightable friend, IFightable enemy, Combat combat) { CloseWindow("LeftPane"); GuiObject window = new GuiObject(new Rect(100, 50, 400, 300), "CentrePane", "Combat!"); Status friendStatus = friend.GetStatus(), enemyStatus = enemy.GetStatus(); combat = new Combat(friend, enemy); string report = combat.Phase()(); window.AddChild(new GuiObject(new Rect(10, 25, 490, 370), (g) => { GUI.Label(g.rect, "Night has fallen and you were attacked!\n" + report); if (GUI.Button(new Rect(175, 260, 50, 25), "OK")) { CloseWindow("CentrePane"); } }, "Report", "")); return(window); }
void Update() { CursorType cursor = CursorType.Default; if (!EventSystem.current.IsPointerOverGameObject()) { if (CastingSkill) { cursor = CursorType.CastSkill; } Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition); RaycastHit hit; if (Physics.Raycast(ray, out hit)) { int x = (int)hit.point.x; int y = (int)hit.point.z; if (hit.transform.tag == "Map") { if (Input.GetMouseButtonDown(0)) { if (!MapMetrics.InsideMap(y, x)) { if (curRegion != null) { curRegion.Selected = false; } curRegion = null; if (army != null) { DeselectArmy(); } } else { RegionTap(Main.regions[regionIndex[y, x]]); } } if (Input.GetMouseButtonDown(1)) { army?.TryMoveTo(hit.point); ship?.TryMoveTo(hit.point); if (curPort) { curPort.ShipOut(hit.point); } } } State other = null; IFightable target = null; if (hit.transform.tag == "Unit") { Army sel = hit.transform.GetComponent <Army>(); if (Input.GetMouseButtonDown(0) || Input.GetMouseButtonDown(1)) { ArmyTap(sel, Input.GetMouseButtonDown(0)); } other = sel.curOwner; target = sel; if (CastingSkill) { if (CastSkill is IArmyCastable cast) { if (cast.CanCastOnArmy(sel)) { cursor = CursorType.CanCastSkill; } } } else { if (other == curPlayer && sel != army) { cursor = CursorType.Select; } } } if (hit.transform.tag == "Ship") { Ship sel = hit.transform.GetComponent <Ship>(); if (Input.GetMouseButtonDown(0) || Input.GetMouseButtonDown(1)) { ShipTap(sel, Input.GetMouseButtonDown(0)); } other = sel.curOwner; if (CastingSkill) { } else { if (other == curPlayer && sel != ship) { cursor = CursorType.Select; } } } if (hit.transform.tag == "Town") { Region reg = MapMetrics.regions[int.Parse(hit.transform.name)]; highlightRegion = reg; TownTap(reg, Input.GetMouseButtonDown(0), Input.GetMouseButtonDown(1)); reg.bar.Active = true; other = reg.curOwner; target = reg; if (CastingSkill) { if (CastSkill is IRegionCastable cast) { if (cast.CanCastOnRegion(reg)) { cursor = CursorType.CanCastSkill; } } } else { if (other == curPlayer && reg != curRegion) { cursor = CursorType.Select; } } } else { if (highlightRegion != null) { highlightRegion.bar.Active = false; } } if (hit.transform.GetComponent <Port>()) { Port port = hit.transform.GetComponent <Port>(); if (Input.GetMouseButtonDown(0) && port.curOwner == curPlayer && port.Ship) { curPort = port; DeselectShip(); } if (Input.GetMouseButtonDown(1) && ship && port.CanshipOn(ship)) { ship.TryMoveTo(port); } } if (!CastingSkill && target != null && army != null && army.CanAttack(target, TargetType)) { switch (TargetType) { case DamageType.Melee: case DamageType.Charge: cursor = CursorType.MeleeAttack; break; case DamageType.Range: cursor = CursorType.RangeAttack; break; case DamageType.Siege: cursor = CursorType.SiegeAttack; break; } } } } if (curRegion == null) { MenuManager.HiddenProvinceMenu(); } if (cursor != cursorType) { cursorType = cursor; CursorHandler.SetCursor(cursorType); } }
public static bool HasLowHealth(IFightable fighter) { return(fighter.Health < fighter.MaxHealth / 4); }
public GuiObject BuildCombatDebugWindow(IFightable friend, IFightable enemy, Combat combat) { CloseWindow("LeftPane"); GuiObject window = new GuiObject(new Rect(20, 50, 800, 500), "CentrePane", "Combat!"); Status friendStatus = friend.GetStatus(), enemyStatus = enemy.GetStatus(); combat = new Combat(friend, enemy); window.AddChild(new GuiObject(new Rect(20, 20, 800, 100), (g) => { GUI.Label(new Rect(10, 25, 780, 100), "Night has fallen, you are under attack!"); if (GUI.Button(new Rect(345, 65, 100, 30), "Attack!")) { combat.Phase(); } }, "Text", "")); window.AddChild(new GuiObject(new Rect(20, 100, 360, 390), (g) => { GUI.Box(g.rect, g.text); GUI.Label(new Rect(30, 200, 200, 25), "Attack: " + friendStatus.attack); if (friendStatus.attackbonus > 0f) { SetColor(() => true); GUI.Label(new Rect(90, 200, 200, 25), "+" + friendStatus.attackbonus); SetColor(); } GUI.Label(new Rect(30, 220, 200, 25), "Armour: " + friendStatus.armour); if (friendStatus.armorbonus > 0f) { SetColor(() => true); GUI.Label(new Rect(90, 220, 200, 25), "+" + friendStatus.armorbonus); SetColor(); } GUI.Label(new Rect(30, 240, 200, 25), "Speed: " + friendStatus.speed); if (friendStatus.speedbonus > 0f) { SetColor(() => true); GUI.Label(new Rect(90, 240, 200, 25), "+" + friendStatus.speedbonus); SetColor(); } GUI.Label(new Rect(130, 200, 100, 25), "Health: " + friendStatus.health); GUI.Label(new Rect(130, 220, 100, 25), "Turn: " + friendStatus.turn); }, "FriendBox", "Friend")); window.AddChild(new GuiObject(new Rect(410, 100, 360, 390), (g) => { GUI.Box(g.rect, g.text); GUI.Label(new Rect(420, 200, 200, 25), "Attack: " + enemyStatus.attack); if (enemyStatus.attackbonus > 0f) { SetColor(() => true); GUI.Label(new Rect(480, 200, 200, 25), "+" + enemyStatus.attackbonus); SetColor(); } GUI.Label(new Rect(420, 220, 200, 25), "Armour: " + enemyStatus.armour); if (enemyStatus.armorbonus > 0f) { SetColor(() => true); GUI.Label(new Rect(480, 220, 200, 25), "+" + enemyStatus.armorbonus); SetColor(); } GUI.Label(new Rect(420, 240, 200, 25), "Speed: " + enemyStatus.speed); if (enemyStatus.speedbonus > 0f) { SetColor(() => true); GUI.Label(new Rect(480, 240, 200, 25), "+" + enemyStatus.speedbonus); SetColor(); } GUI.Label(new Rect(520, 200, 100, 25), "Health: " + enemyStatus.health); GUI.Label(new Rect(520, 220, 100, 25), "Turn: " + enemyStatus.turn); }, "EnemyBox", "Enemy")); return(window); }
public GuiObject BuildCombatWindow(IFightable friend, IFightable enemy, Combat combat) { CloseWindow("LeftPane"); GuiObject window = new GuiObject(new Rect(100, 50, 400, 300), "CentrePane", "Combat!"); Status friendStatus = friend.GetStatus(), enemyStatus = enemy.GetStatus(); combat = new Combat(friend, enemy); string report = combat.Phase()(); window.AddChild(new GuiObject(new Rect(10, 25, 490, 370), (g) => { GUI.Label(g.rect, "Night has fallen and you were attacked!\n" + report); if (GUI.Button(new Rect(175, 260, 50, 25), "OK")) { CloseWindow("CentrePane"); } }, "Report", "")); return window; }
public Combat (IFightable goodguy, IFightable badguy) { friend = goodguy; enemy = badguy; friendStatus = friend.GetStatus(); enemyStatus = enemy.GetStatus(); }
private static void InflictDamage(IFightable target, int damage) { target.Health -= damage; }
private static int CalculateDamage(IFightable attacker, IFightable target) { int resulting = Utilities.RandomNumber(GetMinDamage(attacker), GetMaxDamage(attacker)); return(resulting > 0 ? resulting : 0); }
public static int GetMaxDamage(IFightable fighter) { return(fighter.Attack); }
public static void Hit(IFightable attacker, IFightable target) { InflictDamage(target, CalculateDamage(attacker, target)); DamageWeapon(attacker); CheckIfDead(attacker, target); }
public GuiObject BuildCombatDebugWindow(IFightable friend, IFightable enemy, Combat combat) { CloseWindow("LeftPane"); GuiObject window = new GuiObject(new Rect(20, 50, 800, 500), "CentrePane", "Combat!"); Status friendStatus = friend.GetStatus(), enemyStatus = enemy.GetStatus(); combat = new Combat(friend, enemy); window.AddChild(new GuiObject( new Rect(20, 20, 800, 100), (g) => { GUI.Label(new Rect(10, 25, 780, 100), "Night has fallen, you are under attack!"); if (GUI.Button(new Rect(345, 65, 100, 30), "Attack!")) { combat.Phase(); } }, "Text", "")); window.AddChild(new GuiObject(new Rect(20, 100, 360, 390), (g) => { GUI.Box(g.rect, g.text); GUI.Label(new Rect(30, 200, 200, 25), "Attack: " + friendStatus.attack); if (friendStatus.attackbonus > 0f) { SetColor(() => true); GUI.Label(new Rect(90, 200, 200, 25), "+" + friendStatus.attackbonus); SetColor(); } GUI.Label(new Rect(30, 220, 200, 25), "Armour: " + friendStatus.armour); if (friendStatus.armorbonus > 0f) { SetColor(() => true); GUI.Label(new Rect(90, 220, 200, 25), "+" + friendStatus.armorbonus); SetColor(); } GUI.Label(new Rect(30, 240, 200, 25), "Speed: " + friendStatus.speed); if (friendStatus.speedbonus > 0f) { SetColor(() => true); GUI.Label(new Rect(90, 240, 200, 25), "+" + friendStatus.speedbonus); SetColor(); } GUI.Label(new Rect(130, 200, 100, 25), "Health: " + friendStatus.health); GUI.Label(new Rect(130, 220, 100, 25), "Turn: " + friendStatus.turn); }, "FriendBox", "Friend")); window.AddChild(new GuiObject(new Rect(410, 100, 360, 390), (g) => { GUI.Box(g.rect, g.text); GUI.Label(new Rect(420, 200, 200, 25), "Attack: " + enemyStatus.attack); if (enemyStatus.attackbonus > 0f) { SetColor(() => true); GUI.Label(new Rect(480, 200, 200, 25), "+" + enemyStatus.attackbonus); SetColor(); } GUI.Label(new Rect(420, 220, 200, 25), "Armour: " + enemyStatus.armour); if (enemyStatus.armorbonus > 0f) { SetColor(() => true); GUI.Label(new Rect(480, 220, 200, 25), "+" + enemyStatus.armorbonus); SetColor(); } GUI.Label(new Rect(420, 240, 200, 25), "Speed: " + enemyStatus.speed); if (enemyStatus.speedbonus > 0f) { SetColor(() => true); GUI.Label(new Rect(480, 240, 200, 25), "+" + enemyStatus.speedbonus); SetColor(); } GUI.Label(new Rect(520, 200, 100, 25), "Health: " + enemyStatus.health); GUI.Label(new Rect(520, 220, 100, 25), "Turn: " + enemyStatus.turn); }, "EnemyBox", "Enemy")); return window; }
public void DealDamage(int value, IFightable opponent) { opponent.ChangeHealth(-value); }
public void Attack(IFightable target) { target.Damage(Status); }