ItmeSClass GetBag(string username) { //return rxjh.GetBag(username); var xwwl_char = gamecontext.TBL_XWWL_Char.Where(a => a.FLD_NAME == username).SingleOrDefault(); if (xwwl_char == null) { throw new ArgumentException("提示:错误没有这个人物!数据库可能有问题"); } int num = 36; ItmeSClass class2 = new ItmeSClass(); byte[] src = xwwl_char.FLD_ITEM; for (int i = 0; i < num; i++) { if (src.Length >= ((i * 37) + 37)) { byte[] dst = new byte[37]; try { Buffer.BlockCopy(src, i * 37, dst, 0, 37); 物品类 物品类 = new 物品类(dst); ItmeClass item = new ItmeClass { ID = i, FLD_ID = BitConverter.ToInt64(物品类.物品全局ID, 0), FLD_ItmeID = BitConverter.ToInt32(物品类.物品ID, 0), FLD_NAME = 物品类.物品名称, FLD_Type = 物品类.物品类型, FLD_Suliang = BitConverter.ToInt32(物品类.物品数量, 0), FLD_MAGIC0 = 物品类.FLD_MAGIC0, FLD_MAGIC1 = 物品类.FLD_MAGIC1, FLD_MAGIC2 = 物品类.FLD_MAGIC2, FLD_MAGIC3 = 物品类.FLD_MAGIC3, FLD_MAGIC4 = 物品类.FLD_MAGIC4, //FLD_CjFh = 物品类.FLD_FJ_初级附魂, //FLD_ZjFh = 物品类.FLD_FJ_中级附魂, //FLD_JingHua = 物品类.FLD_FJ_进化, //FLD_Bind = 物品类.物品绑定 }; class2.ItmeList.Add(item); if (BitConverter.ToInt32(物品类.物品ID, 0) == 0) { class2.Kwei++; } } catch (Exception exception) { throw new ArgumentException("提示:数据错误1!" + exception.Message); } class2.FLD_ID = xwwl_char.FLD_ID; class2.FLD_Name = username; class2.FLD_JOB = xwwl_char.FLD_JOB.ToString(); class2.FLD_ZX = xwwl_char.FLD_ZX.ToString(); } } return(class2); }
public static string GetItemslist(ItmeSClass ItmeSC, byte[] Itmes, int 物品数) { Dictionary <int, 物品类> dictionary = new Dictionary <int, 物品类>(); for (int i = 0; i < 物品数; i++) { if (Itmes.Length >= ((i * 0x49) + 0x49)) { byte[] dst = new byte[0x49]; try { Buffer.BlockCopy(Itmes, i * 0x49, dst, 0, 0x49); 物品类 物品类 = new 物品类(dst); dictionary.Add(i, 物品类); ItmeClass item = new ItmeClass { ID = i, FLD_ID = BitConverter.ToInt64(物品类.物品全局ID, 0), FLD_ItmeID = BitConverter.ToInt32(物品类.物品ID, 0), FLD_NAME = 物品类.物品名称, FLD_Type = 物品类.物品类型, FLD_Suliang = BitConverter.ToInt32(物品类.物品数量, 0), FLD_MAGIC0 = 物品类.FLD_MAGIC0, FLD_MAGIC1 = 物品类.FLD_MAGIC1, FLD_MAGIC2 = 物品类.FLD_MAGIC2, FLD_MAGIC3 = 物品类.FLD_MAGIC3, FLD_MAGIC4 = 物品类.FLD_MAGIC4, //FLD_CjFh = 物品类.FLD_FJ_初级附魂, //FLD_ZjFh = 物品类.FLD_FJ_中级附魂, //FLD_JingHua = 物品类.FLD_FJ_进化, FLD_Bind = 物品类.物品绑定 }; ItmeSC.ItmeList.Add(item); if (BitConverter.ToInt32(物品类.物品ID, 0) == 0) { ItmeSC.Kwei++; } } catch (Exception exception) { throw new ArgumentException("提示:数据错误1!" + exception.Message); } } } return(JsonConvert.SerializeObject(ItmeSC)); }
ActionResult Choujiang(int count) { string s_success = JsonConvert.SerializeObject(new { success = true, message = "成功" }); if (string.IsNullOrEmpty(Session_FLDID)) { s_success = JsonConvert.SerializeObject(new { success = false, message = "请重新登录" }); return(Content(s_success, MIME_JSON)); } var gameUser = cjcontext.GamingUser.Where(a => a.UserId == Session_FLDID).SingleOrDefault(); var account = accountcontext.TBL_ACCOUNT.Where(a => a.FLD_ID == Session_FLDID).SingleOrDefault(); string msg = ""; if (gameUser == null || account == null) { s_success = JsonConvert.SerializeObject(new { success = false, message = "该角色不存在!" }); return(Content(s_success, MIME_JSON)); } else { if ((gameUser != null && string.IsNullOrEmpty(gameUser.UserName)) || (account != null && string.IsNullOrEmpty(account.FLD_NAME))) { s_success = JsonConvert.SerializeObject(new { success = false, message = "该角色名不存在!" }); return(Content(s_success, MIME_JSON)); } } if (account.FLD_ONLINE == 1) { s_success = JsonConvert.SerializeObject(new { success = false, message = "帐号在线请先下线!" }); return(Content(s_success, MIME_JSON)); } if (gameUser.Count < count) { s_success = JsonConvert.SerializeObject(new { success = false, message = "抽奖次数不足" }); return(Content(s_success, MIME_JSON)); } if (!CheckFLDZS(gameUser.UserName, out msg)) { s_success = JsonConvert.SerializeObject(new { success = false, message = msg }); return(Content(s_success, MIME_JSON)); } try { ItmeSClass class2 = GetBag(gameUser.UserName); class2.FLD_ONLINE = account.FLD_ONLINE.ToString(); List <int> kwList = new List <int>(); List <GamingGoods> resultGoods = new List <GamingGoods>(); for (int num2 = 0; num2 < 0x24; num2++) { if (class2.ItmeList[num2].FLD_ID == 0 && kwList.Count < count) { kwList.Add(num2); } } if (class2.Kwei >= count) { foreach (int weizi in kwList) { var gameGoods = GetOneGoods(); resultGoods.Add(gameGoods); int itemId = int.Parse(gameGoods.GoodId); bool flag = InsertItem(gameUser.UserName, weizi, itemId); GamingRecord record = new GamingRecord { ItemId = gameGoods.GoodId, ItemName = gameGoods.Name, Struts = flag, UserId = gameUser.UserId, UserName = gameUser.UserName, UserSpace = Request.UserHostAddress, CreateTime = DateTime.Now }; cjcontext.Entry(record).State = System.Data.EntityState.Added; cjcontext.SaveChanges(); if (!flag) { s_success = JsonConvert.SerializeObject(new { success = false, message = "系统异常" }); return(Content(s_success, MIME_JSON)); } gameUser.Count--; cjcontext.Entry(gameUser).State = System.Data.EntityState.Modified; cjcontext.SaveChanges(); } //s_success = JsonConvert.SerializeObject(new //{ // success = true, // message = "成功" //}); if (resultGoods.Count == 1) { s_success = JsonConvert.SerializeObject(new { success = true, message = "成功", itemid = resultGoods[0].GoodId, itemname = resultGoods[0].Name, }); } else { s_success = JsonConvert.SerializeObject(new { success = true, message = "成功", list = (from a in resultGoods select new { Name = a.Name }).ToList() }); } return(Content(s_success, MIME_JSON)); } else { s_success = JsonConvert.SerializeObject(new { success = false, message = "背包空间不足" }); return(Content(s_success, MIME_JSON)); } } catch (Exception ex) { s_success = JsonConvert.SerializeObject(new { success = false, message = ex.Message }); return(Content(s_success, MIME_JSON)); } }
public ItmeSClass GetBag(string username, string serverdb = "0", string serverid = "d1") { Dictionary <int, 物品类> dictionary = null; string server = serverid; string str2 = username; string str3 = serverdb; string str4 = "TBL_XWWL_Char"; string str5 = "FLD_ITEM,FLD_ID,FLD_JOB,FLD_ZX"; string str6 = "FLD_ITEM"; string str7 = "FLD_NAME"; int num = 0x24; if (str3 == "0") { str4 = "TBL_XWWL_Char"; str5 = "FLD_ITEM,FLD_ID,FLD_JOB,FLD_ZX"; str6 = "FLD_ITEM"; str7 = "FLD_NAME"; num = 0x24; } else if (str3 == "1") { str4 = "TBL_XWWL_Char"; str5 = "FLD_WEARITEM,FLD_ID,FLD_JOB,FLD_ZX"; str6 = "FLD_WEARITEM"; str7 = "FLD_NAME"; num = 15; } else if (str3 == "2") { str4 = "TBL_XWWL_Warehouse"; str5 = "FLD_ITEM,FLD_ID"; str6 = "FLD_ITEM"; str7 = "FLD_NAME"; num = 60; } else if (str3 == "3") { str4 = "TBL_XWWL_PublicWarehouse"; str5 = "FLD_ITEM,FLD_ID"; str6 = "FLD_ITEM"; str7 = "FLD_ID"; num = 60; } DataTable table = DBA.GetDBToDataTable(string.Format("select {3} from {2} WHERE {1} ='{0}'", new object[] { str2, str7, str4, str5 }), "rxjhgame", server); if (table == null) { throw new ArgumentException("提示:错误没有这个人物!数据库可能有问题"); } if (table.Rows.Count == 0) { throw new ArgumentException("提示:错误没有这个人物!"); } dictionary = new Dictionary <int, 物品类>(); ItmeSClass class2 = new ItmeSClass(); byte[] src = (byte[])table.Rows[0][str6]; for (int i = 0; i < num; i++) { if (src.Length >= (i * 37 + 37)) { byte[] dst = new byte[37]; try { Buffer.BlockCopy(src, i * 37, dst, 0, 37); 物品类 物品类 = new 物品类(dst); dictionary.Add(i, 物品类); ItmeClass item = new ItmeClass { ID = i, FLD_ID = BitConverter.ToInt64(物品类.物品全局ID, 0), FLD_ItmeID = BitConverter.ToInt32(物品类.物品ID, 0), FLD_NAME = 物品类.物品名称, FLD_Type = 物品类.物品类型, FLD_Suliang = BitConverter.ToInt32(物品类.物品数量, 0), FLD_MAGIC0 = 物品类.FLD_MAGIC0, FLD_MAGIC1 = 物品类.FLD_MAGIC1, FLD_MAGIC2 = 物品类.FLD_MAGIC2, FLD_MAGIC3 = 物品类.FLD_MAGIC3, FLD_MAGIC4 = 物品类.FLD_MAGIC4, }; class2.ItmeList.Add(item); if (BitConverter.ToInt32(物品类.物品ID, 0) == 0) { class2.Kwei++; } } catch (Exception exception) { throw new ArgumentException("提示:数据错误1!" + exception.Message); } class2.FLD_ID = table.Rows[0]["FLD_ID"].ToString(); class2.FLD_Name = str2; if ((str3 != "2") && (str3 != "3")) { class2.FLD_JOB = table.Rows[0]["FLD_JOB"].ToString(); class2.FLD_ZX = table.Rows[0]["FLD_ZX"].ToString(); } DataTable table2 = DBA.GetDBToDataTable(string.Format("select FLD_ID,FLD_ONLINE,FLD_SEX from [TBL_ACCOUNT] where FLD_ID='{0}'", class2.FLD_ID), "rxjhaccount", server); class2.FLD_ONLINE = table2.Rows[0]["FLD_ONLINE"].ToString(); table2.Dispose(); } } table.Dispose(); return(class2); }
public bool InsertItem(string username, int weizi, int itemid) { try { string server = "d1"; string name = username; int num = weizi; long num2 = 0L; int num3 = itemid; int num4 = 0; int num5 = 0; int num6 = 0; int num7 = 0; int num8 = 0; int num9 = 0; int num10 = 0; int num11 = 0; int num12 = 1; bool flag = false; string sm = "550088081"; string selectDb = "0"; string str5 = "TBL_XWWL_Char"; string str6 = "FLD_ITEM,FLD_ID,FLD_JOB,FLD_ZX"; string str7 = "FLD_ITEM"; string str8 = "FLD_NAME"; if (selectDb == "0") { str5 = "TBL_XWWL_Char"; str6 = "FLD_ITEM,FLD_ID,FLD_JOB,FLD_ZX"; str7 = "FLD_ITEM"; str8 = "FLD_NAME"; } else if (selectDb == "1") { str5 = "TBL_XWWL_Char"; str6 = "FLD_WEARITEM,FLD_ID,FLD_JOB,FLD_ZX"; str7 = "FLD_WEARITEM"; str8 = "FLD_NAME"; } else if (selectDb == "2") { str5 = "TBL_XWWL_Warehouse"; str6 = "FLD_ITEM,FLD_ID"; str7 = "FLD_ITEM"; str8 = "FLD_NAME"; } else if (selectDb == "3") { str5 = "TBL_XWWL_PublicWarehouse"; str6 = "FLD_ITEM,FLD_ID"; str7 = "FLD_ITEM"; str8 = "FLD_ID"; } DataTable table = DBA.GetDBToDataTable(string.Format("select {3} from {2} WHERE {1} ='{0}'", new object[] { name, str8, str5, str6 }), "rxjhgame", server); if (table == null) { return(false); } if (table.Rows.Count == 0) { table.Dispose(); throw new ArgumentException("提示:错误没有这个人物!"); } 物品类 物品类 = new 物品类(new byte[37]); if (num2 != 0) { sm = "更新物品 " + sm; } else { num2 = long.Parse(DBA.GetDBValue_3("EXEC XWWL_GetItemSerial 1", "rxjhgame", server).ToString()); } 物品类.物品全局ID = BitConverter.GetBytes(num2); 物品类.物品ID = BitConverter.GetBytes(num3); 物品类.物品数量 = BitConverter.GetBytes(num12); 物品类.FLD_MAGIC0 = num4; 物品类.FLD_MAGIC1 = num5; 物品类.FLD_MAGIC2 = num6; 物品类.FLD_MAGIC3 = num7; 物品类.FLD_MAGIC4 = num8; //物品类.FLD_FJ_初级附魂 = num9; //物品类.FLD_FJ_中级附魂 = num10; //物品类.FLD_FJ_进化 = num11; 物品类.物品绑定 = flag; byte[] dst = (byte[])table.Rows[0][str7]; AdminClass.SetItmeLog(BitConverter.ToInt64(物品类.物品全局ID, 0), 物品类.物品名称, name, string.Concat(new object[] { num4, "_", num5, "_", num6, "_", num7, "_", num8, " 初", num9, " 中", num10, " 进", num11 }), server, sm); Buffer.BlockCopy(物品类.物品_byte, 0, dst, num * 37, 37); AdminClass.UpItemsDate(server, name, dst, selectDb); ItmeSClass itmeSC = new ItmeSClass { FLD_ID = table.Rows[0]["FLD_ID"].ToString(), FLD_Name = name }; if ((selectDb != "2") && (selectDb != "3")) { itmeSC.FLD_JOB = table.Rows[0]["FLD_JOB"].ToString(); itmeSC.FLD_ZX = table.Rows[0]["FLD_ZX"].ToString(); } DataTable table2 = DBA.GetDBToDataTable(string.Format("select FLD_ID,FLD_ONLINE,FLD_SEX from [TBL_ACCOUNT] where FLD_ID='{0}'", itmeSC.FLD_ID) , "rxjhaccount", server); itmeSC.FLD_ONLINE = table2.Rows[0]["FLD_ONLINE"].ToString(); itmeSC.FLD_SEX = table2.Rows[0]["FLD_SEX"].ToString(); table2.Dispose(); AdminClass.GetItemslist(itmeSC, dst, 0x24); table.Dispose(); return(true); } catch (Exception) { return(false); } }