EnemyAttribute.cs 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417
  1. using System;
  2. using DatabaseModel;
  3. using UnityEngine;
  4. public class EnemyAttribute : BaseBehaviour
  5. {
  6. public float viewXFront
  7. {
  8. get
  9. {
  10. return this._viewXFront;
  11. }
  12. set
  13. {
  14. this._viewXFront = Mathf.Clamp(value, 0f, float.MaxValue);
  15. }
  16. }
  17. public float viewXBack
  18. {
  19. get
  20. {
  21. return this._viewXBack;
  22. }
  23. set
  24. {
  25. this._viewXBack = Mathf.Clamp(value, 0f, float.MaxValue);
  26. }
  27. }
  28. public float viewYTop
  29. {
  30. get
  31. {
  32. return this._viewYTop;
  33. }
  34. set
  35. {
  36. this._viewYTop = Mathf.Clamp(value, 0f, float.MaxValue);
  37. }
  38. }
  39. public float viewYDown
  40. {
  41. get
  42. {
  43. return this._viewYDown;
  44. }
  45. set
  46. {
  47. this._viewYDown = Mathf.Clamp(value, 0f, float.MaxValue);
  48. }
  49. }
  50. public float currentFlyHeight
  51. {
  52. get
  53. {
  54. return MathfX.PosToHeight(base.transform.position);
  55. }
  56. }
  57. public int currentHp
  58. {
  59. get
  60. {
  61. return this._currentHp;
  62. }
  63. set
  64. {
  65. this._currentHp = Mathf.Clamp(value, 0, this.maxHp);
  66. }
  67. }
  68. public int currentSp
  69. {
  70. get
  71. {
  72. return this._currentSp;
  73. }
  74. set
  75. {
  76. this._currentSp = Mathf.Clamp(value, 0, this.maxSP);
  77. }
  78. }
  79. public bool canCounterAttack
  80. {
  81. get
  82. {
  83. return this.counterAttack > 0;
  84. }
  85. }
  86. public bool hasActionInterrupt
  87. {
  88. get
  89. {
  90. return this.actionInterruptPoint > 0;
  91. }
  92. }
  93. public int monsterDefence
  94. {
  95. get
  96. {
  97. return (int)((float)this.dynamicDefence * this.hardLevel);
  98. }
  99. }
  100. public int monsterSideStep
  101. {
  102. get
  103. {
  104. return (int)((float)this.dynamicSideStep * this.hardLevel);
  105. }
  106. }
  107. public bool isDead
  108. {
  109. get
  110. {
  111. return this.currentHp <= 0;
  112. }
  113. }
  114. [HideInInspector]
  115. public bool isArmorBroken
  116. {
  117. get
  118. {
  119. return this.currentSp <= 0;
  120. }
  121. }
  122. public bool isOnGround
  123. {
  124. get
  125. {
  126. RaycastHit2D hit = Physics2D.Raycast(base.transform.position, -Vector2.up, this.altitude, LayerManager.ObstacleMask | LayerManager.GroundMask | LayerManager.OneWayGroundMask);
  127. RaycastHit2D hit2 = Physics2D.Raycast(base.transform.position + Vector3.right * this.bounds.size.x / 2f, -Vector2.up, this.altitude, LayerManager.ObstacleMask | LayerManager.GroundMask | LayerManager.OneWayGroundMask);
  128. RaycastHit2D hit3 = Physics2D.Raycast(base.transform.position - Vector3.right * this.bounds.size.x / 2f, -Vector2.up, this.altitude, LayerManager.ObstacleMask | LayerManager.GroundMask | LayerManager.OneWayGroundMask);
  129. return hit || hit2 || hit3;
  130. }
  131. }
  132. public float height
  133. {
  134. get
  135. {
  136. return Physics2D.Raycast(base.transform.position, Vector2.up * -1f, 100f, LayerManager.ObstacleMask | LayerManager.GroundMask | LayerManager.OneWayGroundMask).distance;
  137. }
  138. }
  139. public bool CurrentCanBeExecute
  140. {
  141. get
  142. {
  143. if (this._action == null)
  144. {
  145. this._action = base.GetComponent<EnemyBaseAction>();
  146. }
  147. return this._action.CurrentCanBeExecute();
  148. }
  149. }
  150. protected virtual void Awake()
  151. {
  152. this.timeController = base.GetComponent<TimeController>();
  153. this.currentSp = this.maxSP;
  154. this.currentHp = this.maxHp;
  155. }
  156. protected virtual void Start()
  157. {
  158. if (this.enemyGravity != null)
  159. {
  160. GameObject gameObject = UnityEngine.Object.Instantiate<GameObject>(this.enemyGravity);
  161. gameObject.transform.parent = base.transform;
  162. }
  163. this.dynamicDefence = (int)((float)this.baseDefence * UnityEngine.Random.Range(0.7f, 1.3f));
  164. this.dynamicSideStep = (int)((float)this.baseSideStep * UnityEngine.Random.Range(0.7f, 1.3f));
  165. this.bounds = base.GetComponent<Collider2D>().bounds;
  166. if (this.rankType == EnemyAttribute.RankType.BOSS)
  167. {
  168. this.SetAsBoss();
  169. }
  170. }
  171. protected virtual void Update()
  172. {
  173. }
  174. protected void OnEnable()
  175. {
  176. if (this.InTheWorld)
  177. {
  178. R.Enemy.AddEnemy(this);
  179. }
  180. }
  181. protected void OnDisable()
  182. {
  183. if (this.InTheWorld)
  184. {
  185. R.Enemy.RemoveEnemy(this);
  186. }
  187. }
  188. public void SetBasicData(EnemyAttrData baseData)
  189. {
  190. float num = 1f;
  191. switch (R.GameData.Difficulty)
  192. {
  193. case 0:
  194. num = 0.7f;
  195. break;
  196. case 1:
  197. num = 1f;
  198. break;
  199. case 2:
  200. case 3:
  201. num = 1.5f;
  202. break;
  203. }
  204. float num2 = (R.GameData.Difficulty != 0) ? 1.2f : 1f;
  205. float num3 = (R.GameData.Difficulty != 1) ? 1.5f : 1f;
  206. this.baseData = baseData;
  207. this.maxHp = (int)((float)baseData.maxHp * num2);
  208. this.atk = (int)((float)baseData.atk * num);
  209. this.counterAttack = (int)((float)baseData.counterAttack * num3);
  210. this.level = baseData.level;
  211. this.maxSP = baseData.maxSP;
  212. this.atkSpeed = baseData.atkSpeed;
  213. this.scanSpeed = baseData.scanSpeed;
  214. this.moveSpeed = baseData.moveSpeed;
  215. this.flyHeight = MathfX.HeightToPos((float)baseData.flyHeight);
  216. this.counterAttackProbPercentage = baseData.counterAttackProbPercentage;
  217. this.actionInterruptPoint = baseData.actionInterruptPoint;
  218. this.currentHp = this.maxHp;
  219. this.currentSp = baseData.maxSP;
  220. this.currentActionInterruptPoint = 0;
  221. this.currentCounterAttackValue = 0;
  222. this.currentCounterAttackProbPercentage = (float)baseData.counterAttackProbPercentage;
  223. this.dropCoins = baseData.dropCoins;
  224. this.dropExp = baseData.dropExp;
  225. }
  226. public void SetAsBoss()
  227. {
  228. R.Enemy.Boss = base.gameObject;
  229. R.Ui.bossHpBar.Create(base.GetComponent<EnemyAttribute>(), base.GetComponent<EnemyBaseHurt>().phaseHp);
  230. }
  231. public EnemyAttribute.RankType rankType;
  232. public Bounds bounds;
  233. [SerializeField]
  234. private float _viewXFront;
  235. [SerializeField]
  236. private float _viewXBack;
  237. [SerializeField]
  238. private float _viewYTop;
  239. [SerializeField]
  240. private float _viewYDown;
  241. public bool playerInView;
  242. [Header("敌人关卡基本属性值,编辑器修改无效")]
  243. public EnemyAttrData baseData;
  244. public string id;
  245. [Header("等级值")]
  246. public int level = 1;
  247. [Header("最大护盾值")]
  248. public int maxSP;
  249. [Header("最大血量")]
  250. public int maxHp = 1000;
  251. [Header("攻击力")]
  252. public int atk;
  253. [Header("攻击动画速率")]
  254. public float atkSpeed = 1f;
  255. [Header("扫描速度 ")]
  256. public float scanSpeed = 2f;
  257. [Header("移动速度")]
  258. public float moveSpeed = 4f;
  259. [Header("掉落金币数量")]
  260. public int dropCoins;
  261. [Header("经验值")]
  262. public int dropExp;
  263. [Header("飞行高度,指的是Y值")]
  264. public float flyHeight;
  265. [Header("表示怪物能不能飞")]
  266. public bool iCanFly;
  267. [SerializeField]
  268. private int _currentHp;
  269. [SerializeField]
  270. private int _currentSp;
  271. [Header("反击值")]
  272. public int counterAttack;
  273. [Header("当前反击值")]
  274. public int currentCounterAttackValue;
  275. [Header("当前反击几率")]
  276. public float currentCounterAttackProbPercentage;
  277. [Header("反击触发概率值")]
  278. [Range(0f, 100f)]
  279. public int counterAttackProbPercentage;
  280. [Header("硬直值")]
  281. public int actionInterruptPoint;
  282. [Header("当前的硬直值")]
  283. public int currentActionInterruptPoint;
  284. [Header("基础防御值")]
  285. public int baseDefence;
  286. [Header("基础闪避值")]
  287. public int baseSideStep;
  288. [HideInInspector]
  289. public int dynamicDefence;
  290. [HideInInspector]
  291. public int dynamicSideStep;
  292. [Header("难度系数")]
  293. public float hardLevel;
  294. [Header("防御累计伤害")]
  295. public int currentDefence;
  296. [Header("开始防御")]
  297. public bool startDefence;
  298. [Header("闪避累计伤害")]
  299. public int currentSideStep;
  300. [Header("空中闪避")]
  301. public bool sideStepInAir;
  302. [Header("是否在霸体")]
  303. public bool paBody;
  304. [Header("是否在虚弱状态中")]
  305. public bool inWeakState;
  306. [Header("是否加入世界数据")]
  307. public bool InTheWorld = true;
  308. public int faceDir = -1;
  309. public float stiffTime;
  310. public const int LEFT = -1;
  311. public const int RIGHT = 1;
  312. public bool accpectExecute;
  313. public bool accpectAirExecute;
  314. public bool enterWeakMod;
  315. public bool willBeExecute;
  316. public bool canBeChased;
  317. [HideInInspector]
  318. public bool isFlyingUp;
  319. public bool followLeftHand;
  320. [HideInInspector]
  321. public bool checkHitGround;
  322. [HideInInspector]
  323. public bool flyToFall;
  324. public float altitude = 0.2f;
  325. [NonSerialized]
  326. private EnemyBaseAction _action;
  327. [HideInInspector]
  328. public TimeController timeController;
  329. public GameObject enemyGravity;
  330. public enum RankType
  331. {
  332. Normal,
  333. Elite,
  334. BOSS
  335. }
  336. }