Skip to content
Snippets Groups Projects
Select Git revision
  • a0fd7d5c290db7ee88d981e2ebf0593e05968803
  • master default protected
  • development
  • gh-pages
4 results

index.doctree

Blame
  • Health.java 3.33 KiB
    package Character;
    
    import javafx.beans.property.SimpleIntegerProperty;
    
    import java.util.ArrayList;
    import java.util.Collections;
    
    public class Health {
        private final ArrayList<Integer> healthBoxes = new ArrayList<>();
        private SimpleIntegerProperty numberOfHealth = new SimpleIntegerProperty(0);
    
        private int bashing = 0;
        private int lethal = 0;
        private int agg = 0;
    
        /**
         * @param base Basic health boxes
         * @param oxBody Health boxes per ox-body
         * @param oxBodies Number of ox-bodies purchased
         */
        public Health(int[] base, int[] oxBody, int oxBodies) {
            //Add base health boxes
            for(int box : base) {
                healthBoxes.add(box);
            }
            //Add ox body health boxes
            for(int i =0 ; i < oxBodies; i++) {
                for(int box : oxBody) {
                    healthBoxes.add(box);
                }
            }
            sort();
        }
    
        /**
         * Sort list & update length
         */
        public void sort() {
            //Sort health boxes in order
            Collections.sort(healthBoxes);
            //Update number of health
            numberOfHealth.set(healthBoxes.size());
        }
    
        /**
         * Add Health boxes
         */
        public void gainMaxHealth(int[] boxes) {
            for(int box:boxes) {
                healthBoxes.add(box);
            }
            sort();
        }
    
        /**
         * Remove Health boxes
         */
        public void loseMaxHealth(int[] boxes) {
            //Remove given health boxes
            for(int box:boxes) {
                healthBoxes.remove(Integer.valueOf(box));
            }
            sort();
    
            //If new health levels lower than current damage, resolve
            if(bashing > numberOfHealth.get()) {
                bashingDamage(0);
            }
            if(lethal > numberOfHealth.get()) {
                lethalDamage(0);
            }
            if(agg > numberOfHealth.get()) {
                aggDamage(0);
            }
        }
    
        /**
         * Take bashing damage
         */
        public void bashingDamage(int damage) {
            if(bashing + damage > numberOfHealth.get()) {
                bashing = numberOfHealth.get();
                lethalDamage(bashing + damage - numberOfHealth.get());
            } else {
                bashing += damage;
            }
        }
    
        /**
         * Take lethal damage
         */
        public void lethalDamage(int damage) {
            if(lethal + damage > numberOfHealth.get()) {
                lethal = numberOfHealth.get();
                aggDamage(lethal + damage - numberOfHealth.get());
            } else {
                lethal += damage;
            }
            if(bashing < lethal) {
                bashing = lethal;
            }
        }
    
        /**
         * Take agg damage
         */
        public void aggDamage(int damage) {
            if(agg + damage > numberOfHealth.get()) {
                agg = numberOfHealth.get();
                death(agg + damage - numberOfHealth.get());
            } else {
                agg += damage;
            }
            if(lethal < agg) {
                lethal = agg;
            }
        }
    
        /**
         * When agg damage == health
         */
        public void death(int damage) {
    
        }
    
        /**
         * Assorted getting list
         */
        public SimpleIntegerProperty getNumberOfHealth() {
            return numberOfHealth;
        }
        public int getBashing() {
            return bashing;
        }
        public int getLethal() {
            return lethal;
        }
        public int getAgg() {
            return agg;
        }
        public ArrayList<Integer> getHealthBoxes() {
            return healthBoxes;
        }
    }