Ejemplo n.º 1
0
        /// <summary>
        ///     Load shop information for equipment and commodities.
        /// </summary>
        /// <param name="path"></param>
        private static void LoadGoodData(string path, ILogController log)
        {
            var ini = new FLDataFile(path, true);

            foreach (FLDataFile.Section sec in ini.Sections)
            {
                var sectionName = sec.SectionName.ToLowerInvariant();
                if (sectionName != "good")
                {
                    continue;
                }
                var good = new Good {
                    Nickname = sec.GetSetting("nickname").Str(0)
                };
                good.GoodID = FLUtility.CreateID(good.Nickname);
                string category = sec.GetSetting("category").Str(0);
                if (category == "equipment")
                {
                    good.category  = Good.Category.Equipment;
                    good.BasePrice = sec.GetSetting("price").Float(0);
                    uint archid = FLUtility.CreateID(sec.GetSetting("equipment").Str(0));
                    good.EquipmentOrShipArch = ArchetypeDB.Find(archid);
                }
                else if (category == "commodity")
                {
                    good.category  = Good.Category.Commodity;
                    good.BasePrice = sec.GetSetting("price").Float(0);
                    uint archid = FLUtility.CreateID(sec.GetSetting("equipment").Str(0));
                    good.EquipmentOrShipArch = ArchetypeDB.Find(archid);
                }
                else if (category == "shiphull")
                {
                    good.category  = Good.Category.ShipHull;
                    good.BasePrice = sec.GetSetting("price").Float(0);
                    uint archid = FLUtility.CreateID(sec.GetSetting("ship").Str(0));
                    good.EquipmentOrShipArch = ArchetypeDB.Find(archid);
                }
                else if (category == "ship")
                {
                    good.category = Good.Category.ShipPackage;
                    uint goodid = FLUtility.CreateID(sec.GetSetting("hull").Str(0));
                    good.Shiphull = Goods[goodid];
                }
                else
                {
                    log.AddLog(LogType.ERROR, "error: unknown category " + sec.Desc);
                }

                Goods[good.GoodID] = good;
            }
        }
        public static Account GetOneAccount(string id, string charfilename)
        {
            var cmd = new SQLiteCommand(@"SELECT * FROM Characters Where ID = '" + id + @"' And CharCode = '" + charfilename + @"'", _conn);

            using (var reader = cmd.ExecuteReader())
            {
                reader.Read();
                var a = new Account
                {
                    CharName     = reader.GetString(0),
                    ID           = reader.GetString(1),
                    CharFileName = reader.GetString(2),
                    Money        = reader.GetInt32(3),
                    Ship         = (uint)reader.GetInt64(4),
                    System       = reader.GetString(5),
                    Location     = reader.GetString(6),
                    LastOnline   = reader.GetDateTime(7),
                    Rank         = reader.GetByte(8),
                    IsBanned     = reader.GetBoolean(9),
                    Settings     = reader.GetString(10),
                    ShipState    = reader.GetString(11),
                    Appearance   = reader.GetString(12),
                    Equipment    = reader.GetString(13),
                    Cargo        = reader.GetString(14),
                    RepList      = reader.GetString(15),
                    Visits       = reader.GetString(16),
                    TimeOnline   = (uint)reader.GetInt32(17),
                    UID          = reader.GetString(18)
                };
                Archetype arch = ArchetypeDB.Find(a.Ship);
                if (!(arch is ShipArchetype))
                {
                    _logiface.AddLog(LogType.ERROR, "Wrong ship archetype: " + a.CharName);
                    return(null);
                }

                return(a);
            }
        }
Ejemplo n.º 3
0
            public override void HandleTimerEvent(double deltaSeconds)
            {
                if (runner.System == UniverseDB.FindSystem("li01"))
                {
                    //TODO: AI debug here
                    for (int i = 0; i < 1; i++)
                    {
                        var npc = new Old.Object.Ship.Ship(runner);
                        npc.AI   = new AI.DebugAI(npc);
                        npc.Arch = ArchetypeDB.Find(FLUtility.CreateID("dsy_csv"));
                        if (npc.Arch == null)
                        {
                            return;
                        }

                        npc.Position = new Vector(-30000 + i * 300, i * 100, -25000);
                        //npc.orientation = ;
                        npc.Rank    = 20;
                        npc.System  = runner.System;
                        npc.Health  = 1.0f;
                        npc.faction = UniverseDB.FindFaction("fc_wild");
                        Loadout loadout = UniverseDB.FindLoadout("fc_j_ge_csv_loadout01");
                        if (loadout != null)
                        {
                            uint hpid = 34;
                            foreach (ShipItem item in loadout.Items)
                            {
                                var new_item = new ShipItem();
                                new_item.arch    = item.arch;
                                new_item.count   = item.count;
                                new_item.health  = 1.0f;
                                new_item.hpid    = hpid++;
                                new_item.hpname  = item.hpname;
                                new_item.mounted = item.mounted;
                                npc.Items.Add(new_item.hpid, new_item);
                            }
                        }
                        npc.InitialiseEquipmentSimulation();
                        runner.CreateSimObject(npc);
                    }
                }
                //    int total = 0;
                //    if (runner.players.Count > 0)
                //    {
                //        if (delta_seconds > 1.5)
                //            runner.log.AddLog(LogType.FL_MSG, "bad delta " + delta_seconds);

                //        // wow, this'll really suck if there are lots of NPCs
                //        foreach (Zone z in runner.system.zones)
                //        {
                //            if (z.shape != null && z.density > 0)
                //            {
                //                while (z.interference < z.density) // borrow this
                //                {
                //                    Ship npc = new Ship(runner);
                //                    npc.position = z.shape.position;
                //                    npc.orientation = z.shape.orientation;
                //                    npc.rank = 20;
                //                    npc.arch = ArchetypeDB.Find(FLUtility.CreateID("dsy_csv"));
                //                    npc.system = runner.system;
                //                    npc.health = 1.0f;
                //                    runner.CreateSimObject(npc);

                //                    z.interference++;
                //                    total++;
                //                }
                //            }
                //        }

                //        int working_npcs = 0;
                //        foreach (SimObject o in runner.objects.Values)
                //        {
                //            if (o.health > 0)
                //            {
                //                working_npcs++;

                //                foreach (Player player in runner.players.Values)
                //                {
                //                    if (player.ship != o)
                //                    {
                //                        Vector position = player.ship.position;
                //                        position.x += rand.Next(100);
                //                        position.z += rand.Next(100);
                //                        o.SetUpdateObject(position, player.ship.orientation, 1.0f, 0);
                //                    }
                //                }
                //            }
                //        }

                //        runner.log.AddLog(LogType.GENERAL, "system={0} npcs={1} objects={2} running={3}",
                //            runner.system.nickname, total, runner.objects.Count, working_npcs));

                //    }

                //    ExpireAfter(1);
            }
Ejemplo n.º 4
0
        /// <summary>
        ///     Load a single system
        /// </summary>
        /// <param name="path"></param>
        /// <param name="system"></param>
        /// <param name="log"></param>
        private static void LoadSystem(string path, StarSystem system, ILogController log)
        {
            try
            {
                var ini = new FLDataFile(path, true);
                foreach (FLDataFile.Section sec in ini.Sections)
                {
                    string sectionName = sec.SectionName.ToLowerInvariant();
                    if (sectionName == "zone")
                    {
                        var zone = new Zone {
                            shape = null, nickname = sec.GetSetting("nickname").Str(0)
                        };
                        zone.zoneid = FLUtility.CreateID(zone.nickname);

                        Vector position    = sec.GetSetting("pos").Vector();
                        var    orientation = new Matrix();

                        double[] size = null;

                        string shape = sec.GetSetting("shape").Str(0).ToLowerInvariant();

                        foreach (FLDataFile.Setting set in sec.Settings)
                        {
                            string settingName = set.SettingName.ToLowerInvariant();
                            switch (settingName)
                            {
                            case "rotation":
                                orientation = Matrix.EulerDegToMatrix(set.Vector());
                                break;

                            case "size":
                                size = new double[set.NumValues()];
                                for (int a = 0; a < size.Length; a++)
                                {
                                    size[a] = set.Float(a);
                                }
                                break;

                            case "damage":
                                zone.damage = set.Float(0);
                                break;

                            case "interference":
                                zone.interference = set.Float(0);
                                break;

                            case "encounter":
                                break;

                            case "faction":
                                break;

                            case "density":
                                zone.density = set.Float(0);
                                break;
                            }
                        }

                        if (size != null)
                        {
                            if (shape == "sphere" && size.Length == 1)
                            {
                                zone.shape = new Sphere(position, orientation, size[0]);
                            }
                            else if (shape == "cylinder" && size.Length == 2)
                            {
                                zone.shape = new Cylinder(position, orientation, size[0], size[1]);
                            }
                            else if (shape == "ellipsoid" && size.Length == 3)
                            {
                                zone.shape = new Ellipsoid(position, orientation, new Vector(size[0], size[1], size[2]));
                            }
                            else if (shape == "box" && size.Length == 3)
                            {
                                zone.shape = new Box(position, orientation, new Vector(size[0], size[1], size[2]));
                            }
                            else if (shape == "ring" && size.Length == 3)
                            {
                                zone.shape = new Ring(position, orientation, size[0], size[1], size[2]);
                            }
                        }

                        system.Zones.Add(zone);
                    }
                    else if (sectionName == "object")
                    {
                        var solar = new Object.Solar.Solar(system, sec.GetSetting("nickname").Str(0));

                        if (sec.SettingExists("pos"))
                        {
                            solar.Position = sec.GetSetting("pos").Vector();
                        }

                        if (sec.SettingExists("rotate"))
                        {
                            Vector euler = sec.GetSetting("rotate").Vector();
                            solar.Orientation = Matrix.EulerDegToMatrix(euler);
                        }

                        if (sec.SettingExists("base"))
                        {
                            // When a ship undocks, it undocks from the solar specified by baseid.
                            // uint baseid = FLUtility.CreateID(sec.GetSetting("base").Str(0));
                            // FIXME: check base exists
                            // solar.base_data = bases[baseid];
                            // bases[baseid].solar = solar;
                        }

                        if (sec.SettingExists("archetype"))
                        {
                            uint archetypeid = FLUtility.CreateID(sec.GetSetting("archetype").Str(0));
                            solar.Arch = ArchetypeDB.Find(archetypeid);
                            solar.GetLoadout();
                            // FIXME: check archetype exists
                        }

                        if (sec.SettingExists("dock_with"))
                        {
                            uint baseid = FLUtility.CreateID(sec.GetSetting("dock_with").Str(0));
                            solar.BaseData = Bases[baseid];
                        }

                        if (sec.SettingExists("goto"))
                        {
                            solar.DestinationObjid    = FLUtility.CreateID(sec.GetSetting("goto").Str(1));
                            solar.DestinationSystemid = FLUtility.CreateID(sec.GetSetting("goto").Str(0));
                        }

                        if (sec.SettingExists("prev_ring"))
                        {
                            solar.PrevRing = FLUtility.CreateID(sec.GetSetting("prev_ring").Str(0));
                        }

                        if (sec.SettingExists("next_ring"))
                        {
                            solar.NextRing = FLUtility.CreateID(sec.GetSetting("next_ring").Str(0));
                        }

                        if (sec.SettingExists("reputation"))
                        {
                            Faction faction = FindFaction(sec.GetSetting("reputation").Str(0));
                            if (faction == null)
                            {
                                log.AddLog(LogType.ERROR, "error: not valid faction={0}",
                                           sec.GetSetting("reputation").Str(0));
                            }
                            else
                            {
                                solar.Faction = faction;
                            }
                        }

                        // Rebuild the docking points from the archetype
                        // to the solar position and rotation.
                        foreach (DockingPoint dockingPoint in solar.Arch.DockingPoints)
                        {
                            var dockingObj = new DockingObject
                            {
                                Type          = dockingPoint.Type,
                                Solar         = solar,
                                Index         = (uint)solar.Arch.DockingPoints.IndexOf(dockingPoint),
                                DockingRadius = dockingPoint.DockingRadius,
                                Position      = solar.Orientation * dockingPoint.Position
                            };

                            // rotate the hardpoint by the base orientation and then
                            dockingObj.Position += solar.Position;

                            // the ship launch rotation is the base rotation rotated by the hardpoint rotation
                            dockingObj.Rotation = dockingPoint.Rotation * solar.Orientation;

                            if (solar.BaseData != null)
                            {
                                solar.BaseData.LaunchObjs.Add(dockingObj);
                            }

                            solar.DockingObjs.Add(dockingObj);
                        }


                        // Store the solar.
                        system.Solars[solar.Objid] = solar;
                        Solars[solar.Objid]        = solar;

                        if (solar.Arch.Type == Archetype.ObjectType.JUMP_GATE ||
                            solar.Arch.Type == Archetype.ObjectType.JUMP_HOLE)
                        {
                            system.Gates.Add(solar);
                        }
                    }
                }
            }
            catch (Exception e)
            {
                log.AddLog(LogType.ERROR, "error: '" + e.Message + "' when parsing '" + path);
                if (e.InnerException != null)
                {
                    log.AddLog(LogType.ERROR, "error: '" + e.InnerException.Message + "' when parsing '" + path);
                }
            }
        }
Ejemplo n.º 5
0
        private static void LoadLoadout(string path, ILogController log)
        {
            var ini = new FLDataFile(path, true);

            foreach (FLDataFile.Section sec in ini.Sections)
            {
                string sectionName = sec.SectionName.ToLowerInvariant();
                if (sectionName == "loadout")
                {
                    var  loadout = new Loadout();
                    uint hpid    = 34;
                    foreach (FLDataFile.Setting set in sec.Settings)
                    {
                        if (set.SettingName == "nickname")
                        {
                            loadout.Nickname  = set.Str(0);
                            loadout.LoadoutID = FLUtility.CreateID(loadout.Nickname);
                        }
                        else if (set.SettingName == "equip")
                        {
                            var item = new ShipItem {
                                arch = ArchetypeDB.Find(FLUtility.CreateID(set.Str(0)))
                            };
                            if (item.arch == null)
                            {
                                continue; // TODO: log
                            }
                            item.hpname = "";
                            if (set.NumValues() > 1)
                            {
                                item.hpname = set.Str(1);
                            }
                            item.health  = 1.0f;
                            item.mission = false;
                            item.mounted = true;
                            item.count   = 1;
                            item.hpid    = hpid++;
                            loadout.Items.Add(item);
                        }
                        else if (set.SettingName == "cargo")
                        {
                            var item = new ShipItem {
                                arch = ArchetypeDB.Find(FLUtility.CreateID(set.Str(0)))
                            };
                            if (item.arch == null)
                            {
                                continue; // TODO: log
                            }
                            item.hpname  = "";
                            item.health  = 1.0f;
                            item.mission = false;
                            item.mounted = false;
                            item.count   = set.UInt(1);
                            item.hpid    = hpid++;
                            loadout.Items.Add(item);
                        }
                    }
                    Loadouts[loadout.LoadoutID] = loadout;
                }
            }
        }
        /// <summary>
        ///     Load the specified character file, resetting all character specific
        ///     content for this player and notifying all players of the name.
        /// </summary>
        /// <param name="account">Player account</param>
        /// <param name="log"></param>
        /// <returns>Returns null on successful load otherwise returns error message as a string.</returns>
        public string LoadCharFile(Account account, ILogController log)
        {
            if (account == null)
            {
                log.AddLog(LogType.ERROR, "Broken account found!");
                return("Account is null!");
            }
            //null checks made earlier
            // ReSharper disable once PossibleInvalidOperationException
            PlayerAccount = account;
            Wgrp          = new WeaponGroup();

// ReSharper disable once PossibleNullReferenceException
            Name  = PlayerAccount.CharName;
            Money = PlayerAccount.Money;

            var arch = ArchetypeDB.Find(PlayerAccount.Ship);

            if (arch is ShipArchetype)
            {
                Ship.Arch = arch;
            }
            else
            {
                return("invalid ship");
            }

            if (ShipState.RepGroup == "")
            {
                Ship.faction = new Faction();
            }
            else
            {
                Ship.faction = UniverseDB.FindFaction(ShipState.RepGroup);
                if (Ship.faction == null)
                {
                    return("invalid faction");
                }
            }

            Ship.System = UniverseDB.FindSystem(PlayerAccount.System);
            if (Ship.System == null)
            {
                return("invalid system");
            }

            if (ShipState.Base == null)
            {
                Ship.Basedata = null;
            }
            else
            {
                Ship.Basedata = UniverseDB.FindBase(ShipState.Base);
                if (Ship.Basedata == null)
                {
                    return("invalid base");
                }
            }

            if (ShipState.LastBase == "")
            {
                Ship.RespawnBasedata = null;
                return("no respawn base");
            }

            Ship.RespawnBasedata = UniverseDB.FindBase(ShipState.LastBase);
            if (Ship.RespawnBasedata == null)
            {
                return("invalid respawn base");
            }



            if (Ship.Basedata == null)
            {
                if (ShipState.Position != null)
                {
                    Ship.Position = ShipState.Position;
                }

                if (ShipState.Rotate != null)
                {
                    Ship.Orientation = Matrix.EulerDegToMatrix(ShipState.Rotate);
                }
            }

            //TODO: why ShipState.Hull is always true
            Ship.Health = ShipState.Hull;
            if (Ship.Health <= 0)
            {
                Ship.Health = 0.05f;
            }

            Ship.voiceid = FLUtility.CreateID(Appearance.Voice);

            //TODO: calculate rank
// ReSharper disable once PossibleNullReferenceException
            Ship.Rank = PlayerAccount.Rank;

            Ship.com_body      = Appearance.Body;
            Ship.com_head      = Appearance.Head;
            Ship.com_lefthand  = Appearance.LeftHand;
            Ship.com_righthand = Appearance.RightHand;

            Ship.Items.Clear();

            uint hpid = 34;

            foreach (var set in Equipment)
            {
                var si = new ShipItem
                {
                    arch    = ArchetypeDB.Find(set.Arch),
                    hpname  = set.HpName,
                    health  = set.Health,
                    count   = 1,
                    mission = false,
                    mounted = true,
                    hpid    = hpid++
                };
                Ship.Items[si.hpid] = si;
            }

            foreach (var set in Cargo)
            {
                var si = new ShipItem
                {
                    arch    = ArchetypeDB.Find(set.Arch),
                    hpname  = "",
                    count   = set.Count,
                    health  = 1.0f,
                    mission = false,
                    mounted = false,
                    hpid    = hpid++
                };
                Ship.Items[si.hpid] = si;
            }

            Ship.Reps.Clear();


            foreach (var set in RepDictionary)
            {
                float rep     = set.Value;
                var   faction = UniverseDB.FindFaction(set.Key);
                if (faction == null)
                {
// ReSharper disable once PossibleNullReferenceException
                    log.AddLog(LogType.ERROR, "error: faction not found char={0} faction={1}", account.CharName,
                               set.Value);
                }
                else
                {
                    Ship.Reps[faction] = rep;
                }
            }


            //Visits.Clear();
            //foreach (var set in Visits)
            //{
            //    Visits[set.Key] = set.Value;
            //}

            Ship.CurrentAction = null;

            return(null);
        }