123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117 |
- using System;
- using GameWorld;
- using LitJson;
- using UnityEngine;
- public class EnemyAtk : BaseBehaviour
- {
- public JsonData atkData
- {
- private get
- {
- return this._atkData;
- }
- set
- {
- this._atkData = value;
- this.hitTimes = value.Get<int>("hitTimes", 0);
- this.hitInterval = value.Get<float>("hitInterval", 0f);
- this.hitType = value.Get<int>("hitType", 1);
- }
- }
- private void Start()
- {
- this.eAttr = base.transform.parent.GetComponent<EnemyAttribute>();
- }
- private void Update()
- {
- if (this.atkStart)
- {
- this.hitInterval = Mathf.Clamp(this.hitInterval - Time.deltaTime, 0f, float.PositiveInfinity);
- }
- }
- private void OnTriggerEnter2D(Collider2D other)
- {
- if (other.name == "PlayerHurtBox")
- {
- PlayerHurtAtkEventArgs args = new PlayerHurtAtkEventArgs(other.transform.parent.gameObject, base.transform.parent.gameObject, base.transform.parent.gameObject, this.eAttr.atk, this.atkId, this.atkData, false);
- EventManager.PostEvent<Transform, PlayerHurtAtkEventArgs>("PlayerHurtAtk", base.transform, args);
- this.atkStart = true;
- }
- }
- private void OnTriggerStay2D(Collider2D other)
- {
- if (SingletonMono<WorldTime>.Instance.IsFrozen)
- {
- return;
- }
- if (this.atkData == null)
- {
- return;
- }
- if (other.name == "PlayerHurtBox")
- {
- if (this.hitType == 0)
- {
- this.UnlimitedAttack(other);
- }
- else if (this.hitType == 1)
- {
- this.LimitedAttack(other);
- }
- }
- }
- private void OnTriggerExit2D(Collider2D other)
- {
- if (other.name == "PlayerHurtBox")
- {
- this.atkStart = false;
- }
- }
- private void UnlimitedAttack(Collider2D other)
- {
- if (this.hitInterval <= 0f)
- {
- this.atkId = Incrementor.GetNextId();
- this.hitInterval = this.atkData.Get<float>("hitInterval", 0f);
- PlayerHurtAtkEventArgs args = new PlayerHurtAtkEventArgs(other.transform.parent.gameObject, base.transform.parent.gameObject, base.transform.parent.gameObject, this.eAttr.atk, this.atkId, this.atkData, false);
- EventManager.PostEvent<Transform, PlayerHurtAtkEventArgs>("PlayerHurtAtk", base.transform, args);
- }
- }
- private void LimitedAttack(Collider2D other)
- {
- if (this.hitTimes > 0)
- {
- this.hitInterval -= Time.deltaTime;
- if (this.hitInterval <= 0f)
- {
- this.atkId = Incrementor.GetNextId();
- this.hitInterval = this.atkData.Get<float>("hitInterval", 0f);
- PlayerHurtAtkEventArgs args = new PlayerHurtAtkEventArgs(other.transform.parent.gameObject, base.transform.parent.gameObject, base.transform.parent.gameObject, this.eAttr.atk, this.atkId, this.atkData, false);
- EventManager.PostEvent<Transform, PlayerHurtAtkEventArgs>("PlayerHurtAtk", base.transform, args);
- this.hitTimes--;
- }
- }
- }
- private JsonData _atkData;
- private EnemyAttribute eAttr;
- public int atkId;
- private int hitTimes;
- private float hitInterval;
- private int hitType;
- public bool atkStart;
- }
|