示例#1
0
        void getWorld(LobbyPlayer pl, ref DatabaseObject o, int[] size, string typestring, bool isbeta = false)
        {
            #region get worldId from DB
            string[] types = new string[0],
            ids = new string[0];

            if (o.Contains("roomType") && o.Contains("roomId"))
            {
                types = o.GetString("roomType").Split(',');
                ids   = o.GetString("roomId").Split(',');
            }

            for (int i = 0; i < types.Length; i++)
            {
                if (types[i] == typestring)
                {
                    pl.Send("r", ids[i]);
                    return;
                }
            }
            #endregion

            if (pl.amount_accounts >= 3)
            {
                pl.Send("r", "OW_limit_reached_" + typestring);
                return;
            }

            #region generate world
            string world_id = (isbeta ? "BW" : "PW") + GenWID(info.random.Next(4, 6)) + "I";
            string p_types  = "",
                   p_ids    = "";

            if (o.Contains("roomType") && o.Contains("roomId"))
            {
                p_types = o.GetString("roomType");
                p_ids   = o.GetString("roomId");
            }

            o.Set("roomType", p_types + typestring + ",");
            o.Set("roomId", p_ids + world_id + ",");
            o.Save();

            DatabaseObject data = new DatabaseObject();
            data.Set("name", "Untitled World");
            data.Set("owner", pl.ConnectUserId);
            data.Set("plays", 0);
            data.Set("width", size[0]);
            data.Set("height", size[1]);
            PlayerIO.BigDB.CreateObject("Worlds", world_id, data, delegate(DatabaseObject obj) {
                pl.Send("r", world_id);
            });
            #endregion
        }
示例#2
0
        /// <summary>
        /// Loads the game's version from the database if availible
        /// </summary>
        public int GetGameVersion()
        {
            if (m_Client != null)
            {
                DatabaseObject configObject = m_Toolbelt.RunSafe <DatabaseObject>(() => m_Client.BigDB.Load("config", "config"));

                if (configObject != null)
                {
                    if (configObject.Contains("version"))
                    {
                        if (configObject["version"] is int)
                        {
                            return((int)configObject["version"]);
                        }
                        else
                        {
                            m_Log.Add(FluidLogCategory.Message, "Database has been updated. Config version is no longer a integer.");
                        }
                    }
                    else
                    {
                        m_Log.Add(FluidLogCategory.Message, "Database has been updated. Config version no longer exists.");
                    }
                }
                else
                {
                    m_Log.Add(FluidLogCategory.Message, "Failed to load everybodyedits configuration from database.");
                }
            }

            return(-1);
        }
示例#3
0
        private OnlineStatus(Client c, DatabaseObject existing)
        {
            this.client = c;

            this.RemoveDeprecatedValues(existing);

            this.key              = existing.Key;
            this.Name             = existing.GetString("name", existing.Key == "simpleguest" ? "guest account" : "");
            this.CurrentWorldName = existing.GetString("currentWorldName", "");
            this.CurrentWorldId   = existing.GetString("currentWorldId", "");
            this.Smiley           = existing.GetInt("smiley", 0);
            this.HasGoldBorder    = existing.GetBool("hasGoldBorder", false);
            this.IpAddress        = existing.GetString("ipAddress", "");
            this.Stealthy         = existing.GetBool("stealth", false);

            if (existing.Contains("lastUpdate"))
            {
                this.LastUpdate = existing.GetDateTime("lastUpdate");
            }

            if (!this.IsOnline)
            {
                this.CurrentWorldName = "";
                this.CurrentWorldId   = "";
            }
        }
        public void loadPoints(DatabaseObject roomData, String username)
        {
            DatabaseObject points = roomData.GetObject("points");

            if (!points.Contains(username))
            {
                return;
            }
            DatabaseObject user = points.GetObject(username);

            if (user.GetDateTime("day") < DateTime.Today)
            {
                Console.WriteLine("Purged old slime point data in map: " + RoomId);
                points.Remove(username);
                roomData.Save(true, true);
                return;
            }
            DatabaseArray userpoints = user.GetArray("list");
            ArrayList     listPoints = new ArrayList();

            for (int i = 0; i < userpoints.Count; i++)
            {
                listPoints.Add(userpoints.GetInt(i));
            }
            Points.Add((String)username.Clone(), listPoints);
        }
示例#5
0
        /// <summary>
        /// Trys to get a property value from a database object
        /// </summary>
        /// <typeparam name="T">The value type</typeparam>
        /// <param name="databaseObject">The database object</param>
        /// <param name="propertyName">The property name</param>
        /// <param name="defaultValue">The default value for the property</param>
        private T GetValue <T>(DatabaseObject databaseObject, string propertyName, T defaultValue)
        {
            if (databaseObject.Contains(propertyName))
            {
                return((T)databaseObject[propertyName]);
            }

            return(defaultValue);
        }
示例#6
0
 private void FixDeprecatedValues(DatabaseObject statsobj)
 {
     for (var i = 0; i < this.DEPRECATED_STATS_VALUES.Length; i++)
     {
         if (statsobj.Contains(this.DEPRECATED_STATS_VALUES[i]))
         {
             statsobj.Remove(this.DEPRECATED_STATS_VALUES[i]);
         }
     }
 }
示例#7
0
        /// <summary>
        /// Extracts the world from the BigDB database.
        /// </summary>
        /// <param name="obj">The object.</param>
        public static void FromDatabaseObject(DatabaseObject obj)
        {
            int width = obj.GetInt("width", 200);
            int height = obj.GetInt("height", 200);
            if (!obj.Contains("worlddata")) {
                Console.WriteLine("Error: No world data available");
                return;
            }

            UnserializeFromComplexObject(obj.GetArray("worlddata"), width, height);
        }
示例#8
0
        // This method is called when a player leaves the game
        public override void UserLeft(Player player)
        {
            Broadcast("UserLeft", player.Id);
            endSessionTime = DateTime.Now;
            numPlayers--;
            //Console.WriteLine("User session end!  Set end session time: " + endSessionTime.ToString(DateTimeFormat));

            // if this is a tutorial level, don't save the data
            if (player.tutorialLevel < 5 && quest != null)
            {
                PlayerIO.BigDB.DeleteKeys("NewQuests", quest.Key, null);
                //Console.WriteLine("deleted key " + quest.Key);
            }
            //update player's end session time in the newQuest database
            // if result is not null and contains something, save it into Quests db
            else if (quest != null && quest.Contains("players"))
            {
                // save quest map data
                //Console.WriteLine("questMap data to save: " + questMap);
                quest.Set("tileValues", questMap);

                DatabaseObject players = quest.GetObject("players");
                if (players != null && players.Contains(playerConnectUserId))
                {
                    DatabaseObject thisPlayer = players.GetObject(playerConnectUserId);

                    thisPlayer.Set("lastSessionEndTime", endSessionTime);
                    thisPlayer.Set("AP", player.AP);
                    thisPlayer.Set("positionX", player.positionX);
                    thisPlayer.Set("positionY", player.positionY);

                    // if resources exists, increment it; if not, create it
                    if (thisPlayer.Contains("resources"))
                    {
                        DatabaseObject resourceCount = thisPlayer.GetObject("resources");
                        resourceCount.Set("lumber", amountLumber);
                        resourceCount.Set("cherry", amountCherry);
                    }

                    else
                    {
                        DatabaseObject resourceCount = new DatabaseObject();
                        resourceCount.Set("lumber", amountLumber);
                        resourceCount.Set("cherry", amountCherry);
                        thisPlayer.Set("resources", resourceCount);
                    }
                }
                Broadcast("UserLeft", player.Id);
                quest.Save(delegate()
                {
                    //Console.WriteLine("UserLeft result: " + quest.ToString());
                });
            }
        }
示例#9
0
        private void RemoveDeprecatedValues(DatabaseObject onlineStatus)
        {
            var deprecated = false;

            foreach (var deprecatedValue in DeprecatedOnlineStatusValues)
            {
                if (onlineStatus.Contains(deprecatedValue))
                {
                    onlineStatus.Remove(deprecatedValue);
                    deprecated = true;
                }
            }

            if (deprecated)
            {
                onlineStatus.Save();
            }
        }
示例#10
0
        public void addPotion(Potion potion, Callback <List <Potion> > callback, DatabaseObject potiondata)
        {
            if (potion.expired)
            {
                return;
            }
            var removed = new List <Potion>();

            // Does the player already have a potion active, set the activation date to the latest date.
            if (potiondata.Contains(potion.name))
            {
                var current = potiondata.GetObject(potion.name);
                if (potion.activated > current.GetDateTime("activated"))
                {
                    current.Set("activated", potion.activated);
                }
            }
            else
            {
                // If there is already a potions with the same group, that is older, remove that first.
                var currentpotions = this.getPotions();
                var allow          = true;
                for (var i = 0; i < currentpotions.Count; i++)
                {
                    if (potion.group == currentpotions[i].group)
                    {
                        if (potion.activated > currentpotions[i].activated)
                        {
                            this.removePotion(currentpotions[i]);
                            removed.Add(currentpotions[i]);
                        }
                        else
                        {
                            allow = false;
                        }
                    }
                }
                if (allow)
                {
                    potiondata.Set(potion.name, Potion.createDatabaseObject(potion));
                }
            }
            callback(removed);
        }
示例#11
0
        public void awardAchievement(Achievement achiev)
        {
            bigDB.Load("PlayerObjects", owner.ConnectUserId, delegate(DatabaseObject result) {
                DatabaseObject achievs = result.GetObject("Achievements");
                if (achievs.Contains(achiev.name))
                {
                    return;
                }

                DatabaseObject achievObject = new DatabaseObject();
                achievObject.Set("Date", DateTime.Now);
                owner.achievements.Set(achiev.name, achievObject);
                owner.awardXP(achiev.xpReward, achiev.shardReward);
                owner.PlayerObject.Save(true, delegate()
                {
                    owner.Send(MessageID.ACHIEVEMENT_UNLOCKED, achiev.Id, achiev.name, achiev.xpReward, achiev.shardReward);
                    achievements.Remove(achiev);
                });
            });
        }
示例#12
0
        /// <summary>
        /// Unserializes the BigDB database world object.
        /// </summary>
        /// <param name="worlddata">The world data.</param>
        /// <param name="width">The width of the world.</param>
        /// <param name="height">The height of the world.</param>
        public static void UnserializeFromComplexObject(DatabaseObject input, int width, int height, string worldID)
        {
            Minimap minimap = new Minimap();
            minimap.width = width;
            minimap.height = height;
            minimap.initialize();

            if (input.Contains("worlddata"))
            {
                foreach (DatabaseObject ct in input.GetArray("worlddata").Reverse())
                {
                    if (ct.Count == 0) continue;
                    uint blockId = ct.GetUInt("type");
                    int layer = ct.GetInt("layer", 0);

                    byte[] x = ct.GetBytes("x", new byte[0]), y = ct.GetBytes("y", new byte[0]),
                           x1 = ct.GetBytes("x1", new byte[0]), y1 = ct.GetBytes("y1", new byte[0]);

                    for (int j = 0; j < x1.Length; j++)
                    {
                        byte nx = x1[j];
                        byte ny = y1[j];

                        minimap.drawBlock(layer, nx, ny, blockId);
                    }
                    for (int k = 0; k < x.Length; k += 2)
                    {
                        uint nx2 = (uint)(((int)x[k] << 8) + (int)x[k + 1]);
                        uint ny2 = (uint)(((int)y[k] << 8) + (int)y[k + 1]);

                        minimap.drawBlock(layer, (int)nx2, (int)ny2, blockId);
                    }
                }
            }
            else if (input.Contains("world"))
            {

            }

            minimap.Save(worldID + "_bigdb.png", histogram);
        }
示例#13
0
        public void onStatLoad(DatabaseObject result)
        {
            if (result != null)
            {
                if(result.Contains("games_played"))
                    result.Set("games_played", result.GetInt("games_played") + 1);
                else
                    result.Set("games_played", 1);

                if (result.Contains("towers_basic"))
                    result.Set("towers_basic", result.GetInt("towers_basic") + Stats.Basic);
                else
                    result.Set("towers_basic", Stats.Basic);

                if (result.Contains("towers_rapidfire"))
                    result.Set("towers_rapidfire", result.GetInt("towers_rapidfire") + Stats.RapidFire);
                else
                    result.Set("towers_rapidfire", Stats.RapidFire);

                if(result.Contains("towers_sniper"))
                    result.Set("towers_sniper", result.GetInt("towers_sniper") + Stats.Sniper);
                else
                    result.Set("towers_sniper", Stats.Sniper);

                if(result.Contains("towers_pulse"))
                    result.Set("towers_pulse", result.GetInt("towers_pulse") + Stats.Pulse);
                else
                    result.Set("towers_pulse", Stats.Pulse);

                if(result.Contains("towers_slow"))
                    result.Set("towers_slow", result.GetInt("towers_slow") + Stats.Slow);
                else
                    result.Set("towers_slow", Stats.Slow);

                if(result.Contains("towers_spell"))
                    result.Set("towers_spell", result.GetInt("towers_spell") + Stats.Spell);
                else
                    result.Set("towers_spell", Stats.Spell);

                if(result.Contains("towers_damageboost"))
                    result.Set("towers_damageboost", result.GetInt("towers_damageboost") + Stats.DamageBoost);
                else
                    result.Set("towers_damageboost", Stats.DamageBoost);

                if(result.Contains("towers_rangeboost"))
                    result.Set("towers_rangeboost", result.GetInt("towers_rangeboost") + Stats.RangeBoost);
                else
                    result.Set("towers_rangeboost", Stats.RangeBoost);

                if(result.Contains("towers_firerateboost"))
                    result.Set("towers_firerateboost", result.GetInt("towers_firerateboost") + Stats.FireRateBoost);
                else
                    result.Set("towers_firerateboost", Stats.FireRateBoost);

                result.Save(true);
                Console.WriteLine("Server stats saved.");
            }
        }
示例#14
0
        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();
        }
 private void checkGamesCounterObject(DatabaseObject dbo)
 {
     if (!dbo.Contains(GameTypes.BIG_BATTLE))
     {
         dbo.Set(GameTypes.BIG_BATTLE, 0);
         dbo.Set(GameTypes.FAST_SPRINT, 0);
         dbo.Set(GameTypes.FIRST_100, 0);
         dbo.Set(GameTypes.UPSIDE_DOWN, 0);
     }
 }
示例#16
0
        // 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");
        }
示例#17
0
        /// <summary>
        /// Deserialize's the world data
        /// </summary>
        /// <param name="worldObject">The world data as a database array</param>
        private void Deserialize(DatabaseObject worldObject)
        {
            Owner           = GetValue <string>(worldObject, "owner");
            Width           = GetValue <int>(worldObject, "width", 200);
            Height          = GetValue <int>(worldObject, "height", 200);
            Title           = GetValue <string>(worldObject, "name");
            Plays           = GetValue <int>(worldObject, "plays");
            WorldType       = (WorldType)GetValue <int>(worldObject, "type", 3);
            AllowPotions    = GetValue <bool>(worldObject, "allowpotions", true);
            Woots           = GetValue <int>(worldObject, "woots", 0);
            TotalWoots      = GetValue <int>(worldObject, "totalwoots", 0);
            Visible         = GetValue <bool>(worldObject, "visible", true);
            BackgroundColor = new FluidColor(GetValue <uint>(worldObject, "backgroundColor", 0));

            //Check is worlddata is present
            if (!worldObject.Contains("worlddata"))
            {
                return;
            }

            CreateEmptyWorld();

            DatabaseArray        databaseArray = (DatabaseArray)worldObject["worlddata"];
            IEnumerable <object> databaseEnum  = (IEnumerable <object>)databaseArray;

            using (IEnumerator <object> enumerator = databaseEnum.GetEnumerator())
            {
                while (enumerator.MoveNext())
                {
                    DatabaseObject blockData = (DatabaseObject)enumerator.Current;

                    byte[]  xBytes  = blockData.GetBytes("x");
                    byte[]  yBytes  = blockData.GetBytes("y");
                    BlockID blockId = (BlockID)blockData.GetUInt("type");

                    for (int i = 0; i < xBytes.Length; i += 2)
                    {
                        int x = xBytes[i] << 8 | xBytes[i + 1];
                        int y = yBytes[i] << 8 | yBytes[i + 1];
                        if (blockData.Contains("layer"))
                        {
                            Layer layer = (Layer)blockData.GetInt("layer");

                            switch (blockId)
                            {
                            case BlockID.HazardSpike:
                            case BlockID.DecorSciFi2013BlueSlope:
                            case BlockID.DecorSciFi2013BlueStraight:
                            case BlockID.DecorSciFi2013YellowSlope:
                            case BlockID.DecorSciFi2013YellowStraight:
                            case BlockID.DecorSciFi2013GreenSlope:
                            case BlockID.DecorSciFi2013GreenStraight:
                            case BlockID.OneWayCyan:
                            case BlockID.OneWayPink:
                            case BlockID.OneWayRed:
                            case BlockID.OneWayYellow:
                            {
                                Rotation rotation = (Rotation)blockData.GetUInt("rotation");

                                RotatableBlock rotatableBlock = new RotatableBlock(blockId, x, y, rotation);
                                SetBlock(rotatableBlock);
                            }
                            break;

                            case BlockID.CoinDoor:
                            case BlockID.BlueCoinDoor:
                            case BlockID.CoinGate:
                            case BlockID.BlueCoinGate:
                            {
                                uint goal = blockData.GetUInt("goal");

                                CoinBlock door = new CoinBlock(blockId, x, y, goal);
                                SetBlock(door);
                            }
                            break;

                            case BlockID.MusicDrum:
                            case BlockID.MusicPiano:
                            {
                                uint musicId = blockData.GetUInt("id");

                                MusicBlock musicBlock = new MusicBlock(blockId, x, y, musicId);
                                SetBlock(musicBlock);
                            }
                            break;

                            case BlockID.Portal:
                            case BlockID.InvisiblePortal:
                            {
                                Rotation rotation     = (Rotation)blockData.GetUInt("rotation");
                                uint     portalid     = blockData.GetUInt("id");
                                uint     portaltarget = blockData.GetUInt("target");

                                Portal portal = new Portal(blockId, x, y, rotation, portalid, portaltarget);
                                SetBlock(portal);
                            }
                            break;

                            case BlockID.SwitchPurple:
                            case BlockID.PurpleSwitchDoor:
                            case BlockID.PurpleSwitchGate:
                            {
                                uint goal = 0;
                                if (blockData.Contains("goal"))
                                {
                                    goal = blockData.GetUInt("goal");
                                }

                                PurpleBlock purpleBlock = new PurpleBlock(blockId, x, y, goal);
                                SetBlock(purpleBlock);
                            }
                            break;

                            case BlockID.DeathDoor:
                            case BlockID.DeathGate:
                            {
                                uint goal = blockData.GetUInt("goal");

                                DeathBlock deathBlock = new DeathBlock(blockId, x, y, goal);
                                SetBlock(deathBlock);
                            }
                            break;

                            case BlockID.WorldPortal:
                            {
                                string targetId = blockData.GetString("target");

                                WorldPortal worldPortal = new WorldPortal(blockId, x, y, targetId);
                                SetBlock(worldPortal);
                            }
                            break;

                            case BlockID.DecorSign:
                            {
                                string text = blockData.GetString("text");

                                TextBlock textBlock = new TextBlock(blockId, x, y, text);
                                SetBlock(textBlock);
                            }
                            break;

                            case BlockID.DecorLabel:
                            {
                                string text = blockData.GetString("text");
                                if (blockData.Contains("text_color"))
                                {
                                    string hexColor = blockData.GetString("text_color");

                                    LabelBlock labelBlock = new LabelBlock(blockId, x, y, text, hexColor);
                                    SetBlock(labelBlock);
                                }
                                else
                                {
                                    LabelBlock labelBlock = new LabelBlock(blockId, x, y, text);
                                    SetBlock(labelBlock);
                                }
                            }
                            break;

                            default:
                                Block block = new Block(blockId, layer, x, y);
                                SetBlock(block);
                                break;
                            }
                        }
                    }
                }
            }

            IsLoaded = true;
        }
示例#18
0
        public void saveWinner(DatabaseObject playerObject)
        {
            playerObject.Set(Properties.LastPlayed, DateTime.Now);

            // Damage dealt
            if (!playerObject.Contains(Properties.MaxDamageDealt))
                playerObject.Set(Properties.MaxDamageDealt, Black.DamageDealt);
            else
                if (mWinner.DamageDealt > playerObject.GetUInt(Properties.MaxDamageDealt))
                    playerObject.Set(Properties.MaxDamageDealt, mWinner.DamageDealt);

            playerObject.Save();

            Console.WriteLine(playerObject.Key + " player object has been saved.");
        }
示例#19
0
        public void LoadFromLevel(string level, int datas)
        {
            //errors = false;
            //EEditor.Properties.Settings.Default.LevelPass = levelPassTextBox.Text;

            try
            {
                if (MainForm.accs[MainForm.selectedAcc].loginMethod == 0 && MainForm.accs.ContainsKey(MainForm.selectedAcc))
                {
                    client = PlayerIO.QuickConnect.SimpleConnect(bdata.gameID, MainForm.accs[MainForm.selectedAcc].login, MainForm.accs[MainForm.selectedAcc].password, null);
                }
                else if (MainForm.accs[MainForm.selectedAcc].loginMethod == 1 && MainForm.accs.ContainsKey(MainForm.selectedAcc))
                {
                    client = PlayerIO.QuickConnect.FacebookOAuthConnect(bdata.gameID, MainForm.accs[MainForm.selectedAcc].login, null, null);
                }
                else if (MainForm.accs[MainForm.selectedAcc].loginMethod == 2 && MainForm.accs.ContainsKey(MainForm.selectedAcc))
                {
                    client = PlayerIO.QuickConnect.KongregateConnect(bdata.gameID, MainForm.accs[MainForm.selectedAcc].login, MainForm.accs[MainForm.selectedAcc].password, null);
                }
                else if (MainForm.accs[MainForm.selectedAcc].loginMethod == 3 && MainForm.accs.ContainsKey(MainForm.selectedAcc))
                {
                    client = PlayerIO.Authenticate(bdata.gameID, "secure", new Dictionary <string, string> {
                        { "userId", MainForm.accs[MainForm.selectedAcc].login }, { "authToken", MainForm.accs[MainForm.selectedAcc].password }
                    }, null);
                }
                else if (MainForm.accs[MainForm.selectedAcc].loginMethod == 4 && MainForm.accs.ContainsKey(MainForm.selectedAcc))
                {
                    PlayerIO.QuickConnect.SimpleConnect(bdata.gameID, MainForm.accs[MainForm.selectedAcc].login, MainForm.accs[MainForm.selectedAcc].password, null, delegate(Client cli)
                    {
                        cli.Multiplayer.CreateJoinRoom("$service-room", "AuthRoom", true, null, new Dictionary <string, string>()
                        {
                            { "type", "Link" }
                        }, delegate(Connection con1)
                        {
                            con1.OnMessage += delegate(object sender1, PlayerIOClient.Message m)
                            {
                                if (m.Type == "auth")
                                {
                                    client = PlayerIO.Authenticate("everybody-edits-su9rn58o40itdbnw69plyw", "linked", new Dictionary <string, string>()
                                    {
                                        { "userId", m.GetString(0) }, { "auth", m.GetString(1) }
                                    }, null);
                                    s1.Release();
                                }
                            };
                        },
                                                       delegate(PlayerIOError error)
                        {
                            MessageBox.Show(error.Message, "Error");
                        });
                    }, delegate(PlayerIOError error)
                    {
                        MessageBox.Show(error.Message, "Error");
                    });
                    s1.WaitOne();
                }

                if (datas == 0)
                {
                    if (MainForm.userdata.level.StartsWith("OW"))
                    {
                        client.Multiplayer.ListRooms("Everybodyedits" + client.BigDB.Load("config", "config")["version"], null, 0, 0,
                                                     delegate(RoomInfo[] rinfo)
                        {
                            foreach (var val in rinfo)
                            {
                                if (val.Id.StartsWith("OW"))
                                {
                                    if (val.Id.StartsWith(MainForm.userdata.level.Substring(0, 4)))
                                    {
                                        MainForm.userdata.level = val.Id;
                                        Connection            = client.Multiplayer.CreateJoinRoom(MainForm.userdata.level, "Everybodyedits" + client.BigDB.Load("config", "config")["version"], true, null, null);
                                        Connection.OnMessage += OnMessage;
                                        Connection.Send("init");
                                        NeedsInit = false;
                                        break;
                                    }
                                }
                            }
                        },
                                                     delegate(PlayerIOError error)
                        {
                            Console.WriteLine(error.Message);
                        });
                        s.WaitOne();
                    }
                    else
                    {
                        if (client != null)
                        {
                            Connection            = client.Multiplayer.CreateJoinRoom(MainForm.userdata.level, "Everybodyedits" + client.BigDB.Load("config", "config")["version"], true, null, null);
                            Connection.OnMessage += OnMessage;
                            Connection.Send("init");
                            NeedsInit = false;
                            s.WaitOne();
                        }
                        else
                        {
                            MessageBox.Show("Client is null");
                        }
                    }
                }


                else if (datas == 1)
                {
                    int            w   = 0;
                    int            h   = 0;
                    DatabaseObject dbo = client.BigDB.Load("Worlds", MainForm.userdata.level);
                    if (dbo != null)
                    {
                        var name = dbo.Contains("name") ? dbo["name"].ToString() : "Untitled World";
                        owner = dbo.Contains("owner") ? dbo["owner"].ToString() : null;
                        if (dbo.Contains("width") && dbo.Contains("height") && dbo.Contains("worlddata"))
                        {
                            uid2name(owner, name, Convert.ToInt32(dbo["width"]), Convert.ToInt32(dbo["height"]));
                            MapFrame = new Frame(Convert.ToInt32(dbo["width"]), Convert.ToInt32(dbo["height"]));
                        }
                        else
                        {
                            if (dbo.Contains("type"))
                            {
                                switch ((int)dbo["type"])
                                {
                                case 1:
                                    w = 50;
                                    h = 50;
                                    break;

                                case 2:
                                    w = 100;
                                    h = 100;
                                    break;

                                default:
                                case 3:
                                    w = 200;
                                    h = 200;
                                    break;

                                case 4:
                                    w = 400;
                                    h = 50;
                                    break;

                                case 5:
                                    w = 400;
                                    h = 200;
                                    break;

                                case 6:
                                    w = 100;
                                    h = 400;
                                    break;

                                case 7:
                                    w = 636;
                                    h = 50;
                                    break;

                                case 8:
                                    w = 110;
                                    h = 110;
                                    break;

                                case 11:
                                    w = 300;
                                    h = 300;
                                    break;

                                case 12:
                                    w = 250;
                                    h = 150;
                                    break;

                                case 13:
                                    w = 150;
                                    h = 150;
                                    break;
                                }
                                if (dbo.Contains("worlddata"))
                                {
                                    MapFrame = new Frame(w, h);
                                    uid2name(owner, name, w, h);
                                }
                            }
                            else
                            {
                                uid2name(owner, name, 200, 200);
                                MapFrame = new Frame(200, 200);
                            }
                        }



                        if (dbo.Contains("worlddata"))
                        {
                            MapFrame     = Frame.FromMessage2(dbo);
                            SizeWidth    = MapFrame.Width;
                            SizeHeight   = MapFrame.Height;
                            NeedsInit    = false;
                            DialogResult = System.Windows.Forms.DialogResult.OK;
                        }
                        else
                        {
                            notsaved     = true;
                            DialogResult = System.Windows.Forms.DialogResult.Cancel;
                        }
                        Close();
                    }
                }
                else if (datas == 2)
                {
                    int            w   = 0;
                    int            h   = 0;
                    DatabaseObject dbo = client.BigDB.Load("Worlds", MainForm.userdata.level);
                    if (dbo != null)
                    {
                        var name = dbo.Contains("name") ? dbo["name"].ToString() : "Untitled World";
                        owner = dbo.Contains("owner") ? dbo["owner"].ToString() : null;
                        if (dbo.Contains("width") && dbo.Contains("height") && dbo.Contains("worlddata"))
                        {
                            uid2name(owner, name, Convert.ToInt32(dbo["width"]), Convert.ToInt32(dbo["height"]));
                            MapFrame = new Frame(Convert.ToInt32(dbo["width"]), Convert.ToInt32(dbo["height"]));
                        }
                        else
                        {
                            if (dbo.Contains("type"))
                            {
                                switch ((int)dbo["type"])
                                {
                                case 1:
                                    w = 50;
                                    h = 50;
                                    break;

                                case 2:
                                    w = 100;
                                    h = 100;
                                    break;

                                default:
                                case 3:
                                    w = 200;
                                    h = 200;
                                    break;

                                case 4:
                                    w = 400;
                                    h = 50;
                                    break;

                                case 5:
                                    w = 400;
                                    h = 200;
                                    break;

                                case 6:
                                    w = 100;
                                    h = 400;
                                    break;

                                case 7:
                                    w = 636;
                                    h = 50;
                                    break;

                                case 8:
                                    w = 110;
                                    h = 110;
                                    break;

                                case 11:
                                    w = 300;
                                    h = 300;
                                    break;

                                case 12:
                                    w = 250;
                                    h = 150;
                                    break;

                                case 13:
                                    w = 150;
                                    h = 150;
                                    break;
                                }
                                MapFrame = new Frame(w, h);
                                uid2name(owner, name, w, h);
                            }
                            else
                            {
                                uid2name(owner, name, 200, 200);
                                MapFrame = new Frame(200, 200);
                            }
                        }
                        MapFrame.Reset(false);
                        SizeWidth    = MapFrame.Width;
                        SizeHeight   = MapFrame.Height;
                        NeedsInit    = false;
                        DialogResult = System.Windows.Forms.DialogResult.OK;
                        Close();
                    }
                }
            }
            catch (PlayerIOError error)
            {
                MessageBox.Show("An error occurred:" + error.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
 private void checkSpellDBO(DatabaseObject dbo)
 {
     if (!dbo.Contains("activationCount"))
     {
         dbo.Set("activationCount", 0); //how many times spell was activated (3-hour cycle)
         dbo.Set("usedCount", 0); //how many times spell was used in game
         dbo.Set("gamesCount", 0); //how many games were played with this spell on spellPanel
     }
 }