Esempio n. 1
0
    public bool IsInventoryFull(ResourceDrop resourceDrop)
    {
        foreach (InvSlot slot in _allInvSlots)
        {
            if (slot.IsOccupied && slot.InvSlotContent.Resource && slot.InvSlotContent.ResourceDrop.Type == resourceDrop.Type)
            {
                return(false);
            }
        }
        int fullSlotsCount = 0;

        foreach (InvSlot invSlot in _allInvSlots)
        {
            if (invSlot.IsOccupied && invSlot != HandEquipment && invSlot != BodyEquipment)
            {
                fullSlotsCount++;
            }
        }
        if (fullSlotsCount >= InventoryLimit)
        {
            //TODO: Let player know there is no more space
            Debug.Log("Inventory is full");
            return(true);
        }
        else
        {
            return(false);
        }
    }
Esempio n. 2
0
 void Awake()
 {
     rd = GetComponentInChildren <ResourceDrop>();
     cm = GetComponentInChildren <UEO_ColorCycler>();
     oc = GetComponentInChildren <UEO_ObjectCycler>();
     cs = GetComponentInChildren <UEO_ScaleManipulator>();
 }
 public InvSlotContent(ResourceDrop resourceDrop, int amount)
 {
     ResourceDrop = resourceDrop;
     IconName     = resourceDrop.Type.ToString() + " Icon";
     Amount       = amount;
     Resource     = true;
 }
Esempio n. 4
0
 private void SpawnResourceDrops()
 {
     for (int i = 0; i < resourceDropCount; i++)
     {
         ResourceDrop drop     = Instantiate(resourceDropPrefab, transform.position, Quaternion.identity);
         Vector2      popForce = Random.insideUnitCircle * resourceDropMaxPopForce;
         drop.GetComponent <Rigidbody2D>().AddForce(popForce, ForceMode2D.Impulse);
     }
 }
Esempio n. 5
0
    public void DestroyedByPlayer()
    {
        ResourceDrop rd = GetComponentInChildren <ResourceDrop>();

        if (rd)
        {
            rd.DropResource();
        }
    }
Esempio n. 6
0
    public override void Initialize(object obj)
    {
        base.Initialize(obj);

        drop = obj as ResourceDrop;

        if (drop == null)
        {
            Debug.LogError("No ResourceDrop Reference");
        }
    }
    public void DropResource(IInventoryHolder target, Vector2 pos, Item.Type type)
    {
        if (type == Item.Type.Blank)
        {
            return;
        }

        ResourceDrop rd = Instantiate(dropPrefab);

        rd.Create(target, pos, type);
    }
Esempio n. 8
0
 private void Consume(ResourceDrop resource)
 {
     if (resource.EffectOnPlayer == Resource.EffectOnPlayer.Healthy)
     {
         Player.Heal(Player.HealthyFoodHealAmount);
     }
     else if (resource.EffectOnPlayer == Resource.EffectOnPlayer.Poisonous)
     {
         Player.TakeDamage(Player.PoisonousFoodDamage);
     }
     UpdatePlayerResources(-1, resource.Type);
 }
Esempio n. 9
0
    private bool CanExtinguish()
    {
        // Checking if the player has Full Bucket Equiped
        if (_inventory.HandEquipment.IsOccupied && _inventory.HandEquipment.InvSlotContent.Item.Type == Item.ItemType.FullBucket)
        {
            // TODO: Select the closest object to the player
            foreach (GameObject col in AllInstructionsObjectsColliders)
            {
                if (col.transform.tag == "Resource Mine")
                {
                    NearbyResourceMine = col.GetComponent <ResourceMine>();
                    if (NearbyResourceMine.IsOnFire)
                    {
                        return(true);
                    }
                }
                else if (col.transform.tag == "Resource Drop")
                {
                    NearbyResourceDrop = col.GetComponent <ResourceDrop>();
                    if (NearbyResourceDrop.IsOnFire)
                    {
                        return(true);
                    }
                }
                else if (col.transform.tag == "Campfire")
                {
                    NearbyCampfire = col.GetComponent <Campfire>();
                    if (NearbyCampfire.IsOnFire)
                    {
                        return(true);
                    }
                }
            }

            /*if (NearbyResourceMine != null && NearbyResourceMine.IsOnFire)
             * {
             *  return true;
             * }
             * else if (NearbyResourceDrop != null && NearbyResourceDrop.IsOnFire)
             * {
             *  return true;
             * }
             * else if (NearbyCampfire != null && NearbyResourceDrop.IsOnFire)
             * {
             *  return true;
             * }*/
        }
        return(false);
    }
Esempio n. 10
0
    public ResourceDrop CreateRessourceStack(ResourceStack _stack, Vector2Int _position)
    {
        GameObject   obj  = Instantiate(ressourcesPrefab);
        ResourceDrop drop = obj.GetComponent <ResourceDrop>();

        if (drop != null)
        {
            drop.ressources = _stack;
            GameState.instance.map.GetTile(_position.x, _position.y).relatedObject = drop;
            return(drop);
        }
        else
        {
            return(null);
        }
    }
Esempio n. 11
0
 private bool CanPickUp()
 {
     //GetClosestObjectTemp();
     if (ClosestObject)
     {
         if (ClosestObject.GetComponent <ResourceDrop>() != null)
         {
             NearbyResourceDrop = ClosestObject.GetComponent <ResourceDrop>();
             return(true);
             //haveInstructionsImage = true;
         }
         else if (ClosestObject.GetComponent <ItemDrop>() != null)
         {
             NearbyItemDrop = ClosestObject.GetComponent <ItemDrop>();
             return(true);
             //haveInstructionsImage = true;
         }
     }
     return(false);
 }
Esempio n. 12
0
    // Check whether the nearby object can be set on fire
    private void SetOnFire()
    {
        if (ClosestObject == null)
        {
            return;
        }
        if (ClosestObject.GetComponent <ResourceMine>() != null)
        {
            NearbyResourceMine = ClosestObject.GetComponent <ResourceMine>();
        }
        else if (ClosestObject.GetComponent <ResourceDrop>() != null)
        {
            NearbyResourceDrop = ClosestObject.GetComponent <ResourceDrop>();
        }
        else if (ClosestObject.GetComponent <Campfire>() != null)
        {
            NearbyCampfire = ClosestObject.GetComponent <Campfire>();
        }

        if (NearbyResourceMine != null && NearbyResourceMine.CanBeSetOnFire)
        {
            //SFX: fire
            ActivateFirePrefab(NearbyResourceMine.gameObject, false);
            NearbyResourceMine.IsOnFire = true;
        }
        else if (NearbyResourceDrop != null && NearbyResourceDrop.CanBeSetOnFire)
        {
            //SFX: fire
            ActivateFirePrefab(NearbyResourceDrop.gameObject, false);
            NearbyResourceDrop.IsOnFire = true;
        }
        else if (NearbyCampfire != null && NearbyCampfire)
        {
            //SFX: fire
            ActivateFirePrefab(NearbyCampfire.gameObject, true);
            NearbyCampfire.IsOnFire = true;
            HideInstructionsSprite();
        }
    }
Esempio n. 13
0
 private void OnInteractedWith(Collider2D other)
 {
     if (other.name.Contains("Downstairs"))  // this is bad lol
     {
         DungeonManager.instance.GoDeeper();
     }
     else if (other.GetComponent <FoodDrop>() != null)
     {
         FoodDrop whatIGot = other.GetComponent <FoodDrop>();
         ResourceLocator.instance.PlayerPickedUpFood(whatIGot.foodObject);
         Destroy(other.gameObject);
     }
     else if (other.GetComponent <ResourceDrop>())
     {
         ResourceDrop r = other.GetComponent <ResourceDrop>();
         ResourceLocator.instance.PlayerGotResource(r.ResourceType, r.Amount);
         Destroy(other.gameObject);
     }
     else if (other.name.Contains("Upstairs"))
     {
         DungeonHUD.instance.ShowGoToCity();
     }
 }
Esempio n. 14
0
    public virtual void SetProperties(SimpleJSON.JSONClass N)
    {
//		return;
//		Debug.Log("set prop:"+N.ToString());
        if (N.GetKeys().Contains(uuidKey))
        {
            SetUuid("setprop", N[uuidKey].AsInt);
//			Debug.Log("just set my uuid key:"+N[uuidKey].AsInt);
        }
        ResourceDrop rd = GetComponentInChildren <ResourceDrop>();

        if (rd && N.GetKeys().Contains(ResourceDrop.key))
        {
//			Debug.Log("set prop resource:"+N.ToString());
            rd.SetProperties(N);
        }
        if (N.GetKeys().Contains(JsonUtil.scaleKey))
        {
//			Debug.Log("set scale on: "+myName+", "+N[JsonUtil.scaleKey].AsInt);
//			name += " scaled.";
            transform.localScale     = JsonUtil.GetScaleFromInt(N[JsonUtil.scaleKey].AsInt);
            scaleSetFromInstanceLoad = true;
        }
        UEO_ScaleManipulator cs = GetComponentInChildren <UEO_ScaleManipulator>();

        if (cs && N.GetKeys().Contains(UEO_ScaleManipulator.key))
        {
            int x = MathUtils.IntParse(N[UEO_ScaleManipulator.key][UEO_ScaleManipulator.keyX].Value);
            int y = MathUtils.IntParse(N[UEO_ScaleManipulator.key][UEO_ScaleManipulator.keyY].Value);
            int z = MathUtils.IntParse(N[UEO_ScaleManipulator.key][UEO_ScaleManipulator.keyZ].Value);
            cs.transform.localScale = new Vector3(x, y, z);
            cs.UpdateSize(x, y, z);
            //			if (cloneObject) cloneObject.transform.localScale = transform.localScale;
        }

        if (N.GetKeys().Contains(UEO_ColorCycler.colorManipulatorKey))
        {
            UEO_ColorCycler cc = GetComponentInChildren <UEO_ColorCycler>();
            if (cc)
            {
                cc.SetProperties(N);
            }
        }


        if (N.GetKeys().Contains(UEO_ObjectCycler.objectIndexKey))
        {
            UEO_ObjectCycler cc = GetComponentInChildren <UEO_ObjectCycler>();
            if (cc)
            {
                cc.SetProperties(N);
            }
        }

        if (N.GetKeys().Contains(tagsKey))
        {
            if (N[tagsKey].Value.Length > 0)
            {
                myTags.AddRange(N[tagsKey].Value.Split(','));
//				Debug.Log("<color=#f0f>addtag:</color>"+N[tagsKey].Value);
            }
//			Debug.Log("tags!:"+tags+", json val:"+N[tagsKey].ToString());
        }
        else
        {
//			print("no tagskey on:"+myName);
        }

        PickUppableObject pip = GetComponent <PickUppableObject>();

        if (pip)
        {
            // Vadim todo add Interface IMySetProperties?
            pip.SetProperties(N);
        }
    }
Esempio n. 15
0
    private void InstantiateDungeon(DungeonObject TheDungeon)
    {
        foreach (Vector2 WallPosition in TheDungeon.WallPositions)
        {
            DungeonTile dt = Instantiate(DungeonWall, WallPosition, Quaternion.identity).GetComponent <DungeonTile>();
            m_AllTiles.Add(dt);
        }

        foreach (Vector2 GroundPosition in TheDungeon.GroundPositions)
        {
            DungeonTile dt = Instantiate(DungeonGround, GroundPosition, Quaternion.identity).GetComponent <DungeonTile>();
            m_AllTiles.Add(dt);
        }

        DungeonTile up = Instantiate(Upstairs, TheDungeon.UpstairsPosition, Quaternion.identity).GetComponent <DungeonTile>();

        m_AllTiles.Add(up);

        DungeonTile down = Instantiate(Downstairs, TheDungeon.DownstairsPosition, Quaternion.identity).GetComponent <DungeonTile>();

        m_AllTiles.Add(down);

        DungeonTile extra = Instantiate(DungeonGround, TheDungeon.StartPosition, Quaternion.identity).GetComponent <DungeonTile>();

        m_AllTiles.Add(extra);

        Hero theHero = FindObjectOfType <Hero>();

        theHero.InitializeHero();
        theHero.UpdatePosition(TheDungeon.StartPosition);

        foreach (DungeonTile dt in m_AllTiles)
        {
            Debug.Log("Initializing all Tiles...");
            dt.InitializeTile();
        }

        FindObjectOfType <FourthDimension.Roguelike.FieldOfView>().InitializeFieldOfView(TheDungeon.StartPosition);

        List <Vector3> PossiblePositions = new List <Vector3>();

        foreach (DungeonTile dt in m_AllTiles)
        {
            if (!dt.IsVisible && !dt.IsWall)
            {
                PossiblePositions.Add(dt.transform.position);
            }
        }

        if (Random.value < 0.35f)   // 35% of spawning gold on the floor
        {
            Debug.Log("Spawned gold!");

            Vector3 Position = PossiblePositions.RandomOrDefault();
            PossiblePositions.Remove(Position);

            ResourceDrop goldDrop = Instantiate(ResourceLocator.instance.GoldPrefab, Position, Quaternion.identity).GetComponent <ResourceDrop>();
            goldDrop.Amount = Random.Range(5, 15);
        }

        if (Random.value < 0.1f)  // 10% of spawning a potion
        {
            Debug.Log("Spawned a potion!");

            Vector3 Position = PossiblePositions.RandomOrDefault();
            Instantiate(ResourceLocator.instance.PotionPrefab, Position, Quaternion.identity);
        }
    }
Esempio n. 16
0
    private void OnTriggerExit2D(Collider2D col)
    {
        if (AllInstructionsObjectsColliders.Contains(col.gameObject))
        {
            //GetClosestObject("Exit");
            AllInstructionsObjectsColliders.Remove(col.gameObject);
            if (ClosestObject != null && ClosestObject == col.gameObject)
            {
                HideInstructionsSprite();
                if (ClosestObject.GetComponent <ResourceMine>() != null)
                {
                    NearbyResourceMine = null;
                }
                else if (ClosestObject.GetComponent <ResourceDrop>() != null)
                {
                    NearbyResourceDrop = null;
                }
                else if (ClosestObject.GetComponent <ItemDrop>() != null)
                {
                    NearbyItemDrop = null;
                }
                else if (ClosestObject.GetComponent <Campfire>() != null)
                {
                    NearbyCampfire = null;
                }
                ClosestObject = null;
            }

            /*if (col.transform.Find("Instructions Image") != null)
             * {
             *  if (_instructionsToggled.Contains(col.transform.Find("Instructions Image").gameObject))
             *      _instructionsToggled.Remove(ClosestObject.transform.Find("Instructions Image").gameObject);
             *  col.gameObject.transform.Find("Instructions Image").gameObject.SetActive(false);
             * }*/
            //HideInstructionsSprite();
        }

        /*if (col.GetComponent<ResourceMine>() != null)
         * {
         *  if (NearbyResourceMine == col.GetComponent<ResourceMine>())
         *  {
         *      NearbyResourceMine = null;
         *  }
         * }
         * else if (col.GetComponent<ResourceDrop>() != null)
         * {
         *  if (NearbyResourceDrop == col.GetComponent<ResourceDrop>())
         *  {
         *      NearbyResourceDrop = null;
         *  }
         * }
         * else if (col.GetComponent<ItemDrop>() != null)
         * {
         *  if (NearbyItemDrop == col.GetComponent<ItemDrop>())
         *  {
         *      NearbyItemDrop = null;
         *  }
         * }
         * else if (col.GetComponent<Campfire>() != null)
         * {
         *  if (NearbyCampfire == col.GetComponent<Campfire>())
         *  {
         *      NearbyCampfire = null;
         *  }
         * }*/
    }
Esempio n. 17
0
 public void Raise(ResourceDrop newResourceDrop)
 {
     this.resourceDrop = newResourceDrop;
     this.Raise();
 }
Esempio n. 18
0
 internal void AddItem(ResourceDrop itemDropped)
 {
     Inventory.TryGetValue(itemDropped.Name, out var amount);
     Inventory[itemDropped.Name] = ++amount;
 }
Esempio n. 19
0
    private void InteractWithMine(ResourceMine mine)
    {
        HideInstructionsSprite();
        //SFX: pickaxe swing
        int amountmountOfDrop = mine.Amount;

        if (mine.BigMine)
        {
            amountmountOfDrop *= 2;
        }
        for (int i = 0; i < amountmountOfDrop; i++)
        {
            int          randomNumber    = Random.Range(-3, 4);
            Vector3      positionToSpawn = new Vector3(mine.transform.position.x + randomNumber, mine.transform.position.y + randomNumber, mine.transform.position.z);
            ResourceDrop ResourceDrop    = Instantiate(ResourceDropPrefab, positionToSpawn, Quaternion.identity).GetComponent <ResourceDrop>();

            ResourceDrop.Type = mine.Type;
            if (ResourceDrop.Type == Resource.ResourceType.Wood || ResourceDrop.Type == Resource.ResourceType.Leaf)
            {
                ResourceDrop.CanBeSetOnFire = true;
            }
            ResourceDrop.GetComponent <SpriteRenderer>().sprite = Resources.Load <Sprite>("Sprites/" + mine.Type.ToString());
            ResourceDrop.Consubamle = mine.ConsumableDrop;
            if (ResourceDrop.Consubamle)
            {
                ResourceDrop.EffectOnPlayer = mine.EffectOnPlayer;
            }
        }
        _firstInstruction  = true;
        NearbyResourceMine = null;
        if (mine.WillBeDestroyed)
        {
            Destroy(mine.gameObject);
        }
        else if (mine.WillChangeSprite)
        {
            mine.GetComponent <SpriteRenderer>().sprite = mine.SpriteToChangeTo;
            mine.CanBeCollected = false;
        }
        if (mine.Type2 != Resource.ResourceType.None)
        {
            for (int i = 0; i < amountmountOfDrop; i++)
            {
                int          randomNumber    = Random.Range(-1, 2);
                Vector3      positionToSpawn = new Vector3(mine.transform.position.x + randomNumber, mine.transform.position.y + randomNumber, mine.transform.position.z);
                ResourceDrop ResourceDrop    = Instantiate(ResourceDropPrefab, positionToSpawn, Quaternion.identity).GetComponent <ResourceDrop>();

                ResourceDrop.Type = mine.Type2;
                if (ResourceDrop.Type == Resource.ResourceType.Wood || ResourceDrop.Type == Resource.ResourceType.Leaf)
                {
                    ResourceDrop.CanBeSetOnFire = true;
                }
                ResourceDrop.GetComponent <SpriteRenderer>().sprite = Resources.Load <Sprite>("Sprites/" + mine.Type.ToString());
                ResourceDrop.Consubamle = mine.ConsumableDrop;
                if (ResourceDrop.Consubamle)
                {
                    ResourceDrop.EffectOnPlayer = mine.EffectOnPlayer;
                }
            }
            if (mine.WillBeDestroyed)
            {
                Destroy(mine.gameObject);
            }
            else if (mine.WillChangeSprite)
            {
                mine.GetComponent <SpriteRenderer>().sprite = mine.SpriteToChangeTo;
                mine.CanBeCollected = false;
            }
        }
    }