Example #1
0
    public override bool Activate(GameObject src)
    {
        //int thisType=objInt().GetItemType();
        GameObject triggerObj = ObjectLoader.getGameObjectAt(link);

        if (triggerObj != null)
        {
            if (triggerObj.GetComponent <trap_base>() != null)
            {
                triggerObj.GetComponent <trap_base>().Activate(this, quality, owner, flags);
            }
        }

        //Open/Close trigers may have additional triggers that fire off as well
        if (ObjectLoader.GetItemTypeAt(next) != ObjectInteraction.AN_OPEN_TRIGGER)
        {
            triggerObj = ObjectLoader.getGameObjectAt(next);
            if (triggerObj != null)
            {
                if (triggerObj.GetComponent <trigger_base>() != null)
                {
                    triggerObj.GetComponent <trigger_base>().Activate(this.gameObject);
                }
            }
        }

        PostActivate(src);
        return(true);
    }
Example #2
0
 /// <summary>
 /// The object is used by the player.
 /// </summary>
 /// Checks if the player is already holding something or using something else on this object.
 public virtual bool use()
 {
     //CheckReferences();
     if (UWCharacter.Instance.playerInventory.ObjectInHand == "")
     {
         if ((objInt().isUsable() == true) && (objInt().PickedUp == true))
         {
             BecomeObjectInHand();
             return(true);
         }
         else
         {
             if (objInt().isUsable())
             {                //Hope this does'nt mess up everything!
                 if ((objInt().link != 0) && (objInt().isQuant() == false) && (objInt().enchantment == 0))
                 {            //Not a quantity or an enchanted item.
                     if (ObjectLoader.GetItemTypeAt(objInt().link) == ObjectInteraction.A_USE_TRIGGER)
                     {
                         ObjectLoader.getGameObjectAt(objInt().link).GetComponent <trigger_base>().Activate(this.gameObject);
                     }
                 }
             }
             return(false);
         }
     }
     else
     {
         return(ActivateByObject(UWCharacter.Instance.playerInventory.GetGameObjectInHand()));
     }
 }
 /// <summary>
 /// Populates the container based on what is linked to the objInt
 /// </summary>
 /// <param name="cn">Cn.</param>
 /// <param name="objInt">Object int.</param>
 public static void PopulateContainer(Container cn, ObjectInteraction objInt, ObjectLoader objList)
 {
     //cn.ObjectsAccepted=-1;//For now default to accept all
     cn.Capacity = 40;
     for (int i = 0; i <= cn.MaxCapacity(); i++)
     {                        //init the variables.
         if (cn.items[i] == null)
         {
             cn.items[i] = "";
         }
     }
     if (objInt.link != 0)                           //Container has objects
     {
         ObjectLoaderInfo tmpobj = ObjectLoader.getObjectInfoAt(objInt.link, objList);
         //int count = 0;
         if (ObjectLoader.GetItemTypeAt(objInt.link, objList) != ObjectInteraction.LOCK)
         {
             cn.AddItemToContainer(ObjectLoader.UniqueObjectName(tmpobj));
         }
         while (tmpobj.next != 0)
         {
             tmpobj = ObjectLoader.getObjectInfoAt((int)tmpobj.next, objList);                                        //objList[tmpobj.next];
             cn.AddItemToContainer(ObjectLoader.UniqueObjectName(tmpobj));
         }
     }
 }
Example #4
0
    /// <summary>
    /// For special events when an object is picked up. Eg silver seed or pickup traps
    /// </summary>
    /// If object has a pickup link then the object referenced is activated
    public virtual bool PickupEvent()
    {
        if ((link != 0) && (objInt().isQuantityBln == false) && (enchantment == 0))
        {
            if (ObjectLoader.GetItemTypeAt(link) == ObjectInteraction.A_PICK_UP_TRIGGER)
            {
                ObjectLoader.getGameObjectAt(link).GetComponent <trigger_base>().Activate(this.gameObject);
                link = 0;
            }
        }
        if (CanBeOwned())
        {
            if (((owner & 0x1f)) != 0)
            //if ((owner < 31) && (owner >0))
            {
                if (_RES == GAME_UW1)
                {
                    if ((owner == 13) && (Quest.instance.QuestVariables[32] == 4))
                    {//Do not signal theft if the item belongs to a knight and the player is now a knight
                        owner = 0;
                        return(false);
                    }
                }
                SignalTheft(UWCharacter.Instance.transform.position, owner, 4f);
                owner = 0;
            }
        }

        return(false);
    }
Example #5
0
 /// <summary>
 /// Outputs the look description of the object
 /// </summary>
 /// <returns>The <see cref="System.Boolean"/>.</returns>
 public virtual bool LookAt()
 {
     //CheckReferences();
     UWHUD.instance.MessageScroll.Add(StringController.instance.GetFormattedObjectNameUW(objInt()) + OwnershipString());
     if ((link != 0) && (objInt().isQuantityBln == false) && (enchantment == 0))
     {
         if (ObjectLoader.GetItemTypeAt(link) == ObjectInteraction.A_LOOK_TRIGGER)
         {
             ObjectInteraction obj = ObjectLoader.getObjectIntAt(link);
             if (obj != null)
             {
                 obj.GetComponent <object_base>().Activate(this.gameObject);
             }
         }
     }
     return(true);
 }
 /// <summary>
 /// Gets the lock object interaction.
 /// </summary>
 /// <returns>The lock object int.</returns>
 /// TODO: The portcullis on lvl 7 of the prison tower is linked to a door trap rather than a lock.
 ObjectInteraction getLockObjInt()
 {
     if (objInt().link == 0)
     {
         return(null);
     }
     else
     {
         if (ObjectLoader.GetItemTypeAt(objInt().link) == ObjectInteraction.LOCK)
         {
             return(ObjectLoader.getObjectIntAt(objInt().link));
         }
         else
         {                    //Try and find in the chain of execution.
             return(null);
             //return FindObjectInChain(objInt().link, ObjectInteraction.LOCK);
         }
     }
 }
Example #7
0
 /// <summary>
 /// For special events when an object is picked up. Eg silver seed or pickup traps
 /// </summary>
 /// If object has a pickup link then the object referenced is activated
 public virtual bool PickupEvent()
 {
     if ((objInt().link != 0) && (objInt().isQuant() == false) && (objInt().enchantment == 0))
     {
         if (ObjectLoader.GetItemTypeAt(objInt().link) == ObjectInteraction.A_PICK_UP_TRIGGER)
         {
             ObjectLoader.getGameObjectAt(objInt().link).GetComponent <trigger_base>().Activate(this.gameObject);
             objInt().link = 0;
         }
     }
     if (CanBeOwned())
     {
         if (((objInt().owner & 0x1f)) != 0)
         {
             SignalTheft(UWCharacter.Instance.transform.position, objInt().owner, 4f);
             objInt().owner = 0;
         }
     }
     return(false);
 }
    /// <summary>
    /// Unlocks the door.
    /// </summary>
    public void UnlockDoor(bool PlayerUse)
    {
        ObjectInteraction LockObject = getLockObjInt();

        if (LockObject != null)
        {
            //To unlock unset bit 8 of the flags
            LockObject.flags = (short)(LockObject.flags & 0xE);
            if ((PlayerUse) && (LockObject.next != 0))
            {
                if (ObjectLoader.GetItemTypeAt(LockObject.next) == ObjectInteraction.AN_UNLOCK_TRIGGER)
                {
                    ObjectInteraction triggerObj = ObjectLoader.getObjectIntAt(LockObject.next);
                    if (triggerObj != null)
                    {
                        triggerObj.GetComponent <object_base>().Activate(this.gameObject);
                    }
                }
            }
        }
    }
 /// <summary>
 /// Populates the container based on what is linked to the objInt
 /// </summary>
 /// <param name="cn">Cn.</param>
 /// <param name="objInt">Object int.</param>
 public static void PopulateContainer(Container cn, ObjectInteraction objInt, ObjectLoader objList)
 {
     if (objInt.link != 0)   //Container has objects
     {
         ObjectLoaderInfo tmpobj = ObjectLoader.getObjectInfoAt(objInt.link, objList);
         //int count = 0;
         if (ObjectLoader.GetItemTypeAt(objInt.link, objList) != ObjectInteraction.LOCK)
         {
             cn.AddItemToContainer(tmpobj.instance); //ObjectLoader.UniqueObjectName(tmpobj));
         }
         else
         {
             cn.LockObject = objInt.link;//To preserve the containers lock.
         }
         while (tmpobj.next != 0)
         {
             tmpobj = ObjectLoader.getObjectInfoAt((int)tmpobj.next, objList); //objList[tmpobj.next];
             cn.AddItemToContainer(tmpobj.instance);                           //ObjectLoader.UniqueObjectName(tmpobj));
         }
     }
 }
Example #10
0
 /// <summary>
 /// The object is used by the player.
 /// </summary>
 /// Checks if the player is already holding something or using something else on this object.
 public virtual bool use()
 {
     if (CurrentObjectInHand == null)
     {
         if ((objInt().isUsable == true) && (objInt().PickedUp == true))
         {
             BecomeObjectInHand();
             return(true);
         }
         else
         {
             if (objInt().isUsable)
             {//Hope this does'nt mess up everything!
                 if (
                     (
                         (link != 0) && (objInt().isQuantityBln == false)
                         ||
                         (link == 1) && (objInt().isQuantityBln)
                     )
                     &&
                     (enchantment == 0)
                     )
                 {//Not a quantity or an enchanted item.
                     if (ObjectLoader.GetItemTypeAt(link) == ObjectInteraction.A_USE_TRIGGER)
                     {
                         ObjectLoader.getGameObjectAt(link).GetComponent <trigger_base>().Activate(this.gameObject);
                     }
                 }
             }
             return(false);
         }
     }
     else
     {
         return(ActivateByObject(CurrentObjectInHand));
     }
 }
    /// <summary>
    /// Closes the door.
    /// </summary>
    public void CloseDoor(float DoorTravelTime)
    {
        if (state() == true)
        {
            if (!DoorBusy)
            {
                if (isPortcullis() == false)
                {
                    if (ObjectInteraction.PlaySoundEffects)
                    {
                        objInt().aud.clip = GameWorldController.instance.getMus().SoundEffects[MusicController.SOUND_EFFECT_DOOR_MOVE];
                        objInt().aud.Play();
                    }
                    StartCoroutine(RotateDoor(this.transform, Vector3.up * doordir() * CloseRotation, DoorTravelTime));
                }
                else
                {
                    if (ObjectInteraction.PlaySoundEffects)
                    {
                        objInt().aud.clip = GameWorldController.instance.getMus().SoundEffects[MusicController.SOUND_EFFECT_PORTCULLIS];
                        objInt().aud.Play();
                    }
                    StartCoroutine(RaiseDoor(this.transform, new Vector3(0f, -1.1f, 0f), DoorTravelTime));
                }
                objInt().item_id    -= 8;
                objInt().zpos       -= 24;
                objInt().flags       = 0;
                objInt().enchantment = 0;
                //state=false;

                if (objInt().link != 0)
                {                                                       //If it's link is to something that is not a lock then it is likely to be a trigger
                    if
                    (
                        (ObjectLoader.GetItemTypeAt(objInt().link) != ObjectInteraction.LOCK)
                        &&
                        (ObjectLoader.GetItemTypeAt(objInt().link) != ObjectInteraction.AN_OPEN_TRIGGER)
                    )
                    {
                        trigger_base tb = ObjectLoader.getObjectIntAt(objInt().link).GetComponent <trigger_base>();
                        if (tb != null)
                        {
                            tb.Activate(this.gameObject);
                        }
                    }
                    else
                    {                                                            //The object is linked to a lock. The next of the lock is the use trigger to use here
                        ObjectInteraction LockObj = ObjectLoader.getObjectIntAt(objInt().link);
                        if (LockObj != null)
                        {
                            int next = LockObj.next;

                            while (next != 0)
                            {
                                ObjectInteraction TriggerObject = ObjectLoader.getObjectIntAt(next);

                                if (TriggerObject != null)
                                {
                                    next = 0;
                                    trigger_base tb = TriggerObject.GetComponent <trigger_base>();
                                    if (tb != null)
                                    {
                                        if (tb.objInt().GetItemType() != ObjectInteraction.AN_OPEN_TRIGGER)
                                        {
                                            tb.Activate(this.gameObject);
                                        }
                                        next = tb.objInt().next;
                                    }
                                }
                                else
                                {
                                    next = 0;
                                }
                            }
                        }
                    }
                }
            }
        }
    }
Example #12
0
    public override void ExecuteTrap(object_base src, int triggerX, int triggerY, int State)
    {
        GameObject door = GameWorldController.findDoor(triggerX, triggerY);

        if (door != null)
        {
            DoorControl DC = door.GetComponent <DoorControl>();

            switch (quality)
            {
            case 0:            //Just lock
                //Copy the lock object at the link to use on this door
                if (link != 0)
                {                //link to a lock
                    if (ObjectLoader.GetItemTypeAt(link) == ObjectInteraction.LOCK)
                    {
                        ObjectInteraction lockToCopy = ObjectLoader.getObjectIntAt(link);
                        ObjectLoaderInfo  newobjt    = ObjectLoader.newObject(lockToCopy.item_id, lockToCopy.quality, lockToCopy.owner, lockToCopy.link, 256);
                        newobjt.flags       = lockToCopy.flags;
                        newobjt.doordir     = lockToCopy.doordir;
                        newobjt.invis       = lockToCopy.invis;
                        newobjt.enchantment = lockToCopy.enchantment;
                        newobjt.zpos        = lockToCopy.zpos;
                        newobjt.xpos        = lockToCopy.xpos;
                        newobjt.ypos        = lockToCopy.ypos;
                        newobjt.next        = DC.link;               //To allow proper triggering of traps
                        newobjt.InUseFlag   = 1;
                        GameObject Created = ObjectInteraction.CreateNewObject(CurrentTileMap(), newobjt, CurrentObjectList().objInfo, GameWorldController.instance.InventoryMarker.gameObject, GameWorldController.instance.InventoryMarker.transform.position).gameObject;
                        DC.link = newobjt.index;                        //Point the lock at this new lock
                    }
                }
                else
                {                //unlink the lock and tie the locks next back to the door as it's link
                    ObjectInteraction linkedObj = ObjectLoader.getObjectIntAt(DC.link);
                    if (linkedObj != null)
                    {
                        DC.link = linkedObj.next;
                        linkedObj.objectloaderinfo.InUseFlag = 0;
                        Destroy(linkedObj);
                    }
                }
                break;

            case 1:            //try open
                if (TriggerInstantly)
                {
                    DC.UnlockDoor(false);
                    DC.OpenDoor(0f);
                }
                else
                {
                    DC.UnlockDoor(false);
                    DC.OpenDoor(DoorControl.DefaultDoorTravelTime);
                }

                break;

            case 2:            //try close
                if (TriggerInstantly)
                {
                    DC.CloseDoor(0f);
                    DC.LockDoor();
                }
                else
                {
                    DC.CloseDoor(DoorControl.DefaultDoorTravelTime);
                    DC.LockDoor();
                }

                break;

            case 3:            //try toggle
                //TODO:check if toggle respects unlocked status. (door trap 1001 on level 3)
                if (TriggerInstantly)
                {
                    DC.ToggleDoor(0, false);
                }
                else
                {
                    DC.ToggleDoor(DoorControl.DefaultDoorTravelTime, false);
                }
                break;
            }
        }
        else
        {
            Debug.Log("Door not found!");
        }
    }
Example #13
0
    /// <summary>
    /// Opens the door.
    /// </summary>
    public void OpenDoor(float DoorTravelTime)
    {
        if (state() == false)
        {
            if (!DoorBusy)
            {
                if (isPortcullis() == false)
                {
                    if (ObjectInteraction.PlaySoundEffects)
                    {
                        objInt().aud.clip = MusicController.instance.SoundEffects[MusicController.SOUND_EFFECT_DOOR_MOVE];
                        objInt().aud.Play();
                    }
                    StartCoroutine(RotateDoor(this.transform, Vector3.up * doordirection() * OpenRotation, DoorTravelTime));
                }
                else
                {
                    if (ObjectInteraction.PlaySoundEffects)
                    {
                        objInt().aud.clip = MusicController.instance.SoundEffects[MusicController.SOUND_EFFECT_PORTCULLIS];
                        objInt().aud.Play();
                    }
                    StartCoroutine(RaiseDoor(this.transform, new Vector3(0f, 1.1f, 0f), DoorTravelTime));
                }
                owner       = 0;
                item_id    += 8;
                zpos       += 24;
                enchantment = 1;
                if (isPortcullis())
                {
                    //flags=12;
                    flags = 4;
                    NavMeshObstacle nmo = this.GetComponent <NavMeshObstacle>();
                    if (nmo != null)
                    {
                        nmo.enabled = !state();
                    }
                }
                else
                {
                    //flags=13;
                    flags = 5;
                }

                //state=true;
                if (link != 0)
                {                               //If it's link is to something that is not a lock then it is likely to be a trigger
                    if (
                        (
                            (ObjectLoader.GetItemTypeAt(link) != ObjectInteraction.LOCK)
                            &&
                            (ObjectLoader.GetItemTypeAt(link) != ObjectInteraction.A_CLOSE_TRIGGER)
                        )
                        )
                    {
                        trigger_base tb = ObjectLoader.getObjectIntAt(link).GetComponent <trigger_base>();
                        if (tb != null)
                        {
                            tb.Activate(this.gameObject);
                        }
                    }
                    else
                    {                            //The object is linked to a lock. The next of the lock is the use trigger to use here
                        ObjectInteraction LockObj = ObjectLoader.getObjectIntAt(link);
                        if (LockObj != null)
                        {
                            int next = LockObj.next;

                            while (next != 0)
                            {
                                ObjectInteraction TriggerObject = ObjectLoader.getObjectIntAt(next);
                                if (TriggerObject != null)
                                {
                                    next = 0;
                                    trigger_base tb = TriggerObject.GetComponent <trigger_base>();
                                    if (tb != null)
                                    {
                                        if
                                        (
                                            (tb.objInt().GetItemType() != ObjectInteraction.A_CLOSE_TRIGGER)
                                            &&
                                            (tb.objInt().GetItemType() != ObjectInteraction.AN_UNLOCK_TRIGGER)
                                        )
                                        {
                                            tb.Activate(this.gameObject);
                                        }
                                        next = tb.next;
                                    }
                                }
                                else
                                {
                                    next = 0;
                                }
                            }
                        }
                    }
                }
            }
        }
    }