public DatabaseHelper(IEnumerable <string> lines) { _databaseNames = new HashSet <string>(); foreach (var line in lines) { if (line == "End") { return; } var tempentry = new DatabaseEntry(this); var acsessor = new DatabaseEntry.DatabaseEntryAcessor(tempentry); string[] pairs = line.Split(LineSplitter, StringSplitOptions.RemoveEmptyEntries); tempentry.Name = DecodeIfRequied(pairs[0]); if (!_databaseNames.Add(tempentry.Name)) { continue; } _entrys.Add(tempentry); var data = acsessor.MetadataAcc; foreach (var pair in pairs.Skip(1)) { string[] pairValue = pair.Split(MetaSplitter, StringSplitOptions.RemoveEmptyEntries); var meta = new Metadata(this) { Key = DecodeIfRequied(pairValue[0]) }; if (pairValue.Length == 2) { meta.Value = DecodeIfRequied(pairValue[1]); } if (acsessor.MetaNames.Add(meta.Key)) { data.Add(meta); } } } }
private void setRandom(AuthPlayer player) { switch (this.rnd.Next(5)) { default: { player.PlayerObject.Set("crap" + this.rnd.Next(5), this.rnd.Next(100000)); return; } case 1: { player.PlayerObject.Set("crap" + this.rnd.Next(5), "String " + this.rnd.Next(100000)); return; } case 2: { player.PlayerObject.Set("crap" + this.rnd.Next(5), this.rnd.Next(1) == 0); return; } case 3: { player.PlayerObject.Set("crap" + this.rnd.Next(5), this.rnd.NextDouble()); return; } case 4: { var tst = new DatabaseArray(); for (var i = 0; i < this.rnd.Next(50); i++) { tst.Add(this.rnd.Next()); } player.PlayerObject.Set("crap" + this.rnd.Next(5), tst); return; } } }
public static List <World.Block> FromJsonArray(this JObject world) { var array = world["worlddata"].Values().AsJEnumerable(); var temp = new DatabaseArray(); foreach (var block in array) { var dbo = new DatabaseObject(); foreach (var token in block) { var property = (JProperty)token; var value = property.Value; switch (value.Type) { case JTokenType.Integer: dbo.Set(property.Name, (uint)value); break; case JTokenType.Boolean: dbo.Set(property.Name, (bool)value); break; case JTokenType.Float: dbo.Set(property.Name, (double)value); break; default: dbo.Set(property.Name, (string)value); break; } } temp.Add(dbo); } return(FromWorldData(temp)); }
private void createPreviewObjects() { Console.WriteLine("Objects of same type were deleted."); int currentObjectSize = 0; int currentPartID = 1; var currentObject = new DatabaseObject(); var currentFramesSet = new DatabaseArray(); foreach (byte[] arr in outGoingSnapshots) { Console.WriteLine("Obj size: " + arr.Length); currentObjectSize += arr.Length; currentFramesSet.Add(arr); if (currentObjectSize > 400000) //start new preview part if currentObject size is > 400kb (Playerio obj limmit size is 500kb) { fillObject(currentObject, currentFramesSet); gamelink.PlayerIO.BigDB.CreateObject("Previews", spellName + "_part_" + currentPartID, currentObject, onObjCreated); currentObject = new DatabaseObject(); currentFramesSet = new DatabaseArray(); currentPartID++; currentObjectSize = 0; } } if (currentFramesSet.Count > 0) //create last object { fillObject(currentObject, currentFramesSet); gamelink.PlayerIO.BigDB.CreateObject("Previews", spellName + "_part_" + currentPartID, currentObject, onObjCreated); } Console.WriteLine("Will write obhects with total size: " + outGoingSnapshots); }
public override void resolve(Player player, string[] commandInput) { var lastreport = player.lastreport; if (lastreport.AddSeconds(90) > DateTime.Now) { Console.WriteLine("Spamming. Not saved. " + lastreport + " vs " + DateTime.Now); player.Send("info", "Report submitted", "Thank you for your report, we'll look into it shortly."); return; } if (commandInput.Length < 3) { player.Send("info", "Report", "Please specify a playername and a reason for this report"); return; } var reportedUserName = commandInput[1].Trim().ToLower(); var existingReport = this._game.GetLocalCopyOfReport(reportedUserName); if (existingReport != null) { if (existingReport.GetDateTime("Date").AddSeconds(90) > DateTime.Now) { Console.WriteLine("Existing report found. Not saved"); //if (existingReport.GetString("ReportedByUsername", "") == player.name) //{ player.Send("info", "Report submitted", "Thank you for your report, we'll look into it shortly."); return; //} } } this._game.PlayerIO.BigDB.Load("usernames", reportedUserName, delegate(DatabaseObject o) { if (o == null || o.GetString("owner", null) == null) { player.Send("write", this._game.SystemName, "User " + reportedUserName.ToUpper() + " not found"); return; } var reportedUserConnectId = o.GetString("owner"); // if theres a reason var reason = ""; for (var a = 2; a < commandInput.Length; a++) { reason += commandInput[a] + " "; } // get current chat texts var chatMessages = this._game.GetLastChatMessages(); var messages = new StringBuilder(); foreach (var message in chatMessages) { if (message != null) { messages.Append("name: " + message.name + ": " + message.text + " | "); } } var signsList = this._game.BaseWorld.GetBrickTextSignList(); var signtextArray = new DatabaseArray(); foreach (var sign in signsList) { signtextArray.Add(sign.text); } var chattextArray = new DatabaseArray(); foreach (var message in chatMessages) { chattextArray.Add(message.name + ": " + message.text); } var report = new DatabaseObject(); report.Set("ReportedByUsername", player.name); report.Set("ReportedByConnectId", player.ConnectUserId); report.Set("State", "Open"); report.Set("Date", DateTime.Now); report.Set("WorldId", this._game.BaseWorld.key); report.Set("WorldName", this._game.BaseWorld.name); report.Set("Reason", reason); report.Set("Signs", signtextArray); report.Set("ChatLog", chattextArray); report.Set("ReportedUsername", reportedUserName); report.Set("ReportedUserConnectId", reportedUserConnectId); this._game.SaveLocalCopyOfReport(report); player.lastreport = DateTime.Now; this._game.PlayerIO.BigDB.CreateObject("AbuseReports", null, report, delegate { player.Send("info", "Report submitted", "Thank you for your report, we'll look into it shortly."); }, delegate { player.lastreport = DateTime.Now.AddHours(-1); player.Send("info", "Error occured", "An error occured in while submitting. Please try again."); }); }); }
public override void GotMessage(FBPlayer player, Message m) { switch (m.Type) { case MessageID.FB_INVITED_USERS: player.RefreshPlayerObject(delegate() { DatabaseArray invited = player.PlayerObject.GetArray("FBInvites"); if (invited == null) { player.PlayerObject.Set("FBInvites", new DatabaseArray()); invited = player.PlayerObject.GetArray("FBInvites"); } int count = m.GetInt(0); string[] keys = new string[count]; int keyCount = 0; for (uint i = 0; i < count; i++) { string id = m.GetString(i + 1); bool found = false; for (int j = 0; j < invited.Count; j++) { if (id == invited.GetString(j)) { found = true; break; } } if (!found) { //invited.Add(id); keys[keyCount++] = id; } } /*for (int j = 0; j < invited.Count; j++) { * keys[j] = invited.GetString(j); * }*/ // remove already playing players PlayerIO.BigDB.LoadKeys("PlayerObjects", keys, delegate(DatabaseObject[] arr) { foreach (DatabaseObject dbo in arr) { if (dbo != null) { for (int j = count - 1; j >= 0; j--) { if ("fb" + keys[j] == dbo.Key) { //invited.RemoveAt(j); keys[j] = null; } } } } for (int i = 0; i < count; i++) { if (keys[i] != null) { invited.Add(keys[i]); } } player.PlayerObject.Save(); }); }); break; } }
// This method is called when a player sends a message into the server code public override void GotMessage(Player player, Message message) { switch (message.Type) { // player has moved up, down, left, or right case "move": { //Console.WriteLine("Player position before move: " + player.positionX + ", " + player.positionY); //debug int messageX = message.GetInt(0); int messageY = message.GetInt(1); player.positionX = player.positionX + messageX; player.positionY = player.positionY + messageY; //Console.WriteLine("Player " + player.Id + " is moving to (" + player.positionX + ", " + player.positionY + ")"); //debug Broadcast("PlayerMove", player.Id, messageX, messageY); break; } case "LoadPlayers": { // this is how you broadcast a messa"LoadPlayers": //Update them on who is already in the game foreach (Player x in players) { if (x != null && x != player) { //Console.WriteLine("Sending Player " + player.Id + " Player " + x.Id + " Position (" + x.positionX + ", " + x.positionY + ")"); //debug player.Send("UserJoined", x.Id, x.positionX, x.positionY, x.ConnectUserId); } } break; } //Load the coins, randomize them if they dont exist case "LoadCoins": { Random random = new Random(); if (Coins == null) { DatabaseArray coins = new DatabaseArray(); for (int i = 0; i < 5; i++) { DatabaseObject coin = new DatabaseObject(); int randomX = random.Next(0, 9); int randomY = random.Next(0, 9); coin.Set("xTile", randomX); coin.Set("yTile", randomY); coin.Set("Uses", 0); player.Send("coinSetup", randomX, randomY, 0); coins.Set(i, coin); } Coins = coins; quest.Set("Coins", Coins); quest.Save(); } else { for (int i = 0; i < 5; i++) { DatabaseObject coin = Coins.GetObject(i); player.Send("coinSetup", coin.GetInt("xTile"), coin.GetInt("yTile"), coin.GetInt("Uses")); } } break; } // client is asking for data about player to draw on the screen case "playerInfo": { if (players[player.Id - 1] == null) { player.Send("noSuchPlayer"); } else { player.Send("playerInfo", players[player.Id - 1].positionX, players[player.Id - 1].positionY, playerConnectUserId, player.characterClass); } break; } case "MapTileChanged": { int xTile = message.GetInt(0); int yTile = message.GetInt(1); int newTileType = message.GetInt(2); //Console.WriteLine("Map Tile Change From Player " + player.Id + " (" + xTile + "," + yTile + ") to type: " + newTileType); Broadcast("MapTileChanged", player.Id, xTile, yTile, newTileType); break; } // update server's variables for this player stat case "updateStat": { String statType = message.GetString(0); switch (statType) { case "AP": player.AP = message.GetInt(1); //Console.WriteLine("server: player's AP changed! " + player.AP); break; case "lumber": amountLumber = message.GetInt(1); //Console.WriteLine("server: player's lumber changed! " + amountLumber); break; case "cherry": amountCherry = message.GetInt(1); //Console.WriteLine("server: player's cherry changed! " + amountCherry); break; } break; } case "win": { PlayerIO.BigDB.Load(mapType, levelKey, delegate(DatabaseObject result) { // todo: change these based on what you got in the level int gainedxp = 0; // = result.GetInt("XP"); int gainedcoin = 0; // = result.GetInt("Coin"); if (result != null) { gainedxp = result.GetInt("XP", 0); //How much XP the Level was worth gainedcoin = result.GetInt("Coin", 0); //How mucg coin the level was worth } String nextLevel = ""; //Check to see if player completed Tutorial level, in which case update their tutorial value if (player.PlayerObject.GetInt("tutorial") == 1) { DatabaseArray abilities = new DatabaseArray(); abilities.Add("Crafter_Bridge"); player.PlayerObject.Set("abilities", abilities); player.PlayerObject.Set("tutorial", 2); nextLevel = "Tutorial_2"; } else if (player.PlayerObject.GetInt("tutorial") == 2) { DatabaseArray abilities = player.PlayerObject.GetArray("abilities"); abilities.Add("Planter_RedFlower"); player.PlayerObject.Set("tutorial", 3); nextLevel = "Tutorial_3"; } else if (player.PlayerObject.GetInt("tutorial") == 3) { player.PlayerObject.Set("tutorial", 4); nextLevel = "Tutorial_4"; } else if (player.PlayerObject.GetInt("tutorial") == 4) { DatabaseArray abilities = player.PlayerObject.GetArray("abilities"); abilities.Add("Cook_MonsterBacon"); player.PlayerObject.Set("tutorial", 5); nextLevel = "Tutorial_5"; } else if (player.PlayerObject.GetInt("tutorial") == 5) { nextLevel = "Class_Choose"; player.PlayerObject.Set("tutorial", 6); } int experience = player.PlayerObject.GetInt("xp"); /*int level = player.PlayerObject.GetInt("level"); * * * //Check to see if the player has enough XP to level up * if (experience + gainedxp >= levelXP(level + 1)) * { * player.PlayerObject.Set("level", level + 1); * }*/ player.PlayerObject.Set("xp", experience + gainedxp); player.PlayerObject.Set("coin", player.PlayerObject.GetInt("coin", 0) + gainedcoin); player.PlayerObject.Save(delegate() { // quest is finished; remove this quest from the table // todo: what happens if another player is playing this quest? PlayerIO.BigDB.DeleteKeys("NewQuests", questID); //Console.WriteLine("deleted newquest key"); PlayerIO.BigDB.Load("PlayerObjects", player.ConnectUserId, delegate(DatabaseObject thisPlayer) { thisPlayer.Set("questID", "noQuest"); thisPlayer.Save(delegate() { Broadcast("win", gainedxp, gainedcoin, nextLevel); }); } ); }); }, delegate(PlayerIOError error) { //Console.WriteLine(error.ToString()); }); break; } // recieves one string that is the newly updated map; save to associated quest object case "QuestMapUpdate": { questMap = message.GetString(0); player.GetPlayerObject( delegate(DatabaseObject updatedPlayerObject){ PlayerIO.BigDB.Load("NewQuests", questID, delegate(DatabaseObject dbo) { dbo.Set("tileValues", message.GetString(0)); dbo.Save(); }); }); break; } case "MonsterAPChange": { int newAp = message.GetInt(0); int monsterIndex = message.GetInt(1); PlayerIO.BigDB.Load("newQuests", questID, delegate(DatabaseObject dbo) { DatabaseArray monsters = dbo.GetArray("Monsters"); monsters.GetObject(monsterIndex).Set("AP", newAp); dbo.Save(); }); Broadcast("MonsterAPChange", player.Id, newAp, monsterIndex); break; } case "SpriteMove": { String type = message.GetString(0); int newXTile = message.GetInt(1); int newYTile = message.GetInt(2); int monsterIndex = message.GetInt(3); PlayerIO.BigDB.Load("newQuests", questID, delegate(DatabaseObject dbo) { DatabaseArray sprites = dbo.GetArray(type); DatabaseObject sprite = sprites.GetObject(monsterIndex); sprite.Set("xTile", newXTile); sprite.Set("yTile", newYTile); dbo.Save(); }); break; } case "AddSprite": { String type = message.GetString(0); int xTile = message.GetInt(1); int yTile = message.GetInt(2); String name = message.GetString(3); int range = message.GetInt(4); DatabaseObject newSprite = new DatabaseObject(); newSprite.Set("xTile", xTile); newSprite.Set("yTile", yTile); newSprite.Set("Type", name); newSprite.Set("Uses", 0); newSprite.Set("Range", range); Broadcast("AddSprite", xTile, yTile, name, range); PlayerIO.BigDB.Load("newQuests", questID, delegate(DatabaseObject dbo) { if (dbo.Contains(type)) { DatabaseArray sprites = dbo.GetArray(type); sprites.Add(newSprite); } else { DatabaseArray sprites = new DatabaseArray(); sprites.Add(newSprite); dbo.Set(type, sprites); } dbo.Save(); }); break; } case "SpriteUse": { int index = message.GetInt(0); int uses = message.GetInt(1); //Console.WriteLine("Sprite " + index + " Is being used for the " + uses + " time"); Broadcast("SpriteUse", player.Id, index); PlayerIO.BigDB.Load("newQuests", questID, delegate(DatabaseObject dbo) { DatabaseArray sprites = dbo.GetArray("Effects"); DatabaseObject sprite = sprites.GetObject(index); sprite.Set("Uses", uses); dbo.Save(); }); break; } case "CoinUse": { int index = message.GetInt(0); int uses = message.GetInt(1); Broadcast("CoinUse", player.Id, index); PlayerIO.BigDB.Load("newQuests", questID, delegate(DatabaseObject dbo) { DatabaseArray sprites = dbo.GetArray("Coins"); DatabaseObject sprite = sprites.GetObject(index); Coins.GetObject(index).Set("Uses", uses); sprite.Set("Uses", uses); dbo.Save(); }); break; } } }
// This method is called whenever a player joins the game public override void UserJoined(Player player) { // this is how you send a player a message //Send the player their player Number. playerConnectUserId = player.ConnectUserId; if (numPlayers < players.Length) { players[numPlayers] = player; //Console.WriteLine("New Player " + player.Id); numPlayers++; // if player is not attached to a quest, give them a new quest ID PlayerIO.BigDB.Load("PlayerObjects", player.ConnectUserId, delegate(DatabaseObject result) { player.characterClass = result.GetString("role", "Novice"); player.costume = result.GetString("costume", "novice"); player.tutorialLevel = result.GetInt("tutorial", 1); //Console.WriteLine("player class: " + player.characterClass); if (questID != null && (!result.Contains("questID") || result.GetString("questID") == "noQuest")) { result.Set("questID", questID); result.Save(); PlayerIO.BigDB.Load("NewQuests", questID, delegate(DatabaseObject quest) { this.quest = quest; DatabaseObject questPlayerData = new DatabaseObject(); player.positionX = startX; player.positionY = startY; questPlayerData.Set("positionX", startX); questPlayerData.Set("positionY", startY); questPlayerData.Set("AP", 20); quest.GetObject("players").Set(player.ConnectUserId, questPlayerData); quest.GetObject("players").Set("numPlayers", quest.GetObject("players").Count - 1); quest.Save(delegate() { player.Send("init", player.Id, player.ConnectUserId, startX, startY, questID, 20, levelKey, "", player.characterClass); }); Broadcast("UserJoined", player.Id, player.positionX, player.positionY); }); } // if player does not have a questID associated with it // create new object in Quests db else if (!result.Contains("questID") || result.GetString("questID") == "noQuest") { // create new quest object DatabaseObject newQuest = new DatabaseObject(); // create array for players playing this new quest object DatabaseObject questPlayers = new DatabaseObject(); // create new object for this player and their quest data DatabaseObject questPlayerData = new DatabaseObject(); //Console.WriteLine("questPlayers contents: " + questPlayers.ToString()); //Console.WriteLine("Level key: " + levelKey); //Add Static Map to Quest, to be updated later PlayerIO.BigDB.Load(mapType, levelKey, delegate(DatabaseObject staticMap) { player.positionX = startX = staticMap.GetInt("startX", 0); player.positionY = startY = staticMap.GetInt("startY", 0); questPlayerData.Set("positionX", startX); questPlayerData.Set("positionY", startY); questPlayerData.Set("AP", 20); // add this player to players playing this quest questPlayers.Set("numPlayers", 1); questPlayers.Set(player.ConnectUserId, questPlayerData); newQuest.Set("players", questPlayers); newQuest.Set("StaticMapKey", staticMap.Key); newQuest.Set("tileValues", staticMap.GetString("tileValues")); newQuest.Set("MonsterCount", staticMap.GetInt("MonsterCount")); if (staticMap.Contains("Monsters")) { DatabaseArray monsters = staticMap.GetArray("Monsters"); DatabaseArray newMonsters = new DatabaseArray(); for (int i = 1; i <= monsters.Count; i++) { DatabaseObject monster = new DatabaseObject(); monster.Set("Type", monsters.GetObject(i - 1).GetString("Type")); monster.Set("xTile", monsters.GetObject(i - 1).GetInt("xTile")); monster.Set("yTile", monsters.GetObject(i - 1).GetInt("yTile")); monster.Set("AP", monsters.GetObject(i - 1).GetInt("AP")); newMonsters.Add(monster); } newQuest.Set("Monsters", newMonsters); } if (staticMap.Contains("Buttons")) { DatabaseArray buttons = staticMap.GetArray("Buttons"); DatabaseArray newButtons = new DatabaseArray(); for (int i = 1; i <= buttons.Count; i++) { DatabaseObject button = new DatabaseObject(); button.Set("xTile", buttons.GetObject(i - 1).GetInt("xTile")); button.Set("yTile", buttons.GetObject(i - 1).GetInt("yTile")); button.Set("xOpen", buttons.GetObject(i - 1).GetInt("xOpen")); button.Set("yOpen", buttons.GetObject(i - 1).GetInt("yOpen")); newButtons.Add(button); } newQuest.Set("Buttons", newButtons); } Console.WriteLine("Setting up new quest " + newQuest.ToString()); // add this quest object to Quests db PlayerIO.BigDB.CreateObject("NewQuests", null, newQuest, delegate(DatabaseObject addedQuest) { questID = addedQuest.Key; addedQuest.Set("RoomID", this.RoomId); Console.WriteLine("made new questID! new questID is: " + questID); result.Set("questID", addedQuest.Key); result.Save(); //levelKey = addedQuest.Key; // tell client to initialize (board, monsters, player object & player sprite) with max AP amount addedQuest.Save(delegate() { quest = addedQuest; player.Send("init", player.Id, player.ConnectUserId, startX, startY, questID, 20, levelKey, "", player.costume); }); Broadcast("UserJoined", player.Id, player.positionX, player.positionY); }); }); // save positions in the serverside player.AP = 20; } // else, this player has a questID saved else { questID = result.GetString("questID"); //levelKey = questID; // obtain player's last position and save to serverside PlayerIO.BigDB.Load("NewQuests", questID, delegate(DatabaseObject questObject) { quest = questObject; questObject.Set("RoomID", this.RoomId); questObject.Save(); Coins = questObject.GetArray("Coins"); String resources = ""; // player's resources, to pass to client if (questObject != null) { levelKey = questObject.GetString("StaticMapKey"); // extract players playing this quest DatabaseObject playersInQuest = questObject.GetObject("players"); DatabaseObject thisPlayer = playersInQuest.GetObject(player.ConnectUserId); player.positionX = thisPlayer.GetInt("positionX"); player.positionY = thisPlayer.GetInt("positionY"); int startAP = thisPlayer.GetInt("AP"); if (thisPlayer.Contains("lastSessionEndTime")) { // figure out how much AP player should have based on how long they've been away lastSessionEndTime = thisPlayer.GetDateTime("lastSessionEndTime"); //Console.WriteLine("last session end time : " + lastSessionEndTime.ToString(DateTimeFormat)); int minutesPassedSinceLastPlay = (startSessionTime - lastSessionEndTime).Minutes; startAP += minutesPassedSinceLastPlay / 3; //Console.WriteLine("minutes passed: " + minutesPassedSinceLastPlay + ", amount of AP to add: " + (minutesPassedSinceLastPlay / 3) + ", starting AP: " + startAP); if (startAP > 20) { startAP = 20; } player.AP = startAP; } else { player.AP = 20; } // get information about player resources from db if (thisPlayer.Contains("resources")) { DatabaseObject resourcesObject = thisPlayer.GetObject("resources"); Console.WriteLine("resources object: " + resourcesObject.ToString()); if (resourcesObject.Contains("lumber")) { amountLumber = resourcesObject.GetInt("lumber"); resources += "Lumber:" + amountLumber; } if (resourcesObject.Contains("cherry")) { amountCherry = resourcesObject.GetInt("cherry"); resources += "/Cherry:" + amountCherry; } Console.WriteLine("resources string: " + resources); } } // tell client to initialize (board, monsters, player object & player sprite) player.Send("init", player.Id, player.ConnectUserId, player.positionX, player.positionY, questID, player.AP, levelKey, resources, player.costume); Broadcast("UserJoined", player.Id, player.positionX, player.positionY); } ); } } ); } else { player.Send("full"); } Console.WriteLine("userJoined is done"); }
public void save(Callback callback) { if (this.dbo != null) { var bricks = this.getBrickList(0); bricks.AddRange(this.getBrickList(1)); var worlddata = new DatabaseArray(); foreach (var b in bricks) { var cb = new DatabaseObject(); var i = b.xs.Count; var xs = new byte[i * 2]; var ys = new byte[i * 2]; for (var a = 0; a < i; a++) { xs[a * 2] = (byte)((b.xs[a] & 65280U) >> 8); xs[a * 2 + 1] = (byte)(b.xs[a] & 255U); ys[a * 2] = (byte)((b.ys[a] & 65280U) >> 8); ys[a * 2 + 1] = (byte)(b.ys[a] & 255U); } cb.Set("type", b.type); cb.Set("layer", b.layer); cb.Set("x", xs); cb.Set("y", ys); var type = b.type; if (type <= 77U) { if (type != 43U) { if (type == 77U) { cb.Set("id", b.id); } } else { cb.Set("goal", b.goal); } } else if (type != 83U) { if (type != 242U) { if (type == 1000U) { cb.Set("text", b.text); } } else { cb.Set("rotation", b.rotation); cb.Set("id", b.id); cb.Set("target", b.target); } } else { cb.Set("id", b.id); } worlddata.Add(cb); } this.dbo.Set("worlddata", worlddata); if (this.dbo.Contains("world")) { this.dbo.Remove("world"); } this.dbo.Save(callback); } }
public void Save(string roomId, World world) { var dbo = this.campaignPlayer; var effects = new DatabaseArray(); foreach (var effect in this.player.GetEffects()) { // If it's timed effect we can assume it expired and simply reset player's position to checkpoint if (effect.CanExpire) { this.player.Checkpoint = world.GetBrickType(0, this.player.Checkpoint.X, this.player.Checkpoint.Y) == (uint)ItemTypes.Checkpoint ? this.player.Checkpoint : world.GetSpawn(); this.player.X = this.player.Checkpoint.X * 16; this.player.Y = this.player.Checkpoint.Y * 16; this.player.SpeedX = 0; this.player.SpeedY = 0; this.player.Deaths += 1; } else { var effectObject = new DatabaseObject().Set("Id", (int)effect.Id); if (effect.Id == EffectId.Multijump) { effectObject.Set("Arg", effect.Duration); } else if (effect.Id == EffectId.Gravity) { effectObject.Set("Arg", effect.Duration); } effects.Add(effectObject); } } var goldCoins = this.GetPositionsArray(this.player.Coinmap.Where(it => it.Block.Type == 100).ToList()); var blueCoins = this.GetPositionsArray(this.player.Coinmap.Where(it => it.Block.Type == 101).ToList()); var coinsObject = new DatabaseObject() .Set("Gold", new DatabaseObject() .Set("Count", this.player.Coins) .Set("PosX", goldCoins.Item1) .Set("PosY", goldCoins.Item2)) .Set("Blue", new DatabaseObject() .Set("Count", this.player.BlueCoins) .Set("PosX", blueCoins.Item1) .Set("PosY", blueCoins.Item2)); var backupObject = new DatabaseObject() .Set("RoomId", roomId) .Set("SaveTime", DateTime.UtcNow) .Set("PosX", this.player.X) .Set("PosY", this.player.Y) .Set("Coins", coinsObject) .Set("Deaths", this.player.Deaths) .Set("CheckpointX", this.player.Checkpoint.X) .Set("CheckpointY", this.player.Checkpoint.Y) .Set("TotalMovements", this.player.TotalMovements) .Set("IsCheater", this.player.IsCheater) .Set("AntiFlightHeat", this.player.AntiFlightHeat) .Set("AntiJumpHeat", this.player.AntiJumpHeat) .Set("Switches", VarintConverter.GetVarintBytes(this.player.Switches)) .Set("Team", this.player.Team) .Set("Effects", effects) .Set("SpeedX", this.player.SpeedX) .Set("SpeedY", this.player.SpeedY) .Set("PlayTime", (DateTime.UtcNow - this.player.CampaignJoinTime).TotalMinutes); dbo.Set(ObjectName, backupObject); dbo.Save(); }
public void addLastPlayedMap(String mapKey) { if (isGuest) { return; } DatabaseArray maps = PlayerObject.GetArray("LastPlayedMaps"); DatabaseObject mapEntry = null; DatabaseObject oldestEntry = null; int oldestIndex = 0; for (int i = 0; i < maps.Count; ++i) { DatabaseObject entry = maps.GetObject(i.ToString()); if (entry.Contains("Map")) { if (entry.GetString("Map") == mapKey) { mapEntry = entry; } else { if (oldestEntry == null || DateTime.Compare(entry.GetDateTime("Date"), oldestEntry.GetDateTime("Date")) < 0) { oldestEntry = entry; oldestIndex = i; } } } } // remove oldest entry if list is full //if (maps.Count > 8) { // maps.Remove(oldestIndex.ToString()); //} // if current map is already in last played list, just update date if (mapEntry != null) { mapEntry.Set("Date", DateTime.Now); } else { DatabaseObject entry = new DatabaseObject(); entry.Set("Map", mapKey); entry.Set("Date", DateTime.Now); maps.Add(entry); } PlayerObject.Remove("LastPlayedMaps"); //sort the array from the latest to oldest DatabaseArray newMaps = new DatabaseArray(); int newestIndex = 0; bool found = false; do { found = false; newestIndex = 0; DatabaseObject newestEntry = null; //foreach(DatabaseObject entry in maps) { for (int i = 0; i < maps.Count; ++i) { if (!maps.Contains(i.ToString())) { continue; } DatabaseObject entry = maps.GetObject(i.ToString()); if (!entry.Contains("Date")) { continue; } if (newestEntry == null || DateTime.Compare(entry.GetDateTime("Date"), newestEntry.GetDateTime("Date")) > 0) { newestEntry = entry; newestIndex = i; found = true; } } if (found) { DatabaseObject tmp = maps.GetObject(newestIndex.ToString()); maps.Remove(newestIndex.ToString()); bool duplicate = false; foreach (DatabaseObject dbo in newMaps) { if (dbo.GetString("Map") == tmp.GetString("Map")) { duplicate = true; break; } } if (duplicate) { continue; } DatabaseObject tmp2 = new DatabaseObject(); tmp2.Set("Map", tmp.GetString("Map")); tmp2.Set("Date", tmp.GetDateTime("Date")); //newMaps.Add(tmp2); newMaps.Insert(0, tmp2); } } while (found && newMaps.Count < 8); //newMaps = (DatabaseArray)newMaps.Reverse(); PlayerObject.Set("LastPlayedMaps", newMaps); /*maps = PlayerObject.GetArray("LastPlayedMaps"); * for (int i = 0; i < maps.Count; i++) { * Console.WriteLine(maps.GetObject(i).GetString("Map")); * }*/ savePlayerData(); }