Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* This file is part of Arkhados.
- Arkhados is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation, either version 3 of the License, or
- (at your option) any later version.
- Arkhados is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
- You should have received a copy of the GNU General Public License
- along with Arkhados. If not, see <http://www.gnu.org/licenses/>. */
- package arkhados.controls;
- import arkhados.util.UserDataStrings;
- import com.jme3.math.FastMath;
- import com.jme3.renderer.RenderManager;
- import com.jme3.renderer.ViewPort;
- import com.jme3.scene.Spatial;
- import com.jme3.scene.control.AbstractControl;
- public class CCharacterHeal extends AbstractControl {
- private float recordLowHealth;
- @Override
- public void setSpatial(Spatial spatial) {
- super.setSpatial(spatial);
- recordLowHealth = spatial.getUserData(UserDataStrings.HEALTH_MAX);
- }
- public float getHealingCap() {
- return recordLowHealth + 400f;
- }
- public void regenerated(float health) {
- recordLowHealth += health;
- }
- public void tookDamage() {
- float currentHealth = (float) spatial.getUserData(UserDataStrings.HEALTH_CURRENT);
- if (recordLowHealth > currentHealth) {
- recordLowHealth = currentHealth;
- }
- }
- public float heal(float healing) {
- CInfluenceInterface me =
- spatial.getControl(CInfluenceInterface.class);
- if (me.isDead()) {
- return 0f;
- }
- // TODO: Healing mitigation from negative buff
- float maxHealth = spatial.getUserData(UserDataStrings.HEALTH_MAX);
- float healthBefore =
- spatial.getUserData(UserDataStrings.HEALTH_CURRENT);
- float health =
- FastMath.clamp(healthBefore + healing, healthBefore, maxHealth);
- if (health < getHealingCap()) {
- spatial.setUserData(UserDataStrings.HEALTH_CURRENT, health);
- return health - healthBefore;
- } else {
- spatial.setUserData(UserDataStrings.HEALTH_CURRENT, getHealingCap());
- return getHealingCap() - healthBefore;
- }
- }
- @Override
- protected void controlUpdate(float tpf) {
- }
- @Override
- protected void controlRender(RenderManager rm, ViewPort vp) {
- }
- }
- /* This file is part of Arkhados.
- Arkhados is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation, either version 3 of the License, or
- (at your option) any later version.
- Arkhados is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
- You should have received a copy of the GNU General Public License
- along with Arkhados. If not, see <http://www.gnu.org/licenses/>. */
- package arkhados.controls;
- import com.jme3.math.Vector3f;
- import com.jme3.renderer.RenderManager;
- import com.jme3.renderer.ViewPort;
- import com.jme3.scene.control.AbstractControl;
- /**
- *
- * @author Teemu
- */
- public class CResting extends AbstractControl {
- private float idleTime = 0;
- private Vector3f location = new Vector3f();
- public void stopRegen() {
- idleTime = 0;
- }
- private void regenerate(float tpf) {
- CCharacterHeal healing = spatial.getControl(CCharacterHeal.class);
- float healedFor = healing.heal(2.1f * idleTime * tpf);
- healing.regenerated(healedFor);
- }
- @Override
- protected void controlUpdate(float tpf) {
- Vector3f newLocation = getSpatial().getLocalTranslation();
- if (newLocation.distanceSquared(location) > 0.1) {
- idleTime = 0;
- }
- idleTime += tpf;
- if (idleTime >= 2.5f) {
- regenerate(tpf);
- }
- location.set(newLocation);
- }
- @Override
- protected void controlRender(RenderManager rm, ViewPort vp) {
- }
- }
- /* This file is part of Arkhados.
- Arkhados is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation, either version 3 of the License, or
- (at your option) any later version.
- Arkhados is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
- You should have received a copy of the GNU General Public License
- along with Arkhados. If not, see <http://www.gnu.org/licenses/>. */
- package arkhados.controls;
- import arkhados.util.UserDataStrings;
- import com.jme3.math.FastMath;
- import com.jme3.renderer.RenderManager;
- import com.jme3.renderer.ViewPort;
- import com.jme3.scene.control.AbstractControl;
- public class CCharacterDamage extends AbstractControl {
- public float doDamage(float damage, boolean canBreakCC) {
- CInfluenceInterface me =
- spatial.getControl(CInfluenceInterface.class);
- if (me.isDead()) {
- return 0f;
- }
- float healthBefore =
- spatial.getUserData(UserDataStrings.HEALTH_CURRENT);
- damage = me.mitigateDamage(damage);
- float health = FastMath.clamp(healthBefore - damage, 0, healthBefore);
- spatial.setUserData(UserDataStrings.HEALTH_CURRENT, health);
- if (health == 0.0f) {
- me.death();
- }
- if (canBreakCC) {
- me.removeDamageSensitiveBuffs();
- }
- spatial.getControl(CResting.class).stopRegen();
- spatial.getControl(CCharacterHeal.class).tookDamage();
- return healthBefore - health;
- }
- @Override
- protected void controlUpdate(float tpf) {
- }
- @Override
- protected void controlRender(RenderManager rm, ViewPort vp) {
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement