/// <summary>
        /// creates a weapon for level.
        /// reads an weapon information file(.spec) and configures the weapon class.
        /// The read weapon class is stored in the list.
        /// </summary>
        /// <param name="info">weapon information for level</param>
        /// <param name="sceneParent">3D scene parent node</param>
        /// <returns>weapon class for the game</returns>
        protected GameWeapon CreateWeapon(WeaponInLevel info, NodeBase sceneParent)
        {
            GameWeaponSpec spec = new GameWeaponSpec();

            spec = (GameWeaponSpec)GameDataSpecManager.Load(info.SpecFilePath,
                                                            spec.GetType());

            GameWeapon weapon = new GameWeapon(spec);

            //  creates a collision data.
            Vector3 centerPos = Vector3.Transform(new Vector3(0f, spec.ModelRadius, 0f),
                                                  Matrix.Invert(weapon.RootAxis));

            CollideSphere collide = new CollideSphere(centerPos, spec.ModelRadius);

            weapon.SetCollide(collide);

            weapon.SetDroppedModelActiveFog(true);
            weapon.SetDroppedModelActiveLighting(false);

            //  drop to world.
            weapon.Drop(info.Position, sceneParent, null);

            //  adds a weapon to the list.
            weaponList.Add(weapon);

            return(weapon);
        }
Exemple #2
0
        /// <summary>
        /// Constructor.
        /// </summary>
        public GameWeapon(GameWeaponSpec spec)
        {
            this.specData = spec;

            //  model
            if (spec.ModelAlone)
            {
                modelWeapon            = new GameModel[spec.ModelCount];
                indexWeaponFireDummy   = new int[spec.ModelCount];
                indexWeaponAttachDummy = new int[spec.ModelCount];

                //  Find bones
                for (int i = 0; i < spec.ModelCount; i++)
                {
                    modelWeapon[i]      = new GameModel(spec.ModelFilePath);
                    modelWeapon[i].Name = spec.ModelFilePath;

                    for (int j = 0; j < modelWeapon[i].ModelData.model.Bones.Count; j++)
                    {
                        ModelBone bone = modelWeapon[i].ModelData.model.Bones[j];

                        //  Gun muzzule bone
                        if (bone.Name == spec.MuzzleBone)
                        {
                            indexWeaponFireDummy[i] = bone.Index;
                        }

                        //  Gun attach bone to character
                        if (bone.Name == spec.AttachBone)
                        {
                            indexWeaponAttachDummy[i] = bone.Index;
                        }
                    }
                }

                //  Apply NormalMap and SpeculaMap to only player's machine gun
                if (this.WeaponType == WeaponType.PlayerMachineGun)
                {
                    for (int i = 0; i < spec.ModelCount; i++)
                    {
                        modelWeapon[i].RenderingCustomEffect +=
                            new EventHandler <GameModel.RenderingCustomEffectEventArgs>(
                                OnEffectProcess);
                    }
                }
            }

            Reset();
        }
Exemple #3
0
        /// <summary>
        /// creates a weapon by spec file.
        /// </summary>
        /// <param name="specFileName">weapon information file (.spec)</param>
        public void CreateWeapon(string specFileName)
        {
            GameWeaponSpec spec = new GameWeaponSpec();

            spec =
                (GameWeaponSpec)GameDataSpecManager.Load(specFileName, spec.GetType());

            GameWeapon createWeapon = new GameWeapon(spec);

            createWeapon.AttachOwner(this);

            weaponList.Add(createWeapon);

            SelectWeapon(0);
        }
Exemple #4
0
        /// <summary>
        /// attacked by enemy. when HP is 0, gets destoryed.
        /// </summary>
        /// <param name="attacker"></param>
        public override void ActionHit(GameUnit attacker)
        {
            if (IsDead)
            {
                return;
            }

            if (attacker.CurrentWeapon == null)
            {
                throw new InvalidOperationException("The harmer no have weapon");
            }

            GameWeaponSpec AttackerWeaponSpec = attacker.CurrentWeapon.SpecData;

            //  Superman mode (DEBUG)
            if (RobotGameGame.SinglePlayer.Mode == GamePlayer.DebugMode.Superman ||
                RobotGameGame.SinglePlayer.Mode == GamePlayer.DebugMode.God)
            {
                Life = 0;  // If player is superman mode, This unit must be die ^^
            }
            else
            {
                //  Reduce our player's life point by harmer's weapon power
                Life -= AttackerWeaponSpec.Damage;
                if (Life < 0)
                {
                    Life = 0;
                }
            }

            if (Life == 0)
            {
                //  Our player is dead
                ActionDead(attacker.WorldTransform.Translation);
            }
        }
Exemple #5
0
        /// <summary>
        /// Constructor.
        /// </summary>
        public GameWeapon(GameWeaponSpec spec)
        {
            this.specData = spec;

            //  model
            if (spec.ModelAlone )
            {
                modelWeapon = new GameModel[spec.ModelCount];
                indexWeaponFireDummy = new int[spec.ModelCount];
                indexWeaponAttachDummy = new int[spec.ModelCount];

                //  Find bones
                for (int i = 0; i < spec.ModelCount; i++ )
                {
                    modelWeapon[i] = new GameModel(spec.ModelFilePath);
                    modelWeapon[i].Name = spec.ModelFilePath;

                    for (int j = 0; j < modelWeapon[i].ModelData.model.Bones.Count; j++)
                    {
                        ModelBone bone = modelWeapon[i].ModelData.model.Bones[j];

                        //  Gun muzzule bone
                        if (bone.Name == spec.MuzzleBone)
                            indexWeaponFireDummy[i] = bone.Index;

                        //  Gun attach bone to character
                        if (bone.Name == spec.AttachBone)
                            indexWeaponAttachDummy[i] = bone.Index;
                    }
                }

                //  Apply NormalMap and SpeculaMap to only player's machine gun
                if (this.WeaponType == WeaponType.PlayerMachineGun)
                {
                    for (int i = 0; i < spec.ModelCount; i++)
                    {
                        modelWeapon[i].RenderingCustomEffect +=
                            new EventHandler<GameModel.RenderingCustomEffectEventArgs>(
                            OnEffectProcess);
                    }
                }
            }

            Reset();
        }
Exemple #6
0
        /// <summary>
        /// creates a weapon by spec file.
        /// </summary>
        /// <param name="specFileName">weapon information file (.spec)</param>
        public void CreateWeapon(string specFileName)
        {
            GameWeaponSpec spec = new GameWeaponSpec();
            spec = 
                (GameWeaponSpec)GameDataSpecManager.Load(specFileName, spec.GetType());

            GameWeapon createWeapon = new GameWeapon(spec);
            createWeapon.AttachOwner(this);

            weaponList.Add(createWeapon);

            SelectWeapon(0);
        }