public static DragonAction getSSAction(Vector3 location)
    {
        DragonAction action = CreateInstance <DragonAction>();

        action.posX         = location.x;
        action.posZ         = location.z;
        action.moveDistance = UnityEngine.Random.Range(4, 10);
        return(action);
    }
 void Start()
 {
     player_action = 0;
     dragon_action = 0;
     item          = string.Empty;
     SuccessUse    = false;
     captured      = false;
     Enemy.Heal(Enemy.GetMaxHealth());
 }
    // Used to queue Player action
    // code specifies what will be done
    public void QueuePlayer(int code)
    {
        if (item == string.Empty)
        {
            player_action = (PlayerAction)code;
        }

        // Since the UI does not prevent the player from attacking multiple times
        // then there needs to be a check for TakeRound based on item.

        // Since an attack is being taken, no item can be used
        // item = string.Empty;

        if (player_action == PlayerAction.Flee)
        {
            GameManager.instance.PopState();
        }

        switch (code)
        {
        case (int)PlayerAction.Melee:
            CUI.DisplayLine(Player.GetName() + " prepares to attack.");
            break;

        case (int)PlayerAction.Capture:
            CUI.DisplayLine(Player.GetName() + " prepares to capture the dragon.");

            dragon_action = DragonAction.None;

            CUI.QueuePlayer();
            CUI.QueueDragon();

            TakeRound();
            return;

        case (int)PlayerAction.Defend:
            CUI.DisplayLine(Player.GetName() + " braces against attacks.");
            break;

        case (int)PlayerAction.Flee:
            CUI.DisplayLine(Player.GetName() + " prepares to flee.");
            break;
        }

        CUI.QueuePlayer();

        if ((Dragon == null || (!Dragon.IsDead() && dragon_action != DragonAction.None)) && item == string.Empty)
        {
            TakeRound();
        }
    }
 public void SSActoinEvent(SSAction source, int param = 0, GameObject objParam = null)
 {
     if (param == 0)
     {
         // 侦察兵跟随玩家
         FollowAction followAction = FollowAction.getSSAction(objParam.gameObject.GetComponent <DragonData>().player);
         this.RunAction(objParam, followAction, this);
     }
     else
     {
         DragonAction patrolAction = DragonAction.getSSAction(objParam.gameObject.GetComponent <DragonData>().start_position);
         this.RunAction(objParam, patrolAction, this);
         Singleton <GameEventManager> .GetInstance.playerEscape();
     }
 }
    // Used to queue Dragon action
    // code specifies what will be done
    public void QueueDragon(int code)
    {
        if (!Dragon.IsDead() && Dragon != null)
        {
            dragon_action = (DragonAction)code;
        }
        else
        {
            dragon_action = DragonAction.None;
        }

        switch (code)
        {
        case (int)DragonAction.Attack:
            CUI.DisplayLine(Dragon.GetName() + " prepares to attack.");
            break;

        case (int)DragonAction.Breath:
            CUI.DisplayLine(Dragon.GetName() + " prepares to use its breath weapon.");
            break;

        case (int)DragonAction.Spell:
            CUI.DisplayLine(Dragon.GetName() + " readies a spell.");
            break;

        case (int)DragonAction.Defend:
            CUI.DisplayLine(Dragon.GetName() + " braces against attacks.");
            break;

        case (int)DragonAction.Switch:
            CUI.DisplayLine(Dragon.GetName() + " switches with an ally.");
            break;
        }

        CUI.QueueDragon();

        if (player_action != PlayerAction.None || item != string.Empty)
        {
            TakeRound();
        }
    }
 public void Capture()
 {
     if (Random.Range(0, Enemy.GetMaxHealth()) < Enemy.GetCurrentHealth())
     {
         CUI.DisplayLine("Capture failed!");
     }
     else
     {
         dragon_action = DragonAction.None;
         captured      = true;
         CUI.CaptureDragon();
         CUI.DisplayLine(Enemy.GetName() + " captured!");
         GameObject.Find("Enemy").GetComponent <SpriteRenderer>().enabled = false;
         if (Player.GetNumDragons() < 4)
         {
             Player.AddDragon(Enemy.GetName(), -1);
             CUI.Wait();
         }
         else
         {
             CUI.ReplaceDragon();
         }
     }
 }
Beispiel #7
0
    private void DecideAction()
    {
        int randomAction = Random.Range(0,3);
        switch (randomAction)
        {
        /*case 0:
            m_action = DragonAction.Wait;
            break;
            */
        case 0:
            m_action = DragonAction.Fly;
            break;
        case 1:
            m_action = DragonAction.SpitFire;
            break;
        case 2:
            m_action = DragonAction.Flamethrower;
            break;
        default:
            m_action = DragonAction.Fly;
            break;
        }

        if (m_action == DragonAction.Fly)
        {
            m_flyDirection = DecideDirection();
        }
        if (m_action == DragonAction.SpitFire)
        {
            SpitFire();
        }
        if (m_action == DragonAction.Flamethrower)
        {
            ShootFlamethrower();
        }
    }
    // The main function used to resolve a round of combat
    public void TakeRound()
    {
        CUI.DisplayLine("");

        // Apply defense modifiers first
        if (player_action == PlayerAction.Defend)
        {
            Player.ModifyDefense(4);
        }

        if (dragon_action == DragonAction.Defend)
        {
            Player.ModifyDefense(4);
        }

        // If Player Speed > Enemy Speed and Dragon Speed, Player goes first
        if (Player.GetSpeed() >= Enemy.GetSpeed() && Player.GetSpeed() >= Dragon.GetSpeed())
        {
            PlayerTurn();

            // If Enemy not dead
            if (!Enemy.IsDead())
            {
                //if a dragon exists and is not dead, it gets a turn
                if (Dragon != null && !Dragon.IsDead())
                {
                    //if it's faster than the enemy
                    if (Dragon.GetSpeed() >= Enemy.GetSpeed())
                    {
                        DragonTurn();
                        // If Enemy still not dead and not caputured
                        if (!Enemy.IsDead() || !captured)
                        {
                            EnemyTurn();
                        }
                    }
                    //else if enemy is faster than dragon
                    else
                    {
                        // If Enemy still not dead and not caputured
                        if (!Enemy.IsDead() || !captured)
                        {
                            EnemyTurn();
                        }
                        //if dragon is not dead, dragon's turn
                        if (!Dragon.IsDead())
                        {
                            DragonTurn();
                        }
                    }
                }
                //else if no usable dragonn
                else
                {
                    // If Enemy still not dead and not caputured
                    if (!Enemy.IsDead() || !captured)
                    {
                        EnemyTurn();
                    }
                }
            }
        }
        //Else if dragon is fastest
        else if (Dragon != null && !Dragon.IsDead() && Dragon.GetSpeed() >= Enemy.GetSpeed())
        {
            DragonTurn();

            // If Enemy not dead and player not dead
            if (!Enemy.IsDead() && !Player.IsDead())
            {
                //if player's faster than the enemy
                if (Player.GetSpeed() >= Enemy.GetSpeed())
                {
                    PlayerTurn();
                    // If Enemy still not dead and not caputured
                    if (!Enemy.IsDead() || !captured)
                    {
                        EnemyTurn();
                    }
                }
                //else if enemy is faster than player
                else
                {
                    // If Enemy still not dead and not caputured
                    if (!Enemy.IsDead() || !captured)
                    {
                        EnemyTurn();
                    }
                    //if player is not dead, player's turn
                    if (!Player.IsDead())
                    {
                        PlayerTurn();
                    }
                }
            }
        }
        //Else if enemy is fastest
        else
        {
            EnemyTurn();
            //If Player not dead
            if (!Player.IsDead())
            {
                //if a dragon exists and is not dead, it gets a turn
                if (Dragon != null && !Dragon.IsDead())
                {
                    //if dragon's faster than the player
                    if (Dragon.GetSpeed() >= Player.GetSpeed())
                    {
                        DragonTurn();
                        //if enemy and player not dead, player's turn
                        if (!Enemy.IsDead() && !Player.IsDead())
                        {
                            PlayerTurn();
                        }
                    }
                    //else if player is faster than dragon
                    else
                    {
                        PlayerTurn();
                        //if dragon is not dead and enemy is not caputured or dead, dragon's turn
                        if (!Dragon.IsDead() && !Enemy.IsDead() && !captured)
                        {
                            DragonTurn();
                        }
                    }
                }
                //else if no usable dragonn
                else
                {
                    PlayerTurn();
                }
            }
        }

        // Reset variables at the end of the round
        player_action = PlayerAction.None;
        dragon_action = DragonAction.None;
        item          = string.Empty;
        SuccessUse    = false;

        // Reset any modifiers that occurred this round
        Player.ResetStats();
        Dragon.ResetStats();
        Enemy.ResetStats();

        // Reset queue status
        CUI.ResetQueue();

        CUI.UpdateSliders(Player.GetCurrentHealth(), Dragon.GetCurrentHealth(), Dragon.GetCurrentMana(), Enemy.GetCurrentHealth());

        // If Player dead
        if (Player.IsDead() || Player.AllDragonsDead())
        {
            // Game over
            CUI.DisplayLine("Game over");
            CUI.Wait();
        }

        // If Dragon dead
        if (Dragon.IsDead())
        {
            GameObject.Find("Dragon").GetComponent <SpriteRenderer>().enabled = false;
            //if the player has dragons left with > 0 HP, send one out
            if (!Player.AllDragonsDead())
            {
                CUI.SendOutDragon();
            }
        }

        // If Enemy dead
        if (Enemy.IsDead())
        {
            // Award experience and gold
            //float gold = Enemy.GetGold();
            float gold = Random.Range(1, 25);
            float exp  = 100;

            InventoryCanvasController.instance.InsertReward();

            Player.AddGold(gold);
            Player.GainExperience(100);
            Dragon.GainExperience(100);

            CUI.DisplayLine("");
            CUI.DisplayLine("Enemy defeated!");
            CUI.DisplayLine("Gained " + gold.ToString() + " gold!");
            CUI.DisplayLine("Gained " + exp.ToString() + " XP!");
            CUI.DisplayLine("Press any key to continue...");

            CUI.Wait();
        }

        RoundCounter++;
    }
Beispiel #9
0
 public void Rise()
 {
     m_action = DragonAction.Rise;
     m_mobState.Rise();
 }
Beispiel #10
0
 public void Fall()
 {
     m_action = DragonAction.Fall;
 }
Beispiel #11
0
    void Update()
    {
        if (Clock() && m_action != DragonAction.Grounded)
        {
            // Si nos han dado, no calculamos otro movimiento,
            // esperamos siguiente turno
            if (!m_mobState.m_beenHit && !m_mobState.m_dead &&
                m_action != DragonAction.Fall && m_action != DragonAction.Rise)
            {
                DecideAction();
            }
            else if (m_action != DragonAction.Fall && m_action != DragonAction.Rise)
            {
                m_action = DragonAction.Wait;
            }

        }

        if (m_action == DragonAction.Fly || m_action == DragonAction.SpitFire)
        {
            if (FlyClock())
            {
                m_action = DragonAction.Wait;
            }
            else
            {
                Fly(m_flyDirection);
            }
        }

        if (m_action == DragonAction.Fall)
        {
            if (FlyClock())
            {
                m_action = DragonAction.Grounded;
            }
            else
            {
                Fly(GLOBALS.Direction.South);
            }
        }

        if (m_action == DragonAction.Rise)
        {
            if (FlyClock())
            {
                m_action = DragonAction.Wait;
            }
            else
            {
                Fly(GLOBALS.Direction.North);
            }
        }

        if (m_action == DragonAction.Grounded)
        {
            if (GroundedClock())
            {
                Rise ();
            }
        }
    }
 public void GoDragon(GameObject dragon)
 {
     dragonAction = DragonAction.getSSAction(dragon.transform.position);
     this.RunAction(dragon, dragonAction, this);
 }