Exemplo n.º 1
0
        public MainCharacter()
        {
            this.Id = nameof(MainCharacter) + ": " + NextId++;
            this.Tags.Add(nameof(MainCharacter));
            this.MoveTo(0, 0);
            this.Added.SubscribeForLifetime(() =>
            {
                Current = this;
            }, this.Lifetime);

            this.Inventory.SubscribeForLifetime(nameof(Inventory.PrimaryWeapon), () =>
            {
                if (Inventory.PrimaryWeapon != null)
                {
                    OnEquipWeapon.Fire(Inventory.PrimaryWeapon);
                }
            }, this.Lifetime);

            this.Inventory.SubscribeForLifetime(nameof(Inventory.ExplosiveWeapon), () =>
            {
                if (Inventory.PrimaryWeapon != null)
                {
                    OnEquipWeapon.Fire(Inventory.ExplosiveWeapon);
                }
            }, this.Lifetime);
            InitializeTargeting(SpaceTime.CurrentSpaceTime.Add(new AutoTargetingFunction(new AutoTargetingOptions()
            {
                Source      = this.Velocity,
                TargetsEval = () => SpaceTime.CurrentSpaceTime.Elements.Where(e => e.HasSimpleTag("enemy")),
            })));
        }
Exemplo n.º 2
0
        public MainCharacter()
        {
            this.Id = nameof(MainCharacter) + ": " + NextId++;
            this.MoveTo(0, 0);
            this.Added.SubscribeForLifetime(() =>
            {
                Current = this;
            }, this.Lifetime);

            this.Inventory.SubscribeForLifetime(nameof(Inventory.PrimaryWeapon), () =>
            {
                if (Inventory.PrimaryWeapon != null)
                {
                    OnEquipWeapon.Fire(Inventory.PrimaryWeapon);
                }
            }, this.Lifetime);

            this.Inventory.SubscribeForLifetime(nameof(Inventory.ExplosiveWeapon), () =>
            {
                if (Inventory.PrimaryWeapon != null)
                {
                    OnEquipWeapon.Fire(Inventory.ExplosiveWeapon);
                }
            }, this.Lifetime);
            InitializeTargeting();
        }
Exemplo n.º 3
0
        /// <summary> Performs a Fast equiping of a MWeapon</summary>
        /// <param name="weapon">Weapon to equip</param>
        /// <param name="doParent">Parent the weapon to the Hand, it also resets the scale to 1.1.1</param>
        public virtual void Equip_FAST(MWeapon weapon, bool doParent = true)
        {
            Weapon = weapon;

            if (debug)
            {
                Debug.Log($"<b>{name}:<color=cyan> [FAST EQUIP -> {Weapon.Holster.name} -> {Weapon.name}]</color> </b>");         //Debug
            }
            ExitAim();


            SendMessage(Weapon.IsRightHanded ? FreeRightHand : FreeLeftHand, true);  //IK REINS

            WeaponType   = Weapon.WeaponType;
            WeaponAction = WA.Idle;                                             //Set the Action to Equip
            CombatMode   = true;
            Weapon.PrepareWeapon(this);
            Weapon.GetComponent <ICollectable>()?.Pick();

            Weapon.PlaySound(0); //Play Draw Sound

            if (doParent)
            {
                Weapon.gameObject.SetActive(true);                                                             //Set the Game Object Instance Active
                ParentWeapon();
                Weapon.transform.SetLocalTransform(Weapon.PositionOffset, Weapon.RotationOffset, Vector3.one); //Local position when is Parent to the weapon
            }

            OnEquipWeapon.Invoke(Weapon.gameObject);
        }
Exemplo n.º 4
0
        /// <summary>Equip Weapon from Holders or from Inventory  (Called by the Animator)</summary>
        public virtual void Equip_Weapon()
        {
            //WeaponAction = WA.Equip;                                             //Set the Action to Equip
            WeaponAction = WA.Idle;                                             //Set the Action to Equip
            CombatMode   = true;

            if (ActiveWeapon == null)
            {
                return;
            }

            if (debug)
            {
                Debug.Log($"Equip Weapon Type: <b> {ActiveWeapon.WeaponType.name}</b>");
            }

            ActiveWeapon.HitLayer           = Aimer.AimLayer;                              //Update the Hit Mask on the Weapon
            ActiveWeapon.TriggerInteraction = Aimer.TriggerInteraction;                    //Update the Trigger Interatction on the Weapon

            if (UseHolders)                                                                //If Use Holders Means that the weapons are on the Holders
            {
                if (ActiveHolderTransform.transform.childCount > 0)                        //If there's a Weapon on the Holder
                {
                    ActiveWeaponGameObject = ActiveHolderTransform.GetChild(0).gameObject; //Set the Active Weapon as the First Child Inside the Holder

                    ActiveWeaponGameObject.transform.parent =
                        ActiveWeapon.RightHand ? RightHandEquipPoint : LeftHandEquipPoint; //Parent the Active Weapon to the Right/Left Hand
                    ActiveWeapon.Holder = ActiveHolderSide;

                    StartCoroutine(SmoothWeaponTransition
                                       (ActiveWeaponGameObject.transform, ActiveWeapon.PositionOffset, ActiveWeapon.RotationOffset, 0.3f)); //Smoothly put the weapon in the hand
                }
            }
            else if (UseInventory)                                                            //If Use Inventory means that the weapons are on the inventory
            {
                if (!AlreadyInstantiated)                                                     //Do this if the Instantiation is not handled Externally
                {
                    ActiveWeaponGameObject.transform.parent =
                        ActiveWeapon.RightHand ? RightHandEquipPoint : LeftHandEquipPoint;           //Parent the Active Weapon to the Right/Left Hand

                    ActiveWeaponGameObject.transform.localPosition    = ActiveWeapon.PositionOffset; //Set the Correct Position
                    ActiveWeaponGameObject.transform.localEulerAngles = ActiveWeapon.RotationOffset; //Set the Correct Rotation
                }
                ActiveWeaponGameObject.gameObject.SetActive(true);                                   //Set the Game Object Instance Active
            }

            ActiveWeapon.Owner     = transform;
            ActiveWeapon.IsEquiped = true;                                                     //Inform the weapon that it has been equipped

            OnEquipWeapon.Invoke(ActiveWeaponGameObject);                                      //Let everybody know that the weapon is equipped

            if (ActiveAbility)
            {
                ActiveAbility.ActivateAbility();                                               //Call For the first activation of the weapon when first Equipped
            }
        }
Exemplo n.º 5
0
        ///──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
        /// <summary>
        /// If the Rider had a weapon before mounting.. equip it.
        /// The weapon need an |IMWeapon| Interface, if not it wont be equiped
        /// </summary>
        public virtual void SetWeaponBeforeMounting(GameObject weapon)
        {
            if (weapon == null)
            {
                return;
            }
            if (weapon.GetComponent <IMWeapon>() == null)
            {
                return;                                                                                 //If the weapon doesn't have IMweapon Interface do nothing
            }
            /// Try the set to false the weapon if is not a Prefab ///

            SetActiveWeapon(weapon);

            isInCombatMode = true;

            Active_IMWeapon.Equiped();                                                                   //Let the weapon know that it has been Equiped

            EnableMountAttack(false);

            SetActiveHolder(Active_IMWeapon.Holder);                                                    //Set the Active Holder for the Active Weapon

            _weaponType = GetWeaponType();                                                              //Set the Weapon Type

            SetAction(WeaponActions.Idle);

            SetWeaponIdleAnimState(Active_IMWeapon.RightHand);                                          //Set the Correct Idle Hands Animations

            Active_IMWeapon.HitMask = HitMask;                                                          //Link the Hit Mask

            ActiveAbility = CombatAbilities.Find(ability => ability.WeaponType() == GetWeaponType());   //Find the Ability for the IMWeapon

            if (ActiveAbility)
            {
                ActiveAbility.ActivateAbility();
            }
            else
            {
                Debug.LogWarning("The Weapon is combatible but there's no Combat Ability available for it, please Add the matching ability it on the list of Combat Abilities");
            }

            OnEquipWeapon.Invoke(ActiveWeapon);

            LinkAnimator();
        }
Exemplo n.º 6
0
        /// <summary>Equip Weapon from holster or from Inventory  (Called by the Animator)</summary>
        public virtual void Equip_Weapon()
        {
            if (!Active)
            {
                return;
            }
            //if (Weapon.gameObject.IsPrefab()) return;   //Means the Weapon is a prefab and is not instantiated yet (MAKE A WAIT COROYTINE)

            WeaponAction = WA.Idle;                                             //Set the Action to Equip
            CombatMode   = true;

            if (Weapon == null)
            {
                return;
            }

            if (debug)
            {
                Debug.Log($"<B>{name}:<color=yellow> [Equip -> {Weapon.name}]</color></b> T{Time.time:F3}");
            }

            Weapon.PrepareWeapon(this);

            if (UseHolsters)                                                             //If Use holster Means that the weapons are on the holster
            {
                ParentWeapon();
                StartCoroutine(MTools.AlignTransformLocal(Weapon.transform, Weapon.PositionOffset, Weapon.RotationOffset, Vector3.one, HolsterTime)); //Smoothly put the weapon in the hand
            }
            else //if (UseInventory)                                                            //If Use Inventory means that the weapons are on the inventory
            {
                if (!AlreadyInstantiated)                                                     //Do this if the Instantiation is not handled Externally
                {
                    ParentWeapon();

                    Weapon.transform.localPosition    = Weapon.PositionOffset; //Set the Correct Position
                    Weapon.transform.localEulerAngles = Weapon.RotationOffset; //Set the Correct Rotation
                    Weapon.transform.localScale       = Vector3.one;           //Set the Correct Rotation
                }
                Weapon.gameObject.SetActive(true);                             //Set the Game Object Instance Active
            }

            OnEquipWeapon.Invoke(Weapon.gameObject); //Let everybody know that the weapon is equipped

            Weapon.PlaySound(WSound.Equip);          //Play Equip Sound
        }
Exemplo n.º 7
0
        /// <summary>If the Rider had a weapon before mounting.. equip it.
        /// The weapon need an |IMWeapon| Interface, if not it wont be equiped</summary>
        public virtual void SetWeaponBeforeMounting(GameObject weapon)
        {
            if (weapon == null)
            {
                return;
            }
            if (weapon.GetComponent <IMWeapon>() == null)
            {
                return;                                                                                 //If the weapon doesn't have IMweapon Interface do nothing
            }
            /// Try the set to false the weapon if is not a Prefab ///

            ActiveWeaponGameObject = weapon;

            CombatMode = true;

            ActiveWeapon.Owner              = transform;
            ActiveWeapon.IsEquiped          = true;                                                   //Let the weapon know that it has been Equiped
            ActiveWeapon.HitLayer           = Aimer.AimLayer;                                         //Link the Hit Mask
            ActiveWeapon.TriggerInteraction = Aimer.TriggerInteraction;                               //Link the Trigger Interatction

            SetActiveHolder(ActiveWeapon.Holder);                                                     //Set the Active Holder for the Active Weapon

            WeaponType = GetWeaponType();                                                             //Set the Weapon Type

            WeaponAction = WA.Idle;

            SetWeaponIdleAnimState(ActiveWeapon.RightHand);                                           //Set the Correct Idle Hands Animations

            SetActiveAbility();

            if (ActiveAbility)
            {
                ActiveAbility.ActivateAbility();
            }
            else
            {
                Debug.LogError("The Weapon is combatible but there's no Combat Ability available for it, please Add the matching ability it on the list of Combat Abilities");
            }

            OnEquipWeapon.Invoke(ActiveWeaponGameObject);
        }
Exemplo n.º 8
0
        public MainCharacter()
        {
            this.Id = nameof(MainCharacter) + ": " + NextId++;
            this.AddTag(nameof(MainCharacter));
            this.MoveTo(0, 0);
            this.Added.SubscribeForLifetime(() =>
            {
                Current = this;
                this.Lifetime.OnDisposed(() =>
                {
                    if (_current == this)
                    {
                        _current = null;
                    }
                });
            }, this.Lifetime);

            this.Inventory.SubscribeForLifetime(nameof(Inventory.PrimaryWeapon), () =>
            {
                if (Inventory.PrimaryWeapon != null)
                {
                    OnEquipWeapon.Fire(Inventory.PrimaryWeapon);
                }
            }, this.Lifetime);

            this.Inventory.SubscribeForLifetime(nameof(Inventory.ExplosiveWeapon), () =>
            {
                if (Inventory.PrimaryWeapon != null)
                {
                    OnEquipWeapon.Fire(Inventory.ExplosiveWeapon);
                }
            }, this.Lifetime);
            InitializeTargeting(SpaceTime.CurrentSpaceTime.Add(new AutoTargetingFunction(new AutoTargetingOptions()
            {
                Source    = this.Velocity,
                TargetTag = "enemy",
            })));
        }
Exemplo n.º 9
0
        /// <summary>If the Rider had a weapon before mounting.. equip it.
        /// The weapon need an |IMWeapon| Interface, if not it wont be equiped</summary>
        public virtual void SetWeaponBeforeMounting(MWeapon weapon)
        {
            if (weapon == null)
            {
                return;
            }
            Weapon = weapon;
            if (Weapon)                                        //If the weapon doesn't have IMweapon Interface do nothing
            {
                CombatMode = true;

                Weapon.PrepareWeapon(this);
                Holster_SetActive(Weapon.HolsterID);                                                //Set the Active holster for the Active Weapon

                WeaponType   = Weapon.WeaponType;                                                   //Set the Weapon Type
                WeaponAction = WA.Idle;
                OnEquipWeapon.Invoke(Weapon.gameObject);
                Weapon.GetComponent <ICollectable>()?.Pick();

                ExitAim();

                Weapon.gameObject.SetActive(true);                                      //Set the Game Object Instance Active
                ParentWeapon();

                SendMessage(Weapon.IsRightHanded ? FreeRightHand : FreeLeftHand, true);  //IK REINS Message


                if (debug)
                {
                    Debug.Log($"<b>{name}:<color=cyan> [EQUIP BEFORE MOUNTING -> {Weapon.Holster.name} -> {Weapon.name}]</color> </b>"); //Debug
                }
                Weapon.gameObject.SetActive(true);                                                                                       //Set the Game Object Instance Active
                ParentWeapon();

                Weapon.GetComponent <ICollectable>()?.Pick();
            }
        }