/// <summary>
        ///     FLPACKET_SERVER_SETHULLSTATUS
        /// </summary>
        /// <param name="playerto"></param>
        /// <param name="ship"></param>
        public static void SendSetHullStatus(Player playerto, Old.Object.Ship.Ship ship)
        {
            playerto.Log.AddLog(LogType.FL_MSG, "tx FLPACKET_SERVER_SETHULLSTATUS objid={0}", ship.Objid);

            byte[] omsg = { 0x49, 0x02 };
            FLMsgType.AddFloat(ref omsg, ship.Health);
            playerto.SendMsgToClient(omsg);
        }
 /// <summary>
 ///     FLPACKET_SERVER_REQUESTCREATESHIPRESP
 /// </summary>
 /// <param name="playerto"></param>
 /// <param name="ship"></param>
 public static void SendCreateShipResponse(Player playerto, Old.Object.Ship.Ship ship)
 {
     playerto.Log.AddLog(LogType.FL_MSG, "tx FLPACKET_SERVER_REQUESTCREATESHIPRESP objid={0}", ship.Objid);
     byte[] omsg = { 0x27, 0x02 };
     FLMsgType.AddUInt8(ref omsg, 1); // dunno
     FLMsgType.AddUInt32(ref omsg, ship.Objid);
     playerto.SendMsgToClient(omsg);
 }
        /// <summary>
        ///     FLPACKET_SERVER_SYSTEM_SWITCH_OUT
        /// </summary>
        /// <param name="player"></param>
        /// <param name="ship"></param>
        /// <param name="solar"></param>
        public static void SendSystemSwitchOut(Player player, Old.Object.Ship.Ship ship, Object.Solar.Solar solar)
        {
            player.Log.AddLog(LogType.FL_MSG, "tx FLPACKET_SERVER_SYSTEM_SWITCH_OUT objid={0} solar={1}", ship.Objid,
                              solar.Objid);

            byte[] omsg = { 0x21, 0x02 };
            FLMsgType.AddUInt32(ref omsg, ship.Objid);
            FLMsgType.AddUInt32(ref omsg, solar.Objid);
            player.SendMsgToClient(omsg);
        }
        /// <summary>
        ///     FLPACKET_SERVER_LAND
        /// </summary>
        /// <param name="player"></param>
        /// <param name="ship"></param>
        /// <param name="solarid"></param>
        /// <param name="baseid"></param>
        public static void SendServerLand(Player player, Old.Object.Ship.Ship ship, uint solarid, uint baseid)
        {
            player.Log.AddLog(LogType.FL_MSG, "tx FLPACKET_SERVER_LAND objid={0} targetid={1} baseid={2}", ship.Objid,
                              solarid,
                              baseid);

            byte[] omsg = { 0x0B, 0x02 };
            FLMsgType.AddUInt32(ref omsg, ship.Objid);
            FLMsgType.AddUInt32(ref omsg, solarid);
            FLMsgType.AddUInt32(ref omsg, baseid);
            player.SendMsgToClient(omsg);
        }
예제 #5
0
        /// <summary>
        /// Sends thruster state of a ship.
        /// </summary>
        /// <param name="ship">Ship</param>
        /// <param name="state">Thruster on/off</param>
        public void NotifyOnActivateThrusters(Old.Object.Ship.Ship ship, bool state)
        {
            byte[] omsg = { 0x15, 0x01 };
            FLMsgType.AddUInt32(ref omsg, ship.Objid);
            FLMsgType.AddUInt8(ref omsg, state ? 1u : 0u);

            foreach (Player.Player player in Players.Values)
            {
                if (player.MonitoredObjs.ContainsKey(ship.Objid))
                {
                    player.SendMsgToClient(omsg);
                }
            }
        }
        /// <summary>
        ///     At object creation time we assume that the freelancer player has connected to the
        ///     proxy server and is expecting the normal freelancer server login sequence. This
        ///     class manages this message exchange until they select a character at which point
        ///     the controller will establish a connection to a slave freelancer server and
        ///     forward traffic between the two.
        /// </summary>
        /// <param name="dplayid"></param>
        /// <param name="log"></param>
        /// <param name="flplayerid"></param>
        /// <param name="runner"></param>
        public Player(Session dplayid, ILogController log, uint flplayerid, DPGameRunner runner)
        {
            DPSess     = dplayid;
            Log        = log;
            FLPlayerID = flplayerid;
            Runner     = runner;
            Ship       = new Old.Object.Ship.Ship(runner)
            {
                player = this
            };
            Wgrp = new WeaponGroup();

            _state = DPCLoginState.Instance();
            _state.EnterState(this);
        }
예제 #7
0
        public void NotifyOnStopTradelane(Old.Object.Ship.Ship ship, uint ring1, uint ring2)
        {
            byte[] omsg = { 0x10, 0x01 };
            FLMsgType.AddUInt32(ref omsg, ship.Objid);
            FLMsgType.AddUInt32(ref omsg, ring1);
            FLMsgType.AddUInt32(ref omsg, ring2);

            foreach (Player.Player player in Players.Values)
            {
                if (player.MonitoredObjs.ContainsKey(ship.Objid))
                {
                    player.SendMsgToClient(omsg);
                }
            }
        }
예제 #8
0
        /// <summary>
        ///     Determines a valid hardpoint for launching from
        ///     the given base. Validity is determined by the
        ///     DockingPoint.DockingSphere and ShipArchetype.MissionProperty
        ///     enumerations.
        /// </summary>
        /// <param name="ship"></param>
        /// <returns></returns>
        public DockingObject GetLaunchPoint(Old.Object.Ship.Ship ship)
        {
            // FIXME: select point based on ship moor type
            var validLaunchObjs = new List <DockingObject>();

            var mp = (ship.Arch as ShipArchetype).mission_property;

            var minType = Int32.MaxValue;

            foreach (DockingObject obj in LaunchObjs)
            {
                if (obj.CanDock(mp))
                {
                    if (obj.Type == DockingPoint.DockingSphere.RING)
                    {
                        if (obj.Index == 1)
                        {
                            return(obj);
                        }
                    }
                    else if ((int)obj.Type <= minType)
                    {
                        if ((int)obj.Type < minType)
                        {
                            validLaunchObjs.Clear();
                            minType = (int)obj.Type;
                        }

                        validLaunchObjs.Add(obj);
                    }
                }
            }

            if (validLaunchObjs.Count == 0)
            {
                return(null);
            }

            var selectedPoint = _rand.Next(validLaunchObjs.Count);

            return(validLaunchObjs[selectedPoint]);
        }
예제 #9
0
        public DockingObject GetDockingPoint(Old.Object.Ship.Ship ship)
        {
            var validDockingObjs = new List <DockingObject>();

            ShipArchetype.MissionProperty mp = ((ShipArchetype)ship.Arch).mission_property;

            int minType = Int32.MaxValue;

            foreach (DockingObject obj in DockingObjs)
            {
                if (obj.CanDock(mp))
                {
                    if (obj.Type == DockingPoint.DockingSphere.RING)
                    {
                        if (obj.Index == 0)
                        {
                            return(obj);
                        }
                    }
                    else if ((int)obj.Type <= minType)
                    {
                        if ((int)obj.Type < minType)
                        {
                            validDockingObjs.Clear();
                            minType = (int)obj.Type;
                        }

                        validDockingObjs.Add(obj);
                    }
                }
            }

            if (validDockingObjs.Count == 0)
            {
                return(null);
            }

            int selectedPoint = _rand.Next(Math.Min(2, validDockingObjs.Count));

            return(validDockingObjs.OrderBy(x => x.Position.DistSqr(ship.Position)).ElementAt(selectedPoint));
        }
예제 #10
0
        public CounterMeasure(DPGameRunner runner, Old.Object.Ship.Ship owner, CounterMeasureDropperArchetype gun_arch,
                              ShipItem launcher, uint hpid)
            : base(runner)
        {
            munition_arch = gun_arch.ProjectileArch as CounterMeasureArchetype;
            Arch          = munition_arch;

            Position    = owner.InterpolatedPosition();
            Position   += owner.Orientation * owner.Arch.Hardpoints[launcher.hpname.ToLowerInvariant()].Position;
            Orientation = Matrix.TurnAround(owner.Orientation);
            velocity    = Orientation * gun_arch.MuzzleVelocity + owner.EstimatedVelocity;
            owner_objid = owner.Objid;
            this.hpid   = hpid;

            lifetime        = munition_arch.Lifetime;
            owner_safe_time = munition_arch.OwnerSafeTime;

            Throttle = 1; // (float)(this.velocity.Length() / this.max_speed);

            angular_velocity = new Vector(rand.NextDouble() * 10 - 5, rand.NextDouble() * 10 - 5, rand.NextDouble() * 10 - 5);
        }
        /// <summary>
        ///     Set the attitude and faction of an object with respect to this player's ship
        /// </summary>
        public static void SendSetReputation(Player player, Old.Object.Ship.Ship ship)
        {
            byte[] omsg = { 0x29, 0x02 };
            // If the ship doesn't know about this faction then add it
            // with the default faction affiliaton from the initialworld
            // settings
            if (!player.Ship.Reps.ContainsKey(ship.faction))
            {
                player.Ship.Reps[ship.faction] = 0.0f; //fixme solar.faction.default_rep;
            }
            float attitude = player.Ship.Reps[ship.faction];

            player.Log.AddLog(LogType.FL_MSG,
                              "tx FLPACKET_SERVER_SETREPUTATION solar.objid={0} faction={1} attitude={2}",
                              ship.Objid, ship.faction.Nickname, attitude);

            FLMsgType.AddUInt8(ref omsg, 0x01);
            FLMsgType.AddUInt32(ref omsg, ship.Objid);
            FLMsgType.AddUInt32(ref omsg, ship.faction.FactionID);
            FLMsgType.AddFloat(ref omsg, attitude);
            player.SendMsgToClient(omsg);
        }
예제 #12
0
        /* public void NotifyOnServerLand(Ship ship, uint baseid, uint solarid)
         * {
         *  log.AddLog(LogType.FL_MSG, "tx FLPACKET_SERVER_LAND objid={0} targetid={1} baseid={2}", ship.objid, solarid, baseid));
         *
         *  byte[] omsg = { 0x0B, 0x02 };
         *  FLMsgType.AddUInt32(ref omsg, ship.objid);
         *  FLMsgType.AddUInt32(ref omsg, solarid);
         *  FLMsgType.AddUInt32(ref omsg, baseid);
         *
         *  foreach (Player player in players.Values)
         *  {
         *      if (player.monitored_objs.ContainsKey(ship.objid))
         *      {
         *          player.SendMsgToClient(omsg);
         *      }
         *  }
         * } */

        public void NotifyOnShipFiring(Old.Object.Ship.Ship ship, Vector targetPosition, List <uint> hpids)
        {
            byte[] omsg = { 0x02, 0x01 };
            FLMsgType.AddUInt32(ref omsg, ship.Objid);

            FLMsgType.AddUInt8(ref omsg, 0);
            FLMsgType.AddFloat(ref omsg, (float)targetPosition.x);
            FLMsgType.AddFloat(ref omsg, (float)targetPosition.y);
            FLMsgType.AddFloat(ref omsg, (float)targetPosition.z);
            FLMsgType.AddUInt8(ref omsg, (uint)hpids.Count);
            foreach (var hpid in hpids)
            {
                FLMsgType.AddUInt16(ref omsg, hpid);
            }

            foreach (Player.Player player in Players.Values)
            {
                if (player.MonitoredObjs.ContainsKey(ship.Objid))
                {
                    player.SendMsgToClient(omsg);
                }
            }
        }
        public Missile(DPGameRunner runner, Old.Object.Ship.Ship owner, GunArchetype gun_arch, ShipItem launcher, Vector target_position,
                       uint hpid)
            : base(runner)
        {
            munition_arch = gun_arch.ProjectileArch as MunitionArchetype;
            Arch          = munition_arch;

            Position        = owner.InterpolatedPosition();
            Position       += owner.Orientation * owner.Arch.Hardpoints[launcher.hpname.ToLowerInvariant()].Position;
            Orientation     = Matrix.CreateLookAt(Position, target_position);
            velocity        = Orientation * gun_arch.MuzzleVelocity + owner.EstimatedVelocity;
            owner_objid     = owner.Objid;
            target_objid    = owner.TargetObjID;
            target_subobjid = owner.target_subobjid;
            this.hpid       = hpid;

            lifetime = munition_arch.Lifetime;

            motor_accel        = munition_arch.MotorArch.Accel;
            motor_lifetime_max = motor_lifetime = munition_arch.MotorArch.Lifetime;
            motor_delay        = munition_arch.MotorArch.Delay;

            seek = (munition_arch.Seeker.ToUpper() == "LOCK") && (target_objid != 0);
            if (seek)
            {
                seeker_fov   = munition_arch.SeekerFovDeg * Math.PI / 180;
                seeker_range = munition_arch.SeekerRange;

                time_to_lock         = munition_arch.TimeToLock;
                max_angular_velocity = munition_arch.MaxAngularVelocity * Math.PI / 180;
            }

            max_speed = velocity.Length() + motor_accel * motor_lifetime_max;

            Throttle = 1; // (float)(this.velocity.Length() / this.max_speed);
        }
 public override void Update(Old.Object.Ship.Ship ship, DPGameRunner server, double seconds)
 {
     _state = ProcessState(server, seconds);
 }
예제 #15
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);
            }
예제 #16
0
 /// <summary>
 ///     Activate the docking point (i.e. close the door)
 /// </summary>
 public void Deactivate(DPGameRunner runner)
 {
     runner.SendActivateObject(this, false,
                               Type == DockingPoint.DockingSphere.TRADELANE_RING ? Ship.Objid : Index);
     Ship = null;
 }
예제 #17
0
 /// <summary>
 ///     Activate the docking point (i.e. open the door)
 /// </summary>
 public void Activate(DPGameRunner runner, Old.Object.Ship.Ship ship)
 {
     Ship = ship;
     runner.SendActivateObject(this, true, Type == DockingPoint.DockingSphere.TRADELANE_RING ? ship.Objid : Index);
 }
 public virtual void Update(Old.Object.Ship.Ship ship, DPGameRunner server, double seconds)
 {
 }
 public ShipAI(Old.Object.Ship.Ship ship)
 {
     Ship = ship;
 }
예제 #20
0
        // FLPACKET_SERVER_CREATESHIP
        public byte[] BuildCreateShip(Old.Object.Ship.Ship ship)
        {
            Log.AddLog(LogType.FL_MSG, "tx FLPACKET_SERVER_CREATESHIP objid={0}", ship.Objid);

            byte[] omsg = { 0x04, 0x02 };
            FLMsgType.AddUInt32(ref omsg, ship.Objid);
            FLMsgType.AddUInt16(ref omsg, ship.Arch.SmallID);
            FLMsgType.AddUInt32(ref omsg, 0);
            FLMsgType.AddUInt32(ref omsg, ship.player != null ? ship.player.FLPlayerID : 0);
            FLMsgType.AddUInt32(ref omsg, ship.com_body);
            FLMsgType.AddUInt32(ref omsg, ship.com_head);

            FLMsgType.AddUInt8(ref omsg, (uint)ship.Accessories.Count);
            foreach (uint accessory in ship.Accessories)
            {
                FLMsgType.AddUInt32(ref omsg, accessory);
            }

            FLMsgType.AddUInt32(ref omsg, ship.voiceid);

            FLMsgType.AddFloat(ref omsg, (float)ship.Position.x);
            FLMsgType.AddFloat(ref omsg, (float)ship.Position.y);
            FLMsgType.AddFloat(ref omsg, (float)ship.Position.z);

            Quaternion q = Quaternion.MatrixToQuaternion(ship.Orientation);

            FLMsgType.AddInt8(ref omsg, (int)(q.I * 127));
            FLMsgType.AddInt8(ref omsg, (int)(q.J * 127));
            FLMsgType.AddInt8(ref omsg, (int)(q.K * 127));
            FLMsgType.AddInt8(ref omsg, (int)(q.W * 127));

            FLMsgType.AddUInt8(ref omsg, (uint)(ship.Health * 255));

            FLMsgType.AddUInt16(ref omsg, (uint)(ship.Items.Count));
            foreach (ShipItem item in ship.Items.Values)
            {
                byte flag = 0;

                if (item.mounted)
                {
                    flag |= 0x01;
                }

                if (item.mission)
                {
                    flag |= 0x02;
                }

                if (item.count == 1)
                {
                    flag |= 0x80;
                }
                else
                {
                    flag |= 0x04;
                }

                if (item.health == 1.0f)
                {
                    flag |= 0x40;
                }

                if (item.hpname.Length > 0)
                {
                    flag |= 0x10;
                }
                else
                {
                    flag |= 0x20;
                }

                FLMsgType.AddUInt8(ref omsg, flag);

                if (item.count != 1)
                {
                    FLMsgType.AddUInt32(ref omsg, item.count);
                }

                if (item.health != 1.0f)
                {
                    FLMsgType.AddUInt8(ref omsg, (uint)(item.health * 255));
                }

                FLMsgType.AddUInt16(ref omsg, item.arch.SmallID);
                FLMsgType.AddUInt8(ref omsg, item.hpid);

                if (item.hpname.Length > 0)
                {
                    FLMsgType.AddAsciiStringLen8(ref omsg, item.hpname + "\0");
                }
            }

            FLMsgType.AddUInt8(ref omsg, (uint)(ship.cols.Count));
            foreach (CollisionGroup col in ship.cols)
            {
                FLMsgType.AddUInt8(ref omsg, col.id);
                FLMsgType.AddUInt8(ref omsg, (uint)(col.health * col.max_hit_pts * 255));
            }

            FLMsgType.AddUInt8(ref omsg, (ship.player != null) ? 4u : 0u); // flag
            FLMsgType.AddFloat(ref omsg, 0);                               // x
            FLMsgType.AddFloat(ref omsg, 0);                               // y
            FLMsgType.AddFloat(ref omsg, 0);                               // z
            FLMsgType.AddInt8(ref omsg, 0);
            FLMsgType.AddUInt16(ref omsg, 0);                              // dunno?
            FLMsgType.AddUInt8(ref omsg, ship.Rank);

            if (ship.player != null)
            {
                FLMsgType.AddUInt8(ref omsg, ship.player.FLPlayerID);
                FLMsgType.AddUInt16(ref omsg, 0);
                FLMsgType.AddUnicodeStringLen8(ref omsg, ship.player.Name);
            }
            else
            {
                var patrol_name = new FLFormatString(0x3f20);
                patrol_name.AddString(0x3016b);
                patrol_name.AddString(0x4074);
                patrol_name.AddString(0x30401);
                patrol_name.AddNumber(0x09);
                FLMsgType.AddArray(ref omsg, patrol_name.GetBytes());

                var ship_name = new FLFormatString(0x3f21);
                ship_name.AddString(0x301a4);
                ship_name.AddString(0x37bac);
                ship_name.AddString(0x37c2b);
                FLMsgType.AddArray(ref omsg, ship_name.GetBytes());
            }

            // The faction associated with the ship. For player ships this can be
            // -1 but for NPCs it needs to be set to a faction ID or the NPC will
            // not have a name shown in space or in the radar/scanner
            FLMsgType.AddUInt32(ref omsg, ship.faction.FactionID);

            // The reputation with reference to the faction..but it doesn't seem to
            // do much
            FLMsgType.AddInt8(ref omsg, -127);
            return(omsg);
        }
 protected SimObject SelectTarget(Old.Object.Ship.Ship ship, DPGameRunner runner)
 {
     return(runner.Objects.Values.Where(obj => obj != ship).FirstOrDefault(obj => obj is Old.Object.Ship.Ship && obj.Position.DistanceTo(ship.Position) < 5000));
 }