internal override void OnCycle() { ad++; if (ad == 10) { if (_currentCustomer == null) { _unit.MoveTo(_unit.GetRoom().GetGameMap().getRandomWalkableSquare()); } ad = 0; } if (_currentCustomer != null && _unit.Coordinate == _currentCustomer.SquareInFront) { _unit.Chat("Don't drink it all in one go, savour the flavor!", true); _currentCustomer = null; } RoomUnitManager unitManager = _unit.GetRoom().GetRoomUserManager(); List <Point> area = GetCustomerArea(); List <int> currentCustomers = new List <int>(); foreach (Point p in area) { RoomUser customer = unitManager.GetUnitForSquare(p.X, p.Y) as RoomUser; if (customer == null) { continue; } currentCustomers.Add(customer.VirtualID); if (!_customers.Contains(customer.VirtualID)) // New customer { _customers.Add(customer.VirtualID); _unit.Chat(string.Format("Hello, {0}", customer.Name), true); } } var test = new HashSet <int>(_customers); test.SymmetricExceptWith(currentCustomers); List <int> toRemove = new List <int>(); foreach (int customerID in test) { if (!currentCustomers.Contains(customerID)) // A customer left { _customers.Remove(customerID); //toRemove.Add(customerID); _unit.Chat(string.Format("Bye, {0}", unitManager.GetRoomUnitByVirtualId(customerID).Name), true); } } // Remove old customers //foreach (int customerID in toRemove) // _customers.Remove(customerID); }
public EntersRoom(RoomItem item, WiredHandler handler, RoomUnitManager roomUserManager, bool isOneUser, string userName) { this.item = item; this.handler = handler; this.isOneUser = isOneUser; this.userName = userName; this.delegateFunction = new RoomEventDelegate(roomUserManager_OnUserEnter); roomUserManager.OnUserEnter += delegateFunction; }