protected override void Init() { base.Init(); root = new BTPrioritySelector(); // 根节点首先是一个选择器 // 转移条件 MonsterCheckPlayerInRange playerInRange = new MonsterCheckPlayerInRange(checkPlayerRange, PLAYER_NAME); MonsterCheckPlayerInRange playerNotInRange = new MonsterCheckPlayerInRange(checkPlayerRange, PLAYER_NAME, true); // 行为节点 move = new MonsterMove(DESTINATION, moveSpeed); MonsterFindToTargetDestination findToTargetDestination = new MonsterFindToTargetDestination(PLAYER_NAME, PLAYERLOCATION, DESTINATION, ATKdistance); MonsterWait monsterWait = new MonsterWait(); // 怪兽攻击 MonsterAttack monsterAttack; if (myMonsterType == MonsterType.LongDistanceAttack) { monsterAttack = new MonsterLongDistanceAttacks(longDistanceATK); } else if (myMonsterType == MonsterType.MeleeAttack) { monsterAttack = new MonsterMeleeAttack(meleeATK); } else { monsterAttack = new MonsterAttack(meleeATK); // 先暂时为近战的攻击力 } MonsterRandomMoveDistance randomMoveDistance = new MonsterRandomMoveDistance(DESTINATION, moveX, moveZ); MonsterRotateToTarget monsterMoveRotate = new MonsterRotateToTarget(DESTINATION); MonsterRotateToTarget attackRotate = new MonsterRotateToTarget(PLAYERLOCATION); // 攻击 BTSequence attack = new BTSequence(playerInRange); { BTParallel parallel = new BTParallel(BTParallel.ParallelFunction.Or); { parallel.AddChild(findToTargetDestination); // 先找到走到攻击目标的目的地 BTSequence rotateAndMove = new BTSequence(); { rotateAndMove.AddChild(monsterMoveRotate); rotateAndMove.AddChild(move); } parallel.AddChild(rotateAndMove); // 怪物朝着目的地移动 } attack.AddChild(parallel); attack.AddChild(attackRotate); // 怪物朝向玩家 attack.AddChild(monsterAttack); // 进行攻击 } root.AddChild(attack); // 随机巡逻 BTSequence randomMove = new BTSequence(playerNotInRange); { randomMove.AddChild(monsterWait); // 怪物静止几秒 BTParallel parallel = new BTParallel(BTParallel.ParallelFunction.And); { parallel.AddChild(randomMoveDistance); // 随机找一个移动地点 BTSequence rotateAndMove = new BTSequence(); { rotateAndMove.AddChild(monsterMoveRotate); rotateAndMove.AddChild(move); } parallel.AddChild(rotateAndMove); // 怪物朝着目的地移动 } randomMove.AddChild(parallel); } root.AddChild(randomMove); }
protected override void Init() { base.Init(); root = new BTPrioritySelector(); // 根节点首先是一个选择器 // 转移条件 // 远程攻击条件 MonsterCheckPlayerInRangeAndRandomAttack longAttack = new MonsterCheckPlayerInRangeAndRandomAttack(checkPlayerRange, PLAYER_NAME, true); // 进程攻击条件 MonsterCheckPlayerInRangeAndRandomAttack meleeAttack = new MonsterCheckPlayerInRangeAndRandomAttack(checkPlayerRange, PLAYER_NAME, false); // 静止条件 MonsterCheckPlayerInRange playerNotInRange = new MonsterCheckPlayerInRange(checkPlayerRange, PLAYER_NAME, true); // 行为节点 move = new MonsterMove(DESTINATION, moveSpeed); MonsterFindToTargetDestination findMeleeToTargetDestination = new MonsterFindToTargetDestination(PLAYER_NAME, PLAYERLOCATION, DESTINATION, ATKMeleeDistance); MonsterFindToTargetDestination findLongToTargetDestination = new MonsterFindToTargetDestination(PLAYER_NAME, PLAYERLOCATION, DESTINATION, ATKLongDistance); MonsterWait monsterWait = new MonsterWait(); MonsterLongDistanceAttacks monsterLongDistanceAttacks = new MonsterLongDistanceAttacks(longDistanceATK); MonsterMeleeAttack monsterMeleeAttack = new MonsterMeleeAttack(meleeATK); MonsterRotateToTarget monsterMoveRotate = new MonsterRotateToTarget(DESTINATION); MonsterRotateToTarget attackRotate = new MonsterRotateToTarget(PLAYERLOCATION); MonsterRandomMoveDistance randomMoveDistance = new MonsterRandomMoveDistance(DESTINATION, moveX, moveZ); // 随机巡逻(玩家不在攻击范围) BTSequence randomMove = new BTSequence(playerNotInRange); { BTParallel parallel = new BTParallel(BTParallel.ParallelFunction.And); { parallel.AddChild(randomMoveDistance); // 随机找一个移动地点 BTSequence rotateAndMove = new BTSequence(); { rotateAndMove.AddChild(monsterMoveRotate); rotateAndMove.AddChild(move); } parallel.AddChild(rotateAndMove); // 怪物朝着目的地移动 } randomMove.AddChild(parallel); } root.AddChild(randomMove); // 进程攻击(一个随机数并且玩家在攻击范围内) BTSequence meleeattack = new BTSequence(meleeAttack); { BTParallel parallel = new BTParallel(BTParallel.ParallelFunction.Or); { parallel.AddChild(findMeleeToTargetDestination); // 先找到走到攻击目标的目的地 BTSequence rotateAndMove = new BTSequence(); { rotateAndMove.AddChild(monsterMoveRotate); rotateAndMove.AddChild(move); } parallel.AddChild(rotateAndMove); // 怪物朝着目的地移动 } meleeattack.AddChild(parallel); meleeattack.AddChild(attackRotate); // 怪物朝向玩家 meleeattack.AddChild(monsterMeleeAttack); // 进行攻击 } root.AddChild(meleeattack); // 远程攻击(一个随机数并且玩家在攻击范围内) BTSequence longattack = new BTSequence(longAttack); { BTParallel parallel = new BTParallel(BTParallel.ParallelFunction.Or); { parallel.AddChild(findLongToTargetDestination); // 先找到走到攻击目标的目的地 BTSequence rotateAndMove = new BTSequence(); { rotateAndMove.AddChild(monsterMoveRotate); rotateAndMove.AddChild(move); } parallel.AddChild(rotateAndMove); // 怪物朝着目的地移动 } longattack.AddChild(parallel); longattack.AddChild(attackRotate); // 怪物朝向玩家 longattack.AddChild(monsterLongDistanceAttacks); // 进行攻击 } root.AddChild(longattack); }