Skip to content

Latest commit

 

History

History
55 lines (43 loc) · 1.56 KB

2023-09-06.md

File metadata and controls

55 lines (43 loc) · 1.56 KB

2023-09-06

I'm working to give back more generic point system to manage points like health point, mana point, etc.

I'm create new directory pkg/pts to store point system package.

This package is called "pts" and it provides a point system. It defines a type called Point with type int.

type Point int

I create lots of methods to manipulate the Point type, such as Add, Sub, Set, Get, String, Reset and IsZero.

In the pkg/hp package, I'm use the Point type to manage health point. I'm change the HP struct to use the Point type.

type HP struct {
-       Max     int
-       Current int
+       Max     *pts.Point
+       Current *pts.Point
}

And I'm remove AddMax, AddCurrent, SetMax, SetCurrent, GetCurrent and GetMax methods because I'm use the Point methods.

With the same logic as pkg/hp, I'm create pkg/mp package to manage mana point. I'm change the CharacterState and NPCStats structs to use the new mana point system.

 type CharacterStats struct {
        (...)
        // Secondary characteristics
        // Those characteristics depend on main chars, level and gear
        HP             *hp.HP
+       MP             *mp.MP
-       MaxMP          int
-       CurrentMP      int
        PhysicalDamage int
type NPCStats struct {
        Dialog      string
        Hostile     bool
        Avatar      Avatar
        HP          *hp.HP
+       MP          *mp.MP
-       MaxMP       int
-       CurrentMP   int
        LootXP      int