Beispiel #1
0
    public static TargetableObject GetPlayer()
    {
        TargetableObject player = null;

        if (battleInfo.GetAttacker().MyCountry.isPlayerCountry)
        {
            player = battleInfo.GetAttacker();
        }
        else if (battleInfo.GetDefender().MyCountry.isPlayerCountry)
        {
            player = battleInfo.GetDefender();
        }

        return(player);
    }
Beispiel #2
0
    public static TargetableObject GetAI()
    {
        TargetableObject ai = null;

        if (battleInfo.GetAttacker().MyCountry.isPlayerCountry == false || battleInfo.GetAttacker().MyCountry == null)
        {
            ai = battleInfo.GetAttacker();
        }
        else if (battleInfo.GetDefender().MyCountry.isPlayerCountry == false || battleInfo.GetDefender().MyCountry == null)
        {
            ai = battleInfo.GetDefender();
        }

        return(ai);
    }
    private void Start()
    {
        TargetableObject attacker       = BattleManager.battleInfo.GetAttacker();
        TargetableObject defender       = BattleManager.battleInfo.GetDefender();
        Color            noCountryColor = CountryManager.instance.NoCountryColor;

        attackerColorObj.GetComponent <Renderer>().material.SetColor("_Color", attacker.MyCountry != null ? attacker.MyCountry.GetCountryColor() : noCountryColor);
        defenderColorObj.GetComponent <Renderer>().material.SetColor("_Color", defender.MyCountry != null ? defender.MyCountry.GetCountryColor() : noCountryColor);

        obj = Instantiate(attackBulletPrefab, transform);
        obj.AddComponent <AudioSource>();
        obj.transform.localScale = new Vector3(10, 10, 10);
        currentCardAction        = new CardActionMove(null, null, new Vector3());

        RefreshUI();
    }
Beispiel #4
0
    public static bool WasThisBattleAlreadyStarted(TargetableObject attacker, TargetableObject defender)
    {
        foreach (BattleInfo item in thisFrameBattles)
        {
            if (item != null)
            {
                if (item.GetAttacker().GetInstanceID() == attacker.GetInstanceID() && item.GetDefender().GetInstanceID() == defender.GetInstanceID() ||
                    item.GetAttacker().GetInstanceID() == defender.GetInstanceID() && item.GetDefender().GetInstanceID() == attacker.GetInstanceID())
                {
                    return(true);
                }
            }
        }

        return(false);
    }
Beispiel #5
0
    public static void QuickBattle(TargetableObject attacker, TargetableObject defender)
    {
        Debug.Log("Starting quick battle by " + attacker.name, attacker.gameObject);

        BattleInfo bInfo = new BattleInfo();

        bInfo.Setup(attacker, defender);
        thisFrameBattles.Add(bInfo);

        battleInfo.Setup(attacker, defender);

        battleResult.isStarted = true;

        ///////////// BATTLE END /////////////

        bool attackerWin = false;

        float attackerStrength = attacker.GetArmy().GetArmyStrength();
        float defenderStrength = defender.GetArmy().GetArmyStrength();
        float result           = (Mathf.Max(attackerStrength, defenderStrength) - Mathf.Min(defenderStrength, attackerStrength)) / Mathf.Max(attackerStrength, defenderStrength);

        if (defenderStrength <= 0f || attackerStrength <= 0f)
        {
            result = 1f;
        }

        Debug.Log("Battle result for Astrength " + attackerStrength + " and Dstrength " + defenderStrength + " result: " + result);

        if (attacker.GetArmy().IsThisArmyStrongerThan(defender.GetArmy()))
        {
            attackerWin = true;
            defender.GetArmy().RemoveAllUnits();
            attacker.GetArmy().ChangeUnitsAmountByPercentage(result);
        }
        else
        {
            attackerWin = false;
            attacker.GetArmy().RemoveAllUnits();
            defender.GetArmy().ChangeUnitsAmountByPercentage(result);
        }

        BattleManager.RemoveAllUnitInstancesThatShouldBeDestroyed();
        battleResult = new BattleResult(attackerWin, false, true);

        EndBattleImmediate();
        FinishBattle();
    }
Beispiel #6
0
    private void SpawnAIArmy()
    {
        TargetableObject ai = BattleManager.GetAI();

        if (ai != null)
        {
            int rowIndex = 0;
            //Spawn on other side if player is defending
            FitRowIndex(ref rowIndex, 0, false);

            foreach (UnitInstance unit in ai.GetArmy().GetUnits())
            {
                Card card = SpawnUnitInRow(unit, rowIndex, ai.MyCountry);
                BattleAI.instance.AddCard(card);
            }
        }
    }
Beispiel #7
0
    private void SpawnPlayerArmy()
    {
        TargetableObject player = BattleManager.GetPlayer();

        if (player != null)
        {
            int rowIndex = 0;
            //Spawn on other side if blayer is defending
            FitRowIndex(ref rowIndex, 0, true);

            foreach (UnitInstance unit in player.GetArmy().GetUnits())
            {
                Card card = SpawnUnitInRow(unit, rowIndex, player.MyCountry);
                playerCards.AddCard(card);
            }
        }
    }
Beispiel #8
0
    public override void OnBattleWon(TargetableObject attacker)
    {
        if (MyCountry.isPlayerCountry)
        {
            ActionManager.instance.CreateAction(ActionManager.ActionInformationContent.PlayerBuildingCaptured, gameObject);
        }

        ChangeRelationsAfterBattle(attacker.MyCountry);
        attacker.MyCountry.CaptureNewBuilding(this);
        OnBattleWonBase();

        //Move random unit from attacker's army after conquering this Building
        if (!attacker.MyCountry.isPlayerCountry)
        {
            MoveOneRandomUnitFromAttackerArmy(attacker);
        }
    }
Beispiel #9
0
    public static void StartBattle(TargetableObject attacker, TargetableObject defender)
    {
        Debug.Log("Starting battle!");
        battleInfo.Setup(attacker, defender);

        TacticalMode.instance.Disable();
        //TimeManager.SetPauseTime();
        SceneUtils.instance.LoadBattleSceneAdditive();
        SceneUtils.instance.EnterBattleScene();

        Debug.LogError("Changing fog start/end by code!");
        RenderSettings.fogStartDistance = 25;
        RenderSettings.fogEndDistance   = 40;

        battleResult.isStarted = true;
        isDuringBattle         = true;
    }
Beispiel #10
0
    void ExitFromCurrentObject()
    {
        if (dockedIn)
        {
            if (destinationObject == dockedIn)
            {
                destinationObject = null;
            }
            dockedIn.ExitThisObject(this);
            //Undock();
        }

        if (destinationObject)
        {
            destinationObject = null;
        }
    }
Beispiel #11
0
    public static void EndBattleImmediate()
    {
        TargetableObject attacker = battleInfo.GetAttacker();
        TargetableObject defender = battleInfo.GetDefender();

        if (battleResult.victory)
        {
            if (attacker.MyCountry != defender.MyCountry)
            {
                defender.OnBattleWon(attacker);
            }
        }
        else
        {
            defender.OnBattleLost(attacker);
        }

        //FinishBattle();
    }
Beispiel #12
0
        private void Interact(TargetableObject obj)
        {
            switch (obj.TargetableObjectType)
            {
            case TargetableObject.TargetableObjectTypes.Obtainable:
                try {
                    ObtainableObject obtObj = obj.GetComponent <ObtainableObject>();
                    _inventoryController.AddItem(obtObj.GetItem());
                    Destroy(obj.gameObject);
                }
                catch (InventoryController.InventoryFullException e) {
                    //Trigger object animation here
                }
                break;

            default:
                break;
            }
        }
    void EndBattle()
    {
        TargetableObject winner = GetWinner();
        TargetableObject loser  = GetLoser();

        Debug.Log("Winner: " + winner.MyCountry.GetCountryName());
        Debug.Log("Loser: " + loser.MyCountry.GetCountryName());

        if (GetAICards().Count <= 0 || GetPlayerCards().Count <= 0)
        {
            if (BattleManager.battleInfo.GetAttacker() == winner)
            {
                WinBattle();
            }
            else
            {
                LoseBattle();
            }
        }
    }
Beispiel #14
0
    // Update is called once per frame
    void Update()
    {
        if (!isServer && !isLocalPlayer)
        {
            return;
        }
//		Debug.Log(isServer+" "+name+" "+target+" "+powerHandler.isPowerReady(0));
        //this shouldn't happen every frame
        if (target != null)
        {
            if (!target.isAlive())
            {
                target = null;
            }
            if (powerHandler.isPowerReady(0))
            {
                usePower(0, true);
            }
        }
    }
Beispiel #15
0
 void OnTriggerEnter(Collider other)
 {
     otherTarget = other.GetComponent<TargetableObject>();
     if (thisCollider != null && otherTarget != null)
     {
         if (otherTarget.allegiance != Allegiance)
         {
             DamageInfo damageInfo = new DamageInfo(gameObject, damage);
             HealthController health = other.GetComponent<HealthController>();
             Shield shield = other.GetComponent<Shield>();
             if(shield != null && shield.Charge > 0f)
             {
                 shield.Damage(damageInfo);
             }
             else if (health != null)
             {
                 health.Damage(damageInfo);
                 health.ImpactExplosion(transform.position);
             }
             Destroy(gameObject);
         }
     }
 }
Beispiel #16
0
 void OnTriggerEnter(Collider other)
 {
     _otherTarget = other.GetComponent <TargetableObject>();
     if (_thisCollider != null && _otherTarget != null)
     {
         if (_otherTarget.Allegiance != allegiance)
         {
             DamageInfo       damageInfo = new DamageInfo(gameObject, damage);
             HealthController health     = other.GetComponent <HealthController>();
             Shield           shield     = other.GetComponent <Shield>();
             if (shield != null && shield.Charge > 0f)
             {
                 shield.Damage(damageInfo);
             }
             else if (health != null)
             {
                 health.Damage(damageInfo);
                 health.ImpactExplosion(transform.position);
             }
             Destroy(gameObject);
         }
     }
 }
Beispiel #17
0
    public bool MoveToTargetObject(TargetableObject targetObject)
    {
        if (destinationObject && targetObject)
        {
            if (destinationObject.GetInstanceID() == targetObject.GetInstanceID() && IsDocked())
            {
                if (dockedIn.GetInstanceID() == targetObject.GetInstanceID())
                {
                    return(true);
                }
            }
        }

        Debug.Log("Moving to target obj");
        if (targetObject == null)
        {
            destinationObject = null;
            MoveToPosition(transform.position);
            Debug.LogError("TargetObject == null! Was that intended?");
            return(false);
        }

        MoveToPosition(targetObject.GetEntrancePos());
        destinationObject = targetObject;

        if (destinationObject)
        {
            if (IsOnDestinationPosition())
            {
                return(true);
            }
        }



        return(false);
    }
Beispiel #18
0
    public void Axis_Lock(float value)
    {
        if (value > 0.5f && !lockPressed)
        {
            float            minDist = float.PositiveInfinity;
            TargetableObject targ    = null;

            foreach (var f in FindObjectsOfType <Fighter>())
            {
                if (f.transform != transform)
                {
                    Vector3 vpos = viewTarget.camera.WorldToScreenPoint(f.transform.position);
                    if (vpos.z > 0)
                    {
                        float dist = vpos.sqrMagnitude;
                        if (dist < minDist)
                        {
                            minDist = dist;
                            targ    = f;
                        }
                    }
                }
            }

            if (targ != null)
            {
                controlled.target = targ;
            }

            lockPressed = true;
        }
        else if (value < 0.5f)
        {
            lockPressed = false;
        }
    }
Beispiel #19
0
 public override void OnBattleLost(TargetableObject attacker)
 {
     Debug.Log("PlotCity won. Try again to win");
     Destroy(attacker.gameObject);
     SetWallsActive();
 }
Beispiel #20
0
    private void ChooseTarget()
    {
        if (Time.time >= chooseTargetTimer || target == null)
        {
            chooseTargetTimer = Time.time + Random.Range(5, 30);

            bool possibleTarget = false;
            TargetableObject[] objects = FindObjectsOfType(typeof(TargetableObject)) as TargetableObject[];

            // Check if there is an appropriate target
            foreach(var obj in objects)
            {
                if(obj.allegiance != allegiance)
                {
                    possibleTarget = true;
                }
            }

            // Choose a random target
            if(possibleTarget)
            {
                do
                {
                    targetableObject = objects[Random.Range(0, objects.Length)];
                    target = targetableObject.transform;
                } while (target == null || targetableObject.allegiance == allegiance);
            }
            else
            {
                target = null;
            }
        }
    }
Beispiel #21
0
 public override void OnBattleLost(TargetableObject attacker)
 {
     enteredWorldAgent = null;
     Destroy(attacker.gameObject);
 }
Beispiel #22
0
 public override void OnBattleWon(TargetableObject attacker)
 {
     attacker.MyCountry.Inventory.AddItem(chosenItemsOption);
     enteredWorldAgent = null;
     DestroyMe();
 }
Beispiel #23
0
 public abstract void Resolve(TargetableObject instigator, TargetableObject target);
 public override void Initialize(TargetableObject targetableObject)
 {
     _engine       = targetableObject.GetComponent <Engine>();
     _initialSpeed = _engine.currentSpeed;
 }
Beispiel #25
0
 public override void OnBattleLost(TargetableObject attacker)
 {
     ChangeRelationsAfterBattle(attacker.MyCountry);
     Destroy(attacker.gameObject);
 }
Beispiel #26
0
    // Update is called once per frame
    void Update()
    {
        if (!isLocalPlayer)
        {
            return;
        }
//these should be changed to InputManager for easier remapping.

        /*if (Input.GetButtonDown("Shift")) {
         *      shiftPressed = true;
         * }
         * else if (Input.GetButtonUp("Shift")) {
         *      shiftPressed = false;
         * }*/
        // Power hotkeys
        if (Input.GetKeyDown(KeyCode.Q))
        {
            Debug.Log("Q");
            combatHandler.usePower(1);
        }
        if (Input.GetKeyDown(KeyCode.W))
        {
            Debug.Log("W");
            combatHandler.usePower(2);
        }
        if (Input.GetKeyDown(KeyCode.E))
        {
            Debug.Log("E");
            combatHandler.usePower(3);
        }
        if (Input.GetKeyDown(KeyCode.R))
        {
            Debug.Log("R");
            combatHandler.usePower(4);
        }
        //
        if (Input.GetKeyDown(KeyCode.S))
        {
            //stop attack and stop moving
            Debug.Log("S");
        }
        //Split movement and selecting to 2 different buttons
        //Need to implmement move to
        //select
        if (Input.GetButtonDown("Fire1"))
        {
            var mousePos = Input.mousePosition;
            mousePos.z = 10;
            RaycastHit2D[] hits          = Physics2D.RaycastAll(Camera.main.ScreenToWorldPoint(mousePos), Vector2.zero);
            int            foundPriority = -1;
            GameObject     selected;
            for (int x = 0; x < hits.Length; x++)
            {
                RaycastHit2D hit = hits[x];
                if (hit.collider != null)
                {
                    //square = hit.collider.gameObject.GetComponent<Square>();
                    selected = hit.collider.gameObject;
                    if (selected.tag != "Ground")
                    {
                        foundPriority = 1;
                        touched       = selected;
                    }
                }
            }
            if (touched == null)
            {
                return;
            }
            TargetableObject targetable = touched.GetComponent <TargetableObject>();
            if (targetable != null)
            {
                combatHandler.target = targetable;
            }
            //movementHandler.moveToTarget(touched.transform);
        }
        //move
        else if (Input.GetButtonDown("Fire2"))
        {
            var mousePos = Input.mousePosition;
            mousePos.z = 10;
            RaycastHit2D[] hits          = Physics2D.RaycastAll(Camera.main.ScreenToWorldPoint(mousePos), Vector2.zero);
            int            foundPriority = -1;
            GameObject     selected;
            for (int x = 0; x < hits.Length; x++)
            {
                RaycastHit2D hit = hits[x];
                if (hit.collider != null)
                {
                    //square = hit.collider.gameObject.GetComponent<Square>();
                    selected = hit.collider.gameObject;
                    if (selected.tag == "Ground" && foundPriority <= -1)
                    {
                        foundPriority = 0;
                        touched       = selected;
                    }
                }
            }
            if (touched == null)
            {
                return;
            }
            Vector3 pos = Camera.main.ScreenToWorldPoint(Input.mousePosition);
            pos.z = 0;
            movementHandler.moveToLocation(pos);
        }
    }
Beispiel #27
0
 public override void OnBattleWon(TargetableObject attacker)
 {
     Debug.Log("Battle won! Attacker: " + attacker);
     ChangeRelationsAfterBattle(attacker.MyCountry);
     Destroy(gameObject);
 }
Beispiel #28
0
 public void RemoveTargetableObject(TargetableObject to)
 {
     _targetableObjects.Remove(to);
 }
Beispiel #29
0
 public void AddTargetableObject(TargetableObject to)
 {
     _targetableObjects.Add(to);
 }
Beispiel #30
0
 public void DockTo(TargetableObject target)
 {
     dockedIn = target;
 }
Beispiel #31
0
 public void Undock()
 {
     dockedIn = null;
 }
Beispiel #32
0
 public void initialize(BasicPower payload, TargetableObject target, GameObject owner)
 {
     this.payload = payload;
     this.target  = target;
     this.owner   = owner;
 }