123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256 |
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using FSBuff;
- using FSAssist;
- using UnityEngine.UI;
- namespace FSRole {
-
- public class Role : MonoBehaviour {
-
- public RoleAttr OriginAttr;
-
- public RoleAttr CurrentAttr;
-
- public ArrayList buffs;
-
- private float originWidth;
- private RectTransform bloodRect;
-
- public Transform parryTransform;
- public void SetBloodTrs(Transform blood) {
- bloodRect = blood.Find("Blood").GetComponent<RectTransform>();
- originWidth = bloodRect.rect.width;
- }
-
- void Start() {
- buffs = new ArrayList();
- }
-
- void Update() {
- }
-
-
- public void GetDamage(int value) {
- int damage = DamagePassBuff(value);
- print("角色 : " + CurrentAttr.ID + " 受到了 " + damage + " 点伤害,剩余血量 : " + (CurrentAttr.Hp + damage));
- CurrentAttr.Hp += damage;
-
- if (CurrentAttr.Hp >= 0) {
- float newWidth = (float)CurrentAttr.Hp / OriginAttr.Hp * originWidth;
- print("长度对比 : new = " + newWidth + ", origin = " + originWidth);
- bloodRect.sizeDelta = new Vector2(newWidth, 0.8f);
-
- } else {
- print("角色 : " + CurrentAttr.ID + " 死了 ...");
- }
- }
-
- public void CostEngine(int value) {
- CurrentAttr.Mp -= value;
- }
-
- public void Defense(int value) {
- print("角色 : " + CurrentAttr.ID + "增加了" + value + "点防御,当前防御 : " + (CurrentAttr.Def + value));
- CurrentAttr.Def += value;
- parryTransform.GetComponent<Text>().text = "格挡值 : " + CurrentAttr.Def;
- }
-
- public void BuffExecute() {
-
-
-
-
-
- int index = buffs.Count - 1;
- while (true) {
-
- if (index < 0) {
- return;
- }
- Debug.Log("运行一个Buff : " + index);
- Buff buff = (Buff)buffs[index];
- buff.Execute();
- index--;
- }
- }
-
- public void AddBuff(Buff buff) {
-
-
- foreach (Buff index in buffs) {
- if (index.ID.Equals(buff.ID)) {
-
-
- index.Round = buff.Round;
- index.Overlay++;
-
- SpriteRenderer getRender = index.transform.Find("num").GetComponent<SpriteRenderer>();
- Texture2D getTex = Resources.Load<Texture2D>(string.Format("Textures/Cards/Buff/overlay_{0:d2}", index.Overlay));
- if (getTex != null && getRender != null) {
- Sprite numSprite = Sprite.Create(getTex, new Rect(0, 0, getTex.width, getTex.height), new Vector3(0.5f, 0));
- getRender.sprite = numSprite;
- }
- }
-
- index.transform.position = new Vector3(0.3f * buffs.Count, 1.5f, 1) + transform.position;
- }
- GameObject buffObj = Instantiate(Resources.Load("Prefabs/BuffSub"), transform) as GameObject;
- buff.transform = buffObj.transform;
- buffObj.transform.position = new Vector3(0.3f * buffs.Count, 1.5f, 1) + transform.position;
-
- SpriteRenderer buffRender = buff.transform.Find("buff").GetComponent<SpriteRenderer>();
- SpriteRenderer numRender = buff.transform.Find("num").GetComponent<SpriteRenderer>();
-
- Texture2D buffTex = Resources.Load<Texture2D>("Textures/Cards/Buff/buff_" + buff.ID);
- Texture2D numTex = Resources.Load<Texture2D>(string.Format("Textures/Cards/Buff/overlay_{0:d2}", buff.Overlay));
-
- if (buffTex != null) {
- Sprite buffSprite = Sprite.Create(buffTex, new Rect(0, 0, buffTex.width, buffTex.height), new Vector3(0.5f, 0.5f));
- buffRender.sprite = buffSprite;
- }
- if (numTex != null) {
- Sprite numSprite = Sprite.Create(numTex, new Rect(0, 0, numTex.width, numTex.height), new Vector3(0.5f, 0.5f));
- numRender.sprite = numSprite;
- }
-
- buffs.Add(buff);
- }
-
- public void EraseBuff(Buff buff) {
-
- foreach (Buff index in buffs) {
- if (index.ID.Equals(buff.ID)) {
- print("角色 " + CurrentAttr.ID + " 取消BUFF " + buff.ID);
- buffs.Remove(index);
- Destroy(index.transform.gameObject);
- return;
- }
- }
- }
-
- private int DamagePassBuff(int value) {
-
- if (ContainBuff(AssistConfig.Fracture)) {
- print("存在骨折Buff的影响 ... ");
- Buff buff = GetBuff(AssistConfig.Fracture);
-
- if (buff.Overlay < 3) {
-
- return (int)(value * 1.2f);
- } else if (buff.Overlay >= 3 && buff.Overlay < 6) {
-
- return (int)(value * 1.4f);
- } else if (buff.Overlay >= 6 && buff.Overlay < 9) {
-
- return (int)(value * 1.6f);
- } else {
-
- return (int)(value * (1.6f + (buff.Overlay - 9) * 0.2f));
- }
- }
- return value;
- }
-
- public int CompairePassBuff(int value) {
-
- if (ContainBuff(AssistConfig.Paralysis)) {
- Buff buff = GetBuff(AssistConfig.Paralysis);
- print("存在麻痹Buff的影响 ... " + buff.Overlay);
-
- if (buff.Overlay < 3) {
-
- return value - 1;
- } else if (buff.Overlay >= 3 && buff.Overlay < 6) {
-
- return value - 2;
- } else if (buff.Overlay >= 6 && buff.Overlay < 9) {
-
- return value - 3;
- } else {
-
- return value - 3 - (buff.Overlay - 9);
- }
- }
- return value;
- }
-
- private bool ContainBuff(string ID) {
- foreach (Buff index in buffs) {
-
- if (index.ID == ID) {
- return true;
- }
- }
- return false;
- }
-
- private Buff GetBuff(string ID) {
- foreach (Buff index in buffs) {
-
- if (index.ID == ID) {
- return index;
- }
- }
- return null;
- }
- }
- }
|