Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Threading;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- namespace TurnBasedCombat
- {
- class Program
- {
- public static class StaticRandom
- {
- private static int seed;
- private static ThreadLocal<Random> threadLocal = new ThreadLocal<Random>
- (() => new Random(Interlocked.Increment(ref seed)));
- static StaticRandom()
- {
- seed = Environment.TickCount;
- }
- public static Random Instance { get { return threadLocal.Value; } }
- }
- class Unit
- {
- Random RNG = new Random();
- public int curHP = 0;
- public int maxHP = 0;
- public int curMP;
- public int maxMP;
- public float pow;
- public float vit;
- public float agi;
- public float dex;
- public float Dmg;
- public float randPow;
- public float hitRate;
- public int job;
- public float bonusDamage;
- public int chance = 0;
- public float bonusHP;
- public string name;
- public string team;
- public List<Skill> Skill
- {
- get;
- set;
- }
- public Unit()
- {
- Skill = new List<Skill>();
- }
- public virtual void DisplayStats()
- {
- Console.WriteLine("Name: " + this.name);
- Console.WriteLine("HP: " + this.curHP + "/" + this.maxHP);
- Console.WriteLine("MP: " + curMP + "/" + maxMP);
- Console.WriteLine("POW: " + this.pow);
- Console.WriteLine("VIT: " + this.vit);
- Console.WriteLine("AGI: " + this.agi);
- Console.WriteLine("DEX: " + this.dex);
- }
- public int calculateBaseDmg()
- {
- float percent = StaticRandom.Instance.Next(20);
- percent /= 100;
- int baseDmg = (int)this.pow + (int)(percent * this.pow);
- this.randPow = this.Dmg + percent;
- return baseDmg;
- }
- public virtual int calcuDmg(Unit Target, float skillDamage)
- {
- this.Dmg = (int)((calculateBaseDmg() - Target.vit) * calculateBnsDmg(Target) * skillDamage);
- if (Dmg == 0 || Dmg < 0)
- {
- Dmg = 1;
- }
- else if (Target.Dmg == 0 || Target.Dmg < 0)
- {
- Target.Dmg = 1;
- }
- return (int)Dmg;
- }
- public virtual void calculateHitRate(Unit Target)
- {
- this.hitRate = (this.dex / Target.agi) * 100;
- Target.hitRate = (Target.dex / this.agi) * 100;
- if (this.hitRate > 80)
- {
- this.hitRate = 80;
- }
- else if (Target.hitRate > 80)
- {
- Target.hitRate = 80;
- }
- else if (this.hitRate < 20)
- {
- this.hitRate = 20;
- }
- else if (Target.hitRate < 20)
- {
- Target.hitRate = 20;
- }
- }
- public virtual void printHitRate(Unit target)
- {
- Console.WriteLine(this.hitRate);
- Console.WriteLine(target.hitRate);
- }
- public virtual float calculateBnsDmg(Unit Target)
- {
- if (job == 3 && Target.job == 3 ||
- job == 1 && Target.job == 3 ||
- job == 2 && Target.job == 1)
- {
- return 1.5f;
- }
- else
- {
- return 1.0f;
- }
- }
- public int takeDmg(int Damage)
- {
- this.curHP = this.curHP -= Damage;
- return Damage;
- }
- public int takeHeal()
- {
- this.bonusHP = (int)maxHP * 0.30f;
- this.curHP += (int)bonusHP;
- return (int)this.bonusHP;
- }
- public void mpCost(int cost)
- {
- curMP -= cost;
- }
- public int critHit(int Dmg)
- {
- float critDmg = Dmg * 0.20f;
- curHP -= Dmg + (int)critDmg;
- return Dmg;
- }
- }
- class Warrior : Unit
- {
- public void Initialize(string _name, string _team)
- {
- job = 2;
- this.name = _name;
- team = _team;
- maxHP = StaticRandom.Instance.Next(290, 750);
- curHP = maxHP;
- maxMP = StaticRandom.Instance.Next(100, 250);
- //curMP = maxMP;
- curMP = 0;
- pow = StaticRandom.Instance.Next(400, 550);
- vit = StaticRandom.Instance.Next(300, 600);
- agi = StaticRandom.Instance.Next(10, 250);
- dex = StaticRandom.Instance.Next(50, 340);
- }
- public override void DisplayStats()
- {
- base.DisplayStats();
- }
- }
- class Assassin : Unit
- {
- public void Initialize(string _name, string _team)
- {
- job = 1;
- this.name = _name;
- team = _team;
- maxHP = StaticRandom.Instance.Next(120, 750);
- curHP = maxHP;
- maxMP = StaticRandom.Instance.Next(100, 250);
- //curMP = maxMP;
- curMP = 0;
- pow = StaticRandom.Instance.Next(150, 340);
- vit = StaticRandom.Instance.Next(50, 250);
- agi = StaticRandom.Instance.Next(300, 650);
- dex = StaticRandom.Instance.Next(250, 590);
- }
- public override void DisplayStats()
- {
- base.DisplayStats();
- }
- }
- class Mage : Unit
- {
- public void Initialize(string _name, string _team)
- {
- job = 3;
- this.name = _name;
- team = _team;
- maxHP = StaticRandom.Instance.Next(500, 550);
- curHP = maxHP;
- maxMP = StaticRandom.Instance.Next(100, 250);
- //curMP = maxMP;
- curMP = 0;
- pow = StaticRandom.Instance.Next(100, 330);
- vit = StaticRandom.Instance.Next(200, 620);
- agi = StaticRandom.Instance.Next(100, 390);
- dex = StaticRandom.Instance.Next(140, 310);
- }
- public override void DisplayStats()
- {
- base.DisplayStats();
- }
- }
- class Skill
- {
- public int mpCost = 0;
- public Random RNG = new Random();
- public virtual void Use(Unit user, List<Unit> targets)
- {
- }
- public int findLowest(List<Unit> targets, int lowestHP, int targeted, int index)
- {
- foreach (Unit unit in targets)
- {
- index++;
- if (unit.curHP <= lowestHP)
- {
- lowestHP = unit.curHP;
- targeted = index;
- }
- }
- return targeted;
- }
- }
- class basicAtk : Skill
- {
- public override void Use(Unit user, List<Unit> Targets)
- {
- int random = StaticRandom.Instance.Next(Targets.Count);
- int chance = StaticRandom.Instance.Next(1, 101);
- int critChance = StaticRandom.Instance.Next(1, 101);
- user.calculateBnsDmg(Targets[random]);
- user.calcuDmg(Targets[random], 1);
- Console.WriteLine(user.calcuDmg(Targets[random], 1));
- user.calculateHitRate(user);
- Console.WriteLine("Hit Rate: " + (int)user.hitRate);
- Console.WriteLine("Chance: " + chance);
- //no mp cost
- int randTarget = StaticRandom.Instance.Next(Targets.Count);
- if (chance <= user.hitRate)
- {
- if (critChance <= 20)
- {
- Console.WriteLine("Critcical!");
- Targets[randTarget].critHit((int)user.Dmg);
- }
- else if (critChance > 20)
- {
- Targets[randTarget].takeDmg((int)user.Dmg);
- Console.WriteLine();
- }
- }
- else if (chance > user.hitRate)
- {
- Console.WriteLine("Missed!");
- return;
- }
- Console.WriteLine("---->" + user.name + " dealt " + user.Dmg + " to " + Targets[random].name + "!<------");
- Console.WriteLine("---->" + Targets[random].name + " has " + Targets[random].curHP + "/" + Targets[random].maxHP + " left!<------");
- }
- }
- class Assassinate : Skill
- {
- int index = -1;
- int lowestHP = int.MaxValue;
- int targeted = 10;
- public override void Use(Unit user, List<Unit> Targets)
- {
- mpCost = 5;
- user.curMP = user.curMP - mpCost;
- int target = findLowest(Targets, lowestHP, targeted, index);
- int damage = user.calcuDmg(Targets[target], 0.9f);
- user.calculateBnsDmg(Targets[target]);
- user.calcuDmg(Targets[target], 1);
- user.calculateHitRate(user);
- Targets[target].takeDmg((int)damage);
- Console.WriteLine(user.name + " ASSASSINATED " + Targets[target].name + " dealing " + user.Dmg + " damage!");
- Console.WriteLine(Targets[target].name + " has " + Targets[target].curHP + "/" + Targets[target].maxHP + " left!");
- }
- }
- class Shockwave : Skill
- {
- public override void Use(Unit user, List<Unit> Targets)
- {
- foreach (Unit unit in Targets)
- {
- mpCost = 7;
- user.curMP = user.curMP - mpCost;
- int damage = user.calcuDmg(unit, 0.9f);
- unit.takeDmg((int)damage);
- Console.WriteLine(user.name + " used Shockwave on " + unit.name + " dealing " + unit.Dmg + " damage!");
- Console.WriteLine(unit.name + " has " + unit.curHP + "/" + unit.maxHP + " left!");
- }
- //base.Use(user, Targets);
- }
- }
- class Heal : Skill
- {
- int index = -1;
- int lowestHP = int.MaxValue;
- int targeted = 10;
- public override void Use(Unit user, List<Unit> Targets)
- {
- mpCost = 10;
- user.curMP = user.curMP - mpCost;
- int target = findLowest(Targets, lowestHP, targeted, index);
- Console.WriteLine(user.name + " healed " + Targets[target].name + " for " + Targets[target].takeHeal());
- Console.WriteLine(Targets[target].name + " has " + Targets[target].curHP + "/" + Targets[target].maxHP + " left!");
- }
- }
- static List<Unit> turnOrder(List<Unit> playerList, List<Unit> enemyList, List<Unit> orderTurn)
- {
- // List<Unit> orderTurn = new List<Unit>();
- //add participants
- for (int p = 0; p < playerList.Count(); p++)
- {
- orderTurn.Add(playerList[p]);
- }
- for (int e = 0; e < enemyList.Count(); e++)
- {
- orderTurn.Add(enemyList[e]);
- }
- Unit tempUnit;
- for (int i = 0; i < orderTurn.Count(); i++)
- {
- for (int j = 0; j < orderTurn.Count(); j++)
- {
- if (orderTurn[i].agi > orderTurn[j].agi)
- {
- tempUnit = orderTurn[j];
- orderTurn[j] = orderTurn[i];
- orderTurn[i] = tempUnit;
- }
- }
- }
- return orderTurn;
- }
- static void battleSystem(List<Unit> turnOrders, List<Unit> playerTeam, List<Unit> enemyTeam)
- {
- Unit firstUnit = turnOrders.First();
- for (int i = 0; i < turnOrders.Count; i++)
- {
- if (firstUnit.curHP <= 0)
- {
- Console.WriteLine(firstUnit.name + " is dead!");
- turnOrders.Remove(firstUnit);
- }
- }
- int choice;
- int enemyChoice;
- enemyChoice = StaticRandom.Instance.Next(0, 1);
- if (firstUnit.team == "Player Team")
- {
- Console.WriteLine("==========Current Turn: " + firstUnit.name + "==========");
- firstUnit.DisplayStats();
- Console.WriteLine("0: Attack\n1: Skill");
- //choice = Convert.ToInt32(Console.ReadLine());
- while(true)
- {
- if (int.TryParse(Console.ReadLine(), out choice))
- {
- break;
- }
- }
- Skill skill = firstUnit.Skill[choice];
- if (choice == 0)
- {
- skill.Use(firstUnit, enemyTeam);
- }
- if (choice == 1)
- {
- if (firstUnit.curMP >= skill.mpCost)
- {
- if (firstUnit.job == 3)
- {
- skill.Use(firstUnit, playerTeam); //heal
- }
- else if (firstUnit.job != 3)
- {
- skill.Use(firstUnit, enemyTeam); //attack with skill
- }
- }
- else if (firstUnit.curMP < skill.mpCost)
- {
- Console.WriteLine("Insufficient Mana!");
- }
- }
- }
- else if (firstUnit.team == "Enemy Team")
- {
- Skill skill = firstUnit.Skill[enemyChoice];
- Console.WriteLine("==========Current Turn: " + firstUnit.name + "==========");
- firstUnit.DisplayStats();
- enemyChoice = StaticRandom.Instance.Next(0, 1);
- if (enemyChoice == 0)
- {
- skill.Use(firstUnit, playerTeam);
- }
- else if (enemyChoice == 1)
- {
- if (firstUnit.job == 3)
- {
- skill.Use(firstUnit, enemyTeam);
- }
- else
- {
- skill.Use(firstUnit, playerTeam);
- }
- // skill.Use(firstUnit, playerTeam);
- }
- }
- Console.WriteLine("\nNext Turn!");
- NextTurn(turnOrders);
- }
- static void NextTurn(List<Unit> Participants)
- {
- int i = 0;
- Unit temp;
- for (int j = i + 1; j < Participants.Count; j++)
- {
- temp = Participants[i];
- Participants[i] = Participants[j];
- Participants[j] = temp;
- i++;
- }
- }
- static void Main(string[] args)
- {
- //Skills
- basicAtk basicAttack = new basicAtk();
- Assassinate asssinate = new Assassinate();
- Shockwave shockwave = new Shockwave();
- Heal heal = new Heal();
- /////////
- //Create Player Team//
- List<Unit> playerTeam = new List<Unit>();
- //Create skills
- List<Unit> turnOrders = new List<Unit>();
- //Create Player Members//
- Warrior playerWarrior = new Warrior();
- playerWarrior.Initialize("Grand Saber Cody", "Player Team");
- playerTeam.Add(playerWarrior);
- playerWarrior.Skill.Add(basicAttack);
- playerWarrior.Skill.Add(shockwave);
- Skill playerShockwave = playerWarrior.Skill[1];
- Mage playerMage = new Mage();
- playerMage.Initialize("Grand Caster Paolo", "Player Team");
- playerTeam.Add(playerMage);
- playerMage.Skill.Add(basicAttack);
- playerMage.Skill.Add(heal);
- Skill playerHeal = playerMage.Skill[1];
- Assassin playerAssassin = new Assassin();
- playerAssassin.Initialize("Grand Assassin Virgilio", "Player Team");
- playerTeam.Add(playerAssassin);
- playerAssassin.Skill.Add(basicAttack);
- playerAssassin.Skill.Add(asssinate);
- Skill playerAssassinate = playerAssassin.Skill[1];
- // Initialize Enemy Team
- List<Unit> enemyTeam = new List<Unit>();
- // Initialize Enemy Members
- Warrior enemyWarrior = new Warrior();
- enemyWarrior.Initialize("The Rude Warrior", "Enemy Team");
- enemyTeam.Add(enemyWarrior);
- enemyWarrior.Skill.Add(basicAttack);
- enemyWarrior.Skill.Add(shockwave);
- Skill enemyShockwave = playerWarrior.Skill[1];
- Mage enemyMage = new Mage();
- enemyMage.Initialize("Filthy Mage", "Enemy Team");
- enemyTeam.Add(enemyMage);
- enemyMage.Skill.Add(basicAttack);
- enemyMage.Skill.Add(heal);
- Skill enemyHeal = enemyMage.Skill[1];
- Assassin enenmyAssassin = new Assassin();
- enenmyAssassin.Initialize("Meme Assassin", "Enemy Team");
- enemyTeam.Add(enenmyAssassin);
- enenmyAssassin.Skill.Add(basicAttack);
- enenmyAssassin.Skill.Add(asssinate);
- Skill enemyAssassinate = enenmyAssassin.Skill[1];
- Console.WriteLine("Team: [The F2Ps]");
- foreach (Unit unit in playerTeam) unit.DisplayStats();
- Console.WriteLine("\nTeam: [The Whales]");
- foreach (Unit unit in enemyTeam) unit.DisplayStats();
- turnOrder(playerTeam, enemyTeam, turnOrders);
- ///////////////////
- //turn order//
- Console.WriteLine();
- Console.WriteLine("Turn Order: ");
- for (int i = 0; i < turnOrders.Count; i++)
- Console.WriteLine("[" + i + "]" + turnOrders[i].name);
- ///////////////////
- while (playerTeam.Count > 0 || enemyTeam.Count > 0)
- {
- battleSystem(turnOrders, playerTeam, enemyTeam);
- Console.ReadKey();
- }
- Console.ReadKey();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement