Exemple #1
0
        private void GenerateLoot(ILootable lootable)
        {
            LootConfig.LootDropDef lootDropDef = lootable._lootDropDef;

            List <LootConfig.ProbabilityDef> probabilities = lootDropDef.probabilities;

            probabilities.Sort(LootUtil.CompareLootByProbability);

            int   lootToDrop = LootUtil.GetLootDropCount(lootDropDef);
            float totalSum   = LootUtil.GetTotalSum(probabilities);

            for (int i = 0; i < lootToDrop; i++)
            {
                Loot.Rarity        rarity  = LootUtil.GetWeightedRarity(probabilities, totalSum);
                LootConfig.LootDef lootDef = _lootConfig.GetLootDef(rarity);
                int bucket = Random.Range(0, lootDef.lootItems.Count);
                LootConfig.LootItemDef itemDef = lootDef.lootItems[bucket];
                string    key  = Storeable.GetCachedStoreableKey(itemDef.type);
                ILootItem item = _lootPool.GetPooledObject(key).GetComponent <ILootItem>();
                if (item != null)
                {
                    item.Init(lootable, _playerCombatSystem.playerController.transform, lootDef, _lootConfig, itemDef);
                }
                else
                {
                    Debug.LogError("Item of type " + key + " does not implement  ILootItem");
                }
            }
        }
Exemple #2
0
        public void Init()
        {
            //Init Loot Pooler
            GameObject pool = GameObject.FindGameObjectWithTag("ScenePool");

            if (!pool)
            {
                Debug.LogError("NO SCENE POOL TRANSFORM FOUND IN SCENE");
            }
            _lootPool = new GenericPooler(pool ? pool.transform : null);


            List <LootConfig.LootDef> lootDefs = _lootConfig.lootDefs;

            for (int i = 0; i < lootDefs.Count; i++)
            {
                LootConfig.LootDef            def   = lootDefs[i];
                List <LootConfig.LootItemDef> items = def.lootItems;
                int warmAmount = def.pooledWarmAmount;
                for (int j = 0; j < items.Count; j++)
                {
                    LootConfig.LootItemDef item = items[j];
                    string type = Storeable.GetCachedStoreableKey(item.type);
                    _lootPool.InitPool(type, warmAmount, item.prefab);
                }
            }

            _dispatcher.AddListener(GameplayEventType.ENEMY_KILLED, OnEnemyDestroyed);
        }
Exemple #3
0
 public void update_storeable_resource_UI(Storeable s)
 {
     // Trigger resource property UI updates by setting values to themselves.
     foreach (string resource in s.resources.Keys)
     {
         update_stat_text(s.ID, resource, s.get_res(resource), s.get_sum_storeable_resources(), s.capacity);
     }
 }
Exemple #4
0
 public SStoreableResources(Storeable s)
 {
     light         = s.get_res(Storeable.LIGHT);
     unity         = s.get_res(Storeable.UNITY);
     star_crystals = s.get_res(Storeable.STAR_CRYSTALS);
     minerals      = s.get_res(Storeable.MINERALS);
     arelics       = s.get_res(Storeable.ARELICS);
     erelics       = s.get_res(Storeable.ERELICS);
     mrelics       = s.get_res(Storeable.MRELICS);
 }
Exemple #5
0
        public void InsertValue()
        {
            int       value     = 2;
            Storeable storeable = new Storeable(value);

            repository.Save(storeable);
            var result = repository.Get(value);

            Assert.AreEqual(result.Id, value);
        }
Exemple #6
0
        public void TestRepositorySave_ReturnStorable()
        {
            Storeable <int> storeable = new Storeable <int>()
            {
                Id = 3
            };

            repository = new Repository <Storeable <int>, int>();
            repository.Save(storeable);
            Assert.AreEqual(storeable, repository.Get(3));
        }
        public void Update_Test()
        {
            _repository.Save(_firstItem);
            var updatedFirstItem = new Storeable {
                Id = 1, Name = "UpdatedFirstItem"
            };

            _repository.Update(1, updatedFirstItem);

            var actual = _repository.All();

            Assert.IsTrue(actual.Count() == 1);
            Assert.IsTrue(actual.First().Id == updatedFirstItem.Id);
            Assert.IsTrue(actual.First().Name == updatedFirstItem.Name);
        }
        public void All_ReturnsItems_FromCache()
        {
            //Arrange
            CacheRepository <T>      myCacheRepository      = new CacheRepository <T>(new List <T>());
            BusinessLogicService <T> myBusinessLogicService = new BusinessLogicService <T>(myCacheRepository);

            var storeable = new Storeable {
                Description = "i1", Id = 1, StoreId = 1
            };

            myBusinessLogicService.Save((T)Convert.ChangeType(storeable, typeof(T)));

            var resultItems = myBusinessLogicService.All();

            Assert.IsNotNull(resultItems);
            //Assert.AreEqual(1, resultItems.Count());
        }
Exemple #9
0
        public void TestRepositoryGetAll_ReturnList()
        {
            Storeable <int> storeable1 = new Storeable <int>()
            {
                Id = 2
            };
            Storeable <int> storeable2 = new Storeable <int>()
            {
                Id = 3
            };
            Storeable <int> storeable3 = new Storeable <int>()
            {
                Id = 4
            };

            repository = new Repository <Storeable <int>, int>();
            repository.Save(storeable1);
            repository.Save(storeable2);
            repository.Save(storeable3);
            var equatable = repository.GetAll().ToList();

            Assert.IsTrue(equatable.Count() == 3);
        }