/// <summary> /// 0.超过巡逻点太远,放弃战斗 /// 1.当前有目标,并且在10米内,转下一个条件 /// 2.仇恨高,作为目标 /// 3.范围最近,作为目标 /// </summary> public override bool Check() { //if (!m_bCheckTarget) // return false; //// 如果大于追踪距离 //Vector2 dV = m_creature.GetPos() - m_creature.m_bornPoint; //float dis2 = Vector2.Dot(dV, dV); //if (dis2 >= m_shaseDis * m_shaseDis) //{ // m_dataBase.SetData<int>((int)eAIParam.INT_TARGET_UID, 0); // Vector2 pPos = m_creature.m_bornPoint; // m_creature.GoTo(pPos); // m_bCheckTarget = false; // CFrameTimeMgr.Inst.RegisterEvent(2000, () => // { // m_bCheckTarget = true; // }); // return false; //} bool hasTarget = AIParam.GetAtkTarget(m_creature, m_dataBase, m_lookDis); return(hasTarget); }
public override BtResult Execute() { GetSkillDis(); if (m_skillDis == 0) { AIParam.SendSkill(m_creature, m_dataBase); return(BtResult.Ended); } // 1.实时获取当前选择的技能和目标计算 当前的移动位置 // 2.如果到达,即可结束 int targetUid = m_dataBase.GetData <int>((int)eAIParam.INT_TARGET_UID); CCreature targetCC = CCreatureMgr.Get(targetUid); if (targetCC != null) { FixedPoint dis2 = FPCollide.GetDis2(targetCC.GetPos(), m_creature.GetPos()); if (dis2 < new FixedPoint(m_skillDis * m_skillDis)) { return(BtResult.Ended); } else { // 一秒执行一次 m_curTime += FSPParam.clientFrameMsTime; if (m_curTime >= 30 * FSPParam.clientFrameMsTime) { m_curTime = 0; //Vector2 pPos = targetCC.GetPos(); //m_creature.GoTo(pPos); Vector2d dir = targetCC.GetPos() - m_creature.GetPos(); Vector2d target = m_creature.GetPos() + dir.normalized * new FixedPoint(m_skillDis); Vector2d endPos = CMapMgr.m_map.GetRandomPos(target.x.value, target.y.value, 3, m_creature.m_aiType).ToVector2d(); //Vector2d pPos = targetCC.GetPos(); CmdFspAutoMove cmd = new CmdFspAutoMove(); cmd.m_pos = endPos; if (m_creature.m_aiType == eAIType.Player) { m_creature.SendFspCmd(cmd); } else { m_creature.PushCommand(cmd); } } return(BtResult.Running); } } return(BtResult.Ended); }
public override BtResult Execute() { // 发送常用技能 AIParam.SendSkill(m_creature, m_dataBase, false); return(BtResult.Ended); }
public CCreatureAI(CCreature creature, eAILevel level = eAILevel.HARD, bool bPatrol = true) { //if(creature.IsMaster()) //{ // m_list = GameObject.Find("ai_list").AddComponent<UISuperList>(); // m_list.Init(300, 60, 1, 5); //} m_player = creature; m_level = level; InitComboData(); //m_aiObject = new GameObject("ai_" + creature.GetUid()); m_tree = new BtTree(); m_tree.m_root = new BtPrioritySelector(); m_tree.Init(); m_tree.m_dataBase.SetData <CCreature>((int)eAIParam.INT_ROLE_UID, creature); AIParam.Init(m_tree.m_dataBase); // skill level up //Condi_SkillUp c_skillUp = new Condi_SkillUp(); //Action_SkillUp a_skillUp = new Action_SkillUp(); //BtSequence skillUp = new BtSequence(c_skillUp); //skillUp.AddChild(a_skillUp); //skillUp.name = "升级中"; //Condi_CheckTransmit c_checkTransmit = new Condi_CheckTransmit(); //Action_Transmit a_trans = new Action_Transmit(); //BtSequence transmit = new BtSequence(c_checkTransmit); //transmit.AddChild(a_trans); //transmit.name = "瞬间传送"; // Elude skill Condi_CheckSendSkill_ c_checkSkill = new Condi_CheckSendSkill_(); Action_EludePos_ a_eludePos = new Action_EludePos_(); BtSequence eludeSkill = new BtSequence(c_checkSkill); eludeSkill.AddChild(a_eludePos); eludeSkill.name = "躲技能"; // find buff Condi_FindMapBuff_ c_find = new Condi_FindMapBuff_(); Action_MoveToBuff_ a_move = new Action_MoveToBuff_(); BtSequence findBuff = new BtSequence(c_find); findBuff.AddChild(a_move); findBuff.name = "寻找中"; // fight AICondi[] c_fight = new AICondi[3]; c_fight[0] = new Condi_FindTarget(); // 先通过仇恨,位置获取目标 c_fight[1] = new Condi_CheckState(); // 再检查自身施法条件是否满足 c_fight[2] = new Condi_SelectSkill(); Condi_List findTarget = new Condi_List(c_fight); // fight action BtSequence fight = new BtSequence(findTarget); Action_MoveToTarget a_fight_move = new Action_MoveToTarget(); Action_SendSkill_ a_fight_send = new Action_SendSkill_(); fight.AddChild(a_fight_move); fight.AddChild(a_fight_send); fight.name = "战斗中"; // chase Condi_CheckChase c_chase = new Condi_CheckChase(); Action_Chase a_chase = new Action_Chase(); BtSequence chase = new BtSequence(c_chase); chase.AddChild(a_chase); chase.name = "追逐"; //Condi_CheckFollow c_checkFollow = new Condi_CheckFollow(); //Action_Follow a_follow = new Action_Follow(); //BtSequence follow = new BtSequence(c_checkFollow); //follow.AddChild(a_follow); //follow.name = "跟随"; // patrol Action_Patrol patrol = new Action_Patrol(); patrol.name = "巡逻中"; //if (creature.IsPartner()) //{ // m_tree.m_root.AddChild(transmit); //} //if (creature.IsMaster()) //{ // m_tree.m_root.AddChild(findBuff); //} m_tree.m_root.AddChild(fight); //m_tree.m_root.AddChild(chase); //if (creature.IsPartner()) //{ // m_tree.m_root.AddChild(follow); //} m_tree.m_root.AddChild(patrol); m_tree.OnStart(); }
public override bool Check() { return(AIParam.RandomSelectSkill(m_creature, m_dataBase)); }