stop using global variables

This commit is contained in:
Héctor Giménez
2024-03-21 21:54:18 +09:00
parent 8f9f49addc
commit fec7da3121
5 changed files with 35 additions and 22 deletions

View File

@@ -76,7 +76,14 @@ func (gd *GameReader) GetPlayerUnitPtr(roster data.Roster) (playerUnitPtr uintpt
return
}
func (gd *GameReader) GetPlayerUnit(playerUnit uintptr) data.PlayerUnit {
func (gd *GameReader) GetPlayerUnit(playerUnit uintptr, previousHP, previousMP *data.PointCounter) data.PlayerUnit {
if previousHP == nil {
previousHP = &data.PointCounter{}
}
if previousMP == nil {
previousMP = &data.PointCounter{}
}
unitID := gd.Process.ReadUInt(playerUnit+0x08, Uint32)
// Read X and Y Positions
@@ -148,7 +155,7 @@ func (gd *GameReader) GetPlayerUnit(playerUnit uintptr) data.PlayerUnit {
}
}
return data.PlayerUnit{
d := data.PlayerUnit{
Name: name,
ID: data.UnitID(unitID),
Area: area.Area(levelNo),
@@ -163,7 +170,15 @@ func (gd *GameReader) GetPlayerUnit(playerUnit uintptr) data.PlayerUnit {
LeftSkill: skill.ID(leftSkillId),
RightSkill: skill.ID(rightSkillId),
AvailableWaypoints: availableWPs,
MaxHPValue: previousHP,
MaxMPValue: previousMP,
}
// Recalculate max HP and MP
d.HPPercent()
d.MPPercent()
return d
}
func (gd *GameReader) getSkills(skillListPtr uintptr) map[skill.ID]skill.Points {