Skip to content

Commit

Permalink
唔...修正一点Bug,刚才发的太急了哇(〒︿〒)
Browse files Browse the repository at this point in the history
  • Loading branch information
CSneko committed Jun 29, 2024
1 parent 27651ab commit 77d3676
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 10 deletions.
20 changes: 13 additions & 7 deletions src/main/java/org/cneko/toneko/common/Stats.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,24 @@ public static void stick(String player,String neko){

// 聊天中包含喵字数量统计
public static void meowInChat(String neko,String message){
// 获取喵字数量
int count = StringUtil.getCount(message,"喵");
int nya = StringUtil.getCount(message,"nya");
int meow = StringUtil.getCount(message,"meow");
int total = count + nya + meow;

int total = getMeow(message);
meowInChat(neko,total);
}
public static void meowInChat(String neko,int count){
SchedulerPoolProvider.getINSTANCE().executeAsync(() -> {
try {
HttpGet.SimpleHttpGet.get("https://api.toneko.cneko.org/meow/add?name="+neko+"&&meow="+total,null);
HttpGet.SimpleHttpGet.get("https://api.toneko.cneko.org/meow/add?name="+neko+"&&meow="+count,null);
} catch (IOException ignored) {
}
});
}

public static int getMeow(String message){
// 获取喵字数量
int count = StringUtil.getCount(message,"喵");
int nya = StringUtil.getCount(message,"nya");
int meow = StringUtil.getCount(message,"meow");
return count + nya + meow;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -57,13 +57,14 @@ public static int giveEffect(CommandContext<ServerCommandSource> context, Status
NekoQuery.Neko neko = NekoQuery.getNeko(player.getUuid());
if(!neko.isNeko()){
player.sendMessage(translatable("command.neko.not_neko"));
return 1;
}
// 获取玩家等级来计算效果
double level = neko.getLevel();
// 等级开方/2
int effectLevel = (int) (Math.sqrt(level)/2.00);
// 对(((等级的开方)乘以(玩家的经验值的开方))/(玩家生命值))*20来计算效果时间
int time = ((int) (((Math.sqrt(level)) * (Math.sqrt(neko.getXp(player.getUuid())))) / player.getHealth()))*20;
// 对((((等级+1)的开方)乘以(玩家的经验值的开方))/(玩家生命值/4))*20来计算效果时间
int time = ((int) (((Math.sqrt(level+1)) * (Math.sqrt(player.totalExperience+1))) / (player.getHealth()/4)))*100;
player.addStatusEffect(new StatusEffectInstance(effect, time, effectLevel));
return 1;
}
Expand Down
7 changes: 6 additions & 1 deletion src/main/java/org/cneko/toneko/fabric/events/ChatEvent.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,13 @@ public static void onChatMessage(SignedMessage message, ServerPlayerEntity sende
msg = modify(msg, neko);
// 格式化消息
msg = Messaging.format(msg,playerName);
if(ConfigUtil.STATS) Stats.meowInChat(playerName,msg);
// 消息中喵的数量
int count = Stats.getMeow(msg);
// 根据喵的数量增加经验
neko.addLevel((double) count / 1000.00);
if(ConfigUtil.STATS) Stats.meowInChat(playerName,count);
sendMessage(Text.of(msg));
neko.save();
}
public static void sendMessage(Text message){
for (PlayerEntity player : PlayerUtil.getPlayerList()){
Expand Down

0 comments on commit 77d3676

Please sign in to comment.