Skip to content

Commit

Permalink
refactor ActorType
Browse files Browse the repository at this point in the history
  • Loading branch information
aratama committed Jan 26, 2025
1 parent e4e87a9 commit abb5c6d
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 25 deletions.
2 changes: 1 addition & 1 deletion src/actor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ use witch::WitchWandSprite;
/// registry.actor.ron で種類ごとに移動速度やジャンプ力などが設定されます
/// ActorType は registry.actor.ron と対応しているが、
/// 行動アルゴリズムがコーディングされているため外部設定ファイル化は向いていない
#[derive(Reflect, Clone, Copy, Debug, PartialEq, Eq, Serialize, Deserialize)]
#[derive(Reflect, Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
pub enum ActorType {
Witch,
Chicken,
Expand Down
14 changes: 7 additions & 7 deletions src/cast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ pub fn cast_spell(

let actor_props = registry.get_actor_props(&actor.to_type());

match props.cast {
match &props.cast {
SpellCast::NoCast => {}
SpellCast::Bullet(ref cast) => {
let normalized = actor.pointer.normalize();
Expand Down Expand Up @@ -208,7 +208,7 @@ pub fn cast_spell(
freeze: cast.freeze,
stagger: cast.stagger,
levitation: cast.levitation + actor.effects.levitation,
metamorphose: actor.effects.metamorphse,
metamorphose: actor.effects.metamorphse.clone(),
dispel: 0 < actor.effects.dispel,
web: 0 < actor.effects.web,
slash,
Expand Down Expand Up @@ -290,7 +290,7 @@ pub fn cast_spell(
spawn: Spawn::Seed {
to: actor_position + actor.pointer,
owner: Some(actor_entity),
servant_type,
servant_type: servant_type.clone(),
actor_group: match (actor.actor_group, friend) {
(ActorGroup::Friend, true) => ActorGroup::Friend,
(ActorGroup::Friend, false) => ActorGroup::Enemy,
Expand All @@ -300,7 +300,7 @@ pub fn cast_spell(
(ActorGroup::Entity, _) => ActorGroup::Neutral,
},
remote: true,
servant,
servant: *servant,
},
});
}
Expand Down Expand Up @@ -437,16 +437,16 @@ pub fn cast_spell(
&mut actor_impulse,
&mut collision_groups,
&actor_transform,
velocity,
impulse,
*velocity,
*impulse,
);
}
SpellCast::Metamorphosis => {
let morphing_to = random_actor_type(&mut rng, &actor.to_type());
actor.effects.metamorphse = Some(morphing_to);
}
SpellCast::Slash { damage } => {
actor.effects.slash.push(damage);
actor.effects.slash.push(*damage);
}
SpellCast::Dispel => {
actor.effects.dispel = (actor.effects.dispel + 1).min(4);
Expand Down
7 changes: 4 additions & 3 deletions src/component/metamorphosis.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ pub struct Metamorphosed {
}

pub fn random_actor_type(mut rng: &mut ThreadRng, except: &ActorType) -> ActorType {
*[
[
ActorType::Slime,
ActorType::EyeBall,
ActorType::Shadow,
Expand All @@ -41,10 +41,11 @@ pub fn random_actor_type(mut rng: &mut ThreadRng, except: &ActorType) -> ActorTy
]
.iter()
.filter(|a| **a != *except)
.collect::<Vec<&ActorType>>()
.collect::<Vec<_>>()
.choose(&mut rng)
.cloned()
.unwrap()
.to_owned()
.clone()
}

/// ActorGroupは基本的には変化しませんが、変化先が物体の場合は ENtityGroup になり、
Expand Down
4 changes: 2 additions & 2 deletions src/entity/bullet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ pub fn spawn_bullet(
actor_group: spawn.actor_group,
holder: spawn.holder,
levitation: spawn.levitation,
metamorphose: spawn.metamorphose,
metamorphose: spawn.metamorphose.clone(),
dispel: spawn.dispel,
web: spawn.web,
slash: spawn.slash,
Expand Down Expand Up @@ -361,7 +361,7 @@ fn bullet_collision(
fire: false,
impulse: bullet_velocity.linvel.normalize_or_zero() * bullet.impulse,
stagger: bullet.stagger,
metamorphose: bullet.metamorphose,
metamorphose: bullet.metamorphose.clone(),
dispel: bullet.dispel,
});
} else {
Expand Down
8 changes: 4 additions & 4 deletions src/entity/servant_seed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ pub fn spawn_servant_seed(
to: Vec2,
actor_group: ActorGroup,
_owner: Option<Entity>,
servant_type: ActorType,
servant_type: &ActorType,
remote: bool,
_servant: bool,
) {
Expand All @@ -65,7 +65,7 @@ pub fn spawn_servant_seed(
speed: 60 + rand::random::<u32>() % 30,
// actor_group: actor_group,
// master: owner,
servant_type: servant_type,
servant_type: servant_type.clone(),
// servant: servant,
},
AseSpriteSlice {
Expand Down Expand Up @@ -93,7 +93,7 @@ pub fn spawn_servant_seed(
ActorGroup::Neutral => ActorGroup::Neutral,
ActorGroup::Entity => ActorGroup::Entity,
},
servant_type: servant_type,
servant_type: servant_type.clone(),
};
let serialized = bincode::serialize::<RemoteMessage>(&message).unwrap();
writer.send(ClientMessage::Binary(serialized));
Expand All @@ -119,7 +119,7 @@ fn update_servant_seed(
if let Some(ref chunk) = current.chunk {
if chunk.get_tile_by_coords(seed.to).is_plane() {
spawn_writer.send(SpawnServantEvent {
servant_type: seed.servant_type,
servant_type: seed.servant_type.clone(),
position: seed.to,
// actor_group: seed.actor_group,
// master: seed.master,
Expand Down
14 changes: 7 additions & 7 deletions src/level/entities.rs
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ pub fn spawn_entity(
)
}

match entity {
match &entity {
Spawn::MagicCircle => {
spawn_magic_circle(
&mut commands,
Expand Down Expand Up @@ -370,12 +370,12 @@ pub fn spawn_entity(
&mut client_message_writer,
&websocket,
*position,
to,
actor_group,
owner,
servant_type,
remote,
servant,
*to,
*actor_group,
*owner,
&servant_type,
*remote,
*servant,
);
}
Spawn::Fireball {
Expand Down
2 changes: 1 addition & 1 deletion src/page/in_game.rs
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,7 @@ fn spawn_random_enemies(
Some(enemy_type) => {
spawn.send(SpawnEvent {
position,
spawn: Spawn::Actor(*enemy_type),
spawn: Spawn::Actor(enemy_type.clone()),
});
}
None => {
Expand Down

0 comments on commit abb5c6d

Please sign in to comment.