Esempio n. 1
0
 public PokemonAttack(PokemonSprite attacker, PokemonSprite defender, KeyValuePair <string, string> move)
 {
     Attacker      = attacker;
     Defender      = defender;
     AttackSpecies = attacker.GetSpecies();
     DefendSpecies = defender.GetSpecies();
     AttackerTypes = AttackSpecies.GetPokemonTypes();
     DefenseTypes  = DefendSpecies.GetPokemonTypes();
     this.move     = move;
     Damage        = CalculateDamage();
 }
Esempio n. 2
0
        /// <summary>
        /// levels up the pokemon, along with all the accompanying changes; including evolution
        /// </summary>
        /// <param name="pkm"></param>
        /// <returns></returns>
        public static void LevelUp(this PokemonSprite pkm)
        {
            Random rng       = new Random();
            var    species   = pkm.GetSpecies();
            var    baseStats = species.baseStats;

            pkm.Level += 1;

            //Up them stats
            pkm.MaxHP          = (int)Math.Ceiling((((baseStats["hp"] + rng.Next(0, 12)) + (Math.Sqrt((655535 / 100) * pkm.Level) / 4) * pkm.Level) / 100 + pkm.Level + 10));
            pkm.Attack         = CalcStat(baseStats["attack"], pkm.Level);
            pkm.Defense        = CalcStat(baseStats["defense"], pkm.Level);
            pkm.SpecialAttack  = CalcStat(baseStats["special-attack"], pkm.Level);
            pkm.SpecialDefense = CalcStat(baseStats["special-defense"], pkm.Level);
            pkm.HP             = pkm.MaxHP;
            pkm.Speed          = CalcStat(baseStats["speed"], pkm.Level);

            //Will it evolve!?
            var evolveLevel = species.evolveLevel;

            if (evolveLevel > 0)
            {
                if (evolveLevel == pkm.Level)
                {
                    //*GASP* IT'S GONNA EVOLVE
                    //Play an animation?
                    bool unnamed = (pkm.NickName == pkm.GetSpecies().name);

                    int newSpecies = int.Parse(species.evolveTo);
                    pkm.SpeciesId = newSpecies;
                    if (unnamed)
                    {
                        pkm.NickName = pkm.GetSpecies().name;
                    }
                }
            }
        }
Esempio n. 3
0
        private static int CalcXPReward(PokemonSprite winner, PokemonSprite loser)
        {
            var a   = 1;
            var b   = loser.GetSpecies().baseExperience;
            var L   = loser.Level;
            var s   = 1;
            var L_p = winner.Level;
            var t   = 1;
            //Give them all a lucky egg
            var e      = 1.5;
            var p      = 1;
            var result = (((a * b * L) / (5 * s)) * (Math.Pow(2 * L + 10, 2.5) / Math.Pow(L + L_p + 10, 2.5)) + 1) * t * e * p;

            return((int)Math.Ceiling(result));
        }
Esempio n. 4
0
        public static string PokemonString(this PokemonSprite pkm)
        {
            var species = pkm.GetSpecies();
            var str     = $"**Name**: {pkm.NickName}\n" +
                          $"**Spezies**: {species.name}\n{species.imageLink}\n" +
                          $"**HP**: {pkm.HP}\n" +
                          $"**Level**: {pkm.Level}\n" +
                          $"**XP**: {pkm.XP}/{pkm.XPRequired ()}\n" +
                          $"**Stats**\n" +
                          $"**Angriff:** {pkm.Attack}\n" +
                          $"**Verteidigung:** {pkm.Defense}\n" +
                          $"**Initiative:** {pkm.Speed}\n" +
                          "**Angriffe**:\n";

            foreach (var move in species.moves)
            {
                str += $"**{move.Key}** *{move.Value}*\n";
            }
            return(str);
        }
Esempio n. 5
0
        public static string PokemonMoves(this PokemonSprite pkm, bool justMoves = false)
        {
            var    species = pkm.GetSpecies();
            string str     = "";

            if (justMoves)
            {
                foreach (var move in species.moves)
                {
                    str += $"{move.Key}\n";
                }
            }
            else
            {
                foreach (var move in species.moves)
                {
                    str += $"**{move.Key}** *{move.Value}*\n";
                }
            }
            return(str);
        }
Esempio n. 6
0
        private async System.Threading.Tasks.Task <string> Attack(User attacker, User target, string moveString)
        {
            PokemonSprite attackerPokemon = ActivePokemon(attacker);
            string        returnstring    = "";
            var           species         = attackerPokemon.GetSpecies();

            if (!species.moves.Keys.Contains(moveString))
            {
                returnstring = $"Kann \"{moveString}\" nicht benutzen, benutze `{Prefix}ml` um eine Liste der Attacken zu sehen";
                return(returnstring);
            }
            var attackerStats = UserStats.GetOrAdd(attacker.Id, new TrainerStats());
            var defenderStats = UserStats.GetOrAdd(target.Id, new TrainerStats());

            if (attackerStats.MovesMade > TrainerStats.MaxMoves || attackerStats.LastAttacked.Contains(target.Id))
            {
                returnstring = $"{attacker.Mention} kann sich nicht bewegen!";
                return(returnstring);
            }
            if (attackerPokemon.HP == 0)
            {
                returnstring = $"{attackerPokemon.NickName} wurde besiegt und kann nicht angreifen!";
                return(returnstring);
            }
            var defenderPokemon = ActivePokemon(target);

            if (defenderPokemon.HP <= 0)
            {
                returnstring = $"{defenderPokemon.NickName} wurde bereits besiegt!";
                return(returnstring);
            }
            double p = 0.90 * attackerPokemon.Speed / defenderPokemon.Speed;

            //await e.Channel.SendMessage($"p: {p.ToString()} 1-p: {(1- p).ToString()}");
            if (rng.NextDouble() < (1 - p))
            {
                if (target.Id == MidnightBot.Creds.BotId)
                {
                    attackerStats.LastAttacked.Remove(target.Id);
                    attackerStats.MovesMade = 0;
                    UserStats.AddOrUpdate(attacker.Id, x => attackerStats, (s, t) => attackerStats);
                    UserStats.AddOrUpdate(target.Id, x => defenderStats, (s, t) => defenderStats);
                    DbHandler.Instance.Save(defenderPokemon);
                    DbHandler.Instance.Save(attackerPokemon);
                }
                else
                {
                    defenderStats.LastAttacked.Remove(target.Id);
                    attackerStats.LastAttacked.Add(target.Id);
                    attackerStats.MovesMade++;
                    defenderStats.LastAttacked = new List <ulong>();
                    defenderStats.MovesMade    = 0;
                    UserStats.AddOrUpdate(attacker.Id, x => attackerStats, (s, t) => attackerStats);
                    UserStats.AddOrUpdate(target.Id, x => defenderStats, (s, t) => defenderStats);
                    DbHandler.Instance.Save(defenderPokemon);
                    DbHandler.Instance.Save(attackerPokemon);
                }
                returnstring = $"{attackerPokemon.NickName}'s Attacke fehlgeschlagen!";
                return(returnstring);
            }

            KeyValuePair <string, string> move = new KeyValuePair <string, string> (moveString, species.moves[moveString]);

            PokemonAttack attack = new PokemonAttack(attackerPokemon, defenderPokemon, move);

            returnstring       += attack.AttackString();
            defenderPokemon.HP -= attack.Damage;

            var HP = (defenderPokemon.HP < 0) ? 0 : defenderPokemon.HP;

            returnstring += $"{defenderPokemon.NickName} hat {HP} HP über!\n";


            attackerStats.LastAttacked.Add(target.Id);
            attackerStats.MovesMade++;
            defenderStats.LastAttacked = new List <ulong>();
            defenderStats.MovesMade    = 0;
            UserStats.AddOrUpdate(attacker.Id, x => attackerStats, (s, t) => attackerStats);
            UserStats.AddOrUpdate(target.Id, x => defenderStats, (s, t) => defenderStats);
            DbHandler.Instance.Save(defenderPokemon);
            DbHandler.Instance.Save(attackerPokemon);
            if (defenderPokemon.HP <= 0)
            {
                defenderPokemon.HP = 0;

                if (target.Id != MidnightBot.Creds.BotId)
                {
                    returnstring += $"{defenderPokemon.NickName} wurde besiegt!\n{attackerPokemon.NickName}'s Besitzer {attacker.Mention} erhält 1 {MidnightBot.Config.CurrencySign}\n";
                }
                var lvl = attackerPokemon.Level;

                var extraXP = attackerPokemon.Reward(defenderPokemon);

                returnstring += $"{attackerPokemon.NickName} erhält {extraXP} von diesem Kampf\n";

                if (attackerPokemon.Level > lvl) //levled up
                {
                    returnstring += $"**{attackerPokemon.NickName}** ist aufgelevelt!\n**{attackerPokemon.NickName}** ist nun Level **{attackerPokemon.Level}**";
                    //Check evostatus
                }
                if (target.Id != MidnightBot.Creds.BotId)
                {
                    var list = PokemonList(target).Where(s => (s.HP > 0 && s != defenderPokemon));
                    if (list.Any())
                    {
                        var toSet = list.FirstOrDefault();
                        switch (SwitchPokemon(target, toSet))
                        {
                        case 0:
                        {
                            returnstring            += $"\n{target.Mention}'s aktives Pokemon auf **{toSet.NickName}** gesetzt";
                            defenderPokemon.IsActive = false;
                            break;
                        }

                        case 1:
                        case 2:
                        {
                            returnstring += $"\n **Error:** konnte Pokemon nicht austauschen";
                            break;
                        }
                        }
                    }
                    else
                    {
                        returnstring += $"\n{target.Mention} hat keine Pokemon über!";
                        returnstring += $"\n{attacker.Mention} erhält 3 {MidnightBot.Config.CurrencySign} für das Besiegen von {target.Mention}";
                        await FlowersHandler.AddFlowersAsync(attacker, $"Defeated {target.Mention} in pokemon!", 3);

                        //do something?
                    }
                }
                //await e.Channel.SendMessage(str);
                if (target.Id != MidnightBot.Creds.BotId)
                {
                    await FlowersHandler.AddFlowersAsync(attacker, "Victorious in pokemon", 1, true);
                }
            }

            //Update stats, you shall
            defenderStats.LastAttacked.Remove(target.Id);
            attackerStats.LastAttacked.Add(target.Id);
            attackerStats.MovesMade++;
            defenderStats.LastAttacked = new List <ulong>();
            defenderStats.MovesMade    = 0;
            UserStats.AddOrUpdate(attacker.Id, x => attackerStats, (s, t) => attackerStats);
            UserStats.AddOrUpdate(target.Id, x => defenderStats, (s, t) => defenderStats);
            DbHandler.Instance.Save(defenderPokemon);
            DbHandler.Instance.Save(attackerPokemon);
            if (defenderPokemon.HP == 0 && target.Id == MidnightBot.Creds.BotId)
            {
                var db  = DbHandler.Instance.GetAllRows <PokemonSprite> ();
                var row = db.Where(x => x.OwnerId == (long)MidnightBot.Creds.BotId);
                //var toDelete = DbHandler.Instance.FindAll<PokemonSprite>(s => s.OwnerId == (long)e.User.Id);
                foreach (var todel in row)
                {
                    DbHandler.Instance.Delete <PokemonSprite>(todel.Id.Value);
                }
                PokemonList(target, attackerPokemon.Level);
            }
            return(returnstring);
        }