Skip to content

Commit

Permalink
Upgrade to latest version of WyvernMods.
Browse files Browse the repository at this point in the history
  • Loading branch information
Sindusk committed Jul 23, 2018
1 parent f59852c commit ba8dde1
Show file tree
Hide file tree
Showing 31 changed files with 1,357 additions and 160 deletions.
5 changes: 3 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
apply plugin: 'java'

group "mod.sin"
version "1.0"
version "1.1"

repositories {
mavenCentral()
Expand All @@ -12,8 +12,9 @@ repositories {

dependencies {
compile 'org.gotti.wurmunlimited:server-modlauncher:0.37'
compile 'com.github.Sindusk:sindusklibrary:v1.5'
compile 'com.github.Sindusk:sindusklibrary:v1.7'
compile 'com.github.Sindusk:DiscordRelay:v1.2'
compile 'com.github.Sindusk:DUSKombat:v1.0'
compile 'com.github.Sindusk:TreasureHunting:1.1.4'
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public AffinityOrbQuestion(Creature aResponder, String aTitle, String aQuestion,
this.affinityOrb = orb;
}

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

@Override
public void answer(Properties answer) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,33 @@ protected void topPlayerStats(String statName, int limit){
throw new RuntimeException(e);
}
}
protected void mostCitizens(int limit){
Connection dbcon;
PreparedStatement ps;
ResultSet rs;
String name;
int skillNum;
String mayor;
double stat;
try {
dbcon = DbConnector.getZonesDbCon();
ps = dbcon.prepareStatement("SELECT name, maxcitizens, mayor FROM villages WHERE disbanded = 0 ORDER BY maxcitizens DESC LIMIT "+limit);
rs = ps.executeQuery();
while(rs.next()){
name = rs.getString(1);
stat = rs.getInt(2);
mayor = rs.getString(3);
stat++; // Add one citizen to account for mayor.
names.add(name);
values.add(stat);
extra.add(mayor);
}
DbUtilities.closeDatabaseObjects(ps, rs);
}
catch (SQLException e) {
throw new RuntimeException(e);
}
}

@Override
public void sendQuestion() {
Expand Down Expand Up @@ -347,24 +374,29 @@ public void sendQuestion() {
ignoreOpt = true;
break;
case 8:
limit = 100;
mostCitizens(limit);
ignoreOpt = true;
break;
case 9:
limit = 10;
topPlayerStats("kills", limit);
ignoreOpt = true;
break;
case 9:
case 10:
limit = 10;
topPlayerStats("deaths", limit);
ignoreOpt = true;
break;
case 10:
case 11:
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]);
f.addBoldText("Top "+limit+" players in "+this.getQuestion());
f.addText("\n\n");
int i = 0;
DecimalFormat df = new DecimalFormat(".000");
if(!format){
Expand Down Expand Up @@ -392,11 +424,11 @@ public void sendQuestion() {
}
i++;
}
f.addText(" \n", new String[0]);
f.addText(" \n");
f.beginHorizontalFlow();
f.addButton("Ok", "okay");
f.endHorizontalFlow();
f.addText(" \n", new String[0]);
f.addText(" \n");
this.getResponder().getCommunicator().sendBml(400, 500, true, true, f.toString(), 150, 150, 200, this.title);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -144,13 +144,15 @@ public String getCustomOptions(){
customMap.put(6, "Most Unique Achievements");
builder = builder + ",Largest Structures";
customMap.put(7, "Largest Structures");
builder = builder + ",Most Populated Villages";
customMap.put(8, "Most Populated Villages");
if(Servers.localServer.PVPSERVER || this.getResponder().getPower() >= 5){
builder = builder + ",PvP Kills";
customMap.put(8, "PvP Kills");
customMap.put(9, "PvP Kills");
builder = builder + ",PvP Deaths";
customMap.put(9, "PvP Deaths");
customMap.put(10, "PvP Deaths");
builder = builder + ",Depots Captured";
customMap.put(10, "PvP Depots Captured");
customMap.put(11, "PvP Depots Captured");
}
return builder;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
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;
Expand Down Expand Up @@ -36,6 +34,29 @@ public void answer(Properties answer) {
}
}

public int[] getSkilLevelColors(double skill){
int[] colors = new int[3];
colors[0] = 0; // No red value
if(skill >= 90){
double percentTowards100 = 1-((100-skill)*0.1); // Division by 10
double greenPower = 128 + (128*percentTowards100);
colors[1] = (int) Math.min(255, greenPower);
colors[2] = (int) Math.max(0, 255-greenPower);
}else if(skill >= 50){
double percentTowards90 = 1-((90-skill)*0.025); // Division by 40
double greenPower = percentTowards90*128;
colors[1] = (int) Math.max(128, greenPower);
colors[2] = (int) Math.min(255, 255-greenPower);
}else{
double percentTowards50 = 1-((50-skill)*0.02); // Division by 50
double otherPower = 255 - (percentTowards50*255);
colors[0] = (int) Math.min(255, otherPower);
colors[1] = (int) Math.min(255, Math.max(128, otherPower));
colors[2] = 255;
}
return colors;
}

protected HashMap<String, Integer> optIn = new HashMap<>();
protected void identifyOptIn(){
String name;
Expand Down Expand Up @@ -95,8 +116,8 @@ public void sendQuestion() {
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]);
f.addBoldText("Top 20 players in "+this.getQuestion());
f.addText("\n\n");
int i = 0;
DecimalFormat df = new DecimalFormat(".000");
while(i < names.size() && i < skills.size()){
Expand All @@ -109,19 +130,20 @@ public void sendQuestion() {
if(skillNum == SkillList.CHANNELING){
extra = " ("+ Deities.getDeityName(deities.get(i))+")";
}
int[] color = getSkilLevelColors(skills.get(i));
if(names.get(i).equals(this.getResponder().getName())){
name = names.get(i);
f.addBoldText(df.format(skills.get(i)) + " - " + name + extra);
f.addBoldColoredText(df.format(skills.get(i)) + " - " + name + extra, color[0], color[1], color[2]);
}else{
f.addText(df.format(skills.get(i)) + " - " + name + extra);
f.addColoredText(df.format(skills.get(i)) + " - " + name + extra, color[0], color[1], color[2]);
}
i++;
}
f.addText(" \n", new String[0]);
f.addText(" \n");
f.beginHorizontalFlow();
f.addButton("Ok", "okay");
f.endHorizontalFlow();
f.addText(" \n", new String[0]);
f.addText(" \n");
this.getResponder().getCommunicator().sendBml(400, 500, true, true, f.toString(), 150, 150, 200, this.title);
}
}
101 changes: 101 additions & 0 deletions src/main/java/mod/sin/actions/LeaderboardSkillAction.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
package mod.sin.actions;

import com.wurmonline.server.behaviours.Action;
import com.wurmonline.server.behaviours.ActionEntry;
import com.wurmonline.server.creatures.Creature;
import com.wurmonline.server.items.Item;
import com.wurmonline.server.players.Player;
import com.wurmonline.server.questions.LeaderboardSkillQuestion;
import com.wurmonline.server.skills.NoSuchSkillException;
import com.wurmonline.server.skills.Skill;
import org.gotti.wurmunlimited.modsupport.actions.ActionPerformer;
import org.gotti.wurmunlimited.modsupport.actions.BehaviourProvider;
import org.gotti.wurmunlimited.modsupport.actions.ModAction;
import org.gotti.wurmunlimited.modsupport.actions.ModActions;

import java.util.Collections;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;

public class LeaderboardSkillAction implements ModAction {
private static Logger logger = Logger.getLogger(LeaderboardSkillAction.class.getName());

private final short actionId;
private final ActionEntry actionEntry;

public LeaderboardSkillAction() {
logger.log(Level.WARNING, "LeaderboardSkillAction()");

actionId = (short) ModActions.getNextActionId();
actionEntry = ActionEntry.createEntry(
actionId,
"Open leaderboard",
"opening",
new int[] { 0 /* ACTION_TYPE_NOMOVE */ } // 6 /* ACTION_TYPE_NOMOVE */, 48 /* ACTION_TYPE_ENEMY_ALWAYS */, 36 /* ACTION_TYPE_ALWAYS_USE_ACTIVE_ITEM */
);
ModActions.registerAction(actionEntry);
}

@Override
public BehaviourProvider getBehaviourProvider()
{
return new BehaviourProvider() {
@Override
public List<ActionEntry> getBehavioursFor(Creature performer, Skill skill) {
if(performer instanceof Player && skill.getNumber() > 0) {
return Collections.singletonList(actionEntry);
}

return null;
}

// Never called
@Override
public List<ActionEntry> getBehavioursFor(Creature performer, Item source, Skill skill) {
if (performer instanceof Player && skill.getNumber() > 0) {
return Collections.singletonList(actionEntry);
}

return null;
}
};
}

@Override
public ActionPerformer getActionPerformer()
{
return new ActionPerformer() {

@Override
public short getActionId() {
return actionId;
}
@Override
public boolean action(Action act, Creature performer, Skill skill, short action, float counter) {
LeaderboardSkillQuestion lbsq = new LeaderboardSkillQuestion(performer, "Leaderboard", skill.getName(), performer.getWurmId(), skill.getNumber());
lbsq.sendQuestion();
return true;
}

// Without activated object
@Override
public boolean action(Action act, Creature performer, Item source, Skill skill, short action, float counter) {
if(performer instanceof Player){
this.action(act, performer, skill, action, counter);
}else{
logger.info("Somehow a non-player opened a leaderboard...");
}
return true;
}

@Override
public boolean action(Action act, Creature performer, Item source, Item target, short action, float counter)
{
return this.action(act, performer, target, action, counter);
}


}; // ActionPerformer
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,14 @@ public AffinityCatcherCaptureAction() {
}

public static boolean hasAffinityCatcher(Creature performer){
logger.info("Checking if creature has affinity catcher.");
//logger.info("Checking if creature has affinity catcher.");
for(Item i : performer.getInventory().getItems()){
if(i.getTemplateId() == AffinityCatcher.templateId){
logger.info("Has affinity catcher.");
//logger.info("Has affinity catcher.");
return true;
}
}
logger.info("No affinity catcher found.");
//logger.info("No affinity catcher found.");
return false;
}

Expand Down Expand Up @@ -94,7 +94,6 @@ public boolean action(Action act, Creature performer, Skill skill, short action,
// Without activated object
@Override
public boolean action(Action act, Creature performer, Item source, Skill skill, short action, float counter) {
logger.info("Action with item.");
if(performer instanceof Player){
Player player = (Player) performer;
if (source.getTemplate().getTemplateId() != AffinityCatcher.templateId){
Expand Down Expand Up @@ -134,7 +133,7 @@ public boolean action(Action act, Creature performer, Item source, Skill skill,
// Only called if the affinity is not found or it breaks from having less than one.
player.getCommunicator().sendNormalServerMessage("You must have an affinity in the skill to capture.");
}else{
logger.info("Somehow a non-player activated an Affinity Orb...");
logger.info("Somehow a non-player activated an Affinity Catcher...");
}
return true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,9 +98,15 @@ public boolean action(Action act, Creature performer, Item target, short action,
return true;
}
Affinities.setAffinity(player.getWurmId(), skillNum, affinity.getNumber() + 1, false);
player.getCommunicator().sendSafeServerMessage("Your affinity grows stronger.");
Items.destroyItem(target.getWurmId());
return true;
}
// Has no affinity in this, so should give them one.
Affinities.setAffinity(player.getWurmId(), skillNum, 1, false);
player.getCommunicator().sendSafeServerMessage("You obtain a new affinity.");
Items.destroyItem(target.getWurmId());
return true;
}else{
logger.info("Somehow a non-player activated an Affinity Orb...");
}
Expand Down
Loading

0 comments on commit ba8dde1

Please sign in to comment.