void OnMonsterFxAtHit() { if (monsterFx == null) { return; } if (Time.time > timeLastGetMonsterFx + monsterFx.Duration) { myMC.HpDefault = (int)(myMC.HpDefault * 1.0f - maxHp * monsterFx.HpStealth); myMC.MpDefault = (int)(myMC.MpDefault * 1.0f - maxMp * monsterFx.MpStealth); monsterFx = null; ZeroDame = false; return; } else { myAnim.SetBool("gethit", true); if (monsterFx.Blind == 1) { ZeroDame = true; } if (Time.time < timeLastGetMonsterFx + monsterFx.Cooldown) { int Direction = transform.localRotation.y == 0 ? -1 : 1; myRg.velocity = new Vector2(Direction * monsterFx.Knock, myRg.velocity.y); } moveSpeed -= moveSpeed * monsterFx.MoveSlow; } }
public void TakeDamage(int Damage, int m_nDamageType, GameObject source, bool critical, MonsterFxDb FX) { float Dodge = Random.Range(0.0f, 1.0f); if (Dodge < myMC.DodgeDefault) { TextEffectDamage(0, false); return; } gethit = true; monsterFx = FX; bloodEnable(); // mirror force Damage -= myMC.AMDefault; if (Damage < 0) { if (source) { source.GetComponent <EnemyControll>().TakeDamage(-Damage, gameObject, false); } return; } else { myMC.HpDefault -= Damage; TextEffectDamage(Damage, false); } }
/////////////////////////////////////////////////////////////////////////////////////////////// // set 'false' to 'start' parameter of the animator, SO the monster will do action idle, after action appear finished // load and set 'Player' tranform as the target of the monster // check in the monster list to find databases of the monster and monsterFX via ID of the monster and ID of the monsterFX // release monster list and monsterFX list after get data // load all data we need from db to variables (via db construction) // if the monster has timelife, set 'Destroy' method to the monster with a delay equal to monster's timelife, SO it will be die after it's timelife void LoadProperties() { m_animatorController.SetBool("isAppeared", false); m_tfTarget = GameObject.FindGameObjectWithTag("Player").transform; foreach (var _aMonsterFX in m_dbMonsterFXList.Player.MonsterFxList) { if (m_nID == _aMonsterFX.IdMonsterFX) { m_dbMonsterFX = _aMonsterFX; break; } } foreach (var _aMonster in m_dbMonsterList.Player.MonsterDbList) { if (m_nID == _aMonster.IdMonster) { m_dbMonster = new MonsterDb(_aMonster); break; } } m_dbMonsterFXList = null; m_dbMonsterList = null; m_nMonsterType = m_dbMonster.MonterType; m_nScore = m_dbMonster.Score; m_fTimeLife = m_dbMonster.TimeLife; m_fMaxHP = (float)m_dbMonster.HpDefault; m_fMovementSpeed = m_dbMonster.MoveSpeed; m_fDelayAttack = m_dbMonster.delayAtk; m_nDamageType = m_dbMonster.DameType; m_arATKList = m_dbMonster.ATKList; m_fRateDodge = m_dbMonster.RateDodge; m_fRateDrop = m_dbMonster.RateDrop; m_fMCRegen = m_dbMonster.MCRegen; m_oMonsterEsc = m_dbMonster.ESC; m_arDropList = m_dbMonster.Droplist; foreach (ATK _oTempAttack in m_arATKList) { if (_oTempAttack.RankATK == 1) { m_fAttack1Rate = _oTempAttack.Rate; } if (_oTempAttack.RankATK == 2) { m_fAttack2Rate = _oTempAttack.Rate; } if (_oTempAttack.RankATK == 3) { m_fAttack3Rate = _oTempAttack.Rate; } } m_fCurrentHP = m_fMaxHP; m_fLeftLimit = Camera.main.GetComponent <CameraFollow>().StartLook + 2.0f; m_fRightLimit = Camera.main.GetComponent <CameraFollow>().EndLook + Camera.main.orthographicSize * 2.0f - 3.0f; // LOG : check if rate attack of the monster is wrong //if (m_fRateATK1 + m_fRateATK2 + m_fRateATK3 != 1.0f) { // Debug.Log("Attack rates of the monster is wrong!"); //} m_fMoveCycle = Random.Range(1.0f, 4.0f); m_fBreakTimeCycle = Random.Range(1.0f, 2.0f); if (m_fTimeLife > 0.0f) { Invoke("ExplodeBeforeDie", m_fTimeLife); } m_bDataLoaded = true; }