//高级近战攻击 bool HighNearAttack() { if (!Self.CurrentTargetIsDead) {//有目标 float hpPercent = Self.HP / Self.MaxHP; if (hpPercent <= 0.5f) {//hp<=50% float d = ActorTargetManager.GetTargetDistance(Self.RealPos, Self.CurrentTarget.RealPos); if (d < 2) { if (Time.time - m_battleStartTime > 4) {// //释放“近战”&&“高级”技能 int skillID = GetSkillID(ENSkillDistanceType.enNear, ENSkillLevelType.enHigh); if (skillID != 0 && ActionTryFireSkill(skillID)) { m_battleStartTime = Time.time; return(true); } } } } } return(false); }
void FindFriend(Actor target) { if (m_target != null) { return; } if (target.IsDead) { return; } if (ActorTargetManager.IsFriendly(m_self, target)) { float d = ActorTargetManager.GetTargetDistance(m_self.MainPos, target.MainPos); float attackRange = 0; if (m_self.Type == ActorType.enNPC) { attackRange = (m_self as NPC).CurrentTableInfo.AttackRange; } else { attackRange = (m_self as Player).CurrentTableInfo.AttackRange; } if (d < attackRange) {//攻击范围内 m_target = target; } } }
public static AIBaseData GetActorTargetDis(Actor actor, string name = "") { AIBaseData tmpData = AIBaseData.CreateAIBaseData(); tmpData.SetFloatValue(ActorTargetManager.GetTargetDistance(actor.RealPos, actor.CurrentTarget.RealPos)); return(tmpData); }
public override void Update() { base.BaseUpdate(); if (Self.IsDead) {//死亡 return; } m_nextAITime -= Time.deltaTime; if (m_nextAITime > 0.0f) { return; } m_nextAITime = UnityEngine.Random.Range(0.1f, 0.5f); FindSneak(); switch (m_fearType) { case ENFearType.enEscape: { Actor target = ActorManager.Singleton.Lookup(m_targetID); if (target != null) { float distance = ActorTargetManager.GetTargetDistance(Owner.MainPos, target.MainPos); if (distance < m_escapeDistance) { //恐惧逃跑 Vector3 direction = Owner.MainPos - target.MainPos; direction.y = 0; direction.Normalize(); Vector3 targetPos = Owner.MainPos + direction * (m_escapeDistance - distance); MoveAction action = Owner.ActionControl.AddAction(MoveAction.SGetActionType()) as MoveAction; if (action != null) { action.Retarget(targetPos); } return; } } //恐惧站立 Owner.ActionControl.RemoveAction(MoveAction.SGetActionType()); StandAction standAction = Owner.ActionControl.LookupAction(StandAction.SGetActionType()) as StandAction; if (standAction == null) { standAction = Owner.ActionControl.AddAction(StandAction.SGetActionType()) as StandAction; } if (standAction != null) { standAction.AnimName = "standby"; } } break; } }
//停止跟随主控角色 bool StopFollow() { if (m_isStartFollow) { float distance = ActorTargetManager.GetTargetDistance(Self.RealPos, MainActor.RealPos); distance = Mathf.Abs(distance); if (distance < StopFollowDistance) { Self.ActionControl.RemoveAction(ActorAction.ENType.enMoveAction); return(true); } } return(false); }
void ChangeTarget(Actor target) { if (target.IsDead) { return; } if (ActorTargetManager.IsEnemy(m_self, target)) { float d = ActorTargetManager.GetTargetDistance(m_self.MainPos, target.MainPos); if (m_self.CurrentTableInfo.AttackRange > d) {//改变目标 target.CurrentTarget = m_self; } } }
void CheckSneak(Actor target) { if (target == null || target.IsDead) { return; } if (target.TempType == ActorType.enPlayer_Sneak) {//潜行中 float distance = ActorTargetManager.GetTargetDistance(Self.RealPos, target.RealPos); if (Self.CurrentTableInfo.AlertRange > distance) {//警戒范围内 target.StopSneak(); } } }
bool FollowMainActor() {//跟随 float distance = ActorTargetManager.GetTargetDistance(Self.RealPos, MainActor.RealPos); distance = Mathf.Abs(distance); if (distance > StartFollowDistance) { if (MainActor.CurrentTargetIsDead || Self.CurrentTargetIsDead) {//主控角色没有目标 或 同伴没有目标 ActionMoveTo(MainActor.RealPos); mDisAbleFindPathTime = 0; return(true); } } return(false); }
void CheckTarget(Actor target) { if (target.IsDead) { return; } if (ActorTargetManager.IsEnemy(m_self, target)) { float distance = ActorTargetManager.GetTargetDistance(m_self.RealPos, target.RealPos); if (distance < m_range) { if (!m_targetList.Contains(target)) { m_targetList.Add(target); } } } }
public void SetRoomTargetListToBoxNpc(List <NPC> treasureList) { m_minDistance = float.MaxValue; m_targetIDList.Clear(); foreach (NPC item in treasureList) { if (item.GetNpcType() == ENNpcType.enBoxNPC && !item.IsDead) { float distance = ActorTargetManager.GetTargetDistance(Owner.RealPos, item.RealPos); if (distance < m_minDistance) { m_minDistance = distance; m_minActor = item; } m_targetIDList.Add(item.ID); } } }
void CheckTarget(Actor target) { if (m_target != null) { return; } if (target.IsDead) { return; } if (ActorTargetManager.IsEnemy(m_info.m_actorCamp, m_info.m_actorType, target)) { float d = ActorTargetManager.GetTargetDistance(m_info.m_itemObj.transform.position, target.RealPos); if (d < m_range) { m_target = target; } } }
// 创建reuslt的消息 public override int SendCreateResult_C2BS(int resultId, int source, int target, int skillResultID = 0, int skillID = 0, float[] param = null) { MessageBlock msg = MessageBlock.CreateMessage(GamePacketID.ENMsgCreateResultC2BS, true); msg.AddParam("resultId", resultId); msg.AddParam("source", source); msg.AddParam("target ", target); msg.AddParam("skillResultID", skillResultID); msg.AddParam("skillID", skillID); Actor targetActor = ActorManager.Singleton.Lookup(target); Actor sourceActor = ActorManager.Singleton.Lookup(source); float d = 0.0f; if (null != targetActor && null != sourceActor) { d = ActorTargetManager.GetTargetDistance(sourceActor.RealPos, targetActor.RealPos); } msg.AddParam("distanace", d); if (param != null) { msg.AddParam("paramLength", param.Length); foreach (float item in param) { msg.AddParam("param", item); } } else { msg.AddParam("paramLength", 0); } LCMsgSender.Singleton.SendMsg(msg); int msgID = msg.MessageID; MessageBlock.ReleaseMessage(msg); return(msgID); }
void CheckActorDistance(Actor target, float[] param) { if (target.Type == ActorType.enNPC) { NPC npc = target as NPC; if (npc.GetNpcType() == ENNpcType.enBlockNPC || npc.GetNpcType() == ENNpcType.enFunctionNPC) { return; } } else if (target.Type == ActorType.enMain) { if (target.IsActorExit) { return; } } if (target.IsDead) { return; } if (!ActorTargetManager.IsEnemy(mSelfActor, target)) { return; } float distance = ActorTargetManager.GetTargetDistance(mSelfActor.RealPos, target.RealPos); if (distance <= param[1])//拖拽生效半径 { Vector3 targetPos = mSelfActor.MainPos; DragMoveAction action = target.ActionControl.AddAction(DragMoveAction.SGetActionType()) as DragMoveAction; if (null != action) { action.Init(targetPos, param[2], param[3]);//拖拽偏移量,拖拽速度 } else { Debug.LogWarning("add DragMoveAction failed"); } } }
public void BaseUpdate() { base.Update(); if (Self.IsActorExit) { return; //当前角色离场 } ReliveUI(); #region Unlock if (!Self.CurrentTargetIsDead) {//判断距离 清除目标 float distance = ActorTargetManager.GetTargetDistance(Self.MainPos, Self.CurrentTarget.MainPos); if (distance > Self.CurrentTableInfo.UnlockRange) { Self.CurrentTarget = null; Self.DamageSource = null; } } #endregion CheckAllSkill(); }
//近战攻击 bool NearAttack() { if (!Self.CurrentTargetIsDead) {//有目标 float d = ActorTargetManager.GetTargetDistance(Self.RealPos, Self.CurrentTarget.RealPos); if (d < 2) { if (Time.time - m_battleStartTime > 4) {// //释放“近战”技能 int skillID = GetSkillID(ENSkillDistanceType.enNear, ENSkillLevelType.enBase); if (skillID != 0 && ActionTryFireSkill(skillID)) { m_battleStartTime = Time.time; return(true); } } } } return(false); }
bool Evading() { if (Self.CurrentTargetIsDead) { MoveAction moveAction = MainActor.ActionControl.LookupAction(ActorAction.ENType.enMoveAction) as MoveAction; if (moveAction != null) {//如果主控角色正在移动 float PosDistance = ActorTargetManager.GetTargetDistance(Self.MainPos, MainActor.MainPos); if (PosDistance < m_evadingValue) {//获去主控角色与同伴位置的距离 Vector3 mainMoveForward = moveAction.TargetPos - MainActor.MainPos; Vector3 moveForward = Self.MainPos - MainActor.MainPos; moveForward.y = 0; mainMoveForward.y = 0; moveForward.Normalize(); mainMoveForward.Normalize(); float angle = Vector3.Angle(moveForward, mainMoveForward); if (angle < 90) { Vector3 verticalMoveForward = Vector3.Cross(mainMoveForward, new Vector3(0, 1, 0)); verticalMoveForward.Normalize(); int tmpIntX = (mainMoveForward.x > moveForward.x ? -1 : 1); int tmpIntZ = (mainMoveForward.z > moveForward.z ? -1 : 1); verticalMoveForward.x = Mathf.Abs(verticalMoveForward.x) * tmpIntX; verticalMoveForward.z = Mathf.Abs(verticalMoveForward.z) * tmpIntZ; Vector3 targetPos = Self.MainPos + (verticalMoveForward * m_evadingDistance); if (!SM.RandomRoomLevel.Singleton.QuickFindPath(Self.MainPos, targetPos)) { moveForward.x = moveForward.x * -1; moveForward.z = moveForward.z * -1; targetPos = Self.MainPos + (verticalMoveForward * m_evadingDistance); } ActionMoveTo(targetPos); return(true); } } } } return(false); }
void CheckTarget(Actor target) { if (m_multiTargetList.Count == m_multiTargetNumber) { return; } if (target.IsDead) { return; } if (ActorTargetManager.IsEnemy(m_self, target)) { float d = ActorTargetManager.GetTargetDistance(m_self.MainPos, target.MainPos); if (m_multiTargetRange > d) { if (!m_multiTargetList.Contains(target)) { m_multiTargetList.Add(target); } } } }
public bool ChangeOtherPos() { MoveAction moveAction = Self.ActionControl.LookupAction(ActorAction.ENType.enMoveAction) as MoveAction; if (moveAction != null) {//如果主控角色正在移动 float PosDistance = ActorTargetManager.GetTargetDistance(Self.MainPos, MainActor.MainPos); if (PosDistance < 1) {//获去主控角色与同伴位置的距离 Vector3 selfMoveForward = moveAction.TargetPos - Self.MainPos; Vector3 moveForward = MainActor.MainPos - Self.MainPos; moveForward.y = 0; selfMoveForward.y = 0; moveForward.Normalize(); selfMoveForward.Normalize(); float angle = Vector3.Angle(moveForward, selfMoveForward); if (angle < 45) { Vector3 verticalMoveForward = Vector3.Cross(selfMoveForward, new Vector3(0, 1, 0)); verticalMoveForward.Normalize(); int tmpIntX = (selfMoveForward.x > moveForward.x ? 1 : -1); int tmpIntZ = (selfMoveForward.z > moveForward.z ? 1 : -1); verticalMoveForward.x = Mathf.Abs(verticalMoveForward.x) * tmpIntX; verticalMoveForward.z = Mathf.Abs(verticalMoveForward.z) * tmpIntZ; Vector3 targetPos = Self.MainPos + (verticalMoveForward * 3); // if (!SDungeonsMgr.Singleton.QuickFindPath(Self.MainPos, targetPos)) // { // moveForward.x = moveForward.x * -1; // moveForward.z = moveForward.z * -1; // targetPos = Self.MainPos + (verticalMoveForward * 3); // } ActionMoveTo(targetPos); return(true); } } } return(false); }
public void SetRoomTrageListToTrap(List <Trap> trapList) { m_minDistance = float.MaxValue; m_targetIDList.Clear(); Dictionary <float, List <int> > tmpTrapDic = new Dictionary <float, List <int> >(); List <float> tmpDistList = new List <float>(); foreach (Trap item in trapList) { if (item.mTrapType == TrapType.enAuto || item.mTrapType == TrapType.enTouchType) { continue; } if (!item.m_trapActivate) { float distance = ActorTargetManager.GetTargetDistance(Owner.RealPos, item.RealPos); if (tmpTrapDic.ContainsKey(distance)) { tmpTrapDic[distance].Add(item.ID); } else { List <int> tmpList = new List <int> (); tmpList.Add(item.ID); tmpTrapDic.Add(distance, tmpList); tmpDistList.Add(distance); } } } tmpDistList.Sort(); foreach (var item in tmpDistList) { foreach (var id in tmpTrapDic[item]) { m_targetIDList.Add(id); } } }
void UpdateImpl(bool damping) { //camera跟随目标的位置 Vector3 cameraPos = Vector3.zero; // float smoothTime = 0; switch (m_curTargetType) { case ENCameraTargetType.enActor: { if (m_targetActor == null) { return; } GameObject obj = m_targetActor.CenterPart; if (m_targetActor.ActionControl.IsActionEmpty() || m_targetActor.ActionControl.IsActionRunning(ActorAction.ENType.enStandAction) || m_targetActor.ActionControl.IsActionRunning(ActorAction.ENType.enActorEnterAction) || IsNormalAttack()) { obj = m_targetActor.MainObj; } cameraPos = null != obj ? obj.transform.position : Vector3.zero; if (!m_targetActor.IsDead) { //主控角色未死亡时,对准主控角色跟目标之间 Actor target = m_targetActor.CurrentTarget; if (target != null && !target.IsDead) { Vector3 selfPos = cameraPos; Vector3 targetPos = target.MainPos; selfPos.y = 0; targetPos.y = 0; cameraPos = selfPos + (targetPos - selfPos) * 0.5f; } } //计算smooth时间 smoothTime = GameSettings.Singleton.m_cameraSmoothTimeForStart; MoveAction action = m_targetActor.ActionControl.LookupAction(ActorAction.ENType.enMoveAction) as MoveAction; if (action != null && CursorEffectFunc.Singleton.CurFingerType != CursorEffectFunc.ENFingerType.enOnDragMoveType) { float d = ActorTargetManager.GetTargetDistance(m_targetActor.RealPos, action.m_realTargetPos); if (d < GameSettings.Singleton.m_cameraStopDistance) { smoothTime = GameSettings.Singleton.m_cameraSmoothTimeForStop; } } else if (m_lastCameraPos == cameraPos) { //目标停止运动 smoothTime = GameSettings.Singleton.m_cameraSmoothTimeForStop; } float velocity = 0; m_currentSmoothTime = Mathf.SmoothDamp(m_currentSmoothTime, smoothTime, ref velocity, GameSettings.Singleton.m_timeForCameraChangeTime); } break; case ENCameraTargetType.enGameObject: { cameraPos = m_targetObj.transform.position; smoothTime = m_changeTime; if (m_autoBackTime != 0) { if (Time.time - m_startTime > m_autoBackTime) { m_changeTime = m_backTime; m_startTime = Time.time; m_curTargetType = ENCameraTargetType.enBackToActor; } } m_currentSmoothTime = smoothTime; } break; case ENCameraTargetType.enPostion: { cameraPos = m_targetPos; smoothTime = m_changeTime; if (m_autoBackTime != 0) { if (Time.time - m_startTime > m_autoBackTime) { m_changeTime = m_backTime; m_startTime = Time.time; m_curTargetType = ENCameraTargetType.enBackToActor; } } m_currentSmoothTime = smoothTime; } break; case ENCameraTargetType.enBackToActor: { GameObject obj = m_targetActor.CenterPart; if (m_targetActor.ActionControl.IsActionEmpty() || m_targetActor.ActionControl.IsActionRunning(ActorAction.ENType.enStandAction) || m_targetActor.ActionControl.IsActionRunning(ActorAction.ENType.enActorEnterAction) || IsNormalAttack()) { obj = m_targetActor.MainObj; } cameraPos = null != obj ? obj.transform.position : Vector3.zero; if (!m_targetActor.IsDead) { //主控角色未死亡时,对准主控角色跟目标之间 Actor target = m_targetActor.CurrentTarget; if (target != null && !target.IsDead) { Vector3 selfPos = cameraPos; Vector3 targetPos = target.MainPos; selfPos.y = 0; targetPos.y = 0; cameraPos = selfPos + (targetPos - selfPos) * 0.5f; } } smoothTime = m_changeTime; if (Time.time - m_startTime > m_changeTime) { m_curTargetType = ENCameraTargetType.enActor; } m_currentSmoothTime = smoothTime; } break; default: { m_curTargetType = ENCameraTargetType.enActor; UpdateImpl(damping); return; } // break; } m_lastCameraPos = cameraPos; if (!m_isChangeY) { cameraPos.y = 0.35f; } //拉远 MainCamera.transform.position = cameraPos; MainCamera.transform.Translate(Vector3.back * GameSettings.Singleton.CameraDistance); MainCamera.transform.rotation = Quaternion.Euler(GameSettings.Singleton.CameraRotate); cameraPos = MainCamera.transform.position; //damp if (damping) { float x = Mathf.SmoothDamp(m_lastCacheCameraPos.x, cameraPos.x, ref xVelocity, m_currentSmoothTime, GameSettings.Singleton.m_smoothMaxSpeed); float y = Mathf.SmoothDamp(m_lastCacheCameraPos.y, cameraPos.y, ref yVelocity, m_currentSmoothTime, GameSettings.Singleton.m_smoothMaxSpeed); float z = Mathf.SmoothDamp(m_lastCacheCameraPos.z, cameraPos.z, ref zVelocity, m_currentSmoothTime, GameSettings.Singleton.m_smoothMaxSpeed); cameraPos = new Vector3(x, y, z); } Vector3 pos = CheckFloat(m_shakeObj.transform.localPosition); //shake cameraPos += pos; MainCamera.transform.position = cameraPos; m_lastCacheCameraPos = cameraPos; }
public override void ResultExpr(float[] param) { base.ResultExpr(param); if (param == null || param.Length < 5) { return; } Actor target = ActorManager.Singleton.Lookup(TargetID); if (null == target) { return; } Actor source = ActorManager.Singleton.Lookup(SourceID); if (null == source) { return; } //物理、魔法加成 float phyAdd = 0, magAdd = 0; //攻击力倍数的修正 float modifyValue = 0; //伤害修正 float damageModify = 1; SkillResultInfo info = GameTable.SkillResultTableAsset.Lookup(SkillResultID); if (null != info) { if (info.MinComboCount > 0) { if (source.Combo != null && source.Combo.TotalComboNumber >= info.MinComboCount) { phyAdd = info.PhyAttackAdd; magAdd = info.MagAttackAdd; } } if (source.Combo != null) { int comboNumber = source.Combo.TotalComboNumber; if (comboNumber > 44) { comboNumber = 44; } modifyValue = (int)(1.0f / 15.0f * comboNumber) * info.AttackModify; } if (info.ComboNum > 0) { damageModify = DamageModify; } if (info.IsWeakenComboTime) { target.OnWeakenComboTime(info.WeakenComboTime); } } {//结算 switch ((ENDamageType)param[0]) { #region enDamageFixed case ENDamageType.enDamageFixed: //固定伤害 { float damage = 0.0f; if (param[1] != 0) { //固定伤害 damage = param[1]; } if (param[2] != 0) { //百分比上下浮动 //目标的伤害系数 float woundParam = target.Props.GetProperty_Float(ENProperty.WoundParam); damage *= (woundParam != 0 ? woundParam : 1); damage *= UnityEngine.Random.Range(1 - param[2], 1 + param[2]); } DamageValue = damage; } break; #endregion #region enPhyDamageTimes case ENDamageType.enPhyDamageTimes: //物理攻击倍数伤害 { float srcAttackValue = source.Props.GetProperty_Float(ENProperty.phyattack); if (param[1] != 0) { //物理攻击力的倍数 srcAttackValue *= (param[1] + modifyValue); } srcAttackValue += phyAdd; float damage = srcAttackValue - target.Props.GetProperty_Float(ENProperty.phydefend); float min = GameTable.WorldParamTableAsset.Lookup((int)ENWorldParamIndex.enPhyAttackMinValue).FloatTypeValue; if (damage < srcAttackValue * min) { //伤害最低为物理攻击*物理攻击力的最小值 damage = srcAttackValue * min; } else { if (param[2] != 0) { //百分比上下浮动 //目标的伤害系数 float woundParam = target.Props.GetProperty_Float(ENProperty.WoundParam); damage *= (woundParam != 0 ? woundParam : 1); damage *= UnityEngine.Random.Range(1 - param[2], 1 + param[2]); } } DamageValue = damage; m_attackValue = source.Props.GetProperty_Float(ENProperty.phyattack); } break; #endregion #region enMagDamageTimes case ENDamageType.enMagDamageTimes: //魔法攻击倍数伤害 { float srcAttackValue = source.Props.GetProperty_Float(ENProperty.magattack); if (param[1] != 0) { //魔法攻击力的倍数 srcAttackValue *= (param[1] + modifyValue); } srcAttackValue += magAdd; float damage = srcAttackValue - target.Props.GetProperty_Float(ENProperty.magdefend); float min = GameTable.WorldParamTableAsset.Lookup((int)ENWorldParamIndex.enMagAttackMinValue).FloatTypeValue; if (damage < srcAttackValue * min) { //伤害最低为魔法攻击的10% damage = srcAttackValue * min; } else { if (param[2] != 0) { //百分比上下浮动 //目标的伤害系数 float woundParam = target.Props.GetProperty_Float(ENProperty.WoundParam); damage *= (woundParam != 0 ? woundParam : 1); damage *= UnityEngine.Random.Range(1 - param[2], 1 + param[2]); } } DamageValue = damage; m_attackValue = source.Props.GetProperty_Float(ENProperty.magattack); } break; #endregion #region enDamagePercent case ENDamageType.enDamagePercent: { float percent = param[1]; if (percent > 0 && percent < 1) { float damage = target.MaxHP * percent; float random = param[2]; if (random != 0) { //百分比上下浮动 //目标的伤害系数 float woundParam = target.Props.GetProperty_Float(ENProperty.WoundParam); damage *= (woundParam != 0 ? woundParam : 1); damage *= UnityEngine.Random.Range(1 - param[2], 1 + param[2]); } DamageValue = damage; } } break; #endregion #region enDamageSunder case ENDamageType.enDamageSunder: { float srcAttackValue = source.Props.GetProperty_Float(ENProperty.phyattack); srcAttackValue += phyAdd; float damage = srcAttackValue - target.Props.GetProperty_Float(ENProperty.phydefend) * param[1]; if (damage < srcAttackValue * 0.1f) { //伤害最低为物理攻击的10% damage = srcAttackValue * 0.1f; } else { if (param[2] != 0) { //百分比上下浮动 //目标的伤害系数 float woundParam = target.Props.GetProperty_Float(ENProperty.WoundParam); damage *= (woundParam != 0 ? woundParam : 1); damage *= UnityEngine.Random.Range(1 - param[2], 1 + param[2]); } } DamageValue = damage; m_attackValue = source.Props.GetProperty_Float(ENProperty.phyattack); } break; #endregion #region enDistancePhyDamageTimes case ENDamageType.enPhyDamageDistance: { SkillInfo skillInfo = GameTable.SkillTableAsset.Lookup(SkillID); if (skillInfo == null) { return; } float range = 0; float d = ActorTargetManager.GetTargetDistance(source.RealPos, target.RealPos); if (d < param[1]) { range = param[1]; } else if (d > param[2]) { range = param[2]; } else { range = d; } float attackValue = source.Props.GetProperty_Float(ENProperty.phyattack); float defend = target.Props.GetProperty_Float(ENProperty.phydefend); DamageValue = attackValue * (range / skillInfo.AttackDistance) * param[3] - defend; float min = GameTable.WorldParamTableAsset.Lookup((int)ENWorldParamIndex.enPhyAttackMinValue).FloatTypeValue; if (DamageValue < attackValue * min) { DamageValue = attackValue * min; } } break; #endregion #region enDistanceMagDamageTimes case ENDamageType.enMagDamageDistance: { SkillInfo skillInfo = GameTable.SkillTableAsset.Lookup(SkillID); if (skillInfo == null) { return; } float range = 0; float d = ActorTargetManager.GetTargetDistance(source.RealPos, target.RealPos); if (d < param[1]) { range = param[1]; } else if (d > param[2]) { range = param[2]; } else { range = d; } float attackValue = source.Props.GetProperty_Float(ENProperty.magattack); float defend = target.Props.GetProperty_Float(ENProperty.magdefend); DamageValue = attackValue * (range / skillInfo.AttackDistance) * param[3] - defend; float min = GameTable.WorldParamTableAsset.Lookup((int)ENWorldParamIndex.enMagAttackMinValue).FloatTypeValue; if (DamageValue < attackValue * min) { DamageValue = attackValue * min; } } break; #endregion default: break; } DamageResultType = (ENDamageResultType)param[4]; if (DamageValue != 0) { DamageValue *= damageModify; if (UnityEngine.Random.Range(0.0f, 1f) < source.Props.GetProperty_Float(ENProperty.crit)) {//暴击 m_isCrit = true; DamageValue *= (source.Props.GetProperty_Float(ENProperty.critParam)); } } else { Debug.LogWarning("damage result is error, damage is " + DamageValue.ToString() + ", source actor id is " + source.ID.ToString()); } } }
void CheckTarget(Actor target) { if (SkillTargetIDList.Contains(target.ID)) { return; } if (target.IsDead) { return; } float d = ActorTargetManager.GetTargetDistance(CurrentActor.RealPos, target.RealPos); if (m_skillInfo.AttackDistance >= d) { switch ((ENTargetType)m_skillInfo.TargetType) { case ENTargetType.enEnemy: { if (!ActorTargetManager.IsEnemy(CurrentActor, target)) { return; } } break; case ENTargetType.enFriendly: { if (!ActorTargetManager.IsFriendly(CurrentActor, target)) { return; } } break; case ENTargetType.enSelf: { if (CurrentActor != target) { return; } } break; case ENTargetType.enNullTarget: break; case ENTargetType.enInteraction: { if (!ActorTargetManager.IsInteractionally(CurrentActor, target)) { return; } } break; case ENTargetType.enFriendlyAndSelf: { if (!ActorTargetManager.IsFriendly(CurrentActor, target) && CurrentActor != target) { return; } } break; default: return; } if (d < m_closestDistance) { m_closestTargetID = target.ID; } } }
//战斗托管时组建targetList void CheckAutoBattleTarget(ENTargetType type, Actor target) { if (target.Type == ActorType.enNPC) { NPC npc = target as NPC; if (npc.GetNpcType() == ENNpcType.enBlockNPC || npc.GetNpcType() == ENNpcType.enFunctionNPC) { return; } } else if (target.Type == ActorType.enMain) { if (target.IsActorExit) { return; } } if (target.IsDead) { return; } switch (type) { case ENTargetType.enEnemy: { if (!ActorTargetManager.IsEnemy(Owner, target)) { return; } } break; case ENTargetType.enFriendly: { if (!ActorTargetManager.IsFriendly(Owner, target)) { return; } } break; case ENTargetType.enSelf: { if (Owner != target) { return; } } break; case ENTargetType.enNullTarget: break; case ENTargetType.enFriendlyAndSelf: { if (!ActorTargetManager.IsFriendly(Owner, target) && Owner != target) { return; } } break; default: break; } float distance = ActorTargetManager.GetTargetDistance(Owner.RealPos, target.RealPos); if (distance < m_minDistance) { m_minDistance = distance; m_minActor = target; } m_targetIDList.Add(target.ID); }
void CheckActorDistance(Actor target, BuffResultInfo info) { if (target.Type == ActorType.enNPC) { NPC npc = target as NPC; if (npc.GetNpcType() == ENNpcType.enBlockNPC || npc.GetNpcType() == ENNpcType.enFunctionNPC) { return; } } else if (target.Type == ActorType.enMain) { if (target.IsActorExit) { return; } } if (target.IsDead) { return; } switch ((ENTargetType)info.ParamList[2])//判断技能目标类型 { case ENTargetType.enEnemy: { if (!ActorTargetManager.IsEnemy(m_selfActor, target)) { return; } } break; case ENTargetType.enFriendly: { if (!ActorTargetManager.IsFriendly(m_selfActor, target)) { return; } } break; case ENTargetType.enSelf: { if (m_selfActor != target) { return; } } break; case ENTargetType.enNullTarget: break; case ENTargetType.enFriendlyAndSelf: { if (!ActorTargetManager.IsFriendly(m_selfActor, target) && m_selfActor != target) { return; } } break; default: break; } float distance = ActorTargetManager.GetTargetDistance(m_selfActor.RealPos, target.RealPos); bool tmpFlag = true; if (distance <= info.ParamList[1])//判断光环半径 { foreach (Buff tmpBuf in target.MyBuffControl.BuffList) { if (tmpBuf.BuffID == (int)info.ParamList[2]) { tmpFlag = false; } } if (tmpFlag) { IResult addBuffResult = BattleFactory.Singleton.CreateResult(ENResult.AddBuff, m_selfActor.ID, target.ID, 0, 0, new float[1] { info.ParamList[3] }); if (addBuffResult != null) { addBuffResult.ResultExpr(new float[1] { info.ParamList[3] }); //添加技能ID BattleFactory.Singleton.DispatchResult(addBuffResult); } } } else { tmpFlag = false; foreach (Buff tmpBuf in target.MyBuffControl.BuffList) { if (tmpBuf.BuffID == info.ParamList[2]) { tmpFlag = true; } } if (tmpFlag) { IResult rbResult = BattleFactory.Singleton.CreateResult(ENResult.RemoveBuff, m_selfActor.ID, target.ID, 0, 0, new float[2] { (float)ResultRemoveBuff.ENRemoveBuffType.enBuffID, info.ParamList[3] }); if (rbResult != null) { rbResult.ResultExpr(new float[2] { (float)ResultRemoveBuff.ENRemoveBuffType.enBuffID, info.ParamList[3] }); BattleFactory.Singleton.DispatchResult(rbResult); } } } }
bool LookupTarget(SkillInfo info, out Actor skillTarget, out float closestDistance) { skillTarget = null; closestDistance = float.MaxValue; //if (info.SkillTableInfo.SkillEffectType == (int)ENSkillEffectType.enRestore) //{ // return false; //} if (info.TargetType == (int)ENTargetType.enNullTarget) {//不需要目标就能释放的技能 return(true); } //首先查看是否可对当前目标释放 Actor curTarget = ActorManager.Singleton.Lookup(m_curTargetID); if (curTarget != null && !curTarget.IsDead) { float distance = ActorTargetManager.GetTargetDistance(Owner.MainPos, curTarget.MainPos); if (distance >= info.LeastAttackDistance) {//最小攻击距离外 switch ((ENTargetType)info.TargetType) { case ENTargetType.enEnemy: { if (ActorTargetManager.IsEnemy(Owner, curTarget)) { skillTarget = curTarget; return(true); } } break; case ENTargetType.enFriendly: { if (ActorTargetManager.IsFriendly(Owner, curTarget)) { skillTarget = curTarget; return(true); } } break; case ENTargetType.enSelf: { if (Owner == curTarget) { skillTarget = curTarget; return(true); } } break; case ENTargetType.enNullTarget: break; case ENTargetType.enFriendlyAndSelf: { if (ActorTargetManager.IsFriendly(Owner, curTarget) && Owner != curTarget) { skillTarget = curTarget; return(true); } } break; default: break; } } } //不可以对当前目标释放,查找距离自己最近的 for (int i = 0; i < m_targetIDList.Count; ++i) { Actor target = ActorManager.Singleton.Lookup(m_targetIDList[i]); if (target == null) { continue; } if (target.IsDead) { continue; } float distance = ActorTargetManager.GetTargetDistance(Owner.MainPos, target.MainPos); if (distance < info.LeastAttackDistance) {//最小攻击距离内 continue; } switch ((ENTargetType)info.TargetType) { case ENTargetType.enEnemy: { if (!ActorTargetManager.IsEnemy(Owner, target)) { continue; } } break; case ENTargetType.enFriendly: { if (!ActorTargetManager.IsFriendly(Owner, target)) { continue; } } break; case ENTargetType.enSelf: { if (Owner != target) { continue; } } break; case ENTargetType.enNullTarget: break; case ENTargetType.enFriendlyAndSelf: { if (!ActorTargetManager.IsFriendly(Owner, target) && Owner != target) { continue; } } break; default: break; } if (m_firstTargetType != ActorType.enNone) { //优先选择目标条件成立 if (target.Type == m_firstTargetType) { //是优先选择的目标类型 if (skillTarget == null) { skillTarget = target; closestDistance = distance; } else { if (skillTarget.Type == m_firstTargetType) {//已有优先目标,进行比较,取近的 if (distance < closestDistance) { skillTarget = target; closestDistance = distance; } } else { skillTarget = target; closestDistance = distance; } } } else { if (skillTarget == null) { skillTarget = target; closestDistance = distance; } else { if (skillTarget.Type != m_firstTargetType) { if (distance < closestDistance) { skillTarget = target; closestDistance = distance; } } } } } else { if (distance < info.AttackDistance) { skillTarget = target; break; } else { if (distance < closestDistance) { skillTarget = target; closestDistance = distance; } } } } return(skillTarget != null); }
//释放连接技或特殊技 bool FireConnectOrSpecialSkill() { if (Self.WTF != null && Self.WTF.IsWillBurning) {//意志燃烧中 int randValue = UnityEngine.Random.Range(0, (int)ENRandType.enCount); switch ((ENRandType)randValue) { case ENRandType.enHaveTargetSkill: { //指定目标的技能 foreach (var item in Self.SkillBag) { if (!item.IsCanFire(Self)) { continue; } if (item.SkillTableInfo.TargetType == (int)ENTargetType.enNullTarget) { //无目标技能 continue; } if ((int)ENSkillConnectionType.enConnect == item.SkillTableInfo.SkillConnectionType || (int)ENSkillConnectionType.enSpecial == item.SkillTableInfo.SkillConnectionType) { //连接技和特殊技 if (ActionTryFireSkill(item.SkillTableInfo.ID)) { //释放技能成功 return(true); } } } } break; case ENRandType.enNullTargetSkill: { //无目标的技能 float d = ActorTargetManager.GetTargetDistance(Self.RealPos, Self.CurrentTarget.RealPos); if (Self.CurrentTableInfo.AutoAttackRange >= d) { //自动攻击范围内 foreach (var item in Self.SkillBag) { if (!item.IsCanFire(Self)) { continue; } if (item.SkillTableInfo.TargetType != (int)ENTargetType.enNullTarget) { //不是无目标技能 continue; } if (ActionTryFireSkill(item.SkillTableInfo.ID)) { //释放技能成功 return(true); } } } } break; case ENRandType.enBuffSkill: { //buff技能 Actor friendActor = null; int r = UnityEngine.Random.Range(0, 2); if (r == 0) { friendActor = Self; } else { friendActor = MainActor; } foreach (var item in Self.SkillBag) { if (!item.IsCanFire(Self)) { continue; } if (item.SkillTableInfo.SkillEffectType != (int)ENSkillEffectType.enBuff) { //不是buff技能 continue; } if (ActionTryAttack(item.SkillTableInfo.ID, friendActor)) { //释放技能成功 return(true); } } } break; case ENRandType.enRestoreSkill: { //恢复技能 Actor friendActor = null; int r = UnityEngine.Random.Range(0, 2); if (r == 0) { friendActor = Self; } else { friendActor = MainActor; } foreach (var item in Self.SkillBag) { if (!item.IsCanFire(Self)) { continue; } if (item.SkillTableInfo.SkillEffectType != (int)ENSkillEffectType.enRestore) { //不是恢复技能 continue; } if (ActionTryAttack(item.SkillTableInfo.ID, friendActor)) { //释放技能成功 return(true); } } } break; } } return(false); }
void CheckTarget(Actor target) { if (target.Type == ActorType.enNPC) { NPC npc = target as NPC; if (npc.GetNpcType() == ENNpcType.enBlockNPC || npc.GetNpcType() == ENNpcType.enFunctionNPC) { return; } } else if (target.Type == ActorType.enMain) { if (target.IsActorExit) { return; } } if (target.IsDead) { return; } switch (m_searchTargetType) { case ENTargetType.enEnemy: { if (!ActorTargetManager.IsEnemy(Owner, target)) { return; } } break; case ENTargetType.enFriendly: { if (!ActorTargetManager.IsFriendly(Owner, target)) { return; } } break; case ENTargetType.enSelf: { if (Owner != target) { return; } } break; case ENTargetType.enNullTarget: break; case ENTargetType.enFriendlyAndSelf: { if (!ActorTargetManager.IsFriendly(Owner, target) && Owner != target) { return; } } break; default: break; } float range = 0; if (Owner.Type == ActorType.enMain || Owner.Type == ActorType.enSwitch || Owner.Type == ActorType.enFollow) { Player self = Owner as Player; range = self.CurrentTableInfo.AttackRange; if (range <= 0) { return; } range = m_searchTargetRange != 0 ? m_searchTargetRange : range; } else if (Owner.Type == ActorType.enNPC) { NPC npc = Owner as NPC; if (npc.AttackRange <= 0) { return; } range = m_searchTargetRange != 0 ? m_searchTargetRange : npc.AttackRange; } float distance = ActorTargetManager.GetTargetDistance(Owner.RealPos, target.RealPos); if (range >= distance) { if (distance < m_minDistance) { m_minDistance = distance; m_minActor = target; } m_targetIDList.Add(target.ID); } }
public override void Update() { base.Update(); if (Self.IsActorExit) { return; //当前角色离场 } //TimeToRelive(); ReliveUI(); #region Unlock if (!Self.CurrentTargetIsDead) {//判断距离 清除目标 float distance = ActorTargetManager.GetTargetDistance(Self.MainPos, Self.CurrentTarget.MainPos); if (distance > Self.CurrentTableInfo.UnlockRange) { Self.CurrentTarget = null; Self.DamageSource = null; } } #endregion CheckAllSkill(); //检测可释放技能 if (Self.CurrentCmd == null) { //当前没有命令 MoveAction action = Self.ActionControl.LookupAction(ActorAction.ENType.enMoveAction) as MoveAction; if ((action == null || action.IsStopMove) && !Self.ActionControl.IsActionRunning(ActorAction.ENType.enAttackAction) && !Self.ActionControl.IsActionRunning(ActorAction.ENType.enRollAction)) { //不在移动、攻击、翻滚等位移动作中 if (!Self.CurrentTargetIsDead) { //当前目标没死 float distance = ActorTargetManager.GetTargetDistance(Self.RealPos, Self.CurrentTarget.RealPos); if (Self.CurrentTableInfo.AutoAttackRange > distance) {//当前目标在自动攻击范围内 //Self.FireNormalSkill(); return; } } else { if (m_isAutoAttack) { m_autoAttackInterval -= Time.deltaTime; if (m_autoAttackInterval < 0) { GetRangeTargetList(ENTargetType.enEnemy, Self.CurrentTableInfo.AutoAttackRange); if (m_targetIDList.Count > 0) { Self.TargetManager.CurrentTarget = m_minActor; Self.CurrentCmd = new Player.Cmd(Player.ENCmdType.enLoopNormalAttack); Self.CurrentCmd.m_skillID = Self.NormalSkillList[0]; return; } } } } //自动反击 if (m_lastActionTime == 0) { m_lastActionTime = Time.time; } if (!m_isCounterattack && Time.time - m_lastActionTime > GameSettings.Singleton.m_autoCounterattack) {//距离最后一次位移动作 已超过3秒 可以反击 m_isCounterattack = false; } } if (m_isCounterattack) {//可以反击 if (Self.DamageTime > m_lastActionTime + GameSettings.Singleton.m_autoCounterattack) { if (Self.DamageSource != null && !Self.DamageSource.IsDead && ActorTargetManager.IsEnemy(Self, Self.DamageSource)) { if (m_counterSkillRange == 0) { SkillInfo info = GameTable.SkillTableAsset.Lookup(Self.NormalSkillList[0]); m_counterSkillRange = info.AttackDistance; } Vector3 distance = Owner.RealPos - Self.DamageSource.RealPos; distance.y = 0; if (distance.magnitude > m_counterSkillRange) {//不在攻击范围内 //向技能目标移动 ActionMoveTo(Self.DamageSource.RealPos); } else {//在攻击范围内 //释放技能 if (ActionTryAttack(Self.NormalSkillList[0], Self.DamageSource)) { m_curTargetID = Self.DamageSource.ID; Self.CurrentTarget = ActorManager.Singleton.Lookup(m_curTargetID); m_lastActionTime = 0; m_isCounterattack = false; return; } } } } } } else { MainPlayer.Cmd cmd = Self.CurrentCmd; if (cmd.m_type != Player.ENCmdType.enSkill && cmd.m_type != Player.ENCmdType.enLoopNormalAttack) {//取消自动攻击 m_isAutoAttack = false; } //最后一次动作的时间 m_lastActionTime = 0; //清除自动反击 m_isCounterattack = false; if (cmd.m_type != Player.ENCmdType.enSkill) {//取消技能高亮 DelSkillHighlight(); } m_autoAttackInterval = GameSettings.Singleton.m_autoAttackInterval; if (!IsCmdExecute()) {//命令不允许执行 Self.CurrentCmd = null; return; } m_curTargetID = 0; if (!Self.CurrentTargetIsDead) { m_curTargetID = Self.CurrentTarget.ID; } switch (cmd.m_type) { case Player.ENCmdType.enMove: { // [8/3/2015 tgame] if (cmd.m_isMoveByNoAStar) { if (ActionMoveToNotAStar(cmd.m_moveTargetPos)) { //点击地面特效 Self.IsMoveAfterSwitch = false; Self.CurrentCmd = null; } } else { if (ActionMoveTo(cmd.m_moveTargetPos)) { //点击地面特效 Self.IsMoveAfterSwitch = false; Self.CurrentCmd = null; } } } break; case Player.ENCmdType.enStopMove: { MoveAction ac = Self.ActionControl.LookupAction(ActorAction.ENType.enMoveAction) as MoveAction; if (ac != null) { Self.ActionControl.RemoveAction(ActorAction.ENType.enMoveAction); } } break; case Player.ENCmdType.enRoll: { RollAction rollAction = Self.ActionControl.AddAction(ActorAction.ENType.enRollAction) as RollAction; if (rollAction != null) { rollAction.Init(cmd.m_moveTargetPos); Self.CurrentCmd = null; } } break; case Player.ENCmdType.enSwitchActor: { if (!m_isAttacking) { if (Self.ActionControl.IsActionRunning(ActorAction.ENType.enAttackAction)) { if (ActorManager.Singleton.m_switchCDTotal > 0) { //cd中,继续攻击 Self.FireNormalSkill(); return; } m_isAttacking = true; } } if (ActorManager.Singleton.SwitchMainActor(false, m_isAttacking)) { Self.CurrentCmd = null; m_isAttacking = false; } } break; case Player.ENCmdType.enSkill: { int skillID = cmd.m_skillID; Actor.ActorSkillInfo info = Self.SkillBag.Find(item => item.SkillTableInfo.ID == skillID); if (IsFireSkill(skillID)) { GetRangeTargetList((ENTargetType)info.SkillTableInfo.TargetType, Self.CurrentTableInfo.AttackRange, Self.m_firstTargetType); if (ActionTryFireSkill(skillID)) { m_isAutoAttack = false; m_lastSkillID = skillID; DelSkillHighlight(); Actor target = ActorManager.Singleton.Lookup(m_curTargetID); if (target != null && ActorTargetManager.IsEnemy(Self, target)) { //只对仇人进行循环普攻 Self.CurrentTarget = target; Self.CurrentCmd.m_skillID = Self.NormalSkillList[0]; Self.CurrentCmd.m_type = Player.ENCmdType.enStop; //enLoopNormalAttack; } else { Self.CurrentCmd = null; } } else { if (m_targetIDList.Count == 0) { DelSkillHighlight(); Self.CurrentCmd = null; } } } else { GetRangeTargetList((ENTargetType)info.SkillTableInfo.TargetType, Self.CurrentTableInfo.AttackRange); if (m_targetIDList.Count != 0 && skillID != m_highlightSkillID) { //技能高亮的通知 AddSkillHighlight(); m_highlightSkillID = skillID; } } } break; case Player.ENCmdType.enLoopNormalAttack: { int skillID = Self.CurrentCmd.m_skillID; if (Self.CurrentTargetIsDead) { //循环攻击时 必须要有目标 目标不能死亡 Self.CurrentCmd = null; return; } if (IsFireSkill(skillID)) { if (ActionTryFireSkill(skillID)) { m_lastSkillID = skillID; } } } break; default: break; } } }
bool StartFollow() { mForceMovePos = Vector3.zero; float distance = ActorTargetManager.GetTargetDistance(Self.RealPos, MainActor.RealPos); if (distance > StartFollowDistance) { // MoveAction action = MainActor.ActionControl.LookupAction(ActorAction.ENType.enMoveAction) as MoveAction; // if (action != null && action.mRealSpeed != 0) // { // mForceMovePos = action.mLastMovePos; // } // else // { // if (mForceMovePos == Vector3.zero) // { // mForceMovePos = MainActor.MainPos; // } // } mForceMovePos = GetPosGroundPos(MainActor.MainPos); if (NormalForceMove(distance, mForceMovePos)) { ActionForwardTo(MainActor.ID); return(true); } else if (forceMove(mForceMovePos)) { ActionForwardTo(MainActor.ID); return(true); } else { if (MainActor.CurrentTargetIsDead || Self.CurrentTargetIsDead) {//主控角色没有目标 或 同伴没有目标 ActionMoveTo(MainActor.RealPos); return(true); } } // if (!SDungeonsMgr.Singleton.QuickFindPath(Self.MainPos, MainActor.MainPos) || distance > ForceMoveDistance) // {//跟主控角色之间不能寻路或者距离过大 // if (mDisAbleFindPathTime == 0) // {//如果不能寻路的时间为0说明这次是第一次不能寻路,为不能寻路的时间赋值 // mDisAbleFindPathTime = Time.time; // } // if (Time.time - mDisAbleFindPathTime > MaxFindPathTime) // { // TeleportAction teleportAction = Self.ActionControl.AddAction(ActorAction.ENType.enTeleportAction) as TeleportAction; // if (teleportAction != null) // { // teleportAction.Init(mForceMovePos); // } // //Self.ForceMoveToPosition(mForceMovePos); // mDisAbleFindPathTime = 0; // return true; // } // } // else // { // mDisAbleFindPathTime = 0; // if (MainActor.CurrentTargetIsDead || Self.CurrentTargetIsDead) // {//主控角色没有目标 或 同伴没有目标 // ActionMoveTo(MainActor.RealPos); // return true; // } // } } // if (ForceMove()) // {//瞬移 // return true; // } // else if (FollowMainActor()) // {//跟随 // return true; // } return(false); }
private void CheckTarget(Actor target) { Actor CurrentActor = this as Actor; if (CurrentActor == target) { return; } if (target.IsDead) { return; } if (!IsCanSelectTarget(target)) { return; } if (!ActorTargetManager.IsEnemy(CurrentActor, target)) { if (target.Type == ActorType.enNPC) { NPC npc = target as NPC; if (npc.GetNpcType() != ENNpcType.enBoxNPC) { return; } } else { return; } } float distance = ActorTargetManager.GetTargetDistance(CurrentActor.RealPos, target.RealPos); //Vector3 targetDirection = target.RealPos - CurrentActor.RealPos; //targetDirection.y = 0.0f; WorldParamInfo info = GameTable.WorldParamTableAsset.Lookup((int)ENWorldParamIndex.enChangeTargetDistance); if (info == null) { return; } //if (targetDirection.magnitude > info.FloatTypeValue) if (distance > info.FloatTypeValue) { return; } //targetDirection.Normalize(); //Vector3 direction = CurrentActor.MainObj.transform.forward; //float yRot = Vector3.Angle(targetDirection, direction); //if (yRot < 360.0f) { CurrentActor.TargetManager.AddTarget(target); //if (yRot < m_minRot) if (distance < m_minRot) { if (1 == CurrentActor.TargetManager.GetTargetListValue(target)) { return; } //m_minRot = yRot; m_minRot = distance; CurrentActor.TargetManager.CurrentTarget = target; } } }