Added Stats, damage code, stuff

This commit is contained in:
Niklas Ulf Anders Cullberg
2012-10-17 11:20:09 +02:00
parent 4f8a5ccdb2
commit 092dc176a8
4 changed files with 205 additions and 148 deletions
+38 -5
View File
@@ -7,23 +7,56 @@ namespace DepthsBelow.Component
{ {
public class Stat : Component public class Stat : Component
{ {
protected int hp = 0;
protected int defence = 0;
protected int stepsTaken = 0; protected int stepsTaken = 0;
protected int distanceToTarget = 0; protected int distanceToTarget = 0;
protected int panic = 0; protected int panic = 0;
protected int soldierAim = 0; protected int soldierAim = 100;
protected int weaponAccuracy = 0; protected int weaponAccuracy = 0;
protected int weaponStrength = 0;
protected int ammo = 0;
protected int enemyDodge = 0; protected int enemyDodge = 0;
protected int penaltyRange = 5; protected int penaltyRange = 5;
public int GetAim() public int GetAim
{ {
return (soldierAim + weaponAccuracy); get { return soldierAim + weaponAccuracy; }
set { soldierAim = value; }
} }
public int GetDodge() public int GetDodge
{ {
return enemyDodge; get { return enemyDodge; }
set { enemyDodge = value; }
}
public int Life
{
get { return hp; }
set
{
hp = value;
if (hp <= 0) {
//If you kill me, I will become stronger than you can ever imagine.
Kill();
}
}
}
public int Defence
{
get { return defence; }
set { defence = value; }
}
public int Strength
{
get { return weaponStrength; }
set { weaponStrength = value; }
}
public void Kill()
{
hp = 0;
} }
public int Penalty(int distance) public int Penalty(int distance)
+6
View File
@@ -49,6 +49,12 @@ namespace DepthsBelow
var pfc = new PathFinder(this); var pfc = new PathFinder(this);
AddComponent(pfc); AddComponent(pfc);
stat.Life = 2;
stat.Defence = 0;
stat.Strength = 5;
stat.GetAim = 100;
stat.GetDodge = 10;
} }
public bool Selected public bool Selected
+6
View File
@@ -61,6 +61,12 @@ namespace DepthsBelow
var pfc = new PathFinder(this); var pfc = new PathFinder(this);
AddComponent(pfc); AddComponent(pfc);
stat.Life = 10;
stat.Defence = 10;
stat.Strength = 10;
stat.GetAim = 100;
stat.GetDodge = 20;
} }
public bool Selected public bool Selected
+14 -2
View File
@@ -16,11 +16,23 @@ namespace DepthsBelow
{ {
return 0; return 0;
} }
int baseHitChance = shooting.GetAim(); int baseHitChance = shooting.GetAim;
int baseDodgeChance = dodging.GetDodge(); int baseDodgeChance = dodging.GetDodge;
int basePenalty = shooting.Penalty((int)Vector2.Distance(attacker.GetComponent<Component.Transform>().World.Position, defender.GetComponent<Component.Transform>().World.Position) / Grid.TileSize); int basePenalty = shooting.Penalty((int)Vector2.Distance(attacker.GetComponent<Component.Transform>().World.Position, defender.GetComponent<Component.Transform>().World.Position) / Grid.TileSize);
int chanceToHit = baseHitChance - baseDodgeChance - basePenalty; int chanceToHit = baseHitChance - baseDodgeChance - basePenalty;
return chanceToHit; return chanceToHit;
} }
public static bool HitTest(Entity attacker, Entity defender, int chanceToHit)
{
Component.Stat shooting = attacker.GetComponent<Component.Stat>();
Component.Stat dodging = defender.GetComponent<Component.Stat>();
Random rand = new Random();
if (rand.Next(0, 100) < chanceToHit)
{
dodging.Life -= shooting.Strength - dodging.Defence / 2;
return true;
}
return false;
}
} }
} }