Match vanilla projectile randoms, witch target goal and enderman goal names
Projectiles shot by mobs (arrows, splash potions, snowballs, llama spit, wind charges, crossbow bolts, tridents) take their spread, and arrows their base damage, from the new projectile's own random as vanilla does, leaving the shooter's random alone. The witch's player target goal reports as NearestAttackableWitchTargetGoal (NearestTarget gains a subclass label), and the probe names the enderman goals as vanilla's classes. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -173,6 +173,11 @@ fn goal_name(m: &Mob, name: &str) -> String {
|
||||
"TryFindWater" => "TryFindWaterGoal",
|
||||
"RangedAttack" => "RangedAttackGoal",
|
||||
"MoveTowardsTarget" => "MoveTowardsTargetGoal",
|
||||
"TakeBlock" => "EndermanTakeBlockGoal",
|
||||
"LeaveBlock" => "EndermanLeaveBlockGoal",
|
||||
"FreezeWhenLookedAt" => "EndermanFreezeWhenLookedAt",
|
||||
"LookForPlayer" => "EndermanLookForPlayerGoal",
|
||||
"HealRaiders" => "NearestHealableRaiderTargetGoal",
|
||||
other => return other.to_owned(),
|
||||
};
|
||||
vanilla.to_owned()
|
||||
|
||||
@@ -330,7 +330,12 @@ fn tick_shoot(m: &mut Mob, cx: &mut Cx) {
|
||||
Some(Who::Mob(m.id)),
|
||||
);
|
||||
// 5 - 4 * difficulty at normal.
|
||||
p.shoot(&mut m.random, [xd, yd, zd], 0.7, -3.0);
|
||||
p.shoot(
|
||||
&mut crate::projectiles::own_random(m),
|
||||
[xd, yd, zd],
|
||||
0.7,
|
||||
-3.0,
|
||||
);
|
||||
cx.events.push(MobEvent::Projectile(p));
|
||||
cx.events
|
||||
.push(MobEvent::Sound("entity.breeze.shoot", m.center(), 1.5, 1.0));
|
||||
|
||||
@@ -1015,6 +1015,8 @@ pub struct NearestTarget {
|
||||
/// A condition checked before anything else, by subclasses overriding
|
||||
/// `canUse` (SpiderTargetGoal: only in the dark).
|
||||
pub gate: Option<fn(&Mob, &MobWorld) -> bool>,
|
||||
/// The vanilla class name of a subclass (`Goal::name`).
|
||||
pub label: Option<&'static str>,
|
||||
found: Option<Who>,
|
||||
target_goal: TargetState,
|
||||
}
|
||||
@@ -1043,6 +1045,7 @@ impl NearestTarget {
|
||||
interval: reduced(10),
|
||||
when: None,
|
||||
gate: None,
|
||||
label: None,
|
||||
found: None,
|
||||
target_goal: TargetState {
|
||||
unseen_memory: 60,
|
||||
@@ -1077,6 +1080,11 @@ impl NearestTarget {
|
||||
self.gate = Some(f);
|
||||
self
|
||||
}
|
||||
/// A subclass's name, e.g. `NearestAttackableWitchTargetGoal`.
|
||||
pub fn named(mut self, label: &'static str) -> Self {
|
||||
self.label = Some(label);
|
||||
self
|
||||
}
|
||||
}
|
||||
/// TargetGoal.canContinueToUse
|
||||
pub fn target_continue(st: &mut TargetState, must_see: bool, m: &mut Mob, cx: &mut Cx) -> bool {
|
||||
@@ -1105,6 +1113,9 @@ pub fn target_continue(st: &mut TargetState, must_see: bool, m: &mut Mob, cx: &m
|
||||
}
|
||||
impl Goal for NearestTarget {
|
||||
goal_clone!();
|
||||
fn name(&self) -> &'static str {
|
||||
self.label.unwrap_or("NearestTarget")
|
||||
}
|
||||
fn flags(&self) -> u8 {
|
||||
TARGET
|
||||
}
|
||||
|
||||
@@ -284,7 +284,12 @@ fn snowball_attack(m: &mut Mob, who: Who, _power: f32, cx: &mut Cx) {
|
||||
let yo = (xd * xd + zd * zd).sqrt() * 0.2;
|
||||
let mut p = Projectile::new(ProjectileKind::Snowball, start, Some(Who::Mob(m.id)));
|
||||
// rangedAttackUncertainty: 14 - 4 * difficulty (normal: 6).
|
||||
p.shoot(&mut m.random, [xd, yd + yo - start.y, zd], 1.6, 6.0);
|
||||
p.shoot(
|
||||
&mut crate::projectiles::own_random(m),
|
||||
[xd, yd + yo - start.y, zd],
|
||||
1.6,
|
||||
6.0,
|
||||
);
|
||||
cx.events.push(MobEvent::Projectile(p));
|
||||
let pitch = 0.4 / (m.random.next_float() * 0.4 + 0.8);
|
||||
cx.events.push(MobEvent::Sound(
|
||||
|
||||
@@ -543,7 +543,12 @@ fn shoot_crossbow(m: &mut Mob, who: Who, cx: &mut Cx) {
|
||||
);
|
||||
p.bonus = super::gear::arrow_bonus(m);
|
||||
// rangedAttackUncertainty at normal difficulty: 14 - 2 * 4.
|
||||
p.shoot(&mut m.random, [dx, dy, dz], 1.6, 6.0);
|
||||
p.shoot(
|
||||
&mut crate::projectiles::own_random(m),
|
||||
[dx, dy, dz],
|
||||
1.6,
|
||||
6.0,
|
||||
);
|
||||
cx.events.push(MobEvent::Projectile(p));
|
||||
let pitch = 1.0 / (m.random.next_float() * 0.5 + 1.8) + 0.53;
|
||||
cx.events.push(MobEvent::Sound(
|
||||
|
||||
@@ -174,7 +174,12 @@ fn spit(m: &mut Mob, who: Who, _power: f32, cx: &mut Cx) {
|
||||
let zd = t.position.z - m.position.z;
|
||||
let yo = (xd * xd + zd * zd).sqrt() * f64::from(0.2_f32);
|
||||
let mut p = Projectile::new(ProjectileKind::LlamaSpit, start, Some(Who::Mob(m.id)));
|
||||
p.shoot(&mut m.random, [xd, yd + yo, zd], 1.5, 10.0);
|
||||
p.shoot(
|
||||
&mut crate::projectiles::own_random(m),
|
||||
[xd, yd + yo, zd],
|
||||
1.5,
|
||||
10.0,
|
||||
);
|
||||
cx.events.push(MobEvent::Projectile(p));
|
||||
let pitch = 1.0 + (m.random.next_float() - m.random.next_float()) * 0.2;
|
||||
cx.events.push(MobEvent::Sound(
|
||||
|
||||
@@ -236,10 +236,8 @@ fn drowned_throw(m: &mut Mob, who: Who, _power: f32, cx: &mut Cx) {
|
||||
start,
|
||||
Some(Who::Mob(m.id)),
|
||||
);
|
||||
// The spread draws from the new projectile's own random.
|
||||
let mut spread = horizon_core::random::LegacyRandom::new(i64::from(m.id) ^ m.age as i64);
|
||||
p.shoot(
|
||||
&mut spread,
|
||||
&mut crate::projectiles::own_random(m),
|
||||
[xd, yd + dist * f64::from(0.2_f32), zd],
|
||||
1.6,
|
||||
(14 - 2 * 4) as f32,
|
||||
@@ -739,7 +737,8 @@ pub fn perform_ranged_attack(m: &mut Mob, who: Who, cx: &mut Cx, power: f32) {
|
||||
let zd = t.position.z - m.position.z;
|
||||
let dist = (xd * xd + zd * zd).sqrt();
|
||||
// AbstractArrow.setBaseDamageFromMob: power * 2 + triangle(difficulty * 0.11, 0.57425).
|
||||
let base = f64::from(power) * 2.0 + m.random.triangle(2.0 * 0.11, 0.574_25);
|
||||
let mut arrow_random = crate::projectiles::own_random(m);
|
||||
let base = f64::from(power) * 2.0 + arrow_random.triangle(2.0 * 0.11, 0.574_25);
|
||||
let effect = match m.species() {
|
||||
Species::Stray => Some(("minecraft:slowness", 600)),
|
||||
Species::Bogged => Some(("minecraft:poison", 100)),
|
||||
@@ -757,7 +756,7 @@ pub fn perform_ranged_attack(m: &mut Mob, who: Who, cx: &mut Cx, power: f32) {
|
||||
);
|
||||
p.bonus = super::gear::arrow_bonus(m);
|
||||
p.shoot(
|
||||
&mut m.random,
|
||||
&mut arrow_random,
|
||||
[xd, yd + dist * 0.2, zd],
|
||||
1.6,
|
||||
(14 - 2 * 4) as f32,
|
||||
|
||||
@@ -26,7 +26,8 @@ pub fn register(m: &mut Mob) {
|
||||
3,
|
||||
NearestTarget::player(true)
|
||||
.interval(10)
|
||||
.gate(|m, _| m.extra.counter2 <= 0),
|
||||
.gate(|m, _| m.extra.counter2 <= 0)
|
||||
.named("NearestAttackableWitchTargetGoal"),
|
||||
);
|
||||
}
|
||||
/// `NearestHealableRaiderTargetGoal`: in a raid, target another raider to
|
||||
@@ -221,7 +222,7 @@ fn witch_attack(m: &mut Mob, who: Who, _power: f32, cx: &mut Cx) {
|
||||
);
|
||||
// Splash potions throw with gravity 0.05.
|
||||
p.shoot(
|
||||
&mut m.random,
|
||||
&mut crate::projectiles::own_random(m),
|
||||
[xd, yd + dist * 0.2, zd],
|
||||
if dist <= 2.0 { 0.45 } else { 0.75 },
|
||||
8.0,
|
||||
|
||||
@@ -9,6 +9,17 @@ use horizon_core::{
|
||||
random::RandomSource,
|
||||
};
|
||||
|
||||
/// A new projectile entity's own random: vanilla seeds every entity's random
|
||||
/// unpredictably, and a projectile's spread (and an arrow's base damage) come
|
||||
/// from it, never from the shooter's random.
|
||||
pub fn own_random(shooter: &crate::mobs::Mob) -> horizon_core::random::LegacyRandom {
|
||||
horizon_core::random::LegacyRandom::new(
|
||||
i64::from(shooter.id).wrapping_mul(0x9E37_79B9)
|
||||
^ i64::from(shooter.age)
|
||||
^ shooter.position.x.to_bits() as i64,
|
||||
)
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, PartialEq)]
|
||||
pub enum ProjectileKind {
|
||||
/// Arrow with its base damage, critical flag and tipped/stray/bogged effect.
|
||||
|
||||
Reference in New Issue
Block a user