UnFreezeMovement() public static method

Unfreeze the movement of the specified object if it has a rigid body attached.
public static UnFreezeMovement ( GameObject myObj ) : void
myObj GameObject My object.
return void
 /// <summary>
 /// Moves the objects in contact.
 /// </summary>
 /// <param name="Height">Height.</param>
 /// Could be better.
 public void MoveObjectsInContact(float Height)
 {
     for (int i = 0; i <= colliders.GetUpperBound(0); i++)
     {
         if (colliders[i].gameObject.GetComponent <ObjectInteraction>() != null)
         {
             Vector3 objPosition = colliders[i].gameObject.transform.position;
             GameWorldController.UnFreezeMovement(colliders[i].gameObject);
             colliders[i].gameObject.transform.position = new Vector3(objPosition.x, Height, objPosition.z);
         }
     }
 }
Exemplo n.º 2
0
    public void SpillContentsX()
    {                                                               //Removes the contents of a container out in the real world.
        int     counter;
        TileMap tm = GameWorldController.instance.currentTileMap(); //GameObject.Find("Tilemap").GetComponent<TileMap>();

        GameWorldController.FreezeMovement(this.gameObject);
        ObjectInteraction objInt = this.gameObject.GetComponent <ObjectInteraction>();

        objInt.SetWorldDisplay(objInt.GetEquipDisplay());
        for (short i = 0; i <= MaxCapacity(); i++)
        {
            GameObject Spilled = GetGameObjectAt(i);            //GameObject.Find (GetItemAt (i));
            if (Spilled != null)
            {
                if (Spilled.GetComponent <trigger_base>() != null)
                {
                    Spilled.GetComponent <trigger_base>().Activate(this.gameObject);
                }
                bool    flag        = false;
                Vector3 randomPoint = this.transform.position;
                counter = 0;
                while ((flag == false) && (counter < 25))
                {
                    randomPoint = this.transform.position + Random.insideUnitSphere;
                    if (randomPoint.y < this.transform.position.y)
                    {
                        randomPoint.y = this.transform.position.y + 0.1f;
                    }
                    flag = ((!Physics.CheckSphere(randomPoint, 0.5f)) && (tm.ValidTile(randomPoint)));
                    counter++;
                }
                if (flag == true)
                {                //No object interferes with the spill
                    RemoveItemFromContainer(i);
                    Spilled.transform.position = randomPoint;
                    Spilled.GetComponent <ObjectInteraction>().PickedUp = false;
                    GameWorldController.UnFreezeMovement(Spilled);
                }
                else
                {                //No where to put the item. Put it at the containers position.
                    RemoveItemFromContainer(i);
                    Spilled.transform.position = this.transform.position;
                    Spilled.GetComponent <ObjectInteraction>().PickedUp = false;
                    GameWorldController.UnFreezeMovement(Spilled);
                }
            }
        }
        GameWorldController.UnFreezeMovement(this.gameObject);
    }
Exemplo n.º 3
0
    private void CreateRuneStone(int ItemID)
    {
        //string Item= ItemID.ToString("000");

        ObjectLoaderInfo newobjt = ObjectLoader.newObject(ItemID, 0, 0, 1, 256);
        GameObject       myObj   = ObjectInteraction.CreateNewObject(GameWorldController.instance.currentTileMap(), newobjt, GameWorldController.instance.LevelMarker().gameObject, new Vector3(64.5f, 4.0f, 24.5f)).gameObject;


        //GameObject myObj=  new GameObject("SummonedObject_" + UWCharacter.Instance.PlayerMagic.SummonCount++);
        //myObj.layer=LayerMask.NameToLayer("UWObjects");
        //myObj.transform.parent=GameWorldController.instance.LevelMarker();
        //GameWorldController.MoveToWorld(myObj);
        //ObjectInteraction.CreateObjectGraphics(myObj,_RES +"/Sprites/Objects/Objects_224",true);
        //ObjectInteraction.CreateObjectInteraction(myObj,0.5f,0.5f,0.5f,0.5f, 224, ItemID, ItemID, ObjectInteraction.RUNE, 224, 1, 40, 0, 1, 1, 0, 1, 1, 0, 0, 1);

        //myObj.AddComponent<RuneStone>();

        //myObj.transform.position = new Vector3(64.5f,4.0f,24.5f);
        GameWorldController.UnFreezeMovement(myObj);
    }
Exemplo n.º 4
0
    /*
     * An arrow trap is used to fire projectiles (usually at the player).
     * The item type created is controlled by the object quality and owner
     * target = (currobj.quality << 5) | currobj.owner; //This is set in UWexporter
     *
     * The vector is simply the heading of the trap.
     *
     * Examples of usage
     * The mine collapse on level2
     * The skulls launched at the player on level3 -Troll area.
     */

    public override void ExecuteTrap(object_base src, int triggerX, int triggerY, int State)
    {
        int item_index = (objInt().quality << 5) | objInt().owner;

        ObjectLoaderInfo newobjt = ObjectLoader.newObject(item_index, 0, 0, 0, 256);
        GameObject       myObj   = ObjectInteraction.CreateNewObject(GameWorldController.instance.currentTileMap(), newobjt, GameWorldController.instance.CurrentObjectList().objInfo, GameWorldController.instance.DynamicObjectMarker().gameObject, this.transform.position).gameObject;

        if (objInt().tileX == TileMap.ObjectStorageTile)
        {
            Vector3 pos = GameWorldController.instance.currentTileMap().getTileVector(triggerX, triggerY);
            pos = new Vector3(pos.x, this.transform.position.y, pos.z);
            myObj.transform.position = pos;
        }
        else
        {
            myObj.transform.position = this.transform.position;
        }
        myObj.transform.rotation = this.transform.rotation;
        if (myObj.GetComponent <Rigidbody>() == null)
        {
            myObj.AddComponent <Rigidbody>();
        }

        GameWorldController.UnFreezeMovement(myObj);
        myObj.GetComponent <Rigidbody>().collisionDetectionMode = CollisionDetectionMode.Continuous;
        myObj.GetComponent <Rigidbody>().AddForce(myObj.transform.forward * 20.0f * ((float)(objInt().owner)));

        GameObject myObjChild = new GameObject(myObj.name + "_damage");

        myObjChild.transform.position = myObj.transform.position;
        myObjChild.transform.parent   = myObj.transform;
        ProjectileDamage pd = myObjChild.AddComponent <ProjectileDamage>();

        pd.Source       = this.gameObject; //Traps don't need to be identified.
        pd.Damage       = 10;              //Dunno what drives damage here?
        pd.AttackCharge = 100f;
        pd.AttackScore  = 15;              //down the middle.
    }
Exemplo n.º 5
0
    public void SpillContents()
    {
        TileMap tm = GameWorldController.instance.currentTileMap();                        //GameObject.Find("Tilemap").GetComponent<TileMap>();

        GameWorldController.FreezeMovement(this.gameObject);
        ObjectInteraction objInt = this.gameObject.GetComponent <ObjectInteraction>();

        objInt.UpdatePosition();
        objInt.SetWorldDisplay(objInt.GetEquipDisplay());
        for (short i = 0; i <= MaxCapacity(); i++)
        {
            GameObject Spilled = GetGameObjectAt(i);                                    //GameObject.Find (GetItemAt (i));
            if (Spilled != null)
            {
                if (Spilled.GetComponent <trigger_base>() != null)
                {
                    Spilled.GetComponent <trigger_base>().Activate(this.gameObject);
                }
                else
                {
                    ObjectInteraction objSpilled = Spilled.GetComponent <ObjectInteraction>();
                    Spilled.transform.position = this.transform.position;
                    objSpilled.UpdatePosition();
                    switch (tm.Tiles[objInt.tileX, objInt.tileY].tileType)
                    {
                    case TileMap.TILE_OPEN:
                    case TileMap.TILE_SLOPE_N:
                    case TileMap.TILE_SLOPE_S:
                    case TileMap.TILE_SLOPE_E:
                    case TileMap.TILE_SLOPE_W:
                        objSpilled.x = (short)Random.Range(1, 7);
                        objSpilled.y = (short)Random.Range(1, 7);
                        break;

                    case TileMap.TILE_DIAG_SE:
                        objSpilled.x = (short)Random.Range(1, 7);
                        objSpilled.y = (short)Random.Range(0, objSpilled.x);
                        break;

                    case TileMap.TILE_DIAG_SW:
                        objSpilled.x = (short)Random.Range(1, 7);
                        objSpilled.y = (short)Random.Range(1, 7 - objSpilled.x);
                        break;

                    case TileMap.TILE_DIAG_NE:
                        objSpilled.x = (short)Random.Range(1, 7);
                        objSpilled.y = (short)Random.Range(8 - objSpilled.x, 8);
                        break;

                    case TileMap.TILE_DIAG_NW:
                        objSpilled.x = (short)Random.Range(1, 7);
                        objSpilled.y = (short)Random.Range(objSpilled.x, 8);
                        break;
                    }
                    objSpilled.zpos = (short)(tm.Tiles[objInt.tileX, objInt.tileY].floorHeight * 4);
                    objSpilled.objectloaderinfo.x    = objSpilled.x;
                    objSpilled.objectloaderinfo.y    = objSpilled.y;
                    objSpilled.objectloaderinfo.zpos = objSpilled.zpos;
                    objSpilled.transform.position    = ObjectLoader.CalcObjectXYZ(_RES, tm, tm.Tiles, GameWorldController.instance.CurrentObjectList().objInfo, objSpilled.objectloaderinfo.index, this.objInt().objectloaderinfo.tileX, this.objInt().objectloaderinfo.tileY, 0);
                    RemoveItemFromContainer(i);
                    Spilled.GetComponent <ObjectInteraction>().PickedUp = false;
                    GameWorldController.UnFreezeMovement(Spilled);
                }
            }
        }
    }
Exemplo n.º 6
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.
            }
        }
    }
Exemplo n.º 7
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
        GameObject obj = GetGameObjectAtSlot(PieceToDamage);

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

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

            case 8:                    //HandLeft
                if (UWCharacter.Instance.isLefty)
                {
                    if (obj.gameObject.GetComponent <Shield>() != null)
                    {
                        short durability = obj.gameObject.GetComponent <Shield>().getDurability();
                        if (durability <= 30)
                        {
                            obj.gameObject.GetComponent <Shield>().SelfDamage((short)(Mathf.Max(0, armourDamage - durability)));
                            if (obj.gameObject.GetComponent <ObjectInteraction>().quality <= 0)
                            {
                                playerUW.playerInventory.Refresh();
                            }
                        }
                    }
                }
                break;
            }
        }
    }
Exemplo n.º 8
0
    //spawns vending selection
    public override void ExecuteTrap(object_base src, int triggerX, int triggerY, int State)
    {    //4.4
        Vector3 spawn = GameWorldController.instance.currentTileMap().getTileVector(objInt().tileX, objInt().tileY);

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

        switch (Quest.instance.variables[objInt().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, objInt().tileX, objInt().tileY))
        {        //price check
            ObjectLoaderInfo newobjt = ObjectLoader.newObject(ItemStringIndex, 40, 0, 0, 256);
            newobjt.InUseFlag = 1;
            GameWorldController.UnFreezeMovement(GameWorldController.MoveToWorld(ObjectInteraction.CreateNewObject(GameWorldController.instance.currentTileMap(), newobjt, GameWorldController.instance.CurrentObjectList().objInfo, GameWorldController.instance.DynamicObjectMarker().gameObject, spawn)).gameObject);
        }
    }
Exemplo n.º 9
0
    /// <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.name);
                    launchedItem.transform.parent = GameWorldController.instance.LevelMarker();
                    GameWorldController.MoveToWorld(launchedItem);
                    launchedItem.transform.position = ray.GetPoint(dropRange - 0.1f);
                    launchedItem.GetComponent <ObjectInteraction>().PickedUp = false;                   //Back in the real world
                }
                else
                {                //reduce this quantity by one and create a copy in the world
                    ObjectLoaderInfo newobjt = ObjectLoader.newObject(currWeaponRanged.AmmoType(), 40, 0, 1, 256);
                    launchedItem = ObjectInteraction.CreateNewObject(GameWorldController.instance.currentTileMap(), newobjt, GameWorldController.instance.LevelMarker().gameObject, ray.GetPoint(dropRange - 0.1f)).gameObject;
                    currentAmmo.consumeObject();
                }
                launchedItem.GetComponent <ObjectInteraction>().isquant = 1;
                GameWorldController.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);
        }
    }