Fixed incorrect calculation of mana percentage (#6)

* 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 <hector.fwbz@gmail.com>

---------

Co-authored-by: Héctor Giménez <hector.fwbz@gmail.com>
This commit is contained in:
Jai
2023-12-02 15:20:20 +08:00
committed by GitHub
parent 8ae0eb55c2
commit c32e8d6ae1
2 changed files with 41 additions and 22 deletions

View File

@@ -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 // 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 // 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. // more accurate values for the life %. This value is checked for each memory iteration.
var maxLife = 0 type PointCounter struct {
var maxLifeBO = 0 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 ( const (
goldPerLevel = 10000 goldPerLevel = 10000
@@ -161,28 +183,15 @@ func (pu PlayerUnit) HPPercent() int {
if !found { if !found {
return 100 return 100
} }
return maxHp.Percent(pu.Stats[stat.Life], pu.Stats[stat.MaxLife], pu.States.HasState(state.Battleorders))
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)
} }
func (pu PlayerUnit) MPPercent() int { 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 { func (pu PlayerUnit) HasDebuff() bool {

View File

@@ -50,7 +50,7 @@ func (m Monsters) FindOne(id npc.ID, t MonsterType) (Monster, bool) {
func (m Monsters) Enemies(filters ...MonsterFilter) []Monster { func (m Monsters) Enemies(filters ...MonsterFilter) []Monster {
monsters := make([]Monster, 0) monsters := make([]Monster, 0)
for _, mo := range m { 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) monsters = append(monsters, mo)
} }
} }
@@ -153,3 +153,13 @@ func (m Monster) IsMonsterRaiser() bool {
return false 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
}