0

現在、SteamBot を自分用に編集およびセットアップしています。ここにソースコードがあります: https://github.com/Jessecar96/SteamBot
私はすでに独自の UserHandle を作成しましたが、settings_prices.json ファイルからアイテムの価格をロード (および保存) したい (今のところ、価格のみを記憶しています) .exe ファイルを再起動するまで)。

static int SellPricePerKey = 70; // cena klucza w scrapach np. 31 / 9 = 3.55 ref
static int BuyPricePerKey = 69; // cena klucza w scrapach np e.g. 29 / 9 = 3.33 ref
static int SellPricePerTod = 33; // cena ToD'a w scrapach np. 31 / 9 = 3.55 ref
static int BuyPricePerTod = 28; // cena ToD'a w scrapach np. 29 / 9 = 3.33 ref

販売キー(ゲーム内アイテム)などの価格変更コマンド(ボットとのスチームチャット経由)

else if (message.StartsWith("!sell key"))
{
// Usage: !sell newprice "e.g. sell 26"
    int NewSellPrice = 0;
    if (message.Length >= 10)
    {
        Bot.SteamFriends.SendChatMessage(OtherSID, type, "Aktualna cena sprzedazy kluczy to: " + 
            SellPricePerKeyInRefs + " ref (" 
                + SellPricePerKey + " scapow).");

        int.TryParse(message.Substring(9), out NewSellPrice);

        Bot.log.Success("Admin zmienil cene sprzedazy kluczy z " + 
            SellPricePerKeyInRefs + " ref, na " + 
            Math.Truncate(100 * (NewSellPrice / 9.0)) / 100 + 
            " ref (" + NewSellPrice + " scapow).");

        SellPricePerKey = NewSellPrice;
        double NewSellPricePerKeyInRefs = Math.Truncate(100 * (SellPricePerKey / 9.0)) / 100;
        SellPricePerKeyInRefs = NewSellPricePerKeyInRefs;
        Bot.SteamFriends.SendChatMessage(OtherSID, type, "Zmiana ceny sprzedazy kluczy na: " + 
            SellPricePerKeyInRefs + " ref (" + 
            SellPricePerKey + " scapow).");

        Bot.log.Success("Pomyslnie zmieniono cene sprzedazy kluczy.");
    }
    else
    {
        Bot.SteamFriends.SendChatMessage(OtherSID, type, 
            "Potrzebuje nowej ceny w komendzie. Aktualna cena sprzedazy to: " + 
            SellPricePerKeyInRefs + " refa (" + SellPricePerKey + " scapow).");
    }
}

しかし、次のような settings_prices.json ファイルからこれらの価格を保存してロードする必要があります。

{
"KeySell": "70"
"KeyBuy": "69"
"TodSell": "33"
"TodBuy": "28"
}
4

1 に答える 1

0

これは次のことを行う必要があります。

void Main()
{
    var my_object = new MyObject() {
          SellPricePerKey = 70, // cena klucza w scrapach np. 31 / 9 = 3.55 ref
          BuyPricePerKey = 69, // cena klucza w scrapach np e.g. 29 / 9 = 3.33 ref
          SellPricePerTod = 33,// cena ToD'a w scrapach np. 31 / 9 = 3.55 ref
          BuyPricePerTod = 28 // c
    };
    // create the JSON
    var json_my_object = Newtonsoft.Json.JsonConvert.SerializeObject(my_object);

    // Retrun an a JObject with 4 objects
    var normal_deserialized_object = Newtonsoft.Json.JsonConvert.DeserializeObject(json_my_object);

    // Or deserialize object and play with inner bits
    Newtonsoft.Json.Linq.JObject another_deserialized_object =
        (Newtonsoft.Json.Linq.JObject)Newtonsoft.Json.JsonConvert.DeserializeObject(json_my_object);

    foreach (var pair   in another_deserialized_object)
    {
        Console.WriteLine("Key:[{0}] , Value:[{1}]", pair.Key, pair.Value);
    }

}

// Define other methods and classes here

public class MyObject {
    public  int SellPricePerKey ;
    public  int BuyPricePerKey;
    public  int SellPricePerTod ;
    public  int BuyPricePerTod;
}

返されます:

{"SellPricePerKey":70,"BuyPricePerKey":69,"SellPricePerTod":33,"BuyPricePerTod":28}

保存するには、それをファイルにダンプしJSONます。ロードするには、ファイルから文字列に読み取り、その文字列をJSONデシリアライズに渡すと、オブジェクトが得られます。

于 2014-05-04T00:01:36.977 に答える