Ejemplo n.º 1
0
        public ObjNPC CreateNpc(Scene _this, SceneNpcRecord sceneNpcRecord, int dataId, Vector2 pos, Vector2 dir, string name = "", int level = -1)
        {
            if (Math.Abs(pos.X + 1) < 0.0001f && Math.Abs(pos.Y + 1) < 0.0001f)
            {
                return(null);
            }
            if (dataId != 999 && dataId != 998)
            {
                if (!_this.ValidPosition(pos))
                {
                    Logger.Warn("Npc postion is invalid. DataId={0},pos={1},scene={2}", dataId, pos, _this.TypeId);

                    var temp = _this.FindNearestValidPosition(pos, 10);
                    if (null != temp)
                    {
                        pos = temp.Value;
                    }
                    else
                    {
                        Logger.Error("null==FindNearestValidPosition. DataId={0},pos={1},scene={2}", dataId, pos, _this.TypeId);
                        return(null);
                    }
                }
            }

            var npc = new ObjNPC();

            npc.tbSceneNpc = sceneNpcRecord;
            npc.Init(_this.GenerateNextId(), dataId, level);
            npc.mBornTime = DateTime.Now;

            if (!string.IsNullOrEmpty(name))
            {
                npc.SetName(name);
            }
            //if (level > 0)840824

            //{
            //    npc.SetLevel(level);
            //}

            npc.SetPosition(pos.X, pos.Y);
            npc.SetDirection(dir);
            npc.BornPosition  = pos;
            npc.BornDirection = dir;
            _this.EnterScene(npc);
            return(npc);
        }