Skip to content

Commit

Permalink
fix: 护甲宝石镶嵌、控制台给予经验
Browse files Browse the repository at this point in the history
  • Loading branch information
Mcayear committed Aug 16, 2024
1 parent b2bb11f commit 6c2aadf
Show file tree
Hide file tree
Showing 8 changed files with 124 additions and 94 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>RcRPG.RcRPGMain</groupId>
<artifactId>RcRPG</artifactId>
<version>1.1.3-MOT</version>
<version>1.1.4-MOT</version>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
Expand Down
32 changes: 29 additions & 3 deletions src/main/java/RcRPG/Events.java
Original file line number Diff line number Diff line change
Expand Up @@ -512,8 +512,8 @@ public void damageEvent(EntityDamageByEntityEvent event){
}
if (damagerIsPlayer) {
((Player) damager).sendMessage(RcRPGMain.getI18n().tr(((Player) damager).getLanguageCode(), "rcrpg.events.life_steal_message", lifeSteal));
if (hasDisplayDamage) DamageApi.displayAsParticle(new DamageTextDTO(finalDamage, wounded, "damage:ph"));
}
if (hasDisplayDamage) DamageApi.displayAsParticle(new DamageTextDTO(finalDamage, wounded, "damage:ph"));
}
}

Expand All @@ -533,7 +533,7 @@ public void damageEvent(EntityDamageByEntityEvent event){
Damage.onDamage((Player) damager, wounded);

if (crtDamage > 0) {
if (hasDisplayDamage) DamageApi.displayAsParticle(new DamageTextDTO(finalDamage, wounded, "damage:ed"));
if (hasDisplayDamage) DamageApi.displayAsParticle(new DamageTextDTO((int) crtDamage, wounded, "damage:ed"));
((Player) damager).sendMessage(RcRPGMain.getI18n().tr(((Player) damager).getLanguageCode(), "rcrpg.events.critical_damage_message", woundedName, crtDamage));
}

Expand Down Expand Up @@ -568,7 +568,33 @@ public void toggleSprintEvent(PlayerToggleSprintEvent event) {
PlayerAttr attr = PlayerAttr.getPlayerAttr(player);
if (attr == null) return;
float speedAddition = attr.movementSpeedMultiplier;// 处理移速加成
//TODO: if (speedAddition > 0) player.sendMovementSpeed(speedAddition);
if (speedAddition <= -1) {
return;
}

float finalSpeed = Player.DEFAULT_SPEED;

Effect speedEffect = player.getEffect(Effect.SPEED);
if (speedEffect != null) {
finalSpeed *= (1 + 0.2f * (speedEffect.getAmplifier() + 1));
}

Effect slownessEffect = player.getEffect(Effect.SLOWNESS);
if (slownessEffect != null) {
finalSpeed *= (1 - 0.15f * (slownessEffect.getAmplifier() + 1));
}

// 处理移速加成
finalSpeed *= (1 + speedAddition);

// // 处理冲刺状态的影响
// if (event.isSprinting()) {
// finalSpeed *= 1.3f;
// } else {
// finalSpeed /= 1.3f;
// }

player.setMovementSpeed(finalSpeed);
}

@EventHandler
Expand Down
150 changes: 78 additions & 72 deletions src/main/java/RcRPG/RPG/Armour.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public class Armour extends ItemAttr {

/**
* -- SETTER --
* 仅作为属性分类的标识
* 仅作为属性分类的标识
*
* @param label
*/
Expand All @@ -37,7 +37,7 @@ public class Armour extends ItemAttr {

/**
* -- GETTER --
* 物品名,替代源label用法
* 物品名,替代源label用法
*
* @return
*/
Expand All @@ -49,13 +49,13 @@ public class Armour extends ItemAttr {
private int health;

private int damage;

private int reDamage;

private ArrayList<Effect> effects = new ArrayList<>();

@Getter
private Object attr;
private Map<String, Object> attr;

private int stone;

Expand All @@ -81,15 +81,15 @@ public class Armour extends ItemAttr {
private ArrayList<String> stoneList = new ArrayList<>();

private ArrayList<String> loreList = new ArrayList<>();
public Armour(String name,Config config){

public Armour(String name, Config config) {
this.name = name;
this.config = config;
}

public static Armour loadArmour(String name,Config config){
try{
Armour armour = new Armour(name,config);
public static Armour loadArmour(String name, Config config) {
try {
Armour armour = new Armour(name, config);

armour.setLabel(config.getString("标签"));
armour.setShowName(config.getString("显示名称"));
Expand Down Expand Up @@ -126,9 +126,9 @@ public static Armour loadArmour(String name,Config config){
armour.setStoneList(stoneList);

return armour;
}catch(Exception e){
} catch (Exception e) {
e.printStackTrace();
RcRPGMain.getInstance().getLogger().error("加载盔甲"+name+"配置文件失败");
RcRPGMain.getInstance().getLogger().error("加载盔甲" + name + "配置文件失败");
return null;
}
}
Expand All @@ -147,7 +147,7 @@ private static ColorRGB loadColorFromConfig(Config config) {
private static ArrayList<Effect> loadEffectsFromConfig(Config config) {
ArrayList<Effect> effects = new ArrayList<>();
if (!config.exists("药水效果")) {
return effects;
return effects;
}
for (String effect : config.getStringList("药水效果")) {
String[] parts = effect.split(":");
Expand All @@ -161,44 +161,45 @@ private static ArrayList<Effect> loadEffectsFromConfig(Config config) {
}


public static Config getArmourConfig(String name){
File file = new File(RcRPGMain.getInstance().getDataFolder()+"/Armour/"+name+".yml");
public static Config getArmourConfig(String name) {
File file = new File(RcRPGMain.getInstance().getDataFolder() + "/Armour/" + name + ".yml");
Config config;
if(file.exists()){
config = new Config(file,Config.YAML);
}else{
if (file.exists()) {
config = new Config(file, Config.YAML);
} else {
return null;
}
return config;
}

public static Config addArmourConfig(String name,String id){
if(getArmourConfig(name) == null){
RcRPGMain.getInstance().saveResource("Armour/Armour.yml","/Armour/"+name+".yml",false);
Config config = new Config(RcRPGMain.getInstance().getArmourFile()+"/"+name+".yml");
config.set("物品ID",id);
public static Config addArmourConfig(String name, String id) {
if (getArmourConfig(name) == null) {
RcRPGMain.getInstance().saveResource("Armour/Armour.yml", "/Armour/" + name + ".yml", false);
Config config = new Config(RcRPGMain.getInstance().getArmourFile() + "/" + name + ".yml");
config.set("物品ID", id);
config.save();
return config;
}
return null;
}

public static boolean delArmourConfig(String name){
if(getArmourConfig(name) != null){
File file = new File(RcRPGMain.getInstance().getArmourFile(), name+".yml");
public static boolean delArmourConfig(String name) {
if (getArmourConfig(name) != null) {
File file = new File(RcRPGMain.getInstance().getArmourFile(), name + ".yml");
file.delete();
return true;
}
return false;
}

public static Item getItem(String name, int count) {
Armour armour = RcRPGMain.loadArmour.get(name);
Item item = armour.getItem();
item.setCount(count);
CompoundTag tag = item.hasCompoundTag() ? item.getNamedTag() : new CompoundTag();
tag.putString("type","armour");
tag.putString("name",name);
tag.putByte("Unbreakable",1);
tag.putString("type", "armour");
tag.putString("name", name);
tag.putByte("Unbreakable", 1);

if (!armour.getColor().isEmpty()) {
tag.putInt("customColor", armour.getColor().getRgb());
Expand All @@ -209,8 +210,9 @@ public static Item getItem(String name, int count) {
Armour.setArmourLore(item);
return item;
}
public static boolean giveArmour(Player player, String name, int count){
if(!RcRPGMain.loadArmour.containsKey(name)) {

public static boolean giveArmour(Player player, String name, int count) {
if (!RcRPGMain.loadArmour.containsKey(name)) {
return false;
}
Armour armour = RcRPGMain.loadArmour.get(name);
Expand All @@ -219,130 +221,133 @@ public static boolean giveArmour(Player player, String name, int count){
return false;
}
player.getInventory().addItem(item);
if(!armour.getMyMessage().isEmpty()){
if (!armour.getMyMessage().isEmpty()) {
String text = armour.getMyMessage();
if(text.contains("@player")) text = text.replace("@player", player.getName());
if(text.contains("@item")) text = text.replace("@item", armour.getLabel());
if (text.contains("@player")) text = text.replace("@player", player.getName());
if (text.contains("@item")) text = text.replace("@item", armour.getLabel());
player.sendMessage(text);
}
if(!armour.getServerMessage().isEmpty()){
if (!armour.getServerMessage().isEmpty()) {
String text = armour.getServerMessage();
if(text.contains("@player")) text = text.replace("@player", player.getName());
if(text.contains("@item")) text = text.replace("@item", armour.getLabel());
if (text.contains("@player")) text = text.replace("@player", player.getName());
if (text.contains("@item")) text = text.replace("@item", armour.getLabel());
RcRPGMain.getInstance().getServer().broadcastMessage(text);
}
return true;
}

public static boolean isArmour(Item item){
if(item.getNamedTag() == null) {
public static boolean isArmour(Item item) {
if (item.getNamedTag() == null) {
return false;
}
if(!item.getNamedTag().contains("type")){
if (!item.getNamedTag().contains("type")) {
return false;
}
return item.getNamedTag().getString("type").equals("armour");
}

public static LinkedList<Stone> getStones(Item item){
public static LinkedList<Stone> getStones(Item item) {
LinkedList<Stone> list = new LinkedList<>();
if (!isArmour(item) || item.getNamedTag() == null) return list;
ListTag<StringTag> tags = item.getNamedTag().getList("stone",StringTag.class);
for(StringTag tag : tags.getAll()){
ListTag<StringTag> tags = item.getNamedTag().getList("stone", StringTag.class);
for (StringTag tag : tags.getAll()) {
list.add(Handle.getStoneViaName(tag.parseValue()));
}
Armour armour = RcRPGMain.loadArmour.get(item.getNamedTag().getString("name"));
while(list.size() < armour.getStone()){
while (list.size() < armour.getStone()) {
list.add(null);
}
return list;
}

public static int getStoneSize(Item item){
public static int getStoneSize(Item item) {
LinkedList<Stone> list = Armour.getStones(item);
int i = 0;
for(Stone stone : list){
if(stone != null) i++;
for (Stone stone : list) {
if (stone != null) i++;
}
return i;
}

@Deprecated
public static boolean canInlay(Item item){
if(Armour.isArmour(item)){
public static boolean canInlay(Item item) {
if (Armour.isArmour(item)) {
Armour armour = RcRPGMain.loadArmour.get(item.getNamedTag().getString("name"));
return Armour.getStoneSize(item) < armour.getStone();
}else{
} else {
return false;
}
}

public static void setStone(Player player,Item item,LinkedList<Stone> list){
public static void setStone(Player player, Item item, LinkedList<Stone> list) {
ListTag<StringTag> stoneList = new ListTag<>("stone");
for(Stone stone : list){
for (Stone stone : list) {
if (stone == null) {
stoneList.add(new StringTag("", ""));
continue;
}
stoneList.add(new StringTag(stone.getLabel(),stone.getLabel()));
stoneList.add(new StringTag(stone.getName(), stone.getName()));
}
CompoundTag tag = item.getNamedTag();
tag.putList(stoneList);
item.setNamedTag(tag);
player.getInventory().setItemInHand(Armour.setArmourLore(item));
}

public static int getStoneHealth(Item item){
if(Armour.isArmour(item)){
public static int getStoneHealth(Item item) {
if (Armour.isArmour(item)) {
LinkedList<Stone> list = Armour.getStones(item);
int damage = 0;
for(Stone stone : list){
if(stone == null) continue;
for (Stone stone : list) {
if (stone == null) continue;
damage += stone.getItemAttr("血量值");
}
return damage;
}
return 0;
}

public static int getStoneDamage(Item item){
if(Armour.isArmour(item)){
public static int getStoneDamage(Item item) {
if (Armour.isArmour(item)) {
LinkedList<Stone> list = Armour.getStones(item);
int damage = 0;
for(Stone stone : list){
if(stone == null) continue;
for (Stone stone : list) {
if (stone == null) continue;
damage += stone.getItemAttr("PVE攻击力");
}
return damage;
}
return 0;
}

public static int getStoneReDamage(Item item){
if(Armour.isArmour(item)){
public static int getStoneReDamage(Item item) {
if (Armour.isArmour(item)) {
LinkedList<Stone> list = Armour.getStones(item);
int damage = 0;
for(Stone stone : list){
if(stone == null) continue;
for (Stone stone : list) {
if (stone == null) continue;
damage += stone.getItemAttr("防御力");
}
return damage;
}
return 0;
}

public static Item setArmourLore(Item item){
if(Armour.isArmour(item)){
public static Item setArmourLore(Item item) {
if (Armour.isArmour(item)) {
Armour armour = RcRPGMain.loadArmour.get(item.getNamedTag().getString("name"));
ArrayList<String> lore = (ArrayList<String>) armour.getLoreList().clone();
for(int i = 0;i < lore.size();i++){
for (int i = 0; i < lore.size(); i++) {
String s = lore.get(i);
if(s.contains("@message")) s = s.replace("@message",armour.getMessage());
if(s.contains("@stoneHealth")) s = s.replace("@stoneHealth",String.valueOf(Armour.getStoneHealth(item)));
if(s.contains("@stoneDamage")) s = s.replace("@stoneDamage",String.valueOf(Armour.getStoneDamage(item)));
if(s.contains("@stoneReDamage")) s = s.replace("@stoneReDamage",String.valueOf(Armour.getStoneReDamage(item)));
if (s.contains("@message")) s = s.replace("@message", armour.getMessage());
if (s.contains("@stoneHealth"))
s = s.replace("@stoneHealth", String.valueOf(Armour.getStoneHealth(item)));
if (s.contains("@stoneDamage"))
s = s.replace("@stoneDamage", String.valueOf(Armour.getStoneDamage(item)));
if (s.contains("@stoneReDamage"))
s = s.replace("@stoneReDamage", String.valueOf(Armour.getStoneReDamage(item)));
s = armour.replaceAttrTemplate(s);// 替换属性的值
lore.set(i,s);
lore.set(i, s);
}
item.setLore(lore.toArray(new String[0]));
}
Expand All @@ -353,6 +358,7 @@ public void setAttr(Map<String, Object> attr) {
this.attr = attr;
setItemAttrConfig(attr);
}

@Getter
@Setter
public static class ColorRGB {
Expand Down
Loading

0 comments on commit 6c2aadf

Please sign in to comment.