System.Collections.Generic.IDictionary.ContainsKey(uint)

Here are the examples of the csharp api System.Collections.Generic.IDictionary.ContainsKey(uint) taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.

44 Examples 7

19 Source : SQLWriter.cs
with GNU Affero General Public License v3.0
from ACEmulator

protected string GetValueEnumName(PropertyDataId property, uint value)
        {
            switch (property)
            {
                case PropertyDataId.AlternateCurrency:
                case PropertyDataId.AugmentationCreateItem:
                case PropertyDataId.LastPortal:
                case PropertyDataId.LinkedPortalOne:
                case PropertyDataId.LinkedPortalTwo:
                case PropertyDataId.OriginalPortal:
                case PropertyDataId.UseCreateItem:
                case PropertyDataId.VendorsClreplacedId:
                case PropertyDataId.PCAPPhysicsDIDDataTemplatedFrom:
                    if (WeenieNames != null)
                    {
                        WeenieNames.TryGetValue(value, out var propertyValueDescription);
                        return propertyValueDescription;
                    }
                    break;
                case PropertyDataId.BlueSurgeSpell:
                case PropertyDataId.DeathSpell:
                case PropertyDataId.ProcSpell:
                case PropertyDataId.RedSurgeSpell:
                case PropertyDataId.Spell:
                case PropertyDataId.YellowSurgeSpell:
                    if (SpellNames != null)
                    {
                        SpellNames.TryGetValue(value, out var propertyValueDescription);
                        return propertyValueDescription;
                    }
                    break;
                case PropertyDataId.WieldedTreasureType:
                    string treasureW = "";
                    if (TreasureWielded != null && TreasureWielded.ContainsKey(value))
                    {
                        foreach (var item in TreasureWielded[value])
                        {
                            treasureW += GetValueForTreasureDID(item);
                        }
                        return treasureW;
                    }
                    else if (TreasureDeath != null && TreasureDeath.ContainsKey(value))
                    {
                        return $"Loot Tier: {TreasureDeath[value].Tier}";
                    }
                    break;
                case PropertyDataId.DeathTreasureType:
                    string treasureD = "";
                    if (TreasureDeath != null && TreasureDeath.ContainsKey(value))
                    {
                        return $"Loot Tier: {TreasureDeath[value].Tier}";
                    }
                    else if (TreasureWielded != null && TreasureWielded.ContainsKey(value))
                    {
                        foreach (var item in TreasureWielded[value])
                        {
                            treasureD += GetValueForTreasureDID(item, true);
                        }
                        return treasureD;
                    }
                    break;
                case PropertyDataId.PCAPRecordedObjectDesc:
                    return ((ObjectDescriptionFlag)value).ToString();
                case PropertyDataId.PCAPRecordedPhysicsDesc:
                    return ((PhysicsDescriptionFlag)value).ToString();
                case PropertyDataId.PCAPRecordedWeenieHeader:
                    return ((WeenieHeaderFlag)value).ToString();
                case PropertyDataId.PCAPRecordedWeenieHeader2:
                    return ((WeenieHeaderFlag2)value).ToString();
            }

            return property.GetValueEnumName(value);
        }

19 Source : SQLWriter.cs
with GNU Affero General Public License v3.0
from ACEmulator

protected string GetValueForTreasureData(uint weenieOrType, bool isWeenieClreplacedID = false)
        {
            string label = "UNKNOWN RANDOMLY GENERATED TREASURE";

            uint? deathTreasureType = null;
            uint? wieldedTreasureType = null;

            if (isWeenieClreplacedID)
            {
                if (Weenies != null && Weenies.ContainsKey(weenieOrType))
                {
                    deathTreasureType = Weenies[weenieOrType].GetProperty(PropertyDataId.DeathTreasureType);
                    wieldedTreasureType = Weenies[weenieOrType].GetProperty(PropertyDataId.WieldedTreasureType);
                }
            }
            else
            {
                deathTreasureType = weenieOrType;
                wieldedTreasureType = weenieOrType;
            }

            if (deathTreasureType.HasValue && wieldedTreasureType.HasValue)
            {
                if (TreasureDeath != null && TreasureDeath.ContainsKey(deathTreasureType.Value))
                {
                    label = $"RANDOMLY GENERATED TREASURE from Loot Tier {TreasureDeath[deathTreasureType.Value].Tier} from Death Treasure Table id: {deathTreasureType}";
                }
                else if (TreasureWielded != null && TreasureWielded.ContainsKey(wieldedTreasureType.Value))
                {
                    label = "";
                    foreach (var item in TreasureWielded[wieldedTreasureType.Value])
                    {
                        var wName = "";
                        if (WeenieNames != null && WeenieNames.ContainsKey(item.WeenieClreplacedId))
                            wName = WeenieNames[item.WeenieClreplacedId];

                        label += $"{(item.StackSize > 0 ? $"{item.StackSize}" : "1")}x {wName} ({item.WeenieClreplacedId}), ";
                    }
                    label = label.Substring(0, label.Length - 2) + $" from Wielded Treasure Table id: {wieldedTreasureType}";
                }
            }
            else
            {
                label = "nothing";
            }

            return label;
        }

19 Source : SQLWriter.cs
with GNU Affero General Public License v3.0
from ACEmulator

protected string GetValueForTreasureData(uint weenieOrType, bool isWeenieClreplacedID = false)
        {
            string label = "UNKNOWN RANDOMLY GENERATED TREASURE";

            uint? deathTreasureType = null;
            uint? wieldedTreasureType = null;

            if (isWeenieClreplacedID)
            {
                if (Weenies != null && Weenies.ContainsKey(weenieOrType))
                {
                    deathTreasureType = Weenies[weenieOrType].GetProperty(PropertyDataId.DeathTreasureType);
                    wieldedTreasureType = Weenies[weenieOrType].GetProperty(PropertyDataId.WieldedTreasureType);
                }
            }
            else
            {
                deathTreasureType = weenieOrType;
                wieldedTreasureType = weenieOrType;
            }

            if (deathTreasureType.HasValue && wieldedTreasureType.HasValue)
            {
                if (TreasureDeath != null && TreasureDeath.ContainsKey(deathTreasureType.Value))
                {
                    label = $"RANDOMLY GENERATED TREASURE from Loot Tier {TreasureDeath[deathTreasureType.Value].Tier} from Death Treasure Table id: {deathTreasureType}";
                }
                else if (TreasureWielded != null && TreasureWielded.ContainsKey(wieldedTreasureType.Value))
                {
                    label = "";
                    foreach (var item in TreasureWielded[wieldedTreasureType.Value])
                    {
                        var wName = "";
                        if (WeenieNames != null && WeenieNames.ContainsKey(item.WeenieClreplacedId))
                            wName = WeenieNames[item.WeenieClreplacedId];

                        label += $"{(item.StackSize > 0 ? $"{item.StackSize}" : "1")}x {wName} ({item.WeenieClreplacedId}), ";
                    }
                    label = label.Substring(0, label.Length - 2) + $" from Wielded Treasure Table id: {wieldedTreasureType}";
                }
            }
            else
            {
                label = "nothing";
            }

            return label;
        }

19 Source : AreaTriggers.cs
with MIT License
from barncastle

public static void Initialize(ISandbox sandbox)
        {
            var properties = typeof(Location).GetProperties(BindingFlags.Public | BindingFlags.Instance);
            var resource = Properties.Resources.AreaTriggers;
            var entries = resource.Split(new[] { "\r", "\n" }, StringSplitOptions.RemoveEmptyEntries);

            int j;
            for (int i = 0; i < entries.Length; i++)
            {
                string[] data = entries[i].Split(',');

                var location = new Location();
                for (j = 0; j < properties.Length; j++)
                    properties[j].SetValueEx(location, data[j + 1]);

                // skip invalid expansions
                if (location.Expansion > sandbox.Expansion)
                    continue;

                // take the most recent variant
                var id = uint.Parse(data[0]);
                if (!Triggers.ContainsKey(id) || Triggers[id].Expansion < location.Expansion)
                    Triggers[id] = location;
            }

            ApplyOverrides(sandbox.Build);
        }

19 Source : ComponentManager.cs
with Apache License 2.0
from bnoazx005

public void RegisterEnreplacedy(EnreplacedyId enreplacedyId)
        {
            uint id = (uint)enreplacedyId;

            // check does the enreplacedy have the corresponding component already
            if (mEnreplacedy2ComponentsHashTable.ContainsKey(id))
            {
                return;
            }

            // there is no an enreplacedy with corresponding id in the table
            mEnreplacedy2ComponentsHashTable.Add(id, new Dictionary<Type, int>());
        }

19 Source : ComponentManager.cs
with Apache License 2.0
from bnoazx005

public void AddComponent<T>(EnreplacedyId enreplacedyId, T componentInitializer) where T : struct, IComponent
        {
            uint id = (uint)enreplacedyId;

            // check does the enreplacedy have the corresponding component already
            if (!mEnreplacedy2ComponentsHashTable.ContainsKey(id))
            {
                // there is no an enreplacedy with corresponding id in the table
                mEnreplacedy2ComponentsHashTable.Add(id, new Dictionary<Type, int>());
            }

            var enreplacedyComponentsTable = mEnreplacedy2ComponentsHashTable[id];
            
            Type cachedComponentType = typeof(T);
            
            // create a new group of components if it doesn't exist yet
            if (!mComponentTypesHashTable.ContainsKey(cachedComponentType))
            {
                mComponentTypesHashTable.Add(cachedComponentType, mComponentsMatrix.Count);

                mComponentsMatrix.Add(new List<IComponent>()); // add a list for the new group
            }

            int componentGroupHashValue = mComponentTypesHashTable[cachedComponentType];

            var componentsGroup = mComponentsMatrix[componentGroupHashValue];

            /// update internal value of the component if it already exists
            if (enreplacedyComponentsTable.ContainsKey(cachedComponentType))
            {
                componentsGroup[enreplacedyComponentsTable[cachedComponentType]] = componentInitializer;

                _notifyOnComponentsChanged(enreplacedyId, componentInitializer);

                return;
            }
            
            // NOTE: If the component implements IUniqueComponent we can't create more that one instance of it
            if ((componentsGroup.Count > 0) && typeof(IUniqueComponent).IsreplacedignableFrom(cachedComponentType))
            {
                throw new ComponentAlreadyExistException(cachedComponentType, enreplacedyId);
            }

            // create a new component
            enreplacedyComponentsTable.Add(cachedComponentType, componentsGroup.Count);

            componentsGroup.Add(componentInitializer);

            _notifyOnComponentsChanged(enreplacedyId, componentInitializer);

            ++mNumOfActiveComponents;
        }

19 Source : ComponentManager.cs
with Apache License 2.0
from bnoazx005

public IComponenreplacederator GetComponentsIterator(EnreplacedyId enreplacedyId)
        {
            uint id = (uint)enreplacedyId;

            /// there is no enreplacedy with the specified id
            if (!mEnreplacedy2ComponentsHashTable.ContainsKey(id))
            {
                throw new EnreplacedyDoesntExistException(enreplacedyId);
            }

            return new Componenreplacederator(mEnreplacedy2ComponentsHashTable[id], mComponentTypesHashTable, mComponentsMatrix);
        }

19 Source : ComponentManager.cs
with Apache License 2.0
from bnoazx005

public T GetComponent<T>(EnreplacedyId enreplacedyId) where T : struct, IComponent
        {
            uint id = (uint)enreplacedyId;

            /// there is no enreplacedy with the specified id
            if (!mEnreplacedy2ComponentsHashTable.ContainsKey(id))
            {
                throw new EnreplacedyDoesntExistException(enreplacedyId);
            }

            var enreplacedyComponentsTable = mEnreplacedy2ComponentsHashTable[id];

            /// there is no component with specified type that belongs to the enreplacedy
            Type cachedComponentType = typeof(T);

            if (!enreplacedyComponentsTable.ContainsKey(cachedComponentType))
            {
                // NOTE: If unique component doesn't exist, but someone tries to retrieve it create a new instance
                if (typeof(IUniqueComponent).IsreplacedignableFrom(cachedComponentType))
                {
                    AddComponent<T>(enreplacedyId, default(T));
                }
                else
                {
                    throw new ComponentDoesntExistException(cachedComponentType, enreplacedyId);
                }
            }

            int componentTypeGroupHashValue = mComponentTypesHashTable[cachedComponentType];
            int componentHashValue          = enreplacedyComponentsTable[cachedComponentType];

            return (T)mComponentsMatrix[componentTypeGroupHashValue][componentHashValue];
        }

19 Source : ComponentManager.cs
with Apache License 2.0
from bnoazx005

public void RemoveComponent<T>(EnreplacedyId enreplacedyId) where T : struct, IComponent
        {
            uint id = (uint)enreplacedyId;

            /// there is no enreplacedy with the specified id
            if (!mEnreplacedy2ComponentsHashTable.ContainsKey(id))
            {
                throw new EnreplacedyDoesntExistException(enreplacedyId);
            }

            var enreplacedyComponentsTable = mEnreplacedy2ComponentsHashTable[id];

            /// there is no component with specified type that belongs to the enreplacedy
            _removeComponent(enreplacedyComponentsTable, typeof(T), enreplacedyId);

            mEventManager.Notify<TComponentRemovedEvent>(new TComponentRemovedEvent()
            {
                mOwnerId       = enreplacedyId,
                mComponentType = typeof(T)
            });
        }

19 Source : ComponentManager.cs
with Apache License 2.0
from bnoazx005

public void RemoveAllComponents(EnreplacedyId enreplacedyId)
        {
            uint id = (uint)enreplacedyId;

            /// there is no enreplacedy with the specified id
            if (!mEnreplacedy2ComponentsHashTable.ContainsKey(id))
            {
                throw new EnreplacedyDoesntExistException(enreplacedyId);
            }

            var enreplacedyComponentsTable = mEnreplacedy2ComponentsHashTable[id];

            var enreplacedyComponentsTypes = enreplacedyComponentsTable.Keys;
            
            while (enreplacedyComponentsTable.Count > 0)
            {
                var currEnumerator = enreplacedyComponentsTypes.GetEnumerator();
                currEnumerator.MoveNext();

                _removeComponent(enreplacedyComponentsTable, currEnumerator.Current, enreplacedyId);
            }
        }

19 Source : ComponentManager.cs
with Apache License 2.0
from bnoazx005

public bool HasComponent(EnreplacedyId enreplacedyId, Type componentType)
        {
            uint id = (uint)enreplacedyId;

            /// there is no enreplacedy with the specified id
            if (!mEnreplacedy2ComponentsHashTable.ContainsKey(id))
            {
                throw new EnreplacedyDoesntExistException(enreplacedyId);
            }

            var enreplacedyComponentsTable = mEnreplacedy2ComponentsHashTable[id];

            return enreplacedyComponentsTable.ContainsKey(componentType);
        }

19 Source : AStar.cs
with MIT License
from BrunoSilvaFreire

private static List<uint> Reconstruct(IDictionary<uint, uint> cameFrom, uint current,
            NavMesh2D<KuroiNavMesh.GeometryNode> navmesh) {
            if (!cameFrom.ContainsKey(current)) {
                return null;
            }

            var currentCameFrom = cameFrom[current];
            var totalPath = new List<uint> {
                currentCameFrom
            };
            while (cameFrom.ContainsKey(current)) {
                if (!cameFrom.TryGetValue(current, out var link)) {
                    Debug.Log("Couldn't find value for " + current + "@ " + cameFrom);
                    return totalPath;
                }

                current = link;
                totalPath.Insert(0, link);
            }

            return totalPath;
        }

19 Source : ChatChannel.cs
with GNU General Public License v3.0
from caioavidal

public bool PlayerCanWrite(IPlayer player)
        {
            return player is null
                ? true
                : player is not null && users.ContainsKey(player.Id) && Validate(WriteRule, player);
        }

19 Source : NpcDialog.cs
with GNU General Public License v3.0
from caioavidal

public bool IsTalkingWith(ICreature creature)
        {
            return playerDialogTree.ContainsKey(creature.CreatureId);
        }

19 Source : Scheduler.cs
with MIT License
from CoreOpenMMO

public void CancelAllFor(uint requestorId, Type specificType = null) {
			if (specificType == null) {
				specificType = typeof(BaseEvent);
			}

			if (specificType as IEvent == null) {
				throw new ArgumentException($"Invalid type of event specified. Type must derive from {nameof(IEvent)}.", nameof(specificType));
			}

			lock (_eventsPerRequestorLock) {
				if (!_eventsPerRequestor.ContainsKey(requestorId) || _eventsPerRequestor[requestorId].Count == 0) {
					return;
				}

				foreach (var eventId in _eventsPerRequestor[requestorId]) {
					// TODO: remove only the specified type.
					CancelEvent(eventId);
				}

				_eventsPerRequestor.Remove(requestorId);
			}
		}

19 Source : Scheduler.cs
with MIT License
from CoreOpenMMO

public void ImmediateEvent(IEvent eventToSchedule) {
			if (eventToSchedule == null)
				throw new ArgumentNullException(nameof(eventToSchedule));

			if (!(eventToSchedule is BaseEvent castedEvent)) {
				throw new ArgumentException($"Argument must be of type {nameof(BaseEvent)}.", nameof(eventToSchedule));
			}

			lock (_eventsAvailableLock) {
				lock (_queueLock) {
					if (_priorityQueue.Contains(castedEvent)) {
						throw new ArgumentException($"The event is already scheduled.", nameof(eventToSchedule));
					}

					_priorityQueue.Enqueue(castedEvent, 0);
				}

				// check and add event attribution to the requestor
				if (castedEvent.RequestorId > 0) {
					lock (_eventsPerRequestorLock) {
						if (!_eventsPerRequestor.ContainsKey(castedEvent.RequestorId)) {
							_eventsPerRequestor.Add(castedEvent.RequestorId, new HashSet<string>());
						}

						try {
							_eventsPerRequestor[castedEvent.RequestorId].Add(castedEvent.EventId);
						} catch {
							// ignore clashes, it was our goal to add it anyways.
						}
					}
				}

				Monitor.Pulse(_eventsAvailableLock);
			}
		}

19 Source : Scheduler.cs
with MIT License
from CoreOpenMMO

public void ScheduleEvent(IEvent eventToSchedule, DateTime runAt) {
			if (eventToSchedule == null)
				throw new ArgumentNullException(nameof(eventToSchedule));

			if (!(eventToSchedule is BaseEvent castedEvent)) {
				throw new ArgumentException($"Argument must be of type {nameof(BaseEvent)}.", nameof(eventToSchedule));
			}

			if (runAt < _startTime) {
				throw new ArgumentException($"Value cannot be earlier than the reference time of the scheduler: {_startTime}.", nameof(runAt));
			}

			lock (_eventsAvailableLock) {
				lock (_queueLock) {
					if (_priorityQueue.Contains(castedEvent)) {
						throw new ArgumentException($"The event is already scheduled.", nameof(eventToSchedule));
					}

					_priorityQueue.Enqueue(castedEvent, GetMillisecondsAfterReferenceTime(runAt));
				}

				// check and add event attribution to the requestor
				if (castedEvent.RequestorId > 0) {
					lock (_eventsPerRequestorLock) {
						if (!_eventsPerRequestor.ContainsKey(castedEvent.RequestorId)) {
							_eventsPerRequestor.Add(castedEvent.RequestorId, new HashSet<string>());
						}

						try {
							_eventsPerRequestor[castedEvent.RequestorId].Add(castedEvent.EventId);
						} catch {
							// ignore clashes, it was our goal to add it anyways.
						}
					}
				}

				Monitor.Pulse(_eventsAvailableLock);
			}
		}

19 Source : Turret.cs
with GNU General Public License v2.0
from ensoulsharp-io

private static void EventTurret(AIBaseClient sender)
        {
            var turret = sender as AITurretClient;
            if (turret == null)
            {
                return;
            }
            var turNetworkId = turret.NetworkId;
            if (!Turrets.ContainsKey(turNetworkId))
            {
                Turrets.Add(turNetworkId, new TurretArgs { Turret = turret });
            }

            Turrets[turNetworkId].AttackStart = Variables.TickCount;
            if (Turrets[turNetworkId].Target != null && Turrets[turNetworkId].Target.IsValid)
            {
                Turrets[turNetworkId].AttackDelay = (turret.AttackCastDelay * 1000)
                                                    + (turret.Distance(Turrets[turNetworkId].Target)
                                                       / turret.BasicAttack.MissileSpeed * 1000);
                Turrets[turNetworkId].AttackEnd = (int)(Variables.TickCount + Turrets[turNetworkId].AttackDelay);
            }
            OnTurretAttack?.Invoke(MethodBase.GetCurrentMethod().DeclaringType, Turrets[turNetworkId]);
        }

19 Source : Teleport.cs
with GNU General Public License v2.0
from ensoulsharp-io

private static void EventTeleport(AIBaseClient sender, AIBaseClientTeleportEventArgs args)
        {
            var eventArgs = new TeleportEventArgs { Status = TeleportStatus.Unknown, Type = TeleportType.Unknown };

            if (sender == null || !sender.IsValid)
            {
                FireEvent(eventArgs);
                return;
            }

            if (!TeleportDataByNetworkId.ContainsKey(sender.NetworkId))
            {
                TeleportDataByNetworkId[sender.NetworkId] = eventArgs;
            }

            if (!string.IsNullOrEmpty(args.RecallType))
            {
                ITeleport value;
                if (TypeByString.TryGetValue(args.RecallType, out value))
                {
                    var teleportMethod = value;

                    eventArgs.Status = TeleportStatus.Start;
                    eventArgs.Duration = teleportMethod.GetDuration(args);
                    eventArgs.Type = teleportMethod.Type;
                    eventArgs.Start = Variables.TickCount;
                    eventArgs.IsTarget = teleportMethod.IsTarget(args);
                    eventArgs.Object = sender;

                    TeleportDataByNetworkId[sender.NetworkId] = eventArgs;
                }
                else
                {
                    Console.WriteLine(
                        @"Teleport type {0} with name {1} is not supported yet. Please report it!",
                        args.RecallType,
                        args.RecallName);
                }
            }
            else
            {
                eventArgs = TeleportDataByNetworkId[sender.NetworkId];
                var shorter = Variables.TickCount - eventArgs.Start < eventArgs.Duration - ErrorBuffer;
                eventArgs.Status = shorter ? TeleportStatus.Abort : TeleportStatus.Finish;
            }

            FireEvent(eventArgs);
        }

19 Source : Client.cs
with MIT License
from jlnunez89

public bool KnowsCreatureWithId(uint creatureId)
        {
            lock (this.knownCreaturesLock)
            {
                return this.knownCreatures.ContainsKey(creatureId);
            }
        }

19 Source : ContainerManager.cs
with MIT License
from jlnunez89

private IContainerItem GetContainerAt(uint creatureId, byte atPosition)
        {
            lock (this.internalDictionariesLock)
            {
                if (this.creaturesToContainers.ContainsKey(creatureId) && atPosition < this.creaturesToContainers[creatureId].Length)
                {
                    return this.creaturesToContainers[creatureId][atPosition];
                }
            }

            return null;
        }

19 Source : Client.cs
with MIT License
from jlnunez89

public void RemoveKnownCreature(uint creatureId)
        {
            lock (this.knownCreaturesLock)
            {
                if (this.knownCreatures.ContainsKey(creatureId))
                {
                    this.knownCreatures.Remove(creatureId);

                    this.logger.Verbose($"Removed creatureId {creatureId} to player {this.playerId} known set.");
                }
            }
        }

19 Source : ContainerManager.cs
with MIT License
from jlnunez89

private bool IsContainerOpen(Guid containerUniqueId, uint creatureId, out IEnumerable<byte> openPositions)
        {
            openPositions = null;

            lock (this.internalDictionariesLock)
            {
                if (this.creaturesToContainers.ContainsKey(creatureId))
                {
                    var found = new List<byte>();

                    for (byte i = 0; i < this.creaturesToContainers[creatureId].Length; i++)
                    {
                        if (this.creaturesToContainers[creatureId][i] != null && this.creaturesToContainers[creatureId][i].UniqueId == containerUniqueId)
                        {
                            found.Add(i);
                        }
                    }

                    openPositions = found;
                }
            }

            return openPositions != null;
        }

19 Source : ContainerManager.cs
with MIT License
from jlnunez89

private void CloseContainerInternal(uint forCreatureId, IContainerItem container, byte atPosition)
        {
            lock (this.internalDictionariesLock)
            {
                if (!this.creaturesToContainers.ContainsKey(forCreatureId) ||
                    atPosition >= this.creaturesToContainers[forCreatureId].Length ||
                    container.UniqueId != this.creaturesToContainers[forCreatureId][atPosition].UniqueId)
                {
                    return;
                }

                // For the per-creature map, we need only close the one at the specific position.
                this.creaturesToContainers[forCreatureId][atPosition] = null;

                // For the containers map, we need to get a bit fancy.
                if (this.containersToCreatureIds.ContainsKey(container.UniqueId))
                {
                    if (this.containersToCreatureIds[container.UniqueId][atPosition] == forCreatureId)
                    {
                        this.containersToCreatureIds[container.UniqueId].Remove(atPosition);
                    }

                    // Clean up if this list is now empty.
                    if (this.containersToCreatureIds[container.UniqueId].Count == 0)
                    {
                        this.containersToCreatureIds.Remove(container.UniqueId);

                        // Clean up events because no one else cares about this container.
                        container.ContentAdded -= this.OnContainerContentAdded;
                        container.ContentRemoved -= this.OnContainerContentRemoved;
                        container.ContentUpdated -= this.OnContainerContentUpdated;
                        container.LocationChanged -= this.OnContainerLocationChanged;
                    }
                }

                this.logger.Verbose($"Creature with id {forCreatureId} closed a {container.Type.Name} at position {atPosition}.");
            }
        }

19 Source : ContainerManager.cs
with MIT License
from jlnunez89

private byte OpenContainerInternal(uint forCreatureId, IContainerItem container, byte atPosition)
        {
            lock (this.internalDictionariesLock)
            {
                byte openedAt = ItemConstants.UnsetContainerPosition;

                if (!this.creaturesToContainers.ContainsKey(forCreatureId))
                {
                    this.creaturesToContainers.Add(forCreatureId, new IContainerItem[ItemConstants.MaxContainersPerCreature]);
                }

                if (atPosition >= ItemConstants.MaxContainersPerCreature)
                {
                    // Find any available position.
                    for (byte i = 0; i < ItemConstants.MaxContainersPerCreature; i++)
                    {
                        if (this.creaturesToContainers[forCreatureId][i] != null)
                        {
                            continue;
                        }

                        openedAt = i;
                        this.creaturesToContainers[forCreatureId][i] = container;

                        break;
                    }
                }
                else
                {
                    openedAt = atPosition;
                    this.creaturesToContainers[forCreatureId][atPosition] = container;
                }

                // Now add to the other index per container.
                if (!this.containersToCreatureIds.ContainsKey(container.UniqueId))
                {
                    this.containersToCreatureIds.Add(container.UniqueId, new Dictionary<byte, uint>());

                    // This container is not being tracked at all, let's start tracking it.
                    container.ContentAdded += this.OnContainerContentAdded;
                    container.ContentRemoved += this.OnContainerContentRemoved;
                    container.ContentUpdated += this.OnContainerContentUpdated;
                    container.LocationChanged += this.OnContainerLocationChanged;
                }

                this.containersToCreatureIds[container.UniqueId][openedAt] = forCreatureId;

                this.logger.Verbose($"Creature with id {forCreatureId} opened a {container.Type.Name} at position {openedAt}.");

                return openedAt;
            }
        }

19 Source : ContainerManager.cs
with MIT License
from jlnunez89

public byte FindForCreature(uint creatureId, IContainerItem container)
        {
            if (container == null)
            {
                return ItemConstants.UnsetContainerPosition;
            }

            lock (this.internalDictionariesLock)
            {
                if (this.creaturesToContainers.ContainsKey(creatureId))
                {
                    for (byte i = 0; i < ItemConstants.MaxContainersPerCreature; i++)
                    {
                        if (this.creaturesToContainers[creatureId][i] != null && this.creaturesToContainers[creatureId][i].UniqueId == container.UniqueId)
                        {
                            return i;
                        }
                    }
                }

                return ItemConstants.UnsetContainerPosition;
            }
        }

19 Source : ContainerManager.cs
with MIT License
from jlnunez89

public IEnumerable<IContainerItem> FindAllForCreature(uint creatureId)
        {
            lock (this.internalDictionariesLock)
            {
                if (!this.creaturesToContainers.ContainsKey(creatureId))
                {
                    return Enumerable.Empty<IContainerItem>();
                }

                return this.creaturesToContainers[creatureId].Where(i => i != null).ToList();
            }
        }

19 Source : ContainerManager.cs
with MIT License
from jlnunez89

public IContainerItem FindForCreature(uint creatureId, byte atPosition)
        {
            lock (this.internalDictionariesLock)
            {
                if (this.creaturesToContainers.ContainsKey(creatureId) && atPosition < ItemConstants.MaxContainersPerCreature)
                {
                    return this.creaturesToContainers[creatureId][atPosition];
                }

                return null;
            }
        }

19 Source : Scheduler.cs
with MIT License
from jlnunez89

public void CancelAllFor(uint requestorId, Type specificType = null)
        {
            requestorId.ThrowIfDefaultValue();

            if (specificType == null)
            {
                specificType = typeof(BaseEvent);
            }

            if (!typeof(IEvent).IsreplacedignableFrom(specificType))
            {
                throw new ArgumentException($"Invalid type of event specified. Type must derive from {nameof(IEvent)}.", nameof(specificType));
            }

            lock (this.eventsAvailableLock)
            {
                if (!this.eventsIndexedByRequestor.ContainsKey(requestorId) || this.eventsIndexedByRequestor[requestorId].Count == 0)
                {
                    return;
                }

                foreach (var evt in this.eventsIndexedByRequestor[requestorId])
                {
                    if (specificType.IsreplacedignableFrom(evt.GetType()))
                    {
                        if (this.CancelEvent(evt))
                        {
                            this.Logger.Verbose($"Cancelled {specificType.Name} with id {evt.EventId}.");
                        }
                    }
                }

                this.eventsIndexedByRequestor.Remove(requestorId);
            }
        }

19 Source : Scheduler.cs
with MIT License
from jlnunez89

public void ScheduleEvent(IEvent eventToSchedule, TimeSpan? delayTime = null, bool scheduleAsync = false)
        {
            eventToSchedule.ThrowIfNull(nameof(eventToSchedule));

            if (!(eventToSchedule is BaseEvent castedEvent))
            {
                throw new ArgumentException($"Argument must be of type {nameof(BaseEvent)}.", nameof(eventToSchedule));
            }

            if (delayTime == null || delayTime < TimeSpan.Zero)
            {
                delayTime = TimeSpan.Zero;
            }

            if (scheduleAsync)
            {
                this.eventSchedulingQueue.Enqueue((eventToSchedule, this.CurrentTime, delayTime.Value));

                return;
            }

            lock (this.eventsAvailableLock)
            {
                if (this.priorityQueue.Contains(castedEvent))
                {
                    throw new ArgumentException($"The event is already scheduled.", nameof(eventToSchedule));
                }

                var targetTime = this.CurrentTime + delayTime.Value;
                var milliseconds = this.GetMillisecondsAfterReferenceTime(targetTime);

                if (!castedEvent.HasExpeditionHandler)
                {
                    castedEvent.Expedited += this.HandleEventExpedition;
                }

                if (!castedEvent.HasDelayHandler)
                {
                    castedEvent.Delayed += this.HandleEventDelay;
                }

                if (!castedEvent.HasCancellationHandler)
                {
                    castedEvent.Cancelled += this.HandleEventCancellation;
                }

                this.priorityQueue.Enqueue(castedEvent, milliseconds);

                castedEvent.State = EventState.Scheduled;

                this.Logger.Verbose($"Scheduled {eventToSchedule.GetType().Name} with id {eventToSchedule.EventId}, due in {delayTime.Value} (at {targetTime.ToUnixTimeMilliseconds()}).");

                // check and add event attribution to the requestor
                if (castedEvent.RequestorId > 0)
                {
                    if (!this.eventsIndexedByRequestor.ContainsKey(castedEvent.RequestorId))
                    {
                        this.eventsIndexedByRequestor.Add(castedEvent.RequestorId, new HashSet<BaseEvent>());
                    }

                    this.eventsIndexedByRequestor[castedEvent.RequestorId].Add(castedEvent);
                }

                Monitor.Pulse(this.eventsAvailableLock);
            }
        }

19 Source : Scheduler.cs
with MIT License
from jlnunez89

private void CleanUp(BaseEvent evt, uint eventRequestor = 0)
        {
            this.cancelledEvents.Remove(evt.EventId);

            if (eventRequestor == 0)
            {
                // no requestor, so it shouldn't be on the other dictionary.
                return;
            }

            if (!this.eventsIndexedByRequestor.ContainsKey(eventRequestor))
            {
                return;
            }

            this.eventsIndexedByRequestor[eventRequestor].Remove(evt);

            if (this.eventsIndexedByRequestor[eventRequestor].Count == 0)
            {
                this.eventsIndexedByRequestor.Remove(eventRequestor);
            }
        }

19 Source : Page.cs
with MIT License
from kpali

public static void OverwriteSequenceNumbers (File file,
		                                             long position,
		                                             IDictionary<uint, int> shiftTable)
		{
			if (file == null)
				throw new ArgumentNullException ("file");
			
			if (shiftTable == null)
				throw new ArgumentNullException ("shiftTable");
			
			// Check to see if there are no changes to be made.
			bool done = true;
			foreach (KeyValuePair<uint, int> pair in shiftTable)
				if (pair.Value != 0) {
					done = false;
					break;
				}
			
			// If the file is fine, quit.
			if (done)
				return;
			
			while (position < file.Length - 27) {
				PageHeader header = new PageHeader (file, position);
				int size = (int) (header.Size + header.DataSize);
				
				if (shiftTable.ContainsKey (header.StreamSerialNumber)
					&& shiftTable [header.StreamSerialNumber] != 0) {
					file.Seek (position);
					ByteVector page_data = file.ReadBlock (size);
					
					ByteVector new_data = ByteVector.FromUInt (
						(uint)(header.PageSequenceNumber +
						shiftTable [header.StreamSerialNumber]),
						false);
					
					for (int i = 18; i < 22; i ++)
						page_data [i] = new_data [i - 18];
					for (int i = 22; i < 26; i++)
						page_data [i] = 0;
					
					new_data.Add (ByteVector.FromUInt (
						page_data.Checksum, false));
					file.Seek (position + 18);
					file.WriteBlock (new_data);
				}
				position += size;
			}
		}

19 Source : InMemoryPreKeyStore.cs
with GNU General Public License v3.0
from signal-csharp

public PreKeyRecord LoadPreKey(uint preKeyId)
		{
			try
			{
				if (!store.ContainsKey(preKeyId))
				{
					throw new InvalidKeyIdException("No such prekeyrecord!");
				}
				byte[] record;
				store.TryGetValue(preKeyId, out record);  // get()

				return new PreKeyRecord(record);
			}
			catch (Exception e)
			{
				throw new Exception(e.Message);
			}
		}

19 Source : InMemoryPreKeyStore.cs
with GNU General Public License v3.0
from signal-csharp

public bool ContainsPreKey(uint preKeyId)
		{
			return store.ContainsKey(preKeyId);
		}

19 Source : InMemorySignedPreKeyStore.cs
with GNU General Public License v3.0
from signal-csharp

public SignedPreKeyRecord LoadSignedPreKey(uint signedPreKeyId)
		{
			try
			{
				if (!store.ContainsKey(signedPreKeyId))
				{
					throw new InvalidKeyIdException("No such signedprekeyrecord! " + signedPreKeyId);
				}

				byte[] record;
				store.TryGetValue(signedPreKeyId, out record);  // get()

				return new SignedPreKeyRecord(record);
			}
			catch (Exception e)
			{
				throw new Exception(e.Message);
			}
		}

19 Source : InMemorySignedPreKeyStore.cs
with GNU General Public License v3.0
from signal-csharp

public bool ContainsSignedPreKey(uint signedPreKeyId)
		{
			return store.ContainsKey(signedPreKeyId);
		}

19 Source : JT808_0x8103_Custom_Factory.cs
with MIT License
from SmallChi

public void Register(replacedembly externalreplacedembly)
        {
            var types = externalreplacedembly.GetTypes().Where(w => w.BaseType == typeof(JT808_0x8103_CustomBodyBase)).ToList();
            foreach (var type in types)
            {
                var instance = Activator.CreateInstance(type);
                var paramId = (uint)type.GetProperty(nameof(JT808_0x8103_CustomBodyBase.ParamId)).GetValue(instance);
                if (Map.ContainsKey(paramId))
                {
                    throw new ArgumentException($"{type.FullName} {paramId} An element with the same key already exists.");
                }
                else
                {
                    Map.Add(paramId, instance);
                }
            }
        }

19 Source : JT808_0x8103_Custom_Factory.cs
with MIT License
from SmallChi

public IJT808_0x8103_Custom_Factory SetMap<TJT808_0x8103_CustomBody>() where TJT808_0x8103_CustomBody : JT808_0x8103_CustomBodyBase
        {
            Type type = typeof(TJT808_0x8103_CustomBody);
            var instance = Activator.CreateInstance(type);
            var paramId = (uint)type.GetProperty(nameof(JT808_0x8103_CustomBodyBase.ParamId)).GetValue(instance);
            if (Map.ContainsKey(paramId))
            {
                throw new ArgumentException($"{type.FullName} {paramId} An element with the same key already exists.");
            }
            else
            {
                Map.Add(paramId, instance);
            }
            return this;
        }

19 Source : JT808_0x8103_Factory.cs
with MIT License
from SmallChi

public void Register(replacedembly externalreplacedembly)
        {
            var types = externalreplacedembly.GetTypes().Where(w => w.BaseType == typeof(JT808_0x8103_BodyBase)).ToList();
            foreach (var type in types)
            {
                var instance = Activator.CreateInstance(type);
                uint paramId = 0;
                try
                {
                    paramId = (uint)type.GetProperty(nameof(JT808_0x8103_BodyBase.ParamId)).GetValue(instance);
                }
                catch
                {
                    continue;
                }
                if (Map.ContainsKey(paramId))
                {
                    throw new ArgumentException($"{type.FullName} {paramId} An element with the same key already exists.");
                }
                else
                {
                    Map.Add(paramId, instance);
                }
            }
        }

19 Source : JT808_0x8103_Factory.cs
with MIT License
from SmallChi

public IJT808_0x8103_Factory SetMap<TJT808_0x8103_Body>() where TJT808_0x8103_Body : JT808_0x8103_BodyBase
        {
            Type type = typeof(TJT808_0x8103_Body);
            var instance = Activator.CreateInstance(type);
            var paramId = (uint)type.GetProperty(nameof(JT808_0x8103_BodyBase.ParamId)).GetValue(instance);
            if (Map.ContainsKey(paramId))
            {
                throw new ArgumentException($"{type.FullName} {paramId} An element with the same key already exists.");
            }
            else
            {
                Map.Add(paramId, instance);
            }
            return this;
        }

19 Source : EntityComponents.cs
with MIT License
from spatialos

public void RegisterInterestedComponent(uint componentId, ISpatialOsComponentInternal component)
        {
            if (RegisteredComponents.ContainsKey(componentId))
            {
                throw new InvalidOperationException("Trying to add duplicate componentId to InterestedComponents");
            }

            RegisteredComponents[componentId] = component;
            TriggerInterestedComponentsPotentiallyChanged();
        }

19 Source : EntityComponents.cs
with MIT License
from spatialos

public void DeregisterInterestedComponent(uint componentId)
        {
            if (!RegisteredComponents.ContainsKey(componentId))
            {
                throw new InvalidOperationException("Trying to remove non-existing componentId from InterestedComponents");
            }

            RegisteredComponents.Remove(componentId);
            TriggerInterestedComponentsPotentiallyChanged();
        }

19 Source : Rdc.cs
with MIT License
from tewtal

public bool TryParse<TBlock>(Stream stream, out BlockType block) where TBlock : BlockType, new() {
            block = default;

            var template = new TBlock();
            if (!offsets.ContainsKey(template.Type))
                return false;

            block = template;
            if (blocks.TryGetValue(block.Type, out var cache)) {
                block = (TBlock) cache;
                return true;
            }

            stream.Position = offsets[block.Type];
            block.Parse(stream);
            return true;
        }

19 Source : Rdc.cs
with MIT License
from tewtal

public bool Contains<TBlock>() where TBlock : BlockType, new() {
            var template = new TBlock();
            return offsets.ContainsKey(template.Type);
        }