using System;
|
using Core.Health;
|
using Core.Utilities;
|
using TowerDefense.Agents;
|
using UnityEngine;
|
using Random = UnityEngine.Random;
|
using TowerDefense.Towers;
|
|
namespace ActionGameFramework.Health
|
{
|
/// <summary>
|
/// A component that does damage to damageables
|
/// </summary>
|
public class Damager : MonoBehaviour
|
{
|
/// <summary>
|
/// The amount of damage damager does
|
/// </summary>
|
public float damage;
|
|
/// <summary>
|
/// 强化子弹的多倍攻击
|
/// </summary>
|
public float damageMulti = 1.0f;
|
|
/// <summary>
|
/// 是否是增强的子弹
|
/// </summary>
|
public bool IsEnhancedBullet { get; set; }
|
|
/// <summary>
|
/// 是否击退过小怪
|
/// </summary>
|
public bool IsRepeled { get; set; }
|
|
/// <summary>
|
/// TEST CODE TO TOWER_NAME
|
/// </summary>
|
public string towerName = "";
|
|
public bool bSet = false;
|
|
/// <summary>
|
/// The event that fires off when the damager has been damaged
|
/// </summary>
|
public Action<Vector3> hasDamaged;
|
|
/// <summary>
|
/// 设置局内升级的对应伤害.
|
/// </summary>
|
protected float mInSceneUpGradeDamage = 0;
|
|
/// <summary>
|
/// Random chance to spawn collision projectile prefab
|
/// </summary>
|
[Range(0, 1)]
|
public float chanceToSpawnCollisionPrefab = 1.0f;
|
|
/// <summary>
|
/// The particle system to fire off when the damager attacks
|
/// </summary>
|
public GameObject collisionObj;
|
|
/// <summary>
|
/// The alignment of the damager
|
/// </summary>
|
public SerializableIAlignmentProvider alignment;
|
|
public Tower TowerPtr;
|
|
/// <summary>
|
/// Gets the alignment of the damager
|
/// </summary>
|
public IAlignmentProvider alignmentProvider
|
{
|
get { return alignment != null ? alignment.GetInterface() : null; }
|
}
|
|
protected void Awake()
|
{
|
doubleHit = false;
|
}
|
|
public float inSceneUpGradeDamage
|
{
|
get { return mInSceneUpGradeDamage; }
|
set { mInSceneUpGradeDamage = value; }
|
}
|
|
/// <summary>
|
/// The logic to set the value of the damage
|
/// </summary>
|
/// <param name="damageAmount">
|
/// The amount to set the damage by,
|
/// will not be set for values less than zero
|
/// </param>
|
public void SetDamage(float damageAmount)
|
{
|
if (damageAmount < 0) return;
|
damage = damageAmount;
|
}
|
|
public bool isCrit
|
{
|
get
|
{
|
System.Random mRandom = new System.Random();
|
int val = mRandom.Next(0, 15);
|
if (val <= 1)
|
return true;
|
else
|
return false;
|
}
|
}
|
|
/// <summary>
|
/// 用于精英怪双击.
|
/// </summary>
|
public bool doubleHit { get; set; }
|
|
/// <summary>
|
/// 得到最终的Damage数据,WORK START:
|
/// </summary>
|
public float finalDamage
|
{
|
get
|
{
|
float fd = damage * damageMulti;
|
damageMulti = 1.0f;
|
return fd + inSceneUpGradeDamage;
|
}
|
}
|
|
/// <summary>
|
/// Damagable will tell damager that it has successful hurt the damagable
|
/// </summary>
|
public void HasDamaged(Vector3 point, IAlignmentProvider otherAlignment)
|
{
|
if (hasDamaged != null)
|
{
|
hasDamaged(point);
|
}
|
}
|
|
/// <summary>
|
/// Instantiate particle system and play it
|
/// </summary>
|
void OnCollisionEnter(Collision other)
|
{
|
if (collisionObj == null || Random.value > chanceToSpawnCollisionPrefab)
|
{
|
return;
|
}
|
}
|
|
/// <summary>
|
/// TEST CODE:把Agent的isTrigger勾上了,所以加入了相关的其它处理。
|
/// </summary>
|
/// <param name="other"></param>
|
protected void OnTriggerEnter(Collider other)
|
{
|
var ag = other.gameObject.GetComponent<Agent>();
|
if (ag == null) return;
|
|
if (collisionObj == null || Random.value > chanceToSpawnCollisionPrefab)
|
{
|
return;
|
}
|
|
// 炮弹击中特效
|
GameObject obj = Poolable.TryGetPoolable(collisionObj);
|
ParticleSystem ps = obj.GetComponent<ParticleSystem>();
|
if (ps == null)
|
ps = obj.transform.GetChild(0).GetComponent<ParticleSystem>();
|
ps.transform.position = transform.position;
|
ps.Play();
|
}
|
}
|
}
|