CalcDistancSquareToTarget() public method

public CalcDistancSquareToTarget ( ) : float
return float
コード例 #1
0
        private void MoveNpc(EntityInfo obj, long deltaTime)
        {
            if (obj.HaveState(CharacterPropertyEnum.x3002_昏睡) ||
                obj.HaveState(CharacterPropertyEnum.x3001_眩晕))
            {
                return;
            }
            MovementStateInfo msi = obj.GetMovementStateInfo();

            //npc执行移动时忽略阻挡与避让,这些行为由ai模块在规划其路径时执行。
            if (!obj.IsDead() && obj.CanMove && msi.IsMoving)
            {
                ScriptRuntime.Vector3 pos = msi.GetPosition3D();
                float speed               = (float)obj.ActualProperty.GetFloat(CharacterPropertyEnum.x2011_最终速度);
                float distance            = (speed * (float)(int)deltaTime) / 1000.0f;
                ScriptRuntime.Vector3 dir = msi.TargetDir;

                //LogSystem.Debug("MovementSystem npc:{0} speed:{1} deltaTime:{2} distance:{3}", obj.GetId(), speed, deltaTime, distance);

                float x = 0, y = 0;
                if (msi.CalcDistancSquareToTarget() < distance * distance)
                {
                    x = msi.TargetPosition.X;
                    y = msi.TargetPosition.Z;
                    ScriptRuntime.Vector2 newPos = new ScriptRuntime.Vector2(x, y);
                    msi.SetPosition2D(newPos);
                    msi.IsMoving = false;
                }
                else
                {
                    ScriptRuntime.Vector3 tpos = pos + dir * distance;
                    msi.SetPosition(tpos);
                }
            }
        }
 static public int CalcDistancSquareToTarget(IntPtr l)
 {
     try {
         GameFramework.MovementStateInfo self = (GameFramework.MovementStateInfo)checkSelf(l);
         var ret = self.CalcDistancSquareToTarget();
         pushValue(l, true);
         pushValue(l, ret);
         return(2);
     }
     catch (Exception e) {
         return(error(l, e));
     }
 }
コード例 #3
0
        private void MoveNpc(EntityInfo obj, long deltaTime)
        {
            if (obj.IsHaveStateFlag(CharacterState_Type.CST_Sleep) ||
                obj.IsHaveStateFlag(CharacterState_Type.CST_FixedPosition))
            {
                return;
            }
            MovementStateInfo msi = obj.GetMovementStateInfo();

            //npc执行移动时忽略阻挡与避让,这些行为由ai模块在规划其路径时执行。
            if (!obj.IsDead() && obj.CanMove && msi.IsMoving && !msi.IsSkillMoving)
            {
                ScriptRuntime.Vector3 pos = msi.GetPosition3D();
                float speed               = (float)obj.GetActualProperty().MoveSpeed;
                float distance            = (speed * (float)(int)deltaTime) / 1000.0f;
                ScriptRuntime.Vector3 dir = msi.TargetDir;

                //LogSystem.Debug("MovementSystem npc:{0} speed:{1} deltaTime:{2} distance:{3}", obj.GetId(), speed, deltaTime, distance);

                float x = 0, y = 0;
                if (msi.CalcDistancSquareToTarget() < distance * distance)
                {
                    x = msi.TargetPosition.X;
                    y = msi.TargetPosition.Z;
                    ScriptRuntime.Vector2 newPos = new ScriptRuntime.Vector2(x, y);
                    msi.SetPosition2D(newPos);

                    msi.IsMoving = false;
                    User user = obj.CustomData as User;
                    if (null != user)
                    {
                        Msg_RC_NpcMove npcMoveBuilder = DataSyncUtility.BuildNpcMoveMessage(obj);
                        if (null != npcMoveBuilder)
                        {
                            Scene scene = user.OwnRoom.ActiveScene;
                            if (null != scene)
                            {
                                scene.NotifyAllUser(RoomMessageDefine.Msg_RC_NpcMove, npcMoveBuilder);
                            }
                        }
                    }
                }
                else
                {
                    ScriptRuntime.Vector3 tpos = pos + dir * distance;
                    msi.SetPosition(tpos);
                }
            }
        }