Skip to content

Commit

Permalink
Commit 2.8
Browse files Browse the repository at this point in the history
  • Loading branch information
GneHeHe committed Jun 19, 2021
1 parent 68e1b88 commit 88ceade
Show file tree
Hide file tree
Showing 42 changed files with 10,142 additions and 8,780 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ However, **I guarantee SRBG is virus/trojan-free**.

# How to download and run SRBG ?

1) Download the last **pre-compiled JAR/EXE files** [here](https://github.com/GneHeHe/SmartRandomBuildGeneratorDbD/releases/download/2.7/SRBG.zip) (also available in '**releases**' tab)
1) Download the last **pre-compiled JAR/EXE files** [here](https://github.com/GneHeHe/SmartRandomBuildGeneratorDbD/releases/download/2.8/SRBG.zip) (also available in '**releases**' tab)

2) Unzip the downloaded **ZIP file**

Expand Down
4 changes: 2 additions & 2 deletions dbd/Build.java
Original file line number Diff line number Diff line change
Expand Up @@ -268,8 +268,8 @@ public String toString() {
}

/**
* Check if two Builds are Identical
* Warning: not used anymore in database for efficiency purpose
* Check if two Builds are Identical Warning: not used anymore in database
* for efficiency purpose
*
* @param b
* @param sort
Expand Down
25 changes: 24 additions & 1 deletion dbd/Character.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package dbd;

import java.io.File;
import java.io.IOException;
import javax.swing.ImageIcon;
import javax.swing.JLabel;
Expand All @@ -19,6 +18,8 @@ public class Character implements Comparable<Character> {
private String name;
// Side of Character
private String side;
// Status of Character
private boolean status;
// Icon of Character (as String)
private String icon_string;
// Icon of Character (as JLabel)
Expand Down Expand Up @@ -51,6 +52,7 @@ public Character(String name, String side, String icon) {
setName(name);
setIconString(icon);
setSide(side);
setStatus(true);
try {
setIconPicture();
} catch (IOException ex) {
Expand Down Expand Up @@ -149,6 +151,27 @@ public final void setSide(String side) {
}
}

/**
* Get Character Status
*
* @return
*/
public boolean getStatus() {
return status;
}

/**
* Set Character Status
*
* @param newval
*/
public final void setStatus(boolean newval) {
status = newval;
if (!status) {
System.out.println("# - Character '" + name + "' has been disabled");
}
}

/**
* Get Character Icon as JLabel
*
Expand Down
74 changes: 63 additions & 11 deletions dbd/SRBG.java
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,10 @@ public class SRBG {
private boolean b_cons4_perks;
// Nb of Perks in Build
private int nb_perks_build;
// Thresholds for Random Nb of Perks
private double rand_nb_perk1 = 0.03; // 0.03 ; 0.25
private double rand_nb_perk2 = 0.10; // 0.10 ; 0.50
private double rand_nb_perk3 = 0.25; // 0.25 ; 0.75
// Nb of loaded Perks
private int nb_perks_all;
// Nb of active Perks
Expand Down Expand Up @@ -135,14 +139,16 @@ public class SRBG {
private final int maxloop = 3000;
// Character File
private final String s_char = "data/characters.txt";
// Character Status File
private final String s_char_disabled = "disabled_chars.txt";
// Perk DB Files
private final String s_perk = "data/perk_db.txt";
public final String s_perk_custom = "perk_db_custom.txt";
// Constraint Files
private final String s_cons = "data/perk_cons.txt";
private final String s_cons_custom = "perk_cons_custom.txt";
// Version
public final double VERSION = 2.7;
public final double VERSION = 2.8;
// Title
public final String TITLE = "Smart Random Build Generator for Dead by Daylight ( SRBG " + VERSION + " )";
// GitHub Data
Expand Down Expand Up @@ -428,13 +434,18 @@ public final Character getCharacterRandom() {
while (iterator.hasNext()) {
Map.Entry entry = (Map.Entry) iterator.next();
char_tmp = (String) entry.getKey();
weight_tmp = (int) entry.getValue();
for (int i = 0; i < weight_tmp; i++) {
l_char_random.add(char_tmp);
if (retrieveCharacter(char_tmp).getStatus()) {
weight_tmp = (int) entry.getValue();
for (int i = 0; i < weight_tmp; i++) {
l_char_random.add(char_tmp);
}
}
}
// Get Random Character
int rand = (int) (l_char_random.size() * Math.random());
int rand = 0;
if (l_char_random.size() > 1) {
rand = (int) (l_char_random.size() * Math.random());
}
char_tmp = l_char_random.get(rand);
c = retrieveCharacter(char_tmp);
System.out.println("# Random Character = " + c.getName() + " | Side = " + side);
Expand Down Expand Up @@ -525,8 +536,26 @@ public int getNbPerksBuild() {
* @param n
*/
public final void setNbPerksBuild(int n) {
nb_perks_build = n;
System.out.println("\n# Nb of Perks in a Build = " + nb_perks_build + "\n");
if ((n >= 0) && (n <= 4)) {
if (n == 0) {
System.out.println("# Random Number of Perks");
double rand = Math.random();
if (rand <= rand_nb_perk1) {
n = 1;
} else if (rand <= rand_nb_perk2) {
n = 2;
} else if (rand <= rand_nb_perk3) {
n = 3;
} else {
n = 4;
}
}
nb_perks_build = n;
System.out.println("\n# Nb of Perks in a Build = " + nb_perks_build + "\n");
} else {
System.out.println("# ERROR: Wrong desired Nb of Perks (" + n + ") in a Build");
System.exit(0);
}
}

/**
Expand Down Expand Up @@ -1320,9 +1349,27 @@ private void initCharacters() {
l_char_killer.add(c);
l_char_killer_generic.add(c);
l_char_all_string.add(c.getName());
// Try to detect Character Status File
BufferedReader br = null;
List<String> l_char_disabled = new ArrayList();
String f = System.getProperty("user.dir") + File.separator + s_char_disabled;
if (new File(f).exists()) {
System.out.println("\n# Character Status File Detected");
try {
br = new BufferedReader(new FileReader(new File(f).getAbsolutePath()));
String line = br.readLine();
while (line != null) {
l_char_disabled.add(line);
line = br.readLine();
}
br.close();
} catch (Exception ex) {
System.err.println("\n# ERROR: issues with character status file => Exit");
System.exit(0);
}
}
// Load Characters
try {
// Define the Reader
BufferedReader br = null;
String input = s_char;
InputStream is = getClass().getResourceAsStream(input);
System.out.println("\n# Loading Characters from " + input);
Expand All @@ -1334,7 +1381,7 @@ private void initCharacters() {
// Split Line according to Spacer
String tab[] = line.split(spacer);
if (tab.length == 3) {
// Get Data (4 Fields are expected)
// Get Data (3 Fields are expected)
String myname = tab[0];
String myside = tab[1];
if (!((myside.equals(s_side_surv)) || (myside.equals(s_side_killer)))) {
Expand All @@ -1355,6 +1402,10 @@ private void initCharacters() {
m_char_random_killer.put(myname, char_val_orig);
}
l_char_all_string.add(myname);
// Check if Character must be disabled
if (l_char_disabled.indexOf(myname) >= 0) {
c.setStatus(false);
}
} else {
System.err.println("\n# ERROR: corrupted character file => Exit [ wrong line : >" + line + "< from input file ]\n");
System.exit(0);
Expand All @@ -1364,10 +1415,11 @@ private void initCharacters() {
br.close();
// Display Characters
int i = 1;
System.out.print("# All Characters: ");
for (String s : l_char_all_string) {
System.out.print(s + ", ");
if (i % 10 == 0) {
System.out.println();
System.out.print("\n# ");
}
i++;
}
Expand Down
35 changes: 24 additions & 11 deletions dbd/SRBG_TabBuild.java
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,10 @@ public SRBG_TabBuild(SRBG srbg) {
scrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED);
scrollPane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);

// Define Backgrounds
text.setBackground(pan_config.getBackground());
table_perks.setBackground(pan_config.getBackground());

// Set Layout & add Subpanels
setLayout(new BorderLayout());
add(pan_config, BorderLayout.NORTH);
Expand Down Expand Up @@ -131,21 +135,22 @@ private void addComponents() {
// Define JTextArea Objects
text = new JTextArea(30, 20);
text.setEditable(false);
text.setFont(new Font("Helvetica", Font.PLAIN, 16));
text.setFont(new Font("Helvetica", Font.BOLD, 16));

// Default ComboBox Model
cbm_default = new DefaultComboBoxModel();

// Define JComboBox Object for Perks
cb_nbperks = new JComboBox(new Integer[]{1, 2, 3, 4});
cb_nbperks = new JComboBox(new Integer[]{0, 1, 2, 3, 4});
cb_nbperks.setPreferredSize(new Dimension(50, 20));
cb_nbperks.setToolTipText("Define the number of perks in generated builds");
cb_nbperks.setToolTipText("<html>Define the number of perks in generated builds<br><br>Random number of looted perks will be enabled with '0' value: high chance of 4 perks and pretty low probability of 1 or 2 or 3 perks</html>");
((JLabel) cb_nbperks.getRenderer()).setHorizontalAlignment(SwingConstants.CENTER);
cb_nbperks.setSelectedItem(srbg.getNbPerksBuild());
//cb_nbperks.setSelectedItem(srbg.getNbPerksBuild());
cb_nbperks.setSelectedIndex(0);

// Define JComboBox Object for Nb of Builds
cb_nbbuilds = new JComboBox(new Integer[]{1, 2, 5, 10, 25, 50});
cb_nbbuilds.setPreferredSize(new Dimension(50, 20));
cb_nbbuilds = new JComboBox(new Integer[]{1, 2, 5, 10, 50, 100});
cb_nbbuilds.setPreferredSize(new Dimension(60, 20));
cb_nbbuilds.setToolTipText("<html>Define the number of builds to be generated<br><br>The build with the highest score is graphically displayed<br><br>Meta builds or high-synergy builds are associated with high scores<br><br>Meta builds or high-synergy builds tend to be returned when the number of generated builds is large</html>");
((JLabel) cb_nbbuilds.getRenderer()).setHorizontalAlignment(SwingConstants.CENTER);
cb_nbbuilds.setSelectedIndex(0);
Expand Down Expand Up @@ -473,6 +478,10 @@ public void switchComponents() {
private void genBuild(JTable table, int size_perk, int size_char) {
// Update JCheckBoxes
updateCheckBoxes();
// Set Nb Perks
if (Integer.parseInt(cb_nbperks.getSelectedItem().toString()) == 0) {
srbg.setNbPerksBuild(0);
}
// Monitor Random Feature
force_random = false;
String mode = "";
Expand All @@ -482,6 +491,10 @@ private void genBuild(JTable table, int size_perk, int size_char) {
mode = cb_side.getSelectedItem().toString();
updateComboBoxes();
}
// Display Generic Build
for (int i = 0; i < srbg.nb_perks_ref; i++) {
table.getModel().setValueAt(srbg.perk_generic.getIconImage(size_perk), 0, i);
}
// Reset Table
resetTable(table);
// Define SwingWorker
Expand All @@ -495,7 +508,7 @@ protected Void doInBackground() {
// Enable/Disable Components
switchComponents();
// Reset Text
String fulltext = "";
String fulltext = "\n Generated Builds will be sorted by their Score:\n";
text.setText(fulltext);
// Display loaded Parameters
srbg.showParams(false);
Expand Down Expand Up @@ -597,6 +610,10 @@ private void displayBuild(JTable table, int size_perk, int size_char) throws Exc
* @throws java.lang.Exception
*/
private void displayInit(JTable table, int size_perk, int size_char) {
// Display Generic Build
for (int i = 0; i < srbg.nb_perks_ref; i++) {
table.getModel().setValueAt(srbg.perk_generic.getIconImage(size_perk), 0, i);
}
if ((srbg.getBestBuild() != null) && (srbg.getSide().equals(srbg.getBestBuild().getSide()))) {
// Display Best Build in Table
int nb = 0;
Expand All @@ -607,10 +624,6 @@ private void displayInit(JTable table, int size_perk, int size_char) {
// Display Character
table.getModel().setValueAt(srbg.getCharacter().getIconImage(size_char), 0, 4);
} else {
// Display Generic Build
for (int i = 0; i < srbg.nb_perks_ref; i++) {
table.getModel().setValueAt(srbg.perk_generic.getIconImage(size_perk), 0, i);
}
// Display Generic Character
table.getModel().setValueAt(srbg.getCharacterGeneric().getIconImage(size_char), 0, 4);
}
Expand Down
5 changes: 4 additions & 1 deletion dbd/SRBG_TabHelp.java
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,9 @@ public SRBG_TabHelp(SRBG srbg) {
pan_header.add(new JLabel(pict), BorderLayout.CENTER);
pan_header.add(pan_author, BorderLayout.SOUTH);

// Define Background
editor.setBackground(pan_header.getBackground());

// Add Tutorial to Panel
scrollPane = new JScrollPane(editor);

Expand Down Expand Up @@ -113,7 +116,7 @@ private void addComponents() {
lab_email = new JLabel("<html><u>Contact</u></html>", SwingConstants.CENTER);
lab_email.setFont(new Font("Helvetica", Font.BOLD, 18));
lab_email.setCursor(new Cursor(Cursor.HAND_CURSOR));
lab_email.setToolTipText("<html>Send an Email to " + srbg.GIT_USER +" to:<br><ul><li>Give Feedback</li><br><li>Report any Bug</li><br><li>Suggest potential new Features</li></ul></html>");
lab_email.setToolTipText("<html>Send an Email to " + srbg.GIT_USER + " to:<br><ul><li>Give Feedback</li><br><li>Report any Bug</li><br><li>Suggest potential new Features</li></ul></html>");

// Define JLabel Donate
lab_donate = new JLabel("<html><u>Donate</u></html>", SwingConstants.CENTER);
Expand Down
25 changes: 24 additions & 1 deletion dbd/SRBG_TabPerk.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,19 @@
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.io.*;
import java.net.URL;
import java.nio.channels.Channels;
import java.nio.channels.ReadableByteChannel;
import java.nio.file.Files;
import java.nio.file.StandardCopyOption;
import java.util.ArrayList;
import javax.swing.*;
import javax.swing.filechooser.FileNameExtensionFilter;
import javax.swing.table.TableModel;
import javax.swing.table.TableRowSorter;

/**
*
Expand All @@ -28,7 +33,7 @@ public class SRBG_TabPerk extends JPanel {
private JLabel lab_side;
private JComboBox cb_side;
private JFileChooser fileChooser;
private TablePerk table;
public TablePerk table;
// SRBG Object
private SRBG srbg;
// Synergy Filenames
Expand Down Expand Up @@ -121,6 +126,24 @@ private void addComponents() {
// Update Table
((TableModelPerk) table.getModel()).updateTable(cb_side.getSelectedItem().toString());

TableRowSorter<TableModel> sorter = new TableRowSorter<>(table.getModel());
table.setRowSorter(sorter);
ArrayList<RowSorter.SortKey> sortKeys = new ArrayList<>();

table.getTableHeader().addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent e) {
int column = table.columnAtPoint(e.getPoint());
if (column != 1) {
sortKeys.clear();
sortKeys.add(new RowSorter.SortKey(column, SortOrder.ASCENDING));
sorter.setSortKeys(sortKeys);
sorter.sort();
//table.repaint();
}
}
});

// Define ActionListener
b_load.addActionListener(new ActionListener() {
@Override
Expand Down
3 changes: 2 additions & 1 deletion dbd/TablePerk.java
Original file line number Diff line number Diff line change
Expand Up @@ -129,11 +129,12 @@ public void setIconColumn(int i) {
*/
@Override
public Component prepareRenderer(TableCellRenderer renderer, int row, int col) {
int modelRow = convertRowIndexToModel(row);
Component comp = super.prepareRenderer(renderer, row, col);
// Update Background Color according to Value (Only Process Third Column)
if (col == 3) {
// Get Value (required double/float)
float value = Float.parseFloat(getModel().getValueAt(row, col).toString());
float value = Float.parseFloat(getModel().getValueAt(modelRow, col).toString());
if (value <= 0) {
// No Weight => Red Background
comp.setBackground(Color.RED);
Expand Down

0 comments on commit 88ceade

Please sign in to comment.