Esempio n. 1
0
        private void GiveWeapons()
        {
            var player    = this.world.ConsolePlayer;
            var inventory = player.Entity.GetComponent <InventoryComponent>();

            foreach (var entityInfo in EntityInfo.WithComponent <WeaponComponentInfo>())
            {
                if (inventory.Items.All(ownedItem => ownedItem.Info != entityInfo))
                {
                    inventory.Items.Add(EntityInfo.Create(entityInfo));
                }
            }

            player.Backpack = true;

            foreach (var entityInfo in EntityInfo.WithComponent <AmmoComponentInfo>())
            {
                if (inventory.Items.All(ownedItem => ownedItem.Info != entityInfo))
                {
                    inventory.Items.Add(EntityInfo.Create(entityInfo));
                }
            }

            inventory.Items.ForEach(
                entity =>
            {
                var ammoComponent = entity.GetComponent <AmmoComponent>();

                if (ammoComponent != null)
                {
                    ammoComponent.Amount = ammoComponent.Info.Maximum;
                }
            }
                );
        }
Esempio n. 2
0
        private void GiveWeapons()
        {
            var player    = this.world.Options.Player;
            var inventory = player.Entity.GetComponent <InventoryComponent>();

            foreach (var entityInfo in EntityInfo.WithComponent <WeaponComponentInfo>())
            {
                inventory.TryAdd(EntityInfo.Create(this.world, entityInfo));
            }

            player.Backpack = true;

            foreach (var entityInfo in EntityInfo.WithComponent <AmmoComponentInfo>())
            {
                inventory.TryAdd(EntityInfo.Create(this.world, entityInfo));
            }

            foreach (var entity in inventory.Items.Where(item => item.GetComponent <AmmoComponent>() != null))
            {
                var itemComponent = entity.GetComponent <ItemComponent>();

                if (itemComponent != null)
                {
                    itemComponent.Amount = itemComponent.Info.StackSize;
                }
            }
        }
Esempio n. 3
0
        public void Init()
        {
            Entities = new EntityInfoCollection();
            var factory = new Mock <IFieldPropertyFactory>();

            Entity = EntityInfo.Create(factory.Object, Entities, typeof(Author));
        }
Esempio n. 4
0
        public void SetUp()
        {
            var entityCollection = new EntityInfoCollection();
            var factory          = new Mock <IFieldPropertyFactory>();

            BookVersionEntityInfo = EntityInfo.Create(factory.Object, entityCollection, typeof(BookVersion));
        }
Esempio n. 5
0
        /// <summary>
        /// Give the weapon to the player.
        /// </summary>
        /// <param name="dropped">
        /// True if the weapons is dropped by a monster.
        /// </param>
        public bool GiveWeapon(Player player, string weaponName, bool dropped)
        {
            var entityInfo            = EntityInfo.OfName(weaponName);
            var inventory             = player.Entity.GetComponent <InventoryComponent>();
            var entity                = inventory.Items.FirstOrDefault(entity => entity.Info == entityInfo);
            var requiresAmmoComponent = entity?.GetComponent <RequiresAmmoComponent>();

            if (this.world.Options.NetGame && (this.world.Options.Deathmatch != 2) && !dropped)
            {
                // Leave placed weapons forever on net games.
                if (entity != null)
                {
                    return(false);
                }

                entity = EntityInfo.Create(entityInfo);
                requiresAmmoComponent = entity?.GetComponent <RequiresAmmoComponent>();

                player.BonusCount += ItemPickup.bonusAdd;
                inventory.Items.Add(entity);

                if (requiresAmmoComponent != null)
                {
                    this.GiveAmmo(player, requiresAmmoComponent.Info.Ammo, this.world.Options.Deathmatch != 0 ? 5 : 2);
                }

                player.PendingWeapon = entity;

                if (player == this.world.ConsolePlayer)
                {
                    this.world.StartSound(player.Mobj, Sfx.WPNUP, SfxType.Misc);
                }

                return(false);
            }

            bool gaveWeapon;

            if (entity != null)
            {
                gaveWeapon = false;
            }
            else
            {
                gaveWeapon = true;
                entity     = EntityInfo.Create(entityInfo);
                inventory.Items.Add(entity);
                player.PendingWeapon = entity;
            }

            var gaveAmmo = false;

            if (requiresAmmoComponent != null)
            {
                gaveAmmo = this.GiveAmmo(player, requiresAmmoComponent.Info.Ammo, dropped ? 1 : 2);
            }

            return(gaveWeapon || gaveAmmo);
        }
Esempio n. 6
0
        public void GetCreateSqlQuery_ShouldRightFormated()
        {
            var entityInfo = EntityInfo.Create(FieldPropertyFactory, new EntityInfoCollection(), typeof(IndexedClass));

            Assert.AreEqual("CREATE INDEX ORM_IDX_IndexedClass_MonIndex_ASC ON [IndexedClass] ([Id], [Searchable], [Unique], [SearchableAndUnique] ASC)", entityInfo.Indexes[0].GetCreateSqlQuery());
            Assert.AreEqual("CREATE INDEX ORM_IDX_IndexedClass_Searchable_ASC ON [IndexedClass] ([Searchable] ASC)", entityInfo.Indexes[1].GetCreateSqlQuery());
            Assert.AreEqual("CREATE UNIQUE INDEX ORM_IDX_IndexedClass_Unique_ASC ON [IndexedClass] ([Unique] ASC)", entityInfo.Indexes[2].GetCreateSqlQuery());
            Assert.AreEqual("CREATE UNIQUE INDEX ORM_IDX_IndexedClass_SearchableAndUnique_ASC ON [IndexedClass] ([SearchableAndUnique] ASC)", entityInfo.Indexes[3].GetCreateSqlQuery());
        }
Esempio n. 7
0
        public void CreateEntity_PrimaryKeyShouldInitialize()
        {
            var entities   = new EntityInfoCollection();
            var factory    = new Mock <IFieldPropertyFactory>();
            var entityInfo = EntityInfo.Create(factory.Object, entities, typeof(Book));

            Assert.IsNotNull(entityInfo.PrimaryKey);
            Assert.AreEqual("ORM_PK_Book", entityInfo.PrimaryKey.ConstraintName);
        }
Esempio n. 8
0
        public bool Update(TEntity instance, IDbTransaction ts = null)
        {
            if (_entityInfo == null)
            {
                _entityInfo = EntityInfo <TEntity> .Create();
            }

            return(UpdateFields(instance, _entityInfo.PropertyInfos.Where(x => !x.IsKey).Select(x => x.ColumnName).ToArray(), ts));
        }
Esempio n. 9
0
        public int BulkUpdate(List <TEntity> instances, IDbTransaction ts = null)
        {
            if (_entityInfo == null)
            {
                _entityInfo = EntityInfo <TEntity> .Create();
            }

            return(BulkUpdateWithFields(instances, _entityInfo.PropertyInfos.Where(x => !x.IsKey).Select(x => x.ColumnName).ToArray(), ts));
        }
Esempio n. 10
0
        public World(CommonResource resorces, GameOptions options, DoomGame game)
        {
            this.WorldEntity = EntityInfo.Create(this, EntityInfo.OfType <DoomEngine.Game.Entities.World>());

            this.options = options;
            this.game    = game;
            this.random  = game != null ? game.Random : new DoomRandom();

            this.map              = new Map(resorces, this);
            this.thinkers         = new Thinkers(this);
            this.specials         = new Specials(this);
            this.thingAllocation  = new ThingAllocation(this);
            this.thingMovement    = new ThingMovement(this);
            this.thingInteraction = new ThingInteraction(this);
            this.mapCollision     = new MapCollision(this);
            this.mapInteraction   = new MapInteraction(this);
            this.pathTraversal    = new PathTraversal(this);
            this.hitscan          = new Hitscan(this);
            this.visibilityCheck  = new VisibilityCheck(this);
            this.sectorAction     = new SectorAction(this);
            this.playerBehavior   = new PlayerBehavior(this);
            this.itemPickup       = new ItemPickup(this);
            this.weaponBehavior   = new WeaponBehavior(this);
            this.monsterBehavior  = new MonsterBehavior(this);
            this.lightingChange   = new LightingChange(this);
            this.autoMap          = new AutoMap(this);
            this.cheat            = new Cheat(this);

            options.IntermissionInfo.ParTime = 180;

            options.Player.KillCount   = 0;
            options.Player.SecretCount = 0;
            options.Player.ItemCount   = 0;

            // Initial height of view will be set by player think.
            options.Player.ViewZ = Fixed.Epsilon;

            this.totalKills   = 0;
            this.totalItems   = 0;
            this.totalSecrets = 0;

            this.LoadThings();

            this.statusBar = new StatusBar(this);

            this.specials.SpawnSpecials();

            this.levelTime    = 0;
            this.doneFirstTic = false;
            this.secretExit   = false;
            this.completed    = false;

            this.validCount = 0;

            options.Music.StartMusic(Map.GetMapBgm(options), true);
        }
Esempio n. 11
0
        public void CreateEntity_IndexShouldInitialize()
        {
            var entityInfo = EntityInfo.Create(FieldPropertyFactory, new EntityInfoCollection(), typeof(IndexedClass));

            Assert.AreEqual(4, entityInfo.Indexes.Count);
            Assert.AreEqual("ORM_IDX_IndexedClass_MonIndex_ASC", entityInfo.Indexes[0].GetNameInStore());
            Assert.AreEqual("ORM_IDX_IndexedClass_Searchable_ASC", entityInfo.Indexes[1].GetNameInStore());
            Assert.AreEqual("ORM_IDX_IndexedClass_Unique_ASC", entityInfo.Indexes[2].GetNameInStore());
            Assert.AreEqual("ORM_IDX_IndexedClass_SearchableAndUnique_ASC", entityInfo.Indexes[3].GetNameInStore());
        }
Esempio n. 12
0
        public void Setup()
        {
            Store    = new Mock <ISqlDataStore>();
            Observer = new Mock <IOrmObserver>();
            var entities = new EntityInfoCollection();

            EntityInfo.Create(new Mock <IFieldPropertyFactory>().Object, entities, typeof(ConcreteEntity));
            Store.Setup(_ => _.Entities).Returns(entities);
            Repository = new Repository <ConcreteEntity, ConcreteEntity>(Store.Object);
        }
Esempio n. 13
0
        public void CreateTombstone_PrimaryKeyShouldHaveKeySchemToNone()
        {
            var entities            = new EntityInfoCollection();
            var factory             = new Mock <IFieldPropertyFactory>();
            var entityInfo          = EntityInfo.Create(factory.Object, entities, typeof(EntitySync));
            var entitySync          = SyncEntity.Create(entityInfo);
            var tombstoneEntityInfo = entitySync.CreateEntityTombstone();

            Assert.AreEqual(KeyScheme.None, tombstoneEntityInfo.PrimaryKey.KeyScheme);
        }
Esempio n. 14
0
        public void Reborn(World world)
        {
            world.Entities.Add(this.Entity = EntityInfo.Create <DoomEngine.Game.Entities.Player>(world));

            this.mobj        = null;
            this.playerState = PlayerState.Live;
            this.cmd.Clear();

            this.viewZ           = Fixed.Zero;
            this.viewHeight      = Fixed.Zero;
            this.deltaViewHeight = Fixed.Zero;
            this.bob             = Fixed.Zero;

            this.armorPoints = 0;
            this.armorType   = 0;

            Array.Clear(this.powers, 0, this.powers.Length);
            this.backpack = false;

            var inventory = this.Entity.GetComponent <InventoryComponent>();

            inventory.TryAdd(EntityInfo.Create <WeaponFists>(world));
            inventory.TryAdd(this.ReadyWeapon = this.PendingWeapon = EntityInfo.Create <WeaponPistol>(world));
            inventory.TryAdd(EntityInfo.Create <AmmoBullets>(world));

            // Don't do anything immediately.
            this.useDown    = true;
            this.attackDown = true;

            this.cheats = 0;

            this.refire = 0;

            this.message     = null;
            this.messageTime = 0;

            this.damageCount = 0;
            this.bonusCount  = 0;

            this.attacker = null;

            this.extraLight = 0;

            this.fixedColorMap = 0;

            this.colorMap = 0;

            foreach (var psp in this.playerSprites)
            {
                psp.Clear();
            }

            this.didSecret = false;
        }
Esempio n. 15
0
        public void CreateEntity_ForeignKeyShouldInitialize()
        {
            var entities = new EntityInfoCollection();
            var factory  = new Mock <IFieldPropertyFactory>();

            EntityInfo.Create(factory.Object, entities, typeof(Book));
            var entityInfo = EntityInfo.Create(factory.Object, entities, typeof(BookVersion));

            Assert.AreEqual(1, entityInfo.ForeignKeys.Count);
            Assert.AreEqual("ORM_FK_BookVersion_Book", entityInfo.ForeignKeys[0].ConstraintName);
        }
Esempio n. 16
0
        public void Init()
        {
            Entities = new EntityInfoCollection();
            var factory = new Mock <IFieldPropertyFactory>();

            Entity        = EntityInfo.Create(factory.Object, Entities, typeof(Author));
            SqlFactory    = new Mock <ISqlFactory>();
            FilterFactory = new FilterFactory(SqlFactory.Object, Entities);
            Params        = new List <IDataParameter>();
            SqlFactory.Setup(
                _ => _.AddParam(It.IsAny <object>(), Params)
                ).Returns(SqlValue);
        }
Esempio n. 17
0
        /// <summary>
        /// Give the weapon to the player.
        /// </summary>
        /// <param name="dropped">
        /// True if the weapons is dropped by a monster.
        /// </param>
        public bool GiveWeapon(Player player, string weaponName, bool dropped)
        {
            var weaponEntity          = EntityInfo.Create(this.world, EntityInfo.OfName(weaponName));
            var requiresAmmoComponent = weaponEntity.GetComponent <RequiresAmmoComponent>();

            var inventory  = player.Entity.GetComponent <InventoryComponent>();
            var gaveWeapon = inventory.TryAdd(weaponEntity);
            var gaveAmmo   = requiresAmmoComponent != null && this.GiveAmmo(player, requiresAmmoComponent.Info.Ammo, dropped ? 1 : 2);

            if (gaveWeapon)
            {
                player.PendingWeapon = weaponEntity;
            }

            return(gaveWeapon || gaveAmmo);
        }
Esempio n. 18
0
        public void Init()
        {
            var entityCollection = new EntityInfoCollection();
            var factory          = new Mock <IFieldPropertyFactory>();

            EntityInfo.Create(factory.Object, entityCollection, typeof(Author));
            EntityInfo.Create(factory.Object, entityCollection, typeof(Book));
            BookVersionEntityInfo = EntityInfo.Create(factory.Object, entityCollection, typeof(BookVersion));

            var dataStore  = new Mock <IDataStore>();
            var sqlFactory = new Mock <ISqlFactory>();
            var param      = new Mock <IDataParameter>();

            sqlFactory.Setup(_ => _.CreateParameter()).Returns(param.Object);
            dataStore.Setup(_ => _.SqlFactory).Returns(sqlFactory.Object);
            SqlQuery = new Selectable <Author>(dataStore.Object, entityCollection);
        }
Esempio n. 19
0
        private void FullAmmoAndKeys()
        {
            this.GiveWeapons();
            var player = this.world.Options.Player;

            player.ArmorType   = ItemPickup.IdkfaArmorClass;
            player.ArmorPoints = ItemPickup.IdkfaArmor;

            var inventory = player.Entity.GetComponent <InventoryComponent>();

            foreach (var entityInfo in EntityInfo.WithComponent <KeyComponentInfo>())
            {
                inventory.TryAdd(EntityInfo.Create(this.world, entityInfo));
            }

            player.SendMessage(DoomInfo.Strings.STSTR_KFAADDED);
        }
Esempio n. 20
0
        //private IDbTransaction _transaction;

        public BaseRepository(string dbName)
        {
            _entityInfo = EntityInfo <TEntity> .Create();

            if (dbName.IsEmpty())
            {
                throw new Exception(nameof(dbName));
            }
            _connectionInfo = ConnectionStringInfo.GetConnectionByName(dbName);
            if (_connectionInfo == null)
            {
                throw new Exception("Can not get connection info");
            }

            _connection = new MySqlConnection(_connectionInfo.Value);
            _connection.EnsureOpen();
            //_transaction = _connection.BeginTransaction();
        }
Esempio n. 21
0
        public bool Insert(TEntity entity, IDbTransaction ts = null)
        {
            using (_connection)
            {
                if (_entityInfo == null)
                {
                    _entityInfo = EntityInfo <TEntity> .Create();
                }

                var sql = CommandBuilder.CreateInsertCommand(_entityInfo);

                object dynamicObj = ReflectionHelper.DefineDynamicObject(entity, _entityInfo.PropertyInfos);

                _connection.Execute(sql, dynamicObj);
            }

            return(true);
        }
Esempio n. 22
0
        private void InternalShowEntity(int entityId, string entityAssetName, EntityGroup entityGroup, object entityInstance, bool isNewInstance, float duration, Type logicType, object userData)
        {
            Entity entity = CreateEntity(entityInstance, entityGroup, userData);

            if (entity == null)
            {
                throw new LufyException("Can not create entity in helper.");
            }

            EntityInfo entityInfo = EntityInfo.Create(entity);

            m_EntityInfos.Add(entityId, entityInfo);
            entityInfo.Status = EntityStatus.WillInit;
            entity.OnInit(entityId, entityAssetName, entityGroup, isNewInstance, logicType, userData);
            entityInfo.Status = EntityStatus.Inited;
            entityGroup.AddEntity(entity);
            entityInfo.Status = EntityStatus.WillShow;
            entity.OnShow(userData);
            entityInfo.Status = EntityStatus.Showed;
        }
Esempio n. 23
0
        private void InternalShowEntity(int entityId, string entityAssetName, EntityGroup entityGroup, object entityInstance, bool isNewInstance, float duration, object userData)
        {
            try
            {
                IEntity entity = m_EntityHelper.CreateEntity(entityInstance, entityGroup, userData);
                if (entity == null)
                {
                    throw new GameFrameworkException("Can not create entity in helper.");
                }

                EntityInfo entityInfo = EntityInfo.Create(entity);
                m_EntityInfos.Add(entityId, entityInfo);
                entityInfo.Status = EntityStatus.WillInit;
                entity.OnInit(entityId, entityAssetName, entityGroup, isNewInstance, userData);
                entityInfo.Status = EntityStatus.Inited;
                entityGroup.AddEntity(entity);
                entityInfo.Status = EntityStatus.WillShow;
                entity.OnShow(userData);
                entityInfo.Status = EntityStatus.Showed;

                if (m_ShowEntitySuccessEventHandler != null)
                {
                    ShowEntitySuccessEventArgs showEntitySuccessEventArgs = ShowEntitySuccessEventArgs.Create(entity, duration, userData);
                    m_ShowEntitySuccessEventHandler(this, showEntitySuccessEventArgs);
                    ReferencePool.Release(showEntitySuccessEventArgs);
                }
            }
            catch (Exception exception)
            {
                if (m_ShowEntityFailureEventHandler != null)
                {
                    ShowEntityFailureEventArgs showEntityFailureEventArgs = ShowEntityFailureEventArgs.Create(entityId, entityAssetName, entityGroup.Name, exception.ToString(), userData);
                    m_ShowEntityFailureEventHandler(this, showEntityFailureEventArgs);
                    ReferencePool.Release(showEntityFailureEventArgs);
                    return;
                }

                throw;
            }
        }
Esempio n. 24
0
        public int BulkInsert(List <TEntity> instances, IDbTransaction ts = null)
        {
            using (_connection)
            {
                if (_entityInfo == null)
                {
                    _entityInfo = EntityInfo <TEntity> .Create();
                }

                var command = CommandBuilder.CreateInsertCommand(_entityInfo);

                var insertObjs = new List <object>();
                foreach (var obj in instances)
                {
                    object dynamicObj = ReflectionHelper.DefineDynamicObject(obj, _entityInfo.PropertyInfos);
                    insertObjs.Add(dynamicObj);
                }

                int count = _connection.Execute(command, insertObjs, ts);

                return(count);
            }
        }
Esempio n. 25
0
        /// <summary>
        /// Give the player the ammo.
        /// </summary>
        /// <param name="amount">
        /// The number of clip loads, not the individual count (0 = 1/2 clip).
        /// </param>
        /// <returns>
        /// False if the ammo can't be picked up at all.
        /// </returns>
        public bool GiveAmmo(Player player, string ammoName, int amount)
        {
            var entityInfo = EntityInfo.OfName(ammoName);
            var inventory  = player.Entity.GetComponent <InventoryComponent>();

            var entity        = inventory.Items.FirstOrDefault(entity => entity.Info == entityInfo);
            var ammoComponent = entity?.GetComponent <AmmoComponent>();

            if (entity == null)
            {
                entity               = EntityInfo.Create(entityInfo);
                ammoComponent        = entity.GetComponent <AmmoComponent>();
                ammoComponent.Amount = 0;
                player.Entity.GetComponent <InventoryComponent>().Items.Add(entity);
            }

            if (ammoComponent.Amount == ammoComponent.Info.Maximum)
            {
                return(false);
            }

            if (amount != 0)
            {
                amount *= ammoComponent.Info.ClipSize;
            }
            else
            {
                amount = ammoComponent.Info.ClipSize / 2;
            }

            if (this.world.Options.Skill == GameSkill.Baby || this.world.Options.Skill == GameSkill.Nightmare)
            {
                amount *= 2;
            }

            var oldammo = ammoComponent.Amount;

            ammoComponent.Amount = Math.Min(ammoComponent.Amount + amount, ammoComponent.Info.Maximum);

            if (oldammo != 0)
            {
                return(true);
            }

            if (entity.Info is AmmoBullets)
            {
                if (player.ReadyWeapon.Info is WeaponFists)
                {
                    player.PendingWeapon = inventory.Items.FirstOrDefault(weapon => weapon.Info is WeaponChaingun)
                                           ?? inventory.Items.First(weapon => weapon.Info is WeaponPistol);
                }
            }
            else if (entity.Info is AmmoShells)
            {
                if (player.ReadyWeapon.Info is WeaponFists || player.ReadyWeapon.Info is WeaponPistol)
                {
                    player.PendingWeapon = inventory.Items.FirstOrDefault(weapon => weapon.Info is WeaponShotgun)
                                           ?? inventory.Items.FirstOrDefault(weapon => weapon.Info is WeaponSuperShotgun) ?? player.PendingWeapon;
                }
            }
            else if (entity.Info is AmmoCells)
            {
                if (player.ReadyWeapon.Info is WeaponFists || player.ReadyWeapon.Info is WeaponPistol)
                {
                    player.PendingWeapon = inventory.Items.FirstOrDefault(weapon => weapon.Info is WeaponPlasmagun) ?? player.PendingWeapon;
                }
            }
            else if (entity.Info is AmmoRockets)
            {
                if (player.ReadyWeapon.Info is WeaponFists)
                {
                    player.PendingWeapon = inventory.Items.FirstOrDefault(weapon => weapon.Info is WeaponRocketLauncher) ?? player.PendingWeapon;
                }
            }

            return(true);
        }
Esempio n. 26
0
        /// <summary>
        /// Check for item pickup.
        /// </summary>
        public void TouchSpecialThing(Mobj special, Mobj toucher)
        {
            var delta = special.Z - toucher.Z;

            if (delta > toucher.Height || delta < Fixed.FromInt(-8))
            {
                // Out of reach.
                return;
            }

            var sound  = Sfx.ITEMUP;
            var player = toucher.Player;

            // Dead thing touching.
            // Can happen with a sliding player corpse.
            if (toucher.Health <= 0)
            {
                return;
            }

            var healthComponent = player.Entity.GetComponent <Health>();

            // Identify by sprite.
            switch (special.Sprite)
            {
            // Armor.
            case Sprite.ARM1:
                if (!this.GiveArmor(player, ItemPickup.GreenArmorClass))
                {
                    return;
                }

                player.SendMessage(DoomInfo.Strings.GOTARMOR);

                break;

            case Sprite.ARM2:
                if (!this.GiveArmor(player, ItemPickup.BlueArmorClass))
                {
                    return;
                }

                player.SendMessage(DoomInfo.Strings.GOTMEGA);

                break;

            // Bonus items.
            case Sprite.BON1:
                healthComponent.Current++;

                if (healthComponent.Current > healthComponent.Info.Maximum)
                {
                    healthComponent.Current = healthComponent.Info.Maximum;
                }

                player.Mobj.Health = healthComponent.Current;
                player.SendMessage(DoomInfo.Strings.GOTHTHBONUS);

                break;

            case Sprite.BON2:
                // Can go over 100%.
                player.ArmorPoints++;

                if (player.ArmorPoints > Player.MaxArmor)
                {
                    player.ArmorPoints = Player.MaxArmor;
                }

                if (player.ArmorType == 0)
                {
                    player.ArmorType = ItemPickup.GreenArmorClass;
                }

                player.SendMessage(DoomInfo.Strings.GOTARMBONUS);

                break;

            case Sprite.SOUL:
                healthComponent.Current += ItemPickup.SoulsphereHealth;

                if (healthComponent.Current > healthComponent.Info.Maximum)
                {
                    healthComponent.Current = healthComponent.Info.Maximum;
                }

                player.Mobj.Health = healthComponent.Current;
                player.SendMessage(DoomInfo.Strings.GOTSUPER);
                sound = Sfx.GETPOW;

                break;

            case Sprite.MEGA:
                if (DoomApplication.Instance.IWad != "doom2" &&
                    DoomApplication.Instance.IWad != "freedoom2" &&
                    DoomApplication.Instance.IWad != "plutonia" &&
                    DoomApplication.Instance.IWad != "tnt")
                {
                    return;
                }

                healthComponent.Current = ItemPickup.MegasphereHealth;
                player.Mobj.Health      = healthComponent.Current;
                this.GiveArmor(player, ItemPickup.BlueArmorClass);
                player.SendMessage(DoomInfo.Strings.GOTMSPHERE);
                sound = Sfx.GETPOW;

                break;

            // Cards.
            // Leave cards for everyone.
            case Sprite.BKEY:
                if (player.Entity.GetComponent <InventoryComponent>().TryAdd(EntityInfo.Create <BlueCard>(this.world)))
                {
                    player.SendMessage(DoomInfo.Strings.GOTBLUECARD);
                }

                break;

            case Sprite.YKEY:
                if (player.Entity.GetComponent <InventoryComponent>().TryAdd(EntityInfo.Create <YellowCard>(this.world)))
                {
                    player.SendMessage(DoomInfo.Strings.GOTYELWCARD);
                }

                break;

            case Sprite.RKEY:
                if (player.Entity.GetComponent <InventoryComponent>().TryAdd(EntityInfo.Create <RedCard>(this.world)))
                {
                    player.SendMessage(DoomInfo.Strings.GOTREDCARD);
                }

                break;

            case Sprite.BSKU:
                if (player.Entity.GetComponent <InventoryComponent>().TryAdd(EntityInfo.Create <BlueSkull>(this.world)))
                {
                    player.SendMessage(DoomInfo.Strings.GOTBLUESKUL);
                }

                break;

            case Sprite.YSKU:
                if (player.Entity.GetComponent <InventoryComponent>().TryAdd(EntityInfo.Create <YellowSkull>(this.world)))
                {
                    player.SendMessage(DoomInfo.Strings.GOTYELWSKUL);
                }

                break;

            case Sprite.RSKU:
                if (player.Entity.GetComponent <InventoryComponent>().TryAdd(EntityInfo.Create <RedSkull>(this.world)))
                {
                    player.SendMessage(DoomInfo.Strings.GOTREDSKULL);
                }

                break;

            // Medikits, heals.
            case Sprite.STIM:
                if (!this.GiveHealth(player, 10))
                {
                    return;
                }

                player.SendMessage(DoomInfo.Strings.GOTSTIM);

                break;

            case Sprite.MEDI:
                if (!this.GiveHealth(player, 25))
                {
                    return;
                }

                if (healthComponent.Current < 25)
                {
                    player.SendMessage(DoomInfo.Strings.GOTMEDINEED);
                }
                else
                {
                    player.SendMessage(DoomInfo.Strings.GOTMEDIKIT);
                }

                break;

            // Power ups.
            case Sprite.PINV:
                if (!this.GivePower(player, PowerType.Invulnerability))
                {
                    return;
                }

                player.SendMessage(DoomInfo.Strings.GOTINVUL);
                sound = Sfx.GETPOW;

                break;

            case Sprite.PSTR:
                if (!this.GivePower(player, PowerType.Strength))
                {
                    return;
                }

                player.SendMessage(DoomInfo.Strings.GOTBERSERK);

                var fists = player.Entity.GetComponent <InventoryComponent>().Items.FirstOrDefault(weapon => weapon.Info is WeaponFists);

                if (fists != null && player.ReadyWeapon != fists)
                {
                    player.PendingWeapon = fists;
                }

                sound = Sfx.GETPOW;

                break;

            case Sprite.PINS:
                if (!this.GivePower(player, PowerType.Invisibility))
                {
                    return;
                }

                player.SendMessage(DoomInfo.Strings.GOTINVIS);
                sound = Sfx.GETPOW;

                break;

            case Sprite.SUIT:
                if (!this.GivePower(player, PowerType.IronFeet))
                {
                    return;
                }

                player.SendMessage(DoomInfo.Strings.GOTSUIT);
                sound = Sfx.GETPOW;

                break;

            case Sprite.PMAP:
                if (!this.GivePower(player, PowerType.AllMap))
                {
                    return;
                }

                player.SendMessage(DoomInfo.Strings.GOTMAP);
                sound = Sfx.GETPOW;

                break;

            case Sprite.PVIS:
                if (!this.GivePower(player, PowerType.Infrared))
                {
                    return;
                }

                player.SendMessage(DoomInfo.Strings.GOTVISOR);
                sound = Sfx.GETPOW;

                break;

            // Ammo.
            case Sprite.CLIP:
                if ((special.Flags & MobjFlags.Dropped) != 0)
                {
                    if (!this.GiveAmmo(player, nameof(AmmoBullets), 0))
                    {
                        return;
                    }
                }
                else
                {
                    if (!this.GiveAmmo(player, nameof(AmmoBullets), 1))
                    {
                        return;
                    }
                }

                player.SendMessage(DoomInfo.Strings.GOTCLIP);

                break;

            case Sprite.AMMO:
                if (!this.GiveAmmo(player, nameof(AmmoBullets), 5))
                {
                    return;
                }

                player.SendMessage(DoomInfo.Strings.GOTCLIPBOX);

                break;

            case Sprite.ROCK:
                if (!this.GiveAmmo(player, nameof(AmmoRockets), 1))
                {
                    return;
                }

                player.SendMessage(DoomInfo.Strings.GOTROCKET);

                break;

            case Sprite.BROK:
                if (!this.GiveAmmo(player, nameof(AmmoRockets), 5))
                {
                    return;
                }

                player.SendMessage(DoomInfo.Strings.GOTROCKBOX);

                break;

            case Sprite.CELL:
                if (!this.GiveAmmo(player, nameof(AmmoCells), 1))
                {
                    return;
                }

                player.SendMessage(DoomInfo.Strings.GOTCELL);

                break;

            case Sprite.CELP:
                if (!this.GiveAmmo(player, nameof(AmmoCells), 5))
                {
                    return;
                }

                player.SendMessage(DoomInfo.Strings.GOTCELLBOX);

                break;

            case Sprite.SHEL:
                if (!this.GiveAmmo(player, nameof(AmmoShells), 1))
                {
                    return;
                }

                player.SendMessage(DoomInfo.Strings.GOTSHELLS);

                break;

            case Sprite.SBOX:
                if (!this.GiveAmmo(player, nameof(AmmoShells), 5))
                {
                    return;
                }

                player.SendMessage(DoomInfo.Strings.GOTSHELLBOX);

                break;

            case Sprite.BPAK:
                if (!player.Backpack)
                {
                    // TODO Re-implement this!

                    /*for (var i = 0; i < (int) AmmoType.Count; i++)
                     * {
                     *      player.MaxAmmo[i] *= 2;
                     * }*/

                    player.Backpack = true;
                }

                foreach (var entityInfo in EntityInfo.WithComponent <AmmoComponentInfo>())
                {
                    this.GiveAmmo(player, entityInfo.Name, 1);
                }

                player.SendMessage(DoomInfo.Strings.GOTBACKPACK);

                break;

            // Weapons.
            case Sprite.BFUG:
                if (!this.GiveWeapon(player, nameof(WeaponBfg), false))
                {
                    return;
                }

                player.SendMessage(DoomInfo.Strings.GOTBFG9000);
                sound = Sfx.WPNUP;

                break;

            case Sprite.MGUN:
                if (!this.GiveWeapon(player, nameof(WeaponChaingun), (special.Flags & MobjFlags.Dropped) != 0))
                {
                    return;
                }

                player.SendMessage(DoomInfo.Strings.GOTCHAINGUN);
                sound = Sfx.WPNUP;

                break;

            case Sprite.CSAW:
                if (!this.GiveWeapon(player, nameof(WeaponChainsaw), false))
                {
                    return;
                }

                player.SendMessage(DoomInfo.Strings.GOTCHAINSAW);
                sound = Sfx.WPNUP;

                break;

            case Sprite.LAUN:
                if (!this.GiveWeapon(player, nameof(WeaponRocketLauncher), false))
                {
                    return;
                }

                player.SendMessage(DoomInfo.Strings.GOTLAUNCHER);
                sound = Sfx.WPNUP;

                break;

            case Sprite.PLAS:
                if (!this.GiveWeapon(player, nameof(WeaponPlasmagun), false))
                {
                    return;
                }

                player.SendMessage(DoomInfo.Strings.GOTPLASMA);
                sound = Sfx.WPNUP;

                break;

            case Sprite.SHOT:
                if (!this.GiveWeapon(player, nameof(WeaponShotgun), (special.Flags & MobjFlags.Dropped) != 0))
                {
                    return;
                }

                player.SendMessage(DoomInfo.Strings.GOTSHOTGUN);
                sound = Sfx.WPNUP;

                break;

            case Sprite.SGN2:
                if (!this.GiveWeapon(player, nameof(WeaponSuperShotgun), (special.Flags & MobjFlags.Dropped) != 0))
                {
                    return;
                }

                player.SendMessage(DoomInfo.Strings.GOTSHOTGUN2);
                sound = Sfx.WPNUP;

                break;

            default:
                throw new Exception("Unknown gettable thing!");
            }

            if ((special.Flags & MobjFlags.CountItem) != 0)
            {
                player.ItemCount++;
            }

            this.world.ThingAllocation.RemoveMobj(special);

            player.BonusCount += ItemPickup.bonusAdd;

            this.world.StartSound(player.Mobj, sound, SfxType.Misc);
        }
Esempio n. 27
0
        /// <summary>
        /// Give the player the ammo.
        /// </summary>
        /// <param name="amount">
        /// The number of clip loads, not the individual count (0 = 1/2 clip).
        /// </param>
        /// <returns>
        /// False if the ammo can't be picked up at all.
        /// </returns>
        public bool GiveAmmo(Player player, string ammoName, int amount)
        {
            var ammoEntity    = EntityInfo.Create(this.world, EntityInfo.OfName(ammoName));
            var itemComponent = ammoEntity.GetComponent <ItemComponent>();

            if (amount != 0)
            {
                amount *= itemComponent.Info.InitialAmount;
            }
            else
            {
                amount = itemComponent.Info.InitialAmount / 2;
            }

            if (this.world.Options.Skill == GameSkill.Baby || this.world.Options.Skill == GameSkill.Nightmare)
            {
                amount *= 2;
            }

            itemComponent.Amount = amount;

            var inventory = player.Entity.GetComponent <InventoryComponent>();

            if (!inventory.TryAdd(ammoEntity))
            {
                return(false);
            }

            if (ammoEntity.Info is AmmoBullets)
            {
                if (player.ReadyWeapon.Info is WeaponFists)
                {
                    player.PendingWeapon = inventory.Items.FirstOrDefault(weapon => weapon.Info is WeaponChaingun)
                                           ?? inventory.Items.First(weapon => weapon.Info is WeaponPistol);
                }
            }
            else if (ammoEntity.Info is AmmoShells)
            {
                if (player.ReadyWeapon.Info is WeaponFists || player.ReadyWeapon.Info is WeaponPistol)
                {
                    player.PendingWeapon = inventory.Items.FirstOrDefault(weapon => weapon.Info is WeaponShotgun)
                                           ?? inventory.Items.FirstOrDefault(weapon => weapon.Info is WeaponSuperShotgun) ?? player.PendingWeapon;
                }
            }
            else if (ammoEntity.Info is AmmoCells)
            {
                if (player.ReadyWeapon.Info is WeaponFists || player.ReadyWeapon.Info is WeaponPistol)
                {
                    player.PendingWeapon = inventory.Items.FirstOrDefault(weapon => weapon.Info is WeaponPlasmagun) ?? player.PendingWeapon;
                }
            }
            else if (ammoEntity.Info is AmmoRockets)
            {
                if (player.ReadyWeapon.Info is WeaponFists)
                {
                    player.PendingWeapon = inventory.Items.FirstOrDefault(weapon => weapon.Info is WeaponRocketLauncher) ?? player.PendingWeapon;
                }
            }

            return(true);
        }
Esempio n. 28
0
        public ISyncableEntity CreateEntityTombstone()
        {
            var entity = EntityInfo.Create(FieldPropertyFactory, Entities, EntityTombstoneType);

            return(Create(entity));
        }