-
Notifications
You must be signed in to change notification settings - Fork 142
Health System #394
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Health System #394
Changes from all commits
Commits
Show all changes
41 commits
Select commit
Hold shift + click to select a range
be4c626
Initial health/hunger system.
kirawi be2848b
Initial health/hunger system.
kirawi eb73c9b
Merge branch 'main' of github.com:feather-rs/feather
kirawi 83933c6
Starting to work on generalizing to all mobs.
kirawi 7cdd8ec
fix fmt
kirawi 7e83bc3
regeneration method implemented, working on hunger next.
kirawi ae32d0c
fix fmt
kirawi a60be30
Initial hunger methods.
kirawi b097712
hunger systems
kirawi 3f35b71
quick change
kirawi 56dfc58
wip
kirawi c239772
fmt
kirawi c5d4b78
clippy
kirawi 95d918e
wip
kirawi ab4a407
wip
kirawi 9966496
Merge remote-tracking branch 'upstream/main'
kirawi 5b3bf60
Merge branch 'main' of github.com:feather-rs/feather
kirawi 86af7a3
wip
kirawi 0008646
moved core event to quill
kirawi 72be25e
wip
kirawi 4ee4cee
wip
kirawi abfc718
wip
kirawi 6a5a4a8
wip
kirawi 96beeef
wip
kirawi 30c3ae5
wip
kirawi 989060a
wip
kirawi a108201
wip
kirawi e94891a
sos
kirawi ec59159
wip
kirawi 992cb7a
wip
kirawi 3a0fc32
Merge branch 'generic' of github.com:kirawi/feather
kirawi 4561963
wip
kirawi e1bd602
wip
kirawi ce77fac
wip
kirawi 6330b3f
error handling
kirawi 763ad09
Revert "wip"
kirawi 68be14c
Merge branch 'generic' of github.com:kirawi/feather into generic
kirawi d24a42d
fmt
kirawi 3f2e2bf
Merge branch 'generic' of github.com:kirawi/feather
kirawi 10740b3
wip
kirawi bb4baa5
wip
kirawi File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,40 @@ | ||
| use base::Gamemode; | ||
| use common::Game; | ||
| use ecs::{Entity, SysResult}; | ||
| use protocol::packets::client::ClientStatus; | ||
| use quill_common::events::entity_special_event_kind; | ||
|
|
||
| use crate::{ClientId, Server}; | ||
|
|
||
| pub fn handle_client_status( | ||
| game: &mut Game, | ||
| server: &mut Server, | ||
| player: Entity, | ||
| packet: ClientStatus, | ||
| ) -> SysResult { | ||
| match packet { | ||
| ClientStatus::PerformRespawn => { | ||
| let mut send_event = false; | ||
| { | ||
| let client_id = game.ecs.get::<ClientId>(player)?; | ||
| if let Some(client) = server.clients.get(*client_id) { | ||
| let gamemode = game.ecs.get::<Gamemode>(player)?; | ||
| client.send_respawn(*gamemode, false); | ||
|
|
||
| send_event = true; | ||
| } | ||
| } | ||
|
|
||
| if send_event { | ||
| game.ecs.insert_entity_event( | ||
| player, | ||
| entity_special_event_kind::EntityResurrectionEvent, | ||
| )?; | ||
| } | ||
| } | ||
|
|
||
| ClientStatus::RequestStats => {} | ||
| } | ||
|
|
||
| Ok(()) | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,109 @@ | ||
| use crate::{ClientId, Game, Server}; | ||
| use ecs::{SysResult, SystemExecutor}; | ||
| use quill_common::{ | ||
| components::{Health, Hunger}, | ||
| events::{ | ||
| entity_damage_event_kind, entity_regen_event_kind, entity_special_event_kind, | ||
| EntityHealthEvent, | ||
| }, | ||
| }; | ||
|
|
||
| pub fn register(_game: &mut Game, systems: &mut SystemExecutor<Game>) { | ||
| systems | ||
| .group::<Server>() | ||
| .add_system(entity_resurrection) | ||
| .add_system(entity_suicide) | ||
| .add_system(player_eating_regen) | ||
| .add_system(player_hunger) | ||
| .add_system(health_events_handler); | ||
| } | ||
|
|
||
| // TODO: Implement for entities besides players. | ||
| fn health_events_handler(game: &mut Game, server: &mut Server) -> SysResult { | ||
| for (entity, (event, health)) in game.ecs.query::<(&EntityHealthEvent, &mut Health)>().iter() { | ||
| match event { | ||
| EntityHealthEvent::Regen(amount) => health.heal(*amount), | ||
| EntityHealthEvent::Damage(amount) => health.harm(*amount), | ||
| } | ||
|
|
||
| if let Ok(client_id) = game.ecs.get::<ClientId>(entity) { | ||
| if let Some(client) = server.clients.get(*client_id) { | ||
| let hunger = game.ecs.entity(entity)?.get::<Hunger>()?; | ||
| client.update_status(&health, &hunger); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| Ok(()) | ||
| } | ||
|
|
||
| fn entity_resurrection(game: &mut Game, _server: &mut Server) -> SysResult { | ||
| let mut events = Vec::new(); | ||
|
|
||
| for (entity, (_, health)) in game | ||
| .ecs | ||
| .query::<( | ||
| &entity_special_event_kind::EntityResurrectionEvent, | ||
| &mut Health, | ||
| )>() | ||
| .iter() | ||
| { | ||
| events.push((entity, EntityHealthEvent::Regen(health.max_health))); | ||
| } | ||
|
|
||
| for (entity, event) in events { | ||
| game.ecs.insert_entity_event(entity, event)?; | ||
| } | ||
|
|
||
| Ok(()) | ||
| } | ||
|
|
||
| fn entity_suicide(game: &mut Game, _server: &mut Server) -> SysResult { | ||
| let mut events = Vec::new(); | ||
|
|
||
| for (entity, (_, health)) in game | ||
| .ecs | ||
| .query::<(&entity_special_event_kind::EntitySuicideEvent, &mut Health)>() | ||
| .iter() | ||
| { | ||
| events.push((entity, EntityHealthEvent::Damage(health.max_health))); | ||
| } | ||
|
|
||
| for (entity, event) in events { | ||
| game.ecs.insert_entity_event(entity, event)?; | ||
| } | ||
|
|
||
| Ok(()) | ||
| } | ||
|
|
||
| fn player_eating_regen(game: &mut Game, _server: &mut Server) -> SysResult { | ||
| let mut events = Vec::new(); | ||
|
|
||
| for (entity, _) in game.ecs.query::<&entity_regen_event_kind::Eating>().iter() { | ||
| events.push((entity, EntityHealthEvent::Regen(1))); | ||
| } | ||
|
|
||
| for (entity, event) in events { | ||
| game.ecs.insert_entity_event(entity, event)?; | ||
| } | ||
|
|
||
| Ok(()) | ||
| } | ||
|
|
||
| fn player_hunger(game: &mut Game, _server: &mut Server) -> SysResult { | ||
| let mut events = Vec::new(); | ||
|
|
||
| for (entity, _) in game | ||
| .ecs | ||
| .query::<&entity_damage_event_kind::Starvation>() | ||
| .iter() | ||
| { | ||
| events.push((entity, EntityHealthEvent::Damage(1))); | ||
| } | ||
|
|
||
| for (entity, event) in events { | ||
| game.ecs.insert_entity_event(entity, event)?; | ||
| } | ||
|
|
||
| Ok(()) | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.