Skip to content

Commit

Permalink
adding sync and fishing
Browse files Browse the repository at this point in the history
  • Loading branch information
Kyle Jackson committed Aug 8, 2024
1 parent 15a5f74 commit e774aab
Show file tree
Hide file tree
Showing 27 changed files with 1,139 additions and 49 deletions.
68 changes: 67 additions & 1 deletion .github/workflows/build-images.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,39 @@ on:
- main

jobs:
build-sync-image:
name: Build Sync Image
runs-on: ubuntu-latest
permissions:
packages: write
steps:
- name: Checkout repo
uses: actions/checkout@v4

- name: Setup QEMU
uses: docker/setup-qemu-action@v3

- name: Setup Docker Buildx
uses: docker/setup-buildx-action@v3

- name: Login to Azure Container Registry
uses: docker/login-action@v3
with:
registry: "ghcr.io"
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Build and push image
uses: docker/build-push-action@v5
with:
context: .
push: true
file: build/sync/Dockerfile
platforms: linux/amd64
tags: |
ghcr.io/wizedkyle/artifactsmmo/sync:latest
ghcr.io/wizedkyle/artifactsmmo/sync:1.0.${{ github.run_id }}
build-miner-image:
name: Build Miner Image
runs-on: ubuntu-latest
Expand Down Expand Up @@ -70,4 +103,37 @@ jobs:
platforms: linux/amd64
tags: |
ghcr.io/wizedkyle/artifactsmmo/woodcutting:latest
ghcr.io/wizedkyle/artifactsmmo/woodcutting:1.0.${{ github.run_id }}
ghcr.io/wizedkyle/artifactsmmo/woodcutting:1.0.${{ github.run_id }}
build-fishing-image:
name: Build Woodcutting Image
runs-on: ubuntu-latest
permissions:
packages: write
steps:
- name: Checkout repo
uses: actions/checkout@v4

- name: Setup QEMU
uses: docker/setup-qemu-action@v3

- name: Setup Docker Buildx
uses: docker/setup-buildx-action@v3

- name: Login to Azure Container Registry
uses: docker/login-action@v3
with:
registry: "ghcr.io"
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Build and push image
uses: docker/build-push-action@v5
with:
context: .
push: true
file: build/fishing/Dockerfile
platforms: linux/amd64
tags: |
ghcr.io/wizedkyle/artifactsmmo/fishing:latest
ghcr.io/wizedkyle/artifactsmmo/fishing:1.0.${{ github.run_id }}
10 changes: 10 additions & 0 deletions build/fishing/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
FROM golang:1.22.5-alpine3.20

WORKDIR /go/src/fishing

COPY . /go/src/fishing

RUN go get ./...
RUN go build ./cmd/fishing

ENTRYPOINT ["./fishing"]
10 changes: 10 additions & 0 deletions build/sync/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
FROM golang:1.22.5-alpine3.20

WORKDIR /go/src/sync

COPY . /go/src/sync

RUN go get ./...
RUN go build ./cmd/sync

ENTRYPOINT ["./sync"]
20 changes: 20 additions & 0 deletions cmd/api/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package main

import (
"github.com/wizedkyle/artifactsmmo/v2/internal/database"
"github.com/wizedkyle/artifactsmmo/v2/internal/routes"
"github.com/wizedkyle/artifactsmmo/v2/internal/utils"
"go.uber.org/zap"
)

func main() {
utils.LoggerInit()
database.Init()
router := routes.Init()
routes.GenerateItemRoutes(router)
routes.GenerateTaskRoutes(router)
err := router.Run(":9000")
if err != nil {
utils.Logger.Fatal("failed to start gin server", zap.Error(err))
}
}
112 changes: 112 additions & 0 deletions cmd/fishing/fishing.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
package main

import (
"errors"
"fmt"
"github.com/wizedkyle/artifactsmmo/v2/internal/artifacts"
"github.com/wizedkyle/artifactsmmo/v2/internal/controllers"
"github.com/wizedkyle/artifactsmmo/v2/internal/models"
"github.com/wizedkyle/artifactsmmo/v2/internal/utils"
"go.uber.org/zap"
"os"
"time"
)

func main() {
utils.LoggerInit()
artifacts.Init()
for {
var (
x int
y int
)
fishingResource, ok := os.LookupEnv("FISHING_RESOURCE")
if !ok {
c, err := artifacts.Client.GetCharacter(*artifacts.Client.CharacterName)
if err != nil {
utils.Logger.Error("failed to get character information", zap.Error(err))
continue
}
if c.Data.FishingLevel < models.ShrimpLevel {
x = models.GudgeonX
y = models.GudgeonY
} else if c.Data.MiningLevel < models.TroutLevel {
x = models.ShrimpX
y = models.ShrimpY
} else if c.Data.MiningLevel < models.BassLevel {
x = models.TroutX
y = models.TroutY
} else {
x = models.BassX
y = models.BassY
}
} else {
switch fishingResource {
case models.Gudgeon:
x = models.GudgeonX
y = models.GudgeonY
case models.Shrimp:
x = models.ShrimpX
y = models.ShrimpY
case models.Trout:
x = models.TroutX
y = models.TroutY
case models.Bass:
x = models.BassX
y = models.BassY
default:
x = models.GudgeonX
y = models.GudgeonY
}
}
c, err := artifacts.Client.GetCharacter(*artifacts.Client.CharacterName)
if err != nil {
utils.Logger.Error("failed to get character information", zap.Error(err))
continue
}
if c.Data.X != x || c.Data.Y != y {
fmt.Printf("moving character to x=%d y=%d\n", x, y)
resp, err := artifacts.Client.ActionMove(*artifacts.Client.CharacterName, models.ActionMove{
X: x,
Y: y,
})
if err != nil {
utils.Logger.Error("failed to move character", zap.Error(err))
continue
}
time.Sleep(utils.CalculateTimeDifference(resp.Data.Cooldown.StartedAt, resp.Data.Cooldown.Expiration))
}
resp, err := artifacts.Client.ActionGathering(*artifacts.Client.CharacterName)
if errors.Is(err, utils.ErrCharacterInventoryFull) {
bankX, bankY := artifacts.Client.FindBuilding(models.Bank)
resp, err := artifacts.Client.ActionMove(*artifacts.Client.CharacterName, models.ActionMove{
X: bankX,
Y: bankY,
})
if err != nil {
utils.Logger.Error("failed to move character", zap.Error(err))
continue
}
fmt.Printf("moving character to bank (x=%d y=%d)\n", bankX, bankY)
time.Sleep(utils.CalculateTimeDifference(resp.Data.Cooldown.StartedAt, resp.Data.Cooldown.Expiration))
c, err := artifacts.Client.GetCharacter(*artifacts.Client.CharacterName)
if err != nil {
utils.Logger.Error("failed to get character information", zap.Error(err))
continue
}
controllers.DepositAllInventory(c.Data.Inventory)
resp, err = artifacts.Client.ActionMove(*artifacts.Client.CharacterName, models.ActionMove{
X: x,
Y: y,
})
if err != nil {
utils.Logger.Error("failed to move character", zap.Error(err))
continue
}
time.Sleep(utils.CalculateTimeDifference(resp.Data.Cooldown.StartedAt, resp.Data.Cooldown.Expiration))
} else if err == nil {
fmt.Printf("%s collected %v\n", *artifacts.Client.CharacterName, resp.Data.Details.Items)
time.Sleep(utils.CalculateTimeDifference(resp.Data.Cooldown.StartedAt, resp.Data.Cooldown.Expiration))
}
}
}
48 changes: 48 additions & 0 deletions cmd/sync/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package main

import (
"github.com/wizedkyle/artifactsmmo/v2/internal/artifacts"
"github.com/wizedkyle/artifactsmmo/v2/internal/database"
"github.com/wizedkyle/artifactsmmo/v2/internal/models"
"github.com/wizedkyle/artifactsmmo/v2/internal/utils"
"go.uber.org/zap"
)

func main() {
utils.LoggerInit()
artifacts.Init()
database.Init()
ItemTypes := []string{
"consumable",
"body_armor",
"weapon",
"resource",
"leg_armor",
"helmet",
"boots",
"shield",
"amulet",
"ring",
}
for _, itemType := range ItemTypes {
err := database.Client.DeleteItems(itemType)
if err != nil {
utils.Logger.Error("Failed to delete item type", zap.String("type", itemType), zap.Error(err))
}
var items []interface{}
resp, err := artifacts.Client.GetItems(models.GetAllItemsQueryParameters{
Type: itemType,
Size: 100,
})
if err != nil {
utils.Logger.Error("failed to get items", zap.Error(err))
}
for _, item := range resp.Data {
items = append(items, item)
}
err = database.Client.CreateItems(items)
if err != nil {
utils.Logger.Error("failed to create items", zap.Error(err))
}
}
}
38 changes: 36 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,33 @@ require (
)

require (
github.com/bytedance/sonic v1.11.6 // indirect
github.com/bytedance/sonic/loader v0.1.1 // indirect
github.com/cloudwego/base64x v0.1.4 // indirect
github.com/cloudwego/iasm v0.2.0 // indirect
github.com/fsnotify/fsnotify v1.7.0 // indirect
github.com/gabriel-vasile/mimetype v1.4.3 // indirect
github.com/gin-contrib/cors v1.7.2 // indirect
github.com/gin-contrib/sse v0.1.0 // indirect
github.com/gin-gonic/gin v1.10.0 // indirect
github.com/go-playground/locales v0.14.1 // indirect
github.com/go-playground/universal-translator v0.18.1 // indirect
github.com/go-playground/validator/v10 v10.20.0 // indirect
github.com/goccy/go-json v0.10.2 // indirect
github.com/golang/snappy v0.0.4 // indirect
github.com/google/uuid v1.6.0 // indirect
github.com/hashicorp/hcl v1.0.0 // indirect
github.com/inconshreveable/mousetrap v1.1.0 // indirect
github.com/json-iterator/go v1.1.12 // indirect
github.com/klauspost/compress v1.17.2 // indirect
github.com/klauspost/cpuid/v2 v2.2.7 // indirect
github.com/leodido/go-urn v1.4.0 // indirect
github.com/magiconair/properties v1.8.7 // indirect
github.com/mattn/go-isatty v0.0.20 // indirect
github.com/mitchellh/mapstructure v1.5.0 // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/montanaflynn/stats v0.7.1 // indirect
github.com/pelletier/go-toml/v2 v2.2.2 // indirect
github.com/sagikazarmark/locafero v0.4.0 // indirect
github.com/sagikazarmark/slog-shim v0.1.0 // indirect
Expand All @@ -22,10 +44,22 @@ require (
github.com/spf13/cast v1.6.0 // indirect
github.com/spf13/pflag v1.0.5 // indirect
github.com/subosito/gotenv v1.6.0 // indirect
github.com/twitchyliquid64/golang-asm v0.15.1 // indirect
github.com/ugorji/go/codec v1.2.12 // indirect
github.com/xdg-go/pbkdf2 v1.0.0 // indirect
github.com/xdg-go/scram v1.1.2 // indirect
github.com/xdg-go/stringprep v1.0.4 // indirect
github.com/youmark/pkcs8 v0.0.0-20181117223130-1be2e3e5546d // indirect
go.mongodb.org/mongo-driver v1.16.0 // indirect
go.uber.org/multierr v1.10.0 // indirect
golang.org/x/arch v0.8.0 // indirect
golang.org/x/crypto v0.23.0 // indirect
golang.org/x/exp v0.0.0-20230905200255-921286631fa9 // indirect
golang.org/x/sys v0.18.0 // indirect
golang.org/x/text v0.14.0 // indirect
golang.org/x/net v0.25.0 // indirect
golang.org/x/sync v0.7.0 // indirect
golang.org/x/sys v0.20.0 // indirect
golang.org/x/text v0.15.0 // indirect
google.golang.org/protobuf v1.34.1 // indirect
gopkg.in/ini.v1 v1.67.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
Loading

0 comments on commit e774aab

Please sign in to comment.