예제 #1
0
        static public int GetCharacterIndexFromCharacter(PartyCharacter pc)
        {
            int count = 0;

            if (FinalGambit.BattleState.foeCharacters.Contains(pc))
            {
                foreach (PartyCharacter pc2 in FinalGambit.BattleState.foeCharacters)
                {
                    count++;
                    if (pc2 == pc)
                    {
                        return(-count);
                    }
                }
            }
            else if (FinalGambit.BattleState.partyCharacters.Contains(pc))
            {
                foreach (PartyCharacter pc2 in FinalGambit.BattleState.partyCharacters)
                {
                    count++;
                    if (pc2 == pc)
                    {
                        return(count);
                    }
                }
            }

            return(0);
        }
예제 #2
0
        static public void PerformBattleAction(int battleActionID, PartyCharacter target)
        {
            if (PartyAIManager.actionFileHasBeenWriten)
            {
                Console.WriteLine("PerformBattleAction has already been called!");
                return;
            }

            //if (AreBattleActionAndTargetLegal(battleActionID, target))
            {
                FileStream f = File.Create(FileNames.action);

                StreamWriter sw = new StreamWriter(f);

                if (target == null)
                {
                    Console.WriteLine("Target is null!");
                }

                int targetIndex = GetCharacterIndexFromCharacter(target);

                //Console.WriteLine("writing " + battleActionID + "," + targetIndex);

                sw.WriteLine(battleActionID + "," + targetIndex);

                sw.Close();
                f.Close();
                f = File.Create(FileNames.flag);
                f.Close();

                PartyAIManager.actionFileHasBeenWriten = true;
            }
        }
예제 #3
0
 public RecordOfBattleAction(int CharacterWithInitiative, int CharacterBeingTargeted, int CharacterThatPerformedCover, int BattleActionID)
 {
     characterWithInitiative     = FinalGambit.GetCharacterFromCharacterIndex(CharacterWithInitiative);
     characterBeingTargeted      = FinalGambit.GetCharacterFromCharacterIndex(CharacterBeingTargeted);
     characterThatPerformedCover = FinalGambit.GetCharacterFromCharacterIndex(CharacterThatPerformedCover);
     battleActionID = BattleActionID;
 }
예제 #4
0
        public BattleState()
        {
            partyCharacters = new LinkedList <PartyCharacter>();
            foeCharacters   = new LinkedList <PartyCharacter>();
            partyInventory  = new LinkedList <InventoryItem>();
            foeInventory    = new LinkedList <InventoryItem>();

            legalActions            = new LinkedList <LegalActionAndRequirments>();
            characterWithInitiative = null;
        }
예제 #5
0
        static public void ProcessAI()
        {
            #region SampleCode


            PartyCharacter target = null;

            foreach (PartyCharacter pc in FinalGambit.BattleState.foeCharacters)
            {
                if (pc.hp > 0)
                {
                    if (target == null)
                    {
                        target = pc;
                    }
                    else if (pc.hp < target.hp)
                    {
                        target = pc;
                    }
                }
            }

            FinalGambit.PerformBattleAction(FinalGambit.BattleActionID.Attack, target);


            //Console.WriteLine("Char with init: " + FinalGambit.characterWithInitiative);


            //foreach (PartyCharacter pc in FinalGambit.BattleState.partyCharacters)
            //{
            //    foreach(StatusEffect se in pc.statusEffects)
            //    {
            //        if(se.id == FinalGambit.StatusEffectID.Poison)
            //        {
            //            //We have found a character that is poisoned, do something here...
            //        }
            //    }
            //}

            //if(FinalGambit.characterWithInitiative.classID == FinalGambit.CharacterClassID.Fighter)
            //{
            //    //The character with initiative is a figher, do something here...
            //}

            #endregion
        }
예제 #6
0
        private void ReadBattleStateSerializationFile()
        {
            FinalGambit.BattleState = new BattleState();


            FileStream f = File.OpenRead(FileNames.battleState);

            StreamReader sr = new StreamReader(f);

            bool                      isReadingForParty = true;
            PartyCharacter            lastPC            = null;
            LegalActionAndRequirments lastAction        = null;

            // Console.WriteLine("starting reading ");

            string data;

            while ((data = sr.ReadLine()) != null)
            {
                //Console.WriteLine("reading " + data);
                string[] processing = data.Split(",");
                int      identifier = Int32.Parse(processing[0]);

                if (identifier == CoreStats)
                {
                    lastPC = new PartyCharacter(Int32.Parse(processing[1]), Int32.Parse(processing[2]), Int32.Parse(processing[3]), Int32.Parse(processing[4]), Int32.Parse(processing[5]), float.Parse(processing[6]), float.Parse(processing[7]), Int32.Parse(processing[8]), Int32.Parse(processing[9]), Int32.Parse(processing[10]), Int32.Parse(processing[11]));
                    if (isReadingForParty)
                    {
                        FinalGambit.BattleState.partyCharacters.AddLast(lastPC);
                    }
                    else
                    {
                        FinalGambit.BattleState.foeCharacters.AddLast(lastPC);
                    }
                }
                else if (identifier == FoePartyInfoStart)
                {
                    isReadingForParty = false;
                }
                else if (identifier == Perk)
                {
                    lastPC.perkIDs.AddLast(Int32.Parse(processing[1]));
                }
                else if (identifier == StatusEffect)
                {
                    lastPC.statusEffects.AddLast(new StatusEffect(Int32.Parse(processing[1]), Int32.Parse(processing[2])));
                }
                else if (identifier == PassiveAbility)
                {
                    lastPC.passiveAbilities.AddLast(Int32.Parse(processing[1]));
                }
                else if (identifier == Ability)
                {
                    lastPC.battleActions.AddLast(Int32.Parse(processing[1]));
                }
                else if (identifier == PartyInventoryItem)
                {
                    if (isReadingForParty)
                    {
                        FinalGambit.BattleState.partyInventory.AddLast(new InventoryItem(Int32.Parse(processing[1]), Int32.Parse(processing[2])));
                    }
                    else
                    {
                        FinalGambit.BattleState.foeInventory.AddLast(new InventoryItem(Int32.Parse(processing[1]), Int32.Parse(processing[2])));
                    }
                }
                else if (identifier == CharacterWithInitiative)
                {
                    FinalGambit.BattleState.characterWithInitiative = FinalGambit.GetCharacterFromCharacterIndex(Int32.Parse(processing[1]));
                }
                else if (identifier == PossibleAction)
                {
                    lastAction = new LegalActionAndRequirments(Int32.Parse(processing[1]));
                    FinalGambit.BattleState.legalActions.AddLast(lastAction);
                }
                else if (identifier == ActionLegality)
                {
                    //Console.WriteLine("Adding legality " + Int32.Parse(processing[1]) + " to " + FinalGambit.BattleActionID.lookUp[lastAction.actionID]);
                    lastAction.legalities.AddLast(Int32.Parse(processing[1]));
                }
                else if (identifier == RecordOfBattleAction)
                {
                    FinalGambit.recordOfBattleActions.AddLast(new RecordOfBattleAction(Int32.Parse(processing[1]), Int32.Parse(processing[2]), Int32.Parse(processing[3]), Int32.Parse(processing[4])));

                    FileStream f2;
                    if (!File.Exists(FileNames.battleReport))
                    {
                        //Console.WriteLine("report create");
                        f2 = File.Create(FileNames.battleReport);
                    }
                    else
                    {
                        //Console.WriteLine("report append");
                        f2 = File.Open(FileNames.battleReport, FileMode.Append);
                    }

                    StreamWriter sw = new StreamWriter(f2);

                    //Console.WriteLine("report write = " + data);
                    sw.WriteLine("" + data);
                    sw.Close();

                    f2.Close();
                }
                else if (identifier == IsFistStateSentForNewBattle)
                {
                    FinalGambit.recordOfBattleActions = new LinkedList <RecordOfBattleAction>();
                    File.Delete(FileNames.battleReport);
                }
            }
            sr.Close();

            f.Close();
        }
예제 #7
0
        static public bool AreBattleActionAndTargetLegal(int battleActionID, PartyCharacter target, bool writeErrorToConsole)
        {
            bool isLegal = true;

            LegalActionAndRequirments actionAndLegalReqs = null;

            foreach (LegalActionAndRequirments legalAction in FinalGambit.BattleState.legalActions)
            {
                if (legalAction.actionID == battleActionID)
                {
                    actionAndLegalReqs = legalAction;
                    break;
                }
            }

            if (actionAndLegalReqs == null)
            {
                isLegal = false;

                if (writeErrorToConsole)
                {
                    Console.WriteLine(BattleActionID.lookUp[battleActionID] + " is not in the list of possible actions!");
                }
            }

            if (actionAndLegalReqs != null)
            {
                if (target == null && !actionAndLegalReqs.legalities.Contains(LegalTargetIdentifiers.NoTargetRequired))
                {
                    if (writeErrorToConsole)
                    {
                        Console.WriteLine(BattleActionID.lookUp[battleActionID] + " requires a target!");
                    }
                    isLegal = false;
                }

                if (target != null)
                {
                    if (target.hp > 0)
                    {
                        if (actionAndLegalReqs.legalities.Contains(LegalTargetIdentifiers.TargetSlain))
                        {
                            if (writeErrorToConsole)
                            {
                                Console.WriteLine(BattleActionID.lookUp[battleActionID] + " requires a slain target!");
                            }
                            isLegal = false;
                        }
                    }
                    else
                    {
                        if (!actionAndLegalReqs.legalities.Contains(LegalTargetIdentifiers.TargetSlain))
                        {
                            if (writeErrorToConsole)
                            {
                                Console.WriteLine(BattleActionID.lookUp[battleActionID] + " cannot target a slain character!");
                            }
                            isLegal = false;
                        }
                    }


                    int ind = GetCharacterIndexFromCharacter(target);

                    //Console.WriteLine("ind = " + ind + "  " + actionAndLegalReqs.legalities.Contains(LegalTargetIdentifiers.TargetFoe) + "    " + actionAndLegalReqs.legalities.Contains(LegalTargetIdentifiers.TargetAlly));

                    if (ind > 0)
                    {
                        if (actionAndLegalReqs.legalities.Contains(LegalTargetIdentifiers.TargetFoe))
                        {
                            if (writeErrorToConsole)
                            {
                                Console.WriteLine(BattleActionID.lookUp[battleActionID] + " cannot target an ally, must target a foe!");
                            }
                            isLegal = false;
                        }
                    }
                    else if (ind < 0)
                    {
                        if (actionAndLegalReqs.legalities.Contains(LegalTargetIdentifiers.TargetAlly))
                        {
                            if (writeErrorToConsole)
                            {
                                Console.WriteLine(BattleActionID.lookUp[battleActionID] + " cannot target a foe, must target an ally!");
                            }
                            isLegal = false;
                        }
                    }
                }
            }

            return(isLegal);
        }