Android Open Source - ubisoldiers Item






From Project

Back to project page ubisoldiers.

License

The source code is released under:

MIT License

If you think the Android project ubisoldiers listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.github.gobbisanches.ubisoldiers.mechanics;
//from   w  ww .j av a  2 s .  c  o m
import java.io.Serializable;
import java.util.Comparator;

/**
 * Created by Sanches on 06/07/2014.
 */
public class Item implements Serializable, Comparable {
    public enum Rarity {Common, Uncommon, Rare, Epic, Legendary}
    private static final long serialVersionUID = 1L;

    private int id;
    private Rarity rarity;
    private String name;
    private double attack;
    private double defense;
    private Integer quality;

    public Item(int id, Rarity rarity, String name, double attack, double defense) {
        this.id = id;
        this.rarity = rarity;
        this.name = name;
        this.attack = attack;
        this.defense = defense;
        this.quality = PolicyManager.getRules().calculateQualityOf(this);
    }

    public Item(Item other) {
        this.id = other.id;
        this.rarity = other.rarity;
        this.name = other.name;
        this.attack = other.attack;
        this.defense = other.defense;
    }

    public int getId() {
        return id;
    }

    public Integer getIdAsInteger() {
        return Integer.valueOf(id);
    }

    public Rarity getRarity() {
        return rarity;
    }

    public Integer getQuality() {
        return quality;
    }

    public String getName() {
        return name;
    }

    public double getAttack() {
        return attack;
    }

    public double getDefense() {
        return defense;
    }

    @Override
    public String toString() {
        return "Item{" +
                "id=" + id +
                ", rarity=" + rarity +
                ", name='" + name + '\'' +
                ", attack=" + attack +
                ", defense=" + defense +
                '}';
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (!(o instanceof Item)) return false;

        Item item = (Item) o;

        if (id != item.id) return false;

        return true;
    }

    @Override
    public int hashCode() {
        return id;
    }

    @Override
    public int compareTo(Object o) {
        if(o == null) {
            return -1;
        }

        if(!(o instanceof Item)) {
            return -1;
        }

        Item otherItem = (Item) o;
        return id - otherItem.id;
    }

    public static class ItemQualityComparator implements Comparator<Item> {
        public ItemQualityComparator() {
        }

        @Override
        public int compare(Item item1, Item item2) {
            int qualityDiff =  item1.getQuality() - item2.getQuality();
            if (qualityDiff == 0) {
                // no draw is possible for different cards
                return item1.getId() - item2.getId();
            } else {
                return qualityDiff;
            }

        }
    }
}




Java Source Code List

com.github.gobbisanches.ubisoldiers.app.ArmyFragment.java
com.github.gobbisanches.ubisoldiers.app.BattleActivity.java
com.github.gobbisanches.ubisoldiers.app.BattleFragment.java
com.github.gobbisanches.ubisoldiers.app.ItemListFragment.java
com.github.gobbisanches.ubisoldiers.app.MainActivity.java
com.github.gobbisanches.ubisoldiers.app.ResourceManager.java
com.github.gobbisanches.ubisoldiers.app.SingleFragmentActivity.java
com.github.gobbisanches.ubisoldiers.app.UbisoldierUosApplication.java
com.github.gobbisanches.ubisoldiers.app.UbisoldiersDriver.java
com.github.gobbisanches.ubisoldiers.app.UnitCustomizationActivity.java
com.github.gobbisanches.ubisoldiers.app.UnitCustomizationFragment.java
com.github.gobbisanches.ubisoldiers.app.UnitFragment.java
com.github.gobbisanches.ubisoldiers.app.UosManager.java
com.github.gobbisanches.ubisoldiers.mechanics.Armor.java
com.github.gobbisanches.ubisoldiers.mechanics.BattleLogEntry.java
com.github.gobbisanches.ubisoldiers.mechanics.BattleLogParser.java
com.github.gobbisanches.ubisoldiers.mechanics.BattleLog.java
com.github.gobbisanches.ubisoldiers.mechanics.BattleSquad.java
com.github.gobbisanches.ubisoldiers.mechanics.BattleUnit.java
com.github.gobbisanches.ubisoldiers.mechanics.Battle.java
com.github.gobbisanches.ubisoldiers.mechanics.DefaultGameRules.java
com.github.gobbisanches.ubisoldiers.mechanics.GameRules.java
com.github.gobbisanches.ubisoldiers.mechanics.General.java
com.github.gobbisanches.ubisoldiers.mechanics.ItemCollection.java
com.github.gobbisanches.ubisoldiers.mechanics.Item.java
com.github.gobbisanches.ubisoldiers.mechanics.MechanicsEngine.java
com.github.gobbisanches.ubisoldiers.mechanics.PolicyManager.java
com.github.gobbisanches.ubisoldiers.mechanics.SearchEngine.java
com.github.gobbisanches.ubisoldiers.mechanics.Soldier.java
com.github.gobbisanches.ubisoldiers.mechanics.Squad.java
com.github.gobbisanches.ubisoldiers.mechanics.Unit.java
com.github.gobbisanches.ubisoldiers.mechanics.Weapon.java