Example #1
0
 public TowerProjectile Init(WeakRef target)
 {
     this.Connect("body_entered", this, nameof(this.On_Enemy_Hit));
     if (target.GetRef() is Enemy targetRef)
     {
         targetRef.Connect("EnemyDied", this, nameof(this.On_Enemy_Died));
     }
     this.Target = target;
     return(this);
 }
Example #2
0
        /// Returns true once we have invoked or if we can't invoke
        public bool Invoke(uint Tick)
        {
            if (this.Tick > Tick)
            {
                return(false);
            }

            if (Node.GetRef() == null)
            {
                MDLog.Warn(LOG_CAT, "Node no longer exists for call");
                return(true);
            }

            Node Target = Node.GetRef() as Node;

            switch (Mode)
            {
            case MDRemoteMode.Master:
            case MDRemoteMode.MasterSync:
                if (Target.IsNetworkMaster())
                {
                    DoCall(Target);
                }

                break;

            case MDRemoteMode.PuppetSync:
            case MDRemoteMode.Puppet:
                if (!Target.IsNetworkMaster())
                {
                    DoCall(Target);
                }

                break;

            case MDRemoteMode.Remote:
            case MDRemoteMode.RemoteSync:
                DoCall(Target);
                break;
            }

            return(true);
        }
Example #3
0
        public override void _ApplySteering(TargetAcceleration acceleration, float delta)
        {
            RigidBody2D _body = (RigidBody2D)_body_ref.GetRef();

            if (_body == null)
            {
                return;
            }

            _applied_steering = true;

            _body.ApplyCentralImpulse(Utils.ToVector2(acceleration.linear));
            _body.ApplyTorqueImpulse(acceleration.angular);
            if (calculate_velocities)
            {
                linear_velocity  = Utils.ToVector3(_body.LinearVelocity);
                angular_velocity = _body.AngularVelocity;
            }
        }
Example #4
0
        public MDReplicatedCommandReplicator(MemberInfo Member, bool Reliable, MDReplicatedType ReplicatedType, WeakRef NodeRef, MDReplicatedSetting[] Settings)
            : base(Member, true, ReplicatedType, NodeRef, Settings)
        {
            GameSession = MDStatics.GetGameSession();
            Replicator  = GameSession.Replicator;
            GameClock   = GameSession.GetGameClock();
            Node node = NodeRef.GetRef() as Node;
            IMDCommandReplicator CommandReplicator = InitializeCommandReplicator(Member, node);

            CommandReplicator.MDSetSettings(Settings);
        }
Example #5
0
        public virtual void _ApplySlidingSteering(Vector3 accel, float delta)
        {
            KinematicBody2D _body = (KinematicBody2D)_body_ref.GetRef();

            if (_body == null)
            {
                return;
            }

            var velocity = Utils.ToVector2(linear_velocity + accel * delta).Clamped(linear_speed_max);

            if (apply_linear_drag)
            {
                velocity = velocity.LinearInterpolate(Vector2.Zero, linear_drag_percentage);
            }
            velocity = _body.MoveAndSlide(velocity);
            if (calculate_velocities)
            {
                linear_velocity = Utils.ToVector3(velocity);
            }
        }
Example #6
0
        /// <summary>
        /// Parses the settings we know about
        /// </summary>
        /// <param name="SettingsValues">A setting array that has been run through MDReplicator.ParseParameters</param>
        protected void ParseSettings(MDReplicatedSetting[] SettingsValues)
        {
            foreach (MDReplicatedSetting setting in SettingsValues)
            {
                switch ((Settings)setting.Key)
                {
                case Settings.OnValueChangedEvent:
                    Node Node = NodeRef.GetRef() as Node;
                    OnValueChangedMethodCallback = Node.GetType().GetMethodRecursive(setting.Value.ToString());
                    if (OnValueChangedMethodCallback == null)
                    {
                        OnValueChangedEventCallback = Node.GetType().GetEvent(setting.Value.ToString());
                    }
                    MDLog.CError(OnValueChangedMethodCallback == null && OnValueChangedEventCallback == null, LOG_CAT, $"Failed to find method or event with name {setting.Value.ToString()} on Node {Node.GetPath()}");
                    break;

                case Settings.Converter:
                    Type DataConverterType = Type.GetType(setting.Value.ToString());
                    DataConverter = MDStatics.CreateConverterOfType(DataConverterType);
                    break;

                case Settings.CallOnValueChangedEventLocally:
                    ShouldCallOnValueChangedCallbackLocally = setting.Value as bool? ?? false;
                    break;
                }
            }

            // We got no data converter, get default one
            if (DataConverter == null)
            {
                DataConverter = MDStatics.GetConverterForType(Member.GetUnderlyingType());
            }
        }
        /// <summary>
        /// Parses the settings we know about
        /// </summary>
        /// <param name="SettingsValues">A setting array that has been run through MDReplicator.ParseParameters</param>
        protected void ParseSettings(MDReplicatedSetting[] SettingsValues)
        {
            foreach (MDReplicatedSetting setting in SettingsValues)
            {
                switch ((Settings)setting.Key)
                {
                case Settings.OnValueChangedEvent:
                    Node Node = NodeRef.GetRef() as Node;
                    OnValueChangedCallback = Node.GetType().GetMethodRecursive(setting.Value.ToString());
                    break;

                case Settings.Converter:
                    Type DataConverterType = Type.GetType(setting.Value.ToString());
                    DataConverter = MDStatics.CreateConverterOfType(DataConverterType);
                    break;
                }
            }

            // We got no data converter, get default one
            if (DataConverter == null)
            {
                DataConverter = MDStatics.GetConverterForType(Member.GetUnderlyingType());
            }
        }
Example #8
0
        protected override void Dispose(bool disposing)
        {
            base.Dispose(disposing);

            if (exportPluginWeak != null)
            {
                // We need to dispose our export plugin before the editor destroys EditorSettings.
                // Otherwise, if the GC disposes it at a later time, EditorExportPlatformAndroid
                // will be freed after EditorSettings already was, and its device polling thread
                // will try to access the EditorSettings singleton, resulting in null dereferencing.
                (exportPluginWeak.GetRef() as GodotSharpExport)?.Dispose();

                exportPluginWeak.Dispose();
            }
        }
Example #9
0
 public bool IsFreed()
 {
     return(weakref.GetRef() == null);
 }
Example #10
0
 public void RemoveEnemy(WeakRef enemy)
 {
     CloseEnemies.RemoveAll(e => e.GetRef() == enemy.GetRef());
 }