UnityCommon/Role/Fun.cs
2025-01-07 17:26:01 +08:00

169 lines
4.5 KiB
C#
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using DG.Tweening;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Reflection;
using UnityEngine;
using Random = System.Random;
public enum DamageType
{
/// <summary>
/// 物理伤害
/// </summary>
physicalDamage,
/// <summary>
/// 魔法伤害
/// </summary>
magicDamage,
/// <summary>
/// 无属性伤害
/// </summary>
noAttributeDamage,
}
public class BUff
{
public float timeLeft = 0;//剩余时间
public float executionInterval = 0;//buff执行间隔
public float executionInterval_max = 100;//buff执行间隔
public Action<object[]> Funaction;//调用的函数
public object[] value;//调用函数的值
public BuffTypeState buffTypeState = 0;
public bool hasfalg(BuffTypeState fag)
{
return (buffTypeState & fag) == fag;
}
}
public enum BuffTypeState
{
}
public class Fun : Base
{
/// <summary>
/// 扣血 传入参数 目标,伤害值,攻击类型,使用者子弹射来的方向0是右边1是左边
/// </summary>
/// <param name="objects"></param>
public void bloodLoss(object[] objects,int direction=1)//目标,伤害值,攻击类型,使用者,子弹射来的方向
{
Role targetAudience = (Role)objects[0];
float harm = (float)objects[1];
DamageType damageType = (DamageType)objects[2];
Role UserObj = (Role)objects[3];
float finalDamage = harm;
switch (damageType)
{
case DamageType.physicalDamage://物理伤害
finalDamage -= targetAudience.physicalArmor;
break;
case DamageType.magicDamage://魔法伤害
finalDamage -= targetAudience.magicArmor;
targetAudience.isMoFa = true;
Debug.Log("魔法伤害");
break;
case DamageType.noAttributeDamage://无属性伤害
finalDamage -= 0;
break;
}
if (finalDamage < 0)
{
finalDamage = 0;
}
if (targetAudience.Hp- finalDamage<0)
{
targetAudience.Hp = 0;
}
else
{
targetAudience.Hp -= finalDamage;
}
if (targetAudience.Hp<=0&&targetAudience.HaveDieTime==1)
{
UserObj.killNum++;
Debug.Log(UserObj.name+"击杀数量"+ UserObj.killNum);
}
targetAudience.HurtDirectin = direction;
}
/// <summary>
/// 创建一个眩晕Buff
/// </summary>
/// <param name="duration">眩晕持续时间</param>
/// <param name="probability">触发概率0到1之间</param>
public Action<Role> CreateDecelerationBuff(float duration, float probability)
{
return (Role targetRole) =>
{
float temp = UnityEngine.Random.Range(0f, 1f);
if (temp <= probability)
{
// 执行眩晕效果
targetRole.Navigation.StopPathDoTween(duration);
Debug.LogWarning(targetRole.name + "执行眩晕效果");
GameObject go = Instantiate(Resources.Load<GameObject>("A_Fight/XuanYun"), targetRole.transform);
go.transform.position = new Vector2(go.transform.position.x, go.transform.position.y + 0.35f);
go.GetComponent<XuanYun>().DesSelf(duration);
Debug.LogWarning($"应用眩晕 {duration} 至 {targetRole.name}.");
}
else
{
Debug.Log($"眩晕buff未触发 on {targetRole.name}.");
}
};
}
/// <summary>
/// 减速buff
/// </summary>
/// <param name="slowFactor">减速百分比</param>
/// <param name="duration">时间</param>
/// <returns></returns>
public Action<Role> CreateSlowDownBuff(float slowFactor, float duration)
{
return (Role targetRole) =>
{
Debug.LogError(this.name+"减速buff");
targetRole.SlowDown(slowFactor, duration);
};
}
/// <summary>
/// 中毒buff
/// </summary>
/// <param name="poisonDuration">持续时间</param>
/// <param name="poisonInterval">间隔</param>
/// <param name="poisonInterval">伤害</param>
/// <returns></returns>
public Action<Role> CreatePoisonBuff(float poisonDuration, float poisonInterval, float poisonDamage,Role AttackRole)
{
return (Role targetRole) =>
{
Debug.Log(this.name + "中毒buff");
targetRole.ApplyPoisonDamage(poisonDuration, poisonInterval,poisonDamage, AttackRole);
};
}
}