Exemple #1
0
        ///  <summary>
        /// 验证是否出发地形效果
        ///  </summary>
        ///  <param name="fight"></param>
        ///  <param name="attackrole"></param>
        ///  <param name="rolevo"></param>
        /// <param name="role"></param>
        /// <returns></returns>
        private bool CheckArea(DefenseRoles role, WarFight fight, AttackRoles attackrole, WarFightRoleVo rolevo)
        {
            var type = (int)WarFightSkillType.Area;
            var area = fight.Area.FirstOrDefault(q => q.X == role.X && q.Y == role.Y);

            if (area == null)
            {
                return(false);
            }
            var effectstring = fight.Weather == (int)WeatherType.Rain ? area.raineffect : area.suneffect;

            if (effectstring == "")
            {
                return(false);
            }

            var effects = WarSkillEffect.GetEffectStringInit(effectstring, true);

            if (area.type == (int)AreaType.陷阱)
            {
                type = (int)WarFightSkillType.Trap;
            }
            DefenseRoleEffectsAdd(role, effects, attackrole, rolevo, type);
            fight.Area.Remove(area);
            return(true);
        }
Exemple #2
0
        /// <summary>
        /// 进攻武将攻打防守武将
        /// </summary>
        /// <param name="moves"></param>
        /// <param name="attackrole"></param>
        /// <param name="denfenserole"></param>
        /// <param name="fight"></param>
        private void AttackRolesFight(AttackRoles attackrole, WarMovesVo moves, DefenseRoles denfenserole, WarFight fight)
        {
            try
            {
                var condition = new List <int>();
                var rolevo    = AddNewRoleVo(attackrole, moves);
                //是否出发地形地形效果
                // var isArea = CheckArea(defrole, fight, attrole, rolevo);
                if (attackrole.isFirstAttack)
                {
                    condition.Add((int)WarFightCondition.FirstAttack);
                }
                condition.Add((int)WarFightCondition.Attack);
                CheckAttackRoleSkill(attackrole, condition, fight, denfenserole, rolevo, WarFightSkillType.Character);
                CheckAttackRoleSkill(attackrole, condition, fight, denfenserole, rolevo, WarFightSkillType.NinjaSkill);
                CheckAttackRoleSkill(attackrole, condition, fight, denfenserole, rolevo, WarFightSkillType.NinjaMystery);
                if (CheckAttackRoleSkill(attackrole, condition, fight, denfenserole, rolevo, WarFightSkillType.Skill)) //秘技释放以后气力值清零
                {
                    attackrole.qili = 0;
                }

                CheckAttackRoleSkill(attackrole, condition, fight, denfenserole, rolevo, WarFightSkillType.Katha);

                AttackRoleAttack(attackrole, denfenserole, rolevo);
                CheckDefenseRoleBlood(denfenserole, fight);
            }
            catch (Exception e)
            {
                XTrace.WriteLine("进攻武将技能出错{0}", e.Message);
                throw;
            }
        }
Exemple #3
0
        /// <summary>
        /// 防守武将增加buff
        /// </summary>
        /// <param name="role"></param>
        /// <param name="type"></param>
        /// <param name="value"></param>
        /// <param name="usertype"></param>
        /// <param name="times"></param>
        private void DefenseRoleAddNewBuff(DefenseRoles role, int type, int value, int usertype, int times)
        {
            var buff = new WarFightSkillBuff()
            {
                type     = type,
                value    = value,
                times    = times,
                usertype = usertype
            };
            var repeatbuff = new WarFightSkillBuff();

            //检测是否已经有该buff效果
            repeatbuff = buff.usertype == (int)WarFightSkillType.Area ?
                         role.buffs.FirstOrDefault(q => q.type == buff.type && q.usertype == buff.usertype) :
                         role.buffs.FirstOrDefault(q => q.type == buff.type);

            if (repeatbuff == null)
            {
                role.buffs.Add(buff);
            }
            else
            {
                if (repeatbuff.value > buff.value)
                {
                    return;
                }
                role.buffs.Remove(repeatbuff);
                role.buffs.Add(buff);
            }
        }
Exemple #4
0
        /// <summary>
        /// 防守武将进攻
        /// </summary>
        /// <param name="defrole"></param>
        /// <param name="attrole"></param>
        /// <param name="rolevo"></param>
        /// <returns></returns>
        private void DefenseRoleAttack(DefenseRoles defrole, AttackRoles attrole, WarFightRoleVo rolevo)
        {
            //  attrole.SoldierCount -= 10;//测试数据
            var type = GetHurt(defrole, attrole);

            WarFightRoleVoAddEffect(rolevo, attrole.RoleId, (int)EffectFaceTo.Rival,
                                    type, defrole.SoldierCount, attrole.SoldierCount, 0, 0, 0);
        }
Exemple #5
0
        /// <summary>
        /// 进攻武将进攻
        /// </summary>
        /// <param name="defrole"></param>
        /// <param name="attrole"></param>
        /// <param name="rolevo"></param>
        /// <returns></returns>
        private void AttackRoleAttack(AttackRoles attrole, DefenseRoles defrole, WarFightRoleVo rolevo)
        {
            // defrole.SoldierCount -= 10;//测试数据
            var type = GetHurt(attrole, defrole);

            //var type = (int)WarFightEffectType.普通攻击;
            WarFightRoleVoAddEffect(rolevo, defrole.RoleId, (int)EffectFaceTo.Rival, type, attrole.SoldierCount, defrole.SoldierCount, 0, 0, 0);
        }
Exemple #6
0
        /// <summary>
        /// 公式计算伤害
        /// </summary>
        /// <param name="defrole"></param>
        /// <param name="attackroles"></param>
        /// <returns></returns>
        private int GetHurt(DefenseRoles defrole, AttackRoles attackroles)
        {
            var attacktype = (int)WarFightEffectVoType.普通攻击;
            var dodge      = attackroles.dodge +
                             attackroles.buffs.Where(q => q.type == (int)WarFightEffectType.Dodge).Sum(q => q.value);
            var rolehits = defrole.hits +
                           defrole.buffs.Where(q => q.type == (int)WarFightEffectType.Hits).Sum(q => q.value);
            var hits   = Common.GetInstance().GetRule("32094", rolehits, dodge);
            var ishurt = new RandomSingle().IsTrue(hits);

            if (!ishurt)
            {
                return((int)WarFightEffectVoType.躲避);
            }
            // var basecap = Common.GetInstance().GetRule("32086", defrole.Role.base_captain);
            var equipattack    = Common.GetInstance().GetRule("32087", defrole.EquipAddAttack);
            var total_fo       = tg_role.GetSingleTotal(RoleAttributeType.ROLE_FORCE, defrole.Role);
            var roleattack     = Common.GetInstance().GetRule("32088", total_fo, defrole.Role.base_captain);
            var soldierattack  = Common.GetInstance().GetRule("32089", defrole.attack, defrole.morale, defrole.SoldierCount);
            var rivaldefense   = Common.GetInstance().GetRule("32090", attackroles.EquipAddDefense);
            var addhurt        = Common.GetInstance().GetRule("32091", defrole.Role.base_force);
            var redhurt        = Common.GetInstance().GetRule("32092", attackroles.Role.base_brains);
            var rangesplit     = defrole.hurtRange.Split("_");
            var hurtrange      = RNG.Next(Convert.ToInt32(rangesplit[0]), (Convert.ToInt32(rangesplit[1])));
            var skilladdattack = defrole.buffs.Where(q => q.type == (int)WarFightEffectType.AddAttack)
                                 .Sum(q => q.value);
            var skilladddefense =
                attackroles.buffs.Where(q => q.type == (int)WarFightEffectType.AddDefense).Sum(q => q.value);
            var list = new List <Double>()
            {
                equipattack,
                roleattack,
                soldierattack,
                rivaldefense,
                addhurt,
                redhurt,
                skilladdattack,
                skilladddefense,
                hurtrange,
            };
            var hurt = Common.GetInstance().GetRule("32093", list);
            var crit = defrole.crit +
                       defrole.buffs.Where(q => q.type == (int)WarFightEffectType.Hits).Sum(q => q.value);
            var iscrit = new RandomSingle().IsTrue(crit);

            if (iscrit)
            {
                attacktype = (int)WarFightEffectVoType.暴击;

                hurt = Common.GetInstance().GetRule("32095", hurt);
            }
            attackroles.SoldierCount -= (int)hurt;
            return(attacktype);
        }
Exemple #7
0
        /// <summary>
        /// 防守武将加入到回合中
        /// </summary>
        /// <param name="role">防守武将</param>
        /// <param name="moves">回合数据</param>
        /// <returns></returns>
        private WarFightRoleVo AddNewRoleVo(DefenseRoles role, WarMovesVo moves)
        {
            var vo = moves.roles.FirstOrDefault(q => q.roleId == role.RoleId);

            if (vo == null)
            {
                vo = EntityToRoleVo(role);
                moves.roles.Add(vo);
            }

            return(vo);
        }
Exemple #8
0
 /// <summary> 城门本丸初始</summary>
 private void GetDoorAndCityInit(int gateDurable, int baseDurable)
 {
     Door              = new DefenseRoles();
     City              = new DefenseRoles();
     Door.RoleId       = RNG.Next();
     City.RoleId       = RNG.Next();
     Door.SoldierCount = gateDurable;
     City.SoldierCount = baseDurable;
     Door.type         = (int)WarFightRoleType.城门;
     City.type         = (int)WarFightRoleType.本丸;
     City.X            = 0;
     City.Y            = 4;
 }
Exemple #9
0
 /// <summary>
 /// 获取回合开始时的士气和气力
 /// </summary>
 /// <param name="role"></param>
 private void GetDefenseRoleMoraleAndQili(DefenseRoles role)
 {
     role.morale -= 20;
     if (role.morale <= 0)
     {
         role.morale = 0;
     }
     role.qili += 10;
     if (role.qili > 100)
     {
         role.qili = 100;
     }
 }
Exemple #10
0
 /// <summary>
 /// 验证防守武将是否死亡
 /// </summary>
 /// <param name="role">防守武将实体</param>
 /// <param name="fight">战斗实体</param>
 /// <returns></returns>
 private bool CheckDefenseRoleBlood(DefenseRoles role, WarFight fight)
 {
     if (role.SoldierCount <= 0)
     {
         role.SoldierCount = 0;
         //lock (this)
         //{
         //    fight.DefenseRoles.Remove(role);
         //}
         fight.AttackSort.FirstOrDefault(q => q.RoleId == role.RoleId).isDie = true;
         //tg_war_role.UpdateRoleSoldierCount(0, role.RoleId);
     }
     return(false);
 }
Exemple #11
0
 /// <summary>
 /// 防守武将实体转换成vo
 /// </summary>
 /// <param name="role">防守武将</param>
 /// <returns></returns>
 private WarFightRoleVo EntityToRoleVo(DefenseRoles role)
 {
     return(new WarFightRoleVo()
     {
         blood = role.SoldierCount,
         roleId = role.RoleId,
         point = new PointVo()
         {
             x = role.X, y = role.Y
         },
         type = role.type,
         campType = 0,
         lines = null,
         effects = new List <WarEffectVo>(),
         energy = role.qili,
     });
 }
Exemple #12
0
        public WarFight(int baseid, IEnumerable <WarRolesLinesVo> attackrolRolesVos, List <tg_war_role> attackroles, Int32 frontid, int morale, int baselandid, string username)
        {
            #region 防守武将

            var    basecity = Variable.BASE_WARCITY.FirstOrDefault(q => q.id == baseid);
            Random rd       = new Random();
            var    zhenId   = rd.Next(0, Variable.BASE_WAR_FRONT.Count);
            var    baseLand = Variable.BASE_LAND_POOL.FirstOrDefault(m => m.id == baselandid);
            if (baseLand == null)
            {
                return;
            }
            DefenseFrontId = zhenId;
            Area           = GetMapArea(baseLand.landConfig);
            DefenseRoles   = GetNpcDefenseRoles(baseLand.ambushConfig, basecity.size, basecity.influence);

            DefenseSoldierCount = DefenseRoles.Sum(m => m.SoldierCount);
            if (!isInitSuccess)
            {
                isInitSuccess = false; return;
            }
            //初始武将防守范围
            DefenseRange = Common.GetInstance().GetDefenseRangeInit(DefenseRoles);

            var basesize = Variable.BASE_WARCITYSIZE.FirstOrDefault(q => q.id == basecity.size);
            if (basesize == null)
            {
                return;
            }
            GetDoorAndCityInit(basesize.blood, basesize.strong); //城门本丸初始

            #endregion

            #region 进攻数据初始

            AttackRolesInit(attackrolRolesVos, attackroles, morale, username);
            AttackFrontId = frontid;

            #endregion

            WeatherState = GetWeatherStateInit(); //初始天气持续回合

            FiveState = GetFiveStateInit();       //初始五常持续回合

            AttackSort = GetRolesSort();          //武将出手顺序初始
        }
Exemple #13
0
        /// <summary>
        /// 防守武将攻打进攻武将
        /// </summary>
        /// <param name="defrole"></param>
        /// <param name="moves"></param>
        /// <param name="attrole"></param>
        /// <param name="fight"></param>
        private bool DefenseRolesFight(DefenseRoles defrole, WarMovesVo moves, AttackRoles attrole, WarFight fight)
        {
            try
            {
                if (defrole.SoldierCount <= 0 || attrole.SoldierCount <= 0)
                {
                    return(false);
                }
                var condition = new List <int>();
                var rolevo    = AddNewRoleVo(defrole, moves);

                if (defrole.type == (int)WarFightRoleType.伏兵) //伏兵
                {
                    condition.Add((int)WarFightCondition.DarkRoleFirstAttack);
                    WarFightRoleVoAddEffect(rolevo, defrole.RoleId, (int)EffectFaceTo.Me,
                                            (int)WarFightEffectVoType.伏兵, attrole.SoldierCount, defrole.SoldierCount, 0, 0, 0);
                    defrole.isShow = true;
                }
                //是否出发地形地形效果
                var isArea = CheckArea(defrole, fight, attrole, rolevo);
                if (defrole.isFirstAttack)
                {
                    condition.Add((int)WarFightCondition.FirstAttack);
                }
                condition.Add((int)WarFightCondition.Attack);
                CheckSkill(defrole, condition, fight, attrole, rolevo, WarFightSkillType.Character);
                CheckSkill(defrole, condition, fight, attrole, rolevo, WarFightSkillType.NinjaSkill);
                CheckSkill(defrole, condition, fight, attrole, rolevo, WarFightSkillType.NinjaMystery);
                CheckSkill(defrole, condition, fight, attrole, rolevo, WarFightSkillType.Skill);
                CheckSkill(defrole, condition, fight, attrole, rolevo, WarFightSkillType.Katha);
                //最后进攻
                DefenseRoleAttack(defrole, attrole, rolevo);
                var isend = CheckAttackRoleBlood(attrole, fight);
                return(isend);
            }
            catch (Exception e)
            {
                XTrace.WriteLine(e.Message);
                return(false);
            }
        }
Exemple #14
0
        /// <summary>
        /// 检测防守武将,武将特性是否触发
        /// </summary>
        /// <returns></returns>
        private bool CheckSkill(DefenseRoles role, List <int> nowcondition, WarFight fight, AttackRoles attackrole, WarFightRoleVo rolevo, WarFightSkillType type)
        {
            var skills = role.skills.Where(q => q.type == type).ToList();

            foreach (var skill in skills)
            {
                var ismatch = CheckDefenseRoleCondition(role, nowcondition, fight, attackrole, skill.Condition);
                if (!ismatch)
                {
                    continue;
                }
                if (type == WarFightSkillType.Katha && role.buffs.Any(q => q.type == (int)WarFightEffectType.StartKatha) &&
                    attackrole.buffs.All(q => q.type != (int)WarFightEffectType.StopKatha))  //是否立即释放奥义
                {
                    DefenseRoleEffectsAdd(role, skill.FightSkillEffects, attackrole, rolevo, (int)type);
                }

                DefenseRoleEffectsAdd(role, skill.FightSkillEffects, attackrole, rolevo, (int)type);
                return(true);
            }
            return(false);
        }
Exemple #15
0
        public WarFight(int planId, BaseWarCopy temp, IEnumerable <WarRolesLinesVo> attackrolRolesVos, List <tg_war_role> attackroles, Int32 frontid, int morale, string username)
        {
            #region 防守武将


            var zhenId   = GetRandomNumber(temp.zhenId).First();
            var baseLand = Variable.BASE_LAND_POOL.FirstOrDefault(m => m.id == planId);
            if (baseLand == null)
            {
                return;
            }
            DefenseFrontId = zhenId;
            Area           = GetMapArea(baseLand.landConfig);
            DefenseRoles   = GetNpcDefenseRoles(baseLand.ambushConfig, temp.id);

            DefenseSoldierCount = DefenseRoles.Sum(m => m.SoldierCount);
            if (!isInitSuccess)
            {
                isInitSuccess = false; return;
            }
            //初始武将防守范围
            DefenseRange = Common.GetInstance().GetDefenseRangeInit(DefenseRoles);
            GetDoorAndCityInit(temp.gateDurable, temp.baseDurable); //城门本丸初始

            #endregion

            #region 进攻数据初始

            AttackRolesInit(attackrolRolesVos, attackroles, morale, username);
            AttackFrontId = frontid;

            #endregion

            WeatherState = GetWeatherStateInit(); //初始天气持续回合

            FiveState = GetFiveStateInit();       //初始五常持续回合

            AttackSort = GetRolesSort();          //武将出手顺序初始
        }
Exemple #16
0
        /// <summary>
        /// 进攻武将技能触发
        /// </summary>
        /// <param name="attackrole">进攻武将</param>
        /// <param name="effects">技能实体</param>
        /// <param name="defenserole">防守武将</param>
        /// <param name="rolevo">武将vo</param>
        /// <param name="skilltype"></param>
        private void AttackRoleEffectsAdd(AttackRoles attackrole, List <WarSkillEffect> effects, DefenseRoles defenserole, WarFightRoleVo rolevo, int skilltype)
        {
            //WarFightRoleVoAddEffect(rolevo, attackrole.RoleId, 0, SkillTypeToEffectType(skilltype), attackrole.SoldierCount, defenserole.SoldierCount,
            //    effects[0].id, 0, 0);   //vo增加效果
            foreach (var effect in effects)
            {
                if (effect.Probability > 0 && !new RandomSingle().IsTrue(effect.Probability))
                {
                    continue;          //效果触发概率
                }
                if (effect.times == 0) //永久增加
                {
                    #region 永久效果

                    switch (effect.effectType)
                    {
                        #region 增加攻击力

                    case (int)WarFightEffectType.AddAttack:
                    {
                        if (effect.target == (int)EffectFaceTo.Me)
                        {
                            attackrole.attack += effect.effectValue;
                        }
                        else
                        {
                            defenserole.attack += effect.effectValue;
                        }
                        break;
                    }

                        #endregion

                        #region 增加防御力

                    case (int)WarFightEffectType.AddDefense:
                    {
                        if (effect.target == (int)EffectFaceTo.Me)
                        {
                            attackrole.defense += effect.effectValue;
                        }
                        else
                        {
                            defenserole.defense += effect.effectValue;
                        }
                        break;
                    }

                        #endregion

                        #region 增加命中

                    case (int)WarFightEffectType.Hits:
                    {
                        if (effect.target == (int)EffectFaceTo.Me)
                        {
                            attackrole.hits += effect.effectValue;
                        }
                        else
                        {
                            defenserole.hits += effect.effectValue;
                        }
                        break;
                    }

                        #endregion

                        #region 增加气力

                    case (int)WarFightEffectType.QiLi:
                    {
                        if (effect.target == (int)EffectFaceTo.Me)
                        {
                            attackrole.qili += effect.effectValue;
                        }
                        else
                        {
                            defenserole.qili += effect.effectValue;
                        }
                        break;
                    }

                        #endregion

                        #region 增加兵力

                    case (int)WarFightEffectType.SoldierCount:
                    {
                        if (effect.target == (int)EffectFaceTo.Me)
                        {
                            attackrole.SoldierCount += effect.effectValue;
                            if (attackrole.SoldierCount > attackrole.bloodMax)
                            {
                                attackrole.SoldierCount = attackrole.bloodMax;
                            }
                        }
                        else
                        {
                            if (attackrole.SoldierCount > attackrole.bloodMax)
                            {
                                attackrole.SoldierCount = attackrole.bloodMax;
                            }
                            if (effect.times > 1)
                            {
                                DefenseRoleAddNewBuff(defenserole, effect.effectType, effect.effectValue, skilltype,
                                                      effect.times);
                            }
                        }
                        break;
                    }

                        #endregion

                        #region 增加先手值

                    case (int)WarFightEffectType.FirstAttack:
                    {
                        if (effect.target == (int)EffectFaceTo.Me)
                        {
                            attackrole.AttackSort += effect.effectValue;
                        }
                        else
                        {
                            defenserole.AttackSort += effect.effectValue;
                        }
                        break;
                    }

                        #endregion

                        #region 增加暴击率

                    case (int)WarFightEffectType.BaoJi:
                    {
                        if (effect.target == (int)EffectFaceTo.Me)
                        {
                            attackrole.crit += effect.effectValue;
                        }
                        else
                        {
                            defenserole.crit += effect.effectValue;
                        }
                        break;
                    }

                        #endregion

                        #region 增加躲避率

                    case (int)WarFightEffectType.Dodge:
                    {
                        if (effect.target == (int)EffectFaceTo.Me)
                        {
                            attackrole.dodge += effect.effectValue;
                        }
                        else
                        {
                            defenserole.dodge += effect.effectValue;
                        }
                        break;
                    }

                        #endregion

                        #region 增加士气

                    case (int)WarFightEffectType.ShiQi:
                    {
                        if (effect.target == (int)EffectFaceTo.Me)
                        {
                            attackrole.morale += effect.effectValue;
                        }
                        else
                        {
                            defenserole.morale += effect.effectValue;
                        }
                        break;
                    }

                        #endregion
                    }

                    #endregion

                    WarFightRoleVoAddEffect(rolevo, attackrole.RoleId, effect.target, SkillTypeToEffectType(skilltype),
                                            attackrole.SoldierCount, defenserole.SoldierCount, 0, effect.effectType, effect.effectValue); //vo增加效果
                    continue;
                }
                if (effect.target == (int)EffectFaceTo.Me)
                {
                    AttackRoleAddNewBuff(attackrole, effect.effectType, effect.effectValue, skilltype, effect.times); //实体增加效果数值数据

                    WarFightRoleVoAddEffect(rolevo, attackrole.RoleId, effect.target, SkillTypeToEffectType(skilltype),
                                            attackrole.SoldierCount, defenserole.SoldierCount, 0, effect.effectType, effect.effectValue); //vo增加效果

                    if (effect.times > 1)                                                                                                 //持续超过1回合
                    //添加buff
                    {
                        WarFightRoleVoAddBuff(rolevo, attackrole.RoleId, effect.effectType, effect.effectValue);
                    }
                }
                else
                {
                    DefenseRoleAddNewBuff(defenserole, effect.effectType, effect.effectValue, skilltype, effect.times);                   //实体添加buff
                    WarFightRoleVoAddEffect(rolevo, defenserole.RoleId, effect.target, SkillTypeToEffectType(skilltype),
                                            attackrole.SoldierCount, defenserole.SoldierCount, 0, effect.effectType, effect.effectValue); //vo增加效果
                    if (effect.times > 1)                                                                                                 //
                    //添加buff
                    {
                        WarFightRoleVoAddBuff(rolevo, defenserole.RoleId, effect.effectType, effect.effectValue);
                    }
                }
            }
        }
Exemple #17
0
        /// <summary>
        /// 验证进攻武将进攻范围是否有防守武将
        /// </summary>
        /// <param name="defenseroles">防守武将集合</param>
        /// <param name="attroles">进攻武将集合</param>
        /// <param name="door">城门</param>
        /// <param name="home">本丸</param>
        /// <returns></returns>
        private DefenseRoles CheckIsDefenseRole(List <DefenseRoles> defenseroles, AttackRoles attroles, DefenseRoles door, DefenseRoles home)
        {
            var getdefense = new List <DefenseRoles>();

#if DEBUG
            XTrace.WriteLine("进攻武将坐标({0},{1})", attroles.X, attroles.Y);
            for (int j = 0; j < attroles.AttackRange.Count; j++)
            {
                XTrace.WriteLine("进攻武将攻击范围({0},{1})", attroles.AttackRange[j].X, attroles.AttackRange[j].Y);
            }
#endif
            foreach (var defenserole in defenseroles)
            {
                if (defenserole.SoldierCount <= 0 || defenserole.isShow == false)
                {
                    continue;
                }
#if DEBUG
                XTrace.WriteLine("防守武将{0}的坐标({1},{2}),", defenserole.roleName, defenserole.X, defenserole.Y);
#endif
                if (attroles.AttackRange.Any(q => q.X == defenserole.X && q.Y == defenserole.Y))
                {
                    getdefense.Add(defenserole);
                }
            }

            if (!getdefense.Any())     //攻击范围内没有防守武将
            {
                //验证是否攻打城门
                if (door.SoldierCount > 0)
                {
                    if (attroles.AttackRange.Any(q => q.X == 2 && q.Y > 1 && q.Y < 7))
                    {
                        attroles.isFightDoor = true;
                        return(door);
                    }
                }

                //验证是否攻打本丸
                if (attroles.AttackRange.Any(q => q.X == home.X && q.Y == home.Y))
                {
                    attroles.isFightCity = true;
                    return(home);
                }

                return(null);
            }
            ;
#if DEBUG
            XTrace.WriteLine("进攻武将{0}攻击范围内有防守武将{1}", attroles.roleName, getdefense.OrderBy(q => q.SoldierCount).FirstOrDefault().roleName);
#endif
            //寻找防守武将中血量最少的
            return(getdefense.OrderBy(q => q.SoldierCount).FirstOrDefault());
        }
Exemple #18
0
        /// <summary> 获取NPC防守武将集合 </summary>
        /// <param name="str">伏兵配置</param>
        /// <param name="size">据点规模</param>
        /// <param name="influence">势力</param>
        /// <returns></returns>
        private static List <DefenseRoles> GetNpcDefenseRoles(string str, int size, int influence)
        {
            var list = new List <DefenseRoles>();

            selectedIds = new List <int>();
            foreach (var item in str.Split('|'))
            {
                var id     = 0;
                var flag   = true;
                int number = 0;
                var array  = item.Split('_');
                if (array.Length != 3)
                {
                    continue;
                }
                var type = array[0];                  //伏兵类型:1=远程,2=近战
                var x    = Convert.ToInt32(array[1]); //坐标X
                var y    = Convert.ToInt32(array[2]); //坐标Y

                var roleid = GetRoleId(type, size, influence);
                while (flag)
                {
                    if (selectedIds.Contains(roleid))
                    {
                        id = GetRoleId(type, size, influence);;
                    }
                    else
                    {
                        selectedIds.Add(id);
                        flag = false;
                    }
                    if (number > 5)
                    {
                        flag = false;
                        id   = -100;
                    }
                    number++;
                }
                if (roleid == -100)
                {
                    continue;
                }

                var baseWarMonster = Variable.BASE_WAR_MONSTER.FirstOrDefault(m => m.id == roleid);
                if (baseWarMonster == null)
                {
                    continue;
                }
                var baseArmyType = GetBaseWarArmySoldier(type);
                if (baseArmyType == null)
                {
                    continue;
                }
                var featuresId  = GetRandomNumber(baseWarMonster.featuresId).First();
                var ninjaId     = GetRandomNumber(baseWarMonster.ninjaId).First();
                var cheatcodeId = GetRandomNumber(baseWarMonster.cheatcodeId).First();
                var mysteryId   = GetRandomNumber(baseWarMonster.mysteryId).First();
                var skills      = new List <WarFightSkill>
                {
                    BuildSkill(featuresId),
                    BuildSkill(mysteryId, baseWarMonster.mysteryLevel),
                    BuildNinjaSkill(ninjaId, baseWarMonster.ninjaLevel),
                    BuildSkill(cheatcodeId, baseWarMonster.cheatcodeLevel),
                };
                var role = new DefenseRoles()
                {
                    skills          = skills,
                    RoleId          = RNG.Next(),
                    hits            = baseArmyType.hits,
                    crit            = baseArmyType.crit,
                    dodge           = baseArmyType.dodge,
                    SoldierId       = baseArmyType.id,
                    morale          = baseWarMonster.morale,
                    attack          = baseArmyType.baseAttack,
                    type            = (int)WarFightRoleType.伏兵,
                    defense         = baseArmyType.baseDefence,
                    bloodMax        = baseWarMonster.forceValue,
                    SoldierCount    = baseWarMonster.forceValue,
                    EquipAddAttack  = baseWarMonster.equipAttack,
                    EquipAddDefense = baseWarMonster.equipDefense,
                    WarRole         = new tg_war_role
                    {
                        army_morale  = baseWarMonster.morale,
                        army_soldier = baseWarMonster.forceValue,
                    },
                    Role = new tg_role
                    {
                        role_id      = baseWarMonster.roleId,
                        base_force   = baseWarMonster.force,
                        base_brains  = baseWarMonster.brains,
                        base_captain = baseWarMonster.captain,
                    },
                    isNpc     = 1,
                    X         = x,
                    Y         = y,
                    hurtRange = baseArmyType.hurtRange,
                    roleName  = baseWarMonster.name,
                };
                list.Add(role);
            }
            return(list);
        }
Exemple #19
0
        /// <summary>
        /// 防守武将技能释放条件验证
        /// </summary>
        /// <param name="role">防守武将</param>
        /// <param name="nowcondition"></param>
        /// <param name="fight"></param>
        /// <param name="attrole"></param>
        /// <param name="conditions"></param>
        /// <returns></returns>
        private bool CheckDefenseRoleCondition(DefenseRoles role, List <int> nowcondition, WarFight fight, AttackRoles attrole, List <string> conditions)
        {
            var ismatch = true;

            foreach (var item in conditions)
            {
                var condition = Convert.ToInt32(item);
                #region 技能条件验证
                switch (condition)
                {
                case (int)WarFightCondition.Attack: if (nowcondition.Contains(condition))
                    {
                        ismatch = false;
                    }
                    break;

                case (int)WarFightCondition.Rain: { if (fight.Weather != condition)
                                                    {
                                                        ismatch = false;
                                                    }
                } break;

                case (int)WarFightCondition.Attacked: { if (nowcondition.Contains(condition))
                                                        {
                                                            ismatch = false;
                                                        }
                } break;

                case (int)WarFightCondition.FirstAttack: { if (nowcondition.Contains(condition))
                                                           {
                                                               ismatch = false;
                                                           }
                } break;

                case (int)WarFightCondition.DarkRoleFirstAttack: { if (nowcondition.Contains(condition))
                                                                   {
                                                                       ismatch = false;
                                                                   }
                } break;

                case (int)WarFightCondition.FiveSame: { if (fight.FiveSharp != condition)
                                                        {
                                                            ismatch = false;
                                                        }
                } break;

                case (int)WarFightCondition.SkillAttack: { if (nowcondition.Contains(condition))
                                                           {
                                                               ismatch = false;
                                                           }
                } break;

                // case (int)WarFightCondition.BloodLess: { if (role.SoldierCount > skill.effectBaseInfo.)ismatch = false; } break;
                case (int)WarFightCondition.CharmLessMe: { if (role.Role.base_charm < attrole.Role.base_charm)
                                                           {
                                                               ismatch = false;
                                                           }
                } break;

                case (int)WarFightCondition.ForceLessMe: { if (role.Role.base_force < attrole.Role.base_force)
                                                           {
                                                               ismatch = false;
                                                           }
                } break;

                case (int)WarFightCondition.BrainLessMe: { if (role.Role.base_brains < attrole.Role.base_brains)
                                                           {
                                                               ismatch = false;
                                                           }
                } break;

                case (int)WarFightCondition.AreaSlope:
                {
                    if (!fight.Area.Any(q => q.type == (int)AreaType.高坡 && q.X == role.X && role.Y == q.Y))
                    {
                        ismatch = false;
                    }
                } break;

                case (int)WarFightCondition.AreaRiver:
                {
                    if (!fight.Area.Any(q => q.type == (int)AreaType.河滩 && q.X == role.X && role.Y == q.Y))
                    {
                        ismatch = false;
                    }
                } break;

                case (int)WarFightCondition.AreaSwamp:
                {
                    if (!fight.Area.Any(q => q.type == (int)AreaType.沼泽 && q.X == role.X && role.Y == q.Y))
                    {
                        ismatch = false;
                    }
                } break;

                case (int)WarFightCondition.AreaForest:
                {
                    if (!fight.Area.Any(q => q.type == (int)AreaType.密林 && q.X == role.X && role.Y == q.Y))
                    {
                        ismatch = false;
                    }
                } break;

                case (int)WarFightCondition.FancyAttack:
                {
                    if (nowcondition.Contains(condition))
                    {
                        ismatch = false;
                    }
                } break;
                }
                #endregion
            }
            return(ismatch);
        }
Exemple #20
0
        /// <summary>
        /// 防守武将技能触发
        /// </summary>
        /// <param name="role">防守武将</param>
        /// <param name="effects">技能实体</param>
        /// <param name="attackrole">进攻武将</param>
        /// <param name="rolevo">武将vo</param>
        /// <param name="skilltype"></param>
        private void DefenseRoleEffectsAdd(DefenseRoles role, List <WarSkillEffect> effects, AttackRoles attackrole, WarFightRoleVo rolevo, int skilltype)
        {
            foreach (var effect in effects)
            {
                if (effect.Probability > 0 && !new RandomSingle().IsTrue(effect.Probability))
                {
                    continue;                                                                           //效果触发概率
                }
                if (effect.effectSoldier != "0")
                {
                    if (effect.effectSoldier != role.SoldierId.ToString())
                    {
                        return;                                                    //地形效果兵种
                    }
                }
                var target = effect.target;
                switch (effect.effectType)
                {
                    #region 增加攻击力
                case (int)WarFightEffectType.AddAttack:
                {
                    if (effect.target == (int)EffectFaceTo.Me)
                    {
                        if (effect.times > 1)
                        {
                            DefenseRoleAddNewBuff(role, effect.effectType, effect.effectValue, skilltype, effect.times);
                        }
                    }
                    else
                    {
                        if (effect.times > 1)
                        {
                            AttackRoleAddNewBuff(attackrole, effect.effectType, effect.effectValue, skilltype, effect.times);
                        }
                    }
                    break;
                }
                    #endregion

                    #region 增加防御力
                case (int)WarFightEffectType.AddDefense:
                {
                    if (effect.target == (int)EffectFaceTo.Me)
                    {
                        if (effect.times > 1)
                        {
                            DefenseRoleAddNewBuff(role, effect.effectType, effect.effectValue, skilltype, effect.times);
                        }
                    }
                    else
                    {
                        if (effect.times > 1)
                        {
                            AttackRoleAddNewBuff(attackrole, effect.effectType, effect.effectValue, skilltype, effect.times);
                        }
                    }
                    break;
                }
                    #endregion

                    #region 增加命中
                case (int)WarFightEffectType.Hits:
                {
                    if (effect.target == (int)EffectFaceTo.Me)
                    {
                        if (effect.times > 1)
                        {
                            DefenseRoleAddNewBuff(role, effect.effectType, effect.effectValue, skilltype, effect.times);
                        }
                    }
                    else
                    {
                        if (effect.times > 1)
                        {
                            AttackRoleAddNewBuff(attackrole, effect.effectType, effect.effectValue, skilltype, effect.times);
                        }
                    }
                    break;
                }
                    #endregion

                    #region 增加气力
                case (int)WarFightEffectType.QiLi:
                {
                    if (effect.target == (int)EffectFaceTo.Me)
                    {
                        if (effect.times > 1)
                        {
                            DefenseRoleAddNewBuff(role, effect.effectType, effect.effectValue, skilltype, effect.times);
                        }
                    }
                    else
                    {
                        if (effect.times > 1)
                        {
                            AttackRoleAddNewBuff(attackrole, effect.effectType, effect.effectValue, skilltype, effect.times);
                        }
                    }
                    break;
                }
                    #endregion

                    #region 增加兵力
                case (int)WarFightEffectType.SoldierCount:
                {
                    if (effect.target == (int)EffectFaceTo.Me)
                    {
                        role.SoldierCount += effect.effectValue;
                        if (role.SoldierCount > role.bloodMax)
                        {
                            role.SoldierCount = role.bloodMax;
                        }
                        if (effect.times > 1)
                        {
                            DefenseRoleAddNewBuff(role, effect.effectType, effect.effectValue, skilltype, effect.times);
                        }
                    }
                    else
                    {
                        if (attackrole.SoldierCount > role.bloodMax)
                        {
                            attackrole.SoldierCount = attackrole.bloodMax;
                        }
                        if (effect.times > 1)
                        {
                            AttackRoleAddNewBuff(attackrole, effect.effectType, effect.effectValue, skilltype, effect.times);
                        }
                    }
                    break;
                }
                    #endregion

                    #region 增加先手值
                case (int)WarFightEffectType.FirstAttack:
                {
                    if (effect.target == (int)EffectFaceTo.Me)
                    {
                        if (effect.times > 1)
                        {
                            DefenseRoleAddNewBuff(role, effect.effectType, effect.effectValue, skilltype, effect.times);
                        }
                    }
                    else
                    {
                        if (effect.times > 1)
                        {
                            AttackRoleAddNewBuff(attackrole, effect.effectType, effect.effectValue, skilltype, effect.times);
                        }
                    }
                    break;
                }
                    #endregion

                    #region 增加暴击率
                case (int)WarFightEffectType.BaoJi:
                {
                    if (effect.target == (int)EffectFaceTo.Me)
                    {
                        if (effect.times > 1)
                        {
                            DefenseRoleAddNewBuff(role, effect.effectType, effect.effectValue, skilltype, effect.times);
                        }
                    }
                    else
                    {
                        if (effect.times > 1)
                        {
                            AttackRoleAddNewBuff(attackrole, effect.effectType, effect.effectValue, skilltype, effect.times);
                        }
                    }
                    break;
                }
                    #endregion

                    #region 增加躲避率
                case (int)WarFightEffectType.Dodge:
                {
                    if (effect.target == (int)EffectFaceTo.Me)
                    {
                        if (effect.times > 1)
                        {
                            DefenseRoleAddNewBuff(role, effect.effectType, effect.effectValue, skilltype, effect.times);
                        }
                    }
                    else
                    {
                        if (effect.times > 1)
                        {
                            AttackRoleAddNewBuff(attackrole, effect.effectType, effect.effectValue, skilltype, effect.times);
                        }
                    }
                    break;
                }
                    #endregion

                    #region 增加士气
                case (int)WarFightEffectType.ShiQi:
                {
                    if (effect.target == (int)EffectFaceTo.Me)
                    {
                        if (effect.times > 1)
                        {
                            DefenseRoleAddNewBuff(role, effect.effectType, effect.effectValue, skilltype, effect.times);
                        }
                    }
                    else
                    {
                        if (effect.times > 1)
                        {
                            AttackRoleAddNewBuff(attackrole, effect.effectType, effect.effectValue, skilltype, effect.times);
                        }
                    }
                    break;
                }
                    #endregion

                    #region 免疫僧兵兵种特性
                case (int)WarFightEffectType.CanceCheatroles:
                {
                    if (effect.target == (int)EffectFaceTo.Me)
                    {
                        DefenseRoleAddNewBuff(role, effect.effectType, effect.effectValue, skilltype, effect.times);
                    }
                    else
                    {
                        if (effect.times > 1)
                        {
                            AttackRoleAddNewBuff(attackrole, effect.effectType, effect.effectValue, skilltype, effect.times);
                        }
                    }
                    break;
                }
                    #endregion

                    #region 停止释放奥义
                case (int)WarFightEffectType.StopKatha:
                {
                    AttackRoleAddNewBuff(attackrole, effect.effectType, effect.effectValue, skilltype, effect.times);
                    break;
                }
                    #endregion

                    #region 立即释放奥义
                case (int)WarFightEffectType.StartKatha:
                {
                    DefenseRoleAddNewBuff(role, effect.effectType, effect.effectValue, skilltype, effect.times);

                    break;
                }
                    #endregion
                }
                if (skilltype != (int)WarFightSkillType.Area)
                {
                    //vo添加状态
                    if (effect.target == (int)EffectFaceTo.Me) //对自己
                    {
                        if (effect.times == 1)
                        {
                            WarFightRoleVoAddEffect(rolevo, role.RoleId, target,
                                                    SkillTypeToEffectType(skilltype), role.SoldierCount, attackrole.SoldierCount, effect.id, effect.effectType, effect.effectValue);
                        }
                        else
                        {
                            //添加buff
                            WarFightRoleVoAddBuff(rolevo, role.RoleId, effect.effectType, effect.effectValue);
                        }
                    }
                }
            }
        }