コード例 #1
0
 private void P_OnObserve(int obj)
 {
     if (GameObjectsManager.GetObject(obj, out GameObject go))
     {
         PacketsSender.SpawnGameObject(this, go);
     }
 }
コード例 #2
0
        public void EnterGame(string hash)
        {
            Console.WriteLine("Enter game: " + hash);
            MongoCRUD c = new MongoCRUD("bridge-mmo");

            var client   = new MongoClient(MongoCRUD.connString);
            var database = client.GetDatabase("bridge-mmo");
            var col      = database.GetCollection <dynamic>("sessions");
            var filter   = Builders <dynamic> .Filter.Eq("session_hash", hash);

            var sessionData = col.Find(filter).First();
            var accountId   = sessionData._id;

            DbCharacter data = c.GetRecordByAccountId <DbCharacter>("characters", accountId);

            if (data == null)
            {
                var newId = c.Increment <dynamic>("counters", "characters");
                int id    = newId.seq + 1;

                data = new DbCharacter()
                {
                    accountId = accountId,
                    id        = id,
                    lvl       = 1,
                    nickname  = "newacc"
                };

                c.InsertRecord <DbCharacter>("characters", data);
            }

            var DatabaseId = data.id;

            Player p = GameObject.Instantiate <Player>(data.x, data.y);

            p.DatabaseId      = DatabaseId;
            ObjectRefId       = p.ObjectId;
            p.mapId           = data.mapId;
            p.stats[Stat.LVL] = data.lvl;
            p.stats[Stat.EXP] = data.exp;

            if (MapsManager.GetMap(data.mapId, out Map m))
            {
                m.AddPlayer(ObjectRefId);
            }

            p.OnObserve     += P_OnObserve;
            p.OnUnobserve   += P_OnUnobserve;
            p.OnStatChanged += P_OnStatChanged;
            p.OnSlotChanged += P_OnSlotChanged;

            PacketsSender.SpawnGameObject(this, p);

            JObject pck2 = new JObject();

            pck2["msgId"] = 3;
            pck2["id"]    = ObjectRefId;
            pck2["mapId"] = data.mapId;
            pck2["lvl"]   = data.lvl;
            pck2["exp"]   = data.exp;

            Send(pck2.ToString());

            UsersManager.AddUser(ObjectRefId, this);

            List <DbUniqueItem> inventory = c.GetCharacterItems <DbUniqueItem>(DatabaseId);

            p.SetItems(inventory);

            PacketsSender.SendItems(this, inventory);
        }