Exemplo n.º 1
0
 public static void DisposeObstacle(SceneObstacle obstacle)
 {
     if (!mWaitingPathToFind.IsAddingCompleted)
     {
         mWaitingPathToFind.Add(() => { obstacle.Close(); });
     }
 }
Exemplo n.º 2
0
        public bool Init(SceneManager _this)
        {
            _this.ScenesDic = new Dictionary <int, Dictionary <int, Dictionary <ulong, Scene> > >();

            Table.ForeachSceneNpc(record =>
            {
                var sceneId = record.SceneID;
                List <SceneNpcRecord> tempList;
                if (!SceneManager.SceneNpcs.TryGetValue(sceneId, out tempList))
                {
                    tempList = new List <SceneNpcRecord>();
                    SceneManager.SceneNpcs.Add(sceneId, tempList);
                }
                tempList.Add(record);
                return(true);
            });

            Table.ForeachMapTransfer(record =>
            {
                var sceneId = record.SceneID;
                List <MapTransferRecord> tempList;
                if (!SceneManager.SceneMapNpcs.TryGetValue(sceneId, out tempList))
                {
                    tempList = new List <MapTransferRecord>();
                    SceneManager.SceneMapNpcs.Add(sceneId, tempList);
                }
                tempList.Add(record);
                return(true);
            });

#if DEBUG
            string str;
            Table.ForeachScene(table =>
            {
                str          = "../Scene/" + table.ResName + ".path";
                var obstacle = new SceneObstacle(str);
                obstacle.GetObstacleValue(0, 0);
                return(true);
            });
#endif

            _this.minLevel  = int.Parse(Table.GetServerConfig(450).Value);
            _this.maxExpMul = int.Parse(Table.GetServerConfig(451).Value);
            _this.minDev    = int.Parse(Table.GetServerConfig(452).Value);
            _this.maxDev    = int.Parse(Table.GetServerConfig(453).Value);

            EventSystem.EventDispatcher.Instance.AddEventListener(ReloadTableEvent.EVENT_TYPE, evt =>
            {
                if ((evt as ReloadTableEvent).tableName == "ServerConfig")
                {
                    _this.minLevel  = int.Parse(Table.GetServerConfig(450).Value);
                    _this.maxExpMul = int.Parse(Table.GetServerConfig(451).Value);
                    _this.minDev    = int.Parse(Table.GetServerConfig(452).Value);
                    _this.maxDev    = int.Parse(Table.GetServerConfig(453).Value);
                }
            });

            return(true);
        }
Exemplo n.º 3
0
        public static bool RemoveCollider(SceneObstacle obstacle, uint id)
        {
            if (!mWaitingPathToFind.IsAddingCompleted)
            {
                mWaitingPathToFind.Add(() => { obstacle.RemoveCollider(id); });
            }

            return(true);
        }
Exemplo n.º 4
0
        public static bool FindPath(Coroutine co,
                                    SceneObstacle obstacle,
                                    ObjCharacter obj,
                                    Vector2 start,
                                    Vector2 end,
                                    AsyncReturnValue <List <Vector2> > result)
        {
            if (mWaitingPathToFind.Count > 100)
            {
                if (obj.GetObjType() == ObjType.NPC)
                {
                    var npc = obj as ObjNPC;
                    if (npc.CurrentState != BehaviorState.Combat)
                    {
                        result.Value = SceneObstacle.EmptyPath;
                        if (!SceneServer.Instance.ServerControl.mWaitingEvents.IsAddingCompleted)
                        {
                            SceneServer.Instance.ServerControl.mWaitingEvents.Add(new ContinueEvent(co));
                        }

                        return(false);
                    }
                }
            }

            if (!mWaitingPathToFind.IsAddingCompleted)
            {
                mWaitingPathToFind.Add(() =>
                {
                    var path     = obstacle.FindPath(start, end);
                    result.Value = path;

                    if (path.Count == 0)
                    {
                        // Count为0时,我们认为start点是无效的
                        // 当前点的格子中心点是有效的。。存在无效的可能??
                        var ValidStart = new Vector2(((int)(start.X * 2)) / 2.0f, ((int)(start.Y * 2)) / 2.0f);

                        path         = obstacle.FindPath(ValidStart, end);
                        result.Value = path;
                    }

                    if (!SceneServer.Instance.ServerControl.mWaitingEvents.IsAddingCompleted)
                    {
                        SceneServer.Instance.ServerControl.mWaitingEvents.Add(new ContinueEvent(co));
                    }
                });
            }

            return(true);
        }
Exemplo n.º 5
0
        public static bool AddCollider(Coroutine co,
                                       SceneObstacle obstacle,
                                       ObjCharacter obj,
                                       float radius,
                                       AsyncReturnValue <uint> result)
        {
            if (!mWaitingPathToFind.IsAddingCompleted)
            {
                mWaitingPathToFind.Add(() =>
                {
                    var b        = obstacle.AddCollider(obj.GetPosition(), radius);
                    result.Value = b;

                    if (!SceneServer.Instance.ServerControl.mWaitingEvents.IsAddingCompleted)
                    {
                        SceneServer.Instance.ServerControl.mWaitingEvents.Add(new ContinueEvent(co));
                    }
                });
            }

            return(true);
        }
Exemplo n.º 6
0
        public static bool Raycast(Coroutine co,
                                   SceneObstacle obstacle,
                                   ObjCharacter obj,
                                   Vector2 start,
                                   Vector2 end,
                                   AsyncReturnValue <Vector2> result)
        {
            if (!mWaitingPathToFind.IsAddingCompleted)
            {
                mWaitingPathToFind.Add(() =>
                {
                    Vector2 hit;
                    var b        = obstacle.Raycast(start, end, out hit);
                    result.Value = hit;

                    if (!SceneServer.Instance.ServerControl.mWaitingEvents.IsAddingCompleted)
                    {
                        SceneServer.Instance.ServerControl.mWaitingEvents.Add(new ContinueEvent(co));
                    }
                });
            }

            return(true);
        }