-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Kyle Jackson
committed
Aug 5, 2024
1 parent
23b758b
commit 15a5f74
Showing
4 changed files
with
179 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters