Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.IO;
- using System.Web;
- using Jypeli;
- using Jypeli.Assets;
- using Jypeli.Controls;
- using Jypeli.Effects;
- using Jypeli.Widgets;
- public class Player
- {
- public string Name = "Player";
- public string Class = "Berserker";
- //Attributes
- public int Intelligence = 0;
- public int Dexterity = 0;
- public int Strength = 0;
- //Basic stats
- public int MaxHealth = 0;
- public int Health = 0;
- public int MaxMana = 0;
- public int Mana = 0;
- public int MaxEnergyShield = 0;
- public int EnergyShield = 0;
- //Regen rates
- public double ManaRegenerationRate = 0.0;
- public double HealthRegenerationRate = 0.0;
- //Defense stats
- public double Evasion = 0.0;
- public double Armour = 0.0;
- //Offense stats
- public int Accuracy = 0;
- //Resistances
- public double FireResistance = 0.0; // int 1 = fire damage
- public double ColdResistance = 0.0; // int 2 = cold damage
- public double LightningResistance = 0.0; // int 3 = lightning damage
- public double PureResistance = 0.0; // int 0 = pure damage
- public double BaseWalkSpeed = 16.0;
- public List<string> Effects = new List<string>(); //Contains curses/buffs etc.
- public List<InventoryItem> Inventory = new List<InventoryItem>(); //Inventory
- //Return damage after elemental resistances
- public double SubstractResistances(double rawDmg, int dtype)
- {
- switch(dtype)
- {
- case 0:
- return rawDmg * PureResistance;
- case 1:
- return rawDmg * FireResistance;
- case 2:
- return rawDmg * ColdResistance;
- case 3:
- return rawDmg * LightningResistance;
- default:
- return rawDmg;
- }
- }
- //Negate damage through armour
- public double CalcTrueDamageTaken(double armour, double rawDmg)
- {
- return (armour / (armour + 10.0 * rawDmg));
- }
- //Calculate change to evade
- public double CalcChanceToEvade(double defenderEvasion, double AttackerAccuracy)
- {
- return 1.0 - (AttackerAccuracy / (Math.Pow(AttackerAccuracy + (defenderEvasion * (1.0 / 4.0)), 0.8)));
- }
- //"Give" player the actual damage
- public void TakeDamage(NPC attacker, double damage, int dtype)
- {
- double evade = CalcChanceToEvade(Evasion, attacker.Accuracy);
- double roll = RandomGen.NextDouble(0.0, 1.0);
- if (roll > evade) //If roll<evade then "dodge" attack and take no damage
- {
- double dmg = CalcTrueDamageTaken(Armour, damage);
- dmg = SubstractResistances(dmg, dtype);
- Health = Health - (int)dmg;
- }
- }
- public void SaveToFile(GameLevel currentLevel, string saveFile)
- {
- using (System.IO.StreamWriter file = new System.IO.StreamWriter(saveFile, true))
- {
- string json = System.Web.Helpers.Json.Encode(this);
- file.WriteLine(json);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement