using UnityEngine; using System.Collections; using System.Collections.Generic; public class BattleObject : MapObject, IBattleObject , ITarget { public Animation animation; public Texture[] textureArr; public Material material; protected int _userId; protected AI.AIType _aiType; protected float m_OriginMoveSpeed = 3f; public virtual float originMoveSpeed { get{ return m_OriginMoveSpeed; } set{ m_OriginMoveSpeed = value; } } protected float m_ModifyMoveSpeed = 0f; public virtual float modifyMoveSpeed { get{ return m_ModifyMoveSpeed; } set{ m_ModifyMoveSpeed = value; } } protected bool _enableMove = true; protected bool _enablePower = true; protected bool _holdAction = false; public float headBarHeight = 1.5f; protected HeadBar headBar; public bool enabledHeadBar = true; protected float _hp; protected float _maxHp; protected float _originMaxHp; public int lastShooterId = int.MinValue; public int lastShooterCraftId = int.MinValue; protected float lastDamageTime; protected float hpRecoverInterval = 8f; protected float hpRecoverSpeed = 0.025f; public float viewRange = 8f; public bool overwhelming; protected bool _isDead; protected float deadTime; protected Vector3 deadPos; protected List buffList = new List(); protected ThreatManager threatManager; public event EventUtil.SimpleEventDelegate HpChanged; public event EventUtil.SimpleEventDelegate Killed; private ITarget _target; public ITarget target{ get{ return _target; } set{ _target = value; } } public override void Init (Map map) { base.Init (map); threatManager = new ThreatManager(); if(enabledHeadBar) { InitHeadBar(); } Renderer renderer = GetComponentInChildren (); if (renderer != null) material = renderer.material; else material = null; } public virtual void EnterFrame(){} public int userId { get{ return _userId; } set{ _userId = value; } } public AI.AIType aiType { get{ return _aiType; } set{ _aiType = value; } } public override TeamUtil.Team team { get { return base.team; } set { base.team = value; if(textureArr.Length > 0) { int index = value.GetHashCode() - 1; Renderer[] renderers = this.GetComponentsInChildren(); for(int i=0; i=0; k--) { if(k >= buffList.Count) continue; buffList[k].OnDismove(); } } } get{ return _enableMove; } } public bool enablePower { set{ _enablePower = value; } get{ return _enablePower; } } public virtual bool holdAction { set{ _holdAction = value; } get{ return _holdAction; } } //hp & mp public void InitHeadBar() { if(headBar == null) { GameObject headBarPrefab = Resources.Load(Config.HEAD_BAR_PREFAB) as GameObject; GameObject headBarObj = Instantiate(headBarPrefab) as GameObject; PopUpManager.AddToMainCanvas (headBarObj); headBar = headBarObj.GetComponent(); } headBar.Init(this); } public float hp { set{ if(_hp != value) { _hp = NumberUtil.forceBetween(value, 0, maxHp); if(HpChanged != null) HpChanged(); if(headBar != null) { headBar.UpdateHpBar(); } } } get{ return _hp; } } public float maxHp { set{ _maxHp = value; } get{ return _maxHp; } } public float originMaxHp { get{ return _originMaxHp; } } public virtual void MakeDamage(Bullet bullet) { lastShooterId = bullet.GetOwner ().userId; lastShooterCraftId = (bullet.GetOwner() is Craft ? (bullet.GetOwner() as Craft).GetCraftId() : 0); lastDamageTime = GameTime.time; if(!overwhelming) hp -= bullet.damage; if(bullet.GetOwner().team != team) threatManager.AddThreat(bullet.GetOwner().id, bullet.damage); DamageStat (lastShooterId, bullet.damage); OnDamage(); } public virtual void MakeDamage(float damage, BattleObject launcher) { lastShooterId = launcher.userId; lastDamageTime = GameTime.time; if(!overwhelming) hp -= damage; if(launcher.team != team) threatManager.AddThreat(launcher.id, damage); DamageStat (lastShooterId, damage); OnDamage(); } public void MakeDamage(float damage) { lastDamageTime = GameTime.time; if(!overwhelming) hp -= damage; } private void DamageStat(int userId, float damage) { Player player = Session.GetInstance ().GetBattleSession ().GetPlayer (userId); if (player != null) player.damage += damage; } public virtual void MakeHeal(Bullet bullet) { hp += bullet.damage; HealStat (bullet.GetOwner().userId, bullet.damage); } private void HealStat(int userId, float heal) { Player player = Session.GetInstance ().GetBattleSession ().GetPlayer (userId); if (player != null) player.heal += heal; } protected void CheckHpRecover() { if(hp < maxHp && IsLeaveDamage()) { float hpRecover = maxHp*hpRecoverSpeed*GameTime.deltaTime; hp += hpRecover; } } public bool IsLeaveDamage() { return GameTime.time - lastDamageTime > hpRecoverInterval; } public void AddBuff(Buff buff) { if(buff == null) return; buffList.Add(buff); } public void RemoveBuff(Buff buff) { buffList.Remove(buff); } public List GetBuffList() { return buffList; } public void DealBuff() { for(int i=buffList.Count-1; i>=0; i--) { buffList[i].Update(); } } public void OnMove() { for(int i=buffList.Count-1; i>=0; i--) { buffList[i].OnMove(); } } public void OnDamage() { for(int i=buffList.Count-1; i>=0; i--) { buffList[i].OnDamage(); } } public void OnUserPower() { for(int i=buffList.Count-1; i>=0; i--) { buffList[i].OnUserPower(); } } protected bool invisible; public virtual void SetInvisible(bool invisible, bool isAlly) { if(invisible == this.invisible) { return; } this.invisible = invisible; Collider collider = GetComponent(); if(invisible) { float alpha = isAlly ? 0.5f : 0; Invisibler.Start(this, alpha, false); if(collider != null) collider.enabled = isAlly ? true : false; headBar.gameObject.SetActive(isAlly); } else { float alpha = 1f; Invisibler.Start(this, alpha, true); if(collider != null) collider.enabled = true; headBar.gameObject.SetActive(true); } } public bool IsInvisible() { return invisible; } public bool CanShoot() { return !IsDead() && !IsInvisible(); } public bool IsDead() { return _isDead; } public virtual void Dead() { if(_isDead) return; deadPos = position; _isDead = true; deadTime = GameTime.time; if(SoundUtils.IsSoundNear(position)) { SoundManager.GetInstatnce().effectSound.Play(SoundManager.GetInstatnce().effectSound.explode); } BattleController.Shake(position); GameObject explosionObj = EffectUtil.CreateEffect("Explosion"); Vector3 pos = position; pos.y = 1f; explosionObj.transform.position = pos; if(map != null) map.RemoveBattleObject(this); Collider coll = GetComponent(); if(coll != null) coll.enabled = false; Renderer[] renderList = GetComponentsInChildren(); for(int i=0; i