public void InitLootBag()
        {
            Object[] lootBagObjects = Resources.LoadAll("LootBags");
            GameInstance.Singleton.LootBagEntities = new Dictionary <string, LootBagEntity>();

            HashSet <LiteNetLibIdentity> spawnablePrefabs = new HashSet <LiteNetLibIdentity>(Assets.spawnablePrefabs);

            foreach (Object lootBagObject in lootBagObjects)
            {
                GameObject    lootBagGameObject = lootBagObject as GameObject;
                LootBagEntity lootBagEntity     = lootBagGameObject.GetComponent <LootBagEntity>();
                if (lootBagEntity == null)
                {
                    continue;
                }

                spawnablePrefabs.Add(lootBagEntity.Identity);
                GameInstance.AddBuildingEntities(lootBagEntity);

                GameInstance.Singleton.LootBagEntities.Add(lootBagObject.name, lootBagEntity);
            }

            Assets.spawnablePrefabs = new LiteNetLibIdentity[spawnablePrefabs.Count];
            spawnablePrefabs.CopyTo(Assets.spawnablePrefabs);
        }
Beispiel #2
0
        /// <summary>
        /// Event that occurs on death. Used primarily to trigger dropping of loot bag.
        /// </summary>
        protected virtual void OnDeath()
        {
            characterDB = this.GetDatabase();
            if (characterDB == null)
            {
                Debug.Log("character DB is null");
                return;
            }

            if (!characterDB.useLootBag)
            {
                return;
            }

            // Determine which loot bag entity to use based on character DB.
            switch (characterDB.lootBagEntity)
            {
            case LootBagEntitySelection.Visible:
                if (GameInstance.Singleton.LootBagEntities.ContainsKey(visibleLootBagName))
                {
                    lootBagEntity = GameInstance.Singleton.LootBagEntities[visibleLootBagName];
                }
                break;

            case LootBagEntitySelection.Invisible:
                if (GameInstance.Singleton.LootBagEntities.ContainsKey(invisibleLootBagName))
                {
                    lootBagEntity = GameInstance.Singleton.LootBagEntities[invisibleLootBagName];
                }
                break;

            case LootBagEntitySelection.Override:
                lootBagEntity = characterDB.lootBagEntityOverride;
                break;
            }

            DropLootBag();

            // If character is a monster, set body destroy delay according to character DB settings.
            BaseMonsterCharacterEntity bmce = this as BaseMonsterCharacterEntity;

            if (bmce != null && characterDB is MonsterCharacter)
            {
                var monsterDB = characterDB as MonsterCharacter;
                if (monsterDB != null && monsterDB.syncDestroyDelayWithBody)
                {
                    bmce.SetDestroyDelay(monsterDB.lootBagDestroyDelay);
                }
            }
        }
Beispiel #3
0
        /// <summary>
        /// Creates the loot bag entity building and configures it according to configuration settings.
        /// </summary>
        /// <param name="position">position in gameworld to spawn loot bag entity</param>
        /// <param name="rotation">rotation to use for lootbag entity</param>
        /// <param name="lootItems">items to place on lootbag</param>
        protected void CreateLootBag(Vector3 position, Quaternion rotation, List <CharacterItem> lootItems)
        {
            BuildingEntity buildingEntity;

            if (!GameInstance.BuildingEntities.TryGetValue(lootBagEntity.EntityId, out buildingEntity))
            {
                return;
            }

            if (!(buildingEntity is LootBagEntity))
            {
                return;
            }

            string creatorName = EntityTitle;

            if (this is BasePlayerCharacterEntity)
            {
                creatorName = CharacterName;
            }

            BuildingSaveData bsd = new BuildingSaveData();

            bsd.Id              = GenericUtils.GetUniqueId();
            bsd.ParentId        = string.Empty;
            bsd.EntityId        = buildingEntity.EntityId;
            bsd.CurrentHp       = buildingEntity.MaxHp;
            bsd.RemainsLifeTime = buildingEntity.LifeTime;
            bsd.Position        = position;
            bsd.Rotation        = rotation;
            bsd.CreatorId       = Id;
            bsd.CreatorName     = creatorName;
            LootBagEntity lbe = CurrentGameManager.CreateBuildingEntity(bsd, false) as LootBagEntity;

            lbe.SetOwnerEntity(this);
            lbe.AddItems(lootItems).Forget();
            lbe.SetDestroyDelay(characterDB.lootBagDestroyDelay);
        }