コード例 #1
0
        private void OnTriggerEnter(Collider otherObject)
        {
            // We're only concerned with triggers.
            if (!otherObject.isTrigger)
            {
                return;
            }

            if (otherObject.tag == "Combatant")
            {
                if (this.combatant is PlayerCombatant)
                {
                    EnemyCombatant enemy = otherObject.GetComponent <EnemyCombatant>();

                    if (enemy != null)
                    {
                        this.combatantInRange = enemy;
                        trigger.Invoke();
                    }
                }
                else if (this.combatant is EnemyCombatant)
                {
                    PlayerCombatant player = otherObject.GetComponent <PlayerCombatant>();

                    if (player != null)
                    {
                        this.combatantInRange = player;
                        trigger.Invoke();
                    }
                }
            }
        }
コード例 #2
0
    public async Task OnEnemySelectedForBashingAsync(EnemyCombatant enemy)
    {
        var battleAction = characters[characterIndex].Bash(enemy);

        battleActions.Add(battleAction);
        await RunBattleAsync();
    }
コード例 #3
0
    public void AssignEnemy(EnemyCombatant enemy)
    {
        Enemy = enemy;
        var image = GetComponent <Image>();

        image.overrideSprite = Resources.Load <Sprite>(enemy.BattleSpriteName);
        image.SetNativeSize();
    }
コード例 #4
0
    private async Task ExecuteEnemyAction(EnemyCombatant enemy)
    {
        var battleAction = enemy.AutoFight(combatants);
        await dialogManager.DisplayActionAttemptAsync(battleAction);

        await dialogManager.DisplayActionResultAsync(battleAction);

        // TODO Handle impact to character hitpoints, etc.
    }
コード例 #5
0
    public void InitializeCombat(EnemyCombatant Combatant)
    {
        BattleCanvas.enabled = true;

        EnemyCombatant = Combatant;
        UpdateHealth(PlayerHealthBar, Player.GetHealth());
        UpdateHealth(EnemyHealthBar, EnemyCombatant.GetHealth());

        ProblemManager.Init(EnemyCombatant);
    }
コード例 #6
0
    public BattleAction Bash(EnemyCombatant enemy)
    {
        var battleAction = new BattleAction
        {
            Performer        = this,
            Target           = enemy,
            BattleActionType = BattleActionType.Bash,
            ActionName       = "Bash"
        };

        return(battleAction);
    }
コード例 #7
0
ファイル: Battlefield.cs プロジェクト: tylermwatts/EB-Clone
    private void InstantiateBattleEnemy(EnemyCombatant enemy)
    {
        var battleEnemyGameObject = Instantiate <GameObject>(battleEnemyPrefab);

        battleEnemyGameObject.transform.SetParent(transform, false);
        battleEnemyGameObject.transform.localScale = Vector3.one;

        var battleEnemy = battleEnemyGameObject.GetComponent <BattleEnemy>();

        battleEnemy.AssignEnemy(enemy);

        var button = battleEnemyGameObject.GetComponent <Button>();

        button.enabled = false;
    }
コード例 #8
0
        private void Start()
        {
            // Get the player party from the data repository.
            Party playerParty = DataRepository.Instance().Parties.GetByName("main");

            List <GameObject> players = new List <GameObject>();
            List <GameObject> enemies = new List <GameObject>();

            foreach (string partyMember in playerParty.Members)
            {
                // We want to spawn a combatant for each player in the party.
                GameObject      playerCombatant = Instantiate((GameObject)Resources.Load(string.Format("Prefabs/Battle/Characters/{0}", partyMember)), this.transform.parent);
                PlayerCombatant player          = playerCombatant.GetComponent <PlayerCombatant>();
                player.Character = DataRepository.Instance().Characters.GetByName(partyMember);
                players.Add(playerCombatant);
            }

            // Get the enemy party
            Party enemyParty = BattleTransitionContainer.EnemyParty;

            // If the enemy party is null, grab the test party.
            if (enemyParty == null)
            {
                enemyParty = (Party)DataRepository.Instance().Parties.GetByName("test1");
            }

            foreach (string partyMember in enemyParty.Members)
            {
                // We want to spawn a combatant for each player in the party.
                GameObject     enemyCombatant = Instantiate((GameObject)Resources.Load(string.Format("Prefabs/Battle/Characters/{0}", "Enemy")), this.transform.parent);
                EnemyCombatant enemy          = enemyCombatant.GetComponent <EnemyCombatant>();
                enemy.Enemy = (Enemy)DataRepository.Instance().Enemies.GetByName(partyMember).Clone();
                enemies.Add(enemyCombatant);
            }

            UnitPlacement unitPlacement = this.GetComponentInChildren <UnitPlacement>();

            unitPlacement.PlacePlayers(players);
            unitPlacement.PlaceEnemies(enemies);

            GameObject.Find("BattleManager").GetComponent <BattleManager>().StoreCombatants(players, enemies);

            BattleEventManager.Instance().BattleStart();
        }
コード例 #9
0
 public void Init(EnemyCombatant Enemy) // Called by Battle Manager;
 {
     EnemyCombatant   = Enemy;
     Problem          = Enemy.problem;
     ProblemText.text = Enemy.problem.ProblemText;
     if (Enemy.problem.ProblemImage != null)
     {
         ProblemImage.enabled = true;
         ProblemImage.sprite  = Enemy.problem.ProblemImage;
     }
     else
     {
         ProblemImage.enabled = false;
     }
     ProblemProgress.text  = "Question: " + System.Environment.NewLine;
     ProblemProgress.text += (ProblemText.text + System.Environment.NewLine);
     CurrentPart           = 0;
     SetupOptions(CurrentPart);
 }
コード例 #10
0
    public override void OnGUI()
    {
        base.OnGUI();

        // if the battle has started...
        if (battleEnabled)
        {
            // enforce 16:9 aspect ratio
            GUILayout.BeginArea(AspectUtility.screenRect);

            // draw the player combatants' data
            drawPlayerInfo();

            if (isPlayerTurn())
            {
                PlayerCombatant currentPlayer = (PlayerCombatant)PlayerCombatants[currentTurn];

                switch (turnState)
                {
                case BattleTurnState.Attacking:
                    selectedAttack = getSelectedAttack();

                    if (selectedAttack != null)
                    {
                        currentButtonSelection = 0;
                        turnState = BattleTurnState.Targeting;
                    }

                    checkKeyControlFocus();

                    break;

                case BattleTurnState.Targeting:
                    selectedTarget = getSelectedTarget(selectedAttack);

                    if (selectedTarget != null)
                    {
                        currentButtonSelection = 0;
                        currentPlayer.Attack(selectedAttack, selectedTarget);
                        currentPlayer.IncrementTurnCounter();

                        turnState = BattleTurnState.WaitingForAnimation;
                    }

                    checkKeyControlFocus();

                    break;

                case BattleTurnState.WaitingForAnimation:

                    // has the player's animation finished?
                    if (!PlayerCombatants[currentTurn].AnimationInProgress)
                    {
                        turnState = BattleTurnState.TurnComplete;
                    }

                    break;
                }
            }
            else                 // otherwise it is an enemy's turn
            {
                EnemyCombatant currentEnemy =
                    (EnemyCombatant)EnemyCombatants[currentTurn - PlayerCombatants.Count];

                switch (turnState)
                {
                case BattleTurnState.Attacking:
                    if (!currentEnemy.isSleeping)
                    {
                        currentEnemy.AutoAttack(PlayerCombatants);
                    }

                    currentEnemy.IncrementTurnCounter();
                    turnState = BattleTurnState.WaitingForAnimation;

                    break;

                case BattleTurnState.WaitingForAnimation:
                    // if the enemy attack has finished...
                    if (Event.current.type == EventType.Repaint && !currentEnemy.AnimationInProgress)
                    {
                        turnState = BattleTurnState.TurnComplete;
                    }

                    break;
                }
            }

            if (turnState == BattleTurnState.TurnComplete)
            {
                // if the turn has completed, check if anyone won
                checkForVictory();

                // reset turn state
                turnState = BattleTurnState.Attacking;

                //...and then increment the turn.
                incrementTurn();

                // notify registered listeners of the turn change
                // note: this is not inside incrementTurn due to recursion
                if (OnBattleEvent != null)
                {
                    OnBattleEvent(BattleEvent.TurnChange);
                }
            }

            GUILayout.EndArea();
        }
    }
コード例 #11
0
 public void StartCombat(EnemyCombatant Enemy)
 {
     state = GameState.Battle;
     BattleManager.InitializeCombat(Enemy);
 }