public static void DisableAI() { IsAIDisabled = true; //Cancle attack NpcManager.CancleFighterAttacking(); }
public override void Update(GameTime gameTime) { if (_controledMagicSprite != null) { base.Update(gameTime); return; } if (_blindMilliseconds > 0) { _blindMilliseconds -= (float)gameTime.ElapsedGameTime.TotalMilliseconds; } //Find follow target if (!IsFollowTargetFound || // Not find target. FollowTarget == null || // Follow target not assign. FollowTarget.IsDeathInvoked || //Follow target is death. !FollowTarget.IsVisible || (IsEnemy && FollowTarget.IsEnemy && FollowTarget.Group == Group) || // Follow target relation changed (IsFighterFriend && (FollowTarget.IsFighterFriend || FollowTarget.IsPlayer)) || // Follow target relation changed IsAIDisabled || //Npc AI is disabled. _blindMilliseconds > 0) { if (IsEnemy) { if (StopFindingTarget == 0) { FollowTarget = (IsAIDisabled || _blindMilliseconds > 0) ? null : NpcManager.GetLiveClosestOtherGropEnemy(Group, PositionInWorld); if (NoAutoAttackPlayer == 0 && FollowTarget == null) { FollowTarget = (IsAIDisabled || _blindMilliseconds > 0) ? null : NpcManager.GetLiveClosestPlayerOrFighterFriend(PositionInWorld, true, false); } } else if (FollowTarget != null && FollowTarget.IsDeathInvoked) { FollowTarget = null; } } else if (IsFighterFriend) { if (StopFindingTarget == 0) { FollowTarget = (IsAIDisabled || _blindMilliseconds > 0) ? null : NpcManager.GetClosestEnemyTypeCharacter(PositionInWorld, true, false); } else if (FollowTarget != null && FollowTarget.IsDeathInvoked) { FollowTarget = null; } //Fighter friend may be parter if (FollowTarget == null && IsPartner) { //Can't find enemy, move to player MoveToPlayer(); } } else if (IsNoneFighter) { if (StopFindingTarget == 0) { FollowTarget = (IsAIDisabled || _blindMilliseconds > 0) ? null : NpcManager.GetLiveClosestNonneturalFighter(PositionInWorld); } else if (FollowTarget != null && FollowTarget.IsDeathInvoked) { FollowTarget = null; } } else if (IsPartner) { MoveToPlayer(); } } if (!CheckKeepDistanceWhenFriendDeath() && !KeepDistanceWhenLifeLow() && MagicToUseWhenLifeLow != null && LifeMax > 0 && Life / (float)LifeMax <= LifeLowPercent / 100.0f) { PerformeAttack(PositionInWorld + Utils.GetDirection8(CurrentDirection), MagicToUseWhenLifeLow); } else { //Follow target PerformeFollow(); } //Attack interval if (_idledFrame < Idle) { _idledFrame++; } if (IsFollowTargetFound) { //Character found follow target and move to follow target. //This may cause character move far away from the initial base tile position. //Assing ActionPathTilePositionList value to null, //when get next time, new path is generated use new base tile postion. ActionPathTilePositionList = null; } ////Follow target not found, do something else. if ((FollowTarget == null || !IsFollowTargetFound) && !(IsFighterKind && IsAIDisabled)) //Fighter can't move when AI diaabled { var isFlyer = Kind == (int)CharacterKind.Flyer; const int randWalkPosibility = 400; const int flyerRandWalkPosibility = 20; if (Action == (int)ActionType.LoopWalk && FixedPathTilePositionList != null) { //Loop walk along FixedPos LoopWalk(FixedPathTilePositionList, isFlyer ? flyerRandWalkPosibility : randWalkPosibility, ref _currentFixedPosIndex, isFlyer); } else { switch ((CharacterKind)Kind) { case CharacterKind.Normal: case CharacterKind.Fighter: case CharacterKind.GroundAnimal: case CharacterKind.Eventer: case CharacterKind.Flyer: { switch ((ActionType)Action) { case ActionType.RandWalk: RandWalk(ActionPathTilePositionList, isFlyer ? flyerRandWalkPosibility : randWalkPosibility, isFlyer); break; } } break; case CharacterKind.AfraidPlayerAnimal: { KeepMinTileDistance(Globals.PlayerTilePosition, VisionRadius); } break; } } } base.Update(gameTime); }