Exemplo n.º 1
0
        public HfNewPet(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 "group_hfid": HistoricalFigure = world.GetHistoricalFigure(Convert.ToInt32(property.Value)); break;

                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 "site": if (Site == null)
                    {
                        Site = world.GetSite(Convert.ToInt32(property.Value));
                    }
                    else
                    {
                        property.Known = true;
                    } break;

                case "group": if (HistoricalFigure == null)
                    {
                        HistoricalFigure = world.GetHistoricalFigure(Convert.ToInt32(property.Value));
                    }
                    else
                    {
                        property.Known = true;
                    } break;

                case "pets": Pet = property.Value.Replace("_", " ").Replace("2", "two"); break;
                }
            }

            HistoricalFigure.AddEvent(this);
            Site.AddEvent(this);
            Region.AddEvent(this);
            UndergroundRegion.AddEvent(this);
        }
Exemplo n.º 2
0
        public Duel(List <Property> properties, World world)
            : base(properties, world)
        {
            foreach (Property property in properties)
            {
                switch (property.Name)
                {
                case "ordinal": Ordinal = String.Intern(property.Value); break;

                case "coords": Coordinates = Formatting.ConvertToLocation(property.Value); break;

                case "parent_eventcol": ParentCollection = world.GetEventCollection(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 "site_id": Site = world.GetSite(Convert.ToInt32(property.Value)); break;

                case "attacking_hfid": Attacker = world.GetHistoricalFigure(Convert.ToInt32(property.Value)); break;

                case "defending_hfid": Defender = world.GetHistoricalFigure(Convert.ToInt32(property.Value)); break;
                }
            }
            //foreach (WorldEvent collectionEvent in Collection) this.AddEvent(collectionEvent);
            if (ParentCollection != null && ParentCollection.GetType() == typeof(Battle))
            {
                foreach (HfDied death in Collection.OfType <HfDied>())
                {
                    Battle battle    = ParentCollection as Battle;
                    War    parentWar = battle.ParentCollection as War;
                    if (battle.NotableAttackers.Contains(death.HistoricalFigure))
                    {
                        battle.AttackerDeathCount++;
                        battle.Attackers.Single(squad => squad.Race == death.HistoricalFigure.Race).Deaths++;

                        if (parentWar != null)
                        {
                            parentWar.AttackerDeathCount++;
                        }
                    }
                    else if (battle.NotableDefenders.Contains(death.HistoricalFigure))
                    {
                        battle.DefenderDeathCount++;
                        battle.Defenders.Single(squad => squad.Race == death.HistoricalFigure.Race).Deaths++;
                        if (parentWar != null)
                        {
                            parentWar.DefenderDeathCount++;
                        }
                    }

                    if (parentWar != null)
                    {
                        (ParentCollection.ParentCollection as War).DeathCount++;
                    }
                }
            }
            Attacker.AddEventCollection(this);
            Defender.AddEventCollection(this);
            Region.AddEventCollection(this);
            UndergroundRegion.AddEventCollection(this);
            Site.AddEventCollection(this);
        }
Exemplo n.º 3
0
        public BodyAbused(List <Property> properties, World world)
            : base(properties, world)
        {
            Bodies = new List <HistoricalFigure>();
            int structureId = -1;

            foreach (Property property in properties)
            {
                switch (property.Name)
                {
                case "site_id": Site = world.GetSite(Convert.ToInt32(property.Value)); break;

                case "coords": Coordinates = Formatting.ConvertToLocation(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 "site": if (Site == null)
                    {
                        Site = world.GetSite(Convert.ToInt32(property.Value));
                    }
                    else
                    {
                        property.Known = true;
                    } break;

                case "civ": Abuser = world.GetEntity(Convert.ToInt32(property.Value)); break;

                case "victim_entity": Victim = world.GetEntity(Convert.ToInt32(property.Value)); break;

                case "bodies": Bodies.Add(world.GetHistoricalFigure(Convert.ToInt32(property.Value))); break;

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

                case "props_item_type":
                case "item_type":
                    ItemType = property.Value;
                    break;

                case "props_item_subtype":
                case "item_subtype":
                    ItemSubType = property.Value;
                    break;

                case "props_item_mat":
                case "item_mat":
                    Material = property.Value;
                    break;

                case "abuse_type":
                    switch (property.Value)
                    {
                    case "0":
                    case "impaled":
                        AbuseType = AbuseType.Impaled;
                        break;

                    case "1":
                    case "piled":
                        AbuseType = AbuseType.Piled;
                        break;

                    case "2":
                    case "flayed":
                        AbuseType = AbuseType.Flayed;
                        break;

                    case "3":
                    case "hung":
                        AbuseType = AbuseType.Hung;
                        break;

                    case "4":
                    case "mutilated":
                        AbuseType = AbuseType.Mutilated;
                        break;

                    case "5":
                    case "animated":
                        AbuseType = AbuseType.Animated;
                        break;

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

                case "pile_type":
                    switch (property.Value)
                    {
                    case "gruesomesculpture":
                        PileType = PileType.GruesomeSculpture;
                        break;

                    case "grislymound":
                        PileType = PileType.GrislyMound;
                        break;

                    case "grotesquepillar":
                        PileType = PileType.GrotesquePillar;
                        break;

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

                case "props_pile_type": PileTypeId = Convert.ToInt32(property.Value); break;

                case "props_item_mat_type": MaterialTypeId = Convert.ToInt32(property.Value); break;

                case "props_item_mat_index": MaterialIndex = Convert.ToInt32(property.Value); break;

                case "tree":
                    property.Known = true;     // TODO no idea what this is
                    break;

                case "structure":
                    structureId = Convert.ToInt32(property.Value);
                    break;

                case "interaction":
                    property.Known = true;     // TODO no idea what this is
                    break;
                }
            }

            Site.AddEvent(this);
            Region.AddEvent(this);
            UndergroundRegion.AddEvent(this);
            Bodies.ForEach(body =>
            {
                if (body != HistoricalFigure.Unknown)
                {
                    body.AddEvent(this);
                    if (AbuseType == AbuseType.Animated)
                    {
                        body.CreatureTypes.Add(new HistoricalFigure.CreatureType("animated corpse", this));
                    }
                }
            });
            HistoricalFigure.AddEvent(this);
            Abuser.AddEvent(this);
            Victim.AddEvent(this);
            if (structureId != -1 && Site != null)
            {
                Structure = Site.Structures.FirstOrDefault(structure => structure.Id == structureId);
                Structure.AddEvent(this);
            }
        }
Exemplo n.º 4
0
        public ChangeHfState(List <Property> properties, World world)
            : base(properties, world)
        {
            foreach (Property property in properties)
            {
                switch (property.Name)
                {
                case "state":
                    switch (property.Value)
                    {
                    case "settled": State = HfState.Settled; break;

                    case "wandering": State = HfState.Wandering; break;

                    case "scouting": State = HfState.Scouting; break;

                    case "snatcher": State = HfState.Snatcher; break;

                    case "refugee": State = HfState.Refugee; break;

                    case "thief": State = HfState.Thief; break;

                    case "hunting": State = HfState.Hunting; break;

                    case "visiting": State = HfState.Visiting; break;

                    default: State = HfState.Unknown; property.Known = false; break;
                    }
                    break;

                case "substate": SubState = Convert.ToInt32(property.Value); break;

                case "coords": Coordinates = Formatting.ConvertToLocation(property.Value); break;

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

                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 "site": Site = world.GetSite(Convert.ToInt32(property.Value)); break;

                case "mood":
                    switch (property.Value)
                    {
                    case "macabre":
                        Mood = Mood.Macabre;
                        break;

                    case "secretive":
                        Mood = Mood.Secretive;
                        break;

                    case "insane":
                        Mood = Mood.Insane;
                        break;

                    case "possessed":
                        Mood = Mood.Possessed;
                        break;

                    case "berserk":
                        Mood = Mood.Berserk;
                        break;

                    case "fey":
                        Mood = Mood.Fey;
                        break;

                    case "melancholy":
                        Mood = Mood.Melancholy;
                        break;

                    case "fell":
                        Mood = Mood.Fell;
                        break;

                    case "catatonic":
                        Mood = Mood.Catatonic;
                        break;

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

                case "reason":
                    switch (property.Value)
                    {
                    case "failed mood":
                        Reason = ChangeHfStateReason.FailedMood;
                        break;

                    case "gather information":
                        Reason = ChangeHfStateReason.GatherInformation;
                        break;

                    case "be with master":
                        Reason = ChangeHfStateReason.BeWithMaster;
                        break;

                    case "flight":
                        Reason = ChangeHfStateReason.Flight;
                        break;

                    case "scholarship":
                        Reason = ChangeHfStateReason.Scholarship;
                        break;

                    case "on a pilgrimage":
                        Reason = ChangeHfStateReason.Pilgrimage;
                        break;

                    case "lack of sleep":
                        Reason = ChangeHfStateReason.LackOfSleep;
                        break;

                    default:
                        if (property.Value != "-1")
                        {
                            property.Known = false;
                        }
                        break;
                    }
                    break;
                }
            }
            if (HistoricalFigure != null)
            {
                HistoricalFigure.AddEvent(this);
                HistoricalFigure.States.Add(new HistoricalFigure.State(State, Year));
                HistoricalFigure.State lastState = HistoricalFigure.States.LastOrDefault();
                if (lastState != null)
                {
                    lastState.EndYear = Year;
                }

                HistoricalFigure.CurrentState = State;
            }
            Site.AddEvent(this);
            Region.AddEvent(this);
            UndergroundRegion.AddEvent(this);
        }
Exemplo n.º 5
0
        public BodyAbused(List <Property> properties, World world)
            : base(properties, world)
        {
            Bodies = new List <HistoricalFigure>();
            foreach (Property property in properties)
            {
                switch (property.Name)
                {
                case "site_id": Site = world.GetSite(Convert.ToInt32(property.Value)); break;

                case "coords": Coordinates = Formatting.ConvertToLocation(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 "site": if (Site == null)
                    {
                        Site = world.GetSite(Convert.ToInt32(property.Value));
                    }
                    else
                    {
                        property.Known = true;
                    } break;

                case "civ": Abuser = world.GetEntity(Convert.ToInt32(property.Value)); break;

                case "bodies": Bodies.Add(world.GetHistoricalFigure(Convert.ToInt32(property.Value))); break;

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

                case "props_item_type": ItemType = property.Value; break;

                case "props_item_subtype": ItemSubType = property.Value; break;

                case "props_item_mat": Material = property.Value; break;

                case "abuse_type":
                    switch (property.Value)
                    {
                    case "0":
                        AbuseType = AbuseType.Impaled;
                        break;

                    case "1":
                        AbuseType = AbuseType.Piled;
                        break;

                    case "2":
                        AbuseType = AbuseType.Flayed;
                        break;

                    case "3":
                        AbuseType = AbuseType.Hung;
                        break;

                    case "4":
                        AbuseType = AbuseType.Mutilated;
                        break;

                    case "5":
                        AbuseType = AbuseType.Animated;
                        break;

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

                case "props_pile_type": PileTypeId = Convert.ToInt32(property.Value); break;

                case "props_item_mat_type": MaterialTypeId = Convert.ToInt32(property.Value); break;

                case "props_item_mat_index": MaterialIndex = Convert.ToInt32(property.Value); break;
                }
            }

            Site.AddEvent(this);
            Region.AddEvent(this);
            UndergroundRegion.AddEvent(this);
            Bodies.ForEach(body => body.AddEvent(this));
            HistoricalFigure.AddEvent(this);
            Abuser.AddEvent(this);
        }
Exemplo n.º 6
0
        public Battle(List <Property> properties, World world)
            : base(properties, world)
        {
            Initialize();

            var attackerSquadRaces            = new List <CreatureInfo>();
            var attackerSquadEntityPopulation = new List <int>();
            var attackerSquadNumbers          = new List <int>();
            var attackerSquadDeaths           = new List <int>();
            var attackerSquadSite             = new List <int>();
            var defenderSquadRaces            = new List <CreatureInfo>();
            var defenderSquadEntityPopulation = new List <int>();
            var defenderSquadNumbers          = new List <int>();
            var defenderSquadDeaths           = new List <int>();
            var defenderSquadSite             = new List <int>();

            foreach (Property property in properties)
            {
                switch (property.Name)
                {
                case "outcome":
                    switch (property.Value)
                    {
                    case "attacker won": Outcome = BattleOutcome.AttackerWon; break;

                    case "defender won": Outcome = BattleOutcome.DefenderWon; break;

                    default: Outcome = BattleOutcome.Unknown; world.ParsingErrors.Report("Unknown Battle Outcome: " + property.Value); break;
                    }
                    break;

                case "name": Name = Formatting.InitCaps(property.Value); break;

                case "coords": Coordinates = Formatting.ConvertToLocation(property.Value); break;

                case "war_eventcol": ParentCollection = world.GetEventCollection(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 "site_id": Site = world.GetSite(Convert.ToInt32(property.Value)); break;

                case "attacking_hfid": NotableAttackers.Add(world.GetHistoricalFigure(Convert.ToInt32(property.Value))); break;

                case "defending_hfid": NotableDefenders.Add(world.GetHistoricalFigure(Convert.ToInt32(property.Value))); break;

                case "attacking_squad_race": attackerSquadRaces.Add(world.GetCreatureInfo(property.Value)); break;

                case "attacking_squad_entity_pop": attackerSquadEntityPopulation.Add(Convert.ToInt32(property.Value)); break;

                case "attacking_squad_number":
                    int attackerSquadNumber = Convert.ToInt32(property.Value);
                    attackerSquadNumbers.Add(attackerSquadNumber <0 || attackerSquadNumber> Squad.MAX_SIZE ? Squad.MAX_SIZE : attackerSquadNumber);
                    break;

                case "attacking_squad_deaths":
                    int attackerSquadDeath = Convert.ToInt32(property.Value);
                    attackerSquadDeaths.Add(attackerSquadDeath <0 || attackerSquadDeath> Squad.MAX_SIZE ? Squad.MAX_SIZE : attackerSquadDeath);
                    break;

                case "attacking_squad_site": attackerSquadSite.Add(Convert.ToInt32(property.Value)); break;

                case "defending_squad_race": defenderSquadRaces.Add(world.GetCreatureInfo(property.Value)); break;

                case "defending_squad_entity_pop": defenderSquadEntityPopulation.Add(Convert.ToInt32(property.Value)); break;

                case "defending_squad_number":
                    int defenderSquadNumber = Convert.ToInt32(property.Value);
                    defenderSquadNumbers.Add(defenderSquadNumber <0 || defenderSquadNumber> Squad.MAX_SIZE ? Squad.MAX_SIZE : defenderSquadNumber);
                    break;

                case "defending_squad_deaths":
                    int defenderSquadDeath = Convert.ToInt32(property.Value);
                    defenderSquadDeaths.Add(defenderSquadDeath <0 || defenderSquadDeath> Squad.MAX_SIZE ? Squad.MAX_SIZE : defenderSquadDeath);
                    break;

                case "defending_squad_site": defenderSquadSite.Add(Convert.ToInt32(property.Value)); break;

                case "noncom_hfid": NonCombatants.Add(world.GetHistoricalFigure(Convert.ToInt32(property.Value))); break;

                case "individual_merc": property.Known = true; IndividualMercenaries = true; break;

                case "company_merc": property.Known = true; CompanyMercenaries = true; break;

                case "attacking_merc_enid":
                    AttackingMercenaryEntity = world.GetEntity(Convert.ToInt32(property.Value));
                    if (AttackingMercenaryEntity != null)
                    {
                        AttackingMercenaryEntity.Type = EntityType.MercenaryCompany;
                    }
                    break;

                case "defending_merc_enid":
                    DefendingMercenaryEntity = world.GetEntity(Convert.ToInt32(property.Value));
                    if (DefendingMercenaryEntity != null)
                    {
                        DefendingMercenaryEntity.Type = EntityType.MercenaryCompany;
                    }
                    break;

                case "attacking_squad_animated": property.Known = true; AttackingSquadAnimated = true; break;

                case "defending_squad_animated": property.Known = true; DefendingSquadAnimated = true; break;

                case "a_support_merc_enid":
                    var attackerSupportMercenaryEntity = world.GetEntity(Convert.ToInt32(property.Value));
                    if (attackerSupportMercenaryEntity != null)
                    {
                        AttackerSupportMercenaryEntities.Add(attackerSupportMercenaryEntity);
                        attackerSupportMercenaryEntity.Type = EntityType.MercenaryCompany;
                    }
                    break;

                case "d_support_merc_enid":
                    var defenderSupportMercenaryEntity = world.GetEntity(Convert.ToInt32(property.Value));
                    if (defenderSupportMercenaryEntity != null)
                    {
                        DefenderSupportMercenaryEntities.Add(defenderSupportMercenaryEntity);
                        defenderSupportMercenaryEntity.Type = EntityType.MercenaryCompany;
                    }
                    break;

                case "a_support_merc_hfid": AttackerSupportMercenaryHfs.Add(world.GetHistoricalFigure(Convert.ToInt32(property.Value))); break;

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

            if (Collection.OfType <AttackedSite>().Any())
            {
                Attacker = Collection.OfType <AttackedSite>().First().Attacker;
                Defender = Collection.OfType <AttackedSite>().First().Defender;
            }
            else if (Collection.OfType <FieldBattle>().Any())
            {
                Attacker = Collection.OfType <FieldBattle>().First().Attacker;
                Defender = Collection.OfType <FieldBattle>().First().Defender;
            }

            foreach (HistoricalFigure involvedHf in NotableAttackers.Union(NotableDefenders).Where(hf => hf != HistoricalFigure.Unknown))
            {
                involvedHf.Battles.Add(this);
                involvedHf.AddEventCollection(this);
                involvedHf.AddEvent(new BattleFought(involvedHf, this, World));
            }

            foreach (HistoricalFigure involvedSupportMercenaries in AttackerSupportMercenaryHfs.Union(DefenderSupportMercenaryHfs).Where(hf => hf != HistoricalFigure.Unknown))
            {
                involvedSupportMercenaries.Battles.Add(this);
                involvedSupportMercenaries.AddEventCollection(this);
                involvedSupportMercenaries.AddEvent(new BattleFought(involvedSupportMercenaries, this, World, true, true));
            }

            for (int i = 0; i < attackerSquadRaces.Count; i++)
            {
                AttackerSquads.Add(new Squad(attackerSquadRaces[i], attackerSquadNumbers[i], attackerSquadDeaths[i], attackerSquadSite[i], attackerSquadEntityPopulation[i]));
            }

            for (int i = 0; i < defenderSquadRaces.Count; i++)
            {
                DefenderSquads.Add(new Squad(defenderSquadRaces[i], defenderSquadNumbers[i], defenderSquadDeaths[i], defenderSquadSite[i], defenderSquadEntityPopulation[i]));
            }

            var groupedAttackerSquads = from squad in AttackerSquads
                                        group squad by squad.Race into squadRace
                                        select new { Race = squadRace.Key, Count = squadRace.Sum(squad => squad.Numbers), Deaths = squadRace.Sum(squad => squad.Deaths) };

            foreach (var squad in groupedAttackerSquads)
            {
                int   attackerSquadNumber = squad.Count + NotableAttackers.Count(attacker => attacker?.Race?.Id == squad.Race.Id);
                int   attackerSquadDeath  = squad.Deaths + Collection.OfType <HfDied>().Count(death => death.HistoricalFigure?.Race == squad.Race && NotableAttackers.Contains(death.HistoricalFigure));
                Squad attackerSquad       = new Squad(squad.Race, attackerSquadNumber, attackerSquadDeath, -1, -1);
                Attackers.Add(attackerSquad);
            }

            foreach (var attacker in NotableAttackers.Where(hf => Attackers.Count(squad => squad.Race == hf.Race) == 0).GroupBy(hf => hf.Race).Select(race => new { Race = race.Key, Count = race.Count() }))
            {
                var attackerDeath = Collection.OfType <HfDied>().Count(death => NotableAttackers.Contains(death.HistoricalFigure) && death.HistoricalFigure?.Race == attacker.Race);
                Attackers.Add(new Squad(attacker.Race, attacker.Count, attackerDeath, -1, -1));
            }

            var groupedDefenderSquads = from squad in DefenderSquads
                                        group squad by squad.Race into squadRace
                                        select new { Race = squadRace.Key, Count = squadRace.Sum(squad => squad.Numbers), Deaths = squadRace.Sum(squad => squad.Deaths) };

            foreach (var squad in groupedDefenderSquads)
            {
                int defenderSquadNumber = squad.Count + NotableDefenders.Count(defender => defender?.Race?.Id == squad.Race.Id);
                int defenderSquadDeath  = squad.Deaths + Collection.OfType <HfDied>().Count(death => death.HistoricalFigure?.Race == squad.Race && NotableDefenders.Contains(death.HistoricalFigure));
                Defenders.Add(new Squad(squad.Race, defenderSquadNumber, defenderSquadDeath, -1, -1));
            }

            foreach (var defender in NotableDefenders.Where(hf => Defenders.Count(squad => squad.Race == hf.Race) == 0).GroupBy(hf => hf.Race).Select(race => new { Race = race.Key, Count = race.Count() }))
            {
                int defenderDeath = Collection.OfType <HfDied>().Count(death => NotableDefenders.Contains(death.HistoricalFigure) && death.HistoricalFigure.Race == defender.Race);
                Defenders.Add(new Squad(defender.Race, defender.Count, defenderDeath, -1, -1));
            }

            Deaths = new Dictionary <CreatureInfo, int>();
            foreach (Squad squad in Attackers.Concat(Defenders).Where(a => a.Race != null && a.Race != CreatureInfo.Unknown))
            {
                if (Deaths.ContainsKey(squad.Race))
                {
                    Deaths[squad.Race] += squad.Deaths;
                }
                else
                {
                    Deaths[squad.Race] = squad.Deaths;
                }
            }

            AttackerDeathCount = Attackers.Sum(attacker => attacker.Deaths);
            DefenderDeathCount = Defenders.Sum(defender => defender.Deaths);

            if (Outcome == BattleOutcome.AttackerWon)
            {
                Victor = Attacker;
            }
            else if (Outcome == BattleOutcome.DefenderWon)
            {
                Victor = Defender;
            }

            if (ParentCollection is War parentWar)
            {
                if (parentWar.Attacker == Attacker)
                {
                    parentWar.AttackerDeathCount += AttackerDeathCount;
                    parentWar.DefenderDeathCount += DefenderDeathCount;
                }
                else
                {
                    parentWar.AttackerDeathCount += DefenderDeathCount;
                    parentWar.DefenderDeathCount += AttackerDeathCount;
                }
                parentWar.DeathCount += attackerSquadDeaths.Sum() + defenderSquadDeaths.Sum() + Collection.OfType <HfDied>().Count();

                if (Attacker == parentWar.Attacker && Victor == Attacker)
                {
                    parentWar.AttackerVictories.Add(this);
                }
                else
                {
                    parentWar.DefenderVictories.Add(this);
                }
            }

            Site?.Warfare.Add(this);
            Region?.Battles.Add(this);
            UndergroundRegion?.Battles.Add(this);

            if (attackerSquadDeaths.Sum() + defenderSquadDeaths.Sum() + Collection.OfType <HfDied>().Count() == 0)
            {
                Notable = false;
            }

            if (attackerSquadNumbers.Sum() + NotableAttackers.Count > (defenderSquadNumbers.Sum() + NotableDefenders.Count) * 10 && //NotableDefenders outnumbered 10 to 1
                Victor == Attacker &&
                AttackerDeathCount < (NotableAttackers.Count + attackerSquadNumbers.Sum()) * 0.1)    //NotableAttackers losses < 10%
            {
                Notable = false;
            }
            Attacker.AddEventCollection(this);
            if (Defender != Attacker)
            {
                Defender.AddEventCollection(this);
            }
            Region.AddEventCollection(this);
            UndergroundRegion.AddEventCollection(this);
            Site.AddEventCollection(this);
        }
Exemplo n.º 7
0
        public Site(List <Property> properties, World world)
            : base(properties, world)
        {
            Type                     = Name = UntranslatedName = "";
            Warfare                  = new List <EventCollection>();
            OwnerHistory             = new List <OwnerPeriod>();
            Connections              = new List <Site>();
            Populations              = new List <Population>();
            Officials                = new List <Official>();
            BeastAttacks             = new List <BeastAttack>();
            Structures               = new List <Structure>();
            RelatedHistoricalFigures = new List <HistoricalFigure>();
            SiteProperties           = new List <SiteProperty>();

            foreach (Property property in properties)
            {
                switch (property.Name)
                {
                case "type":
                    Type = Formatting.InitCaps(property.Value);
                    switch (property.Value)
                    {
                    case "cave": SiteType = SiteType.Cave; break;

                    case "fortress": SiteType = SiteType.Fortress; break;

                    case "forest retreat": SiteType = SiteType.ForestRetreat; break;

                    case "dark fortress": SiteType = SiteType.DarkFortress; break;

                    case "town": SiteType = SiteType.Town; break;

                    case "hamlet": SiteType = SiteType.Hamlet; break;

                    case "vault": SiteType = SiteType.Vault; break;

                    case "dark pits": SiteType = SiteType.DarkPits; break;

                    case "hillocks": SiteType = SiteType.Hillocks; break;

                    case "tomb": SiteType = SiteType.Tomb; break;

                    case "tower": SiteType = SiteType.Tower; break;

                    case "mountain halls": SiteType = SiteType.MountainHalls; break;

                    case "camp": SiteType = SiteType.Camp; break;

                    case "lair": SiteType = SiteType.Lair; break;

                    case "labyrinth": SiteType = SiteType.Labyrinth; break;

                    case "shrine": SiteType = SiteType.Shrine; break;

                    case "important location": SiteType = SiteType.ImportantLocation; break;

                    case "fort": SiteType = SiteType.Fort; break;

                    case "monastery": SiteType = SiteType.Monastery; break;

                    case "castle": SiteType = SiteType.Castle; break;

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

                case "name": Name = Formatting.InitCaps(property.Value); break;

                case "coords": Coordinates = Formatting.ConvertToLocation(property.Value); break;

                case "structures":
                    HasStructures  = true;
                    property.Known = true;
                    if (property.SubProperties != null)
                    {
                        foreach (Property subProperty in property.SubProperties)
                        {
                            subProperty.Known = true;
                            Structures.Add(new Structure(subProperty.SubProperties, world, this));
                        }
                    }
                    break;

                case "civ_id": property.Known = true; break;

                case "cur_owner_id": property.Known = true; break;

                case "rectangle":
                    char[]   delimiterChars = { ':', ',' };
                    string[] rectArray      = property.Value.Split(delimiterChars);
                    if (rectArray.Length == 4)
                    {
                        int x0 = Convert.ToInt32(rectArray[0]);
                        int y0 = Convert.ToInt32(rectArray[1]);
                        int x1 = Convert.ToInt32(rectArray[2]);
                        int y1 = Convert.ToInt32(rectArray[3]);
                        Rectangle = new Rectangle(x0, y0, x1 - x0, y1 - y0);
                    }
                    else
                    {
                        property.Known = false;
                    }
                    break;

                case "site_properties":
                    property.Known = true;
                    if (property.SubProperties != null)
                    {
                        foreach (Property subProperty in property.SubProperties)
                        {
                            subProperty.Known = true;
                            SiteProperties.Add(new SiteProperty(subProperty.SubProperties, world, this));
                        }
                    }
                    break;
                }
            }
            SetIconByType(SiteType);
        }
Exemplo n.º 8
0
        public Battle(List <Property> properties, World world)
            : base(properties, world)
        {
            Initialize();

            var attackerSquadRace             = new List <string>();
            var attackerSquadEntityPopulation = new List <int>();
            var attackerSquadNumbers          = new List <int>();
            var attackerSquadDeaths           = new List <int>();
            var attackerSquadSite             = new List <int>();
            var defenderSquadRace             = new List <string>();
            var defenderSquadEntityPopulation = new List <int>();
            var defenderSquadNumbers          = new List <int>();
            var defenderSquadDeaths           = new List <int>();
            var defenderSquadSite             = new List <int>();

            foreach (Property property in properties)
            {
                switch (property.Name)
                {
                case "outcome":
                    switch (property.Value)
                    {
                    case "attacker won": Outcome = BattleOutcome.AttackerWon; break;

                    case "defender won": Outcome = BattleOutcome.DefenderWon; break;

                    default: Outcome = BattleOutcome.Unknown; world.ParsingErrors.Report("Unknown Battle Outcome: " + property.Value); break;
                    }
                    break;

                case "name": Name = Formatting.InitCaps(property.Value); break;

                case "coords": Coordinates = Formatting.ConvertToLocation(property.Value); break;

                case "war_eventcol": ParentCollection = world.GetEventCollection(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 "site_id": Site = world.GetSite(Convert.ToInt32(property.Value)); break;

                case "attacking_hfid": NotableAttackers.Add(world.GetHistoricalFigure(Convert.ToInt32(property.Value))); break;

                case "defending_hfid": NotableDefenders.Add(world.GetHistoricalFigure(Convert.ToInt32(property.Value))); break;

                case "attacking_squad_race": attackerSquadRace.Add(Formatting.FormatRace(property.Value)); break;

                case "attacking_squad_entity_pop": attackerSquadEntityPopulation.Add(Convert.ToInt32(property.Value)); break;

                case "attacking_squad_number": attackerSquadNumbers.Add(Convert.ToInt32(property.Value)); break;

                case "attacking_squad_deaths": attackerSquadDeaths.Add(Convert.ToInt32(property.Value)); break;

                case "attacking_squad_site": attackerSquadSite.Add(Convert.ToInt32(property.Value)); break;

                case "defending_squad_race": defenderSquadRace.Add(Formatting.FormatRace(property.Value)); break;

                case "defending_squad_entity_pop": defenderSquadEntityPopulation.Add(Convert.ToInt32(property.Value)); break;

                case "defending_squad_number": defenderSquadNumbers.Add(Convert.ToInt32(property.Value)); break;

                case "defending_squad_deaths": defenderSquadDeaths.Add(Convert.ToInt32(property.Value)); break;

                case "defending_squad_site": defenderSquadSite.Add(Convert.ToInt32(property.Value)); break;

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

            if (Collection.OfType <AttackedSite>().Any())
            {
                Attacker = Collection.OfType <AttackedSite>().First().Attacker;
                Defender = Collection.OfType <AttackedSite>().First().Defender;
            }
            else if (Collection.OfType <FieldBattle>().Any())
            {
                Attacker = Collection.OfType <FieldBattle>().First().Attacker;
                Defender = Collection.OfType <FieldBattle>().First().Defender;
            }

            foreach (HistoricalFigure attacker in NotableAttackers)
            {
                attacker.Battles.Add(this);
            }

            foreach (HistoricalFigure defender in NotableDefenders)
            {
                defender.Battles.Add(this);
            }

            foreach (HistoricalFigure nonCombatant in NonCombatants)
            {
                nonCombatant.Battles.Add(this);
            }

            for (int i = 0; i < attackerSquadRace.Count; i++)
            {
                AttackerSquads.Add(new Squad(attackerSquadRace[i], attackerSquadNumbers[i], attackerSquadDeaths[i], attackerSquadSite[i], attackerSquadEntityPopulation[i]));
            }

            for (int i = 0; i < defenderSquadRace.Count; i++)
            {
                DefenderSquads.Add(new Squad(defenderSquadRace[i], defenderSquadNumbers[i], defenderSquadDeaths[i], defenderSquadSite[i], defenderSquadEntityPopulation[i]));
            }

            var groupedAttackerSquads = from squad in AttackerSquads
                                        group squad by squad.Race into squadRace
                                        select new { Race = squadRace.Key, Count = squadRace.Sum(squad => squad.Numbers), Deaths = squadRace.Sum(squad => squad.Deaths) };

            foreach (var squad in groupedAttackerSquads)
            {
                Attackers.Add(new Squad(squad.Race, squad.Count + NotableAttackers.Count(attacker => attacker.Race == squad.Race), squad.Deaths + Collection.OfType <HfDied>().Count(death => death.HistoricalFigure.Race == squad.Race && NotableAttackers.Contains(death.HistoricalFigure)), -1, -1));
            }

            foreach (var attacker in NotableAttackers.Where(hf => Attackers.Count(squad => squad.Race == hf.Race) == 0).GroupBy(hf => hf.Race).Select(race => new { Race = race.Key, Count = race.Count() }))
            {
                Attackers.Add(new Squad(attacker.Race, attacker.Count, Collection.OfType <HfDied>().Count(death => NotableAttackers.Contains(death.HistoricalFigure) && death.HistoricalFigure.Race == attacker.Race), -1, -1));
            }
            AttackersAsList = new List <string>();
            foreach (Squad squad in Attackers)
            {
                for (int i = 0; i < squad.Numbers; i++)
                {
                    AttackersAsList.Add(squad.Race);
                }
            }

            var groupedDefenderSquads = from squad in DefenderSquads
                                        group squad by squad.Race into squadRace
                                        select new { Race = squadRace.Key, Count = squadRace.Sum(squad => squad.Numbers), Deaths = squadRace.Sum(squad => squad.Deaths) };

            foreach (var squad in groupedDefenderSquads)
            {
                Defenders.Add(new Squad(squad.Race, squad.Count + NotableDefenders.Count(defender => defender.Race == squad.Race), squad.Deaths + Collection.OfType <HfDied>().Count(death => death.HistoricalFigure.Race == squad.Race && NotableDefenders.Contains(death.HistoricalFigure)), -1, -1));
            }

            foreach (var defender in NotableDefenders.Where(hf => Defenders.Count(squad => squad.Race == hf.Race) == 0).GroupBy(hf => hf.Race).Select(race => new { Race = race.Key, Count = race.Count() }))
            {
                Defenders.Add(new Squad(defender.Race, defender.Count, Collection.OfType <HfDied>().Count(death => NotableDefenders.Contains(death.HistoricalFigure) && death.HistoricalFigure.Race == defender.Race), -1, -1));
            }
            DefendersAsList = new List <string>();
            foreach (Squad squad in Defenders)
            {
                for (int i = 0; i < squad.Numbers; i++)
                {
                    DefendersAsList.Add(squad.Race);
                }
            }

            Deaths = new List <string>();
            foreach (Squad squad in Attackers.Concat(Defenders))
            {
                for (int i = 0; i < squad.Deaths; i++)
                {
                    Deaths.Add(squad.Race);
                }
            }

            AttackerDeathCount = Attackers.Sum(attacker => attacker.Deaths);
            DefenderDeathCount = Defenders.Sum(defender => defender.Deaths);

            if (Outcome == BattleOutcome.AttackerWon)
            {
                Victor = Attacker;
            }
            else if (Outcome == BattleOutcome.DefenderWon)
            {
                Victor = Defender;
            }

            if (ParentCollection is War parentWar)
            {
                if (parentWar.Attacker == Attacker)
                {
                    parentWar.AttackerDeathCount += AttackerDeathCount;
                    parentWar.DefenderDeathCount += DefenderDeathCount;
                }
                else
                {
                    parentWar.AttackerDeathCount += DefenderDeathCount;
                    parentWar.DefenderDeathCount += AttackerDeathCount;
                }
                parentWar.DeathCount += attackerSquadDeaths.Sum() + defenderSquadDeaths.Sum() + Collection.OfType <HfDied>().Count();

                if (Attacker == parentWar.Attacker && Victor == Attacker)
                {
                    parentWar.AttackerVictories.Add(this);
                }
                else
                {
                    parentWar.DefenderVictories.Add(this);
                }
            }

            if (Site != null)
            {
                Site.Warfare.Add(this);
            }

            if (Region != null)
            {
                Region.Battles.Add(this);
            }

            if (UndergroundRegion != null)
            {
                UndergroundRegion.Battles.Add(this);
            }

            if (attackerSquadDeaths.Sum() + defenderSquadDeaths.Sum() + Collection.OfType <HfDied>().Count() == 0)
            {
                Notable = false;
            }

            if (attackerSquadNumbers.Sum() + NotableAttackers.Count > (defenderSquadNumbers.Sum() + NotableDefenders.Count) * 10 && //NotableDefenders outnumbered 10 to 1
                Victor == Attacker &&
                AttackerDeathCount < (NotableAttackers.Count + attackerSquadNumbers.Sum()) * 0.1)    //NotableAttackers lossses < 10%
            {
                Notable = false;
            }
        }