Esempio n. 1
0
 //Función que se encarga de actualizar el estado de los tokens de movimiento y ataque.
 public void RefreshTokens()
 {
     for (int i = 0; i < attackTokens.Count; i++)
     {
         //Añado este if para que compruebe si es un decoy o no.
         if (assignedPlayer != null && !assignedPlayer.GetComponent <MageDecoy>())
         {
             //attackTokens[i].SetActive(!assignedPlayer.hasAttacked);
             if (!assignedPlayer.hasAttacked)
             {
                 attackTokens[i].GetComponent <Animator>().Play("TokenReset");
             }
             else
             {
                 attackTokens[i].GetComponent <Animator>().Play("TokenFlip");
             }
         }
     }
     for (int i = 0; i < movementTokens.Count; i++)
     {
         //Añado este if para que compruebe si es un decoy o no.
         if (assignedPlayer != null && !assignedPlayer.GetComponent <MageDecoy>())
         {
             //movementTokens[i].SetActive(!assignedPlayer.hasMoved);
             if (!assignedPlayer.hasMoved)
             {
                 movementTokens[i].GetComponent <Animator>().Play("TokenReset");
             }
             else
             {
                 movementTokens[i].GetComponent <Animator>().Play("TokenFlip");
             }
         }
     }
 }
Esempio n. 2
0
    void Update()
    {
        if (ResetDetector.Active && _reloaded)
        {
            _reloaded = false;
        }

        if (Activator.Active && !_reloaded)
        {
            Reload();
        }

        if (Player == null)
        {
            Player = GameObject.FindGameObjectWithTag("Player").GetComponent <PlayerUnit>();

            Player.GetComponent <Health>().CurrentHealth = _health;
            Player.transform.position = _position;
            Player.transform.rotation = _rotation;
            Player.FuelAmount         = _fuel;
            Player.GetComponent <PlayerMover>().Camera.transform.position = _cameraPosition;
        }

        if (Input.GetKey(KeyCode.Escape))
        {
            Destroy(gameObject);
        }
    }
    private void UpdateUnitDisplay()
    {
        for (int i = 0; i < owner.playerUnits.Count; i++)
        {
            PlayerUnit unit = owner.playerUnits[i];
            if (unit.GetComponent <UnitStats>().IsDead())
            {
                owner.battleUI.Die(unit.GetComponent <UnitStats>().playerUnitInfo);
                owner.playerUnits.Remove(unit);
                unit.Die();
            }
        }

        for (int i = 0; i < owner.enemyUnits.Count; i++)
        {
            EnemyUnit unit = owner.enemyUnits[i];
            if (unit.GetComponent <UnitStats>().IsDead())
            {
                owner.enemyUnits.Remove(unit);
                unit.Die();

                board.DeselectForecast(unit.GetNextMove());
            }
        }
    }
Esempio n. 4
0
    private void Reload()
    {
        _health         = Player.GetComponent <Health>().CurrentHealth;
        _position       = Player.transform.position;
        _rotation       = Player.transform.rotation;
        _fuel           = Player.FuelAmount;
        _cameraPosition = Player.GetComponent <PlayerMover>().Camera.transform.position;

        SceneManager.LoadScene("TestLevel");
        _reloaded = true;
    }
Esempio n. 5
0
 public void Replace(PlayerUnit unit, HeroPanel heropanel)
 {
     Deselect();
     this.unit   = unit;
     heroRef     = heropanel;
     icon.sprite = unit.GetComponent <CharacterStats>().unitClass.icon;
 }
Esempio n. 6
0
        private void OnStageChange(object sender, GameState gs)
        {
            switch (gs)
            {
            case GameState.InitializeGame:
                PlayerUnit        = GameObject.Instantiate(UnitPrefab, new Vector3(-3f, 1f, 0), Quaternion.identity);
                PlayerUnitManager = PlayerUnit.GetComponent <UnitManager>();

                // Set Guid;
                PlayerUnit.name = PlayerUnitManager.ID.ToString();
                PlayerUnitManager.Setup();
                PlayerUnitManager.UserType = UserType.Human;
                gameManager.ChangeState(GameState.InitializeFinished);
                break;

            case GameState.BattleBegin:
                position = PlayerUnit.transform.position;
                break;

            case GameState.PlayerTurnStart:
            case GameState.BattleFinished:
                PlayerUnit.transform.position = position;
                break;

            default:
                break;
            }
        }
    public void UpdateButtons(Point pos)
    {
        adjacentUnit = DirectionsExtensions.GetAdjacentPlayer(controller.board, pos);

        if (adjacentUnit == null)
        {
            talkButton.gameObject.SetActive(false);
            comboUI.gameObject.SetActive(false);

            return;
        }

        UnitID adjacentID = adjacentUnit.GetComponent <UnitStats>().ID;

        if (!controller.currentUnit.talked &&
            BattleDialogue.StillHasDialogue(currentUnit, adjacentID) &&
            !controller.talked)
        {
            talkButton.gameObject.SetActive(true);
        }

        comboUI.gameObject.SetActive(true);
        UnitPair pair = RelationshipManager.GetRelationshipPair(currentUnit, adjacentID);

        comboUI.SetWithoutObj(GameInformation.instance.GetComboInfo(pair));
    }
Esempio n. 8
0
    /// <summary>
    /// Updates after the main update - here is where we move our characters to face
    /// each other if they are not already
    /// </summary>
    void LateUpdate()
    {
        if (theTextBox.inConversation == true && !startedTalking && isColliding)
        {
            Animator anim;
            Vector2  direction;
            startedTalking = true;

            if (!isMotionlessObject)
            {
                anim      = player.GetComponent <Animator> ();
                direction = new Vector2(mainPlayer.transform.position.x -
                                        player.transform.position.x,
                                        mainPlayer.transform.position.y -
                                        player.transform.position.y);
                anim.SetBool("isWalking", true);
                anim.SetFloat("input_x", direction.x);
                anim.SetFloat("input_y", direction.y);
                anim.SetBool("isWalking", false);
                //rbody.MovePosition(rbody.position + direction * 0.01f);
            }

            // do the same change for the main player in reverse
            anim      = mainPlayer.GetComponent <Animator> ();
            direction = new Vector2(player.transform.position.x - mainPlayer.transform.position.x, player.transform.position.y - mainPlayer.transform.position.y);
            anim.SetBool("isWalking", true);
            anim.SetFloat("input_x", direction.x);
            anim.SetFloat("input_y", direction.y);
            anim.SetBool("isWalking", false);
        }
    }
 private void MeleeAttack(PlayerUnit player)
 {
     if (!isDead)
     {
         player.GetComponent <PlayerController>().TakeDmg(dmg);
     }
     animController.SetTrigger("Attack");
 }
Esempio n. 10
0
    private void UpdateUnitDisplay()
    {
        Queue <PlayerUnit> deadPlayers = new Queue <PlayerUnit>();

        for (int i = 0; i < owner.playerUnits.Count; i++)
        {
            PlayerUnit unit = owner.playerUnits[i];
            if (unit.GetComponent <UnitStats>().IsDead())
            {
                owner.battleUI.Die(unit.GetComponent <UnitStats>().playerUnitInfo);
                unit.Die();

                deadPlayers.Enqueue(unit);
            }
        }
        while (deadPlayers.Count > 0)
        {
            owner.playerUnits.Remove(deadPlayers.Dequeue());
        }

        Queue <EnemyUnit> deadEnemies = new Queue <EnemyUnit>();

        for (int i = 0; i < owner.enemyUnits.Count; i++)
        {
            EnemyUnit unit = owner.enemyUnits[i];

            if (unit.GetComponent <UnitStats>().IsDead())
            {
                unit.Die();
                board.DeselectForecast(unit.GetNextMove());

                deadEnemies.Enqueue(unit);
            }
            else if (unit.GetComponent <UnitStats>().HasStatus(StatusEffects.FREEZE))
            {
                board.DeselectForecast(unit.GetNextMove());
                unit.ResetMove();
            }
        }
        while (deadEnemies.Count > 0)
        {
            owner.enemyUnits.Remove(deadEnemies.Dequeue());
        }
    }
 /// <summary>
 /// Sets up the characterpanel
 /// </summary>
 public void Setup()
 {
     unitName.text  = unit.name;
     stats          = unit.GetComponent <CharacterStats>();
     unitClass.text = stats.unitClass.name;
     unitLevel.text = stats.level.ToString();
     unitBaB.text   = stats.baseAttackBonus.ToString();
     UnitAC.text    = (10 + stats.GetArmour()).ToString();
     Debug.Log("BAB: " + stats.baseAttackBonus.ToString());
     Debug.Log("AC: " + stats.GetArmour().ToString());
     attributeController.Setup(stats);
 }
Esempio n. 12
0
    public void AddUnit(PlayerUnit unit, HeroPanel heropanel)
    {
        if (this.unit != null)
        {
            Debug.Log("There's already a unit in this slot(" + partyIndex + ")");
            RemoveUnit();
        }
        this.unit = unit;
        heroRef   = heropanel;
        PlayerController.instance.AddToParty(unit, partyIndex);
        icon.sprite = unit.GetComponent <CharacterStats>().unitClass.icon;
//        Debug.Log("Unit added to party");
    }
Esempio n. 13
0
    public void PurchaseUpgrade(Upgrade upgrade)
    {
        PlayerUnit pu   = GameObject.FindObjectOfType <PlayerUnit>();
        Unit       unit = pu.GetComponent <Unit>();

        if (unit.Health < upgrade.Cost)
        {
            return;
        }

        SoundManager.Instance.PlayUpgradePurchased();

        unit.Health -= upgrade.Cost;
        upgrade.Cost = Mathf.CeilToInt(upgrade.Cost * 2f);
        upgrade.UpgradeAction(pu);
    }
Esempio n. 14
0
    public bool SetupHeroPanel(PlayerUnit unit)
    {
        canvas     = GameObject.Find("Canvas").GetComponent <Canvas>();
        content    = FindObjectOfType <HeroListUI>().transform;
        layout     = GetComponent <LayoutElement>();
        panelImage = GetComponent <Image>();

        this.unit = unit;
        stats     = unit.GetComponent <CharacterStats>();

        if (unit != null && stats != null)
        {
            isSetUp = true;
        }
//        Debug.Log(name + " was set up?" + isSetUp);
        return(isSetUp);
    }
Esempio n. 15
0
    public void unitChange()
    {
        ActionBar.gameObject.GetComponent <Image>().sprite = Unit.GetComponent <Status>().unitSkillIcon;
        passiveSkillBar.GetComponent <Image>().sprite      = Unit.GetComponent <Status>().unitPassiveIcon;

        BattleMgr.GetComponent <BattleManager>().isPlayerUnitChanged = true;
        GameObject temp = Unit;

        Unit = PlayerUnit.GetComponent <PlayerUnitManager>().PlayerUnit;
        PlayerUnit.GetComponent <PlayerUnitManager>().PlayerUnit = temp;

        Unit.transform.GetChild(0).gameObject.SetActive(false);
        PlayerUnit.GetComponent <PlayerUnitManager>().PlayerUnit.transform.GetChild(0).gameObject.SetActive(true);
        gameObject.GetComponent <Image>().sprite = Unit.GetComponent <Status>().unitIcon;

        //        gameObject.GetComponent<SpriteRenderer>().sprite = Resources.Load(Unit.GetComponent<Status>().unitName) as Sprite;
    }
Esempio n. 16
0
    private void InitializePlayer()
    {
        playerUnit = Instantiate(playerPrefab, playerBattleStation.position, playerBattleStation.rotation).GetComponent <PlayerUnit>();

        playerUnit.GetComponent <PlayerUnit>().OnLevelUp += OnPlayerLevelUp;

        var playerData = PlayerDataTransfer.LoadPlayerData();

        playerUnit.unitName         = playerData.unitName;
        playerUnit.unitLevel        = playerData.unitLevel;
        playerUnit.unitPower        = playerData.unitPower;
        playerUnit.unitDex          = playerData.unitSpeed;
        playerUnit.maxHP            = playerData.maxHP;
        playerUnit.currentHP        = playerData.maxHP;
        playerUnit.unitIntelligence = playerData.unitIntelligence;
        //playerUnit.currentMP = 0;
        playerUnit.currentExp           = playerData.currentExp;
        playerUnit.expToLevel           = playerData.expToLevel;
        playerUnit.totalGold            = playerData.totalGold;
        playerUnit.availableStatPoints  = playerData.availableStatPoints;
        playerUnit.availableSkillPoints = playerData.availableSkillPoints;

        playerUnit.knownSkills    = playerData.knownSkills;
        playerUnit.equippedSkills = playerData.equippedSkills;

        for (int i = 0; i < playerUnit.equippedSkills.Count; i++)
        {
            skillButtons[i].SetActive(true);
            Button skillButton = skillButtons[i].GetComponent <Button>();
            var    buttonText  = skillButton.GetComponentInChildren <Text>();
            if (buttonText != null)
            {
                buttonText.text = playerUnit.equippedSkills[i].SkillName;
            }
        }

        playerHUD.SetHP(playerUnit.currentHP);
        playerHUD.SetMP(playerUnit.CurrentMP);
        playerHUD.SetXp(playerUnit.currentExp);
    }
Esempio n. 17
0
    void SendInfoToPawn()
    {
        if (pawnSelected && wayPoints.Count > minimumWaypoints) //check pawn for null value and waypoints for a minimum
        {
            pawnSelected = false;

            if (wayPoints.Count > waypointsLimit)
            {
                wayPoints.RemoveRange(waypointsLimit, wayPoints.Count - waypointsLimit);
            }

            if (!pawn.GetComponent <PlayerUnit>().isWaiting)
            {
                pawn.steerigBhvr.PathNodes = wayPoints.ToArray();
                pawn.steerigBhvr.SetNodeLineRenderPoints();
                pawn.steerigBhvr.currentNode = 0;
                pawn.GetComponentInChildren <SkinnedMeshRenderer>().material.SetColor("_OutlineColor", Color.black);
            }
            pawn = null;
        }
        ClearWayPointData();
    }
Esempio n. 18
0
    public void GameOver()
    {
        Pause();
        EndScreen.SetActive(true);

        string s = "game over";

        if (playerUnit != null && playerUnit.GetComponent <Unit>().Health >= 0)
        {
            s = "victory!";
            SoundManager.Instance.PlayVictory();
        }
        else
        {
            SoundManager.Instance.PlayGameOver();
        }

        EndScreen.transform.Find("title").GetComponent <TextMeshProUGUI>().text = s;

        EndScreen_Levels.GetComponent <TextMeshProUGUI>().text  = "you reached level " + (currentLevel + 1) + " of " + levelParent.childCount;
        EndScreen_Enemies.GetComponent <TextMeshProUGUI>().text = "you killed " + EnemiesKilled + " enemies (" + ((EnemiesKilled * 100) / EnemiesSpawned) + "%)";
        EndScreen_Scrap.GetComponent <TextMeshProUGUI>().text   = "you collected " + (ScrapCollected) + " scrap";
    }
Esempio n. 19
0
    public IEnumerator UnitReproduce(GridTileInfo targetTile)
    {
        yield return(new WaitForSeconds(moveAnimationInterval));

        GameObject newClone     = Instantiate(gameObject);
        PlayerUnit newCloneUnit = newClone.GetComponent <PlayerUnit>();

        newCloneUnit.GetComponent <MapObjectInfo>().currentOccupyingTile = null; // Reset new clone's MapObjectInfo's occupying tile info, because it has not been placed on the map yet

        // Place new clone on target tile
        MapManager.PlaceObject(newClone.transform, targetTile.xCoord, targetTile.zCoord);

        newCloneUnit.InitiateClone();

        // Add new clone to new clone list
        TurnManager.newCloneReproduced.Add(newCloneUnit);

        // Clear selected tile in TurnManager;
        TurnManager.currentSelectedUnitTile = null;

        yield return(new WaitForSeconds(moveAnimationInterval));

        // If new clone meet the win requirement
        if (GameManager.sGameManager.CheckWinCondition(newCloneUnit))
        {
            //GameManager.playerUnits.Add(newCloneUnit);
            GameManager.sGameManager.PlayerWin();
        }

        // Finish reproduction
        TurnManager.playerUnitReproducing = false;
        isReproducing = false;

        // Finish animation
        TurnManager.inPlayerUnitAnimation = false;
    }
Esempio n. 20
0
    private void HandleGameStateInfo(IMarshallable dataReceived)
    {
        //GameManager.Instance.MessageManager.AddMessage(dataReceived.ToString(), GameManager.MessageTypes.Game, null);


        GameStateInfo gameInfo = dataReceived as GameStateInfo;

        if (gameInfo != null)
        {
            switch (gameInfo.InfoType)
            {
            case CommsMarshaller.GameStateInfoType.UnitIsDestroyed:
                PlayerUnit unit = GameManager.Instance.UnitManager.FindUnitById(gameInfo.Id);
                if (unit != null)
                {
                    unit.Kill(true);
                }
                //~ ShowMessage("GameStateInfo object, UnitIsDestroyed");
                break;

            case CommsMarshaller.GameStateInfoType.DetectedContactIsLost:
                //~ ShowMessage("GameStateInfo object, DetectedContactIsLost");
                Debug.Log(string.Format("Lost detection Id: {0} - Time:{1}", gameInfo.Id, Time.time));

                Enemy e = GameManager.Instance.UnitManager.FindEnemyById(gameInfo.Id);
                if (e != null)
                {
                    e.Kill();
                }
                else
                {
                    Debug.Log("Lost contact with unit not in enemy list. Error?");
                }

                break;

            case CommsMarshaller.GameStateInfoType.AircraftIsLanded:
            {
                PlayerUnit launchPlatform = GameManager.Instance.UnitManager.FindUnitById(gameInfo.SecondaryId);
                PlayerUnit aircraft       = GameManager.Instance.UnitManager.FindUnitById(gameInfo.Id);

                Debug.Log(string.Format("Aircraft has landed: {0} on {1}", aircraft.Info.UnitName, launchPlatform.Info.UnitName));
                if (aircraft != null)
                {
                    Debug.Log(string.Format("Killing off unit: {0}. ", aircraft.Info.UnitName));
                    aircraft.Kill(false);
                    Debug.Log(string.Format("{0} killed ", aircraft.Info.UnitName));
                }
                else
                {
                    Debug.Log("Aircraft is null");
                    break;
                }

                //gameInfo.
                if (launchPlatform != null)
                {
                    AnimationLauncher al = launchPlatform.GetComponent <AnimationLauncher>();
                    Debug.Log(string.Format("Animation launcher is on: {0}", al.gameObject.name));
                    if (al != null)
                    {
                        UnitClass uc = GameManager.Instance.GetUnitClass(aircraft.Info.UnitClassId);
                        Debug.Log(string.Format("Unitclass found: {0}. ", uc.UnitClassShortName));
                        al.TakeOffMode = uc.UnitType == GameConstants.UnitType.Helicopter ? AnimationLauncher.AnimMode.HelicopterLanding : AnimationLauncher.AnimMode.FixedWingLanding;
                        Debug.Log(string.Format("Changed takeoffmode to: {0}. Attempting launch...", al.TakeOffMode.ToString()));
                        al.LaunchAnimation();
                        Debug.Log(string.Format("Animation launched..."));
                    }
                    else
                    {
                        Debug.Log("AnimationLauncher is null");
                    }
                }
                else
                {
                    Debug.Log("Launchplatform is null");
                }



                //if (carrier != null)
                //{
                //    GameManager.Instance.UnitManager.SelectedUnit = carrier;
                //}
                //~ ShowMessage("GameStateInfo object, AircraftIsLanded");
                break;
            }

            case CommsMarshaller.GameStateInfoType.AircraftTakeoff:
            {
                PlayerUnit launchPlatform = GameManager.Instance.UnitManager.FindUnitById(gameInfo.SecondaryId);
                //gameInfo.
                if (launchPlatform != null)
                {
                    AnimationLauncher al = launchPlatform.GetComponent <AnimationLauncher>();
                    if (al != null)
                    {
                        UnitClass uc = GameManager.Instance.GetUnitClass(gameInfo.UnitClassId);

                        al.TakeOffMode = uc.UnitType == GameConstants.UnitType.Helicopter ? AnimationLauncher.AnimMode.HelicopterTakeOff : AnimationLauncher.AnimMode.FixedWingTakeOff;
                        al.LaunchAnimation();
                    }
                }
                break;
            }

            case CommsMarshaller.GameStateInfoType.MissileLaunch:
                PlayerUnit shooter = GameManager.Instance.UnitManager.FindUnitById(gameInfo.SecondaryId);


                if (shooter != null)
                {
                    shooter.FireMissile();
                }
                else
                {
                    Debug.Log(gameInfo.SecondaryId + " is not a unit here");
                }

                break;
            }
        }
    }
Esempio n. 21
0
 private void Update()
 {
     DescriptionText.text = "there are three randomly selected upgrades for you to buy with scrap -- but remember that scrap also protects you in battle. spend wisely! you have " + playerUnit.GetComponent <Unit>().Health + " scrap.";
 }
Esempio n. 22
0
    /// <summary>
    /// Resolves the commands sent from options in a conversation
    /// </summary>
    /// <param name="optionItem">Option item.</param>
    public void resolveBattleCommands(Options optionItem)
    {
        // we are looking at the command
        string        playerToAlter  = optionItem.playerToAlter;
        string        currentPlayer  = optionItem.currentPlayer;
        string        commandsString = optionItem.command;
        BattleManager batMan         = GameObject.FindGameObjectWithTag("MainCamera").GetComponent <BattleManager>();

        bool finalSelection = false;

        // if player to alter is blank, debug that

        Debug.Log("COMMANDS STRING : " + commandsString);

        // next we need to take that command that we have and we need
        // to parse it out. We'll split it by semicolon
        string[] commandsList = commandsString.Split(';');



        // now that we have everything split up, we want to loop over that list
        foreach (var commandItem in commandsList)
        {
            // now we add that section from options
            // if we have a number, just go to that number
            if (commandItem.Contains("id#"))
            {
                Debug.Log("CONTAINS ID : " + commandItem);

                // split our command our and send it to our function
                string command = (commandItem.Split('#')) [1];
                changeBattleDialogueID(command, playerToAlter);
            }

            // otherwise, if we are doing an immediate branching, branch out immediately
            // to the other branch
            else if (commandItem.Contains("goto#"))
            {
                // split our command our and send it to our function
                string command = (commandItem.Split('#')) [1];
                branchBattle(command, playerToAlter);
            }

            // unrecognized command
            else if (commandItem.Contains("attack"))
            {
                Debug.Log("we are attacking");

                if (playerAttacking == null)
                {
                    Debug.Log("attacking player is null");
                }
                else if (playerAttacking.GetComponent <PlayerAttack> () == null)
                {
                    Debug.Log("PLAYERATTACK is null");
                }



                playerAttacking.GetComponent <PlayerAttack> ().startAttacking = true;
                finalSelection = true;
            }

            // for SPELL attacks
            else if (commandItem.Contains("ice") || commandItem.Contains("fire") || commandItem.Contains("water"))
            {
                playerAttacking.GetComponent <PlayerAttack> ().castOffensiveSpell(commandItem);
                finalSelection = true;
            }

            // for damage like in items
            else if (commandItem.Contains("damage#"))
            {
                // get the number of damage
                playerAttacking.GetComponent <PlayerAttack> ().dealDamage(commandItem);
                finalSelection = true;
            }

            // for healing (or potentially other buffs)
            else if (commandItem.Contains("health#"))
            {
                // get the number of damage

                playerAttacking.GetComponent <PlayerAttack> ().buffPlayer(commandItem, unitBeingBuffed);
                finalSelection = true;
            }
            else if (commandItem.Contains("defend"))
            {
                Debug.Log("we are attacking in commands");
                playerAttacking.GetComponent <PlayerAttack> ().buffPlayer(commandItem, playerAttacking);
            }

            // otherwise, we have something we don't recognize
            else
            {
                Debug.Log("We have an unrecognized command : " + commandItem + " " + currentPlayer);
                finalSelection = true;
            }
        }

        playerAttacking.GetComponent <BattleMenu> ().updatingItems = true;


        // no longer our turn
        if (finalSelection)
        {
            playerAttacking.GetComponent <BattleMenu> ().isMyTurn = false;
            batMan.turnFinished = true;
        }
    }
    public void Talk()
    {
        controller.ChangeState <BattleDialogueState>();
        controller.otherUnit = adjacentUnit;

        Relationship        r     = RelationshipManager.GetRelationshipBetween(currentUnit, adjacentUnit.GetComponent <UnitStats>().ID);
        RelationshipRank    rank  = r.GetNextRank();
        UnitPair            pair  = r.pair;
        List <DialogueLine> lines = BattleDialogue.GetBattleDialogueBetween(currentUnit, adjacentUnit.GetComponent <UnitStats>().ID);

        dialogueManager.StartDialogue(lines, rank, pair);
    }
Esempio n. 24
0
    /// <summary>
    /// Loads the battle scene items.
    /// </summary>
    public void LoadBattleSceneItems()
    {
        Toolbox.Instance.sceneAlreadyLoaded = false;
        Debug.Log("LOADING....");


        // get our first two characters and their children.


        // let's sort by speed - reverse order so that we can have the highest speeds go first
        allCombatants.Sort((GameObject x, GameObject y) => y.GetComponent <CharacterConversable>().speed.CompareTo(x.GetComponent <CharacterConversable>().speed));


        // now that we have all combatants...
        // loop over the objects?
        // we can tell what they are by their tags
        float playerIndex = 0.8f;
        float enemyIndex  = 0.0f;

        foreach (var combatant in allCombatants)
        {
            CharacterConversable combatantCharacter = combatant.GetComponent <CharacterConversable> ();

            Debug.Log("COMBATANT NAME : " + combatant.name + " AND THEIR SPEED : " + combatantCharacter.speed);
            turnOrder.Add(combatant.GetComponent <CharacterConversable> ());

            // IF THE UNIT IS A PLAYER CHARACTER, PUT IT ON THE PLAYER'S SIDE
            if (combatant.GetComponent <CharacterConversable>().isPlayerCharacter)
            {
                Debug.Log("COMBATANT " + combatant.name + " BEFORE TRANSFORM : " + combatant.transform.position);

                if (!combatant.Equals(currentPlayer))
                {
                    // find positions for everyone.
                    combatant.transform.position = new Vector2(1.8f, -3.40f + (playerIndex));
                    playerIndex += 0.8f;
                }

                Debug.Log("COMBATANT " + combatant.name + " AFTER TRANSFORM : " + combatant.transform.position);

                // let's also make them face one another
                Animator anim = combatant.GetComponent <Animator>();


                // set the players to face each other.
                PlayerUnit combatantUnit = combatant.GetComponent <PlayerUnit>();
                combatantUnit.GetComponent <PlayerUnit>().freeze = false;
                anim.SetBool("isWalking", true);
                anim.SetFloat("input_x", 1f);
                anim.SetFloat("input_y", 0);
                combatantUnit.GetComponent <PlayerUnit> ().freeze = true;

                // give all players their health bar
                PlayerHealth health = combatantUnit.GetComponent <PlayerHealth> ();


                //if (combatant.playerName == "Princess")
                //{
                health.healthField  = GameObject.Find("HealthStats").GetComponent <Text> ();
                health.healthSlider = GameObject.Find("PlayerHealth").GetComponent <Slider> ();
                //}

                combatant.AddComponent <BattleMenu> ().battleXML = tempPlayerXML;
                BattleMenu battleMenu = combatant.GetComponent <BattleMenu> ();
                battleMenu.allCombatants = turnOrder;
                battleMenu.battlePanel   = GameObject.Find("BattlePanel");
            }

            // otherwise, we're an enemy character - but let's check and see if we have an enemy unit
            // component anyway
            else
            {
                if (!combatant.Equals(currentEnemy))
                {
                    enemyIndex += 0.8f;
                    // find positions for everyone.
                    combatant.transform.position = new Vector2(5.2f, -3.40f + (enemyIndex));
                    Debug.Log("ENEMY NAME : " + combatant.name + " POSITION : " + combatant.transform.position);
                }


                // let's also make them face one another
                Animator  anim          = combatant.GetComponent <Animator>();
                EnemyUnit combatantUnit = combatant.GetComponent <EnemyUnit>();

                // make enemy face hero side
                combatantUnit.freeze = false;
                anim = combatant.GetComponent <Animator> ();
                anim.SetBool("isWalking", true);
                anim.SetFloat("input_x", -1f);
                anim.SetFloat("input_y", 0);
                combatantUnit.freeze = true;


                // add in attack sequence to all enemies and give them their damage
                // activate attack
                combatantUnit.enemyAttack.isActive = true;

                // just the grue gets it's own health bar at the moment until we figure that out.
                EnemyHealth enemyHealth = combatantUnit.enemyHealth;
                enemyHealth.healthSlider          = GameObject.Find("EnemyHealth").GetComponent <Slider> ();
                enemyHealth.healthField           = GameObject.Find("EnemyHealthStats").GetComponent <Text> ();
                enemyHealth.healthSlider.maxValue = enemyHealth.maxHealth;
                enemyHealth.healthSlider.minValue = 0;
                enemyHealth.healthSlider.value    = enemyHealth.currentHealth;
                enemyHealth.healthField.text      = "<color=yellow>" + enemyHealth.currentHealth + "</color> / <color=white>" + enemyHealth.maxHealth + "</color>";
            }
        }
    }
Esempio n. 25
0
    /// <summary>
    /// When one of our menu buttons is clicked, we go here to deal with the command issued
    /// </summary>
    /// <param name="buttonCommand">Button command.</param>
    public IEnumerator ButtonClicked(Options buttonCommand)
    {
        isActive = false;
        Destroy(waitingObject);

        if (selectionMade)
        {
            /// what type of options list do we have? conversation or more main menu?
            if (menuType == "conversation")
            {
                if (buttonCommand.command == "exit")
                {
                    yield break;
                }
                else if (buttonCommand.command == "accept")
                {
                    hasAccepted = true;
                    yield break;
                }

                Commands command = new Commands();
                command.resolveConversationCommands(buttonCommand);
            }

            // if we have a main menu, we can send those commands over to commands as well
            // and just run our functions for that.
            else if (menuType == "PauseMenu")
            {
                Commands command = new Commands();
                command.resolvePauseMenuCommands(buttonCommand);
                // what is our command?
            }
            else if (menuType == "BattleMenu")
            {
                // yield on starting a new
                // add targetpicker to this player character, and then use that
                // to get the list of players from his battlemenu? who has the list of
                // units to attack?
                // player -> battle menu -> all combatants shoved into player -> add component -> targetpicker
                TargetPicker playerTargetPicker = attackingPlayer.GetOrAddComponent <TargetPicker>();
                playerTargetPicker.currentPlayer = attackingPlayer;
                playerTargetPicker.battleList    = attackingPlayer.GetComponent <BattleMenu> ().allCombatants;
                playerTargetPicker.loadBattle();


                // disable button presses
                // check and see which item is highlighted here before we enter and make that
                // our indexselected
                for (var i = 0; i < menuOptions.Count; i++)
                {
                    // if the item is highlighted, set our value to that
                    // set i to max
                    Button currentButton = optionsBox.transform.GetChild(i).gameObject.GetComponent <Button>();
                    currentButton.interactable = false;
                }

                // now that we've loaded the battle, we want to do an enumerator that waits
                // for an input from our user. Either we get a "back up" with a null, or we get
                // a character to attack (for now let's just assume it will be an enemy)
                yield return(StartCoroutine(playerTargetPicker.selectTarget()));


                while (!playerTargetPicker.hasChosenTarget)
                {
                    yield return(null);
                }



                if (playerTargetPicker.chosenTarget == null)
                {
                    Destroy(playerTargetPicker);

                    // if we get a null, make the buttons live again and we'll try again?
                    // disable button presses
                    // check and see which item is highlighted here before we enter and make that
                    // our indexselected
                    // check and see which item is highlighted here before we enter and make that
                    // our indexselected
                    for (var i = 0; i < menuOptions.Count; i++)
                    {
                        // if the item is highlighted, set our value to that
                        // set i to max
                        Button currentButton = optionsBox.transform.GetChild(i).gameObject.GetComponent <Button>();
                        currentButton.interactable = true;

                        if (i == 0 && indexSelected <= 0)
                        {
                            currentButton.Select();
                        }
                        else if (i == indexSelected)
                        {
                            currentButton.Select();
                        }
                    }

                    selectionMade = false;
                    isActive      = true;

                    yield break;
                }


                // get our command object
                Commands command = new Commands();

                GameObject targetObject = playerTargetPicker.chosenTarget.gameObject;
                command.setAttackingPlayer(attackingPlayer);
                if (targetObject.GetComponent <PlayerUnit> () != null)
                {
                    command.setPlayerBeingBuffed(targetObject.GetComponent <PlayerUnit> ());
                }
                if (targetObject.GetComponent <EnemyUnit> ())
                {
                    command.setEnemyUnderAttack(targetObject.GetComponent <EnemyUnit>());
                }

                Destroy(playerTargetPicker);

                // let's resolve our battle commands
                buttonCommand.playerToAlter = "Player";
                command.resolveBattleCommands(buttonCommand);
            }
        }

        yield return(new WaitForSeconds(0.01f));
    }
Esempio n. 26
0
    /// <summary>
    /// Try to attack a player clone
    /// </summary>
    /// <param name="enemy"></param>
    /// <returns></returns>
    public IEnumerator EnemyAttack(PlayerUnit target)
    {
        yield return(new WaitForSeconds(animationInterval));

        // If target is within attack range
        if (MapManager.sMapManager.GetManhattenDistance(GetComponent <MapObjectInfo>().currentOccupyingTile, target.GetComponent <MapObjectInfo>().currentOccupyingTile) <= attackRange)
        {
            target.health -= attackPower; // Decrease enemy health

            // If the player clone dead
            if (target.health <= 0)
            {
                target.CloneDie();
            }
        }

        isInSomeMove = false; // Finish attack
    }