void ControlEventAction(GameWorld world, UserCtrlFlags ctrlFlag) { if (ctrlFlag.HasFlag(UserCtrlFlags.Use)) { var player = world.GetEntityOrNull("player", e => e.UserGuid == Guid); world.TryUse(player); } }
/// <summary> /// /// </summary> /// <param name="sender"></param> /// <param name="e"></param> void Keyboard_KeyDown(object sender, KeyEventArgs e) { if (e.Key == UseWeapon1) { weaponControl &= ~UserCtrlFlags.AllWeapon; weaponControl |= UserCtrlFlags.Machinegun; } if (e.Key == UseWeapon2) { weaponControl &= ~UserCtrlFlags.AllWeapon; weaponControl |= UserCtrlFlags.Shotgun; } if (e.Key == UseWeapon3) { weaponControl &= ~UserCtrlFlags.AllWeapon; weaponControl |= UserCtrlFlags.SuperShotgun; } if (e.Key == UseWeapon4) { weaponControl &= ~UserCtrlFlags.AllWeapon; weaponControl |= UserCtrlFlags.GrenadeLauncher; } if (e.Key == UseWeapon5) { weaponControl &= ~UserCtrlFlags.AllWeapon; weaponControl |= UserCtrlFlags.RocketLauncher; } if (e.Key == UseWeapon6) { weaponControl &= ~UserCtrlFlags.AllWeapon; weaponControl |= UserCtrlFlags.Chaingun; } if (e.Key == UseWeapon7) { weaponControl &= ~UserCtrlFlags.AllWeapon; weaponControl |= UserCtrlFlags.Railgun; } if (e.Key == UseWeapon8) { weaponControl &= ~UserCtrlFlags.AllWeapon; weaponControl |= UserCtrlFlags.HyperBlaster; } if (e.Key == UseWeapon9) { weaponControl &= ~UserCtrlFlags.AllWeapon; weaponControl |= UserCtrlFlags.BFG; } }
/// <summary> /// /// </summary> /// <param name="writer"></param> public void Read(BinaryReader reader, float lerpFactor) { // keep old teleport counter : var oldTeleport = TeleportCount; // set old values : PositionOld = LerpPosition(lerpFactor); RotationOld = LerpRotation(lerpFactor); // read state : UserGuid = new Guid(reader.ReadBytes(16)); ParentID = reader.ReadUInt32(); State = (EntityState)reader.ReadInt32(); ClassID = reader.ReadInt16(); TeleportCount = reader.ReadByte(); Position = reader.Read <Vector3>(); Rotation = reader.Read <Quaternion>(); UserCtrlFlags = (UserCtrlFlags)reader.ReadInt32(); LinearVelocity = reader.Read <Vector3>(); AngularVelocity = reader.Read <Vector3>(); AnimFrame = reader.ReadSingle(); for (int i = 0; i < inventory.Length; i++) { inventory[i] = reader.ReadInt16(); } ActiveItem = (Inventory)reader.ReadByte(); Model = reader.ReadInt16(); Sfx = reader.ReadInt16(); // entity teleported - reset position and rotation : if (oldTeleport != TeleportCount) { PositionOld = Position; RotationOld = Rotation; } }
/// <summary> /// Used to spawn entity on server side. /// </summary> /// <param name="id"></param> public Entity(uint id, short classId, uint parentId, Vector3 position, Quaternion rotation, string targetName) { ClassID = classId; this.ID = id; this.TargetName = targetName; TeleportCount = 0; RotationOld = Quaternion.Identity; PositionOld = Vector3.Zero; UserGuid = new Guid(); ParentID = parentId; Rotation = rotation; UserCtrlFlags = UserCtrlFlags.None; Position = position; PositionOld = position; }
/// <summary> /// /// </summary> /// <param name="writer"></param> public void Read ( BinaryReader reader, float lerpFactor ) { // keep old teleport counter : var oldTeleport = TeleportCount; // set old values : PositionOld = LerpPosition( lerpFactor ); RotationOld = LerpRotation( lerpFactor ); // read state : UserGuid = new Guid( reader.ReadBytes(16) ); ParentID = reader.ReadUInt32(); PrefabID = reader.ReadUInt32(); State = (EntityState)reader.ReadInt32(); TeleportCount = reader.ReadByte(); Position = reader.Read<Vector3>(); Rotation = reader.Read<Quaternion>(); UserCtrlFlags = (UserCtrlFlags)reader.ReadInt32(); LinearVelocity = reader.Read<Vector3>(); AngularVelocity = reader.Read<Vector3>(); for (int i=0; i<inventory.Length; i++) { inventory[i] = reader.ReadInt16(); } ActiveItem = (Inventory)reader.ReadByte(); // entity teleported - reset position and rotation : if (oldTeleport!=TeleportCount) { PositionOld = Position; RotationOld = Rotation; } }
/// <summary> /// Used to spawn entity on server side. /// </summary> /// <param name="id"></param> public Entity ( uint id, uint prefabId, uint parentId, Vector3 position, Quaternion rotation ) { this.ID = id; TeleportCount = 0; RotationOld = Quaternion.Identity; PositionOld = Vector3.Zero; UserGuid = new Guid(); PrefabID = prefabId; ParentID = parentId; Rotation = rotation; UserCtrlFlags = UserCtrlFlags.None; Position = position; PositionOld = position; }
void Keyboard_KeyDown( object sender, KeyEventArgs e ) { if (e.Key==UseWeapon1) { weaponControl &= ~UserCtrlFlags.AllWeapon; weaponControl |= UserCtrlFlags.Machinegun; } if (e.Key==UseWeapon2) { weaponControl &= ~UserCtrlFlags.AllWeapon; weaponControl |= UserCtrlFlags.Shotgun; } if (e.Key==UseWeapon3) { weaponControl &= ~UserCtrlFlags.AllWeapon; weaponControl |= UserCtrlFlags.SuperShotgun; } if (e.Key==UseWeapon4) { weaponControl &= ~UserCtrlFlags.AllWeapon; weaponControl |= UserCtrlFlags.GrenadeLauncher; } if (e.Key==UseWeapon5) { weaponControl &= ~UserCtrlFlags.AllWeapon; weaponControl |= UserCtrlFlags.RocketLauncher; } if (e.Key==UseWeapon6) { weaponControl &= ~UserCtrlFlags.AllWeapon; weaponControl |= UserCtrlFlags.Chaingun; } if (e.Key==UseWeapon7) { weaponControl &= ~UserCtrlFlags.AllWeapon; weaponControl |= UserCtrlFlags.Railgun; } if (e.Key==UseWeapon8) { weaponControl &= ~UserCtrlFlags.AllWeapon; weaponControl |= UserCtrlFlags.HyperBlaster; } if (e.Key==UseWeapon9) { weaponControl &= ~UserCtrlFlags.AllWeapon; weaponControl |= UserCtrlFlags.BFG; } }