Пример #1
0
        public static T WeightedRandom <T>(Dictionary <T, float> weights)
        {
            if (weights.Count == 1)
            {
                var enu = weights.Keys.GetEnumerator();
                enu.MoveNext();
                return(enu.Current);
                //return weights.GetEnumerator().Current.Key;
            }

            int    randMax = 10000;
            double sum     = 0;

            foreach (double i in weights.Values)
            {
                sum += i;
            }

            int    p  = GameObject.Random(randMax);
            double pt = 0;

            foreach (KeyValuePair <T, float> td in weights)
            {
                pt += td.Value / sum * randMax;
                if (p < pt)
                {
                    return(td.Key);
                }
            }
            throw new InvalidOperationException("null resulted in WeightedRandom");
        }
Пример #2
0
        public bool checkConditions(Architecture a)
        {
            if (this.happened && !this.repeatable)
            {
                return(false);
            }
            if (GameObject.Random(this.happenChance) != 0)
            {
                return(false);
            }

            if (this.AfterEventHappened >= 0)
            {
                if (!(base.Scenario.AllEvents.GetGameObject(this.AfterEventHappened) as Event).happened)
                {
                    return(false);
                }
            }

            if (this.Scenario.Date.Year < this.StartYear || this.Scenario.Date.Year > this.EndYear)
            {
                return(false);
            }

            if (this.Scenario.Date.Year == this.StartYear)
            {
                if (this.Scenario.Date.Month < this.StartMonth)
                {
                    return(false);
                }
            }

            if (this.Scenario.Date.Year == this.EndYear)
            {
                if (this.Scenario.Date.Month > this.EndMonth)
                {
                    return(false);
                }
            }

            foreach (Condition i in this.architectureCond)
            {
                if (!i.CheckCondition(a, this))
                {
                    return(false);
                }
            }

            foreach (Condition i in this.factionCond)
            {
                if (a.BelongedFaction == null || !i.CheckCondition(a.BelongedFaction, this))
                {
                    return(false);
                }
            }

            return(this.matchEventPersons(a));
        }
Пример #3
0
 internal void CallInformation()
 {
     if (!this.InformationDestination.HasValue)
     {
         PersonList list = new PersonList();
         foreach (LinkNode node in this.WillArchitecture.AIAllLinkNodes.Values)
         {
             if ((((node.A.BelongedFaction == this.BelongedFaction) && node.A.BelongedSection != null &&
                   node.A.BelongedSection.AIDetail.AllowInvestigateTactics) && node.A.InformationAvail()) &&
                 (node.A.RecentlyAttacked <= 0))
             {
                 foreach (Person person in node.A.MovablePersons)
                 {
                     if (person.LocationArchitecture != null)
                     {
                         list.Add(person);
                     }
                 }
                 if (list.Count >= 10)
                 {
                     break;
                 }
             }
         }
         if (list.Count > 0)
         {
             Person person = list[GameObject.Random(list.Count)] as Person;
             InformationKindList availList = base.Scenario.GameCommonData.AllInformationKinds.GetAvailList(person.LocationArchitecture);
             if (availList.Count > 0)
             {
                 if (availList.Count > 1)
                 {
                     if (this.WillArchitecture.BelongedFaction == null)
                     {
                         availList.PropertyName = "CostFund";
                         availList.SmallToBig   = true;
                     }
                     else
                     {
                         availList.PropertyName = "FightingWeighing";
                     }
                     availList.IsNumber = true;
                     availList.ReSort();
                 }
                 this.SetInformationPosition();
                 if (this.InformationDestination.HasValue)
                 {
                     person.CurrentInformationKind = availList[GameObject.Random(availList.Count / 2)] as InformationKind;
                     person.GoForInformation(this.InformationDestination.Value);
                 }
             }
         }
     }
 }
 public void DayEvent()
 {
     if (((this.BelongedFaction != null) && (this.CaptiveFaction != null)) && (this.RansomArriveDays > 0))
     {
         this.RansomArriveDays--;
         if (this.RansomArriveDays == 0)
         {
             if (this.BelongedFaction.Capital != null)
             {
                 if (this.BelongedFaction.Capital == this.RansomArchitecture)
                 {
                     if (base.Scenario.IsPlayer(this.BelongedFaction))
                     {
                         if (!(!this.BelongedFaction.AutoRefuse || GameObject.Chance(10)))
                         {
                             this.ReturnRansom();
                         }
                         else if (this.OnPlayerRelease != null)
                         {
                             this.OnPlayerRelease(this.BelongedFaction, this.CaptiveFaction, this);
                         }
                     }
                     else
                     {
                         int diplomaticRelation = base.Scenario.GetDiplomaticRelation(this.BelongedFaction.ID, this.CaptiveFaction.ID);
                         if (((diplomaticRelation >= 0) || (GameObject.Random(this.RansomFund) > GameObject.Random(this.RansomFund + this.BelongedFaction.Capital.Fund))) || (GameObject.Random(Math.Abs(diplomaticRelation) + 100) < GameObject.Random(100)))
                         {
                             this.ReleaseCaptive();
                         }
                         else
                         {
                             this.ReturnRansom();
                         }
                     }
                 }
                 else
                 {
                     this.RansomArriveDays = (int)(base.Scenario.GetDistance(this.RansomArchitecture.ArchitectureArea, this.BelongedFaction.Capital.ArchitectureArea) / 5.0);
                     if (this.RansomArriveDays <= 0)
                     {
                         this.RansomArriveDays = 1;
                     }
                     this.RansomArchitecture = this.BelongedFaction.Capital;
                 }
             }
             else
             {
                 this.ReturnRansom();
             }
         }
     }
 }
Пример #5
0
        public List <int> GenerateRandomIndexList()
        {
            int        num;
            List <int> list = new List <int>();

            for (num = 0; num < this.Count; num++)
            {
                list.Add(num);
            }
            for (num = 0; num < this.Count; num++)
            {
                int num2 = num + GameObject.Random(this.Count - num);
                int num3 = list[num];
                list[num]  = list[num2];
                list[num2] = num3;
            }
            return(list);
        }
Пример #6
0
        public bool checkConditions(Architecture a)
        {
            if (a.ID == 91)
            {
                int z = 0;
                z++;
            }

            if (this.happened && !this.repeatable)
            {
                return(false);
            }
            if (GameObject.Random(this.happenChance) != 0)
            {
                return(false);
            }

            if (this.AfterEventHappened >= 0)
            {
                if (!(base.Scenario.AllEvents.GetGameObject(this.AfterEventHappened) as Event).happened)
                {
                    return(false);
                }
            }

            foreach (Condition i in this.architectureCond)
            {
                if (!i.CheckCondition(a, this))
                {
                    return(false);
                }
            }

            foreach (Condition i in this.factionCond)
            {
                if (a.BelongedFaction == null || !i.CheckCondition(a.BelongedFaction, this))
                {
                    return(false);
                }
            }

            return(this.matchEventPersons(a));
        }
Пример #7
0
        public static T WeightedRandom <T>(Dictionary <T, float> weights)
        {
            int    randMax = 10000;
            double sum     = 0;

            foreach (double i in weights.Values)
            {
                sum += i;
            }

            int    p  = GameObject.Random(randMax);
            double pt = 0;

            foreach (KeyValuePair <T, float> td in weights)
            {
                pt += td.Value / sum * randMax;
                if (p < pt)
                {
                    return(td.Key);
                }
            }
            throw new InvalidOperationException("null resulted in WeightedRandom");
        }
Пример #8
0
        public bool checkConditions(Architecture a)
        {
            if (this.happened && !this.repeatable)
            {
                return(false);
            }
            if (GameObject.Random(this.happenChance) != 0)
            {
                return(false);
            }

            if (this.AfterEventHappened >= 0)
            {
                if (!(Session.Current.Scenario.AllEvents.GetGameObject(this.AfterEventHappened) as Event).happened)
                {
                    return(false);
                }
            }

            if (Session.Current.Scenario.Date.Year < this.StartYear || Session.Current.Scenario.Date.Year > this.EndYear)
            {
                return(false);
            }

            if (Session.Current.Scenario.Date.Year == this.StartYear)
            {
                if (Session.Current.Scenario.Date.Month < this.StartMonth)
                {
                    return(false);
                }
            }

            if (Session.Current.Scenario.Date.Year == this.EndYear)
            {
                if (Session.Current.Scenario.Date.Month > this.EndMonth)
                {
                    return(false);
                }
            }

            if (!Condition.CheckConditionList(this.architectureCond, a, this))
            {
                return(false);
            }
            if (!Condition.CheckConditionList(this.factionCond, a.BelongedFaction, this))
            {
                return(false);
            }

            if (architecture.Count > 0 || faction.Count > 0)
            {
                bool contains = false;
                if (architecture != null)
                {
                    foreach (Architecture archi in this.architecture)
                    {
                        if (archi.ID == a.ID)
                        {
                            contains = true;
                        }
                    }
                }

                if (faction != null)
                {
                    foreach (Faction f in faction)
                    {
                        if (a.BelongedFaction != null && f != null)
                        {
                            if (f.ID == a.BelongedFaction.ID)
                            {
                                contains = true;
                            }
                        }
                    }
                }
                if (contains)
                {
                    return(true);
                }
                else
                {
                    return(false);
                }
            }


            return(this.matchEventPersons(a));
        }
Пример #9
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);
        }
Пример #10
0
 public GameObject GetRandomObject()
 {
     return(this.GameObjects[GameObject.Random(this.GameObjects.Count)]);
 }
Пример #11
0
        public bool matchEventPersons(Architecture a)
        {
            Dictionary <int, List <Person> > candidates = new Dictionary <int, List <Person> >();

            foreach (int i in this.person.Keys)
            {
                candidates[i] = new List <Person>();
            }
            foreach (KeyValuePair <int, List <Condition> > i in this.personCond)
            {
                foreach (Person p in a.Persons)
                {
                    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);
                        }
                    }
                }
            }
            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);
            }

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

            return(true);
        }
 public void TransformToNoFaction()
 {
     if ((this.CaptivePerson != null) && (this.CaptivePerson.BelongedFaction != null))
     {
         this.CaptivePerson.Loyalty = 0;
         this.CaptivePerson.BelongedFaction.RemovePerson(this.CaptivePerson);
         this.CaptiveFaction.RemoveSelfCaptive(this);
         if (this.LocationArchitecture != null)
         {
             this.LocationArchitecture.AddNoFactionPerson(this.CaptivePerson);
             this.LocationArchitecture.RemoveCaptive(this);
         }
         else if (this.LocationTroop != null)
         {
             if (this.BelongedFaction.Capital != null)
             {
                 this.CaptivePerson.MoveToArchitecture(this.BelongedFaction.Capital);
             }
             else if (base.Scenario.Architectures.Count > 0)
             {
                 this.CaptivePerson.MoveToArchitecture(base.Scenario.Architectures[GameObject.Random(base.Scenario.Architectures.Count)] as Architecture);
             }
             this.LocationTroop.RemoveCaptive(this);
         }
         this.CaptivePerson.BelongedCaptive = null;
         this.BelongedFaction.RemoveCaptive(this);
         base.Scenario.Captives.Remove(this);
     }
 }
Пример #13
0
        public bool checkConditions(Architecture a)
        {
            if (a.ID == 139)
            {
                int zz = 0;
                zz++;
            }
            if (this.happened && !this.repeatable)
            {
                return(false);
            }
            if (GameObject.Random(this.happenChance) != 0)
            {
                return(false);
            }

            if (this.AfterEventHappened >= 0)
            {
                if (!(base.Scenario.AllEvents.GetGameObject(this.AfterEventHappened) as Event).happened)
                {
                    return(false);
                }
            }

            if (this.Scenario.Date.Year < this.StartYear || this.Scenario.Date.Year > this.EndYear)
            {
                return(false);
            }

            if (this.Scenario.Date.Year == this.StartYear)
            {
                if (this.Scenario.Date.Month < this.StartMonth)
                {
                    return(false);
                }
            }

            if (this.Scenario.Date.Year == this.EndYear)
            {
                if (this.Scenario.Date.Month > this.EndMonth)
                {
                    return(false);
                }
            }

            foreach (Condition i in this.architectureCond)
            {
                if (!i.CheckCondition(a, this))
                {
                    return(false);
                }
            }

            foreach (Condition i in this.factionCond)
            {
                if (a.BelongedFaction == null || !i.CheckCondition(a.BelongedFaction, this))
                {
                    return(false);
                }
            }

            if ((architecture.Count > 0 || faction.Count > 0))
            {
                bool contains = false;
                if (this.architecture != null)
                {
                    foreach (Architecture archi in this.architecture)
                    {
                        if (archi.ID == a.ID)
                        {
                            contains = true;
                        }
                    }
                }

                if (this.faction != null)
                {
                    foreach (Faction f in this.faction)
                    {
                        if (a.BelongedFaction != null)
                        {
                            if (f.ID == a.BelongedFaction.ID)
                            {
                                contains = true;
                            }
                        }
                    }
                }

                if (!contains)
                {
                    return(false);
                }
            }

            return(this.matchEventPersons(a));
        }
Пример #14
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);
        }
Пример #15
0
        public bool checkConditions(Architecture a)
        {
            if (this.happened && !this.repeatable)
            {
                return(false);
            }
            if (GameObject.Random(this.happenChance) != 0)
            {
                return(false);
            }

            if (this.AfterEventHappened >= 0)
            {
                if (!(base.Scenario.AllEvents.GetGameObject(this.AfterEventHappened) as Event).happened)
                {
                    return(false);
                }
            }

            foreach (Condition i in this.architectureCond)
            {
                if (!i.CheckCondition(a, this))
                {
                    return(false);
                }
            }

            foreach (Condition i in this.factionCond)
            {
                if (!i.CheckCondition(a.BelongedFaction, this))
                {
                    return(false);
                }
            }

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

            foreach (int i in this.personCond.Keys)
            {
                candidates[i] = new List <Person>();
            }
            foreach (KeyValuePair <int, List <Condition> > i in this.personCond)
            {
                foreach (Person p in a.Persons)
                {
                    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);
                        }
                    }
                }
            }

            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[i.id].Name);
                }
                matchedDialog.Add(pd);
            }

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

            return(true);
        }
Пример #16
0
 public void TransformToNoFaction()  //变成在野人物
 {
     if (this.CaptivePerson != null)
     {
         this.CaptivePerson.Loyalty = 0;
         this.CaptivePerson.Status  = GameObjects.PersonDetail.PersonStatus.NoFaction;
         if (this.LocationTroop == null)
         {
         }
         else
         {
             this.CaptivePerson.LocationArchitecture = base.Scenario.Architectures[GameObject.Random(base.Scenario.Architectures.Count)] as Architecture;
             if ((this.CaptivePerson.BelongedFaction != null) && this.BelongedFaction.Capital != null)
             {
                 this.CaptivePerson.MoveToArchitecture(this.BelongedFaction.Capital, this.CaptivePerson.LocationTroop.Position);
             }
             else if (base.Scenario.Architectures.Count > 0)
             {
                 this.CaptivePerson.MoveToArchitecture(base.Scenario.Architectures[GameObject.Random(base.Scenario.Architectures.Count)] as Architecture, this.CaptivePerson.LocationTroop.Position);
             }
         }
         this.CaptivePerson.BelongedCaptive = null;
     }
 }
Пример #17
0
 public void DayEvent()
 {
     if (((this.BelongedFaction != null) && (this.CaptiveFaction != null)) && (this.RansomArriveDays > 0))
     {
         this.RansomArriveDays--;
         if (this.RansomArriveDays == 0)
         {
             if (this.BelongedFaction.Capital != null)
             {
                 if (this.BelongedFaction.Capital == this.RansomArchitecture)
                 {
                     if (base.Scenario.IsPlayer(this.BelongedFaction))
                     {
                         if (!(!this.BelongedFaction.AutoRefuse))
                         {
                             this.ReturnRansom();
                         }
                         else if (this.OnPlayerRelease != null)
                         {
                             this.OnPlayerRelease(this.BelongedFaction, this.CaptiveFaction, this);
                         }
                     }
                     else
                     {
                         int diplomaticRelation = base.Scenario.GetDiplomaticRelation(this.BelongedFaction.ID, this.CaptiveFaction.ID);
                         //if (((diplomaticRelation >= 0) || (GameObject.Random(this.RansomFund) > GameObject.Random(this.RansomFund + this.BelongedFaction.Capital.Fund))) || (GameObject.Random(Math.Abs(diplomaticRelation) + 100) < GameObject.Random(100)))
                         if (diplomaticRelation >= 0 || ((!this.CaptivePerson.RecruitableBy(this.BelongedFaction, 0) || (this.CaptivePerson.Loyalty >= 100 && GameObject.Chance(80 - this.CaptivePerson.PersonalLoyalty * 20))) &&
                                                         (!this.BelongedFaction.Capital.IsFundEnough || GameObject.Random(this.RansomFund) > GameObject.Random(this.RansomFund + this.BelongedFaction.Capital.Fund))) &&
                             (!GameGlobal.GlobalVariables.AIAutoTakePlayerCaptives || !base.Scenario.IsPlayer(this.CaptiveFaction)))
                         {
                             this.ReleaseCaptive();
                         }
                         else
                         {
                             this.ReturnRansom();
                         }
                     }
                 }
                 else
                 {
                     this.RansomArriveDays = (int)(base.Scenario.GetDistance(this.RansomArchitecture.ArchitectureArea, this.BelongedFaction.Capital.ArchitectureArea) / 5.0);
                     if (this.RansomArriveDays <= 0)
                     {
                         this.RansomArriveDays = 1;
                     }
                     this.RansomArchitecture = this.BelongedFaction.Capital;
                 }
             }
             else
             {
                 this.ReturnRansom();
             }
         }
     }
 }
Пример #18
0
        private bool ChallengeOftenShow = false;  //暴击必然触发单挑,调试单挑程序用,默认为false


        public void ChallgenEvent(Troop sourceTroop, Troop troop, TroopDamage damage)
        {
            if ((!sourceTroop.IsFriendly(troop.BelongedFaction) && !sourceTroop.AirOffence) && (this.ChallengeOftenShow || GameObject.Chance(20)))
            {
                Person maxStrengthPerson = sourceTroop.Persons.GetMaxStrengthPerson();
                Person destination       = troop.Persons.GetMaxStrengthPerson();
                if (((maxStrengthPerson != null) && (destination != null)) && (this.ChallengeOftenShow || (GameObject.Random(GameObject.Square(destination.Calmness)) < GameObject.Random(0x19))))
                {
                    if (maxStrengthPerson.IsCivil() || destination.IsCivil() || maxStrengthPerson.ID == 7108 || destination.ID == 7108)  //文官不单挑
                    {
                        return;
                    }
                    int chance = Person.ChanlengeWinningChance(maxStrengthPerson, destination);
                    if (this.ChallengeOftenShow || (maxStrengthPerson.Character.ChallengeChance + chance) >= 60)
                    {
                        this.challengeHappen(damage, maxStrengthPerson, destination, chance);
                    }
                }
            }
        }