private void P_OnObserve(int obj) { if (GameObjectsManager.GetObject(obj, out GameObject go)) { PacketsSender.SpawnGameObject(this, go); } }
private void P_OnSlotChanged(int arg1, DbUniqueItem arg2) { PacketsSender.SendItems(this, new List <DbUniqueItem>() { arg2 }); }
public void SetStat(Stat stat, int val, bool sync) { stats[stat] = val; OnStatChanged(stat, val); if (sync) { UpdateObservedObjects(); foreach (var item in UsersManager.GetUsers(Observed)) { PacketsSender.SetStat(item.Value, ObjectId, stat, val); } } }
public void TeleportToMap(int newMapId, int posX, int posY) { MapsManager.GetMap(mapId, out Map oldMap); oldMap.RemovePlayer(ObjectId); UsersManager.GetUser(ObjectId, out User user); mapId = newMapId; MapsManager.GetMap(mapId, out Map newMap); newMap.AddPlayer(ObjectId); this.posX = posX; this.posY = posY; PacketsSender.TeleportToMap(user, newMapId, posX, posY); }
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); }
private void P_OnUnobserve(int obj) { PacketsSender.DespawnGameObject(this, obj); }
private void P_OnStatChanged(Stat arg1, int arg2) { PacketsSender.SetStat(this, ObjectRefId, arg1, arg2); }