/**比赛中取有效技能 根据当前command*/ public SkillInstance GetValidSkillInMatch(Command curCommand, bool isAI = false, System.Predicate <SkillInstance> filter = null) { if (curCommand == Command.None) { return(null); } PlayerState curPlayerState = m_player.m_StateMachine.m_curState; if (curPlayerState != null && !curPlayerState.IsCommandValid(curCommand)) { return(null); } List <SkillInstance> skills = m_cachedSkillList; GameMatch curMatch = GameSystem.Instance.mClient.mCurMatch; PlayerState curState = m_player.m_StateMachine.m_curState; bool bIsSkillState = curState is PlayerState_Skill; List <SkillInstance> matchedSkills = new List <SkillInstance>(); List <SkillInstance> toMatchSkills = new List <SkillInstance>(); foreach (SkillInstance skillInstance in skills) { if (isAI && (Command)skillInstance.skill.action_type != curCommand) { continue; } if (!_MatchArea(curMatch, skillInstance)) { continue; } if (!_MatchActionCondition(skillInstance)) { continue; } if (!_MatchSkillSpecParam(skillInstance)) { continue; } //has power & has vigour if (!_MatchStamina(skillInstance)) { if (curMatch.mainRole == m_player) { curMatch.ShowTips((Vector3)m_player.position + Vector3.up, CommonFunction.GetConstString("MATCH_TIPS_NOT_ENOUGH_STAMINA"), GlobalConst.MATCH_TIP_COLOR_RED); if (isAI) { Debug.Log(string.Format("SkillSystem, no enough stamina for skill: {0} {1}", skillInstance.skill.id, skillInstance.skill.name)); } } continue; } if (isAI && filter != null && !filter(skillInstance)) { continue; } toMatchSkills.Add(skillInstance); //precise matching if (!isAI && !_MatchAction(curCommand, skillInstance, false)) { continue; } matchedSkills.Add(skillInstance); } if (!isAI && matchedSkills.Count == 0) { foreach (SkillInstance skillInstance in toMatchSkills) { //unprecise matching if (!_MatchAction(curCommand, skillInstance, true)) { continue; } matchedSkills.Add(skillInstance); } } //filter out shoot dunk layup and offense type if (!isAI && curCommand == Command.Shoot) { List <OffenseType> offenses = new List <OffenseType>(); foreach (SkillInstance skillInstance in matchedSkills) { if (skillInstance.skill.action_type == 1 && !offenses.Contains(OffenseType.eShot)) { offenses.Add(OffenseType.eShot); } else if (skillInstance.skill.action_type == 2 && !offenses.Contains(OffenseType.eLayup)) { offenses.Add(OffenseType.eLayup); } else if (skillInstance.skill.action_type == 3 && !offenses.Contains(OffenseType.eDunk)) { offenses.Add(OffenseType.eDunk); } } if (offenses.Count > 0) { OffenseType type = _CalcOffenseType(m_player, offenses); if (type != OffenseType.eNone) { //Debug.Log("OffenseType : " + type ); for (int i = matchedSkills.Count - 1; i >= 0; i--) { SkillInstance skillInstance = matchedSkills[i]; if (skillInstance.skill.action_type != (uint)type) { //Debug.Log("Remove action_type : " + skillInstance.skill.action_type + " Type value: " + (uint)skillInstance.skill.action_type); matchedSkills.Remove(skillInstance); } } } } } /* * if( matchedSkills.Count != 0 ) * { * Debug.Log("====matched skill==="); * foreach( SkillInstance instance in matchedSkills ) * Debug.Log("matched skill: " + instance.curAction.action_id); * Debug.Log("===================="); * } */ //choose highest weight. SkillInstance finalSkill = null; finalSkill = MatchSkillByWeight(matchedSkills); //if( finalSkill != null ) // Debug.Log("final skill: " + finalSkill.curAction.action_id); //choose a default skill if (finalSkill == null && !bIsSkillState && curCommand != Command.CutIn) //TODO: 临时针对空切特殊处理,以后修改 { foreach (SkillInstance skillInstance in m_basicMatchedSkills) { if ((Command)skillInstance.skill.action_type != curCommand) { continue; } if (!_MatchArea(curMatch, skillInstance)) { continue; } if (!_MatchActionCondition(skillInstance)) { continue; } //has power & has vigour if (!_MatchStamina(skillInstance)) { continue; } finalSkill = skillInstance; //Debug.Log("Get basic skill: "); break; } } return(finalSkill); }