-
Couldn't load subscription status.
- Fork 12
Badge trading #231
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Mogiiii
wants to merge
21
commits into
TwitchPlaysPokemon:badge-trading
Choose a base branch
from
Mogiiii:BadgeTrading
base: badge-trading
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Badge trading #231
Changes from 10 commits
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
1f56dd2
Add badge forms
Mogiiii 570514c
Add badge forms
Mogiiii c28319f
format code
Mogiiii 047a245
Expand !giftbadge args to allow specified form and source
Mogiiii 637b048
add BadgeSourceParser
Mogiiii c7e3d71
Convert badgeform to int
Mogiiii f706dbf
Add shiny field to badges
Mogiiii 3d867e1
fix issues found in code review
Mogiiii 4123a3e
Implement badge selling
Mogiiii be38334
Add test for null shiny field on badges
Mogiiii ff11dc9
Extend shiny test, fix bug
Mogiiii ce5c836
Add BadgeBuyOfferRepo
Mogiiii 63cfecd
simplify forms, general fixes, format
Mogiiii 15afff9
add indexes
Mogiiii 51c6d32
Extend BadgeBuyOfferRepo
Mogiiii 641bc4c
Rename BadgeBuyOfferRepo -> BadgeMarketRepo, fixes
Mogiiii a3f0c52
Rename BadgeBuyOfferRepo -> BadgeMarketRepo, fixes
Mogiiii 3d0038e
try to fill buy offers into the highest sell offer
Mogiiii 56cbc36
BadgeMarketRepo.ResolveBuyOffers returns sales
Mogiiii eb1ef3f
Merge branch 'master' of https://github.com/TwitchPlaysPokemon/tpp-co…
Mogiiii 7073e32
WIP expand commands to use metadata
Mogiiii File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 @@ | ||
| using System; | ||
| using System.Collections.Immutable; | ||
| using System.Linq; | ||
| using System.Threading.Tasks; | ||
| using TPP.Persistence.Models; | ||
|
|
||
| namespace TPP.ArgsParsing.TypeParsers | ||
| { | ||
| public class BadgeSourceParser : BaseArgumentParser<Badge.BadgeSource> | ||
| { | ||
| public override Task<ArgsParseResult<Badge.BadgeSource>> Parse(IImmutableList<string> args, Type[] genericTypes) | ||
| { | ||
| string source = args[0]; | ||
| ArgsParseResult<Badge.BadgeSource> result; | ||
| Badge.BadgeSource? parsedSource = null; | ||
| try | ||
| { | ||
| parsedSource = (Badge.BadgeSource)Enum.Parse(typeof(Badge.BadgeSource), source, ignoreCase: true); | ||
| } | ||
| catch (ArgumentException) | ||
| { | ||
| switch (args[1].ToLower()) | ||
| { | ||
| case "run": | ||
| case "caught": | ||
| parsedSource = Badge.BadgeSource.RunCaught; | ||
| break; | ||
| } | ||
| } | ||
| if (parsedSource != null) | ||
| result = ArgsParseResult<Badge.BadgeSource>.Success(parsedSource.Value, args.Skip(1).ToImmutableList()); | ||
| else | ||
| result = ArgsParseResult<Badge.BadgeSource>.Failure($"Did not find a source named '{args[0]}'"); | ||
| return Task.FromResult(result); | ||
| } | ||
| } | ||
| } |
This file contains hidden or 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,45 @@ | ||
| using System; | ||
| using System.Collections.Immutable; | ||
| using System.Linq; | ||
| using System.Threading.Tasks; | ||
| using TPP.Common; | ||
| using TPP.ArgsParsing.Types; | ||
|
|
||
| namespace TPP.ArgsParsing.TypeParsers | ||
| { | ||
| /// <summary> | ||
| /// A parser that determines if something is indicated to be shiny or not. | ||
| /// </summary> | ||
| public class ShinyParser : BaseArgumentParser<Shiny> | ||
| { | ||
| string[] shinyWords = | ||
| { | ||
| "shiny", | ||
| "shiny:true" | ||
| }; | ||
| string[] plainWords = | ||
| { | ||
| "plain", | ||
| "regular", | ||
| "shiny:false" | ||
| }; | ||
| public override Task<ArgsParseResult<Shiny>> Parse(IImmutableList<string> args, Type[] genericTypes) | ||
| { | ||
| string s = args[0]; | ||
| ArgsParseResult<Shiny> result; | ||
| if (shinyWords.Contains(s)) | ||
| { | ||
| result = ArgsParseResult<Shiny>.Success(new Shiny { Value = true }, args.Skip(1).ToImmutableList()); | ||
| } | ||
| else if (plainWords.Contains(s)) | ||
| { | ||
| result = ArgsParseResult<Shiny>.Success(new Shiny { Value = false }, args.Skip(1).ToImmutableList()); | ||
| } | ||
| else | ||
| { | ||
| result = ArgsParseResult<Shiny>.Failure("The argument couldn't be understood as shiny or not", ErrorRelevanceConfidence.Unlikely); | ||
| } | ||
| return Task.FromResult(result); | ||
| } | ||
| } | ||
| } | ||
This file contains hidden or 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 hidden or 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,19 @@ | ||
| using System; | ||
| using System.Collections.Generic; | ||
| using System.Linq; | ||
| using System.Text; | ||
| using System.Threading.Tasks; | ||
|
|
||
| namespace TPP.ArgsParsing.Types | ||
| { | ||
| public class ImplicitBoolean | ||
| { | ||
| public bool Value { get; internal init; } | ||
| public static implicit operator bool(ImplicitBoolean b) => b.Value; | ||
| public override string ToString() => Value.ToString(); | ||
| } | ||
|
|
||
| public class Shiny : ImplicitBoolean | ||
| { | ||
| } | ||
| } |
This file contains hidden or 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,63 @@ | ||
| using System; | ||
| using System.Collections.Generic; | ||
| using System.Collections.Immutable; | ||
| using System.Linq; | ||
| using TPP.Common; | ||
|
|
||
| namespace TPP.Common | ||
| { | ||
| public static class PkmnForms | ||
| { | ||
| /// <summary> | ||
| /// | ||
| /// </summary> | ||
| static readonly Dictionary<string, Dictionary<string, int>> Forms = new Dictionary<string, Dictionary<string, int>> | ||
| { | ||
| ["unown"] = new Dictionary<string, int> | ||
| { | ||
| ["a"] = 1, | ||
| ["b"] = 2, | ||
| }, | ||
| ["shellos"] = new Dictionary<string, int> | ||
| { | ||
| ["west sea"] = 1, | ||
| ["westsea"] = 1, | ||
| ["west"] = 1, | ||
| ["pink"] = 1, | ||
| ["east sea"] = 2, | ||
| ["eastsea"] = 2, | ||
| ["east"] = 2, | ||
| ["blue"] = 2, | ||
| }, | ||
| }; | ||
|
|
||
| public static string getFormName(PkmnSpecies pokemon, int formid) | ||
| { | ||
| string pkmnName = pokemon.Name.ToLower(); //TODO: use normalize_name from pkmnspecies | ||
| Dictionary<string, int>? forms; | ||
| if (!Forms.TryGetValue(pkmnName, out forms)) | ||
| throw new ArgumentException($"{pokemon.Name} does not have alternate forms."); | ||
| string formName = forms.FirstOrDefault(p => p.Value == formid).Key; | ||
| if (formName == null) | ||
| throw new ArgumentException($"{pokemon.Name} does not have a form with id {formid}."); | ||
| return formName; | ||
| } | ||
|
|
||
| public static int getFormId(PkmnSpecies pokemon, string formName) | ||
| { | ||
| string pkmnName = pokemon.Name.ToLower(); | ||
| Dictionary<string, int>? forms; | ||
| if (!Forms.TryGetValue(pkmnName, out forms)) | ||
| throw new ArgumentException($"{pokemon.Name} does not have alternate forms."); | ||
| int formid = forms.GetValueOrDefault(formName.ToLower()); | ||
Mogiiii marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| if (formid == 0) | ||
| throw new ArgumentException($"{pokemon.Name} does not have a form called {formName}."); | ||
| return formid; | ||
| } | ||
|
|
||
| public static bool pokemonHasForms(PkmnSpecies pokemon) | ||
| { | ||
| return Forms.ContainsKey(pokemon.Name.ToLower()); | ||
| } | ||
| } | ||
| } | ||
This file contains hidden or 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 hidden or 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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.