Пример #1
0
 public override void OnInspectorGUI()
 {
     base.OnInspectorGUI();
     if (GUILayout.Button("Reset Position"))
     {
         TileOccupier tileOccupier = (TileOccupier)target;
         tileOccupier.transform.position = GameObject.Find("Tiles").GetComponent <TileManager>().FindTiles(tileOccupier.X, tileOccupier.Y)[tileOccupier.Index].transform.position;
     }
 }
Пример #2
0
    private void Update()
    {
        TileOccupier tO = TileOccupier.GetTileOccupant(Engine.MapCursor.GetTile());

        if (tO != null && tO.gameObject == gameObject && Engine.MapCursor.PanelMode != 0)
        {
            Mode = Engine.MapCursor.PanelMode;
        }
        else
        {
            Mode = 0;
        }
    }
Пример #3
0
    public static void ThrowStone(CombatUnit caster, Tile targetTile, CombatUnit targetUnit)
    {
        Action action = Engine.CombatManager.ActionTable["ThrowStone"];

        Timeline t = new GameObject("Throw Stone Timeline").AddComponent <Timeline>();

        t.gameObject.AddComponent <CameraFocus_TimelineEvent>().Init(t, 0, caster.transform.position, .5f);
        t.Advance(.5f);

        t.gameObject.AddComponent <Message_TimelineEvent>().Init(t, 0, "Effect", action.GetName());
        t.Advance(.15f);

        t.gameObject.AddComponent <FaceTile_TimelineEvent>().Init(t, 0, caster.GetComponent <Facer>(), targetTile);
        t.gameObject.AddComponent <UnitAnimation_TimelineEvent>().Init(t, 0, "Armature|SwordAttack", caster.GetComponentInChildren <Animator>());
        t.gameObject.AddComponent <PlaySound_TimelineEvent>().Init(t, 0, "sword_swing");
        t.Advance(.25f); // Moment of impact


        TileOccupier tO = TileOccupier.GetTileOccupant(targetTile);

        if (tO != null)
        {
            targetUnit = tO.GetComponent <CombatUnit>();

            int damage = Action.Mod2(caster.PA, false, Element.None, caster, targetUnit, System.Reflection.MethodBase.GetCurrentMethod().Name);


            targetUnit.TakeDamage(damage);

            t.gameObject.AddComponent <UnitAnimation_TimelineEvent>().Init(t, 0f, "Armature|Hurt", targetUnit.GetComponentInChildren <Animator>());
            t.gameObject.AddComponent <PlaySound_TimelineEvent>().Init(t, 0, "slash");
            t.gameObject.AddComponent <SpawnEffect_TimelineEvent>().Init(t, .2f, "PhysicalDamage", targetTile);
            t.gameObject.AddComponent <FlyingText_TimelineEvent>().Init(t, .35f, damage.ToString(), targetUnit);
            t.gameObject.AddComponent <UnitAnimation_TimelineEvent>().Init(t, .55f, caster.GetDefaultAnimation(), caster.GetComponentInChildren <Animator>());
            t.gameObject.AddComponent <UnitAnimation_TimelineEvent>().Init(t, .55f, targetUnit.GetDefaultAnimation(), targetUnit.GetComponentInChildren <Animator>());
            t.Advance(.55f);
        }
        else
        {
            t.gameObject.AddComponent <UnitAnimation_TimelineEvent>().Init(t, 1f, caster.GetDefaultAnimation(), caster.GetComponentInChildren <Animator>());
        }

        t.gameObject.AddComponent <DestroyTimeline_TimelineEvent>().Init(t, .25f);
        t.PlayFromStart();
    }
Пример #4
0
    // Update is called once per frame
    void Update()
    {
        animate();

        if (Engine.InputManager.Attach == this)
        {
            DelegatedInput();

            if (Engine.InputManager.Accept)
            {
                Engine.InputManager.Accept = false;
                TileOccupier tO = TileOccupier.GetTileOccupant(GetTile());
                if (tO)
                {
                    tO.GetComponent <CombatUnit>().ShowMenu();
                }
            }
        }
    }
Пример #5
0
    public static void Fire(CombatUnit caster, Tile targetTile, CombatUnit targetUnit)
    {
        Action action = Engine.CombatManager.ActionTable["Fire"];

        Timeline t = new GameObject("Fire Timeline").AddComponent <Timeline>();

        t.gameObject.AddComponent <CameraFocus_TimelineEvent>().Init(t, 0, caster.transform.position, .5f);
        t.Advance(.5f);

        t.gameObject.AddComponent <Message_TimelineEvent>().Init(t, 0, "Effect", action.GetName());
        t.Advance(.15f);

        t.gameObject.AddComponent <FaceTile_TimelineEvent>().Init(t, 0, caster.GetComponent <Facer>(), targetTile);
        t.Advance(.25f); // Moment of impact

        List <Tile> affected = action.AffectedTiles(targetTile, new List <Tile>());

        foreach (Tile affectedTile in affected)
        {
            TileOccupier tO = TileOccupier.GetTileOccupant(affectedTile);
            if (tO != null)
            {
                targetUnit = tO.GetComponent <CombatUnit>();
                int damage = Action.Mod5(Element.Fire, 14, caster, targetUnit);

                targetUnit.TakeDamage(damage);

                t.gameObject.AddComponent <CameraFocus_TimelineEvent>().Init(t, 0, tO.transform.position, .25f);
                t.gameObject.AddComponent <SpawnEffect_TimelineEvent>().Init(t, .25f, "Fire", tO.GetOccupiedTile());
                t.gameObject.AddComponent <UnitAnimation_TimelineEvent>().Init(t, 1.25f, "Armature|Hurt", tO.GetComponentInChildren <Animator>());
                t.gameObject.AddComponent <FlyingText_TimelineEvent>().Init(t, 2.25f, damage.ToString(), tO);
                t.gameObject.AddComponent <UnitAnimation_TimelineEvent>().Init(t, 3.75f, targetUnit.GetDefaultAnimation(), targetUnit.GetComponentInChildren <Animator>());
                t.gameObject.AddComponent <UnitAnimation_TimelineEvent>().Init(t, 3.75f, caster.GetDefaultAnimation(), caster.GetComponentInChildren <Animator>());
                t.Advance(3.75f);
            }
        }

        t.gameObject.AddComponent <UnitAnimation_TimelineEvent>().Init(t, 0f, caster.GetDefaultAnimation(), caster.GetComponentInChildren <Animator>());
        t.gameObject.AddComponent <DestroyTimeline_TimelineEvent>().Init(t, .25f);
        t.PlayFromStart();
    }
Пример #6
0
    public static CombatUnit TargetUnit(Tile targetTile)
    {
        TileOccupier tO = TileOccupier.GetTileOccupant(targetTile);

        return((tO != null) ? tO.GetComponent <CombatUnit>() : null);
    }
    private void Update()
    {
        if (Engine.InputManager.Attach != this)
        {
            return;
        }
        switch (State)
        {
        case TargetableActionState.WaitingForTileSelect:
            Engine.MapCursor.DelegatedInput();
            if (Engine.InputManager.Accept)
            {
                Engine.InputManager.Accept = false;
                Tile TargetTile = Engine.MapCursor.GetTile();
                if (TargetTile.CurrentlySelectable)
                {
                    TargetTile = Engine.MapCursor.GetTile();
                    HighlightAffectedTiles(TargetTile);
                    Caster.gameObject.GetComponent <UnitPanel>().ModeOverride = 1;
                    State = TargetableActionState.WaitingForTileConfirm;

                    if (TileOccupier.GetTileOccupant(TargetTile) != null)
                    {
                        CombatUnit target = TileOccupier.GetTileOccupant(TargetTile).GetComponent <CombatUnit>();
                        if (target)
                        {
                            PredictEffect(target);
                        }
                    }
                }
                else
                {
                    Message m = new GameObject().AddComponent <Message>();
                    m.BoxMessageLabel = "Check";
                    m.BoxMessage      = "Select within range.";
                    m.ReturnControlTo = this;
                    Engine.AssignControl(m);
                }
            }
            else if (Engine.InputManager.Cancel)
            {
                Engine.InputManager.Cancel = false;
                State = TargetableActionState.Inactive;
                Menu.ShowAllMenus();
                Engine.AssignControl(Menu);
                Engine.TileManager.ClearHighlights();     //Engine.PathManager.ClearAll(false);
                Engine.CameraManager.SetTargetPosition(Caster.transform.position, .5f);
                Engine.MapCursor.X = Caster.gameObject.GetComponent <TileOccupier>().X;
                Engine.MapCursor.Y = Caster.gameObject.GetComponent <TileOccupier>().Y;
                Engine.MapCursor.GoToTile();
            }
            break;

        case TargetableActionState.WaitingForTileConfirm:
            if (Engine.InputManager.Accept)
            {
                Engine.InputManager.Accept = false;
                Menu m = new GameObject().AddComponent <Menu>();
                m.Attach          = Caster.gameObject;
                m.Top             = .5f;
                m.Left            = .7f;
                m.name            = "Confirm Effect";
                m.ReturnControlTo = this;
                Execute_MenuOption e = m.gameObject.AddComponent <Execute_MenuOption>();
                SetExecute(e);
                m.AddMenuOption("Execute", e);
                NoExecute_MenuOption ne = m.gameObject.AddComponent <NoExecute_MenuOption>();
                m.AddMenuOption("Quit", ne);
            }
            if (Engine.InputManager.Cancel)
            {
                Engine.InputManager.Cancel = false;
                State = TargetableActionState.WaitingForTileSelect;

                Engine.TileManager.ClearHighlights();
                HighlightSelectableTiles();

                //Prediction[] ps = ReturnControlTo.gameObject.GetComponents<Prediction>();
                //foreach (Prediction p in ps)
                //{
                //    Destroy(p);
                //}
            }
            break;
        }
    }
Пример #8
0
    //public void MarkNeighbors(int MaxRange, int MaxJump)
    //{
    //    List<KeyValuePair<Tile, int>> neighbors = GetNeighbors(MaxRange, MaxJump);
    //    foreach(KeyValuePair<Tile, int> kvp in neighbors)
    //    {
    //        Tile t = (Tile)kvp.Key;
    //        t.Highlight();
    //        t.SearchNeighbors = true;
    //        if (BestParent.Key == null || kvp.Value < BestParent.Value)
    //        {
    //            t.BestParent = kvp;
    //        }
    //    }
    //}

    public void MarkTravelNeighbors(int MaxRange, int MaxJump)
    {
        Direction[] checkDirections = new Direction[] { Direction.North, Direction.East, Direction.South, Direction.West };

        for (int i = 0; i < checkDirections.Length; i++)
        {
            Direction d  = checkDirections[i];           // direction to check
            Direction di = checkDirections[(i + 2) % 4]; // direction inverse for edge

            int counter = 1;

            // Tiles in straight line
            while (counter <= MaxRange)
            {
                Tile[] tiles = transform.parent.GetComponent <TileManager>().FindTilesInDirection(this, d, counter);

                // Multiple tiles at same height
                foreach (Tile t in tiles)
                {
                    if (t == null)
                    {
                        // If there's no tile or the tile is unselectable, pass over it
                        continue;
                    }

                    // Gather some values
                    int   occupied      = TileOccupier.IsTileOccupied(t);
                    float difference    = Height - t.HeightAtEdge(di);
                    int   cost          = (int)Math.Abs(difference) + counter;
                    float walkThreshold = 2f;

                    // Determine some conditions
                    bool enemyOccupied  = (occupied == 1);
                    bool canWalk        = Math.Abs(difference) <= walkThreshold;
                    bool canJumpV       = Math.Abs(difference) <= MaxJump;
                    bool canJumpH       = ((counter - 1) <= MaxJump / 2);
                    bool terrainAllowed = true;

                    // Status
                    bool stop = false;
                    bool mark = false;

                    //// Check adjacent tiles on the next pass
                    //if (counter == 1 && !t.Impassable && !enemyOccupied)
                    //{
                    //    t.SearchNeighbors = true;
                    //}

                    // If the unit can't pass to this tile, stop and don't mark
                    if (t.Impassable)
                    {
                        stop = true;
                    }

                    // If the unit can walk to a tile, stop and mark
                    else if (counter == 1 && canWalk && terrainAllowed && !enemyOccupied)
                    {
                        stop = true;
                        mark = true;
                    }

                    // If the unit can jump up to the tile, stop and mark
                    else if (!enemyOccupied && counter == 1 && difference < 0 && canJumpV)
                    {
                        stop = true;
                        mark = true;
                    }

                    // If the unit can jump horizontally, stop and mark
                    else if (!enemyOccupied && canJumpH && difference == 0)
                    {
                        stop = true;
                        mark = true;
                    }

                    // If we can't jump horizontally this far, stop and don't mark
                    else if (counter > MaxJump / 2)
                    {
                        stop = true;
                    }

                    // If we can't travel this far, stop and don't mark
                    else if (counter > MaxRange)
                    {
                        stop = true;
                    }

                    // If the tile is impassable, stop and don't mark
                    else if (t.Impassable)
                    {
                        stop = true;
                    }

                    // If occupied by an enemy, stop and don't mark
                    else if (enemyOccupied)
                    {
                        stop = true;
                    }

                    // If we're obstructed by a barrier we can't jump up to, stop and don't mark
                    else if (!canJumpV && difference < 0)
                    {
                        stop = true;
                    }

                    // If the unit can jump down, continue and mark
                    else if (canJumpV && canJumpH && difference > 0)
                    {
                        mark = true;
                    }

                    // Do the actual work of marking/stopping
                    if (mark)
                    {
                        MarkTile(t, cost);
                        t.SearchNeighbors = counter;
                    }
                    if (stop)
                    {
                        counter += 1000; // arbitrarily high number
                    }
                }

                counter++;
            }
        }
    }