Esempio n. 1
0
        public void SetAbsBox(Edict pent)
        {
            var entity = pent.TryGetEntity();

            if (entity == null)
            {
                throw new InvalidOperationException($"Error: Entity \"{pent.Vars.ClassName}\" (index {EntUtils.EntIndex(pent)}) has no entity instance assigned for SetAbsBox call");
            }

            entity.SetObjectCollisionBox();
        }
Esempio n. 2
0
        public void Command(Edict pEntity, ICommand command)
        {
            // Is the client spawned yet?
            var player = pEntity.TryGetEntity <BasePlayer>();

            if (player == null)
            {
                return;
            }

            var commandName = command.Name;

            //TODO: implement commands

            if (commandName == PlayerUtils.SayCommandName)
            {
                PlayerUtils.HostSay(player, command, false);
            }
            else if (commandName == PlayerUtils.SayTeamCommandName)
            {
                PlayerUtils.HostSay(player, command, true);
            }
            else if (commandName == "closemenus")
            {
                // just ignore it
            }
            else if (Engine.GameRules.ClientCommand(player, command))
            {
                // MenuSelect returns true only if the command is properly handled,  so don't print a warning
            }
            else
            {
                // check the length of the command (prevents crash)
                // max total length is 192 ...and we're adding a string below ("Unknown command: %s\n")
                var printableName = commandName.Length > 127 ? commandName.Substring(0, 127) : commandName;

                // tell the user they entered an unknown command
                PlayerUtils.ClientPrint(player, HudPrint.Console, $"Unknown command: {printableName}\n");
            }
        }
Esempio n. 3
0
        public void SetupVisibility(Edict pViewEntity, Edict pClient, out IntPtr pvs, out IntPtr pas)
        {
            var client = pClient.Entity();

            // Find the client's PVS
            var view = pViewEntity?.TryGetEntity() ?? client;

            if ((client.Flags & EntFlags.Proxy) != 0)
            {
                pvs = IntPtr.Zero;    // the spectator proxy sees
                pas = IntPtr.Zero;    // and hears everything
                return;
            }

            var org = view.Origin + view.ViewOffset;

            if ((view.Flags & EntFlags.Ducking) != 0)
            {
                org += (WorldConstants.HULL_MIN - WorldConstants.DUCK_HULL_MIN);
            }

            pvs = EngineServer.SetFatPVS(org);
            pas = EngineServer.SetFatPAS(org);
        }
Esempio n. 4
0
        public void UpdateClientData(Edict ent, bool sendWeapons, ClientData cd)
        {
            if (ent == null || ent.PrivateData == null)
            {
                return;
            }

            var player = ent.TryGetEntity <BasePlayer>();

            BasePlayer originalPlayer = null;

            // if user is spectating different player in First person, override some vars
            if (player?.pev.UserInt1 == (int)ObserverMode.InEye && player.m_hObserverTarget)
            {
                originalPlayer = player;
                player         = player.m_hObserverTarget;
            }

            cd.Flags  = player.Flags;
            cd.Health = player.Health;

            cd.ViewModel = EngineModel.IndexOf(player.ViewModelName);

            cd.WaterLevel = player.WaterLevel;
            cd.WaterType  = player.WaterType;
            cd.Weapons    = player.pev.Weapons;

            // Vectors
            cd.Origin     = player.Origin;
            cd.Velocity   = player.Velocity;
            cd.ViewOffset = player.ViewOffset;
            cd.PunchAngle = player.PunchAngle;

            cd.InDuck        = player.pev.InDuck;
            cd.TimeStepSound = player.pev.TimeStepSound;
            cd.DuckTime      = player.pev.DuckTime;
            cd.SwimTime      = player.pev.SwimTime;
            cd.WaterJumpTime = (int)player.pev.TeleportTime;

            cd.SetPhysInfo(EngineServer.GetUnmanagedClientPhysicsInfoBuffer(ent));

            cd.MaxSpeed    = player.pev.MaxSpeed;
            cd.FieldOfView = player.pev.FieldOfView;
            cd.WeaponAnim  = player.pev.WeaponAnim;

            cd.PushMSec = player.pev.PushMSec;

            //Spectator mode
            if (originalPlayer != null)
            {
                // don't use spec vars from chased player
                cd.UserInt1 = originalPlayer.pev.UserInt1;
                cd.UserInt2 = originalPlayer.pev.UserInt2;
            }
            else
            {
                cd.UserInt1 = player.pev.UserInt1;
                cd.UserInt2 = player.pev.UserInt2;
            }

#if CLIENT_WEAPONS
            if (sendWeapons && player != null)
            {
                cd.NextAttack = player.m_flNextAttack;
                cd.UserFloat2 = player.m_flNextAmmoBurn;
                cd.UserFloat3 = player.m_flAmmoStartCharge;

                cd.UserVector1 = new Vector(
                    player.ammo_9mm,
                    player.ammo_357,
                    player.ammo_argrens
                    );

                cd.AmmoNails   = player.ammo_bolts;
                cd.AmmoShells  = player.ammo_buckshot;
                cd.AmmoRockets = player.ammo_rockets;
                cd.AmmoCells   = player.ammo_uranium;
                var vector2 = cd.UserVector2;
                vector2.x      = player.ammo_hornets;
                cd.UserVector2 = vector2;

                if (player.m_pActiveItem != null)
                {
                    BasePlayerWeapon gun = player.m_pActiveItem as BasePlayerWeapon;

                    if (gun?.IsPredicted() == true)
                    {
                        //TODO:
#if false
                        ItemInfo II;
                        memset(&II, 0, sizeof(II));
                        gun.GetItemInfo(&II);

                        cd.m_iId = II.iId;

                        cd.vuser3.z = gun.m_iSecondaryAmmoType;
                        cd.vuser4.x = gun.m_iPrimaryAmmoType;
                        cd.vuser4.y = player.m_rgAmmo[gun.m_iPrimaryAmmoType];
                        cd.vuser4.z = player.m_rgAmmo[gun.m_iSecondaryAmmoType];

                        if (player.m_pActiveItem.m_iId == WEAPON_RPG)
                        {
                            cd.vuser2.y = ((Rpg)player.m_pActiveItem).m_fSpotActive;
                            cd.vuser2.z = ((Rpg)player.m_pActiveItem).m_cActiveRockets;
                        }
#endif
                    }
                }
            }
#endif
        }
Esempio n. 5
0
 public void PostThink(Edict pEntity)
 {
     pEntity.TryGetEntity <BasePlayer>()?.PostThink();
 }