Back to project page MythTrack.
The source code is released under:
MIT License
If you think the Android project MythTrack listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
/** * Hero represents a single hero. It is meant to allow easier access to and modification of hero * attributes while reducing the amount of reads and writes to the database. */*ww w . j a v a2 s .c o m*/ * @author Nolan Jurgens */ package nolanjurgens.mythtrack.app; // IMPORTS ///////////////////////////////////////////////////////////////////////////////////////// import android.content.Context; import android.content.res.Resources; import nolanjurgens.mythtrack.R; import nolanjurgens.mythtrack.provider.MythTrackContract; //////////////////////////////////////////////////////////////////////////////////////////////////// // CLASS - Hero // //////////////////////////////////////////////////////////////////////////////////////////////////// public class Hero { // FIELDS //////////////////////////////////////////////////////////////////////////////////////// /** Object for accessing Android resources.*/ private Resources resources; // Hero stats. /** The hero's database ID.*/ private long id; /** The hero's name.*/ private String name; /** The hero's class ID.*/ private int classID; /** The hero's movement points.*/ private int movement; /** The hero's courage.*/ private int courage; /** The hero's threat level.*/ private int threat; /** The hero's vitality.*/ private int vitality; /** The hero's base vitality.*/ private int baseVitality; /** The hero's gold.*/ private int gold; /** The hero's serendipity.*/ private int serendipity; // Hero equipment. /** The hero's equipped primary item.*/ private Item primary; /** The hero's equipped secondary item.*/ private Item secondary; /** The hero's equipped armor.*/ private Item armor; /** The hero's equipped helm.*/ private Item helm; /** The hero's equipped accessory.*/ private Item accessory; // Inventory IDs for equipped items. /** The inventory ID of the hero's equipped primary item.*/ private long primaryID; /** The inventory ID of the hero's equipped secondary item.*/ private long secondaryID; /** The inventory ID of the hero's equipped armor.*/ private long armorID; /** The inventory ID of the hero's equipped helm.*/ private long helmID; /** The inventory ID of the hero's equipped accessory.*/ private long accessoryID; // METHODS /////////////////////////////////////////////////////////////////////////////////////// /** * Constructor */ public Hero(Context context) { // Get handle to resources. resources = context.getResources(); } /** * Returns the accessory ID. * @return The hero's accessory ID. */ public long getAccessoryID() { return accessoryID; } /** * Returns the accessory Item. * @return The hero's accessory Item. */ public Item getAccessoryItem() { return accessory; } /** * Returns the armor ID. * @return The hero's armor ID. */ public long getArmorID() { return armorID; } /** * Returns the armor Item. * @return The hero's armor Item. */ public Item getArmorItem() { return armor; } /** * Returns the hero's base vitality. * @return The hero's base vitality. */ public int getBaseVitality() { return baseVitality; } /** * Returns the hero's equipment cautious movement modifier. * @return The hero's equipment cautious movement modifier. */ public int getCautiousMovementModifier() { // Check for two-handed item in use. if(primaryID == secondaryID) { return primary.getCautiousMovementModifier() + armor.getCautiousMovementModifier() + helm.getCautiousMovementModifier() + accessory.getCautiousMovementModifier(); } else { return primary.getCautiousMovementModifier() + secondary.getCautiousMovementModifier() + armor.getCautiousMovementModifier() + helm.getCautiousMovementModifier() + accessory.getCautiousMovementModifier(); } } /** * Returns the hero's class. * @return The hero's class. */ public String getClassName() { switch(classID) { case MythTrackContract.Heroes.ACOLYTE: { return resources.getString(R.string.acolyte); } case MythTrackContract.Heroes.APPRENTICE: { return resources.getString(R.string.apprentice); } case MythTrackContract.Heroes.ARCHER: { return resources.getString(R.string.archer); } case MythTrackContract.Heroes.BRIGAND: { return resources.getString(R.string.brigand); } case MythTrackContract.Heroes.DRUID: { return resources.getString(R.string.druid); } case MythTrackContract.Heroes.SKALD: { return resources.getString(R.string.skald); } case MythTrackContract.Heroes.SOLDIER: { return resources.getString(R.string.soldier); } case MythTrackContract.Heroes.SPRIGGAN: { return resources.getString(R.string.spriggan); } case MythTrackContract.Heroes.TRICKSTER: { return resources.getString(R.string.trickster); } default: { return resources.getString(R.string.invalid_class); } } } /** * Returns the hero's class ID. * @return The hero's class ID. */ public int getClassID() { return classID; } /** * Returns the hero's courage level. * @return The hero's courage level. */ public int getCourage() { return courage; } /** * Returns the hero's equipment courage modifier. * @return The hero's equipment courage modifier. */ public int getCourageModifier() { // Check for two-handed item in use. if(primaryID == secondaryID) { return primary.getCourageModifier() + armor.getCourageModifier() + helm.getCourageModifier() + accessory.getCourageModifier(); } else { return primary.getCourageModifier() + secondary.getCourageModifier() + armor.getCourageModifier() + helm.getCourageModifier() + accessory.getCourageModifier(); } } /** * Returns the amount of gold the hero has. * @return The hero's amount of gold. */ public int getGold() { return gold; } /** * Returns the helm ID. * @return The hero's helm ID. */ public long getHelmID() { return helmID; } /** * Returns the helm Item. * @return The hero's helm Item. */ public Item getHelmItem() { return helm; } /** * Returns the hero's unique database ID. * @return The hero's ID. */ public long getID() { return id; } /** * Returns the hero's equipment minimum threat modifier. * @return The hero's equipment minimum threat modifier. */ public int getMinThreat() { int minThreat = 0; if(primary.getMinThreat() > minThreat) { minThreat = primary.getMinThreat(); } if(secondary.getMinThreat() > minThreat) { minThreat = secondary.getMinThreat(); } if(armor.getMinThreat() > minThreat) { minThreat = armor.getMinThreat(); } if(helm.getMinThreat() > minThreat) { minThreat = helm.getMinThreat(); } if(accessory.getMinThreat() > minThreat) { minThreat = accessory.getMinThreat(); } return minThreat; } /** * Returns the hero's equipment maximum threat modifier. * @return The hero's equipment maximum threat modifier. */ public int getMaxThreat() { int maxThreat = 10; if(primary.getMaxThreat() < maxThreat) { maxThreat = primary.getMaxThreat(); } if(secondary.getMaxThreat() < maxThreat) { maxThreat = secondary.getMaxThreat(); } if(armor.getMaxThreat() < maxThreat) { maxThreat = armor.getMaxThreat(); } if(helm.getMaxThreat() < maxThreat) { maxThreat = helm.getMaxThreat(); } if(accessory.getMaxThreat() < maxThreat) { maxThreat = accessory.getMaxThreat(); } return maxThreat; } /** * Returns the hero's number of movement points. * @return The hero's movement points. */ public int getMovement() { return movement; } /** * Returns the hero's equipment movement points modifier. * @return The hero's equipment movement points modifier. */ public int getMovementPointsModifier() { // Check for two-handed item in use. if(primaryID == secondaryID) { return primary.getMovementPointsModifier() + armor.getMovementPointsModifier() + helm.getMovementPointsModifier() + accessory.getMovementPointsModifier(); } else { return primary.getMovementPointsModifier() + secondary.getMovementPointsModifier() + armor.getMovementPointsModifier() + helm.getMovementPointsModifier() + accessory.getMovementPointsModifier(); } } /** * Returns the hero's name. * @return The hero's name. */ public String getName() { return name; } /** * Returns the hero's equipment non-combat action modifier. * @return The hero's equipment non-combat action modifier. */ public int getNonCombatActionModifier() { // Check for two-handed item in use. if(primaryID == secondaryID) { return primary.getNonCombatActionModifier() + armor.getNonCombatActionModifier() + helm.getNonCombatActionModifier() + accessory.getNonCombatActionModifier(); } else { return primary.getNonCombatActionModifier() + secondary.getNonCombatActionModifier() + armor.getNonCombatActionModifier() + helm.getNonCombatActionModifier() + accessory.getNonCombatActionModifier(); } } /** * Returns the primary ID. * @return The hero's primary ID. */ public long getPrimaryID() { return primaryID; } /** * Returns the primary Item. * @return The hero's primary Item. */ public Item getPrimaryItem() { return primary; } /** * Returns the secondary ID. * @return The hero's secondary ID. */ public long getSecondaryID() { return secondaryID; } /** * Returns the secondary Item. * @return The hero's secondary Item. */ public Item getSecondaryItem() { return secondary; } /** * Returns the amount of serendipity the hero has. * @return The hero's amount of serendipity. */ public int getSerendipity() { return serendipity; } /** * Returns the hero's threat level. * @return The hero's threat level. */ public int getThreat() { return threat; } /** * Returns the hero's vitality. * @return The hero's vitality. */ public int getVitality() { return vitality; } /** * Returns the hero's equipment vitality modifier. * @return The hero's equipment vitality modifier. */ public int getVitalityModifier() { // Check for two-handed item in use. if(primaryID == secondaryID) { return primary.getVitalityModifier() + armor.getVitalityModifier() + helm.getVitalityModifier() + accessory.getVitalityModifier(); } else { return primary.getVitalityModifier() + secondary.getVitalityModifier() + armor.getVitalityModifier() + helm.getVitalityModifier() + accessory.getVitalityModifier(); } } /** * Set the hero's accessory ID. * @param accessoryID The inventory ID to set as the accessory ID. */ public void setAccessoryID(long accessoryID) { this.accessoryID = accessoryID; } /** * Set the hero's accessory Item. * @param accessory The Item to set as the accessory. */ public void setAccessoryItem(Item accessory) { this.accessory = accessory; } /** * Set the hero's armor ID. * @param armorID The inventory ID to set as the armor ID. */ public void setArmorID(long armorID) { this.armorID = armorID; } /** * Set the hero's armor Item. * @param armor The Item to set as the armor. */ public void setArmorItem(Item armor) { this.armor = armor; } /** * Sets the hero's base vitality. * @param baseVitality The hero's base vitality. */ public void setBaseVitality(int baseVitality) { this.baseVitality = baseVitality; } /** * Sets the hero's class ID. * @param classID The new class ID value. */ public void setClassID(int classID) { this.classID = classID; } /** * Set the hero's courage level. * @param courage The hero's courage level. */ public void setCourage(int courage) { this.courage = courage; } /** * Set the hero's amount of gold. * @param gold The hero's amount of gold. */ public void setGold(int gold) { this.gold = gold; } /** * Set the hero's helm ID. * @param helmID The inventory ID to set as the helm ID. */ public void setHelmID(long helmID) { this.helmID = helmID; } /** * Set the hero's helm Item. * @param helm The Item to set as the helm. */ public void setHelmItem(Item helm) { this.helm = helm; } /** * Sets the hero's unique ID. * @param id The hero's ID. */ public void setID(long id) { this.id = id; } /** * Set the hero's movement points. * @param movement The hero's movement points. */ public void setMovement(int movement) { this.movement = movement; } /** * Sets the hero's name. * @param name The new name value. */ public void setName(String name) { this.name = name; } /** * Set the hero's primary ID. * @param primaryID The inventory ID to set as the primary ID. */ public void setPrimaryID(long primaryID) { this.primaryID = primaryID; } /** * Set the hero's primary Item. * @param primary The Item to set as the primary. */ public void setPrimaryItem(Item primary) { this.primary = primary; } /** * Set the hero's secondary ID. * @param secondaryID The inventory ID to set as the secondary ID. */ public void setSecondaryID(long secondaryID) { this.secondaryID = secondaryID; } /** * Set the hero's secondary Item. * @param secondary The Item to set as the secondary. */ public void setSecondaryItem(Item secondary) { this.secondary = secondary; } /** * Set the hero's amount of serendipity. * @param serendipity The hero's amount of serendipity. */ public void setSerendipity(int serendipity) { this.serendipity = serendipity; } /** * Set the hero's threat level. * @param threat The hero's threat level. */ public void setThreat(int threat) { this.threat = threat; } /** * Set the hero's vitality. * @param vitality The hero's vitality. */ public void setVitality(int vitality) { this.vitality = vitality; } }