private void P_OnObserve(int obj)
 {
     if (GameObjectsManager.GetObject(obj, out GameObject go))
     {
         PacketsSender.SpawnGameObject(this, go);
     }
 }
Beispiel #2
0
        public static void Destroy(GameObject g)
        {
            GameObjectsManager.RemoveObject(g.ObjectId);

            if (MapsManager.GetMap(g.mapId, out Map m))
            {
                m.RemovePlayer(g.ObjectId);
            }
        }
        private void Update()
        {
            while (true)
            {
                Thread.Sleep(100);

                foreach (var item in GameObjectsManager.GetObjectsList())
                {
                    item.Update();
                }

                OnUpdate();
            }
        }
Beispiel #4
0
        public static T Instantiate <T>(int x, int y, SpawnsManager.SpawnData data = null) where T : GameObject, new()
        {
            T g = new T();

            GameObjectsManager.AddObject(g);
            g.SetPosition(x, y);
            if (data != null)
            {
                g.SetData(data);
            }

            g.Init();
            return(g);
        }
        public override void Update()
        {
            base.Update();

            if (TargetId != -1)
            {
                if (stats[Stat.HEALTH] > 0 && Time.time > lastAttackTime + 1)
                {
                    if (GameObjectsManager.GetObject(TargetId, out Character target))
                    {
                        target.DealDamage(this, stats[Stat.DAMAGE]);
                        lastAttackTime = Time.time;
                    }
                }
            }
        }
        protected override void OnClose(CloseEventArgs e)
        {
            Console.WriteLine("Player Disconnected " + e.Reason);
            GameObjectsManager.GetObject <Player>(ObjectRefId, out Player p);

            MongoCRUD c = new MongoCRUD("bridge-mmo");

            c.UpdateCharacter(Player);

            p.OnObserve     -= P_OnObserve;
            p.OnUnobserve   -= P_OnUnobserve;
            p.OnStatChanged -= P_OnStatChanged;

            GameObject.Destroy(p);

            UsersManager.RemoveUser(ObjectRefId);
        }
        private void ReadMessage(int msgId, dynamic obj)
        {
            switch (msgId)
            {
            case 0:
                int x = (int)obj.x;
                int y = (int)obj.y;

                JObject pck = new JObject();
                pck["msgId"] = 2;
                pck["id"]    = ObjectRefId;
                pck["x"]     = x;
                pck["y"]     = y;

                var p = Player;
                p.posX = x;
                p.posY = y;

                foreach (var item in UsersManager.GetUsers(Player.Observed))
                {
                    item.Value.Send(pck.ToString());
                }

                Send(pck.ToString());
                break;

            case 1:
                if (GameObjectsManager.GetObject((int)obj.id, out GameObject go))
                {
                    go.Click(this);
                }
                break;

            case 2:
                if (ObjectRefId == -1)
                {
                    EnterGame((string)obj.hash);
                }
                break;
            }
        }
Beispiel #8
0
        private void Instance_OnUpdate()
        {
            HashSet <int> itemsToRemove = new HashSet <int>();

            foreach (var item in objectsToRespawn)
            {
                if (item.Value.respawnTime < Time.time)
                {
                    GameObjectsManager.AddObject(item.Value.id, item.Value.go);
                    if (MapsManager.GetMap(item.Value.go.mapId, out Map m))
                    {
                        m.AddPlayer(item.Value.id);
                    }

                    item.Value.Respawn();
                    itemsToRemove.Add(item.Value.id);
                }
            }

            foreach (var item in itemsToRemove)
            {
                objectsToRespawn.Remove(item);
            }
        }