public virtual IEnumerator ApplyDamage(DamageParameter damageParam) { if (unit.IsDead) { yield break; } if (unit.receiveDamageStatus == UnitReceiveDamageStatus.invincible) { yield break; } //Minus HP: unit.HP -= damageParam.damagePoint; //if HP < 0, goto Die routine if (unit.HP <= 0) { SendMessage("Die", damageParam); yield break; } //Else, goto DoDamage routine. else { StartCoroutine("DoDamage", damageParam); this.unit.ReceiveDamageCounter++; yield break; } }
IEnumerator ApplyDamage(DamageParameter damageParam) { Transform trans = damageParam.src.transform; Vector3 attackerLocalPos = transform.InverseTransformPoint(trans.position); bool shouldFall = damageParam.damagePoint >= StrikePowerToHitFall; //Attacker in front if (attackerLocalPos.z >= 0) { if (shouldFall) { string fallAni = Util.RandomFromArray(ReceiveHitDownBackwardDamageAnimation); animation.CrossFade(fallAni); yield return new WaitForSeconds(animation[fallAni].length); } else animation.CrossFade(Util.RandomFromArray(ReceiveFrontDamageAnimations)); } //Attacker in back else { if (shouldFall) { string fallAni = Util.RandomFromArray(ReceiveHitDownForwardDamageAnimation); animation.CrossFade(fallAni); yield return new WaitForSeconds(animation[fallAni].length); } else animation.CrossFade(Util.RandomFromArray(ReceiveBackDamageAnimations)); } yield return null; }
/// <summary> /// on receive damage /// </summary> /// <param name="param"></param> void ApplyDamage(DamageParameter param) { if (param.damagePoint > 0 && stealth) { SendMessage("CloakOut"); } }
public virtual IEnumerator ApplyDamage(DamageParameter damageParam) { if (unit.IsDead) { yield break; } if(unit.receiveDamageStatus == UnitReceiveDamageStatus.invincible) { yield break; } //Minus HP: unit.HP -= damageParam.damagePoint; //if HP < 0, goto Die routine if (unit.HP <= 0) { SendMessage("Die", damageParam); yield break; } //Else, goto DoDamage routine. else { StartCoroutine("DoDamage", damageParam); this.unit.ReceiveDamageCounter++; yield break; } }
/// <summary> /// Usually, this method is invoked by AIApplyDamage.ApplyDamage() /// </summary> void Die(DamageParameter dp) { foreach(GameEvent _e in eventOnUnitDie) { _e.sender = this.gameObject; LevelManager.OnGameEvent(_e, this); } }
/// <summary> /// Usually, this method is invoked by AIApplyDamage.ApplyDamage() /// </summary> void Die(DamageParameter dp) { foreach (GameEvent _e in eventOnUnitDie) { _e.sender = this.gameObject; LevelManager.OnGameEvent(_e, this); } }
IEnumerator ApplyDamage(DamageParameter param) { yield return new WaitForEndOfFrame(); GameEvent _e = new GameEvent(GameEventType.DisplayDamageParameterOnPlayer); _e.ObjectParameter = param; _e.Vector2Parameter = new Vector2(RectOfHealthRealtime.x + RectOfHealthRealtime.width, RectOfHealthRealtime.y + RectOfHealthRealtime.height); //send gameEvent to display player damage number SendMessage("OnGameEvent", _e); }
/// <summary> /// Sends the ApplyDamage message to enemy. /// </summary> public IEnumerator SendHitMessage(PredatorPlayerAttackData attackData, GameObject enemy) { if (enemy == null) { yield break; } //if attackData.hitTime > 0, wait for the hitTime. if (Mathf.Approximately(attackData.HitTime, 0) == false) { yield return(new WaitForSeconds(attackData.HitTime)); } //in case the enemy object is destoryed between the previous yield time. if (enemy == null) { yield break; } //if attack type = Instant, means there is only one target to be attacked. if (attackData.Type == AIAttackType.Instant) { if (CheckHitCondition(enemy, attackData)) { //send applyDamage to target. DamageParameter damageParam = GetDamageParameter(attackData); enemy.SendMessage("ApplyDamage", damageParam); //at each hit, plus the rage this.PredatorPlayerUnit.Rage = Mathf.Clamp(this.PredatorPlayerUnit.Rage + this.PredatorPlayerUnit.RageEarnPerHit, 0, this.PredatorPlayerUnit.MaxRage); //send GameEvent to HUD to display the damage text. GameEvent _e = new GameEvent(GameEventType.DisplayDamageParameterOnNPC); _e.receiver = enemy; _e.ObjectParameter = damageParam; PredatorPlayerUnit.HUDObject.SendMessage("OnGameEvent", _e); } } else if (attackData.Type == AIAttackType.Regional) { Collider[] colliders = Physics.OverlapSphere(transform.position, this.RushRadius, this.EnemyLayer); foreach (Collider collider in colliders) { if (attackData.HitTestCollider.bounds.Intersects(collider.bounds)) { //send applyDamage to every object intersect with the hitTestCollider. DamageParameter damageParam = GetDamageParameter(attackData); collider.gameObject.SendMessage("ApplyDamage", damageParam); // this.SendMessage("AddRage", damageParam); //send GameEvent to HUD to display the damage text. GameEvent _e = new GameEvent(GameEventType.DisplayDamageParameterOnNPC); _e.receiver = collider.gameObject; _e.ObjectParameter = damageParam; PredatorPlayerUnit.HUDObject.SendMessage("OnGameEvent", _e); } } } }
IEnumerator ApplyDamage(DamageParameter param) { yield return(new WaitForEndOfFrame()); GameEvent _e = new GameEvent(GameEventType.DisplayDamageParameterOnPlayer); _e.ObjectParameter = param; _e.Vector2Parameter = new Vector2(RectOfHealthRealtime.x + RectOfHealthRealtime.width, RectOfHealthRealtime.y + RectOfHealthRealtime.height); //send gameEvent to display player damage number SendMessage("OnGameEvent", _e); }
/// <summary> /// CALL this method, when the unit apply a damageParameter. /// </summary> public void UpdateDamageInfo(DamageParameter dp) { switch (this.applyDamageConditionType) { case ApplyDamageConditionType.ReceiveDamageAmountGreaterThanValue: this.CurrentDamageAmount += dp.damagePoint; break; case ApplyDamageConditionType.ReceiveDamageAmountInTimePeriod: this.CurrentDamageAmount += dp.damagePoint; this.LastResetTime = Time.time; break; } }
void Fire(Transform target) { Object.Instantiate(electric, ParticlePivot.position, ParticlePivot.rotation); CharacterController controller = target.GetComponent <CharacterController>(); bool isHit = BoundToDetectHit.bounds.Intersects(controller.collider.bounds); if (isHit) { DamageParameter dP = new DamageParameter(this.gameObject, DamageForm.ElectricityBoltHit, HitPower); target.SendMessage("ApplyDamage", dP); if (paralysisTaget) { target.SendMessage("Decelerate", 0.8f); } } }
IEnumerator PunctureAndFetch() { //Avoid frequent invoking if (PredatorPlayerStatus.IsAttacking == true || HasFetchSomething) { yield break; } if ((currentFetchedObject = FindFetchable(FetchRadius)) != null) { Util.RotateToward(transform, currentFetchedObject.collider.bounds.center, false, 0); float TargetHP = currentFetchedObject.GetComponent <UnitHealth>().GetCurrentHP(); //Puncture only, or puncture to kill then lift if (TargetHP <= PunctureTossPower) { animation.CrossFade(FetchLiftAnimation); yield return(new WaitForSeconds(0.5f)); //Send apply damage message DamageParameter dP = new DamageParameter(this.gameObject, DamageForm.Punctured, PunctureTossPower); dP.extraParameter.Add(DamageParameter.ExtraParameterKey.PuncturedAnchor, this.FetchAnchor); currentFetchedObject.SendMessage("ApplyDamage", dP); HasFetchSomething = true; float liftTime = animation[FetchLiftAnimation].length - 0.5f; animation.CrossFade(FetchLiftAnimation); yield return(new WaitForSeconds(liftTime)); animation.CrossFade(FetchHoldAnimation); } else { animation.CrossFade(PunctureAnimation); yield return(new WaitForSeconds(0.5f)); DamageParameter dP = new DamageParameter(this.gameObject, DamageForm.Predator_Strike_Single_Claw, PunctureTossPower); currentFetchedObject.SendMessage("ApplyDamage", dP); } } //No object fetched, animating only else { animation.CrossFade(PunctureAnimation); Debug.Log("No object to fetch!"); //yield return new WaitForSeconds(FetchAnimationLength * 1.75f); //animation.Stop(PunctureAnimation); } yield return(null); }
public virtual IEnumerator ApplyDamage(DamageParameter param) { predatorPlayerUnit.HP -= param.damagePoint; predatorPlayerUnit.HUDObject.SendMessage("ApplyDamage", param); predatorPlayerUnit.Rage = Mathf.Clamp(this.predatorPlayerUnit.Rage + this.predatorPlayerUnit.RageEarnPerBeingHit, 0, this.predatorPlayerUnit.MaxRage); // Debug.Log("ApplyDamage at PredatorPlayer, current HP:" + predatorPlayerUnit.HP); switch (param.damageForm) { case DamageForm.ElectricityBoltHit: electricityHitEffect.Play(); break; } if (predatorPlayerUnit.HP <= 0) { yield return(StartCoroutine("Die", param)); } }
/// <summary> /// Handles the display damageparameter gameevent. Display damage on NPC or player. /// For Player, the start screen position is given in gameEvent.ObjectParameter as Vector2. /// For NPC, the DamageParameter is given in gameEvent.ObjectParameter as DamageParameter. /// </summary> public void OnGameEvent(GameEvent _e) { DamageParameter dp = _e.ObjectParameter as DamageParameter; switch (_e.type) { case GameEventType.DisplayDamageParameterOnNPC: dp = _e.ObjectParameter as DamageParameter; ShowNumberOverGameObject(_e.receiver, Mathf.RoundToInt(dp.damagePoint), NormalNPCDamagePointFadeSetting); break; case GameEventType.DisplayDamageParameterOnPlayer: Vector2 GUIPosition = _e.Vector2Parameter; ShowNumber(GUIPosition, Mathf.RoundToInt(dp.damagePoint), PlayerDamagePointFadeSetting); break; } }
public virtual IEnumerator ApplyDamage(DamageParameter param) { predatorPlayerUnit.HP -= param.damagePoint; predatorPlayerUnit.HUDObject.SendMessage("ApplyDamage", param); predatorPlayerUnit.Rage = Mathf.Clamp(this.predatorPlayerUnit.Rage + this.predatorPlayerUnit.RageEarnPerBeingHit, 0, this.predatorPlayerUnit.MaxRage); // Debug.Log("ApplyDamage at PredatorPlayer, current HP:" + predatorPlayerUnit.HP); switch (param.damageForm) { case DamageForm.ElectricityBoltHit: electricityHitEffect.Play(); break; } if(predatorPlayerUnit.HP <= 0) { yield return StartCoroutine("Die", param); } }
public DamageParameter GetDamageParameter(PredatorPlayerAttackData attackData) { DamageParameter dp = new DamageParameter(this.gameObject, attackData.DamageForm, 0); UnityEngine.Random.seed = DateTime.Now.Millisecond; //calculate damage point = base point + random(min, max) dp.damagePoint = attackData.DamagePointBase + UnityEngine.Random.Range(attackData.MinDamageBonus, attackData.MaxDamageBonus); //if critical attack is enabled and random chance matches, multiple the bonus rate. //Usually, designer can put the critical attack chance to the final combat of a combo-combat, this is like the great-final hit. if (attackData.CanDoCriticalAttack && UnityEngine.Random.Range(0f, 1f) <= attackData.CriticalAttackChance) { dp.damagePoint *= attackData.CriticalAttackBonusRate; dp.extraParameter.Add(DamageParameter.ExtraParameterKey.IsCriticalStrike, true); dp.extraParameter.Add(DamageParameter.ExtraParameterKey.CritcialStrikeRate, attackData.CriticalAttackBonusRate); } return(dp); }
public virtual IEnumerator Die(DamageParameter param) { if(canDie == false) yield break; // Destroy(this.transform.root.gameObject); // yield return null; foreach(GameEvent e in DieEvents) { LevelManager.OnGameEvent(e, this); } animation.Play(this.DieAnimation); this.GetComponent<CharacterController>().enabled = false; foreach(MonoBehaviour mono in this.GetComponents<MonoBehaviour>()) { mono.enabled = false; } yield break; }
IEnumerator ApplyDamage(DamageParameter damageParam) { HitCounter++; HP -= damageParam.damagePoint; //if (HP > 0) //{ // //Play from beginning every time receives a damage // CurrentSpeed = 0; // string getHitAni = Util.RandomFromArray(this.ReceiveDamageAnimations); // animation.Rewind(getHitAni); // animation.CrossFade(getHitAni); // LastHitTime = Time.time; // LastHitAnimationDuration = animation[getHitAni].length; // yield return new WaitForSeconds(animation[getHitAni].length); // //For the first time get hit, stop sawing and escape from the monster! // if (HitCounter == 1) // { // if (canEscape) // { // StopCoroutine(defaultBeheavior); // animation.Stop(); // CurrentSpeed = RunToOffenseSpeed; // Invoke("Escape", animation[getHitAni].length); // } // else // { // StopCoroutine("Sawing"); // animation.Stop(); // StartCoroutine("Attack"); // } // } //} //else //{ // StopAllCoroutines(); // animation.Stop(); // SendMessage("Die", damageParam.damageForm); // currentTarget = null; //} yield return(null); }
public virtual IEnumerator Die(DamageParameter param) { if (canDie == false) { yield break; } // Destroy(this.transform.root.gameObject); // yield return null; foreach (GameEvent e in DieEvents) { LevelManager.OnGameEvent(e, this); } animation.Play(this.DieAnimation); this.GetComponent <CharacterController>().enabled = false; foreach (MonoBehaviour mono in this.GetComponents <MonoBehaviour>()) { mono.enabled = false; } yield break; }
/// <summary> /// Receives a damageParam, and performs consequential behavior - play particle, play animation..etc. /// </summary> public virtual IEnumerator DoDamage(DamageParameter damageParam) { #region Look for the suitable ReceiveDamageData //if there is no receive damage defined, quit now! if (this.unit.ReceiveDamageData.Length == 0) { yield break; } foreach (ApplyDamagerCondition applyDamageCondition in ApplyDamagerConditionArray) { applyDamageCondition.UpdateDamageInfo(damageParam); } //Get ReceiveDamageData ReceiveDamageData receiveDamageData = null; if (unit.ReceiveDamageDataDict.ContainsKey(damageParam.damageForm)) { if (unit.ReceiveDamageDataDict[damageParam.damageForm].Count == 1) { receiveDamageData = unit.ReceiveDamageDataDict[damageParam.damageForm][0]; } else //if more than one matched receive damage data is found, randomly choose one. { int RandomIndex = Random.Range(0, unit.ReceiveDamageDataDict[damageParam.damageForm].Count); receiveDamageData = unit.ReceiveDamageDataDict[damageParam.damageForm][RandomIndex]; } } //If ReceiveDamageDataDict[DamageForm.Common] = null or Count ==0, will have error! //So make sure you have assign a Common receive damage data! else { receiveDamageData = unit.ReceiveDamageDataDict[DamageForm.Common][0]; } #endregion //play receive damage animation yield return(StartCoroutine("ProcessReceiveDamageData", receiveDamageData)); }
IEnumerator ApplyDamage(DamageParameter damageParam) { Transform trans = damageParam.src.transform; Vector3 attackerLocalPos = transform.InverseTransformPoint(trans.position); bool shouldFall = damageParam.damagePoint >= StrikePowerToHitFall; //Attacker in front if (attackerLocalPos.z >= 0) { if (shouldFall) { string fallAni = Util.RandomFromArray(ReceiveHitDownBackwardDamageAnimation); animation.CrossFade(fallAni); yield return(new WaitForSeconds(animation[fallAni].length)); } else { animation.CrossFade(Util.RandomFromArray(ReceiveFrontDamageAnimations)); } } //Attacker in back else { if (shouldFall) { string fallAni = Util.RandomFromArray(ReceiveHitDownForwardDamageAnimation); animation.CrossFade(fallAni); yield return(new WaitForSeconds(animation[fallAni].length)); } else { animation.CrossFade(Util.RandomFromArray(ReceiveBackDamageAnimations)); } } yield return(null); }
virtual protected IState CreateDamageState(DamageParameter damage) { return(new CharacterDamageState(this, damage)); }
public void TestingDieBehead() { DamageParameter dp = new DamageParameter(null, DamageForm.Predator_Waving_Claw, HP); ApplyDamage(dp); }
void ApplyDamage(DamageParameter damageParam) { show = true; lastChangeDisplayTime = Time.time; }
public Damage(int hitstop, bool addDamage, float damage, int direction, bool ignoreDeffence) { hitStop = new HitStop(hitstop); isAddDamage = addDamage; damageParameter = new DamageParameter(direction, damage, ignoreDeffence); }
public CharacterDamageState(Character parent, DamageParameter dParameter) : base(parent) { damageParameter = dParameter; damageParameter.DamageCalculate(character.parameter); }
public DamageParameter GetDamageParameter(PredatorPlayerAttackData attackData) { DamageParameter dp = new DamageParameter(this.gameObject, attackData.DamageForm, 0); UnityEngine.Random.seed = DateTime.Now.Millisecond; //calculate damage point = base point + random(min, max) dp.damagePoint = attackData.DamagePointBase + UnityEngine.Random.Range(attackData.MinDamageBonus, attackData.MaxDamageBonus); //if critical attack is enabled and random chance matches, multiple the bonus rate. //Usually, designer can put the critical attack chance to the final combat of a combo-combat, this is like the great-final hit. if(attackData.CanDoCriticalAttack && UnityEngine.Random.Range(0f,1f) <= attackData.CriticalAttackChance) { dp.damagePoint *= attackData.CriticalAttackBonusRate; dp.extraParameter.Add(DamageParameter.ExtraParameterKey.IsCriticalStrike, true); dp.extraParameter.Add(DamageParameter.ExtraParameterKey.CritcialStrikeRate, attackData.CriticalAttackBonusRate); } return dp; }
IEnumerator PunctureAndFetch() { //Avoid frequent invoking if (PredatorPlayerStatus.IsAttacking == true || HasFetchSomething) { yield break; } if ((currentFetchedObject = FindFetchable(FetchRadius)) != null) { Util.RotateToward(transform, currentFetchedObject.collider.bounds.center, false, 0); float TargetHP = currentFetchedObject.GetComponent<UnitHealth>().GetCurrentHP(); //Puncture only, or puncture to kill then lift if (TargetHP <= PunctureTossPower) { animation.CrossFade(FetchLiftAnimation); yield return new WaitForSeconds(0.5f); //Send apply damage message DamageParameter dP = new DamageParameter(this.gameObject, DamageForm.Punctured, PunctureTossPower); dP.extraParameter.Add(DamageParameter.ExtraParameterKey.PuncturedAnchor, this.FetchAnchor); currentFetchedObject.SendMessage("ApplyDamage", dP); HasFetchSomething = true; float liftTime = animation[FetchLiftAnimation].length - 0.5f; animation.CrossFade(FetchLiftAnimation); yield return new WaitForSeconds(liftTime); animation.CrossFade(FetchHoldAnimation); } else { animation.CrossFade(PunctureAnimation); yield return new WaitForSeconds(0.5f); DamageParameter dP = new DamageParameter(this.gameObject, DamageForm.Predator_Strike_Single_Claw, PunctureTossPower); currentFetchedObject.SendMessage("ApplyDamage", dP); } } //No object fetched, animating only else { animation.CrossFade(PunctureAnimation); Debug.Log("No object to fetch!"); //yield return new WaitForSeconds(FetchAnimationLength * 1.75f); //animation.Stop(PunctureAnimation); } yield return null; }
public virtual IEnumerator Die(DamageParameter DamageParameter) { //Basic death processing. unit.IsDead = true; //stop and remove AI foreach (AI _ai in GetComponents <AI>()) { _ai.StopAI(); Destroy(_ai); } //stop and remove navigator foreach (Navigator nav in GetComponents <Navigator>()) { nav.StopAllCoroutines(); Destroy(nav); } if (animation != null) { animation.Stop(); } //Handle DeathData: //1. Find the suitable DeathData: DeathData deathData = null; if (unit.DeathDataDict.ContainsKey(DamageParameter.damageForm)) { IList <DeathData> DeathDataList = unit.DeathDataDict[DamageParameter.damageForm]; deathData = Util.RandomFromList(DeathDataList); } else { //if no DeathData matched to the DamageForm in DamageParameter,use the DamageForm.Common deathData = Util.RandomFromList <DeathData>(unit.DeathDataDict[DamageForm.Common]); } if (deathData.DestoryCharacterController && controller != null) { controller.enabled = false; } //Create effect data if (deathData.EffectDataName != null && deathData.EffectDataName.Length > 0) { foreach (string effectDataName in deathData.EffectDataName) { EffectData effectData = unit.EffectDataDict[effectDataName]; GlobalBloodEffectDecalSystem.CreateEffect(effectData); } } //Create blood decal: if (deathData.DecalDataName != null && deathData.DecalDataName.Length > 0) { foreach (string decalName in deathData.DecalDataName) { DecalData DecalData = unit.DecalDataDict[decalName]; GlobalBloodEffectDecalSystem.CreateBloodDecal(transform.position + controller.center, DecalData); } } //Play audio: if (deathData.AudioDataName != null && deathData.AudioDataName.Length > 0) { foreach (string audioDataName in deathData.AudioDataName) { GetComponent <AudioController>()._PlayAudio(audioDataName); } } if (deathData.UseDieReplacement) { if (deathData.ReplaceAfterAnimationFinish) { animation.CrossFade(deathData.AnimationName); yield return(new WaitForSeconds(animation[deathData.AnimationName].length)); } else if (deathData.ReplaceAfterSeconds > 0) { animation.CrossFade(deathData.AnimationName); yield return(new WaitForSeconds(deathData.ReplaceAfterSeconds)); } GameObject DieReplacement = (GameObject)Object.Instantiate(deathData.DieReplacement, transform.position, transform.rotation); if (deathData.CopyChildrenTransformToDieReplacement) { Util.CopyTransform(transform, DieReplacement.transform); } //if deathData.ReplaceOldObjectInSpawnedList is true, means this object has a replacement in SpawnedList. if (deathData.ReplaceOldObjectInSpawnedList) { // the Spawner must not be null, when ReplaceOldObjectInSpawnedList is true if (unit.Spawner != null) { unit.Spawner.ReplaceSpawnedWithNewObject(this.gameObject, DieReplacement); } else { Debug.LogError(string.Format("Unit:{0} hsa no Spawner", unit.gameObject.name)); } } Destroy(gameObject); } else { animation.Play(deathData.AnimationName); if (deathData.DestoryGameObject) { Destroy(gameObject, deathData.DestoryLagTime); } } }
IEnumerator ApplyDamage(DamageParameter damageParam) { HitCounter++; HP -= damageParam.damagePoint; //if (HP > 0) //{ // //Play from beginning every time receives a damage // CurrentSpeed = 0; // string getHitAni = Util.RandomFromArray(this.ReceiveDamageAnimations); // animation.Rewind(getHitAni); // animation.CrossFade(getHitAni); // LastHitTime = Time.time; // LastHitAnimationDuration = animation[getHitAni].length; // yield return new WaitForSeconds(animation[getHitAni].length); // //For the first time get hit, stop sawing and escape from the monster! // if (HitCounter == 1) // { // if (canEscape) // { // StopCoroutine(defaultBeheavior); // animation.Stop(); // CurrentSpeed = RunToOffenseSpeed; // Invoke("Escape", animation[getHitAni].length); // } // else // { // StopCoroutine("Sawing"); // animation.Stop(); // StartCoroutine("Attack"); // } // } //} //else //{ // StopAllCoroutines(); // animation.Stop(); // SendMessage("Die", damageParam.damageForm); // currentTarget = null; //} yield return null; }
/// <summary> /// Receives a damageParam, and performs consequential behavior - play particle, play animation..etc. /// </summary> public virtual IEnumerator DoDamage(DamageParameter damageParam) { #region Look for the suitable ReceiveDamageData //if there is no receive damage defined, quit now! if(this.unit.ReceiveDamageData.Length == 0) { yield break; } foreach(ApplyDamagerCondition applyDamageCondition in ApplyDamagerConditionArray) { applyDamageCondition.UpdateDamageInfo(damageParam); } //Get ReceiveDamageData ReceiveDamageData receiveDamageData = null; if (unit.ReceiveDamageDataDict.ContainsKey(damageParam.damageForm)) { if (unit.ReceiveDamageDataDict[damageParam.damageForm].Count == 1) { receiveDamageData = unit.ReceiveDamageDataDict[damageParam.damageForm][0]; } else //if more than one matched receive damage data is found, randomly choose one. { int RandomIndex = Random.Range(0, unit.ReceiveDamageDataDict[damageParam.damageForm].Count); receiveDamageData = unit.ReceiveDamageDataDict[damageParam.damageForm][RandomIndex]; } } //If ReceiveDamageDataDict[DamageForm.Common] = null or Count ==0, will have error! //So make sure you have assign a Common receive damage data! else { receiveDamageData = unit.ReceiveDamageDataDict[DamageForm.Common][0]; } #endregion //play receive damage animation yield return StartCoroutine("ProcessReceiveDamageData",receiveDamageData); }
/// <summary> /// on receive damage /// </summary> /// <param name="param"></param> void ApplyDamage(DamageParameter param) { if (param.damagePoint > 0 && stealth) SendMessage("CloakOut"); }
public void TestingDieBehead() { DamageParameter dp = new DamageParameter(null, DamageForm.Predator_Waving_Claw, HP); ApplyDamage(dp); }
public virtual IEnumerator Die(DamageParameter DamageParameter) { //Basic death processing. unit.IsDead = true; //stop and remove AI foreach(AI _ai in GetComponents<AI>()) { _ai.StopAI(); Destroy(_ai); } //stop and remove navigator foreach(Navigator nav in GetComponents<Navigator>()) { nav.StopAllCoroutines(); Destroy(nav); } if(animation != null) animation.Stop(); //Handle DeathData: //1. Find the suitable DeathData: DeathData deathData = null; if(unit.DeathDataDict.ContainsKey(DamageParameter.damageForm)) { IList<DeathData> DeathDataList = unit.DeathDataDict[DamageParameter.damageForm]; deathData = Util.RandomFromList(DeathDataList); } else { //if no DeathData matched to the DamageForm in DamageParameter,use the DamageForm.Common deathData = Util.RandomFromList<DeathData>( unit.DeathDataDict[DamageForm.Common]); } if(deathData.DestoryCharacterController && controller != null) { controller.enabled = false; } //Create effect data if (deathData.EffectDataName != null && deathData.EffectDataName.Length > 0) { foreach (string effectDataName in deathData.EffectDataName) { EffectData effectData = unit.EffectDataDict[effectDataName]; GlobalBloodEffectDecalSystem.CreateEffect(effectData); } } //Create blood decal: if (deathData.DecalDataName != null && deathData.DecalDataName.Length > 0) { foreach (string decalName in deathData.DecalDataName) { DecalData DecalData = unit.DecalDataDict[decalName]; GlobalBloodEffectDecalSystem.CreateBloodDecal(transform.position + controller.center, DecalData); } } //Play audio: if(deathData.AudioDataName != null && deathData.AudioDataName.Length > 0) { foreach (string audioDataName in deathData.AudioDataName) { GetComponent<AudioController>()._PlayAudio(audioDataName); } } if(deathData.UseDieReplacement) { if(deathData.ReplaceAfterAnimationFinish) { animation.CrossFade(deathData.AnimationName); yield return new WaitForSeconds(animation[deathData.AnimationName].length); } else if(deathData.ReplaceAfterSeconds > 0) { animation.CrossFade(deathData.AnimationName); yield return new WaitForSeconds(deathData.ReplaceAfterSeconds); } GameObject DieReplacement = (GameObject)Object.Instantiate(deathData.DieReplacement, transform.position, transform.rotation); if(deathData.CopyChildrenTransformToDieReplacement) { Util.CopyTransform(transform, DieReplacement.transform); } //if deathData.ReplaceOldObjectInSpawnedList is true, means this object has a replacement in SpawnedList. if(deathData.ReplaceOldObjectInSpawnedList) { // the Spawner must not be null, when ReplaceOldObjectInSpawnedList is true if(unit.Spawner != null) { unit.Spawner.ReplaceSpawnedWithNewObject(this.gameObject, DieReplacement); } else { Debug.LogError(string.Format("Unit:{0} hsa no Spawner", unit.gameObject.name)); } } Destroy(gameObject); } else { animation.Play(deathData.AnimationName); if(deathData.DestoryGameObject) { Destroy(gameObject, deathData.DestoryLagTime); } } }
void ApplyDamage(DamageParameter damageParam) { show = true; lastChangeDisplayTime = Time.time; }
protected virtual IState CreateDamageState(DamageParameter damage) { return new CharacterDamageState(this, damage); }
public CharacterDamageState(Character parent, DamageParameter dParameter) : base(parent) { damageParameter = dParameter; damageParameter.DamageCalculate(character.parameter); }
/// <summary> /// CALL this method, when the unit apply a damageParameter. /// </summary> public void UpdateDamageInfo(DamageParameter dp) { switch(this.applyDamageConditionType) { case ApplyDamageConditionType.ReceiveDamageAmountGreaterThanValue: this.CurrentDamageAmount += dp.damagePoint; break; case ApplyDamageConditionType.ReceiveDamageAmountInTimePeriod: this.CurrentDamageAmount += dp.damagePoint; this.LastResetTime = Time.time; break; } }
public Damage(int hitstop, bool addDamage, float damage, int direction, bool ignoreDeffence) { hitStop = new HitStop(hitstop); isAddDamage = addDamage; damageParameter = new DamageParameter(direction, damage, ignoreDeffence); }