コード例 #1
0
ファイル: TurnState.cs プロジェクト: Parakoopa/RogueEssence
        public void UpdateCharRemoval(int removedTeam, int charIndex)
        {
            //all characters on the team with an index higher than the removed char need to be decremented to reflect their new position
            //the removed character (if they're in this turn map, which may not be true) needs to be removed

            //remove the character and update the indices accordingly
            int removeIndex = TurnToChar.Count;

            for (int ii = TurnToChar.Count - 1; ii >= 0; ii--)
            {
                CharIndex turnChar = TurnToChar[ii];
                if (turnChar.Team == removedTeam)
                {
                    if (turnChar.Char > charIndex)
                    {
                        TurnToChar[ii] = new CharIndex(turnChar.Team, turnChar.Char - 1);
                    }
                    else if (turnChar.Char == charIndex)
                    {
                        TurnToChar.RemoveAt(ii);
                        removeIndex = ii;
                    }
                }
            }

            if (CurrentOrder.TurnIndex > removeIndex)
            {
                CurrentOrder.TurnIndex--;
            }
        }
コード例 #2
0
ファイル: Map.cs プロジェクト: RogueCollab/RogueEssence
        public CharIndex GetCharIndex(Character character)
        {
            {
                CharIndex charIndex = ActiveTeam.GetCharIndex(character);
                if (charIndex != CharIndex.Invalid)
                {
                    return(new CharIndex(Faction.Player, 0, charIndex.Guest, charIndex.Char));
                }
            }

            for (int ii = 0; ii < AllyTeams.Count; ii++)
            {
                CharIndex charIndex = AllyTeams[ii].GetCharIndex(character);
                if (charIndex != CharIndex.Invalid)
                {
                    return(new CharIndex(Faction.Friend, ii, charIndex.Guest, charIndex.Char));
                }
            }

            for (int ii = 0; ii < MapTeams.Count; ii++)
            {
                CharIndex charIndex = MapTeams[ii].GetCharIndex(character);
                if (charIndex != CharIndex.Invalid)
                {
                    return(new CharIndex(Faction.Foe, ii, charIndex.Guest, charIndex.Char));
                }
            }

            return(CharIndex.Invalid);
        }
コード例 #3
0
        public void RemoveTeam(Faction faction, int teamIndex)
        {
            CharIndex turnChar = ZoneManager.Instance.CurrentMap.CurrentTurnMap.GetCurrentTurnChar();

            //note: this cannot be called when it is the team's turn
            if (turnChar.Faction == faction && turnChar.Team == teamIndex)
            {
                throw new Exception("Can't remove a team whose turn it currently is!");
            }
            if (faction == Faction.Player)
            {
                throw new Exception("Can't remove player team!");
            }

            switch (faction)
            {
            case Faction.Foe:
                ZoneManager.Instance.CurrentMap.MapTeams.RemoveAt(teamIndex);
                break;

            case Faction.Friend:
                ZoneManager.Instance.CurrentMap.AllyTeams.RemoveAt(teamIndex);
                break;
            }

            ZoneManager.Instance.CurrentMap.CurrentTurnMap.UpdateTeamRemoval(faction, teamIndex);
        }
コード例 #4
0
ファイル: TurnState.cs プロジェクト: Parakoopa/RogueEssence
 public void UpdateTeamRemoval(int removedTeam)
 {
     //all characters with a team index higher than the removed char need to be decremented to reflect their new position
     //keep in mind: team -1 is never removed
     for (int ii = 0; ii < TurnToChar.Count; ii++)
     {
         CharIndex turnChar = TurnToChar[ii];
         if (turnChar.Team > removedTeam)
         {
             TurnToChar[ii] = new CharIndex(turnChar.Team - 1, turnChar.Char);
         }
     }
 }
コード例 #5
0
        public void RemoveTeam(int teamIndex)
        {
            CharIndex turnChar = ZoneManager.Instance.CurrentMap.CurrentTurnMap.GetCurrentTurnChar();

            //note: this cannot be called when it is the team's turn
            if (turnChar.Team == teamIndex)
            {
                throw new Exception();
            }

            ZoneManager.Instance.CurrentMap.MapTeams.RemoveAt(teamIndex);

            ZoneManager.Instance.CurrentMap.CurrentTurnMap.UpdateTeamRemoval(teamIndex);
        }
コード例 #6
0
        public Character LookupCharIndex(CharIndex charIndex)
        {
            Character character = null;

            if (charIndex.Team == -1)
            {
                character = ActiveTeam.Players[charIndex.Char];
            }
            else
            {
                character = MapTeams[charIndex.Team].Players[charIndex.Char];
            }
            return(character);
        }
コード例 #7
0
        public void RemoveChar(CharIndex charIndex)
        {
            CharIndex turnChar = ZoneManager.Instance.CurrentMap.CurrentTurnMap.GetCurrentTurnChar();

            //note: this cannot be called when it is the character's turn
            if (turnChar == charIndex)
            {
                throw new Exception("Attempted to delete a character on their turn.");
            }

            Team team = ZoneManager.Instance.CurrentMap.GetTeam(charIndex.Faction, charIndex.Team);

            List <Character> playerList = (charIndex.Guest) ? team.Guests : team.Players;
            Character        character  = playerList[charIndex.Char];

            character.OnRemove();
            playerList.RemoveAt(charIndex.Char);

            //update leader
            if (!charIndex.Guest)
            {
                if (charIndex.Char < team.LeaderIndex)
                {
                    team.LeaderIndex--;
                }
                if (team.LeaderIndex >= playerList.Count)
                {
                    team.LeaderIndex = playerList.Count - 1;
                }
                if (team.LeaderIndex < 0)
                {
                    team.LeaderIndex = 0;
                }
            }

            ZoneManager.Instance.CurrentMap.CurrentTurnMap.UpdateCharRemoval(charIndex);

            if (charIndex.Faction == Faction.Player && focusedPlayerIndex > charIndex.Char)
            {
                focusedPlayerIndex--;
            }

            //if the team is all empty (not all dead), definitely remove them
            if (team.Players.Count == 0 && team.Guests.Count == 0 && charIndex.Faction != Faction.Player)
            {
                RemoveTeam(charIndex.Faction, charIndex.Team);
            }
        }
コード例 #8
0
ファイル: Map.cs プロジェクト: RogueCollab/RogueEssence
        public Character LookupCharIndex(CharIndex charIndex)
        {
            Team             team = GetTeam(charIndex.Faction, charIndex.Team);
            List <Character> playerList;

            if (charIndex.Guest)
            {
                playerList = team.Guests;
            }
            else
            {
                playerList = team.Players;
            }

            return(playerList[charIndex.Char]);
        }
コード例 #9
0
        public void RemoveChar(CharIndex charIndex)
        {
            CharIndex turnChar = ZoneManager.Instance.CurrentMap.CurrentTurnMap.GetCurrentTurnChar();

            //note: this cannot be called when it is the character's turn
            if (turnChar == charIndex)
            {
                throw new Exception("Attempted to delete a character on their turn.");
            }

            Team team = null;

            if (charIndex.Team == -1)
            {
                team = ZoneManager.Instance.CurrentMap.ActiveTeam;
            }
            else
            {
                team = ZoneManager.Instance.CurrentMap.MapTeams[charIndex.Team];
            }

            Character character = team.Players[charIndex.Char];

            character.OnRemove();
            team.Players.RemoveAt(charIndex.Char);

            //update leader
            if (team is ExplorerTeam && charIndex.Char < team.GetLeaderIndex())
            {
                ((ExplorerTeam)team).LeaderIndex--;
            }

            ZoneManager.Instance.CurrentMap.CurrentTurnMap.UpdateCharRemoval(charIndex.Team, charIndex.Char);

            if (charIndex.Team == -1 && focusedPlayerIndex > charIndex.Char)
            {
                focusedPlayerIndex--;
            }

            //if the team is all empty (not all dead), definitely remove them
            if (team.Players.Count == 0 && charIndex.Team > -1)
            {
                RemoveTeam(charIndex.Team);
            }
        }
コード例 #10
0
        public void UpdateTeamRemoval(Faction faction, int removedTeam)
        {
            //The TurnToChar list will always contain only one faction's worth of turns.
            //which faction can be automatically deduced from CurrentOrder.Faction
            if (faction != CurrentOrder.Faction)
            {
                return;
            }

            //all characters with a team index higher than the removed char need to be decremented to reflect their new position
            for (int ii = 0; ii < TurnToChar.Count; ii++)
            {
                CharIndex turnChar = TurnToChar[ii];
                if (turnChar.Team > removedTeam)
                {
                    TurnToChar[ii] = new CharIndex(turnChar.Faction, turnChar.Team - 1, turnChar.Guest, turnChar.Char);
                }
            }
        }
コード例 #11
0
ファイル: TurnState.cs プロジェクト: Parakoopa/RogueEssence
 public void AdjustDemotion(int teamIndex, int newSlot)
 {
     for (int ii = 0; ii < TurnToChar.Count; ii++)
     {
         CharIndex turnChar = TurnToChar[ii];
         if (turnChar.Team == teamIndex)
         {
             if (turnChar.Char == 0) //team member of char index 0 is now the last member of the team
             {
                 TurnToChar[ii] = new CharIndex(turnChar.Team, newSlot);
             }
             else//also decrement everyone else in team
             {
                 TurnToChar[ii] = new CharIndex(turnChar.Team, turnChar.Char - 1);
             }
             //Maybe we should update their turn position, since they're last.
             //however, this code is only called for enemy death, so it's probably okay
         }
     }
 }
コード例 #12
0
ファイル: TurnState.cs プロジェクト: Parakoopa/RogueEssence
        public void AdjustPromotion(int teamIndex, int newSlot)
        {
            //this code is not necessarily safe when dealing with enemy teams,
            //but this only gets called when a player team messes with their team formation,
            //and when it's specifically the leader's turn.
            //so this code will ride on those assumptions

            //first put the current leader where it belongs (in order)
            CharIndex leaderChar = TurnToChar[0];

            for (int ii = TurnToChar.Count - 1; ii > 0; ii--)
            {
                CharIndex turnChar = TurnToChar[ii];
                if (turnChar.Team == teamIndex)
                {
                    if (turnChar.Char < leaderChar.Char)
                    {
                        TurnToChar.RemoveAt(0);
                        TurnToChar.Insert(ii, leaderChar);
                        break;
                    }
                }
            }
            //then, promote the new one
            for (int ii = 0; ii < TurnToChar.Count; ii++)
            {
                CharIndex turnChar = TurnToChar[ii];
                if (turnChar.Team == teamIndex)
                {
                    if (turnChar.Char == newSlot)
                    {
                        TurnToChar.RemoveAt(ii);
                        TurnToChar.Insert(0, turnChar);
                        break;
                    }
                }
            }
        }
コード例 #13
0
        public void AdjustSlotSwap(Faction faction, int teamIndex, bool guest, int oldSlot, int newSlot)
        {
            if (faction != CurrentOrder.Faction)
            {
                return;
            }

            for (int ii = 0; ii < TurnToChar.Count; ii++)
            {
                CharIndex turnChar = TurnToChar[ii];
                if (turnChar.Team == teamIndex && turnChar.Guest == guest)
                {
                    if (turnChar.Char == oldSlot)
                    {
                        TurnToChar[ii] = new CharIndex(turnChar.Faction, turnChar.Team, turnChar.Guest, newSlot);
                    }
                    else if (turnChar.Char == newSlot)
                    {
                        TurnToChar[ii] = new CharIndex(turnChar.Faction, turnChar.Team, turnChar.Guest, oldSlot);
                    }
                }
            }
        }
コード例 #14
0
        public void UpdateCharRemoval(CharIndex charIndex)
        {
            //The TurnToChar list will always contain only one faction's worth of turns.
            //which faction can be automatically deduced from CurrentOrder.Faction
            if (charIndex.Faction != CurrentOrder.Faction)
            {
                return;
            }
            //all characters on the team with an index higher than the removed char need to be decremented to reflect their new position
            //the removed character (if they're in this turn map, which may not be true) needs to be removed

            //remove the character and update the indices accordingly
            int removeIndex = TurnToChar.Count;

            for (int ii = TurnToChar.Count - 1; ii >= 0; ii--)
            {
                CharIndex turnChar = TurnToChar[ii];
                if (turnChar.Team == charIndex.Team && turnChar.Guest == charIndex.Guest)
                {
                    if (turnChar.Char > charIndex.Char)
                    {
                        TurnToChar[ii] = new CharIndex(turnChar.Faction, turnChar.Team, turnChar.Guest, turnChar.Char - 1);
                    }
                    else if (turnChar.Char == charIndex.Char)
                    {
                        TurnToChar.RemoveAt(ii);
                        removeIndex = ii;
                    }
                }
            }

            if (CurrentOrder.TurnIndex > removeIndex)
            {
                CurrentOrder.TurnIndex--;
            }
        }
コード例 #15
0
        private void OrganizeAIMovement(int depth)
        {
            //here, we check to see if this AI wants to move, and if its ideal movement is blocked
            GameAction intendedInput = CurrentCharacter.Tactic.GetAction(CurrentCharacter, DataManager.Instance.Save.Rand, true);

            if (intendedInput.Type == GameAction.ActionType.Move)
            {
                Loc       dest         = CurrentCharacter.CharLoc + intendedInput.Dir.GetLoc();
                Character blockingChar = ZoneManager.Instance.CurrentMap.GetCharAtLoc(dest);
                if (blockingChar != null && ZoneManager.Instance.CurrentMap.CurrentTurnMap.IsEligibleToMove(blockingChar))
                {
                    //they need to be later in index than the current order + depth
                    int blockingTurn = ZoneManager.Instance.CurrentMap.CurrentTurnMap.CurrentOrder.TurnIndex;
                    for (int ii = ZoneManager.Instance.CurrentMap.CurrentTurnMap.CurrentOrder.TurnIndex + 1; ii < ZoneManager.Instance.CurrentMap.CurrentTurnMap.TurnToChar.Count; ii++)
                    {
                        CharIndex turnChar = ZoneManager.Instance.CurrentMap.CurrentTurnMap.TurnToChar[ii];
                        if (blockingChar == ZoneManager.Instance.CurrentMap.LookupCharIndex(turnChar))
                        {
                            blockingTurn = ii;
                            break;
                        }
                    }

                    //pull them forward in the turn queue.  note: this changes the current character
                    if (blockingTurn > ZoneManager.Instance.CurrentMap.CurrentTurnMap.CurrentOrder.TurnIndex + depth)
                    {
                        CharIndex newTurnChar = ZoneManager.Instance.CurrentMap.CurrentTurnMap.TurnToChar[blockingTurn];
                        ZoneManager.Instance.CurrentMap.CurrentTurnMap.TurnToChar.RemoveAt(blockingTurn);
                        ZoneManager.Instance.CurrentMap.CurrentTurnMap.TurnToChar.Insert(ZoneManager.Instance.CurrentMap.CurrentTurnMap.CurrentOrder.TurnIndex, newTurnChar);

                        //then, recursively check to see if they are blocked themselves
                        OrganizeAIMovement(depth + 1);
                    }
                }
            }
        }
コード例 #16
0
        public void AdjustLeaderSwap(Faction faction, int teamIndex, bool guest, int oldSlot, int newSlot)
        {
            if (faction != CurrentOrder.Faction)
            {
                return;
            }

            //find the index of the oldslot
            //move it to the place it belongs if it wasnt a leader
            int oldIdx  = -1;
            int destIdx = -1;

            for (int ii = 0; ii < TurnToChar.Count; ii++)
            {
                CharIndex turnChar = TurnToChar[ii];
                if (turnChar.Team == teamIndex && turnChar.Guest == guest)
                {
                    if (turnChar.Char == oldSlot)
                    {
                        oldIdx = ii;
                    }
                    //keep updating the destIdx; we want the highest index equal to or lower than the leader's idx
                    if (turnChar.Char <= oldSlot)
                    {
                        destIdx = ii + 1;
                    }
                }
            }

            //if we couldn't find the old leader index, don't need to change anything
            if (oldIdx > -1)
            {
                if (oldIdx < destIdx)
                {
                    destIdx--;
                }
                CharIndex leaderIndex = TurnToChar[oldIdx];
                TurnToChar.RemoveAt(oldIdx);
                TurnToChar.Insert(destIdx, leaderIndex);
            }

            //find the index of the newslot
            //move it to the front
            int newIdx   = -1;
            int firstIdx = 0;

            for (int ii = 0; ii < TurnToChar.Count; ii++)
            {
                CharIndex turnChar = TurnToChar[ii];
                if (turnChar.Team == teamIndex && turnChar.Guest == guest)
                {
                    if (turnChar.Char == newSlot)
                    {
                        newIdx = ii;
                    }
                }
                if (turnChar.Team < teamIndex)
                {
                    firstIdx = ii + 1;
                }
            }

            if (newIdx > -1)
            {
                CharIndex leaderIndex = TurnToChar[newIdx];
                TurnToChar.RemoveAt(newIdx);
                TurnToChar.Insert(firstIdx, leaderIndex);
            }
        }
コード例 #17
0
ファイル: CharIndex.cs プロジェクト: RogueCollab/RogueEssence
 public bool Equals(CharIndex other)
 {
     return(Faction == other.Faction && Team == other.Team && Guest == other.Guest && Char == other.Char);
 }
コード例 #18
0
 public bool Equals(CharIndex other)
 {
     return(Team == other.Team && Char == other.Char);
 }