/// <summary>先后手 阵和武将 记录到全局属性中</summary> /// <param name="matrix">先手方阵</param> /// <param name="_matrix">后手方阵</param> private void GlobalMatrix(FightPersonal matrix, FightPersonal _matrix) { attack_matrix = matrix; defense_matrix = _matrix; GlobalRole(attack_matrix, true); GlobalRole(defense_matrix, false); }
/// <summary> 获取阵中武将Id </summary> /// <param name="personal">要获取的阵</param> /// <returns>阵中武将Id集合</returns> private List <Int64> GetMatrixRids(FightPersonal personal) { var ids = new List <Int64>(); if (personal.matrix1_rid != 0) //阵中的所有武将 { ids.Add(personal.matrix1_rid); } if (personal.matrix2_rid != 0) { ids.Add(personal.matrix2_rid); } if (personal.matrix3_rid != 0) { ids.Add(personal.matrix3_rid); } if (personal.matrix4_rid != 0) { ids.Add(personal.matrix4_rid); } if (personal.matrix5_rid != 0) { ids.Add(personal.matrix5_rid); } return(ids); }
/// <summary>构建NPC个人战数据</summary> private FightPersonal BuildFightPersonal(String matrix) { var model = new FightPersonal(); var matrix_rid = matrix.Split(','); switch (RivalFightType) { case (int)FightType.NPC_MONSTER: { matrix_rid = GetMatrixRid(matrix_rid); break; } } for (var i = 0; i < matrix_rid.Length; i++) { switch (i) { case 0: model.matrix1_rid = Convert.ToInt64(matrix_rid[0]); break; case 1: model.matrix2_rid = Convert.ToInt64(matrix_rid[1]); break; case 2: model.matrix3_rid = Convert.ToInt64(matrix_rid[2]); break; case 3: model.matrix4_rid = Convert.ToInt64(matrix_rid[3]); break; case 4: model.matrix5_rid = Convert.ToInt64(matrix_rid[4]); break; } } //NPC user_id 暂时用-10000 //model.user_id = -10000; return(model); }
/// <summary>设置NPC战斗全局数据</summary> private bool SetNpcFightData(FightPersonal rival) { bool flag = false; var base_1 = rival.matrix1_rid == 0 ? null : GetNpcData(rival.matrix1_rid); if (base_1 != null) { list_role_hp.Add(base_1); flag = true; } var base_2 = rival.matrix2_rid == 0 ? null : GetNpcData(rival.matrix2_rid); if (base_2 != null) { list_role_hp.Add(base_2); flag = true; } var base_3 = rival.matrix3_rid == 0 ? null : GetNpcData(rival.matrix3_rid); if (base_3 != null) { list_role_hp.Add(base_3); flag = true; } var base_4 = rival.matrix4_rid == 0 ? null : GetNpcData(rival.matrix4_rid); if (base_4 != null) { list_role_hp.Add(base_4); flag = true; } var base_5 = rival.matrix5_rid == 0 ? null : GetNpcData(rival.matrix5_rid); if (base_5 != null) { list_role_hp.Add(base_5); flag = true; } return(flag); }
/// <summary>先手判定</summary> /// <param name="personal">己方的阵</param> /// <param name="rivalPersonal">敌方的阵</param> public void WhoFirst(FightPersonal personal, FightPersonal rivalPersonal) { switch (RivalFightType) { case (int)FightType.SIEGE: case (int)FightType.BUILDING: { GlobalMatrix(personal, rivalPersonal); //活动始终玩家先手 return; } default: { var attack = list_role.Where(m => m.user_id == personal.user_id).Sum(m => m.attack); var rivalAttack = list_role.Where(m => m.user_id == rivalPersonal.user_id).Sum(m => m.attack); if (attack >= rivalAttack) { GlobalMatrix(personal, rivalPersonal); //攻击值验证 判定先后手 } else { GlobalMatrix(rivalPersonal, personal); } return; } } }
/// <summary> 获取雇佣武将 </summary> private void GetHireRole(FightPersonal personal) { bool flag = false; if (personal.matrix1_rid == 0) //阵中的所有武将 { flag = true; var role = GetHireRole(personal.user_id); if (role != null) { personal.matrix1_rid = role.id; list_role_hp.Add(role); } } if (personal.matrix2_rid == 0 && !flag) { flag = true; var role = GetHireRole(personal.user_id); if (role != null) { personal.matrix2_rid = role.id; list_role_hp.Add(role); } } if (personal.matrix3_rid == 0 && !flag) { flag = true; var role = GetHireRole(personal.user_id); if (role != null) { personal.matrix3_rid = role.id; list_role_hp.Add(role); } } if (personal.matrix4_rid == 0 && !flag) { flag = true; var role = GetHireRole(personal.user_id); if (role != null) { personal.matrix4_rid = role.id; list_role_hp.Add(role); } } if (personal.matrix5_rid == 0 && !flag) { var role = GetHireRole(personal.user_id); if (role != null) { personal.matrix5_rid = role.id; list_role_hp.Add(role); } } }
/// <summary> 获取阵中最前面未死的武将 </summary> /// <param name="matrix">需要获取武将的阵</param> private FightRole GetFrontRole(FightPersonal matrix) { var list = attack_matrix.user_id == matrix.user_id ? list_attack_role.Where(m => m != null).ToList() : list_defense_role.Where(m => m != null).ToList(); if (matrix.matrix1_rid != 0) { var model = list.FirstOrDefault(m => m.id == matrix.matrix1_rid && m.hp > 0); if (model != null) { model.damage = 0; return(model); } } if (matrix.matrix2_rid != 0) { var model = list.FirstOrDefault(m => m.id == matrix.matrix2_rid && m.hp > 0); if (model != null) { model.damage = 0; return(model); } } if (matrix.matrix3_rid != 0) { var model = list.FirstOrDefault(m => m.id == matrix.matrix3_rid && m.hp > 0); if (model != null) { model.damage = 0; return(model); } } if (matrix.matrix4_rid != 0) { var model = list.FirstOrDefault(m => m.id == matrix.matrix4_rid && m.hp > 0); if (model != null) { model.damage = 0; return(model); } } if (matrix.matrix5_rid != 0) { var model = list.FirstOrDefault(m => m.id == matrix.matrix5_rid && m.hp > 0); if (model != null) { model.damage = 0; return(model); } } return(null); }
/// <summary> 获取双方阵中所有武将 (获取的武将存储到战斗全局 list_role)</summary> private ResultType GetRoleByMatrixAll(FightPersonal oneself, FightPersonal rival) { var ids = GetMatrixRids(oneself); if (!ids.Any()) { return(ResultType.FIGHT_RIVAL_ID_ERROR); } switch (RivalFightType) { case (int)FightType.NPC_MONSTER: case (int)FightType.NPC_FIGHT_ARMY: { if (!SetNpcFightData(rival)) { return(ResultType.FIGHT_NPC_BASE_ERROR); } GetHireRole(oneself); SetPlayerFightData(ids); return(ResultType.SUCCESS); } case (int)FightType.SIEGE: case (int)FightType.BUILDING: case (int)FightType.CONTINUOUS: case (int)FightType.SINGLE_FIGHT: case (int)FightType.DUPLICATE_SHARP: { if (!SetNpcFightData(rival)) { return(ResultType.FIGHT_NPC_BASE_ERROR); } SetPlayerFightData(ids); return(ResultType.SUCCESS); } case (int)FightType.BOTH_SIDES: case (int)FightType.ONE_SIDE: { ids.AddRange(GetMatrixRids(rival)); SetPlayerFightData(ids); return(ResultType.SUCCESS); } default: { return(ResultType.FIGHT_TYPE_ERROR); } } }
/// <summary> 武将位置变化 下次攻击武将排在前面 </summary> /// <param name="matrix">阵</param> /// <param name="roleid">当前攻击武将主键id</param> private void RolePositionChange(FightPersonal matrix, Int64 roleid) { if (matrix.matrix1_rid == roleid) { matrix.matrix1_rid = matrix.matrix2_rid; matrix.matrix2_rid = matrix.matrix3_rid; matrix.matrix3_rid = matrix.matrix4_rid; matrix.matrix4_rid = matrix.matrix5_rid; matrix.matrix5_rid = roleid; return; } if (matrix.matrix2_rid == roleid) { matrix.matrix2_rid = matrix.matrix3_rid; matrix.matrix3_rid = matrix.matrix4_rid; matrix.matrix4_rid = matrix.matrix5_rid; matrix.matrix5_rid = matrix.matrix1_rid; matrix.matrix1_rid = roleid; return; } if (matrix.matrix3_rid == roleid) { matrix.matrix3_rid = matrix.matrix4_rid; matrix.matrix4_rid = matrix.matrix5_rid; matrix.matrix5_rid = matrix.matrix1_rid; matrix.matrix1_rid = matrix.matrix2_rid; matrix.matrix2_rid = roleid; return; } if (matrix.matrix4_rid == roleid) { matrix.matrix4_rid = matrix.matrix5_rid; matrix.matrix5_rid = matrix.matrix1_rid; matrix.matrix1_rid = matrix.matrix2_rid; matrix.matrix2_rid = matrix.matrix3_rid; matrix.matrix3_rid = roleid; return; } if (matrix.matrix5_rid == roleid) { matrix.matrix5_rid = matrix.matrix1_rid; matrix.matrix1_rid = matrix.matrix2_rid; matrix.matrix2_rid = matrix.matrix3_rid; matrix.matrix3_rid = matrix.matrix4_rid; matrix.matrix4_rid = roleid; return; } }
/// <summary> 获取目标武将 </summary> /// <param name="p">受影响方的阵形</param> /// <param name="flag">目标范围 true:全体 flase:单体</param> /// <param name="istarget">是否己方为目标</param> private List <FightRole> GetTargetRole(FightPersonal p, bool flag, bool istarget) { if (!istarget) { return(GetRoleOrRoleAll(p, flag)); } if (flag) { return(GetRoleOrRoleAll(p, true)); } var list = new List <FightRole> { GetShotRole() }; return(list); }
/// <summary> 验证是否修改为只有主角武将阵形 </summary> /// <param name="session">当前玩家session</param> /// <param name="oneself">当前玩家 FightPersonal</param> private FightPersonal IsUpdatePersonal(TGGSession session, FightPersonal oneself) { switch (RivalFightType) { case (int)FightType.CONTINUOUS: case (int)FightType.SINGLE_FIGHT: { var roleid = session.Player.Role.Kind.id; oneself.matrix1_rid = roleid; oneself.matrix2_rid = 0; oneself.matrix3_rid = 0; oneself.matrix4_rid = 0; oneself.matrix5_rid = 0; return(oneself); } } return(oneself); }
/// <summary>记录全局属性的武将</summary> /// <param name="matrix">阵</param> /// <param name="flag">true:先手 false:后手</param> private void GlobalRole(FightPersonal matrix, bool flag) { var list = new List <FightRole> { matrix.matrix1_rid != 0 ? list_role.FirstOrDefault(m => m.id == matrix.matrix1_rid) : null, matrix.matrix2_rid != 0 ? list_role.FirstOrDefault(m => m.id == matrix.matrix2_rid) : null, matrix.matrix3_rid != 0 ? list_role.FirstOrDefault(m => m.id == matrix.matrix3_rid) : null, matrix.matrix4_rid != 0 ? list_role.FirstOrDefault(m => m.id == matrix.matrix4_rid) : null, matrix.matrix5_rid != 0 ? list_role.FirstOrDefault(m => m.id == matrix.matrix5_rid) : null }; if (flag) { list_attack_role = list; } else { list_defense_role = list; } }
/// <summary>初始化</summary> private void Init() { WIN = 0; Round = 0; IsAttack = true; attack_number = 0; defense_number = 0; vo = new FightVo(); move = new MovesVo(); list_move = new List <MovesVo>(); list_skill = new List <SkillVo>(); list_role = new List <FightRole>(); attack_matrix = new FightPersonal(); list_role_hp = new List <FightRole>(); defense_matrix = new FightPersonal(); list_buff = new List <FightRoleBuff>(); list_attack_role = new List <FightRole>(); list_defense_role = new List <FightRole>(); dic_round = new Dictionary <decimal, int>(); dic_yincount = new Dictionary <decimal, int>(); dic_vocation = new Dictionary <decimal, double>(); }
/// <summary> 获取武将</summary> /// <param name="p">要获取方的阵</param> /// <param name="flag">获取单个还是全体 true:全体 false:单体</param> private List <FightRole> GetRoleOrRoleAll(FightPersonal p, bool flag) { var list = new List <FightRole>(); if (!flag) { var role = GetFrontRole(p); if (role != null) { list.Add(role); } } else { list = FindRoleList(p.user_id); } //foreach (var item in list)//清除伤害 //{ // item.damage = 0; //} return(list); }
/// <summary> 获取技能目标武将 </summary> /// <param name="skill">技能</param> /// <param name="p">触发方的阵形</param> /// <param name="_p">触发方敌对的阵形</param> /// <returns></returns> private List <FightRole> GetTargetRole(FightSkillEffects skill, FightPersonal p, FightPersonal _p) { bool flag; switch (skill.target) //目标类型 1己方 2敌方 { case (int)FightTargetType.OWN: { flag = true; break; } //己方 case (int)FightTargetType.ENEMY: { flag = false; break; } //敌方 default: { return(new List <FightRole>()); } } var tp = flag ? p : _p; switch (skill.range) //效果范围 1单人 2多人 { case (int)EffectRangeType.SINGLE: { return(GetTargetRole(tp, false, flag)); } //单人 case (int)EffectRangeType.ALL: { return(GetTargetRole(tp, true, flag)); } //多人 default: { return(new List <FightRole>()); } } }