Example #1
0
    public void SetAttackTarget(BMapTile bMapTile)
    {
        Debug.Log("SetAttackTarget action=" + action);
        switch (action)
        {
        case Action.ATTACK:
        {
            SelectAttackTarget(bMapTile);
            break;
        }

        case Action.CONFIRMATTACK:
        {
            if (bMapTile == target)
            {
                context.controller.AttackMapTile(this.unit, bMapTile.mapTile, selectedAttack);
                action = Action.IDLE;
            }
            else
            {
                SelectAttackTarget(bMapTile);
            }
            break;
        }
        }
    }
    /// <summary>
    /// Routine to perfome a attack animation
    /// </summary>
    /// <returns>IEnumerator is needed for co-routines.<</returns>
    /// <param name="target">The BUnit whom is the attack target.</param>
    /// <param name="attack">The attack which will be performed.</param>
    /// <param name="efficeny">0 = not effectiv, 1 = normal efficeny, 2 = very effectiv</param>
    /// <param name="damage">The amount of damage dealt by this attack.</param>
    public IEnumerator AttackRoutine(UnitAttackedEvent e, BMapTile target, BUnit[] victims, BCombatMenu bCombatMenu)
    {
        meshContainer.transform.LookAt(target.transform.position);
        bCombatMenu.Hide();
        // sound effect
        attackSound.Play();
        // animation
        animator.SetTrigger("AttackTrigger");
        // wait some time before starting the attack effect
        yield return(new WaitForSeconds(e.attack.effectDelay));

        // caluclate the direction of the attack and project it on one of the 4 vectors: (0,1),(1,0),(0,-1),(-1,0)
        Vector direction = new Vector(Mathf.FloorToInt(target.transform.position.x - this.transform.position.x),
                                      Mathf.FloorToInt(target.transform.position.z - this.transform.position.z));

        direction.NormalizeTo4Direction();
        BParticleManager.PlayEffect(e.attack.attackName, target.transform.position, new Vector3(direction.x, 0, direction.y));

        // wait some time before trigger the hit animtion/effect
        yield return(new WaitForSeconds(e.attack.hitDelay));

        for (int i = 0; i < victims.Length; i++)
        {
            victims[i].PlayHitAnimation(e.efficiency, e.damage[i]);
            victims[i].unitUI.ShowDamage(e.damage[i]);
        }

        // wait the rest of the time for the animation before contuine with next event
        yield return(new WaitForSeconds(e.attack.fullAnimationTime - e.attack.effectDelay - e.attack.hitDelay));

        EventProxyManager.FireEvent(this, new EventDoneEvent());
    }
Example #3
0
    void HandleToppingDestroyed(object sender, EventArgs args)
    {
        ToppingDestroyedEvent e = args as ToppingDestroyedEvent;
        BMapTile bMapTile       = GetBMapTile(e.target.mapTile);

        bMapTile.DestroyTopping();
        EventProxyManager.FireEvent(this, new EventDoneEvent());
    }
    // Use this for initialization
    void Awake()
    {
        if (Application.isPlaying)
        {
            Destroy(this);
        }

        bMapTile = GetComponent <BMapTile>();
    }
Example #5
0
 public void Activate()
 {
     target = context.GetBMapTile(this.unit.mapTile);
     path   = new Path(new MapTile[] { this.unit.mapTile });
     ClearDisplayRange();
     if (unit.team == Unit.Team.PLAYER)
     {
         DisplayMovementRange(this.unit.mapTile, unit.MovePoints);
     }
 }
Example #6
0
    void OnTap()
    {
        // we clicked with mouse or tapped on the touchscreen

        // cast an ray from the screen point
        Ray cursorRay = Camera.main.ScreenPointToRay(Input.mousePosition);

        // create layer mask to ignore layer "Ignore Raycast" and hit all others
        int mask = 1 << LayerMask.NameToLayer("Ignore Raycast");

        mask = ~mask;

        BMapTile bMapTile = null;

        RaycastHit[] hits = Physics.RaycastAll(cursorRay, Mathf.Infinity, mask);

        // this does not work since buttons will be Deactivate just as we cast the ray
        // so we don't hit them anymore :(
        if (CheckUIHit())
        {
            return;
        }

        // check all objects hit on raycast
        foreach (RaycastHit hit in hits)
        {
            // let's see what we hit with the raycast
            switch (hit.collider.gameObject.layer)
            {
            case UI_LAYER:
                // we hit an ui element first
                // stop looking for map and stuff and just return
                Debug.LogWarning("Hit UI! Stop here");
                return;

            case UNIT_LAYER:
                // find the quad the unit is standing on
                BUnit bUnit = hit.collider.GetComponent <BUnit>();
                // fire event for the tapped bUnit
                tapFieldSound.Play();
                EventProxyManager.FireEvent(this, new BUnitTappedEvent(bUnit));
                break;

            case GRID_LAYER:
                // we hit an quad of the map
                bMapTile = hit.collider.GetComponent <BMapTile>();
                // fire event for the tapped mapTile
                tapFieldSound.Play();
                EventProxyManager.FireEvent(this, new BMapTileTappedEvent(bMapTile));
                break;
            }
        }
    }
Example #7
0
    public void SelectMovementTarget(Path path)
    {
        // save selected target
        this.path.Add(path);
        target = context.GetBMapTile(this.path.Last);

        ClearDisplayRange();
        DisplayMovementRange(target.mapTile, unit.MovePoints - this.path.Cost);
        // display calculated path
        context.HighlightMovementPath(this.path);
        context.SetFieldMarker(target);

        action = Action.CONFIRMMOVE;
    }
Example #8
0
    public void SelectAttackTarget(BMapTile bMapTile)
    {
        // save selected target
        target = bMapTile;

        ClearDisplayRange();
        DisplayAttackRange(selectedAttack);
        context.DisplayArea(bMapTile, RotateArea(selectedAttack.area));
        context.SetFieldMarker(bMapTile);

        action = Action.CONFIRMATTACK;

        bCombatMenu.HideAttackinfo();
    }
Example #9
0
    void HighlightBMapTile(BMapTile bMapTile, int mode, bool isAttackRange)
    {
        switch (mode)
        {
        case DisplayRangeMode.TEAM_0_CLICKABLE:
            // mark BMapTile as clickable if there is a unit of team 0 on top
            // use inRange material else
            if (bMapTile.mapTile.unit != null)
            {
                if (bMapTile.mapTile.unit.team == Unit.Team.AI)
                {
                    bMapTile.ChangeColorState(BMapTile.ColorState.CLICKABLE);
                }
            }
            else
            {
                bMapTile.ChangeColorState(BMapTile.ColorState.MOVERANGE);
            }
            break;

        case DisplayRangeMode.TEAM_1_CLICKABLE:
            // mark BMapTile as clickable if there is a unit of team 1 on top
            // use inRange material else
            if (bMapTile.mapTile.unit != null)
            {
                if (bMapTile.mapTile.unit.team == Unit.Team.PLAYER)
                {
                    bMapTile.ChangeColorState(BMapTile.ColorState.CLICKABLE);
                }
            }
            else
            {
                bMapTile.ChangeColorState(BMapTile.ColorState.MOVERANGE);
            }
            break;

        case DisplayRangeMode.ALL_CLICKABLE:
            // mark the BMapTile alweays as clickable
            // use different color states for attack range and move range
            if (isAttackRange)
            {
                bMapTile.ChangeColorState(BMapTile.ColorState.ATTACKRANGE);
            }
            else
            {
                bMapTile.ChangeColorState(BMapTile.ColorState.MOVERANGE);
            }
            break;
        }
    }
Example #10
0
    void HandleUnitAttacked(object sender, EventArgs args)
    {
        UnitAttackedEvent e = args as UnitAttackedEvent;

        BUnit[] bUnits = new BUnit[e.victims.Count];
        for (int i = 0; i < e.victims.Count; i++)
        {
            bUnits[i] = GetBUnit(e.victims[i]);
        }

        BMapTile bMapTile = GetBMapTile(e.target);

        GetBUnit(e.source).PlayAttack(e, bMapTile, bUnits);
        CleanMap();
    }
Example #11
0
    void HandleUnitMoved(object sender, EventArgs args)
    {
        UnitMovedEvent e = args  as UnitMovedEvent;

        // convert MapTile path to BMapTile path
        BMapTile[] path = new BMapTile[e.path.Length];
        for (int i = 0; i < e.path.Length; i++)
        {
            path[i] = GetBMapTile(e.path[i]);
        }
        // send movement path to BUnit for animation
        GetBUnit(e.unit).MoveAlongPath(path);
        bCameraMover.Focus(path.Last().transform.position);
        CleanMap();
    }
Example #12
0
    public void DisplayArea(BMapTile bMaptile, Vector[] area)
    {
        int x = 0;
        int y = 0;

        //bCombatMenu.backButton.gameObject.SetActive(true);

        foreach (Vector pt in area)
        {
            x = bMaptile.mapTile.x + pt.x;
            y = bMaptile.mapTile.y + pt.y;
            if (x >= 0 && x < bMap.lengthX && y >= 0 && y < bMap.lengthY)
            {
                bMap[x, y].ChangeColorState(BMapTile.ColorState.ATTACKAREA);
            }
        }
    }
Example #13
0
 public void PlayAttack(UnitAttackedEvent e, BMapTile target, BUnit[] victims)
 {
     StartCoroutine(bUnitAnimator.AttackRoutine(e, target, victims, bCombatMenu));
 }
Example #14
0
 /// <summary>
 /// Place a marker on the given BMapTile
 /// </summary>
 /// <param name="bMapTile">BMapTile.</param>
 public void SetFieldMarker(BMapTile bMapTile)
 {
     BParticleManager.PlayEffect("FieldMarker", bMapTile.transform.position);
 }
Example #15
0
 public BMapTileTappedEvent(BMapTile bMapTile)
 {
     this.name     = EventName.BMapTileTapped;
     this.bMapTile = bMapTile;
 }