Skip to content

Commit fbff5f8

Browse files
committed
Reuse ModifySP struct and adjust SP if SP greater than new max SP
1 parent 49cabaf commit fbff5f8

File tree

4 files changed

+11
-15
lines changed

4 files changed

+11
-15
lines changed

pkg/engine/attribute/attribute.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ type Manager interface {
2929
Getter
3030

3131
ModifySP(data info.ModifySP) error
32-
ModifyMaxSP(data info.ModifyMaxSP) error
32+
ModifyMaxSP(data info.ModifySP) error
3333

3434
AddTarget(target key.TargetID, base info.Attributes) error
3535

pkg/engine/attribute/modify.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,8 +201,15 @@ func (s *Service) ModifySP(data info.ModifySP) error {
201201
return s.emitSPChange(data.Key, data.Source, old, s.sp)
202202
}
203203

204-
func (s *Service) ModifyMaxSP(data info.ModifyMaxSP) error {
204+
func (s *Service) ModifyMaxSP(data info.ModifySP) error {
205205
old := s.sp
206206
s.maxsp += data.Amount
207+
if s.sp > s.maxsp {
208+
s.ModifySP(info.ModifySP{
209+
Key: data.Key,
210+
Source: data.Source,
211+
Amount: s.maxsp - s.sp,
212+
})
213+
}
207214
return s.emitMaxSPChange(data.Key, data.Source, old, s.maxsp)
208215
}

pkg/engine/info/attribute.go

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -59,18 +59,7 @@ type ModifySP struct {
5959
// The source of this modification
6060
Source key.TargetID `json:"source"`
6161

62-
// The amount of SP to be added or removed
63-
Amount int `json:"amount"`
64-
}
65-
66-
type ModifyMaxSP struct {
67-
// A unique identifier for this modification
68-
Key key.Reason `json:"key"`
69-
70-
// The source of this modification
71-
Source key.TargetID `json:"source"`
72-
73-
// The amount of maximum SP available
62+
// The amount of SP or maximum SP to be added or removed
7463
Amount int `json:"amount"`
7564
}
7665

pkg/simulation/attribute.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ func (sim *Simulation) ModifySP(data info.ModifySP) error {
3535
return sim.Attr.ModifySP(data)
3636
}
3737

38-
func (sim *Simulation) ModifyMaxSP(data info.ModifyMaxSP) error {
38+
func (sim *Simulation) ModifyMaxSP(data info.ModifySP) error {
3939
return sim.Attr.ModifyMaxSP(data)
4040
}
4141

0 commit comments

Comments
 (0)