bool CanYouAttackedbyMe(int position)
    {
        battle script = GameObject.Find("BattleManager").GetComponent <battle>();
        bool   yes    = false;

        if (position - 7 < script.bossfield.Count || position == 6)
        {
            switch (position)
            {
            case 6:
                if (script.bossfield.Count <= 0)
                {
                    yes = true;
                }
                break;

            case 7:
            case 8:
            case 9:
            case 10:
            case 11:
                LoadCardDataFromjson(script.bossfield[position - 7 + script.how_many_boss_right]);
                if (Carddata.type == Type.MERCENARY)
                {
                    yes = script.Board.action_EF[position - 7];
                }
                break;
            }
        }
        return(yes);
    }
    bool CanIAttackYou(int position)
    {
        battle script = GameObject.Find("BattleManager").GetComponent <battle>();
        bool   yes    = false;

        if (position - 1 < script.field.Count || position == 0)
        {
            switch (position)
            {
            case 0:
                yes = script.Board.action_P;
                break;

            case 1:
            case 2:
            case 3:
            case 4:
            case 5:
                LoadCardDataFromjson(script.field[position - 1 + script.how_many_my_right]);
                yes = script.Board.action_PF[position - 1];
                break;
            }
        }
        return(yes);
    }
Beispiel #3
0
    void UnfoldBattle()
    {
        // give battle results
        // TODO : for each tick of update, each unit dmges the other
        int numberofPendingRequest = battlePendingRequest.Count;

        // decide winner on a coin toss
        for (int i = battleList.Count - 1; i >= 0; i--)
        {
            //DeclineDuplicateRequest(battleList[i].party0, battleList[i].party1);

            if (battleList[i].party0 == null || battleList[i].party1 == null || battleList[i].party0.party.Count == 0 || battleList[i].party1.party.Count == 0)
            {
                Debug.Log("UnfoldBattle battle ended " + " party0 null? " + (null == battleList[i].party0) + " party1 null? " + (null == battleList[i].party1));
                //battleList[i] = new battle(battleList[i].party0, battleList[i].party1, false);
                RemoveBattleList(i);
                continue;
            }
            if (!battleList[i].processed)
            {
                Debug.Log("UnfoldBattle not battle ended " + i);
                StartCoroutine(Fighting(i));
            }
        }

        // process the pending battle requests
        for (int i = numberofPendingRequest - 1; i >= 0; i--)
        {
            battle tmp = battlePendingRequest[i];
            battleList.Add(tmp);
            tmp.party0.EngageBattle();
            tmp.party1.EngageBattle();
            battlePendingRequest.RemoveAt(i);
        }
    }
    void activateSpell(int position)
    {
        battle script = GameObject.Find("BattleManager").GetComponent <battle>();

        script.field.RemoveAt(position - 1 + script.how_many_my_right);
        script.Board.action_PF.RemoveAt(position - 1 + script.how_many_my_right);
        script.Board.current_PF.RemoveAt(position - 1 + script.how_many_my_right);
        script.Board.max_PF.RemoveAt(position - 1 + script.how_many_my_right);
    }
Beispiel #5
0
    IEnumerator Fighting(int i)
    {
        // select a random faction, then select a random unit, it dmges a random enemy unit
        WM_Unit attacker = null;
        WM_Unit defender = null;
        battle  b;

        battleList[i] = new battle(battleList[i].party0, battleList[i].party1, true);
        b             = battleList[i];
        while (b.party0.party.Count > 0 && b.party1.party.Count > 0)
        {
            while (GameManager.FreezeTime)
            {
                yield return(new WaitForSeconds(0.2f));
            }

            if (b.party0 == fightingThePlayer || b.party1 == fightingThePlayer)
            {
                break;
            }

            yield return(new WaitForSeconds(0.5f));

            while ((attacker == null && defender == null) || !attacker.isAlive() || !defender.isAlive())
            {
                if (Random.Range(0, 1f) > 0.5f)
                {
                    attacker = b.party0.party[Random.Range(0, b.party0.party.Count)];
                    defender = b.party1.party[Random.Range(0, b.party1.party.Count)];
                }
                else
                {
                    defender = b.party0.party[Random.Range(0, b.party0.party.Count)];
                    attacker = b.party1.party[Random.Range(0, b.party1.party.Count)];
                }
            }

            defender.hp = defender.hp - attacker.atk;


            if (defender.hp <= 0)
            {
                defender.eliminated = true;
                defender.party.RemoveUnit(defender);
            }
        }
        yield return(null);
    }
    void Update()
    {
        // WASD & Arrow Keys -Movement
        this.transform.position += new Vector3(Input.GetAxis("Horizontal") * speed /*down*/, Input.GetAxis("Vertical") * speed /*up*/, 0);


        //Mining
        if (Input.GetMouseButtonDown(0))
        {
            Ray          ray = Camera.main.ScreenPointToRay(Input.mousePosition);
            RaycastHit2D hit = Physics2D.Raycast(ray.origin, ray.direction);

            if (hit.collider != null)
            {
                GameObject target = (GameObject)hit.collider.gameObject;
                //enemy attack
                if (target.name == "Enemy")
                {
                    battle b = target.GetComponent <battle>();
                    if (b != null)
                    {
                        b.StartCoroutine("animate");
                    }
                    if (b == null)
                    {
                        Debug.Log("Missing script!");
                    }
                }
                else
                {
                    // portals
                    Animator anim = target.GetComponent <Animator>();
                    if (anim != null)
                    {
                        anim.SetTrigger("Chopping");
                    }
                    pos = target.transform.position;
                    Destroy(target);
                    GameObject a = (GameObject)Instantiate(Block, pos, Quaternion.identity);

                    a.GetComponent <changetype>().change(6);
                }
            }
        }
    }
    public void OnPointerClick(PointerEventData eventData)
    {
        battle script = GameObject.Find("BattleManager").GetComponent <battle>();

        if (script.currentPhase == battle.phase.battle)
        {
            int myPosition = -1;
            if (script.aiming == false)
            {
                if (gameObject.transform.parent.name == "MyCardZone")
                {
                    myPosition = int.Parse(gameObject.name.Substring(8, 1));
                    if (CanIAttackYou(myPosition))
                    {
                        script.aiming = true;
                        LoadCardDataFromjson(script.field[myPosition - 1 + script.how_many_my_right]);
                        if (Carddata.type == Type.MERCENARY)
                        {
                            script.attacker = myPosition;
                        }
                        else if (Carddata.type == Type.SPELL)
                        {
                            activateSpell(myPosition);
                            script.aiming = false;
                        }
                        else
                        {
                            script.aiming = false;
                        }
                    }
                }
                else if (gameObject.transform.name == "MyCharacterZone")
                {
                    myPosition    = 0;
                    script.aiming = true;
                    if (CanIAttackYou(myPosition))
                    {
                        script.attacker = myPosition;
                    }
                }
            }
            else
            {
                if (gameObject.transform.parent.name == "EnemyCardZone")
                {
                    myPosition    = int.Parse(gameObject.name.Substring(8, 1)) + 6;
                    script.aiming = false;
                }
                else if (gameObject.transform.name == "EnemyCharacterZone")
                {
                    myPosition    = 6;
                    script.aiming = false;
                }
                if (script.aiming == false)
                {
                    if (CanYouAttackedbyMe(myPosition))
                    {
                        script.fight(script.attacker, myPosition);
                    }
                    else
                    {
                        script.aiming = false;
                    }
                }
            }
        }
    }
Beispiel #8
0
 TryAppend(battle, entity.FirstBattleDetail);