public int GetTarget(int lookDis) { int targetUid = 0; FixedPoint m_minDis2 = new FixedPoint(999999); List <long> list = CCreatureMgr.GetCreatureList(); for (int i = 0; i < list.Count; i++) { CCreature cc = CCreatureMgr.Get(list[i]); FixedPoint abDis2 = FPCollide.GetDis2(GetPos(), cc.GetPos()); if (abDis2 > new FixedPoint(lookDis * lookDis)) { continue; } if (cc.IsDie() || cc.GetUid() == GetUid()) { continue; } if (abDis2 < new FixedPoint(lookDis * lookDis)) // 如果目标在视线范围内 { if (abDis2 < m_minDis2) { m_minDis2 = abDis2; targetUid = (int)cc.GetUid(); } } } return(targetUid); }
public static bool SendSkill(CCreature m_creature, BtDatabase m_dataBase, bool bDown = false) { int targetUid = m_dataBase.GetData <int>((int)eAIParam.INT_TARGET_UID); if (targetUid == m_creature.GetUid()) { return(false); } CCreature targetCc = CCreatureMgr.Get(targetUid); if (targetCc != null) { Vector2d dir = (targetCc.GetPos() - m_creature.GetPos()); dir.Normalize(); //if (dir == Vector2.zero) //{ // dir = m_creature.GetDir(); //} int selectSkillUid = m_dataBase.GetData <int>((int)eAIParam.INT_SELECT_SKILL_INDEX); CSkillInfo skillInfo = m_creature.GetSkillByIndex(selectSkillUid); CmdFspSendSkill cmd = new CmdFspSendSkill(); cmd.m_casterUid = (int)m_creature.GetUid(); cmd.m_skillIndex = selectSkillUid; if (skillInfo.m_skillInfo.selectTargetType == (int)eSelectTargetType.Self) { } else if (skillInfo.m_skillInfo.selectTargetType == (int)eSelectTargetType.Dir || skillInfo.m_skillInfo.selectTargetType == (int)eSelectTargetType.SectorDir) { cmd.m_dir = dir; } else if (skillInfo.m_skillInfo.selectTargetType == (int)eSelectTargetType.Pos) { cmd.m_dir = dir; cmd.m_endPos = targetCc.GetPos(); } cmd.m_bDown = bDown; if (m_creature.m_aiType == eAIType.Player) { m_creature.SendFspCmd(cmd); } else { m_creature.PushCommand(cmd); } // 进入公共CD m_dataBase.SetData <int>((int)eAIParam.INT_SKILL_INTERVAL, GetSkillCastCd(m_creature, m_dataBase)); // 清空当前发送的技能 m_dataBase.SetData <int>((int)eAIParam.INT_SELECT_SKILL_INDEX, -1); return(true); } return(false); }
public void OnHitTarget() { FixedPoint m_minDis2 = new FixedPoint(999999); CCreature target = null; List <long> list = CCreatureMgr.GetCreatureList(); for (int i = 0; i < list.Count; i++) { CCreature creature = CCreatureMgr.Get(list[i]); if (m_listHited != null && m_listHited.Contains((int)list[i])) { continue; } if (m_caster == creature || m_caster.bCamp(creature) || creature.IsDie() || creature == m_rec) { continue; } FixedPoint abDis2 = FPCollide.GetDis2(m_rec.GetPos(), creature.GetPos()); if (abDis2 < new FixedPoint(m_triggerData.Length * m_triggerData.Length)) { if (abDis2 < m_minDis2) { target = creature; m_minDis2 = abDis2; } } } if (target != null) { if (m_listHited == null) { m_listHited = new List <int>(); } Debug.Log("添加单位:" + target.GetUid()); m_listHited.Add((int)target.GetUid()); OnHitAddBuff(m_caster, target, m_listHited); VTrigger vTri = GetVTrigger(); if (vTri != null && m_rec != null && m_rec.GetVObject() != null) { Vector3 sh = m_rec.GetVObject().GetHitHeight(); Vector3 th = target.GetVObject().GetHitHeight(); vTri.SetLineStartPos(GetPos().ToVector3() + sh); vTri.SetLineTargetPos(target.GetPos().ToVector3() + th); } } else { Destory(); } }
/// <summary> /// 是否同阵营 /// </summary> /// <param name="target"></param> /// <returns></returns> public bool bCamp(CCreature target) { if (GetUid() == target.GetUid()) { return(true); } return(false); if (IsPlayer() && target.IsMonster()) // 玩家对怪物 { return(false); } //else if (IsPartner() && target.IsMonster()) //{ // return false; //} else if (IsMonster() && target.IsPlayer()) // 怪物对玩家 { return(false); } else if (IsNpc() && target.IsMonster()) // 坐骑对怪物 { return(false); } return(true); }
public static void SendSkill(CCreature m_creature, BtDatabase m_dataBase) { int selectSkillUid = m_dataBase.GetData <int>((int)eAIParam.INT_SELECT_SKILL_INDEX); CmdFspSendSkill cmd = new CmdFspSendSkill(); cmd.m_casterUid = (int)m_creature.GetUid(); cmd.m_skillIndex = selectSkillUid; cmd.m_bDown = false; m_creature.PushCommand(cmd); // 进入公共CD m_dataBase.SetData <int>((int)eAIParam.INT_SKILL_INTERVAL, GetSkillCastCd(m_creature, m_dataBase)); // 清空当前发送的技能 m_dataBase.SetData <int>((int)eAIParam.INT_SELECT_SKILL_INDEX, 0); }
public void EnterFrame() { if (m_player.IsDie()) { return; } m_curTime += FSPParam.clientFrameMsTime; if (m_curTime >= 40 * FSPParam.clientFrameMsTime) { if (m_tree != null) { m_tree.OnUpdate(); } // AI技能外部CD int curSkillInterval = m_tree.m_dataBase.GetData <int>((int)eAIParam.INT_SKILL_INTERVAL); if (curSkillInterval >= 0) { curSkillInterval -= FSPParam.clientFrameMsTime; m_tree.m_dataBase.SetData <int>((int)eAIParam.INT_SKILL_INTERVAL, curSkillInterval); } if (Client.Inst().m_bDebug) { string state = GetCurState(); if (!string.IsNullOrEmpty(state))// 如果卡主,可以知道最后一个状态 { // 状态显示 VObject mt = m_player.GetVObject(); if (mt == null) { return; } CmdUIHead cmd = new CmdUIHead(); cmd.type = 1; cmd.name = m_player.GetUid() + ":" + state; mt.PushCommand(cmd); } } // 仇恨值 m_curHatredTime += FSPParam.clientFrameMsTime; if (m_curHatredTime >= 30 * FSPParam.clientFrameMsTime) { _UpdateHatredList(); //主角显示测试界面 if (m_player.IsMaster()) { m_hatredList.Sort((x, y) => { if (x.val == y.val) { return(0); } else if (x.val > y.val) { return(-1); } else { return(1); } }); //m_list.Init(m_hatredList.Count, (item, index) => //{ // UIItem.SetText(item, "txt", m_hatredList[index].uid + " 仇恨值:" + m_hatredList[index].val); // UIItem.SetProgress(item, "pct", m_hatredList[index].val, 100); //}); } m_curHatredTime = 0; } } }