Skip to content

Commit

Permalink
opt code
Browse files Browse the repository at this point in the history
  • Loading branch information
buffge committed Feb 24, 2022
1 parent 03c84ac commit dee557e
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 15 deletions.
12 changes: 3 additions & 9 deletions app.go
Original file line number Diff line number Diff line change
Expand Up @@ -378,14 +378,12 @@ func calcUserGameScore(summonerID int64, gameSummary lcu.GameSummary) (*lcu.Scor
userKillRateLoop:
for _, killRateConfItem := range calcScoreConf.KillRate {
if userKillRate > killRateConfItem.Limit {
killRateConfItemLoop:
for _, limitConf := range killRateConfItem.ScoreConf {
if userParticipant.Stats.Kills > int(limitConf[0]) {
gameScore.Add(limitConf[1], lcu.ScoreOptionKillRate)
break killRateConfItemLoop
break userKillRateLoop
}
}
break userKillRateLoop
}
}
}
Expand All @@ -396,14 +394,12 @@ func calcUserGameScore(summonerID int64, gameSummary lcu.GameSummary) (*lcu.Scor
userHurtRateLoop:
for _, killRateConfItem := range calcScoreConf.HurtRate {
if userHurtRate > killRateConfItem.Limit {
hurtRateConfItemLoop:
for _, limitConf := range killRateConfItem.ScoreConf {
if userParticipant.Stats.Kills > int(limitConf[0]) {
gameScore.Add(limitConf[1], lcu.ScoreOptionHurtRate)
break hurtRateConfItemLoop
break userHurtRateLoop
}
}
break userHurtRateLoop
}
}
}
Expand All @@ -414,14 +410,12 @@ func calcUserGameScore(summonerID int64, gameSummary lcu.GameSummary) (*lcu.Scor
userAssistRateLoop:
for _, killRateConfItem := range calcScoreConf.AssistRate {
if userAssistRate > killRateConfItem.Limit {
assistRateConfItemLoop:
for _, limitConf := range killRateConfItem.ScoreConf {
if userParticipant.Stats.Kills > int(limitConf[0]) {
gameScore.Add(limitConf[1], lcu.ScoreOptionAssistRate)
break assistRateConfItemLoop
break userAssistRateLoop
}
}
break userAssistRateLoop
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion bootstrap/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,11 +126,11 @@ func initGlobal() {
func initAutoReloadCalcConf() {
ticker := time.NewTicker(time.Minute)
for {
<-ticker.C
latestScoreConf, err := buffApi.GetCurrConf()
if err == nil && latestScoreConf != nil && latestScoreConf.Enabled {
global.SetScoreConf(*latestScoreConf)
}
<-ticker.C
}
}

Expand Down
1 change: 1 addition & 0 deletions conf/appConf.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,5 +63,6 @@ type (
AssistRate []RateItemConf `json:"assistRate" required:"true"` // 助攻占比
AdjustKDA [2]float64 `json:"adjustKDA" required:"true"` // kda
Horse [6]HorseScoreConf `json:"horse" required:"true"`
MergeMsg bool `json:"mergeMsg"` // 是否合并消息为一条
}
)
1 change: 1 addition & 0 deletions global/global.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ var (
{Score: 95, Name: "下等马"},
{Score: 0.0001, Name: "牛马"},
},
MergeMsg: false,
},
}
userInfo = UserInfo{}
Expand Down
26 changes: 22 additions & 4 deletions prophet.go
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ func (p *Prophet) initGameFlowMonitor(port int, authPwd string) error {
}
p.lcuActive = true
// if global.IsDevMode() {
// lcu.ChampionSelectStart()
// p.ChampionSelectStart()
// }

_ = c.WriteMessage(websocket.TextMessage, []byte("[5, \"OnJsonApiEvent\"]"))
Expand Down Expand Up @@ -390,9 +390,12 @@ func (p Prophet) ChampionSelectStart() {

scoreCfg := global.GetScoreConf()
allMsg := ""
mergedMsg := ""
// 发送到选人界面
for _, scoreInfo := range summonerIDMapScore {
time.Sleep(time.Second / 2)
if !scoreCfg.MergeMsg {
time.Sleep(time.Second / 2)
}
var horse string
horseIdx := 0
for i, v := range scoreCfg.Horse {
Expand All @@ -414,12 +417,16 @@ func (p Prophet) ChampionSelectStart() {
msg := fmt.Sprintf("%s(%d): %s %s -- %s", horse, int(scoreInfo.Score), scoreInfo.SummonerName,
currKDAMsg, global.AdaptChatWebsiteTitle)
<-sendConversationMsgDelayCtx.Done()
if clientCfg.AutoSendTeamHorse {
mergedMsg += msg + "\n"
}
if !clientCfg.AutoSendTeamHorse {
if !clientCfg.ShouldSendSelfHorse && p.currSummoner != nil &&
if !scoreCfg.MergeMsg && !clientCfg.ShouldSendSelfHorse && p.currSummoner != nil &&
scoreInfo.SummonerID == p.currSummoner.SummonerId {
continue
}
allMsg += msg + "\n"
mergedMsg += msg + "\n"
continue
}
if !clientCfg.ShouldSendSelfHorse && p.currSummoner != nil &&
Expand All @@ -429,11 +436,18 @@ func (p Prophet) ChampionSelectStart() {
if !clientCfg.ChooseSendHorseMsg[horseIdx] {
continue
}
if scoreCfg.MergeMsg {
continue
}
_ = SendConversationMsg(msg, conversationID)
}
if !clientCfg.AutoSendTeamHorse {
log.Println("已将队伍马匹信息复制到剪切板")
_ = clipboard.WriteAll(allMsg)
return
}
if scoreCfg.MergeMsg {
_ = SendConversationMsg(mergedMsg, conversationID)
}
}
func (p Prophet) AcceptGame() {
Expand All @@ -455,8 +469,12 @@ func (p Prophet) CalcEnemyTeamScore() {
selfTeamUsers, enemyTeamUsers := getAllUsersFromSession(selfID, session)
_ = selfTeamUsers
summonerIDList := enemyTeamUsers
// if !false && global.IsDevMode() {
// summonerIDList = []int64{2964390005, 4103784618, 4132401993, 4118593599, 4019221688}
// // summonerIDList = []int64{4006944917}
// }
logger.Debug("敌方队伍人员列表:", zap.Any("summonerIDList", summonerIDList))
if len(enemyTeamUsers) == 0 {
if len(summonerIDList) == 0 {
return
}
// 查询所有用户的信息并计算得分
Expand Down
2 changes: 1 addition & 1 deletion version.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package hh_lol_prophet
import "github.com/real-web-world/hh-lol-prophet/global"

var (
APPVersion = "0.1.1"
APPVersion = "0.2.0"
Commit = "dev"
BuildTime = ""
BuildUser = ""
Expand Down

0 comments on commit dee557e

Please sign in to comment.