Esempio n. 1
0
        public void AddObject(MapObject obj, bool spawn = false)
        {
            if (Objects.ContainsKey(obj.MapObjectID))
            {
                Log.WriteLine(LogLevel.Warn, "Duplicate object id in sector {0}:{1}", Y, X);
                Objects.Remove(obj.MapObjectID);
            }

            Objects.Add(obj.MapObjectID, obj);
            obj.MapSector = this;

            if (spawn)
            {
                //broadcast mob to map
                //broadcast other players to map (port code from Map.CharacterEnteredMap to here)

                // If Player: Spawn all Mobs and Players in range to Player, and Whole NPC list
                // If Mob: Spawn Mob to all Players in range
                // If NPC: Lolwut

                if (obj is ZoneCharacter)
                {
                    Map.SendCharacterEnteredMap(obj as ZoneCharacter);
                }
                else if (obj is Mob)
                {
                    using (var spawnpacket = obj.Spawn())
                    {
                        Broadcast(spawnpacket);
                    }
                }
            }
        }
Esempio n. 2
0
            public SimObject AddOrGetObject(string name)
            {
                SimObject obj;

                if (Objects.ContainsKey(name))
                {
                    obj = Objects[name];
                }
                else
                {
                    if (name.StartsWith("bot"))
                    {
                        obj = new Bot(this, name);
                        Bots.Add(obj as Bot);
                    }
                    else if (name.StartsWith("output"))
                    {
                        obj = new Output(this, name);
                        Outputs.Add(obj as Output);
                    }
                    else
                    {
                        throw new ArgumentException("unknown name");
                    }
                    Objects[name] = obj;
                }
                return(obj);
            }
Esempio n. 3
0
        public bool Remove(K key)
        {
            lock (this)
            {
                for (var i = 0; i < mAddList.Count; i++)
                {
                    if (EqualityComparer <K> .Default.Equals(mAddList[i].Key, key))
                    {
                        mAddList.RemoveAt(i);
                        return(true);
                    }
                }
                for (var i = 0; i < mRemoveList.Count; i++)
                {
                    if (EqualityComparer <K> .Default.Equals(mRemoveList[i], key))
                    {
                        return(true);
                    }
                }

                if (Objects.ContainsKey(key))
                {
                    mRemoveList.Add(key);
                    return(true);
                }
            }

            return(false);
        }
Esempio n. 4
0
        /// <summary>
        /// Delete the object named key from existence.
        /// </summary>
        public static void DeleteObject(string key)
        {
            if (!Objects.ContainsKey(key))
            {
                return;
            }
            GameObject del = (CollidableObject)Objects[key];

            if (CollidableObjects.Contains(del))
            {
                CollidableObjects.Remove((CollidableObject)del);
            }
            if (UIObjects.Contains(del))
            {
                UIObjects.Remove((UIObject)del);
            }
            if (NonUIObjects.Contains(del))
            {
                NonUIObjects.Remove(del);
            }
            if (Backgrounds.Contains(del))
            {
                Backgrounds.Remove((Background)(del));
            }
            Objects.Remove(key);
        }
Esempio n. 5
0
        public bool Remove(K key, out V value)
        {
            lock (this)
            {
                for (var i = 0; i < mAddList.Count; i++)
                {
                    if (EqualityComparer <K> .Default.Equals(mAddList[i].Key, key))
                    {
                        value = mAddList[i].Value;
                        mAddList.RemoveAt(i);
                        return(true);
                    }
                }

                if (Objects.ContainsKey(key))
                {
                    value = Objects[key];
                    foreach (var item in mRemoveList)
                    {
                        if (EqualityComparer <K> .Default.Equals(item, key))
                        {
                            return(true);
                        }
                    }
                    mRemoveList.Add(key);
                    return(true);
                }
            }
            value = default(V);
            return(false);
        }
Esempio n. 6
0
        public MapsData(MySqlConnection connection)
        {
            using (var command = connection.CreateCommand())
            {
                command.CommandText = "SELECT * FROM `data_maps`";
                command.Prepare();
                using (var reader = command.ExecuteReader())
                {
                    while (reader.Read())
                    {
                        var map = new MapDataModel
                        {
                            Id      = reader.GetUInt16("id"),
                            Name    = reader.GetString("name"),
                            X1      = reader.GetUInt16("x1"),
                            Y1      = reader.GetUInt16("y1"),
                            X2      = reader.GetUInt16("x2"),
                            Y2      = reader.GetUInt16("y2"),
                            Unk1    = reader.GetUInt16("unk1"),
                            Unk2    = reader.GetUInt16("unk2"),
                            Unk3    = reader.GetUInt16("unk3"),
                            Unk4    = reader.GetUInt16("unk4"),
                            Regions = new Dictionary <ushort, RegionDataModel>()
                        };

                        Objects.Add(map.Id, map);
                    }
                }
            }

            using (var command = connection.CreateCommand())
            {
                command.CommandText = "SELECT * FROM `data_map_regions`";
                command.Prepare();
                using (var reader = command.ExecuteReader())
                {
                    while (reader.Read())
                    {
                        var mapId = reader.GetUInt16("map_id");
                        if (!Objects.ContainsKey(mapId))
                        {
                            continue;
                        }

                        var id     = reader.GetUInt16("id");
                        var region = new RegionDataModel
                        {
                            TpX      = reader.GetUInt32("x"),
                            TpY      = reader.GetUInt32("y"),
                            Location = reader.GetUInt16("location"),
                            TpLevel  = (TpLevel)reader.GetUInt16("tp_level"),
                            Unk      = reader.GetUInt16("unk1"),
                            Name     = reader.GetString("region_name")
                        };
                        Objects[mapId].Regions.Add(id, region);
                    }
                }
            }
        }
Esempio n. 7
0
        private void Save <T>(Stream stream, ISheet sheet, bool overwrite)
        {
            var sheetName = sheet.SheetName;
            var objects   = Objects.ContainsKey(sheetName) ? Objects[sheetName] : new Dictionary <int, object>();

            Put(sheet, objects.Values.OfType <T>(), overwrite);
            Workbook.Write(stream);
        }
Esempio n. 8
0
 private Dictionary <int, object> Get(ulong owner)
 {
     if (!Objects.ContainsKey(owner))
     {
         Objects[owner] = new Dictionary <int, object>();
     }
     return(Objects[owner]);
 }
Esempio n. 9
0
 public T[] GetObjects <T>() where T : ToffeeObject
 {
     if (Objects.ContainsKey(typeof(T)))
     {
         return((T[])Objects[typeof(T)].ToArray());
     }
     return(new T[0]);
 }
Esempio n. 10
0
        /// <summary>
        /// Gibt alle verwalteten Singletons eines Typs zurück
        /// </summary>
        /// <typeparam name="T">Objekttyp</typeparam>
        /// <returns>Liste aller Singletons des angegeben Typs</returns>
        public static List <T> All <T>()
        {
            if (!Objects.ContainsKey(typeof(T)))
            {
                return(new List <T>());
            }

            return(Objects[typeof(T)].Values.Cast <T>().ToList());
        }
Esempio n. 11
0
        /// <summary>
        /// Prüft, ob ein Singleton von einem bestimmten Typ enthaltne ist
        /// </summary>
        /// <typeparam name="T">Objekttyp</typeparam>
        /// <param name="key">Schlüssel (otional)</param>
        /// <returns>Objekt</returns>
        public static bool Contains <T>(string key)
        {
            if (!Objects.ContainsKey(typeof(T)))
            {
                return(false);
            }

            return(Objects[typeof(T)].ContainsKey(key));
        }
Esempio n. 12
0
        /// <summary>
        /// Gibt die Anzahl der verwalteten Singletons eines Typs zurück
        /// </summary>
        /// <typeparam name="T">Objekttyp</typeparam>
        /// <returns>verwaltete Singletons</returns>
        public static int Count <T>()
        {
            if (!Objects.ContainsKey(typeof(T)))
            {
                return(0);
            }

            return(Objects[typeof(T)].Keys.Count);
        }
Esempio n. 13
0
 public ObjectInfo GetObject(string unpackedHash)
 {
     if (!(!string.IsNullOrWhiteSpace(unpackedHash)))
     {
         throw new ArgumentNullException("!string.IsNullOrWhiteSpace(unpackedHash)");
     }
     lock (Objects) {
         return(Objects.ContainsKey(unpackedHash) ? new ObjectInfo(unpackedHash, Objects[unpackedHash]) : null);
     }
 }
Esempio n. 14
0
        public bool Contains(string strName)
        {
            if (strName == null)
            {
                throw new ArgumentNullException("strName", "A valid non-null string is required..");
            }

            bool blnContains = Objects.ContainsKey(strName);

            return(blnContains);
        }
Esempio n. 15
0
        public MobData(string path)
        {
            try
            {
                JsonUtil.DeserializeFile(path + "MobPos.bin.json", out List <MobPosJson> mobPosData);

                foreach (var dir in Directory.GetDirectories(path))
                {
                    var collection = new MobCollection();
                    foreach (var file in Directory.GetFiles(dir, "*.json"))
                    {
                        var fileName = Path.GetFileNameWithoutExtension(file);
                        switch (fileName)
                        {
                        case "MobData":
                            JsonUtil.DeserializeFile(file, out MobDataJson dialog);
                            collection.MobData = dialog;
                            break;
                        }
                    }

                    if (collection.MobData?.MobId > 0)
                    {
                        Objects.Add((ushort)collection.MobData.MobId, collection);
                    }
                }

                foreach (var mobPos in mobPosData)
                {
                    if (Objects.ContainsKey(mobPos.MobId))
                    {
                        Objects[mobPos.MobId].MobPos = mobPos;
                    }
                }

                var keys = new List <ushort>();
                foreach (var(key, value) in Objects)
                {
                    if (value.MobPos == null || value.MobData == null)
                    {
                        keys.Add(key);
                    }
                }

                foreach (var key in keys)
                {
                    Objects.Remove(key);
                }
            }
            catch (Exception)
            {
                throw new FileNotFoundException("MOB data is missing.");
            }
        }
Esempio n. 16
0
    private void ProcessUpdateMessage(UpdateMessage msg, uint connNodeId, Connection conn)
    {
        // Ignore out-of-order updates
        if (LatestTickReceived.ContainsKey(connNodeId) &&
            LatestTickReceived[connNodeId] > msg.Tick)
        {
            return;
        }
        LatestTickReceived[connNodeId] = msg.Tick;

        foreach (ObjectUpdate update in msg.ObjectUpdates)
        {
            var id = update.ObjectId;
            if (!Objects.ContainsKey(id))
            {
                Logger.Log("Node", $"Ignoring update for non-registered ObjectId={id}");
                continue;
            }
            if (Objects[id].OriginalNodeId != connNodeId && connNodeId != ServerNodeId)
            {
                Logger.Error("Node", $"Blocked invalid update for ObjectId={id}");
                continue;   // Original object cannot be updated by nodes other than OriginalNodeId or the server (NodeId=0)
            }

            //Logger.Log("Node", $"ObjectId={id} updated");

            // fields
            foreach (var field in update.Fields)
            {
                //Logger.Log("Node", $"object {id} Field {field.Name} = {field.Value}");

                /*
                 * if (field.Name == "tags" && field.Value is Sequence seq)
                 * {
                 *  foreach (var elem in seq.Elements)
                 *  {
                 *      if (elem is Primitive<string> tag)
                 *          Logger.Debug("Node", $"{connNodeId} {id} {tag.Value}");
                 *  }
                 * }
                 */
                //Objects[id].Fields[field.Name] = field.Value;
                Objects[id].SetField(field.Name, field.Value);
            }
        }

        // Notify the sender that this node have processed the message
        conn.SendMessage <ISyncMessage>(
            Connection.ChannelType.Sync,
            new AckMessage {
            AcknowledgedTick = msg.Tick
        }
            );
    }
Esempio n. 17
0
 /// <summary>
 /// Get a GameObject named name from the Objects dictionary
 /// </summary>
 /// <param name="name"></param>
 /// <returns></returns>
 public static GameObject Get(string name)
 {
     if (Objects.ContainsKey(name))
     {
         return(Objects[name]);
     }
     else
     {
         return(null);
     }
 }
Esempio n. 18
0
 public bool RemoveObject(string unpackedHash)
 {
     lock (Objects) {
         if (Objects.ContainsKey(unpackedHash))
         {
             Objects.Remove(unpackedHash);
             return(true);
         }
     }
     return(false);
 }
Esempio n. 19
0
 public string GetValue(string key)
 {
     if (Objects.ContainsKey(key))
     {
         string value;
         Objects.TryGetValue(key, out value);
         return(value);
     }
     else
     {
         return(null);
     }
 }
Esempio n. 20
0
 /// <summary>
 /// Versucht ein Singleton für einen Objekttyp unter Anwendung des Standardkonstruktors zu erstellen
 /// </summary>
 /// <typeparam name="T">Objekttyp</typeparam>
 /// <param name="key">Schlüssel (optional)</param>
 public static void Register <T>(string key)
 {
     if (Objects.ContainsKey(typeof(T)))
     {
         IoC.Objects[typeof(T)][key] = Activator.CreateInstance <T>();
     }
     else
     {
         Dictionary <string, object> storage = new Dictionary <string, object>();
         storage[key]           = Activator.CreateInstance <T>();
         IoC.Objects[typeof(T)] = storage;
     }
 }
Esempio n. 21
0
    public WorldObjectData GetObject(int x, int z)
    {
        if (Objects == null)
        {
            return(null);
        }
        int hash = WorldObject.ObjectPositionHash(x, z);

        if (Objects.ContainsKey(hash))
        {
            return(Objects[hash]);
        }
        return(null);
    }
Esempio n. 22
0
        //Чтение списка сигналов
        private void ReadSignals()
        {
            AddEvent("Чтение списка сигналов");
            SignalsReceivers.Clear();
            if (ThreadCalc.IsReadSources)
            {
                SignalsSources.Clear();
                _signalsCodes.Clear();
            }

            using (var rec = new ReaderAdo(File, "SELECT * FROM SignalsInUse"))
            {
                int i = 0, n = rec.RecordCount("SELECT Count(*) FROM SignalsInUse");
                while (rec.Read())
                {
                    var sig = new CalcUnit(rec, this, true);
                    if (IsError)
                    {
                        return;
                    }
                    if (ThreadCalc.IsReadSources && !sig.SourceName.IsEmpty())
                    {
                        _signalsCodes.Add(sig.FullCode, sig.DataType);
                        SignalsSources.Add(sig.FullCode, sig);
                        if (sig.CodeObject != null)//null для сигналов ручного ввода
                        {
                            if (!Objects.ContainsKey(sig.CodeObject))
                            {
                                Objects.Add(sig.CodeObject, new CalcObject(sig.CodeObject));
                            }
                            var ob = Objects[sig.CodeObject];
                            ob.Signals.Add(sig.CodeSignal, sig);
                            sig.Object = ob;
                            if (sig.Default)
                            {
                                ob.DefaultSignal = sig;
                            }
                        }
                    }
                    if (ThreadCalc.IsWriteReceivers && !sig.ReceiverName.IsEmpty())
                    {
                        SignalsReceivers.Add(sig.FullCode, sig);
                    }
                    if (++i % 50 == 0)
                    {
                        Procent = i * 100.0 / n;
                    }
                }
            }
        }
Esempio n. 23
0
        /// <summary>
        /// Creates an instance of object.
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="key"></param>
        /// <param name="constructorParameters"></param>
        /// <returns></returns>
        public T CreateInstance <T>(string key, params object[] constructorParameters) where T : class
        {
            T o = (T)Activator.CreateInstance(typeof(T), constructorParameters);

            lock (_lock)
            {
                if (!Objects.ContainsKey(key))
                {
                    Objects.Add(key, o);
                }

                return(o);
            }
        }
Esempio n. 24
0
        public object GetObject(string key)
        {
            if (!Objects.ContainsKey(key))
            {
                return(null);
            }
            var data = Objects[key];

            if (data == null)
            {
                return(null);
            }
            return(DeserializeObject(data));
        }
Esempio n. 25
0
    public void SetValue <T>(string key, T value, bool save = true)
    {
        if (Objects.ContainsKey(key))
        {
            Objects.Remove(key);
        }

        Objects.Add(key, value.ToString());

        if (save)
        {
            Save();
        }
    }
Esempio n. 26
0
        public void Remove(string strName)
        {
            if (strName == null)
            {
                throw new ArgumentNullException("strName", "A valid non-null string is required..");
            }

            if (Objects.ContainsKey(strName) == true)
            {
                List <SerializedObject> objIndexedObjects = Objects[strName];
                objIndexedObjects.Clear();
                Objects.Remove(strName);
            }
        }
Esempio n. 27
0
 public bool Insert(ILocatableObject obj)
 {
     if (obj == null)
     {
         return(false);
     }
     if (Objects.ContainsKey(obj.UID))
     {
         return(false);
     }
     obj.Map = this;
     Objects.TryAdd(obj.UID, obj);
     return(true);
 }
Esempio n. 28
0
        public MakeItemsData(MySqlConnection connection)
        {
            using (var command = connection.CreateCommand())
            {
                command.CommandText = "SELECT * FROM `data_make_items`";
                command.Prepare();
                using (var reader = command.ExecuteReader())
                {
                    while (reader.Read())
                    {
                        var makeItem = new MakeItemDataModel
                        {
                            ResultItemId    = reader.GetUInt16("id"),
                            ResultSupItemId = reader.GetUInt16("result_sup_item_id"),
                            Level           = reader.GetByte("level"),
                            Price           = reader.GetUInt64("price"),
                            Quantity        = reader.GetUInt16("quantity"),
                            Rate            = reader.GetUInt32("rate"),
                            RateSup         = reader.GetUInt32("rate_sup"),
                            RateDouble      = reader.GetUInt32("rate_double"),
                            Ingredients     = new List <MakeItemIngredients>()
                        };
                        Objects.Add(makeItem.ResultItemId, makeItem);
                    }
                }
            }

            using (var command = connection.CreateCommand())
            {
                command.CommandText = "SELECT * FROM `data_make_item_ingredients`";
                command.Prepare();
                using (var reader = command.ExecuteReader())
                {
                    while (reader.Read())
                    {
                        var id = reader.GetUInt16("id");
                        var makeItemIngredients = new MakeItemIngredients
                        {
                            ItemId   = reader.GetUInt16("item_id"),
                            Quantity = reader.GetByte("quantity")
                        };
                        if (Objects.ContainsKey(id))
                        {
                            Objects[id].Ingredients.Add(makeItemIngredients);
                        }
                    }
                }
            }
        }
Esempio n. 29
0
    protected void HandleAudioDataMessage(AudioDataMessage msg)
    {
        if (!Objects.ContainsKey(msg.ObjectId))
        {
            return;                                      // Something is wrong
        }
        SyncObject obj = Objects[msg.ObjectId];

        if (obj.OriginalNodeId == NodeId)
        {
            return;
        }

        obj.HandleAudio(msg.OpusData);
    }
Esempio n. 30
0
 public Model.Object this[int objectId]
 {
     get
     {
         lock (this)
         {
             if (objectId != 0 && Objects.ContainsKey(objectId))
             {
                 return(Objects[objectId]);
             }
             else
             {
                 return(null);
             }
         }
     }
 }