private void BeAttackedEnd() { hitMoveSpeed = Vector2.zero; damageConf = null; hitMoveVector = Vector3.zero; //Debug.Log("BeAttackedEnd"); }
void Update_Damage() { if (attackConf.damageMode == 2 && !isInCollision) { return; } if (damageIndex < damageConfArray.Length) { damageTimer += Time.deltaTime; DBSkillDamageConf damage = damageConfArray[damageIndex]; if (!isBuffEnabled) { if (damageTimer >= damage.buffEnableTime) { isBuffEnabled = true; if (damage.buffID > 0) { actor.BeBuff(damage.buffID); } } } //多久后开始攻击 if (!isCurDamageEnd && damageTimer >= damage.startTime) { //进行多次攻击,第一次攻击立即触发 attackTimer += Time.deltaTime; if (attackTimes == 0 || attackTimer >= damage.interval) { DoDamage(damage); attackTimer = 0f; attackTimes++; //伤害次数+1 if (attackTimes >= damage.times) { isCurDamageEnd = true; } } } if (isBuffEnabled && isCurDamageEnd) { damageTimer = 0f; attackTimes = 0; damageIndex++; //这次damage完成,下个继续 isCurDamageEnd = false; isBuffEnabled = false; } } else { isAllDamageEnd = true; } }
public bool IsInAttackRange(ActorBase enemy, DBSkillDamageConf damage) { //伤害中心 Vector3 damageCenter = Vector3.zero; Vector3 t = damage.damageCenterPos; if (damage.damageCenterType == EmDamageCenterType.Attacker) { if (!actor.objectbase.isFacingRight) { t.x = -t.x; } damageCenter = actor.objectbase.realPos + t; } else if (damage.damageCenterType == EmDamageCenterType.Target) { damageCenter = enemy.objectbase.realPos + damage.damageCenterPos; } else if (damage.damageCenterType == EmDamageCenterType.AttackObject) { damageCenter = eo.effectObject.realPos + damage.damageCenterPos; } else { Debug.LogError("damage.damageCenterType is none"); } //球形区域不用判断 if (damage.damageArenaType == EmDamageArenaType.FrontArena) { if (!actor.objectbase.IsInFrontOfMe(enemy.objectbase.realLocalPos)) { return(false); } } //伤害区域这样处理是以伤害中心为球心的球 //todo,中心为Target和AttackObject作为球体处理,Attacker才具有多样化,因为attacker可以获取到朝向。其他的朝向都是未知/变动的。 //float dist = (damageCenter - enemy.objectbase.realLocalPos).sqrMagnitude; //Debug.Log(dist); //if(dist > damage.damageDistance * damage.damageDistance) // return false; //伤害区域这样处理是以伤害中心为中心的立方体 return(ColliderManager.IsCollision(damageCenter, new Vector3(damage.damageArenaRadius, damage.damageArenaRadius, damage.damageArenaRadius), enemy.objectbase.realLocalPos + new Vector3(0, enemy.actorConf.size.y * 0.5f, 0), enemy.actorConf.size)); //return true; }
//获取记录,如果不存在返回null public static DBSkillDamageConf GetRecord(int ID, bool errorMsg = true) { if (instance == null) { Debug.LogError("表DBSkillDamageTable未加载"); return(null); } DBSkillDamageConf record = null; if (recordDict.TryGetValue(ID, out record)) { return(record); } if (errorMsg) { Debug.LogErrorFormat("表DBSkillDamageTable没有ID = {0}的记录", ID); } return(null); }
public void Init() { //如果recordDict不为null,说明已经初始化了 if (recordDict != null) { return; } recordDict = new Dictionary <int, DBSkillDamageConf>(); for (int i = 0; i < recordArray.Length; i++) { DBSkillDamageConf record = recordArray[i]; if (!recordDict.ContainsKey(record.ID)) { recordDict.Add(record.ID, record); } else { Debug.LogErrorFormat("表DBSkillDamageTable有重复的记录,id = {0}", record.ID); } } }
// public void DoDamage(DBSkillDamageConf damage) { List <ActorBase> enemyList = GameMain.curSceneManager.GetEnemyList(actor); if (enemyList == null) { return; } for (int i = 0; i < enemyList.Count; i++) { if (!enemyList[i].isAlive) { continue; } ActorBase enemy = enemyList[i]; if (!IsInAttackRange(enemy, damage)) { continue; } enemy.BeAttacked(actor, damage, skill); //Debug.Log("Do damage: " + damage.ID); } }
public static float GetDamageDuration(DBSkillDamageConf conf) { return(conf.startTime + conf.interval * (conf.times - 1)); }
public void Show(DBSkillInfoConf skillInfoConf) { nameLabel.text = skillInfoConf.skillNameText; cdLabel.text = skillInfoConf.cd + "秒"; castTimeLabel.text = skillInfoConf.castTime == 0 ? "瞬发" : skillInfoConf.castTime + "秒"; castCombinKeyLabel.text = skillInfoConf.castCombianKey; descLabel.text = skillInfoConf.instruction; DBSkillConf skillConf = DBSkillTable.GetRecord(skillInfoConf.skillID, false); if (skillConf == null) { //没有伤害的技能 attributeLabel.text = ""; return; } List <DBSkillDamageConf> damageList = new List <DBSkillDamageConf>(); //跳过伤害为0的攻击 for (int i = 0; i < skillConf.attackList.Count; i++) { for (int j = 0; j < skillConf.attackList[i].damages.Length; j++) { DBSkillDamageConf damageConf = DBSkillDamageTable.GetRecord(skillConf.attackList[i].damages[j]); if (damageConf.damagePercent > 0) { damageList.Add(damageConf); } } } if (damageList.Count == 0) { attributeLabel.text = ""; } else if (damageList.Count == 1) { attributeLabel.text = string.Format("造成{0}%攻击力的伤害", damageList[0].damagePercent); } else { string text = ""; for (int i = 0; i < damageList.Count; i++) { DBSkillDamageConf damageConf = damageList[i]; string damageText = ""; if (damageConf.times <= 1) { damageText = string.Format("造成{0}%攻击力的伤害", damageConf.damagePercent); } else { damageText = string.Format("每次造成{0}%攻击力的伤害", damageConf.damagePercent); } if (string.IsNullOrEmpty(damageConf.desc)) { text += string.Format(" 第{0}段,进行{1}次攻击,{2}\n", i + 1, damageConf.times, damageText); } else { text += string.Format(" 第{0}段,{1}, 进行{2}次攻击,{3}\n", i + 1, damageConf.desc, damageConf.times, damageText); } } attributeLabel.text = text; } }
public void BeAttacked(ActorBase attacker, DBSkillDamageConf damage, SkillBase skill) { if (isParrying) { ChangeStatus(EmActorStatus.ParryBeAttacked); //暂时不掉血了,背击可以破 return; } if (isAttacking) { if (mySkill != null) { //技能已释放出了 if (mySkill.curAttackConf.isGod) { return; //无敌 } else { mySkill.Stop(); mySkill = null; //被打断 isReadyToCombo = false; } } else { //技能还未释放出,被打断 } } //伤害计算 float damageValue = attacker.curAttribute.attack * damage.damagePercent / 100f + damage.damageFixed; float preHp = curAttribute.hp; curAttribute.hp -= damageValue; if (GameMain.curStatus != GameStatus.Tutorial) { if (curAttribute.hp < 0) { curAttribute.hp = 0; } } else { if (curAttribute.hp < 0) { curAttribute.hp = orgAttribute.hp; //教学模式下,满血继续打 } } //伤害数字等提示 Vector3 damageTipPos = objectbase.transform.position; if (attacker.objectbase.isFacingRight) { damageTipPos += new Vector3(actorConf.size.x * 0.7f, actorConf.size.y * 0.5f, 0); } else { damageTipPos += new Vector3(actorConf.size.x * -0.7f, actorConf.size.y * 0.5f, 0); } UIDamageNumberPanel.ShowTipText(damageTipPos, (int)damageValue); if (actorType == EmActorType.MainPlayer) { UIMainPanel.instance.ShowHp(); } else { UIBattleHpPanel.instance.ShowMonsterHP(actorConf, orgAttribute.hp, curAttribute.hp, preHp, monsterType); } //Debug.LogFormat("Be attacked: {0}-->{1}", preHp, curAttribute.hp); //转向,面向攻击者 objectbase.isFacingRight = attacker.objectbase.realPos.x - objectbase.realPos.x > 0; damageConf = damage; //状态效果是否触发 EmDamageStatusEffect statusEffect = EmDamageStatusEffect.None; if (damageConf.damageStatusEffectProbability >= Random.Range(0, 101)) { statusEffect = damageConf.damageStatusEffect; } //如果当前是眩晕或者冰冻,则不改变当前效果 //在changeStatus的时候,保持原来的持续时间,不做修改 if (actorCurStatus == EmActorStatus.BeAttackedStun) { statusEffect = EmDamageStatusEffect.Stun; } else if (actorCurStatus == EmActorStatus.BeAttackedFreeze) { statusEffect = EmDamageStatusEffect.Freeze; } //状态效果 if (statusEffect == EmDamageStatusEffect.Freeze) { ChangeStatus(EmActorStatus.BeAttackedFreeze); } else if (statusEffect == EmDamageStatusEffect.Stun) { ChangeStatus(EmActorStatus.BeAttackedStun); } else { //移动效果 if (damage.damageMoveEffect == EmDamageMoveEffect.Frozen) { ChangeStatus(EmActorStatus.BeAttackedFrozen); } else if (damage.damageMoveEffect == EmDamageMoveEffect.HitMove) { hitMoveSpeed = damage.hitMoveSpeed; //要阻力计算 ChangeStatus(EmActorStatus.BeAttackedHitMove); } else if (damage.damageMoveEffect == EmDamageMoveEffect.HitMoveFreezeInAir) { if (objectbase.realLocalPos.y > 0) { hitMoveSpeed = Vector2.zero; ChangeStatus(EmActorStatus.BeAttackedFrozen); Debug.Log("HitMoveFreeze.BeAttackedFreeze"); } else { hitMoveSpeed = damage.hitMoveSpeed; //要阻力计算 ChangeStatus(EmActorStatus.BeAttackedHitMove); } } else if (damage.damageMoveEffect == EmDamageMoveEffect.HitMoveDist || damage.damageMoveEffect == EmDamageMoveEffect.HitMoveTo) { //去除移动速度 hitMoveSpeed = Vector2.zero; if (damage.damageMoveEffect == EmDamageMoveEffect.HitMoveDist) { hitMoveCurve = AnimationCurveCollection.GetAnimationCurve(damageConf.hitMoveVectorCurveName); hitMoveVector = damage.hitMoveVector; if (!attacker.objectbase.isFacingRight) { hitMoveVector.x = -hitMoveVector.x; } } else { hitMoveCurve = AnimationCurveCollection.GetAnimationCurve(damageConf.hitMoveToCurveName); Vector3 t = Vector3.zero; if (attacker.objectbase.isFacingRight) { t.x = damage.hitMoveTo.x + actorConf.size.x * 0.4f; } else { t.x = -damage.hitMoveTo.x - actorConf.size.x * 0.4f; } if (skill.skillConf.skillID == (int)EmSkillIDSet.GrabBlast) { //如果是嗜魂之手的话,对于高度低抓取位置的怪,头部对齐到目标位置 if (actorConf.size.y < damage.hitMoveTo.y) //目标怪的高度低于抓取的位置,高度要升高 { t.y = damage.hitMoveTo.y - actorConf.size.y * 0.8f; } } else { //默认是怪物中心对齐到指定地点,如果怪物中心高于指定点,则只平移 if (actorConf.size.y * 0.5f < damage.hitMoveTo.y) { t.y = damage.hitMoveTo.y - actorConf.size.y * 0.5f; } } t.z -= 10; //将怪放到玩家下面,避免怪遮住手 hitMoveVector = attacker.objectbase.realPos + t - objectbase.realPos; Debug.Log(hitMoveVector); } hitMoveStartPos = objectbase.realLocalPos; ChangeStatus(EmActorStatus.BeAttackedHitMoveDist); } else if (damage.damageMoveEffect == EmDamageMoveEffect.HitFallDown) { ChangeStatus(EmActorStatus.BeAttackedFallDown); } else { Debug.LogError("Unkown damage result"); } } if (!attacker.objectbase.isFacingRight) { hitMoveSpeed.x = -hitMoveSpeed.x; } //音效 if (!string.IsNullOrEmpty(damageConf.hitSoundName)) { audioSource.clip = ResourceLoader.LoadCharactorSound(damageConf.hitSoundName); audioSource.Play(); } //击中效果,目前只有鬼剑士普攻有 if (attacker.actorConf.actorID < 1004 && damage.ID / 10 <= 1002) { EffectObject eo = EffectManager.GetEffect("Common_HitEffect_Slash" + (damage.ID % 10), transform); Vector3 pos = objectbase.realLocalPos; pos.y += actorConf.size.y * 0.5f; eo.effectObject.realPos = pos; eo.autoDestroy = true; eo.x2dEffect.Play(); } }