Skip to content

Commit

Permalink
Unlocked Forms -- HashSet
Browse files Browse the repository at this point in the history
  • Loading branch information
KAMKEEL committed Apr 23, 2024
1 parent c77ec29 commit de5c39b
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 26 deletions.
42 changes: 18 additions & 24 deletions src/main/java/kamkeel/npcdbc/data/PlayerDBCInfo.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;

/**
Expand All @@ -22,7 +23,11 @@ public class PlayerDBCInfo {
public int currentForm = -1;
public int selectedForm = -1;

public HashMap<Integer, String> unlockedForms = new HashMap<Integer, String>();
public int currentAura = -1;
public int selectedAura = -1;
public HashSet<Integer> unlockedAuras = new HashSet<Integer>();

public HashSet<Integer> unlockedForms = new HashSet<Integer>();
public HashMap<Integer, Float> formLevels = new HashMap<Integer, Float>();
public HashMap<Integer, Integer> formTimers = new HashMap<>();

Expand All @@ -31,28 +36,28 @@ public PlayerDBCInfo(PlayerData parent) {
}

public void addForm(Form form) {
if (!unlockedForms.containsKey(form.id)) {
unlockedForms.put(form.id, form.name);
if (!unlockedForms.contains(form.id)) {
unlockedForms.add(form.id);
formLevels.put(form.id, 0f);
}
}

public boolean hasUnlocked(int id) {
return unlockedForms.containsKey(id);
return unlockedForms.contains(id);
}

public String removeForm(Form form) {
public boolean removeForm(Form form) {
formLevels.remove(form.id);
return unlockedForms.remove(form.id);
}

public String removeForm(int id) {
public boolean removeForm(int id) {
formLevels.remove(id);
return unlockedForms.remove(id);
}

public Form getForm(int id) {
if (unlockedForms.containsKey(id))
if (unlockedForms.contains(id))
return (Form) FormController.getInstance().get(id);

return null;
Expand All @@ -63,7 +68,7 @@ public boolean hasSelectedForm() {
}

public boolean hasForm(Form form) {
return unlockedForms.containsKey(form.id);
return unlockedForms.contains(form.id);
}

public boolean isInCustomForm() {
Expand Down Expand Up @@ -93,20 +98,9 @@ public Form getCurrentForm() {
return null;
}

public List<String> getAllForms() {
List<String> list = new ArrayList<>();
for (Integer id : unlockedForms.keySet()) {
Form f = getUnlockedForm(id);
if (!list.contains(getColoredName(f)))
list.add(getColoredName(f));

}
return list;
}

public Form getUnlockedForm(int id) {
if (unlockedForms.containsKey(id))
return (Form) FormController.Instance.get(unlockedForms.get(id));
if (unlockedForms.contains(id))
return (Form) FormController.Instance.get(id);
return null;
}

Expand Down Expand Up @@ -181,7 +175,7 @@ public void resetAll() {
TransformController.handleFormDescend((EntityPlayerMP) parent.player);
currentForm = -1;
selectedForm = -1;
unlockedForms = new HashMap();
unlockedForms = new HashSet<>();
formLevels = new HashMap();
updateClient();
}
Expand Down Expand Up @@ -223,15 +217,15 @@ public boolean hasTimer(int formid) {
public void saveNBTData(NBTTagCompound compound) {
compound.setInteger("CurrentForm", currentForm);
compound.setInteger("SelectedForm", selectedForm);
compound.setTag("UnlockedForms", NBTTags.nbtIntegerStringMap(unlockedForms));
compound.setTag("UnlockedForms", NBTTags.nbtIntegerSet(unlockedForms));
compound.setTag("FormMastery", NBTTags.nbtIntegerFloatMap(formLevels));
compound.setTag("FormTimers", NBTTags.nbtIntegerIntegerMap(formTimers));
}

public void loadNBTData(NBTTagCompound compound) {
currentForm = compound.getInteger("CurrentForm");
selectedForm = compound.getInteger("SelectedForm");
unlockedForms = NBTTags.getIntegerStringMap(compound.getTagList("UnlockedForms", 10));
unlockedForms = NBTTags.getIntegerSet(compound.getTagList("UnlockedForms", 10));
formLevels = NBTTags.getIntegerFloatMap(compound.getTagList("FormMastery", 10));
formTimers = NBTTags.getIntegerIntegerMap(compound.getTagList("FormTimers", 10));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ public void formPacketSet(EntityPlayer player, ByteBuf buffer) throws IOExceptio
return;

if(formID > -1){
if(data.selectedForm != formID && data.unlockedForms.containsKey(formID)){
if(data.selectedForm != formID && data.unlockedForms.contains(formID)){
Form customForm = (Form) FormController.getInstance().get(formID);
NBTTagCompound compound = new NBTTagCompound();
if(customForm != null){
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/kamkeel/npcdbc/util/Utility.java
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ public static void sendPlayerFormData(EntityPlayerMP player) {
PlayerDBCInfo data = ((IPlayerDBCInfo) PlayerDataController.Instance.getPlayerData(player)).getPlayerDBCInfo();

Map<String, Integer> map = new HashMap<String, Integer>();
for (int formID : data.unlockedForms.keySet()) {
for (int formID : data.unlockedForms) {
Form form = (Form) FormController.getInstance().get(formID);
if (form != null) {
map.put(form.name, form.id);
Expand Down

0 comments on commit de5c39b

Please sign in to comment.