aboutsummaryrefslogtreecommitdiffstats
path: root/rust/src/buff_phase.rs
diff options
context:
space:
mode:
authorLibravatar IcECreAm777 <31211782+IcECreAm777@users.noreply.github.com>2022-07-16 15:03:50 +0200
committerLibravatar IcECreAm777 <31211782+IcECreAm777@users.noreply.github.com>2022-07-16 15:03:50 +0200
commit4435579498beefeb75b524111d24b1cb922cd22a (patch)
tree026b0ad61d6abb5deb736e69015a897a3283c6cf /rust/src/buff_phase.rs
parentf2ad01fe09709bc32b9b06a0aecc4c1b4d0a870d (diff)
parent9739b6d40258440cef4f7664f501efa81497263b (diff)
download2022-4435579498beefeb75b524111d24b1cb922cd22a.tar.gz
2022-4435579498beefeb75b524111d24b1cb922cd22a.tar.bz2
2022-4435579498beefeb75b524111d24b1cb922cd22a.zip
Merge branch 'BuffSystem'
Diffstat (limited to 'rust/src/buff_phase.rs')
-rw-r--r--rust/src/buff_phase.rs60
1 files changed, 60 insertions, 0 deletions
diff --git a/rust/src/buff_phase.rs b/rust/src/buff_phase.rs
new file mode 100644
index 0000000..e64508e
--- /dev/null
+++ b/rust/src/buff_phase.rs
@@ -0,0 +1,60 @@
+use gdnative::api::*;
+use gdnative::prelude::*;
+use crate::buff_trait::Buff;
+
+struct BuffPhase {
+ name: String,
+ description: String,
+ rigid_body: Option<Ref<RigidBody>>,
+
+ wall_layer_bit: i64,
+}
+
+impl BuffPhase {
+ fn new(rigid_body: Option<Ref<RigidBody>>) -> Self {
+ // calculate the bit for the mask to enable/ disable collision detection
+ let mask_layer = 2;
+ let mask_bit = 2_i64.pow(mask_layer - 1);
+
+ BuffPhase {
+ name: String::from("Phase"),
+ description: String::from("Phases through thin fences"),
+ rigid_body,
+
+ wall_layer_bit: mask_bit,
+ }
+ }
+}
+
+impl Buff for BuffPhase {
+ unsafe fn execute_buff(&mut self) {
+ match &self.rigid_body {
+ Some(body) => {
+ // actually disable the collision to the fences
+ let save_body = body.assume_safe();
+ save_body.set_collision_mask_bit(self.wall_layer_bit, false);
+ },
+ None => godot_warn!("Rigid body not found")
+ }
+ }
+
+ unsafe fn revert_buff(& mut self) {
+ // make sure the rigid body exists
+ match &self.rigid_body {
+ Some(body) => {
+ // actually enable the collision again
+ let save_body = body.assume_safe();
+ save_body.set_collision_mask_bit(self.wall_layer_bit, false);
+ },
+ None => godot_warn!("Rigid body not found")
+ }
+ }
+
+ fn get_name(self) -> GodotString {
+ GodotString::from_str(self.name)
+ }
+
+ fn get_description(self) -> GodotString {
+ GodotString::from_str(self.description)
+ }
+}