Exemple #1
0
    private void LoadGame(Instigator instigator)
    {
        LogController.LogAction(instigator, "loaded game");

        if (File.Exists(GetSavePath()) == false)
        {
            Debug.Log("No Game Saved");
            LoadDefaultGame();
        }
        else
        {
            //BinaryFormatter bf = new BinaryFormatter();
            //FileStream file = File.Open(GetSavePath(), FileMode.Open);
            //GameData = (GameData)bf.Deserialize(file);
            //file.Close();
            string jsonSaveData = File.ReadAllText(GetSavePath());
            try {
                GameData = JsonUtility.FromJson(jsonSaveData, typeof(GameData)) as GameData;
                Debug.Log("Game Loaded");
                OnLoadAction?.Invoke();
            }
            catch {
                Debug.LogWarning("Something went wrong casting the json, loading default game");
                LoadDefaultGame();
            }
        }
    }
 public async Task EditInstigator(Instigator instigator)
 {
     try {
         await _db.ExecuteAsync("UPDATE Instigators SET FactionId = @factionId, FileId = @fileId WHERE Id = @id AND IsDeleted != 0", new { id = instigator.Id, factionId = instigator.FactionId, fileId = instigator.FileId });
     } catch (Exception) {
         throw;
     }
 }
        public async Task <int> AddInstigator(Instigator instigator)
        {
            try {
                instigator.Id = await _db.QueryFirstAsync <int>("SELECT Id FROM Instigators ORDER BY Id DESC");

                await _db.ExecuteAsync("INSERT INTO Instigators VALUES (@id, @factionId, @fileId, 0)", new { id = instigator.Id, factionId = instigator.FactionId, fileId = instigator.FileId });

                return(instigator.Id);
            } catch (Exception) {
                return(0);
            }
        }
Exemple #4
0
    private void SaveGame(Instigator instigator)
    {
        LogController.LogAction(instigator, "saved game");

        string jsonSaveData = JsonUtility.ToJson(GameData);

        TextWriter tw = new StreamWriter(GetSavePath());

        tw.Write(jsonSaveData);
        tw.Close();

        Debug.Log("Game Saved");

        OnSaveAction?.Invoke();
    }
Exemple #5
0
        public override string Print(bool link = true, DwarfObject pov = null)
        {
            string eventString = GetYearTime();

            eventString += Instigator.ToLink(link, pov, this);
            eventString += " toppled the government of ";
            eventString += OverthrownHistoricalFigure.ToLink(link, pov, this);
            eventString += " of ";
            eventString += Entity.ToLink(link, pov, this);
            if (PositionTaker != Instigator)
            {
                eventString += " placed ";
                eventString += PositionTaker.ToLink(link, pov, this);
                eventString += " in power";
            }
            else
            {
                eventString += " and assumed control";
            }
            if (Site != null)
            {
                eventString += " in ";
                eventString += Site.ToLink(link, pov, this);
            }
            eventString += PrintParentCollection(link, pov);
            eventString += ".";
            if (Conspirators.Any())
            {
                eventString += " The support of ";
                for (int i = 0; i < Conspirators.Count; i++)
                {
                    var conspirator = Conspirators[i];
                    eventString += conspirator.ToLink(link, pov, this);
                    if (Conspirators.Count - i > 2)
                    {
                        eventString += ", ";
                    }
                    else if (Conspirators.Count - i == 2)
                    {
                        eventString += " and ";
                    }
                }
                eventString += "was crucial to the coup.";
            }
            return(eventString);
        }
Exemple #6
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);
                }
            }
        }
Exemple #7
0
    public static void LogAction(Instigator instigator, string action)
    {
        switch (Application.platform)
        {
        case RuntimePlatform.Android:
            if (File.Exists(GetAndroidLogPath()) == false)
            {
                TextWriter tw = new StreamWriter(GetAndroidLogPath());
                tw.WriteLine(DateTime.Now.ToShortDateString());
                tw.Close();
            }
            File.AppendAllText(GetAndroidLogPath(),
                               (DateTime.Now.ToLongTimeString() + " " + instigator + " " + action) + Environment.NewLine);
            if (DEBUG)
            {
                Debug.Log("Logged action: " + instigator + action);
            }
            break;

        case RuntimePlatform.OSXEditor:
        case RuntimePlatform.WindowsEditor:
            if (File.Exists(GetEditorLogPath()) == false)
            {
                TextWriter tw = new StreamWriter(GetEditorLogPath());
                tw.WriteLine(DateTime.Now.ToShortDateString());
                tw.Close();
            }
            File.AppendAllText(GetEditorLogPath(),
                               (DateTime.Now.ToLongTimeString() + " " + instigator + " " + action) + Environment.NewLine);
            if (DEBUG)
            {
                Debug.Log("Logged action: " + instigator + " " + action);
            }
            break;

        default:
            throw new NotImplementedException("Logging is not implemented for this platform");
        }
    }
Exemple #8
0
        public override void PostPreApplyDamage(DamageInfo dinfo, out bool absorbed)
        {
            bool acidburns = true;

            if (base.parent is Pawn pawn && pawn != null)
            {
                if (dinfo.Def != null)
                {
                    if (dinfo.Def.hediff == DefDatabase <HediffDef> .GetNamedSilentFail("CP_CQCTakedownHediff"))
                    {
                        absorbed = true;
                        return;
                    }
                    if (!dinfo.Def.isRanged)
                    {
                        if (dinfo.Instigator is Pawn Instigator && Instigator != null && Instigator != pawn && Instigator.AdjacentTo8WayOrInside(pawn))
                        {
                            if (dinfo.Weapon is ThingDef WeaponDef && WeaponDef != null)
                            {
                                if (WeaponDef.IsWeapon)
                                {
                                    if (WeaponDef == Instigator.equipment.Primary.def && Instigator.equipment.Primary is ThingWithComps Weapon && Instigator.equipment.PrimaryEq is CompEquippable WeaponEQ)
                                    {
                                        if (WeaponDef.MadeFromStuff && Weapon.Stuff is ThingDef WeaponStuff)
                                        {
                                            if (WeaponStuff.defName.Contains("RRY_Xeno"))
                                            {
                                                acidburns = false;
                                            }
                                        }
                                        else
                                        {
                                            foreach (var item in Weapon.def.costList)
                                            {
                                                if (item.thingDef == XenomorphDefOf.RRY_Xenomorph_TailSpike || item.thingDef == XenomorphDefOf.RRY_Xenomorph_HeadShell)
                                                {
                                                    acidburns = false;
                                                }
                                            }
                                        }
                                        if (acidburns)
                                        {
                                            Weapon.HitPoints -= Rand.Range(0, 5);
                                            if (Weapon.HitPoints <= 0)
                                            {
                                                Weapon.Destroy();
                                            }
                                        }
                                    }
                                }
                            }
                            if (Rand.Chance(0.25f) && Instigator.Map != null)
                            {
                                FilthMaker.MakeFilth(Instigator.Position, Instigator.Map, pawn.RaceProps.BloodDef, pawn.LabelIndefinite(), 1);
                            }
                        }
                    }
                    else if (dinfo.Def.isRanged)
                    {
#if DEBUG
                        Log.Message(string.Format("{0} is ranged: {1}", dinfo.Weapon.LabelCap, dinfo.Def.isRanged));
#endif
                    }
                    else
                    {
#if DEBUG
                        Log.Message(string.Format("{0} is unknown", dinfo.Weapon.LabelCap));
#endif
                    }
                }
            }
            base.PostPreApplyDamage(dinfo, out absorbed);
        }