2
0
Fork 0
You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

130 lines
4.7 KiB
C#

2 years ago
using System;
using UnityEngine;
namespace Game
{
public class SkillHitInfo
{
public AttackBehaviour SkillParam;
public float AttackRate;
public float StunkRate;
public float ExecutekRate;
public int OwnerEntity;
public int HitEntity; //0为非实体对象
2 years ago
public Vector3 HitPos;
public Vector3 HitDir;
public bool IsRight;
public bool IsDealed; //已经结算
2 years ago
public string SkillId; //是否技能造成的伤害
public uint Performance; //性能tag的mask
2 years ago
public int StaggerLevel;
public bool IsBreak;
public EHitType HitType;
2 years ago
}
2 years ago
public class ClipAttack : TimelineClipBase
{
private AttackClip _mRealAsset;
2 years ago
public override void OnEnter()
{
_mRealAsset = Asset as AttackClip;
}
2 years ago
public override void OnStay()
{
var skill = Owner.skill;
var castDir = Owner.skill.CastDir;
castDir = new Vector3(castDir.x, 0, castDir.z); //忽略y
2 years ago
var param = _mRealAsset.template;
void DealFunc(GameObject hitGo, Vector3 hitPos)
{
var hitEntityId = 0;
EntityInfo info;
if (hitGo.TryGetComponent<EntityInfo>(out info))
{
hitEntityId = info.entityId;
if (Util.GetEntity(hitEntityId).Team() == Owner.Team())
{
return;
}
}
2 years ago
var hitKey = new Tuple<int, int>(hitEntityId, param.hitId);
if (!Owner.skill.SkillHitInfo.ContainsKey(hitKey))
{
var skillHitInfo = new SkillHitInfo()
{
SkillParam = param,
AttackRate = 1,
StunkRate = 1,
ExecutekRate = 1,
OwnerEntity = Owner.ID(),
HitEntity = hitEntityId,
HitPos = hitPos,
HitDir = castDir,
IsRight = Owner.move.IsRight,
IsDealed = false,
SkillId = skill.SkillId.Value,
Performance = 0,
StaggerLevel = param.staggerLevel,
IsBreak = true,
HitType = param.hitType,
2 years ago
};
if (!string.IsNullOrEmpty(skillHitInfo.SkillId))
{
var skillCfg = Util.GetSkillMasterConfigData(skillHitInfo.SkillId);
if (skillCfg != null)
{
var featureSkill = skillCfg.GetFeatureSkill();
skillHitInfo.AttackRate = featureSkill.AttackRate;
skillHitInfo.StunkRate = featureSkill.StunRate;
skillHitInfo.ExecutekRate = featureSkill.ExecuteRate;
}
}
Owner.skill.SkillHitInfo[hitKey] = skillHitInfo;
2 years ago
}
}
if (param.isRaycast)
{
var posPre = Owner.PosPre();
var pos = Owner.Pos();
var distance = Vector3.Distance(pos, posPre);
var dir = pos - posPre;
var hitInfos = Physics.RaycastAll(posPre, dir, distance, UtilPhysics.LayerMaskHit);
Util.Draw(posPre, pos, Color.green);
foreach (var hitInfo in hitInfos)
{
var hitGo = hitInfo.transform.gameObject;
DealFunc(hitGo, hitInfo.point);
}
}
else
{
var rot = Quaternion.FromToRotation(Vector3.right, castDir);
var toGridSize = 16f / 64f;
var center = rot * param.center * toGridSize + Owner.Pos();
var halfExtents = param.halfExtents * toGridSize;
var hitInfos = Physics.BoxCastAll(center, halfExtents, castDir, rot, 0,
layerMask: UtilPhysics.LayerMaskHit);
2 years ago
Util.DrawBox(center, halfExtents, castDir, Color.green);
foreach (var hitInfo in hitInfos)
{
var hitGo = hitInfo.transform.gameObject;
DealFunc(hitGo, hitInfo.point);
}
}
}
2 years ago
public override void OnLeave()
{
}
}
}