Skip to content

Commit

Permalink
Revert "Revert "游戏限制无法一次发送太多文字,战绩得分分开发送""
Browse files Browse the repository at this point in the history
This reverts commit 8267662.
  • Loading branch information
4379711 committed May 9, 2024
1 parent 8267662 commit 0538336
Show file tree
Hide file tree
Showing 4 changed files with 127 additions and 48 deletions.
18 changes: 18 additions & 0 deletions src/main/java/yalong/site/bo/SummonerScoreBO.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package yalong.site.bo;

import lombok.AllArgsConstructor;
import lombok.Data;

import java.util.List;

/**
* 战绩
*
* @author yaLong
*/
@AllArgsConstructor
@Data
public class SummonerScoreBO {
private SummonerInfoBO summonerInfo;
private List<ScoreBO> scoreBOList;
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import yalong.site.cache.GameDataCache;
import yalong.site.utils.KeyEventUtil;

import java.util.ArrayList;
import java.util.concurrent.TimeUnit;
import java.util.function.Consumer;

Expand All @@ -12,19 +13,24 @@
*/
public class SendMyTeamScoreConsumer implements HotKeyConsumer {

@Override
public Consumer<Integer> build() {
return i -> {
if (FrameCache.sendScore) {
for (String s : GameDataCache.myTeamScore) {
KeyEventUtil.sendMsg("我方" + s);
try {
TimeUnit.MILLISECONDS.sleep(500);
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
}
}
};
}
@Override
public Consumer<Integer> build() {
return i -> {
if (FrameCache.sendScore) {
ArrayList<String> myTeamScore = GameDataCache.myTeamScore;
for (int j = 0; j < myTeamScore.size(); j++) {
String s = myTeamScore.get(j);
if (j == 0) {
s = "我方" + s;
}
KeyEventUtil.sendMsg(s);
try {
TimeUnit.MILLISECONDS.sleep(500);
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
}
}
};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import yalong.site.cache.GameDataCache;
import yalong.site.utils.KeyEventUtil;

import java.util.ArrayList;
import java.util.concurrent.TimeUnit;
import java.util.function.Consumer;

Expand All @@ -14,8 +15,13 @@ public class SendOtherTeamScoreConsumer implements HotKeyConsumer {
@Override
public Consumer<Integer> build() {
return i -> {
for (String s : GameDataCache.otherTeamScore) {
KeyEventUtil.sendMsg("对方" + s);
ArrayList<String> otherTeamScore = GameDataCache.otherTeamScore;
for (int j = 0; j < otherTeamScore.size(); j++) {
String s = otherTeamScore.get(j);
if (j == 0) {
s = "对方" + s;
}
KeyEventUtil.sendMsg(s);
try {
TimeUnit.MILLISECONDS.sleep(500);
} catch (InterruptedException e) {
Expand Down
111 changes: 80 additions & 31 deletions src/main/java/yalong/site/services/lcu/CalculateScore.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
package yalong.site.services.lcu;

import lombok.extern.slf4j.Slf4j;
import yalong.site.bo.ScoreBO;
import yalong.site.bo.SummonerInfoBO;
import yalong.site.bo.SummonerScoreBO;
import yalong.site.cache.GameDataCache;

import java.io.IOException;
import java.util.ArrayList;
Expand All @@ -12,63 +15,109 @@
/**
* @author yalong
*/
@Slf4j
public class CalculateScore {
private final LinkLeagueClientApi api;

public CalculateScore(LinkLeagueClientApi api) {
this.api = api;
}

/**
* 查询战绩,格式化为要发送的消息
*/
public ArrayList<String> dealScore2Msg(List<String> puuidList) throws IOException {
ArrayList<String> result = new ArrayList<>();
TreeMap<Float, String> treeMap = new TreeMap<>();
int gameNum=3;
public ArrayList<SummonerScoreBO> getScoreByPuuidList(List<String> puuidList, int gameNum) throws IOException {
ArrayList<SummonerScoreBO> arrayList = new ArrayList<>();
//根据puuid查最近几次的战绩
for (String puuid : puuidList) {
//查看玩家名称
SummonerInfoBO summonerInfo = api.getInfoByPuuId(puuid);
StringBuilder stringBuilder = new StringBuilder();
stringBuilder.append("【");
stringBuilder.append(summonerInfo.getDisplayName());
stringBuilder.append("】, 最近");
stringBuilder.append(gameNum);
stringBuilder.append("场战绩为:");
//查询战绩
List<ScoreBO> scoreBOList = api.getScoreById(puuid, gameNum-1);
List<ScoreBO> scoreBOList = api.getScoreById(puuid, gameNum - 1);
SummonerScoreBO summonerScoreBO = new SummonerScoreBO(summonerInfo, scoreBOList);
arrayList.add(summonerScoreBO);
}
return arrayList;
}

/**
* 根据战绩计算出得分
*/
public TreeMap<Float, SummonerScoreBO> calcScore2treeMap(ArrayList<SummonerScoreBO> list) {
TreeMap<Float, SummonerScoreBO> treeMap = new TreeMap<>();
for (SummonerScoreBO summonerScoreBO : list) {
// 计算得分 最近三把(KDA+输赢)的平均值
// KDA->(击杀*1.2+助攻*0.8)/(死亡*1.2)
// 输赢->赢+1 输-1
List<ScoreBO> scoreBOList = summonerScoreBO.getScoreBOList();
float score = 0.0f;
for (ScoreBO scoreBO : scoreBOList) {
if (scoreBO.getWin()) {
score += 1;
score += 1f;
} else {
score -= 1;
score -= 1f;
}
Integer kills = scoreBO.getKills();
Integer deaths = scoreBO.getDeaths();
Integer assists = scoreBO.getAssists();
score += (kills * 1.2 + assists * 0.8) / Math.max(deaths * 1.2, 1);
stringBuilder.append(kills);
stringBuilder.append("-");
stringBuilder.append(deaths);
stringBuilder.append("-");
stringBuilder.append(assists);
stringBuilder.append(", ");
score += ((kills * 1.2f + assists * 0.8f) / Math.max(deaths * 1.2f, 1f));
}
score /= gameNum;
stringBuilder.append("评分: ");
stringBuilder.append(String.format("%.2f", score));
treeMap.put(score, stringBuilder.toString());
treeMap.put(score, summonerScoreBO);
}
Map.Entry<Float, String> firstEntry = treeMap.firstEntry();
Map.Entry<Float, String> lastEntry = treeMap.lastEntry();
result.add("傻鸟是:" + firstEntry.getValue());
result.add("大神是:" + lastEntry.getValue());
return treeMap;
}

public ArrayList<String> entry2String(Map.Entry<Float, SummonerScoreBO> entry, String type) {
SummonerScoreBO stupid = entry.getValue();
//整理成字符串
ArrayList<String> result = new ArrayList<>();
StringBuilder stringBuilder = new StringBuilder();
List<ScoreBO> stupidScoreBOList = stupid.getScoreBOList();
int gameNum = stupidScoreBOList.size();
stringBuilder.append(type);
stringBuilder.append("是:【");
stringBuilder.append(stupid.getSummonerInfo().getDisplayName());
stringBuilder.append("】,得分");
stringBuilder.append(String.format("%.2f", entry.getKey() / gameNum));
result.add(stringBuilder.toString());
stringBuilder = new StringBuilder();
stringBuilder.append("近");
stringBuilder.append(gameNum);
stringBuilder.append("场战绩为:");
for (ScoreBO scoreBO : stupidScoreBOList) {
stringBuilder.append(scoreBO.getKills());
stringBuilder.append("-");
stringBuilder.append(scoreBO.getDeaths());
stringBuilder.append("-");
stringBuilder.append(scoreBO.getAssists());
stringBuilder.append(" ");
}
result.add(stringBuilder.toString());
return result;
}

/**
* 查询战绩,格式化为要发送的消息
*/
public ArrayList<String> dealScore2Msg(List<String> puuidList) {
int gameNum = 3;
ArrayList<SummonerScoreBO> scoreByPuuidList = new ArrayList<>();
try {
scoreByPuuidList = getScoreByPuuidList(puuidList, gameNum);
} catch (Exception e) {
log.error("查询战绩错误", e);
}
TreeMap<Float, SummonerScoreBO> treeMap = calcScore2treeMap(scoreByPuuidList);
Map.Entry<Float, SummonerScoreBO> firstEntry = treeMap.firstEntry();
Map.Entry<Float, SummonerScoreBO> lastEntry = treeMap.lastEntry();
//排除自己
SummonerScoreBO stupid = firstEntry.getValue();
if (stupid.getSummonerInfo().getPuuid().equals(GameDataCache.me.getPuuid())) {
treeMap.remove(firstEntry.getKey());
firstEntry = treeMap.firstEntry();
}

ArrayList<String> stupidList = entry2String(firstEntry, "傻鸟");
ArrayList<String> smartList = entry2String(lastEntry, "大神");
smartList.addAll(stupidList);
return smartList;
}

}

0 comments on commit 0538336

Please sign in to comment.