攻击属性计算
This commit is contained in:
parent
bf88fb96a3
commit
44483bcb6a
307
Role/Role.cs
307
Role/Role.cs
@ -1,22 +1,23 @@
|
||||
using System;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.Threading.Tasks;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
using DG.Tweening;
|
||||
using TMPro;
|
||||
|
||||
public enum Camp
|
||||
{/// <summary>
|
||||
/// 玩家
|
||||
/// 玩家
|
||||
/// </summary>
|
||||
Player,
|
||||
/// <summary>
|
||||
/// 怪物
|
||||
/// 怪物
|
||||
/// </summary>
|
||||
Enemy,
|
||||
/// <summary>
|
||||
/// 中立
|
||||
/// 中立
|
||||
/// </summary>
|
||||
Neutral
|
||||
}
|
||||
@ -29,6 +30,7 @@ public enum CharacterFlags
|
||||
land = 1 << 1,
|
||||
big = 1 << 2,
|
||||
min = 1 << 3,
|
||||
|
||||
FlyBig=fly|big,
|
||||
FlyMin=fly|min,
|
||||
LandBig = land | big,
|
||||
@ -36,38 +38,38 @@ public enum CharacterFlags
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 角色基类,玩家处理事件
|
||||
/// 角色基类,玩家处理事件
|
||||
/// </summary>
|
||||
[ExecuteInEditMode]
|
||||
public class Role : Fun
|
||||
{
|
||||
[Header("Id")] public string id;
|
||||
[Header("名称")] public string Name;
|
||||
[Header("阵营")] public Camp camp ;
|
||||
[Header("血量")] public float hp = 100f;//血量
|
||||
[Header("名称")] public string Name;
|
||||
[Header("阵营")] public Camp camp ;
|
||||
[Header("血量")] public float hp = 100f;//血量
|
||||
private float maxHp;
|
||||
[Header(("死亡动画编号"))] public int dieIndex=-1;
|
||||
[Header(("死亡动画编号"))] public int dieIndex=-1;
|
||||
|
||||
[Header("hp填充直接扣")] public Image Hpfiil;
|
||||
[Header("hp填充慢慢扣")] public Image HpfiilYello;
|
||||
[Header("扣血填充")] public GameObject HpTextPrefab;
|
||||
[Header("hp填充直接扣")] public Image Hpfiil;
|
||||
[Header("hp填充慢慢扣")] public Image HpfiilYello;
|
||||
[Header("扣血填充")] public GameObject HpTextPrefab;
|
||||
|
||||
[Header("自己的画布")]public Canvas _Canvas;
|
||||
[Header("自己的图片")] public SpriteRenderer spriteRenderers; // 存储所有的SpriteRenderer组件
|
||||
[Header("被打的方向")] public int HurtDirectin;
|
||||
public string Quality;//品质
|
||||
public string Elements;//属性
|
||||
public string Info;//详情
|
||||
public string SkillId;//技能
|
||||
public string AttackType;//攻击类型
|
||||
public string AttackActionType;//攻击作用类型
|
||||
[Header("自己的画布")]public Canvas _Canvas;
|
||||
[Header("自己的图片")] public SpriteRenderer spriteRenderers; // 存储所有的SpriteRenderer组件
|
||||
[Header("被打的方向")] public int HurtDirectin;
|
||||
public string Quality;//品质
|
||||
public string Elements;//属性
|
||||
public string Info;//详情
|
||||
public string SkillId;//技能
|
||||
public string AttackType;//攻击类型
|
||||
public string AttackActionType;//攻击作用类型
|
||||
|
||||
public float AttackRange;//攻击范围
|
||||
public float AttackRange;//攻击范围
|
||||
|
||||
public float AttackCD;//攻击CD
|
||||
public float CritRate;//暴击率
|
||||
public float CriticalHitRateBonus;//暴击加成
|
||||
[Header("击杀数量")] public int killNum;
|
||||
public float AttackCD;//攻击CD
|
||||
public float CritRate;//暴击率
|
||||
public float CriticalHitRateBonus;//暴击加成
|
||||
[Header("击杀数量")] public int killNum;
|
||||
|
||||
public float Hp
|
||||
{
|
||||
@ -81,35 +83,44 @@ public class Role : Fun
|
||||
hp = value;
|
||||
|
||||
|
||||
// 更新血条显示
|
||||
// 更新血条显示
|
||||
if (Hpfiil != null)
|
||||
{
|
||||
Hpfiil.fillAmount = hp / maxHp;
|
||||
|
||||
// 使用 DOTween 动画平滑过渡血条填充
|
||||
DOTween.To(() => HpfiilYello.fillAmount, x => HpfiilYello.fillAmount = x, hp / maxHp, 0.8f) // 0.5f 为过渡时间
|
||||
.SetEase(Ease.InOutQuad); // 使用缓动效果,使血条变化更加平滑
|
||||
// 使用 DOTween 动画平滑过渡血条填充
|
||||
DOTween.To(() => HpfiilYello.fillAmount, x => HpfiilYello.fillAmount = x, hp / maxHp, 0.8f) // 0.5f 为过渡时间
|
||||
.SetEase(Ease.InOutQuad); // 使用缓动效果,使血条变化更加平滑
|
||||
}
|
||||
|
||||
// 更新血量文本效果
|
||||
// 更新血量文本效果
|
||||
if (HpTextPrefab != null && hp < maxHp)
|
||||
{
|
||||
hit();
|
||||
Navigation.StopPathDoTween(0.2f); // 停止任何进行中的 DoTween 动画,0.2s为示例值
|
||||
Navigation.StopPathDoTween(0.2f); // 停止任何进行中的 DoTween 动画,0.2s为示例值
|
||||
GameObject go = GameObject.Instantiate(HpTextPrefab, _Canvas.transform);
|
||||
go.GetComponent<SnowHpControl>().direction = HurtDirectin;
|
||||
go.GetComponent<SnowHpControl>().CreateText();
|
||||
go.GetComponent<Text>().text = (temp - hp).ToString("F0"); // 显示伤害值
|
||||
if (isGoodDamege)
|
||||
{
|
||||
go.GetComponent<SnowHpControl>().CreateText(true);
|
||||
isGoodDamege = false;
|
||||
}
|
||||
// 判断角色是否死亡
|
||||
else
|
||||
{
|
||||
go.GetComponent<SnowHpControl>().CreateText();
|
||||
}
|
||||
|
||||
go.GetComponent<Text>().text = (temp - hp).ToString("F0"); // 显示伤害值
|
||||
}
|
||||
// 判断角色是否死亡
|
||||
if (hp <= 0)
|
||||
{
|
||||
die(); // 执行死亡处理
|
||||
die(); // 执行死亡处理
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
[Header("掉落")] public int gold = 6;
|
||||
[Header("掉落")] public int gold = 6;
|
||||
public int Gold
|
||||
{
|
||||
[DebuggerStepThrough]
|
||||
@ -117,47 +128,48 @@ public class Role : Fun
|
||||
[DebuggerStepThrough]
|
||||
set => gold = value;
|
||||
}
|
||||
[Header("攻击力")] private float attack = 10f;
|
||||
[Header("攻击力上限")] public float MaxAttack = 10f;
|
||||
[Header("攻击力下限")] public float MinAttack = 10f;
|
||||
[Header("攻击力")] private float attack = 10f;
|
||||
[Header("攻击力上限")] public float MaxAttack = 10f;
|
||||
[Header("攻击力下限")] public float MinAttack = 10f;
|
||||
public bool isGoodDamege=false;//是否暴击
|
||||
public float Attack
|
||||
{
|
||||
get => attack;
|
||||
set => attack = value;
|
||||
}
|
||||
[Header("等级")] private int level = 1;
|
||||
[Header("等级")] private int level = 1;
|
||||
public int Level
|
||||
{
|
||||
[DebuggerStepThrough] get => level;
|
||||
[DebuggerStepThrough] set => level = value;
|
||||
}
|
||||
[Header("物理护甲")] public int physicalArmor = 10;//物理护甲
|
||||
[Header("魔法护甲")] public int magicArmor = 5;//魔法护甲
|
||||
[Header("物理护甲")] public int physicalArmor = 10;//物理护甲
|
||||
[Header("魔法护甲")] public int magicArmor = 5;//魔法护甲
|
||||
|
||||
|
||||
[Header("导航组件")] public SimplePathfindingDoTween Navigation;
|
||||
[Header("导航组件")] public SimplePathfindingDoTween Navigation;
|
||||
[System.Serializable ]
|
||||
public class AnimationList//动画list
|
||||
public class AnimationList//动画list
|
||||
{
|
||||
//[Header("动画是否循环")] public bool isloop = false;
|
||||
[Header("动画图片")] public List<Sprite> value; // 字典的值
|
||||
[Header("角色动画帧数间隔(毫秒)")] public int CharacterAnimationFrameInterval = 50;
|
||||
//[Header("动画是否循环")] public bool isloop = false;
|
||||
[Header("动画图片")] public List<Sprite> value; // 字典的值
|
||||
[Header("角色动画帧数间隔(毫秒)")] public int CharacterAnimationFrameInterval = 50;
|
||||
}
|
||||
[Header("角色动画")] public List<AnimationList> AnimationTree = new List<AnimationList>();
|
||||
[Header("角色动画播放")] public int animationHighlight = 0;
|
||||
[Header("角色精灵位置")] public SpriteRenderer spriteRenderer;
|
||||
[Header("角色Image位置")] public Image image;
|
||||
[Header("角色动画")] public List<AnimationList> AnimationTree = new List<AnimationList>();
|
||||
[Header("角色动画播放")] public int animationHighlight = 0;
|
||||
[Header("角色精灵位置")] public SpriteRenderer spriteRenderer;
|
||||
[Header("角色Image位置")] public Image image;
|
||||
public delegate void AnimationItem(int AnimationItem);
|
||||
public event AnimationItem OnAnimationStart;
|
||||
public event AnimationItem OnAnimationIng;
|
||||
public event AnimationItem OnAnimationEnd;
|
||||
[Header("动画是否正常播放")] public bool isAnimationPlay = false;//动画是否正常播放
|
||||
[Header("碰撞体")]public Collider2D mycollider;
|
||||
[Header("攻击脚本")] public Attack attackClass;
|
||||
[Header("当前播放图片序列")] public int CurrentIndex;
|
||||
[Header("动画是否正常播放")] public bool isAnimationPlay = false;//动画是否正常播放
|
||||
[Header("碰撞体")]public Collider2D mycollider;
|
||||
[Header("攻击脚本")] public Attack attackClass;
|
||||
[Header("当前播放图片序列")] public int CurrentIndex;
|
||||
|
||||
public int hitIndex = 2;//受击动画索引
|
||||
public int normalIndex = 0;//移动动画索引
|
||||
public int hitIndex = 2;//受击动画索引
|
||||
public int normalIndex = 0;//移动动画索引
|
||||
public bool isHit=false;//
|
||||
|
||||
public List<BUff> buffList = new List<BUff>();
|
||||
@ -171,12 +183,12 @@ public class Role : Fun
|
||||
public SkillUp mySkillUp;
|
||||
|
||||
/// <summary>
|
||||
/// 储存buff
|
||||
/// 储存buff
|
||||
/// </summary>
|
||||
public List<Action<Role>> storageBuff = new List<Action<Role>>();
|
||||
|
||||
/// <summary>
|
||||
/// 使用buff
|
||||
/// 使用buff
|
||||
/// </summary>
|
||||
public List<Action<Role>> PlayerBuff=new List<Action<Role>>();
|
||||
|
||||
@ -189,7 +201,7 @@ public class Role : Fun
|
||||
|
||||
maxHp = hp;
|
||||
SetSelfInfo();
|
||||
//SetAttackRange();//设置攻击范围
|
||||
//SetAttackRange();//设置攻击范围
|
||||
if (Application.isPlaying)
|
||||
{
|
||||
if (attackClass)
|
||||
@ -205,32 +217,32 @@ public class Role : Fun
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 添加Buff
|
||||
/// 添加Buff
|
||||
/// </summary>
|
||||
/// <param name="buffAction"></param>
|
||||
public void AddBuff(List<Action<Role>> buffs, Action<Role> buffAction)
|
||||
{
|
||||
buffs.Add(buffAction);
|
||||
UnityEngine.Debug.LogError(this.name + "添加buff到"+ buffs);
|
||||
UnityEngine.Debug.LogError(this.name + "添加buff到"+ buffs);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 执行所有当前 Buff
|
||||
/// 执行所有当前 Buff
|
||||
/// </summary>
|
||||
public void ApplyBuffs()
|
||||
{
|
||||
foreach (var buff in PlayerBuff)
|
||||
{
|
||||
UnityEngine.Debug.LogError(this.name + "进入执行buff判断");
|
||||
buff.Invoke(this); // 将自己作为目标传递
|
||||
UnityEngine.Debug.LogError(this.name + "进入执行buff判断");
|
||||
buff.Invoke(this); // 将自己作为目标传递
|
||||
}
|
||||
|
||||
// 清空 Buff 列表,假设 Buff 是一次性的
|
||||
// 清空 Buff 列表,假设 Buff 是一次性的
|
||||
PlayerBuff.Clear();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 角色动画更新
|
||||
/// 角色动画更新
|
||||
/// </summary>
|
||||
public async void updateAnimation()
|
||||
{
|
||||
@ -289,7 +301,7 @@ public class Role : Fun
|
||||
{
|
||||
SpawnPool.intance.DeadNumber += 1;
|
||||
Destroy(gameObject);
|
||||
// SpawnPool.intance.ReturnEnemyToPool(this.gameObject); // 回收当前敌人到池中
|
||||
// SpawnPool.intance.ReturnEnemyToPool(this.gameObject); // 回收当前敌人到池中
|
||||
// ResetAllStatus();
|
||||
}
|
||||
|
||||
@ -303,7 +315,7 @@ public class Role : Fun
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 角色死亡
|
||||
/// 角色死亡
|
||||
/// </summary>
|
||||
public virtual void die()
|
||||
{
|
||||
@ -324,7 +336,7 @@ public class Role : Fun
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 角色受到攻击
|
||||
/// 角色受到攻击
|
||||
/// </summary>
|
||||
public virtual void hit()
|
||||
{
|
||||
@ -336,16 +348,16 @@ public class Role : Fun
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 角色减速
|
||||
/// 角色减速
|
||||
/// </summary>
|
||||
public void SlowDown(float num)
|
||||
{
|
||||
Navigation.speedFactor *= num;
|
||||
}
|
||||
/// <summary>
|
||||
/// 单位更新buff
|
||||
/// 单位更新buff
|
||||
/// </summary>
|
||||
async void UpdateBuff()//单位buff更新
|
||||
async void UpdateBuff()//单位buff更新
|
||||
{
|
||||
while (true)
|
||||
{
|
||||
@ -370,83 +382,83 @@ public class Role : Fun
|
||||
{
|
||||
buffList.Remove(item);
|
||||
}
|
||||
await Task.Delay(100);//buff检测最小时间0.1秒执行一次
|
||||
await Task.Delay(100);//buff检测最小时间0.1秒执行一次
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 重置角色所有状态
|
||||
/// 重置角色所有状态
|
||||
/// </summary>
|
||||
public void ResetAllStatus()
|
||||
{
|
||||
|
||||
IsDead = false;
|
||||
// 重置血量
|
||||
// 重置血量
|
||||
Hp = 100f;
|
||||
|
||||
// 重置攻击力
|
||||
// 重置攻击力
|
||||
Attack = 10f;
|
||||
|
||||
// 重置护甲
|
||||
// 重置护甲
|
||||
physicalArmor = 10;
|
||||
magicArmor = 5;
|
||||
|
||||
// 重置等级
|
||||
// 重置等级
|
||||
Level = 1;
|
||||
|
||||
// 重置金币
|
||||
// 重置金币
|
||||
Gold = 10;
|
||||
|
||||
// 清空 Buff 列表
|
||||
// 清空 Buff 列表
|
||||
buffList.Clear();
|
||||
|
||||
// 如果有导航组件,停止当前的导航行为
|
||||
// 如果有导航组件,停止当前的导航行为
|
||||
if (Navigation != null)
|
||||
{
|
||||
//Navigation.Stop(); // 假设你有 Stop 方法来停止导航
|
||||
//Navigation.Stop(); // 假设你有 Stop 方法来停止导航
|
||||
}
|
||||
|
||||
// 重置角色动画
|
||||
// 重置角色动画
|
||||
animationHighlight = 0;
|
||||
isAnimationPlay = false;
|
||||
|
||||
// 重置碰撞体(根据需求是否需要调整)
|
||||
// 重置碰撞体(根据需求是否需要调整)
|
||||
if (mycollider != null)
|
||||
{
|
||||
mycollider.enabled = true; // 启用碰撞体
|
||||
mycollider.enabled = true; // 启用碰撞体
|
||||
}
|
||||
|
||||
// 如果有其他需要重置的状态,可以在这里添加
|
||||
// 如果有其他需要重置的状态,可以在这里添加
|
||||
}
|
||||
|
||||
public void FlashRedEffect(int color = 0, float time = 0.2f)//0、1 红、蓝
|
||||
public void FlashRedEffect(int color = 0, float time = 0.2f)//0、1 红、蓝
|
||||
{
|
||||
// 如果spriteRenderer存在
|
||||
// 如果spriteRenderer存在
|
||||
if (spriteRenderer != null)
|
||||
{
|
||||
// 创建一个Sequence来确保动画按顺序执行
|
||||
// 创建一个Sequence来确保动画按顺序执行
|
||||
Sequence sequence = DOTween.Sequence();
|
||||
|
||||
// 颜色变化
|
||||
// 颜色变化
|
||||
if (color == 0)
|
||||
{
|
||||
// 变为红色并恢复白色
|
||||
// 变为红色并恢复白色
|
||||
sequence.Append(spriteRenderer.DOColor(UnityEngine.Color.red, 0.2f))
|
||||
.Append(spriteRenderer.DOColor(UnityEngine.Color.white, time));
|
||||
}
|
||||
else if (color == 1)
|
||||
{
|
||||
// 更冷的深蓝色
|
||||
UnityEngine.Color frostBlueWithAlpha = new UnityEngine.Color(0.2f, 0.5f, 1f); ; // 冰冻蓝色
|
||||
// 更冷的深蓝色
|
||||
UnityEngine.Color frostBlueWithAlpha = new UnityEngine.Color(0.2f, 0.5f, 1f); ; // 冰冻蓝色
|
||||
|
||||
// 变为蓝色并恢复白色
|
||||
// 变为蓝色并恢复白色
|
||||
sequence.Append(spriteRenderer.DOColor(frostBlueWithAlpha, 0.2f))
|
||||
.Append(spriteRenderer.DOColor(UnityEngine.Color.white, time));
|
||||
}
|
||||
|
||||
// 开始执行Sequence
|
||||
// 开始执行Sequence
|
||||
sequence.Play();
|
||||
}
|
||||
}
|
||||
@ -454,13 +466,13 @@ public class Role : Fun
|
||||
|
||||
public void StopDoTween(float stopTime)
|
||||
{
|
||||
// 暂停当前的动画
|
||||
// 暂停当前的动画
|
||||
transform.DOPause();
|
||||
|
||||
// 插入一个自定义的延迟(僵直时间)
|
||||
// 插入一个自定义的延迟(僵直时间)
|
||||
DOTween.To(() => 0f, x => { }, 0f, stopTime).OnKill(() =>
|
||||
{
|
||||
// 在延迟结束后恢复动画
|
||||
// 在延迟结束后恢复动画
|
||||
transform.DOPlay();
|
||||
});
|
||||
}
|
||||
@ -470,7 +482,7 @@ public class Role : Fun
|
||||
|
||||
if (camp==Camp.Player)
|
||||
{
|
||||
// Debug.Log("攻击力赋值==============================" + MengyaoInfo.Instance.m_Mengyao.Count);
|
||||
// Debug.Log("攻击力赋值==============================" + MengyaoInfo.Instance.m_Mengyao.Count);
|
||||
foreach (Character character in MengyaoInfo.Instance.m_Mengyao)
|
||||
{
|
||||
if (id ==character.Id)
|
||||
@ -480,15 +492,15 @@ public class Role : Fun
|
||||
MaxAttack = int.Parse(character.MaxAttack);
|
||||
AttackCD = float.Parse(character.AttackCD);
|
||||
CritRate = float.Parse(character.CritRate);
|
||||
Quality=character.Quality;//品质
|
||||
Elements=character.Elements;//属性
|
||||
Info=character.Info;//详情
|
||||
SkillId=character.SkillId;//技能
|
||||
AttackType=character.AttackType;//攻击类型
|
||||
AttackActionType=character.AttackActionType;//攻击作用类型
|
||||
Quality=character.Quality;//品质
|
||||
Elements=character.Elements;//属性
|
||||
Info=character.Info;//详情
|
||||
SkillId=character.SkillId;//技能
|
||||
AttackType=character.AttackType;//攻击类型
|
||||
AttackActionType=character.AttackActionType;//攻击作用类型
|
||||
CriticalHitRateBonus = float.Parse(character.CriticalHitRateBonus);
|
||||
AttackRange = float.Parse(character.AttackRange);
|
||||
//Debug.Log("攻击力赋值++++++++++++++++++++++++++++++");
|
||||
//Debug.Log("攻击力赋值++++++++++++++++++++++++++++++");
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -496,52 +508,66 @@ public class Role : Fun
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 计算伤害
|
||||
/// 计算伤害
|
||||
/// </summary>
|
||||
/// <param name="self">造成者</param>
|
||||
/// <param name="Target">目标</param>
|
||||
/// <param name="self">造成者</param>
|
||||
/// <param name="Target">目标</param>
|
||||
/// <returns></returns>
|
||||
public float DamageCreate(Role Target)//伤害生成
|
||||
/// 萌妖每次攻击对敌人造成伤害=a*(1+g+d+e)*(1-b/100)*c*(1+h)
|
||||
//暴击情况下萌妖每次攻击对敌人造成伤害=a* (1+g+d+e)*(1-b/100)*c* (1+h)*(2+f)
|
||||
public float DamageCreate(Role Target)//伤害生成
|
||||
{
|
||||
// 生成普通伤害
|
||||
// 生成普通伤害
|
||||
float hurt = UnityEngine.Random.Range(MinAttack, MaxAttack);
|
||||
// 判断是否暴击
|
||||
float critChance = UnityEngine.Random.Range(0f, 1f); // 生成一个0到1之间的随机数
|
||||
// 判断是否暴击
|
||||
float critChance = UnityEngine.Random.Range(0f, 1f); // 生成一个0到1之间的随机数
|
||||
//敌人防御力
|
||||
float TargetDefense = Target.gameObject.GetComponent<enemy>().Defense;
|
||||
|
||||
|
||||
if (critChance < CritRate*(1+mySkillUp.CriticalRate)) // 如果暴击发生
|
||||
if (critChance < CritRate*(1+mySkillUp.CriticalRate)) // 如果暴击发生
|
||||
{
|
||||
// 计算暴击伤害(普通伤害乘以暴击加成)
|
||||
hurt *= (1 + CriticalHitRateBonus*(1+ mySkillUp.CriticalDamage));
|
||||
//Debug.Log("暴击发生!伤害增加:" + num);
|
||||
// 计算暴击伤害(普通伤害乘以暴击加成)
|
||||
hurt *= (2 + CriticalHitRateBonus*(1+ mySkillUp.CriticalDamage));
|
||||
isGoodDamege = true;
|
||||
UnityEngine.Debug.Log("暴击发生!伤害增加");
|
||||
}
|
||||
|
||||
hurt *= (1 + mySkillUp.DamageUp);
|
||||
// Debug.LogError("伤害加成:"+ mySkillUp.DamageUp);
|
||||
if (Target.hasfalg(CharacterFlags.big)) // 如果是大型敌人
|
||||
// Debug.LogError("伤害加成:"+ mySkillUp.DamageUp);
|
||||
if (Target.hasfalg(CharacterFlags.big)) // 如果是大型敌人
|
||||
{
|
||||
hurt*=(1+mySkillUp.DamageOfBig);
|
||||
//Debug.LogError("大型敌人加成");
|
||||
//Debug.LogError("大型敌人加成");
|
||||
}
|
||||
|
||||
if (Target.hasfalg(CharacterFlags.min)) // 如果是小型敌人
|
||||
if (Target.hasfalg(CharacterFlags.min)) // 如果是小型敌人
|
||||
{
|
||||
hurt *= (1 + mySkillUp.DamageOfMin);
|
||||
//Debug.LogError("小型敌人加成");
|
||||
//Debug.LogError("小型敌人加成");
|
||||
}
|
||||
|
||||
if (Target.hasfalg(CharacterFlags.fly)) // 如果是飞行敌人
|
||||
if (Target.hasfalg(CharacterFlags.fly)) // 如果是飞行敌人
|
||||
{
|
||||
hurt *= (1 + mySkillUp.DamageOfSky);
|
||||
//Debug.LogError("飞行敌人加成");
|
||||
//Debug.LogError("飞行敌人加成");
|
||||
}
|
||||
|
||||
if (Target.hasfalg(CharacterFlags.land)) // 如果是地面敌人
|
||||
if (Target.hasfalg(CharacterFlags.land)) // 如果是地面敌人
|
||||
{
|
||||
hurt *= (1 + mySkillUp.DamageOfland);
|
||||
//Debug.LogError("地面敌人加成");
|
||||
//Debug.LogError("地面敌人加成");
|
||||
}
|
||||
|
||||
if (hurt * (1 - TargetDefense / 100) < 1)
|
||||
{
|
||||
hurt = 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
hurt *=(1- TargetDefense/100) ;
|
||||
}
|
||||
|
||||
hurt *= (1 + WuxingDamage(Target.gameObject.GetComponent<enemy>()));//计算五行属性伤害
|
||||
if (GetComponent<enemy>())
|
||||
{
|
||||
GetComponent<enemy>().HarmNumber += Mathf.Round(hurt);
|
||||
@ -554,6 +580,29 @@ public class Role : Fun
|
||||
|
||||
}
|
||||
|
||||
public float WuxingDamage(enemy Target)//五行属性伤害计算 返回倍率减伤或增加伤害
|
||||
{
|
||||
// 克制关系表(使用二维数组或字典表示)
|
||||
// 行:敌人属性,列:萌妖属性
|
||||
// 正数表示加成,负数表示减成,0表示无影响
|
||||
float[,] attributeRelations = new float[5, 5]
|
||||
{
|
||||
// 金 木 水 火 土
|
||||
{ 0f, 0.5f, 0f, -0.25f, 0f }, // 金
|
||||
{ -0.25f, 0f, 0f, 0f, 0.5f }, // 木
|
||||
{ 0f, 0f, 0f, 0.5f, -0.25f }, // 水
|
||||
{ 0.5f, 0f, -0.25f, 0f, 0f }, // 火
|
||||
{ 0f, -0.25f, 0.5f, 0f, 0f } // 土
|
||||
};
|
||||
|
||||
|
||||
// 获取克制关系
|
||||
float relation = attributeRelations[ (int)GetComponent<enemy>().elementType,(int)Target.elementType];
|
||||
|
||||
// 如果是正数,表示加成,增加伤害
|
||||
// 如果是负数,表示减成,减少伤害
|
||||
UnityEngine.Debug.Log("属性关系:"+"萌妖"+ GetComponent<enemy>().elementType+"::"+"敌人"+ Target.elementType+"伤害加成"+relation);
|
||||
return relation;
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user