public void AttackDamage(EntityBase entity, int skillId) { entity._listSkillDamageCallback.Clear(); entity._listSkillMoveCallback.Clear(); SkillDataCfg skillData = resSvc.GetSkillCfg(skillId); List <int> listSkillAction = skillData.skillActionList; int accumulate = 0; for (int idx = 0; idx < listSkillAction.Count; idx++) { SkillActionCfg actionCfg = resSvc.GetSkillActionCfg(listSkillAction[idx]); accumulate += actionCfg.delayTime; int skillIdx = idx; if (accumulate > 0) { int actionId = -1; actionId = timeSvc.AddTimeTask((int tid) => { if (entity != null) { SelectDamageObj(entity, skillData, skillIdx); entity.RemoveDamageCallbackID(actionId); } }, accumulate); entity._listSkillDamageCallback.Add(actionId); } else { SelectDamageObj(entity, skillData, skillIdx); } } }
private void SelectDamageObj(EntityBase attacker, SkillDataCfg skillCfg, int skillIdx) { SkillActionCfg actionCfg = resSvc.GetSkillActionCfg(skillCfg.skillActionList[skillIdx]); int damageVal = skillCfg.skillDamageList[skillIdx]; if (attacker._entityType == Constants.EntityType.Monster) { EntityPlayer entityPlayer = attacker._battleMgr.GetEntityPlayer; if (entityPlayer == null) { return; } if (InRange(attacker.GetEntityPosition(), entityPlayer.GetEntityPosition(), actionCfg.radius) && InAngle(attacker.GetEntityTransform(), entityPlayer.GetEntityPosition(), actionCfg.angle)) { CalcDamage(attacker, entityPlayer, skillCfg, damageVal); } } else if (attacker._entityType == Constants.EntityType.Player) { //获取场景中所有的怪物 List <EntityMonster> listMonster = attacker._battleMgr.GetAllEntityMonsters(); for (int i = 0; i < listMonster.Count; i++) { EntityMonster monster = listMonster[i]; //在攻击范围内 if (InRange(attacker.GetEntityPosition(), monster.GetEntityPosition(), actionCfg.radius) && InAngle(attacker.GetEntityTransform(), monster.GetEntityPosition(), actionCfg.angle)) { CalcDamage(attacker, monster, skillCfg, damageVal); } } } }
public void CheckCombo() { _bCanControl = true; if (_skillCfg != null) { if (!_skillCfg.bBreak) { _entityState = Constants.EntitiyState.None; } if (_skillCfg.bCombo) { if (_comboQue.Count > 0) { _nextSkillID = _comboQue.Dequeue(); } else { _nextSkillID = 0; } } //攻击完了要置空 _skillCfg = null; } SetAction(Constants.cActionDefault); }
public SkillDataCfg GetSkillCfg(int id) { SkillDataCfg skillData = null; if (dictSkillCfgData.TryGetValue(id, out skillData)) { return(skillData); } return(null); }
public void AttackEffect(EntityBase entity, int skillId) { SkillDataCfg skillData = resSvc.GetSkillCfg(skillId); //判断技能能不能碰撞 if (!skillData.bCollide) { //忽略掉刚体碰撞 Physics.IgnoreLayerCollision(Constants.cLayerPlayer, Constants.cLayerMonster); timeSvc.AddTimeTask((int tid) => { //技能播放完给恢复 Physics.IgnoreLayerCollision(Constants.cLayerPlayer, Constants.cLayerMonster, false); }, skillData.skillTime); } if (entity._entityType == Constants.EntityType.Player) { if (entity.GetCurrentDirection() == Vector2.zero) { //搜索最近的怪物 Vector2 dir = entity.CalcTargetDirection(); if (dir != Vector2.zero) { entity.SetAttackDirection(dir); } } else { entity.SetAttackDirection(entity.GetCurrentDirection(), true); } } entity.SetAction(skillData.aniAction); entity.SetFx(skillData.fx, skillData.skillTime); skillMoveLogical(entity, skillData); entity._bCanControl = false; entity.SetDirection(Vector2.zero); if (!skillData.bBreak) { entity._entityState = Constants.EntitiyState.NoEffectHit; } entity._skillEndCallbackID = timeSvc.AddTimeTask((int tid) => { entity.Idle(); }, skillData.skillTime); }
private void skillMoveLogical(EntityBase entity, SkillDataCfg skillData) { int totalDelayTime = 0; List <int> skillMoveList = skillData.skillMoveList; for (int i = 0; i < skillMoveList.Count; i++) { SkillMoveCfg skillMoveCfg = resSvc.GetSkillMoveCfg(skillMoveList[i]); float spd = skillMoveCfg.moveDistance / (skillMoveCfg.moveTime / 1000.0f); totalDelayTime += skillMoveCfg.delayTime; if (totalDelayTime > 0) { int moveCallbackId = -1; moveCallbackId = timeSvc.AddTimeTask((int tid) => { entity.SetSkillMoveState(true, spd); entity.RemoveMoveCallbackID(moveCallbackId); }, totalDelayTime); entity._listSkillMoveCallback.Add(moveCallbackId); } else { entity.SetSkillMoveState(true, spd); } totalDelayTime += skillMoveCfg.moveTime; int stopSkillMoveCallbackID = -1; stopSkillMoveCallbackID = timeSvc.AddTimeTask((int tid) => { entity.SetSkillMoveState(false); entity.RemoveMoveCallbackID(stopSkillMoveCallbackID); }, totalDelayTime); entity._listSkillMoveCallback.Add(stopSkillMoveCallbackID); } }
private void InitSkillCfgData(string xmlPath) { TextAsset xmlText = Resources.Load <TextAsset>(xmlPath); if (!xmlText) { CommonTools.Log("xml file: " + PathDefine.cPath_RandomNameCfg + "not exits!", LogType.LogType_Error); return; } //开始解析xml文件 XmlDocument doc = new XmlDocument(); doc.LoadXml(xmlText.text); XmlNodeList nodeList = doc.SelectSingleNode("root").ChildNodes; for (int i = 0; i < nodeList.Count; i++) { XmlElement element = nodeList[i] as XmlElement; if (element.GetAttributeNode("ID") == null) { continue; } int id = Convert.ToInt32(element.GetAttributeNode("ID").InnerText); SkillDataCfg skillData = new SkillDataCfg { ID = id, skillMoveList = new List <int>(), skillActionList = new List <int>(), skillDamageList = new List <int>() }; #region 遍历解析 foreach (XmlElement elem in nodeList[i].ChildNodes) { switch (elem.Name) { case "skillName": skillData.skillName = elem.InnerText; break; case "cdTime": skillData.cdTime = int.Parse(elem.InnerText); break; case "isCombo": skillData.bCombo = elem.InnerText.Equals("1"); break; case "isCollide": skillData.bCollide = elem.InnerText.Equals("1"); break; case "isBreak": skillData.bBreak = elem.InnerText.Equals("1"); break; case "skillTime": skillData.skillTime = int.Parse(elem.InnerText); break; case "aniAction": skillData.aniAction = int.Parse(elem.InnerText); break; case "fx": skillData.fx = elem.InnerText; break; case "dmgType": { if (elem.InnerText.Equals("1")) { skillData.damageType = Constants.DamageType.DamageType_AD; } else if (elem.InnerText.Equals("2")) { skillData.damageType = Constants.DamageType.DamageType_AP; } } break; case "skillMoveLst": { string[] skillList = elem.InnerText.Split('|'); for (int skillIdx = 0; skillIdx < skillList.Length; skillIdx++) { if (skillList[skillIdx] != "") { skillData.skillMoveList.Add(int.Parse(skillList[skillIdx])); } } } break; case "skillActionLst": { string[] skillActionList = elem.InnerText.Split('|'); for (int skillIdx = 0; skillIdx < skillActionList.Length; skillIdx++) { if (skillActionList[skillIdx] != "") { skillData.skillActionList.Add(int.Parse(skillActionList[skillIdx])); } } } break; case "skillDamageLst": { string[] damageList = elem.InnerText.Split('|'); for (int damagedx = 0; damagedx < damageList.Length; damagedx++) { if (damageList[damagedx] != "") { skillData.skillDamageList.Add(int.Parse(damageList[damagedx])); } } } break; } } #endregion dictSkillCfgData.Add(id, skillData); } }
private void CalcDamage(EntityBase attacker, EntityBase patient, SkillDataCfg skillCfg, int damageVal) { int finalDamageVal = damageVal; if (skillCfg.damageType == Constants.DamageType.DamageType_AD) { System.Random rd = new System.Random(); //闪避 int dodgeVal = CommonTools.RandomInt(1, 100, rd); if (dodgeVal <= patient.BattleProps.dodge) { patient.SetDodge(); return; } //基础属性 finalDamageVal += attacker.BattleProps.ad; //暴击 int criticalVal = CommonTools.RandomInt(1, 100, rd); if (criticalVal <= patient.BattleProps.critical) { float criticalRate = 1.0f + (CommonTools.RandomInt(1, 100) / 100.0f); finalDamageVal = (int)criticalRate * finalDamageVal; patient.SetCritical(finalDamageVal); } //穿甲 int addefVal = (int)((1.0f - attacker.BattleProps.pierce / 100.0f) * patient.BattleProps.addef); finalDamageVal -= addefVal; } else if (skillCfg.damageType == Constants.DamageType.DamageType_AP) { //基础属性 finalDamageVal += patient.BattleProps.ap; //魔法抗性 finalDamageVal -= patient.BattleProps.apdef; } finalDamageVal = finalDamageVal < 0 ? 0 : finalDamageVal; if (finalDamageVal == 0) { return; } patient.SetHurt(finalDamageVal); if (patient.HP < finalDamageVal) { patient.HP = 0; patient.Die(); if (patient._entityType == Constants.EntityType.Monster) { patient._battleMgr.RemoveMonsterData(patient.EntityName); } else if (patient._entityType == Constants.EntityType.Player) { patient._battleMgr.FinishBattle(false, 0); patient._battleMgr.GetEntityPlayer = null; } } else { patient.HP -= finalDamageVal; if (patient._entityState == Constants.EntitiyState.None && patient.CanBeBreak()) { patient.Hit(); } } }