本文整理汇总了C#中db.Database.CreateChest方法的典型用法代码示例。如果您正苦于以下问题:C# Database.CreateChest方法的具体用法?C# Database.CreateChest怎么用?C# Database.CreateChest使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类db.Database
的用法示例。
在下文中一共展示了Database.CreateChest方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: HandleRequest
protected override void HandleRequest()
{
StreamWriter wtr = new StreamWriter(Context.Response.OutputStream);
if (Query.AllKeys.Length > 0)
{
using (Database db = new Database())
{
Package package = Package.GetPackage(int.Parse(Query["packageId"]));
if (package == null)
{
wtr.Write("<Error>This package is not available any more</Error>");
return;
}
JsonSerializer s = new JsonSerializer();
var contents = s.Deserialize<PackageContent>(new JsonTextReader(new StringReader(package.Contents)));
Account acc = db.Verify(Query["guid"], Query["password"], Program.GameData);
if (CheckAccount(acc, db, false))
{
if (acc.Credits < package.Price)
{
wtr.Write("<Error>Not enough gold.<Error/>");
return;
}
var cmd = db.CreateQuery();
if (contents.items?.Count > 0)
{
foreach (var i in contents.items)
{
Dictionary<string, int> itemDic = new Dictionary<string, int>();
List<int> gifts = acc.Gifts;
gifts.Add(i);
cmd = db.CreateQuery();
cmd.CommandText =
"UPDATE accounts SET [email protected] WHERE [email protected] AND password=SHA1(@password);";
cmd.Parameters.AddWithValue("@gifts", Utils.GetCommaSepString<int>(gifts.ToArray()));
cmd.Parameters.AddWithValue("@uuid", Query["guid"]);
cmd.Parameters.AddWithValue("@password", Query["password"]);
cmd.ExecuteNonQuery();
}
}
if (contents.charSlots > 0)
{
cmd = db.CreateQuery();
cmd.CommandText =
"UPDATE accounts SET maxCharSlot=maxCharSlot + @amount WHERE [email protected] AND password=SHA1(@password);";
cmd.Parameters.AddWithValue("@amount", contents.charSlots);
cmd.Parameters.AddWithValue("@uuid", Query["guid"]);
cmd.Parameters.AddWithValue("@password", Query["password"]);
if (cmd.ExecuteNonQuery() == 0)
return;
}
if (contents.vaultChests > 0)
{
for (int j = 0; j < contents.vaultChests; j++)
db.CreateChest(acc);
}
db.UpdateCredit(acc, -package.Price);
wtr.Write("<Success/>");
}
}
}
}
示例2: ParseContents
private bool ParseContents(Account acc, string json)
{
try
{
using (var db = new Database())
{
var code = GiftCode.FromJson(json);
if (code == null) return false;
var cmd = db.CreateQuery();
if (code.Gifts.Count > 0)
{
List<int> gifts = acc.Gifts;
foreach (var i in code.Gifts)
gifts.Add(i);
cmd = db.CreateQuery();
cmd.CommandText =
"UPDATE accounts SET [email protected] WHERE [email protected] AND password=SHA1(@password);";
cmd.Parameters.AddWithValue("@gifts", Utils.GetCommaSepString<int>(gifts.ToArray()));
cmd.Parameters.AddWithValue("@uuid", Query["guid"]);
cmd.Parameters.AddWithValue("@password", Query["password"]);
cmd.ExecuteNonQuery();
}
if (code.CharSlots > 0)
{
cmd = db.CreateQuery();
cmd.CommandText =
"UPDATE accounts SET maxCharSlot=maxCharSlot + @amount WHERE [email protected] AND password=SHA1(@password);";
cmd.Parameters.AddWithValue("@amount", code.CharSlots);
cmd.Parameters.AddWithValue("@uuid", Query["guid"]);
cmd.Parameters.AddWithValue("@password", Query["password"]);
cmd.ExecuteNonQuery();
}
if (code.VaultChests > 0)
for (int j = 0; j < code.VaultChests; j++)
db.CreateChest(acc);
if (code.Gold > 0)
db.UpdateCredit(acc, code.Gold);
if (code.Fame > 0)
db.UpdateFame(acc, code.Fame);
}
}
catch (Exception)
{
return false;
}
return true;
}