package com.github.pkunk.progressquest.gameplay;

import java.util.ArrayList;
import java.util.List;

/**
 * User: pkunk
 * Date: 2012-01-01
 */
public class Stats extends ArrayList<Integer> {
    public static final int STR  = 0;
    public static final int CON  = 1;
    public static final int DEX  = 2;
    public static final int INT  = 3;
    public static final int WIS  = 4;
    public static final int CHA  = 5;

    public static final int BASE_STATS_NUM = CHA + 1;

    public static final int HP_MAX = 6;
    public static final int MP_MAX = 7;

    public static final String[] label = new String[] {
            "STR",
            "CON",
            "DEX",
            "INT",
            "WIS",
            "CHA",
            "HP max",
            "SP max"
    };

    public static final int STATS_NUM = label.length;

    public Stats(int[] stats) {
        super(STATS_NUM);
        if (STATS_NUM != stats.length) {
            throw new IllegalArgumentException("Number of stats is wrong");
        }
        for (int i=0; i< STATS_NUM; i++) {
            add(stats[i]);
        }
    }

    public void inc(int key, int value) {
        set(key, get(key) + value);
    }

    public void dec(int key, int value) {
        set(key, get(key) - value);
    }

    public List<String> saveStats() {
        List<String> result = new ArrayList<String>(STATS_NUM);
        for (Integer stat : this) {
            result.add(String.valueOf(stat));
        }
        return result;
    }

    public static Stats loadStats(List<String> strings) {
        int[] array = new int[strings.size()];
        for (int i=0; i<array.length; i++) {
            array[i] = Integer.getInteger(strings.get(i));
        }
        return new Stats(array);
    }
}

@@ -1261,32 +1261,238 @@
  value);%0A    %7D%0A%0A
+    public static Stats newBonuses(int... bonuses) %7B%0A%0A        int%5B%5D stats = new int%5BSTATS_NUM%5D;%0A%0A        for (int i : bonuses) %7B%0A            stats%5Bi%5D = 1;%0A        %7D%0A%0A        return new Stats(stats);%0A    %7D%0A%0A
     public List%3C

add stat bonuses