Advertisement
Guest User

Untitled

a guest
May 12th, 2016
176
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 5.91 KB | None | 0 0
  1. public class CharParameters {
  2.     private Array<Ability> abilities;
  3.     private Array<String> immunities;
  4.  
  5.     private LiveActor character;
  6.  
  7.     private final float maxSatiety = 100.0f;
  8.     private float maxHelath;
  9.  
  10.     private float health;
  11.     private float satiety;
  12.     private float radiation;
  13.  
  14.     private float starvingPerAction = 0.5f;
  15.     private float hpregen;
  16.  
  17.     private Attacker attacker;
  18.  
  19.     private float physDamage;
  20.     private float energyDamage;
  21.     private float radiateValue;
  22.     private float attackRange;
  23.  
  24.     private float physResist;
  25.     private float energyResist;
  26.     private float radiationResist;
  27.  
  28.     private float visionRange;
  29.  
  30.     public CharParameters(float health, Attacker attacker) {
  31.         immunities = new Array<String>();
  32.         abilities = new Array<Ability>();
  33.  
  34.         this.maxHelath = health;
  35.         this.health = health;
  36.  
  37.  
  38.         hpregen = 0.5f;
  39.         satiety = -1;
  40.         radiation = 0;
  41.         physDamage = 0;
  42.         energyDamage = 0;
  43.         radiateValue = 0;
  44.  
  45.         physResist = 0;
  46.         energyResist = 0;
  47.         radiationResist = 0;
  48.         attackRange = 1.5f;
  49.  
  50.         visionRange = 10;
  51.         setAttacker(attacker);
  52.     }
  53.  
  54.     public void setCharacter(LiveActor character) {
  55.         this.character = character;
  56.     }
  57.  
  58.     public void setDamage(float phys, float energy, float radiation) {
  59.         physDamage = phys;
  60.         energyDamage = energy;
  61.         radiateValue = radiation;
  62.     }
  63.  
  64.     public void setAttckRange(float range) {
  65.         attackRange = range;
  66.     }
  67.  
  68.     public float getAttackRange() {
  69.         return attackRange;
  70.     }
  71.  
  72.     public void setAttacker(Attacker attacker) {
  73.         this.attacker = attacker;
  74.         attacker.equip(this);
  75.     }
  76.  
  77.     public void setResists(float phys, float energy, float radiation) {
  78.         physResist = phys;
  79.         energyResist = energy;
  80.         radiationResist = radiation;
  81.     }
  82.  
  83.     public void addResists(float phys, float energy, float radiation) {
  84.         physResist += phys;
  85.         energyResist += energy;
  86.         radiationResist += radiation;
  87.     }
  88.  
  89.     public void multiplyResists(float phys, float energy, float radiation) {
  90.         physResist *= phys;
  91.         energyResist *= energy;
  92.         radiationResist *= radiation;
  93.     }
  94.  
  95.     public void addHpRegen(float regen) {
  96.         hpregen += regen;
  97.     }
  98.  
  99.     public void addDamage(float phys, float energy, float radiation) {
  100.         physDamage += phys;
  101.         energyDamage += energy;
  102.         radiateValue += radiation;
  103.     }
  104.  
  105.     public void multiplyDamage(float phys, float energy, float radiation) {
  106.         physDamage *= phys;
  107.         energyDamage *= energy;
  108.         radiateValue *= radiation;
  109.     }
  110.  
  111.     public void processDamage(float phys, float energy, float radiation, LiveActor damager) {
  112.         health -= phys * (1 - physResist) * MathUtils.random(0.9f, 1.1f);
  113.         health -= energy * (1 - energyResist) * MathUtils.random(0.8f, 1.2f);
  114.         this.radiation += radiation * (1 - radiationResist)* MathUtils.random(0.6f, 1.4f);
  115.     }
  116.  
  117.     public void attack(int x, int y) {
  118.         attacker.attack(physDamage, energyDamage, radiateValue, x, y, character);
  119.     }
  120.  
  121.     public void postAction() {
  122.         if(satiety != -1) {
  123.             if(satiety > 0) {
  124.                 satiety -= starvingPerAction;
  125.             }
  126.         }
  127.  
  128.         for(Ability b : abilities) {
  129.             b.postAction();
  130.             if(!b.isinfinite() && b.getRemaining() <= 0) {
  131.                 b.end();
  132.                 abilities.removeValue(b, true);
  133.             }
  134.         }
  135.     }
  136.  
  137.  
  138.     public void addBuff(String id, int duration) {
  139.         if(immunities.contains(id, false)) {
  140.             return;
  141.         }
  142.  
  143.         for(Ability b : abilities) {
  144.             if(b.getId().equals(id)) {
  145.                 if(duration == -1) b.setInfinite(true);
  146.                 else {
  147.                     if(b.getDuration() < duration) b.reset(duration);
  148.                 }
  149.                 return;
  150.             }
  151.         }
  152.  
  153.         Ability ability = null;
  154.         boolean infinite = (duration == -1);
  155.  
  156.         if(id.equals("bleeding")) {
  157.             ability = new Bleeding(this, duration, infinite);
  158.  
  159.         }
  160.         else if(id.equals("radiation")) {
  161.             ability = new Radiation(this, duration, infinite);
  162.         }
  163.  
  164.         ability.start();
  165.         abilities.add(ability);
  166.     }
  167.  
  168.     public void addImmunity(String id) {
  169.         if(!immunities.contains(id, false)) {
  170.             immunities.add(id);
  171.         }
  172.     }
  173.  
  174.     public void removeImmunity(String id) {
  175.         immunities.removeValue(id, false);
  176.     }
  177.  
  178.     public void removeBuff(String id) {
  179.         for(Ability b : abilities) {
  180.             if(b.getId().equals(id)) {
  181.                 abilities.removeValue(b, true);
  182.             }
  183.         }
  184.     }
  185.  
  186.     public void allowStarving() {
  187.         satiety = 100.0f;
  188.     }
  189.  
  190.     public void addSatiety(float val) {
  191.         satiety += val;
  192.         if(satiety >= maxSatiety) satiety = maxSatiety;
  193.     }
  194.  
  195.  
  196.     public void damage(float value) {
  197.         health -= value;
  198.         if(health < 0.0f) health = 0.0f;
  199.     }
  200.  
  201.     public void heal(float value) {
  202.         health += value;
  203.         if(health > maxHelath) health = maxHelath;
  204.     }
  205.  
  206.     public float getVisionRange() {
  207.         return visionRange;
  208.     }
  209.  
  210.     public Array<Ability> getAbilities() {
  211.         return abilities;
  212.     }
  213.  
  214.  
  215.     public float getPhysResist() {
  216.         return physResist;
  217.     }
  218.  
  219.     public float getEnergyResist() {
  220.         return energyResist;
  221.     }
  222.  
  223.     public float getRadiationResist() {
  224.         return radiationResist;
  225.     }
  226.  
  227.     public float getHealth() {
  228.         return health;
  229.     }
  230.     public float getMaxHelath() {
  231.         return maxHelath;
  232.     }
  233.  
  234.     public float getSatiety() {
  235.         return satiety;
  236.     }
  237.     public float getMaxSatiety() {
  238.         return maxSatiety;
  239.     }
  240.  
  241. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement