Beispiel #1
0
        public static string WriteSave(NetCharacter ch, string description, int ids, DateTime?timeStamp)
        {
            var builder = new StringBuilder();

            builder.AppendLine("[Player]");
            if (timeStamp != null)
            {
                var fileTime = timeStamp?.ToFileTime();
                builder.Append("tstamp = ");
                builder.Append((fileTime >> 32).ToString());
                builder.Append(", ");
                builder.AppendLine((fileTime & 0xFFFFFFFF).ToString());
            }
            if (description != null)
            {
                builder.Append("description = ").AppendLine(SavePlayer.EncodeName(description));
            }
            else
            {
                builder.Append("descrip_strid = ").AppendLine(ids.ToString());
            }
            if (!string.IsNullOrWhiteSpace(ch.Name))
            {
                builder.Append("name = ").AppendLine(SavePlayer.EncodeName(ch.Name));
            }
            if (!string.IsNullOrWhiteSpace(ch.Base))
            {
                builder.Append("base = ").AppendLine(ch.Base);
            }
            if (!string.IsNullOrWhiteSpace(ch.System))
            {
                builder.Append("system = ").AppendLine(ch.System);
            }
            builder.Append("pos = ").AppendLine(Vector3(ch.Position));
            builder.Append("money = ").AppendLine(ch.Credits.ToString());
            if (ch.Ship != null)
            {
                builder.Append("ship_archetype = ").AppendLine(ch.Ship.Nickname);
            }
            foreach (var item in ch.Items)
            {
                if (!string.IsNullOrEmpty(item.Hardpoint))
                {
                    var hp = item.Hardpoint.Equals("internal", StringComparison.OrdinalIgnoreCase)
                        ? ""
                        : item.Hardpoint;
                    builder.Append("equip = ").Append(item.Equipment.Nickname).Append(",")
                    .Append(hp).Append(",").AppendLine("1");
                }
                else
                {
                    builder.Append("cargo = ");
                    builder.AppendLine($"{item.Equipment.Nickname}, {item.Count}, , , 0");
                }
            }
            return(builder.ToString());
        }
Beispiel #2
0
        public SaveGame NewCharacter(string name, int factionIndex)
        {
            var fac   = GameData.Ini.NewCharDB.Factions[factionIndex];
            var pilot = GameData.Ini.NewCharDB.Pilots.First(x =>
                                                            x.Nickname.Equals(fac.Pilot, StringComparison.OrdinalIgnoreCase));
            var package = GameData.Ini.NewCharDB.Packages.First(x =>
                                                                x.Nickname.Equals(fac.Package, StringComparison.OrdinalIgnoreCase));
            //TODO: initial_rep = %%FACTION%%
            //does this have any effect in FL?

            var src = new StringBuilder(Encoding.UTF8.GetString(FlCodec.ReadFile(GameData.VFS.Resolve("EXE\\mpnewcharacter.fl"))));

            src.Replace("%%NAME%%", SavePlayer.EncodeName(name));
            src.Replace("%%BASE_COSTUME%%", pilot.Body);
            src.Replace("%%COMM_COSTUME%%", pilot.Comm);
            //Changing voice breaks in vanilla (commented out in mpnewcharacter)
            src.Replace("%%VOICE%%", pilot.Voice);
            //TODO: pilot comm_anim (not in vanilla mpnewcharacter)
            //TODO: pilot body_anim (not in vanilla mpnewcharacter)
            src.Replace("%%MONEY%%", package.Money.ToString());
            src.Replace("%%HOME_SYSTEM%%", GameData.GetBase(fac.Base).System);
            src.Replace("%%HOME_BASE%%", fac.Base);

            var pkgStr = new StringBuilder();

            pkgStr.Append("ship_archetype = ").AppendLine(package.Ship);
            var loadout = GameData.Ini.Loadouts.Loadouts.First(x =>
                                                               x.Nickname.Equals(package.Loadout, StringComparison.OrdinalIgnoreCase));

            //do loadout
            foreach (var x in loadout.Equip)
            {
                pkgStr.AppendLine(new PlayerEquipment()
                {
                    EquipName = x.Nickname,
                    Hardpoint = x.Hardpoint ?? ""
                }.ToString());
            }

            foreach (var x in loadout.Cargo)
            {
                pkgStr.AppendLine(new PlayerCargo()
                {
                    CargoName = x.Nickname,
                    Count     = x.Count
                }.ToString());
            }
            //append
            src.Replace("%%PACKAGE%%", pkgStr.ToString());
            var initext = src.ToString();

            return(SaveGame.FromString($"mpnewcharacter: {fac.Nickname}", initext));
        }