Exemple #1
0
    public void OnPointerClick(PointerEventData eventData)
    {
        Item        targetItem = GetComponentInChildren <DisplayItemInInventory>().item;
        ChestScript cs         = UIManager.ins.targetChest.GetComponent <ChestScript>();
        PlayerInfo  pi         = UIManager.ins.player.GetComponent <PlayerInfo>();

        if (transform.parent.name.ToString() == UIManager.ins.ChestPlayerGridLayout.name.ToString())
        {
            //is in player's inv and needs to go to chest
            if (!cs.chestInventory.CanAddItem())
            {
                return;
            }
            pi.inventory.RemoveItem(targetItem, 1);
            cs.chestInventory.AddItem(targetItem);
        }
        else
        {
            //is in chest inv and needs to go to player's inv
            if (!pi.inventory.CanAddItem())
            {
                return;
            }
            pi.inventory.AddItem(targetItem);
            cs.chestInventory.RemoveItem(targetItem, 1);
        }
        cs.ReloadItems();
        UIManager.ins.UpdateChestItemCount(cs.chestInventory.Size, cs.chestInventory.maxSize);
        UIManager.ins.UpdateChestPlayerItemCount(GameManagerScript.ins.playerInventory.Size, GameManagerScript.ins.playerInventory.maxSize);
    }
Exemple #2
0
 // Use this for initialization
 void Start()
 {
     switchR = GameObject.Find("switchR").GetComponent <RedSwitchScript> ();
     switchG = GameObject.Find("switchG").GetComponent <GreenSwitchScript> ();
     switchB = GameObject.Find("switchB").GetComponent <BlueSwitchScript> ();
     chest   = transform.parent.GetComponentInChildren <ChestScript>();
 }
Exemple #3
0
 private void CheckCommands()
 {
     if (Input.GetKeyDown(KeyCode.E))
     {
         RaycastHit hit = new RaycastHit();
         Debug.DrawRay(this.collider.bounds.center, this.transform.forward, Color.green, 100.0f);
         if (Physics.Raycast(this.collider.bounds.center, this.transform.forward, out hit, 100.0f))
         {
             GameObject obj = hit.collider.gameObject;
             //Get absolute parent
             while (obj.transform.parent != null)
             {
                 obj = obj.transform.parent.gameObject;
             }
             if (obj.tag == "Chest")
             {
                 ChestScript chest = (ChestScript)obj.GetComponent(typeof(ChestScript));
                 //If locked and we have a key
                 if (chest.IsLocked() && keys > 0)
                 {
                     keys--;
                     chest.Open();
                 }
                 else                    //Unlocked
                 {
                     chest.Open();
                 }
             }
         }
     }
 }
Exemple #4
0
    public void AddWorldObjectsToChunk(int seed, ChunkScript chunk)
    {
        List <ChestScript> chunkChests = new List <ChestScript>();
        int numToSpawn = Random.Range(MinObjPerChunk, MaxObjPerChunk);

        if (c_Pool.Count < numToSpawn)
        {
            numToSpawn = c_Pool.Count;
        }
        for (int i = 0; i < numToSpawn; i++)
        {
            if (c_Pool.Count < 1)
            {
                return;
            }

            GameObject tile = chunk.GetRandomTile();

            ChestScript chest = c_Pool[0];

            chest.Init(tile.transform.position);

            chunkChests.Add(chest);



            c_Pool.Remove(chest);
        }
        c_Active.Add(seed, chunkChests);
    }
    void Start()
    {
        chest     = transform.parent.GetComponentInChildren <ChestScript>();
        lightSink = transform.parent.transform.Find("sink").gameObject;

        // apply rules to the room.
        RuleParser.implement(transform.parent.gameObject, FindObjectOfType <MapEngine>().RoomRules(transform.parent.name));
    }
Exemple #6
0
 // Start is called before the first frame update
 void Start()
 {
     audioSource = GetComponent <AudioSource>();
     nextFire    = 0;
     cs          = chest.GetComponent <ChestScript>();
     cs1         = chest1.GetComponent <ChestScript>();
     cs2         = chest2.GetComponent <ChestScript>();
 }
Exemple #7
0
 public static void Postfix(ChestScript __instance)
 {
     if (__instance.isGold)
     {
         LootTables.DropLoot("chest:gold", __instance.transform.position, 0.2f);
     }
     else
     {
         LootTables.DropLoot("chest:basic", __instance.transform.position, 0.2f);
     }
 }
Exemple #8
0
 public void Init(int minPer, int maxPer, int totalMax)
 {
     MinObjPerChunk = minPer;
     MaxObjPerChunk = maxPer;
     for (int i = 0; i < totalMax; i++)
     {
         GameObject  obj = Instantiate(chestPrefab, gameObject.transform);
         ChestScript cs  = obj.GetComponent <ChestScript>();
         cs.SetSpriteRenderer(obj.GetComponent <SpriteRenderer>());
         cs.Hide();
         c_Pool.Add(cs);
     }
 }
 // Use this for initialization
 private void Start()
 {
     m_CharacterController = GetComponent <CharacterController>();
     rb       = gameObject.GetComponent <Rigidbody>();
     m_Camera = Camera.main;
     m_OriginalCameraPosition = m_Camera.transform.localPosition;
     m_FovKick.Setup(m_Camera);
     m_HeadBob.Setup(m_Camera, m_StepInterval);
     m_StepCycle   = 0f;
     m_NextStep    = m_StepCycle / 2f;
     m_Jumping     = false;
     m_AudioSource = GetComponent <AudioSource>();
     m_MouseLook.Init(transform, m_Camera.transform);
     script        = chest.GetComponent <ChestScript>();
     speedUpgraded = false;
 }
Exemple #10
0
        protected override void OnCantMove <T>(T component)
        {
            isMoving = false;
            Enemy       hitEnemy = component as Enemy;
            ChestScript chest    = component as ChestScript;

            anim.SetTrigger("Attack");
            if (component == hitEnemy)
            {
                hitEnemy.DamageEntity(hitEnemy.name, attack.GetValue());
            }
            if (component == chest)
            {
                chest.OpenChest();
            }
            GameManager.instance.AddTurn();
        }
Exemple #11
0
        protected override void OnCantMove <T>(T component)
        {
            Player      hitPlayer = component as Player;
            ChestScript chest     = component as ChestScript;

            if (component == hitPlayer)
            {
                hitPlayer.DamageEntity(hitPlayer.name, attack.GetValue());
            }
            if (component == chest)
            {
                return;
            }
            //hitPlayer.LoseFood(playerDamage);

            ////Set the attack trigger of animator to trigger Enemy attack animation.
            //animator.SetTrigger("enemyAttack");
        }
Exemple #12
0
    public void unlockNewChest()
    {
        ChestScript chestScript = actualChest.GetComponent <ChestScript>();

        //If there is otherChest to unlock
        if (listAllChest.Count != listUnlockChest.Count)
        {
            //deduct the money of the player
            player.money -= chestScript.getGoldToUnlock();
            //For all the item that we need to unlock the chest
            for (int i = 0; i < chestScript.getItemToUnlock().Count; i++)
            {
                //Check in inventory
                for (int j = 0; j < player.listIDItem.Count; j++)
                {
                    //If this is the right item
                    if (player.listIDItem[j] == chestScript.getItemToUnlock()[i].GetComponent <ItemScript>().id)
                    {
                        //deduct the number
                        player.listNumberItem[j] -= chestScript.getNumberItemToUnlock()[i];
                        //Refresh the number
                        TextMeshProUGUI textNumberItem = inventory.transform.GetChild(player.listSlotItem[j]).GetChild(1).GetComponent <TextMeshProUGUI>();
                        textNumberItem.text = "" + player.listNumberItem[j];
                        //If we use all the item
                        if (player.listNumberItem[j] == 0)
                        {
                            //remove from the inventory and reset the number to null
                            player.listNumberItem.RemoveAt(j);
                            player.listIDItem.RemoveAt(j);
                            inventory.transform.GetChild(player.listSlotItem[j]).GetChild(0).GetComponent <Image>().sprite = null;
                            textNumberItem.text = null;
                            player.listSlotItem.RemoveAt(j);
                        }
                    }
                }
            }
            //add to the unlockChest
            listUnlockChest.Add(listAllChest[player.actualChestNumber]);
            //Save the new timer and set it to the default timer
            player.listTimer.Add(listAllChest[player.actualChestNumber].GetComponent <ChestScript>().calculateTimer());
        }
        setChestSprite();
        setArrowActive();
    }
Exemple #13
0
    public void OpenChest()
    {
        //If the chest is unlock
        if (canNextChest)
        {
            ChestScript actualChestScript = actualChest.GetComponent <ChestScript>();
            //If the timer is up or the chest is open
            if (player.listTimer[player.actualChestNumber] == 0 || imageChest.sprite == actualChestScript.open)
            {
                //Open the chest, get a loot and reset the timer
                if (imageChest.sprite == actualChestScript.close)
                {
                    imageChest.sprite = actualChestScript.open;
                    actualChestScript.getLoot();
                    //Reset and save the timer
                    player.listTimer[player.actualChestNumber] = actualChestScript.calculateTimer();
                    //To fill the inventory
                    bool isInInventory = false;
                    int  numberSlot    = 0;
                    if (player.listIDItem.Contains(actualChest.GetComponent <ChestScript>().getDropLoot().GetComponent <ItemScript>().id))
                    {
                        isInInventory = true;
                        numberSlot    = player.listIDItem.IndexOf(actualChest.GetComponent <ChestScript>().getDropLoot().GetComponent <ItemScript>().id);
                    }


                    ////If the item is already in the inventory
                    //if (inventory.transform.GetChild(i).GetChild(0).GetComponent<Image>().sprite == GameObject.Find("Loot").GetComponent<Image>().sprite)
                    //{
                    //    //Set the amount of the item
                    //    inventory.transform.GetChild(i).GetComponent<slotScript>().setTextNumber();
                    //    //Save the amount of the item
                    //    player.listNumberItem[i] = inventory.transform.GetChild(i).GetComponent<slotScript>().getNumber();
                    //    isInInventory = true;
                    //}
                    ////Else put in a new slot
                    //else if (inventory.transform.GetChild(i).GetChild(0).GetComponent<Image>().sprite == null)
                    //{
                    //   //Save the slot position
                    //    player.listSlotItem.Add(i);
                    //    //Put the loot sprite in the inventory
                    //    inventory.transform.GetChild(i).GetChild(0).GetComponent<Image>().sprite = GameObject.Find("Loot").GetComponent<Image>().sprite;
                    //    slotScript slotScript = inventory.transform.GetChild(i).GetComponent<slotScript>();
                    //    //Set the amount of the item
                    //    slotScript.setTextNumber();
                    //    //Save the new numberItem and the new idItem
                    //    player.listNumberItem.Add(1);
                    //    player.listIDItem.Add(actualChestScript.getIDLoot());
                    //    isInInventory = true;
                    //}


                    if (!isInInventory)
                    {
                        bool isFill = false;
                        for (int i = 0; i < inventory.transform.childCount && !isFill; i++)
                        {
                            if (!player.listSlotItem.Contains(i))
                            {
                                player.listSlotItem.Add(i);
                                player.listIDItem.Add(actualChest.GetComponent <ChestScript>().getDropLoot().GetComponent <ItemScript>().id);
                                player.listNumberItem.Add(1);
                                Debug.Log("ça bug ? : " + actualChest.GetComponent <ChestScript>().getDropLoot().GetComponent <ItemScript>().id);
                                inventory.transform.GetChild(i).GetComponent <slotScript>().setNewItemSlot(actualChest.GetComponent <ChestScript>().getDropLoot().GetComponent <ItemScript>().id);
                                inventory.transform.GetChild(i).GetComponent <slotScript>().setText(1);


                                isFill = true;
                            }
                        }
                        if (!isFill)
                        {
                            Debug.Log("Inventory full !");
                        }
                    }
                    else if (isInInventory)
                    {
                        player.listNumberItem[numberSlot]++;
                        inventory.transform.GetChild(numberSlot).GetComponent <slotScript>().setText(player.listNumberItem[numberSlot]);
                    }
                }
                //Close the chest and destroy the loot image
                else if (imageChest.sprite == actualChestScript.open)
                {
                    GameObject.Find("Loot").GetComponent <Image>().sprite = null;
                    imageChest.sprite = actualChestScript.close;
                }
            }
        }
    }
 void Start()
 {
     chest = transform.parent.GetComponentInChildren <ChestScript>();
 }
Exemple #15
0
    private void setSlotToUnlock(GameObject panel)
    {
        bool canUnlock = true;
        //for each slot in unlockPanel
        ChestScript chestScript = chestImageScript.getActualChest().GetComponent <ChestScript>();

        for (int i = 0; i < chestScript.getItemToUnlock().Count; i++)
        {
            Transform transformSlot = panel.transform.GetChild(0).GetChild(i);
            //set the sprite with the item in the chestScript
            transformSlot.GetChild(1).GetComponent <Image>().sprite = chestScript.getItemToUnlock()[i].GetComponent <SpriteRenderer>().sprite;
            //set the number with the number in the chestScript
            transformSlot.GetChild(0).GetComponent <TextMeshProUGUI>().text = "" + chestScript.getNumberItemToUnlock()[i];
            //set the gold with the gold in the chestScript
            panel.transform.GetChild(2).GetChild(0).GetComponent <TextMeshProUGUI>().text = "" + chestScript.getGoldToUnlock();
            //(Put this because have some probleme with the next unlock)
            transformSlot.GetComponent <Image>().sprite = slotWrong;
            //Check the inventory
            bool findItem = false;
            for (int j = 0; j < player.listIDItem.Count && !findItem; j++)
            {
                //If we have the item
                if (player.listIDItem[j] == chestScript.getItemToUnlock()[i].GetComponent <ItemScript>().id)
                {
                    if (player.listNumberItem[j] < chestScript.getNumberItemToUnlock()[i])
                    {
                        if (canUnlock)
                        {
                            canUnlock = false;
                        }
                        //Set the red slot
                        transformSlot.GetComponent <Image>().sprite = slotWrong;
                    }
                    //If we have enought item
                    else if (player.listNumberItem[j] >= chestScript.getNumberItemToUnlock()[i])
                    {
                        //Set the red slot
                        transformSlot.GetComponent <Image>().sprite = slotRight;
                    }
                    findItem = true;
                }
            }
            if (!findItem)
            {
                canUnlock = false;
            }
            //Even if the inventory is empty
            if (player.listIDItem.Count == 0)
            {
                if (canUnlock)
                {
                    canUnlock = false;
                }
                transformSlot.GetComponent <Image>().sprite = slotWrong;
            }
            Image slotMoneyImage = panel.transform.GetChild(2).GetComponent <Image>();
            //If we don't have enought money
            if (player.money < chestScript.getGoldToUnlock())
            {
                if (canUnlock)
                {
                    canUnlock = false;
                }
                slotMoneyImage.sprite = slotWrong;
            }
            else
            {
                slotMoneyImage.sprite = slotRight;
            }
        }
        //active the unlock button and change the color of the button
        Transform transformUnlockPanel = panel.transform.GetChild(3);

        if (canUnlock)
        {
            transformUnlockPanel.GetChild(1).gameObject.SetActive(true);
            transformUnlockPanel.GetComponent <Image>().color = Color.white;
            transformUnlockPanel.GetChild(0).GetComponent <TextMeshProUGUI>().color = Color.white;
        }
        else
        {
            transformUnlockPanel.GetChild(1).gameObject.SetActive(false);
            transformUnlockPanel.GetComponent <Image>().color = new Color32(147, 147, 147, 226);
            transformUnlockPanel.GetChild(0).GetComponent <TextMeshProUGUI>().color = new Color32(149, 134, 134, 255);
        }
    }
    void Update()
    {
        if (loadInfo.pause == false)
        {
            if (invalnurability > 0)
            {
                invalnurability -= Time.deltaTime;
            }
            else if (invalnurability < 0)
            {
                invalnurability = 0;
            }

            input.Set(Input.GetAxisRaw("Horizontal"), Input.GetAxisRaw("Vertical"));
            rigidBody.velocity = input * movementSpeed;
            if (Mathf.Abs(Input.GetAxisRaw("Horizontal")) < Mathf.Abs(Input.GetAxisRaw("Vertical")))
            {
                if (Input.GetAxisRaw("Vertical") > 0)
                {
                    rotation = Vector2.up;
                }
                else
                {
                    rotation = Vector2.down;
                }
            }
            else if (Mathf.Abs(Input.GetAxisRaw("Horizontal")) > Mathf.Abs(Input.GetAxisRaw("Vertical")))
            {
                if (Input.GetAxisRaw("Horizontal") > 0)
                {
                    rotation = Vector2.right;
                }
                else
                {
                    rotation = Vector2.left;
                }
            }
            else
            {
                // To do: diagonal? Prolly not
            }
        }
        else
        {
            rigidBody.velocity = new Vector3(0, 0);
        }

        //gameObject.GetComponent<SpriteRenderer>().sortingOrder =

        if (Input.GetButtonUp("Interact") && !loadInfo.pause)
        {
            Debug.Log("Interacting...");
            interactionRay = Physics2D.Raycast(transform.position, rotation, 1, interactionLayers); // To do: learn how to use layermasks without the inspector
            if (interactionRay)
            {
                switch (interactionRay.collider.tag)
                {
                case "Walls":
                    Debug.Log("Just a wall.");
                    break;

                case "WorldEnemy":
                    Debug.Log("Look out, an enemy!");
                    break;

                case "Item":
                    Debug.Log(interactionRay.collider.gameObject.GetComponent <ItemPickupScript>().item.Description);
                    break;

                case "Door":
                    Debug.Log(interactionRay.collider.gameObject.GetComponent <DoorScript>().description);
                    break;

                case "Chest":
                    ChestScript chest = interactionRay.collider.gameObject.GetComponent <ChestScript>();
                    for (int n = 0; n < chest.items.Count; n++)
                    {
                        if (n < chest.amounts.Count)
                        {
                            InventoryScript.Instance.ModifyInventory(chest.amounts[n], chest.items[n]);
                        }
                    }
                    break;

                case "WorldNpc":
                    Debug.Log("Talking to an NPC!");
                    pauseController.SetupDialogue(interactionRay.collider.gameObject.GetComponent <NpcWorldScript>().dialogue);
                    break;
                }
            }
            else
            {
                Debug.Log("Nothing to interact with!");
            }
        }
    }
 public Chest(Transform chest)
 {
     _chest = chest.GetComponent <ChestScript>();
 }
 private void Awake()
 {
     instance = this;
 }