public override void behaviorAtGameTick(GameTime time) { base.behaviorAtGameTick(time); if ((double)this.timeBeforeAIMovementAgain <= 0.0) { this.isInvisible = false; } if (!this.spottedPlayer && Utility.couldSeePlayerInPeripheralVision((Character)this) && Utility.doesPointHaveLineOfSightInMine(this.getTileLocation(), Game1.player.getTileLocation(), 8)) { this.controller = (PathFindController)null; this.spottedPlayer = true; this.Halt(); this.facePlayer(Game1.player); if (Game1.random.NextDouble() >= 0.3) { return; } Game1.playSound("shadowpeep"); } else if (this.casting) { this.IsWalkingTowardPlayer = false; this.sprite.Animate(time, 16, 4, 200f); TimeSpan timeSpan = time.TotalGameTime; this.rotationTimer = (float)((double)timeSpan.Milliseconds * 0.0245436932891607 / 24.0 % (1024.0 * Math.PI)); int coolDown = this.coolDown; timeSpan = time.ElapsedGameTime; int milliseconds = timeSpan.Milliseconds; this.coolDown = coolDown - milliseconds; if (this.coolDown > 0) { return; } this.scale = 1f; Vector2 velocityTowardPlayer = Utility.getVelocityTowardPlayer(this.GetBoundingBox().Center, 15f, Game1.player); if (Game1.player.attack >= 0 && Game1.random.NextDouble() < 0.6) { Game1.currentLocation.projectiles.Add((Projectile) new DebuffingProjectile(new Buff(14), 7, 4, 4, 0.1963495f, velocityTowardPlayer.X, velocityTowardPlayer.Y, new Vector2((float)this.GetBoundingBox().X, (float)this.GetBoundingBox().Y), (Character)this)); } else { List <Monster> monsterList = new List <Monster>(); foreach (NPC character in Game1.currentLocation.characters) { if (character is Monster && (character as Monster).withinPlayerThreshold(6)) { monsterList.Add((Monster)character); } } Monster monster1 = (Monster)null; double num = 1.0; foreach (Monster monster2 in monsterList) { if ((double)monster2.health / (double)monster2.maxHealth <= num) { monster1 = monster2; num = (double)monster2.health / (double)monster2.maxHealth; } } if (monster1 != null) { int number = 60; monster1.health = Math.Min(monster1.maxHealth, monster1.health + number); Game1.playSound("healSound"); Game1.currentLocation.temporarySprites.Add(new TemporaryAnimatedSprite(Game1.animations, new Rectangle(0, 256, 64, 64), 40f, 8, 0, monster1.position + new Vector2((float)(Game1.tileSize / 2), (float)Game1.tileSize), false, false)); Game1.currentLocation.debris.Add(new Debris(number, new Vector2((float)monster1.GetBoundingBox().Center.X, (float)monster1.GetBoundingBox().Center.Y), Color.Green, 1f, (Character)monster1)); } } this.casting = false; this.coolDown = 1500; this.IsWalkingTowardPlayer = true; } else if (this.spottedPlayer && this.withinPlayerThreshold(8)) { if (this.health < 30) { int y1 = Game1.player.GetBoundingBox().Center.Y; Rectangle boundingBox = this.GetBoundingBox(); int y2 = boundingBox.Center.Y; if (Math.Abs(y1 - y2) > Game1.tileSize * 3) { boundingBox = Game1.player.GetBoundingBox(); int x1 = boundingBox.Center.X; boundingBox = this.GetBoundingBox(); int x2 = boundingBox.Center.X; if (x1 - x2 > 0) { this.SetMovingLeft(true); } else { this.SetMovingRight(true); } } else { boundingBox = Game1.player.GetBoundingBox(); int y3 = boundingBox.Center.Y; boundingBox = this.GetBoundingBox(); int y4 = boundingBox.Center.Y; if (y3 - y4 > 0) { this.SetMovingUp(true); } else { this.SetMovingDown(true); } } } else if (this.controller == null && !Utility.doesPointHaveLineOfSightInMine(this.getTileLocation(), Game1.player.getTileLocation(), 8)) { this.controller = new PathFindController((Character)this, Game1.currentLocation, new Point((int)Game1.player.getTileLocation().X, (int)Game1.player.getTileLocation().Y), -1, (PathFindController.endBehavior)null, 300); if (this.controller == null || this.controller.pathToEndPoint == null || this.controller.pathToEndPoint.Count == 0) { this.spottedPlayer = false; this.Halt(); this.controller = (PathFindController)null; this.addedSpeed = 0; } } else if (this.coolDown <= 0 && Game1.random.NextDouble() < 0.02) { this.casting = true; this.Halt(); this.coolDown = 500; } this.coolDown = this.coolDown - time.ElapsedGameTime.Milliseconds; } else if (this.spottedPlayer) { this.IsWalkingTowardPlayer = false; this.spottedPlayer = false; this.controller = (PathFindController)null; this.addedSpeed = 0; } else { this.defaultMovementBehavior(time); } }
public override void behaviorAtGameTick(GameTime time) { base.behaviorAtGameTick(time); if (this.timeBeforeAIMovementAgain <= 0f) { this.isInvisible = false; } if (!this.spottedPlayer && Utility.couldSeePlayerInPeripheralVision(this) && Utility.doesPointHaveLineOfSightInMine(base.getTileLocation(), Game1.player.getTileLocation(), 8)) { this.controller = null; this.spottedPlayer = true; this.Halt(); base.facePlayer(Game1.player); if (Game1.random.NextDouble() < 0.3) { Game1.playSound("shadowpeep"); return; } } else if (this.casting) { base.IsWalkingTowardPlayer = false; this.sprite.Animate(time, 16, 4, 200f); this.rotationTimer = (float)((double)((float)time.TotalGameTime.Milliseconds * 0.0245436933f / 24f) % 3216.9908772759482); this.coolDown -= time.ElapsedGameTime.Milliseconds; if (this.coolDown <= 0) { this.scale = 1f; Vector2 velocityTowardPlayer = Utility.getVelocityTowardPlayer(this.GetBoundingBox().Center, 15f, Game1.player); if (Game1.player.attack >= 0 && Game1.random.NextDouble() < 0.6) { Game1.currentLocation.projectiles.Add(new DebuffingProjectile(new Buff(14), 7, 4, 4, 0.196349546f, velocityTowardPlayer.X, velocityTowardPlayer.Y, new Vector2((float)this.GetBoundingBox().X, (float)this.GetBoundingBox().Y), this)); } else { List <Monster> list = new List <Monster>(); foreach (NPC current in Game1.currentLocation.characters) { if (current is Monster && (current as Monster).withinPlayerThreshold(6)) { list.Add((Monster)current); } } Monster monster = null; double num = 1.0; foreach (Monster current2 in list) { if ((double)current2.health / (double)current2.maxHealth <= num) { monster = current2; num = (double)current2.health / (double)current2.maxHealth; } } if (monster != null) { int num2 = 60; monster.health = Math.Min(monster.maxHealth, monster.health + num2); Game1.playSound("healSound"); Game1.currentLocation.temporarySprites.Add(new TemporaryAnimatedSprite(Game1.animations, new Rectangle(0, 256, 64, 64), 40f, 8, 0, monster.position + new Vector2((float)(Game1.tileSize / 2), (float)Game1.tileSize), false, false)); Game1.currentLocation.debris.Add(new Debris(num2, new Vector2((float)monster.GetBoundingBox().Center.X, (float)monster.GetBoundingBox().Center.Y), Color.Green, 1f, monster)); } } this.casting = false; this.coolDown = 1500; base.IsWalkingTowardPlayer = true; return; } } else { if (this.spottedPlayer && base.withinPlayerThreshold(8)) { if (this.health < 30) { if (Math.Abs(Game1.player.GetBoundingBox().Center.Y - this.GetBoundingBox().Center.Y) > Game1.tileSize * 3) { if (Game1.player.GetBoundingBox().Center.X - this.GetBoundingBox().Center.X > 0) { this.SetMovingLeft(true); } else { this.SetMovingRight(true); } } else if (Game1.player.GetBoundingBox().Center.Y - this.GetBoundingBox().Center.Y > 0) { this.SetMovingUp(true); } else { this.SetMovingDown(true); } } else if (this.controller == null && !Utility.doesPointHaveLineOfSightInMine(base.getTileLocation(), Game1.player.getTileLocation(), 8)) { this.controller = new PathFindController(this, Game1.currentLocation, new Point((int)Game1.player.getTileLocation().X, (int)Game1.player.getTileLocation().Y), -1, null, 300); if (this.controller == null || this.controller.pathToEndPoint == null || this.controller.pathToEndPoint.Count == 0) { this.spottedPlayer = false; this.Halt(); this.controller = null; this.addedSpeed = 0; } } else if (this.coolDown <= 0 && Game1.random.NextDouble() < 0.02) { this.casting = true; this.Halt(); this.coolDown = 500; } this.coolDown -= time.ElapsedGameTime.Milliseconds; return; } if (this.spottedPlayer) { base.IsWalkingTowardPlayer = false; this.spottedPlayer = false; this.controller = null; this.addedSpeed = 0; return; } this.defaultMovementBehavior(time); } }
public override void behaviorAtGameTick(GameTime time) { base.behaviorAtGameTick(time); if (timeBeforeAIMovementAgain <= 0f) { base.IsInvisible = false; } if (!spottedPlayer && Utility.couldSeePlayerInPeripheralVision(base.Player, this) && Utility.doesPointHaveLineOfSightInMine(base.currentLocation, getTileLocation(), base.Player.getTileLocation(), 8)) { controller = null; spottedPlayer = true; Halt(); facePlayer(base.Player); if (Game1.random.NextDouble() < 0.3) { base.currentLocation.playSound("shadowpeep"); } } else if ((bool)casting) { base.IsWalkingTowardPlayer = false; Sprite.Animate(time, 16, 4, 200f); rotationTimer = (float)((double)((float)time.TotalGameTime.Milliseconds * ((float)Math.PI / 128f) / 24f) % (Math.PI * 1024.0)); coolDown -= time.ElapsedGameTime.Milliseconds; if (coolDown > 0) { return; } base.Scale = 1f; Vector2 velocityTowardPlayer = Utility.getVelocityTowardPlayer(GetBoundingBox().Center, 15f, base.Player); if (base.Player.attack >= 0 && Game1.random.NextDouble() < 0.6) { base.currentLocation.projectiles.Add(new DebuffingProjectile(14, 7, 4, 4, (float)Math.PI / 16f, velocityTowardPlayer.X, velocityTowardPlayer.Y, new Vector2(GetBoundingBox().X, GetBoundingBox().Y), base.currentLocation, this)); } else { List <Monster> monstersNearPlayer = new List <Monster>(); foreach (NPC i in base.currentLocation.characters) { if (i is Monster && (i as Monster).withinPlayerThreshold(6)) { monstersNearPlayer.Add((Monster)i); } } Monster lowestHealthMonster = null; double lowestHealth = 1.0; foreach (Monster j in monstersNearPlayer) { if ((double)j.Health / (double)j.MaxHealth <= lowestHealth) { lowestHealthMonster = j; lowestHealth = (double)j.Health / (double)j.MaxHealth; } } if (lowestHealthMonster != null) { int amountToHeal = 60; lowestHealthMonster.Health = Math.Min(lowestHealthMonster.MaxHealth, lowestHealthMonster.Health + amountToHeal); base.currentLocation.playSound("healSound"); Game1.multiplayer.broadcastSprites(base.currentLocation, new TemporaryAnimatedSprite("TileSheets\\animations", new Rectangle(0, 256, 64, 64), 40f, 8, 0, lowestHealthMonster.Position + new Vector2(32f, 64f), flicker: false, flipped: false)); base.currentLocation.debris.Add(new Debris(amountToHeal, new Vector2(lowestHealthMonster.GetBoundingBox().Center.X, lowestHealthMonster.GetBoundingBox().Center.Y), Color.Green, 1f, lowestHealthMonster)); } } casting.Value = false; coolDown = 1500; base.IsWalkingTowardPlayer = true; } else if (spottedPlayer && withinPlayerThreshold(8)) { if (base.Health < 30) { if (Math.Abs(base.Player.GetBoundingBox().Center.Y - GetBoundingBox().Center.Y) > 192) { if (base.Player.GetBoundingBox().Center.X - GetBoundingBox().Center.X > 0) { SetMovingLeft(b: true); } else { SetMovingRight(b: true); } } else if (base.Player.GetBoundingBox().Center.Y - GetBoundingBox().Center.Y > 0) { SetMovingUp(b: true); } else { SetMovingDown(b: true); } } else if (controller == null && !Utility.doesPointHaveLineOfSightInMine(base.currentLocation, getTileLocation(), base.Player.getTileLocation(), 8)) { controller = new PathFindController(this, base.currentLocation, new Point((int)base.Player.getTileLocation().X, (int)base.Player.getTileLocation().Y), -1, null, 300); if (controller == null || controller.pathToEndPoint == null || controller.pathToEndPoint.Count == 0) { spottedPlayer = false; Halt(); controller = null; base.addedSpeed = 0; } } else if (coolDown <= 0 && Game1.random.NextDouble() < 0.02) { casting.Value = true; Halt(); coolDown = 500; } coolDown -= time.ElapsedGameTime.Milliseconds; } else if (spottedPlayer) { base.IsWalkingTowardPlayer = false; spottedPlayer = false; controller = null; base.addedSpeed = 0; } else { defaultMovementBehavior(time); } }