public override void OnTickIdle(ObjNPC npc, float delta) { if (!npc.CanMove()) { return; } if (npc.IsMoving()) { return; } if (mPtIdx < 0 || mPtIdx >= ListDestination.Count) { npc.Disapeare(); return; } if (mTime > DateTime.Now) { return; } if (MoveResult.AlreadyThere == npc.MoveTo(ListDestination[mPtIdx])) { mPtIdx++; mTime = DateTime.Now.AddSeconds(WaitTime); } }
public override void OnTickCombat(ObjNPC npc, float delta) { if (!npc.CanSkill()) { return; } //判断敌人是否存在 var enemy = GetCanAttack(npc); if (null == enemy) { npc.EnterState(BehaviorState.GoHome); return; } var WillskillId = npc.NormalSkillId; //GetCanDoSkill(npc);//npc.NormalSkillId; var mTableWillskill = Table.GetSkill(WillskillId); if (mTableWillskill == null) { return; } mSkillDistance = SkillManager.GetSkillDistance((SkillTargetType)mTableWillskill.TargetType, mTableWillskill.TargetParam); //跟着敌人打 if ((npc.GetPosition() - enemy.GetPosition()).Length() > mSkillDistance) { var diffDis = mSkillDistance - 1.0f; if (diffDis < 0) { diffDis = 0; } npc.MoveTo(enemy.GetPosition(), diffDis); } else { npc.TurnFaceTo(enemy.GetPosition()); if (npc.IsMoving()) { npc.StopMove(); } if (DateTime.Now >= mNextNormalAttackTime) { var reCodes = npc.MustSkill(ref WillskillId, enemy); //npc.UseSkill(ref skillId, enemy); //if (reCodes == ErrorCodes.OK) //{ // PushSkillCd(npc, WillskillId); //} } } }
//回家 public override void OnEnterGoHome(ObjNPC npc) { base.OnEnterGoHome(npc); if ((npc.GetPosition() - npc.BornPosition).LengthSquared() < 0.01f) { npc.EnterState(BehaviorState.Idle); return; } // 30 秒后如果还没有回去,强制拉回去,并开始idle TimeToReset = DateTime.Now.AddSeconds(30); npc.MoveTo(npc.BornPosition); }
public override void OnTickGoHome(ObjNPC npc, float delta) { if (!npc.IsMoving()) { if ((npc.BornPosition - npc.GetPosition()).LengthSquared() < 1.5f) { npc.EnterState(BehaviorState.Idle); } else { npc.MoveTo(npc.BornPosition); } } }
//回家 public override void OnEnterGoHome(ObjNPC npc) { base.OnEnterGoHome(npc); var retinue = npc as ObjRetinue; if (retinue == null) { return; } if (retinue.Owner == null) { retinue.Scene.LeaveScene(retinue); } npc.MoveTo(retinue.Owner.GetPosition(), 1); }
public override void OnTickIdle(ObjNPC npc, float delta) { if (!npc.CanMove()) { return; } if (npc.IsMoving()) { return; } if (mStayTime > DateTime.Now) { return; } if (ListDestination.Count <= 0) { return; } if (MoveResult.AlreadyThere == npc.MoveTo(ListDestination[mPtIdx])) { if (mForward) { mPtIdx++; if (mPtIdx >= ListDestination.Count) { mForward = false; mPtIdx = ListDestination.Count - 2; } } else { mPtIdx--; if (mPtIdx < 0) { mForward = true; mPtIdx = 1; } } mStayTime = DateTime.Now.AddSeconds(WaitTime); } }
public override void OnTickIdle(ObjNPC npc, float delta) { if (npc.IsAggressive()) { if (npc.TableNpc.ViewDistance > 0) { var target = ScanEnemy(npc, (float)npc.TableNpc.ViewDistance); if (target != null) { npc.EnterState(BehaviorState.Combat); npc.PushHatre(target, 1); npc.AddEnemy(target.ObjId); target.AddEnemy(npc.ObjId); return; } } } if (!npc.CanMove()) { return; } if (npc.IsMoving()) { return; } if (mPtIdx < 0 || mPtIdx >= ListDestination.Count) { //npc.Disapeare(); return; } if (mTime > DateTime.Now) { return; } if (MoveResult.AlreadyThere == npc.MoveTo(ListDestination[mPtIdx])) { mPtIdx++; mTime = DateTime.Now.AddSeconds(WaitTime); } }
public override void OnTickGoHome(ObjNPC npc, float delta) { if (!npc.IsMoving()) { if ((npc.BornPosition - npc.GetPosition()).LengthSquared() < 1.5f) { npc.EnterState(BehaviorState.Idle); } else { npc.MoveTo(npc.BornPosition, 1); } } if (DateTime.Now > TimeToReset) { npc.SetPosition(npc.BornPosition); npc.EnterState(BehaviorState.Idle); TimeToReset = TimeToReset.AddYears(100); } }
public override void OnTickGoHome(ObjNPC npc, float delta) { var retinue = npc as ObjRetinue; if (retinue == null) { return; } if (retinue.Owner == null) { return; } if (!npc.IsMoving()) { if ((npc.BornPosition - npc.GetPosition()).LengthSquared() < 1.5f) { npc.EnterState(BehaviorState.Idle); } else { npc.MoveTo(retinue.Owner.GetPosition(), 1); } } }
public override void OnTickCombat(ObjNPC npc, float delta) { ObjCharacter enemy = null; //判断敌人是否存在 if (npc.TableAI == null) { enemy = npc.GetMaxHatre(); } else { enemy = GetAttackTarget(npc); } //判断敌人是否存在 if (null == enemy) { npc.EnterState(BehaviorState.GoHome); return; } //判断敌人是否有效 if (enemy.IsDead() || !enemy.Active) { npc.EnterState(BehaviorState.GoHome); return; } //判断是否太远了 var dis = (npc.GetPosition() - mBackPosition).Length(); if (npc.TableNpc.MaxCombatDistance > 0 && dis >= npc.TableNpc.MaxCombatDistance) { npc.EnterState(BehaviorState.GoHome); return; } //如果有普通 if (null != mTableNormalSkill) { //跟着敌人打 if ((npc.GetPosition() - enemy.GetPosition()).Length() <= mSkillDistance) { npc.TurnFaceTo(enemy.GetPosition()); if (npc.IsMoving()) { GenNextNormalAttackTime(100); npc.StopMove(); } if (DateTime.Now >= mNextNormalAttackTime) { npc.Seperate(enemy, mSkillDistance / 3); var skillId = npc.NormalSkillId; npc.UseSkill(ref skillId, enemy); GenNextNormalAttackTime(); mNoMoveTime = 0; //攻击了一次就把自己站在原地的累计时间清空 } } else { var targetPos = npc.CalculatePostionToEnemy(enemy, mSkillDistance / 3); if (MoveResult.CannotReach == npc.MoveTo(targetPos)) { //如果长时间无法到达目的地说明卡怪了, 就回去 mNoMoveTime += delta; if (mNoMoveTime >= MAX_NO_MOVE_TIME) { npc.EnterState(BehaviorState.GoHome); } } else { mNoMoveTime = 0; } } } }
public override void OnTickCombat(ObjNPC npc, float delta) { var retinue = npc as ObjRetinue; if (retinue == null) { return; } if (retinue.Owner == null || retinue.Owner.Scene == null) { retinue.Scene.LeaveScene(retinue); return; } var myPos = retinue.GetPosition(); var ownerPos = retinue.Owner.GetPosition(); if (mNextNormalAttackTime > DateTime.Now) { return; } var distance = (myPos - ownerPos).LengthSquared(); //if (distance > 400) //{ // var diff = GetRandomPostion(); // diff += ownerPos; // npc.SetCheckPostion(diff); // //retinue.MoveTo(ownerPos, 2); // npc.EnterState(BehaviorState.GoHome); // return; //} if (distance > 64) { retinue.MoveTo(ownerPos, 2); return; //var p = myPos + Vector2.Normalize(ownerPos - myPos) * 2; //retinue.MoveTo(p); } var tag = retinue.Owner.Scene.GetObstacleValue(ownerPos.X, ownerPos.Y); if (tag == SceneObstacle.ObstacleValue.Walkable) //自身在安全区禁止攻击 { return; } var enemyTarget = GetEnemyCharacter(retinue); if (enemyTarget == null) { npc.EnterState(BehaviorState.GoHome); return; } if (enemyTarget.GetObjType() == ObjType.PLAYER) { tag = enemyTarget.Scene.GetObstacleValue(ownerPos.X, ownerPos.Y); if (tag == SceneObstacle.ObstacleValue.Walkable) //对方在安全区禁止攻击 { return; } } LastTargetId = enemyTarget.ObjId; var WillskillId = GetCanDoSkill(npc); //npc.NormalSkillId; var mTableWillskill = Table.GetSkill(WillskillId); if (mTableWillskill == null) { return; } mSkillDistance = SkillManager.GetSkillDistance((SkillTargetType)mTableWillskill.TargetType, mTableWillskill.TargetParam); //跟着敌人打 if ((npc.GetPosition() - enemyTarget.GetPosition()).Length() > mSkillDistance) { npc.MoveTo(enemyTarget.GetPosition(), mSkillDistance - 0.3f); } else { if (npc.IsMoving()) { npc.StopMove(); } if (npc.UseSkill(ref WillskillId, enemyTarget) == ErrorCodes.OK) { //int cd = mTableNormalSkill.Cd; //if (cd < mTableNormalSkill.CommonCd) //{ // cd = mTableNormalSkill.CommonCd; //} //int milliseconds = cd <= 0 ? DEFAULT_NORMAL_ATTACK_INTERVAL_MILLISECONDS : cd; //mNextNormalAttackTime = DateTime.Now + TimeSpan.FromMilliseconds(milliseconds); PushSkillCd(npc, WillskillId); } } }
public override void OnTickCombat(ObjNPC npc, float delta) { var enemyTarget = GetEnemyCharacter(npc); if (enemyTarget == null) { npc.EnterState(BehaviorState.Idle); return; } if (!npc.CanMove()) { return; } NextSkill = FindFreeSkill(npc, enemyTarget); if (NextSkill == -1) { return; } var tbSkill = Table.GetSkill(NextSkill); if (tbSkill == null) { return; } if ((SkillTargetType)tbSkill.TargetType == SkillTargetType.SELF || (eCampType)tbSkill.CampType == eCampType.Team) { if (npc.IsMoving()) { npc.StopMove(); } if (npc.CanSkill()) { LastTargetId = enemyTarget.ObjId; SelectLastTarger = true; npc.TurnFaceTo(enemyTarget.GetPosition()); npc.UseSkill(ref NextSkill, npc); } return; } mSkillDistance = SkillManager.GetSkillDistance((SkillTargetType)tbSkill.TargetType, tbSkill.TargetParam); //跟着敌人打 if ((npc.GetPosition() - enemyTarget.GetPosition()).Length() > mSkillDistance) { npc.MoveTo(enemyTarget.GetPosition(), mSkillDistance - 0.1f); } else { if (npc.IsMoving()) { npc.StopMove(); } if (npc.CanSkill()) { LastTargetId = enemyTarget.ObjId; SelectLastTarger = true; npc.TurnFaceTo(enemyTarget.GetPosition()); npc.UseSkill(ref NextSkill, enemyTarget); } } }
public override void OnTickCombat(ObjNPC npc, float delta) { if (npc.TableAI.Id == MieShiBuildingAI) { if (!npc.CanSkill()) { return; } if (!npc.CanSkill()) { return; } //判断敌人是否存在 var enemy = GetCanAttack(npc); if (null == enemy) { npc.EnterState(BehaviorState.GoHome); return; } var WillskillId = npc.NormalSkillId; //GetCanDoSkill(npc);//npc.NormalSkillId; var mTableWillskill = Table.GetSkill(WillskillId); if (mTableWillskill == null) { return; } mSkillDistance = SkillManager.GetSkillDistance((SkillTargetType)mTableWillskill.TargetType, mTableWillskill.TargetParam); //跟着敌人打 if ((npc.GetPosition() - enemy.GetPosition()).Length() > mSkillDistance) { var diffDis = mSkillDistance - 1.0f; if (diffDis < 0) { diffDis = 0; } npc.MoveTo(enemy.GetPosition(), diffDis); } else { npc.TurnFaceTo(enemy.GetPosition()); if (npc.IsMoving()) { npc.StopMove(); } if (DateTime.Now >= mNextNormalAttackTime) { var reCodes = npc.MustSkill(ref WillskillId, enemy); //npc.UseSkill(ref skillId, enemy); //if (reCodes == ErrorCodes.OK) //{ // PushSkillCd(npc, WillskillId); //} } } } else { PatrolTime += 500; //判断是否需要状态转换 if (!bAIChange) { var nextAi = CheckToStateChange(npc); if (nextAi > -1) { Logger.Warn("======================ChangeAi============================[179] {0}", npc.mTypeId); ChangeAi(npc, nextAi); bAIChange = true; return; } } base.OnTickCombat(npc, delta); } }
public override void OnTickCombat(ObjNPC npc, float delta) { CombatTime += 500; if (!npc.CanSkill()) { return; } //判断是否需要状态转换 var nextAi = CheckStateChange(npc); ChangeAi(npc, nextAi); //判断敌人是否存在 var enemy = GetAttackTarget(npc); if (null == enemy) { npc.EnterState(BehaviorState.GoHome); return; } //判断敌人是否有效 if (enemy.IsDead() || !enemy.Active) { npc.EnterState(BehaviorState.GoHome); return; } //判断是否太远了 var dis = (npc.GetPosition() - mBackPosition).Length(); if (npc.TableNpc.MaxCombatDistance > 0 && dis >= npc.TableNpc.MaxCombatDistance) { npc.EnterState(BehaviorState.GoHome); return; } var WillskillId = GetCanDoSkill(npc); //npc.NormalSkillId; var mTableWillskill = Table.GetSkill(WillskillId); if (mTableWillskill == null) { return; } switch ((SkillTargetType)mTableWillskill.TargetType) { case SkillTargetType.SELF: { if (DateTime.Now >= mNextNormalAttackTime) { var reCodes = npc.MustSkill(ref WillskillId, npc); //npc.UseSkill(ref skillId, enemy); if (reCodes == ErrorCodes.OK) { PushSkillCd(npc, WillskillId); } return; } mTableWillskill = Table.GetSkill(npc.TableAI.CommonSkill); if (mTableWillskill == null) { return; } } break; case SkillTargetType.SINGLE: break; case SkillTargetType.CIRCLE: break; case SkillTargetType.SECTOR: break; case SkillTargetType.RECT: break; case SkillTargetType.TARGET_CIRCLE: break; case SkillTargetType.TARGET_RECT: break; case SkillTargetType.TARGET_SECTOR: break; default: break; } mSkillDistance = SkillManager.GetSkillDistance((SkillTargetType)mTableWillskill.TargetType, mTableWillskill.TargetParam); //跟着敌人打 if ((npc.GetPosition() - enemy.GetPosition()).Length() > mSkillDistance) { var diffDis = mSkillDistance - 1.0f; if (diffDis < 0) { diffDis = 0; } npc.MoveTo(enemy.GetPosition(), diffDis); } else { npc.TurnFaceTo(enemy.GetPosition()); if (npc.IsMoving()) { npc.StopMove(); } if (DateTime.Now >= mNextNormalAttackTime) { var reCodes = npc.MustSkill(ref WillskillId, enemy); //npc.UseSkill(ref skillId, enemy); if (reCodes == ErrorCodes.OK) { PushSkillCd(npc, WillskillId); } } } }
//回家 public override void OnEnterGoHome(ObjNPC npc) { base.OnEnterGoHome(npc); npc.MoveTo(npc.BornPosition); }