//复活 private bool DaoJuRevive(FightPlayer a, int p, PlayerEx package, GameConfig c) { string target = a.Action.Target; FightPlayer t = m_teamA.FirstOrDefault(x => x.ID == target) as FightPlayer; if (t == null) t = m_teamB.FirstOrDefault(x => x.ID == target) as FightPlayer; if (t == null || t.IsLive) return false; //检查使用限制.. //if (!SupplyLimit(note, c)) return false; if (a.Player.RemoveGoods(p, GoodsSource.DaoJuRevive)) { ActionResult result = new ActionResult(target); //百分比复活生命 int hp = (int)(t.Life.ShengMing * c.Value.GetDoubleOrDefault("A")); int mp = (int)(t.Life.MoFa * c.Value.GetDoubleOrDefault("B")) - t.MP; if (mp < 0) mp = 0; t.AddHPAndMP(hp, mp); if (hp > 0) { result.Value["HP"] = hp; result.Value["ShengMing"] = t.HP; } if (mp > 0) { result.Value["MP"] = mp; result.Value["MoFa"] = t.MP; } result.ActionFlag |= ActionFlag.Supply; a.Action.Result = new List<ActionResult>() { result }; a.Action.FightCount = FightAction.HasAction; m_actions.Add(a.Action); return true; } return false; }
static void Start() { try { int index = random.Next(names.Length); string name = names[index]; PlayerEx client = new PlayerEx(id, name); client.Value = new Variant(); for (int i = 0; i < index * 10; i++) { client.Value.Add("sd" + i, i); } PlayerExAccess.Instance.Save(client); var q = Query.EQ("_id", id); //long count = PlayerExAccess.Instance.GetCount(q); //Variant x = PlayerExAccess.Instance.FindOneById<Variant>(id); System.Threading.Interlocked.Increment(ref sucess); Console.WriteLine("写成功:" + sucess); } catch (System.TimeoutException) { } catch (System.Exception ex) { Console.WriteLine(ex.Message, ex.TargetSite); } }
/// <summary> /// 得到装备面板列表 /// </summary> /// <param name="note"></param> private void GetEquipPanel(UserNote note) { PlayerEx equip = note.Player.Equips; //判断角色装备信息 if (equip == null) { PlayerEx p = new PlayerEx(note.PlayerID, "Equips"); p.Value = new Variant(); Variant v = p.Value; for (int i = 0; i < 12; i++) { Variant t = new Variant(); t.Add("E", string.Empty); t.Add("G", string.Empty); t.Add("A", 0); t.Add("S", 0); t.Add("H", 0); t.Add("D", 0); t.Add("T", null); v.Add("P" + i, t); } p.Save(); //内存创建 note.Player.Value["Equips"] = p; equip = p; } //note.Call(GoodsCommand.GetEquipPanelR, true, Business.GoodsBusiness.RemoveEquips(note)); note.Call(GoodsCommand.GetEquipPanelR, true, equip); }
/// <summary> /// 判断是否允许 /// </summary> /// <param name="note"></param> /// <param name="id">id</param> /// <param name="key">类型</param> /// <returns></returns> public static bool IsLet(PlayerEx social, string id, List<string> k) { foreach (string n in k) { IList list = null; if (n == "Master" || n == "Apprentice") { Variant mentor = social.Value.GetValueOrDefault<Variant>("Mentor"); if (mentor == null) continue; list = mentor[n] as IList; if (list == null) continue; } else { list = social.Value.GetValue<IList>(n); } if (list != null) { foreach (Variant d in list) { if (d == null) continue; if (d.GetStringOrDefault("PlayerID") == id) return true; } } } return false; }
/// <summary> /// 好友祝福 /// </summary> /// <param name="note"></param> public static void FriendsBless(UserNote note) { string soleid = note.PlayerID + "FriendsBless"; try { if (!m_dic.TryAdd(soleid, soleid)) return; string playerid = note.GetString(0); string goodsid = note.GetString(1); GameConfig gc = GameConfigAccess.Instance.FindOneById("BL_0001"); if (gc == null || gc.Value == null) { note.Call(SocialCommand.FriendsBlessR, false, TipManager.GetMessage(SocialReturn.FriendsBless1)); return; } Variant bless = gc.Value.GetValueOrDefault<Variant>("Bless"); Variant tmp = null; foreach (var k in bless) { string[] strs = k.Key.Split('-'); if (strs.Length < 2) { note.Call(SocialCommand.FriendsBlessR, false, TipManager.GetMessage(SocialReturn.FriendsBless1)); return; } int min = Convert.ToInt32(strs[0]); int max = Convert.ToInt32(strs[1]); if (note.Player.Level >= min && note.Player.Level <= max) { tmp = k.Value as Variant; break; } } if (tmp == null || (!tmp.ContainsKey(goodsid))) { note.Call(SocialCommand.FriendsBlessR, false, TipManager.GetMessage(SocialReturn.FriendsBless1)); return; } Variant goods = tmp.GetValueOrDefault<Variant>(goodsid); Dictionary<string, Variant> dic = new Dictionary<string, Variant>(); Variant vv = new Variant(); vv.Add("Number1", goods.GetIntOrDefault("Count")); dic.Add(goodsid, vv); if (BurdenManager.IsFullBurden(note.Player.B0, dic)) { note.Call(SocialCommand.FriendsBlessR, false, TipManager.GetMessage(SocialReturn.FriendsBless2)); return; } Variant beBless = gc.Value.GetValueOrDefault<Variant>("BeBless"); Variant beTmp = null; foreach (var k in beBless) { string[] strs = k.Key.Split('-'); if (strs.Length < 2) { note.Call(SocialCommand.FriendsBlessR, false, TipManager.GetMessage(SocialReturn.FriendsBless1)); return; } int min = Convert.ToInt32(strs[0]); int max = Convert.ToInt32(strs[1]); if (note.Player.Level >= min && note.Player.Level <= max) { beTmp = k.Value as Variant; break; } } if (beTmp == null) { note.Call(SocialCommand.FriendsBlessR, false, TipManager.GetMessage(SocialReturn.FriendsBless1)); return; } int mn = 0; string beGoods = BeBless(beTmp, out mn); if (string.IsNullOrEmpty(beGoods) || mn <= 0) { note.Call(SocialCommand.FriendsBlessR, false, TipManager.GetMessage(SocialReturn.FriendsBless1)); return; } GameConfig gc1 = GameConfigAccess.Instance.FindOneById(beGoods); if (gc1 == null) { note.Call(SocialCommand.FriendsBlessR, false, TipManager.GetMessage(SocialReturn.FriendsBless1)); return; } PlayerBusiness pb = PlayersProxy.FindPlayerByID(playerid); if (pb == null) { //"好友不存在"); note.Call(SocialCommand.FriendsBlessR, false, TipManager.GetMessage(SocialReturn.UserInfoError)); return; } PlayerEx ex; Variant v; if (!note.Player.Value.TryGetValueT("Bless", out ex)) { ex = new PlayerEx(note.PlayerID, "Bless"); v = new Variant(); v.Add("Total", 10);//允许祝福次数 v.Add("BlessList", null); ex.Value = v; //祝福时间 note.Player.Value.Add("Bless", ex); } v = ex.Value; Variant blessList = v.GetValueOrDefault<Variant>("BlessList"); if (blessList != null) { int count = 0;//今日祝福次数 foreach (DateTime k in blessList.Values) { if (k.ToLocalTime().Date == DateTime.Now.Date) count++; if (count >= v.GetIntOrDefault("Total")) { //"今日祝福次已经用完,每日最多能祝福好友10次" note.Call(SocialCommand.FriendsBlessR, false, TipManager.GetMessage(SocialReturn.FriendsBless3)); return; } } if (blessList.ContainsKey(playerid)) { DateTime blessDate = blessList.GetDateTimeOrDefault(playerid); if (blessDate.ToLocalTime().Date == DateTime.Now.Date) { //"每日同一好友只能祝福一次" note.Call(SocialCommand.FriendsBlessR, false, TipManager.GetMessage(SocialReturn.FriendsBless4)); return; } } } else { v["BlessList"] = new Variant(); blessList = v.GetValueOrDefault<Variant>("BlessList"); } string gid = "G_d000683"; if (!note.Player.RemoveGoods(gid, 1, GoodsSource.FriendsBless)) { //"你没有鲜花,无法祝福" note.Call(SocialCommand.FriendsBlessR, false, TipManager.GetMessage(SocialReturn.FriendsBless5)); return; } //更新祝福时间 blessList[playerid] = DateTime.UtcNow; ex.Save(); note.Player.AddGoods(dic, GoodsSource.FriendsBless); note.Player.AddAcivity(ActivityType.FriendsBless, 1); if (mn > 0) { Variant gs = new Variant(); gs.Add("G", beGoods); gs.Add("A", mn); gs.Add("E", beGoods); gs.Add("H", 1); List<Variant> goodsList = new List<Variant>(); goodsList.Add(gs); int reTime = Convert.ToInt32(TipManager.GetMessage(EmailReturn.HameDay)); //"因为你好友【" + note.Player.Name + "】对你的祝福,你获得了【" + gc1.Name+ "】,为了你们的友谊,你也快祝福祝福他吧!"; string msg = string.Format(TipManager.GetMessage(SocialReturn.FriendsBless6), note.Player.Name, gc1.Name); //if (EmailAccess.Instance.SendEmail("好友祝福", "系统邮件", pb.ID, pb.Name, msg, string.Empty, goodsList)) if (EmailAccess.Instance.SendEmail(TipManager.GetMessage(SocialReturn.FriendsBless7), TipManager.GetMessage(SocialReturn.FriendsBless8), pb.ID, pb.Name, msg, string.Empty, goodsList, reTime)) { if (pb.Online) { pb.Call(EmailCommand.NewEmailTotalR, EmailAccess.Instance.NewTotal(pb.ID)); pb.Call(SocialCommand.FriendsBlessR, true, note.Player.Name); } } } note.Call(ClientCommand.UpdateActorR, new PlayerExDetail(ex)); note.Call(SocialCommand.FriendsBlessR, true, TipManager.GetMessage(SocialReturn.FriendsBless9)); note.Player.FinishNote(FinishCommand.WishFriends); //日志记录 //note.Player.AddLog(Log.Actiontype.GoodsUse, gid, 1, GoodsSource.FriendsBless, "", 0); } finally { m_dic.TryRemove(soleid, out soleid); } }
/// <summary> /// 更新表中持久度 /// </summary> /// <param name="equips"></param> /// <param name="goodsid"></param> /// <param name="max"></param> private void UpdateStamina(PlayerEx equips, string goodsid, int max) { Variant v = equips.Value; Variant tmp = null; foreach (Variant vas in v.Values) { if (vas.GetStringOrDefault("E") == goodsid) { tmp = vas; break; } } Variant t = tmp.GetVariantOrDefault("T"); if (t != null) { t["Stamina"] = max; } }
/// <summary> /// 移除过期的物品 /// </summary> /// <param name="burden"></param> public static Dictionary<string, int> Remove(PlayerEx burden) { Dictionary<string, int> dic = new Dictionary<string, int>(); IList c = burden.Value.GetValue<IList>("C"); for (int i = 0; i < c.Count; i++) { Variant v = c[i] as Variant; if (v.GetStringOrDefault("E") == string.Empty) continue; if (v.GetStringOrDefault("E") != v.GetStringOrDefault("G")) { Goods g = GoodsAccess.Instance.FindOneById(v.GetStringOrDefault("E")); if (g == null) continue; Variant Timelines = g.Value.GetVariantOrDefault("TimeLines"); if (Timelines != null) { //永久有效0 //获得时计时1 //使用后计时2 if (Timelines.GetIntOrDefault("Type") == 0) continue; DateTime dt = DateTime.UtcNow; TimeSpan ts = dt - g.Created; if (ts.TotalHours >= Timelines.GetIntOrDefault("Hour")) { //表示物品已经过期,移除 BurdenManager.BurdenClear(v); if (dic.ContainsKey(g.Name)) { dic[g.Name] += v.GetIntOrDefault("A"); } else { dic.Add(g.Name, v.GetIntOrDefault("A")); } } } } } burden.Save(); return dic; }
/// <summary> /// 批量移除对应位置的道具,主要用来交易使用 /// </summary> /// <param name="burden"></param> /// <param name="goods"></param> public static bool Remove(PlayerEx burden, IList goods) { IList c = burden.Value.GetValue<IList>("C"); foreach (Variant d in goods) { for (int i = 0; i < c.Count; i++) { Variant v = c[i] as Variant; if (v == null) continue; if (d.GetIntOrDefault("P") == v.GetIntOrDefault("P")) { if (d.GetStringOrDefault("ID") != v.GetStringOrDefault("E")) { return false; } if (d.GetIntOrDefault("Count") != v.GetIntOrDefault("A")) { return false; } if (d.GetIntOrDefault("Count") == v.GetIntOrDefault("A")) { BurdenClear(v); } else if (v.GetIntOrDefault("Count") > d.GetIntOrDefault("A")) { v["A"] = v.GetIntOrDefault("Count") - d.GetIntOrDefault("A"); } } } } burden.Save(); return true; }
/// <summary> /// 得到对应包袱位置的信息 /// </summary> /// <param name="burden"></param> /// <param name="p"></param> /// <returns></returns> public static Variant BurdenPlace(PlayerEx burden, int p) { IList c = burden.Value.GetValue<IList>("C"); Variant tmp = null; foreach (Variant v in c) { if (v.GetIntOrDefault("P") == p) { tmp = v; break; } } return tmp; }
/// <summary> ///交易使用 /// </summary> /// <param name="burden"></param> /// <param name="goods"></param> public static void BurdenInsert(PlayerEx burden, IList goods) { IList c = burden.Value.GetValue<IList>("C"); //交易得到的物品 foreach (Variant k in goods) { Variant v = GetBurdenSpace(c); //得到第一个空格子 Goods g = GoodsAccess.Instance.FindOneById(k.GetStringOrDefault("ID")); if (g != null) { v["E"] = g.ID; v["G"] = g.GoodsID; v["S"] = g.Value.GetIntOrDefault("Sort"); v["H"] = 0; v["A"] = 1; v["D"] = 0; v["T"] = CreateT(g); g.PlayerID = burden.PlayerID; g.Save(); } else { GameConfig gc = GameConfigAccess.Instance.FindOneById(k.GetStringOrDefault("ID")); if (gc == null) continue; v["E"] = gc.ID; v["G"] = gc.ID; v["S"] = gc.Value.GetIntOrDefault("Sort"); v["H"] = 0; v["A"] = k.GetIntOrDefault("Count"); v["D"] = 1; v["T"] = null; } } burden.Save(); }
/// <summary> /// 请先判断包袱是否足够存放道具,否则如果包袱满将不能再得到道具 /// </summary> /// <param name="c"></param> /// <param name="goodsList"></param> /// <param name="issave">是否保存</param> public static Dictionary<string, int> BurdenBatchInsert(PlayerEx burden, Dictionary<string, Variant> goodsList, bool issave = true) { //成功加入道具数量 try { Dictionary<string, int> dic = new Dictionary<string, int>(goodsList.Count); IList c = burden.Value.GetValue<IList>("C"); foreach (var item1 in goodsList) { GameConfig gc = GameConfigAccess.Instance.FindOneById(item1.Key); if (gc == null) continue; int sc = GameConfigAccess.Instance.GetStactCount(item1.Key); if (sc <= 0) break; //表示得到道具 Variant v = goodsList[item1.Key] as Variant; if (v == null) continue; //int number = 0; //int isbinding = 0; for (int isbinding = 0; isbinding <= 1; isbinding++) { //0为非绑定,1为绑定 int number = v.GetIntOrDefault("Number" + isbinding); if (number <= 0) continue; int num = 0;//当前分配数量 foreach (Variant m in c) { if (sc == 1) { #region 唯一道具 if (m.GetStringOrDefault("E") == string.Empty) { Variant m_vc = gc.Value; //Variant m_ui = gc.UI; Variant cv = new Variant(); foreach (var item in m_vc) { if (item.Key == "Affix") { Variant affix = new Variant(); GetAffix((Variant)item.Value, affix); if (affix == null || affix.Count == 0) continue; //cv.Add(item.Key, affix); cv[item.Key] = affix; } else { cv[item.Key] = item.Value; } } //过期时间 if (v.ContainsKey("EndTime")) { cv["EndTime"] = v.GetDateTimeOrDefault("EndTime"); } Goods g = Goods.Create(); g.ID = ObjectId.GenerateNewId().ToString(); g.GoodsID = gc.ID; g.Name = gc.Name; g.PlayerID = burden.PlayerID; g.Value = cv; g.Created = DateTime.UtcNow; g.Save(); m["E"] = g.ID; m["G"] = gc.ID; m["S"] = gc.Value.GetIntOrDefault("Sort"); m["H"] = isbinding; m["D"] = 0; m["A"] = 1; Variant tv = new Variant(); if (v.ContainsKey("EndTime")) { //过期时间 tv["EndTime"] = v.GetDateTimeOrDefault("EndTime"); } if (tv.Count != 0) { m["T"] = tv; } num += 1; if (num == number) break; } #endregion } else { #region 可堆叠道具 if (m.GetStringOrDefault("E") == string.Empty) { m["E"] = gc.ID; m["G"] = gc.ID; m["S"] = gc.Value.GetIntOrDefault("Sort"); m["H"] = isbinding; m["D"] = 1; if ((number - num) >= sc) { m["A"] = sc; num += sc; //dic.SetOrInc(gc.ID, sc); } else { m["A"] = number - num; //dic.SetOrInc(gc.ID, number - num); num = number; } if (v.ContainsKey("EndTime")) { Variant vt = new Variant(); vt.Add("EndTime", v.GetDateTimeOrDefault("EndTime")); m["T"] = vt; } else { m["T"] = null; } if (num == number) break; } else { if (m.GetStringOrDefault("E") != gc.ID) continue; int a = m.GetIntOrDefault("A"); if (a >= sc || m.GetIntOrDefault("H") != isbinding) continue; Variant t = m.GetValueOrDefault<Variant>("T"); if (t != null) { if (v.ContainsKey("EndTime")) { if (t.GetDateTimeOrDefault("EndTime") != v.GetDateTimeOrDefault("EndTime")) continue; } else { if (t.ContainsKey("EndTime")) continue; } } if ((number - num + a) >= sc) { m["A"] = sc; //dic.SetOrInc(gc.ID, sc - a); num += (sc - a); } else { m["A"] = number - num + a; //dic.SetOrInc(gc.ID, (number - num + a)); num = number; } if (num == number) break; } #endregion } } if (num > 0) { if (dic.ContainsKey(gc.ID)) { dic[gc.ID] += num; } else { dic.Add(gc.ID, num); } } } } if (issave) { burden.Save(); } return dic; } catch (Exception e) { LogWrapper.Warn("BurdenBatchInsert:" + burden.PlayerID, e); return new Dictionary<string, int>(); } }
/// <summary> /// 交易判断包袱能否装入下面物品 /// </summary> /// <param name="burdens"></param> /// <param name="goods"></param> /// <returns>true表示包袱格子不够</returns> public static bool BurdenDealFull(PlayerEx burdens, IList goods) { IList c = burdens.Value.GetValue<IList>("C"); if (BurdenSpace(c) >= goods.Count) return false; return true; }
/// <summary> /// 移除一件物品[0] /// </summary> /// <param name="burdens">物品所在包袱</param> /// <param name="p">物品所在位置</param> /// <param name="isall">true表示移除整个格子,false表示移除1个</param> public static bool RemoveGoods(PlayerEx burdens, int p, bool isall, out string goodsid,out int number) { IList c = burdens.Value.GetValue<IList>("C"); foreach (Variant k in c) { if (k.GetIntOrDefault("P") == p) { string soleid = k.GetStringOrDefault("E"); if (string.IsNullOrEmpty(soleid)) { goodsid = ""; number = 0; return false; } string goods = k.GetStringOrDefault("G"); int num = k.GetIntOrDefault("A"); if (num <= 0) { //数量不足 goodsid = ""; number = 0; return false; } if (soleid != goods) { BurdenClear(k); burdens.Save(); goodsid = goods; number = 1; GoodsAccess.Instance.Remove(soleid, burdens.PlayerID); return true; } else { //批量使用或物品只剩1个的时候 if (isall || num == 1) { BurdenClear(k); burdens.Save(); goodsid = goods; number = num; return true; } else { k["A"] = num - 1; burdens.Save(); goodsid = goods; number = 1; return true; } } //if (isall) //{ // goodsid = gid; // number = num; // BurdenClear(d); // burdens.Save(); // if (sid != gid) // { // GoodsAccess.Instance.Remove(sid, burdens.PlayerID); // } // return true; //} //else //{ // if (num == 1) // { // if (sid != gid) // { // GoodsAccess.Instance.Remove(sid, burdens.PlayerID); // } // goodsid = gid; // number = 1; // BurdenClear(d); // burdens.Save(); // return true; // } // else if (num > 1) // { // d["A"] = num - 1; // burdens.Save(); // goodsid = gid; // number = 1; // return true; // } // goodsid = ""; // number = 0; // return false; //} } } goodsid = ""; number = 0; return false; }
/// <summary> /// 移除所有指定道具 /// </summary> /// <param name="burden"></param> /// <param name="goodsid"></param> public static int RemoveAll(PlayerEx burden, string goodsid) { IList c = burden.Value.GetValue<IList>("C"); int count = 0; foreach (Variant v in c) { if (v.GetStringOrDefault("G") == goodsid) { count += v.GetIntOrDefault("A"); BurdenClear(v); } } burden.Save(); return count; }
/// <summary> /// 创建宠物槽 /// </summary> /// <param name="note"></param> private void CreatePetGroove(UserNote note) { PlayerEx PetGroove = note.Player.B3; if (PetGroove == null) { PlayerEx p = new PlayerEx(note.PlayerID, "B3"); p.Value = new Variant(); Variant v = p.Value; for (int i = 0; i < 8; i++) { if (!v.ContainsKey(i.ToString())) { Variant d = new Variant(); if (i < 4) d.Add("E", "0");//表示已经开启 else d.Add("E", "-1");//表示没有开启 d.Add("G", string.Empty); d.Add("I", 0);//0表示没有参加战斗,1表示参加战斗 v.Add(i.ToString(), d); } } p.Save(); } }
/// <summary> /// 移除一个指定类型的物品 /// </summary> /// <param name="burden"></param> /// <param name="goodsid"></param> /// <returns></returns> public static bool Remove(PlayerEx burden, string goodsid) { return Remove(burden, goodsid, 1); }
/// <summary> /// 移除道具 /// </summary> /// <param name="burden">包袱</param> /// <param name="goodsid">物品</param> /// <param name="number">数量</param> /// <returns></returns> public static bool Remove(PlayerEx burden, string goodsid, int number) { if (string.IsNullOrEmpty(goodsid)) return false; IList c = burden.Value.GetValue<IList>("C"); int num = 0; int count = 0; foreach (Variant v in c) { if (v.GetStringOrDefault("G") == goodsid) { count += v.GetIntOrDefault("A"); } } //表示数量不足 if (count < number) return false; foreach (Variant v in c) { if (v.GetStringOrDefault("G") != goodsid) continue; if ((number - num) >= v.GetIntOrDefault("A")) { num += v.GetIntOrDefault("A"); BurdenClear(v); } else { v["A"] = v.GetIntOrDefault("A") - (number - num); num = number; } if (num == number) break; } burden.Save(); return true; }
/// <summary> /// 得到包袱信息 /// </summary> /// <param name="burden"></param> /// <param name="id"></param> /// <returns></returns> public static Variant BurdenPlace(PlayerEx burden, string id) { IList c = burden.Value.GetValue<IList>("C"); Variant tmp = null; foreach (Variant v in c) { if (v.GetStringOrDefault("E") == id) { tmp = v; break; } } return tmp; }
/// <summary> /// 请先判断包袱道具是否满足,再进行批量移除道具 /// </summary> public static void Remove(PlayerEx burden, Dictionary<string, int> goods, out int isbinding) { int isb = 0; if (burden != null && goods.Count != 0) { foreach (var item in goods) { //移除道具数量 int number = goods[item.Key]; if (number <= 0) { isbinding = 1; return; } IList c = burden.Value.GetValue<IList>("C"); int curr = number;//当前还要移除的数量 foreach (Variant v in c) { if (v.GetStringOrDefault("G") == item.Key) { int A = v.GetIntOrDefault("A"); if (A > curr) { v["A"] = A - curr; curr = 0; if (v.GetIntOrDefault("H") == 1) { isb = 1; } break; } else { curr = curr - A; if (v.GetStringOrDefault("E") != v.GetStringOrDefault("G")) { GoodsAccess.Instance.RemoveOneById(v.GetStringOrDefault("E"), SafeMode.False); } if (v.GetIntOrDefault("H") == 1) { isb = 1; } BurdenManager.BurdenClear(v); if (curr == 0) break; } } } } burden.Save(); } isbinding = isb; //InvokeClientNote note = new InvokeClientNote(MessageCommand.InvokeClientByUserID, new object[] { isBinding }); //note.IDList = new List<string> { burden.PlayerID }; //note.Type = "方法名"; //Notifier.Instance.Publish(note); }
/// <summary> /// 得到空格数量 /// </summary> /// <param name="burden"></param> /// <returns></returns> public static int BurdenSpace(PlayerEx burden) { Variant v = burden.Value; if (v == null) return 0; IList c = v.GetValue<IList>("C"); return BurdenSpace(c); }
/// <summary> /// 清理领取奖励 /// </summary> /// <param name="note"></param> private void SystemAwardClear(UserNote note) { string name = "SystemAward"; PlayerEx p; if (!note.Player.Value.TryGetValueT(name, out p)) { p = new PlayerEx(note.Player.ID, name); } Variant v = p.Value; if (v != null) { if (v.Count > 0) { string[] strs = new string[v.Count]; v.Keys.CopyTo(strs, 0); for (int i = 0; i < strs.Length; i++) { if (!v.ContainsKey(strs[i])) continue; DateTime dt = v.GetDateTimeOrDefault(strs[i]).ToLocalTime(); TimeSpan ts = DateTime.Now.Date - dt.Date; if (ts.TotalDays >= 1) { v.Remove(strs[i]); } } } } else { p.Value = new Variant(); } p.Save(); //领奖成功 note.Call(ClientCommand.UpdateActorR, new PlayerExDetail(p)); }
/// <summary> /// 计算一个道具的数量G /// </summary> /// <param name="burden">包袱</param> /// <param name="goodsid">G道具ID</param> /// <returns></returns> public static int GoodsCount(PlayerEx burden, string goodsid) { int count = 0; IList c = burden.Value.GetValue<IList>("C"); foreach (Variant k in c) { if (k.GetStringOrDefault("G") == goodsid) { count += k.GetIntOrDefault("A"); } } return count; }
/// <summary> /// 每日奖励 /// </summary> /// <param name="note"></param> private void SystemAward(UserNote note) { string soleid = note.PlayerID; if (!m_dic.TryAdd(soleid, soleid)) return; try { string name = "SystemAward"; PlayerEx SystemAward; if (!note.Player.Value.TryGetValueT(name, out SystemAward)) { SystemAward = new PlayerEx(note.PlayerID, name); note.Player.Value.Add("SystemAward", SystemAward); } string id = note.GetString(0); string key = note.GetString(1);//选择的奖励 Variant v = AwardManager.Instance.FindOne(id); if (v == null) { note.Call(GoodsCommand.SystemAwardR, false, TipManager.GetMessage(GoodsReturn.NoAward)); return; } DateTime dt = DateTime.Now; string[] UpdateTime = v.GetStringOrDefault("UpdateTime").Split(':'); int Hour = Convert.ToInt32(UpdateTime[0].Trim());//小时 int Minute = Convert.ToInt32(UpdateTime[1].Trim());//分钟 //要求更新时间 DateTime ut = dt.Date.AddHours(Hour).AddMinutes(Minute); if (dt < ut) { note.Call(GoodsCommand.SystemAwardR, false, TipManager.GetMessage(GoodsReturn.NoAwardDate)); return; } //等级限制 string[] Level = v.GetStringOrDefault("Level").Split('-'); int minLevel = Convert.ToInt32(Level[0]); int maxLevel = Convert.ToInt32(Level[1]); if (note.Player.Level < minLevel || note.Player.Level > maxLevel) { note.Call(GoodsCommand.SystemAwardR, false, TipManager.GetMessage(GoodsReturn.NoAwardLevel)); return; } Variant award = v.GetVariantOrDefault("Award"); if (award == null) { note.Call(GoodsCommand.SystemAwardR, false, TipManager.GetMessage(GoodsReturn.AwardConfigError)); return; } Variant awardList = award.GetVariantOrDefault(note.Player.RoleID + note.Player.Sex); if (awardList == null) { note.Call(GoodsCommand.SystemAwardR, false, TipManager.GetMessage(GoodsReturn.AwardConfigError)); return; } Variant s = SystemAward.Value; if (s != null) { //表示已经领奖 if (s.ContainsKey(id)) { note.Call(GoodsCommand.SystemAwardR, false, TipManager.GetMessage(GoodsReturn.IsAward)); return; } //判断当天是否领奖 if (s.Count > 0) { note.Call(GoodsCommand.SystemAwardR, false, TipManager.GetMessage(GoodsReturn.IsAward)); return; } } //是否为选择类型 int selectType = awardList.GetIntOrDefault("SelectType"); int score = 0, bond = 0, exp = 0, pExp = 0; //石币,晶币,经验,宠物经验 Dictionary<string, Variant> dic = new Dictionary<string, Variant>(); if (selectType == 0) { if (key != string.Empty) { note.Call(GoodsCommand.SystemAwardR, false, TipManager.GetMessage(GoodsReturn.NoSelect)); return; } foreach (string k in awardList.Keys) { if (k == "SelectType") continue; int count = awardList.GetIntOrDefault(k); switch (k) { case "Score": score = count; break; case "Coin": bond = count; break; case "Exp": exp = count; break; case "PExp": pExp = count; break; default: Variant vn = new Variant(); vn.Add("Number1", awardList.GetIntOrDefault(k)); if (dic.ContainsKey(k)) { Variant t = dic[k]; t["Number1"] = t.GetIntOrDefault("Number1") + count; } else { dic.Add(k, vn); } break; } } if (dic.Count > 0) { #if QY Variant mv = MemberAccess.MemberInfo(note.Player.MLevel); if (mv != null) { string gid = ""; int c = mv.GetIntOrDefault("Award"); if (c >= 0) { Variant gv = new Variant(); gv.Add("Number1", c); if (dic.ContainsKey(gid)) { Variant t = dic[gid]; t["Number1"] = t.GetIntOrDefault("Number1") + c; } else { dic.Add(gid, gv); } } } #endif //包袱满 if (BurdenManager.IsFullBurden(note.Player.B0, dic)) { note.Call(GoodsCommand.SystemAwardR, false, TipManager.GetMessage(GoodsReturn.BurdenB0Full)); return; } } } else { if (!awardList.ContainsKey(key)) { note.Call(GoodsCommand.SystemAwardR, false, TipManager.GetMessage(GoodsReturn.SelectNoAward)); return; } //奖励数量 int count = awardList.GetIntOrDefault(key); if (key == "PExp") { if (note.Player.Pet == null) { note.Call(GoodsCommand.SystemAwardR, false, TipManager.GetMessage(GoodsReturn.NoPetExp)); return; } pExp = count; } else if (key == "Score") { score = count; } else if (key == "Bond") { bond = count; } else if (key == "Exp") { exp = count; } } //领奖时间 if (s != null) { s.Add(id, dt); } else { Variant mn = new Variant(); mn.Add(id, dt); SystemAward.Value = mn; s = SystemAward.Value; } if (!SystemAward.Save()) { note.Call(GoodsCommand.SystemAwardR, false, TipManager.GetMessage(GoodsReturn.IsAward)); return; } if (bond > 0) { note.Player.AddBond(bond, FinanceType.SystemAward); } if (score > 0) { note.Player.AddScore(score, FinanceType.SystemAward); } if (exp > 0) { note.Player.AddExperience(exp, FinanceType.SystemAward); } if (pExp > 0) { note.Player.AddPetExp(note.Player.Pet, pExp, true, (int)FinanceType.SystemAward); } if (dic.Count > 0) { note.Player.AddGoods(dic, GoodsSource.SystemAward); } //操作成功移除 //领奖成功 note.Call(ClientCommand.UpdateActorR, new PlayerExDetail(SystemAward)); note.Call(GoodsCommand.SystemAwardR, true, TipManager.GetMessage(GoodsReturn.AwardSuccess)); } finally { m_dic.TryRemove(soleid, out soleid); } }
/// <summary> /// 判断有过期时间的物品数量 /// </summary> /// <param name="burden">包袱</param> /// <param name="goodsid">道具ID</param> /// <param name="endtime">过期时间</param> /// <returns></returns> public static int GoodsCount(PlayerEx burden, string goodsid, DateTime endtime) { int count = 0; IList c = burden.Value.GetValue<IList>("C"); foreach (Variant k in c) { Variant t = k["T"] as Variant; if (t != null) { if (t.ContainsKey("EndTime")) { if (t.GetDateTimeOrDefault("EndTime") == endtime && k.GetStringOrDefault("G") == goodsid) { count += k.GetIntOrDefault("A"); } } } } return count; }
/// <summary> /// 判断角色是否存在包袱与仓库 /// </summary> /// <param name="note"></param> private void CreateBurden(UserNote note) { for (int i = 0; i < 2; i++) { string key = "B" + i; if (!note.Player.Value.ContainsKey(key)) { int max = 0; int cur = 0; switch (i) { case 0: max = 64; cur = 64; break; case 1: max = 105; cur = 35; break; } PlayerEx p = new PlayerEx(note.PlayerID, key); p.Value = new Variant(); Variant v = p.Value; v.Add("Max", max); v.Add("Cur", cur); List<Variant> list = new List<Variant>(); for (int j = 0; j < v.GetIntOrDefault("Cur"); j++) { Variant d = new Variant(); d.Add("P", j); d.Add("E", string.Empty); d.Add("G", string.Empty);//道具ID d.Add("A", 0); d.Add("S", 0);//排序 d.Add("H", 0);//0非绑定,1绑定是否绑定 d.Add("D", 0);//0不能堆叠,1可以 d.Add("T", null);//物品类型 list.Add(d); } v.Add("C", list); note.Player.Value.Add(key, p); p.Save(); } } }
/// <summary> /// 判断需要的物品是否为绑定 /// </summary> /// <param name="burden"></param> /// <param name="goodsid">物品</param> /// <param name="number">需要数量</param> /// <returns>0表示非绑定,1绑定</returns> public static int IsBinding(PlayerEx burden, string goodsid, int number) { if (string.IsNullOrEmpty(goodsid)) return 1; Variant bv = burden.Value; if (bv == null) return 1; IList c = bv.GetValue<IList>("C"); int n = 0; foreach (Variant v in c) { string gid = v.GetStringOrDefault("G"); if (gid != goodsid) continue; int a = v.GetIntOrDefault("A"); int h = v.GetIntOrDefault("H"); n += a; if (n < number && h == 1) { return 1; } if (n >= a) { return h; } } if (n < number) return 1; return 1; }
/// <summary> /// 重置日常任务 /// </summary> /// <param name="pb">当前在线</param> /// <param name="iscall"></param> public static void DayTask(PlayerBusiness pb, bool iscall = true) { string[] strs = TipManager.GetMessage(TaskReturn.DayTaskConfig).Split('|'); if (strs.Length < 2) return; List<string> list = TaskAccess.Instance.Remove_1(pb.ID, 2); if (iscall) { foreach (string id in list) { pb.Call(TaskCommand.GiveupR, true, id); } } int total = Convert.ToInt32(strs[0]); int max = Convert.ToInt32(strs[1]); PlayerEx ex; Variant v = null; if (pb.Value.ContainsKey("DayTask")) { ex = pb.Value["DayTask"] as PlayerEx; v = ex.Value; //表示时间到,更新日常任务的当前值 if (v.GetLocalTimeOrDefault("NowData").Date != DateTime.Now.Date) { v["Cur"] = 0; v["Total"] = total;// v["Max"] = max;//最大日常任务数量 v["NowData"] = DateTime.UtcNow; } } else { ex = new PlayerEx(pb.ID, "DayTask"); v = new Variant(); v.Add("Cur", 0);//当前完成数量 v.Add("Total", total);//默认可以执行次数 v.Add("Max", max);//每天最多允许执行次数 v.Add("NowData", DateTime.UtcNow);//谋一天 ex.Value = v; ex.Save(); pb.Value.Add("DayTask", ex); } //更新一次,通知客户端 if (v != null && v.GetIntOrDefault("Cur") < v.GetIntOrDefault("Total")) { if (!TaskAccess.Instance.IsDayTask(pb.ID,2)) { //表示当天日常任务已经完成 GameConfig gc = GameConfigAccess.Instance.GetDayTaskOne(pb.Level, 2); if (gc != null) { Task t = TaskAccess.Instance.TaskBase(pb.ID, pb.RoleID, gc,0,0); if (t != null) { v["Cur"] = v.GetIntOrDefault("Cur") + 1; if (iscall) { pb.Call(TaskCommand.TaskActivationR, TaskAccess.Instance.GetTaskInfo(t)); } } } } else { v["Cur"] = v.GetIntOrDefault("Cur") == 0 ? 1 : v.GetIntOrDefault("Cur"); } } //如果成在变化测发送 ex.Save(); pb.Call(ClientCommand.UpdateActorR, new PlayerExDetail(ex)); }
/// <summary> /// 判断包袱是否装满 /// </summary> /// <param name="Content">包袱信息</param> /// <param name="goodsList">key为道具ID,Value为Variant,说明Number道具数量,IsBinding绑定状态:0非绑定1为绑定,StactCount道具堆叠数</param> /// <returns>true包袱空格子数不足</returns> public static bool IsFullBurden(PlayerEx burden, Dictionary<string, Variant> goodsList) { IList Content = burden.Value.GetValue<IList>("C"); return IsFullBurden(Content, goodsList); }
public PlayerExDetail(PlayerEx playerEx) { this.m_playerEx = playerEx; }
/// <summary> /// 移除指定时间的物品 /// </summary> /// <param name="burden"></param> /// <param name="goodsid">道具</param> /// <param name="endtime">结束时间</param> /// <param name="number">数量</param> /// <returns></returns> public static bool Remove(PlayerEx burden, string goodsid, DateTime endtime, int number) { IList c = burden.Value.GetValue<IList>("C"); int m = 0; foreach (Variant v in c) { if (v.GetStringOrDefault("G") == goodsid) { Variant t = v["T"] as Variant; if (t == null) continue; if (!t.ContainsKey("EndTime")) continue; if (t.GetDateTimeOrDefault("EndTime") != endtime) continue; int num = t.GetIntOrDefault("A"); if ((number - m) >= num) { BurdenClear(v); m += num; } else { t["A"] = num - (number - m); m = number; } if (m == number) break; } } burden.Save(); return true; }