Пример #1
0
        public TrinityItem ItemByAnnId(int annId)
        {
            TrinityItem item;

            if (_inventory.TryGetValue(annId, out item))
            {
                return(item);
            }

            short index;

            if (!_annToAcdIndex.TryGetValue(annId, out index))
            {
                return(null);
            }

            var acd = ZetaDia.Storage.ActorCommonData[index];

            if (acd != null && acd.IsValid)
            {
                var bones = ActorFactory.GetActorSeed(acd);
                return(ActorFactory.CreateActor <TrinityItem>(bones));
            }
            return(null);
        }
Пример #2
0
        /// <summary>
        /// Updates the acds that are inventory items, stash/equipped/backpack etc.
        /// </summary>
        private void UpdateInventory()
        {
            var newInventory = new ConcurrentDictionary <int, TrinityItem>();

            foreach (var acd in ZetaDia.Actors.ACDList)
            {
                var type = acd.ActorType;
                if (type != ActorType.Item)
                {
                    continue;
                }

                var inventorySlot = acd.GetInventorySlot();
                if (inventorySlot == InventorySlot.Merchant)
                {
                    continue;
                }

                var annId = acd.AnnId;
                if (annId == -1)
                {
                    continue;
                }

                if (!acd.IsValid || acd.IsDisposed)
                {
                    continue;
                }

                if (!_inventory.ContainsKey(annId))
                {
                    var newObj = ActorFactory.CreateItem(acd);
                    newObj.OnCreated();
                    newInventory.TryAdd(annId, newObj);
                }
                else
                {
                    var oldObj = _inventory[annId];
                    if (!UpdateInventoryItem(oldObj, acd))
                    {
                        continue;
                    }

                    newInventory.TryAdd(annId, oldObj);
                }
            }

            _inventory = newInventory;
        }
Пример #3
0
        private TrinityActor TryAddRActor(int id, DiaObject rActor, out bool result)
        {
            _timer.Restart();
            var actor  = ActorFactory.CreateActor(rActor);
            var player = actor as TrinityPlayer;

            if (player != null && player.IsMe)
            {
                Me = player;
            }
            _acdToRActorIndex[actor.AcdId] = actor.RActorId;
            _timer.Stop();
            actor.CreateTime = _timer.Elapsed.TotalMilliseconds;
            actor.Created    = DateTime.UtcNow;
            result           = true;
            return(actor);
        }
Пример #4
0
        /// <summary>
        /// Get new RActors from Memory; update ones we already know about.
        /// * Some RActors like client effects and environment do not have an associated acd.
        /// </summary>
        private void UpdateRActors()
        {
            var newRactors         = new Dictionary <int, TrinityActor>();
            var newAcdToRactorDict = new Dictionary <int, int>();

            foreach (var zetaActor in ZetaDia.Actors.RActorList)
            {
                if (_rActors.ContainsKey(zetaActor.RActorId))
                {
                    var existingTrinityActor = _rActors[zetaActor.RActorId];
                    if (!newRactors.ContainsKey(zetaActor.RActorId))
                    {
                        newRactors.Add(zetaActor.RActorId, existingTrinityActor);
                    }
                    if (existingTrinityActor.AcdId > 0)
                    {
                        newAcdToRactorDict.Add(existingTrinityActor.AcdId, existingTrinityActor.RActorId);
                    }
                    existingTrinityActor.OnUpdated();
                }
                else
                {
                    var newTrinityActor = ActorFactory.CreateActor(zetaActor);
                    if (!newRactors.ContainsKey(zetaActor.RActorId))
                    {
                        newRactors.Add(newTrinityActor.RActorId, newTrinityActor);
                    }
                    if (newTrinityActor.AcdId > 0)
                    {
                        newAcdToRactorDict.Add(newTrinityActor.AcdId, newTrinityActor.RActorId);
                    }
                    newTrinityActor.OnCreated();
                    if (newTrinityActor.IsMe)
                    {
                        Me = newTrinityActor as TrinityPlayer;
                    }
                }
            }

            _rActors          = newRactors;
            _acdToRActorIndex = newAcdToRactorDict;
        }
Пример #5
0
        /// <summary>
        /// Get new RActors from Memory; update ones we already know about.
        /// * Some RActors like client effects and environment do not have an associated acd.
        /// </summary>
        private void UpdateRActors()
        {
            var newRactors         = new Dictionary <int, TrinityActor>();
            var newAcdToRactorDict = new Dictionary <int, int>();

            foreach (var zetaActor in ZetaDia.Actors.RActorList)
            {
                var rid = zetaActor.RActorId;
                if (RActors.TryGetValue(rid, out var actor))
                {
                    actor.OnUpdated();
                }
                else
                {
                    actor = ActorFactory.CreateActor(zetaActor);
                    actor.OnCreated();
                }

                if (!newRactors.ContainsKey(rid))
                {
                    newRactors.Add(rid, actor);
                }

                if (actor.AcdId > 0 &&
                    !newAcdToRactorDict.ContainsKey(actor.AcdId))
                {
                    newAcdToRactorDict.Add(actor.AcdId, rid);
                }

                if (actor.IsMe)
                {
                    Me = actor as TrinityPlayer;
                }
            }

            Interlocked.Exchange(ref RActors, newRactors);
            Interlocked.Exchange(ref _acdToRActorIndex, newAcdToRactorDict);
        }
Пример #6
0
        /// <summary>
        /// Updates the acds that are inventory items, stash/equipped/backpack etc.
        /// </summary>
        private void UpdateInventory()
        {
            var untouchedIds = new List <int>(_inventory.Keys);

            foreach (var newItem in _commonData)
            {
                var commonData = newItem.Value;
                var type       = commonData.ActorType;
                if (type != ActorType.Item)
                {
                    continue;
                }

                var inventorySlot = commonData.GetInventorySlot();
                if (inventorySlot == InventorySlot.Merchant)
                {
                    continue;
                }

                var annId = commonData.AnnId;
                if (annId == -1)
                {
                    continue;
                }

                if (!commonData.IsValid || commonData.IsDisposed)
                {
                    continue;
                }

                if (!_inventory.ContainsKey(annId))
                {
                    var newObj = ActorFactory.CreateActor <TrinityItem>(commonData);
                    _inventory.TryAdd(annId, newObj);
                }
                else
                {
                    var oldObj = _inventory[annId];
                    if (!UpdateInventoryItem(oldObj, commonData))
                    {
                        continue;
                    }
                }

                //_inventory.AddOrUpdate(annId,
                //    id => AddInventoryItem(id, commonData),
                //    (id, existingItem) => UpdateInventoryItem(id, existingItem, commonData));

                untouchedIds.Remove(annId);
            }

            foreach (var key in untouchedIds)
            {
                TrinityItem item;
                if (_inventory.TryRemove(key, out item) && item != null)
                {
                    //item.RActor?.UpdatePointer(IntPtr.Zero);
                    //item.CommonData?.UpdatePointer(IntPtr.Zero);
                    //item.ActorInfo?.UpdatePointer(IntPtr.Zero);
                    //item.MonsterInfo?.UpdatePointer(IntPtr.Zero);
                    item.OnDestroyed();
                }
            }
        }