Witches stand still while drinking and skip potions a target already has
A drinking witch now gets the -0.25 drinking speed modifier, so it does not walk for the 32 ticks. When it throws a potion, slowness, poison and weakness are only picked if the target (player or mob) does not already have that effect, as Witch.performRangedAttack does.
This commit is contained in:
@@ -1050,6 +1050,7 @@ pub fn main() -> horizon_client::Result<()> {
|
||||
velocity: Vec3::ZERO,
|
||||
yaw: 0.0,
|
||||
hero: false,
|
||||
effects: Vec::new(),
|
||||
uuid: PLAYER_UUID,
|
||||
allies: Default::default(),
|
||||
remote: false,
|
||||
|
||||
@@ -193,6 +193,7 @@ impl Game<'_> {
|
||||
velocity: p.velocity,
|
||||
yaw: self.yaw,
|
||||
hero: self.potions.effects.get("hero_of_the_village").is_some(),
|
||||
effects: self.potions.effects.list.iter().map(|e| e.id).collect(),
|
||||
uuid: self.level.player_uuid.unwrap_or_default(),
|
||||
allies: std::sync::Arc::new(self.player_allies()),
|
||||
remote: false,
|
||||
|
||||
@@ -370,6 +370,7 @@ mod tests {
|
||||
velocity: Vec3::ZERO,
|
||||
yaw: 0.0,
|
||||
hero: false,
|
||||
effects: Vec::new(),
|
||||
uuid: [0; 4],
|
||||
allies: Default::default(),
|
||||
remote: false,
|
||||
|
||||
@@ -1243,6 +1243,14 @@ pub struct Seen {
|
||||
/// `MAX_HEALTH`, `JUMP_STRENGTH` and `MOVEMENT_SPEED` base values (a
|
||||
/// horse's breeding stock).
|
||||
pub stats: [f64; 3],
|
||||
/// The active effects, without namespace (`slowness`, `poison`...).
|
||||
pub effects: Vec<&'static str>,
|
||||
}
|
||||
impl Seen {
|
||||
/// `LivingEntity.hasEffect`, by id without namespace.
|
||||
pub fn has_effect(&self, effect: &str) -> bool {
|
||||
self.effects.contains(&effect)
|
||||
}
|
||||
}
|
||||
impl Mob {
|
||||
pub fn burning_time(&self) -> f64 {
|
||||
@@ -1315,6 +1323,12 @@ impl Mob {
|
||||
m.extra.vector[0],
|
||||
m.attrs.speed,
|
||||
],
|
||||
effects: m
|
||||
.extra
|
||||
.effects
|
||||
.iter()
|
||||
.map(|e| e.0.trim_start_matches("minecraft:"))
|
||||
.collect(),
|
||||
}
|
||||
}
|
||||
/// `EntityType.getCategory`'s name.
|
||||
@@ -1459,6 +1473,8 @@ pub struct PlayerView {
|
||||
pub yaw: f32,
|
||||
/// The Hero of the Village effect.
|
||||
pub hero: bool,
|
||||
/// The active effects, without namespace (`slowness`, `poison`...).
|
||||
pub effects: Vec<&'static str>,
|
||||
/// The player's UUID (villagers' gossip is keyed by it).
|
||||
pub uuid: [i32; 4],
|
||||
/// The mobs on the player's team (`isAlliedTo`): combat targeting
|
||||
@@ -1468,6 +1484,12 @@ pub struct PlayerView {
|
||||
/// (`EntitySelector.pushableBy` on the client).
|
||||
pub remote: bool,
|
||||
}
|
||||
impl PlayerView {
|
||||
/// `LivingEntity.hasEffect`, by id without namespace.
|
||||
pub fn has_effect(&self, effect: &str) -> bool {
|
||||
self.effects.contains(&effect)
|
||||
}
|
||||
}
|
||||
#[derive(Clone)]
|
||||
pub struct MobWorld<'a> {
|
||||
pub world: &'a World,
|
||||
@@ -1839,7 +1861,8 @@ impl Mob {
|
||||
/// Movement speed attribute bonus (baby zombies, sprinting modifiers).
|
||||
/// MOVEMENT_SPEED including effects (speed +20%/level, slowness -15%/level).
|
||||
pub fn movement_speed(&self) -> f64 {
|
||||
let mut v = strider::movement_speed(self, self.attrs.speed) * self.speed_bonus();
|
||||
let mut v = strider::movement_speed(self, witch::speed(self, self.attrs.speed))
|
||||
* self.speed_bonus();
|
||||
for (e, _, amp) in &self.extra.effects {
|
||||
match *e {
|
||||
"minecraft:speed" => v *= 1.0 + 0.2 * f64::from(amp + 1),
|
||||
|
||||
@@ -193,6 +193,11 @@ fn witch_attack(m: &mut Mob, who: Who, _power: f32, cx: &mut Cx) {
|
||||
}
|
||||
Who::Player => false,
|
||||
};
|
||||
// `target.hasEffect`: a target that already has the effect gets the next one.
|
||||
let has = |effect: &str| match who {
|
||||
Who::Player => cx.w.player.as_ref().is_some_and(|p| p.has_effect(effect)),
|
||||
Who::Mob(id) => cx.w.seen(id).is_some_and(|s| s.has_effect(effect)),
|
||||
};
|
||||
let (effect, ticks, amplifier) = if heals {
|
||||
m.ai.target = None;
|
||||
if health <= 4.0 {
|
||||
@@ -200,11 +205,11 @@ fn witch_attack(m: &mut Mob, who: Who, _power: f32, cx: &mut Cx) {
|
||||
} else {
|
||||
("minecraft:regeneration", 900, 0)
|
||||
}
|
||||
} else if dist >= 8.0 {
|
||||
} else if dist >= 8.0 && !has("slowness") {
|
||||
("minecraft:slowness", 1800, 0)
|
||||
} else if health >= 8.0 {
|
||||
} else if health >= 8.0 && !has("poison") {
|
||||
("minecraft:poison", 900, 0)
|
||||
} else if dist <= 3.0 && m.random.next_float() < 0.25 {
|
||||
} else if dist <= 3.0 && !has("weakness") && m.random.next_float() < 0.25 {
|
||||
("minecraft:weakness", 1800, 0)
|
||||
} else {
|
||||
("minecraft:instant_damage", 1, 0)
|
||||
@@ -236,6 +241,15 @@ fn witch_attack(m: &mut Mob, who: Who, _power: f32, cx: &mut Cx) {
|
||||
pitch,
|
||||
));
|
||||
}
|
||||
/// The movement speed of a witch with `SPEED_MODIFIER_DRINKING` (-0.25,
|
||||
/// `ADD_VALUE`) while it drinks: it stands still for the 32 ticks.
|
||||
pub fn speed(m: &Mob, base: f64) -> f64 {
|
||||
if m.species() == Species::Witch && m.extra.flag {
|
||||
(base - 0.25).max(0.0)
|
||||
} else {
|
||||
base
|
||||
}
|
||||
}
|
||||
/// Witch.aiStep before `super.aiStep()`: the healing cooldown, then drink
|
||||
/// water breathing, fire resistance, healing or swiftness.
|
||||
pub fn ai_step(m: &mut Mob, cx_events: &mut Vec<MobEvent>, target_far: bool) {
|
||||
|
||||
Reference in New Issue
Block a user