Skip to content

Commit

Permalink
Latest Updates.
Browse files Browse the repository at this point in the history
  • Loading branch information
Sindusk committed Jun 22, 2018
1 parent 76681b6 commit f59852c
Show file tree
Hide file tree
Showing 44 changed files with 2,595 additions and 299 deletions.
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ repositories {
}

dependencies {
compile 'org.gotti.wurmunlimited:server-modlauncher:0.35-beta1'
compile 'com.github.Sindusk:sindusklibrary:1.2'
compile 'org.gotti.wurmunlimited:server-modlauncher:0.37'
compile 'com.github.Sindusk:sindusklibrary:v1.5'
compile 'com.github.Sindusk:DiscordRelay:v1.2'
compile 'com.github.Sindusk:TreasureHunting:1.1.4'
}
Expand Down
113 changes: 113 additions & 0 deletions src/main/java/com/wurmonline/server/questions/AffinityOrbQuestion.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
package com.wurmonline.server.questions;

import com.wurmonline.server.Items;
import com.wurmonline.server.Server;
import com.wurmonline.server.creatures.Creature;
import com.wurmonline.server.items.Item;
import com.wurmonline.server.players.Player;
import com.wurmonline.server.skills.Affinities;
import com.wurmonline.server.skills.Affinity;
import com.wurmonline.server.skills.SkillSystem;
import net.coldie.tools.BmlForm;

import java.util.HashMap;
import java.util.Properties;
import java.util.Random;

public class AffinityOrbQuestion extends Question {
protected Item affinityOrb;

public AffinityOrbQuestion(Creature aResponder, String aTitle, String aQuestion, long aTarget, Item orb){
super(aResponder, aTitle, aQuestion, 79, aTarget);
this.affinityOrb = orb;
}

public static HashMap<Integer, Integer> affinityMap = new HashMap<>();

@Override
public void answer(Properties answer) {
boolean accepted = answer.containsKey("accept") && answer.get("accept") == "true";
if (accepted) {
logger.info("Accepted AffinityOrb");
int entry = Integer.parseInt(answer.getProperty("affinity"));
int skillNum = affinityMap.get(entry);
if(affinityOrb == null || affinityOrb.getOwnerId() != this.getResponder().getWurmId()){
this.getResponder().getCommunicator().sendNormalServerMessage("You must own an affinity orb to obtain an affinity.");
}else{
if(this.getResponder() instanceof Player) {
Player player = (Player) this.getResponder();
//logger.info("Converting "+player.getName()+" to " + Deities.getDeityName(deity));
String skillName = SkillSystem.getNameFor(skillNum);
logger.info("Adding affinity for skill "+skillName+" to "+player.getName());
Items.destroyItem(affinityOrb.getWurmId());

Affinity[] affs = Affinities.getAffinities(player.getWurmId());
boolean found = false;
for (Affinity affinity : affs) {
if (affinity.getSkillNumber() != skillNum) continue;
if (affinity.getNumber() >= 5){
player.getCommunicator().sendSafeServerMessage("You already have the maximum amount of affinities for "+skillName);
return;
}
Affinities.setAffinity(player.getWurmId(), skillNum, affinity.getNumber() + 1, false);
found = true;
Items.destroyItem(affinityOrb.getWurmId());
player.getCommunicator().sendSafeServerMessage("Vynora infuses you with an affinity for " + skillName + "!");
break;
}
if (!found) {
Affinities.setAffinity(player.getWurmId(), skillNum, 1, false);
Items.destroyItem(affinityOrb.getWurmId());
player.getCommunicator().sendSafeServerMessage("Vynora infuses you with an affinity for " + skillName + "!");
}
}else{
logger.info("Non-player used a "+affinityOrb.getName()+"?");
}
}
}
}

public String getAffinities(){
String builder = "";
Random rand = new Random();
if(affinityOrb.getAuxData() == 0){
logger.info("Orb has no affinity set, creating random seed now.");
affinityOrb.setAuxData((byte) ((1+Server.rand.nextInt(120))*(Server.rand.nextBoolean() ? 1 : -1)));
}
rand.setSeed(affinityOrb.getAuxData());
logger.info("Seed set to "+affinityOrb.getAuxData());
affinityMap.clear();
int i = 0;
while(i < 10){
int num = rand.nextInt(SkillSystem.getNumberOfSkillTemplates());
if(!affinityMap.containsValue(num)) {
builder = builder + SkillSystem.getSkillTemplateByIndex(num).getName();
affinityMap.put(i, SkillSystem.getSkillTemplateByIndex(num).getNumber());
i++;
if (i < 10) {
builder = builder + ",";
}
}
}
return builder;
}

@Override
public void sendQuestion() {
if(affinityOrb == null || affinityOrb.getOwnerId() != this.getResponder().getWurmId()){
this.getResponder().getCommunicator().sendNormalServerMessage("You must own an affinity orb before being infused.");
return;
}
BmlForm f = new BmlForm("");
f.addHidden("id", String.valueOf(this.id));
f.addBoldText("Select the affinity you would like to obtain\n", new String[0]);
f.addRaw("harray{label{text='Select Affinity:'}dropdown{id='affinity';options='");
f.addRaw(getAffinities());
f.addRaw("'}}");
f.addText("\n\n", new String[0]);
f.beginHorizontalFlow();
f.addButton("Accept", "accept");
f.endHorizontalFlow();
this.getResponder().getCommunicator().sendBml(400, 300, true, true, f.toString(), 255, 255, 255, this.title);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
package com.wurmonline.server.questions;

import com.wurmonline.server.DbConnector;
import com.wurmonline.server.creatures.Creature;
import com.wurmonline.server.deities.Deities;
import com.wurmonline.server.players.AchievementTemplate;
import com.wurmonline.server.skills.SkillList;
import com.wurmonline.server.utils.DbUtilities;
import mod.sin.wyvern.AchievementChanges;
import net.coldie.tools.BmlForm;
import org.gotti.wurmunlimited.modsupport.ModSupportDb;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Properties;

public class LeaderboardAchievementQuestion extends Question {
protected int achievementNum;
protected AchievementTemplate template;

public LeaderboardAchievementQuestion(Creature aResponder, String aTitle, String aQuestion, long aTarget, int achievementNum){
super(aResponder, aTitle, aQuestion, 79, aTarget);
this.achievementNum = achievementNum;
this.template = AchievementChanges.goodAchievements.get(achievementNum);
}

@Override
public void answer(Properties answer) {
boolean accepted = answer.containsKey("okay") && answer.get("okay") == "true";
if (accepted) {
LeaderboardQuestion lbq = new LeaderboardQuestion(this.getResponder(), "Leaderboard", "Which leaderboard would you like to view?", this.getResponder().getWurmId());
lbq.sendQuestion();
}
}

protected HashMap<String, Integer> optIn = new HashMap<>();
protected void identifyOptIn(){
String name;
int opted;
Connection dbcon;
PreparedStatement ps;
ResultSet rs;
try {
dbcon = ModSupportDb.getModSupportDb();
ps = dbcon.prepareStatement("SELECT * FROM LeaderboardOpt");
rs = ps.executeQuery();
while (rs.next()) {
name = rs.getString("name");
opted = rs.getInt("OPTIN");
optIn.put(name, opted);
}
rs.close();
ps.close();
}
catch (SQLException e) {
throw new RuntimeException(e);
}
}

@Override
public void sendQuestion() {
BmlForm f = new BmlForm("");
f.addHidden("id", String.valueOf(this.id));
ArrayList<String> names = new ArrayList<>();
ArrayList<Integer> counts = new ArrayList<>();
//ArrayList<Integer> deities = new ArrayList<>();
String name;
int counter;
int deity;
String extra = "";

// Populates HashMap with latest opt-in data.
identifyOptIn();

Connection dbcon;
PreparedStatement ps;
ResultSet rs;
try {
dbcon = DbConnector.getPlayerDbCon();
//ps = dbcon.prepareStatement("SELECT players.name, skills.value, players.deity FROM skills JOIN players ON skills.owner = players.wurmid WHERE skills.number = " + skillNum + " AND (players.power = 0) ORDER BY skills.value DESC LIMIT 20");
ps = dbcon.prepareStatement("SELECT players.name, achievements.counter FROM achievements JOIN players ON achievements.player = players.wurmid WHERE achievements.achievement = " + achievementNum + " AND achievements.counter > 0 AND players.power = 0 ORDER BY achievements.counter DESC LIMIT 20");
rs = ps.executeQuery();
while(rs.next()){
name = rs.getString(1);
counter = rs.getInt(2);
//deity = rs.getInt(3);
names.add(name);
counts.add(counter);
//deities.add(deity);
}
DbUtilities.closeDatabaseObjects(ps, rs);
}
catch (SQLException e) {
throw new RuntimeException(e);
}
f.addBoldText("Top 20 players with achievement "+this.getQuestion(), new String[0]);
f.addBoldText(template.getRequirement(), new String[0]);
f.addText("\n\n", new String[0]);
int i = 0;
DecimalFormat df = new DecimalFormat(".000");
while(i < names.size() && i < counts.size()){
name = names.get(i);
if(!optIn.containsKey(name)){
name = "Unknown";
}else if(optIn.get(name).equals(0)){
name = "Unknown";
}
if(names.get(i).equals(this.getResponder().getName())){
name = names.get(i);
f.addBoldText(counts.get(i) + " - " + name + extra);
}else{
f.addText(counts.get(i) + " - " + name + extra);
}
i++;
}
f.addText(" \n", new String[0]);
f.beginHorizontalFlow();
f.addButton("Ok", "okay");
f.endHorizontalFlow();
f.addText(" \n", new String[0]);
this.getResponder().getCommunicator().sendBml(400, 500, true, true, f.toString(), 150, 150, 200, this.title);
}
}
Loading

0 comments on commit f59852c

Please sign in to comment.