public void NotifyNpcRun(NpcInfo npc) { npc.GetActualProperty().SetMoveSpeed(Operate_Type.OT_Absolute, npc.GetBaseProperty().RunSpeed); npc.GetMovementStateInfo().MovementMode = MovementMode.HighSpeed; if (null != OnNpcMove) { OnNpcMove(npc); } }
private void PursuitHandler(NpcInfo npc, AiCommandDispatcher aiCmdDispatcher, long deltaTime) { if (!CanAiControl(npc)) { npc.GetMovementStateInfo().IsMoving = false; return; } NpcAiStateInfo info = npc.GetAiStateInfo(); AiData_Npc_ActionDrive data = GetAiData(npc); if (null != data) { CharacterInfo target = AiLogicUtility.GetLivingCharacterInfoHelper(npc, info.Target); if (null != target) { float dist = (float)npc.GetActualProperty().AttackRange; float distGoHome = (float)npc.GohomeRange; Vector3 targetPos = target.GetMovementStateInfo().GetPosition3D(); Vector3 srcPos = npc.GetMovementStateInfo().GetPosition3D(); float powDist = Geometry.DistanceSquare(srcPos, targetPos); float powDistToHome = Geometry.DistanceSquare(srcPos, info.HomePos); // 遇敌是播放特效, 逗留两秒。 if (data.WaitTime <= npc.MeetEnemyStayTime) { if (!data.HasMeetEnemy) { NotifyNpcMeetEnemy(npc, Animation_Type.AT_Attack); data.HasMeetEnemy = true; } TrySeeTarget(npc, target); data.WaitTime += deltaTime; return; } // 走向目标1.5秒 if (data.MeetEnemyWalkTime < npc.MeetEnemyWalkTime) { data.MeetEnemyWalkTime += deltaTime; NotifyNpcWalk(npc); info.Time += deltaTime; if (info.Time > m_IntervalTime) { info.Time = 0; AiLogicUtility.PathToTargetWithoutObstacle(npc, data.FoundPath, targetPos, m_IntervalTime, true, this); } return; } ChangeToState(npc, (int)AiStateId.ActionDrive); } else { ChangeToState(npc, (int)AiStateId.Idle); } } }
private bool IsAiActionSatifyWithOutProbability(NpcInfo npc, CharacterInfo target, AiActionInfo aiActionInfo) { Vector3 targetPos = target.GetMovementStateInfo().GetPosition3D(); Vector3 srcPos = npc.GetMovementStateInfo().GetPosition3D(); float dist = Geometry.Distance(srcPos, targetPos); if (aiActionInfo.IsSatifyCD(TimeUtility.GetServerMilliseconds()) && aiActionInfo.IsSatifyDis(dist) && aiActionInfo.IsSatisfySelfHp(npc.Hp, npc.GetActualProperty().HpMax) && aiActionInfo.IsSatisfyTargetHp(target.Hp, target.GetActualProperty().HpMax) && aiActionInfo.IsSatifyUser(npc)) { return(true); } return(false); }
private void PursuitHandler(NpcInfo npc, AiCommandDispatcher aiCmdDispatcher, long deltaTime) { if (!CanAiControl(npc)) { npc.GetMovementStateInfo().IsMoving = false; return; } NpcAiStateInfo info = npc.GetAiStateInfo(); AiData_Demo_Melee data = GetAiData(npc); if (null != data) { CharacterInfo target = AiLogicUtility.GetLivingCharacterInfoHelper(npc, info.Target); if (null != target) { float dist = (float)npc.GetActualProperty().AttackRange; float distGoHome = (float)npc.GohomeRange; Vector3 targetPos = target.GetMovementStateInfo().GetPosition3D(); Vector3 srcPos = npc.GetMovementStateInfo().GetPosition3D(); float powDist = Geometry.DistanceSquare(srcPos, targetPos); float powDistToHome = Geometry.DistanceSquare(srcPos, info.HomePos); if (powDist < dist * dist) { npc.GetMovementStateInfo().IsMoving = false; info.Time = 0; data.Time = 0; ChangeToState(npc, (int)AiStateId.Combat); NotifyNpcMove(npc); } else { info.Time += deltaTime; if (info.Time > m_IntervalTime) { info.Time = 0; AiLogicUtility.PathToTargetWithoutObstacle(npc, data.FoundPath, targetPos, m_IntervalTime, true, this); } } } } }
private void MoveNpc(NpcInfo obj, long deltaTime) { if (obj.IsHaveStateFlag(CharacterState_Type.CST_Sleep) || obj.IsHaveStateFlag(CharacterState_Type.CST_FixedPosition) || null != obj.ControllerObject) { return; } MovementStateInfo msi = obj.GetMovementStateInfo(); //npc执行移动时忽略阻挡与避让,这些行为由ai模块在规划其路径时执行。 if (!obj.IsDead() && obj.CanMove && msi.IsMoving && !msi.IsSkillMoving) { Vector3 pos = msi.GetPosition3D(); float cos_angle = (float)msi.MoveDirCosAngle; float sin_angle = (float)msi.MoveDirSinAngle; float speed = (float)obj.GetActualProperty().MoveSpeed *(float)obj.VelocityCoefficient; float distance = (speed * (float)(int)deltaTime) / 1000.0f; //LogSystem.Debug("MovementSystem npc:{0} speed:{1} deltaTime:{2} distance:{3}", obj.GetId(), speed, deltaTime, distance); float x = 0, y = 0; if (msi.CalcDistancSquareToTarget() < distance * distance) { x = msi.TargetPosition.X; y = msi.TargetPosition.Z; AdjustPosition(obj.SpatialSystem, ref x, ref y); Vector2 newPos = new Vector2(x, y); msi.SetPosition2D(newPos); } else { float len = pos.Length(); y = pos.Z + distance * cos_angle; x = pos.X + distance * sin_angle; AdjustPosition(obj.SpatialSystem, ref x, ref y); Vector2 newPos = new Vector2(x, y); msi.SetPosition2D(newPos); } } }
public void OnGfxSimulateMove(int id) { NpcInfo npc = WorldSystem.Instance.GetCharacterById(id) as NpcInfo; if (npc == null) { return; } if (npc.SummonOwnerId < 0) { return; } CharacterInfo owner = WorldSystem.Instance.GetCharacterById(npc.SummonOwnerId); if (owner == null) { return; } CharacterView owner_view = EntityManager.Instance.GetCharacterViewById(npc.SummonOwnerId); if (owner_view == null) { return; } npc.GetActualProperty().SetMoveSpeed(Operate_Type.OT_Absolute, owner.GetActualProperty().MoveSpeed); npc.VelocityCoefficient = owner.VelocityCoefficient; npc.Combat2IdleSkill = owner.Combat2IdleSkill; npc.Combat2IdleTime = owner.Combat2IdleTime; npc.Idle2CombatWeaponMoves = owner.Idle2CombatWeaponMoves; List <SkillInfo> skills = owner.GetSkillStateInfo().GetAllSkill(); npc.GetSkillStateInfo().AddSkill(new SkillInfo(npc.Combat2IdleSkill)); foreach (SkillInfo si in skills) { npc.GetSkillStateInfo().AddSkill(new SkillInfo(si.SkillId)); } npc.SkillController.Init(); npc.IsSimulateMove = true; }
private void PursuitHandler(NpcInfo npc, AiCommandDispatcher aiCmdDispatcher, long deltaTime) { if (!CanAiControl(npc)) { npc.GetMovementStateInfo().IsMoving = false; return; } NpcAiStateInfo info = npc.GetAiStateInfo(); AiData_Npc_CommonMelee data = GetAiData(npc); if (null != data) { CharacterInfo target = AiLogicUtility.GetLivingCharacterInfoHelper(npc, info.Target); if (null != target) { float dist = (float)npc.GetActualProperty().AttackRange; float distGoHome = (float)npc.GohomeRange; Vector3 targetPos = target.GetMovementStateInfo().GetPosition3D(); Vector3 srcPos = npc.GetMovementStateInfo().GetPosition3D(); float powDist = Geometry.DistanceSquare(srcPos, targetPos); float powDistToHome = Geometry.DistanceSquare(srcPos, info.HomePos); // 遇敌是播放特效, 逗留两秒。 if (data.WaitTime <= npc.MeetEnemyStayTime) { if (!data.HasMeetEnemy) { NotifyNpcMeetEnemy(npc, Animation_Type.AT_Attack); data.HasMeetEnemy = true; } TrySeeTarget(npc, target); data.WaitTime += deltaTime; return; } // 走向目标1.5秒 if (data.MeetEnemyWalkTime < npc.MeetEnemyWalkTime) { data.MeetEnemyWalkTime += deltaTime; NotifyNpcWalk(npc); info.Time += deltaTime; if (info.Time > m_IntervalTime) { info.Time = 0; if (!npc.UnityPathFinding) { AiLogicUtility.PathToTargetWithoutObstacle(npc, data.FoundPath, targetPos, m_IntervalTime, true, this); } else { if (!npc.PathFindingFinished) { GfxSystem.NpcCommonMeleePathToTarget(npc, targetPos); ChangeToState(npc, (int)AiStateId.PathFinding); } else { npc.PathFindingFinished = false; AiLogicUtility.PathToTargetWithoutObstacle(npc, data.FoundPath, targetPos, m_IntervalTime, true, this); } } } return; } // 大于攻击距离 跑向目标 if (powDist > m_AttackRange * m_AttackRange && 0 == data.CurAiAction) { npc.IsTaunt = false; NotifyNpcRun(npc); info.Time += deltaTime; if (info.Time > m_IntervalTime) { info.Time = 0; if (!npc.UnityPathFinding) { AiLogicUtility.PathToTargetWithoutObstacle(npc, data.FoundPath, targetPos, m_IntervalTime, true, this); } else { if (!npc.PathFindingFinished) { GfxSystem.NpcCommonMeleePathToTarget(npc, targetPos); ChangeToState(npc, (int)AiStateId.PathFinding); } else { npc.PathFindingFinished = false; AiLogicUtility.PathToTargetWithoutObstacle(npc, data.FoundPath, targetPos, m_IntervalTime, true, this); } } } } else { //小于攻击距离 if (data.CurAiAction == (int)AiAction.NONE) { npc.GetMovementStateInfo().IsMoving = false; NotifyNpcMove(npc); data.CurAiAction = (int)GetNextAction(); } switch (data.CurAiAction) { case (int)AiAction.SKILL: if (0 >= data.SkillToCast) { data.SkillToCast = GetCanCastSkillId(npc, (float)Math.Sqrt(powDist)); } if (0 >= data.SkillToCast || !AiLogicUtility.CanCastSkill(npc, data.SkillToCast, target)) { info.Time += deltaTime; if (info.Time > m_IntervalTime) { info.Time = 0; NotifyNpcRun(npc); if (!npc.UnityPathFinding) { AiLogicUtility.PathToTargetWithoutObstacle(npc, data.FoundPath, targetPos, m_IntervalTime, true, this); } else { if (!npc.PathFindingFinished) { GfxSystem.NpcCommonMeleePathToTarget(npc, targetPos); ChangeToState(npc, (int)AiStateId.PathFinding); } else { npc.PathFindingFinished = false; AiLogicUtility.PathToTargetWithoutObstacle(npc, data.FoundPath, targetPos, m_IntervalTime, true, this); } } } } else { npc.GetMovementStateInfo().IsMoving = false; NotifyNpcMove(npc); if (TryCastSkill(npc, data.SkillToCast, target)) { data.CurAiAction = 0; data.SkillToCast = -1; } } break; case (int)AiAction.STAND: data.ChaseStandTime += deltaTime; TrySeeTarget(npc, target); if (data.ChaseStandTime > m_ChaseWalkMaxTime) { data.ChaseStandTime = 0; data.CurAiAction = 0; } break; case (int)AiAction.TAUNT: npc.GetMovementStateInfo().IsMoving = false; NotifyNpcMove(npc); npc.IsTaunt = true; data.TauntTime += deltaTime; TrySeeTarget(npc, target); if (data.TauntTime > m_TauntTime) { npc.IsTaunt = false; data.TauntTime = 0; data.CurAiAction = 0; } break; case (int)AiAction.WALK: data.ChaseWalkTime += deltaTime; info.Time += deltaTime; if (info.Time > m_IntervalTime) { info.Time = 0; NotifyNpcWalk(npc); if (!npc.UnityPathFinding) { AiLogicUtility.PathToTargetWithoutObstacle(npc, data.FoundPath, targetPos, m_IntervalTime, true, this); } else { if (!npc.PathFindingFinished) { GfxSystem.NpcCommonMeleePathToTarget(npc, targetPos); ChangeToState(npc, (int)AiStateId.PathFinding); } else { npc.PathFindingFinished = false; AiLogicUtility.PathToTargetWithoutObstacle(npc, data.FoundPath, targetPos, m_IntervalTime, true, this); } } } if (data.ChaseWalkTime > m_ChaseStandMaxTime) { data.ChaseWalkTime = 0; data.CurAiAction = 0; } break; } } } else { NotifyNpcTargetChange(npc); npc.GetMovementStateInfo().IsMoving = false; NotifyNpcMove(npc); info.Time = 0; ChangeToState(npc, (int)AiStateId.Idle); } } }
private void PursuitHandler(NpcInfo npc, AiCommandDispatcher aiCmdDispatcher, long deltaTime) { if (npc.IsDead() || npc.GetSkillStateInfo().IsSkillActivated()) { npc.GetMovementStateInfo().IsMoving = false; NotifyNpcMove(npc); return; } NpcAiStateInfo info = npc.GetAiStateInfo(); AiData_Npc_BossDevilWarrior data = GetAiData(npc); if (null != data) { CharacterInfo target = AiLogicUtility.GetLivingCharacterInfoHelper(npc, info.Target); if (null != target) { if (npc.IsUnderControl()) { data.ControlTime += deltaTime; if (data.ControlTime >= m_MaxControlTime && npc.CanDisControl() && AiLogicUtility.CanCastSkill(npc, data.DecontrolSkill, target)) { NotifyNpcAddImpact(npc, m_DisControlImpact); data.ControlTime = 0; TryCastSkill(npc, data.DecontrolSkill, target, false); data.CurSkillCombo = data.DecontrolCombo; data.CurSkillComboIndex = 0; } return; } float dist = (float)npc.GetActualProperty().AttackRange; float distGoHome = (float)npc.GohomeRange; Vector3 targetPos = target.GetMovementStateInfo().GetPosition3D(); Vector3 srcPos = npc.GetMovementStateInfo().GetPosition3D(); float powDist = Geometry.DistanceSquare(srcPos, targetPos); float powDistToHome = Geometry.DistanceSquare(srcPos, info.HomePos); // 遇敌是播放特效, 逗留两秒。 if (data.WaitTime <= m_ResponseTime) { if (!data.HasMeetEnemy) { NotifyNpcMeetEnemy(npc, Animation_Type.AT_Attack); data.HasMeetEnemy = true; } TrySeeTarget(npc, target); data.WaitTime += deltaTime; return; } if (null != data.CurSkillCombo) { if (data.CurSkillCombo.Length > data.CurSkillComboIndex) { TryCastSkill(npc, data.CurSkillCombo[data.CurSkillComboIndex], target); data.CurSkillComboIndex = data.CurSkillComboIndex + 1; } else { data.CurSkillCombo = null; data.CurSkillComboIndex = 0; } } // 大于攻击距离 跑向目标 if (powDist > m_AttackRange * m_AttackRange) { if ((int)GfxCharacterState_Type.HitFly == target.GfxStateFlag) { if (TryCastSkill(npc, data.FlyRangeSkill, target)) { return; } } else { if (TryCastSkill(npc, data.RangeSkill, target)) { return; } } info.Time += deltaTime; if (info.Time > m_IntervalTime) { NotifyNpcRun(npc); info.Time = 0; AiLogicUtility.PathToTargetWithoutObstacle(npc, data.FoundPath, targetPos, m_IntervalTime, true, this); } } else { if ((int)GfxCharacterState_Type.HitFly == target.GfxStateFlag) { if (TryCastSkill(npc, data.FlyMeeleSkill, target)) { return; } } else { if (TryCastSkill(npc, data.MeeleSkill, target)) { return; } } } } else { NotifyNpcTargetChange(npc); npc.GetMovementStateInfo().IsMoving = false; NotifyNpcMove(npc); info.Time = 0; ChangeToState(npc, (int)AiStateId.Idle); } } }
private void PursuitHandler(NpcInfo npc, AiCommandDispatcher aiCmdDispatcher, long deltaTime) { if (npc.IsDead()) { npc.GetMovementStateInfo().IsMoving = false; NotifyNpcMove(npc); return; } NpcAiStateInfo info = npc.GetAiStateInfo(); AiData_Npc_CommonBoss data = GetAiData(npc); if (null != data) { CharacterInfo target = AiLogicUtility.GetLivingCharacterInfoHelper(npc, info.Target); if (null != target) { if (npc.GetSkillStateInfo().IsSkillActivated()) { npc.GetMovementStateInfo().IsMoving = false; NotifyNpcMove(npc); data.LastUseSkillTime = TimeUtility.GetServerMilliseconds(); return; } if (npc.IsUnderControl()) { data.ControlTime += deltaTime; if (data.ControlTime >= m_MaxControlTime && npc.CanDisControl() && AiLogicUtility.CanCastSkill(npc, m_DisControlSkillId, target)) { NotifyNpcAddImpact(npc, m_DisControlImpactId); data.ControlTime = 0; TryCastSkill(npc, m_DisControlSkillId, target, false); } return; } float dist = (float)npc.GetActualProperty().AttackRange; float distGoHome = (float)npc.GohomeRange; Vector3 targetPos = target.GetMovementStateInfo().GetPosition3D(); Vector3 srcPos = npc.GetMovementStateInfo().GetPosition3D(); float powDist = Geometry.DistanceSquare(srcPos, targetPos); float powDistToHome = Geometry.DistanceSquare(srcPos, info.HomePos); // 遇敌是播放特效, 逗留两秒。 if (data.WaitTime <= m_ResponseTime) { if (!data.HasMeetEnemy) { NotifyNpcMeetEnemy(npc, Animation_Type.AT_Attack); data.HasMeetEnemy = true; } TrySeeTarget(npc, target); data.WaitTime += deltaTime; return; } int skillId = GetCanCastSkillId(npc, (float)Math.Sqrt(powDist)); long curTime = TimeUtility.GetServerMilliseconds(); if (-1 != skillId && curTime - data.LastUseSkillTime > m_SkillInterval && AiLogicUtility.CanCastSkill(npc, skillId, target)) { if (TryCastSkill(npc, skillId, target, true)) { NotifyNpcAddImpact(npc, m_SuperArmorImpactId); } } else { info.Time += deltaTime; if (info.Time > m_IntervalTime) { info.Time = 0; AiLogicUtility.PathToTargetWithoutObstacle(npc, data.FoundPath, targetPos, m_IntervalTime, true, this); } } } else { NotifyNpcTargetChange(npc); npc.GetMovementStateInfo().IsMoving = false; NotifyNpcMove(npc); info.Time = 0; ChangeToState(npc, (int)AiStateId.Idle); } } }
private void SummonPartner(int key_code, int what) { RoleInfo roleself = LobbyClient.Instance.CurrentRole; if (null == roleself) { return; } UserInfo playerself = WorldSystem.Instance.GetPlayerSelf(); if (null == playerself) { return; } /// if ((int)Keyboard.Event.Up == what) { // summonpartner PartnerInfo partnerInfo = roleself.PartnerStateInfo.GetActivePartner(); if (null != partnerInfo) { Data_Unit data = new Data_Unit(); data.m_Id = -1; data.m_LinkId = partnerInfo.LinkId; data.m_CampId = playerself.GetCampId(); data.m_Pos = playerself.GetMovementStateInfo().GetPosition3D(); data.m_RotAngle = 0; data.m_AiLogic = partnerInfo.GetAiLogic(); data.m_AiParam[0] = ""; data.m_AiParam[1] = ""; data.m_AiParam[2] = partnerInfo.GetAiParam().ToString(); data.m_IsEnable = true; NpcInfo npc = WorldSystem.Instance.NpcManager.AddNpc(data); if (null != npc) { AppendAttributeConfig aac = AppendAttributeConfigProvider.Instance.GetDataById(partnerInfo.GetAppendAttrConfigId()); float inheritAttackAttrPercent = partnerInfo.GetInheritAttackAttrPercent(); float inheritDefenceAttrPercent = partnerInfo.GetInheritDefenceAttrPercent(); if (null != aac) { // attack npc.GetBaseProperty().SetAttackBase(Operate_Type.OT_Absolute, (int)(playerself.GetActualProperty().AttackBase *inheritAttackAttrPercent)); npc.GetBaseProperty().SetFireDamage(Operate_Type.OT_Absolute, playerself.GetActualProperty().FireDamage *inheritAttackAttrPercent); npc.GetBaseProperty().SetIceDamage(Operate_Type.OT_Absolute, playerself.GetActualProperty().IceDamage *inheritAttackAttrPercent); npc.GetBaseProperty().SetPoisonDamage(Operate_Type.OT_Absolute, playerself.GetActualProperty().PoisonDamage *inheritAttackAttrPercent); // defence npc.GetBaseProperty().SetHpMax(Operate_Type.OT_Absolute, (int)(playerself.GetActualProperty().HpMax *inheritDefenceAttrPercent)); npc.GetBaseProperty().SetEnergyMax(Operate_Type.OT_Absolute, (int)(playerself.GetActualProperty().EnergyMax *inheritDefenceAttrPercent)); npc.GetBaseProperty().SetADefenceBase(Operate_Type.OT_Absolute, (int)(playerself.GetActualProperty().ADefenceBase *inheritDefenceAttrPercent)); npc.GetBaseProperty().SetMDefenceBase(Operate_Type.OT_Absolute, (int)(playerself.GetActualProperty().MDefenceBase *inheritDefenceAttrPercent)); npc.GetBaseProperty().SetFireERD(Operate_Type.OT_Absolute, playerself.GetActualProperty().FireERD *inheritDefenceAttrPercent); npc.GetBaseProperty().SetIceERD(Operate_Type.OT_Absolute, playerself.GetActualProperty().IceERD *inheritDefenceAttrPercent); npc.GetBaseProperty().SetPoisonERD(Operate_Type.OT_Absolute, playerself.GetActualProperty().PoisonERD *inheritDefenceAttrPercent); // reset hp & energy npc.SetHp(Operate_Type.OT_Absolute, npc.GetActualProperty().HpMax); npc.SetEnergy(Operate_Type.OT_Absolute, npc.GetActualProperty().EnergyMax); } npc.SetAIEnable(true); npc.GetSkillStateInfo().RemoveAllSkill(); npc.BornTime = TimeUtility.GetServerMilliseconds(); List <int> skillList = partnerInfo.GetSkillList(); if (null != skillList) { for (int i = 0; i < skillList.Count; ++i) { SkillInfo skillInfo = new SkillInfo(skillList[i]); npc.GetSkillStateInfo().AddSkill(skillInfo); } } npc.SkillController = new SwordManSkillController(npc, GfxModule.Skill.GfxSkillSystem.Instance); npc.OwnerId = playerself.GetId(); playerself.PartnerId = npc.GetId(); EntityManager.Instance.CreateNpcView(npc.GetId()); if (partnerInfo.BornSkill > 0) { SkillInfo skillInfo = new SkillInfo(partnerInfo.BornSkill); npc.GetSkillStateInfo().AddSkill(skillInfo); npc.SkillController.ForceStartSkill(partnerInfo.BornSkill); } CharacterView view = EntityManager.Instance.GetCharacterViewById(npc.GetId()); if (null != view) { GfxSystem.SetLayer(view.Actor, "PhysicObj"); } } } } }
private void CombatHandler(NpcInfo npc, AiCommandDispatcher aiCmdDispatcher, long deltaTime) { if (!CanAiControl(npc)) { npc.GetMovementStateInfo().IsMoving = false; return; } NpcAiStateInfo info = npc.GetAiStateInfo(); info.Time += deltaTime; if (info.Time > m_IntervalTime) { AiData_Demo_Melee data = GetAiData(npc); if (null != data) { data.Time += info.Time; info.Time = 0; CharacterInfo target = AiLogicUtility.GetLivingCharacterInfoHelper(npc, info.Target); //CharacterInfo target = AiLogicUtility.GetInterestestTargetHelper(npc, CharacterRelation.RELATION_ENEMY, AiTargetType.USER); if (null != target) { float dist = (float)npc.GetActualProperty().AttackRange; float distGoHome = (float)npc.GohomeRange; Vector3 targetPos = target.GetMovementStateInfo().GetPosition3D(); Vector3 srcPos = npc.GetMovementStateInfo().GetPosition3D(); float powDist = Geometry.DistanceSquare(srcPos, targetPos); float powDistToHome = Geometry.DistanceSquare(srcPos, info.HomePos); if (powDist < dist * dist) { float rps = npc.GetActualProperty().Rps; long curTime = TimeUtility.GetServerMilliseconds(); float dir = Geometry.GetYAngle(new Vector2(srcPos.X, srcPos.Z), new Vector2(targetPos.X, targetPos.Z)); NotifyNpcFace(npc, dir); //if (rps > 0.001f && curTime - data.LastUseSkillTime > 1000 / rps) { data.Time = 0; data.LastUseSkillTime = curTime; List <SkillInfo> skillInfos = npc.GetSkillStateInfo().GetAllSkill(); if (skillInfos.Count > 0) { int index = CrossEngineHelper.Random.Next(skillInfos.Count); if (null != skillInfos[index]) { NotifyNpcSkill(npc, skillInfos[index].SkillId); } } //} } else { npc.GetMovementStateInfo().IsMoving = false; NotifyNpcMove(npc); info.Time = 0; data.FoundPath.Clear(); ChangeToState(npc, (int)AiStateId.Pursuit); } } } else { info.Time = 0; } } }
private void PursuitHandler(NpcInfo npc, AiCommandDispatcher aiCmdDispatcher, long deltaTime) { if (npc.IsDead() || npc.GetSkillStateInfo().IsSkillActivated()) { npc.GetMovementStateInfo().IsMoving = false; NotifyNpcMove(npc); return; } NpcAiStateInfo info = npc.GetAiStateInfo(); AiData_Npc_Bluelf data = GetAiData(npc); if (null != data) { if (npc.IsUnderControl()) { data.ControlTime += deltaTime; if (data.ControlTime >= m_MaxControlTime && npc.CanDisControl()) { NotifyNpcAddImpact(npc, m_SuperAmorImpact); data.ControlTime = 0; } return; } CharacterInfo target = AiLogicUtility.GetLivingCharacterInfoHelper(npc, info.Target); if (null != target) { float dist = (float)npc.GetActualProperty().AttackRange; float distGoHome = (float)npc.GohomeRange; Vector3 targetPos = target.GetMovementStateInfo().GetPosition3D(); Vector3 srcPos = npc.GetMovementStateInfo().GetPosition3D(); float powDist = Geometry.DistanceSquare(srcPos, targetPos); float powDistToHome = Geometry.DistanceSquare(srcPos, info.HomePos); // 遇敌是播放特效, 短暂逗留。 if (data.WaitTime <= m_ResponseTime) { if (!data.HasMeetEnemy) { NotifyNpcMeetEnemy(npc, Animation_Type.AT_Attack); data.HasMeetEnemy = true; } TrySeeTarget(npc, target); data.WaitTime += deltaTime; return; } int randomNum = CrossEngineHelper.Random.Next(0, 10); // 大于攻击距离 跑向目标 if (powDist > m_AttackRange * m_AttackRange && 0 == data.CurAiAction) { if (randomNum < 8) { TryCastSkill(npc, m_DisSkill, target); return; } else if (randomNum < 9) { TryCastSkill(npc, m_CommonSkill, target); return; } npc.IsTaunt = false; NotifyNpcRun(npc); info.Time += deltaTime; if (info.Time > m_IntervalTime) { info.Time = 0; AiLogicUtility.PathToTargetWithoutObstacle(npc, data.FoundPath, targetPos, m_IntervalTime, true, this); } } else { //小于攻击距离 if (data.CurAiAction == (int)AiAction.NONE) { if (randomNum < 7) { TryCastSkill(npc, m_CommonSkill, target); return; } npc.GetMovementStateInfo().IsMoving = false; NotifyNpcMove(npc); data.CurAiAction = (int)GetNextAction(); } switch (data.CurAiAction) { case (int)AiAction.SKILL: int skillId = GetCanCastSkillId(npc, (float)Math.Sqrt(powDist)); if (-1 == skillId) { info.Time += deltaTime; if (info.Time > m_IntervalTime) { info.Time = 0; NotifyNpcRun(npc); AiLogicUtility.PathToTargetWithoutObstacle(npc, data.FoundPath, targetPos, m_IntervalTime, true, this); } } else { npc.GetMovementStateInfo().IsMoving = false; NotifyNpcMove(npc); if (TryCastSkill(npc, skillId, target)) { data.CurAiAction = 0; } } break; case (int)AiAction.STAND: data.ChaseStandTime += deltaTime; TrySeeTarget(npc, target); if (data.ChaseStandTime > m_ChaseWalkMaxTime) { data.ChaseStandTime = 0; data.CurAiAction = 0; } break; case (int)AiAction.TAUNT: npc.GetMovementStateInfo().IsMoving = false; NotifyNpcMove(npc); npc.IsTaunt = true; data.TauntTime += deltaTime; TrySeeTarget(npc, target); if (data.TauntTime > m_TauntTime) { npc.IsTaunt = false; data.TauntTime = 0; data.CurAiAction = 0; } break; case (int)AiAction.WALK: data.ChaseWalkTime += deltaTime; info.Time += deltaTime; if (info.Time > m_IntervalTime) { info.Time = 0; NotifyNpcWalk(npc); AiLogicUtility.PathToTargetWithoutObstacle(npc, data.FoundPath, targetPos, m_IntervalTime, true, this); } if (data.ChaseWalkTime > m_ChaseWalkMaxTime) { data.ChaseWalkTime = 0; data.CurAiAction = 0; } break; } } } else { NotifyNpcTargetChange(npc); npc.GetMovementStateInfo().IsMoving = false; NotifyNpcMove(npc); info.Time = 0; ChangeToState(npc, (int)AiStateId.Idle); } } }
private void IdleHandler(NpcInfo npc, AiCommandDispatcher aiCmdDispatcher, long deltaTime) { NpcAiStateInfo info = npc.GetAiStateInfo(); info.Time += deltaTime; if (info.Time > m_IntervalTime) { info.Time = 0; DropOutInfo dropInfo = npc.GetAiStateInfo().AiDatas.GetData <DropOutInfo>(); if (null != dropInfo) { if (npc.IsBorning) { Vector3 curPos = npc.GetMovementStateInfo().GetPosition3D(); if (dropInfo.BornTarget == Vector3.Zero) { double tempAngle = CrossEngineHelper.Random.NextFloat() * Math.PI; float length = CrossEngineHelper.Random.NextFloat() * 3.0f; dropInfo.BornTarget = curPos + new Vector3((float)Math.Cos(tempAngle), 0, (float)Math.Sin(tempAngle)) * length; dropInfo.BornAngle = (float)tempAngle; } //npc.GetMovementStateInfo().SetMoveDir(dropInfo.BornAngle); //npc.GetMovementStateInfo().IsMoving = true; //NotifyNpcWalk(npc); return; } else { if (!dropInfo.IsBornOver) { npc.GetMovementStateInfo().IsMoving = false; NotifyNpcMove(npc); } } } UserInfo target = null; target = AiLogicUtility.GetNearstTargetHelper(npc, CharacterRelation.RELATION_FRIEND, AiTargetType.USER) as UserInfo; if (null != target && !npc.NeedDelete) { Vector3 srcPos = npc.GetMovementStateInfo().GetPosition3D(); Vector3 targetPos = target.GetMovementStateInfo().GetPosition3D(); float dis = Geometry.Distance(srcPos, targetPos); float angle = Geometry.GetYAngle(new Vector2(srcPos.X, srcPos.Z), new Vector2(targetPos.X, targetPos.Z)); if (dis <= m_AttractRange && dis > m_PickUpRange) { // 吸取 float move = npc.GetActualProperty().MoveSpeed *m_IntervalTime / 1000; npc.GetMovementStateInfo().SetMoveDir(angle); //npc.GetMovementStateInfo().PositionY = targetPos.Y + (1 - dis / m_AttractRange) * m_Height; //npc.GetMovementStateInfo().SetPosition2D(srcPos.X + move * (float)Math.Cos(angle), srcPos.Z + move * (float)Math.Sin(angle)); npc.GetMovementStateInfo().IsMoving = true; NotifyNpcRun(npc); } else if (dis <= m_PickUpRange) { npc.GetMovementStateInfo().IsMoving = false; NotifyNpcMove(npc); string path = ""; if (null != dropInfo) { switch (dropInfo.DropType) { case DropOutType.GOLD: target.Money += dropInfo.Value; target.UserManager.FireGainMoneyEvent(target.GetId(), dropInfo.Value); path = "ef_head"; break; case DropOutType.HP: int addHp = (int)(target.GetActualProperty().HpMax *dropInfo.Value / 100.0f); if (target.GetActualProperty().HpMax > addHp + target.Hp) { target.SetHp(Operate_Type.OT_Relative, addHp); } else { target.SetHp(Operate_Type.OT_Absolute, target.GetActualProperty().HpMax); } target.UserManager.FireDamageEvent(target.GetId(), -1, false, false, addHp, 0); path = "Bone_Root"; break; case DropOutType.MP: int addEnergy = (int)(target.GetActualProperty().EnergyMax *dropInfo.Value / 100.0f); if (target.GetActualProperty().EnergyMax > addEnergy + target.Energy) { target.SetEnergy(Operate_Type.OT_Relative, addEnergy); } else { target.SetEnergy(Operate_Type.OT_Absolute, target.GetActualProperty().EnergyMax); } target.UserManager.FireDamageEvent(target.GetId(), -1, false, false, 0, addEnergy); path = "Bone_Root"; break; case DropOutType.MULT_GOLD: target.Money += dropInfo.Value; target.UserManager.FireGainMoneyEvent(target.GetId(), dropInfo.Value); path = "ef_head"; break; } if (null != OnDropoutPlayEffect) { OnDropoutPlayEffect(target, npc, dropInfo.Particle, path, (int)dropInfo.DropType, dropInfo.Value); } } npc.NeedDelete = true; } } } }
private void PursuitHandler(NpcInfo npc, AiCommandDispatcher aiCmdDispatcher, long deltaTime) { if (npc.IsDead()) { npc.GetMovementStateInfo().IsMoving = false; NotifyNpcMove(npc); return; } if (npc.GetSkillStateInfo().IsSkillActivated()) { return; } NpcAiStateInfo info = npc.GetAiStateInfo(); AiData_Npc_Bluelf data = GetAiData(npc); if (null != data) { // 写黑板 if (0 != info.HateTarget) { GetBlackBorad(npc).TargetId = info.HateTarget; } if (npc.IsUnderControl()) { return; } // 读黑板 int blackBoardTarget = GetBlackBorad(npc).TargetId; if (0 != blackBoardTarget) { info.Target = blackBoardTarget; NotifyNpcTargetChange(npc); } CharacterInfo target = AiLogicUtility.GetLivingCharacterInfoHelper(npc, info.Target); if (null != target) { float dist = (float)npc.GetActualProperty().AttackRange; float distGoHome = (float)npc.GohomeRange; Vector3 targetPos = target.GetMovementStateInfo().GetPosition3D(); Vector3 srcPos = npc.GetMovementStateInfo().GetPosition3D(); float powDist = Geometry.DistanceSquare(srcPos, targetPos); float powDistToHome = Geometry.DistanceSquare(srcPos, info.HomePos); // 遇敌是播放特效 逗留两秒。 if (data.WaitTime <= m_ResponseTime) { if (!data.HasMeetEnemy) { NotifyNpcMeetEnemy(npc, Animation_Type.AT_Attack); data.HasMeetEnemy = true; } TrySeeTarget(npc, target); data.WaitTime += deltaTime; return; } // 追逐目标 if (powDist > m_AttackRange * m_AttackRange) { npc.GetActualProperty().SetMoveSpeed(Operate_Type.OT_Absolute, AiLogicUtility.GetRunSpeed(npc)); npc.GetMovementStateInfo().MovementMode = MovementMode.HighSpeed; info.Time += deltaTime; if (info.Time > m_IntervalTime) { info.Time = 0; AiLogicUtility.PathToTargetWithoutObstacle(npc, data.FoundPath, targetPos, m_IntervalTime, true, this); } } else { //小于攻击距离, 可以攻击 npc.GetMovementStateInfo().IsMoving = false; if (0 != blackBoardTarget) { int skillId = GetCanCastSkillId(npc, (float)Math.Sqrt(powDist)); TryCastSkill(npc, skillId, target); } else { // 不敢攻击 TrySeeTarget(npc, target); } } } else { NotifyNpcTargetChange(npc); npc.GetMovementStateInfo().IsMoving = false; NotifyNpcMove(npc); info.Time = 0; ChangeToState(npc, (int)AiStateId.Idle); } } }
private void PursuitHandler(NpcInfo npc, AiCommandDispatcher aiCmdDispatcher, long deltaTime) { if (npc.IsDead()) { npc.GetMovementStateInfo().IsMoving = false; NotifyNpcMove(npc); return; } NpcAiStateInfo info = npc.GetAiStateInfo(); AiData_Npc_BossHulun data = GetAiData(npc); if (null != data) { CharacterInfo target = AiLogicUtility.GetLivingCharacterInfoHelper(npc, info.Target); if (null != target) { if (npc.IsUnderControl()) { data.ControlTime += deltaTime; if (data.ControlTime > m_MaxControlTime && npc.CanDisControl()) { NotifyNpcAddImpact(npc, m_SuperArmorImpactId); data.ControlTime = 0; NotifyNpcSkill(npc, 380308); } } float dist = (float)npc.GetActualProperty().AttackRange; float distGoHome = (float)npc.GohomeRange; Vector3 targetPos = target.GetMovementStateInfo().GetPosition3D(); Vector3 srcPos = npc.GetMovementStateInfo().GetPosition3D(); float powDist = Geometry.DistanceSquare(srcPos, targetPos); float powDistToHome = Geometry.DistanceSquare(srcPos, info.HomePos); // 遇敌是播放特效, 逗留两秒。 if (data.WaitTime <= m_ResponseTime) { if (!data.HasMeetEnemy) { NotifyNpcMeetEnemy(npc, Animation_Type.AT_Attack); data.HasMeetEnemy = true; } TrySeeTarget(npc, target); data.WaitTime += deltaTime; return; } if (npc.GetSkillStateInfo().IsSkillActivated()) { SkillInfo curSkill = npc.GetSkillStateInfo().GetCurSkillInfo(); if (null != curSkill && curSkill.SkillId == data.ChaseTargetSkill) { NotifyNpcRun(npc); AiLogicUtility.PathToTargetWithoutObstacle(npc, data.FoundPath, targetPos, deltaTime, true, this); data.IsUsingChaseSkill = true; } return; } else if (data.IsUsingChaseSkill) { npc.GetMovementStateInfo().IsMoving = false; NotifyNpcMove(npc); data.IsUsingChaseSkill = false; } if (1 == data.CurStage) { if (npc.Hp < npc.GetActualProperty().HpMax *data.StageTwoLimit) { data.CurStage = 2; NotifyNpcSkill(npc, data.EnterStageTwoSkill); data.CurSkillCombo = null; data.CurSkillComboIndex = 0; return; } else { if (null == data.CurSkillCombo) { data.CurSkillCombo = data.m_StageOneSkillCombo; data.CurSkillComboIndex = 0; } } } else if (2 == data.CurStage) { if (npc.Hp < npc.GetActualProperty().HpMax *data.StageThreeLimit) { data.CurStage = 3; NotifyNpcSkill(npc, data.EnterStageTwoSkill); data.CurSkillCombo = null; data.CurSkillComboIndex = 0; return; } else { if (null == data.CurSkillCombo) { data.CurSkillCombo = data.m_StageTwoSkillCombo; data.CurSkillComboIndex = 0; } } } else if (3 == data.CurStage) { if (null == data.CurSkillCombo) { data.CurSkillCombo = data.m_StageThreeSkillCombo; data.CurSkillComboIndex = 0; } } if (null != data.CurSkillCombo) { if (data.CurSkillCombo.Length > data.CurSkillComboIndex) { if (TryCastSkill(npc, data.CurSkillCombo[data.CurSkillComboIndex], target)) { data.CurSkillComboIndex = data.CurSkillComboIndex + 1; return; } } else { data.CurSkillCombo = null; data.CurSkillComboIndex = 0; } } // 大于攻击距离 跑向目标 info.Time += deltaTime; if (info.Time > m_IntervalTime) { NotifyNpcRun(npc); info.Time = 0; AiLogicUtility.PathToTargetWithoutObstacle(npc, data.FoundPath, targetPos, m_IntervalTime, true, this); } } else { NotifyNpcTargetChange(npc); npc.GetMovementStateInfo().IsMoving = false; NotifyNpcMove(npc); info.Time = 0; ChangeToState(npc, (int)AiStateId.Idle); } } }