Пример #1
0
        /// <summary>
        /// 战斗计算
        /// </summary>
        private static void Fight(ArenaBase model)
        {
            ArenaScene scene = model.SceneSession;

            ConcurrentDictionary<string, Pet> doc = model.Pets;
            foreach (Pet p in doc.Values)
            {
                Variant root = p.Value;
                Variant rsm = root.GetValueOrDefault<Variant>("ShengMing");
                //不能再攻击别人
                if (rsm.GetIntOrDefault("V") <= 0)
                {
                    p.CoolingTime = 0;
                    continue;
                }

                if (p.CoolingTime > 0)
                {
                    p.CoolingTime -= 500;
                    if (p.CoolingTime > 0)
                        continue;
                }

                Variant rmf = root.GetValueOrDefault<Variant>("MoFa");

                FightBase fightBase = new FightBase(model);
                fightBase.ID = p.ID;
                fightBase.Name = p.Name;
                fightBase.PlayerID = p.PlayerID;
                fightBase.Persons = 1;

                int CoolingTime = 0;

                if (!string.IsNullOrEmpty(p.CurSkill))
                {
                    GameConfig gc = GameConfigAccess.Instance.FindOneById(p.CurSkill);
                    if (gc != null)
                    {
                        //得到技能基本信息
                        ArenaSkill askill = new ArenaSkill(gc);
                        askill.BaseLevel(p.CurLevel);
                        if (rmf.GetIntOrDefault("V") >= askill.MPCost)
                        {
                            fightBase.Persons += askill.AddTargets;
                            //攻击方魔法消耗值
                            fightBase.MPCost = askill.MPCost;
                            fightBase.InjuryType = askill.InjuryType;
                            fightBase.A = askill.A;
                            fightBase.B = askill.B;
                            fightBase.CurSkill = p.CurSkill;
                            CoolingTime = askill.CoolingTime;

                            p.Range = askill.Range;//技能攻击范围
                        }
                        else
                        {
                            p.Range = 100;
                        }
                    }
                    else
                    {
                        p.Range = 100;
                    }
                }
                else
                {
                    p.Range = 100;
                }

                List<PetFightDetail> list = new List<PetFightDetail>();

                bool isRangetPet = false;
                if (!string.IsNullOrEmpty(p.RangePet))
                {
                    //主动攻击的宠物
                    Pet pt;
                    if (doc.TryGetValue(p.RangePet, out pt))
                    {
                        if (ChechFight(p, pt))
                        {
                            //主要攻击目标
                            fightBase.RangePet = pt.ID;
                            isRangetPet = true;
                            list.Add(fightBase.FightObject(p, pt));
                        }
                    }
                }

                //循环所有宠物,寻找可攻击的目标
                if (fightBase.Persons > list.Count)
                {
                    foreach (Pet pet in doc.Values)
                    {
                        if (ChechFight(p, pet))
                        {
                            if (!isRangetPet)
                            {
                                //主要攻击目标
                                fightBase.RangePet = pet.ID;
                            }
                            else
                            {
                                //主要攻击目标已经被攻击
                                if (pet.ID == fightBase.RangePet)
                                    continue;
                            }
                            list.Add(fightBase.FightObject(p, pet));
                            //攻击对象已经满,不需要再找
                            if (list.Count == fightBase.Persons)
                                break;
                        }
                    }
                }

                if (list.Count > 0)
                {
                    if (CoolingTime <= 0)
                    {
                        //攻击成功添加冷却时间
                        CoolingTime = 3000;
                    }
                    p.CoolingTime = CoolingTime;
                    //当前
                    rmf["V"] = rmf.GetIntOrDefault("V") - fightBase.MPCost;
                    fightBase.MoFa = rmf;
                    fightBase.ShengMing = rsm;

                    PetFightDetail gongji = new PetFightDetail(fightBase);
                    model.CallAll(ArenaCommand.ArenaFightR, gongji, list);
                }
            }
        }
Пример #2
0
        /// <summary>
        /// 补充宠物的HP/MP
        /// </summary>
        /// <param name="v"></param>
        /// <returns></returns>
        private static bool SupplyPet(Variant v, Pet m_pet, ArenaBase model, string name)
        {
            bool use = false;
            //庞物
            if (m_pet == null) return use;
            Variant pet = m_pet.Value;
            if (pet == null) return use;

            Variant moFa = pet.GetVariantOrDefault("MoFa");
            Variant shengMing = pet.GetVariantOrDefault("ShengMing");

            double dhp = v.GetDoubleOrDefault("HP");
            double dmp = v.GetDoubleOrDefault("MP");
            int hp, mp;
            if (dhp <= 1)
            {
                hp = (int)(dhp * shengMing.GetIntOrDefault("M")); //百分比方式
            }
            else
            {
                hp = (int)(dhp);
            }
            if (dmp <= 1)
            {
                mp = (int)(dmp * moFa.GetIntOrDefault("M")); //百分比方式
            }
            else
            {
                mp = (int)(dmp);
            }

            if (hp > 0)
            {
                int sv = shengMing.GetIntOrDefault("V");
                int need = shengMing.GetIntOrDefault("M") - sv;
                if (need > 0)
                {
                    m_pet.HP = Math.Min(need, hp) + sv;
                    shengMing["V"] = m_pet.HP;
                    use = true;
                }
            }

            if (mp > 0)
            {
                int mv = moFa.GetIntOrDefault("V");
                int need = moFa.GetIntOrDefault("M") - mv;
                if (need > 0)
                {
                    m_pet.MP = Math.Min(need, mp) + mv;
                    moFa["V"] = m_pet.MP;
                    use = true;
                }
            }

            if (hp > 0 || mp > 0)
            {
                List<PetDetail> list = new List<PetDetail>();
                PetDetail detail = new PetDetail(m_pet, name);
                list.Add(detail);
                model.CallAll(ArenaCommand.ArenaGoodsR, true, list);
                m_pet.Save();
            }
            return use;
        }
Пример #3
0
        /// <summary>
        /// 检查竞技场是否可以开始
        /// </summary>
        /// <param name="model">竞技场</param>
        /// <returns></returns>
        private static void CheckArenaStart(ArenaBase model)
        {
            Dictionary<string, int> dic = new Dictionary<string, int>();
            foreach (Pet p in model.Pets.Values)
            {
                if (!dic.ContainsKey(p.GroupName))
                {
                    dic.Add(p.GroupName, 1);
                }
                else
                {
                    dic[p.GroupName]++;
                }

                PlayerBusiness user;
                if (model.Players.TryGetValue(p.PlayerID, out user))
                {
                    Settle settle;
                    if (!model.SettleInfo.TryGetValue(p.PlayerID, out settle))
                    {
                        settle = new Settle();
                        settle.PlayerID = p.PlayerID;
                        settle.GroupName = p.GroupName;
                        settle.PlayerName = user.Name;
                        settle.ResultType = 0;
                        model.SettleInfo.TryAdd(p.PlayerID, settle);
                    }
                }
            }

            if (dic.Count <= 1)
            {
                //竞技场不满足开始条件
                model.CallAll(ArenaCommand.ArenaStartR, false,TipManager.GetMessage(ArenaReturn.CheckArenaStart1));
                ArenaBase tmp;
                if (ArenaBusiness.ArenaList.TryRemove(model.SoleID, out tmp))
                {
                    PlayerOut(tmp);
                }
                return;
            }

            model.Status = 1;
            //竞技场开始
            model.CallAll(ArenaCommand.ArenaStartR, true, TipManager.GetMessage(ArenaReturn.CheckArenaStart2));
        }