Exemplo n.º 1
0
    public DamageDetails TakeDamage(Move move, Nuzlon attacker)
    {
        //this is the damage magic. This is where you must look at the numbers to see how much damage moves should do
        float typeEffect = TypeChart.GetEffectiveness(move.Base.Type, this.Base.Type1) * TypeChart.GetEffectiveness(move.Base.Type, this.Base.Type2);

        DamageDetails details = new DamageDetails()
        {
            TypeEffect = typeEffect,
            Fainted    = false
        };

        float attack  = (move.Base.IsRanged) ? attacker.SpecialAttack : attacker.Attack;
        float defense = (move.Base.IsRanged) ? SpecialDefense : Defense;

        float modifiers = Random.Range(0.85f, 1f) * typeEffect;
        float a         = (2f * attacker.Level + 10f) / 50f;
        float d         = a * move.Base.Power * (attack / defense) + 2f;
        int   damage    = Mathf.FloorToInt(d * modifiers);

        CurrentHP -= damage;
        if (CurrentHP <= 0)
        {
            CurrentHP       = 0;
            details.Fainted = true;
        }
        return(details);
    }
Exemplo n.º 2
0
    public DamageDetails TakeDamage(Move move, Pokemon attacker)
    {
        float critical = 1f;

        if (UnityEngine.Random.value * 100f <= 6.25f)
        {
            critical = 2f;
        }

        float type = TypeChart.GetEffectiveness(move.Base.Type, this.Base.Type1) * TypeChart.GetEffectiveness(move.Base.Type, this.Base.Type2);

        var damageDetails = new DamageDetails()
        {
            Type     = type,
            Critical = critical,
            Fainted  = false
        };

        float attack  = (move.Base.IsSpecial) ? attacker.SpAttack : attacker.Attack; // aixo es com un if else pero mes curt
        float defense = (move.Base.IsSpecial) ? SpDefense : Defense;

        float modifiers = UnityEngine.Random.Range(0.85f, 1f) * type * critical;
        float a         = (2 * attacker.Level + 10) / 250f;
        float d         = a * move.Base.Power * ((float)attack / defense) + 2;
        int   damage    = Mathf.FloorToInt(d * modifiers);

        HP -= damage;
        if (HP <= 0)
        {
            HP = 0;
            damageDetails.Fainted = true; //pokemon = fainted
        }
        return(damageDetails);
    }
Exemplo n.º 3
0
    //function that deals damage
    public DamageDetails TakeDamage(Ability ability, Piece attacker)
    {
        // critcal hit
        float crit = 1f;

        if (Random.value * 100f <= 6.25f)
        {
            crit = 2f;
        }

        //gets type weakness
        float type = TypeChart.GetWeakness(ability.Base.Type, this.Base.Type1) * TypeChart.GetWeakness(ability.Base.Type, this.Base.Type2);


        var damageDetails = new DamageDetails()
        {
            TypeWeakness = type,
            Crit         = crit,
            Dead         = false
        };

        //checks if the move is ult or not
        float attack  = (ability.Base.Category == AbilityCategory.Ultimate) ? attacker.UltAttack : attacker.Attack;
        float defense = (ability.Base.Category == AbilityCategory.Ultimate) ? UltDefense : Defense;

        // damage formula
        float modifiers = Random.Range(0.85f, 1f) * type * crit;
        float a         = (2 * attacker.Level + 10) / 250f;
        float d         = a * ability.Base.Power * ((float)attack / defense) + 2;
        int   damage    = Mathf.FloorToInt(d * modifiers);

        DecreaseHP(damage);

        return(damageDetails);
    }
Exemplo n.º 4
0
 private void OnValidate()
 {
     if (chart != this)
     {
         chart = this;
     }
 }
Exemplo n.º 5
0
    public DamageDetails TakeDamage(Move move, Pokemon attacker)
    {
        float critical = 1f;

        if (Random.value * 100f <= 6.25f)
        {
            critical = 2f;
        }

        float type = TypeChart.GetEffectiveness(move.Base.Type, this.Base.Type1) * TypeChart.GetEffectiveness(move.Base.Type, this.Base.Type2);

        var damageDetails = new DamageDetails()
        {
            TypeEffectiveness = type,
            Critical          = critical,
            Fainted           = false
        };

        float attack  = (move.Base.Category == MoveCategory.Special) ? attacker.SpAttack : attacker.Attack;
        float defense = (move.Base.Category == MoveCategory.Special) ? SpDefense : Defense;

        float modifiers = Random.Range(0.85f, 1f) * type * critical;
        float a         = (2 * attacker.Level + 10) / 250f;
        float d         = a * move.Base.Power * ((float)attack / defense) + 2;
        int   damage    = Mathf.FloorToInt(d * modifiers);

        UpdateHP(damage);

        return(damageDetails);
    }
Exemplo n.º 6
0
        public IActionResult EditTypeChart(IDictionary <int, Matchup> Matchups)
        {
            ViewBag.User = context.GetOneUser(HttpContext.Session.GetInt32("UserId"));
            if (ViewBag.User == null)
            {
                return(RedirectToAction("Index", "Home", new { area = "Account" }));
            }
            foreach (KeyValuePair <int, Matchup> matchup in Matchups)
            {
                Matchup ExistingMatchup = context.GetOneMatchup(matchup.Key);
                if (ExistingMatchup == null)
                {
                    TempData["ErrorMessage"] = "One of the types couldn't be found anymore - perhaps it was deleted?";
                    return(RedirectToAction("EditTypeChart"));
                }
                ExistingMatchup.EffectivenessId = matchup.Value.EffectivenessId;
            }
            context.SaveChanges();
            TempData["SuccessMessage"] = "Type chart successfully updated!";
            TypeChart NewTypeChart = new TypeChart(Matchups, context);
            string    filelocation = Path.Combine(_env.WebRootPath + "\\jsondata\\typechart.json");

            FileIO.WriteAllText(filelocation, JsonConvert.SerializeObject(NewTypeChart));
            return(RedirectToAction("EditTypeChart"));
        }
Exemplo n.º 7
0
    public DamageDetails TakeDamage(Move move, Character attacker)
    {
        float critical = 1f;

        if (Random.value * 100f <= 6.25f)
        {
            critical = 2f;
        }

        float type = TypeChart.GetEffectiveness(move.Base.Type, this.Base.Type1) * TypeChart.GetEffectiveness(move.Base.Type, this.Base.Type2);

        var damageDetails = new DamageDetails()
        {
            TypeEffectiveness = type,
            Critical          = critical,
            Fainted           = false
        };

        float modifiers = Random.Range(0.85f, 1f) * type * critical;
        float a         = (2 * attacker.Level + 10) / 250f;
        float d         = a * move.Base.Power * ((float)attacker.Attack / Defense) + 2;
        int   damage    = Mathf.FloorToInt(d * modifiers);

        HP -= damage;
        if (HP <= 0)
        {
            HP = 0;
            damageDetails.Fainted = true;
        }

        return(damageDetails);
    }
Exemplo n.º 8
0
    public DamageInfo TakeDamage(Move move, Pokemon attacker)
    {
        AudioManager.instance.PlaySound("Hit");

        float atk = 1.0f;
        float def = 1.0f;

        if (move.Base.AtkType == AttackType.Physical)
        {
            atk = attacker.Attack;
            def = Defence;
        }
        else if (move.Base.AtkType == AttackType.Special)
        {
            atk = attacker.SpAtk;
            def = SpDef;
        }

        float crit = 1.0f;

        if (Random.value * 100.0f <= 4.167f)
        {
            crit = 2.0f;
        }

        float type = TypeChart.GetEffectiveness(move.Base.Type, this.Base.Type1) * TypeChart.GetEffectiveness(move.Base.Type, this.Base.Type2);

        var dmgInfo = new DamageInfo()
        {
            Critical          = crit,
            TypeEffectiveness = type,
            Faint             = false
        };

        float modifiers = Random.Range(0.85f, 1.0f) * type * crit;
        float a         = (attacker.level * 0.4f + 2);
        float d         = (a * move.Base.Power * (atk / def) * 0.02f) + 2;

        if (move.Base.Power == 0)
        {
            d = 0.0f;
        }
        int dmg = Mathf.FloorToInt(d * modifiers);

        hp -= dmg;

        if (hp <= 0)
        {
            hp            = 0;
            dmgInfo.Faint = true;
        }

        return(dmgInfo);
    }
Exemplo n.º 9
0
 /// <summary>
 /// Umwandlung in eine CSS-Klasse
 /// </summary>
 /// <param name="color">Die Farbe, welches umgewandelt werden soll</param>
 /// <returns>Die zum Layout gehörende CSS-KLasse</returns>
 public static string ToType(this TypeChart color)
 {
     return(color switch
     {
         TypeChart.Line => "line",
         TypeChart.Bar => "bar",
         TypeChart.Pie => "pie",
         TypeChart.Doughnut => "doughnut",
         TypeChart.Radar => "radar",
         _ => "line",
     });
Exemplo n.º 10
0
    //gets the attacker information from the attack sprite that hits the enemy, and then calculate the damage. method invoked from the Attack Effects script
    public void OutputDamage(string atkName, string atkType, int atkPower, float atkStat, int attackerLevel, float critChance, float criMod, Monster attacker, MonsterAttack monsterAttack)
    {
        if (monster.info.type2 == "none" || monster.info.type2 == null || monster.info.type2 == "")
        {
            if (GameManager.Instance.monstersData.typeChartDict.ContainsKey(atkType) && GameManager.Instance.monstersData.typeChartDict.ContainsKey(monster.info.type1))
            {
                float force = (((attackerLevel * 2) / 2) + 2) * atkPower * (atkStat / monster.info.Defense.Value);
                //float force = (((attackerLevel * 2) / 5) + 2) * atkPower * (atkStat / stats.def);
                //float resistance = 38 * (stats.def / atkStat);
                float resistance = 38 * (monster.info.Defense.Value / atkStat);

                TypeInfo  attacking = GameManager.Instance.monstersData.typeChartDict[atkType];
                TypeInfo  defending = GameManager.Instance.monstersData.typeChartDict[monster.info.type1];
                TypeChart attack    = new TypeChart(attacking, defending, force, resistance);

                DealDamage(attack, attack.typeModifier, attacker, critChance, criMod, monsterAttack);
            }
        }
        else
        {
            if (GameManager.Instance.monstersData.typeChartDict.ContainsKey(atkType) && GameManager.Instance.monstersData.typeChartDict.ContainsKey(monster.info.type1) && GameManager.Instance.monstersData.typeChartDict.ContainsKey(monster.info.type2))
            {
                float force = (((attackerLevel * 2) / 2) + 2) * atkPower * (atkStat / monster.info.Defense.Value);
                //float force = (((attackerLevel * 2) / 5) + 2) * atkPower * (atkStat / stats.def);
                //float resistance = 38 * (stats.def / atkStat);
                float resistance = 38 * (monster.info.Defense.Value / atkStat);
                float damageMod  = new float();


                for (int i = 0; i < 2; i++)
                {
                    if (i == 0)
                    {
                        TypeInfo  attacking = GameManager.Instance.monstersData.typeChartDict[atkType];
                        TypeInfo  defending = GameManager.Instance.monstersData.typeChartDict[monster.info.type1];
                        TypeChart attack    = new TypeChart(attacking, defending, force, resistance);
                        damageMod = attack.typeModifier;
                    }
                    else
                    {
                        TypeInfo  attacking = GameManager.Instance.monstersData.typeChartDict[atkType];
                        TypeInfo  defending = GameManager.Instance.monstersData.typeChartDict[monster.info.type2];
                        TypeChart attack    = new TypeChart(attacking, defending, force, resistance);
                        damageMod *= attack.typeModifier;
                        DealDamage(attack, damageMod, attacker, critChance, criMod, monsterAttack);
                    }
                }
            }
        }
    }
Exemplo n.º 11
0
    public Move GetAIMove(Pokemon target, int depth = 0)
    {
        //Test random Move
        int r = Random.Range(0, Moves.Count);

        if (TypeChart.GetEffectiveness(Moves[r].Base.Type, target.Base.Type1) >= 1.0f)
        {
            return(Moves[r]); // Move is Effective
        }
        else if (depth > 4)
        {
            return(Moves[r]); // Take it or leave it
        }
        else
        {
            return(GetAIMove(target, ++depth)); // Try Again
        }
    }
Exemplo n.º 12
0
    //this calculation is the same as the one preformed in a pokemon game, complicated. Yes.
    public DamageDetails TakeDamage(Move move, Creature attacker)
    {
        //crit hits happen only 6.25 percent of the time
        float critical = 1f;

        if (Random.value * 100f <= 6.25f)
        {
            critical = 2f;
        }

        //uses the type chart to get effectivenss of attacks
        float type = TypeChart.GetEffectiveness(move.Base.Type, this.Base.Type1) * TypeChart.GetEffectiveness(move.Base.Type, this.Base.Type2);

        var damageDetails = new DamageDetails()
        {
            TypeEffectiveness = type,
            Critical          = critical,
            Fainted           = false
        };

        //conditional operator, in place of an if else
        float attack  = (move.Base.Category == MoveCategory.Special) ? attacker.SpecialAttack : attacker.Attack;
        float defense = (move.Base.Category == MoveCategory.Special) ? SpecialDefense : Defense;

        //modifiers including random range, type bonus and critical bonus
        float modifiers = Random.Range(0.85f, 1f) * type * critical;
        float a         = (2 * attacker.Level + 10) / 250f;
        float d         = a * move.Base.Power * ((float)attack / defense) + 2;
        int   damage    = Mathf.FloorToInt(d * modifiers);

        //HP -= damage;
        //if(HP <= 0)
        //{
        //    HP = 0;
        //    damageDetails.Fainted = true;
        //}
        UpdateHP(damage);

        return(damageDetails);
    }
Exemplo n.º 13
0
    public DamageDetails TakeDamage(Move move, Pokemon attacker)
    {
        float affinityMultiplier = TypeChart.GetEffectivness(move.Base.Affinity, this.Base.Affinity);

        var damageDetails = new DamageDetails()
        {
            TypeEffectiveness = affinityMultiplier,
            Fainted           = false
        };

        int damageValue = (attacker.Base.BaseAttack + move.Base.Power) * Mathf.FloorToInt(affinityMultiplier);

        HP -= damageValue;

        if (HP <= 0)
        {
            HP = 0;
            damageDetails.Fainted = true;
        }

        return(damageDetails);
    }
Exemplo n.º 14
0
    public Move EnemyAtk(Pokemon playerPokemon)
    {
        PokemonType type1 = playerPokemon.Base.Type1;
        PokemonType type2 = playerPokemon.Base.Type2;

        List <MoveInfo> moveInfos = new List <MoveInfo>();

        foreach (var move in enemyUnit.Pokemon.Moves)
        {
            if (move.Base.AtkType != AttackType.StatChange)
            {
                MoveInfo info = new MoveInfo();
                info.move = move;
                info.typeEffectiveness = TypeChart.GetEffectiveness(move.Base.Type, type1) * TypeChart.GetEffectiveness(move.Base.Type, type2);
                moveInfos.Add(info);
            }
        }

        MoveInfo finalMove = new MoveInfo();

        finalMove = moveInfos[0];
        foreach (var moveInfo in moveInfos)
        {
            if (moveInfo.typeEffectiveness > finalMove.typeEffectiveness)
            {
                finalMove = moveInfo;
            }
            else if (moveInfo.typeEffectiveness == finalMove.typeEffectiveness)
            {
                if (moveInfo.move.Base.Power > finalMove.move.Base.Power)
                {
                    finalMove = moveInfo;
                }
            }
        }

        return(finalMove.move);
    }
Exemplo n.º 15
0
        public void EditTypeChart()
        {
            var path = Path.Combine(ROM.PathExeFS, "main");
            var data = FileMitm.ReadAllBytes(path);
            var nso  = new NSO(data);

            byte[] pattern = // N2nn3pia9transport18UnreliableProtocolE
            {
                0x4E, 0x32, 0x6E, 0x6E, 0x33, 0x70, 0x69, 0x61, 0x39, 0x74, 0x72, 0x61, 0x6E, 0x73, 0x70, 0x6F, 0x72,
                0x74, 0x31, 0x38, 0x55, 0x6E, 0x72, 0x65, 0x6C, 0x69, 0x61, 0x62, 0x6C, 0x65, 0x50, 0x72, 0x6F, 0x74,
                0x6F, 0x63, 0x6F, 0x6C, 0x45, 0x00
            };
            int ofs = CodePattern.IndexOfBytes(nso.DecompressedRO, pattern);

            if (ofs < 0)
            {
                WinFormsUtil.Alert("Not able to find type chart data in ExeFS.");
                return;
            }
            ofs += pattern.Length + 0x24; // 0x5B4C0C in lgpe 1.0 RO

            var cdata = new byte[18 * 18];
            var types = ROM.GetStrings(TextName.Types);

            Array.Copy(nso.DecompressedRO, ofs, cdata, 0, cdata.Length);
            var chart = new TypeChartEditor(cdata);

            using var editor = new TypeChart(chart, types);
            editor.ShowDialog();
            if (!editor.Modified)
            {
                return;
            }

            chart.Data.CopyTo(nso.DecompressedRO, ofs);
            data = nso.Write();
            FileMitm.WriteAllBytes(path, data);
        }
Exemplo n.º 16
0
    public DamageDetails TakeDamage(Move move, Pokemon attacker)
    {
        //Crtic hit prob
        float critical = 1f;

        if (Random.value * 100f <= criticalHitRate)
        {
            critical = 1.5f;
        }

        //Type efectivenes
        float type = TypeChart.GetEffectiveness(move.Base.Type, this.Base.Type1) * TypeChart.GetEffectiveness(move.Base.Type, this.Base.Type2);

        //STAB
        float stab = attacker.CalculateStab(move);

        float modifiers = Random.Range(0.85f, 1f) * type * critical * stab;

        var damageDetails = new DamageDetails()
        {
            Effectiveness = type,
            Critical      = critical,
            Fainted       = false
        };

        //Determinamos la categoría del movimiento:
        float attack  = (move.Base.Category == MoveCategory.Special) ? attacker.SpAttack : attacker.Attack;
        float defense = (move.Base.Category == MoveCategory.Special) ? attacker.SpDefense : attacker.Defense;

        //Formula real:
        float a      = ((2 * attacker.Level) / 5) + 2;
        float d      = ((a * move.Base.Power * (attack / defense)) / 50f) + 2;
        int   damage = Mathf.FloorToInt(d * modifiers);

        UpdateHP(damage);
        return(damageDetails);
    }
Exemplo n.º 17
0
    public DamageDetails TakeDamage(Move move, PokemonLevel attacker)
    {
        float criticalhit = 1.0f;

        if (Random.value * 100.0f <= 6.25)   // random value for critical hit
        {
            criticalhit = 2.0f;
        }

        float type = TypeChart.GetEffectiveness(move.Base.Type, this.Base.Type1) * TypeChart.GetEffectiveness(move.Base.Type, this.Base.Type2);

        var damageDetails = new DamageDetails()
        {
            TypeEffectiveness = type,
            Critical          = criticalhit,
            Fainted           = false
        };

        float attack  = (move.Base.Category == MoveCategory.Special)? attacker.SpAttack : attacker.Attack;
        float defense = (move.Base.Category == MoveCategory.Special) ? SpDefense : Defense;

        float modifiers = Random.Range(0.85f, 1.0f) * type * criticalhit;      // damage depend on the Level of the attacker // random range so that the damage is a lil bit different everytime
        float a         = (2 * attacker.Level + 10) / 250f;
        float d         = a * move.Base.Power * ((float)attack / defense) + 2; // depend the power of the move and the attack stats and the defense the pokemon.
        int   damage    = Mathf.FloorToInt(d * modifiers);

        UpdateHP(damage);

        //HP -= damage; // checking if the pokemon faint
        //if(HP <= 0)
        //{
        //    HP = 0;
        //    damageDetails.Fainted = true;
        //}

        return(damageDetails);
    }
Exemplo n.º 18
0
    public DamageDetails TakeDamage(Move move, Pokemon attacker)
    {
        float critical = 1f;

        if (Random.value * 100f <= 6.25f)
        {
            critical = 2f;
        }

        float type = TypeChart.GetEffectiveness(move.Base.GetType1(), this._base.GetType1()) * TypeChart.GetEffectiveness(move.Base.GetType1(), this._base.GetType2()) * TypeChart.GetEffectiveness(move.Base.GetType1(), this._base.GetType3());

        var damageDetails = new DamageDetails()
        {
            TypeEffectiveness = type,
            Critical          = critical,
            ko = false
        };

        float modifier = Random.Range(0.05f, 1f) * type * critical;
        float a        = (float)((0.4 * attacker.level) + 2);

        Debug.Log(a);
        float d = (float)(a * move.Base.GetPower() * (float)attacker.GetAttack() / (GetDefense() * 50)) + 2;

        Debug.Log(d);
        int damage = Mathf.FloorToInt(d * modifier);

        Debug.Log(damage);
        HP -= damage;
        if (HP <= 0)
        {
            HP = 0;
            damageDetails.ko = true;
        }
        return(damageDetails);
    }
Exemplo n.º 19
0
    //Called when hit a target
    public int TryMoveHit(TargetableElement target)
    {
        activeData.zBrokeProtect = false;
        bool hitResult = true;

        if (battle.SingleEvent("Try", activeData.moveData, null, source.targetScript, target.sourceElement, activeData.moveData).getEndEvent())
        {
            return(-1);
        }

        //Affecting directly to a side o to the field
        if (target.teamTarget != null || target.battleTarget != null)
        {
            if (target.battleTarget != null)
            {
                hitResult = !battle.RunEvent("TryHitField", target, source, activeData.moveData).getEndEvent();
            }
            else
            {
                hitResult = !battle.RunEvent("TryHitSide", target, source, activeData.moveData).getEndEvent();
            }

            if (!hitResult)
            {
                return(-1);
            }

            return(MoveHit(target));
        }

        //Immunity
        hitResult = !battle.RunEvent("TryImmunity", target, source, activeData.moveData).getEndEvent();
        if (!hitResult)
        {
            return(-1);
        }

        if (activeData.moveData.ignoreImmunity == "")
        {
            activeData.moveData.ignoreImmunity = (activeData.moveData.category == Globals.MoveCategory.Status) ? "All" : "";
        }

        //TryHit
        hitResult = !battle.RunEvent("TryHit", target, source, activeData.moveData).getEndEvent();
        if (!hitResult)
        {
            return(-1);
        }

        //Immunity
        if (((PokemonCharacter)target.sourceElement).pokemonData.HasImmunity(activeData.moveType) &&
            activeData.moveData.ignoreImmunity == "")
        {
            return(-1);
        }

        //Powder Immunity
        if (target.sourceElement is PokemonCharacter && (activeData.moveData.flags & Globals.MoveFlags.Powder) != 0 &&
            target != source.targetScript && TypeChart.HasImmunity("powder", ((PokemonCharacter)target.sourceElement).pokemonData.types))
        {
            return(-1);
        }

        //Prankster Immunity
        if (activeData.pranksterBoosted && target.sourceElement is PokemonCharacter && source.pokemonData.HasAbilityActive(new string[] { "prankster" }) &&
            ((PokemonCharacter)target.sourceElement).pokemonData.team != source.pokemonData.team &&
            TypeChart.HasImmunity("prankster", ((PokemonCharacter)target.sourceElement).pokemonData.types)
            )
        {
            return(-1);
        }

        //Now it surely hits!!!

        //Breaks protect
        if (activeData.moveData.breaksProtect)
        {
            //Remove ShieldVolatiles
            //Remove ShieldConditions
        }

        //StealsBoosts
        if (activeData.moveData.stealsBoosts && target.sourceElement is PokemonCharacter)
        {
            Globals.BoostsTable boosts = ((PokemonCharacter)target.sourceElement).pokemonData.boosts.ShallowCopy();
            boosts.ClearNegatives();
            if (boosts.HasPositiveBoosts())
            {
                battle.Boost(boosts, source.targetScript, source);
                ((PokemonCharacter)target.sourceElement).pokemonData.SetBoosts(boosts);
            }
        }

        //If MultiHit (here?)

        //Else
        int damage = MoveHit(target);

        activeData.totalDamage += damage;

        //set to target gotAttacked
        if ((target.sourceElement is PokemonCharacter) && source.pokemonData != ((PokemonCharacter)target.sourceElement).pokemonData)
        {
            ((PokemonCharacter)target.sourceElement).pokemonData.GotAttacked(activeData.moveId, damage, source);
        }

        //return if no damage
        if (damage < 0)
        {
            return(damage);
        }

        //eachevent update
        battle.EventForActives("Update");

        //Secondary events
        if ((target.sourceElement is PokemonCharacter) && !activeData.negateSecondary && !(activeData.hasSheerForce /*&& source.pokemonData.HasAbilityActive(new string[] { "sheerforce" })*/))
        {
            battle.SingleEvent("AfterMoveSecondary", activeData.moveData, null, target, source, activeData.moveData);
            battle.RunEvent("AfterMoveSecondary", target, source, activeData.moveData);
        }

        return(damage);
    }
Exemplo n.º 20
0
    static void LoadPokeInfoFromJson()
    {
        try
        {
            PokeData pokeData = (PokeData)AssetDatabase.LoadAssetAtPath(PokeDataObjPath, typeof(PokeData));

            #region Fill Type Chart
            TextAsset typeChartJsonString = (TextAsset)AssetDatabase.LoadAssetAtPath(JsonPath + TypeChartJsonName, typeof(TextAsset));

            PokeTypeChartJson typeChartJson = JsonUtility.FromJson <PokeTypeChartJson>(typeChartJsonString.text);
            TypeChart         typeChart     = pokeData.TypeChart = new TypeChart(typeChartJson.TypeChart.Length);

            for (int i = 0; i < typeChart.TypeParameters.Length; i++)
            {
                TypeParameter typeParam = typeChart.TypeParameters[i] = new TypeParameter();

                typeParam.BaseType = (PokeType)Enum.Parse(typeof(PokeType), typeChartJson.TypeChart[i].Type);

                if (!string.IsNullOrEmpty(typeChartJson.TypeChart[i].Strenghts))
                {
                    string[] strenghtsString = typeChartJson.TypeChart[i].Strenghts.Split(new[] { ", " }, StringSplitOptions.None);
                    typeParam.StrenghtsTypes = new PokeType[strenghtsString.Length];
                    for (int j = 0; j < typeParam.StrenghtsTypes.Length; j++)
                    {
                        typeParam.StrenghtsTypes[j] = (PokeType)Enum.Parse(typeof(PokeType), strenghtsString[j]);
                    }
                }

                if (!string.IsNullOrEmpty(typeChartJson.TypeChart[i].Weaknesses))
                {
                    string[] weaksString = typeChartJson.TypeChart[i].Weaknesses.Split(new[] { ", " }, StringSplitOptions.None);
                    typeParam.WeaknessesTypes = new PokeType[weaksString.Length];
                    for (int j = 0; j < typeParam.WeaknessesTypes.Length; j++)
                    {
                        typeParam.WeaknessesTypes[j] = (PokeType)Enum.Parse(typeof(PokeType), weaksString[j]);
                    }
                }
            }
            #endregion

            #region Load Primary Moves
            TextAsset            primaryMovesJsonString = (TextAsset)AssetDatabase.LoadAssetAtPath(JsonPath + PrimaryMovesJsonName, typeof(TextAsset));
            PrimaryMovesDataJson primaryMovesDataJson   = JsonUtility.FromJson <PrimaryMovesDataJson>(primaryMovesJsonString.text);

            pokeData.PrimaryMoves = new PrimaryMove[primaryMovesDataJson.PrimaryMoves.Length];
            for (int i = 0; i < primaryMovesDataJson.PrimaryMoves.Length; i++)
            {
                PrimaryMove      primaryMove      = pokeData.PrimaryMoves[i] = new PrimaryMove();
                PrimaryMovesJson primaryMovesJson = primaryMovesDataJson.PrimaryMoves[i];

                primaryMove.Name       = primaryMovesJson.Name;
                primaryMove.Type       = (PokeType)Enum.Parse(typeof(PokeType), primaryMovesJson.Type);
                primaryMove.Attack     = primaryMovesJson.Atk;
                primaryMove.Cooldown   = primaryMovesJson.Cooldown;
                primaryMove.Dps        = primaryMovesJson.DPS;
                primaryMove.EnergyGain = primaryMovesJson.EnergyGain;

                primaryMove.StrongAgaints = pokeData.TypeChart.GetStrenghts(primaryMove.Type);
                primaryMove.WeakAgains    = pokeData.TypeChart.GetWeaknesses(primaryMove.Type);
            }
            #endregion

            #region Load Secondary Moves
            TextAsset secondaryMovesJsonString            = (TextAsset)AssetDatabase.LoadAssetAtPath(JsonPath + SecondaryMovesJsonName, typeof(TextAsset));
            SecondaryMovesDataJson secondaryMovesDataJson = JsonUtility.FromJson <SecondaryMovesDataJson>(secondaryMovesJsonString.text);

            pokeData.SecondaryMoves = new SecondaryMove[secondaryMovesDataJson.SecondaryMoves.Length];
            for (int i = 0; i < secondaryMovesDataJson.SecondaryMoves.Length; i++)
            {
                SecondaryMove      secMove     = pokeData.SecondaryMoves[i] = new SecondaryMove();
                SecondaryMovesJson secMoveJson = secondaryMovesDataJson.SecondaryMoves[i];

                secMove.Name        = secMoveJson.Name;
                secMove.Type        = (PokeType)Enum.Parse(typeof(PokeType), secMoveJson.Type);
                secMove.ChargeCount = Mathf.Clamp(secMoveJson.ChargeCount, 1, 5);
                secMove.Attack      = secMoveJson.Atk;
                secMove.Cooldown    = secMoveJson.Cooldown;
                secMove.Dps         = secMoveJson.DPS;
                secMove.CritChance  = secMoveJson.CritChance;
                secMove.DidgeWindow = secMoveJson.DodgeWindow;

                secMove.StrongAgaints = pokeData.TypeChart.GetStrenghts(secMove.Type);
                secMove.WeakAgains    = pokeData.TypeChart.GetWeaknesses(secMove.Type);
            }
            #endregion

            #region Load Pokemons
            TextAsset    pokemonsJsonString = (TextAsset)AssetDatabase.LoadAssetAtPath(JsonPath + PokemonsJsonName, typeof(TextAsset));
            PokeDataJson pokeDataJson       = JsonUtility.FromJson <PokeDataJson>(pokemonsJsonString.text);

            pokeData.PokeInfos = new PokeInfo[pokeDataJson.Pokemons.Length];
            for (int i = 0; i < pokeDataJson.Pokemons.Length; i++)
            {
                PokeInfo     pokeInfo     = pokeData.PokeInfos[i] = new PokeInfo();
                PokeInfoJson pokeInfoJson = pokeDataJson.Pokemons[i];
                pokeInfoJson.Name = Regex.Replace(pokeInfoJson.Name, @"\p{Z}", "");

                pokeInfo.Name = pokeInfoJson.Name;
                pokeInfo.Id   = i + 1;

                #region Fill Type
                string[] pokeTypesJson = pokeInfoJson.Type.Split(new[] { ", " }, StringSplitOptions.None);
                pokeInfo.Type = new PokeType[pokeTypesJson.Length];

                for (int j = 0; j < pokeTypesJson.Length; j++)
                {
                    pokeTypesJson[j] = pokeTypesJson[j].Replace(" ", string.Empty);
                    pokeInfo.Type[j] = (PokeType)Enum.Parse(typeof(PokeType), pokeTypesJson[j]);
                }
                #endregion

                pokeInfo.Weight         = pokeInfoJson.Weight;
                pokeInfo.Height         = pokeInfoJson.Height;
                pokeInfo.MaxCp          = pokeInfoJson.MaxCp;
                pokeInfo.CpMultiFromEvo = pokeInfoJson.EvoCpMulti;
                pokeInfo.BaseAttack     = pokeInfoJson.BaseAttack;
                pokeInfo.BaseDefense    = pokeInfoJson.BaseDefense;
                pokeInfo.BaseStamina    = pokeInfoJson.BaseStamina;
                pokeInfo.BaseHp         = pokeInfoJson.BaseHP;
                pokeInfo.Rarity         = pokeInfoJson.Rarity;
                pokeInfo.CaptureRate    = pokeInfoJson.CaptureRate;
                pokeInfo.FleeRate       = pokeInfoJson.FleeRate;
                pokeInfo.Class          = (PokeClass)Enum.Parse(typeof(PokeClass), pokeInfoJson.Class);
                pokeInfo.CandyToEvolve  = pokeInfoJson.CandyToEvolve;

                int eggDistance = 0;
                if (int.TryParse(pokeInfoJson.EggDistanceToHatch.Replace("km", string.Empty), out eggDistance))
                {
                    pokeInfo.EggDistanceType = (EggType)eggDistance;
                }

                #region Fill Primary Moves
                string[] primaryMovesString = pokeInfoJson.PossiblePrimaryMoves.Split(new[] { ", " }, StringSplitOptions.None);

                pokeInfo.PrimaryMovesIds = new int[primaryMovesString.Length];
                for (int j = 0; j < pokeInfo.PrimaryMovesIds.Length; j++)
                {
                    pokeInfo.PrimaryMovesIds[j] = pokeData.GetPrimaryMoveId(primaryMovesString[j]);
                }
                #endregion

                #region Fill Secondary Moves
                string[] secondaryMovesString = pokeInfoJson.PossibleSecondaryMoves.Split(new[] { ", " }, StringSplitOptions.None);

                pokeInfo.SecondaryMovesIds = new int[secondaryMovesString.Length];
                for (int j = 0; j < pokeInfo.SecondaryMovesIds.Length; j++)
                {
                    pokeInfo.SecondaryMovesIds[j] = pokeData.GetSecondaryMoveId(secondaryMovesString[j]);
                }
                #endregion

                pokeInfo.Resistance = pokeData.TypeChart.GetResistance(pokeInfo.Type);
                pokeInfo.Weaknesses = pokeData.TypeChart.GetWeaknesses(pokeInfo.Type);
            }

            #region Fill Evo FromTo
            for (int i = 0; i < pokeData.PokeInfos.Length; i++)
            {
                PokeInfo     pokeInfo     = pokeData.PokeInfos[i];
                PokeInfoJson pokeInfoJson = pokeDataJson.Pokemons[i];

                if (!string.IsNullOrEmpty(pokeInfoJson.EvoFrom))
                {
                    pokeInfo.EvoFromId = pokeData.GetPokeInfoIdByName(Regex.Replace(pokeInfoJson.EvoFrom, @"\p{Z}", ""));
                }
                else
                {
                    pokeInfo.EvoFromId = -1;
                }
                if (!string.IsNullOrEmpty(pokeInfoJson.EvoTo))
                {
                    pokeInfo.EvoToId = pokeData.GetPokeInfoIdByName(Regex.Replace(pokeInfoJson.EvoTo, @"\p{Z}", ""));
                }
                else
                {
                    pokeInfo.EvoToId = -1;
                }
            }
            #endregion

            Debug.Log("Loading complete!");
            #endregion

            #region Fill Pokemon stats Rates
            Vector3 maxStatsRates = Vector3.zero; //x-Attack, y-Defense, z-Hp
            for (int i = 0; i < pokeData.PokeInfos.Length; i++)
            {
                PokeInfo pInfo = pokeData.PokeInfos[i];
                if (pInfo.BaseAttack > maxStatsRates.x)
                {
                    maxStatsRates.x = pInfo.BaseAttack;
                }
                if (pInfo.BaseDefense > maxStatsRates.y)
                {
                    maxStatsRates.y = pInfo.BaseDefense;
                }
                if (pInfo.BaseStamina > maxStatsRates.z)
                {
                    maxStatsRates.z = pInfo.BaseStamina;
                }
            }

            for (int i = 0; i < pokeData.PokeInfos.Length; i++)
            {
                PokeInfo pInfo = pokeData.PokeInfos[i];
                pInfo.AttackRate  = (float)pInfo.BaseAttack / maxStatsRates.x;
                pInfo.DefenseRate = (float)pInfo.BaseDefense / maxStatsRates.y;
                pInfo.StaminaRate = (float)pInfo.BaseStamina / maxStatsRates.z;
            }
            #endregion

            #region Fill Move stats Rates
            Vector3 maxMoveRates = Vector3.zero; //x-Attack, y-Cooldown, z-DPS

            //Primary
            for (int i = 0; i < pokeData.PrimaryMoves.Length; i++)
            {
                PrimaryMove move = pokeData.PrimaryMoves[i];
                if (move.Attack > maxMoveRates.x)
                {
                    maxMoveRates.x = move.Attack;
                }
                if (move.Cooldown > maxMoveRates.y)
                {
                    maxMoveRates.y = move.Cooldown;
                }
                if (move.Dps > maxMoveRates.z)
                {
                    maxMoveRates.z = move.Dps;
                }
            }

            for (int i = 0; i < pokeData.PrimaryMoves.Length; i++)
            {
                PrimaryMove move = pokeData.PrimaryMoves[i];
                move.AttackRate   = (float)move.Attack / maxMoveRates.x;
                move.CooldownRate = (float)move.Cooldown / maxMoveRates.y;
                move.DpsRate      = (float)move.Dps / maxMoveRates.z;
            }

            //Secondary
            maxMoveRates = Vector3.zero;
            for (int i = 0; i < pokeData.SecondaryMoves.Length; i++)
            {
                SecondaryMove move = pokeData.SecondaryMoves[i];
                if (move.Attack > maxMoveRates.x)
                {
                    maxMoveRates.x = move.Attack;
                }
                if (move.Cooldown > maxMoveRates.y)
                {
                    maxMoveRates.y = move.Cooldown;
                }
                if (move.Dps > maxMoveRates.z)
                {
                    maxMoveRates.z = move.Dps;
                }
            }

            for (int i = 0; i < pokeData.SecondaryMoves.Length; i++)
            {
                SecondaryMove move = pokeData.SecondaryMoves[i];
                move.AttackRate   = (float)move.Attack / maxMoveRates.x;
                move.CooldownRate = (float)move.Cooldown / maxMoveRates.y;
                move.DpsRate      = (float)move.Dps / maxMoveRates.z;
            }
            #endregion

            EditorUtility.SetDirty(pokeData);
            Debug.Log("Loading Poke info complete!");
        }
        catch (Exception)
        {
            Debug.LogError("Error while loading data from json");
            throw;
        }
    }
Exemplo n.º 21
0
 private void Awake()
 {
     chart = this;
 }
Exemplo n.º 22
0
    //when the attack animation hits the enemy, deal the damage. this method is invoked from the AttackEffects script. Also gives information about the attacking monster, so if an enemy is destroyed, it can tell which monster destroyed it
    public void DealDamage(TypeChart atk, float damageMod, Monster attacker, float critChance, float critMod, MonsterAttack attack)
    {
        var statuses = GameManager.Instance.GetComponent <AllStatusEffects>().allStatusDict;

        float damageTaken = Mathf.Round(atk.totalDamage * damageMod);

        if (damageTaken <= 0)
        {
            damageTaken = 1;
        }

        float critRand   = Random.Range(0f, 100f);
        float rand       = Random.Range(0f, 100f);
        float statusRand = Random.Range(0f, 100f);


        //check to see if the attack misses by comparing the enemies' dodge stat with a number from 1-100. if the enemy dodges, deal 0 damage and spawn the word DODGE instead of a damage value
        if (rand >= monster.info.evasionBase)
        {
            monster.monsterMotion.SetBool("isHit", true);
            monster.monsterMotion.GetComponent <MotionControl>().IsHit(attack);



            //check and see if the attack is a critical hit, and if so, change the damage output and color of the font to indicate a crit
            if (critRand <= critChance)
            {
                damageTaken = damageTaken * (1 + critMod);
                //spawn the box to display damage done and change the properties
                var damage = Instantiate(damageText, transform.position, Quaternion.identity);
                damage.transform.SetParent(enemyCanvas.transform, false);
                damage.transform.position = new Vector3(transform.position.x, transform.position.y, 1f);
                damage.GetComponentInChildren <TMP_Text>().text  = "-" + damageTaken + "!";
                damage.GetComponentInChildren <TMP_Text>().color = Color.yellow;
                Destroy(damage, damage.GetComponent <Animator>().GetCurrentAnimatorStateInfo(0).length);
            }
            else
            {
                //spawn the box to display damage done and change the properties to signify a critical hit
                var damage = Instantiate(damageText, transform.position, Quaternion.identity);
                damage.transform.SetParent(enemyCanvas.transform, false);
                damage.transform.position = new Vector3(transform.position.x, transform.position.y, 1f);
                damage.GetComponentInChildren <TMP_Text>().text = "-" + damageTaken.ToString();
                Destroy(damage, damage.GetComponent <Animator>().GetCurrentAnimatorStateInfo(0).length);
            }


            //if the attack hits and it has a chance to inflict a secondary status, that is calculated here
            if (attack.effectName != "none")
            {
                if (statusRand <= attack.effectChance * 100)
                {
                    //checks if the monster is already inflicted with this status. if they are not, then the monster is now inflicted.
                    if (statuses.ContainsKey(attack.effectName))
                    {
                        if (monster.statuses.Contains(statuses[attack.effectName]))
                        {
                            //
                        }
                        else
                        {
                            monster.AddStatus(statuses[attack.effectName]);
                        }
                    }
                }
            }
        }
        else
        {
            monster.monsterMotion.SetBool("isDodge", true);

            //spawn the box to display damage done and change the properties to "DODGE" if the enemy succesfully evades
            var damage = Instantiate(damageText, transform.position, Quaternion.identity);
            damage.transform.SetParent(enemyCanvas.transform, false);
            damage.transform.position = new Vector3(transform.position.x, transform.position.y, 1f);
            damage.GetComponentInChildren <TMP_Text>().text = "Dodge!";
            Destroy(damage, damage.GetComponent <Animator>().GetCurrentAnimatorStateInfo(0).length);
            damageTaken = 0;
        }



        //call this to actually deal the damage afer its been calculated
        TakeDamage(damageTaken, attacker);
    }
Exemplo n.º 23
0
 //gotten from the Enemy script
 public void Damage(TypeChart attack, Monster target)
 {
     enemy = target;
     attackInfo = attack;
 }