From c32e8d6ae175b4b7ac14f6404854103de166d230 Mon Sep 17 00:00:00 2001 From: Jai <814683@qq.com> Date: Sat, 2 Dec 2023 15:20:20 +0800 Subject: [PATCH] Fixed incorrect calculation of mana percentage (#6) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Fixed incorrect calculation of mana percentage * Check for some monsters that need to be skipped * Fixed incorrect values when not a pointer function Co-authored-by: Héctor Giménez --------- Co-authored-by: Héctor Giménez --- pkg/data/data.go | 51 ++++++++++++++++++++++++++++-------------------- pkg/data/npc.go | 12 +++++++++++- 2 files changed, 41 insertions(+), 22 deletions(-) diff --git a/pkg/data/data.go b/pkg/data/data.go index ddb1375..c7033b1 100644 --- a/pkg/data/data.go +++ b/pkg/data/data.go @@ -12,8 +12,30 @@ import ( // since stat.MaxLife is returning max life without stats, we are setting the max life value that we read from the // game memory, overwriting this value each time it increases. It's not a good solution but it will provide // more accurate values for the life %. This value is checked for each memory iteration. -var maxLife = 0 -var maxLifeBO = 0 +type PointCounter struct { + MaxPoint int + MaxPointBo int +} + +func (pc *PointCounter) Percent(point int, maxPoint int, hasBo bool) int { + if pc.MaxPoint == 0 && pc.MaxPointBo == 0 { + pc.MaxPoint = maxPoint + pc.MaxPointBo = maxPoint + } + if hasBo { + if pc.MaxPointBo < point { + pc.MaxPointBo = point + } + return int((float64(point) / float64(pc.MaxPointBo)) * 100) + } + if pc.MaxPoint < point { + pc.MaxPoint = point + } + return int((float64(point) / float64(pc.MaxPoint)) * 100) +} + +var maxHp PointCounter +var maxMp PointCounter const ( goldPerLevel = 10000 @@ -161,28 +183,15 @@ func (pu PlayerUnit) HPPercent() int { if !found { return 100 } - - if maxLifeBO == 0 && maxLife == 0 { - maxLife = pu.Stats[stat.MaxLife] - maxLifeBO = pu.Stats[stat.MaxLife] - } - - if pu.States.HasState(state.Battleorders) { - if maxLifeBO < pu.Stats[stat.Life] { - maxLifeBO = pu.Stats[stat.Life] - } - return int((float64(pu.Stats[stat.Life]) / float64(maxLifeBO)) * 100) - } - - if maxLife < pu.Stats[stat.Life] { - maxLife = pu.Stats[stat.Life] - } - - return int((float64(pu.Stats[stat.Life]) / float64(maxLife)) * 100) + return maxHp.Percent(pu.Stats[stat.Life], pu.Stats[stat.MaxLife], pu.States.HasState(state.Battleorders)) } func (pu PlayerUnit) MPPercent() int { - return int((float64(pu.Stats[stat.Mana]) / float64(pu.Stats[stat.MaxMana])) * 100) + _, found := pu.Stats[stat.MaxMana] + if !found { + return 100 + } + return maxMp.Percent(pu.Stats[stat.Mana], pu.Stats[stat.MaxMana], pu.States.HasState(state.Battleorders)) } func (pu PlayerUnit) HasDebuff() bool { diff --git a/pkg/data/npc.go b/pkg/data/npc.go index 998e2de..99cf975 100644 --- a/pkg/data/npc.go +++ b/pkg/data/npc.go @@ -50,7 +50,7 @@ func (m Monsters) FindOne(id npc.ID, t MonsterType) (Monster, bool) { func (m Monsters) Enemies(filters ...MonsterFilter) []Monster { monsters := make([]Monster, 0) for _, mo := range m { - if !mo.IsMerc() && mo.Name != npc.BaalTaunt && mo.Name != npc.Act5Combatant && mo.Name != npc.Act5Combatant2 && !mo.IsGoodNPC() && mo.Stats[stat.Life] > 0 { + if !mo.IsMerc() && mo.Name != npc.BaalTaunt && mo.Name != npc.Act5Combatant && mo.Name != npc.Act5Combatant2 && !mo.IsSkip() && !mo.IsGoodNPC() && mo.Stats[stat.Life] > 0 { monsters = append(monsters, mo) } } @@ -153,3 +153,13 @@ func (m Monster) IsMonsterRaiser() bool { return false } + +// Monster can`t be targeted normally +func (m Monster) IsSkip() bool { + switch m.Name { + case npc.WaterWatcherLimb, npc.WaterWatcherHead: + return true + } + + return false +}