Adds skills to monster cards.
This commit is contained in:
@@ -13,6 +13,7 @@ public class Monster {
|
|||||||
|
|
||||||
public Monster() {
|
public Monster() {
|
||||||
mSavingThrows = new HashSet<>();
|
mSavingThrows = new HashSet<>();
|
||||||
|
mSkills = new HashSet<>();
|
||||||
}
|
}
|
||||||
|
|
||||||
private String mName;
|
private String mName;
|
||||||
@@ -586,4 +587,36 @@ public class Monster {
|
|||||||
public void setCustomProficiencyBonus(int proficiencyBonus) {
|
public void setCustomProficiencyBonus(int proficiencyBonus) {
|
||||||
mCustomProficiencyBonus = proficiencyBonus;
|
mCustomProficiencyBonus = proficiencyBonus;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private HashSet<Skill> mSkills;
|
||||||
|
public Set<Skill> getSkills() {
|
||||||
|
return mSkills;
|
||||||
|
}
|
||||||
|
public void addSkill(Skill skill) {
|
||||||
|
mSkills.add(skill);
|
||||||
|
}
|
||||||
|
public void removeSkill(Skill skill) {
|
||||||
|
mSkills.remove(skill);
|
||||||
|
}
|
||||||
|
public void clearSkill(Skill skill) {
|
||||||
|
mSkills.clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getSkillsDescription() {
|
||||||
|
Skill[] elements = new Skill[mSkills.size()];
|
||||||
|
elements = mSkills.toArray(elements);
|
||||||
|
Arrays.sort(elements);
|
||||||
|
StringBuilder sb = new StringBuilder();
|
||||||
|
boolean isFirst = true;
|
||||||
|
for (Skill skill : elements) {
|
||||||
|
if (!isFirst) {
|
||||||
|
sb.append(", ");
|
||||||
|
}
|
||||||
|
String name = skill.getName();
|
||||||
|
sb.append(skill.getText(this));
|
||||||
|
isFirst = false;
|
||||||
|
}
|
||||||
|
return sb.toString();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,95 +1,68 @@
|
|||||||
package com.majinnaibu.monstercards.models;
|
package com.majinnaibu.monstercards.models;
|
||||||
|
|
||||||
import android.annotation.SuppressLint;
|
|
||||||
|
|
||||||
import androidx.annotation.Nullable;
|
|
||||||
|
|
||||||
import com.majinnaibu.monstercards.data.enums.AbilityScore;
|
|
||||||
import com.majinnaibu.monstercards.data.enums.AdvantageType;
|
|
||||||
import com.majinnaibu.monstercards.data.enums.ProficiencyType;
|
|
||||||
|
|
||||||
import java.util.Comparator;
|
import java.util.Comparator;
|
||||||
import java.util.Objects;
|
import java.util.Locale;
|
||||||
|
|
||||||
@SuppressLint("DefaultLocale")
|
|
||||||
public class Skill implements Comparator<Skill>, Comparable<Skill> {
|
public class Skill implements Comparator<Skill>, Comparable<Skill> {
|
||||||
|
|
||||||
public String name;
|
private String mName;
|
||||||
public AbilityScore abilityScore;
|
private String mAbilityScoreName;
|
||||||
public AdvantageType advantageType;
|
private String mNote;
|
||||||
public ProficiencyType proficiencyType;
|
|
||||||
|
|
||||||
public Skill(String name, AbilityScore abilityScore) {
|
public Skill(String name, String abilityScoreName) {
|
||||||
this(name, abilityScore, AdvantageType.NONE, ProficiencyType.PROFICIENT);
|
mName = name;
|
||||||
|
mAbilityScoreName = abilityScoreName;
|
||||||
|
mNote = "";
|
||||||
}
|
}
|
||||||
|
|
||||||
public Skill(String name, AbilityScore abilityScore, AdvantageType advantageType) {
|
public Skill(String name, String abilityScoreName, String note) {
|
||||||
this(name, abilityScore, advantageType, ProficiencyType.PROFICIENT);
|
mName = name;
|
||||||
|
mAbilityScoreName = abilityScoreName;
|
||||||
|
mNote = note;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Skill(String name, AbilityScore abilityScore, AdvantageType advantageType, ProficiencyType proficiencyType) {
|
public String getName() {
|
||||||
this.name = name;
|
return mName;
|
||||||
this.abilityScore = abilityScore;
|
}
|
||||||
this.advantageType = advantageType;
|
public void setName(String name) {
|
||||||
this.proficiencyType = proficiencyType;
|
mName = name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getAbilityScoreName() {
|
||||||
|
return mAbilityScoreName;
|
||||||
|
}
|
||||||
|
public void setAbilityScoreName(String abilityScoreName) {
|
||||||
|
mAbilityScoreName = abilityScoreName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getNote() {
|
||||||
|
return mNote;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getSkillBonus(Monster monster) {
|
public int getSkillBonus(Monster monster) {
|
||||||
int modifier = monster.getAbilityModifier(abilityScore);
|
int bonus = monster.getAbilityModifier(mAbilityScoreName);
|
||||||
switch (proficiencyType) {
|
if (" (ex)".equals(getNote())) {
|
||||||
case PROFICIENT:
|
bonus += 2 * monster.getProficiencyBonus();
|
||||||
return modifier + monster.getProficiencyBonus();
|
} else {
|
||||||
case EXPERTISE:
|
bonus += monster.getProficiencyBonus();
|
||||||
return modifier + monster.getProficiencyBonus() * 2;
|
|
||||||
case NONE:
|
|
||||||
default:
|
|
||||||
return modifier;
|
|
||||||
}
|
}
|
||||||
|
return bonus;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getText(Monster monster) {
|
public String getText(Monster monster) {
|
||||||
int bonus = getSkillBonus(monster);
|
int bonus = getSkillBonus(monster);
|
||||||
|
|
||||||
return String.format(
|
return String.format(Locale.US, "%s%s %d", mName.substring(0,1), mName.substring(1), bonus);
|
||||||
"%s%s %+d%s",
|
|
||||||
name.charAt(0),
|
|
||||||
name.substring(1),
|
|
||||||
bonus,
|
|
||||||
advantageType == AdvantageType.ADVANTAGE ? " A" : advantageType == AdvantageType.DISADVANTAGE ? " D" : ""
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int compareTo(Skill o) {
|
public int compareTo(Skill o) {
|
||||||
return this.name.compareToIgnoreCase(o.name);
|
return this.getName().compareToIgnoreCase(o.getName());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int compare(Skill o1, Skill o2) {
|
public int compare(Skill o1, Skill o2) {
|
||||||
return o1.name.compareToIgnoreCase(o2.name);
|
return o1.getName().compareToIgnoreCase(o2.getName());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean equals(@Nullable Object obj) {
|
|
||||||
if (obj == null) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
if (!(obj instanceof Skill)) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
Skill otherSkill = (Skill) obj;
|
|
||||||
if (!Objects.equals(this.name, otherSkill.name)) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
if (this.abilityScore != otherSkill.abilityScore) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
if (this.advantageType != otherSkill.advantageType) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
if (this.proficiencyType != otherSkill.proficiencyType) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,6 +17,7 @@ import com.majinnaibu.monstercards.R;
|
|||||||
import com.majinnaibu.monstercards.helpers.StringHelper;
|
import com.majinnaibu.monstercards.helpers.StringHelper;
|
||||||
import com.majinnaibu.monstercards.models.Monster;
|
import com.majinnaibu.monstercards.models.Monster;
|
||||||
import com.majinnaibu.monstercards.models.SavingThrow;
|
import com.majinnaibu.monstercards.models.SavingThrow;
|
||||||
|
import com.majinnaibu.monstercards.models.Skill;
|
||||||
|
|
||||||
@SuppressWarnings("FieldCanBeLocal")
|
@SuppressWarnings("FieldCanBeLocal")
|
||||||
public class MonsterFragment extends Fragment {
|
public class MonsterFragment extends Fragment {
|
||||||
@@ -66,6 +67,9 @@ public class MonsterFragment extends Fragment {
|
|||||||
monster.addSavingThrow(new SavingThrow("int", 3));
|
monster.addSavingThrow(new SavingThrow("int", 3));
|
||||||
monster.addSavingThrow(new SavingThrow("wis", 4));
|
monster.addSavingThrow(new SavingThrow("wis", 4));
|
||||||
monster.addSavingThrow(new SavingThrow("cha", 5));
|
monster.addSavingThrow(new SavingThrow("cha", 5));
|
||||||
|
//Skills
|
||||||
|
monster.addSkill(new Skill("perception", "wis"));
|
||||||
|
monster.addSkill(new Skill("stealth", "dexterity"));
|
||||||
|
|
||||||
// Challenge Rating
|
// Challenge Rating
|
||||||
monster.setChallengeRating("*");
|
monster.setChallengeRating("*");
|
||||||
@@ -177,6 +181,19 @@ public class MonsterFragment extends Fragment {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
final TextView monsterSkills = root.findViewById(R.id.skills);
|
||||||
|
monsterViewModel.getSkills().observe(getViewLifecycleOwner(), new Observer<String>() {
|
||||||
|
@Override
|
||||||
|
public void onChanged(String skills) {
|
||||||
|
if (StringHelper.isNullOrEmpty(skills)) {
|
||||||
|
monsterSkills.setVisibility(View.GONE);
|
||||||
|
} else {
|
||||||
|
monsterSkills.setVisibility(View.VISIBLE);
|
||||||
|
}
|
||||||
|
monsterSkills.setText(Html.fromHtml("<b>Skills</b> " + skills));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
return root;
|
return root;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -34,6 +34,8 @@ public class MonsterViewModel extends ViewModel {
|
|||||||
mCharisma.setValue("");
|
mCharisma.setValue("");
|
||||||
mSavingThrows = new MutableLiveData<>();
|
mSavingThrows = new MutableLiveData<>();
|
||||||
mSavingThrows.setValue("");
|
mSavingThrows.setValue("");
|
||||||
|
mSkills = new MutableLiveData<>();
|
||||||
|
mSkills.setValue("");
|
||||||
}
|
}
|
||||||
|
|
||||||
private MutableLiveData<String> mName;
|
private MutableLiveData<String> mName;
|
||||||
@@ -84,6 +86,10 @@ public class MonsterViewModel extends ViewModel {
|
|||||||
public LiveData<String> getSavingThrows() {
|
public LiveData<String> getSavingThrows() {
|
||||||
return mSavingThrows;
|
return mSavingThrows;
|
||||||
}
|
}
|
||||||
|
private MutableLiveData<String> mSkills;
|
||||||
|
public LiveData<String> getSkills() {
|
||||||
|
return mSkills;
|
||||||
|
}
|
||||||
|
|
||||||
private Monster mMonster;
|
private Monster mMonster;
|
||||||
public void setMonster(Monster monster) {
|
public void setMonster(Monster monster) {
|
||||||
@@ -100,5 +106,6 @@ public class MonsterViewModel extends ViewModel {
|
|||||||
mWisdom.setValue(monster.getWisdomDescription());
|
mWisdom.setValue(monster.getWisdomDescription());
|
||||||
mCharisma.setValue(monster.getCharismaDescription());
|
mCharisma.setValue(monster.getCharismaDescription());
|
||||||
mSavingThrows.setValue(monster.getSavingThrowsDescription());
|
mSavingThrows.setValue(monster.getSavingThrowsDescription());
|
||||||
|
mSkills.setValue(monster.getSkillsDescription());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -318,5 +318,18 @@
|
|||||||
app:layout_constraintTop_toBottomOf="@+id/divider3"
|
app:layout_constraintTop_toBottomOf="@+id/divider3"
|
||||||
tools:text="Saving Throws" />
|
tools:text="Saving Throws" />
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/skills"
|
||||||
|
android:layout_width="0dp"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginStart="8dp"
|
||||||
|
android:layout_marginTop="8dp"
|
||||||
|
android:layout_marginEnd="8dp"
|
||||||
|
android:layout_marginBottom="8dp"
|
||||||
|
app:layout_constraintEnd_toEndOf="parent"
|
||||||
|
app:layout_constraintStart_toStartOf="parent"
|
||||||
|
app:layout_constraintTop_toBottomOf="@+id/saving_throws"
|
||||||
|
tools:text="Skills" />
|
||||||
|
|
||||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||||
</ScrollView>
|
</ScrollView>
|
||||||
Reference in New Issue
Block a user