| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689 |
- using Spine.Unity;
- using Spine;
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using TMPro;
- using Sirenix.OdinInspector;
- public enum CharacterTag
- {
- Common,
- Tank
- }
- public class MoveCharacter : Character
- {
- [Space(30)]
- [Title("MoveCharacter属性")]
- public CharacterTag charactertag;
- [LabelText("角色抗击打值")] public int hitResistance;
- [LabelText("Buff控制器")] public BuffController bc;
- [FoldoutGroup("组件")] public Foot foot;
- [HideInInspector] public AttributeStatus attributeStatus;
- [HideInInspector] public HitFeedbackSystem hitFeedbackSystem;
- [HideInInspector] public SpineEvent spineEvent;
- [FoldoutGroup("额外重力",order:-1)] [LabelText("上升")] public float extraRiseGravity = -28.8f; //上升时额外重力加速度
- [FoldoutGroup("额外重力")] [LabelText("下落")] public float extraFallGravity = -14.4f; //下落时额外重力加速度
- [FoldoutGroup("额外重力")] [LabelText("近地")] public float extraGroundGravity = -28.8f;
- [FoldoutGroup("平台", order: -1)] [LabelText("移速增量")]public float velocityAddition;
- [FoldoutGroup("平台")] [DisplayOnly] public float platformPosY;
- [FoldoutGroup("平台")] [DisplayOnly] public float platformRotZ;
- [FoldoutGroup("平台")] public float RotLerpSpeed = 0.6f;
- [FoldoutGroup("平台")] [DisplayOnly] public float RotLerpTime;
- [FoldoutGroup("飞行兵落地后回升")] [LabelText("是否需要判定回升")] public bool needToAdjustFlyHeight;
- [FoldoutGroup("飞行兵落地后回升", order: -1)] [DisplayOnly] public float flyHeight;
- [FoldoutGroup("飞行兵落地后回升")] [LabelText("最大高度")] public float maxFlyHeight;
- [FoldoutGroup("飞行兵落地后回升")] [LabelText("最低高度")] public float minFlyHeight;
- float refspeed = 1;
- [FoldoutGroup("飞行兵落地后回升")] [LabelText("速度")] [Range(0, 1)] public float flyUpTime;
- [HideInInspector]
- public int isAdjustHeight;
- [Header("材质")]
- public float matState = 1;
- public GameObject spinee;
- public MeshRenderer mesh;
- public Material[] mats;
- public Material[] outlineMats;
- public Material[] outline1Mats;
- [Header("属性")]
- public float moveSpeed = 5;
- public float moveSpeedScale = 1;
- [Header("减伤")]
- public bool isDamageReduction;
- public float reductionDegree;
- public GameObject reductionEffect;
- //技能类,后面移到其他脚本
- [Header("临时血量")]
- public GameObject effect;
- private int temptHP;
- private int curHP;
- private float continueTime;
- private bool isTempt;
- [Header("魂")]
- public GameObject soulPrefab;
- public float soulStartSpeed = 1f;
- [Header("隐身")]
- public bool isInvisible;
- public float invisibleTime;
- [Header("传送门")]
- public bool haveTransmit;
- [HideInInspector]
- public float transmitTime;
- public PortalsController portalsController;
- [Header("受到持续伤害")]
- public bool isSustainedInjury; //是否正在受到持续伤害
- [HideInInspector] public float sustainedInjuryTime; //存储持续伤害经过的时间
- public float sustainedInjury_IntervalTime; //每次伤害的间隔时间
- public int sustainedInjury_damage; //每次造成的伤害
- [Header("受到重伤")]
- public float heavyDamage;
- [Header("被谁击杀")]
- [DisplayOnly]
- public Character killer;
- [Header("冰冻效果")]
- public bool isFrozen = false;
- private float frozenTimer;
- [Header("感电效果")]
- public bool isElectrify = false;
- private float electrifyTimer;
- public GameObject electrifyEffect;
- [Header("灼烧效果")]
- public bool isOnFire = false;
- public int fireStacks;
- private float fireTimer;
- private float fireBuffTimer;
- private GameObject fireEffect;
- public virtual void Awake()
- {
- spinee = bodyTrans.GetChild(0).gameObject;
- mesh = spinee.GetComponent<MeshRenderer>();
- mats = mesh.materials;
- attributeStatus = GetComponentInChildren<AttributeStatus>();
- hitFeedbackSystem = beHitTrigger.GetComponent<HitFeedbackSystem>();
- }
- private void Start()
- {
- }
- public override void Init()
- {
- base.Init();
- attributeStatus.Init();
- transform.localScale = Vector3.one;
- mecanim.transform.localPosition = Vector3.zero;
- mecanim.transform.localRotation = Quaternion.Euler(Vector3.zero);
- platformRotZ = 0;
- }
- //0:漂浮 1:正常 2:无敌
- public void ChangeMat(int state)
- {
- if((state == 0 && matState == 2) || (state == 2 && matState == 0))
- {
- return;
- }
- if (outline1Mats.Length == 0)
- {
- return;
- }
- if (spinee == null || mesh == null || mats == null)
- {
- spinee = transform.GetChild(0).GetChild(0).gameObject;
- mesh = spinee.GetComponent<MeshRenderer>();
- mats = mesh.materials;
- }
- switch (state)
- {
- case 0:
- mesh.materials = outlineMats;
- break;
- case 1:
- mesh.materials = mats;
- break;
- case 2:
- mesh.materials = outline1Mats;
- break;
- }
- matState = state;
- }
- public void GetTemptHP(int addTemptHP, float time)
- {
- isTempt = true;
- effect.SetActive(true);
- curHP = hp;
- totalHp += addTemptHP;
- hp += addTemptHP;
- temptHP = addTemptHP;
- continueTime = time;
- }
- private void LoseTemptHP()
- {
- isTempt = false;
- effect.SetActive(false);
- totalHp -= temptHP;
- if (hp > curHP)
- {
- hp = curHP;
- }
- }
- public virtual void Update()
- {
- CheckElectrify();
- CheckFrozen();
- CheckFire();
- if (isTempt)
- {
- continueTime -= Time.deltaTime;
- if (continueTime <= 0 || hp <= curHP)
- {
- LoseTemptHP();
- }
- }
- if (beLarger)
- {
- Enlarge();
- }/*
- if (isInvisible)
- {
- invisibleTime -= Time.deltaTime;
- if(invisibleTime <= 0)
- {
- isInvisible = false;
- ChangeMat(1);
- }
- }
- if (haveTransmit)
- {
- transmitTime -= Time.deltaTime;
- if(transmitTime <=0)
- {
- haveTransmit = false;
- portalsController.rbs.Remove(rb);
- }
- }*/
- //受到持续伤害
- if (isSustainedInjury)
- {
- SustainedInjury();
- }
- }
- //伤害减免状态开启(减免程度,减免时长)
- public void DamageReductionStateOn(float degree, GameObject effect)
- {
- if (reductionEffect == null)
- {
- reductionEffect = PoolManager.Instantiate(effect, transform.position, new Quaternion(0, 0, 0, 0), transform);
- }
- reductionEffect.SetActive(true);
- isDamageReduction = true;
- reductionDegree = degree;
- canNotChangeHurt = true;
- }
- public void DamageReductionStateToOff(float onTime)
- {
- Invoke("DamageReductionStateOff", onTime);
- }
- private void DamageReductionStateOff()
- {
- isDamageReduction = false;
- reductionEffect.SetActive(false);
- canNotChangeHurt = false;
- }
- //仅造成伤害
- public override void BeHit(int damage)
- {
- if (invincibleTime > 0)
- {
- //attributeStatus.AddSpecialState(attackInfo, attackFrom);
- return;
- }
- if (Random.Range(0, 100) < attributeStatus.resistances.dodge)
- {
- return;
- }
- int armorRate = attributeStatus.resistances.armor;
- //计算护甲减免
- damage = (int)(damage * (100f / (100 + armorRate)) + 0.5f);
- damage = (int)(damage * (1 + attributeStatus.vulnerableRate) + 0.5f);
- //伤害跳字
- if (showInjuryNum && damage > 0)
- {
- GameObject injuryNum;
- injuryNum = PoolManager.Instantiate(injuryNumTextSummon);
- injuryNum.transform.position = new Vector3(
- transform.position.x + injuryNumPos_summon.x + Random.Range(-injuryNumRandom_summon.x / 2f, injuryNumRandom_summon.x / 2f),
- transform.position.y + injuryNumPos_summon.y + Random.Range(-injuryNumRandom_summon.y / 2f, injuryNumRandom_summon.y / 2f),
- transform.position.z);
- TextMeshProUGUI text = injuryNum.GetComponentInChildren<TextMeshProUGUI>();
- text.text = damage.ToString();
- }
- hp -= damage;
- uiHp.Show(hp, totalHp);
- if (hp <= 0)
- {
- hitFeedbackSystem.curCharacterState = CharacterState.None;
- ChangeState(CharacterState.Die);
- }
- }
- //造成伤害附加其他效果,最好都用这个新版本的
- //damage 有传参的话会忽略attackinfo 中的damage值
- public override void BeHit(AttackController.AttackMethod attackMethod, Character attackFrom, int damage = -1)
- {
- if (invincibleTime > 0)
- {
- //attributeStatus.AddSpecialState(attackInfo, attackFrom);
- return;
- }
- if (Random.Range(0, 100) < attributeStatus.resistances.dodge && CompareTag("Demonic"))
- {
- GameObject missTxt = PoolManager.Instantiate(injuryNumTextSummon);
- missTxt.transform.position = new Vector3(
- transform.position.x + injuryNumPos_summon.x + Random.Range(-injuryNumRandom_summon.x / 2f, injuryNumRandom_summon.x / 2f),
- transform.position.y + injuryNumPos_summon.y + Random.Range(-injuryNumRandom_summon.y / 2f, injuryNumRandom_summon.y / 2f),
- transform.position.z);
- TextMeshProUGUI text = missTxt.GetComponentInChildren<TextMeshProUGUI>();
- text.text = "Miss";
- return;
- }
- AttackInfo attackInfo = attackMethod.attackInfo;
- ScreenReflectPresets.instance.ScreenReflect(hitFeedbackSystem, attackInfo.attackValue - hitResistance);
- int damageData;
- if(damage == -1)
- {
- damageData = attackInfo.damage;
- }
- else
- {
- damageData = damage;
- }
- if (attackFrom.CompareTag("Demonic") || attackFrom.CompareTag("Player"))
- {
- damageData = CalculateFinalDamage(damageData, attackFrom);
- }
- int armorRate = attributeStatus.resistances.armor;
- bool haveStackingWords = false;
- if (attackInfo.attackEffect != null && attackInfo.attackEffect.Count > 0)
- {
- foreach (AttackEffect ae in attackInfo.attackEffect)
- {
- switch (ae)
- {
- /*非控制*/
- //穿甲
- case AttackEffect.ArmorPiercing:
- armorRate = attributeStatus.AddArmorPiercing(attackMethod);
- break;
- //易伤
- case AttackEffect.Vulnerable:
- attributeStatus.AddVulnerable(attackMethod.attackInfo.vulnerable.rate, attackMethod.attackInfo.vulnerable.time);
- break;
- case AttackEffect.StackingWounds:
- haveStackingWords = true;
- attributeStatus.AddStackingWouds(attackMethod);
- break;
- }
- }
- }
- //计算累伤
- if (haveStackingWords)
- {
- damageData = (int)(damageData + attributeStatus.stackingWords + 0.5f);
- }
- //计算护甲减免
- damageData = (int)(damageData * (100f / (100 + armorRate)) + 0.5f);
- //计算易伤
- damageData = (int)(damageData * (1 + attributeStatus.vulnerableRate) + 0.5f);
- //伤害减免,先注释,用到的时候再改
- //if (isDamageReduction)
- //{
- // damage = (int)((1 - reductionDegree) * damage);
- //}
- if (Random.Range(0, 100) < attackInfo.criticalChance)
- {
- damageData = (int)((2 + attackInfo.criticalStrikeEffect/100f) * damageData);
- }
- hp -= damageData;
- if(Random.Range(0,100) < attackInfo.lifesteal)
- {
- attackFrom.hp = Mathf.Clamp(attackFrom.hp + attackFrom.attackController.lifesteal, 0, attackFrom.totalHp);
- }
- //敌方士兵受起手式伤害/我方士兵受伤 闪白
- if (!isFrozen)
- {
- if ((attackFrom.CompareTag("Demonic")||attackFrom.CompareTag("Player")) && attackInfo.attackMethod_Type == AttackMethod_Type.Attack_Summon)
- {
- beHitTrigger.JudgeTurnWhite(true, this);
- }
- else
- {
- beHitTrigger.JudgeTurnWhite(false, this);
- }
- }
- //击中特效(如果有的话)
- if (attackInfo.effect)
- {
- Vector3 effectPos = beHitTrigger.GetComponent<Collider>().bounds.center;
- PoolManager.Instantiate(attackInfo.effect, effectPos);
- }
- //伤害跳字
- if (showInjuryNum && damageData > 0)
- {
- GameObject injuryNum;
- //是起手式
- if ((attackFrom.CompareTag("Demonic") || attackFrom.CompareTag("Player") )&& attackInfo.attackMethod_Type == AttackMethod_Type.Attack_Summon)
- {
- injuryNum = PoolManager.Instantiate(injuryNumTextSummon);
- injuryNum.transform.position = new Vector3(
- transform.position.x + injuryNumPos_summon.x + Random.Range(-injuryNumRandom_summon.x / 2f, injuryNumRandom_summon.x / 2f),
- transform.position.y + injuryNumPos_summon.y + Random.Range(-injuryNumRandom_summon.y / 2f, injuryNumRandom_summon.y / 2f),
- transform.position.z);
- if (isElectrify && GameManager.instance.isWindThunderEnable)
- {
- int randomInt = Random.Range(0, 100);
- if (randomInt < GameManager.instance.windThunderProbability)
- {
- LightningStrike();
- }
- }
- }
- //不是起手式
- else
- {
- injuryNum = PoolManager.Instantiate(injuryNumText);
- injuryNum.transform.position = new Vector3(
- transform.position.x + injuryNumPos_march.x + Random.Range(-injuryNumRandom_march.x / 2f, injuryNumRandom_march.x / 2f),
- transform.position.y + injuryNumPos_march.y + Random.Range(-injuryNumRandom_march.y / 2f, injuryNumRandom_march.y / 2f),
- transform.position.z);
- }
- TextMeshProUGUI text = injuryNum.GetComponentInChildren<TextMeshProUGUI>();
- text.text = damageData.ToString();
- }
- //if ((attackMethod.additionalEffects & AttackAdditionalEffects.Wind) == AttackAdditionalEffects.Wind)
- //{
- // rb.mass -= rb.mass * GameManager.instance.weightReductionratio;
- // BeHit(GameManager.instance.windDamage);
- //}
- uiHp.Show(hp, totalHp);
- if (hp <= 0)
- {
- killer = attackFrom;
- hitFeedbackSystem.curCharacterState = CharacterState.None;
- ChangeState(CharacterState.Die);
- return;
- }
-
- //顿帧
- if(damage == -1)
- {
- hitFeedbackSystem.FreezeFrame(attackMethod, attackFrom);
- }
- if ((attackMethod.additionalEffects & AttackAdditionalEffects.Fire) == AttackAdditionalEffects.Fire)
- {
- AddFireBuff();
- }
- if ((attackMethod.additionalEffects & AttackAdditionalEffects.Ice) == AttackAdditionalEffects.Ice)
- {
- BeFrozen();
- }
- }
- //受到持续伤害
- public void SustainedInjury()
- {
- sustainedInjuryTime += Time.deltaTime;
- if(sustainedInjuryTime >= sustainedInjury_IntervalTime)
- {
- sustainedInjuryTime = 0;
- BeHit(sustainedInjury_damage);
- }
- }
- public override bool AdjustHeight()
- {
- if (canFly)
- {
- if (transform.position.y - flyHeight > 0.1f)
- {
- Vector3 pos = transform.position;
- pos.y = Mathf.Lerp(pos.y, flyHeight, flyUpTime);
- transform.position = pos;
- return false;
- }
- else if (transform.position.y - flyHeight < -0.1f)
- {
- Vector3 pos = transform.position;
- pos.y = Mathf.Lerp(pos.y, flyHeight, flyUpTime);
- transform.position = pos;
- return false;
- }
- else
- {
- Vector3 pos = transform.position;
- pos.y = flyHeight;
- transform.position = pos;
- }
- }
- isAdjustHeight = 2;
- return true;
- }
- #region 冰冻效果
- public void CheckFrozen()
- {
- if (isFrozen)
- {
- if(Time.time - frozenTimer > GameManager.instance.frozenTime + GameManager.instance.myTreasuresTag[2] * GameManager.instance.iceLabelEffectRatio)
- {
- isFrozen = false;
- beHitTrigger.ChangeRenderState(RenderState.Normal);
- if (canFly)
- {
- rb.useGravity = false;
- //rb.velocity = Vector3.zero;
- isAdjustHeight = 1;
- }
- }
- else
- {
- if(state != CharacterState.SpecialStatus_BlowUp && state != CharacterState.SpecialStatus_ShotDown)
- {
- if(state != CharacterState.FramePause && state != CharacterState.HitStun && state != CharacterState.SpecialStatus_Weak)
- {
- attributeStatus.AddWeak(GameManager.instance.frozenTime + GameManager.instance.myTreasuresTag[2] * GameManager.instance.iceLabelEffectRatio + frozenTimer - Time.time);
- }
- if (!foot.TrigGround) rb.velocity -= Vector3.down * extraFallGravity * Time.deltaTime;
- else nowCanFly = false;
- rb.constraints &= ~RigidbodyConstraints.FreezePositionY;
- }
- }
- }
- }
- public void BeFrozen()
- {
- if (!isFrozen)
- {
- beHitTrigger.ChangeRenderState(RenderState.Frozen);
- if (GameManager.instance.isFireIceEnable)
- {
- int randomInt = Random.Range(0, 100);
- if (randomInt < GameManager.instance.fireIceProbability)
- {
- FireExplosion();
- }
- }
- }
- isFrozen = true;
- frozenTimer = Time.time;
- rb.useGravity = true;
- rb.constraints &= ~RigidbodyConstraints.FreezePositionY;
- }
- #endregion
- #region 感电效果
- private void CheckElectrify()
- {
- if (isElectrify)
- {
- if(Time.time - electrifyTimer > GameManager.instance.electrifyTime)
- {
- isElectrify = false;
- ani.speed = 1;
- moveSpeedScale = 1f;
- electrifyEffect.SetActive(false);
- }
- }
- }
- public void BeElectrify()
- {
- if (!isElectrify)
- {
- isElectrify = true;
- ani.speed = GameManager.instance.attackSpeedScale;
- moveSpeedScale = GameManager.instance.moveSpeedScale;
- attributeStatus.AddVulnerable(GameManager.instance.vulnerableRate + GameManager.instance.myTreasuresTag[5] * GameManager.instance.thunderLabelEffectRatio, GameManager.instance.electrifyTime);
- if (electrifyEffect == null)
- {
- electrifyEffect = Instantiate(Resources.Load<GameObject>("Prefab/FX/ElectrifyEffect"), transform.position + Vector3.up, Quaternion.identity, transform);
- electrifyEffect.transform.localPosition = new Vector3(0, 0.8f, 0);
- }
- else electrifyEffect.SetActive(true);
- }
- electrifyTimer = Time.time;
- //BeHit(CalculateFinalDamage(GameManager.instance.thunderDamage + GameManager.instance.thunderAttributeDamage));
- }
- private void LightningStrike()
- {
- CountDownDestory countDownDestory = PoolManager.Instantiate(Resources.Load<GameObject>("Prefab/FX/Effc_Fall_thunder"), transform.position, Quaternion.identity, transform).AddComponent<CountDownDestory>();
- countDownDestory.StartCountDown(1f);
- BeHit(GameManager.instance.thunderboltDamage + (int)((GameManager.instance.myTreasuresTag[1] + GameManager.instance.myTreasuresTag[5]) * GameManager.instance.windThunderLabelEffectRatio));
- attributeStatus.AddWeak(1f);
- }
- #endregion
- #region 灼烧效果
- public void AddFireBuff()
- {
- fireStacks++;
- fireBuffTimer = Time.time;
- if (isFrozen && GameManager.instance.isFireIceEnable)
- {
- int randomInt = Random.Range(0, 100);
- if (randomInt < GameManager.instance.fireIceProbability)
- {
- FireExplosion();
- isFrozen = false;
- beHitTrigger.ChangeRenderState(RenderState.Normal);
- if (canFly)
- {
- rb.useGravity = false;
- isAdjustHeight = 1;
- }
- }
- }
- if(fireStacks > 0 && !isOnFire)
- {
- isOnFire = true;
- if (fireEffect == null)
- {
- fireEffect = Instantiate(Resources.Load<GameObject>("Prefab/FX/FireEffect"), transform.position, Quaternion.identity, transform);
- fireEffect.transform.localPosition = new Vector3(0, 0.8f, 0);
- }
- else fireEffect.SetActive(true);
- }
- fireTimer = Time.time;
- }
- public void CheckFire()
- {
- if (isOnFire)
- {
- if(Time.time - fireTimer > GameManager.instance.fireInterval)
- {
- BeHit(CalculateFinalDamage((GameManager.instance.fireDamage + (int)(GameManager.instance.myTreasuresTag[7] * GameManager.instance.fireLabelEffectRatio)) * fireStacks));
- Debug.Log(GameManager.instance.myTreasuresTag[7] * GameManager.instance.fireLabelEffectRatio);
- fireTimer = Time.time;
- }
- if (Time.time - fireBuffTimer > GameManager.instance.fireBuffTime)
- {
- fireStacks = 0;
- isOnFire = false;
- fireEffect.SetActive(false);
- }
- }
- }
- private void FireExplosion()
- {
- GameObject explosionObj = PoolManager.Instantiate(Resources.Load<GameObject>("Prefab/FX/Explosion"),transform.position);
- Explosion explosion = explosionObj.GetComponent<Explosion>();
- explosion.Init(this,CalculateFinalDamage(GameManager.instance.explosionDamage + (int)((GameManager.instance.myTreasuresTag[6] + GameManager.instance.myTreasuresTag[2]) * GameManager.instance.fireIceLabelEffectRatio)), 4f,1f);
- fireStacks = 0;
- isOnFire = false;
- if(fireEffect != null) fireEffect.SetActive(false);
- Debug.Log("爆炸");
- }
- #endregion
- protected virtual void OnDisable()
- {
- isOnFire = false;
- fireStacks = 0;
- if (fireEffect != null) fireEffect.SetActive(false);
- isFrozen = false;
- isElectrify = false;
- if (electrifyEffect != null) electrifyEffect.SetActive(false);
- ani.speed = 1;
- moveSpeedScale = 1f;
- }
- }
|