Tuesday, May 20, 2014

Hoardomatic Code: Enchantment Class

Enchantments are structurally very similar to Embellishments. The big difference is how costs are accounted for by the Item containing them.

Enchantment


String Enchantment_name: The name of the enchantment, usually just the name of a spell, though it may include a degree (Accuracy 3) or notation about which version of an enchantment the item has (Bravery (Cast only)).
Double cf: The embellishment's CF value. Not actually used, but it's there because I started enchantments by copying the embellishment class.
Double flat_cost: The base cost of the enchantment.
Double wt_mod: Weight adjustment, if any, which spells generally don't have.
String motif_option: Not used.
String ench_code: A code similar to the embellishment codes, indicating what kind of item the enchantment can be on. Most are generally applicable, but a few are limited to weapons or armor.

This class works very much like the Embellishments class: it takes a node provided to it and populates the enchantment's properties.

package hoardomatic;

import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;

public class Enchantment {
   
    private String Enchantment_name;
    private Double cf;
    private Double flat_cost;
    private Double wt_mod;
    private String motif_option;
    private String ench_code;

    public Enchantment() {

        Enchantment_name = "";
        cf = 0.0;
        flat_cost = 0.0;
        wt_mod = 1.0;
        motif_option = "";
        ench_code = "";
    }
   
    public Enchantment(Node node) {
        flat_cost = 0.0;

        NodeList tempNodes = node.getChildNodes();
        for (int j = 0; j < tempNodes.getLength(); j++) {
            Node subnode = tempNodes.item(j);

            if (subnode.getNodeType() == Node.ELEMENT_NODE) {
                Element element = (Element) subnode;
               
                if (element.getNodeName().contentEquals("Enchantment")) {
                    Enchantment_name = element.getTextContent();
                }

                if (element.getNodeName().contentEquals("CF")) {
                    cf =Double.parseDouble(element.getTextContent());
                }

                if (element.getNodeName().contentEquals("Cost")) {
                    flat_cost =Double.parseDouble(element.getTextContent());
                }

                if (element.getNodeName().contentEquals("wtmod")) {
                    wt_mod = Double.parseDouble(element.getTextContent());
                }

                if (element.getNodeName().contentEquals("ench_code")) {
                    ench_code = element.getTextContent();
                }

                if (element.getNodeName().contentEquals("Type")) {
                    ench_code = element.getTextContent();
                }

            }

        }

    }

   
   
    public Enchantment(String the_name, Double the_cf, Double the_wt_mod) {

        Enchantment_name = the_name;
        cf = the_cf;
        wt_mod = the_wt_mod;
    }
   
    public void setCost(Double new_cost){
        flat_cost = new_cost;
    }
   
    public Double getCost(){
        return flat_cost;
    }
   
    public void setCF(Double new_cf){
        cf = new_cf;
    }
   
   
    public String getEnchantmentName(){
        return Enchantment_name;
    }
   
    public String getMotifOption(){
        return motif_option;
    }
   
    public Double getCf(){
        return cf;
    }

    public Double getWtMod(){
        return wt_mod;
    }
   
    public String getenchCode(){
        return ench_code;
    }


}

No comments: