-
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.
* feat: remove duplicate schema * feat: split up actions * feat: more refactor * feat: consistent logging / error returns for engine * feat: remove shadows
- Loading branch information
1 parent
e9846db
commit 9ddb398
Showing
24 changed files
with
485 additions
and
435 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package actions | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"net/http" | ||
|
||
"github.com/promiseofcake/artifactsmmo-go-client/client" | ||
|
||
"github.com/promiseofcake/artifactsmmo-engine/internal/models" | ||
) | ||
|
||
// Craft crafts the given item, with the given quantity and assumes the character is in the correct | ||
// map position | ||
func (r *Runner) Craft(ctx context.Context, character string, code string, quantity int) (*SkillResponse, error) { | ||
req := client.ActionCraftingMyNameActionCraftingPostJSONRequestBody{ | ||
Code: code, | ||
Quantity: &quantity, | ||
} | ||
|
||
resp, err := r.Client.ActionCraftingMyNameActionCraftingPostWithResponse(ctx, character, req) | ||
if err != nil { | ||
return nil, fmt.Errorf("failed to craft %s (%d): %w", code, quantity, err) | ||
} | ||
|
||
if resp.StatusCode() != http.StatusOK { | ||
return nil, fmt.Errorf("failed to craft: %s (%d)", resp.Body, resp.StatusCode()) | ||
} | ||
|
||
return &SkillResponse{ | ||
SkillInfo: resp.JSON200.Data.Details, | ||
Response: Response{ | ||
CharacterResponse: models.Character{CharacterSchema: resp.JSON200.Data.Character}, | ||
CooldownSchema: resp.JSON200.Data.Cooldown, | ||
}, | ||
}, nil | ||
} |
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,33 @@ | ||
package actions | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
|
||
"github.com/promiseofcake/artifactsmmo-go-client/client" | ||
|
||
"github.com/promiseofcake/artifactsmmo-engine/internal/models" | ||
) | ||
|
||
// Deposit deposits an item and quantity into the bank | ||
func (r *Runner) Deposit(ctx context.Context, character string, code string, qty int) (*BankResponse, error) { | ||
resp, err := r.Client.ActionDepositBankMyNameActionBankDepositPostWithResponse( | ||
ctx, | ||
character, | ||
client.ActionDepositBankMyNameActionBankDepositPostJSONRequestBody{ | ||
Code: code, | ||
Quantity: qty, | ||
}, | ||
) | ||
if err != nil { | ||
return nil, fmt.Errorf("failed to deposit: %w", err) | ||
} | ||
return &BankResponse{ | ||
Item: resp.JSON200.Data.Item, | ||
BankItems: resp.JSON200.Data.Bank, | ||
Response: Response{ | ||
CharacterResponse: models.Character{CharacterSchema: resp.JSON200.Data.Character}, | ||
CooldownSchema: resp.JSON200.Data.Cooldown, | ||
}, | ||
}, nil | ||
} |
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,30 @@ | ||
package actions | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"net/http" | ||
|
||
"github.com/promiseofcake/artifactsmmo-engine/internal/models" | ||
) | ||
|
||
// Fight attacks the mob at the current position for the given character | ||
func (r *Runner) Fight(ctx context.Context, character string) (*FightResponse, error) { | ||
resp, err := r.Client.ActionFightMyNameActionFightPostWithResponse(ctx, character) | ||
if err != nil { | ||
return nil, fmt.Errorf("failed to fight: %w", err) | ||
} | ||
|
||
if resp.StatusCode() != http.StatusOK { | ||
return nil, fmt.Errorf("failed to fight: %s (%d)", resp.Body, resp.StatusCode()) | ||
} | ||
|
||
return &FightResponse{ | ||
FightResponse: resp.JSON200.Data.Fight, | ||
Response: Response{ | ||
CharacterResponse: models.Character{CharacterSchema: resp.JSON200.Data.Character}, | ||
CooldownSchema: resp.JSON200.Data.Cooldown, | ||
}, | ||
}, nil | ||
|
||
} |
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,29 @@ | ||
package actions | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"net/http" | ||
|
||
"github.com/promiseofcake/artifactsmmo-engine/internal/models" | ||
) | ||
|
||
// Gather performs resource gathering at the current position for the given character | ||
func (r *Runner) Gather(ctx context.Context, character string) (*SkillResponse, error) { | ||
resp, err := r.Client.ActionGatheringMyNameActionGatheringPostWithResponse(ctx, character) | ||
if err != nil { | ||
return nil, fmt.Errorf("failed to gather: %w", err) | ||
} | ||
|
||
if resp.StatusCode() != http.StatusOK { | ||
return nil, fmt.Errorf("failed to gather: %s (%d)", resp.Body, resp.StatusCode()) | ||
} | ||
|
||
return &SkillResponse{ | ||
SkillInfo: resp.JSON200.Data.Details, | ||
Response: Response{ | ||
CharacterResponse: models.Character{CharacterSchema: resp.JSON200.Data.Character}, | ||
CooldownSchema: resp.JSON200.Data.Cooldown, | ||
}, | ||
}, nil | ||
} |
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,31 @@ | ||
package actions | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"net/http" | ||
|
||
"github.com/promiseofcake/artifactsmmo-go-client/client" | ||
|
||
"github.com/promiseofcake/artifactsmmo-engine/internal/models" | ||
) | ||
|
||
// Move changes the x, y position the given character | ||
func (r *Runner) Move(ctx context.Context, character string, x, y int) (*Response, error) { | ||
resp, err := r.Client.ActionMoveMyNameActionMovePostWithResponse(ctx, character, client.ActionMoveMyNameActionMovePostJSONRequestBody{ | ||
X: x, | ||
Y: y, | ||
}) | ||
if err != nil { | ||
return nil, fmt.Errorf("failed to move: %w", err) | ||
} | ||
|
||
if resp.StatusCode() != http.StatusOK { | ||
return nil, fmt.Errorf("failed to move: %s (%d)", resp.Body, resp.StatusCode()) | ||
} | ||
|
||
return &Response{ | ||
CharacterResponse: models.Character{CharacterSchema: resp.JSON200.Data.Character}, | ||
CooldownSchema: resp.JSON200.Data.Cooldown, | ||
}, nil | ||
} |
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,42 @@ | ||
package actions | ||
|
||
import ( | ||
"time" | ||
|
||
"github.com/promiseofcake/artifactsmmo-go-client/client" | ||
|
||
"github.com/promiseofcake/artifactsmmo-engine/internal/models" | ||
) | ||
|
||
// Response is a generic return value for most actions | ||
// it includes the most common return values for Character State | ||
// and request cooldown | ||
type Response struct { | ||
CharacterResponse models.Character | ||
CooldownSchema client.CooldownSchema | ||
} | ||
|
||
// GetCooldownDuration returns the duration for the Response cooldown | ||
func (g *Response) GetCooldownDuration() time.Duration { | ||
return time.Until(g.CooldownSchema.Expiration) | ||
} | ||
|
||
// FightResponse wraps a generic Response with Fight related data | ||
type FightResponse struct { | ||
Response | ||
FightResponse client.FightSchema | ||
} | ||
|
||
// SkillResponse wraps a generic Response with Skill related data | ||
// Used for craft, gather | ||
type SkillResponse struct { | ||
Response | ||
SkillInfo client.SkillInfoSchema | ||
} | ||
|
||
// BankResponse wraps a generic Response with Banking related data | ||
type BankResponse struct { | ||
Response | ||
BankItems []client.SimpleItemSchema | ||
Item client.ItemSchema | ||
} |
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
Oops, something went wrong.