public void mateWith(GreenSlime mateToPursue, GameLocation location) { if (location.canSlimeMateHere()) { GreenSlime baby = new GreenSlime(Vector2.Zero); Utility.recursiveFindPositionForCharacter(baby, location, getTileLocation(), 30); Random r = new Random((int)Game1.stats.DaysPlayed + (int)Game1.uniqueIDForThisGame / 10 + (int)((float)scale * 100f) + (int)((float)mateToPursue.scale * 100f)); switch (r.Next(4)) { case 0: baby.color.Value = new Color(Math.Min(255, Math.Max(0, color.R + r.Next((int)((float)(-color.R) * 0.25f), (int)((float)(int)color.R * 0.25f)))), Math.Min(255, Math.Max(0, color.G + r.Next((int)((float)(-color.G) * 0.25f), (int)((float)(int)color.G * 0.25f)))), Math.Min(255, Math.Max(0, color.B + r.Next((int)((float)(-color.B) * 0.25f), (int)((float)(int)color.B * 0.25f))))); break; case 1: case 2: baby.color.Value = Utility.getBlendedColor(color, mateToPursue.color); break; case 3: baby.color.Value = new Color(Math.Min(255, Math.Max(0, mateToPursue.color.R + r.Next((int)((float)(-mateToPursue.color.R) * 0.25f), (int)((float)(int)mateToPursue.color.R * 0.25f)))), Math.Min(255, Math.Max(0, mateToPursue.color.G + r.Next((int)((float)(-mateToPursue.color.G) * 0.25f), (int)((float)(int)mateToPursue.color.G * 0.25f)))), Math.Min(255, Math.Max(0, mateToPursue.color.B + r.Next((int)((float)(-mateToPursue.color.B) * 0.25f), (int)((float)(int)mateToPursue.color.B * 0.25f))))); break; } int red = baby.color.R; int green = baby.color.G; int blue = baby.color.B; baby.Name = name; if (baby.Name == "Tiger Slime") { baby.makeTigerSlime(); } else if (red > 100 && blue > 100 && green < 50) { baby.parseMonsterInfo("Sludge"); while (r.NextDouble() < 0.1) { baby.objectsToDrop.Add(386); } if (r.NextDouble() < 0.01) { baby.objectsToDrop.Add(337); } } else if (red >= 200 && green < 75) { baby.parseMonsterInfo("Sludge"); } else if (blue >= 200 && red < 100) { baby.parseMonsterInfo("Frost Jelly"); } baby.Health = ((r.NextDouble() < 0.5) ? base.Health : mateToPursue.Health); baby.Health = Math.Max(1, base.Health + r.Next(-4, 5)); baby.DamageToFarmer = ((r.NextDouble() < 0.5) ? base.DamageToFarmer : mateToPursue.DamageToFarmer); baby.DamageToFarmer = Math.Max(0, base.DamageToFarmer + r.Next(-1, 2)); baby.resilience.Value = ((r.NextDouble() < 0.5) ? resilience : mateToPursue.resilience); baby.resilience.Value = Math.Max(0, (int)resilience + r.Next(-1, 2)); baby.missChance.Value = ((r.NextDouble() < 0.5) ? missChance : mateToPursue.missChance); baby.missChance.Value = Math.Max(0.0, (double)missChance + (double)((float)r.Next(-1, 2) / 100f)); baby.Scale = ((r.NextDouble() < 0.5) ? scale : mateToPursue.scale); baby.Scale = Math.Max(0.6f, Math.Min(1.5f, (float)scale + (float)r.Next(-2, 3) / 100f)); baby.Slipperiness = 8; base.speed = ((r.NextDouble() < 0.5) ? base.speed : mateToPursue.speed); if (r.NextDouble() < 0.015) { base.speed = Math.Max(1, Math.Min(6, base.speed + r.Next(-1, 2))); } baby.setTrajectory(Utility.getAwayFromPositionTrajectory(baby.GetBoundingBox(), getStandingPosition()) / 2f); baby.ageUntilFullGrown.Value = 120000; baby.Halt(); baby.firstGeneration.Value = false; if (Utility.isOnScreen(base.Position, 128)) { base.currentLocation.playSound("slime"); } } mateToPursue.doneMating(); doneMating(); }
public override void behaviorAtGameTick(GameTime time) { if (mate == null) { pursuingMate.Value = false; avoidingMate.Value = false; } switch (FacingDirection) { case 2: if (facePosition.X > 0f) { facePosition.X -= 2f; } else if (facePosition.X < 0f) { facePosition.X += 2f; } if (facePosition.Y < 0f) { facePosition.Y += 2f; } break; case 1: if (facePosition.X < 8f) { facePosition.X += 2f; } if (facePosition.Y < 0f) { facePosition.Y += 2f; } break; case 3: if (facePosition.X > -8f) { facePosition.X -= 2f; } if (facePosition.Y < 0f) { facePosition.Y += 2f; } break; case 0: if (facePosition.X > 0f) { facePosition.X -= 2f; } else if (facePosition.X < 0f) { facePosition.X += 2f; } if (facePosition.Y > -8f) { facePosition.Y -= 2f; } break; } if (stackedSlimes.Value <= 0) { if ((int)ageUntilFullGrown <= 0) { readyToMate -= time.ElapsedGameTime.Milliseconds; } else { ageUntilFullGrown.Value -= time.ElapsedGameTime.Milliseconds; } } if ((bool)pursuingMate && mate != null) { if (readyToMate <= -35000) { mate.doneMating(); doneMating(); return; } moveTowardOtherSlime(mate, moveAway: false, time); if (mate.mate != null && (bool)mate.pursuingMate && !mate.mate.Equals(this)) { doneMating(); } else if (Vector2.Distance(getStandingPosition(), mate.getStandingPosition()) < (float)(GetBoundingBox().Width + 4)) { if (mate.mate != null && (bool)mate.avoidingMate && mate.mate.Equals(this)) { mate.avoidingMate.Value = false; mate.matingCountdown = 2000; mate.pursuingMate.Value = true; } matingCountdown -= time.ElapsedGameTime.Milliseconds; if (base.currentLocation != null && matingCountdown <= 0 && (bool)pursuingMate && (!base.currentLocation.isOutdoors || Utility.getNumberOfCharactersInRadius(base.currentLocation, Utility.Vector2ToPoint(base.Position), 1) <= 4)) { mateWith(mate, base.currentLocation); } } else if (Vector2.Distance(getStandingPosition(), mate.getStandingPosition()) > (float)(matingRange * 2)) { mate.mate = null; mate.avoidingMate.Value = false; mate = null; } return; } if ((bool)avoidingMate && mate != null) { moveTowardOtherSlime(mate, moveAway: true, time); return; } if (readyToMate < 0 && (bool)cute) { readyToMate = -1; if (Game1.random.NextDouble() < 0.001) { GreenSlime newMate = (GreenSlime)Utility.checkForCharacterWithinArea(GetType(), base.Position, base.currentLocation, new Rectangle(getStandingX() - matingRange, getStandingY() - matingRange, matingRange * 2, matingRange * 2)); if (newMate != null && newMate.readyToMate <= 0 && !newMate.cute && newMate.stackedSlimes.Value <= 0) { matingCountdown = 2000; mate = newMate; pursuingMate.Value = true; newMate.mate = this; newMate.avoidingMate.Value = true; base.addedSpeed = 1; mate.addedSpeed = 1; return; } } } else if (!isGlowing) { base.addedSpeed = 0; } base.behaviorAtGameTick(time); if (readyToJump != -1) { Halt(); base.IsWalkingTowardPlayer = false; readyToJump -= time.ElapsedGameTime.Milliseconds; Sprite.currentFrame = 16 + (800 - readyToJump) / 200; if (readyToJump <= 0) { timeSinceLastJump = timeSinceLastJump; base.Slipperiness = 10; base.IsWalkingTowardPlayer = true; readyToJump = -1; invincibleCountdown = 0; Vector2 trajectory = Utility.getAwayFromPlayerTrajectory(GetBoundingBox(), base.Player); trajectory.X = (0f - trajectory.X) / 2f; trajectory.Y = (0f - trajectory.Y) / 2f; jumpEvent.Fire(trajectory); setTrajectory((int)trajectory.X, (int)trajectory.Y); } } else if (Game1.random.NextDouble() < 0.1 && !base.focusedOnFarmers) { if (FacingDirection == 0 || FacingDirection == 2) { if ((bool)leftDrift && !base.currentLocation.isCollidingPosition(nextPosition(3), Game1.viewport, isFarmer: false, 1, glider: false, this)) { position.X -= base.speed; } else if (!leftDrift && !base.currentLocation.isCollidingPosition(nextPosition(1), Game1.viewport, isFarmer: false, 1, glider: false, this)) { position.X += base.speed; } } else if ((bool)leftDrift && !base.currentLocation.isCollidingPosition(nextPosition(0), Game1.viewport, isFarmer: false, 1, glider: false, this)) { position.Y -= base.speed; } else if (!leftDrift && !base.currentLocation.isCollidingPosition(nextPosition(2), Game1.viewport, isFarmer: false, 1, glider: false, this)) { position.Y += base.speed; } if (Game1.random.NextDouble() < 0.08) { leftDrift.Value = !leftDrift; } } else if (withinPlayerThreshold() && timeSinceLastJump > (base.focusedOnFarmers ? 1000 : 4000) && Game1.random.NextDouble() < 0.01 && stackedSlimes.Value <= 0) { if (base.Name.Equals("Frost Jelly") && Game1.random.NextDouble() < 0.25) { base.addedSpeed = 2; startGlowing(Color.Cyan, border: false, 0.15f); } else { base.addedSpeed = 0; stopGlowing(); readyToJump = 800; } } }
public void mateWith(GreenSlime mateToPursue, GameLocation location) { if (location.canSlimeMateHere()) { GreenSlime greenSlime = new GreenSlime(Vector2.Zero); Utility.recursiveFindPositionForCharacter((NPC)greenSlime, location, this.getTileLocation(), 30); Random random = new Random((int)Game1.stats.DaysPlayed + (int)Game1.uniqueIDForThisGame / 10 + (int)((double)this.scale * 100.0) + (int)((double)mateToPursue.scale * 100.0)); switch (random.Next(4)) { case 0: greenSlime.color = new Color(Math.Min((int)byte.MaxValue, Math.Max(0, (int)this.color.R + random.Next((int)((double)-this.color.R * 0.25), (int)((double)this.color.R * 0.25)))), Math.Min((int)byte.MaxValue, Math.Max(0, (int)this.color.G + random.Next((int)((double)-this.color.G * 0.25), (int)((double)this.color.G * 0.25)))), Math.Min((int)byte.MaxValue, Math.Max(0, (int)this.color.B + random.Next((int)((double)-this.color.B * 0.25), (int)((double)this.color.B * 0.25))))); break; case 1: case 2: greenSlime.color = Utility.getBlendedColor(this.color, mateToPursue.color); break; case 3: greenSlime.color = new Color(Math.Min((int)byte.MaxValue, Math.Max(0, (int)mateToPursue.color.R + random.Next((int)((double)-mateToPursue.color.R * 0.25), (int)((double)mateToPursue.color.R * 0.25)))), Math.Min((int)byte.MaxValue, Math.Max(0, (int)mateToPursue.color.G + random.Next((int)((double)-mateToPursue.color.G * 0.25), (int)((double)mateToPursue.color.G * 0.25)))), Math.Min((int)byte.MaxValue, Math.Max(0, (int)mateToPursue.color.B + random.Next((int)((double)-mateToPursue.color.B * 0.25), (int)((double)mateToPursue.color.B * 0.25))))); break; } int r = (int)greenSlime.color.R; int g = (int)greenSlime.color.G; int b = (int)greenSlime.color.B; if (r > 100 && b > 100 && g < 50) { greenSlime.parseMonsterInfo("Sludge"); while (random.NextDouble() < 0.1) { greenSlime.objectsToDrop.Add(386); } if (random.NextDouble() < 0.01) { greenSlime.objectsToDrop.Add(337); } } else if (r >= 200 && g < 75) { greenSlime.parseMonsterInfo("Sludge"); } else if (b >= 200 && r < 100) { greenSlime.parseMonsterInfo("Frost Jelly"); } greenSlime.health = random.NextDouble() < 0.5 ? this.health : mateToPursue.health; greenSlime.health = Math.Max(1, this.health + random.Next(-4, 5)); greenSlime.damageToFarmer = random.NextDouble() < 0.5 ? this.damageToFarmer : mateToPursue.damageToFarmer; greenSlime.damageToFarmer = Math.Max(0, this.damageToFarmer + random.Next(-1, 2)); greenSlime.resilience = random.NextDouble() < 0.5 ? this.resilience : mateToPursue.resilience; greenSlime.resilience = Math.Max(0, this.resilience + random.Next(-1, 2)); greenSlime.missChance = random.NextDouble() < 0.5 ? this.missChance : mateToPursue.missChance; greenSlime.missChance = Math.Max(0.0, this.missChance + (double)random.Next(-1, 2) / 100.0); greenSlime.scale = random.NextDouble() < 0.5 ? this.scale : mateToPursue.scale; greenSlime.scale = Math.Max(0.6f, Math.Min(1.5f, this.scale + (float)random.Next(-2, 3) / 100f)); greenSlime.slipperiness = 8; this.speed = random.NextDouble() < 0.5 ? this.speed : mateToPursue.speed; if (random.NextDouble() < 0.015) { this.speed = Math.Max(1, Math.Min(6, this.speed + random.Next(-1, 2))); } greenSlime.setTrajectory(Utility.getAwayFromPositionTrajectory(greenSlime.GetBoundingBox(), this.getStandingPosition()) / 2f); greenSlime.ageUntilFullGrown = 120000; greenSlime.Halt(); greenSlime.firstGeneration = false; if (Utility.isOnScreen(this.position, 128)) { Game1.playSound("slime"); } } mateToPursue.doneMating(); this.doneMating(); }