Ejemplo n.º 1
0
        public override void ApplyEffectKind(Person person, Event e)
        {
            FactionList factionlist   = person.Scenario.Factions;
            Faction     targetFaction = factionlist.GetGameObject(targetFactionID) as Faction;

            /*
             * if (targetFaction != null)
             * {
             *  throw new Exception("targetFaction 为" + targetFaction.Name);
             * }
             */

            if (person.BelongedFaction == null && person.LocationArchitecture != null && targetFaction != null)
            {
                //person.Status = GameObjects.PersonDetail.PersonStatus.Normal;
                person.MoveToArchitecture(targetFaction.Capital);
                person.ChangeFaction(targetFaction);
            }
            else if (person.LocationArchitecture != null && person.LocationArchitecture.BelongedFaction != null)
            {
                person.MoveToArchitecture(targetFaction.Capital);
                person.ChangeFaction(targetFaction);
                //person.ChangeFaction(targetFaction);
            }
        }
Ejemplo n.º 2
0
    private float GetSpawnFrequency()
    {
        int   memberCount = FactionList.GetFaction(FactionName).GetMembers().Length;
        float t           = memberCount / (float)MemberLimit;

        return(Mathf.Lerp(MaxSpawnFreqeuncy, MinSpawnFreqeuncy, t));
    }
Ejemplo n.º 3
0
        private void  除势力ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            FactionList list = new FactionList();

            for (int i = 0; i < this.dgvFactions.SelectedRows.Count; i++)
            {
                list.Add(this.Factions[this.dgvFactions.SelectedRows[i].Index]);
            }
            foreach (Faction faction in this.Scenario.Factions)
            {
                foreach (Faction faction2 in list)
                {
                    this.Scenario.DiplomaticRelations.RemoveDiplomaticRelationByFactionID(faction2.ID);
                }
            }
            foreach (Faction faction in list)
            {
                this.Scenario.Factions.RemoveFaction(faction);
            }
            foreach (Legion legion in this.Scenario.Legions.GetList())
            {
                if (legion.BelongedFaction == null)
                {
                    this.Scenario.Legions.Remove(legion);
                }
            }
            foreach (Section section in this.Scenario.Sections.GetList())
            {
                if (section.BelongedFaction == null)
                {
                    this.Scenario.Sections.Remove(section);
                }
            }
            this.RebindDataSource();
        }
Ejemplo n.º 4
0
 public Game(string name)
 {
     Name          = name;
     Worldspace    = Worldspace.Instance;
     FactionList   = new FactionList();
     CharacterList = new CharacterList();
 }
Ejemplo n.º 5
0
        /// <summary>
        /// Handles the <see cref="ButtonBase.Click"/> event for the "Remove Faction" <see
        /// cref="Button"/>.</summary>
        /// <param name="sender">
        /// The <see cref="Object"/> where the event handler is attached.</param>
        /// <param name="args">
        /// A <see cref="RoutedEventArgs"/> object containing event data.</param>
        /// <remarks>
        /// <b>OnFactionRemove</b> removes the first selected item in the "Faction" list view, if
        /// any, from that list view and from the current <see cref="FactionSection"/>, and sets the
        /// <see cref="SectionTabItem.DataChanged"/> flag.</remarks>

        private void OnFactionRemove(object sender, RoutedEventArgs args)
        {
            args.Handled = true;

            // retrieve selected faction, if any
            int index = FactionList.SelectedIndex;

            if (index < 0)
            {
                return;
            }
            FactionClass faction = (FactionClass)FactionList.Items[index];

            // delete existing ID references
            var factions = MasterSection.Instance.Factions.Collection;

            if (!SectionTabItem.ProcessAllIdentifiers(factions, faction.Id, null))
            {
                return;
            }

            // select item in the same position
            FactionList.Items.Refresh();
            if (FactionList.Items.Count > 0)
            {
                FactionList.SelectAndShow(Math.Min(FactionList.Items.Count - 1, index));
            }

            // broadcast data changes
            EnableListButtons();
            SectionTab.DataChanged = true;
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Handles the <see cref="ButtonBase.Click"/> event for the "Move Up" <see cref="Button"/>.
        /// </summary>
        /// <param name="sender">
        /// The <see cref="Object"/> where the event handler is attached.</param>
        /// <param name="args">
        /// A <see cref="RoutedEventArgs"/> object containing event data.</param>
        /// <remarks>
        /// <b>OnFactionUp</b> swaps the first selected item in the "Faction" list view with its
        /// upper neighbour, propagates the change to the current <see cref="FactionSection"/>, and
        /// sets the <see cref="SectionTabItem.DataChanged"/> flag.</remarks>

        private void OnFactionUp(object sender, RoutedEventArgs args)
        {
            args.Handled = true;

            // retrieve selected faction, if any
            if (FactionList.Items.Count < 2)
            {
                return;
            }
            FactionClass faction = FactionList.SelectedItem as FactionClass;

            if (faction == null)
            {
                return;
            }

            // move item up in section table
            var factions = MasterSection.Instance.Factions.Collection;
            int index    = factions.IndexOfKey(faction.Id);

            if (index > 0)
            {
                var pair = factions[index - 1];
                factions[index - 1] = factions[index];
                factions[index]     = pair;
            }

            // broadcast data changes
            FactionList.Items.Refresh();
            FactionList.SelectAndShow(index - 1);
            SectionTab.DataChanged = true;
        }
Ejemplo n.º 7
0
    public Transform GetTarget(Vector3 center, Vector3 direction)
    {
        Faction faction = FactionList.GetFaction(TargetFactions[UnityEngine.Random.Range(0, TargetFactions.Length)]);
        var     members = faction.GetMembers();

        if (members.Length > 0)
        {
            float highestScore  = float.MinValue;
            var   highestMember = members.FirstOrDefault();

            foreach (var member in members)
            {
                float score = _scoreFunc(center, direction, member);
                if (score > highestScore)
                {
                    highestScore  = score;
                    highestMember = member;
                }
            }

            return(highestMember.transform);
        }
        else
        {
            return(null);
        }
    }
Ejemplo n.º 8
0
        /// <summary>
        /// Updates all dialog controls to reflect the current player assignments.</summary>
        /// <remarks>
        /// <b>OnPlayersChanged</b> updates the "Faction" list view and the "Selected Faction" and
        /// "Selected Player" group boxes to reflect the current player assignments, and sets the
        /// <see cref="DataChanged"/> flag.</remarks>

        internal void UpdatePlayers()
        {
            // remember selected faction, if any
            int index = FactionList.SelectedIndex;

            FactionList.SelectedIndex = -1;

            // update Faction list view
            FactionList.Items.Clear();
            foreach (Faction faction in Session.Instance.WorldState.Factions)
            {
                FactionList.Items.Add(CreateFactionRow(faction));
            }

            // reselect remembered faction, if any
            if (index >= 0 && index < FactionList.Items.Count)
            {
                FactionList.SelectAndShow(index);
            }
            else if (FactionList.Items.Count > 0)
            {
                FactionList.SelectedIndex = 0;
            }

            // broadcast data change
            DataChanged = true;
        }
Ejemplo n.º 9
0
 public void Spawn(int amount)
 {
     for (int i = 0; i < amount; i++)
     {
         GameObject obj = Instantiate(Prefab, GetSpawnPosition(transform.position, SpawnRadius), transform.rotation);
         obj.GetComponent <FactionMember>().SetFaction(FactionList.GetFaction(FactionName));
         obj.GetComponent <FactionTargetProvider>().TargetFactions = FactionList.Instance.Factions.Where(x => x.Name != FactionName).Select(x => x.Name).ToArray();
     }
 }
Ejemplo n.º 10
0
        /// <summary>
        /// Handles the <see cref="ButtonBase.Click"/> event for the "Add Faction" <see
        /// cref="Button"/>.</summary>
        /// <param name="sender">
        /// The <see cref="Object"/> where the event handler is attached.</param>
        /// <param name="args">
        /// A <see cref="RoutedEventArgs"/> object containing event data.</param>
        /// <remarks><para>
        /// <b>OnFactionAdd</b> displays a <see cref="Dialog.ChangeIdentifier"/> dialog, followed by
        /// a <see cref="Dialog.ChangeFaction"/> dialog, allowing the user to define a new faction.
        /// The new faction copies the properties of the first selected item in the "Faction" list
        /// view, if any; otherwise, it is created with default properties.
        /// </para><para>
        /// If the user confirmed both dialogs, <b>OnFactionAdd</b> adds the new faction to the
        /// "Faction" list view and to the current <see cref="FactionSection"/>, and sets the <see
        /// cref="SectionTabItem.DataChanged"/> flag.</para></remarks>

        private void OnFactionAdd(object sender, RoutedEventArgs args)
        {
            args.Handled = true;

            // ask user for new faction ID
            var factions = MasterSection.Instance.Factions.Collection;
            var dialog   = new Dialog.ChangeIdentifier("faction-id",
                                                       Global.Strings.TitleFactionIdEnter, factions.ContainsKey, false);

            dialog.Owner = MainWindow.Instance;
            if (dialog.ShowDialog() != true)
            {
                return;
            }

            // retrieve new faction ID
            string id = String.Intern(dialog.Identifier);

            // create new faction based on selected faction, if any
            FactionClass faction, selection = FactionList.SelectedItem as FactionClass;

            if (selection == null)
            {
                faction = new FactionClass(id);
                // add default defeat condition (site loss)
                faction.DefeatConditions.Add(new Condition());
            }
            else
            {
                faction    = (FactionClass)selection.Clone();
                faction.Id = id;
            }

            // let user make changes to new faction
            var factionDialog = new Dialog.ChangeFaction(faction)
            {
                Owner = MainWindow.Instance
            };

            if (factionDialog.ShowDialog() != true)
            {
                return;
            }

            // add faction to section table
            factions.Add(id, faction);

            // update list view and select new item
            FactionList.Items.Refresh();
            FactionList.SelectAndShow(faction);

            // broadcast data changes
            EnableListButtons();
            SectionTab.DataChanged = true;
        }
 void Start()
 {
     if (!string.IsNullOrEmpty(DefaultFaction))
     {
         Faction faction = FactionList.GetFaction(DefaultFaction);
         if (faction != null)
         {
             SetFaction(faction);
         }
     }
 }
        public override void ApplyEffectKind(Person person, Event e)
        {
            FactionList factionlist  = person.Scenario.Factions;
            Faction     oldFaction   = person.BelongedFaction;
            Faction     mergeFaction = factionlist.GetGameObject(mergeFactionID) as Faction;

            if (oldFaction != null && mergeFaction != null && person == oldFaction.Leader)
            {
                oldFaction.ChangeFaction(mergeFaction);

                //oldFaction.Leader.InitialLoyalty();
            }
        }
Ejemplo n.º 13
0
 public void ReadXml(XmlReader reader)
 {
     Instance    = this;
     factionList = new FactionList();
     if (reader.ReadToDescendant(typeof(Terrain).Name))
     {
         if (reader.MoveToContent() == XmlNodeType.Element && reader.LocalName == typeof(Terrain).Name)
         {
             terrain = new Terrain();
             terrain.ReadXml(reader);
             reader.Read();
         }
     }
     //personName = reader.ReadString();
 }
Ejemplo n.º 14
0
        private void EditFactions()
        {
            FactionList list = new FactionList();

            for (int i = 0; i < this.dgvFactions.SelectedRows.Count; i++)
            {
                list.Add(this.Factions[this.dgvFactions.SelectedRows[i].Index]);
            }
            if (list.Count > 0)
            {
                frmEditFaction faction = new frmEditFaction();
                faction.Factions = list;
                faction.ShowDialog();
                this.dgvFactions.Invalidate();
            }
        }
        private void SetCurrentScenario(string filename)
        {
            OleDbConnectionStringBuilder builder = new OleDbConnectionStringBuilder
            {
                DataSource = filename,
                Provider   = "Microsoft.Jet.OLEDB.4.0"
            };
            OleDbConnection dbConnection            = new OleDbConnection(builder.ConnectionString);
            string          gameScenarioDescription = GameScenario.GetGameScenarioDescription(dbConnection);

            this.tbScenarioDescription.Text = gameScenarioDescription;
            this.currentFactions            = GameScenario.GetGameScenarioFactions(dbConnection);
            this.clbFactions.Items.Clear();
            foreach (Faction faction in this.currentFactions)
            {
                this.clbFactions.Items.Add(faction.Name);
            }
        }
Ejemplo n.º 16
0
        /// <summary>
        /// Sets the <see cref="FactionClass.HomeSite"/> of the selected faction to the specified
        /// location.</summary>
        /// <param name="newHome">
        /// The new <see cref="FactionClass.HomeSite"/> for the selected faction.</param>
        /// <remarks>
        /// <b>SetHome</b> sets the <see cref="FactionClass.HomeSite"/> stored with the first
        /// selected item in the "Faction" list view, if any, to the specified <paramref
        /// name="newHome"/>, updates the dialog accordingly, and sets the <see cref="DataChanged"/>
        /// flag if the <b>HomeSite</b> has changed.</remarks>

        private void SetHome(PointI newHome)
        {
            // retrieve selected faction, if any
            int index = FactionList.SelectedIndex;

            if (index < 0)
            {
                return;
            }
            FactionListItem item = (FactionListItem)FactionList.Items[index];

            // quit if coordinates unchanged
            PointI oldHome = item.Item3;

            if (newHome == oldHome)
            {
                return;
            }

            // highlight new home site if valid
            if (Finder.MapGrid.Contains(newHome))
            {
                this._mapView.SelectedRegion[newHome.X, newHome.Y] = true;
            }

            // show new home site and store coordinates
            item = new FactionListItem(item.Item1, Site.Format(newHome), newHome);
            FactionList.Items[index] = item;
            FactionList.SelectAndShow(index);

            DataChanged = true;

            // remove highlight on old home site if not used by another faction
            if (!IsHomeSite(oldHome) && Finder.MapGrid.Contains(oldHome))
            {
                this._mapView.SelectedRegion[oldHome.X, oldHome.Y] = false;
            }

            // show or hide buttons
            ShowButtons(newHome, true);
            this._mapView.Redraw();
        }
Ejemplo n.º 17
0
        public void Init(FactionList list)
        {
            foreach (Faction f in list)
            {
                foreach (Faction f2 in list)
                {
                    if (f.ID == f2.ID)
                    {
                        continue;
                    }

                    Dictionary <int, DiplomaticRelation> copy = new Dictionary <int, DiplomaticRelation>(DiplomaticRelations);
                    foreach (KeyValuePair <int, DiplomaticRelation> dr in copy)
                    {
                        if (dr.Value.RelationFaction1ID == f.ID && dr.Value.RelationFaction2ID == f2.ID)
                        {
                            int relation = dr.Value.Relation;
                            int truce    = dr.Value.Truce;
                            this.DiplomaticRelations.Remove(dr.Key);
                            this.AddDiplomaticRelation(f.ID, f2.ID, relation);
                            DiplomaticRelation newRel = GetDiplomaticRelation(f.ID, f2.ID);
                            newRel.Truce = truce;
                        }
                        else if (dr.Value.RelationFaction1ID == f2.ID && dr.Value.RelationFaction2ID == f.ID)
                        {
                            int relation = dr.Value.Relation;
                            int truce    = dr.Value.Truce;
                            this.DiplomaticRelations.Remove(dr.Key);
                            this.AddDiplomaticRelation(f.ID, f2.ID, relation);
                            DiplomaticRelation newRel = GetDiplomaticRelation(f.ID, f2.ID);
                            newRel.Truce = truce;
                        }
                    }
                }
            }
        }
Ejemplo n.º 18
0
 public void BlacklistFaction(FactionList fac)
 {
     blacklist.Add(fac);
 }
Ejemplo n.º 19
0
 void Awake()
 {
     Instance = this;
 }
Ejemplo n.º 20
0
 public void InitializeNewWorld()
 {
     terrain     = new Terrain();
     factionList = new FactionList();
     factionList.AddFaction("Player");
 }
Ejemplo n.º 21
0
        public NewEventWindow(bool editing, DataGrid dataGrid, GameScenario scen)
        {
            this.scen = scen;
            edit      = editing;
            InitializeComponent();

            ev = new Event();

            if (editing)
            {
                ev = scen.AllEvents.GetGameObject(int.Parse(((DataRowView)dataGrid.SelectedItem).Row["ID"].ToString())) as Event;
            }
            else
            {
                ev.ID = scen.AllEvents.GetFreeGameObjectID();
            }

            tempDialog = ev.dialog;
            if (tempDialog == null)
            {
                tempDialog = new List <PersonIdDialog>();
            }
            tempYesDialog = ev.yesdialog;
            if (tempYesDialog == null)
            {
                tempYesDialog = new List <PersonIdDialog>();
            }
            tempNoDialog = ev.nodialog;
            if (tempNoDialog == null)
            {
                tempNoDialog = new List <PersonIdDialog>();
            }

            tempPerson = ev.person;
            if (tempPerson == null)
            {
                tempPerson = new Dictionary <int, List <Person> >();
            }
            tempPersonCond = ev.personCond;
            if (tempPersonCond == null)
            {
                tempPersonCond = new Dictionary <int, List <GameObjects.Conditions.Condition> >();
            }
            tempEffect = ev.effect;
            if (tempEffect == null)
            {
                tempEffect = new Dictionary <int, List <GameObjects.ArchitectureDetail.EventEffect.EventEffect> >();
            }
            tempBiography = ev.scenBiography;
            if (tempBiography == null)
            {
                tempBiography = new List <PersonIdDialog>();
            }
            tempYesEffect = ev.yesEffect;
            if (tempYesEffect == null)
            {
                tempYesEffect = new Dictionary <int, List <GameObjects.ArchitectureDetail.EventEffect.EventEffect> >();
            }
            tempNoEffect = ev.noEffect;
            if (tempNoEffect == null)
            {
                tempNoEffect = new Dictionary <int, List <GameObjects.ArchitectureDetail.EventEffect.EventEffect> >();
            }

            tempArchitecture = ev.architecture;
            if (tempArchitecture == null)
            {
                tempArchitecture = new ArchitectureList();
            }
            tempArchitectureCond = ev.architectureCond;
            if (tempArchitectureCond == null)
            {
                tempArchitectureCond = new List <GameObjects.Conditions.Condition>();
            }
            tempArchEffect = ev.architectureEffect;
            if (tempArchEffect == null)
            {
                tempArchEffect = new List <GameObjects.ArchitectureDetail.EventEffect.EventEffect>();
            }
            tempArchYesEffect = ev.yesArchitectureEffect;
            if (tempArchYesEffect == null)
            {
                tempArchYesEffect = new List <GameObjects.ArchitectureDetail.EventEffect.EventEffect>();
            }
            tempArchNoEffect = ev.noArchitectureEffect;
            if (tempArchNoEffect == null)
            {
                tempArchNoEffect = new List <GameObjects.ArchitectureDetail.EventEffect.EventEffect>();
            }

            tempFactions = ev.faction;
            if (tempFactions == null)
            {
                tempFactions = new FactionList();
            }
            tempFactionCond = ev.factionCond;
            if (tempFactionCond == null)
            {
                tempFactionCond = new List <GameObjects.Conditions.Condition>();
            }
            tempFactionEffect = ev.factionEffect;
            if (tempFactionEffect == null)
            {
                tempFactionEffect = new List <GameObjects.ArchitectureDetail.EventEffect.EventEffect>();
            }

            txname.Text                   = ev.Name;
            cbHappened.IsChecked          = ev.happened;
            cbRepeatable.IsChecked        = ev.repeatable;
            cbMinor.IsChecked             = ev.Minor;
            cbGloballyDisplayed.IsChecked = ev.GloballyDisplayed;
            tbHappenChance.Text           = ev.happenChance.ToString();
            tbStartYear.Text              = ev.StartYear.ToString();
            tbStartMonth.Text             = ev.StartMonth.ToString();
            tbEndYear.Text                = ev.EndYear.ToString();
            tbEndMonth.Text               = ev.EndMonth.ToString();
            tbImage.Text                  = ev.Image;
            tbSound.Text                  = ev.Sound;

            PopulateAllPersonData();

            lblArchitcture.Content          = String.Join(" ", tempArchitecture.GameObjects.Select(p => p.Name));
            lblArchitctureCond.Content      = String.Join(" ", tempArchitectureCond.Select(p => p.Name));
            lblArchitctureEffect.Content    = String.Join(" ", tempArchEffect.Select(p => p.Name));
            lblArchitctureYesEffect.Content = String.Join(" ", tempArchYesEffect.Select(p => p.Name));
            lblArchitctureNoEffect.Content  = String.Join(" ", tempArchNoEffect.Select(p => p.Name));
            lblFaction.Content       = String.Join(" ", tempFactions.GameObjects.Select(p => p.Name));
            lblFactionCond.Content   = String.Join(" ", tempFactionCond.Select(p => p.Name));
            lblFactionEffect.Content = String.Join(" ", tempFactionEffect.Select(p => p.Name));

            List <string> events = new List <string>();

            events.Add("-1 无");
            events.AddRange(scen.AllEvents.GameObjects.Select(e => e.ID + " " + e.Name));
            cbAfterEventHappened.ItemsSource = events;
            GameObject currentAfterHappened = scen.AllEvents.GetGameObject(ev.AfterEventHappened);

            cbAfterEventHappened.SelectedItem = ev.AfterEventHappened + " " + (currentAfterHappened == null ? "无" : currentAfterHappened.Name);
        }