Exemplo n.º 1
0
        public bool Event_OnOpen(ComponentEvent e)
        {
            // only worry about looking for valid key if its locked
            if (!isLocked)
            {
                return(true);
            }

            EOpen openEvent = (EOpen)e;

            // Check if the asker has a valid key
            Entity opener = openEvent.asker;

            // check if the opener has enything that can unlock this entity, if they do, it is used up
            var requestKey = (EConsumeItem)opener.FireEvent(new EConsumeItem()
            {
                itemName = keyType
            });

            // there is a valid key
            if (requestKey.hasItem)
            {
                isLocked = false;

                var getAskerName = (EGetScreenName)openEvent.asker.FireEvent(new EGetScreenName());
                var getOwnerName = (EGetScreenName)owner.FireEvent(new EGetScreenName());
                var getItemName  = (EGetScreenName)requestKey.consumedItem.FireEvent(new EGetScreenName());
                Engine.LogMessage("%2" + getAskerName.text + "% unlocks %2" + getOwnerName.text + "% with %2" + getItemName.text + "%", openEvent.asker);
            }

            // if its still locked, stop the openable event. Lock should be ranked above any component it is supposed to block
            return(!isLocked);
        }
Exemplo n.º 2
0
        public bool Event_OnOpen(ComponentEvent e)
        {
            EOpen openEvent = (EOpen)e;

            // was already opened previously
            if (opened)
            {
                openEvent.wasOpened = false;
                return(true);
            }

            // and update the graphic
            owner.FireEvent(new ESetGraphic()
            {
                ch = openedCh
            });

            // most important part, set the opened flag in the event so other components can respond to this fact
            opened = true;
            openEvent.wasOpened = true;

            var getAskerName = (EGetScreenName)openEvent.asker.FireEvent(new EGetScreenName());
            var getOwnerName = (EGetScreenName)owner.FireEvent(new EGetScreenName());

            Engine.LogMessage("%2" + getAskerName.text + "% opens %2" + getOwnerName.text + "%", openEvent.asker);
            return(true);
        }