Unarmed skill added, framework for herbalism and excavation skill in.

This commit is contained in:
nossr50 2011-02-07 22:05:12 -08:00
parent 3695b55f38
commit 56f8eb55f7
3 changed files with 245 additions and 1 deletions

View File

@ -2,7 +2,11 @@ package com.bukkit.nossr50.mcMMO;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.entity.Animals;
import org.bukkit.entity.Creature;
import org.bukkit.entity.Entity; import org.bukkit.entity.Entity;
import org.bukkit.entity.Monster;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.event.entity.EntityDamageByEntityEvent; import org.bukkit.event.entity.EntityDamageByEntityEvent;
import org.bukkit.event.entity.EntityDamageEvent; import org.bukkit.event.entity.EntityDamageEvent;
@ -22,9 +26,98 @@ public class mcEntityListener extends EntityListener {
//If attacker is player... //If attacker is player...
if(y instanceof Player){ if(y instanceof Player){
Player attacker = (Player)y; Player attacker = (Player)y;
if(x instanceof Monster){
Monster defender = (Monster)event.getEntity();
if(mcUsers.getProfile(attacker).getUnarmedInt() >= 50 && mcUsers.getProfile(attacker).getUnarmedInt() < 100){
defender.setHealth(calculateDamage(defender, 1));
} else if(mcUsers.getProfile(attacker).getUnarmedInt() >= 100 && mcUsers.getProfile(attacker).getUnarmedInt() < 200){
defender.setHealth(calculateDamage(defender, 2));
} else if(mcUsers.getProfile(attacker).getUnarmedInt() >= 200 && mcUsers.getProfile(attacker).getUnarmedInt() < 325){
defender.setHealth(calculateDamage(defender, 3));
} else if(mcUsers.getProfile(attacker).getUnarmedInt() >= 325 && mcUsers.getProfile(attacker).getUnarmedInt() < 475){
defender.setHealth(calculateDamage(defender, 4));
} else if(mcUsers.getProfile(attacker).getUnarmedInt() >= 475 && mcUsers.getProfile(attacker).getUnarmedInt() < 600){
defender.setHealth(calculateDamage(defender, 5));
} else if(mcUsers.getProfile(attacker).getUnarmedInt() >= 600 && mcUsers.getProfile(attacker).getUnarmedInt() < 775){
defender.setHealth(calculateDamage(defender, 6));
} else if(mcUsers.getProfile(attacker).getUnarmedInt() >= 775 && mcUsers.getProfile(attacker).getUnarmedInt() < 950){
defender.setHealth(calculateDamage(defender, 7));
} else if(mcUsers.getProfile(attacker).getUnarmedInt() >= 950){
defender.setHealth(calculateDamage(defender, 8));
}
//XP
if(Math.random() * 10 > 8){
mcUsers.getProfile(attacker).skillUpUnarmed(1);
attacker.sendMessage(ChatColor.YELLOW+"Unarmed skill increased by 1. Total ("+mcUsers.getProfile(attacker).getUnarmed()+")");
}
}
if(x instanceof Animals){
Animals defender = (Animals)event.getEntity();
if(mcUsers.getProfile(attacker).getUnarmedInt() >= 50 && mcUsers.getProfile(attacker).getUnarmedInt() < 100){
defender.setHealth(calculateDamage(defender, 1));
} else if(mcUsers.getProfile(attacker).getUnarmedInt() >= 100 && mcUsers.getProfile(attacker).getUnarmedInt() < 200){
defender.setHealth(calculateDamage(defender, 2));
} else if(mcUsers.getProfile(attacker).getUnarmedInt() >= 200 && mcUsers.getProfile(attacker).getUnarmedInt() < 325){
defender.setHealth(calculateDamage(defender, 3));
} else if(mcUsers.getProfile(attacker).getUnarmedInt() >= 325 && mcUsers.getProfile(attacker).getUnarmedInt() < 475){
defender.setHealth(calculateDamage(defender, 4));
} else if(mcUsers.getProfile(attacker).getUnarmedInt() >= 475 && mcUsers.getProfile(attacker).getUnarmedInt() < 600){
defender.setHealth(calculateDamage(defender, 5));
} else if(mcUsers.getProfile(attacker).getUnarmedInt() >= 600 && mcUsers.getProfile(attacker).getUnarmedInt() < 775){
defender.setHealth(calculateDamage(defender, 6));
} else if(mcUsers.getProfile(attacker).getUnarmedInt() >= 775 && mcUsers.getProfile(attacker).getUnarmedInt() < 950){
defender.setHealth(calculateDamage(defender, 7));
} else if(mcUsers.getProfile(attacker).getUnarmedInt() >= 950){
defender.setHealth(calculateDamage(defender, 8));
}
}
//If defender is player //If defender is player
if(x instanceof Player){ if(x instanceof Player){
Player defender = (Player)x; Player defender = (Player)x;
if(attacker.getItemInHand().getTypeId() == 0){
//DMG MODIFIER
if((mcUsers.getProfile(defender).inParty() && mcUsers.getProfile(attacker).inParty())&& !mcUsers.getProfile(defender).getParty().equals(mcUsers.getProfile(attacker).getParty())) {
if(mcUsers.getProfile(attacker).getUnarmedInt() >= 50 && mcUsers.getProfile(attacker).getUnarmedInt() < 100){
defender.setHealth(calculateDamage(defender, 1));
} else if(mcUsers.getProfile(attacker).getUnarmedInt() >= 100 && mcUsers.getProfile(attacker).getUnarmedInt() < 200){
defender.setHealth(calculateDamage(defender, 2));
} else if(mcUsers.getProfile(attacker).getUnarmedInt() >= 200 && mcUsers.getProfile(attacker).getUnarmedInt() < 325){
defender.setHealth(calculateDamage(defender, 3));
} else if(mcUsers.getProfile(attacker).getUnarmedInt() >= 325 && mcUsers.getProfile(attacker).getUnarmedInt() < 475){
defender.setHealth(calculateDamage(defender, 4));
} else if(mcUsers.getProfile(attacker).getUnarmedInt() >= 475 && mcUsers.getProfile(attacker).getUnarmedInt() < 600){
defender.setHealth(calculateDamage(defender, 5));
} else if(mcUsers.getProfile(attacker).getUnarmedInt() >= 600 && mcUsers.getProfile(attacker).getUnarmedInt() < 775){
defender.setHealth(calculateDamage(defender, 6));
} else if(mcUsers.getProfile(attacker).getUnarmedInt() >= 775 && mcUsers.getProfile(attacker).getUnarmedInt() < 950){
defender.setHealth(calculateDamage(defender, 7));
} else if(mcUsers.getProfile(attacker).getUnarmedInt() >= 950){
defender.setHealth(calculateDamage(defender, 8));
}
if(mcUsers.getProfile(defender).isDead())
return;
}
//XP
if(Math.random() * 10 > 9){
mcUsers.getProfile(attacker).skillUpUnarmed(1);
attacker.sendMessage(ChatColor.YELLOW+"Unarmed skill increased by 1. Total ("+mcUsers.getProfile(attacker).getUnarmed()+")");
}
//PROC
if(simulateUnarmedProc(attacker)){
attacker.sendMessage(ChatColor.DARK_RED+"You have hit with great force.");
Location loc = defender.getLocation();
ItemStack item = defender.getItemInHand();
loc.getWorld().dropItemNaturally(loc, item);
item.setTypeId(0);
}
if(defender.getHealth() <= 0){
for(Player derp : plugin.getServer().getOnlinePlayers()){
derp.sendMessage(ChatColor.GRAY+attacker.getName() + " has " +ChatColor.DARK_RED+"slain "+ChatColor.GRAY+defender.getName());
mcUsers.getProfile(defender).setDead(true);
}
}
return;
}
if(mcUsers.getProfile(defender).isDead()) if(mcUsers.getProfile(defender).isDead())
return; return;
if((defender.getHealth() - event.getDamage()) <= 0){ if((defender.getHealth() - event.getDamage()) <= 0){
@ -39,6 +132,45 @@ public class mcEntityListener extends EntityListener {
} }
} }
} }
public boolean simulateUnarmedProc(Player player){
if(mcUsers.getProfile(player).getUnarmedInt() >= 750){
if(Math.random() * 10 > 4){
return true;
}
}if(mcUsers.getProfile(player).getUnarmedInt() >= 350 && mcUsers.getProfile(player).getUnarmedInt() < 750){
if(Math.random() * 10 > 4){
return true;
}
}
return false;
}
public int calculateDamage(Player player, int dmg){
int health = player.getHealth();
if(health - dmg <0){
return 0;
} else {
health-= dmg;
return health;
}
}
public int calculateDamage(Monster monster, int dmg){
int health = monster.getHealth();
if(health - dmg <0){
return 0;
} else {
health-= dmg;
return health;
}
}
public int calculateDamage(Animals animal, int dmg){
int health = animal.getHealth();
if(health - dmg <0){
return 0;
} else {
health-= dmg;
return health;
}
}
public void onEntityDamage(EntityDamageEvent event) { public void onEntityDamage(EntityDamageEvent event) {
//Thanks to TimberJaw for sharing his source code! //Thanks to TimberJaw for sharing his source code!
Entity x = event.getEntity(); Entity x = event.getEntity();

View File

@ -74,6 +74,10 @@ public class mcPlayerListener extends PlayerListener {
Block block = event.getBlockClicked(); Block block = event.getBlockClicked();
Player player = event.getPlayer(); Player player = event.getPlayer();
ItemStack is = player.getItemInHand(); ItemStack is = player.getItemInHand();
if(block != null && block.getTypeId() == 42 && player.getItemInHand().getDurability() <= 0){
player.sendMessage(ChatColor.YELLOW+"That is at full durability.");
return;
}
if(block != null && block.getTypeId() == 42){ if(block != null && block.getTypeId() == 42){
short durability = is.getDurability(); short durability = is.getDurability();
if(mcm.getInstance().isArmor(is) && block.getTypeId() == 42){ if(mcm.getInstance().isArmor(is) && block.getTypeId() == 42){
@ -126,6 +130,7 @@ public class mcPlayerListener extends PlayerListener {
String[] split = event.getMessage().split(" "); String[] split = event.getMessage().split(" ");
String playerName = player.getName(); String playerName = player.getName();
if(split[0].equalsIgnoreCase("/mcmmo")){ if(split[0].equalsIgnoreCase("/mcmmo")){
event.setCancelled(true);
player.sendMessage(ChatColor.GRAY+"mcMMO is an RPG inspired plugin"); player.sendMessage(ChatColor.GRAY+"mcMMO is an RPG inspired plugin");
player.sendMessage(ChatColor.GRAY+"You can gain skills in several professions by"); player.sendMessage(ChatColor.GRAY+"You can gain skills in several professions by");
player.sendMessage(ChatColor.GRAY+"doing things related to that profession."); player.sendMessage(ChatColor.GRAY+"doing things related to that profession.");
@ -144,6 +149,7 @@ public class mcPlayerListener extends PlayerListener {
player.sendMessage(ChatColor.GREEN+"Find out mcMMO commands with /mcc"); player.sendMessage(ChatColor.GREEN+"Find out mcMMO commands with /mcc");
} }
if(split[0].equalsIgnoreCase("/mcc")){ if(split[0].equalsIgnoreCase("/mcc")){
event.setCancelled(true);
player.sendMessage(ChatColor.GRAY+"mcMMO has a party system included"); player.sendMessage(ChatColor.GRAY+"mcMMO has a party system included");
player.sendMessage(ChatColor.GREEN+"~~Commands~~"); player.sendMessage(ChatColor.GREEN+"~~Commands~~");
player.sendMessage(ChatColor.GRAY+"/party <name> - to join a party"); player.sendMessage(ChatColor.GRAY+"/party <name> - to join a party");
@ -157,6 +163,7 @@ public class mcPlayerListener extends PlayerListener {
player.sendMessage(ChatColor.GRAY+"/whois - view detailed info about a player (req op)"); player.sendMessage(ChatColor.GRAY+"/whois - view detailed info about a player (req op)");
} }
if(mcUsers.getProfile(player).inParty() && split[0].equalsIgnoreCase("/ptp")){ if(mcUsers.getProfile(player).inParty() && split[0].equalsIgnoreCase("/ptp")){
event.setCancelled(true);
if(split.length < 2){ if(split.length < 2){
player.sendMessage(ChatColor.RED+"Usage is /ptp <playername>"); player.sendMessage(ChatColor.RED+"Usage is /ptp <playername>");
return; return;
@ -171,6 +178,7 @@ public class mcPlayerListener extends PlayerListener {
} }
} }
if(player.isOp() && split[0].equalsIgnoreCase("/whois")){ if(player.isOp() && split[0].equalsIgnoreCase("/whois")){
event.setCancelled(true);
if(split.length < 2){ if(split.length < 2){
player.sendMessage(ChatColor.RED + "Proper usage is /whois <playername>"); player.sendMessage(ChatColor.RED + "Proper usage is /whois <playername>");
return; return;
@ -192,6 +200,9 @@ public class mcPlayerListener extends PlayerListener {
player.sendMessage("Mining Skill: "+mcUsers.getProfile(target).getMining()); player.sendMessage("Mining Skill: "+mcUsers.getProfile(target).getMining());
player.sendMessage("Repair Skill: "+mcUsers.getProfile(target).getRepair()); player.sendMessage("Repair Skill: "+mcUsers.getProfile(target).getRepair());
player.sendMessage("Woodcutting Skill: "+mcUsers.getProfile(target).getWoodCutting()); player.sendMessage("Woodcutting Skill: "+mcUsers.getProfile(target).getWoodCutting());
player.sendMessage("Unarmed Skill: "+mcUsers.getProfile(target).getUnarmed());
player.sendMessage("Herbalism Skill: "+mcUsers.getProfile(target).getHerbalism());
player.sendMessage("Excavation Skill: "+mcUsers.getProfile(target).getWoodCutting());
player.sendMessage(ChatColor.GREEN+"~~COORDINATES~~"); player.sendMessage(ChatColor.GREEN+"~~COORDINATES~~");
player.sendMessage("X: "+x); player.sendMessage("X: "+x);
player.sendMessage("Y: "+y); player.sendMessage("Y: "+y);
@ -199,6 +210,7 @@ public class mcPlayerListener extends PlayerListener {
} }
} }
if(split[0].equalsIgnoreCase("/setmyspawn")){ if(split[0].equalsIgnoreCase("/setmyspawn")){
event.setCancelled(true);
double x = player.getLocation().getX(); double x = player.getLocation().getX();
double y = player.getLocation().getY(); double y = player.getLocation().getY();
double z = player.getLocation().getZ(); double z = player.getLocation().getZ();
@ -206,18 +218,24 @@ public class mcPlayerListener extends PlayerListener {
player.sendMessage(ChatColor.DARK_AQUA + "Myspawn has been set to your current location."); player.sendMessage(ChatColor.DARK_AQUA + "Myspawn has been set to your current location.");
} }
if(player.isOp() && split[0].equalsIgnoreCase("/setspawn")){ if(player.isOp() && split[0].equalsIgnoreCase("/setspawn")){
event.setCancelled(true);
spawn = player.getLocation(); spawn = player.getLocation();
player.sendMessage("Spawn set to current location"); player.sendMessage("Spawn set to current location");
} }
if(split[0].equalsIgnoreCase("/stats")){ if(split[0].equalsIgnoreCase("/stats")){
event.setCancelled(true);
player.sendMessage(ChatColor.DARK_GREEN + "mcMMO stats"); player.sendMessage(ChatColor.DARK_GREEN + "mcMMO stats");
player.sendMessage(ChatColor.DARK_GREEN + "Mining Skill: " + mcUsers.getProfile(player).getMining()); player.sendMessage(ChatColor.DARK_GREEN + "Mining Skill: " + mcUsers.getProfile(player).getMining());
player.sendMessage(ChatColor.DARK_GREEN + "Repair Skill: " + mcUsers.getProfile(player).getRepair()); player.sendMessage(ChatColor.DARK_GREEN + "Repair Skill: " + mcUsers.getProfile(player).getRepair());
player.sendMessage(ChatColor.DARK_GREEN + "Woodcutting Skill: "+mcUsers.getProfile(player).getWoodCutting()); player.sendMessage(ChatColor.DARK_GREEN + "Woodcutting Skill: "+mcUsers.getProfile(player).getWoodCutting());
player.sendMessage(ChatColor.DARK_GREEN + "Unarmed Skill: " + mcUsers.getProfile(player).getUnarmed());
player.sendMessage(ChatColor.DARK_GREEN + "Herbalism Skill: " + mcUsers.getProfile(player).getHerbalism());
player.sendMessage(ChatColor.DARK_GREEN + "Excavation Skill: " + mcUsers.getProfile(player).getExcavation());
player.sendMessage(ChatColor.GRAY + "Increases depending on the material you mine"); player.sendMessage(ChatColor.GRAY + "Increases depending on the material you mine");
} }
//Party command //Party command
if(split[0].equalsIgnoreCase("/party")){ if(split[0].equalsIgnoreCase("/party")){
event.setCancelled(true);
if(split.length == 1 && !mcUsers.getProfile(player).inParty()){ if(split.length == 1 && !mcUsers.getProfile(player).inParty()){
player.sendMessage("Proper usage is /party <name> or 'q' to quit"); player.sendMessage("Proper usage is /party <name> or 'q' to quit");
return; return;
@ -254,6 +272,7 @@ public class mcPlayerListener extends PlayerListener {
} }
} }
if(split[0].equalsIgnoreCase("/p")){ if(split[0].equalsIgnoreCase("/p")){
event.setCancelled(true);
if(mcConfig.getInstance().isAdminToggled(player.getName())) if(mcConfig.getInstance().isAdminToggled(player.getName()))
mcConfig.getInstance().toggleAdminChat(playerName); mcConfig.getInstance().toggleAdminChat(playerName);
mcConfig.getInstance().togglePartyChat(playerName); mcConfig.getInstance().togglePartyChat(playerName);
@ -264,6 +283,7 @@ public class mcPlayerListener extends PlayerListener {
} }
} }
if(split[0].equalsIgnoreCase("/a") && player.isOp()){ if(split[0].equalsIgnoreCase("/a") && player.isOp()){
event.setCancelled(true);
if(mcConfig.getInstance().isPartyToggled(player.getName())) if(mcConfig.getInstance().isPartyToggled(player.getName()))
mcConfig.getInstance().togglePartyChat(playerName); mcConfig.getInstance().togglePartyChat(playerName);
mcConfig.getInstance().toggleAdminChat(playerName); mcConfig.getInstance().toggleAdminChat(playerName);
@ -274,6 +294,7 @@ public class mcPlayerListener extends PlayerListener {
} }
} }
if(split[0].equalsIgnoreCase("/myspawn")){ if(split[0].equalsIgnoreCase("/myspawn")){
event.setCancelled(true);
if(mcUsers.getProfile(player).getMySpawn(player) != null){ if(mcUsers.getProfile(player).getMySpawn(player) != null){
player.getInventory().clear(); player.getInventory().clear();
player.setHealth(20); player.setHealth(20);
@ -284,6 +305,7 @@ public class mcPlayerListener extends PlayerListener {
} }
} }
if(split[0].equalsIgnoreCase("/spawn")){ if(split[0].equalsIgnoreCase("/spawn")){
event.setCancelled(true);
if(spawn != null){ if(spawn != null){
player.teleportTo(spawn); player.teleportTo(spawn);
player.sendMessage("Welcome to spawn, home of the feeble."); player.sendMessage("Welcome to spawn, home of the feeble.");

View File

@ -154,7 +154,7 @@ class PlayerList
class PlayerProfile class PlayerProfile
{ {
protected final Logger log = Logger.getLogger("Minecraft"); protected final Logger log = Logger.getLogger("Minecraft");
private String playerName, gather, wgather, woodcutting, repair, mining, party, myspawn; private String playerName, gather, wgather, woodcutting, repair, mining, party, myspawn, unarmed, herbalism, excavation;
private boolean dead; private boolean dead;
char defaultColor; char defaultColor;
@ -176,6 +176,9 @@ class PlayerList
myspawn = new String(); myspawn = new String();
mining = new String(); mining = new String();
repair = new String(); repair = new String();
unarmed = new String();
herbalism = new String();
excavation = new String();
//mining = "0"; //mining = "0";
wgather = new String(); wgather = new String();
//wgather = "0"; //wgather = "0";
@ -222,6 +225,12 @@ class PlayerList
wgather = character[6]; wgather = character[6];
if(character.length > 7) if(character.length > 7)
repair = character[7]; repair = character[7];
if(character.length > 8)
unarmed = character[8];
if(character.length > 9)
herbalism = character[9];
if(character.length > 10)
repair = character[10];
in.close(); in.close();
return true; return true;
} }
@ -268,6 +277,9 @@ class PlayerList
writer.append(woodcutting+":"); writer.append(woodcutting+":");
writer.append(wgather+":"); writer.append(wgather+":");
writer.append(repair+":"); writer.append(repair+":");
writer.append(unarmed+":");
writer.append(herbalism+":");
writer.append(excavation+":");
writer.append("\r\n"); writer.append("\r\n");
} }
} }
@ -296,6 +308,9 @@ class PlayerList
out.append(0+":"); //woodcutting out.append(0+":"); //woodcutting
out.append(0+":"); //wgather out.append(0+":"); //wgather
out.append(0+":"); //repair out.append(0+":"); //repair
out.append(0+":"); //unarmed
out.append(0+":"); //herbalism
out.append(0+":"); //excavation
//Add more in the same format as the line above //Add more in the same format as the line above
out.newLine(); out.newLine();
@ -343,6 +358,48 @@ class PlayerList
mining = Integer.toString(x); mining = Integer.toString(x);
save(); save();
} }
public void skillUpUnarmed(int newskill){
int x = 0;
if(unarmed != null){
if(isInt(unarmed)){
x = Integer.parseInt(unarmed);
}else {
unarmed = "0";
x = Integer.parseInt(unarmed);
}
}
x += newskill;
unarmed = Integer.toString(x);
save();
}
public void skillUpHerbalism(int newskill){
int x = 0;
if(herbalism != null){
if(isInt(herbalism)){
x = Integer.parseInt(herbalism);
}else {
herbalism = "0";
x = Integer.parseInt(herbalism);
}
}
x += newskill;
herbalism = Integer.toString(x);
save();
}
public void skillUpExcavation(int newskill){
int x = 0;
if(excavation != null){
if(isInt(excavation)){
x = Integer.parseInt(excavation);
}else {
excavation = "0";
x = Integer.parseInt(excavation);
}
}
x += newskill;
excavation = Integer.toString(x);
save();
}
public void skillUpWoodcutting(int newskill){ public void skillUpWoodcutting(int newskill){
int x = 0; int x = 0;
if(woodcutting != null){ if(woodcutting != null){
@ -363,6 +420,15 @@ class PlayerList
public String getMining(){ public String getMining(){
return mining; return mining;
} }
public String getUnarmed(){
return unarmed;
}
public String getHerbalism(){
return herbalism;
}
public String getExcavation(){
return excavation;
}
public int getMiningInt(){ public int getMiningInt(){
if(isInt(mining)){ if(isInt(mining)){
int x = Integer.parseInt(mining); int x = Integer.parseInt(mining);
@ -371,6 +437,30 @@ class PlayerList
return 0; return 0;
} }
} }
public int getUnarmedInt(){
if(isInt(unarmed)){
int x = Integer.parseInt(unarmed);
return x;
} else{
return 0;
}
}
public int getHerbalismInt(){
if(isInt(herbalism)){
int x = Integer.parseInt(herbalism);
return x;
} else{
return 0;
}
}
public int getExcavationInt(){
if(isInt(excavation)){
int x = Integer.parseInt(excavation);
return x;
} else{
return 0;
}
}
public int getRepairInt(){ public int getRepairInt(){
if(isInt(repair)){ if(isInt(repair)){
int x = Integer.parseInt(repair); int x = Integer.parseInt(repair);