Esempio n. 1
0
        public bool matchEventPersons(Architecture a)
        {
            GameObjectList allPersons = a.AllPersonAndChildren.GetList();

            HashSet <int> haveCond = new HashSet <int>();

            foreach (KeyValuePair <int, List <Condition> > i in this.personCond)
            {
                haveCond.Add(i.Key);
            }

            HashSet <int> noCond = new HashSet <int>();

            foreach (KeyValuePair <int, List <Person> > i in this.person)
            {
                if (!haveCond.Contains(i.Key) && i.Value.Count == 0)
                {
                    noCond.Add(i.Key);
                }
            }

            Dictionary <int, List <Person> > candidates = new Dictionary <int, List <Person> >();

            foreach (int i in this.person.Keys)
            {
                candidates[i] = new List <Person>();
                if (noCond.Contains(i))
                {
                    foreach (Person p in allPersons.GetList())
                    {
                        candidates[i].Add(p);
                    }
                }
            }

            // check person in the architecture
            foreach (KeyValuePair <int, List <Condition> > i in this.personCond)
            {
                foreach (Person p in allPersons)
                {
                    bool ok = Condition.CheckConditionList(i.Value, p, this);
                    if (ok)
                    {
                        if (this.person[i.Key].Contains(null) || this.person[i.Key].Contains(p))
                        {
                            candidates[i.Key].Add(p);
                        }
                    }
                }
            }
            // check 7000 - 8000 persons which can be in anywhere
            foreach (KeyValuePair <int, List <Person> > i in this.person)
            {
                foreach (Person p in i.Value)
                {
                    if (p != null /*&& p.ID >= 7000 && p.ID < 8000*/)
                    {
                        bool ok;
                        if (this.personCond.ContainsKey(i.Key))
                        {
                            ok = Condition.CheckConditionList(this.personCond[i.Key], p, this);
                        }
                        else
                        {
                            ok = true;
                        }
                        if (ok)
                        {
                            if (this.person[i.Key].Contains(null) || this.person[i.Key].Contains(p))
                            {
                                candidates[i.Key].Add(p);
                            }
                        }
                    }
                }
            }

            foreach (List <Person> i in candidates.Values)
            {
                if (i.Count == 0)
                {
                    return(false);
                }
            }

            Dictionary <int, Person> matchedPersons = new Dictionary <int, Person>();

            foreach (KeyValuePair <int, List <Person> > i in candidates)
            {
                if (i.Value.Count <= 0)
                {
                    return(false);
                }
                Person selected = i.Value[GameObject.Random(i.Value.Count)];
                matchedPersons[i.Key] = selected;
                foreach (List <Person> j in candidates.Values)
                {
                    j.Remove(selected);
                }
            }

            matchedDialog = new List <PersonDialog>();
            foreach (PersonIdDialog i in this.dialog)
            {
                if (!matchedPersons.ContainsKey(i.id))
                {
                    return(false);
                }

                PersonDialog pd = new PersonDialog();
                pd.SpeakingPerson = matchedPersons[i.id];
                pd.Text           = i.dialog;
                for (int j = 0; j < matchedPersons.Count; ++j)
                {
                    pd.Text = pd.Text.Replace("%" + j, matchedPersons[j].Name);
                }
                matchedDialog.Add(pd);
            }

            matchedyesDialog = new List <PersonDialog>();
            foreach (PersonIdDialog i in this.yesdialog)
            {
                if (!matchedPersons.ContainsKey(i.id))
                {
                    return(false);
                }

                PersonDialog pd = new PersonDialog();
                pd.SpeakingPerson = matchedPersons[i.id];
                pd.Text           = i.yesdialog;
                for (int j = 0; j < matchedPersons.Count; ++j)
                {
                    pd.Text = pd.Text.Replace("%" + j, ' ' + matchedPersons[j].Name + ' ');
                }
                matchedyesDialog.Add(pd);
            }

            matchednoDialog = new List <PersonDialog>();
            foreach (PersonIdDialog i in this.nodialog)
            {
                if (!matchedPersons.ContainsKey(i.id))
                {
                    return(false);
                }

                PersonDialog pd = new PersonDialog();
                pd.SpeakingPerson = matchedPersons[i.id];
                pd.Text           = i.nodialog;
                for (int j = 0; j < matchedPersons.Count; ++j)
                {
                    pd.Text = pd.Text.Replace("%" + j, ' ' + matchedPersons[j].Name + ' ');
                }
                matchednoDialog.Add(pd);
            }

            matchedScenBiography = new List <PersonDialog>();
            foreach (PersonIdDialog i in this.scenBiography)
            {
                if (!matchedPersons.ContainsKey(i.id))
                {
                    return(false);
                }

                PersonDialog pd = new PersonDialog();
                pd.SpeakingPerson = matchedPersons[i.id];
                pd.Text           = i.dialog;
                for (int j = 0; j < matchedPersons.Count; ++j)
                {
                    pd.Text = pd.Text.Replace("%" + j, matchedPersons[j].Name);
                }
                matchedScenBiography.Add(pd);
            }

            matchedEffect = new Dictionary <Person, List <EventEffect> >();
            foreach (KeyValuePair <int, List <EventEffect> > i in this.effect)
            {
                matchedEffect.Add(matchedPersons[i.Key], i.Value);
            }
            matchedYesEffect = new Dictionary <Person, List <EventEffect> >();
            foreach (KeyValuePair <int, List <EventEffect> > i in this.yesEffect)
            {
                matchedYesEffect.Add(matchedPersons[i.Key], i.Value);
            }
            matchedNoEffect = new Dictionary <Person, List <EventEffect> >();
            foreach (KeyValuePair <int, List <EventEffect> > i in this.noEffect)
            {
                matchedNoEffect.Add(matchedPersons[i.Key], i.Value);
            }

            if (a.BelongedFaction != null)
            {
                foreach (Person p in matchedPersons.Values)
                {
                    if (p == a.BelongedFaction.Leader && Session.Current.Scenario.IsPlayer(a.BelongedFaction))
                    {
                        involveLeader = true;
                    }
                }
            }

            return(true);
        }
Esempio n. 2
0
 public static Troop Create(Architecture from, GameObjectList persons, Person leader, Military military, int food, Point position)
 {
     Troop troop = new Troop();
     troop.Scenario = from.Scenario;
     troop.destination = position;
     troop.realDestination = position;
     troop.StartingArchitecture = from;
     troop.ID = troop.Scenario.Troops.GetFreeGameObjectID();
     foreach (Person p in persons.GetList())
     {
         troop.persons.Add(p);
         p.LocationTroop = troop;
         if (p.LocationArchitecture != null)
         {
             p.LocationArchitecture = null;
             p.OldWorkKind = p.WorkKind;
             p.WorkKind = ArchitectureWorkKind.无;
         }
     }
     troop.SetLeader(leader);
     if (from.BelongedFaction != null)
     {
         from.BelongedFaction.AddTroop(troop);
         troop.TechnologyIncrement = from.Technology / 50;
         if (military.ShelledMilitary == null)
         {
             from.RemoveMilitary(military);
         }
         else
         {
             from.RemoveMilitary(military.ShelledMilitary);
             from.Scenario.Militaries.AddMilitary(military);
         }
     }
     troop.Army = military;
     if (food < 0)
     {
         if (from.Food > (6 * military.FoodMax))
         {
             troop.Food = military.FoodMax;
         }
         else if (from.Food > (3 * military.FoodMax))
         {
             troop.Food = military.FoodCostPerDay * ((int)Math.Ceiling((double)(((float)military.RationDays) / 2f)));
         }
         else if (from.Food > military.FoodMax)
         {
             troop.Food = military.FoodCostPerDay * (1 + (military.RationDays / 4));
         }
         else if (from.Food > (military.FoodCostPerDay * (1 + (military.RationDays / 6))))
         {
             troop.Food = military.FoodCostPerDay * (1 + (military.RationDays / 6));
         }
         else if (from.Food > military.FoodCostPerDay)
         {
             troop.Food = military.FoodCostPerDay;
         }
         else
         {
             troop.Food = 0;
         }
     }
     else
     {
         troop.Food = food;
     }
     if (troop.Food > 0)
     {
         from.DecreaseFood(troop.Food);
     }
     troop.InitializePosition(position);
     troop.Scenario.SetMapTileTroop(troop);
     troop.Scenario.Troops.AddTroopWithEvent(troop);
     if (troop.OnTroopCreate != null)
     {
         troop.OnTroopCreate(troop);
     }
     troop.Scenario.ClearPersonStatusCache();
     //troop.Persons.ApplyInfluences();
     troop.RefreshAllData();
     ExtensionInterface.call("CreateTroop", new Object[] { troop.Scenario, troop });
     return troop;
 }
Esempio n. 3
0
 public static Troop Create(Architecture from, GameObjectList persons, Person leader, Military military, int food, Point position)
 {
     Troop troop = new Troop();
     troop.Scenario = from.Scenario;
     troop.destination = position;
     troop.realDestination = position;
     troop.StartingArchitecture = from;
     troop.ID = troop.Scenario.Troops.GetFreeGameObjectID();
     foreach (Person person in persons.GetList())
     {
         troop.AddPerson(person);
         from.RemovePerson(person);
     }
     troop.SetLeader(leader);
     if (from.BelongedFaction != null)
     {
         from.BelongedFaction.AddTroop(troop);
         troop.TechnologyIncrement = from.Technology / 50;
         if (military.ShelledMilitary == null)
         {
             from.RemoveMilitary(military);
         }
         else
         {
             from.RemoveMilitary(military.ShelledMilitary);
             from.Scenario.Militaries.AddMilitary(military);
         }
     }
     troop.Army = military;
     if (food < 0)
     {
         if (from.Food > (6 * military.FoodMax))
         {
             troop.Food = military.FoodMax;
         }
         else if (from.Food > (3 * military.FoodMax))
         {
             troop.Food = military.FoodCostPerDay * ((int) Math.Ceiling((double) (((float) military.RationDays) / 2f)));
         }
         else if (from.Food > military.FoodMax)
         {
             troop.Food = military.FoodCostPerDay * (1 + (military.RationDays / 4));
         }
         else if (from.Food > (military.FoodCostPerDay * (1 + (military.RationDays / 6))))
         {
             troop.Food = military.FoodCostPerDay * (1 + (military.RationDays / 6));
         }
         else if (from.Food > military.FoodCostPerDay)
         {
             troop.Food = military.FoodCostPerDay;
         }
         else
         {
             troop.Food = 0;
         }
     }
     else
     {
         troop.Food = food;
     }
     if (troop.Food > 0)
     {
         from.DecreaseFood(troop.Food);
     }
     troop.InitializePosition(position);
     troop.Scenario.Troops.AddTroopWithEvent(troop);
     if (troop.OnTroopCreate != null)
     {
         troop.OnTroopCreate(troop);
     }
     return troop;
 }
Esempio n. 4
0
        public bool matchEventPersons(Architecture a)
        {
            GameObjectList allPersons = a.Persons.GetList();

            foreach (Person p in a.NoFactionPersons)
            {
                allPersons.Add(p);
            }
            foreach (Captive p in a.Captives)
            {
                allPersons.Add(p.CaptivePerson);
            }
            foreach (Person p in a.Feiziliebiao)
            {
                allPersons.Add(p);
            }

            HashSet <int> haveCond = new HashSet <int>();

            foreach (KeyValuePair <int, List <Condition> > i in this.personCond)
            {
                haveCond.Add(i.Key);
            }

            HashSet <int> noCond = new HashSet <int>();

            foreach (KeyValuePair <int, List <Person> > i in this.person)
            {
                if (!haveCond.Contains(i.Key) && i.Value.Count == 0)
                {
                    noCond.Add(i.Key);
                }
            }

            Dictionary <int, List <Person> > candidates = new Dictionary <int, List <Person> >();

            foreach (int i in this.person.Keys)
            {
                candidates[i] = new List <Person>();
                if (noCond.Contains(i))
                {
                    foreach (Person p in allPersons.GetList())
                    {
                        candidates[i].Add(p);
                    }
                }
            }

            // check person in the architecture
            foreach (KeyValuePair <int, List <Condition> > i in this.personCond)
            {
                foreach (Person p in allPersons)
                {
                    bool ok = true;
                    foreach (Condition c in i.Value)
                    {
                        if (!c.CheckCondition(p, this))
                        {
                            ok = false;
                            break;
                        }
                    }
                    if (ok)
                    {
                        if (this.person[i.Key].Contains(null) || this.person[i.Key].Contains(p))
                        {
                            candidates[i.Key].Add(p);
                        }
                    }
                }
            }
            // check 7000 - 8000 persons which can be in anywhere
            foreach (KeyValuePair <int, List <Person> > i in this.person)
            {
                foreach (Person p in i.Value)
                {
                    if (p != null /*&& p.ID >= 7000 && p.ID < 8000*/)
                    {
                        bool ok = true;
                        if (this.personCond.ContainsKey(i.Key))
                        {
                            foreach (Condition c in this.personCond[i.Key])
                            {
                                if (!c.CheckCondition(p, this))
                                {
                                    ok = false;
                                    break;
                                }
                            }
                        }
                        if (ok)
                        {
                            if (this.person[i.Key].Contains(null) || this.person[i.Key].Contains(p))
                            {
                                candidates[i.Key].Add(p);
                            }
                        }
                    }
                }
            }

            foreach (List <Person> i in candidates.Values)
            {
                if (i.Count == 0)
                {
                    return(false);
                }
            }

            //Dictionary<int, Person> matchedPersons = new Dictionary<int, Person>();
            foreach (KeyValuePair <int, List <Person> > i in candidates)
            {
                if (i.Value.Count <= 0)
                {
                    return(false);
                }
                Person selected = i.Value[GameObject.Random(i.Value.Count)];
                matchedPersons[i.Key] = selected;
                foreach (List <Person> j in candidates.Values)
                {
                    j.Remove(selected);
                }
            }

            matchedDialog = new List <PersonDialog>();
            foreach (PersonIdDialog i in this.dialog)
            {
                if (!matchedPersons.ContainsKey(i.id))
                {
                    return(false);
                }

                PersonDialog pd = new PersonDialog();
                pd.SpeakingPerson = matchedPersons[i.id];
                pd.Text           = i.dialog;
                for (int j = 0; j < matchedPersons.Count; ++j)
                {
                    pd.Text = pd.Text.Replace("%" + j, matchedPersons[j].Name);
                }
                matchedDialog.Add(pd);
            }

            matchedScenBiography = new List <PersonDialog>();
            foreach (PersonIdDialog i in this.scenBiography)
            {
                if (!matchedPersons.ContainsKey(i.id))
                {
                    return(false);
                }

                PersonDialog pd = new PersonDialog();
                pd.SpeakingPerson = matchedPersons[i.id];
                pd.Text           = i.dialog;
                for (int j = 0; j < matchedPersons.Count; ++j)
                {
                    pd.Text = pd.Text.Replace("%" + j, matchedPersons[j].Name);
                }
                matchedScenBiography.Add(pd);
            }

            matchedEffect = new Dictionary <Person, List <EventEffect> >();
            foreach (KeyValuePair <int, List <EventEffect> > i in this.effect)
            {
                matchedEffect.Add(matchedPersons[i.Key], i.Value);
            }
            matchedYesEffect = new Dictionary <Person, List <EventEffect> >();
            foreach (KeyValuePair <int, List <EventEffect> > i in this.yesEffect)
            {
                matchedYesEffect.Add(matchedPersons[i.Key], i.Value);
            }
            matchedNoEffect = new Dictionary <Person, List <EventEffect> >();
            foreach (KeyValuePair <int, List <EventEffect> > i in this.noEffect)
            {
                matchedNoEffect.Add(matchedPersons[i.Key], i.Value);
            }

            return(true);
        }