예제 #1
0
    void BattleWork(object threadParams)
    {
        ThreadParams param = threadParams as ThreadParams;

        try
        {
            foreach (Battleground battleground in terrainManager.battlegrounds)
            {
                for (int i = param.startIndex; i <= param.endIndex; i++)
                {
                    foreach (Creature creatureB in population)
                    {
                        if (population[i] != creatureB)
                        {
                            BattleStats stats = BattleSimulation.Battle(population[i], creatureB, battleground);
                            stats.winner.fitnessValue++;
                            battles++;
                            requiresUIUpdate = true;
                        }
                    }
                }
            }
        }
        finally
        {
            param.currentHandle.Set();
        }
    }
    // Calculates the damage of a single attack or spell (including healing spells).
    static int CalcDamage(BattleStats attStats, BattleStats defStats = null, bool isPhysical = true)
    {
        // See above constants for Variance

        // if physical, use str, otherwise, use magic
        int attAbilityScore = isPhysical ? attStats.Strength : attStats.Magic;

        // 1 +/- DamageVariance per Str or Mag
        int attackDamage = Mathf.CeilToInt(Random.Range(1f - DamageVariance, 1f + DamageVariance) * attAbilityScore);


        // if defStats == null, there is 0 reduction
        int defDamage = 0;

        if (defStats != null)
        {
            // if physical, use def, otherwise, use resistance
            int defAbilityScore = isPhysical ? defStats.Defense : defStats.Resistance;

            // 0.5 +/- ReduceVariance damage reduction per def or res
            defDamage = Mathf.FloorToInt(Random.Range(1f - ReduceVariance, 1f + ReduceVariance) * defAbilityScore);
        }

        int output = Mathf.Max(attackDamage - defDamage, 1);

        return(output);
    }
예제 #3
0
        internal static async Task UserWonBattle(UserAccount userAccount, List <Rewardable> rewards,
                                                 BattleStats battleStats, ITextChannel lobbyChannel, ITextChannel battleChannel)
        {
            var oldLevel = userAccount.LevelNumber;

            userAccount.BattleStats += battleStats;
            _ = UnlockBattleClasses(userAccount, lobbyChannel);

            var awardStrings = rewards.Select(f => f.Award(userAccount)).Where(s => !s.IsNullOrEmpty()).ToList();

            if (awardStrings.Any())
            {
                _ = WriteAndDeleteRewards(awardStrings, battleChannel);
            }

            userAccount.ServerStats.ColossoWins++;
            userAccount.ServerStats.ColossoStreak++;
            userAccount.ServerStats.ColossoHighestStreak = Math.Max(userAccount.ServerStats.ColossoHighestStreak,
                                                                    userAccount.ServerStats.ColossoStreak);

            UserAccountProvider.StoreUser(userAccount);
            var newLevel = userAccount.LevelNumber;

            if (oldLevel != newLevel)
            {
                var user = (SocketGuildUser)await lobbyChannel.GetUserAsync(userAccount
                                                                            .Id); // Where(s => s. == userAccount.ID).First();

                Leveling.LevelUp(userAccount, user, (SocketTextChannel)lobbyChannel);
            }

            await Task.CompletedTask;
        }
예제 #4
0
    private void Start()
    {
        enemyStats = GameObject.FindGameObjectWithTag("Enemy").GetComponent <BattleStats>();
        Debug.Log(GameObject.FindGameObjectWithTag("Enemy").name + " found.");

        slider.value = enemyStats.currentHP;
    }
        /// <summary>
        /// Adds an Evasion modifier.
        /// </summary>
        /// <param name="evasionMod">The percentage change in decimal form. For example, .6 would indicate a 60% decrease in Evasion.</param>
        public void AddEvasionMod(double evasionMod)
        {
            BattleStats.EvasionModifiers.Add(evasionMod);
            BattleStats.CalculateTotalEvasionMod();

            Debug.Log($"Added evasion mod of {evasionMod}. Total evasion mod is now: {BattleStats.EvasionMod}");
        }
예제 #6
0
 public Species()
 {
     Name      = "defaultSpecies";
     Element   = new Element();
     BaseStats = new BattleStats();
     Image     = "defaultSpecies.jpg";
 }
        /// <summary>
        /// Removes an Accuracy modifier.
        /// </summary>
        /// <param name="accuracyMod">The percentage change in decimal form. For example, .6 would indicate a 60% decrease in Accuracy.</param>
        public void RemoveAccuracyMod(double accuracyMod)
        {
            BattleStats.AccuracyModifiers.Remove(accuracyMod);
            BattleStats.CalculateTotalAccuracyMod();

            Debug.Log($"Removed accuracy mod of {accuracyMod}. Total accuracy mod is now: {BattleStats.AccuracyMod}");
        }
예제 #8
0
 private void Start()
 {
     if (!Stats.IsPlayer)
     {
         Stats = Game.Enemy;
     }
 }
예제 #9
0
 // Constructors
 public Species(string name, Element element, BattleStats basestats, string image)
 {
     Name      = name;
     Element   = element;
     BaseStats = basestats;
     Image     = image;
 }
예제 #10
0
 private void CacheOwnerReferences(GameObject owner)
 {
     this.Owner      = owner;
     PCAnimator      = Owner.GetComponent <Animator>();
     BattleActorView = Owner.GetComponent <BattleActorView>();
     stats           = Owner.GetComponent <BaseBattleActor>().stats;
 }
예제 #11
0
    /// <summary>
    /// Adds a given BattleStats's values to itself, and deducts another if supplied.
    /// The most common scenario for this method is in donning (adding stats) and doffing
    /// (deducting stats) equipment, but the method is also used for Tomes, which have
    /// single-value BattleStats.
    /// </summary>
    /// <param name="addStats"></param>
    /// <param name="removeStats"></param>
    public void Equip(BattleStats addStats, BattleStats removeStats = null)
    {
        // Deduct existing equipment stats, if any, from self
        if (removeStats != null)
        {
            strength   -= removeStats.Strength;
            defense    -= removeStats.Defense;
            magic      -= removeStats.Magic;
            resistance -= removeStats.Resistance;
            stamina    -= removeStats.Stamina;
            agility    -= removeStats.Agility;

            // Derived stats use a "bonus", and are then calculated.
            UpdateMax(-removeStats.BaseHPMax, -removeStats.BaseMPMax);
            UpdateHitEvadeCrit(-removeStats.BaseHit, -removeStats.BaseEvade, -removeStats.CritChance);
        }

        // Add new equipment/tome stats to self
        strength   += addStats.Strength;
        defense    += addStats.Defense;
        magic      += addStats.Magic;
        resistance += addStats.Resistance;
        stamina    += addStats.Stamina;
        agility    += addStats.Agility;

        // Derived stats use a "bonus", and are then calculated.
        UpdateMax(addStats.BaseHPMax, addStats.BaseMPMax);
        UpdateHitEvadeCrit(addStats.BaseHit, addStats.BaseEvade, addStats.CritChance);
    }
예제 #12
0
        public DefenseCombatUnit(uint id,
                                 uint battleId,
                                 ITroopStub stub,
                                 FormationType formation,
                                 ushort type,
                                 byte lvl,
                                 ushort count,
                                 IBattleFormulas battleFormulas,
                                 Formula formula,
                                 UnitFactory unitFactory,
                                 IDbManager dbManager)
            : base(id, battleId, battleFormulas, dbManager)
        {
            troopStub      = stub;
            this.formation = formation;
            this.type      = type;
            this.count     = count;
            this.formula   = formula;
            this.lvl       = lvl;

            stats      = stub.Template[type];
            leftOverHp = stats.MaxHp;

            eachUnitUpkeep = unitFactory.GetUnitStats(type, lvl).Upkeep;
        }
예제 #13
0
 public void Explode(BattleStats target)
 {
     if (target == Player)
     {
         PlayerPrefs.SetFloat("PlayerXPos", -4);
         PlayerPrefs.SetFloat("PlayerZPos", 4);
         PlayerPrefs.SetInt("IsBoss", 0);
     }
     else if (PlayerPrefs.GetInt("IsBoss", 0) == 0)
     {
         PlayerPrefs.SetInt(PlayerPrefs.GetString("EnemyID"), 1);
         PlayerPrefs.SetInt("Kills", PlayerPrefs.GetInt("Kills", 0) + 1);
         if (PlayerPrefs.GetInt("Kills") >= 3)
         {
             PlayerPrefs.SetInt("Kills", 0);
             Player.Missed.Show("Level up");
             PlayerPrefs.SetInt("Level", PlayerPrefs.GetInt("Level", 0) + 1);
             Player.MaxHealth += 2;
             Player.MaxEnergy += 2;
             Player.Power     += 1;
             Player.Defense   += 1;
         }
         PlayerPrefs.SetString("PlayerStats", Player.ToString());
     }
     Instantiate(Boom, target.transform.position, Quaternion.identity).SetActive(true);
     Destroy(target.gameObject);
     count = DeathDelay;
 }
예제 #14
0
        public AttackCombatUnit(uint id,
                                uint battleId,
                                ITroopObject troopObject,
                                FormationType formation,
                                ushort type,
                                byte lvl,
                                ushort count,
                                UnitFactory unitFactory,
                                IBattleFormulas battleFormulas,
                                Formula formula,
                                ITileLocator tileLocator,
                                IDbManager dbManager)
            : base(id, battleId, battleFormulas, dbManager)
        {
            this.troopObject = troopObject;
            this.formation   = formation;
            this.type        = type;
            this.count       = count;
            this.formula     = formula;
            this.tileLocator = tileLocator;
            this.lvl         = lvl;

            stats          = troopObject.Stub.Template[type];
            LeftOverHp     = stats.MaxHp;
            eachUnitUpkeep = unitFactory.GetUnitStats(type, lvl).Upkeep;
        }
예제 #15
0
    /// <summary>
    /// A simplified version of Damage(), used for hero or enemy Fight attacks.
    /// Returns a Damage object (not an int), which contains 1 or more hits/misses,
    /// and info on whether each hit was a crit.
    /// </summary>
    /// <param name="attStats">BattleStats of the attacker</param>
    /// <param name="defStats">BattleStats of the defender</param>
    /// <returns></returns>
    public static Damage FightDamage(BattleStats attStats, BattleStats defStats)
    {
        // Calculate the number of hits
        int hits = CalcHitsOrMiss(attStats, defStats);

        // Create an empty Damage object
        Damage damage = new Damage();

        // If no hits, return a Damage with a single value of 0 to signify a miss
        if (hits <= 0)
        {
            damage.Add(0);
        }
        else
        {
            // Calculate a crit for each hit
            for (int i = 0; i < hits; i++)
            {
                //if (i > 1) { Debug.Log("Hit No. " + (i + 1)); }

                // CalcCrit(). If crit, increase the multiplier to 2
                bool isCrit         = false;
                int  critMultiplier = CalcCrit(attStats) ? 2 : 1;
                if (critMultiplier == 2)
                {
                    isCrit = true;
                    //Debug.Log("Critical");
                }

                // Adds the value of a crit-modified hit to the list in Damage
                damage.Add(CalcDamage(attStats, defStats) * critMultiplier, isCrit);
            }
        }
        return(damage);
    }
        /// <summary>
        /// Removes an Evasion modifier.
        /// </summary>
        /// <param name="evasionMod">The percentage change in decimal form. For example, .6 would indicate a 60% decrease in Evasion.</param>
        public void RemoveEvasionMod(double evasionMod)
        {
            BattleStats.EvasionModifiers.Remove(evasionMod);
            BattleStats.CalculateTotalEvasionMod();

            Debug.Log($"Removed evasion mod of {evasionMod}. Total evasion mod is now: {BattleStats.EvasionMod}");
        }
예제 #17
0
 public CombatStructure(uint id,
                        uint battleId,
                        IStructure structure,
                        BattleStats stats,
                        decimal hp,
                        ushort type,
                        byte lvl,
                        string theme,
                        Formula formula,
                        IActionFactory actionFactory,
                        IBattleFormulas battleFormulas,
                        ITileLocator tileLocator,
                        IRegionManager regionManager,
                        IDbManager dbManager)
     : base(id, battleId, battleFormulas, dbManager)
 {
     Structure          = structure;
     this.formula       = formula;
     this.actionFactory = actionFactory;
     this.tileLocator   = tileLocator;
     this.regionManager = regionManager;
     this.stats         = stats;
     this.hp            = hp;
     this.type          = type;
     this.lvl           = lvl;
     this.Theme         = theme;
 }
예제 #18
0
    // Calculates whether a single attack is a critical
    static bool CalcCrit(BattleStats attStats)
    {
        int  chance = Random.Range(0, (100 + 2 * attStats.CritChance));
        bool output = chance >= (100 - BaseCritChance) ? true : false;

        return(output);
    }
예제 #19
0
    public Status CreateStatusInstance(BattleStats curModifiedStats)
    {
        Status statusToCreate = Instantiate(this);//TODO: this may be creating scriptable objects that never get destroyed

        statusToCreate.stats = curModifiedStats;
        statusToCreate.SetModifiers();
        return(statusToCreate);
    }
예제 #20
0
    public BattleStats Copy()
    {
        BattleStats tempStats = new BattleStats();

        tempStats.basic    = basic;
        tempStats.modified = modified;
        return(tempStats);
    }
예제 #21
0
    virtual public void Hit(GameObject target, bool facingRight, bool fromCollsion)
    {
        BattleStats stats = target.GetComponent <BattleStats>();

        stats.health -= attacks[currentAttackIndex].damage;

        DefaultBattleScript targetBattleScript = target.gameObject.GetComponent <DefaultBattleScript>();

        if (stats.health == 0)
        {
            doubleHop = false;

            FindObjectOfType <BattleSceneManager>().RemoveEntity(targetBattleScript);

            if (target.gameObject.GetComponent <GreggBattleScript>())
            {
                GreggBattleScript enemy = target.gameObject.GetComponent <GreggBattleScript>();

                foreach (BattleMenu menu in FindObjectsOfType <BattleMenu>())
                {
                    menu.RemoveEnemy(enemy);
                }
            }

            targetBattleScript.currentState = States.DEAD;
        }
        else
        {
            targetBattleScript.currentState = States.ATTACKED;
        }

        if (currentCoroutine != null && fromCollsion)
        {
            StopCoroutine(currentCoroutine);
            currentCoroutine = null;
        }

        if (doubleHop)
        {
            rb.velocity = new Vector3(0.0f, hopHeight, rb.velocity.z);

            doubleHop = false;
        }
        else
        {
            if (fromCollsion)
            {
                rb.velocity = new Vector3(-moveSpeed, hopHeight / 2, rb.velocity.z);

                currentState = States.RETREAT;

                currentCoroutine = StartCoroutine(RetreatBehavior(facingRight));
            }

            target.gameObject.layer = targetBattleScript.initLayer;
        }
    }
예제 #22
0
        public void UseMagicLimitWorks()
        {
            //Given
            BattleStats bs = new BattleStats();
            bool        mg = bs.UseMagic(30);

            //Then
            Assert.False(mg);
        }
예제 #23
0
    protected override void Initialize()
    {
        base.Initialize();

        BattleStats.StatsChanged   += OnStatsChanged;
        BattleController.ClockTick += OnClockTick;
        battleStats = BattleRoot.BattleController.BattleStats;
        battleStats.ResetStats();
    }
    /// <summary>
    /// Builds a new BattleEnemy: name, stats, hp/mpMax.
    /// Other properties are set later with a call of LoadObjs.
    /// </summary>
    /// <param name="name">Name as EnemyName</param>
    /// <param name="stats">BattleStats is created outside this class and passed in</param>
    public BattleEnemy(EnemyName name, BattleStats stats)
    {
        enemyName = name;

        this.Stats = stats;

        hp = stats.HPMax;
        mp = stats.MPMax;
    }
예제 #25
0
    public BattleStats GetPlayerStats(CharacterType type, BattleStats currentStats)
    {
        if (playerStats.ContainsKey(type))
        {
            return(playerStats[type]);
        }

        playerStats.Add(type, currentStats);
        return(currentStats);
    }
예제 #26
0
 void Start()
 {
     if (GetComponent <BattleStats>())
     {
         battleStats = GetComponent <BattleStats>();
     }
     if (anim.Equals(null))
     {
         anim = transform.GetChild(0).GetComponent <Animator>();
     }
 }
예제 #27
0
 public HQ(Unit parent)
 {
     Parent = parent;
     Name   = "HQ-Abteilung";
     Stats  = new BattleStats();
     Stats.CurOrganisation = 25;
     Stats.MaxOrganisation = 25;
     Stats.CurStrength     = (int)UnitTypes.HQ;
     Stats.MaxStrength     = (int)UnitTypes.HQ;
     IsLinked = true;
 }
    // Cheat accessed through a cheatbutton. Turns the current hero into a super hero
    // by adding obscenely high values to its BattleStats.
    public void Click_Cheat_SuperHuman()
    {
        BattleStats stats = new BattleStats();

        int[] bonuses = new int[] { 2000, 2000, 500, 500, 500, 500,
                                    50, 50, 50, 50, 50, 0, 0 };
        stats.Import(bonuses);
        BattleLoader.Party.Hero[ID].BStats.Equip(stats);
        BattleLoader.Party.Hero[ID].HealAll();
        RefreshHeroStats();
    }
예제 #29
0
        public void AddExperienceWorks()
        {
            //Given
            BattleStats bs = new BattleStats();

            //When
            bool exp = bs.AddExperience(10);

            //Then
            Assert.False(exp);
        }
예제 #30
0
        public void CanBeConstructed()
        {
            //Given
            BattleStats bs = new BattleStats(5, 3, 8, 10, 10);

            //When
            int expected = 5;
            int actual   = bs.Speed;

            //Then
            Assert.True(expected == actual);
        }
예제 #31
0
        private static void Create_NewGame()
        {
            #region Prepare UI and get menu result

            ZConsoleMain.ClearScreen();
            Draw_Interface();
            Draw_Credits();
            var loadGameFileName = MainMenu();

            #endregion

            #region Create Galaxy, Player and all area handlers

            GameConfig.Reset();
            Galaxy = GalaxyModel.Create(GameConfig.CurrentGalaxySizeX, GameConfig.CurrentGalaxySizeY);
            Player = PlayerModel.Create();
            CurrentStarSystem.IsExplored = true;

            GalaxyMap	= new GalaxyMap(GalaxyArea, GameConfig.CurrentGalaxySizeX, GameConfig.CurrentGalaxySizeY);
            EventLog	= new EventLog(EventArea);
            ActionPanel	= new ActionPanel(ActionArea);
            PlayerStats = new PlayerStats(PlayerStatsArea);
            BattleStats	= new BattleStats(BattleStatsArea);
            EventLog.ClearArea();

            #endregion

            #region Load game or show Intro Text and get Player name

            if (!string.IsNullOrEmpty(loadGameFileName))
            {
                SaveLoad.LoadGame(loadGameFileName);
            }
            else
            {
                PrintIntroText();
                EventLog.Print("Common_EnterYourName");
                ZCursor.SetCursorVisibility(true);
                Player.Name = ZInput.ReadLine(2 + Lang["Common_EnterYourName"].Length, 7, 9, Color.Yellow, Color.Black, false, "Jameson");
                ZCursor.SetCursorVisibility(false);
            }

            #endregion

            #region Prepare UI, draw galaxy, etc.

            Draw_Controls(true);
            GlobalEvent.Create(Galaxy, CurrentStarSystem);
            ActionPanel.ClearArea();
            PlayerStats.Draw_PlayerStats();
            GalaxyMap.Draw_GalaxyMap();
            GalaxyMap.HighlightArea();
            EventLog.Print("Galaxy_ChooseSystem");

            #endregion
        }