public void Strike(Action <BattleAttributes> hitAction, BattleAttributes battleAttributes)
        {
            StrikePeriod = battleAttributes.strikePeriod;

            StartCoroutine(StrikePeriodCoroutine());

            StartCoroutine(HitEnemyCoroutine(hitAction, battleAttributes));
        }
 public void SetUI(BattleAttributes unit)
 {
     name.text = unit.name;
     level.text = "Level: " + unit.level;
     healthSlider.maxValue = unit.maxHealth;
     healthSlider.value = unit.currentHealth;
     expSlider.maxValue = unit.maxExp;
     expSlider.value = unit.currentExp;
 }
        protected void Strike(Action <BattleAttributes> strikeAction, BattleAttributes battleAttributes)
        {
            if (IsOnTheGround && CanStrike && !IsStriking)
            {
                StopRunning();
                AnimationController.SetIsNotRunning();

                AnimationController.PlayStrikeAnimation();

                BattleController.Strike(strikeAction, battleAttributes);
            }
        }
        public void EndPlayback()
        {
            this.SetDefaultPlaybackScale();
            if (this.timers != null)
            {
                int i   = 0;
                int num = this.timers.Length;
                while (i < num)
                {
                    this.timerManager.KillSimTimer(this.timers[i]);
                    i++;
                }
            }
            this.ScalePlaybackTime();
            this.eventManager.UnregisterObserver(this, EventId.BattleEndProcessing);
            this.eventManager.UnregisterObserver(this, EventId.EntityKilled);
            this.eventManager.SendEvent(EventId.BattleReplayEnded, null);
            if (BattleAttributes.Equals(this.playbackBattleAttr, this.recordBattleAttr))
            {
                Service.Get <StaRTSLogger>().Debug("Verified: Playback and Record matched.");
            }
            else
            {
                Service.Get <StaRTSLogger>().DebugFormat("PLAYBACK_MISMATCH!!! DamagePercentage, CreditsEarned, MaterialsEarned, ContrabandEarned, DeathLogCount, BattleEndedAt", new object[0]);
                Service.Get <StaRTSLogger>().DebugFormat("PLAYBACK_MISMATCH!!! We got: {0}, {1}, {2}, {3}, {4}, {5}", new object[]
                {
                    this.playbackBattleAttr.DamagePercentage,
                    this.playbackBattleAttr.LootCreditsEarned,
                    this.playbackBattleAttr.LootMaterialsEarned,
                    this.playbackBattleAttr.LootContrabandEarned,
                    this.playbackBattleAttr.DeathLogCount,
                    this.playbackBattleAttr.BattleEndedAt
                });
                Service.Get <StaRTSLogger>().DebugFormat("PLAYBACK_MISMATCH!!! We expect: {0}, {1}, {2}, {3}, {4}, {5}", new object[]
                {
                    this.recordBattleAttr.DamagePercentage,
                    this.recordBattleAttr.LootCreditsEarned,
                    this.recordBattleAttr.LootMaterialsEarned,
                    this.recordBattleAttr.LootContrabandEarned,
                    this.recordBattleAttr.DeathLogCount,
                    this.recordBattleAttr.BattleEndedAt
                });
            }
            string text  = this.playbackBattleAttr.ToJson();
            string text2 = this.recordBattleAttr.ToJson();

            Service.Get <StaRTSLogger>().Debug("playbackBattleAttr: " + text);
            Service.Get <StaRTSLogger>().Debug("recordBattleAttr: " + text2);
        }
 private void LoadPlayerData()
 {
     if (PlayerPrefs.HasKey("playerLevel"))
     {
         Debug.Log("loading player data");
         player.GetComponent <BattleAttributes>().SetAttributes("Player", PlayerPrefs.GetString("playerLevel")
                                                                , PlayerPrefs.GetInt("playerMaxHP"), PlayerPrefs.GetInt("playerCurrentHP")
                                                                , PlayerPrefs.GetInt("playerMaxXP"), PlayerPrefs.GetInt("playerCurrentXP")); // use this setter first before assigning
         playerAttributes = player.GetComponent <BattleAttributes>();
     }
     else
     {
         player.GetComponent <BattleAttributes>().SetAttributes("Player", "1", 100, 100, 100, 0); // first time battling
         playerAttributes = player.GetComponent <BattleAttributes>();
     }
 }
    // Start is called before the first frame update
    void Start()
    {
        rigidbody        = GetComponent <Rigidbody2D>();
        animator         = GetComponent <Animator>();
        myData           = GetComponent <BattleAttributes>();
        justExitedBattle = true;

        if (PlayerPrefs.HasKey("playerLevel"))
        {
            myData.SetAttributes("Player", PlayerPrefs.GetString("playerLevel")
                                 , PlayerPrefs.GetInt("playerMaxHP"), PlayerPrefs.GetInt("playerCurrentHP")
                                 , PlayerPrefs.GetInt("playerMaxXP"), PlayerPrefs.GetInt("playerCurrentXP"));
        }
        StartCoroutine(IdleScreen());
        // load player position if possible
        LoadPosition();
    }
        public void SingleEnemyStrike(BattleAttributes battleAttributes)
        {
            var damage = battleAttributes.damage;

            var attackedEnemies = TriggeredEnemies.Take(battleAttributes.attackedEnemiesAmount).ToList();

            float damageLoss = battleAttributes.splashDamageLossPercent;
            float multiplier = 0;

            foreach (var enemy in attackedEnemies)
            {
                float lostDamage  = damage * damageLoss * multiplier / 100;
                float finalDamage = damage - lostDamage;

                multiplier++;

                DamageEnemy(enemy, finalDamage);
            }
        }
Example #8
0
    IEnumerator StartBattle()
    {
        int battleEncounter = Random.Range(0, 3);

        Instantiate(enemy[battleEncounter], enemySpawn.position, Quaternion.identity);
        // LOAD ALL DATA
        LoadPlayerData();
        if (PlayerPrefs.HasKey("playerLevel"))
        {
            playerLvl = PlayerPrefs.GetString("playerLevel");
        }
        else
        {
            playerLvl = "1";
        }
        enemyAttributes = enemy[battleEncounter].GetComponent <BattleAttributes>();

        if (playerAttributes.level == "1") // only show available abilities
        {
            // hide all but attack/flee
            ability3.gameObject.SetActive(false);
            ability4.gameObject.SetActive(false);
        }
        if (playerAttributes.level == "2")
        {
            // hide last ability
            ability4.gameObject.SetActive(false);
        }

        dialogueText.text = "A wild " + enemyAttributes.name + " approaches!";

        // add ui elements
        playerUI.SetUI(playerAttributes);
        enemyUI.SetUI(enemyAttributes);

        yield return(new WaitForSeconds(2f));

        state = BattleState.PLAYERTURN;
        PlayerTurn();
    }
    IEnumerator StartBattle()
    {
        // LOAD ALL DATA
        LoadPlayerData();
        if (PlayerPrefs.HasKey("playerLevel"))
        {
            playerLvl = PlayerPrefs.GetString("playerLevel");
        }
        else
        {
            playerLvl = "1";
        }
        bossAttributes = boss.GetComponent <BattleAttributes>();

        if (playerAttributes.level == "1") // only show available abilities
        {
            // hide all but attack/flee
            ability3.gameObject.SetActive(false);
            ability4.gameObject.SetActive(false);
        }
        if (playerAttributes.level == "2")
        {
            // hide last ability
            ability4.gameObject.SetActive(false);
        }

        dialogueText.text = "A massive " + bossAttributes.name + " approaches! Careful, this is a boss!";

        // add ui elements
        playerUI.SetUI(playerAttributes);
        bossUI.SetUI(bossAttributes);

        yield return(new WaitForSeconds(2f));

        state = BattleState.PLAYERTURN;
        PlayerTurn();
    }
 public void StartPlayback()
 {
     this.SetDefaultPlaybackScale();
     Service.Get <UXController>().HUD.UpdateCurrentReplaySpeedUI();
     Service.Get <UXController>().HUD.ShowReplayTimer();
     this.battleController.PrepareWorldForBattle();
     Service.Get <EventManager>().SendEvent(EventId.EquipmentBuffShaderRemove, GameConstants.EQUIPMENT_SHADER_DELAY_REPLAY);
     this.battleController.StartBattle();
     this.eventManager.RegisterObserver(this, EventId.EntityKilled, EventPriority.Default);
     this.eventManager.RegisterObserver(this, EventId.BattleEndProcessing, EventPriority.Default);
     this.playbackBattleAttr = new BattleAttributes();
     this.recordBattleAttr   = this.CurrentBattleRecord.BattleAttributes;
     this.timers             = new uint[this.CurrentBattleRecord.BattleActions.Count];
     for (int i = 0; i < this.CurrentBattleRecord.BattleActions.Count; i++)
     {
         IBattleAction battleAction = this.CurrentBattleRecord.BattleActions[i];
         TimerDelegate callback;
         if (!this.actionCallbacks.TryGetValue(battleAction.ActionId, out callback))
         {
             callback = new TimerDelegate(this.DefaultActionCallback);
         }
         this.timers[i] = this.timerManager.CreateSimTimer(battleAction.Time + 1u, false, callback, battleAction);
     }
 }
        private IEnumerator HitEnemyCoroutine(Action <BattleAttributes> hitAction, BattleAttributes battleAttributes)
        {
            yield return(new WaitForSeconds(battleAttributes.hitDelay));

            hitAction.Invoke(battleAttributes);
        }