package com.heishi.ai.move;
import java.util.ArrayDeque;
import java.util.Deque;
import org.slf4j.Logger;
import com.heishi.ai.astar.PathSplit;
import com.heishi.ai.formula.DistanceFormula;
import com.heishi.bean.hero.Hero;
import com.heishi.bean.sprite.Sprite;
import com.heishi.commons.logs.LoggerProvider;
import com.heishi.commons.message.ServerResponse;
import com.heishi.consts.ClientConfig;
import com.heishi.game.map.response.sprite.SpriteJumpMsg400010;
import com.heishi.game.map.response.sprite.SpriteMoveMsg400008;
/**
* 移动控制器基类
*
* @author zss
*/
public class MoveController implements IMoveController {
private static final Logger logger = LoggerProvider.getLogger(MoveController.class);
private Sprite vo;
/*** 制造连续行走的路径储存空间(路径有可能被切割) ***/
private Deque<MoveInfo> pathQueue = new ArrayDeque<MoveInfo>();
/*** 当前移动方式 **/
private int moveType;
/**** 存放精灵当前行走线路 格式为 x1,y1,x2,y2,x3,y3.....即偶数为x坐标 奇数为y坐标 **/
private short[] lines;
/** 计时器,开始走walklines时的时间 **/
private long beginTime = 0;
/** 是否允许移动 **/
private boolean enableMove = true;
/**** 当前的路径位置(行走专用) **/
private int pathIndex = 0;
/**** 已经计算出来的距离 **/
private float realDistance = 0;
/***跳跃专用的属性 上一次跳跃结束的时间 **/
private long previousJumpEndTime = 0;
/*** 持续跳跃次数 **/
int continueJumpcount = 0;
public short[] getLines() {
return lines;
}
public void destory() {
if (pathQueue != null) {
pathQueue.clear();
pathQueue = null;
}
vo=null;
lines = null;
}
@Override
public boolean isEnableMove() {
return enableMove;
}
/**
* 客户端保证所有移动都停止后,才开始的攻击,也就是攻击时角色所在的点,一定等于路径中的最后一点 因此遇到攻击消息时,服务器判定路径差距,如果不是太大
* 就直接停止移动,更新为路径的最后点,否则不处理,等待之后的位置矫正
*/
public void checkToStopTailPoint() {
if (isMoving()) {
// 获得最后点
short lastx = 0;
short lasty = 0;
if (pathQueue.size() > 0) {
MoveInfo last = pathQueue.getLast();
short[] lastpath = last.path;
lastx = lastpath[lastpath.length - 2];
lasty = lastpath[lastpath.length - 1];
} else {
lastx = lines[lines.length - 2];
lasty = lines[lines.length - 1];
}
if (vo.getGridDistance(lastx, lasty) < 10) {
vo.setX(lastx);
vo.setY(lasty);
vo.getEyeShotManager().onMove();
stopMove();
} else {
// 不处理,等待之后的位置矫正
}
}
}
@Override
public void setEnableMove(boolean enable) {
this.enableMove = enable;
if (!enableMove) {
stopMove();
}
}
public MoveController(Sprite vo) {
this.vo = vo;
}
@Override
public long getPreviousJumpEndTime() {
return previousJumpEndTime;
}
private boolean isTailPoint(short startX, short startY, short[] path) {
return startX == path[path.length - 2]
&& startY == path[path.length - 1];
}
@Override
public void addWalkLines(short[] gopath) {
continueJumpcount = 0;
if (vo.isPlayer()) {
Hero hero = (Hero) vo;
hero.getFollowMeController().onMyselfWalk(gopath);
}
short startX = gopath[0];
short startY = gopath[1];
if (pathQueue.size() > 0) {
short[] pathInQueue = pathQueue.getLast().path;
if (isTailPoint(startX, startY, pathInQueue)) {
PathSplit.splitPathToQueue(pathQueue, gopath);
return;
}
for (int i = 0; i < pathInQueue.length; i += 2) {
if (pathInQueue[i] == startX && pathInQueue[i + 1] == startY) {
pathQueue.removeLast();
if (i > 0) {
short[] newpath = new short[i + 2];
System.arraycopy(pathInQueue, 0, newpath, 0,newpath.length);
pathQueue.add(MoveInfo.createWalkPath(newpath));
}
PathSplit.splitPathToQueue(pathQueue,gopath);
return;
}
}
for (int i = 0; i < pathInQueue.length; i+= 2) {
if (Math.abs(startX - pathInQueue[i]) <= 1&& Math.abs(startY - pathInQueue[i + 1]) <= 1) {
pathQueue.removeLast();
if (i > 0) {
short[] newpath = new short[i + 2];
System.arraycopy(pathInQueue, 0, newpath, 0,
newpath.length);
pathQueue.add(MoveInfo.createWalkPath(newpath));
}
PathSplit.splitPathToQueue(pathQueue, gopath);
return;
}
}
} else {
//如果是 正好首尾相接
if (isTailPoint(startX, startY, lines)) {
PathSplit.splitPathToQueue(pathQueue,gopath);
return;
}
for (int i = 0; i < lines.length; i += 2) {//
if (startX == lines[i] && startY == lines[i + 1]) {
if (i > 0) {
short[] newpath = new short[i + 2];
System.arraycopy(lines, 0, newpath, 0, newpath.length);
PathSplit.splitPathToQueue(pathQueue, gopath);
lines = newpath;
if (pathIndex >= lines.length) {
pathIndex = lines.length - 2;
}
} else {
internalSetMoveline(MoveInfo.createWalkPath(gopath));
}
return;
}
}
for (int i = 0; i < lines.length; i += 2) {
if (Math.abs(startX - lines[i]) <= 1
&& Math.abs(startY - lines[i + 1]) <= 1) {
if (i > 0) {
short[] newpath = new short[i + 2];
System.arraycopy(lines, 0, newpath, 0, newpath.length);
PathSplit.splitPathToQueue(pathQueue, gopath);
lines = newpath;
if (pathIndex >= lines.length) {
pathIndex = lines.length - 2;
}
} else {
internalSetMoveline(MoveInfo.createWalkPath(gopath));
}
return;
}
}
}
}
@Override
public void setJumpLines(short[] gopath, boolean is2jitiao, long begintime) {
if (gopath.length == 4) {// 跳跃必须是4个点
stopMove();
internalSetMoveline(MoveInfo.createJumpPath(gopath, is2jitiao));
if (vo.isPlayer()) {
Hero hero = (Hero) vo;
hero.getFollowMeController().onMyslefJump(gopath);
}
this.beginTime = begintime;
this.previousJumpEndTime = begintime;
}
}
public String toString(){
StringBuilder builder=new StringBuilder();
if (moveType == MoveInfo.TYPE_WALK) {
if(isMoving())
{
for(short temp:lines)
{
builder.append(temp+"-");
}
for(MoveInfo info:pathQueue)
{
for(short temp:info.path)
{
builder.append(temp+"-");
}
}
}
return builder.toString();
} else {
if(isMoving())
{
for(short temp:lines)
{
builder.append(temp+"-");
}
}
return builder.toString();
}
}
public void setWalkLines(short[] gopath, long begintime) {
continueJumpcount = 0;
stopMove();
if (gopath != null && gopath.length > 3) {
if (vo.isPlayer()) {
Hero hero = (Hero) vo;
hero.getFollowMeController().onMyselfWalk(gopath);
}
// 目标点
if (gopath.length > PathSplit.MAXPATHPOINT) {
PathSplit.splitPathToQueue(pathQueue, gopath);
getNextPathSplit();
} else {
internalSetMoveline(MoveInfo.createWalkPath(gopath));
}
this.beginTime = begintime;
}
}
@Override
public boolean checkArrived() {
return moveByTime();
}
// 获得下一个路径分断
private void getNextPathSplit() {
MoveInfo mi = pathQueue.poll();
if (mi != null) {
internalSetMoveline(mi);
} else {
lines = null;
moveType = MoveInfo.TYPE_STAND;
}
}
private void internalSetMoveline(MoveInfo mi) {
lines = mi.path;
moveType = mi.moveType;
pathIndex = 0;
realDistance = 0;
if (moveType == MoveInfo.TYPE_JUMP || moveType == MoveInfo.TYPE_JUMP2) {
vo.setLocation(Location.Location_KONG);
} else {
vo.setLocation(Location.Location_DI);
}
vo.setX(lines[0]);
vo.setY(lines[1]);
broadMovePath(mi);
}
@Override
public void stopMove() {
// if (moveType == MoveInfo.TYPE_WALK) {
// lines = null;
//// moveType = MoveInfo.TYPE_STAND;
// }
lines=null;
moveType = MoveInfo.TYPE_STAND;
pathQueue.clear();
}
没有合适的资源?快使用搜索试试~ 我知道了~
行为树的具体例子
共611个文件
svn-base:200个
class:178个
java:162个
需积分: 48 22 下载量 176 浏览量
2019-04-27
16:32:56
上传
评论
收藏 937KB RAR 举报
温馨提示
另一个行为树的具体例子实现,可解码运行,虽然简单但功能俱全
资源详情
资源评论
资源推荐
收起资源包目录
行为树的具体例子 (611个子文件)
all-wcprops 4KB
all-wcprops 4KB
all-wcprops 2KB
all-wcprops 2KB
all-wcprops 2KB
all-wcprops 2KB
all-wcprops 2KB
all-wcprops 2KB
all-wcprops 2KB
all-wcprops 2KB
all-wcprops 1KB
all-wcprops 1KB
all-wcprops 1KB
all-wcprops 1KB
all-wcprops 850B
all-wcprops 850B
all-wcprops 765B
all-wcprops 765B
all-wcprops 714B
all-wcprops 714B
all-wcprops 649B
all-wcprops 649B
all-wcprops 647B
all-wcprops 647B
all-wcprops 442B
all-wcprops 442B
all-wcprops 140B
all-wcprops 140B
all-wcprops 131B
all-wcprops 131B
all-wcprops 124B
all-wcprops 124B
BaseEyeShotManager.class 12KB
IdleState.class 12KB
MoveController.class 10KB
FollowMeControllerImp.class 9KB
MonsterStateMachine.class 7KB
AStarNewArithmetic.class 7KB
FightPetStateMachine.class 7KB
TreeConfigContext.class 6KB
Agent.class 6KB
HeroAttackState.class 6KB
SceneEffectEyeshortManager.class 6KB
GameXml.class 6KB
IdleState$Interval.class 6KB
Agent.class 5KB
Agent.class 5KB
Game.class 5KB
Test.class 5KB
FightPetState.class 5KB
DataContext.class 5KB
AttackState.class 5KB
HeroStateMachine.class 5KB
XMLConfigReader.class 5KB
ISPursuitState.class 5KB
HeroIdleState.class 5KB
HeroEyeShotManager.class 4KB
PursuitState.class 4KB
FightPetIdleState.class 4KB
AbstractNode.class 4KB
FightPetEyeShotManager.class 4KB
JiTuiState.class 4KB
HeroJiTuiState.class 4KB
AbstractNode.class 4KB
FightPetIsPursuitState.class 4KB
FightPetIsPickUpState.class 4KB
Point.class 3KB
FightPetAttackState.class 3KB
MonsterState.class 3KB
FightPetPursuitState.class 3KB
DisposeState.class 3KB
FightPetPickUpState.class 3KB
FightPetDieState.class 3KB
PatrolState.class 3KB
ISResetState.class 3KB
ConditionPrototype.class 3KB
FollwerState.class 3KB
HeroMoveState.class 3KB
FightPetFollwerState.class 3KB
HeroJumpState.class 2KB
FightPetISResetState.class 2KB
EscapeState.class 2KB
HeroState.class 2KB
Node.class 2KB
FollwerStateMachine.class 2KB
HeroJumpAttackState.class 2KB
SkillShowResponse10286.class 2KB
StateMachineImpl.class 2KB
PathSplit.class 2KB
StepPrototype.class 2KB
HeroDaZuoState.class 2KB
ISEscapeState.class 2KB
HiddenWeaponSkillMsg52000.class 2KB
ActionNode.class 2KB
FightPetResetState.class 2KB
BehaviorPrototype.class 2KB
Hunter.class 2KB
ResetState.class 2KB
DieState.class 2KB
HeroDieState.class 2KB
共 611 条
- 1
- 2
- 3
- 4
- 5
- 6
- 7
weixin_42684102
- 粉丝: 0
- 资源: 3
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- 基于Python实现的自动化办公项目.zip
- 基于python实现的基于PyQt5和爬虫的小说阅读系统.zip
- 机械设计整经机上纱自动化sw20非常好的设计图纸100%好用.zip
- Screenshot_20240427_031602.jpg
- 网页PDF_2024年04月26日 23-46-14_QQ浏览器网页保存_QQ浏览器转格式(6).docx
- 直接插入排序,冒泡排序,直接选择排序.zip
- 在排序2的基础上,再次对快排进行优化,其次增加快排非递归,归并排序,归并排序非递归版.zip
- 实现了7种排序算法.三种复杂度排序.三种nlogn复杂度排序(堆排序,归并排序,快速排序)一种线性复杂度的排序.zip
- 冒泡排序 直接选择排序 直接插入排序 随机快速排序 归并排序 堆排序.zip
- 课设-内部排序算法比较 包括冒泡排序、直接插入排序、简单选择排序、快速排序、希尔排序、归并排序和堆排序.zip
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
评论0