-
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
1 parent
0707fbb
commit 625b87f
Showing
8 changed files
with
201 additions
and
55 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
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
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
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,70 @@ | ||
package engine | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
|
||
"github.com/promiseofcake/artifactsmmo-engine/internal/actions" | ||
"github.com/promiseofcake/artifactsmmo-engine/internal/logging" | ||
"github.com/promiseofcake/artifactsmmo-engine/internal/models" | ||
) | ||
|
||
func ShouldFulfilOrder(ctx context.Context, r *actions.Runner, order models.SimpleItem) bool { | ||
// determine what's in the bank | ||
items, err := r.GetBankItems(ctx) | ||
if err != nil { | ||
return false | ||
} | ||
|
||
var bankItem models.SimpleItem | ||
for _, item := range items { | ||
if item.Code == order.Code { | ||
bankItem = item | ||
break | ||
} | ||
} | ||
|
||
logging.Get(ctx).Debug("") | ||
|
||
if bankItem.Quantity < order.Quantity { | ||
logging.Get(ctx).Debug("order quantity is greater than quantity on hand", "resource", order.Code, "required", order.Quantity, "on_hand", bankItem.Quantity) | ||
return true | ||
} else { | ||
return false | ||
} | ||
|
||
} | ||
|
||
func FulfilOrder(ctx context.Context, r *actions.Runner, character string, order models.SimpleItem) error { | ||
// determine all resources that drop the order | ||
resources, err := r.GetResourcesByDrop(ctx, order.Code) | ||
if err != nil { | ||
return fmt.Errorf("get resources by drop: %w", err) | ||
} | ||
|
||
// get character location | ||
c, err := r.GetMyCharacterInfo(ctx, character) | ||
if err != nil { | ||
return fmt.Errorf("get character info: %w", err) | ||
} | ||
|
||
if c.ShouldBank() { | ||
dErr := DepositAll(ctx, r, character) | ||
if dErr != nil { | ||
return fmt.Errorf("failed to deposit all: %w", dErr) | ||
} | ||
} | ||
|
||
// goto the nearest resource | ||
gErr := Gather(ctx, r, character, resources[0]) | ||
if gErr != nil { | ||
return fmt.Errorf("failed to gather resources: %w", gErr) | ||
} else { | ||
dErr := DepositAll(ctx, r, character) | ||
if dErr != nil { | ||
return fmt.Errorf("failed to deposit all: %w", dErr) | ||
} | ||
} | ||
|
||
return nil | ||
} |
Oops, something went wrong.