public AIModule PickShuffleModule() { if (ModuleHistory.Count == AllModules.Count) { ModuleHistory.Clear(); } var possibleModules = AllModules.Where(m => m.GetPriority() > Mathf.Epsilon).ToList(); AIModule nextModule = possibleModules[Random.Range(0, possibleModules.Count)]; if (AllModules.Count != 1) { int steps = 0; while (steps != possibleModules.Count && (ModuleHistory.Contains(nextModule) || nextModule == PreviousModule)) { nextModule = possibleModules[Random.Range(0, possibleModules.Count)]; steps++; } // Unable to pick shuffled module, pick best one if (steps == possibleModules.Count) { nextModule = null; } } return(nextModule); }
public bool Equals(AIModule obj) { if (obj == null) { return(false); } return(obj.swigCPtr.Handle == this.swigCPtr.Handle); }
protected override void OnProcessControll() { if (!Pawn) { return; } if (Pawn.Damageable && WasAlive && !Pawn.Damageable.IsAlive) { Kill(); } if (Enabled) { if (CurrentEnemy && !CurrentEnemy.IsAlive) { CurrentEnemy = null; SwitchToBestModule(); } if (NextModule) { SwitchModuleInternal(NextModule); NextModule = null; } } WasAlive = Pawn.Damageable.IsAlive; Vector3 direction = Vector3.zero; if (Enabled && Pawn.IsAlive() && CanMove()) { if (ActiveModule) { direction = ActiveModule.ProcessMovement(); } direction = ProcessAbilities(direction); } else { direction = Vector3.zero; Pawn.ResetBody(); } Abilities.Tick(); Pawn.ProcessMovement(direction); Pawn.Tick(); }
//public static List<Entity> entities = new List<Entity>(); public void setMode(AIMode mode) { // Debug.Log("Mode (" + mode + ") set! (try to reduce these, the AI is initialized each time)"); if (mode == this.mode) { return; } this.mode = mode; switch (mode) { case AIMode.Follow: module = new FollowAI(); break; case AIMode.Path: module = new PathAI(); break; case AIMode.Battle: module = new BattleAI(); break; case AIMode.Inactive: if (module is TractorAI tractorAI) { tractorAI.StopFollowing(); movement.StopMoving(); } module = null; break; case AIMode.Tractor: module = new TractorAI(); break; default: break; } if (module != null) { module.craft = craft; module.owner = owner; module.ai = this; module.Init(); } }
private void SwitchModuleInternal(AIModule newModule) { if (ActiveModule == newModule) { return; } PreviousModule = ActiveModule; if (ActiveModule) { ActiveModule.End(); } ActiveModule = newModule; if (ActiveModule) { ActiveModule.Begin(); ModuleHistory.Add(ActiveModule); } }
void InitModules() { Anim = new AnimationModule(this); //动作控制模块 Move = new MoveModule(this); //移动模块 Skill = new SkillModule(this); //技能模块 Hud = new HUDModule(this); //角色头顶信息模块 Property = new PropertyModule(this); //属性模块 Buff = new BuffModule(this); //Buff 模块 Render = new RenderModule(this); //渲染模块 AI = new AIModule(this); _moduleList = new List <ModuleBase>() { Anim, Move, Skill, Hud, Property, Buff, Render, AI }; }
public MasterModule(AIModule aim) { this.aim = aim; }
public override void Update() { base.Update(); creatureLooker.Update(); for (int i = tracker.CreaturesCount - 1; i >= 0; i--) { if (tracker.GetRep(i).TicksSinceSeen > 160) { tracker.ForgetCreature(tracker.GetRep(i).representedCreature); } } if (!enteredRoom && WalkerBeast.room != null && creature.pos.x > 2 && creature.pos.x < WalkerBeast.room.TileWidth - 3) { enteredRoom = true; } if (enteredRoom) { boredofroom++; } AIModule aimodule = utilityComparer.HighestUtilityModule(); currentUtility = utilityComparer.HighestUtility(); if (aimodule != null) { if (aimodule is ThreatTracker) { behavior = Behavior.Flee; } else if (aimodule is RainTracker) { behavior = Behavior.EscapeRain; } else if (aimodule is PreyTracker) { behavior = Behavior.Hunt; } else if (aimodule is StuckTracker) { behavior = Behavior.GetUnstuck; } } if (currentUtility < 0.03f) { behavior = Behavior.Idle; } if (WalkerBeast.grasps[0] != null && behavior != Behavior.Flee && behavior != Behavior.EscapeRain) { behavior = Behavior.ReturnPrey; } switch (behavior) { case Behavior.Idle: //Debug.Log("time:" + (boredofroom)); if (boredofroom > 1600) { creature.abstractAI.SetDestination(denFinder.GetDenPosition().Value); } break; case Behavior.Flee: { WorldCoordinate destination = threatTracker.FleeTo(creature.pos, 5, 30, currentUtility > 0.3f); if (threatTracker.mostThreateningCreature != null) { focusCreature = threatTracker.mostThreateningCreature; } creature.abstractAI.SetDestination(destination); break; } case Behavior.Hunt: focusCreature = preyTracker.MostAttractivePrey; creature.abstractAI.SetDestination(preyTracker.MostAttractivePrey.BestGuessForPosition()); break; case Behavior.EscapeRain: if (denFinder.GetDenPosition() != null) { creature.abstractAI.SetDestination(denFinder.GetDenPosition().Value); } break; case Behavior.ReturnPrey: if (denFinder.GetDenPosition() != null) { creature.abstractAI.SetDestination(denFinder.GetDenPosition().Value); } break; case Behavior.GetUnstuck: creature.abstractAI.SetDestination(stuckTracker.getUnstuckPosCalculator.unstuckGoalPosition); break; } }
public WeatherModule(AIModule aim) { this.aim = aim; }
static void Main(string[] args) { Grid Playfield = new Grid(); AIModule enemyAI = new AIModule(); logger = new Logger(); string coordinate; int aiX, aiY; Console.WriteLine("-----"); Console.WriteLine("Greetings, commander! Welcome to the next iteration of Battleship board game implementation."); Console.WriteLine("Write a letter and a digit to shoot to a field! For example: A5"); while (!isOver) { while (!isOver) { coordinate = Console.ReadLine(); try { if (Playfield.EnemyMap[CoordinateCalculator.GetX(coordinate), CoordinateCalculator.GetY(coordinate)].State == State.basic) { if (Playfield.EnemyMap[CoordinateCalculator.GetX(coordinate), CoordinateCalculator.GetY(coordinate)].Shoot()) { logger.AppendLog("You hit the enemy ship!"); } else { logger.AppendLog("Miss..."); } logger.DumpLog(); break; } Console.WriteLine("You already shot there! Try again."); } catch (IndexOutOfRangeException) { Console.WriteLine("You shot outside of the map area. The sea is not quite impressed."); break; } } while (!isOver) { aiX = enemyAI.Aim(); aiY = enemyAI.Aim(); if (Playfield.PlayerMap[aiX, aiY].State == State.basic) { if (Playfield.PlayerMap[aiX, aiY].Shoot()) { logger.AppendLog("Enemy hit one of your ships!"); } else { logger.AppendLog("Enemy missed the shot."); } logger.DumpLog(); break; } } Console.ReadKey(); if (!isOver) { Playfield.DrawGrid(); } } }
public DTimeModule(AIModule aim) { this.aim = aim; }
public iTunesModule(AIModule aim) { itc = new ITunesController(aim); }
public void SwitchModule(AIModule newModule) { NextModule = newModule; }
internal static global::System.Runtime.InteropServices.HandleRef getCPtr(AIModule obj) { return((obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr); }
// Token: 0x06001E6C RID: 7788 RVA: 0x001B2720 File Offset: 0x001B0920 public override void Update() { this.focusCreature = null; base.Update(); if (this.getAwayCounter > 0) { this.getAwayCounter--; } AIModule aimodule = base.utilityComparer.HighestUtilityModule(); this.currentUtility = base.utilityComparer.HighestUtility(); if (aimodule != null) { if (aimodule is ThreatTracker) { this.behavior = SeaDrakeAI.Behavior.Flee; } else if (aimodule is RainTracker) { this.behavior = SeaDrakeAI.Behavior.EscapeRain; } else if (aimodule is PreyTracker) { if (this.creature.realizedCreature != null && preyTracker.MostAttractivePrey.representedCreature.realizedCreature != null && !this.creature.realizedCreature.room.PointSubmerged(preyTracker.MostAttractivePrey.representedCreature.realizedCreature.mainBodyChunk.pos)) { this.behavior = SeaDrakeAI.Behavior.Idle; } this.behavior = SeaDrakeAI.Behavior.Hunt; } else if (aimodule is NoiseTracker) { this.behavior = SeaDrakeAI.Behavior.ExamineSound; } else if (aimodule is StuckTracker) { this.behavior = SeaDrakeAI.Behavior.GetUnstuck; } } if (this.currentUtility < 0.1f) { this.behavior = SeaDrakeAI.Behavior.Idle; } if (this.behavior != SeaDrakeAI.Behavior.Flee && this.fish.grasps[0] != null) { this.behavior = SeaDrakeAI.Behavior.ReturnPrey; } switch (this.behavior) { case SeaDrakeAI.Behavior.Idle: if (this.exploreCoordinate != null) { this.creature.abstractAI.SetDestination(this.exploreCoordinate.Value); if (Custom.ManhattanDistance(this.creature.pos, this.exploreCoordinate.Value) < 5 || (UnityEngine.Random.value < 0.0125f && base.pathFinder.DoneMappingAccessibility && this.fish.room.aimap.TileAccessibleToCreature(this.creature.pos.x, this.creature.pos.y, this.creature.creatureTemplate) && !base.pathFinder.CoordinateReachableAndGetbackable(this.exploreCoordinate.Value))) { this.exploreCoordinate = null; } } else if (Custom.ManhattanDistance(this.creature.pos, base.pathFinder.GetDestination) < 5 || !base.pathFinder.CoordinateReachableAndGetbackable(base.pathFinder.GetDestination)) { WorldCoordinate worldCoordinate = this.fish.room.GetWorldCoordinate(Custom.RestrictInRect(this.fish.mainBodyChunk.pos, new FloatRect(0f, 0f, this.fish.room.PixelWidth, this.fish.room.PixelHeight)) + Custom.RNV() * 200f); if (this.fish.room.IsPositionInsideBoundries(worldCoordinate.Tile) && base.pathFinder.CoordinateReachableAndGetbackable(worldCoordinate) && this.fish.room.VisualContact(this.creature.pos.Tile, worldCoordinate.Tile)) { this.creature.abstractAI.SetDestination(worldCoordinate); } } if (UnityEngine.Random.value < 1f / ((this.exploreCoordinate == null) ? 80f : 1600f)) { WorldCoordinate worldCoordinate2 = new WorldCoordinate(this.fish.room.abstractRoom.index, UnityEngine.Random.Range(0, this.fish.room.TileWidth), UnityEngine.Random.Range(0, this.fish.room.TileHeight), -1); if (this.fish.room.aimap.TileAccessibleToCreature(worldCoordinate2.Tile, this.creature.creatureTemplate) && base.pathFinder.CoordinateReachableAndGetbackable(worldCoordinate2)) { this.exploreCoordinate = new WorldCoordinate?(worldCoordinate2); } } if (Custom.DistLess(this.creature.pos, base.pathFinder.GetDestination, 20f) && this.fish.room.VisualContact(this.creature.pos, base.pathFinder.GetDestination)) { this.floatGoalPos = new Vector2?(this.fish.room.MiddleOfTile(base.pathFinder.GetDestination)); } else { this.floatGoalPos = null; } break; case SeaDrakeAI.Behavior.Flee: { WorldCoordinate destination = base.threatTracker.FleeTo(this.creature.pos, 3, 30, this.currentUtility > 0.3f); if (base.threatTracker.mostThreateningCreature != null) { this.focusCreature = base.threatTracker.mostThreateningCreature; } this.creature.abstractAI.SetDestination(destination); this.floatGoalPos = null; break; } case SeaDrakeAI.Behavior.Hunt: this.attackCounter--; this.focusCreature = base.preyTracker.MostAttractivePrey; if (this.focusCreature.VisualContact) { this.floatGoalPos = new Vector2?(this.focusCreature.representedCreature.realizedCreature.mainBodyChunk.pos); } else { this.creature.abstractAI.SetDestination(this.focusCreature.BestGuessForPosition()); } if (this.focusCreature.VisualContact && this.focusCreature.representedCreature.realizedCreature.collisionLayer != this.fish.collisionLayer && Custom.DistLess(this.focusCreature.representedCreature.realizedCreature.mainBodyChunk.pos, this.fish.bodyChunks[2].pos, this.fish.bodyChunks[2].rad + this.focusCreature.representedCreature.realizedCreature.mainBodyChunk.rad)) { this.fish.Collide(this.focusCreature.representedCreature.realizedCreature, 2, 0); } break; case SeaDrakeAI.Behavior.ExamineSound: if (this.fish != null) { this.floatGoalPos = new Vector2?(this.fish.room.MiddleOfTile(this.noiseTracker.ExaminePos)); } else { this.creature.abstractAI.SetDestination(base.noiseTracker.ExaminePos); } break; case SeaDrakeAI.Behavior.EscapeRain: if (base.denFinder.GetDenPosition() != null) { this.creature.abstractAI.SetDestination(base.denFinder.GetDenPosition().Value); } this.floatGoalPos = null; break; case SeaDrakeAI.Behavior.ReturnPrey: if (base.denFinder.GetDenPosition() != null) { this.creature.abstractAI.SetDestination(base.denFinder.GetDenPosition().Value); } this.floatGoalPos = null; break; case SeaDrakeAI.Behavior.GoToFood: this.creature.abstractAI.SetDestination(this.fish.room.GetWorldCoordinate(this.goToFood.firstChunk.pos)); break; case SeaDrakeAI.Behavior.GetUnstuck: this.creature.abstractAI.SetDestination(base.stuckTracker.getUnstuckPosCalculator.unstuckGoalPosition); if (UnityEngine.Random.value < Custom.LerpMap(base.stuckTracker.Utility(), 0.9f, 1f, 0f, 0.1f) && this.fish.room.GetTile(this.fish.mainBodyChunk.pos).AnyWater&& this.fish.enteringShortCut == null && base.stuckTracker.stuckCloseToShortcutModule.foundShortCut != null) { this.fish.enteringShortCut = base.stuckTracker.stuckCloseToShortcutModule.foundShortCut; base.stuckTracker.Reset(); } break; } }