コード例 #1
0
ファイル: Tile.cs プロジェクト: Herhangi/HerhangiOT
        public sealed override void PostAddNotification(Thing thing, Thing oldParent, int index, CylinderLinks link = CylinderLinks.Owner)
        {
            HashSet <Creature> list = new HashSet <Creature>();

            Map.GetSpectators(ref list, GetPosition(), true, true);
            foreach (Player spectator in list)
            {
                spectator.PostAddNotification(thing, oldParent, index, CylinderLinks.Near);
            }

            //add a reference to this item, it may be deleted after being added (mailbox for example)
            Creature creature = thing as Creature;
            Item     item;

            if (creature != null)
            {
                creature.IncrementReferenceCounter();
                item = null;
            }
            else
            {
                item = thing as Item;
                if (item != null)
                {
                    item.IncrementReferenceCounter();
                }
            }

            if (link == CylinderLinks.Owner)
            {
                if (Flags.HasFlag(TileFlags.Teleport))
                {
                    Teleport teleport = GetTeleportItem();
                    if (teleport != null)
                    {
                        teleport.AddThing(thing);
                    }
                }
                else if (Flags.HasFlag(TileFlags.TrashHolder))
                {
                    TrashHolder trashholder = GetTrashHolder();
                    if (trashholder != null)
                    {
                        trashholder.AddThing(thing);
                    }
                }
                else if (Flags.HasFlag(TileFlags.MailBox))
                {
                    Mailbox mailbox = GetMailbox();
                    if (mailbox != null)
                    {
                        mailbox.AddThing(thing);
                    }
                }

                //calling movement scripts TODO: Scripting
                //if (creature != null)
                //{
                //    g_moveEvents->onCreatureMove(creature, this, oldParent ? oldParent->getPosition() : getPosition(), MOVE_EVENT_STEP_IN);
                //}
                //else if (item)
                //{
                //    g_moveEvents->onItemMove(item, this, true);
                //}
            }

            //release the reference to this item onces we are finished
            if (creature != null)
            {
                Game.ReleaseCreature(creature);
            }
            else if (item != null)
            {
                Game.ReleaseItem(item);
            }
        }
コード例 #2
0
        public static Item CreateItem(ushort itemId, byte count = 0)
        {
            Item newItem = null;

            ItemTemplate it = ItemManager.Templates[itemId];

            if (it.Group == ItemGroups.Deprecated)
            {
                return(null);
            }

            if (it.IsStackable && count == 0)
            {
                count = 1;
            }

            if (it.Id != 0)
            {
                if (it.Type == ItemTypes.Depot)
                {
                    newItem = new DepotLocker(itemId);
                }
                else if (it.Group.HasFlag(ItemGroups.Container))
                {
                    newItem = new Container(itemId);
                }
                else if (it.Type == ItemTypes.Teleport)
                {
                    newItem = new Teleport(itemId);
                }
                else if (it.Type == ItemTypes.MagicField)
                {
                    newItem = new MagicField(itemId);
                }
                else if (it.Type == ItemTypes.Door)
                {
                    newItem = new Door(itemId);
                }
                else if (it.Type == ItemTypes.TrashHolder)
                {
                    newItem = new TrashHolder(itemId);
                }
                else if (it.Type == ItemTypes.Mailbox)
                {
                    newItem = new Mailbox(itemId);
                }
                else if (it.Type == ItemTypes.Bed)
                {
                    newItem = new BedItem(itemId);
                }
                else if (it.Id >= 2210 && it.Id <= 2212)
                {
                    newItem = new Item((ushort)(itemId - 3), count);
                }
                else if (it.Id == 2215 || it.Id == 2216)
                {
                    newItem = new Item((ushort)(itemId - 2), count);
                }
                else if (it.Id >= 2202 && it.Id <= 2206)
                {
                    newItem = new Item((ushort)(itemId - 37), count);
                }
                else if (it.Id == 2640)
                {
                    newItem = new Item(6132, count);
                }
                else if (it.Id == 6301)
                {
                    newItem = new Item(6300, count);
                }
                else if (it.Id == 18528)
                {
                    newItem = new Item(18408, count);
                }
                else
                {
                    newItem = new Item(itemId, count);
                }

                newItem.IncrementReferenceCounter();
            }

            return(newItem);
        }