Example #1
0
        public void AddMultipleEventsOfSameType()
        {
            int eventsFired = 0;

            Entity entity = new Entity();
            entity.Events.CollectionChanged += (o, e) => eventsFired++;

            entity.AddEvent(new Event(Workspace.Instance.GetPlugin(TriggerOccursEventType)));
            entity.AddEvent(new Event(Workspace.Instance.GetPlugin(TriggerOccursEventType)));

            Assert.AreEqual(2, eventsFired);
            Assert.AreEqual(2, entity.Events.Count);
        }
        public EntityDissolved(List <Property> properties, World world) : base(properties, world)
        {
            foreach (Property property in properties)
            {
                switch (property.Name)
                {
                case "entity_id": Entity = world.GetEntity(Convert.ToInt32(property.Value)); break;

                case "reason":
                    ReasonString = property.Value;
                    switch (property.Value)
                    {
                    case "heavy losses in battle": Reason = DissolveReason.HeavyLossesInBattle; break;

                    case "lack of funds": Reason = DissolveReason.LackOfFunds; break;

                    default:
                        property.Known = false;
                        break;
                    }
                    break;
                }
            }

            Entity.AddEvent(this);
        }
Example #3
0
        public AttackedSite(List <Property> properties, World world)
            : base(properties, world)
        {
            foreach (Property property in properties)
            {
                switch (property.Name)
                {
                case "attacker_civ_id": Attacker = world.GetEntity(Convert.ToInt32(property.Value)); break;

                case "defender_civ_id": Defender = world.GetEntity(Convert.ToInt32(property.Value)); break;

                case "site_civ_id": SiteEntity = world.GetEntity(Convert.ToInt32(property.Value)); break;

                case "site_id": Site = world.GetSite(Convert.ToInt32(property.Value)); break;

                case "attacker_general_hfid": AttackerGeneral = world.GetHistoricalFigure(Convert.ToInt32(property.Value)); break;

                case "defender_general_hfid": DefenderGeneral = world.GetHistoricalFigure(Convert.ToInt32(property.Value)); break;
                }
            }

            Attacker.AddEvent(this);
            Defender.AddEvent(this);
            SiteEntity.AddEvent(this);
            Site.AddEvent(this);
            AttackerGeneral.AddEvent(this);
            DefenderGeneral.AddEvent(this);
        }
Example #4
0
        public SiteAbandoned(List <Property> properties, World world)
            : base(properties, world)
        {
            foreach (Property property in properties)
            {
                switch (property.Name)
                {
                case "civ_id": Civ = world.GetEntity(Convert.ToInt32(property.Value)); break;

                case "site_civ_id": SiteEntity = world.GetEntity(Convert.ToInt32(property.Value)); break;

                case "site_id": Site = world.GetSite(Convert.ToInt32(property.Value)); break;
                }
            }

            Site.OwnerHistory.Last().EndYear  = Year;
            Site.OwnerHistory.Last().EndCause = "abandoned";
            if (SiteEntity != null)
            {
                SiteEntity.SiteHistory.Last(s => s.Site == Site).EndYear  = Year;
                SiteEntity.SiteHistory.Last(s => s.Site == Site).EndCause = "abandoned";
            }
            Civ.SiteHistory.Last(s => s.Site == Site).EndYear  = Year;
            Civ.SiteHistory.Last(s => s.Site == Site).EndCause = "abandoned";

            Civ.AddEvent(this);
            SiteEntity.AddEvent(this);
            Site.AddEvent(this);

            world.AddPlayerRelatedDwarfObjects(SiteEntity);
            world.AddPlayerRelatedDwarfObjects(Site);
        }
        public EntityExpelsHf(List <Property> properties, World world)
            : base(properties, world)
        {
            foreach (Property property in properties)
            {
                switch (property.Name)
                {
                case "entity_id":
                    Entity = world.GetEntity(Convert.ToInt32(property.Value));
                    break;

                case "hfid":
                    HistoricalFigure = world.GetHistoricalFigure(Convert.ToInt32(property.Value));
                    break;

                case "site_id":
                    Site = world.GetSite(Convert.ToInt32(property.Value));
                    break;
                }
            }

            Entity.AddEvent(this);
            HistoricalFigure.AddEvent(this);
            Site.AddEvent(this);
        }
Example #6
0
        public PeaceEfforts(List <Property> properties, World world)
            : base(properties, world)
        {
            foreach (Property property in properties)
            {
                switch (property.Name)
                {
                case "site_id": Site = world.GetSite(Convert.ToInt32(property.Value)); break;

                case "site": if (Site == null)
                    {
                        Site = world.GetSite(Convert.ToInt32(property.Value));
                    }
                    else
                    {
                        property.Known = true;
                    } break;

                case "topic": Topic = property.Value; break;

                case "source": Source = world.GetEntity(Convert.ToInt32(property.Value)); break;

                case "destination": Destination = world.GetEntity(Convert.ToInt32(property.Value)); break;
                }
            }

            Site.AddEvent(this);
            Source.AddEvent(this);
            Destination.AddEvent(this);
        }
        public HfInterrogated(List <Property> properties, World world) : base(properties, world)
        {
            foreach (Property property in properties)
            {
                switch (property.Name)
                {
                case "target_hfid": TargetHf = world.GetHistoricalFigure(Convert.ToInt32(property.Value)); break;

                case "interrogator_hfid": InterrogatorHf = world.GetHistoricalFigure(Convert.ToInt32(property.Value)); break;

                case "arresting_enid": ArrestingEntity = world.GetEntity(Convert.ToInt32(property.Value)); break;

                case "held_firm_in_interrogation": property.Known = true; HeldFirmInInterrogation = true; break;

                case "wanted_and_recognized": property.Known = true; WantedAndRecognized = true; break;
                }
            }

            TargetHf.AddEvent(this);
            if (InterrogatorHf != TargetHf)
            {
                InterrogatorHf.AddEvent(this);
            }
            ArrestingEntity.AddEvent(this);
        }
Example #8
0
        public override void Parse(System.Xml.XmlNode data)
        {
            foreach (XmlNode child in data)
            {
                if (child.Attributes["file"] != null)
                {
                    String filename = child.Attributes["file"].Value;
                    m_Sounds.Add(filename, null);
                    foreach (XmlNode innerChild in child)
                    {
                        switch (innerChild.Attributes["action"].Value.ToLower())
                        {
                        case "play":
                            Entity.AddEvent(innerChild.Attributes["event"].Value, (o) => Play(filename));
                            break;

                        case "pause":
                            Entity.AddEvent(innerChild.Attributes["event"].Value, (o) => Pause(filename));
                            break;

                        case "stop":
                            Entity.AddEvent(innerChild.Attributes["event"].Value, (o) => Stop(filename));
                            break;
                        }
                    }
                }
            }
        }
Example #9
0
        public FieldBattle(List <Property> properties, World world)
            : base(properties, world)
        {
            foreach (Property property in properties)
            {
                switch (property.Name)
                {
                case "coords": Coordinates = Formatting.ConvertToLocation(property.Value); break;

                case "attacker_civ_id": Attacker = world.GetEntity(Convert.ToInt32(property.Value)); break;

                case "defender_civ_id": Defender = world.GetEntity(Convert.ToInt32(property.Value)); break;

                case "subregion_id": Region = world.GetRegion(Convert.ToInt32(property.Value)); break;

                case "attacker_general_hfid": AttackerGeneral = world.GetHistoricalFigure(Convert.ToInt32(property.Value)); break;

                case "defender_general_hfid": DefenderGeneral = world.GetHistoricalFigure(Convert.ToInt32(property.Value)); break;

                case "feature_layer_id": UndergroundRegion = world.GetUndergroundRegion(Convert.ToInt32(property.Value)); break;
                }
            }

            Attacker.AddEvent(this);
            Defender.AddEvent(this);
            AttackerGeneral.AddEvent(this);
            DefenderGeneral.AddEvent(this);
            Region.AddEvent(this);
            UndergroundRegion.AddEvent(this);
        }
Example #10
0
        public EntityLaw(List <Property> properties, World world)
            : base(properties, world)
        {
            foreach (Property property in properties)
            {
                switch (property.Name)
                {
                case "entity_id": Entity = world.GetEntity(Convert.ToInt32(property.Value)); break;

                case "hist_figure_id": HistoricalFigure = world.GetHistoricalFigure(Convert.ToInt32(property.Value)); break;

                case "law_add":
                case "law_remove":
                    switch (property.Value)
                    {
                    case "harsh": Law = EntityLawType.Harsh; break;

                    default:
                        Law             = EntityLawType.Unknown;
                        _unknownLawType = property.Value;
                        world.ParsingErrors.Report("Unknown Law Type: " + _unknownLawType);
                        break;
                    }
                    LawLaid = property.Name == "law_add";
                    break;
                }
            }

            Entity.AddEvent(this);
            HistoricalFigure.AddEvent(this);
        }
Example #11
0
        public EntityCreated(List <Property> properties, World world)
            : base(properties, world)
        {
            foreach (Property property in properties)
            {
                switch (property.Name)
                {
                case "entity_id": Entity = world.GetEntity(Convert.ToInt32(property.Value)); break;

                case "site_id": Site = world.GetSite(Convert.ToInt32(property.Value)); break;

                case "structure_id": StructureId = Convert.ToInt32(property.Value); break;
                }
            }
            if (Site != null)
            {
                Structure = Site.Structures.FirstOrDefault(structure => structure.Id == StructureId);
                if (Entity != null && Structure != null)
                {
                    Entity.OriginStructure = Structure;
                }
            }
            Entity.AddEvent(this);
            Site.AddEvent(this);
            Structure.AddEvent(this);
        }
Example #12
0
        public DiplomatLost(List <Property> properties, World world)
            : base(properties, world)
        {
            foreach (Property property in properties)
            {
                switch (property.Name)
                {
                case "site_id": Site = world.GetSite(Convert.ToInt32(property.Value)); break;

                case "site": if (Site == null)
                    {
                        Site = world.GetSite(Convert.ToInt32(property.Value));
                    }
                    else
                    {
                        property.Known = true;
                    } break;

                case "entity": Entity = world.GetEntity(Convert.ToInt32(property.Value)); break;

                case "involved": InvolvedEntity = world.GetEntity(Convert.ToInt32(property.Value)); break;
                }
            }

            Site.AddEvent(this);
            Entity.AddEvent(this);
            InvolvedEntity.AddEvent(this);
        }
Example #13
0
        public PlunderedSite(List <Property> properties, World world)
            : base(properties, world)
        {
            foreach (Property property in properties)
            {
                switch (property.Name)
                {
                case "attacker_civ_id": Attacker = world.GetEntity(Convert.ToInt32(property.Value)); break;

                case "defender_civ_id": Defender = world.GetEntity(Convert.ToInt32(property.Value)); break;

                case "site_civ_id": SiteEntity = world.GetEntity(Convert.ToInt32(property.Value)); break;

                case "site_id": Site = world.GetSite(Convert.ToInt32(property.Value)); break;
                }
            }

            Attacker.AddEvent(this);
            Defender.AddEvent(this);
            if (Defender != SiteEntity)
            {
                SiteEntity.AddEvent(this);
            }

            Site.AddEvent(this);
        }
Example #14
0
        public CreatedSite(List <Property> properties, World world)
            : base(properties, world)
        {
            foreach (Property property in properties)
            {
                switch (property.Name)
                {
                case "civ_id": Civ = world.GetEntity(Convert.ToInt32(property.Value)); break;

                case "site_civ_id": SiteEntity = world.GetEntity(Convert.ToInt32(property.Value)); break;

                case "site_id": Site = world.GetSite(Convert.ToInt32(property.Value)); break;

                case "builder_hfid": Builder = world.GetHistoricalFigure(Convert.ToInt32(property.Value)); break;
                }
            }

            if (SiteEntity != null)
            {
                SiteEntity.Parent = Civ;
                Site.OwnerHistory.Add(new OwnerPeriod(Site, SiteEntity, Year, "founded"));
            }
            else if (Civ != null)
            {
                Site.OwnerHistory.Add(new OwnerPeriod(Site, Civ, Year, "founded"));
            }
            else if (Builder != null)
            {
                Site.OwnerHistory.Add(new OwnerPeriod(Site, Builder, Year, "created"));
            }
            Site.AddEvent(this);
            SiteEntity.AddEvent(this);
            Civ.AddEvent(this);
            Builder.AddEvent(this);
        }
Example #15
0
        public SiteTakenOver(List <Property> properties, World world) : base(properties, world)
        {
            foreach (Property property in properties)
            {
                switch (property.Name)
                {
                case "attacker_civ_id":
                    Attacker = world.GetEntity(Convert.ToInt32(property.Value));
                    break;

                case "defender_civ_id":
                    Defender = world.GetEntity(Convert.ToInt32(property.Value));
                    break;

                case "new_site_civ_id":
                    NewSiteEntity = world.GetEntity(Convert.ToInt32(property.Value));
                    break;

                case "site_civ_id":
                    SiteEntity = world.GetEntity(Convert.ToInt32(property.Value));
                    break;

                case "site_id":
                    Site = world.GetSite(Convert.ToInt32(property.Value));
                    break;
                }
            }

            if (Site.OwnerHistory.Count == 0)
            {
                if (SiteEntity != null && SiteEntity != Defender)
                {
                    SiteEntity.Parent = Defender;
                    Site.OwnerHistory.Add(new OwnerPeriod(Site, SiteEntity, -1, "founded"));
                }
                else
                {
                    Site.OwnerHistory.Add(new OwnerPeriod(Site, Defender, -1, "founded"));
                }
            }

            Site.OwnerHistory.Last().EndCause = "taken over";
            Site.OwnerHistory.Last().EndYear  = Year;
            Site.OwnerHistory.Last().Ender    = Attacker;
            NewSiteEntity.Parent = Attacker;
            Site.OwnerHistory.Add(new OwnerPeriod(Site, NewSiteEntity, Year, "took over"));

            Attacker.AddEvent(this);
            if (Defender != Attacker)
            {
                Defender.AddEvent(this);
            }
            NewSiteEntity.AddEvent(this);
            if (SiteEntity != Defender)
            {
                SiteEntity.AddEvent(this);
            }

            Site.AddEvent(this);
        }
Example #16
0
        public ReplacedStructure(List <Property> properties, World world) : base(properties, world)
        {
            foreach (Property property in properties)
            {
                switch (property.Name)
                {
                case "old_ab_id": OldStructureId = Convert.ToInt32(property.Value); break;

                case "new_ab_id": NewStructureId = Convert.ToInt32(property.Value); break;

                case "civ_id": Civ = world.GetEntity(Convert.ToInt32(property.Value)); break;

                case "site_civ_id": SiteEntity = world.GetEntity(Convert.ToInt32(property.Value)); break;

                case "site_id": Site = world.GetSite(Convert.ToInt32(property.Value)); break;

                case "site": if (Site == null)
                    {
                        Site = world.GetSite(Convert.ToInt32(property.Value));
                    }
                    else
                    {
                        property.Known = true;
                    } break;

                case "civ": if (Civ == null)
                    {
                        Civ = world.GetEntity(Convert.ToInt32(property.Value));
                    }
                    else
                    {
                        property.Known = true;
                    } break;

                case "site_civ": if (SiteEntity == null)
                    {
                        SiteEntity = world.GetEntity(Convert.ToInt32(property.Value));
                    }
                    else
                    {
                        property.Known = true;
                    } break;

                case "old_structure": OldStructureId = Convert.ToInt32(property.Value); break;

                case "new_structure": NewStructureId = Convert.ToInt32(property.Value); break;
                }
            }
            if (Site != null)
            {
                OldStructure = Site.Structures.FirstOrDefault(structure => structure.Id == OldStructureId);
                NewStructure = Site.Structures.FirstOrDefault(structure => structure.Id == NewStructureId);
            }
            Civ.AddEvent(this);
            SiteEntity.AddEvent(this);
            Site.AddEvent(this);
        }
        public EntityRelocate(List <Property> properties, World world)
            : base(properties, world)
        {
            foreach (Property property in properties)
            {
                switch (property.Name)
                {
                case "entity_id": Entity = world.GetEntity(Convert.ToInt32(property.Value)); break;

                case "site_id": Site = world.GetSite(Convert.ToInt32(property.Value)); break;

                case "structure_id": StructureId = Convert.ToInt32(property.Value); break;

                case "site": if (Site == null)
                    {
                        Site = world.GetSite(Convert.ToInt32(property.Value));
                    }
                    else
                    {
                        property.Known = true;
                    } break;

                case "entity": if (Entity == null)
                    {
                        Entity = world.GetEntity(Convert.ToInt32(property.Value));
                    }
                    else
                    {
                        property.Known = true;
                    } break;

                case "action":
                    switch (property.Value)
                    {
                    case "entity_relocate":
                        Action = ActionsForEntities.Relocate;
                        break;

                    default:
                        property.Known = false;
                        break;
                    }
                    break;

                case "structure": StructureId = Convert.ToInt32(property.Value); break;
                }
            }
            if (Site != null)
            {
                Structure = Site.Structures.FirstOrDefault(structure => structure.Id == StructureId);
            }
            Entity.AddEvent(this);
            Site.AddEvent(this);
            Structure.AddEvent(this);
        }
        public ArtifactClaimFormed(List <Property> properties, World world)
            : base(properties, world)
        {
            foreach (Property property in properties)
            {
                switch (property.Name)
                {
                case "artifact_id":
                    Artifact = world.GetArtifact(Convert.ToInt32(property.Value));
                    break;

                case "hist_figure_id":
                    HistoricalFigure = world.GetHistoricalFigure(Convert.ToInt32(property.Value));
                    break;

                case "entity_id":
                    Entity = world.GetEntity(Convert.ToInt32(property.Value));
                    break;

                case "claim":
                    switch (property.Value)
                    {
                    case "symbol":
                        Claim = Claim.Symbol;
                        break;

                    case "heirloom":
                        Claim = Claim.Heirloom;
                        break;

                    case "treasure":
                        Claim = Claim.Heirloom;
                        break;

                    default:
                        property.Known = false;
                        break;
                    }

                    break;

                case "position_profile_id":
                    PositionProfileId = Convert.ToInt32(property.Value);
                    break;

                case "circumstance":
                    Circumstance = property.Value;
                    break;
                }
            }

            Artifact.AddEvent(this);
            HistoricalFigure.AddEvent(this);
            Entity.AddEvent(this);
        }
        public KeyboardController(Entity ent, String name) : base(ent, name)
        {
            m_InputObj = XNAGame.Instance.GetBroadphase <Broadphases.Input>("Input");
            m_Position = Entity.AddProperty <Vector3>("Position", Vector3.Zero);

            Entity.AddEvent("SetActive", (o) => this.IsActive   = true);
            Entity.AddEvent("SetInactive", (o) => this.IsActive = false);

            IsActive = true;
            Speed    = 0.5f;
        }
Example #20
0
        public void AddLocalEvent()
        {
            bool collectionChanged = false;

            Entity entity = new Entity();
            entity.Events.CollectionChanged += (o, e) => collectionChanged = true;

            Event evt = new Event(Workspace.Instance.GetPlugin(TriggerOccursEventType));
            entity.AddEvent(evt);

            Assert.IsTrue(collectionChanged);
            Assert.IsTrue(evt.IsEditable);
            Assert.AreEqual(1, entity.Events.Count);
        }
Example #21
0
        public ReclaimSite(List <Property> properties, World world)
            : base(properties, world)
        {
            foreach (Property property in properties)
            {
                switch (property.Name)
                {
                case "civ_id": Civ = world.GetEntity(Convert.ToInt32(property.Value)); break;

                case "site_civ_id": SiteEntity = world.GetEntity(Convert.ToInt32(property.Value)); break;

                case "site_id": Site = world.GetSite(Convert.ToInt32(property.Value)); break;

                case "unretire": Unretired = true; property.Known = true; break;
                }
            }

            if (SiteEntity != null && SiteEntity != Civ)
            {
                SiteEntity.Parent = Civ;
            }

            //Make sure period was lost by an event, otherwise unknown loss
            if (Site.OwnerHistory.Count == 0)
            {
                Site.OwnerHistory.Add(new OwnerPeriod(Site, null, -1, "founded"));
            }
            if (Site.OwnerHistory.Last().EndYear == -1)
            {
                Site.OwnerHistory.Last().EndCause = "abandoned";
                Site.OwnerHistory.Last().EndYear  = Year - 1 == 0 ? -1 : Year - 1;
            }
            if (Unretired)
            {
                Site.OwnerHistory.Add(new OwnerPeriod(Site, SiteEntity, Year, "unretired"));
            }
            else
            {
                Site.OwnerHistory.Add(new OwnerPeriod(Site, SiteEntity, Year, "reclaimed"));
            }

            Civ.AddEvent(this);
            if (SiteEntity != Civ)
            {
                SiteEntity.AddEvent(this);
            }

            Site.AddEvent(this);
        }
        public Selectable(Entity ent, String name) : base(ent, name)
        {
            m_Selected = Entity.AddProperty <bool>("Selected", false);
            m_Position = Entity.AddProperty <Vector3>("Position", Vector3.Zero);
            m_Origin   = Entity.AddProperty <Vector2>("Origin", Vector2.Zero);
            m_Bounds   = Entity.AddProperty <Vector2>("Bounds", Vector2.Zero);
            m_Scale    = Entity.AddProperty <float>("Scale", 0.0f);

            m_Position.ValueChanged += new ValueChanged <Vector3>(PositionChanged);
            m_Bounds.ValueChanged   += new ValueChanged <Vector2>(BoundsChanged);
            m_Scale.ValueChanged    += new ValueChanged <float>(ScaleChanged);

            Entity.AddEvent("Select", (o) => ChangeSelect(true));
            Entity.AddEvent("Deselect", (o) => ChangeSelect(false));
        }
        public HolyCityDeclaration(List <Property> properties, World world)
            : base(properties, world)
        {
            foreach (Property property in properties)
            {
                switch (property.Name)
                {
                case "site_id": Site = world.GetSite(Convert.ToInt32(property.Value)); break;

                case "religion_id": ReligionEntity = world.GetEntity(Convert.ToInt32(property.Value)); break;
                }
            }
            Site.AddEvent(this);
            ReligionEntity.AddEvent(this);
        }
        public EntityAllianceFormed(List <Property> properties, World world) : base(properties, world)
        {
            foreach (Property property in properties)
            {
                switch (property.Name)
                {
                case "initiating_enid": InitiatingEntity = world.GetEntity(Convert.ToInt32(property.Value)); break;

                case "joining_enid": JoiningEntity = world.GetEntity(Convert.ToInt32(property.Value)); break;
                }
            }


            InitiatingEntity.AddEvent(this);
            JoiningEntity.AddEvent(this);
        }
Example #25
0
        public EntityEquipmentPurchase(List <Property> properties, World world) : base(properties, world)
        {
            foreach (Property property in properties)
            {
                switch (property.Name)
                {
                case "entity_id": Entity = world.GetEntity(Convert.ToInt32(property.Value)); break;

                case "hfid": HistoricalFigure = world.GetHistoricalFigure(Convert.ToInt32(property.Value)); break;

                case "new_equipment_level": Quality = Convert.ToInt32(property.Value); break;
                }
            }

            Entity.AddEvent(this);
            HistoricalFigure.AddEvent(this);
        }
Example #26
0
        public FirstContact(List <Property> properties, World world)
            : base(properties, world)
        {
            foreach (Property property in properties)
            {
                switch (property.Name)
                {
                case "site_id": Site = world.GetSite(Convert.ToInt32(property.Value)); break;

                case "contactor_enid": Contactor = world.GetEntity(Convert.ToInt32(property.Value)); break;

                case "contacted_enid": Contacted = world.GetEntity(Convert.ToInt32(property.Value)); break;
                }
            }
            Site.AddEvent(this);
            Contactor.AddEvent(this);
            Contacted.AddEvent(this);
        }
Example #27
0
        public CreatedWorldConstruction(List <Property> properties, World world)
            : base(properties, world)
        {
            foreach (Property property in properties)
            {
                switch (property.Name)
                {
                case "civ_id": Civ = world.GetEntity(Convert.ToInt32(property.Value)); break;

                case "site_civ_id": SiteEntity = world.GetEntity(Convert.ToInt32(property.Value)); break;

                case "site_id1": Site1 = world.GetSite(Convert.ToInt32(property.Value)); break;

                case "site_id2": Site2 = world.GetSite(Convert.ToInt32(property.Value)); break;

                case "wcid": WorldConstruction = world.GetWorldConstruction(Convert.ToInt32(property.Value)); break;

                case "master_wcid": MasterWorldConstruction = world.GetWorldConstruction(Convert.ToInt32(property.Value)); break;
                }
            }

            Civ.AddEvent(this);
            SiteEntity.AddEvent(this);

            WorldConstruction.AddEvent(this);
            MasterWorldConstruction.AddEvent(this);

            Site1.AddEvent(this);
            Site2.AddEvent(this);

            Site1.AddConnection(Site2);
            Site2.AddConnection(Site1);

            if (WorldConstruction != null)
            {
                WorldConstruction.Site1 = Site1;
                WorldConstruction.Site2 = Site2;
                if (MasterWorldConstruction != null)
                {
                    MasterWorldConstruction.Sections.Add(WorldConstruction);
                    WorldConstruction.MasterConstruction = MasterWorldConstruction;
                }
            }
        }
Example #28
0
        public ImpersonateHf(List <Property> properties, World world)
            : base(properties, world)
        {
            foreach (Property property in properties)
            {
                switch (property.Name)
                {
                case "trickster_hfid": Trickster = world.GetHistoricalFigure(Convert.ToInt32(property.Value)); break;

                case "cover_hfid": Cover = world.GetHistoricalFigure(Convert.ToInt32(property.Value)); break;

                case "target_enid": Target = world.GetEntity(Convert.ToInt32(property.Value)); break;
                }
            }

            Trickster.AddEvent(this);
            Cover.AddEvent(this);
            Target.AddEvent(this);
        }
Example #29
0
        public DestroyedSite(List <Property> properties, World world)
            : base(properties, world)
        {
            foreach (Property property in properties)
            {
                switch (property.Name)
                {
                case "site_id": Site = world.GetSite(Convert.ToInt32(property.Value)); break;

                case "site_civ_id": SiteEntity = world.GetEntity(Convert.ToInt32(property.Value)); break;

                case "attacker_civ_id": Attacker = world.GetEntity(Convert.ToInt32(property.Value)); break;

                case "defender_civ_id": Defender = world.GetEntity(Convert.ToInt32(property.Value)); break;
                }
            }

            if (Site.OwnerHistory.Count == 0)
            {
                if (SiteEntity != null && SiteEntity != Defender)
                {
                    SiteEntity.Parent = Defender;
                    new OwnerPeriod(Site, SiteEntity, 1, "founded");
                }
                else
                {
                    new OwnerPeriod(Site, Defender, 1, "founded");
                }
            }

            Site.OwnerHistory.Last().EndCause = "destroyed";
            Site.OwnerHistory.Last().EndYear  = Year;
            Site.OwnerHistory.Last().Ender    = Attacker;

            Site.AddEvent(this);
            if (SiteEntity != Defender)
            {
                SiteEntity.AddEvent(this);
            }

            Attacker.AddEvent(this);
            Defender.AddEvent(this);
        }
Example #30
0
        public CreatureDevoured(List <Property> properties, World world)
            : base(properties, world)
        {
            foreach (Property property in properties)
            {
                switch (property.Name)
                {
                case "site_id": Site = world.GetSite(Convert.ToInt32(property.Value)); break;

                case "subregion_id": Region = world.GetRegion(Convert.ToInt32(property.Value)); break;

                case "feature_layer_id": UndergroundRegion = world.GetUndergroundRegion(Convert.ToInt32(property.Value)); break;

                case "victim": Victim = world.GetHistoricalFigure(Convert.ToInt32(property.Value)); break;

                case "eater": Eater = world.GetHistoricalFigure(Convert.ToInt32(property.Value)); break;

                case "entity": Entity = world.GetEntity(Convert.ToInt32(property.Value)); break;

                case "race": Race = property.Value.Replace("_", " "); break;

                case "caste": Caste = property.Value; break;

                case "site": if (Site == null)
                    {
                        Site = world.GetSite(Convert.ToInt32(property.Value));
                    }
                    else
                    {
                        property.Known = true;
                    } break;
                }
            }

            Site.AddEvent(this);
            Region.AddEvent(this);
            UndergroundRegion.AddEvent(this);
            Eater.AddEvent(this);
            Victim.AddEvent(this);
            Entity.AddEvent(this);
        }
Example #31
0
        public void CannotRemoveReadOnlyEventFromInheritingEntity()
        {
            bool collectionChanged = false;

            Entity parent = new Entity() { Name = "parent" };

            Event parentEvent = new Event(Workspace.Instance.GetPlugin(TriggerOccursEventType));
            parentEvent.SetProperty("Trigger", new Value("test"));
            parent.AddEvent(parentEvent);

            Entity child = new Entity();
            child.AddPrototype(parent);

            child.Events.CollectionChanged += (o, e) => collectionChanged = true;

            AbstractEvent childEvent = child.Events.Single();
            child.RemoveEvent(childEvent);

            Assert.IsFalse(collectionChanged);
            Assert.AreEqual(1, child.Events.Count);
        }
        public AddHfEntityHonor(List <Property> properties, World world) : base(properties, world)
        {
            HonorId = -1;
            foreach (Property property in properties)
            {
                switch (property.Name)
                {
                case "entity_id": Entity = world.GetEntity(Convert.ToInt32(property.Value)); break;

                case "hfid": HistoricalFigure = world.GetHistoricalFigure(Convert.ToInt32(property.Value)); break;

                case "honor_id": HonorId = Convert.ToInt32(property.Value); break;
                }
            }

            if (HonorId >= 0)
            {
                Honor = Entity.Honors.FirstOrDefault(h => h.Id == HonorId);
            }
            Entity.AddEvent(this);
            HistoricalFigure.AddEvent(this);
        }
Example #33
0
        public EntityOverthrown(List <Property> properties, World world) : base(properties, world)
        {
            Conspirators = new List <HistoricalFigure>();
            foreach (Property property in properties)
            {
                switch (property.Name)
                {
                case "entity_id": Entity = world.GetEntity(Convert.ToInt32(property.Value)); break;

                case "position_profile_id": PositionProfileId = Convert.ToInt32(property.Value); break;

                case "overthrown_hfid": OverthrownHistoricalFigure = world.GetHistoricalFigure(Convert.ToInt32(property.Value)); break;

                case "site_id": Site = world.GetSite(Convert.ToInt32(property.Value)); break;

                case "pos_taker_hfid": PositionTaker = world.GetHistoricalFigure(Convert.ToInt32(property.Value)); break;

                case "instigator_hfid": Instigator = world.GetHistoricalFigure(Convert.ToInt32(property.Value)); break;

                case "conspirator_hfid": Conspirators.Add(world.GetHistoricalFigure(Convert.ToInt32(property.Value))); break;
                }
            }

            Entity.AddEvent(this);
            OverthrownHistoricalFigure.AddEvent(this);
            Site.AddEvent(this);
            PositionTaker.AddEvent(this);
            if (Instigator != PositionTaker)
            {
                Instigator.AddEvent(this);
            }
            foreach (HistoricalFigure conspirator in Conspirators)
            {
                if (conspirator != PositionTaker && conspirator != Instigator)
                {
                    conspirator.AddEvent(this);
                }
            }
        }
Example #34
0
        public void CannotSetReadOnlyEventProperty()
        {
            Entity parent = new Entity() { Name = "parent" };

            Event parentEvent = new Event(Workspace.Instance.GetPlugin(TriggerOccursEventType));
            parentEvent.SetProperty("Trigger", new Value("test", true));
            parent.AddEvent(parentEvent);

            Entity child = new Entity();
            child.AddPrototype(parent);

            AbstractProperty childProperty = child.Events.Single().GetProperty("Trigger");
            childProperty.Value = new Value("test2", true);

            Assert.AreEqual("test", childProperty.Value.Reader.GetStrValue());
        }
Example #35
0
        public void RemoveReadOnlyEvent()
        {
            int eventsFired = 0;

            Entity parent = new Entity() { Name = "parent" };

            Entity child = new Entity();
            child.Events.CollectionChanged += (o, e) => eventsFired++;

            child.AddPrototype(parent);

            Event parentEvent = new Event(Workspace.Instance.GetPlugin(TriggerOccursEventType));
            parent.AddEvent(parentEvent);
            parent.RemoveEvent(parentEvent);

            Assert.AreEqual(2, eventsFired);
            Assert.AreEqual(0, parent.Events.Count);
            Assert.AreEqual(0, child.Events.Count);
        }
Example #36
0
        public void RemoveLocalEvent()
        {
            int eventsFired = 0;

            Entity entity = new Entity();
            entity.Events.CollectionChanged += (o, e) => eventsFired++;

            Event evt = new Event(Workspace.Instance.GetPlugin(TriggerOccursEventType));
            entity.AddEvent(evt);
            entity.RemoveEvent(evt);

            Assert.AreEqual(2, eventsFired);
            Assert.AreEqual(0, entity.Events.Count);
        }
Example #37
0
        public void EventsInheritedFromPrototype()
        {
            bool collectionChanged = false;

            Entity parent = new Entity() { Name = "parent" };

            Entity child = new Entity();
            child.Events.CollectionChanged += (o, e) => collectionChanged = true;

            child.AddPrototype(parent);

            Event parentEvent = new Event(Workspace.Instance.GetPlugin(TriggerOccursEventType));
            parent.AddEvent(parentEvent);

            Assert.IsTrue(collectionChanged);
            Assert.AreEqual(1, parent.Events.Count(x => x.IsEditable));
            Assert.AreEqual(1, child.Events.Count(x => x.IsReadOnly));
        }
Example #38
0
        public void EventsInheritedFromAllPrototypes()
        {
            int eventsFired = 0;

            Entity parent = new Entity() { Name = "parent" };
            Entity otherParent = new Entity() { Name = "otherParent" };

            Entity child = new Entity();
            child.Events.CollectionChanged += (o, e) => eventsFired++;

            child.AddPrototype(parent);
            child.AddPrototype(otherParent);

            parent.AddEvent(new Event(Workspace.Instance.GetPlugin(TriggerOccursEventType)));
            otherParent.AddEvent(new Event(Workspace.Instance.GetPlugin(TriggerOccursEventType)));

            Assert.AreEqual(2, eventsFired);
            Assert.AreEqual(1, parent.Events.Count(x => x.IsEditable));
            Assert.AreEqual(1, otherParent.Events.Count(x => x.IsEditable));
            Assert.AreEqual(2, child.Events.Count(x => x.IsReadOnly));
        }