-
Notifications
You must be signed in to change notification settings - Fork 2
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
Showing
7 changed files
with
280 additions
and
8 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text.Json.Serialization; | ||
using System.Threading.Tasks; | ||
using CS2Interface.Localization; | ||
using SteamKit2; | ||
|
||
namespace CS2Interface { | ||
public class Recipe : GameObject { | ||
[JsonInclude] | ||
[JsonPropertyName("id")] | ||
public ushort RecipeID { get; private init; } | ||
|
||
[JsonInclude] | ||
[JsonPropertyName("name")] | ||
public string? Name { get; private set; } | ||
|
||
[JsonInclude] | ||
[JsonPropertyName("inputs")] | ||
public string? InputDescription { get; private set; } | ||
|
||
[JsonInclude] | ||
[JsonPropertyName("outputs")] | ||
public string? OutputDescription { get; private set; } | ||
|
||
[JsonInclude] | ||
[JsonPropertyName("quality")] | ||
public string? Quality { get; private set; } | ||
|
||
[JsonInclude] | ||
[JsonPropertyName("defs")] | ||
[JsonConverter(typeof(KVConverter))] | ||
public KeyValue? RecipeData { get; private set; } | ||
|
||
public bool ShouldSerializeRecipeID() => true; | ||
public bool ShouldSerializeName() => Name != null && ShouldSerializeAdditionalProperties; | ||
public bool ShouldSerializeInputDescription() => InputDescription != null && ShouldSerializeAdditionalProperties; | ||
public bool ShouldSerializeOutputDescription() => OutputDescription != null && ShouldSerializeAdditionalProperties; | ||
public bool ShouldSerializeQuality() => Quality != null && ShouldSerializeAdditionalProperties; | ||
public bool ShouldSerializeRecipeData() => RecipeData != null && ShouldSerializeDefs; | ||
|
||
public Recipe(ushort recipeID) { | ||
RecipeID = recipeID; | ||
|
||
SetDefs(); | ||
SetAdditionalProperties(); | ||
} | ||
|
||
protected override bool SetDefs() { | ||
KeyValue? recipeDef = GameData.ItemsGame.GetDef("recipes", RecipeID.ToString()); | ||
if (recipeDef == null) { | ||
return false; | ||
} | ||
|
||
RecipeData = recipeDef.Clone(); | ||
|
||
return true; | ||
} | ||
|
||
protected override bool SetAdditionalProperties() { | ||
if (RecipeData == null) { | ||
return false; | ||
} | ||
|
||
Name = GameData.CsgoEnglish.Format(RecipeData["name"].Value?.Substring(1), GameData.CsgoEnglish[RecipeData["n_A"].Value?.Substring(1)]); | ||
InputDescription = GameData.CsgoEnglish.Format(RecipeData["desc_inputs"].Value?.Substring(1), RecipeData["di_A"].Value, GameData.CsgoEnglish[RecipeData["di_B"].Value?.Substring(1)]); | ||
OutputDescription = GameData.CsgoEnglish.Format(RecipeData["desc_outputs"].Value?.Substring(1), RecipeData["do_A"].Value, GameData.CsgoEnglish[RecipeData["do_B"].Value?.Substring(1)]); | ||
|
||
{ | ||
List<KeyValue>? inputConditions = RecipeData["input_items"].Children.FirstOrDefault()?["conditions"].Children; | ||
if (inputConditions != null) { | ||
foreach (KeyValue condition in inputConditions) { | ||
if (condition["field"].Value == "*quality") { | ||
Quality = GameData.CsgoEnglish[condition["value"].Value]; | ||
break; | ||
} | ||
} | ||
} | ||
} | ||
|
||
return true; | ||
} | ||
|
||
public static async Task<List<Recipe>> GetAll() { | ||
if (!await GameData.IsLoaded(update: false).ConfigureAwait(false)) { | ||
throw new ClientException(EClientExceptionType.Failed, Strings.GameDataLoadingFailed); | ||
} | ||
|
||
List<KeyValue>? kvs = GameData.ItemsGame["recipes"]; | ||
if (kvs == null) { | ||
return []; | ||
} | ||
|
||
List<Recipe> recipes = []; | ||
foreach (KeyValue kv in kvs) { | ||
if (ushort.TryParse(kv.Name, out ushort recipeID)) { | ||
recipes.Add(new Recipe(recipeID)); | ||
} | ||
} | ||
|
||
return recipes; | ||
} | ||
} | ||
} |
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,110 @@ | ||
# GET /Api/CS2Interface/Recipes | ||
|
||
## Description | ||
|
||
Get a list of crafting recipes currently in the game | ||
|
||
## Path Parameters | ||
|
||
None | ||
|
||
## Query Parameters | ||
|
||
Name | Required | Description | ||
--- | --- | --- | ||
`showDefs` | No | If set to true, the response will include a `defs` property containing additional game data | ||
|
||
## Response Result | ||
|
||
Property | Type | Description | ||
--- | --- | --- | ||
`id` | `ushort` | The recipe ID | ||
`name` | `string` | The name of the crafting recipe | ||
`inputs` | `string` | A description of the inputs | ||
`outputs` | `string` | A description of the outputs | ||
`quality` | `string` | The quality of the inputs and outputs (Unique or StatTrak™) | ||
|
||
## Example Response | ||
|
||
``` | ||
http://127.0.0.1:1242/Api/CS2Interface/Recipes | ||
``` | ||
|
||
```json | ||
{ | ||
"Message": "OK", | ||
"Success": true, | ||
"Result": [ | ||
{ | ||
"id": 0, | ||
"name": "Trade Up Consumer-Grade Weapons", | ||
"inputs": "Requires: 10 Consumer-Grade Weapons", | ||
"outputs": "Produces: 1 Industrial-Grade Weapon", | ||
"quality": "Unique" | ||
}, | ||
{ | ||
"id": 1, | ||
"name": "Trade Up Industrial-Grade Weapons", | ||
"inputs": "Requires: 10 Industrial-Grade Weapons", | ||
"outputs": "Produces: 1 Mil-Spec Weapon", | ||
"quality": "Unique" | ||
}, | ||
{ | ||
"id": 2, | ||
"name": "Trade Up Mil-Spec Weapons", | ||
"inputs": "Requires: 10 Mil-Spec Weapons", | ||
"outputs": "Produces: 1 Restricted Weapon", | ||
"quality": "Unique" | ||
}, | ||
{ | ||
"id": 3, | ||
"name": "Trade Up Restricted Weapons", | ||
"inputs": "Requires: 10 Restricted Weapons", | ||
"outputs": "Produces: 1 Classified Weapon", | ||
"quality": "Unique" | ||
}, | ||
{ | ||
"id": 4, | ||
"name": "Trade Up Classified Weapons", | ||
"inputs": "Requires: 10 Classified Weapons", | ||
"outputs": "Produces: 1 Covert Weapon", | ||
"quality": "Unique" | ||
}, | ||
{ | ||
"id": 10, | ||
"name": "Trade Up Consumer-Grade Weapons", | ||
"inputs": "Requires: 10 Consumer-Grade Weapons", | ||
"outputs": "Produces: 1 Industrial-Grade Weapon", | ||
"quality": "StatTrak™" | ||
}, | ||
{ | ||
"id": 11, | ||
"name": "Trade Up Industrial-Grade Weapons", | ||
"inputs": "Requires: 10 Industrial-Grade Weapons", | ||
"outputs": "Produces: 1 Mil-Spec Weapon", | ||
"quality": "StatTrak™" | ||
}, | ||
{ | ||
"id": 12, | ||
"name": "Trade Up Mil-Spec Weapons", | ||
"inputs": "Requires: 10 Mil-Spec Weapons", | ||
"outputs": "Produces: 1 Restricted Weapon", | ||
"quality": "StatTrak™" | ||
}, | ||
{ | ||
"id": 13, | ||
"name": "Trade Up Restricted Weapons", | ||
"inputs": "Requires: 10 Restricted Weapons", | ||
"outputs": "Produces: 1 Classified Weapon", | ||
"quality": "StatTrak™" | ||
}, | ||
{ | ||
"id": 14, | ||
"name": "Trade Up Classified Weapons", | ||
"inputs": "Requires: 10 Classified Weapons", | ||
"outputs": "Produces: 1 Covert Weapon", | ||
"quality": "StatTrak™" | ||
} | ||
] | ||
} | ||
``` |
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