Skip to content

Commit

Permalink
added woodcutting bot
Browse files Browse the repository at this point in the history
  • Loading branch information
Kyle Jackson committed Aug 5, 2024
1 parent 23b758b commit 15a5f74
Show file tree
Hide file tree
Showing 4 changed files with 179 additions and 20 deletions.
35 changes: 34 additions & 1 deletion .github/workflows/build-images.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,37 @@ jobs:
platforms: linux/amd64
tags: |
ghcr.io/wizedkyle/artifactsmmo/miner:latest
ghcr.io/wizedkyle/artifactsmmo/miner:1.0.${{ github.run_id }}
ghcr.io/wizedkyle/artifactsmmo/miner:1.0.${{ github.run_id }}
build-woodcutting-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/woodcutting/Dockerfile
platforms: linux/amd64
tags: |
ghcr.io/wizedkyle/artifactsmmo/woodcutting:latest
ghcr.io/wizedkyle/artifactsmmo/woodcutting:1.0.${{ github.run_id }}
10 changes: 10 additions & 0 deletions build/woodcutting/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/miner

COPY . /go/src/miner

RUN go get ./...
RUN go build ./cmd/woodcutting

ENTRYPOINT ["./woodcutting"]
106 changes: 106 additions & 0 deletions cmd/woodcutting/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
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
)
woodResource, ok := os.LookupEnv("WOOD_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.WoodcuttingLevel < models.SpruceTreeLevel {
x = models.AshTeeX
y = models.AshTreeY
} else if c.Data.WoodcuttingLevel < models.BirchTreeLevel {
x = models.SpruceTreeX
y = models.SpruceTreeY
} else {
x = models.BirchTreeX
y = models.BirchTreeY
}
} else {
switch woodResource {
case models.AshTree:
x = models.AshTeeX
y = models.AshTreeY
case models.SpruceTree:
x = models.SpruceTreeX
y = models.SpruceTreeY
case models.BirchTree:
x = models.BirchTreeX
y = models.BirchTreeY
default:
x = models.AshTeeX
y = models.AshTreeY
}
}
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: 29 additions & 19 deletions internal/models/generic.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,35 @@ package models
import "time"

const (
Bank string = "bank"
BankX int = 4
BankY int = 1
CoalLevel int = 20
Coal string = "coal_rocks"
CoalX int = 1
CoalY int = 6
Copper string = "copper_ore"
CopperLevel int = 0
CopperX int = 2
CopperY int = 0
GoldLevel int = 30
Gold string = "gold_rocks"
GoldX int = 10
GoldY int = -4
IronLevel int = 10
Iron string = "iron_rocks"
IronX int = 1
IronY int = 7
AshTree string = "ash_tree"
AshTeeX int = 6
AshTreeY int = 1
Bank string = "bank"
BankX int = 4
BankY int = 1
BirchTree string = "birch_tree"
BirchTreeLevel int = 20
BirchTreeX int = 3
BirchTreeY int = 5
CoalLevel int = 20
Coal string = "coal_rocks"
CoalX int = 1
CoalY int = 6
Copper string = "copper_ore"
CopperX int = 2
CopperY int = 0
GoldLevel int = 30
Gold string = "gold_rocks"
GoldX int = 10
GoldY int = -4
IronLevel int = 10
Iron string = "iron_rocks"
IronX int = 1
IronY int = 7
SpruceTree string = "spruce_tree"
SpruceTreeLevel int = 10
SpruceTreeX int = 2
SpruceTreeY int = 6
)

type Cooldown struct {
Expand Down

0 comments on commit 15a5f74

Please sign in to comment.