123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497 |
- 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<Buff> buffList = new List<Buff>();
- 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<Renderer> ();
- 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<Renderer>();
- for(int i=0; i<renderers.Length; i++)
- {
- renderers[i].material.mainTexture = textureArr[index];
- }
- }
- }
- }
- public HeadBar GetHeadBar()
- {
- return headBar;
- }
- public virtual Transform GetBaseTransform()
- {
- return transform;
- }
- public override Vector3 position {
- get {
- if(IsDead())
- return deadPos;
- return base.position;
- }
- set {
- if(!IsDead())
- base.position = value;
- }
- }
- public virtual Vector3 heartPos
- {
- get{
- Vector3 pos = position;
- pos.y = 1.5f;
- return pos;
- }
- }
- public virtual bool isMoving
- {
- get{
- return false;
- }
- }
- public virtual bool enableMove
- {
- set{
- _enableMove = value;
- if(!value)
- {
- for(int k=buffList.Count-1; k>=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>();
- }
- 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<Buff> 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<Collider>();
- 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<Collider>();
- if(coll != null)
- coll.enabled = false;
- Renderer[] renderList = GetComponentsInChildren<Renderer>();
- for(int i=0; i<renderList.Length; i++)
- {
- renderList[i].enabled = false;
- }
- if(Killed != null)
- Killed();
- }
- public ThreatManager GetThreadManager()
- {
- return threatManager;
- }
- }
|