Advertisement
Guest User

Untitled

a guest
Sep 25th, 2016
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.02 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.IO;
  6. using System.Web;
  7. using Jypeli;
  8. using Jypeli.Assets;
  9. using Jypeli.Controls;
  10. using Jypeli.Effects;
  11. using Jypeli.Widgets;
  12.  
  13.  
  14.  
  15. public class Player
  16. {
  17. public string Name = "Player";
  18. public string Class = "Berserker";
  19.  
  20.  
  21. //Attributes
  22. public int Intelligence = 0;
  23. public int Dexterity = 0;
  24. public int Strength = 0;
  25.  
  26. //Basic stats
  27. public int MaxHealth = 0;
  28. public int Health = 0;
  29. public int MaxMana = 0;
  30. public int Mana = 0;
  31. public int MaxEnergyShield = 0;
  32. public int EnergyShield = 0;
  33.  
  34. //Regen rates
  35. public double ManaRegenerationRate = 0.0;
  36. public double HealthRegenerationRate = 0.0;
  37.  
  38. //Defense stats
  39. public double Evasion = 0.0;
  40. public double Armour = 0.0;
  41.  
  42. //Offense stats
  43. public int Accuracy = 0;
  44.  
  45.  
  46. //Resistances
  47. public double FireResistance = 0.0; // int 1 = fire damage
  48. public double ColdResistance = 0.0; // int 2 = cold damage
  49. public double LightningResistance = 0.0; // int 3 = lightning damage
  50. public double PureResistance = 0.0; // int 0 = pure damage
  51.  
  52. public double BaseWalkSpeed = 16.0;
  53.  
  54.  
  55. public List<string> Effects = new List<string>(); //Contains curses/buffs etc.
  56. public List<InventoryItem> Inventory = new List<InventoryItem>(); //Inventory
  57.  
  58. //Return damage after elemental resistances
  59. public double SubstractResistances(double rawDmg, int dtype)
  60. {
  61. switch(dtype)
  62. {
  63. case 0:
  64. return rawDmg * PureResistance;
  65. case 1:
  66. return rawDmg * FireResistance;
  67. case 2:
  68. return rawDmg * ColdResistance;
  69. case 3:
  70. return rawDmg * LightningResistance;
  71. default:
  72. return rawDmg;
  73. }
  74. }
  75.  
  76. //Negate damage through armour
  77. public double CalcTrueDamageTaken(double armour, double rawDmg)
  78. {
  79. return (armour / (armour + 10.0 * rawDmg));
  80. }
  81.  
  82. //Calculate change to evade
  83. public double CalcChanceToEvade(double defenderEvasion, double AttackerAccuracy)
  84. {
  85. return 1.0 - (AttackerAccuracy / (Math.Pow(AttackerAccuracy + (defenderEvasion * (1.0 / 4.0)), 0.8)));
  86. }
  87.  
  88.  
  89. //"Give" player the actual damage
  90. public void TakeDamage(NPC attacker, double damage, int dtype)
  91. {
  92. double evade = CalcChanceToEvade(Evasion, attacker.Accuracy);
  93. double roll = RandomGen.NextDouble(0.0, 1.0);
  94. if (roll > evade) //If roll<evade then "dodge" attack and take no damage
  95. {
  96. double dmg = CalcTrueDamageTaken(Armour, damage);
  97. dmg = SubstractResistances(dmg, dtype);
  98. Health = Health - (int)dmg;
  99. }
  100. }
  101.  
  102. public void SaveToFile(GameLevel currentLevel, string saveFile)
  103. {
  104. using (System.IO.StreamWriter file = new System.IO.StreamWriter(saveFile, true))
  105. {
  106. string json = System.Web.Helpers.Json.Encode(this);
  107. file.WriteLine(json);
  108. }
  109. }
  110.  
  111.  
  112.  
  113.  
  114.  
  115.  
  116. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement