public static void SetItemsParent(Container cn, Transform Parent)
 {
     for (short i = 0; i <= cn.MaxCapacity(); i++)
     {
         string ItemName = cn.GetItemAt(i);
         if (ItemName != "")
         {
             GameObject item = cn.GetGameObjectAt(i);                 //GameObject.Find (cn.GetItemAt(i));
             if (item != null)
             {
                 item.transform.parent = Parent;
                 if (Parent == GameWorldController.instance.LevelMarker())
                 {
                     GameWorldController.MoveToWorld(item);
                 }
                 else
                 {
                     GameWorldController.MoveToInventory(item);
                 }
                 if (item.GetComponent <Container>() != null)
                 {
                     Container.SetItemsParent(item.GetComponent <Container>(), Parent);
                 }
             }
         }
     }
 }
Example #2
0
    private void LeftOvers()
    {
        int LeftOverToCreate = -1;

        switch (item_id)
        {
        case 176:
        case 177:    //meat
            LeftOverToCreate = 197; break;

        case 186:    //honeycomb
            LeftOverToCreate = 210; break;

        case 187:
        case 188:
        case 189:    //bottles.
            LeftOverToCreate = 317; break;
        }

        if (LeftOverToCreate != -1)
        {
            ObjectLoaderInfo newobjt = ObjectLoader.newObject(LeftOverToCreate, 40, 0, 0, 256);
            newobjt.InUseFlag = 1;
            ObjectInteraction created = ObjectInteraction.CreateNewObject(CurrentTileMap(), newobjt, CurrentObjectList().objInfo, GameWorldController.instance.DynamicObjectMarker().gameObject, GameWorldController.instance.InventoryMarker.transform.position);
            GameWorldController.MoveToWorld(created.gameObject);
            CurrentObjectInHand = created;
            //UWHUD.instance.CursorIcon = created.GetInventoryDisplay().texture;
            UWCharacter.InteractionMode = UWCharacter.InteractionModePickup;
        }
    }
Example #3
0
    public override void MoveToWorldEvent()
    {
        if (enchantment == 0)
        {        //Object links to a spell.
            if (linkedspell != null)
            {
                bool match = false;
                //Try and find a spell already in the level that matches the characteristics of this spell
                ObjectLoaderInfo[] objList = CurrentObjectList().objInfo;
                for (int i = 0; i <= objList.GetUpperBound(0); i++)
                {
                    if (objList[i].GetItemType() == ObjectInteraction.SPELL)
                    {
                        if (objList[i].instance != null)
                        {
                            if (objList[i].link == linkedspell.link)
                            {
                                Destroy(linkedspell.gameObject);
                                linkedspell = objList[i].instance.GetComponent <a_spell>();
                                link        = i;
                                match       = true;
                                break;
                            }
                        }
                    }
                }

                if (!match)
                {
                    //linkedspell.gameObject.transform.parent=GameWorldController.instance.DynamicObjectMarker();
                    GameWorldController.MoveToWorld(linkedspell.gameObject);
                }
            }
        }
    }
    //To support potions that are linked to spells/damage traps
    public override void MoveToWorldEvent()
    {
        if ((isquant == 0) && (link < 256) && (link > 0))
        {//Object links to a spell.
            if (linked != null)
            {
                bool match = false;
                //Try and find a spell already in the level that matches the characteristics of this spell
                ObjectLoaderInfo[] objList = CurrentObjectList().objInfo;
                for (int i = 0; i <= objList.GetUpperBound(0); i++)
                {
                    if (objList[i].GetItemType() == linked.GetItemType())//Find a matching item type
                    {
                        if (objList[i].instance != null)
                        {
                            if ((objList[i].link == linked.link) && (objList[i].owner == linked.owner) && (objList[i].quality == linked.quality))
                            {//Point to that instance if found instead.
                                Destroy(linked.gameObject);
                                linked = objList[i].instance;
                                link   = i;
                                match  = true;
                                break;
                            }
                        }
                    }
                }

                if (!match)
                {
                    //linkedspell.gameObject.transform.parent=GameWorldController.instance.DynamicObjectMarker();
                    GameWorldController.MoveToWorld(linked.gameObject);
                }
            }
        }
    }
Example #5
0
    public override bool use()
    {
        if (UWCharacter.Instance.playerInventory.ObjectInHand == "")
        {
            if ((objInt().item_id == 290) && (objInt().PickedUp == true))
            {
                //I'll test positioning later. For now just place it at the players position
                //Turn it into a sapling.
                objInt().item_id           = 458;
                objInt().WorldDisplayIndex = 458;
                objInt().InvDisplayIndex   = 458;
                AnimationOverlay animo = this.GetComponent <AnimationOverlay>();
                if (animo != null)
                {
                    animo.Stop();
                }
                objInt().UpdateAnimation();                //Update the inventory display
                objInt().SetWorldDisplay(objInt().GetInventoryDisplay());
                UWHUD.instance.MessageScroll.Add(StringController.instance.GetString(1, 12));


                UWHUD.instance.CursorIcon = UWHUD.instance.CursorIconDefault;
                UWCharacter.Instance.ResurrectPosition = UWCharacter.Instance.transform.position;
                UWCharacter.Instance.ResurrectLevel    = (short)(GameWorldController.instance.LevelNo + 1);
                //int tileX= GameWorldController.instance.Tilemap.visitTileX;
                //int tileY= GameWorldController.instance.Tilemap.visitTileY;
                objInt().gameObject.transform.parent = GameWorldController.instance.DynamicObjectMarker();

                objInt().gameObject.transform.position = GameWorldController.instance.currentTileMap().getTileVector(TileMap.visitTileX, TileMap.visitTileY);
                UWCharacter.Instance.playerInventory.RemoveItemFromEquipment(objInt().gameObject.name);
                UWCharacter.Instance.playerInventory.GetCurrentContainer().RemoveItemFromContainer(objInt().gameObject.name);
                UWCharacter.Instance.playerInventory.Refresh();
                objInt().PickedUp = false;
                GameWorldController.MoveToWorld(objInt());
                return(true);
            }
            else
            {
                return(false);
            }
        }
        else
        {
            return(ActivateByObject(UWCharacter.Instance.playerInventory.GetGameObjectInHand()));
        }
    }
Example #6
0
    /// <summary>
    /// Sends the avatar into the ethereal void.
    /// </summary>
    /// Spins the avatar and the slasher (specific object name) towards a newly spawned moongate.
    IEnumerator SuckItAvatar()
    {
        //Spawn a moon gate at the center of the lava
        ObjectInteraction slasher    = GameWorldController.instance.CurrentObjectList().objInfo[129].instance;             //GameObject.Find("slasher_of_veils_32_33_07_0129");//Assumes slasher will be at this index.
        Vector3           slasherPos = Vector3.zero;

        if (slasher != null)
        {
            slasherPos = slasher.transform.position;
        }
        ObjectLoaderInfo newobjt = ObjectLoader.newObject(346, 0, 0, 0, 256);
        GameObject       myObj   = ObjectInteraction.CreateNewObject(GameWorldController.instance.currentTileMap(),
                                                                     newobjt,
                                                                     GameWorldController.instance.CurrentObjectList().objInfo,
                                                                     GameWorldController.instance.DynamicObjectMarker().gameObject,
                                                                     GameWorldController.instance.InventoryMarker.transform.position).gameObject;

        GameWorldController.MoveToWorld(myObj.GetComponent <ObjectInteraction>());
        myObj.transform.localPosition = this.transform.position + new Vector3(0.0f, 0.5f, 0.0f);

        //GameObject myInstance = Resources.Load("Models/MoonGate") as GameObject;
        //GameObject newObj = (GameObject)GameObject.Instantiate(myInstance);
        //newObj.transform.parent=GameWorldController.instance.DynamicObjectMarker();
        //	GameWorldController.MoveToWorld(newObj);
        //newObj.transform.localPosition=this.transform.position+new Vector3(0.0f,0.5f,0.0f);
        Quaternion playerRot = UWCharacter.Instance.transform.rotation;
        Quaternion EndRot    = new Quaternion(playerRot.x, playerRot.y, playerRot.z + 1.2f, playerRot.w);
        Vector3    StartPos  = UWCharacter.Instance.transform.position;
        Vector3    EndPos    = myObj.transform.localPosition;
        float      rate      = 1.0f / 2.0f;
        float      index     = 0.0f;

        while (index < 1.0f)
        {
            UWCharacter.Instance.transform.position = Vector3.Lerp(StartPos, EndPos, index);
            UWCharacter.Instance.transform.rotation = Quaternion.Lerp(playerRot, EndRot, index);
            if (slasher != null)
            {
                slasher.transform.position = Vector3.Lerp(slasherPos, EndPos, index);
            }
            index += rate * Time.deltaTime;
            yield return(new WaitForSeconds(0.01f));
        }
        UWCharacter.Instance.transform.rotation = playerRot;
        GameWorldController.instance.SwitchLevel(8, 26, 24);              //One way trip.
    }
Example #7
0
 public override void InventoryEventOnLevelExit()
 {
     base.InventoryEventOnLevelExit();
     if (_RES == GAME_UW2)
     {
         if (GameWorldController.instance.LevelNo == 42)
         {
             //make sure the wand of telekinesis is removed from the player as long as the player is not holding it in there hand
             if ((SpellIndex == 295) && (linkedspell == null))
             {
                 if (this.objInt() != CurrentObjectInHand)
                 {
                     UWCharacter.Instance.playerInventory.RemoveItem(this.objInt());
                     //Remove object and place at 29,29
                     GameWorldController.MoveToWorld(objInt());
                     this.transform.position = CurrentTileMap().getTileVector(29, 29);
                 }
             }
         }
     }
 }
Example #8
0
    /// <summary>
    /// A wand linked to a spell object needs to also copy it's spell object to the world.
    /// </summary>
    public override void MoveToWorldEvent()
    {
        if (enchantment == 0)
        {        //Object links to a spell.
            if (linkedspell != null)
            {
                bool match = false;
                //Try and find a spell already in the level that matches the characteristics of this spell
                //If so point to that instead. This avoids filling up the gameworld with stale spells everytime the wand is dropped.
                ObjectLoaderInfo[] objList = CurrentObjectList().objInfo;
                for (int i = 0; i <= objList.GetUpperBound(0); i++)
                {
                    if (objList[i].GetItemType() == ObjectInteraction.SPELL)
                    {
                        if (objList[i].instance != null)
                        {
                            if (objList[i].link == linkedspell.link)
                            {
                                Destroy(linkedspell.gameObject);
                                linkedspell = objList[i].instance.GetComponent <a_spell>();
                                link        = i;                          //Point the spell.
                                match       = true;
                                break;
                            }
                        }
                    }
                }

                if (!match)
                {                //If no spell is found move the spell to the gameworld.  Q? Where does the object appear on map??
                    //linkedspell.gameObject.transform.parent=GameWorldController.instance.DynamicObjectMarker();
                    GameWorldController.MoveToWorld(linkedspell.gameObject);
                    Debug.Log("Spell" + linkedspell.name + " moved from inventory to world. Check to see where it landed!");
                }
            }
        }
    }
Example #9
0
 public void PlayerSlotLeftClick()
 {
     if (TradeSlot.Locked)
     {
         return;
     }
     if (UWCharacter.Instance.playerInventory.ObjectInHand != "")
     {
         //put the object in hand in this slot.
         if (objectInSlot == "")
         {            //Empty slot
             GameObject objToMove = UWCharacter.Instance.playerInventory.GetGameObjectInHand();
             if (objToMove != null)
             {
                 if (objToMove.transform.parent != GameWorldController.instance.DynamicObjectMarker())
                 {                    //Object needs to be moved to world
                     //objToMove.transform.parent= GameWorldController.instance.DynamicObjectMarker();
                     GameWorldController.MoveToWorld(objToMove);
                     ConversationVM.BuildObjectList();
                 }
                 objectInSlot = UWCharacter.Instance.playerInventory.ObjectInHand;
                 UWCharacter.Instance.playerInventory.ObjectInHand = "";
                 SlotImage.texture         = UWHUD.instance.CursorIcon;
                 UWHUD.instance.CursorIcon = UWHUD.instance.CursorIconDefault;
                 Selected = true;
             }
         }
         else
         {            //Swap the objects
             GameObject objInSlot = GetGameObjectInteraction().gameObject;
             GameObject objInHand = UWCharacter.Instance.playerInventory.GetGameObjectInHand();
             if (objInSlot != null)
             {
                 objInSlot.transform.parent = GameWorldController.instance.InventoryMarker.transform;
                 GameWorldController.MoveToInventory(objInSlot);                    //This will call rebuild list
             }
             if (objInHand != null)
             {
                 if (objInHand.transform.parent != GameWorldController.instance.DynamicObjectMarker())
                 {                    //Object needs to be moved to world
                     //objInHand.transform.parent= GameWorldController.instance.DynamicObjectMarker();
                     GameWorldController.MoveToWorld(objInHand);
                 }
             }
             objectInSlot              = objInHand.name;
             SlotImage.texture         = objInHand.GetComponent <ObjectInteraction>().GetInventoryDisplay().texture;
             UWHUD.instance.CursorIcon = objInSlot.GetComponent <ObjectInteraction>().GetInventoryDisplay().texture;
             UWCharacter.Instance.playerInventory.ObjectInHand = objInSlot.name;
             ConversationVM.BuildObjectList();
             Selected = true;
         }
     }
     else
     {
         if (objectInSlot != "")
         {
             //Pickup the object in the slot
             UWCharacter.Instance.playerInventory.SetObjectInHand(objectInSlot);
             UWHUD.instance.CursorIcon = UWCharacter.Instance.playerInventory.GetGameObject(objectInSlot).GetComponent <ObjectInteraction>().GetInventoryDisplay().texture;
             objectInSlot      = "";
             SlotImage.texture = Blank;
             Selected          = false;
             GameObject objToMove = UWCharacter.Instance.playerInventory.GetGameObjectInHand();
             if (objToMove != null)
             {
                 objToMove.transform.parent = GameWorldController.instance.InventoryMarker.transform;
                 GameWorldController.MoveToInventory(objToMove);                    //This will call rebuild list
                 objToMove.GetComponent <object_base>().PickupEvent();
             }
         }
     }
     if (objectInSlot == "")
     {
         Quantity.text = "";
     }
     else
     {
         int qty = GetGameObjectInteraction().GetQty();
         if (qty <= 1)
         {
             Quantity.text = "";
         }
         else
         {
             Quantity.text = qty.ToString();
         }
     }
 }
Example #10
0
    public override bool Eat()
    {    //TODO:Implement drag and drop feeding.
        if (Nutrition() + UWCharacter.Instance.FoodLevel >= 255)
        {
            UWHUD.instance.MessageScroll.Add(StringController.instance.GetString(1, StringController.str_you_are_too_full_to_eat_that_now_));
            return(false);
        }
        else
        {
            UWCharacter.Instance.FoodLevel = Nutrition() + UWCharacter.Instance.FoodLevel;
            switch (objInt().item_id)    //TODO:update for UW2
            {
            case 192:                    //plants
            case 207:
            case 212:
                UWHUD.instance.MessageScroll.Add(StringController.instance.GetString(1, StringController.str_the_plant_is_plain_tasting_but_nourishing_));
                break;

            case 217:                    //Dead rotworm
                UWHUD.instance.MessageScroll.Add(StringController.instance.GetString(1, 234));
                break;

            case 283:                    //Rotworm stew
                UWHUD.instance.MessageScroll.Add(StringController.instance.GetString(1, 235));
                break;

            default:
                UWHUD.instance.MessageScroll.Add("That " + StringController.instance.GetObjectNounUW(objInt()) + foodFlavourText());
                break;
            }
            if (ObjectInteraction.PlaySoundEffects)
            {
                switch (Random.Range(1, 3))
                {
                case 1:
                    UWCharacter.Instance.aud.clip = GameWorldController.instance.getMus().SoundEffects[MusicController.SOUND_EFFECT_EAT_1]; break;

                case 2:
                    UWCharacter.Instance.aud.clip = GameWorldController.instance.getMus().SoundEffects[MusicController.SOUND_EFFECT_EAT_2]; break;

                default:
                    UWCharacter.Instance.aud.clip = GameWorldController.instance.getMus().SoundEffects[MusicController.SOUND_EFFECT_EAT_3]; break;
                }
                UWCharacter.Instance.aud.Play();
            }

            if (_RES == GAME_UW2)
            {            //Some food items leave left overs
                int LeftOverToCreate = -1;
                switch (objInt().item_id)
                {
                case 176:
                case 177:                        //meat
                    LeftOverToCreate = 197; break;

                case 186:                        //honeycomb
                    LeftOverToCreate = 210; break;

                case 187:
                case 188:
                case 189:                        //bottles.
                    LeftOverToCreate = 317; break;
                }

                if (LeftOverToCreate != -1)
                {
                    ObjectLoaderInfo newobjt = ObjectLoader.newObject(LeftOverToCreate, 40, 0, 0, 256);
                    newobjt.InUseFlag = 1;
                    ObjectInteraction created = ObjectInteraction.CreateNewObject(GameWorldController.instance.currentTileMap(), newobjt, GameWorldController.instance.CurrentObjectList().objInfo, GameWorldController.instance.DynamicObjectMarker().gameObject, GameWorldController.instance.InventoryMarker.transform.position);
                    GameWorldController.MoveToWorld(created.gameObject);
                    UWCharacter.Instance.playerInventory.ObjectInHand = created.name;
                    UWHUD.instance.CursorIcon   = created.GetInventoryDisplay().texture;
                    UWCharacter.InteractionMode = UWCharacter.InteractionModePickup;
                }
            }
            objInt().consumeObject(); //destroy and remove from inventory/world.

            return(true);             //Food was eaten.
        }
    }
Example #11
0
    /// <summary>
    /// Applies the armour damage to the players armour (random piece)
    /// If no piece is in the slot picked then no damage is applied
    /// </summary>
    public void ApplyArmourDamage(short armourDamage)
    {
        int[] slots         = { 0, 1, 2, 3, 4, 7, 8 };
        int   PieceToDamage = slots[Random.Range(0, slots.GetUpperBound(0))];

        PieceToDamage = 2;//test
        ObjectInteraction obj = GetObjectIntAtSlot(PieceToDamage);

        if (obj != null)
        {
            switch (PieceToDamage)
            {
            case 0:    //Helm
            case 1:    //Chest
            case 2:    //Leggings
            case 3:    //Boots
            case 4:    //Gloves
                if (obj.GetComponent <Armour>() != null)
                {
                    short durability = obj.GetComponent <Armour>().getDurability();
                    if (durability <= 30)
                    {
                        obj.GetComponent <Armour>().SelfDamage((short)(Mathf.Max(0, armourDamage - durability)));
                        if (obj.quality <= 0)
                        {
                            playerUW.playerInventory.ClearSlot((short)PieceToDamage);
                            obj.transform.parent   = GameWorldController.instance.DynamicObjectMarker().transform;
                            obj.transform.position = playerUW.transform.position;
                            GameWorldController.MoveToWorld(obj);
                            UnFreezeMovement(obj);
                            playerUW.playerInventory.Refresh();
                        }
                    }
                }
                break;

            case 7:    //HandRight
                if (!UWCharacter.Instance.isLefty)
                {
                    if (obj.gameObject.GetComponent <Shield>() != null)
                    {
                        short durability = obj.GetComponent <Shield>().getDurability();
                        if (durability <= 30)
                        {
                            obj.GetComponent <Shield>().SelfDamage((short)(Mathf.Max(0, armourDamage - durability)));
                            if (obj.quality <= 0)
                            {
                                playerUW.playerInventory.Refresh();
                            }
                        }
                    }
                }
                break;

            case 8:    //HandLeft
                if (UWCharacter.Instance.isLefty)
                {
                    if (obj.gameObject.GetComponent <Shield>() != null)
                    {
                        short durability = obj.GetComponent <Shield>().getDurability();
                        if (durability <= 30)
                        {
                            obj.GetComponent <Shield>().SelfDamage((short)(Mathf.Max(0, armourDamage - durability)));
                            if (obj.quality <= 0)
                            {
                                playerUW.playerInventory.Refresh();
                            }
                        }
                    }
                }
                break;
            }
        }
    }
Example #12
0
    public override void ExecuteTrap(object_base src, int triggerX, int triggerY, int State)
    {
        Vector3 spawn = CurrentTileMap().getTileVector(ObjectTileX, ObjectTileY);

        spawn = new Vector3(spawn.x, 4.4f, spawn.z);
        int ItemStringIndex = 0;
        int Price           = 0;

        //Pick the item to sell and get its price
        switch (Quest.instance.variables[owner])
        {
        case 0:    //fish
            ItemStringIndex = 182;
            Price           = 3;
            break;

        case 1:    //meat
            ItemStringIndex = 176;
            Price           = 3;
            break;

        case 2:    //ale
            ItemStringIndex = 187;
            Price           = 4;
            break;

        case 3:    //leeches
            ItemStringIndex = 293;
            Price           = 4;
            break;

        case 4:    //water
            ItemStringIndex = 188;
            Price           = 3;
            break;

        case 5:    //dagger
            ItemStringIndex = 3;
            Price           = 11;
            break;

        case 6:    //lockpick
            ItemStringIndex = 257;
            Price           = 6;
            break;

        case 7:    //torch
            ItemStringIndex = 145;
            Price           = 4;
            break;

        default:
            return;
        }

        if (CheckPrice(Price, ObjectTileX, ObjectTileY))
        {//price check
            ObjectLoaderInfo newobjt = ObjectLoader.newObject(ItemStringIndex, 40, 0, 0, 256);
            newobjt.InUseFlag = 1;
            UnFreezeMovement(GameWorldController.MoveToWorld(ObjectInteraction.CreateNewObject(CurrentTileMap(), newobjt, CurrentObjectList().objInfo, GameWorldController.instance.DynamicObjectMarker().gameObject, spawn)).gameObject);
        }
    }
Example #13
0
    /// <summary>
    /// Throws the object in hand along a vector in the 3d view.
    /// </summary>
    protected override void ThrowObjectInHand()
    {
        base.ThrowObjectInHand();
        if (UWCharacter.Instance.playerInventory.GetObjectInHand() != "")
        {                                                                   //The player is holding something
            if (UWCharacter.Instance.playerInventory.JustPickedup == false) //To prevent the click event dropping an object immediately after pickup
            {
                //Determine what is directly in front of the player via a raycast
                //If something is in the way then cancel the drop
                //Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);

                Ray ray;
                if (UWCharacter.Instance.MouseLookEnabled == true)
                {
                    ray = Camera.main.ViewportPointToRay(new Vector3(0.5f, 0.5f, 0f));
                }
                else
                {
                    ray = Camera.main.ScreenPointToRay(Input.mousePosition);
                }


                RaycastHit hit       = new RaycastHit();
                float      dropRange = 0.5f;
                if (!Physics.Raycast(ray, out hit, dropRange))
                {                                                //No object interferes with the drop
                    //Calculate the force based on how high the mouse is
                    float force = Input.mousePosition.y / Camera.main.pixelHeight * 200;
                    //float force = Camera.main.ViewportToWorldPoint(Input.mousePosition).y/Camera.main.pixelHeight *200;


                    //Get the object being dropped and moved towards the end of the ray

                    GameObject droppedItem = UWCharacter.Instance.playerInventory.GetGameObjectInHand();                                                             //GameObject.Find(UWCharacter.Instance.playerInventory.ObjectInHand);


                    droppedItem.GetComponent <ObjectInteraction>().PickedUp = false;                                                            //Back in the real world
                    droppedItem.GetComponent <ObjectInteraction>().Drop();
                    droppedItem.GetComponent <ObjectInteraction>().UpdateAnimation();
                    GameWorldController.MoveToWorld(droppedItem);
                    droppedItem.transform.parent = GameWorldController.instance.DynamicObjectMarker();

                    if (droppedItem.GetComponent <Container>() != null)
                    {                                                            //Set the picked up flag recursively for container items.
                        Container.SetPickedUpFlag(droppedItem.GetComponent <Container>(), false);
                        Container.SetItemsParent(droppedItem.GetComponent <Container>(), GameWorldController.instance.DynamicObjectMarker());
                        Container.SetItemsPosition(droppedItem.GetComponent <Container>(), UWCharacter.Instance.playerInventory.InventoryMarker.transform.position);
                    }
                    droppedItem.transform.position = ray.GetPoint(dropRange - 0.1f);                                                        //UWCharacter.Instance.transform.position;

                    GameWorldController.UnFreezeMovement(droppedItem);
                    if (Camera.main.ScreenToViewportPoint(Input.mousePosition).y > 0.4f)
                    {                                                            //throw if above a certain point in the view port.
                        Vector3 ThrowDir = ray.GetPoint(dropRange) - ray.origin;
                        //Apply the force along the direction.
                        if (droppedItem.GetComponent <Rigidbody>() != null)
                        {
                            droppedItem.GetComponent <Rigidbody>().AddForce(ThrowDir * force);
                        }
                    }

                    //Clear the object and reset the cursor
                    UWHUD.instance.CursorIcon = UWHUD.instance.CursorIconDefault;
                    UWCharacter.Instance.playerInventory.SetObjectInHand("");
                }
            }
            else
            {
                UWCharacter.Instance.playerInventory.JustPickedup = false;                                              //The next click event will allow dropping.
            }
        }
    }
    /// <summary>
    /// Launchs the ammo.
    /// </summary>
    /// <returns><c>true</c>, if ammo was launched, <c>false</c> otherwise.</returns>
    bool LaunchAmmo(float charge)
    {
        if (currentAmmo != null)
        {
            Ray ray;
            if (UWCharacter.Instance.MouseLookEnabled == true)
            {
                ray = Camera.main.ViewportPointToRay(new Vector3(0.5f, 0.5f, 0f));
            }
            else
            {
                ray = Camera.main.ScreenPointToRay(Input.mousePosition);
            }

            RaycastHit hit       = new RaycastHit();
            float      dropRange = 0.5f;
            if (!Physics.Raycast(ray, out hit, dropRange))
            {///Checks No object interferes with the launch
                float      force = 1000.0f * (charge / 100.0f);
                GameObject launchedItem;
                if (currentAmmo.GetQty() == 1)
                {
                    launchedItem = currentAmmo.gameObject;
                    UWCharacter.Instance.playerInventory.RemoveItem(currentAmmo);
                    //launchedItem.transform.parent=GameWorldController.instance.DynamicObjectMarker();
                    GameWorldController.MoveToWorld(launchedItem);
                    launchedItem.transform.position = ray.GetPoint(dropRange - 0.1f);
                }
                else
                {//reduce this quantity by one and create a copy in the world
                    ObjectLoaderInfo newobjt = ObjectLoader.newWorldObject(currWeaponRanged.AmmoType(), 40, 0, 1, 256);
                    launchedItem = ObjectInteraction.CreateNewObject(CurrentTileMap(), newobjt, CurrentObjectList().objInfo, GameWorldController.instance.DynamicObjectMarker().gameObject, ray.GetPoint(dropRange - 0.1f)).gameObject;
                    currentAmmo.consumeObject();
                }
                launchedItem.GetComponent <ObjectInteraction>().isquant = 1;
                UnFreezeMovement(launchedItem);
                Vector3 ThrowDir = ray.GetPoint(dropRange) - ray.origin;

                ///Apply the force along the direction of the ray that the player has targetted along.
                launchedItem.GetComponent <Rigidbody>().AddForce(ThrowDir * force);
                GameObject myObjChild = new GameObject(launchedItem.name + "_damage");
                myObjChild.transform.position = launchedItem.transform.position;
                myObjChild.transform.parent   = launchedItem.transform;
                ///Appends ProjectileDamage to the projectile to act as the damage delivery method.
                ProjectileDamage pd = myObjChild.AddComponent <ProjectileDamage>();
                pd.Source       = UWCharacter.Instance.gameObject;
                pd.Damage       = (short)currWeaponRanged.Damage(); //   (short)(10.0f*(Charge/100.0f));
                pd.AttackCharge = charge;
                pd.AttackScore  = UWCharacter.Instance.PlayerSkills.GetSkill(Skills.SkillAttack) / 2 + UWCharacter.Instance.PlayerSkills.GetSkill(Skills.SkillMissile);
                return(true);
            }
            else
            {
                return(false);
            }
        }
        else
        {//No ammo?? Should not happen
            return(false);
        }
    }
Example #15
0
    public void PlayerSlotLeftClick()
    {
        if (TradeSlot.Locked)
        {
            return;
        }
        ObjectInteraction objIntAtSlot = GetGameObjectInteraction();

        if (CurrentObjectInHand != null)
        {
            //put the object in hand in this slot.
            if (objectInSlot == null)
            {            //Empty slot
                if (CurrentObjectInHand != null)
                {
                    if (CurrentObjectInHand.transform.parent != GameWorldController.instance.DynamicObjectMarker())
                    {                    //Object needs to be moved to world
                        GameWorldController.MoveToWorld(CurrentObjectInHand);
                        ConversationVM.BuildObjectList();
                    }
                    objectInSlot        = CurrentObjectInHand;
                    SlotImage.texture   = UWHUD.instance.CursorIcon;
                    CurrentObjectInHand = null;
                    Selected            = true;
                }
            }
            else
            {            //Swap the objects
                if (objIntAtSlot != null)
                {
                    objIntAtSlot.transform.parent = GameWorldController.instance.InventoryMarker.transform;
                    GameWorldController.MoveToInventory(objIntAtSlot);                    //This will call rebuild list
                }
                if (CurrentObjectInHand != null)
                {
                    if (CurrentObjectInHand.transform.parent != GameWorldController.instance.DynamicObjectMarker())
                    {                    //Object needs to be moved to world
                        GameWorldController.MoveToWorld(CurrentObjectInHand);
                    }
                }
                objectInSlot        = CurrentObjectInHand;
                SlotImage.texture   = CurrentObjectInHand.GetInventoryDisplay().texture;
                CurrentObjectInHand = objIntAtSlot;
                ConversationVM.BuildObjectList();
                Selected = true;
            }
        }
        else
        {
            if (objectInSlot != null)
            {
                //Pickup the object in the slot
                CurrentObjectInHand = objIntAtSlot;
                objectInSlot        = null;
                SlotImage.texture   = Blank;
                Selected            = false;
                if (CurrentObjectInHand != null)
                {
                    CurrentObjectInHand.transform.parent = GameWorldController.instance.InventoryMarker.transform;
                    GameWorldController.MoveToInventory(CurrentObjectInHand);                    //This will call rebuild list
                    CurrentObjectInHand.GetComponent <object_base>().PickupEvent();
                }
            }
        }
        if (objectInSlot == null)
        {
            Quantity.text = "";
        }
        else
        {
            int qty = GetGameObjectInteraction().GetQty();
            if (qty <= 1)
            {
                Quantity.text = "";
            }
            else
            {
                Quantity.text = qty.ToString();
            }
        }
    }