/// <summary> /// Grabs an object /// </summary> /// <param name="_objectID">ID of the object to grab</param> public virtual void GrabObject(int _objectID) { // If the character already have a projectile, return if (projectile) { return; } // Find the object via photon ID & get its Throwable component PhotonView _objectPhoton = PhotonView.Find(_objectID); if (_objectPhoton) { TDS_Throwable _projectile = _objectPhoton.GetComponent <TDS_Throwable>(); if (!_projectile) { TDS_CustomDebug.CustomDebugLogWarning($"The object \"{_objectPhoton.name}\" couldn't be found"); return; } // If the character can grab the object, stock it if (_projectile.Grab(this)) { projectile = _projectile; } } else { TDS_CustomDebug.CustomDebugLogWarning($"The object with PhotonID \"{_objectID}\" doesn't have the \"TDS_Throwable\" component !"); return; } }
/// <summary> /// Link a throwable to this area. /// </summary> /// <param name="_throwable">Throwable to link.</param> public void LinkThrowable(TDS_Throwable _throwable) { if (!areaThrowables.Contains(_throwable)) { areaThrowables.Add(_throwable); _throwable.OnDestroyed += () => RemoveThrowable(_throwable); } }
/// <summary> /// Removes the throwable from the character. /// </summary> /// <returns>Returns true if successfully removed the throwable, false otherwise.</returns> public virtual bool RemoveThrowable() { if (!throwable) { return(false); } throwable = null; return(true); }
/// <summary> /// Try to grab a throwable. /// When grabbed, the object follows the character and can be thrown by this one. /// </summary> /// <param name="_throwable">ID of the throwable to try to grab.</param> /// <returns>Returns true if the throwable was successfully grabbed, false either.</returns> public virtual bool GrabObject(int _throwableID) { TDS_Throwable _throwable = PhotonView.Find(_throwableID).GetComponent <TDS_Throwable>(); if (!_throwable) { return(false); } return(GrabObject(_throwable)); }
/// <summary> /// Throw the grabed object /// </summary> public virtual void ThrowObject() { // If the character doesn't have a projectile to throw, return if (!projectile) { return; } // Throw the projectile and remove it from the current weared object projectile.Throw(FacingSide); projectile = null; }
/// <summary> /// Drop the graned object /// </summary> public virtual void DropObject() { // If the character doesn't have a projectile to drop, return if (!projectile) { return; } // Drop the projectile and remove it from the current weared object projectile.Drop(); projectile = null; }
/// <summary> /// Remove a throwable from this area. /// </summary> /// <param name="_throwable">Throwable to remove.</param> public void RemoveThrowable(TDS_Throwable _throwable) { if (areaThrowables.Contains(_throwable)) { areaThrowables.Remove(_throwable); if (isActivated) { CheckRemainingObjects(); } } }
/// <summary> /// Loots a random object from a given list. /// </summary> /// <param name="_availableLoot">List of available objects to loot.</param> /// <returns>Returns the looted object.</returns> protected override GameObject Loot(ref List <GameObject> _availableLoot) { GameObject _loot = base.Loot(ref _availableLoot); TDS_Throwable _throwable = _loot.GetComponent <TDS_Throwable>(); // Link the looted throwable to the first active spawn area found if (_throwable && (TDS_SpawnerArea.ActivatedAreas.Count > 0)) { TDS_SpawnerArea.ActivatedAreas[0].LinkThrowable(_throwable); } return(_loot); }
/// <summary> /// Try to grab a throwable. /// When grabbed, the object follows the character and can be thrown by this one. /// </summary> /// <param name="_throwable">Throwable to try to grab.</param> /// <returns>Returns true if the throwable was successfully grabbed, false either.</returns> public virtual bool GrabObject(TDS_Throwable _throwable) { // Call this method in master client only if (!PhotonNetwork.isMasterClient) { TDS_RPCManager.Instance.RPCPhotonView.RPC("CallMethodOnline", PhotonTargets.MasterClient, TDS_RPCManager.GetInfo(photonView, GetType(), "GrabObject"), new object[] { _throwable.photonView.viewID }); return(false); } // Take the object if possible if (throwable || !_throwable.PickUp(this)) { return(false); } return(true); }
/// <summary> /// Try to grab a throwable. /// When grabbed, the object follows the character and can be thrown by this one. /// </summary> /// <param name="_throwable">Throwable to try to grab.</param> /// <returns>Returns true if the throwable was successfully grabbed, false either.</returns> public override bool GrabObject(TDS_Throwable _throwable) { // Call this method in master client only if (!PhotonNetwork.isMasterClient) { TDS_RPCManager.Instance.RPCPhotonView.RPC("CallMethodOnline", PhotonTargets.MasterClient, TDS_RPCManager.GetInfo(photonView, GetType(), "GrabObject"), new object[] { _throwable.photonView.viewID }); return(false); } // If currently wearing the maximum amount of throwables he can, return if ((CurrentThrowableAmount == MaxThrowableAmount) || !_throwable.PickUp(this)) { return(false); } return(true); }
public override void ApplyAttackBehaviour(TDS_Enemy _caster) { if (thrownObjectName == string.Empty) { return; } GameObject _thrownObject = PhotonNetwork.Instantiate(thrownObjectName, _caster.HandsTransform.position, _caster.transform.rotation, 0); //Debug.LogError("Stop!"); if (!_thrownObject) { return; } TDS_Throwable _throwable = _thrownObject.GetComponent <TDS_Throwable>(); if (_throwable) { _throwable.HitBox.HittableTags = _caster.HitBox.HittableTags; _caster.GrabObject(_throwable); if (_throwable.ThrowableAttackEffectType == AttackEffectType.BringCloser) { _throwable.ObjectDurability = 1; //_throwable.HitBox.OnTouch += () => _caster.SetAnimationState((int)EnemyAnimationState.BringTargetCloser); _throwable.HitBox.OnStopAttack += _caster.NoTargetToBrought; } _caster.ThrowObject(_caster.PlayerTarget.transform.position); if (!_caster.IsFacingRight) { _thrownObject.transform.Rotate(Vector3.up, 180); _thrownObject.transform.localScale = new Vector3(_thrownObject.transform.localScale.x, _thrownObject.transform.localScale.y, _thrownObject.transform.localScale.z * -1); } } else if (_thrownObject.GetComponent <TDS_Projectile>()) { Vector3 _dir = _caster.IsFacingRight ? Vector3.right : Vector3.left; TDS_Projectile _proj = _thrownObject.GetComponent <TDS_Projectile>(); _proj.HitBox.HittableTags = _caster.HitBox.HittableTags; _proj.HitBox.Activate(this, _caster); _proj.StartProjectileMovement(_dir, MaxRange); } }
/// <summary> /// Set this character throwable. /// </summary> /// <param name="_throwable">Throwable to set.</param> /// <returns>Returns true if successfully set the throwable, false otherwise.</returns> public virtual bool SetThrowable(TDS_Throwable _throwable) { if (_throwable) { Throwable = _throwable; _throwable.transform.SetParent(handsTransform, true); _throwable.transform.localPosition = Vector3.zero; _throwable.transform.rotation = Quaternion.identity; if (!isFacingRight) { _throwable.transform.Rotate(Vector3.up, 180); _throwable.transform.localScale = new Vector3(_throwable.transform.localScale.x, _throwable.transform.localScale.y, _throwable.transform.localScale.z * -1); } return(true); } return(false); }
/// <summary> /// Set this character throwable. /// </summary> /// <param name="_throwable">Throwable to set.</param> /// <returns>Returns true if successfully set the throwable, false otherwise.</returns> public override bool SetThrowable(TDS_Throwable _throwable) { // Get if was juggling before taking this throwable bool _wasJuggling = CurrentThrowableAmount > 0; if (!_throwable) { return(false); } Throwable = _throwable; if (CurrentThrowableAmount > 0) { if (!_wasJuggling) { SetAnim(PlayerAnimState.HasObject); } // Updates juggling informations UpdateJuggleParameters(true); if (CurrentThrowableAmount == MaxThrowableAmount) { // Desactivates the detection box interactionBox.DisplayInteractionFeedback(false); } } // Triggers event if (photonView.isMine) { OnHasObject?.Invoke(true); } return(true); }
/// <summary> /// Switch the selected throwable with one among throwables juggling with. /// </summary> /// <param name="_doIncrease">Should the new throwable be at the increased index of the current one.</param> public void SwitchThrowable(bool _doIncrease) { // Do that for all other clients too if (photonView.isMine) { TDS_RPCManager.Instance.RPCPhotonView.RPC("CallMethodOnline", PhotonTargets.Others, TDS_RPCManager.GetInfo(photonView, GetType(), "SwitchThrowable"), new object[] { _doIncrease }); } // Get selected throwable & place the previous one in the juggling list TDS_Throwable _selected = null; Transform[] _objectAnchors = new Transform[objectAnchors.Length]; if (!_doIncrease) { _selected = Throwables[CurrentThrowableAmount - 1]; Throwables.RemoveAt(CurrentThrowableAmount - 1); Throwables.Insert(0, throwable); // Reorder the anchor array _objectAnchors[0] = objectAnchors[CurrentThrowableAmount - 1]; _objectAnchors[0].position = throwable.Sprite.bounds.center; throwable.transform.SetParent(_objectAnchors[0]); for (int _i = 0; _i < CurrentThrowableAmount - 1; _i++) { _objectAnchors[_i + 1] = objectAnchors[_i]; } for (int _i = CurrentThrowableAmount; _i < objectAnchors.Length; _i++) { _objectAnchors[_i] = objectAnchors[_i]; } } else { _selected = Throwables[0]; Throwables.RemoveAt(0); Throwables.Add(throwable); // Reorder the anchor array _objectAnchors[CurrentThrowableAmount - 1] = objectAnchors[0]; _objectAnchors[CurrentThrowableAmount - 1].position = throwable.Sprite.bounds.center; throwable.transform.SetParent(_objectAnchors[CurrentThrowableAmount - 1]); for (int _i = 0; _i < CurrentThrowableAmount - 1; _i++) { _objectAnchors[_i] = objectAnchors[_i + 1]; } for (int _i = CurrentThrowableAmount; _i < objectAnchors.Length; _i++) { _objectAnchors[_i] = objectAnchors[_i]; } } objectAnchors = _objectAnchors; // Stop coroutine if needed if (throwableLerpCoroutine != null) { StopCoroutine(throwableLerpCoroutine); throwableLerpCoroutine = null; } // Set the new throwable _selected.transform.SetParent(handsTransform, true); _selected.transform.rotation = Quaternion.identity; throwable = _selected; // Starts position lerp coroutine throwableLerpCoroutine = StartCoroutine(LerpThrowableToHand()); }