public void StartAttack(SkillBase skill, ActorBase actor, DBSkillAttackConf attackConf) { //Debug.Log("Do attack: " + attackConf.ID); isAttackObjectMoving = false; isAllDamageEnd = false; isEffectPlayEnd = false; this.skill = skill; damageConfArray = new DBSkillDamageConf[attackConf.damages.Length]; for (int i = 0; i < attackConf.damages.Length; i++) { damageConfArray[i] = DBSkillDamageTable.GetRecord(attackConf.damages[i]); } if (!string.IsNullOrEmpty(attackConf.attackObjectName)) { eo = EffectManager.GetEffect(attackConf.attackObjectName, null); eo.effectObject.gameObject.SetActive(attackConf.attackObjectAppearTime <= 0); //需要倒计时显示的话,先隐藏 X2DEffect effect = eo.x2dEffect; if (effect != null) { effect.Play(); Vector3 pos = Vector3.zero; pos.x = attackConf.attackObjectAppearPos.x; pos.y = attackConf.attackObjectAppearPos.y; pos = actor.objectbase.GetFaceBasedPos(pos); if (attackConf.attackObjectMoveMode == EmAttackObjectMoveMode.FollowCaster) { eo.effectObject.transform.parent = actor.transform; eo.effectObject.transform.localRotation = Quaternion.identity; eo.effectObject.realLocalPos = pos; } else { eo.effectObject.realPos = actor.objectbase.realLocalPos + pos; } eo.effectObject.isFacingRight = actor.objectbase.isFacingRight; //攻击物体移动 if (attackConf.attackObjectMoveMode == EmAttackObjectMoveMode.AutoMove_Vector) { //向量移动 isAttackObjectMoving = true; attackObjectMoveTimer = 0; attackObjectMoveDuration = attackConf.attackObjectMoveDuration; // attackObjectMoveCurve = AnimationCurveCollection.GetAnimationCurve(attackConf.attackObjectMoveVectorCurve); attackObjectMoveVector = attackConf.attackObjectMoveVector; attackObjectMoveStartPos = eo.effectObject.realLocalPos; if (!eo.effectObject.isFacingRight) { attackObjectMoveVector.x = -attackObjectMoveVector.x; } } else if (attackConf.attackObjectMoveMode == EmAttackObjectMoveMode.AutoMove_Speed) { //曲线移动 isAttackObjectMoving = true; attackObjectMoveTimer = 0; attackObjectMoveDuration = attackConf.attackObjectMoveDuration; // attackObjectMoveSpeed = attackConf.attackObjectMoveSpeed; if (!eo.effectObject.isFacingRight) { attackObjectMoveSpeed.x = -attackObjectMoveSpeed.x; } } } } //音效 if (!string.IsNullOrEmpty(attackConf.actorCastSoundName)) { actor.audioSource.clip = ResourceLoader.LoadCharactorSound(attackConf.actorCastSoundName); actor.audioSource.Play(); } this.actor = actor; this.attackConf = attackConf; damageTimer = 0f; attackTimer = 0f; attackTimes = 0; showTimer = 0; damageIndex = 0; isFinished = false; isCurDamageEnd = false; isBuffEnabled = false; isInCollision = false; isLifeTimeEnd = false; isShowed = false; }
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(); } }