PsyOps

DoorMan.cs

Nov 1st, 2013
143
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.36 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5.  
  6. namespace BattleZone
  7. {
  8.     public class DoorMan
  9.     {
  10.         // Status of all Doors - if you want to set some on and off by default set them here
  11.         private bool[] _DoorStatus = new bool[8] { true, true, true, true, true, true, true, true };
  12.         // Used to send back binary command to ss
  13.         private ushort[] _Multiplier = new ushort[8] {1,2,4,8,16,32,64,128};
  14.         // Old mode to check against - we only update if there is a change
  15.         private ushort _OldDoorMode = 0;
  16.         // Current DoorMode
  17.         private ushort _DoorMode = 255;
  18.  
  19.         /// <summary>
  20.         /// Change door status.
  21.         /// Door that you want to change: 1-8
  22.         /// New status of door: True/False
  23.         /// (Open = True, Closed = False)
  24.         /// </summary>
  25.         /// <param name="door">Door Number</param>
  26.         /// <param name="status">True if open/False if closed</param>
  27.         public void ChangeDoorStatus(byte door, bool status)
  28.         {
  29.             byte index = (byte)(door - 1);
  30.             _DoorStatus[index] = status;
  31.  
  32.             ushort NewDoorMode = 0;
  33.  
  34.             for (int i = 0; i < _DoorStatus.Length; i += 1)
  35.             {
  36.                 if (_DoorStatus[i])
  37.                     NewDoorMode += _Multiplier[i];
  38.             }
  39.  
  40.             _DoorMode = NewDoorMode;
  41.         }
  42.  
  43.         /// <summary>
  44.         /// Status of Door. open/closed.
  45.         /// </summary>
  46.         /// <param name="door">Door Number</param>
  47.         /// <returns>Open = True. Closed = False.</returns>
  48.         public bool DoorStatus(byte door)
  49.         {
  50.             return _DoorStatus[door - 1];
  51.         }
  52.  
  53.         /// <summary>
  54.         /// If Doors are in need of an update.
  55.         /// </summary>
  56.         public bool UpdateDoors
  57.         {
  58.             get
  59.             {
  60.                 if (_OldDoorMode != _DoorMode)
  61.                     return true;
  62.                 return false;
  63.             }
  64.         }
  65.  
  66.         /// <summary>
  67.         /// Command string to send.
  68.         /// Have bot send this in a public message.
  69.         /// </summary>
  70.         public string UpdateCommand
  71.         {
  72.             get
  73.             {
  74.                 _OldDoorMode = _DoorMode;
  75.                 return "?set Door:DoorMode=" + _DoorMode;
  76.             }
  77.         }
  78.     }
  79. }
Advertisement
Add Comment
Please, Sign In to add comment