public EBTStatus SelectNearestRoute() { if (Singleton <BattleLogic> .GetInstance() == null || BattleLogic.instance.mapLogic == null) { return(EBTStatus.BT_FAILURE); } CUtilList <WaypointsHolder> waypointsList = BattleLogic.instance.mapLogic.GetWaypointsList(m_wrapper.actor.pCharMeta.ActorCamp); if (waypointsList == null || waypointsList.Count == 0) { return(EBTStatus.BT_FAILURE); } long num = long.MaxValue; WaypointsHolder waypointsHolder = null; for (int i = 0; i < waypointsList.Count; i++) { VecInt3 vInt = new VecInt3(waypointsList[i].startPoint.transform.position); long sqrMagnitudeLong2D = (m_wrapper.actorLocation - vInt).sqrMagnitudeLong2D; if (sqrMagnitudeLong2D < num) { waypointsHolder = waypointsList[i]; num = sqrMagnitudeLong2D; } } if (waypointsHolder == null) { return(EBTStatus.BT_FAILURE); } m_wrapper.m_curWaypointsHolder = waypointsHolder; m_wrapper.m_curWaypointTarget = m_wrapper.m_curWaypointsHolder.startPoint; m_wrapper.m_curWaypointTargetPosition = new VecInt3(m_wrapper.m_curWaypointTarget.transform.position); return(EBTStatus.BT_SUCCESS); }
public bool IsDistanceToPosInRange(Vector3 aimPos, int range) { VecInt3 vInt = new VecInt3(aimPos); long num = (long)range; return((m_wrapper.actorLocation - vInt).sqrMagnitudeLong2D < num * num); }
private void LoadModel(string file) { viewer.Clear(); curPath = file; BlockData.Model model = ModelSerializer.LoadModel(file); VecInt3 offset = new VecInt3(viewer.GetPivot().x - model.pivotX, viewer.GetPivot().y - model.pivotY, viewer.GetPivot().z - model.pivotZ); int index = 0; for (int i = 0; i < model.blocks.Count; i++) { short blockType = (short)model.blocks[i].type; for (int j = 0; j < model.blocks[i].lenght; j++) { int y = index % model.sizeY; int x = (index / model.sizeY) % model.sizeX; int z = index / (model.sizeX * model.sizeY); viewer.blockManager.setBlock(x + offset.x, y + offset.y, z + offset.z, blockType); index++; } } viewer.SetDirty(); commandManager.Clear(); }
public static void SaveModel(Block.BlockManager bm, VecInt3 pivot, string path) { //Block.BoundsInt bounds = new Block.BoundsInt(); //bm.forEachChunk((Block.BlockChunk chunk, int cx, int cy, int cz) => { // if (!chunk.isEmpty()) { // for (int z = 0; z < Block.Const.ChunkSize; z++) { // for (int x = 0; x < Block.Const.ChunkSize; x++) { // for (int y = 0; y < Block.Const.ChunkSize; y++) { // int gx = cx * Block.Const.ChunkSize + x; // int gy = cy * Block.Const.ChunkSize + y; // int gz = cz * Block.Const.ChunkSize + z; // short blockType = bm.getBlock(gx, gy, gz); // if (bm.blockTypeFun.isOpacity(blockType)) { // bounds.Encapsulate(new Block.VecInt3(gx, gy, gz)); // } // } // } // } // } //}); //if (bounds.IsValid()) { // BlockData.Model model = new BlockData.Model(); // model.version = 0; // model.sizeX = bounds.Size.x; // model.sizeY = bounds.Size.y; // model.sizeZ = bounds.Size.z; // model.pivotX = pivot.x - bounds.min.x; // model.pivotY = pivot.y - bounds.min.y; // model.pivotZ = pivot.z - bounds.min.z; // // int num = 0; // short lastType = bm.getBlock(bounds.min.x, bounds.min.y, bounds.min.z); // for (int z = bounds.min.z; z <= bounds.max.z; z++) { // for (int x = bounds.min.z; x <= bounds.max.x; x++) { // for (int y = bounds.min.y; y <= bounds.max.y; y++) { // short curType = bm.getBlock(x, y, z); // if (lastType == curType) { // num++; // } // else { // BlockData.BlockPair block = new BlockData.BlockPair(); // block.lenght = num; // block.type = lastType; // model.blocks.Add(block); // lastType = curType; // num = 1; // } // } // } // } // BlockData.BlockPair blockLast = new BlockData.BlockPair(); // blockLast.lenght = num; // blockLast.type = lastType; // model.blocks.Add(blockLast); // Write<BlockData.Model>(model, path); //} }
public static bool isOnBlock(Block.BlockManager bm, Vector3 pos) { VecInt3 bpos = getBlockPos(pos - Vector3.up * 0.1f); short block = bm.getBlock(bpos.x, bpos.y, bpos.z); if (bm.blockTypeFun.isCollider(block)) { return(true); } return(false); }
public Vector3 GetRestoredHpPos() { Vector3 result = Vector3.zero; VecInt3 zero = VecInt3.zero; VecInt3 forward = VecInt3.forward; if (BattleLogic.instance.mapLogic.GetRevivePosDir(ref m_wrapper.actor.pCharMeta, true, out zero, out forward)) { result = (Vector3)zero; } return(result); }
public void ClearRange(VecInt3 min, VecInt3 size) { for (int i = 0; i < size.x; i++) { for (int j = 0; j < size.y; j++) { for (int k = 0; k < size.z; k++) { model[i, j, k] = false; } } } }
public void FillRange(VecInt3 min, VecInt3 size) { for (int i = 0; i < size.x; i++) { for (int j = 0; j < size.y; j++) { for (int k = 0; k < size.z; k++) { model[min.x + i, min.y + j, min.z + k] = true; } } } }
static float GetDistanceToGround(RayCastManager scene, Vector3 pos, int height) { VecInt3 g = pos; Vector3 localPos = pos - g; if (scene.isWalkable(g.x, g.y - 1, g.z, height)) { return(1 + localPos.y); } else if (scene.isWalkable(g.x, g.y, g.z, height)) { return(localPos.y); } else if (!scene.isWalkable(g.x, g.y, g.z, height)) { return(localPos.y - 1); } return(1); }
public virtual void LookAtDirection(Vector3 dest) { //if (dest == Vector3.zero) //{ // return; //} //VecInt3 inDirection = new VecInt3(dest); //m_wrapper.actor.pMoveCtrl.SetRotate(inDirection, true); VecInt3 vInt = new VecInt3(dest); if (vInt != VecInt3.zero) { int num = (int)((double)(IntMath.atan2(-vInt.z, vInt.x).single * 180f) / 3.1416); DebugHelper.Assert(num <32767 && num> -32768, "WARN: num < 32767 && num > -32768"); InputModel.instance.SendMoveDirection(num); InputModel.instance.SendStopMove(null, false); } }
public virtual void RequestMoveToActor(uint objID) { // RealMoveToActor(objID); // return; CharHandle_t actor = GameCharMgr.instance.GetActor(objID); if (!actor) { return; } VecInt3 dest2 = actor.handle.location; if (m_lastDest != dest2) { m_lastDest = dest2; //VecInt3 vInt = dest2 - m_wrapper.actor.location; //if (vInt != VecInt3.zero) //{ // int num = (int)((double)(IntMath.atan2(-vInt.z, vInt.x).single * 180f) / 3.1416); // DebugHelper.Assert(num < 32767 && num > -32768, "WARN: num < 32767 && num > -32768"); // int num2 = num - InputModel.instance.PreMoveDirection; // if (num2 > 1 || num2 < -1 || InputModel.instance.FixtimeDirSndFrame > 30) // { // InputModel.instance.SendMoveDirection(num); // } //} FrameCommand <MoveToPosCommand> frameCommand = FrameCommandFactory.CreateFrameCommand <MoveToPosCommand>(); MGFrameCommand <MoveToPosCommand> final = SmartReferencePool.instance.Fetch <MGFrameCommand <MoveToPosCommand> >(); Player ownerPlayer = CharHelper.GetOwnerPlayer(ref m_wrapper.actorPtr); frameCommand.playerID = ownerPlayer.PlayerId; frameCommand.cmdData.destPosition = dest2; final.SetFrameCommand(ref frameCommand); final.playerID = ownerPlayer.PlayerId; GameDefine.BattleNetHandler.WriteMsg(final); } }
public void RequestMovePosition(Vector3 dest) { // RealMovePosition(dest); // return; // // UnityEngine.Debug.Log(".................." + dest VecInt3 dest2 = new VecInt3(dest); if (m_lastDest != dest2 || m_wrapper.myBehavior != eObjBehavMode.Destination_Move) { m_lastDest = dest2; //VecInt3 vInt = dest2 - m_wrapper.actor.location; //if (vInt != VecInt3.zero) //{ // int num = (int)((double)(IntMath.atan2(-vInt.z, vInt.x).single * 180f) / 3.1416); // DebugHelper.Assert(num < 32767 && num > -32768, "WARN: num < 32767 && num > -32768"); // int num2 = num - InputModel.instance.PreMoveDirection; // if (num2 > 1 || num2 < -1 || InputModel.instance.FixtimeDirSndFrame > 30) // { // InputModel.instance.SendMoveDirection(num); // } //} FrameCommand <MoveToPosCommand> frameCommand = FrameCommandFactory.CreateFrameCommand <MoveToPosCommand>(); MGFrameCommand <MoveToPosCommand> final = SmartReferencePool.instance.Fetch <MGFrameCommand <MoveToPosCommand> >(); Player ownerPlayer = CharHelper.GetOwnerPlayer(ref m_wrapper.actorPtr); frameCommand.playerID = ownerPlayer.PlayerId; frameCommand.cmdData.destPosition = dest2; final.SetFrameCommand(ref frameCommand); final.playerID = ownerPlayer.PlayerId; GameDefine.BattleNetHandler.WriteMsg(final); } }
static Vector3 GetNearestWalkablePos(RayCastManager scene, Vector3 pos, int height) { float r = 0.3f; VecInt3 g = pos; Vector3 localPos = pos - g; VecInt3 step;//移动的方向,-1,0,1 step.x = localPos.x < r ? -1 : (localPos.x > (1 - r) ? 1 : 0); step.z = localPos.z < r ? -1 : (localPos.z > (1 - r) ? 1 : 0); Vector3 offset;//退回到正确的位置需要移动的量 offset.x = step.x == -1 ? r - localPos.x : (step.x == 1 ? ((1 - r) - localPos.x) : 0); offset.z = step.z == -1 ? r - localPos.z : (step.z == 1 ? ((1 - r) - localPos.z) : 0); bool bCanMoveX = step.x != 0 ? scene.isWalkable(g.x + step.x, g.y, g.z, height) : true; bool bCanMoveZ = step.z != 0 ? scene.isWalkable(g.x, g.y, g.z + step.z, height) : true; bool bCanMoveXZ = (step.x != 0 && step.z != 0) ? scene.isWalkable(g.x + step.x, g.y, g.z + step.z, height) : true; bool bCanUpX = scene.isWalkable(g.x + step.x, g.y + 1, g.z, height); bool bCanUpZ = scene.isWalkable(g.x, g.y + 1, g.z + step.z, height); bool bCanUpXZ = scene.isWalkable(g.x + step.x, g.y + 1, g.z + step.z, height); bCanMoveX |= bCanUpX; bCanMoveZ |= bCanUpZ; bCanMoveXZ |= bCanUpXZ; if (!bCanMoveXZ && bCanMoveX && bCanMoveZ) { if (Mathf.Abs(offset.x) < Mathf.Abs(offset.z)) { bCanMoveX = false; } else { bCanMoveZ = false; } } if (!bCanMoveX) { pos.x += offset.x; } if (!bCanMoveZ) { pos.z += offset.z; } //if ((!bCanMoveX) || (!bCanMoveZ)) { // bool bCanStepUp = scene.testBlock(g.x + step.x, g.y + 1, g.z + step.z, RayCastBlockType.Walkable); // if (bCanStepUp) { // pos.y = g.y + 1; // } // else { // // } //} return(pos); }
static bool IsWalkable(RayCastManager scene, Vector3 pos, int height) { VecInt3 g = pos; return(scene.isWalkable(g.x, g.y, g.z, height)); }
public HouseItem(VecInt3 pos, GameItemType item) { this.pos = pos; this.item = item; }