Skip to main content

Hoardomatic Code: Gem Class

Last class. Gems have their own bundle of properties, so they get their own class.

Gem


String gem_name: Name of the gem.
Double val_constant: The value constant for the stone, the V in the(C^2 + C*4) * V value formula.
Double carats: Weight of the gem in carats.

This one is similar to the previous two, but it takes on itself the task of randomly selecting a node from Gems.xml to turn into an object.   

package hoardomatic;

import java.io.File;
import java.io.FileInputStream;
import java.io.InputStream;
import java.util.Random;

import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;

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

public class Gem {

    private String gem_name;
    private Double val_constant;
    private Double carats;
   
    public Gem() {
        // TODO Auto-generated constructor stub
        Node gemnode = getRandomNodeFromTable("Gems.xml");
       
        NodeList tempNodes = gemnode.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("Gem")) {
                    gem_name = element.getTextContent();
                }

                if (element.getNodeName().contentEquals("V")) {
                    val_constant =Double.parseDouble(element.getTextContent());
                }

            }

        }
       
        double dr = (double) dieRoll(1,6) + dieRoll(1,6);
        double the_carats = dr/4;
       
        int get_big = dieRoll(1,12);
        while (get_big == 12){
            the_carats = the_carats + dieRoll(1,6);
            get_big = dieRoll(1,12);
        }
       
        carats = the_carats;
       
    }
   
   
        public Node getRandomNodeFromTable(String fname) {
           
            Node return_it;
            return_it = null;

            try {
                InputStream items = new FileInputStream(new File(fname));
               
                DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
                DocumentBuilder dBuilder = dbFactory.newDocumentBuilder();
                Document doc = dBuilder.parse(items);

                doc.getDocumentElement().normalize();
                // System.out.println(doc.getDocumentElement().getNodeName());
                NodeList nodes = doc.getElementsByTagName("item");
               
                Integer itemlistlen = nodes.getLength();
               
                Integer pickItm = dieRoll(0, itemlistlen - 1);
               
                // System.out.println("==========================");
//                System.out.println(pickItm);

                for (int i = 0; i < nodes.getLength(); i++) {
                    Node node = nodes.item(i);
                    if (i == pickItm) {
                        return_it = node;
                    }
                }

            } catch (Exception e) {
                e.printStackTrace();
            }
            return return_it;
        }
   
   
    public Gem(Node gemnode){
       
       
        NodeList tempNodes = gemnode.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("Gem")) {
                    gem_name = element.getTextContent();
                }

                if (element.getNodeName().contentEquals("V")) {
                    val_constant =Double.parseDouble(element.getTextContent());
                }

            }

        }
       
       
        double the_carats = (dieRoll(1,6) + dieRoll(1,6))/4;
       
        int get_big = dieRoll(1,12);
        while (get_big == 12){
            the_carats = the_carats + dieRoll(1,6);
            get_big = dieRoll(1,12);
        }
       
        carats = the_carats;
       
       
    }
   
    public Double getGemCost(){
        Double return_it = 0.0;
        // (c^2 + 4 x c) ^ v
        return_it = (carats * carats + 4 * carats) * val_constant;
        return return_it;
    }
   
    public String getGemName(){
        return gem_name;
    }
   
    public Double getGemWt(){
        return carats;
    }
   
    private int dieRoll(Integer min, Integer max) {

        Random r = new Random();
        int inroll = r.nextInt(max - min + 1) + min;
        return inroll;
    }


}

Comments

Popular posts from this blog

Spaced Out Rides

(This is the kind of thing I'd have sent into Pyramid   back in the day, but that's not an option now, so here we are.)   The GURPS Action series is the gift that keeps on giving for a lot of modern-and-later gaming. GURPS Action 2: Exploits has rules for sneaking around, running away, and all kinds of other activities which can be easily transplanted to cyberpunk and other high-tech settings. GURPS Action 6: Tricked-Out Rides provides more of the same for its topic, giving an easy framework for describing and even designing common types of vehicles without all the math and paralysis-by-analysis of GURPS Vehicles. Pick a standardized vehicle type (van, compact car, etc.) and apply modifiers (rugged, tinted windows). But, of course, it’s limited. It’s just ten pages, after all, so it’s great for common passenger vehicles for the modern(ish) era. But higher-tech vehic...

G$ --> DND GP

A GURPS $ is worth 1.27 D&D 5e SP, which is interesting because in GURPS Dungeon Fantasy, the typical $1 coin is a silver piece. And a D&D GP is worth about $7.87 in GURPS. So, where does that come from? A while back, I cautioned someone considering using (among other things) GURPS Renaissance Venice: Merchants of Venice  in a non-GURPS game that prices listed in the extensive lists of trade goods were expressed in GURPS $, which might not have obvious conversions into other game systems. But if one wanted to convert GURPS prices into D&D or vice versa, how would that work? It crossed my mind to take a "basket of goods" approach. Economists measure inflation not by picking a single commodity, like the price of gold or oil or wheat, and seeing how that changes over time, but by taking the combined value of a set of common commodities. This provides a more comprehensive picture of the cost of living. Perhaps gas becomes less expensive while the price of whe...

2020 GURPS Challenge PDFs: Incense Trail prices

Over on the forum, somebody asked me how much frankincense and myrrh cost in antiquity. Well, we don't know. We never get as much price information as we like out of history. There's the occasional mention of this or that product being worth its weight in silver or gold, but we can reasonably believe that those are descriptions written by political, cultural, or philosophical commentators trying to give an idea of how expensive things are, not people who have actually done an economic analysis and discovered that the material in question is, by coincidence, exactly the same value as silver or gold and not, say, one and a half times the price of silver or three quarters of the price of gold. We know it was valuable, but not how valuable on the level of individual purchases. But for the convenience of the GM, we can use those comparisons to establish some ballpark figures. Mind you, this is based largely on GURPS rather than historical sources, so it's not something I would h...