Esempio n. 1
0
    /// <summary>
    /// The brawler starts each fight phase without having used any attacks or defeated anyone.
    ///
    /// If the Brawler is a significant distance down the Rampage track, they also get ready to move into the spaces of enemies they defeat.
    /// </summary>
    public override void PrepareToFight()
    {
        base.PrepareToFight();

        attacksSoFar.Clear();
        lastDefeatedLoc = null;

        if ((int)currentRampage >= (int)RampageTrack.Wade_In)
        {
            boardFunc = JumpToSpace;
            Services.Events.Register <BoardClickedEvent>(boardFunc);
            jumpsSoFar = 0;
        }

        if (currentRampage == RampageTrack.Wade_In)
        {
            availableJumps = AVAILABLE_JUMPS_WADE_IN;
        }
        else if (currentRampage == RampageTrack.Berserk)
        {
            availableJumps = AVAILABLE_JUMPS_BERSERK;
        }
        else if (currentRampage == RampageTrack.The_Last_One_Standing)
        {
            availableJumps = AVAILABLE_JUMPS_LAST_STANDING;
        }
        defeatedLastTarget = true;         //important for The Last One Standing
    }
    /// <summary>
    /// The Ranger has an extra rule with regard to movement: the Movement Tricks track allows the Ranger to gain inspiration
    /// by moving their full distance.
    /// </summary>
    public override void Move()
    {
        Services.Tasks.AddTask(new MoveDefenderTask(rb, moveSpeed, moves));
        ClearLine();


        //move on the grid used for game logic
        Services.Board.TakeThingFromSpace(GridLoc.x, GridLoc.z);
        TwoDLoc destination = moves[moves.Count - 1];

        Services.Board.PutThingInSpace(gameObject, destination.x, destination.z, SpaceBehavior.ContentType.Defender);
        NewLoc(destination.x, destination.z);
        BeUnselected();
        Services.UI.ShutOffCharSheet();
        Services.Defenders.DeclareSelfDone(this);
        Services.Events.Fire(new NotSelectableEvent(this));

        if (currentMoveTricks > MoveTricksTrack.None)
        {
            if (remainingSpeed == 0)
            {
                DefeatAttacker();
            }
        }

        remainingSpeed = 0;

        //send out an event announcing that this defender has moved; important for the tutorial
    }
Esempio n. 3
0
    /// <summary>
    /// This function is enabled (as a delegate) when the Brawler is advancing down the Rampage track.
    ///
    /// Each time the board is clicked, this checks whether the place clicked is the place where the Brawler last
    /// defeated an enemy. If so, it moves the Brawler there.
    /// </summary>
    private void JumpToSpace(Event e)
    {
        if (jumpsSoFar >= availableJumps)
        {
            return;
        }

        BoardClickedEvent boardEvent = e as BoardClickedEvent;

        //if the clicked space wasn't the last place where the Brawler defeated an attacker, do nothing
        if (lastDefeatedLoc == null || boardEvent.coords.x != lastDefeatedLoc.x || boardEvent.coords.z != lastDefeatedLoc.z)
        {
            return;
        }

        //move on the screen
        Services.Tasks.AddTask(new MoveDefenderTask(rb, moveSpeed, new List <TwoDLoc>()
        {
            boardEvent.coords
        }));

        //move on the grid used for game logic
        Services.Board.TakeThingFromSpace(GridLoc.x, GridLoc.z);
        Services.Board.PutThingInSpace(gameObject, boardEvent.coords.x, boardEvent.coords.z, SpaceBehavior.ContentType.Defender);
        NewLoc(boardEvent.coords.x, boardEvent.coords.z);
        Services.Board.HighlightSpace(lastDefeatedLoc.x, lastDefeatedLoc.z, BoardBehavior.OnOrOff.Off);
        lastDefeatedLoc = null;

        //record this jump
        jumpsSoFar++;
    }
    /////////////////////////////////////////////
    /// Functions
    /////////////////////////////////////////////


    #region setup


    //initialize variables
    public virtual void Setup()
    {
        Speed            = baseSpeed;
        AttackMod        = baseAttackMod;
        Armor            = baseArmor;
        Selected         = false;
        selectedParticle = transform.Find(SELECT_PARTICLE_OBJ).gameObject;
        lineRend         = GetComponent <LineRenderer>();
        ClearLine();
        moveButton            = transform.Find(PRIVATE_UI_CANVAS).Find(MOVE_BUTTON_OBJ).GetComponent <Button>();
        undoButton            = transform.Find(PRIVATE_UI_CANVAS).Find(UNDO_BUTTON_OBJ).GetComponent <Button>();
        moveCanvas            = transform.Find(PRIVATE_UI_CANVAS);
        selectableIcon        = transform.Find(PRIVATE_UI_CANVAS).Find(SELECTABLE_ICON_OBJ).GetComponent <Image>();
        selectableIcon.sprite = Services.Cursor.CurrentCursor;
        rb                   = GetComponent <Rigidbody>();
        GridLoc              = new TwoDLoc(0, 0); //default initialization
        combatHand           = MakeCombatHand();
        uICanvas             = GameObject.Find(CARD_UI_CANVAS).transform;
        defenderCards        = uICanvas.GetComponent <DefenderUIBehavior>();
        noFightButton        = transform.Find(PRIVATE_UI_CANVAS).Find(NO_FIGHT_BUTTON).GetComponent <Button>();
        DefeatedSoFar        = START_DEFEATED;
        xpParticle           = transform.Find(XP_PARTICLE_OBJ).GetComponent <ParticleSystem>();
        powerupReadyParticle = transform.Find(POWER_UP_PARTICLE_OBJ).gameObject;
        pose                 = transform.Find(MODEL_OBJ).Find(MINI_OBJ).GetComponent <Animation>();
        unmovingMini         = transform.Find(UNMOVING_OBJ).gameObject;
    }
    /// <summary>
    /// The Ranger can, from Secret Paths on in the Movement Tricks track, move through the Horde.
    /// </summary>
    /// <param name="loc">The grid location to which the Ranger wants to move.</param>
    /// <returns><c>true</c> if the Ranger can move to that space, <c>false</c> otherwise.</returns>
    public override bool TryPlanMove(TwoDLoc loc)
    {
        if (CheckAdjacent(moves[Speed - remainingSpeed], loc) &&
            remainingSpeed > 0 &&
            !CheckAlreadyThroughSpace(loc))
        {
            //the Ranger can enter a space if either:
            //1. it is empty, or
            //2. it is not the last space of the move, the Horde is present, and the Ranger has reached at least Secret Paths
            //on the Movement Tricks track
            if (Services.Board.GeneralSpaceQuery(loc.x, loc.z) == SpaceBehavior.ContentType.None ||
                (currentMoveTricks >= MoveTricksTrack.Secret_Paths &&
                 remainingSpeed - 1 > 0 &&             //check remaining speed after the proposed move
                 Services.Board.GeneralSpaceQuery(loc.x, loc.z) == SpaceBehavior.ContentType.Attacker))
            {
                moves.Add(loc);
                remainingSpeed--;
                DrawLine(Speed - remainingSpeed, loc.x, loc.z);
                moveCanvas.position = Services.Board.GetWorldLocation(loc.x, loc.z) + new Vector3(0.0f, LINE_OFFSET, 0.0f);

                return(true);
            }
        }

        return(false);
    }
Esempio n. 6
0
    /// <summary>
    /// Give each defender in a space with a tankard at the end of the Defenders Move phase inspiration.
    /// </summary>
    /// <param name="e">An EndPhaseEvent.</param>
    private void GiveInspiration(Event e)
    {
        Debug.Assert(e.GetType() == typeof(EndPhaseEvent), "Non-EndPhaseEvent in GiveInspiration");

        EndPhaseEvent endEvent = e as EndPhaseEvent;

        if (endEvent.Phase.GetType() == typeof(TurnManager.PlayerMove))
        {
            foreach (DefenderSandbox defender in Services.Defenders.GetAllDefenders())
            {
                if (defender != this)
                {
                    TwoDLoc loc = defender.ReportGridLoc();

                    if (Services.Board.CheckIfTankard(loc.x, loc.z))
                    {
                        for (int i = 0; i < BETTER_DRINK_INSP; i++)
                        {
                            defender.DefeatAttacker();
                        }
                    }
                }
            }
        }
    }
Esempio n. 7
0
        //constructor
        public DefenderData(DefenderSandbox defender)
        {
            Defender = defender;

            //default initializations; these are nonsense values that can be used for error checking
            Loc      = new TwoDLoc(-1, -1);
            Movement = -1;
        }
    protected bool CheckAlreadyThroughSpace(TwoDLoc loc)
    {
        foreach (TwoDLoc move in moves)
        {
            if (move.x == loc.x &&
                move.z == loc.z)
            {
                return(true);
            }
        }

        return(false);
    }
Esempio n. 9
0
    /// <summary>
    /// Get a tankard in a known space.
    /// </summary>
    /// <returns>The tankard in the space.</returns>
    /// <param name="loc">The grid location of the tankard.</param>
    public Transform GetTankardInSpace(TwoDLoc loc)
    {
        foreach (TankardBehavior tankard in GetAllTankards())
        {
            if (tankard.GridLoc.x == loc.x &&
                tankard.GridLoc.z == loc.z)
            {
                return(tankard.transform);
            }
        }

        return(null);        //nonsense return value for error-checking.
    }
    /// <summary>
    /// Create a single defender, and add it to the grid.
    /// </summary>
    /// <returns>The defender's controller script.</returns>
    /// <param name="defenderType">The in-game type of defender to create (not its c# class!).</param>
    /// <param name="spawnPoint">The spawn point where the defender will appear.</param>
    protected DefenderSandbox MakeDefender(DefenderTypes defenderType, TwoDLoc spawnPoint)
    {
        GameObject newDefender = MonoBehaviour.Instantiate <GameObject>(Resources.Load <GameObject>(defenderType.ToString()),
                                                                        Services.Board.GetWorldLocation(spawnPoint.x, spawnPoint.z),
                                                                        Quaternion.identity,
                                                                        defenderOrganizer);

        Services.Board.PutThingInSpace(newDefender, spawnPoint.x, spawnPoint.z, SpaceBehavior.ContentType.Defender);

        newDefender.GetComponent <DefenderSandbox>().Setup();
        newDefender.GetComponent <DefenderSandbox>().NewLoc(spawnPoint.x, spawnPoint.z);
        newDefender.name = newDefender.name.Remove(newDefender.name.Length - CLONE_LENGTH);

        return(newDefender.GetComponent <DefenderSandbox>());
    }
    /// <summary>
    /// Reset this defender's position and available movement when a player undoes the Defenders Move phase.
    /// </summary>
    public virtual void UndoMovePhase()
    {
        if (Services.Undo == null)
        {
            return;                                //in the event that there's somehow no undo system in place, prevent null reference exceptions
        }
        Services.Board.TakeThingFromSpace(GridLoc.x, GridLoc.z);
        GridLoc = new TwoDLoc(Services.Undo.GetDefenderLoc(this).x, Services.Undo.GetDefenderLoc(this).z);
        Services.Board.PutThingInSpace(gameObject, GridLoc.x, GridLoc.z, SpaceBehavior.ContentType.Defender);

        moveButton.gameObject.SetActive(false);
        undoButton.gameObject.SetActive(false);

        transform.position = Services.Board.GetWorldLocation(GridLoc.x, GridLoc.z);
    }
Esempio n. 12
0
    /// <summary>
    /// Turn a world location into a grid location.
    ///
    /// Returns null if the world location is not within the grid.
    /// </summary>
    /// <returns>The grid location.</returns>
    /// <param name="x">The world x coordinate.</param>
    /// <param name="z">The world z coordinate.</param>
    public TwoDLoc GetGridLocation(float x, float z)
    {
        if (!CheckValidWorldLoc(x, z))
        {
            return(null);
        }

        TwoDLoc gridLoc = new TwoDLoc(-1, -1);         //nonsense value


        for (int i = 0; i < BOARD_WIDTH; i++)
        {
            if (x >= i * SpaceSize - SpaceSize / 2 && x <= i * SpaceSize + SpaceSize / 2)
            {
                gridLoc.x = i;
                break;
            }
        }

        for (int i = 0; i <= BOARD_HEIGHT; i++)
        {
            if (i == WallZPos + 1)
            {
                continue;                                //don't check the row where the wall is; note that WallZPos is "the row beyond which the wall appears"
            }
            if (z >= i * SpaceSize - SpaceSize / 2 && z <= i * SpaceSize + SpaceSize / 2)
            {
                if (i > WallZPos)
                {
                    gridLoc.z = i - 1;
                }
                else
                {
                    gridLoc.z = i;
                }
                break;
            }
        }

        if (gridLoc.x == -1 || gridLoc.z == -1)
        {
            return(null);                                            //final sanity check; were both x and z set properly?
        }
        else
        {
            return(gridLoc);
        }
    }
Esempio n. 13
0
    /// <summary>
    /// Choose an action--undo the planned move or execute the planned move--based on the mini's final location.
    /// </summary>
    private void ChooseMoveAction()
    {
        TwoDLoc miniFinalPos = Services.Board.GetGridLocation(mini.position.x, mini.position.z);

        //check if the player brought the mini back to the defender's start location
        if (miniFinalPos != null)                                                                            //separate null check to avoid null references; if this is null, the mini is off the board
        {
            if (miniFinalPos.x == defender.ReportGridLoc().x&& miniFinalPos.z == defender.ReportGridLoc().z) //the mini is on the board; is it at the defender's location?
            {
                defender.UndoMove();
            }
        }
        if (defender.CheckIfMovePlanned())
        {
            defender.Move();
        }
    }
Esempio n. 14
0
    /// <summary>
    /// Call this to determine whether the rockfall can occur in a given space.
    /// </summary>
    /// <returns><c>true</c> if the space meets all requirements for the rockfall occurring there, <c>false</c> otherwise.</returns>
    /// <param name="spaceLoc">The space's location in the grid.</param>
    private bool CheckBlockable(TwoDLoc spaceLoc)
    {
        //is the space adjacent?
        if (!(Mathf.Abs(spaceLoc.x - ranger.ReportGridLoc().x) <= 1) ||
            !(Mathf.Abs(spaceLoc.z - ranger.ReportGridLoc().z) <= 1))
        {
            return(false);
        }

        //is the space empty?
        if (Services.Board.GeneralSpaceQuery(spaceLoc.x, spaceLoc.z) != SpaceBehavior.ContentType.None)
        {
            return(false);
        }

        return(true);
    }
Esempio n. 15
0
    //trace out the player's intended move. When the player lets the model go, put it down and resolve the move
    public override void Tick()
    {
        if (!Input.GetMouseButton(0))
        {
            SetStatus(TaskStatus.Success);
            return;
        }


        mini.localPosition += DragDefender();

        TwoDLoc miniLoc = Services.Board.GetGridLocation(mini.position.x, mini.position.z);

        if (miniLoc != null)
        {
            defender.TryPlanMove(miniLoc);
        }
    }
    /// <summary>
    /// Whenever the player tries to move a defender, TurnManager calls this function to determine whether the move is legal--
    /// the defender has the movement remaining, the space is legal to enter, etc.
    ///
    /// A move is illegal if:
    /// 1. It is not adjacent to the defender (or to the last space the defender would move to), or
    /// 2. the space is occupied.
    /// </summary>
    /// <param name="loc">Location.</param>
    public virtual bool TryPlanMove(TwoDLoc loc)
    {
        if (CheckAdjacent(moves[Speed - remainingSpeed], loc) &&
            remainingSpeed > 0 &&
            !CheckAlreadyThroughSpace(loc) &&
            Services.Board.GeneralSpaceQuery(loc.x, loc.z) == SpaceBehavior.ContentType.None)
        {
            moves.Add(loc);
            remainingSpeed--;
            DrawLine(Speed - remainingSpeed, loc.x, loc.z);
            moveCanvas.position = Services.Board.GetWorldLocation(loc.x, loc.z) + new Vector3(0.0f, LINE_OFFSET, 0.0f);

            //the button UI for movement is no longer used
//			moveButton.gameObject.SetActive(true);
//			undoButton.gameObject.SetActive(true);

            return(true);
        }

        return(false);
    }
Esempio n. 17
0
    public override void WinFight(AttackerSandbox attacker)
    {
        DefeatAttacker();
        Services.UI.ReviseNextLabel(defeatsToNextUpgrade, DefeatedSoFar);
        if (currentRampage == RampageTrack.Wade_In ||
            currentRampage == RampageTrack.Berserk ||
            currentRampage == RampageTrack.The_Last_One_Standing)
        {
            if (lastDefeatedLoc != null)
            {
                Services.Board.HighlightSpace(lastDefeatedLoc.x, lastDefeatedLoc.z, BoardBehavior.OnOrOff.Off);
            }
            lastDefeatedLoc = new TwoDLoc(attacker.XPos, attacker.ZPos);

            if (Services.Board.GeneralSpaceQuery(attacker.XPos, attacker.ZPos) != SpaceBehavior.ContentType.Attacker)
            {
                Services.Board.HighlightSpace(attacker.XPos, attacker.ZPos, BoardBehavior.OnOrOff.On);
            }
        }
        defeatedLastTarget = true;         //only important for The Last One Standing

        FinishWithCard();
    }
    /////////////////////////////////////////////
    /// Functions
    /////////////////////////////////////////////


    //constructor
    public DamageRemotelyTask(TwoDLoc loc, int damage, DefenderSandbox defender)
    {
        this.loc      = loc;
        this.damage   = damage;
        this.defender = defender;
    }
Esempio n. 19
0
 /// <summary>
 /// Checks adjacency of two spaces on the grid, including diagonal adjacency.
 /// </summary>
 /// <returns><c>true</c> if the spaces are adjacent, <c>false</c> otherwise.</returns>
 /// <param name="one">The first space to check.</param>
 /// <param name="two">The space the first is being checked against.</param>
 private bool CheckAllAdjacent(TwoDLoc one, TwoDLoc two)
 {
     return((Mathf.Abs(one.x - two.x) <= 1 &&
             Mathf.Abs(one.z - two.z) <= 1) ? true : false);
 }
    /////////////////////////////////////////////
    /// Functions
    /////////////////////////////////////////////


    //constructor
    public MoveObjectTask(Transform obj, TwoDLoc start, TwoDLoc end)
    {
        this.obj   = obj;
        this.start = start;
        this.end   = end;
    }
Esempio n. 21
0
 /// <summary>
 /// Changes the information associated with a defender.
 /// </summary>
 /// <param name="defender">The defender.</param>
 /// <param name="loc">The defender's current location.</param>
 /// <param name="movement">The defender's movement available.</param>
 public void ReviseDefenderState(DefenderSandbox defender, TwoDLoc loc)
 {
     defenders[defender].Loc = new TwoDLoc(loc.x, loc.z);
 }
 /// <summary>
 /// Determine whether two grid spaces are orthogonally adjacent.
 /// </summary>
 /// <returns><c>true</c>, if so, <c>false</c> if not.</returns>
 /// <param name="next">the grid space being checked.</param>
 /// <param name="current">The space being checked against.</param>
 protected bool CheckAdjacent(TwoDLoc next, TwoDLoc current)
 {
     return(((next.x == current.x && Mathf.Abs(next.z - current.z) == 1) ||
             (Mathf.Abs(next.x - current.x) == 1 && next.z == current.z)) ? true : false);
 }
 public BoardClickedEvent(TwoDLoc coords)
 {
     this.coords = coords;
 }
Esempio n. 24
0
    //constructor
    public MoveEvent(Transform movingObj, TwoDLoc endPos)
    {
        this.movingObj = movingObj;

        this.endPos = new TwoDLoc(endPos.x, endPos.z);
    }
    /////////////////////////////////////////////
    /// Functions
    /////////////////////////////////////////////


    //constructor
    public AttackerDefeatedEvent(AttackerSandbox attacker)
    {
        this.attacker = attacker;
        location      = new TwoDLoc(this.attacker.XPos, this.attacker.ZPos);
    }
Esempio n. 26
0
    /////////////////////////////////////////////
    /// Functions
    /////////////////////////////////////////////


    //constructor
    public WaitToArriveTask(Transform obj, TwoDLoc end)
    {
        this.obj = obj;
        this.end = end;
    }