//刷新道具技能 public void FreshItemSkill(Google.Protobuf.Collections.RepeatedField <global::Protomsg.SkillDatas> itemskilldata) { //m_ItemSkillDatas //buff数据 叠加计算出正确数据 foreach (var item in itemskilldata) { bool isfind = false;//如果在以前的BuffDatas中没找到 则为新增buff if (m_ItemSkillDatas != null) { for (var i = 0; i < m_ItemSkillDatas.Length; i++) { if (item.TypeID == m_ItemSkillDatas[i].TypeID) { item.Level += m_ItemSkillDatas[i].Level; item.RemainCDTime += m_ItemSkillDatas[i].RemainCDTime; item.CanUpgrade += m_ItemSkillDatas[i].CanUpgrade; item.Index += m_ItemSkillDatas[i].Index; item.CastType += m_ItemSkillDatas[i].CastType; item.CastTargetType += m_ItemSkillDatas[i].CastTargetType; item.UnitTargetTeam += m_ItemSkillDatas[i].UnitTargetTeam; item.UnitTargetCamp += m_ItemSkillDatas[i].UnitTargetCamp; item.NoCareMagicImmune += m_ItemSkillDatas[i].NoCareMagicImmune; item.CastRange += m_ItemSkillDatas[i].CastRange; item.Cooldown += m_ItemSkillDatas[i].Cooldown; item.HurtRange += m_ItemSkillDatas[i].HurtRange; item.ManaCost += m_ItemSkillDatas[i].ManaCost; item.AttackAutoActive += m_ItemSkillDatas[i].AttackAutoActive; item.Visible += m_ItemSkillDatas[i].Visible; item.RemainSkillCount += m_ItemSkillDatas[i].RemainSkillCount; //isfind = true; //FreshBuffSpecial(item); } } } } //道具技能数据赋值 if (itemskilldata.Count > 0) { m_ItemSkillDatas = new Protomsg.SkillDatas[itemskilldata.Count]; int index = 0; foreach (var item in itemskilldata) { m_ItemSkillDatas[index++] = item; } } else { m_ItemSkillDatas = null; } }
//获取离本单位 夹角最小的单位 满足技能释放目标条件 且夹角小于45度 public UnityEntity GetMinAngleUnitForSkillTarget(UnityEntity my, Vector2 dir, Protomsg.SkillDatas skilldata) { if (my == null || dir == Vector2.zero || skilldata.CastRange <= 0) { return(null); } float minangle = 0; UnityEntity minangelUnityEntity = null; foreach (var item in m_UnityEntitys) { if (item.Key == my.ID || item.Value.IsDeath == 1) { continue; } if (CheckCastSkillTarget(item.Value, my, skilldata) == false) { continue; } var dis = Vector2.Distance(new Vector2(item.Value.X, item.Value.Y), new Vector2(my.X, my.Y)); if (skilldata.CastRange > dis) { float angle1 = Vector2.Angle(dir, new Vector2(item.Value.X - my.X, item.Value.Y - my.Y)); //是否超过最大角度 if (angle1 > MaxAngle) { continue; } if (minangelUnityEntity == null) { minangelUnityEntity = item.Value; minangle = angle1; } else if (angle1 < minangle) { minangelUnityEntity = item.Value; minangle = angle1; } } } return(minangelUnityEntity); }
//获取离本单位最近的敌方英雄和BOSS 且距离小于 distanse public UnityEntity GetNearestBigUnitForSkillTarget(UnityEntity my, Protomsg.SkillDatas skilldata, float distanse) { var myunityentity = my; if (myunityentity == null) { Debug.Log("GetNearestEnemy null"); return(null); } var mindis = distanse; UnityEntity nearrestUnityEntity = null; foreach (var item in m_UnityEntitys) { if (item.Key == myunityentity.ID || item.Value.IsDeath == 1) { continue; } ////单位类型(1:英雄 2:普通单位 3:远古 4:boss) if (item.Value.IsBigUnit() == false) { continue; } if (CheckCastSkillTarget(item.Value, myunityentity, skilldata) == false) { continue; } var dis = Vector2.Distance(new Vector2(item.Value.X, item.Value.Y), new Vector2(myunityentity.X, myunityentity.Y)); if (mindis > dis) { Debug.Log("dis " + dis); mindis = dis; nearrestUnityEntity = item.Value; } } return(nearrestUnityEntity); }
public void PressSkillBtn(int touchstate, Vector2 dir, Protomsg.SkillDatas skilldata, bool isno, bool ismy) { if (m_MyMainUnit == null) { return; } float showattackrange = AttackSelectTargetDis; if (skilldata.CastRange > showattackrange) { showattackrange = skilldata.CastRange; } //CastTargetType 施法目标类型 1:自身为目标 2:以单位为目标 3:以地面1点为目标 //4:攻击时自动释放(攻击特效)5:以地面一点为方向 if (touchstate == 1) { //第一次选择目标 if (m_TargetUnit == null) { m_TargetUnit = UnityEntityManager.Instance.GetNearestBigUnitForSkillTarget(m_MyMainUnit, skilldata, showattackrange); if (m_TargetUnit == null) { m_TargetUnit = UnityEntityManager.Instance.GetNearestUnitForSkillTarget(m_MyMainUnit, skilldata); } } else { m_TargetUnit.TargetShow(false); m_TargetUnit.TargetShowRedCircle(false); if (UnityEntityManager.Instance.CheckCastSkillTarget(m_TargetUnit, m_MyMainUnit, skilldata) == false) { var target1 = UnityEntityManager.Instance.GetNearestBigUnitForSkillTarget(m_MyMainUnit, skilldata, showattackrange); //m_TargetUnit = UnityEntityManager.Instance.GetNearestBigUnitForSkillTarget(m_MyMainUnit, skilldata, showattackrange); if (target1 == null) { target1 = UnityEntityManager.Instance.GetNearestUnitForSkillTarget(m_MyMainUnit, skilldata); } if (target1 != null) { m_TargetUnit = target1; } } //不在范围内都重新寻找 //如果是普通单位且不在寻找攻击范围内 则重新寻找最近单位 var dis = Vector2.Distance(new Vector2(m_MyMainUnit.X, m_MyMainUnit.Y), new Vector2(m_TargetUnit.X, m_TargetUnit.Y)); if (showattackrange < dis) { m_TargetUnit = UnityEntityManager.Instance.GetNearestBigUnitForSkillTarget(m_MyMainUnit, skilldata, showattackrange); if (m_TargetUnit == null) { m_TargetUnit = UnityEntityManager.Instance.GetNearestUnitForSkillTarget(m_MyMainUnit, skilldata); } } else { //单位类型(1:英雄 2:普通单位 3:远古 4:boss) //如果不是大仇恨敌方单位 if (m_TargetUnit.IsBigUnit() == false) { var bigenemy = UnityEntityManager.Instance.GetNearestBigUnitForSkillTarget(m_MyMainUnit, skilldata, showattackrange); if (bigenemy != null) { m_TargetUnit = bigenemy; } else { //不在攻击范围内 if (skilldata.CastRange < dis) { m_TargetUnit = UnityEntityManager.Instance.GetNearestUnitForSkillTarget(m_MyMainUnit, skilldata); } } } } } switch (skilldata.CastTargetType) { case 4: Protomsg.CS_PlayerSkill msg4 = new Protomsg.CS_PlayerSkill(); msg4.ID = m_MyMainUnit.ID; msg4.TargetUnitID = 0; msg4.X = 0; msg4.Y = 0; msg4.SkillID = skilldata.TypeID; MyKcp.Instance.SendMsg(m_ServerName, "CS_PlayerSkill", msg4); break; case 1: if (skilldata.HurtRange > 0.1) { m_MyMainUnit.ShowOutCircle(true, skilldata.HurtRange); } break; case 2: if (m_TargetUnit == null) { m_TargetUnit = UnityEntityManager.Instance.GetNearestUnitForSkillTarget(m_MyMainUnit, skilldata); if (m_TargetUnit == null) { return; } } m_TargetUnit.TargetShow(true); m_TargetUnit.TargetShowRedCircle(true); m_MyMainUnit.ShowSkillAreaLookAt(true, new Vector2(m_TargetUnit.X, m_TargetUnit.Y)); //m_MyMainUnit.ShowOutCircle(true, skilldata.CastRange); break; case 3: { var targetPos = new Vector2(m_MyMainUnit.X, m_MyMainUnit.Y); if (m_TargetUnit != null) { targetPos = new Vector2(m_TargetUnit.X, m_TargetUnit.Y); } else { //进攻性技能 var skillclientitem = ExcelManager.Instance.GetSkillManager().GetSkillByID(skilldata.TypeID); if (skillclientitem != null) { //技能自动瞄准类型 1:普通 2:位移技能(朝目标方向最大距离) 3:进攻技能(瞄准敌人) if (skillclientitem.AutoAimType == 3) { var targetunit = UnityEntityManager.Instance.GetNearestEnemy(m_MyMainUnit); if (targetunit != null) { targetPos = new Vector2(targetunit.X, targetunit.Y); } } else if (skillclientitem.AutoAimType == 2) { var targetDir = new Vector2(m_MyMainUnit.DirectionX, m_MyMainUnit.DirectionY); targetPos = new Vector2(m_MyMainUnit.X, m_MyMainUnit.Y) + (targetDir.normalized * skilldata.CastRange); } } } m_MyMainUnit.ShowInCircle(true, skilldata.HurtRange, new Vector3(targetPos.x - m_MyMainUnit.X, 0, targetPos.y - m_MyMainUnit.Y)); break; } case 5: { var targetDir = new Vector2(m_MyMainUnit.DirectionX, m_MyMainUnit.DirectionY); if (m_TargetUnit != null) { targetDir = new Vector2(m_TargetUnit.X - m_MyMainUnit.X, m_TargetUnit.Y - m_MyMainUnit.Y); } else { //进攻性技能 var skillclientitem = ExcelManager.Instance.GetSkillManager().GetSkillByID(skilldata.TypeID); if (skillclientitem != null) { //技能自动瞄准类型 1:普通 2:位移技能(朝目标方向最大距离) 3:进攻技能(瞄准敌人) if (skillclientitem.AutoAimType == 3) { var targetunit = UnityEntityManager.Instance.GetNearestEnemy(m_MyMainUnit); if (targetunit != null) { targetDir = new Vector2(targetunit.X - m_MyMainUnit.X, targetunit.Y - m_MyMainUnit.Y); } } else if (skillclientitem.AutoAimType == 2) { } } } var targetpos = new Vector2(m_MyMainUnit.X, m_MyMainUnit.Y) + (targetDir.normalized * skilldata.CastRange); //m_MyMainUnit.ShowInCircle(true, 1, new Vector3(targetPos.x - m_MyMainUnit.X, 0, targetPos.y - m_MyMainUnit.Y)); m_MyMainUnit.ShowSkillAreaLookAt(true, targetpos); break; } } if (skilldata.CastRange > 0.1) { m_MyMainUnit.ShowOutCircle(true, skilldata.CastRange); } } else if (touchstate == 2) { switch (skilldata.CastTargetType) { case 1: break; case 2: var target = UnityEntityManager.Instance.GetMinAngleUnitForSkillTarget(m_MyMainUnit, dir, skilldata); if (target != null) { if (m_TargetUnit != null) { m_TargetUnit.TargetShow(false); m_TargetUnit.TargetShowRedCircle(false); } m_TargetUnit = target; m_TargetUnit.TargetShow(true); m_TargetUnit.TargetShowRedCircle(true); var targetpos = new Vector2(m_MyMainUnit.X, m_MyMainUnit.Y) + (dir.normalized * skilldata.CastRange); m_MyMainUnit.ShowSkillAreaLookAt(true, targetpos); } else { if (m_TargetUnit != null) { m_TargetUnit.TargetShow(true); m_TargetUnit.TargetShowRedCircle(true); var targetpos = new Vector2(m_MyMainUnit.X, m_MyMainUnit.Y) + (dir.normalized * skilldata.CastRange); m_MyMainUnit.ShowSkillAreaLookAt(true, targetpos); } } break; case 3: { if (m_TargetUnit != null) { m_TargetUnit.TargetShow(false); m_TargetUnit.TargetShowRedCircle(false); m_TargetUnit = null; } m_MyMainUnit.ShowInCircle(true, skilldata.HurtRange, new Vector3(dir.x, 0, dir.y)); } break; case 5: { if (m_TargetUnit != null) { m_TargetUnit.TargetShow(false); m_TargetUnit.TargetShowRedCircle(false); m_TargetUnit = null; } var targetpos = new Vector2(m_MyMainUnit.X, m_MyMainUnit.Y) + (dir.normalized * skilldata.CastRange); m_MyMainUnit.ShowSkillAreaLookAt(true, targetpos); //m_MyMainUnit.ShowInCircle(true, 1, new Vector3(dir.x, 0, dir.y)); } break; } if (skilldata.CastRange > 0.1) { m_MyMainUnit.ShowOutCircle(true, skilldata.CastRange); } } else if (touchstate == 3) { if (isno == true) { if (m_TargetUnit != null) { m_TargetUnit.TargetShow(false); } m_MyMainUnit.ShowOutCircle(false, 10); m_MyMainUnit.ShowSkillAreaLookAt(false, Vector2.zero); m_MyMainUnit.ShowInCircle(false, 1, new Vector3(0, 0, 0)); return; } if (ismy == true) { Protomsg.CS_PlayerSkill msgmy = new Protomsg.CS_PlayerSkill(); msgmy.ID = m_MyMainUnit.ID; msgmy.TargetUnitID = m_MyMainUnit.ID; msgmy.X = 0; msgmy.Y = 0; msgmy.SkillID = skilldata.TypeID; MyKcp.Instance.SendMsg(m_ServerName, "CS_PlayerSkill", msgmy); if (m_TargetUnit != null) { m_TargetUnit.TargetShow(false); } m_MyMainUnit.ShowOutCircle(false, 10); m_MyMainUnit.ShowSkillAreaLookAt(false, Vector2.zero); m_MyMainUnit.ShowInCircle(false, 1, new Vector3(0, 0, 0)); return; } switch (skilldata.CastTargetType) { case 1: Protomsg.CS_PlayerSkill msg2 = new Protomsg.CS_PlayerSkill(); msg2.ID = m_MyMainUnit.ID; msg2.TargetUnitID = 0; msg2.X = 0; msg2.Y = 0; msg2.SkillID = skilldata.TypeID; MyKcp.Instance.SendMsg(m_ServerName, "CS_PlayerSkill", msg2); m_MyMainUnit.ShowOutCircle(false, 10); Debug.Log("CS_PlayerSkill 1111"); break; case 2: if (m_TargetUnit == null) { return; } Protomsg.CS_PlayerSkill msg1 = new Protomsg.CS_PlayerSkill(); msg1.ID = m_MyMainUnit.ID; msg1.TargetUnitID = m_TargetUnit.ID; msg1.X = 0; msg1.Y = 0; msg1.SkillID = skilldata.TypeID; MyKcp.Instance.SendMsg(m_ServerName, "CS_PlayerSkill", msg1); Debug.Log("CS_PlayerSkill"); m_TargetUnit.TargetShow(false); m_MyMainUnit.ShowOutCircle(false, 10); m_MyMainUnit.ShowSkillAreaLookAt(false, Vector2.zero); break; case 3: { var targetPos = new Vector2(m_MyMainUnit.X + dir.x, m_MyMainUnit.Y + dir.y); if (m_TargetUnit != null) { targetPos = new Vector2(m_TargetUnit.X, m_TargetUnit.Y); } Protomsg.CS_PlayerSkill msg3 = new Protomsg.CS_PlayerSkill(); msg3.ID = m_MyMainUnit.ID; msg3.TargetUnitID = -1; //msg3.X = targetPos.x; //msg3.Y = targetPos.y; msg3.X = m_MyMainUnit.m_SkillAreaInCircleOffsetPos.x + m_MyMainUnit.X; msg3.Y = m_MyMainUnit.m_SkillAreaInCircleOffsetPos.z + m_MyMainUnit.Y; msg3.SkillID = skilldata.TypeID; MyKcp.Instance.SendMsg(m_ServerName, "CS_PlayerSkill", msg3); Debug.Log("CS_PlayerSkill"); m_MyMainUnit.ShowOutCircle(false, 10); m_MyMainUnit.ShowInCircle(false, skilldata.HurtRange, new Vector3(dir.x, 0, dir.y)); m_MyMainUnit.ShowSkillAreaLookAt(false, Vector2.zero); } break; case 5: { var targetPos = new Vector2(m_MyMainUnit.X + dir.x, m_MyMainUnit.Y + dir.y); if (m_TargetUnit != null) { targetPos = new Vector2(m_TargetUnit.X, m_TargetUnit.Y); } Protomsg.CS_PlayerSkill msg3 = new Protomsg.CS_PlayerSkill(); msg3.ID = m_MyMainUnit.ID; msg3.TargetUnitID = -1; //msg3.X = targetPos.x; //msg3.Y = targetPos.y; msg3.X = m_MyMainUnit.m_SkillAreaLookAtDir.x + m_MyMainUnit.X; msg3.Y = m_MyMainUnit.m_SkillAreaLookAtDir.z + m_MyMainUnit.Y; msg3.SkillID = skilldata.TypeID; MyKcp.Instance.SendMsg(m_ServerName, "CS_PlayerSkill", msg3); Debug.Log("CS_PlayerSkill"); m_MyMainUnit.ShowOutCircle(false, 10); m_MyMainUnit.ShowInCircle(false, 1, new Vector3(0, 0, 0)); m_MyMainUnit.ShowSkillAreaLookAt(false, Vector2.zero); } break; } } return; }
//检查单位是否满足技能释放条件 //int32 UnitTargetTeam = 8;//目标单位关系 1:友方 2:敌方 3:友方敌方都行包括自己 4:友方敌方都行不包括自己 5:自己 6:自己和敌方 10:除自己外的其他 20 自己控制的单位(不包括自己) //int32 UnitTargetCamp = 9;////目标单位阵营 (1:英雄 2:普通单位 3:远古 4:boss) 5:都行 6:除了boss都行 public bool CheckCastSkillTarget(UnityEntity target, UnityEntity my, Protomsg.SkillDatas skilldata) { if (target == null || my == null) { return(true); } if (skilldata.UnitTargetTeam == 1) { //是否是敌人 if (CheckIsEnemy(target, my) == true) { return(false); } } else if (skilldata.UnitTargetTeam == 2) { //是否是敌人 if (CheckIsEnemy(target, my) == false) { return(false); } } else if (skilldata.UnitTargetTeam == 4 || skilldata.UnitTargetTeam == 10) { if (target == my) { return(false); } } else if (skilldata.UnitTargetTeam == 5) { if (target != my) { return(false); } } else if (skilldata.UnitTargetTeam == 6) { if (target != my && CheckIsEnemy(target, my) == false) { return(false); } } else if (skilldata.UnitTargetTeam == 20) { //Debug.Log("-------:" + target.ControlID + " :" + my.ControlID); if (target.ControlID != my.ControlID || target == my) { return(false); } } if (skilldata.UnitTargetCamp != 5) { if (skilldata.UnitTargetCamp == 6) { if (target.UnitType == 4) { return(false); } return(true); } if (target.UnitType != skilldata.UnitTargetCamp) { return(false); } if (skilldata.UnitTargetCamp == 1 && target.IsMirrorImage == 1) { return(false); } } //if (skilldata.UnitTargetCamp == 1) //{ // if (target.UnitType != 1) // { // return false; // } //} //else if (skilldata.UnitTargetCamp == 2) //{ // if (target.UnitType == 1) // { // return false; // } //} return(true); }
public int WatchVedioAddDiamond; //观看视频能获得的砖石数 public UnityEntity(Protomsg.UnitDatas data, GameScene scene) { //m_AllWords = new Dictionary<WordsInfo, WordsInfo>(); RotateSpeed = 480; m_Scene = scene; Name = data.Name; GuildName = data.GuildName; Level = data.Level; Experience = data.Experience; MaxExperience = data.MaxExperience; HP = data.HP; MP = data.MP; MaxHP = data.MaxHP; MaxMP = data.MaxMP; ControlID = data.ControlID; AttackAnim = data.AttackAnim; ModeType = data.ModeType; ID = data.ID; TypeID = data.TypeID; TeamID = data.TeamID; GuildID = data.GuildID; GroupID = data.GroupID; Gold = data.Gold; Diamond = data.Diamond; RemainReviveTime = data.RemainReviveTime; RemainExperience = data.RemainExperience; ReviveGold = data.ReviveGold; ReviveDiamond = data.ReviveDiamond; SkillEnable = data.SkillEnable; ItemEnable = data.ItemEnable; RemainWatchVedioCountToday = data.RemainWatchVedioCountToday; WatchVedioAddDiamond = data.WatchVedioAddDiamond; CharacterID = data.Characterid; X = data.X; Y = data.Y; Z = data.Z; IsMirrorImage = data.IsMirrorImage; AttackRange = data.AttackRange; DirectionX = data.DirectionX; DirectionY = data.DirectionY; AttackMode = data.AttackMode; //攻击模式(1:和平模式 2:组队模式 3:全体模式 4:阵营模式(玩家,NPC) 5:行会模式) UnitType = data.UnitType; //需要数据 ModeType AttackAcpabilities = data.AttackAcpabilities; IsMain = data.IsMain; IsDeath = data.IsDeath; Camp = data.Camp; //InOtherSpace = data.InOtherSpace; AttackTime = data.AttackTime; if (data.SD.Count > 0) { m_SkillDatas = new Protomsg.SkillDatas[data.SD.Count]; int index = 0; foreach (var item in data.SD) { m_SkillDatas[index++] = item; } } FreshBuff(data.BD); FreshItemSkill(data.ISD); m_Mode.transform.position = new Vector3(data.X, data.Z, data.Y); AnimotorState = data.AnimotorState; AnimotorPause = data.AnimotorPause; if (data.IsMiss) { this.ShowMiss(); } }