Merge pull request #601 from SirLoading/skill-feedback

Skill feedback
This commit is contained in:
Phillip Thelen 2016-09-05 13:57:15 +02:00 committed by GitHub
commit 4e15428d5a
3 changed files with 28 additions and 5 deletions

View file

@ -2,6 +2,7 @@ package com.habitrpg.android.habitica.callbacks;
import com.habitrpg.android.habitica.events.SkillUsedEvent;
import com.magicmicky.habitrpgwrapper.lib.models.HabitRPGUser;
import com.magicmicky.habitrpgwrapper.lib.models.Stats;
import com.magicmicky.habitrpgwrapper.lib.models.Skill;
import com.magicmicky.habitrpgwrapper.lib.models.responses.SkillResponse;
@ -26,6 +27,10 @@ public class SkillCallback implements Action1<SkillResponse> {
@Override
public void call(SkillResponse skillResponse) {
Double xp = this.user.getStats().getExp();
Double hp = this.user.getStats().getHp();
Double gold = this.user.getStats().getGp();
HabitRPGUser user = skillResponse.user;
if (user.getItems() != null) {
this.user.setItems(user.getItems());
@ -43,7 +48,7 @@ public class SkillCallback implements Action1<SkillResponse> {
this.user.async().save();
callBack.onUserReceived(this.user);
EventBus.getDefault().post(new SkillUsedEvent(this.usedSkill, skillResponse.user.getStats().getMp()));
Stats stats = skillResponse.user.getStats();
EventBus.getDefault().post(new SkillUsedEvent(this.usedSkill, stats.getMp(), stats.getExp() - xp, stats.getHp() - hp, stats.getGp() - gold));
}
}

View file

@ -8,10 +8,13 @@ import com.magicmicky.habitrpgwrapper.lib.models.Skill;
public class SkillUsedEvent {
public Skill usedSkill;
public Double newMana;
public Double newMana, xp, hp, gold;
public SkillUsedEvent(Skill usedSkill, Double newMana) {
public SkillUsedEvent(Skill usedSkill, Double newMana, Double xp, Double hp, Double gold) {
this.usedSkill = usedSkill;
this.newMana = newMana;
this.xp = xp;
this.hp = hp;
this.gold = gold;
}
}

View file

@ -112,7 +112,18 @@ public class SkillsFragment extends BaseMainFragment {
removeProgressDialog();
Skill skill = event.usedSkill;
adapter.setMana(event.newMana);
UiUtils.showSnackbar(activity, activity.getFloatingMenuWrapper(), activity.getString(R.string.used_skill, skill.text, skill.mana), UiUtils.SnackbarDisplayType.NORMAL);
StringBuilder message = new StringBuilder();
message.append(activity.getString(R.string.used_skill, skill.text, skill.mana));
if (event.xp != 0) {
message.append(" + ").append(round(event.xp, 2)).append(" XP");
}
if (event.hp != 0) {
message.append(" + ").append(round(event.hp, 2)).append(" HP");
}
if (event.gold != 0) {
message.append(" + ").append(round(event.gold, 2)).append(" GP");
}
UiUtils.showSnackbar(activity, activity.getFloatingMenuWrapper(), message.toString(), UiUtils.SnackbarDisplayType.NORMAL);
apiHelper.apiService.getUser()
.compose(apiHelper.configureApiCallObserver())
.subscribe(new MergeUserCallback(activity, user), throwable -> {
@ -163,4 +174,8 @@ public class SkillsFragment extends BaseMainFragment {
}
}
static public Double round(Double value, int n) {
return (Math.round(value * Math.pow(10, n))) / (Math.pow(10, n));
}
}