public static Ninja levelUp(Ninja n) { if (n.getExpNeeded() > n.getExpCurrent()) return null; n.setExpCurrent(n.getExpCurrent() - n.getExpNeeded()); n.setExpNeeded(n.getExpNeeded() + ((n.getExpNeeded() * 4) / 10)); n.setLevel(n.getLevel() + 1); try { NinjaDAO dao = new NinjaDAO(); dao.update(n); dao.close(); } catch (Exception e) { e.printStackTrace(); } return n; }
public static Ninja missionRewards(Ninja n, String missionRewards, String missionName) { String ninjaRewardsString = ""; String[] rewards = missionRewards.split(";"); for (String reward : rewards) { try { String[] div = reward.split("\\+"); String type = div[0]; String value = div[1]; switch (type) { case "exp": n.setExpCurrent(n.getExpCurrent() + Integer.parseInt(value)); ninjaRewardsString += "+" + value + " Experience Points; "; break; case "gld": n.getBits().setGold(n.getBits().getGold() + Integer.parseInt(value)); ninjaRewardsString += "+" + value + " Gold Bits; "; break; case "acd": n.setAcademyLevel(n.getAcademyLevel() + 1); break; } } catch (Exception e) { e.printStackTrace(); } } n.setLastMission(missionName); n.setLastMissionRewards(ninjaRewardsString); try { NinjaDAO dao = new NinjaDAO(); dao.update(n); dao.close(); } catch (Exception e) { e.printStackTrace(); } return n; }