/// <summary> /// On init we grab our components /// </summary> protected override void Initialization() { _characterHandleWeapon = this.gameObject.GetComponent <CharacterHandleWeapon>(); _aiActionShoot2D = this.gameObject.GetComponent <AIActionShoot2D>(); _aiActionShoot3D = this.gameObject.GetComponent <AIActionShoot3D>(); _controller = this.gameObject.GetComponent <TopDownController>(); }
/// <summary> /// When one of the weapons has ended its attack, we start our countdown and switch to the next weapon /// </summary> /// <param name="weaponThatStopped"></param> public virtual void WeaponStopped(Weapon weaponThatStopped) { OwnerCharacterHandleWeapon = Weapons[_currentWeaponIndex].CharacterHandleWeapon; int newIndex = 0; if (OwnerCharacterHandleWeapon != null) { if (Weapons.Length > 1) { if (_currentWeaponIndex < Weapons.Length - 1) { newIndex = _currentWeaponIndex + 1; } else { newIndex = 0; } _countdownActive = true; TimeSinceLastWeaponStopped = 0f; _currentWeaponIndex = newIndex; OwnerCharacterHandleWeapon.CurrentWeapon = Weapons[newIndex]; OwnerCharacterHandleWeapon.CurrentWeapon.WeaponCurrentlyActive = false; OwnerCharacterHandleWeapon.ChangeWeapon(Weapons[newIndex], Weapons[newIndex].WeaponID, true); OwnerCharacterHandleWeapon.CurrentWeapon.WeaponCurrentlyActive = true; } } }
/// <summary> /// Grabs all inventories, and fills weapon lists /// </summary> protected virtual void Setup() { GrabInventories(); if (CharacterHandleWeapon == null) { CharacterHandleWeapon = _character?.FindAbility <CharacterHandleWeapon> (); } FillAvailableWeaponsLists(); // we auto pick items if needed if (AutoPickItems.Length > 0) { foreach (AutoPickItem item in AutoPickItems) { MMInventoryEvent.Trigger(MMInventoryEventType.Pick, null, item.Item.TargetInventoryName, item.Item, item.Quantity, 0); } } // we auto equip a weapon if needed if (AutoEquipWeaponOnStart != null) { MMInventoryEvent.Trigger(MMInventoryEventType.Pick, null, AutoEquipWeaponOnStart.TargetInventoryName, AutoEquipWeaponOnStart, 1, 0); EquipWeapon(AutoEquipWeaponOnStart.ItemID); } }
/// <summary> /// Sets the weapon's owner /// </summary> /// <param name="newOwner">New owner.</param> public virtual void SetOwner(Character newOwner, CharacterHandleWeapon handleWeapon) { Owner = newOwner; if (Owner != null) { CharacterHandleWeapon = handleWeapon; _characterMovement = Owner.GetComponent <Character>()?.FindAbility <CharacterMovement>(); _controller = Owner.GetComponent <TopDownController>(); if (CharacterHandleWeapon.AutomaticallyBindAnimator) { if (CharacterHandleWeapon.CharacterAnimator != null) { _ownerAnimator = CharacterHandleWeapon.CharacterAnimator; } if (_ownerAnimator == null) { _ownerAnimator = CharacterHandleWeapon.gameObject.GetComponentInParent <Character>().CharacterAnimator; } if (_ownerAnimator == null) { _ownerAnimator = CharacterHandleWeapon.gameObject.GetComponentInParent <Animator>(); } } } }
/// <summary> /// What happens when the weapon gets picked /// </summary> protected override void Pick(GameObject picker) { Character character = _collidingObject.gameObject.MMGetComponentNoAlloc <Character>(); if (character == null) { return; } // we equip the weapon to the chosen CharacterHandleWeapon CharacterHandleWeapon targetHandleWeapon = null; CharacterHandleWeapon[] handleWeapons = character.GetComponentsInChildren <CharacterHandleWeapon>(); foreach (CharacterHandleWeapon handleWeapon in handleWeapons) { if (handleWeapon.HandleWeaponID == HandleWeaponID) { targetHandleWeapon = handleWeapon; } } if (targetHandleWeapon != null) { targetHandleWeapon.ChangeWeapon(WeaponToGive, null); } }
/// <summary> /// Grabs the CharacterHandleWeapon component and sets the weapon /// </summary> /// <param name="newWeapon">New weapon.</param> protected virtual void EquipWeapon(Weapon newWeapon) { if (EquippableWeapon == null) { return; } if (TargetInventory.Owner == null) { return; } Character character = TargetInventory.Owner.GetComponent <Character>(); if (character == null) { return; } // we equip the weapon to the chosen CharacterHandleWeapon CharacterHandleWeapon targetHandleWeapon = null; CharacterHandleWeapon[] handleWeapons = character.GetComponentsInChildren <CharacterHandleWeapon>(); foreach (CharacterHandleWeapon handleWeapon in handleWeapons) { if (handleWeapon.HandleWeaponID == HandleWeaponID) { targetHandleWeapon = handleWeapon; } } if (targetHandleWeapon != null) { targetHandleWeapon.ChangeWeapon(newWeapon, this.ItemID); } }
/// <summary> /// What happens when the weapon gets picked /// </summary> protected override void Pick(GameObject picker) { _handleWeapon = _collidingObject.gameObject.MMGetComponentNoAlloc <CharacterHandleWeapon>(); if (_handleWeapon != null) { if (_handleWeapon.CanPickupWeapons) { _handleWeapon.ChangeWeapon(WeaponToGive, null); } } }
/// <summary> /// On init we grab our model if necessary /// </summary> protected override void Initialization() { base.Initialization(); if (MovementRotatingModel == null) { MovementRotatingModel = _model; } _characterRun = this.gameObject.GetComponent <CharacterRun>(); _characterHandleWeapon = this.gameObject.GetComponent <CharacterHandleWeapon>(); if (WeaponRotatingModel == null) { WeaponRotatingModel = _model; } }
/// <summary> /// On init we grab our model if necessary /// </summary> protected override void Initialization() { base.Initialization(); if (MovementRotatingModel == null) { MovementRotatingModel = _model; } _characterHandleWeapon = _character?.FindAbility <CharacterHandleWeapon>(); if (WeaponRotatingModel == null) { WeaponRotatingModel = _model; } }
/// <summary> /// Triggered when something collides with the coin /// </summary> /// <param name="collider">Other.</param> protected override void Pick(GameObject picker) { _characterHandleWeapon = picker.MMGetComponentNoAlloc <CharacterHandleWeapon>(); if (_characterHandleWeapon == null) { return; } _explodudesWeapon = _characterHandleWeapon.CurrentWeapon.GetComponent <ExplodudesWeapon>(); if (_explodudesWeapon == null) { return; } _explodudesWeapon.MaximumAmountOfBombsAtOnce += BombsToAdd; _explodudesWeapon.RemainingBombs += BombsToAdd; }
/// <summary> /// Grabs the CharacterHandleWeapon component and sets the weapon /// </summary> /// <param name="newWeapon">New weapon.</param> protected virtual void EquipWeapon(Weapon newWeapon) { if (EquippableWeapon == null) { return; } if (TargetInventory.Owner == null) { return; } CharacterHandleWeapon characterHandleWeapon = TargetInventory.Owner.GetComponent <CharacterHandleWeapon>(); if (characterHandleWeapon != null) { characterHandleWeapon.ChangeWeapon(newWeapon, this.ItemID); } }
/// <summary> /// On awake we init our facing direction and grab components /// </summary> protected override void Awake() { base.Awake(); if (InitialFacingDirection == Character.FacingDirections.West) { IsFacingRight = false; _direction = -1; } else { IsFacingRight = true; _direction = 1; } Face(InitialFacingDirection); _directionLastFrame = 0; _characterHandleWeapon = this.gameObject.GetComponentInParent <CharacterHandleWeapon>(); CurrentFacingDirection = InitialFacingDirection; switch (InitialFacingDirection) { case Character.FacingDirections.East: _lastDirectionX = 1f; _lastDirectionY = 0f; break; case Character.FacingDirections.West: _lastDirectionX = -1f; _lastDirectionY = 0f; break; case Character.FacingDirections.North: _lastDirectionX = 0f; _lastDirectionY = 1f; break; case Character.FacingDirections.South: _lastDirectionX = 0f; _lastDirectionY = -1f; break; } }
/// <summary> /// Makes sure the collider matches our specs, and the angle is right. /// If yes, triggers the dash sequence /// </summary> protected virtual void TestForDash(Collider collider) { // if there's already a dash in progress, we do nothing and exit if ((_dashInProgress == true) || !DashAuthorized) { return; } // we make sure it's the right kind of character _character = collider.gameObject.MMGetComponentNoAlloc <Character>(); _characterDash3D = collider.gameObject.MMGetComponentNoAlloc <CharacterDash3D>(); if (_characterDash3D == null) { return; } // we make sure the angle is right _characterOrientation3D = collider.gameObject.MMGetComponentNoAlloc <CharacterOrientation3D>(); _direction1 = (_character.CharacterModel.transform.forward).normalized; _direction1.y = 0f; _direction2 = (this.transform.forward).normalized; _direction2.y = 0f; float angle = Vector3.Angle(_direction1, _direction2); if (angle > MaxFacingAngle) { return; } // we trigger the dash _characterHandleWeapon = collider.gameObject.MMGetComponentNoAlloc <CharacterHandleWeapon>(); // we start the sequence StartCoroutine(DashSequence()); }
/// <summary> /// On Update, we check for obstacles and prevent shooting if needed /// </summary> protected virtual void Update() { if (_weapon == null) { return; } if (_weapon.Owner == null) { return; } if (_characterHandleWeapon == null) { _characterHandleWeapon = _weapon.Owner.GetComponent <CharacterHandleWeapon>(); } if (_characterHandleWeapon == null) { return; } // if we've found an obstacle, we prevent shooting if (CheckForObstacles()) { _characterHandleWeapon.ShootStop(); _characterHandleWeapon.AbilityPermitted = false; _shootStopped = true; } else { // if we haven't found an obstacle and were preventing shoot, we resume if (_shootStopped) { _shootStopped = false; _characterHandleWeapon.AbilityPermitted = true; } } }
/// <summary> /// On Start we grab our CharacterHandleWeapon component /// </summary> protected virtual void Start() { _handleWeapon = this.GetComponentInParent <Character>()?.FindAbility <CharacterHandleWeapon>(); }
/// <summary> /// On init we grab our CharacterHandleWeapon ability /// </summary> protected override void Initialization() { _character = GetComponentInParent <Character>(); _orientation3D = _character?.FindAbility <CharacterOrientation3D>(); _characterHandleWeapon = _character?.FindAbility <CharacterHandleWeapon>(); }
/// <summary> /// Grabs all inventories, and fills weapon lists /// </summary> protected virtual void Setup() { GrabInventories(); _characterHandleWeapon = GetComponent <CharacterHandleWeapon> (); FillAvailableWeaponsLists(); }
/// <summary> /// On Start we grab our CharacterHandleWeapon component /// </summary> protected virtual void Start() { _handleWeapon = this.GetComponentInParent(typeof(CharacterHandleWeapon)) as CharacterHandleWeapon; }
/// <summary> /// On init we grab our components /// </summary> protected override void Initialization() { _characterHandleWeapon = this.gameObject.GetComponentInParent <Character>()?.FindAbility <CharacterHandleWeapon>(); _controller = this.gameObject.GetComponentInParent <TopDownController>(); _coneOfVision2D = this.gameObject.GetComponent <MMConeOfVision2D>(); }
/// <summary> /// On Awake we grab our CharacterHandleWeapon component /// </summary> protected virtual void Awake() { _characterHandleWeapon = this.gameObject.GetComponent <CharacterHandleWeapon>(); }
/// <summary> /// On init we grab our CharacterHandleWeapon ability /// </summary> protected override void Initialization() { _characterHandleWeapon = this.gameObject.GetComponent <CharacterHandleWeapon>(); }
/// <summary> /// On init we grab our CharacterHandleWeapon ability /// </summary> protected override void Initialization() { _characterHandleWeapon = this.gameObject.GetComponentInParent <Character>()?.FindAbility <CharacterHandleWeapon>(); }