public async Task PlayActionAnimation_Animator(int actionId, AnimActionType animActionType, float playSpeedMultiplier) { // If animator is not null, play the action animation ActionAnimation actionAnimation; AnimationClip clip; float triggerDuration; float extraDuration; AudioClip audioClip; if (GameInstance.ActionAnimations.TryGetValue(actionId, out actionAnimation) && actionAnimation.GetData(this, out clip, out triggerDuration, out extraDuration, out audioClip)) { CacheAnimator.SetBool(ANIM_DO_ACTION, false); CacheAnimatorController[ANIM_STATE_ACTION_CLIP] = clip; if (audioClip != null) { AudioSource.PlayClipAtPoint(audioClip, CacheTransform.position, AudioManager.Singleton == null ? 1f : AudioManager.Singleton.sfxVolumeSetting.Level); } CacheAnimator.SetFloat(ANIM_ACTION_CLIP_MULTIPLIER, playSpeedMultiplier); CacheAnimator.SetBool(ANIM_DO_ACTION, true); // Waits by current transition + clip duration before end animation int waitDelay = (int)(1000 * (CacheAnimator.GetAnimatorTransitionInfo(0).duration + (clip.length / playSpeedMultiplier))); await Task.Delay(waitDelay); CacheAnimator.SetBool(ANIM_DO_ACTION, false); // Waits by current transition + extra duration before end playing animation state waitDelay = (int)(1000 * (CacheAnimator.GetAnimatorTransitionInfo(0).duration + (extraDuration / playSpeedMultiplier))); await Task.Delay(waitDelay); } }
public async Task PlayActionAnimation_LegacyAnimation(int actionId, AnimActionType animActionType, float playSpeedMultiplier) { // If animator is not null, play the action animation ActionAnimation actionAnimation; AnimationClip clip; float triggerDuration; float extraDuration; AudioClip audioClip; if (GameInstance.ActionAnimations.TryGetValue(actionId, out actionAnimation) && actionAnimation.GetData(this, out clip, out triggerDuration, out extraDuration, out audioClip)) { if (CacheAnimation.GetClip(LEGACY_CLIP_ACTION) != null) { CacheAnimation.RemoveClip(LEGACY_CLIP_ACTION); } CacheAnimation.AddClip(clip, LEGACY_CLIP_ACTION); if (audioClip != null) { AudioSource.PlayClipAtPoint(audioClip, CacheTransform.position, AudioManager.Singleton == null ? 1f : AudioManager.Singleton.sfxVolumeSetting.Level); } CrossFadeLegacyAnimation(LEGACY_CLIP_ACTION, legacyAnimationData.actionClipFadeLength); // Waits by current transition + clip duration before end animation int waitDelay = (int)(1000 * (clip.length / playSpeedMultiplier)); await Task.Delay(waitDelay); CrossFadeLegacyAnimation(legacyAnimationData.idleClip, legacyAnimationData.idleClipFadeLength); // Waits by current transition + extra duration before end playing animation state waitDelay = (int)(1000 * (extraDuration / playSpeedMultiplier)); await Task.Delay(waitDelay); } }
public ActionAnimation GetActionAnimation(AnimActionType animActionType, int dataId, int index) { ActionAnimation tempActionAnimation = default(ActionAnimation); switch (animActionType) { case AnimActionType.AttackRightHand: tempActionAnimation = GetRightHandAttackAnimations(dataId)[index]; break; case AnimActionType.AttackLeftHand: tempActionAnimation = GetLeftHandAttackAnimations(dataId)[index]; break; case AnimActionType.Skill: tempActionAnimation = GetSkillActivateAnimation(dataId); break; case AnimActionType.ReloadRightHand: tempActionAnimation = GetRightHandReloadAnimation(dataId); break; case AnimActionType.ReloadLeftHand: tempActionAnimation = GetLeftHandReloadAnimation(dataId); break; } return(tempActionAnimation); }
private IEnumerator PlayActionAnimation_LegacyAnimation(AnimActionType animActionType, int dataId, int index, float playSpeedMultiplier) { // If animator is not null, play the action animation ActionAnimation tempActionAnimation = GetActionAnimation(animActionType, dataId, index); if (legacyAnimation.GetClip(CLIP_ACTION) != null) { legacyAnimation.RemoveClip(CLIP_ACTION); } legacyAnimation.AddClip(tempActionAnimation.clip, CLIP_ACTION); AudioClip audioClip = tempActionAnimation.GetRandomAudioClip(); if (audioClip != null) { AudioSource.PlayClipAtPoint(audioClip, CacheTransform.position, AudioManager.Singleton == null ? 1f : AudioManager.Singleton.sfxVolumeSetting.Level); } isPlayingActionAnimation = true; CrossFadeLegacyAnimation(CLIP_ACTION, actionClipFadeLength, WrapMode.Once); // Waits by current transition + clip duration before end animation yield return(new WaitForSecondsRealtime(tempActionAnimation.GetClipLength() / playSpeedMultiplier)); CrossFadeLegacyAnimation(CLIP_IDLE, idleClipFadeLength, WrapMode.Loop); // Waits by current transition + extra duration before end playing animation state yield return(new WaitForSecondsRealtime(tempActionAnimation.GetExtraDuration() / playSpeedMultiplier)); isPlayingActionAnimation = false; }
private ActionAnimation2D GetActionAnimation(AnimActionType animActionType, int dataId) { ActionAnimation2D animation2D = null; switch (animActionType) { case AnimActionType.AttackRightHand: if (!CacheRightHandAttackAnimations.TryGetValue(dataId, out animation2D)) { animation2D = defaultAttackAnimation2D; } break; case AnimActionType.AttackLeftHand: if (!CacheLeftHandAttackAnimations.TryGetValue(dataId, out animation2D)) { animation2D = defaultAttackAnimation2D; } break; case AnimActionType.Skill: if (!CacheSkillCastAnimations.TryGetValue(dataId, out animation2D)) { animation2D = defaultSkillCastAnimation2D; } break; } return(animation2D); }
protected virtual void NetFuncReload(bool isLeftHand) { if (!CanAttack()) { return; } CharacterItem weapon; if (isLeftHand) { weapon = EquipWeapons.leftHand; } else { weapon = EquipWeapons.rightHand; } if (weapon.IsEmpty()) { return; } Item weaponItem = weapon.GetWeaponItem(); if (weaponItem != null && weaponItem.WeaponType != null && weaponItem.WeaponType.requireAmmoType != null && weaponItem.ammoCapacity > 0 && weapon.ammo < weaponItem.ammoCapacity) { // Prepare reload data AnimActionType animActionType = isLeftHand ? AnimActionType.ReloadLeftHand : AnimActionType.ReloadRightHand; int weaponTypeDataId = weaponItem.WeaponType.DataId; float triggerDuration = 0f; float totalDuration = 0f; if (!isLeftHand) { CharacterModel.GetRightHandReloadAnimation(weaponTypeDataId, out triggerDuration, out totalDuration); } else { CharacterModel.GetLeftHandReloadAnimation(weaponTypeDataId, out triggerDuration, out totalDuration); } int reloadingAmount = weaponItem.ammoCapacity - weapon.ammo; int inventoryAmount = this.CountAmmos(weaponItem.WeaponType.requireAmmoType); if (inventoryAmount < reloadingAmount) { reloadingAmount = inventoryAmount; } if (reloadingAmount > 0) { // Start reload routine isAttackingOrUsingSkill = true; StartCoroutine(ReloadRoutine(animActionType, weaponTypeDataId, triggerDuration, totalDuration, isLeftHand, weapon, (short)reloadingAmount)); } } }
private IEnumerator PlayActionAnimationRoutine(AnimActionType animActionType, int skillOrWeaponTypeDataId, int index) { this.animActionType = animActionType; float playSpeedMultiplier = 1f; switch (animActionType) { case AnimActionType.AttackRightHand: playSpeedMultiplier = CacheAtkSpeed; // Set doing action state at clients and server isAttackingOrUsingSkill = true; // Calculate move speed rate while doing action at clients and server moveSpeedRateWhileAttackOrUseSkill = 1f; if (EquipWeapons != null && EquipWeapons.rightHand != null && EquipWeapons.rightHand.GetWeaponItem() != null) { moveSpeedRateWhileAttackOrUseSkill = EquipWeapons.rightHand.GetWeaponItem().moveSpeedRateWhileAttacking; } break; case AnimActionType.AttackLeftHand: playSpeedMultiplier = CacheAtkSpeed; // Set doing action state at clients and server isAttackingOrUsingSkill = true; // Calculate move speed rate while doing action at clients and server moveSpeedRateWhileAttackOrUseSkill = 1f; if (EquipWeapons != null && EquipWeapons.leftHand != null && EquipWeapons.leftHand.GetWeaponItem() != null) { moveSpeedRateWhileAttackOrUseSkill = EquipWeapons.leftHand.GetWeaponItem().moveSpeedRateWhileAttacking; } break; case AnimActionType.Skill: // Set doing action state at clients and server isAttackingOrUsingSkill = true; // Calculate move speed rate while doing action at clients and server moveSpeedRateWhileAttackOrUseSkill = 1f; if (GameInstance.Skills.ContainsKey(skillOrWeaponTypeDataId)) { moveSpeedRateWhileAttackOrUseSkill = GameInstance.Skills[skillOrWeaponTypeDataId].moveSpeedRateWhileUsingSkill; } break; case AnimActionType.ReloadLeftHand: case AnimActionType.ReloadRightHand: // Set doing action state at clients and server isAttackingOrUsingSkill = true; // Calculate move speed rate while doing action at clients and server moveSpeedRateWhileAttackOrUseSkill = 1f; break; } if (CharacterModel != null) { yield return(CharacterModel.PlayActionAnimation(animActionType, skillOrWeaponTypeDataId, index, playSpeedMultiplier)); } // Set doing action state at clients and server this.animActionType = AnimActionType.None; isAttackingOrUsingSkill = false; }
public bool RequestPlayActionAnimation(AnimActionType animActionType, int dataId, byte animationIndex) { if (IsDead()) { return(false); } CallNetFunction(NetFuncPlayActionAnimation, FunctionReceivers.All, (byte)animActionType, dataId, animationIndex); return(true); }
public async Task PlayActionAnimation(int actionId, AnimActionType animActionType, float playSpeedMultiplier = 1f) { switch (animatorType) { case AnimatorType.Animator: await PlayActionAnimation_Animator(actionId, animActionType, playSpeedMultiplier); break; case AnimatorType.LegacyAnimtion: await PlayActionAnimation_LegacyAnimation(actionId, animActionType, playSpeedMultiplier); break; } }
private IEnumerator PlayActionAnimation_Animator(AnimActionType animActionType, int dataId, int index, float playSpeedMultiplier) { // If animator is not null, play the action animation HeroEditorActionAnimation animation = GetHeroEditorActionAnimation(animActionType, dataId); // Action Animator.SetFloat(ANIM_SPEED, playSpeedMultiplier); Animator.SetTrigger(animation.GetTriggerName()); AudioManager.PlaySfxClipAtAudioSource(animation.GetRandomAudioClip(), genericAudioSource); // Waits by current transition + clip duration before end animation yield return(new WaitForSecondsRealtime(animation.GetClipLength() / playSpeedMultiplier)); // Waits by current transition + extra duration before end playing animation state yield return(new WaitForSecondsRealtime(animation.GetExtraDuration() / playSpeedMultiplier)); }
public virtual void GetAttackingData( ref bool isLeftHand, out AnimActionType animActionType, out int dataId, out int animationIndex, out CharacterItem weapon, out float triggerDuration, out float totalDuration, out DamageInfo damageInfo, out Dictionary <DamageElement, MinMaxFloat> allDamageAmounts) { // Initialize data animActionType = AnimActionType.None; dataId = 0; animationIndex = 0; weapon = this.GetAvailableWeapon(ref isLeftHand); triggerDuration = 0f; totalDuration = 0f; damageInfo = null; allDamageAmounts = new Dictionary <DamageElement, MinMaxFloat>(); // Prepare weapon data Item weaponItem = weapon.GetWeaponItem(); WeaponType weaponType = weaponItem.WeaponType; // Assign data id dataId = weaponType.DataId; // Assign animation action type animActionType = !isLeftHand ? AnimActionType.AttackRightHand : AnimActionType.AttackLeftHand; // Random animation if (!isLeftHand) { CharacterModel.GetRandomRightHandAttackAnimation(dataId, out animationIndex, out triggerDuration, out totalDuration); } else { CharacterModel.GetRandomLeftHandAttackAnimation(dataId, out animationIndex, out triggerDuration, out totalDuration); } // Assign damage data damageInfo = weaponType.damageInfo; // Calculate all damages allDamageAmounts = GameDataHelpers.CombineDamages( allDamageAmounts, weaponItem.GetDamageAmount(weapon.level, weapon.GetEquipmentBonusRate(), this)); allDamageAmounts = GameDataHelpers.CombineDamages( allDamageAmounts, CacheIncreaseDamages); }
public override void GetAttackingData( ref bool isLeftHand, out AnimActionType animActionType, out int dataId, out int animationIndex, out CharacterItem weapon, out float triggerDuration, out float totalDuration, out DamageInfo damageInfo, out Dictionary <DamageElement, MinMaxFloat> allDamageAmounts) { // Initialize data isLeftHand = false; animActionType = AnimActionType.AttackRightHand; // Monster will not have weapon type so set dataId to `0`, then random attack animation from default attack animtions dataId = 0; // Monster will not have weapon data weapon = null; // Random attack animation CharacterModel.GetRandomRightHandAttackAnimation(dataId, out animationIndex, out triggerDuration, out totalDuration); // Assign damage data damageInfo = monsterCharacter.damageInfo; // Assign damage amounts allDamageAmounts = new Dictionary <DamageElement, MinMaxFloat>(); DamageElement damageElement = monsterCharacter.damageAmount.damageElement; MinMaxFloat damageAmount = monsterCharacter.damageAmount.amount.GetAmount(Level); if (damageElement == null) { damageElement = gameInstance.DefaultDamageElement; } allDamageAmounts.Add(damageElement, damageAmount); }
private IEnumerator ReloadRoutine( AnimActionType animActionType, int weaponTypeDataId, float triggerDuration, float totalDuration, bool isLeftHand, CharacterItem weapon, short reloadingAmount) { // Play animation on clients RequestPlayActionAnimation(animActionType, weaponTypeDataId, 0); yield return(new WaitForSecondsRealtime(triggerDuration)); // Prepare data EquipWeapons equipWeapons = EquipWeapons; Item weaponItem = weapon.GetWeaponItem(); Dictionary <CharacterItem, short> decreaseItems; if (this.DecreaseAmmos(weaponItem.WeaponType.requireAmmoType, reloadingAmount, out decreaseItems)) { weapon.ammo += reloadingAmount; if (isLeftHand) { equipWeapons.leftHand = weapon; } else { equipWeapons.rightHand = weapon; } EquipWeapons = equipWeapons; } yield return(new WaitForSecondsRealtime(totalDuration - triggerDuration)); isAttackingOrUsingSkill = false; }
public AnimInfos(AnimActionType _animType, Sprite _targetEntitySprite, RevealIcon _targetIcon) { animType = _animType; displaySprite = _targetEntitySprite; targetIcon = _targetIcon; }
private IEnumerator UseSkillRoutine( Skill skill, short level, AnimActionType animActionType, int skillOrWeaponTypeDataId, int animationIndex, float triggerDuration, float totalDuration, bool isLeftHand, CharacterItem weapon, DamageInfo damageInfo, Dictionary <DamageElement, MinMaxFloat> allDamageAmounts, bool hasAimPosition, Vector3 aimPosition) { if (onUseSkillRoutine != null) { onUseSkillRoutine.Invoke(skill, level, animActionType, skillOrWeaponTypeDataId, animationIndex, triggerDuration, totalDuration, isLeftHand, weapon, damageInfo, allDamageAmounts, hasAimPosition, aimPosition); } // Set doing action data isCastingSkillCanBeInterrupted = skill.canBeInterruptedWhileCasting; isCastingSkillInterrupted = false; float castDuration = skill.GetCastDuration(level); if (castDuration > 0f) { // Play casting effects on clients RequestPlayEffect(skill.castEffects.Id); // Tell clients that character is casting RequestSkillCasting(skill.DataId, castDuration); yield return(new WaitForSecondsRealtime(castDuration)); } // If skill casting not interrupted, continue doing action if (!isCastingSkillInterrupted || !isCastingSkillCanBeInterrupted) { // Play animation on clients RequestPlayActionAnimation(animActionType, skillOrWeaponTypeDataId, (byte)animationIndex); // Update skill usage states CharacterSkillUsage newSkillUsage = CharacterSkillUsage.Create(SkillUsageType.Skill, skill.DataId); newSkillUsage.Use(this, level); skillUsages.Add(newSkillUsage); yield return(new WaitForSecondsRealtime(triggerDuration)); // Reduce ammo amount if (skill.skillAttackType != SkillAttackType.None) { Dictionary <DamageElement, MinMaxFloat> increaseDamages; ReduceAmmo(weapon, isLeftHand, out increaseDamages); if (increaseDamages != null) { allDamageAmounts = GameDataHelpers.CombineDamages(allDamageAmounts, increaseDamages); } } ApplySkill(skill, level, isLeftHand, weapon, damageInfo, allDamageAmounts, hasAimPosition, aimPosition); yield return(new WaitForSecondsRealtime(totalDuration - triggerDuration)); } isAttackingOrUsingSkill = false; }
public virtual void GetUsingSkillData( Skill skill, short level, ref bool isLeftHand, out AnimActionType animActionType, out int skillOrWeaponTypeDataId, out int animationIndex, out CharacterItem weapon, out float triggerDuration, out float totalDuration, out DamageInfo damageInfo, out Dictionary <DamageElement, MinMaxFloat> allDamageAmounts) { // Initialize data animActionType = AnimActionType.None; skillOrWeaponTypeDataId = 0; animationIndex = 0; weapon = this.GetAvailableWeapon(ref isLeftHand); triggerDuration = 0f; totalDuration = 0f; damageInfo = null; allDamageAmounts = new Dictionary <DamageElement, MinMaxFloat>(); // Prepare skill data if (skill == null) { return; } // Prepare weapon data Item weaponItem = weapon.GetWeaponItem(); WeaponType weaponType = weaponItem.WeaponType; SkillActivateAnimationType useSkillActivateAnimationType = CharacterModel.UseSkillActivateAnimationType(skill); // Prepare animation if (useSkillActivateAnimationType == SkillActivateAnimationType.UseAttackAnimation && skill.skillAttackType != SkillAttackType.None) { // If there is no cast animations // Assign data id skillOrWeaponTypeDataId = weaponType.DataId; // Assign animation action type animActionType = !isLeftHand ? AnimActionType.AttackRightHand : AnimActionType.AttackLeftHand; // Random animation if (!isLeftHand) { CharacterModel.GetRandomRightHandAttackAnimation(skillOrWeaponTypeDataId, out animationIndex, out triggerDuration, out totalDuration); } else { CharacterModel.GetRandomLeftHandAttackAnimation(skillOrWeaponTypeDataId, out animationIndex, out triggerDuration, out totalDuration); } } else if (useSkillActivateAnimationType == SkillActivateAnimationType.UseActivateAnimation) { // Assign data id skillOrWeaponTypeDataId = skill.DataId; // Assign animation action type animActionType = AnimActionType.Skill; // Random animation CharacterModel.GetSkillActivateAnimation(skillOrWeaponTypeDataId, out triggerDuration, out totalDuration); } // If it is attack skill if (skill.skillAttackType != SkillAttackType.None) { switch (skill.skillAttackType) { case SkillAttackType.Normal: // Assign damage data damageInfo = skill.damageInfo; // Calculate all damages allDamageAmounts = weaponItem.GetDamageAmountWithInflictions(weapon.level, weapon.GetEquipmentBonusRate(), this, skill.GetWeaponDamageInflictions(level)); // Sum damage with additional damage amounts allDamageAmounts = GameDataHelpers.CombineDamages( allDamageAmounts, skill.GetDamageAmount(level, this)); // Sum damage with skill damage allDamageAmounts = GameDataHelpers.CombineDamages( allDamageAmounts, skill.GetAdditionalDamageAmounts(level)); break; case SkillAttackType.BasedOnWeapon: // Assign damage data damageInfo = weaponType.damageInfo; // Calculate all damages allDamageAmounts = weaponItem.GetDamageAmountWithInflictions(weapon.level, weapon.GetEquipmentBonusRate(), this, skill.GetWeaponDamageInflictions(level)); // Sum damage with additional damage amounts allDamageAmounts = GameDataHelpers.CombineDamages( allDamageAmounts, skill.GetAdditionalDamageAmounts(level)); break; } allDamageAmounts = GameDataHelpers.CombineDamages( allDamageAmounts, CacheIncreaseDamages); } }
public override void PlayActionAnimation(AnimActionType animActionType, int dataId, int index, float playSpeedMultiplier = 1f) { StartCoroutine(PlayActionAnimation_Animator(animActionType, dataId, index, playSpeedMultiplier)); }
private IEnumerator AttackRoutine( AnimActionType animActionType, int weaponTypeDataId, int animationIndex, float triggerDuration, float totalDuration, bool isLeftHand, CharacterItem weapon, DamageInfo damageInfo, Dictionary <DamageElement, MinMaxFloat> allDamageAmounts, bool hasAimPosition, Vector3 aimPosition) { if (onAttackRoutine != null) { onAttackRoutine.Invoke(animActionType, weaponTypeDataId, animationIndex, triggerDuration, totalDuration, isLeftHand, weapon, damageInfo, allDamageAmounts); } // Play animation on clients RequestPlayActionAnimation(animActionType, weaponTypeDataId, (byte)animationIndex); yield return(new WaitForSecondsRealtime(triggerDuration)); // Reduce ammo amount Dictionary <DamageElement, MinMaxFloat> increaseDamages; ReduceAmmo(weapon, isLeftHand, out increaseDamages); if (increaseDamages != null) { allDamageAmounts = GameDataHelpers.CombineDamages(allDamageAmounts, increaseDamages); } // If no aim position set with attack function get aim position which set from client-controller if existed if (!hasAimPosition && HasAimPosition) { hasAimPosition = true; aimPosition = AimPosition; } byte fireSpread = 0; Vector3 fireStagger = Vector3.zero; if (weapon != null && weapon.GetWeaponItem() != null) { Item weaponItem = weapon.GetWeaponItem(); // For monsters, their weapon can be null so have to avoid null exception fireSpread = weaponItem.fireSpread; fireStagger = weaponItem.fireStagger; } Vector3 stagger; for (int i = 0; i < fireSpread + 1; ++i) { stagger = new Vector3(Random.Range(-fireStagger.x, fireStagger.x), Random.Range(-fireStagger.y, fireStagger.y)); LaunchDamageEntity( isLeftHand, weapon, damageInfo, allDamageAmounts, CharacterBuff.Empty, 0, hasAimPosition, aimPosition, stagger); } RequestPlayWeaponLaunchEffect(isLeftHand); yield return(new WaitForSecondsRealtime(totalDuration - triggerDuration)); isAttackingOrUsingSkill = false; }
public override Coroutine PlayActionAnimation(AnimActionType animActionType, int dataId, int index, float playSpeedMultiplier = 1) { return(StartCoroutine(PlayActionAnimationRoutine(animActionType, dataId, index, playSpeedMultiplier))); }
private HeroEditorActionAnimation GetHeroEditorActionAnimation(AnimActionType animActionType, int dataId) { HeroEditorActionAnimation animation = defaultAnimations.attackAnimation; HeroEditorWeaponAnimation weaponAnimations; HeroEditorSkillAnimation skillAnimations; switch (animActionType) { case AnimActionType.AttackRightHand: if (!TryGetWeaponAnimations(dataId, out weaponAnimations)) { animation = defaultAnimations.attackAnimation; } else { animation = weaponAnimations.rightHandAttackAnimation; } break; case AnimActionType.AttackLeftHand: if (!TryGetWeaponAnimations(dataId, out weaponAnimations)) { animation = defaultAnimations.attackAnimation; } else { animation = weaponAnimations.leftHandAttackAnimation; } break; case AnimActionType.SkillRightHand: case AnimActionType.SkillLeftHand: if (!TryGetSkillAnimations(dataId, out skillAnimations)) { animation = defaultAnimations.skillActivateAnimation; } else { animation = skillAnimations.activateAnimation; } break; case AnimActionType.ReloadRightHand: if (!TryGetWeaponAnimations(dataId, out weaponAnimations)) { animation = defaultAnimations.reloadAnimation; } else { animation = weaponAnimations.rightHandReloadAnimation; } break; case AnimActionType.ReloadLeftHand: if (!TryGetWeaponAnimations(dataId, out weaponAnimations)) { animation = defaultAnimations.reloadAnimation; } else { animation = weaponAnimations.leftHandReloadAnimation; } break; } return(animation); }