Update to latest stable WyvernMods (1.6).
This commit is contained in:
@@ -0,0 +1,93 @@
|
||||
package com.wurmonline.server.questions;
|
||||
|
||||
import com.wurmonline.server.Items;
|
||||
import com.wurmonline.server.creatures.Creature;
|
||||
import com.wurmonline.server.deities.Deities;
|
||||
import com.wurmonline.server.deities.Deity;
|
||||
import com.wurmonline.server.items.Item;
|
||||
import com.wurmonline.server.players.Player;
|
||||
import net.coldie.tools.BmlForm;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.HashMap;
|
||||
import java.util.Properties;
|
||||
|
||||
public class BookConversionQuestion extends Question {
|
||||
protected Item convertBook;
|
||||
|
||||
public BookConversionQuestion(Creature aResponder, String aTitle, String aQuestion, long aTarget, Item book){
|
||||
super(aResponder, aTitle, aQuestion, 79, aTarget);
|
||||
this.convertBook = book;
|
||||
}
|
||||
|
||||
public static HashMap<Integer, Integer> deityMap = new HashMap<>();
|
||||
|
||||
@Override
|
||||
public void answer(Properties answer) {
|
||||
boolean accepted = answer.containsKey("accept") && answer.get("accept") == "true";
|
||||
if (accepted) {
|
||||
logger.info("Accepted BookOfConversion");
|
||||
int entry = Integer.parseInt(answer.getProperty("deity"));
|
||||
int deity = deityMap.get(entry);
|
||||
if(convertBook == null || convertBook.getOwnerId() != this.getResponder().getWurmId()){
|
||||
this.getResponder().getCommunicator().sendNormalServerMessage("You must own a book of conversion to begin changing faith.");
|
||||
}else{
|
||||
if(this.getResponder() instanceof Player) {
|
||||
try {
|
||||
Player p = (Player) this.getResponder();
|
||||
logger.info("Converting "+p.getName()+" to " + Deities.getDeityName(deity));
|
||||
Items.destroyItem(convertBook.getWurmId());
|
||||
Deity d = Deities.getDeity(deity);
|
||||
p.setDeity(d);
|
||||
p.setPriest(true);
|
||||
if(d.hateGod){
|
||||
p.setAlignment(-Math.abs(p.getAlignment()));
|
||||
}else{
|
||||
p.setAlignment(Math.abs(p.getAlignment()));
|
||||
}
|
||||
p.setFaith(p.getFaith()*0.9f);
|
||||
p.getCommunicator().sendAlertServerMessage(Deities.getDeityName(deity)+" accepts your conversion.");
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}else{
|
||||
logger.info("Non-player used a "+convertBook.getName()+"?");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static String getDeityNames(){
|
||||
String builder = "";
|
||||
int i = 0;
|
||||
Deity[] deities = Deities.getDeities();
|
||||
while(i < deities.length){
|
||||
builder = builder + deities[i].getName();
|
||||
deityMap.put(i, deities[i].getNumber());
|
||||
i++;
|
||||
if(i < deities.length){
|
||||
builder = builder + ",";
|
||||
}
|
||||
}
|
||||
return builder;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendQuestion() {
|
||||
if(convertBook == null || convertBook.getOwnerId() != this.getResponder().getWurmId()){
|
||||
this.getResponder().getCommunicator().sendNormalServerMessage("You must own a book of conversion to begin changing faith.");
|
||||
return;
|
||||
}
|
||||
BmlForm f = new BmlForm("");
|
||||
f.addHidden("id", String.valueOf(this.id));
|
||||
f.addBoldText("Select the deity you would like to convert to\nAccepting this will reduce your faith by 10 percent\n", new String[0]);
|
||||
f.addRaw("harray{label{text='Select New Deity:'}dropdown{id='deity';options='");
|
||||
f.addRaw(getDeityNames());
|
||||
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);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,238 @@
|
||||
package com.wurmonline.server.questions;
|
||||
|
||||
import com.wurmonline.server.DbConnector;
|
||||
import com.wurmonline.server.creatures.Creature;
|
||||
import com.wurmonline.server.skills.SkillSystem;
|
||||
import com.wurmonline.server.utils.DbUtilities;
|
||||
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 LeaderboardCustomQuestion extends Question {
|
||||
protected int entryNum;
|
||||
|
||||
public LeaderboardCustomQuestion(Creature aResponder, String aTitle, String aQuestion, long aTarget, int entryNum){
|
||||
super(aResponder, aTitle, aQuestion, 79, aTarget);
|
||||
this.entryNum = entryNum;
|
||||
}
|
||||
|
||||
@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);
|
||||
}
|
||||
}
|
||||
|
||||
protected ArrayList<String> names = new ArrayList<>();
|
||||
protected ArrayList<Double> values = new ArrayList<>();
|
||||
protected ArrayList<String> extra = new ArrayList<>();
|
||||
protected void totalSkills(int limit){
|
||||
Connection dbcon;
|
||||
PreparedStatement ps;
|
||||
ResultSet rs;
|
||||
String name;
|
||||
int skillNum;
|
||||
double skill;
|
||||
try {
|
||||
dbcon = DbConnector.getPlayerDbCon();
|
||||
ps = dbcon.prepareStatement("SELECT players.name, achievements.counter FROM achievements JOIN players ON achievements.player = players.wurmid WHERE achievements.achievement = 371 AND players.power = 0 ORDER BY achievements.counter DESC LIMIT "+limit);
|
||||
rs = ps.executeQuery();
|
||||
while(rs.next()){
|
||||
name = rs.getString(1);
|
||||
skill = rs.getDouble(2);
|
||||
names.add(name);
|
||||
values.add(skill);
|
||||
}
|
||||
DbUtilities.closeDatabaseObjects(ps, rs);
|
||||
}
|
||||
catch (SQLException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
protected void topAnySkill(int limit){
|
||||
Connection dbcon;
|
||||
PreparedStatement ps;
|
||||
ResultSet rs;
|
||||
String name;
|
||||
int skillNum;
|
||||
double skill;
|
||||
try {
|
||||
dbcon = DbConnector.getPlayerDbCon();
|
||||
ps = dbcon.prepareStatement("SELECT players.name, skills.number, skills.value FROM skills JOIN players ON skills.owner = players.wurmid WHERE players.power = 0 ORDER BY skills.value DESC LIMIT "+limit);
|
||||
rs = ps.executeQuery();
|
||||
while(rs.next()){
|
||||
name = rs.getString(1);
|
||||
skillNum = rs.getInt(2);
|
||||
skill = rs.getDouble(3);
|
||||
names.add(name);
|
||||
values.add(skill);
|
||||
extra.add(SkillSystem.getNameFor(skillNum));
|
||||
}
|
||||
DbUtilities.closeDatabaseObjects(ps, rs);
|
||||
}
|
||||
catch (SQLException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
//select wurmid, count(*) from titles group by wurmid order by count(*) desc;
|
||||
protected void totalTitles(int limit){
|
||||
Connection dbcon;
|
||||
PreparedStatement ps;
|
||||
ResultSet rs;
|
||||
String name;
|
||||
int skillNum;
|
||||
double skill;
|
||||
try {
|
||||
dbcon = DbConnector.getPlayerDbCon();
|
||||
ps = dbcon.prepareStatement("SELECT players.name, COUNT(titles.wurmid) as Count FROM titles JOIN players ON titles.wurmid = players.wurmid WHERE players.power = 0 GROUP BY titles.wurmid ORDER BY Count DESC LIMIT "+limit);
|
||||
rs = ps.executeQuery();
|
||||
while(rs.next()){
|
||||
name = rs.getString(1);
|
||||
skill = rs.getDouble(2);
|
||||
names.add(name);
|
||||
values.add(skill);
|
||||
}
|
||||
DbUtilities.closeDatabaseObjects(ps, rs);
|
||||
}
|
||||
catch (SQLException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
protected void topPlayerStats(String statName, int limit){
|
||||
Connection dbcon;
|
||||
PreparedStatement ps;
|
||||
ResultSet rs;
|
||||
String name;
|
||||
int skillNum;
|
||||
double stat;
|
||||
try {
|
||||
dbcon = ModSupportDb.getModSupportDb();
|
||||
ps = dbcon.prepareStatement("SELECT name, "+statName+" FROM PlayerStats ORDER BY "+statName+" DESC LIMIT "+limit);
|
||||
rs = ps.executeQuery();
|
||||
while(rs.next()){
|
||||
name = rs.getString(1);
|
||||
stat = rs.getDouble(2);
|
||||
names.add(name);
|
||||
values.add(stat);
|
||||
}
|
||||
DbUtilities.closeDatabaseObjects(ps, rs);
|
||||
}
|
||||
catch (SQLException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendQuestion() {
|
||||
BmlForm f = new BmlForm("");
|
||||
f.addHidden("id", String.valueOf(this.id));
|
||||
|
||||
// Populates HashMap with latest opt-in data.
|
||||
identifyOptIn();
|
||||
|
||||
// Identify and execute correct list generation.
|
||||
boolean format = false;
|
||||
boolean ignoreOpt = false;
|
||||
int limit = 20;
|
||||
switch(entryNum){
|
||||
case 0:
|
||||
limit = 50;
|
||||
totalSkills(limit);
|
||||
break;
|
||||
case 1:
|
||||
limit = 50;
|
||||
topAnySkill(limit);
|
||||
format = true;
|
||||
break;
|
||||
case 2:
|
||||
limit = 50;
|
||||
totalTitles(limit);
|
||||
break;
|
||||
case 3:
|
||||
limit = 10;
|
||||
topPlayerStats("kills", limit);
|
||||
ignoreOpt = true;
|
||||
break;
|
||||
case 4:
|
||||
limit = 10;
|
||||
topPlayerStats("deaths", limit);
|
||||
ignoreOpt = true;
|
||||
break;
|
||||
case 5:
|
||||
limit = 10;
|
||||
topPlayerStats("depots", limit);
|
||||
ignoreOpt = true;
|
||||
break;
|
||||
}
|
||||
|
||||
f.addBoldText("Top "+limit+" players in "+this.getQuestion(), new String[0]);
|
||||
f.addText("\n\n", new String[0]);
|
||||
int i = 0;
|
||||
DecimalFormat df = new DecimalFormat(".000");
|
||||
if(!format){
|
||||
df = new DecimalFormat("#");
|
||||
}
|
||||
String name;
|
||||
String line;
|
||||
while(i < names.size() && i < values.size()){
|
||||
name = names.get(i);
|
||||
if(!ignoreOpt) {
|
||||
if (!optIn.containsKey(name)) {
|
||||
name = "Unknown";
|
||||
} else if (optIn.get(name).equals(0)) {
|
||||
name = "Unknown";
|
||||
}
|
||||
}
|
||||
line = df.format(values.get(i)) + " - " + name;
|
||||
if(extra.size() >= i+1){
|
||||
line = line + " ("+ extra.get(i)+")";
|
||||
}
|
||||
if(names.get(i).equals(this.getResponder().getName())){
|
||||
f.addBoldText(line);
|
||||
}else{
|
||||
f.addText(line);
|
||||
}
|
||||
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);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,157 @@
|
||||
package com.wurmonline.server.questions;
|
||||
|
||||
import com.wurmonline.server.Servers;
|
||||
import com.wurmonline.server.creatures.Creature;
|
||||
import com.wurmonline.server.skills.SkillSystem;
|
||||
import com.wurmonline.server.skills.SkillTemplate;
|
||||
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.util.Arrays;
|
||||
import java.util.Comparator;
|
||||
import java.util.HashMap;
|
||||
import java.util.Properties;
|
||||
|
||||
public class LeaderboardQuestion extends Question {
|
||||
|
||||
public LeaderboardQuestion(Creature aResponder, String aTitle, String aQuestion, long aTarget){
|
||||
super(aResponder, aTitle, aQuestion, 79, aTarget);
|
||||
}
|
||||
|
||||
protected void setPlayerOptStatus(String name, int opt){
|
||||
Connection dbcon;
|
||||
PreparedStatement ps;
|
||||
try {
|
||||
dbcon = ModSupportDb.getModSupportDb();
|
||||
ps = dbcon.prepareStatement("UPDATE LeaderboardOpt SET OPTIN = " + opt + " WHERE name = \"" + name + "\"");
|
||||
ps.executeUpdate();
|
||||
ps.close();
|
||||
}
|
||||
catch (SQLException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void answer(Properties answer) {
|
||||
boolean accepted = answer.containsKey("accept") && answer.get("accept") == "true";
|
||||
boolean custom = answer.containsKey("custom") && answer.get("custom") == "true";
|
||||
if (accepted) {
|
||||
int entry = Integer.parseInt(answer.getProperty("leaderboard"));
|
||||
String val = skillMap.get(entry);
|
||||
int skillNum = skillIdMap.get(entry);
|
||||
//this.getResponder().getCommunicator().sendNormalServerMessage("Received response: "+val);
|
||||
LeaderboardSkillQuestion lbsq = new LeaderboardSkillQuestion(this.getResponder(), "Leaderboard", val, this.getResponder().getWurmId(), skillNum);
|
||||
lbsq.sendQuestion();
|
||||
}else if(custom){
|
||||
int entry = Integer.parseInt(answer.getProperty("customboard"));
|
||||
String val = customMap.get(entry);
|
||||
LeaderboardCustomQuestion lbcq = new LeaderboardCustomQuestion(this.getResponder(), "Leaderboard", val, this.getResponder().getWurmId(), entry);
|
||||
lbcq.sendQuestion();
|
||||
}else{
|
||||
String name = this.getResponder().getName();
|
||||
if(answer.containsKey("optin") && answer.get("optin") == "true"){
|
||||
logger.info("Player "+name+" has opted into Leaderboard system.");
|
||||
setPlayerOptStatus(name, 1);
|
||||
this.getResponder().getCommunicator().sendNormalServerMessage("You have opted into the Leaderboard system!");
|
||||
}else if(answer.containsKey("optout") && answer.get("optout") == "true"){
|
||||
logger.info("Player "+name+" has opted out of the Leaderboard system.");
|
||||
setPlayerOptStatus(name, 0);
|
||||
this.getResponder().getCommunicator().sendNormalServerMessage("You have opted out of the Leaderboard system.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected HashMap<Integer, String> skillMap = new HashMap<>();
|
||||
protected HashMap<Integer, Integer> skillIdMap = new HashMap<>();
|
||||
protected HashMap<Integer, String> customMap = new HashMap<>();
|
||||
|
||||
public String getSkillOptions(){
|
||||
String builder = "";
|
||||
SkillTemplate[] skillTemplates = SkillSystem.getAllSkillTemplates();
|
||||
Arrays.sort(skillTemplates, new Comparator<SkillTemplate>(){
|
||||
public int compare(SkillTemplate o1, SkillTemplate o2){
|
||||
return o1.getName().compareTo(o2.getName());
|
||||
}
|
||||
});
|
||||
int i = 0;
|
||||
int index = 0;
|
||||
skillMap.clear();
|
||||
while(i < skillTemplates.length){
|
||||
builder = builder + skillTemplates[i].getName();
|
||||
skillMap.put(index, skillTemplates[i].getName());
|
||||
skillIdMap.put(index, skillTemplates[i].getNumber());
|
||||
i++;
|
||||
index++;
|
||||
if(i < skillTemplates.length){
|
||||
builder = builder + ",";
|
||||
}
|
||||
}
|
||||
return builder;
|
||||
}
|
||||
|
||||
public String getCustomOptions(){
|
||||
String builder = "Total Skill";
|
||||
customMap.put(0, "Total Skill");
|
||||
builder = builder + ",High Skills";
|
||||
customMap.put(1, "High Skills");
|
||||
builder = builder + ",Most Titles";
|
||||
customMap.put(2, "Most Titles");
|
||||
if(Servers.localServer.PVPSERVER || this.getResponder().getPower() >= 5){
|
||||
builder = builder + ",PvP Kills";
|
||||
customMap.put(3, "PvP Kills");
|
||||
builder = builder + ",PvP Deaths";
|
||||
customMap.put(4, "PvP Deaths");
|
||||
builder = builder + ",Depots Captured";
|
||||
customMap.put(5, "PvP Depots Captured");
|
||||
}
|
||||
return builder;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendQuestion() {
|
||||
BmlForm f = new BmlForm("");
|
||||
f.addHidden("id", String.valueOf(this.id));
|
||||
int opted;
|
||||
Connection dbcon;
|
||||
PreparedStatement ps;
|
||||
ResultSet rs;
|
||||
try {
|
||||
dbcon = ModSupportDb.getModSupportDb();
|
||||
ps = dbcon.prepareStatement("SELECT * FROM LeaderboardOpt WHERE name = \"" + this.getResponder().getName() + "\"");
|
||||
rs = ps.executeQuery();
|
||||
opted = rs.getInt("OPTIN");
|
||||
rs.close();
|
||||
ps.close();
|
||||
}
|
||||
catch (SQLException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
f.addBoldText("You are currently " + (opted == 0 ? "not " : "") + "opted into the leaderboard system.\n\n", new String[0]);
|
||||
f.addRaw("harray{label{text='View leaderboard:'}dropdown{id='leaderboard';options='");
|
||||
f.addRaw(getSkillOptions());
|
||||
f.addRaw("'}}");
|
||||
f.beginHorizontalFlow();
|
||||
f.addButton("Accept", "accept");
|
||||
f.endHorizontalFlow();
|
||||
f.addText(" \n\n", new String[0]);
|
||||
f.addBoldText("Opt into or out of the Leaderboard system.");
|
||||
f.beginHorizontalFlow();
|
||||
f.addButton("Opt In", "optin");
|
||||
f.addButton("Opt Out", "optout");
|
||||
f.endHorizontalFlow();
|
||||
f.addText(" \n\n", new String[0]);
|
||||
f.addBoldText("Special leaderboards are available below.");
|
||||
f.addRaw("harray{label{text='View leaderboard:'}dropdown{id='customboard';options='");
|
||||
f.addRaw(getCustomOptions());
|
||||
f.addRaw("'}}");
|
||||
f.beginHorizontalFlow();
|
||||
f.addButton("Accept", "custom");
|
||||
f.endHorizontalFlow();
|
||||
this.getResponder().getCommunicator().sendBml(400, 500, true, true, f.toString(), 150, 150, 200, this.title);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,127 @@
|
||||
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.skills.SkillList;
|
||||
import com.wurmonline.server.skills.SkillSystem;
|
||||
import com.wurmonline.server.skills.SkillTemplate;
|
||||
import com.wurmonline.server.utils.DbUtilities;
|
||||
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 LeaderboardSkillQuestion extends Question {
|
||||
protected int skillNum;
|
||||
|
||||
public LeaderboardSkillQuestion(Creature aResponder, String aTitle, String aQuestion, long aTarget, int skillNum){
|
||||
super(aResponder, aTitle, aQuestion, 79, aTarget);
|
||||
this.skillNum = skillNum;
|
||||
}
|
||||
|
||||
@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<Double> skills = new ArrayList<>();
|
||||
ArrayList<Integer> deities = new ArrayList<>();
|
||||
String name;
|
||||
double skill;
|
||||
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");
|
||||
rs = ps.executeQuery();
|
||||
while(rs.next()){
|
||||
name = rs.getString(1);
|
||||
skill = rs.getDouble(2);
|
||||
deity = rs.getInt(3);
|
||||
names.add(name);
|
||||
skills.add(skill);
|
||||
deities.add(deity);
|
||||
}
|
||||
DbUtilities.closeDatabaseObjects(ps, rs);
|
||||
}
|
||||
catch (SQLException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
f.addBoldText("Top 20 players in "+this.getQuestion(), new String[0]);
|
||||
f.addText("\n\n", new String[0]);
|
||||
int i = 0;
|
||||
DecimalFormat df = new DecimalFormat(".000");
|
||||
while(i < names.size() && i < skills.size()){
|
||||
name = names.get(i);
|
||||
if(!optIn.containsKey(name)){
|
||||
name = "Unknown";
|
||||
}else if(optIn.get(name).equals(0)){
|
||||
name = "Unknown";
|
||||
}
|
||||
if(skillNum == SkillList.CHANNELING){
|
||||
extra = " ("+ Deities.getDeityName(deities.get(i))+")";
|
||||
}
|
||||
if(names.get(i).equals(this.getResponder().getName())){
|
||||
name = names.get(i);
|
||||
f.addBoldText(df.format(skills.get(i)) + " - " + name + extra);
|
||||
}else{
|
||||
f.addText(df.format(skills.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);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,146 @@
|
||||
package com.wurmonline.server.questions;
|
||||
|
||||
import com.wurmonline.mesh.Tiles;
|
||||
import com.wurmonline.server.*;
|
||||
import com.wurmonline.server.creatures.Creature;
|
||||
import com.wurmonline.server.players.Player;
|
||||
import com.wurmonline.server.players.Spawnpoint;
|
||||
import com.wurmonline.server.villages.Village;
|
||||
import com.wurmonline.server.villages.Villages;
|
||||
import net.coldie.tools.BmlForm;
|
||||
import org.gotti.wurmunlimited.modloader.ReflectionUtil;
|
||||
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.util.HashMap;
|
||||
import java.util.Properties;
|
||||
|
||||
public class NewSpawnQuestion extends Question {
|
||||
|
||||
public NewSpawnQuestion(Creature aResponder, String aTitle, String aQuestion, long aTarget){
|
||||
super(aResponder, aTitle, aQuestion, 79, aTarget);
|
||||
}
|
||||
|
||||
public void spawn(Player p, Spawnpoint spawnpoint) {
|
||||
if (p.isDead()) {
|
||||
p.addNewbieBuffs();
|
||||
p.setLayer(0, false);
|
||||
boolean found = false;
|
||||
if (p.isUndead()) {
|
||||
float[] txty = Player.findRandomSpawnX(false, false);
|
||||
float posX = txty[0];
|
||||
float posY = txty[1];
|
||||
p.setTeleportPoints(posX, posY, 0, 0);
|
||||
p.startTeleporting();
|
||||
p.getCommunicator().sendNormalServerMessage("You are cast back into the horrible light.");
|
||||
} else {
|
||||
p.setTeleportPoints(spawnpoint.tilex, spawnpoint.tiley, spawnpoint.surfaced ? 0 : -1, 0);
|
||||
p.startTeleporting();
|
||||
p.getCommunicator().sendNormalServerMessage("You are cast back into the light.");
|
||||
}
|
||||
p.getCommunicator().sendTeleport(false);
|
||||
try { //p.setDead(false);
|
||||
ReflectionUtil.callPrivateMethod(p, ReflectionUtil.getMethod(p.getClass(), "setDead"), false);
|
||||
} catch (IllegalAccessException | InvocationTargetException | NoSuchMethodException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
p.spawnpoints = null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void answer(Properties answer) {
|
||||
boolean accepted = answer.containsKey("accept") && answer.get("accept") == "true";
|
||||
if (accepted) {
|
||||
logger.info("Accepted NewSpawnQuestion");
|
||||
int entry = Integer.parseInt(answer.getProperty("spawnpoint"));
|
||||
Spawnpoint spawn = spawns.get(entry);
|
||||
this.spawn((Player) this.getResponder(), spawn);
|
||||
}else{
|
||||
boolean transfer = answer.containsKey("transfer") && answer.get("transfer") == "true";
|
||||
if(transfer) {
|
||||
try {
|
||||
ServerEntry targetServer = Servers.localServer.serverSouth;
|
||||
Player player = Players.getInstance().getPlayer(this.getResponder().getWurmId());
|
||||
if(targetServer == null){
|
||||
player.getCommunicator().sendNormalServerMessage("Error: Something went wrong [TARGETSERVER=NULL].");
|
||||
}
|
||||
if (!targetServer.isAvailable(player.getPower(), true)) {
|
||||
player.getCommunicator().sendNormalServerMessage(targetServer.name + " is not currently available.");
|
||||
} else {
|
||||
player.sendTransfer(Server.getInstance(), targetServer.EXTERNALIP, Integer.parseInt(targetServer.EXTERNALPORT), targetServer.INTRASERVERPASSWORD, targetServer.getId(), -1, -1, true, false, player.getKingdomId());
|
||||
}
|
||||
} catch (NoSuchPlayerException e) {
|
||||
logger.info("Could not find player for WurmId " + this.getResponder().getWurmId() + " [" + this.getResponder().getName() + "]");
|
||||
e.printStackTrace();
|
||||
}
|
||||
}else {
|
||||
this.getResponder().getCommunicator().sendNormalServerMessage("You can bring the spawn question back by typing /respawn in a chat window.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected static HashMap<Integer, Spawnpoint> spawns = new HashMap<>();
|
||||
|
||||
public Spawnpoint getRandomSpawnpoint(byte spawnNums){
|
||||
int i = 1000;
|
||||
while(i > 0){
|
||||
i--;
|
||||
int x = Server.rand.nextInt(Server.surfaceMesh.getSize());
|
||||
int y = Server.rand.nextInt(Server.surfaceMesh.getSize());
|
||||
short height = Tiles.decodeHeight(Server.surfaceMesh.getTile(x, y));
|
||||
if(height > 0 && height < 1000 && Creature.getTileSteepness(x, y, true)[1] < 30){
|
||||
Village v = Villages.getVillage(x, y, true);
|
||||
if (v == null) {
|
||||
for (int vx = -50; vx < 50; vx += 5) {
|
||||
for (int vy = -50; vy < 50 && (v = Villages.getVillage(x + vx, y + vy, true)) == null; vy += 5) {
|
||||
}
|
||||
}
|
||||
}
|
||||
if(v != null){
|
||||
continue;
|
||||
}
|
||||
return new Spawnpoint(spawnNums, "Random location", (short) x, (short) y, true);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
public String getSpawnpointOptions(){
|
||||
String builder = "";
|
||||
byte spawnNums = 0;
|
||||
if(this.getResponder().citizenVillage != null){
|
||||
Village v = this.getResponder().citizenVillage;
|
||||
short tpx = (short)v.getTokenX();
|
||||
short tpy = (short)v.getTokenY();
|
||||
Spawnpoint home = new Spawnpoint(spawnNums, "Token of " + v.getName(), tpx, tpy, v.isOnSurface());
|
||||
spawns.put((int) spawnNums, home);
|
||||
builder += home.description+",";
|
||||
spawnNums++;
|
||||
}
|
||||
Spawnpoint random = getRandomSpawnpoint(spawnNums);
|
||||
spawns.put((int) spawnNums, random);
|
||||
builder += random.description;
|
||||
return builder;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendQuestion() {
|
||||
BmlForm f = new BmlForm("");
|
||||
f.addHidden("id", String.valueOf(this.id));
|
||||
f.addBoldText("Where would you like to spawn?\n\n", new String[0]);
|
||||
f.addText("\n\n", new String[0]);
|
||||
f.addRaw("harray{label{text='Respawn Point:'}dropdown{id='spawnpoint';options='");
|
||||
f.addRaw(getSpawnpointOptions());
|
||||
f.addRaw("'}}");
|
||||
f.addText("\n\n", new String[0]);
|
||||
f.beginHorizontalFlow();
|
||||
f.addButton("Accept", "accept");
|
||||
f.endHorizontalFlow();
|
||||
f.addText("\n\n", new String[0]);
|
||||
f.addBoldText("Or transfer back to the PvE server:");
|
||||
f.addText("\n\n", new String[0]);
|
||||
f.beginHorizontalFlow();
|
||||
f.addButton("Transfer to PvE", "transfer");
|
||||
f.endHorizontalFlow();
|
||||
this.getResponder().getCommunicator().sendBml(400, 300, true, true, f.toString(), 128, 50, 50, this.title);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user