private void removeEntityImplementationFromWorld(EntityImplementation enImpl) { // Basic implementation check if (!(enImpl is PlayerCharacter) && !(enImpl is ServerCharacter)) throw new ArgumentException("Unknown type of EntityImplementation: " + enImpl.GetType().ToString()); // Type specific remove operations if (enImpl is PlayerCharacter) { // Total active players activePlayerCharacters.Remove(enImpl as PlayerCharacter); // By Name dictionary if (loggedInPlayersByName.ContainsKey(enImpl.Name.ToLower())) loggedInPlayersByName.Remove(enImpl.Name.ToLower()); } if (enImpl is ServerCharacter) { // Total server characters activeServerCharacters.Remove(enImpl as ServerCharacter); } // By EntityID dictionary if (worldEntitiesByEntityID.ContainsKey(enImpl.EntityID)) worldEntitiesByEntityID.Remove(enImpl.EntityID); // Cancel time based actions enImpl.TimeBasedActionCancelExecuted(); // Remove from current map enImpl.LocationLeaveMapAtExitWorld(); // Stop following enImpl.FollowingStopFollowing(); enImpl.TimeBasedActionConnectToManager(null); enImpl.LocationSetMapManager(null); }
private void addEntityImplementationToWorld(EntityImplementation enImpl) { // Basic implementation check if (!(enImpl is PlayerCharacter) && !(enImpl is ServerCharacter)) throw new ArgumentException("Unknown type of EntityImplementation: " + enImpl.GetType().ToString()); // Type specific test operations if (enImpl is PlayerCharacter) { if (loggedInPlayersByName.ContainsKey(enImpl.Name.ToLower())) // This should not happen. It should be checked before making login successful throw new InvalidOperationException("Player is already in 'by name' dictionary!"); } if (enImpl is ServerCharacter) { if (activeServerCharacters.Contains(enImpl as ServerCharacter)) // This should not happen unless bug in script logic. throw new InvalidOperationException("Server character " + enImpl.Name + " already on the list of active characters!"); } // Searching for the next free entityID for (UInt16 i = 1; i < UInt16.MaxValue; i++) if (!worldEntitiesByEntityID.ContainsKey(i)) { enImpl.EntityID = i; worldEntitiesByEntityID[i] = enImpl; break; } if (enImpl.EntityID == 0) throw new InvalidOperationException("Could not allocate entityID to entity."); // Connect entity to time based actions manager enImpl.TimeBasedActionConnectToManager(timeBasedActionsManager); // Connecct entity to map manager enImpl.LocationSetMapManager(mapManager); // Type specific final operations if (enImpl is PlayerCharacter) { loggedInPlayersByName[enImpl.Name.ToLower()] = (enImpl as PlayerCharacter); } if (enImpl is ServerCharacter) { activeServerCharacters.Add(enImpl as ServerCharacter); } }