// called by attack button to instigate an AoE damage sequence
    public void AoEAttack()
    {
        //TileMarker.Instance.Clear();
        TileMarker.Instance.HideMarkers();

        // attacking unit has committed to this AoE weapon for the turn so equip it
        PlayerManager.Instance.getCurrentPlayer().selectedObject.GetComponent <Unit>().Equip(AoEWeapon);

        AoESequence = true;
        timer       = 0;

        GLOBAL.setLock(true);                // lock input during AoE sequence

        UIManager.Instance.setUnitUI(false); // disable unit UI (unit turn is done after attack sequence anyway)
        UIManager.Instance.deactivateConfirmButton();

        // play animation, offset by half of tilesize to accommodate center anchor
        if (AoEWeapon.AoEanim != null)
        {
            Instantiate(AoEWeapon.AoEanim, GLOBAL.gridToWorld(AoERoot) + new Vector3((int)(IntConstants.TileSize) / 2, (int)(IntConstants.TileSize) / 2), Quaternion.identity);
        }
        else
        {
            AoEWeapon.StartAoEAnim();
        }
    }
Example #2
0
    public void SetCrossHair(int posX, int posY)
    {
        this.gameObject.GetComponent <CrosshairsController>().target.x = posX;
        this.gameObject.GetComponent <CrosshairsController>().target.y = posY;

        this.gameObject.GetComponent <CrosshairsController>().displacement = GLOBAL.gridToWorld(this.gameObject.GetComponent <CrosshairsController>().target) - transform.position;
    }
    public void InitiateSequence()
    {
        // destroy crosshairs
        Destroy(lockon);

        // disable UI components
        DisableUI();

        preCombat = false;

        // calculate battle results before depicting (TEMP: needs to be greatly expanded, especially if we implement multiple attacks)
        attackerHit = false;
        defenderHit = false;

        if (Random.Range(0, 100) <= attackerHitrate)
        {
            attackerHit = true;
        }
        if (retaliation && Random.Range(0, 100) <= defenderHitrate)
        {
            defenderHit = true;
        }

        // TEMP movement stuff
        timer        = 0;
        displacement = (GLOBAL.gridToWorld(defender.pos) - GLOBAL.gridToWorld(attacker.pos)).normalized;

        phase = CombatPhase.attackerLunge;
    }
Example #4
0
    public IEnumerator AddAttackTile(int j, int i)
    {
        Debug.Log("Adding Attack Tile for player: " + PhotonNetwork.playerName);

        GameObject marker = Instantiate(TileMarker.Instance.attackMarker, GLOBAL.gridToWorld(j, i), Quaternion.identity) as GameObject;

        TileMarker.Instance.attackTiles.Add(new Vector2i(j, i), marker);

        yield return(0);
    }
Example #5
0
    // Use this for initialization
    void Start()
    {
        // get displacement
        displacement = GLOBAL.gridToWorld(target) - transform.position;

        timer = 0;

        // disable UI until lockon complete
        UIManager.Instance.setUnitUI(false);
    }
    // draw laser
    public override void StartAoEAnim()
    {
        int range = Mathf.Max((int)(unit.combatEnergyAtk * 0.5f), 3); // minimum beam size is 3x3 (length extendable)

        GameObject laserRoot = GameObject.Instantiate(Resources.Load("WeaponEffects/laser_root") as GameObject);

        laserRoot.transform.position = new Vector3(GLOBAL.gridToWorld(unit.pos).x + (int)IntConstants.TileSize * 0.5f, GLOBAL.gridToWorld(unit.pos).y + (int)IntConstants.TileSize * 0.5f);

        GameObject[] laser = new GameObject[range + 1];
        for (int i = 0; i < laser.Length; i++)
        {
            if (i == 0)
            {
                laser[i] = GameObject.Instantiate(Resources.Load("WeaponEffects/laser_tail")) as GameObject;
            }
            else if (i == laser.Length - 1)
            {
                laser[i] = GameObject.Instantiate(Resources.Load("WeaponEffects/laser_head")) as GameObject;
            }
            else
            {
                laser[i] = GameObject.Instantiate(Resources.Load("WeaponEffects/laser_mid")) as GameObject;
            }

            laser[i].transform.parent = laserRoot.transform;
        }

        // place laser pieces on correct tiles
        for (int i = 0; i < laser.Length; i++)
        {
            laser[i].transform.position = GLOBAL.gridToWorld(unit.pos + (new Vector2i(1, 0) * (i + 1)));
        }
        laser[laser.Length - 1].transform.Translate(new Vector3(-5, 0, 0)); // offset head of laser by 5 pixels

        // rotate laser according to direction
        foreach (GameObject go in laser)
        {
            go.transform.Translate(new Vector3(0, (int)IntConstants.TileSize * 0.5f, 0)); // move up half a tile due to units' bottomleft anchor
        }

        if (direction.y == 1)
        {
            laserRoot.transform.eulerAngles = new Vector3(0, 0, 90);
        }
        else if (direction.x == -1)
        {
            laserRoot.transform.eulerAngles = new Vector3(0, 0, 180);
        }
        else if (direction.y == -1)
        {
            laserRoot.transform.eulerAngles = new Vector3(0, 0, 270);
        }
    }
Example #7
0
    // Update is called once per frame
    void Update()
    {
        prevTimer = timer;
        timer    += Time.deltaTime;

        // handles crosshair movement
        if (moving)
        {
            if (timer < 0.8f)
            {
                transform.position += displacement * (Time.deltaTime / 0.8f);
            }

            else
            {
                transform.position = GLOBAL.gridToWorld(target);
                moving             = false;
                timer = 0;
                BlinkOff();
            }
        }
        // handles crosshair blinking
        else
        { // invoke's timing is really bizarre so hardcode it like a scrub
            if (timer >= 0.125f && prevTimer < 0.125f)
            {
                Camera.main.GetComponent <AudioSource>().PlayOneShot(sfx);
                BlinkOn();
            }
            else if (timer >= 0.2f && prevTimer < 0.2f)
            {
                BlinkOff();
            }
            else if (timer >= 0.325f && prevTimer < 0.325f)
            {
                BlinkOn();
            }
            else if (timer >= 0.4f && prevTimer < 0.4f)
            {
                BlinkOff();
            }
            else if (timer >= 0.525f && prevTimer < 0.525f)
            {
                BlinkOn();
            }
            else if (timer >= 0.6f && prevTimer < 0.6f)
            {
                Finish();
            }
        }
    }
    // marks all tiles a unit can reach
    public void markTravTiles(Unit unit)
    {
        int range = unit.effectiveMovementRange;

        // if the unit has flying mark all traversible tiles within movement range
        if (unit.flying)
        {
            for (int i = Mathf.Max(unit.Pos.y - range, 0); i <= Mathf.Min(unit.Pos.y + range, MapScript.Instance.Height); i++)
            {
                for (int j = Mathf.Max(unit.Pos.x - range, 0); j <= Mathf.Min(unit.Pos.x + range, MapScript.Instance.Width); j++)
                {
                    if (unit.Pos.Distance(j, i) <= range && terrain.Tiles[j, i].trav)
                    {
                        GameObject marker = Instantiate(travMarker, GLOBAL.gridToWorld(j, i), Quaternion.identity) as GameObject;
                        travTiles.Add(new Vector2i(j, i), marker);
                    }
                }
            }
        }

        // REAL TILE MARKING:
        else
        {
            // start by resetting all cost and parent info
            foreach (Tile t in TerrainLayer.Instance.Tiles)
            {
                t.cost   = 10000;
                t.parent = null;
            }

            Tile start = TerrainLayer.Instance.Tiles[unit.Pos.x, unit.Pos.y];

            start.cost = 0; //we are already on this tile; costs nothing to get where you already are

            PriorityQueue <Tile> openList = new PriorityQueue <Tile>();
            openList.Add(start, start.cost);

            while (!openList.Empty())
            {
                Tile current = openList.delete_min();

                if (current != start && ObjectManager.Instance.ObjectGrid[current.pos.x, current.pos.y] == null && !travTiles.ContainsKey(current.pos))
                { //don't add root, occupied or duplicate tiles to traversible list
                    GameObject marker = Instantiate(travMarker, GLOBAL.gridToWorld(current.pos), Quaternion.identity) as GameObject;
                    travTiles.Add(current.pos, marker);
                }

                expand(openList, current, range);
            }
        }
    }
    // called manually on enable by Unit.Attack(), shoots crosshairs at target
    public void Enable(Unit a, Unit d)
    {
        attacker = a;
        defender = d;

        attackerOrigWep = attacker.equipped;
        defenderOrigWep = defender.equipped;

        distance = attacker.pos.Distance(defender.pos);

        // Attacker selects weapon and presses CONFIRM button, then Defender selects weapon and presses CONFIRM calling InitiateSequence()
        // Note all UI is temporary.  These variables may have to be modified or nuked to accommodate whatever you decide to implement.

        // crosshair lockon
        lockon = Instantiate(crosshairs, GLOBAL.gridToWorld(attacker.pos), Quaternion.identity) as GameObject;
        lockon.GetComponent <CrosshairsController>().target = defender.pos;

        // check if units are equipping proper weapons (if available)
        CheckWeapons();

        // calculate damage and hit rate for each unit
        //CalculateStats();
    }
    public void addAoETile(Vector2i pos)
    {
        GameObject marker = Instantiate(AoEMarker, GLOBAL.gridToWorld(pos), Quaternion.identity) as GameObject;

        AoETiles.Add(pos, marker);
    }
Example #11
0
 // returns world distance from quantized position
 public float Distance(Vector3 v)
 {
     return(new Vector3(v.x - GLOBAL.gridToWorld(this).x, v.y - GLOBAL.gridToWorld(this).y, 0).magnitude);
 }
    public void createNext()
    {
        Unit     unit = CombatSequence.Instance.attacker;//PlayerManager.Instance.getCurrentPlayer().selectedObject.GetComponent<Unit>();
        Vector2i next = GLOBAL.worldToGrid(transform.position) + direction;

        if (next.x >= 0 && next.x < MapScript.Instance.mapWidth && next.y >= 0 && next.y < MapScript.Instance.mapHeight)
        {
            GameObject go = GameObject.Instantiate(Resources.Load("WeaponEffects/EnergyGreen") as GameObject, GLOBAL.gridToWorld(GLOBAL.worldToGrid(transform.position) + direction), Quaternion.identity) as GameObject;
            go.GetComponent <EnergyChainShot>().max       = max;
            go.GetComponent <EnergyChainShot>().direction = direction;
        }
    }
Example #13
0
    // generate initial 1-4 surrounding attacks
    public override void StartAoEAnim()
    {
        shot = Resources.Load("WeaponEffects/EnergyGreen") as GameObject;

        Vector2i dir   = new Vector2i(-1, 1);
        Vector2i start = unit.pos + dir;

        if (start.x >= 0 && start.y < MapScript.Instance.mapHeight)
        { // upper left
            GameObject go = GameObject.Instantiate(Resources.Load("WeaponEffects/EnergyGreen") as GameObject, GLOBAL.gridToWorld(start), Quaternion.identity) as GameObject;
            go.GetComponent <EnergyChainShot>().max       = max;
            go.GetComponent <EnergyChainShot>().direction = dir;
        }

        dir   = new Vector2i(1, 1);
        start = unit.pos + dir;
        if (start.x < MapScript.Instance.mapWidth && start.y < MapScript.Instance.mapHeight)
        { // upper right
            GameObject go = GameObject.Instantiate(Resources.Load("WeaponEffects/EnergyGreen") as GameObject, GLOBAL.gridToWorld(start), Quaternion.identity) as GameObject;
            go.GetComponent <EnergyChainShot>().max       = max;
            go.GetComponent <EnergyChainShot>().direction = dir;
        }

        dir   = new Vector2i(-1, -1);
        start = unit.pos + dir;
        if (start.x >= 0 && start.y >= 0)
        { // bottom left
            GameObject go = GameObject.Instantiate(Resources.Load("WeaponEffects/EnergyGreen") as GameObject, GLOBAL.gridToWorld(start), Quaternion.identity) as GameObject;
            go.GetComponent <EnergyChainShot>().max       = max;
            go.GetComponent <EnergyChainShot>().direction = dir;
        }

        dir   = new Vector2i(1, -1);
        start = unit.pos + dir;
        if (start.x < MapScript.Instance.mapWidth && start.y >= 0)
        { // bottom right
            GameObject go = GameObject.Instantiate(Resources.Load("WeaponEffects/EnergyGreen") as GameObject, GLOBAL.gridToWorld(start), Quaternion.identity) as GameObject;
            go.GetComponent <EnergyChainShot>().max       = max;
            go.GetComponent <EnergyChainShot>().direction = dir;
        }
    }