Skip to content

Commit

Permalink
Enforce Socketed items
Browse files Browse the repository at this point in the history
This ensures that any non-gem item socketed into a piece
of equipment is subject to enforcement. This is necessary due
to abyssal jewel sockets.

An additional test has been added for fetching a character from
the api.
  • Loading branch information
Everlag committed Jan 19, 2020
1 parent cfcdfdd commit c5914d1
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 1 deletion.
16 changes: 15 additions & 1 deletion items/items.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,8 @@ type ItemResp struct {
//
// We care about restricting non-flasks
InventoryID string `json:"inventoryId"`

SocketedItems []ItemResp `json:"socketedItems,omitempty"`
}

// FullName returns the name derived from name and typeline of an item.
Expand Down Expand Up @@ -152,9 +154,21 @@ func (i *ItemResp) EnforceGucciHobo(now time.Time,
return PolicyFailure{}, false
}

// Check socketed items first; control flow is a bit easier
for _, s := range i.SocketedItems {
fail, failed := s.EnforceGucciHobo(now,
characterName, characterLevel, accountName)
if !failed {
continue
}
return fail, true
}

// Allow uniques or relics, which are fancy uniques
// Also allow gems since those are always okay.
if i.FrameType == FrameTypeUnique ||
i.FrameType == FrameTypeRelic {
i.FrameType == FrameTypeRelic ||
i.FrameType == FrameTypeGem {
return PolicyFailure{}, false
}

Expand Down
36 changes: 36 additions & 0 deletions items/items_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,42 @@ func TestEnforceGucciHobo(t *testing.T) {
)
require.NotEmpty(t, failures)
})

t.Run("socketed gem valid", func(t *testing.T) {
failures := run(99, ItemResp{
FrameType: FrameTypeUnique,
SocketedItems: []ItemResp{
ItemResp{
FrameType: FrameTypeGem,
},
},
})
require.Empty(t, failures)
})

t.Run("unique socketed jewel valid", func(t *testing.T) {
failures := run(99, ItemResp{
FrameType: FrameTypeUnique,
SocketedItems: []ItemResp{
ItemResp{
FrameType: FrameTypeUnique,
},
},
})
require.Empty(t, failures)
})

t.Run("non-unique socketed jewel invalid", func(t *testing.T) {
failures := run(99, ItemResp{
FrameType: FrameTypeUnique,
SocketedItems: []ItemResp{
ItemResp{
FrameType: FrameTypeRare,
},
},
})
require.NotEmpty(t, failures)
})
}

func TestPolicyFailureCSV(t *testing.T) {
Expand Down
18 changes: 18 additions & 0 deletions remote/fetch_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"testing"
"time"

"github.com/Everlag/slippery-policy/items"
"github.com/Everlag/slippery-policy/ladder"
"github.com/Everlag/slippery-policy/passives"
"github.com/stretchr/testify/require"
Expand Down Expand Up @@ -35,6 +36,23 @@ func TestFetchLadder(t *testing.T) {
require.NotEmpty(t, parsed.Entries)
}

func TestFetchCharacter(t *testing.T) {
logger, err := zap.NewProduction()
require.NoError(t, err)

characterName := "SleeperSpectreBoi"
accountName := "Everlag"
l := NewLimiter(time.Millisecond*1500, time.Second*2,
5, logger.With(zap.String("limiter", "snapshot")))
result, err := FetchCharacter(logger, l, accountName, characterName)
require.NoError(t, err)

parsed, err := items.ReadGetItemResp(bytes.NewReader(result))
require.NoError(t, err)

require.NotEmpty(t, parsed.Items)
}

func TestFetchPassives(t *testing.T) {
logger, err := zap.NewProduction()
require.NoError(t, err)
Expand Down

0 comments on commit c5914d1

Please sign in to comment.