Android Open Source - ubisoldiers Default Game Rules






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;
/* www  .jav a 2 s  .c o m*/
import android.location.Location;
import android.util.Log;

import java.util.Calendar;
import java.util.Date;
import java.util.Random;

import static com.github.gobbisanches.ubisoldiers.mechanics.Item.Rarity.*;
import static java.lang.Math.floor;

/**
 * Created by Sanches on 29/06/2014.
 */
public class DefaultGameRules implements GameRules {
    private Location baseLocation;

    public DefaultGameRules() {
        baseLocation = new Location("");
        baseLocation.setLatitude(-15.76243);
        baseLocation.setLongitude(-47.87004);
    }

    @Override
    public Integer calculateHitPointsForUnit(Unit unit) {
        return ((int) floor(unit.getDefense() * 10));
    }

    @Override
    public Integer calculateDamage(Random random, Unit attacker, Unit defender) {
        double randomValue = random.nextDouble();
        int damage = (int)Math.floor(Math.max(attacker.getAttack() * (2+2* randomValue), 0));

        Log.d("UBISOLDIERS", "Damage = " + damage + ", with attack=" + attacker.getAttack() +
                ", with defense=" + defender.getDefense() +
                " and randomValue=" + randomValue);

        return new Integer(damage);
    }

    @Override
    public Integer calculateQualityOf(Item item) {
        int quality = 0;

        switch(item.getRarity()) {
            case Common: quality += 1000;
                break;
            case Uncommon: quality += 500;
                break;
            case Rare: quality += 300;
                break;
            case Epic: quality += 50;
                break;
            case Legendary: quality += 10;
                break;
            default: throw new RuntimeException("Invalid item rarity " + item.getRarity());
        }

        return new Integer(quality);
    }

    @Override
    public Double calculateSearchModifier(Location location, Long wifiStrength) {
        // modifier is a number between 0.6 and 1.4 (+/- 30%)

        // locationModifier is a number between -0.3 and 0.3 (+/- 30%)
        long distanceInKm = (long) Math.floor(Math.abs(location.distanceTo(baseLocation) / 1000));
        Calendar calendar = Calendar.getInstance();
        calendar.setTimeInMillis(location.getTime());

        long dayOfMonth = calendar.get(Calendar.DAY_OF_MONTH);
        double locationComponent = distanceInKm + dayOfMonth;
        double locationModifier = (((locationComponent % 30) - 15)*2 / 100);

        double wifiComponent = ((((double)wifiStrength) / 500) - 0.1);
        double wifiModifier = Math.max(Math.min(wifiComponent, 0.1), -0.1);

        double modifier = Math.max(Math.min(1 + locationModifier + wifiModifier, 1.3), 0.7);

        Log.d("UBISOLDIERS", "[CALCULATE SEARCH MODIFIER] distance = " + distanceInKm);
        Log.d("UBISOLDIERS", "[CALCULATE SEARCH MODIFIER] wifiStrength = " + wifiStrength);
        Log.d("UBISOLDIERS", "[CALCULATE SEARCH MODIFIER] modifier = " + modifier);

        return new Double(modifier);
    }
}
;




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