aboutsummaryrefslogtreecommitdiffstats
path: root/src/shared/player.rs
blob: f65851d67c3c839afe6b2c3628cc51a80f046909 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
use crate::protocol::*;
use crate::shared::activation::*;
use crate::shared::buffs::*;
use crate::shared::champion::*;
use crate::shared::cooldown::*;
use crate::shared::faction::*;
use crate::shared::health::*;
use crate::shared::imperative::*;
use crate::shared::name::*;
use crate::shared::shape::*;
use crate::shared::stats::*;
use bevy::prelude::*;
use lightyear::prelude::*;
use serde::*;

#[derive(Bundle)]
pub struct PlayerBundle {
    id: PlayerId,
    position: PlayerPosition,
    color: PlayerColor,
    imperative: Imperative,
    cooldown: Cooldown,
    health: Health,
    champion: Champion,
    effective_stats: EffectiveStats,
    buffs: Buffs,
    activation: Activation,
    shape: Shape,
    faction: Faction,
    player: Player,
    name: Name_,
    replicate: Replicate,
}

impl PlayerBundle {
    pub fn new(id: ClientId, name: String, position: Vec2, color: Color) -> Self {
        let mut replicate = Replicate {
            replication_group: ReplicationGroup::default().set_priority(10.),
            ..Default::default()
        };
        replicate.enable_replicate_once::<PlayerId>();
        replicate.enable_replicate_once::<PlayerColor>();
        replicate.target::<Champion>(NetworkTarget::Single(id));
        replicate.target::<Cooldown>(NetworkTarget::Single(id));
        replicate.target::<EffectiveStats>(NetworkTarget::Single(id));
        let champion = Champion::default();
        let effective_stats = EffectiveStats(champion.base_stats().0);
        PlayerBundle {
            id: PlayerId(id),
            position: PlayerPosition(position),
            color: PlayerColor(color),
            imperative: Imperative::Idle,
            cooldown: Cooldown::default(),
            health: Health {
                health: effective_stats.0.max_health,
                shield: 0.,
            },
            champion,
            effective_stats,
            buffs: Buffs::default(),
            activation: Activation::default(),
            shape: Shape::player(),
            faction: Faction::default(),
            player: Player::default(),
            name: Name_(name),
            replicate,
        }
    }
}

#[derive(Component, Message, Serialize, Deserialize, Clone, Copy, Debug, PartialEq, Eq)]
pub struct PlayerId(pub ClientId);

#[derive(Component, Message, Serialize, Deserialize, Clone, Copy, Debug, PartialEq)]
pub struct PlayerPosition(pub Vec2);

#[derive(Component, Message, Serialize, Deserialize, Clone, Debug, PartialEq)]
pub struct PlayerColor(pub Color);

#[derive(Component, Message, Serialize, Deserialize, Clone, Debug, PartialEq, Eq, Default)]
pub struct Player;