Ejemplo n.º 1
0
        /// <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();
                }
            }
        }
Ejemplo n.º 2
0
        /// <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));
        }
Ejemplo n.º 3
0
        /// <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);
        }
Ejemplo n.º 4
0
        /// <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;
        }
Ejemplo n.º 5
0
        /// <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;
        }
Ejemplo n.º 6
0
        /// <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;
        }
Ejemplo n.º 7
0
 /// <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();
 }
Ejemplo n.º 8
0
 /// <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;
 }
Ejemplo n.º 9
0
        /// <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>();
            }
        }
Ejemplo n.º 10
0
        /// <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;
        }
Ejemplo n.º 11
0
 /// <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;
 }
Ejemplo n.º 12
0
 /// <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();
     }
 }
Ejemplo n.º 13
0
        /// <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);
        }