Advertisement
Guest User

Untitled

a guest
May 30th, 2015
228
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 6.25 KB | None | 0 0
  1. /*    This file is part of Arkhados.
  2.  
  3.  Arkhados is free software: you can redistribute it and/or modify
  4.  it under the terms of the GNU General Public License as published by
  5.  the Free Software Foundation, either version 3 of the License, or
  6.  (at your option) any later version.
  7.  
  8.  Arkhados is distributed in the hope that it will be useful,
  9.  but WITHOUT ANY WARRANTY; without even the implied warranty of
  10.  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  11.  GNU General Public License for more details.
  12.  
  13.  You should have received a copy of the GNU General Public License
  14.  along with Arkhados.  If not, see <http://www.gnu.org/licenses/>. */
  15. package arkhados.controls;
  16.  
  17. import arkhados.util.UserDataStrings;
  18. import com.jme3.math.FastMath;
  19. import com.jme3.renderer.RenderManager;
  20. import com.jme3.renderer.ViewPort;
  21. import com.jme3.scene.Spatial;
  22. import com.jme3.scene.control.AbstractControl;
  23.  
  24. public class CCharacterHeal extends AbstractControl {
  25.  
  26.     private float recordLowHealth;
  27.  
  28.     @Override
  29.     public void setSpatial(Spatial spatial) {
  30.         super.setSpatial(spatial);
  31.         recordLowHealth = spatial.getUserData(UserDataStrings.HEALTH_MAX);
  32.     }
  33.  
  34.     public float getHealingCap() {
  35.         return recordLowHealth + 400f;
  36.     }
  37.  
  38.     public void regenerated(float health) {
  39.         recordLowHealth += health;
  40.     }
  41.  
  42.     public void tookDamage() {
  43.         float currentHealth = (float) spatial.getUserData(UserDataStrings.HEALTH_CURRENT);
  44.         if (recordLowHealth > currentHealth) {
  45.             recordLowHealth = currentHealth;
  46.         }
  47.     }
  48.  
  49.     public float heal(float healing) {
  50.         CInfluenceInterface me =
  51.                 spatial.getControl(CInfluenceInterface.class);
  52.         if (me.isDead()) {
  53.             return 0f;
  54.         }
  55.         // TODO: Healing mitigation from negative buff
  56.         float maxHealth = spatial.getUserData(UserDataStrings.HEALTH_MAX);
  57.         float healthBefore =
  58.                 spatial.getUserData(UserDataStrings.HEALTH_CURRENT);
  59.         float health =
  60.                 FastMath.clamp(healthBefore + healing, healthBefore, maxHealth);
  61.         if (health < getHealingCap()) {
  62.             spatial.setUserData(UserDataStrings.HEALTH_CURRENT, health);
  63.             return health - healthBefore;
  64.         } else {
  65.             spatial.setUserData(UserDataStrings.HEALTH_CURRENT, getHealingCap());
  66.             return getHealingCap() - healthBefore;
  67.         }
  68.     }
  69.  
  70.     @Override
  71.     protected void controlUpdate(float tpf) {
  72.     }
  73.  
  74.     @Override
  75.     protected void controlRender(RenderManager rm, ViewPort vp) {
  76.     }
  77. }
  78.  
  79.  
  80. /*    This file is part of Arkhados.
  81.  
  82.  Arkhados is free software: you can redistribute it and/or modify
  83.  it under the terms of the GNU General Public License as published by
  84.  the Free Software Foundation, either version 3 of the License, or
  85.  (at your option) any later version.
  86.  
  87.  Arkhados is distributed in the hope that it will be useful,
  88.  but WITHOUT ANY WARRANTY; without even the implied warranty of
  89.  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  90.  GNU General Public License for more details.
  91.  
  92.  You should have received a copy of the GNU General Public License
  93.  along with Arkhados.  If not, see <http://www.gnu.org/licenses/>. */
  94. package arkhados.controls;
  95.  
  96. import com.jme3.math.Vector3f;
  97. import com.jme3.renderer.RenderManager;
  98. import com.jme3.renderer.ViewPort;
  99. import com.jme3.scene.control.AbstractControl;
  100.  
  101. /**
  102.  *
  103.  * @author Teemu
  104.  */
  105. public class CResting extends AbstractControl {
  106.  
  107.     private float idleTime = 0;
  108.     private Vector3f location = new Vector3f();
  109.  
  110.     public void stopRegen() {
  111.         idleTime = 0;
  112.     }
  113.  
  114.     private void regenerate(float tpf) {
  115.         CCharacterHeal healing = spatial.getControl(CCharacterHeal.class);
  116.         float healedFor = healing.heal(2.1f * idleTime * tpf);
  117.         healing.regenerated(healedFor);
  118.     }
  119.  
  120.     @Override
  121.     protected void controlUpdate(float tpf) {
  122.         Vector3f newLocation = getSpatial().getLocalTranslation();
  123.         if (newLocation.distanceSquared(location) > 0.1) {
  124.             idleTime = 0;
  125.         }
  126.         idleTime += tpf;
  127.         if (idleTime >= 2.5f) {
  128.             regenerate(tpf);
  129.         }
  130.         location.set(newLocation);
  131.     }
  132.  
  133.     @Override
  134.     protected void controlRender(RenderManager rm, ViewPort vp) {
  135.     }
  136. }
  137.  
  138. /*    This file is part of Arkhados.
  139.  
  140.  Arkhados is free software: you can redistribute it and/or modify
  141.  it under the terms of the GNU General Public License as published by
  142.  the Free Software Foundation, either version 3 of the License, or
  143.  (at your option) any later version.
  144.  
  145.  Arkhados is distributed in the hope that it will be useful,
  146.  but WITHOUT ANY WARRANTY; without even the implied warranty of
  147.  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  148.  GNU General Public License for more details.
  149.  
  150.  You should have received a copy of the GNU General Public License
  151.  along with Arkhados.  If not, see <http://www.gnu.org/licenses/>. */
  152. package arkhados.controls;
  153.  
  154. import arkhados.util.UserDataStrings;
  155. import com.jme3.math.FastMath;
  156. import com.jme3.renderer.RenderManager;
  157. import com.jme3.renderer.ViewPort;
  158. import com.jme3.scene.control.AbstractControl;
  159.  
  160. public class CCharacterDamage extends AbstractControl {
  161.  
  162.     public float doDamage(float damage, boolean canBreakCC) {
  163.         CInfluenceInterface me =
  164.                 spatial.getControl(CInfluenceInterface.class);
  165.         if (me.isDead()) {
  166.             return 0f;
  167.         }
  168.  
  169.         float healthBefore =
  170.                 spatial.getUserData(UserDataStrings.HEALTH_CURRENT);
  171.  
  172.         damage = me.mitigateDamage(damage);
  173.  
  174.         float health = FastMath.clamp(healthBefore - damage, 0, healthBefore);
  175.         spatial.setUserData(UserDataStrings.HEALTH_CURRENT, health);
  176.  
  177.         if (health == 0.0f) {
  178.             me.death();
  179.         }
  180.  
  181.         if (canBreakCC) {
  182.             me.removeDamageSensitiveBuffs();
  183.         }
  184.  
  185.         spatial.getControl(CResting.class).stopRegen();
  186.         spatial.getControl(CCharacterHeal.class).tookDamage();
  187.  
  188.         return healthBefore - health;
  189.     }
  190.  
  191.     @Override
  192.     protected void controlUpdate(float tpf) {
  193.     }
  194.  
  195.     @Override
  196.     protected void controlRender(RenderManager rm, ViewPort vp) {
  197.     }
  198. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement