Exemple #1
0
        public static Area City(Character player)
        {
            if (Sound != null)
                Sound.Stop();

            Sound = ContentLoader.TownSong.CreateInstance();
            Sound.IsLooped = true;
            Sound.Play();

            Point levelrange = new Point(3, 8);
            var map = ContentLoader.City;

            Vector2 spawn = Vector2.One;
            if (player.PreviousArea != null)
                if (player.PreviousArea.Name == "Shop") {
                    spawn = new Vector2(256, 192);
                }
                else if (player.PreviousArea.Name == "Route 1") {
                    spawn = new Vector2(256, 416);
                }
                else {
                    spawn = new Vector2(32, 96);
                }

            List<Monster> monsters = new List<Monster>();
            List<Character> opponents = new List<Character>();
            //Sound = ContentLoader.RouteSong;
            //Sound.IsLooped = true;
            //Sound.Play();

            return new Area("City", levelrange, monsters, opponents, spawn, map);
        }
Exemple #2
0
 public void Access(Character player, Vector2 pos)
 {
     this.player = player;
     CurrentPage = 1;
     Page = 1;
     var index = 0;
     boxBounds = new Rectangle((int)pos.X, (int)pos.Y, 48 * maxMonstersWidth, 48 * maxMonstersHeight);
     if (player.Box.Count != Monsters.Count) {
         Party = new List<ContainerButton>();
         Monsters = new List<ContainerButton>();
         var rect = new Rectangle(-48, 0, 48, 48);
         foreach (var mon in player.Box) {
             if (player.Box.Count > MaxMonstersPerPage) {
                 index++;
                 if (index > MaxMonstersPerPage) {
                     rect = new Rectangle(0, 0, 48, 48);
                     Page++;
                 }
             }
             rect = new Rectangle(rect.X += mon.PartySprite.Width, rect.Y, 48, 48);
             if (rect.X == 48 * (maxMonstersWidth)) {
                 rect = new Rectangle(0, rect.Y += mon.PartySprite.Width, 48, 48);
             }
             var boxed = new BoxedMonster(mon, Page);
             Monsters.Add(new ContainerButton(new Button(rect, mon.PartySprite), boxed));
         }
     }
     GetParty(player);
     Visible = true;
 }
Exemple #3
0
 public void Draw(SpriteBatch batch, Character player)
 {
     buyButton.Draw(batch);
     sellButton.Draw(batch);
     if (drawBuy) {
         GetItems(player);
         DrawBuy(batch);
     }
     if (drawSell) {
         GetItems(player);
         DrawSell(batch, player);
     }
     if (SelectedCapture != null || SelectedMedicine != null) {
         if (drawSell) {
             sell.Draw(batch);
         }
         if (drawBuy) {
             buy.Draw(batch);
         }
     }
     if (drawSellConfirm) {
         yesButton.Draw(batch);
         NoButton.Draw(batch);
     }
     if (drawBuyConfirm) {
         yesButton.Draw(batch);
         NoButton.Draw(batch);
     }
     var moneySize = ContentLoader.Arial.MeasureString(player.Money.ToString());
     batch.DrawString(ContentLoader.Arial, $"User money: {player.Money}", new Vector2(ContentLoader.MessageBox.Width - 150, Settings.ResolutionHeight - moneySize.Y),Color.Black);
 }
Exemple #4
0
 public void GetMessages(Character player, ref Battle battle, ref bool allowedToWalk, ref List<Shop> shops)
 {
     switch (character.NpcKind)
     {
         case NPCKind.Trainer:
             if (!character.BattleMessage.Said)
             {
                 character.BattleMessage.Visible = true;
                 character.Talking = true;
             }
             if (!character.Talking)
             {
                 battle = new Battle(player, character);
                 allowedToWalk = true;
             }
             break;
         case NPCKind.Healer:
             if (!character.IntroMessage.Said)
             {
                 character.IntroMessage.Visible = true;
                 character.Talking = true;
             }
             if (!character.Talking)
             {
                 if (character.ByeMessage.Said == false)
                 {
                     HealMonsters(player);
                     character.ByeMessage.Visible = true;
                 }
                 else
                 {
                     character.Talking = false;
                 }
             }
             break;
         case NPCKind.Shop:
             if (!character.IntroMessage.Said)
             {
                 character.IntroMessage.Visible = true;
                 character.Talking = true;
             }
             if (!character.Talking)
             {
                 if (character.ByeMessage.Said == false)
                 {
                     if (!shopAdded)
                     {
                         shops.Add( new Shop("Best shop around TM", character, player));
                         shopAdded = true;
                     }
                 }
                 else
                 {
                     character.Talking = false;
                 }
             }
             break;
     }
 }
Exemple #5
0
        public Shop(string shopName, Character guy, Character player)
        {
            Name = shopName;
            ShopKeeper = guy;
            this.player = player;
            GetItems(player);
            var buttonPos = 0;
            Rectangle rec = new Rectangle(buttonPos - ContentLoader.Button.Width, ContentLoader.GrassyBackground.Height, ContentLoader.Button.Width, ContentLoader.Button.Height);

            buyButton = new Button(new Rectangle(rec.X += ContentLoader.Button.Width, rec.Y, rec.Width, rec.Height), ContentLoader.Button, "Buy", ContentLoader.Arial);
            sellButton = new Button(new Rectangle(rec.X += ContentLoader.Button.Width, rec.Y, rec.Width, rec.Height), ContentLoader.Button, "Sell", ContentLoader.Arial);
            closeButton = new Button(new Rectangle(rec.X += ContentLoader.Button.Width, rec.Y, rec.Width, rec.Height), ContentLoader.Button, "Leave", ContentLoader.Arial);
        }
Exemple #6
0
        public static void DrawInventory(SpriteBatch batch, Character player)
        {
            ClearLists();
            var buttonPos = 0;
            Rectangle rec = new Rectangle(buttonPos - ContentLoader.Button.Width, ContentLoader.GrassyBackground.Height, ContentLoader.Button.Width, ContentLoader.Button.Height);
            bMedicine = new Button(new Rectangle(rec.X += ContentLoader.Button.Width, rec.Y + ContentLoader.Button.Height, rec.Width, rec.Height),
                ContentLoader.Button, "Medicine", ContentLoader.Arial);
            bCapture = new Button(new Rectangle(rec.X += ContentLoader.Button.Width, rec.Y + ContentLoader.Button.Height, rec.Width, rec.Height),
                ContentLoader.Button, "Capture", ContentLoader.Arial);

            bMedicine.Draw(batch);
            bCapture.Draw(batch);
            InventoryButtons.AddMany(bMedicine, bCapture);
            DrawItems(batch, player);
        }
Exemple #7
0
        public Menu(Character player, Vector2 pos)
        {
            ButtonList = new List<Button>();
            var buttonTexture = ContentLoader.Button;
            var hoverTexture = ContentLoader.ButtonHover;
            var clickedTexture = ContentLoader.ButtonClicked;
            var width = buttonTexture.Width;
            var height = buttonTexture.Height;
            this.player = player;
            position = pos;
            KnownMonstersButton = new Button(new Rectangle((int)pos.X, (int)pos.Y, width, height), buttonTexture, hoverTexture, clickedTexture, "Monsters", ContentLoader.Arial);
            PartyButton = new Button(new Rectangle((int)pos.X, (int)pos.Y + height, width, height), buttonTexture, hoverTexture, clickedTexture, "Party", ContentLoader.Arial);
            SaveButton = new Button(new Rectangle((int)pos.X, (int)pos.Y + (height * 2), width, height), buttonTexture, hoverTexture, clickedTexture, "Save", ContentLoader.Arial);
            MuteButton = new Button(new Rectangle((int)pos.X, (int)pos.Y + (height * 3), width, height), buttonTexture, hoverTexture, clickedTexture, "Mute", ContentLoader.Arial);
            CloseButton = new Button(new Rectangle((int)pos.X, (int)pos.Y + (height * 4), width, height), buttonTexture, hoverTexture, clickedTexture, "Close", ContentLoader.Arial);

            ButtonList.AddMany(KnownMonstersButton, PartyButton, SaveButton, MuteButton, CloseButton);
        }
Exemple #8
0
 public void Update(KeyboardState curKey, KeyboardState prevKey, Character player)
 {
     if (Visible) {
         player.Talking = true;
         if (curKey.IsKeyDown(Settings.conversation) && prevKey.IsKeyUp(Settings.conversation)) {
             if (CurrentIndex < Lines.Count - 1) {
                 CurrentIndex++;
                 CurrentLine = Lines[CurrentIndex];
             }
             else {
                 Visible = false;
                 Said = true;
             }
         }
     }
     else {
         player.Talking = false;
     }
 }
Exemple #9
0
        public void Draw(Camera2D camera, SpriteBatch batch, Character player)
        {
            foreach (var layer in Map.Layers) layer.Draw();

            if (Debug) {
                foreach (var encounterCollide in EncounterColliders) {
                    batch.Draw(ContentLoader.Button, encounterCollide, Color.Green);
                }
                foreach (var collisionCollide in CollisionColliders) {
                    batch.Draw(ContentLoader.Button, collisionCollide, Color.Blue);
                }
                foreach (var areaCollide in AreaColliders) {
                    batch.Draw(ContentLoader.Button, areaCollide.Key, Color.Aqua);
                }
                foreach (var opponent in OpponentList) {
                    batch.Draw(ContentLoader.Health, opponent.AI.Hitbox, Color.White);
                }
            }
            foreach (var opponent in OpponentList) {
                opponent.Draw(batch);
            }
            foreach (var shop in shopList) {
                shop.Draw(batch, player);
            }
            Box.Draw(batch);
            foreach (var boxCollide in BoxColliders) {
                batch.Draw(ContentLoader.Health, boxCollide, Color.Red);
            }
        }
Exemple #10
0
        public static Area Shop()
        {
            var spawn = new Vector2(288, 256);
            var map = ContentLoader.Shop;
            var inventory = new Inventory();
            inventory.Add(Capture.RottenNet(), 99);
            inventory.Add(Capture.RegularNet(), 99);
            inventory.Add(Capture.GreatNet(), 99);
            inventory.Add(Capture.MasterNet(), 99);

            inventory.Add(Medicine.LeafBandage(), 99);
            inventory.Add(Medicine.MagicStone(), 99);
            inventory.Add(Medicine.NastySpoon(), 99);
            inventory.Add(Medicine.AntiPoison(), 99);
            inventory.Add(Medicine.BucketOfWater(), 99);
            inventory.Add(Medicine.Salt(), 99);
            inventory.Add(Medicine.AirHorn(), 99);
            inventory.Add(Medicine.RoosVicee(), 99);

            var introShopLines = new List<string> { "Hello!\n Do you want to buy something?" };
            var byeShopLines = new List<string> { "Take a look", "Thanks for stopping by" };
            var ShopLady = new Character("HealLady", 0, inventory, introShopLines, byeShopLines, NPCKind.Shop, ContentLoader.HealLady, new Vector2(288, 64));

            ShopLady.AI = new AI(ShopLady, 2);
            ShopLady.Direction = Direction.Down;
            ShopLady.SetLineOfSight(2);

            var introLines = new List<string> { "Hello!\n Do you want to restore your monsters?" };
            var byeLines = new List<string> { "Here you go", "Thanks for stopping by" };
            var healLady = new Character("HealLady", 0, null, introLines, byeLines, NPCKind.Healer, ContentLoader.HealLady, new Vector2(224, 64));

            healLady.AI = new AI(healLady, 2);
            healLady.Direction = Direction.Down;
            healLady.SetLineOfSight(2);

            List<Character> opponents = new List<Character>();
            opponents.Add(healLady);
            opponents.Add(ShopLady);

            return new Area("Shop", Point.Zero, new List<Monster>(), opponents, spawn, map);
        }
Exemple #11
0
        public static Area SecretTunnel(Character player)
        {
            if (Sound != null)
                Sound.Stop();

            Sound = ContentLoader.TownSong.CreateInstance();
            Sound.IsLooped = true;
            Sound.Play();

            Random random = new Random();
            Point levelrange = new Point(3, 8);
            var map = ContentLoader.SecretTunnel;

            Vector2 spawn = Vector2.One;
            if (player.PreviousArea != null)
                if (player.PreviousArea.Name == "EasterCity") {
                    spawn = new Vector2(384, 416);
                }
                else {
                    spawn = new Vector2(384, 32);
                }

            List<Monster> monsters = new List<Monster>();
            List<Character> opponents = new List<Character>();
            //Sound = ContentLoader.RouteSong;
            //Sound.IsLooped = true;
            //Sound.Play();

            return new Area("SecretTunnel", levelrange, monsters, opponents, spawn, map);
        }
Exemple #12
0
        public static Area Route9(Character player)
        {
            int money = 10000;
            if (Sound != null)
                Sound.Stop();

            Sound = ContentLoader.RouteSong.CreateInstance();
            Sound.IsLooped = true;
            Sound.Play();

            Character tegenstander;
            Inventory inventory = new Inventory();
            inventory.Add(Medicine.MagicStone(), 2);
            List<string> battleLine = new List<string> { "Hah! Almost didn't catch you" };
            List<string> winLine = new List<string> { "That's what you get for getting caught by me" };
            List<string> loseLine = new List<string> { "I wish I didn't catch you", $"{player.Name} got ${money} for winning" };
            tegenstander = new Character("Christguy", money, inventory,
                new List<Monster> {
                    DatabaseConnector.GetMonster(3, 40),
                    DatabaseConnector.GetMonster(6, 40),
                    DatabaseConnector.GetMonster(9, 40),
                    DatabaseConnector.GetMonster(13, 40),
                    DatabaseConnector.GetMonster(15, 40),
                    DatabaseConnector.GetMonster(16, 50)
                },
                battleLine, winLine, loseLine, ContentLoader.MCGirlWorld, new Vector2(352, 254));
            tegenstander.AI = new AI(tegenstander, 4);

            Random random = new Random();
            Point levelrange = new Point(22, 27);
            var map = ContentLoader.Route9;
            Vector2 spawn = Vector2.One;
            spawn = new Vector2(352, 32);

            List<Monster> monsters = new List<Monster>
            {
                DatabaseConnector.GetMonster(12, random.Next(levelrange.X, levelrange.Y - 2)),
                DatabaseConnector.GetMonster(12, random.Next(levelrange.X, levelrange.Y)),
                DatabaseConnector.GetMonster(13, random.Next(levelrange.X, levelrange.Y)),
                DatabaseConnector.GetMonster(17, random.Next(levelrange.X, levelrange.Y - 2)),
                DatabaseConnector.GetMonster(21, random.Next(levelrange.X, levelrange.Y + 1)),
                DatabaseConnector.GetMonster(18, random.Next(levelrange.X, levelrange.Y)),
                DatabaseConnector.GetMonster(23, random.Next(levelrange.X, levelrange.Y - 2))

            };
            List<Character> opponents = new List<Character>
            {
                tegenstander
            };

            return new Area("Route 9", levelrange, monsters, opponents, spawn, map);
        }
Exemple #13
0
        public static void SaveData(Character user)
        {
            //Get id
            var playerId = user.Id;

            //Get player data
            var name = user.Name;
            var money = user.Money;
            var textureId = ContentLoader.GetIdFromCharacterWorldTexture(user.WorldSprite);
            var area = user.CurrentArea;
            var posX = user.Position.X;
            var posY = user.Position.Y;
            if (user.Position.X % 32 != 0) {
                var difference = user.Position.X % 32;
                if (difference <= 16)
                    posX += difference;
                else posX -= difference;
            }
            if (user.Position.Y % 32 != 0) {
                var difference = user.Position.Y % 32;
                if (difference <= 16)
                    posY += difference;
                else posY -= difference;
            }

            var cmd = connection.CreateCommand();

            #region Player

            cmd = connection.CreateCommand();
            //User should always be in database
            cmd.CommandText = "UPDATE `character` SET `Money` = @money, `Area` = @area, `PositionX` = @posX, `PositionY` = @posY " +
                              "WHERE `Id` = @id";
            cmd.Parameters.AddWithValue("@money", money);
            cmd.Parameters.AddWithValue("@area", area.Name);
            cmd.Parameters.AddWithValue("@posX", posX);
            cmd.Parameters.AddWithValue("@posY", posY);
            cmd.Parameters.AddWithValue("@id", playerId);
            cmd.ExecuteNonQuery();

            #endregion
            #region Known and Caught Monsters

            //var mergedList = ExtensionManager.CombineDictionaries(user.KnownMonsters, user.CaughtMonster);
            foreach (var mon in user.KnownMonsters.Values) {
                cmd = connection.CreateCommand();
                cmd.CommandText =
                    "SELECT COUNT(*) FROM `knownmonsterlink` WHERE `playerId` = @playerId AND `monsterId` = @monsterId";
                cmd.Parameters.AddWithValue("@playerId", playerId);
                cmd.Parameters.AddWithValue("@monsterId", mon.Id);
                var count = Convert.ToInt32(cmd.ExecuteScalar());
                if (count == 0) {
                    //Player has not seen the monster before
                    cmd.CommandText = "INSERT INTO `knownmonsterlink`(`playerId`, `monsterId`, `Caught`) VALUES (@playerId, @monsterId, FALSE)";
                    cmd.ExecuteNonQuery();
                }
            }

            #endregion
            #region Monsters
            foreach (var mon in user.Monsters) {
                cmd = connection.CreateCommand();
                cmd.CommandText = "SELECT COUNT(*) FROM `monsterlink` WHERE `Uid` = @monUid";
                cmd.Parameters.AddWithValue("@monUid", mon.UId);
                var count = Convert.ToInt32(cmd.ExecuteScalar());

                if (count > 0) {
                    //Monster is already in database
                    //Update stats
                    cmd.CommandText =
                        "UPDATE `stats` SET `Health` = @health, `Attack` = @attack, `Defense` = @defense, `SpecialAttack` = @specAttack, `SpecialDefense` = @specDefense, `Speed` = @speed," +
                        "`RandAttack` = @randAttack, `RandDefense` = @randDefense, `RandSpecialAttack` = @randSpecAttack, `RandSpecialDefense` = @randSpecDefense, `RandSpeed` = @randSpeed " +
                        "WHERE `stats`.`Id` = @statid";
                    cmd.Parameters.AddWithValue("@health", mon.Stats.Health);
                    cmd.Parameters.AddWithValue("@attack", mon.Stats.Attack);
                    cmd.Parameters.AddWithValue("@defense", mon.Stats.Defense);
                    cmd.Parameters.AddWithValue("@specAttack", mon.Stats.SpecialAttack);
                    cmd.Parameters.AddWithValue("@specDefense", mon.Stats.SpecialDefense);
                    cmd.Parameters.AddWithValue("@speed", mon.Stats.Speed);
                    cmd.Parameters.AddWithValue("@randAttack", mon.Stats.RandAttack);
                    cmd.Parameters.AddWithValue("@randDefense", mon.Stats.RandDefense);
                    cmd.Parameters.AddWithValue("@randSpecAttack", mon.Stats.RandSpecialAttack);
                    cmd.Parameters.AddWithValue("@randSpecDefense", mon.Stats.RandSpecialDefense);
                    cmd.Parameters.AddWithValue("@randSpeed", mon.Stats.RandSpeed);
                    cmd.Parameters.AddWithValue("@statid", mon.StatId);
                    cmd.ExecuteNonQuery();

                    cmd.CommandText =
                        "UPDATE `monsterlink` SET `monsterId` = @monId, `Level` = @level, `Experience` = @exp, `Ability` = @ability, `ItemId` = @itemId, `ItemKind` = @itemKind, `Boxed` = @box " +
                        "WHERE `Uid` = @uid";
                    cmd.Parameters.AddWithValue("@monId", mon.Id);
                    cmd.Parameters.AddWithValue("@level", mon.Level);
                    cmd.Parameters.AddWithValue("@exp", mon.Experience);
                    cmd.Parameters.AddWithValue("@ability", mon.Ability.Name);
                    cmd.Parameters.AddWithValue("@itemId", mon.HeldItem);
                    cmd.Parameters.AddWithValue("@itemKind", mon.HeldItem.Kind.ToString());
                    cmd.Parameters.AddWithValue("@box", user.Box.Contains(mon));
                    cmd.Parameters.AddWithValue("@uid", mon.UId);
                    cmd.ExecuteNonQuery();
                }
                else {
                    //Insert stats
                    cmd.CommandText =
                        "INSERT INTO `stats`(`Id`, `Health`, `Attack`, `Defense`, `SpecialAttack`, `SpecialDefense`, `Speed`, `RandAttack`, `RandDefense`, `RandSpecialAttack`, `RandSpecialDefense`, `RandSpeed`) " +
                        "VALUES(@statid, @health, @attack, @defense, @specAttack, @specDefense, @speed, @randAttack, @randDefense, @randSpecAttack, @randSpecDefense, @randSpeed)";
                    cmd.Parameters.AddWithValue("@health", mon.Stats.Health);
                    cmd.Parameters.AddWithValue("@attack", mon.Stats.Attack);
                    cmd.Parameters.AddWithValue("@defense", mon.Stats.Defense);
                    cmd.Parameters.AddWithValue("@specAttack", mon.Stats.SpecialAttack);
                    cmd.Parameters.AddWithValue("@specDefense", mon.Stats.SpecialDefense);
                    cmd.Parameters.AddWithValue("@speed", mon.Stats.Speed);
                    cmd.Parameters.AddWithValue("@randAttack", mon.Stats.RandAttack);
                    cmd.Parameters.AddWithValue("@randDefense", mon.Stats.RandDefense);
                    cmd.Parameters.AddWithValue("@randSpecAttack", mon.Stats.RandSpecialAttack);
                    cmd.Parameters.AddWithValue("@randSpecDefense", mon.Stats.RandSpecialDefense);
                    cmd.Parameters.AddWithValue("@randSpeed", mon.Stats.RandSpeed);
                    cmd.Parameters.AddWithValue("@statid", mon.StatId);
                    cmd.ExecuteNonQuery();

                    cmd.CommandText =
                        "INSERT INTO `monsterlink`(`Id`, `Uid`, `playerId`, `monsterId`, `statsId`, `Level`, `Experience`, `Ability`, `ItemId`, `ItemKind`, `Gender`, `Boxed`) " +
                        "VALUES (@id, @uid, @pid, @mid, @sid, @level, @exp, @ability, @itemId, @itemKind, @gender, @box)";
                    var id = RandomId.GenerateLinkId();
                    cmd.Parameters.AddWithValue("@id", id);
                    cmd.Parameters.AddWithValue("@uid", mon.UId);
                    cmd.Parameters.AddWithValue("@pid", playerId);
                    cmd.Parameters.AddWithValue("@mid", mon.Id);
                    cmd.Parameters.AddWithValue("@sid", mon.StatId);
                    cmd.Parameters.AddWithValue("@level", mon.Level);
                    cmd.Parameters.AddWithValue("@exp", mon.Experience);
                    cmd.Parameters.AddWithValue("@ability", mon.Ability.Name);
                    cmd.Parameters.AddWithValue("@itemId", mon.HeldItem);
                    cmd.Parameters.AddWithValue("@itemKind", mon.HeldItem.Kind.ToString());
                    cmd.Parameters.AddWithValue("@gender", mon.Gender.ToString());
                    cmd.Parameters.AddWithValue("@box", user.Box.Contains(mon));
                    cmd.ExecuteNonQuery();
                }
            }
            #endregion
            #region Inventory
            foreach (var cap in user.Inventory.Captures.Values) {
                cmd = connection.CreateCommand();
                cmd.CommandText = "SELECT COUNT(*) FROM `capturelink` WHERE `playerId` = @playerId AND `captureId` = @captureId";
                cmd.Parameters.AddWithValue("@playerId", playerId);
                cmd.Parameters.AddWithValue("@captureId", cap.Id);
                var count = Convert.ToInt32(cmd.ExecuteScalar());
                if (count > 0) {
                    //player already has item
                    cmd.CommandText = "UPDATE `capturelink` SET `Amount` = @amount WHERE `playerId` = @playerId AND `captureId` = @captureId";
                    cmd.Parameters.AddWithValue("@amount", cap.Amount);
                    cmd.ExecuteScalar();
                }
                else {
                    //player recently receiver item
                    cmd.CommandText = "INSERT INTO `capturelink`(`playerId`, `captureId`, `Amount`) VALUES (@playerId, @captureId, @amount)";
                    cmd.Parameters.AddWithValue("@amount", cap.Amount);
                    cmd.ExecuteScalar();
                }
            }
            foreach (var med in user.Inventory.Medicine.Values) {
                cmd = connection.CreateCommand();
                cmd.CommandText = "SELECT COUNT(*) FROM `medicinelink` WHERE `playerId` = @playerId AND `medicineId` = @medicineId";
                cmd.Parameters.AddWithValue("@playerId", playerId);
                cmd.Parameters.AddWithValue("@medicineId", med.Id);
                var count = Convert.ToInt32(cmd.ExecuteScalar());
                if (count > 0) {
                    //player already has item
                    cmd.CommandText = "UPDATE `medicinelink` SET `Amount` = @amount WHERE `playerId` = @playerId AND `medicineId` = @medicineId";
                    cmd.Parameters.AddWithValue("@amount", med.Amount);
                    cmd.ExecuteScalar();
                }
                else {
                    //player recently receiver item
                    cmd.CommandText = "INSERT INTO `medicinelink`(`playerId`, `medicineId`, `Amount`) VALUES (@playerId, @medicineId, @amount)";
                    cmd.Parameters.AddWithValue("@amount", med.Amount);
                    cmd.ExecuteScalar();
                }
            }
            #endregion
        }
Exemple #14
0
 public static void DrawItems(SpriteBatch batch, Character player)
 {
     ClearLists();
     var buttonPos = 0;
     Rectangle rec = new Rectangle(buttonPos - ContentLoader.Button.Width, ContentLoader.GrassyBackground.Height, ContentLoader.Button.Width, ContentLoader.Button.Height);
     if (DrawMedicine) {
         foreach (var item in player.Inventory.Medicine.Where(x => x.Value.Amount > 0)) {
             var b = new Button(new Rectangle(rec.X += ContentLoader.Button.Width, rec.Y + (ContentLoader.Button.Height * 2), rec.Width, rec.Height),
                     ContentLoader.Button);
             b.Draw(batch);
             MedicineButtons.Add(new ContainerButton(b, item.Value));
             batch.Draw(item.Value.Sprite, new Vector2(b.Position.X + (item.Value.Sprite.Width / 2), b.Position.Y), Color.White);
             batch.DrawString(ContentLoader.Arial, $"{item.Value.Amount}x",
                 new Vector2(b.Position.X, b.Position.Y + ContentLoader.Button.Height), Color.White);
         }
     }
     if (DrawCapture) {
         foreach (var item in player.Inventory.Captures.Where(x => x.Value.Amount > 0)) {
             var b = new Button(new Rectangle(rec.X += ContentLoader.Button.Width, rec.Y + (ContentLoader.Button.Height * 2), rec.Width, rec.Height),
                 ContentLoader.Button) { Text = item.Value.Name };
             b.Draw(batch);
             CaptureButtons.Add(new ContainerButton(b, item.Value));
             batch.Draw(item.Value.Sprite, new Vector2(b.Position.X + (item.Value.Sprite.Width / 2), b.Position.Y), Color.White);
             batch.DrawString(ContentLoader.Arial, $"{item.Value.Amount}x",
                 new Vector2(b.Position.X, b.Position.Y + ContentLoader.Button.Height), Color.White);
         }
     }
 }
Exemple #15
0
 public void GetCollision(Character player)
 {
     CollisionColliders.Clear();
     var collisionLayers = Map.TileLayers.Where(layer => layer.Properties.ContainsKey("Collision") && layer.Properties.ContainsValue("true")).ToList();
     foreach (var layer in collisionLayers) {
         foreach (var tile in layer.Tiles) {
             if (tile.Id != 0) {
                 collisionHitbox = new Rectangle((tile.X * tileWidth), (tile.Y * tileHeight), tileWidth, tileHeight);
                 CollisionColliders.Add(collisionHitbox);
             }
         }
     }
     var boxLayer = Map.TileLayers.Where(layer => layer.Properties.ContainsKey("Box") && layer.Properties.ContainsValue("true")).ToList();
     foreach (var tile in boxLayer.SelectMany(layer => layer.Tiles.Where(x => x.Id != 0))) {
         collisionHitbox = new Rectangle((tile.X * tileWidth), (tile.Y * tileHeight), tileWidth, tileHeight);
         CollisionColliders.Add(collisionHitbox);
     }
     if (CollisionColliders.Count != 0) {
         foreach (var collision in CollisionColliders) {
             if (player.Hitbox.Intersects(collision)) {
                 var moduloX = player.Position.X % 32;
                 var moduloY = player.Position.Y % 32;
                 var vector = new Vector2(collision.X, collision.Y);
                 //If right of it
                 if (vector.X >= player.Position.X) {
                     if (player.RightCollide(collision)) {
                         if (moduloX >= 16) moduloX -= 32;
                         player.Position.X -= moduloX;
                     }
                 }
                 //if left of it
                 if (vector.X <= player.Position.X) {
                     if (player.LeftCollide(collision)) {
                         if (moduloX >= 16) moduloX -= 32;
                         player.Position.X -= moduloX;
                     }
                 }
                 //if above it
                 if (player.UpperCollide(collision))
                     if (vector.Y >= player.Position.Y - 32) {
                         if (moduloY >= 16) moduloY -= 32;
                         player.Position.Y -= moduloY;
                     }
                 //}
                 //if below it
                 if (player.LowerCollide(collision))
                     if (vector.Y <= player.Position.Y + 32) {
                         if (moduloY >= 16) moduloY -= 32;
                         player.Position.Y -= moduloY;
                     }
             }
         }
     }
 }
Exemple #16
0
 public void GetArea(Character player)
 {
     AreaColliders.Clear();
     var collisionLayers = Map.TileLayers.Where(layer => layer.Properties.ContainsKey("EnterArea")).ToList();
     foreach (var layer in collisionLayers) {
         foreach (var tile in layer.Tiles.Where(tile => tile.Id != 0)) {
             //if(AreaColliders.ContainsKey(layer.Properties.Values))
             collisionHitbox = new Rectangle((tile.X * tileWidth), (tile.Y * tileHeight), tileWidth, tileHeight);
             var areaName = layer.Properties.Values.ElementAt(0);
             if (!AreaColliders.ContainsKey(collisionHitbox))
                 AreaColliders.Add(collisionHitbox, areaName);
         }
     }
     if (AreaColliders.Count != 0) {
         foreach (var entry in AreaColliders.Where(entry => player.Hitbox.Intersects(entry.Key))) {
             //Enter area
             player.CountingDown = false;
             player.Moved = 0;
             player.PreviousArea = player.CurrentArea;
             player.CurrentArea = GetAreaFromName(entry.Value, player);
             player.Position = player.CurrentArea.SpawnLocation;
             break;
         }
     }
 }
Exemple #17
0
 public Message(List<string> lines, Color color, Character character)
 {
     Lines = lines;
     CurrentIndex = 0;
     CurrentLine = Lines[CurrentIndex];
     Color = color;
     Font = ContentLoader.Arial;
     SourceTexture = ContentLoader.MessageBox;
     Position = new Vector2(0, Settings.ResolutionHeight - SourceTexture.Height);
     Character = character;
     Visible = false;
 }
Exemple #18
0
        public void StoreItemsInList(Character character)
        {
            Rectangle rec = new Rectangle(0 - ContentLoader.Button.Width, ContentLoader.GrassyBackground.Height, ContentLoader.Button.Width, ContentLoader.Button.Height);

            int index = 1;
            foreach (var cap in character.Inventory.Captures.Values) {
                index++;
                //new Rectangle(rec.X += ContentLoader.Button.Width, rec.Y + (ContentLoader.Button.Height * 2), rec.Width, rec.Height
                var btn = new Button(new Rectangle(rec.X += ContentLoader.Button.Width, rec.Y + (ContentLoader.Button.Height * 2), rec.Width, rec.Height), cap.Sprite);
                if (character.Name == ShopKeeper.Name)
                    shopCaptureButtons.Add(new ContainerButton(btn, cap));
                else {
                    playerCaptureButtons.Add(new ContainerButton(btn, cap));
                }
            }
            rec = new Rectangle(0 - ContentLoader.Button.Width, ContentLoader.GrassyBackground.Height, ContentLoader.Button.Width, ContentLoader.Button.Height);
            index = 1;
            foreach (var med in character.Inventory.Medicine.Values) {
                index++;
                var btn = new Button(new Rectangle(rec.X += ContentLoader.Button.Width, rec.Y + (ContentLoader.Button.Height * 2), rec.Width, rec.Height), med.Sprite);
                if (character.Name == ShopKeeper.Name)
                    shopMedicineButtons.Add(new ContainerButton(btn, med));
                else {
                    playerMedicineButtons.Add(new ContainerButton(btn, med));
                }
            }
        }
Exemple #19
0
 public void GetItems(Character player)
 {
     shopCaptureButtons = new List<ContainerButton>();
     shopMedicineButtons = new List<ContainerButton>();
     playerCaptureButtons = new List<ContainerButton>();
     playerMedicineButtons = new List<ContainerButton>();
     StoreItemsInList(ShopKeeper);
     StoreItemsInList(player);
 }
Exemple #20
0
 public void DrawSell(SpriteBatch batch, Character player)
 {
     if (Drawer.DrawCapture)
         foreach (var containerButton in playerCaptureButtons.Where(x => x.Capture.Amount > 0)) {
             containerButton.Button.Draw(batch);
         }
     if (Drawer.DrawMedicine)
         foreach (var containerButton in playerMedicineButtons.Where(x => x.Medicine.Amount > 0)) {
             containerButton.Button.Draw(batch);
         }
     Drawer.DrawInventory(batch, player);
 }
Exemple #21
0
 public void GetBox(Character player)
 {
     var boxLayers = Map.TileLayers.Where(layer => layer.Properties.ContainsKey("Box") && layer.Properties.ContainsValue("true")).ToList();
     foreach (var layer in boxLayers) {
         foreach (var tile in layer.Tiles.Where(tile => tile.Id != 0)) {
             encounterHitbox = new Rectangle((tile.X * tileWidth), (tile.Y * (tileHeight * 2)), tileWidth, tileHeight);
             BoxColliders.Add(encounterHitbox);
         }
     }
     if (BoxColliders.Count != 0) {
         foreach (var collision in BoxColliders) {
             if (player.Hitbox.Intersects(collision)) {
                 //Show the box
                 if (!BoxAccesed) {
                     Box.Access(player, new Vector2(0, 0));
                     BoxAccesed = true;
                 }
             }
             else {
                 Box.Disconnect();
                 BoxAccesed = false;
             }
         }
     }
 }
Exemple #22
0
        public void GetEncounters(Character player, ref Battle battle, ref bool battling)
        {
            EncounterColliders.Clear();
            var encounterLayers = Map.TileLayers.Where(layer => layer.Properties.ContainsKey("Encounters") && layer.Properties.ContainsValue("true")).ToList();
            foreach (var layer in encounterLayers) {
                foreach (var tile in layer.Tiles) {
                    if (tile.Id != 0) {
                        encounterHitbox = new Rectangle((tile.X * tileWidth), (tile.Y * tileHeight), tileWidth, tileHeight);
                        EncounterColliders.Add(encounterHitbox);
                    }
                }
            }
            if (EncounterColliders.Count != 0) {
                foreach (var collision in EncounterColliders) {
                    if (player.Hitbox.Intersects(collision)) {
                        Random rand = new Random();

                        if (player.Position != previousPos && player.Moved >= 29f) {
                            var chanceToEncounter = rand.Next(0, 100);

                            if (chanceToEncounter <= 5) {
                                battling = true;
                                battle = new Battle(player, GetRandomMonster());
                            }
                        }
                    }
                }
            }
            previousPos = player.Position;
        }
Exemple #23
0
 public static Area GetAreaFromName(string n, Character player)
 {
     //return area if n is the name
     switch (n.ToLower()) {
     case "route 1":
         return Route1(player);
     case "route 2":
         return Route2(player);
     case "route 3":
         return Route3(player);
     case "route 4":
         return Route4(player);
     case "route 5":
         return Route5(player);
     case "route 6":
         return Route6(player);
     case "route 7":
         return Route7(player);
     case "route 8":
         return Route8(player);
     case "route 9":
         return Route9(player);
         case "city":
         Random random = new Random();
         return random.Next(0, 10) == 2 ? EasterCity(player) : City(player);
     case "eastercity":
         return EasterCity(player);
     case "shop":
         return Shop();
     case "secrettunnel":
         return SecretTunnel(player);
     case "secretcity":
         return SecretCity(player);
     }
     return null;
 }
Exemple #24
0
        public void Use(Monster monster, Character player)
        {
            if (Cures != Cure.None) {
                if (Cures == Cure.All) {
                    monster.Ailment = Ailment.Normal;
                }
                if (monster.Ailment == (Ailment)Cures) {
                    monster.Ailment = Ailment.Normal;
                }
            }
            if (inflict != Cure.None) {
                monster.Ailment = (Ailment)inflict;
            }
            if ((monster.Stats.Health + HealAmount) >= monster.MaxHealth) {
                monster.Stats.Health = monster.MaxHealth;
            }
            else if (monster.Stats.Health != monster.MaxHealth)
                monster.Stats.Health += HealAmount;
            else {
                Amount++;
            }
            Amount--;

            if (Amount < 1) {
                player.Inventory.Medicine.Remove(Id);
            }
        }
Exemple #25
0
 public void Update(GameTime gameTime, KeyboardState currentKeyboardState, KeyboardState previousKeyboardState,
     MouseState currentMouseState, MouseState previousMouseState,
     Character player, ref Battle currentBattle)
 {
     if (OpponentList == null) return;
     if (OpponentList.Count == 0) return;
     foreach (var opponent in OpponentList) {
         opponent.UpdateMessages(currentKeyboardState, previousKeyboardState, player);
         opponent.Update(gameTime, currentKeyboardState, previousKeyboardState);
         opponent.AI.Update(player, ref currentBattle, ref shopList, currentMouseState, previousMouseState);
     }
     foreach (var shop in shopList) {
         shop.Update(currentMouseState, previousMouseState);
     }
     Box.Update(currentMouseState, previousMouseState, gameTime);
 }
Exemple #26
0
        public static Area Route1(Character player)
        {
            int money = 500;
            if (Sound != null)
                Sound.Stop();

            Sound = ContentLoader.RouteSong.CreateInstance();
            Sound.IsLooped = true;
            Sound.Play();

            Character tegenstander;
            Inventory inventory = new Inventory();
            inventory.Add(Medicine.MagicStone(), 2);
            List<string> battleLine = new List<string> { "Hah! Almost didn't catch you" };
            List<string> winLine = new List<string> { "That's what you get for getting caught by me" };
            List<string> loseLine = new List<string> { "I wish I didn't catch you", $"{player.Name} got ${money} for winning" };
            tegenstander = new Character("Christguy", money, inventory,
                new List<Monster> {
                    DatabaseConnector.GetMonster(1, 5),
                    DatabaseConnector.GetMonster(4, 7)
                },
                battleLine, winLine, loseLine, ContentLoader.ChristmanWorld, new Vector2(192, 192));
            tegenstander.AI = new AI(tegenstander, 3);

            Random random = new Random();
            Point levelrange = new Point(2, 8);
            var map = ContentLoader.Route1;
            Vector2 spawn = Vector2.One;
            if (player.PreviousArea != null)
                if (player.PreviousArea.Name == "City") {
                    spawn = new Vector2(384, 32);
                }
                else if (player.PreviousArea.Name == "EasterCity") {
                    spawn = new Vector2(384, 32);
                }
                else {
                    spawn = new Vector2(192, 416);
                }
            List<Monster> monsters = new List<Monster>
            {
                DatabaseConnector.GetMonster(10, random.Next(levelrange.X, levelrange.Y -2)),
                DatabaseConnector.GetMonster(10, random.Next(levelrange.X, levelrange.Y - 1)),
                DatabaseConnector.GetMonster(10, random.Next(levelrange.X, levelrange.Y)),
                DatabaseConnector.GetMonster(12, random.Next(levelrange.X, levelrange.Y - 1)),
                DatabaseConnector.GetMonster(12, random.Next(levelrange.X, levelrange.Y - 2)),
                DatabaseConnector.GetMonster(14, random.Next(levelrange.X, levelrange.Y))
            };
            List<Character> opponents = new List<Character>
            {
                tegenstander
            };

            return new Area("Route 1", levelrange, monsters, opponents, spawn, map);
        }
Exemple #27
0
        public void Use(Monster monster, Character player)
        {
            //Throw the net
            Random random = new Random();
            int capturechance = 0;

            CaptureAnimation(new List<Vector2>
            {
                new Vector2(20,20),
                new Vector2(50,50)
            });

            if (monster.Stats.Health < (monster.PreviousStats.Health / 100 * 20)) capturechance += 25;
            else if (monster.Stats.Health < (monster.PreviousStats.Health / 100 * 40)) capturechance += 20;
            else if (monster.Stats.Health < (monster.PreviousStats.Health / 100 * 60)) capturechance += 15;
            else if (monster.Stats.Health < (monster.PreviousStats.Health / 100 * 80)) capturechance += 10;

            switch (monster.Ailment) {
            case Ailment.Sleep: capturechance += 20; break;
            case Ailment.Poisoned: capturechance += 10; break;
            case Ailment.Burned: capturechance += 10; break;
            case Ailment.Dazzled: capturechance += 10; break;
            case Ailment.Frozen: capturechance += 20; break;
            case Ailment.Frenzied: capturechance += 5; break;
            }

            capturechance += CaptureChance;
            capturechance += (player.Monsters[0].Level - monster.Level);
            capturechance -= monster.CaptureChance;

            if (capturechance < 5) capturechance = 5;
            var dice = random.Next(0, 100);
            if (dice < capturechance) {
                //Add monster to caught list
                //if (!player.CaughtMonster.ContainsKey(monster.Id)) player.CaughtMonster.Add(monster.Id, monster);
                monster.UId = RandomId.GenerateRandomUId();
                if (player.Monsters.Count >= 6) player.Box.Add(monster);
                else player.Monsters.Add(monster);
            }
            Amount--;

            if (Amount < 1) player.Inventory.Captures.Remove(Id);
        }
Exemple #28
0
        public static Area Route3(Character player)
        {
            if (Sound != null)
                Sound.Stop();

            Sound = ContentLoader.RouteSong.CreateInstance();
            Sound.IsLooped = true;
            Sound.Play();

            Random random = new Random();
            Point levelrange = new Point(13, 17);
            var map = ContentLoader.Route3;
            Vector2 spawn = Vector2.One;
            if (player.PreviousArea != null)
                if (player.PreviousArea.Name == "Route 2") {
                    spawn = new Vector2(736, 392);
                }
                else {
                    spawn = new Vector2(352, 32);
                }
            List<Monster> monsters = new List<Monster>
            {
                DatabaseConnector.GetMonster(10, random.Next(levelrange.X, levelrange.Y)),
                DatabaseConnector.GetMonster(10, random.Next(levelrange.X, levelrange.Y - 1)),
                DatabaseConnector.GetMonster(12, random.Next(levelrange.X, levelrange.Y - 3)),
                DatabaseConnector.GetMonster(12, random.Next(levelrange.X, levelrange.Y)),
                DatabaseConnector.GetMonster(16, random.Next(levelrange.X, levelrange.Y - 2)),
                DatabaseConnector.GetMonster(17, random.Next(levelrange.X, levelrange.Y - 2))
             };
            List<Character> opponents = new List<Character> {
            };

            return new Area("Route 3", levelrange, monsters, opponents, spawn, map);
        }
Exemple #29
0
        /// <summary>
        /// Get all information about a character from the database
        /// </summary>
        /// <param name="name">Name of the character</param>
        public static List<Character> GetCharacters(string name)
        {
            //TODO: Find a way to use the id as a parameter instead of the name
            var charactersList = new List<Character>();
            MySqlDataReader reader;
            MySqlCommand cmd;
            //try {
            cmd = connection.CreateCommand();
            cmd.CommandText = $"SELECT COUNT(*) FROM `character` where `Name` = @X";
            cmd.Parameters.AddWithValue("@X", name);
            int count = Convert.ToInt32(cmd.ExecuteScalar());
            if (count == 0) { return charactersList; }
            if (count > 1) {
                //TODO: Think of a way to handle multiple returns
                //Multiple characters found with the same name, how do we handle this?
            }
            cmd = connection.CreateCommand();
            cmd.CommandText = $"SELECT * FROM `character` WHERE `Name` = @X";
            cmd.Parameters.AddWithValue("@X", name);
            using (var rdr = cmd.ExecuteReader()) {
                while (rdr.Read()) {
                    var id = rdr.GetInt32("Id");
                    idList.Add(id);
                }
            }

            foreach (var id in idList) {
                var inventory = GetInventory(id);
                List<Monster> box = new List<Monster>();
                var monsters = GetMonsters(id, ref box);
                var caughtMonster = new Dictionary<int, Monster>();
                var knownMonsters = GetKnownMonsters(id, ref caughtMonster);

                using (var rdr = cmd.ExecuteReader()) {
                    while (rdr.Read()) {
                        var money = rdr.GetInt32("Money");
                        var textureId = rdr.GetInt32("TextureId");
                        var world = ContentLoader.GetTextureFromPlayer(textureId);
                        Vector2 position = new Vector2(rdr.GetInt32("PositionX"), rdr.GetInt32("PositionY"));

                        Character character = new Character(name, money, inventory, monsters, world, position, true, true);
                        character.CurrentArea = new Area { Name = rdr.GetString("Area") };
                        character.Id = id;
                        character.Box = box;
                        character.KnownMonsters = knownMonsters;
                        //character.CaughtMonster = caughtMonster;
                        charactersList.Add(character);
                    }
                }
            }
            foreach (var player in charactersList) {
                var areaName = player.CurrentArea.Name;
                player.CurrentArea = null;
                player.CurrentArea = Area.GetAreaFromName(areaName, player);
            }
            return charactersList;
        }
Exemple #30
0
        public static Area Route8(Character player)
        {
            if (Sound != null)
                Sound.Stop();

            Sound = ContentLoader.RouteSong.CreateInstance();
            Sound.IsLooped = true;
            Sound.Play();

            Random random = new Random();
            Point levelrange = new Point(22, 27);
            var map = ContentLoader.Route8;
            Vector2 spawn = Vector2.One;
            if (player.PreviousArea != null)
                if (player.PreviousArea.Name == "Route 7") {
                    spawn = new Vector2(672, 128);
                }
                else {
                    spawn = new Vector2(192, 416);
                }
            List<Monster> monsters = new List<Monster>
            {
                DatabaseConnector.GetMonster(12, random.Next(levelrange.X, levelrange.Y - 2)),
                DatabaseConnector.GetMonster(12, random.Next(levelrange.X, levelrange.Y)),
                DatabaseConnector.GetMonster(13, random.Next(levelrange.X, levelrange.Y)),
                DatabaseConnector.GetMonster(17, random.Next(levelrange.X, levelrange.Y - 2)),
                DatabaseConnector.GetMonster(21, random.Next(levelrange.X, levelrange.Y + 1)),
                DatabaseConnector.GetMonster(18, random.Next(levelrange.X, levelrange.Y)),
                DatabaseConnector.GetMonster(23, random.Next(levelrange.X, levelrange.Y - 2))

            };
            List<Character> opponents = new List<Character> {
            };

            return new Area("Route 8", levelrange, monsters, opponents, spawn, map);
        }