Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- namespace BattleZone
- {
- public class DoorMan
- {
- // Status of all Doors - if you want to set some on and off by default set them here
- private bool[] _DoorStatus = new bool[8] { true, true, true, true, true, true, true, true };
- // Used to send back binary command to ss
- private ushort[] _Multiplier = new ushort[8] {1,2,4,8,16,32,64,128};
- // Old mode to check against - we only update if there is a change
- private ushort _OldDoorMode = 0;
- // Current DoorMode
- private ushort _DoorMode = 255;
- /// <summary>
- /// Change door status.
- /// Door that you want to change: 1-8
- /// New status of door: True/False
- /// (Open = True, Closed = False)
- /// </summary>
- /// <param name="door">Door Number</param>
- /// <param name="status">True if open/False if closed</param>
- public void ChangeDoorStatus(byte door, bool status)
- {
- byte index = (byte)(door - 1);
- _DoorStatus[index] = status;
- ushort NewDoorMode = 0;
- for (int i = 0; i < _DoorStatus.Length; i += 1)
- {
- if (_DoorStatus[i])
- NewDoorMode += _Multiplier[i];
- }
- _DoorMode = NewDoorMode;
- }
- /// <summary>
- /// Status of Door. open/closed.
- /// </summary>
- /// <param name="door">Door Number</param>
- /// <returns>Open = True. Closed = False.</returns>
- public bool DoorStatus(byte door)
- {
- return _DoorStatus[door - 1];
- }
- /// <summary>
- /// If Doors are in need of an update.
- /// </summary>
- public bool UpdateDoors
- {
- get
- {
- if (_OldDoorMode != _DoorMode)
- return true;
- return false;
- }
- }
- /// <summary>
- /// Command string to send.
- /// Have bot send this in a public message.
- /// </summary>
- public string UpdateCommand
- {
- get
- {
- _OldDoorMode = _DoorMode;
- return "?set Door:DoorMode=" + _DoorMode;
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment