예제 #1
0
        //a method to set a target faction:
        void SetTargetFaction()
        {
            //first get the factions that are not yet defeated in a list:
            List <GameManager.FactionInfo> activeFactions = new List <GameManager.FactionInfo>();

            activeFactions.AddRange(gameMgr.Factions);

            //remove the defeated factions and pick the weakest:
            FactionManager weakestFaction = null;

            int i = 0; //counter

            while (i < activeFactions.Count)
            {
                //if this is the player's faction or faction is already defeated:
                if (activeFactions[i].FactionMgr == factionMgr || activeFactions[i].Lost == true)
                {
                    //remove from list:
                    activeFactions.RemoveAt(i);
                }
                else
                {
                    if (pickWeakestFaction == true) //if we're picking the weakest faction as the target:
                    {
                        //look for weakest faction:
                        if (weakestFaction == null)
                        {
                            weakestFaction = activeFactions[i].FactionMgr;
                        }
                        //if this faction has less army power than the current weakest:
                        else if (weakestFaction.GetCurrentAttackPower() > activeFactions[i].FactionMgr.GetCurrentAttackPower())
                        {
                            //assign new weakest faction:
                            weakestFaction = activeFactions[i].FactionMgr;
                        }
                    }

                    //increment timer:
                    i++;
                }
            }

            //pick weakest faction or random faction:
            targetFaction = (pickWeakestFaction == true) ? weakestFaction : activeFactions[Random.Range(0, activeFactions.Count)].FactionMgr;
        }
예제 #2
0
        //a method to set a target faction:
        void SetTargetFaction()
        {
            //first get the factions that are not yet defeated in a list:
            List <FactionSlot> activeFactions = gameMgr.GetFactions().Where(faction => !faction.Lost && faction.FactionMgr != factionMgr).ToList();

            //remove the defeated factions and pick the weakest:
            FactionManager weakestFaction = null;

            if (pickWeakestFaction == true) //if we're picking the weakest faction as the target:
            {
                foreach (FactionSlot faction in activeFactions)
                {
                    //look for weakest faction:
                    if (weakestFaction == null || weakestFaction.GetCurrentAttackPower() > faction.FactionMgr.GetCurrentAttackPower())
                    {
                        weakestFaction = faction.FactionMgr;
                    }
                }
            }

            //pick weakest faction or random faction:
            targetFaction = (pickWeakestFaction == true) ? weakestFaction : activeFactions[Random.Range(0, activeFactions.Count)].FactionMgr;
        }