public ComboSystem(string path)
 {
     moveListFile = path;
     tempInput = new ButtonInput();
     performedMove = new Move();
     LoadMoves(Stage.Content.Load<Move[]>(moveListFile));
 }
        public Move getAttack(ButtonInput input)
        {
            //our list contains our 3 one button moves, plus the 3 button move
            if (moveList.ContainsKey(input))
                return moveList[input];

            //no such move exists so either two buttons are pressed, or no buttons are pressed

            Move strongMove = null;
            tempMove = null;

            if (input.Red)
            {
                tempInput.Red = true;
                tempMove = moveList[tempInput]; //this is the first input we check so tempMove can't be used
                tempInput.Red = false;
            }
            if (input.Yellow)
            {
                tempInput.Yellow = true;
                if (tempMove != null)
                    strongMove = moveList[tempInput];
                else tempMove = moveList[tempInput];
                tempInput.Yellow = false;
            }
            if (input.Blue)
            {
                tempInput.Blue = true;
                strongMove = moveList[tempInput]; //this is the last input we check so tempMove must be used
                tempInput.Blue = false;
            }

            return strongMove;
            /*
            if (strongMove != null && tempMove != null)
            {
                //interpolate between the two moves
                performedMove = strongMove;
                //performedMove.FrontArea = strongMove.FrontArea;
                //performedMove.BackArea = strongMove.BackArea;
                //performedMove.Damage = strongMove.Damage + tempMove.Damage * .5f;
                performedMove.TimeBeforeSecond = tempMove.TimeBeforeAttack;
                performedMove.AnimationType = strongMove.AnimationType;
                performedMove.AnimationSecond = tempMove.AnimationType;
                //performedMove.ParticleEffect =
                //performedMove.animation
                return performedMove;
            }
            else
                tempMove = null;

            return null;
             * */
        }
 public MoveCreator(MoveCreatorForm parent, Move move)
 {
     InitializeComponent();
     this.FormClosing += MoveCreator_FormClosing;
     this.label1.Text = "Edit New Move";
     this.parent = parent;
     this.move = move;
     move.BoxDims = new string[]{"3", "3"};
     SetDefaults();
     PopulateEditFields();
 }
        private Boolean Save()
        {
            if (nameField.Text == String.Empty) {
                MessageBox.Show("You must specify a move name", "Cannot Save", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return false;
            }
            Move move = new Move();
            move.Name = nameField.Text;
            move.Damage = float.Parse(damageField.Value.ToString());
            move.AttackTime = float.Parse(attackTimeField.Value.ToString());
            move.AttackTypeFlag = (AttackType) Enum.Parse(typeof(AttackType), attackTypeField.SelectedItem.ToString());
            //move.Animation = animationField.SelectedText;
            move.Audio = audioField.SelectedText;
            move.Status = (MoveStatus)Enum.Parse(typeof(MoveStatus), statusField.SelectedItem.ToString());
            move.ButtonSequence = getButtonSequence();
            move.IsSubMove = subMoveCheck.Checked;
            move.BoxDims = new string[]{"3", "3"};

            if (parent.movelist.ContainsKey(move.Name))
                parent.movelist.Remove(move.Name);

            parent.movelist.Add(move.Name, move);
            return true;
        }
        private void updateGuitarWithOutStrum(float dt)
        {
            int dir = (int)strum.value;

            SetFacingDirection(dir);

            if (dir != 0)
                State = PlayerState.Running;
            else
                State = PlayerState.Normal;

            switch (MoveDirection)
            {
                case PlayerDirection.Right:
                    this.actor.PhysicsObject.CharacterController.HorizontalMotionConstraint.MovementDirection = dir * Vector2.UnitX;
                    break;
                case PlayerDirection.Left:
                    this.actor.PhysicsObject.CharacterController.HorizontalMotionConstraint.MovementDirection = dir * -Vector2.UnitX;
                    break;
                case PlayerDirection.Forward:
                    this.actor.PhysicsObject.CharacterController.HorizontalMotionConstraint.MovementDirection = dir * -Vector2.UnitY;
                    break;
                case PlayerDirection.Backward:
                    this.actor.PhysicsObject.CharacterController.HorizontalMotionConstraint.MovementDirection = dir * Vector2.UnitY;
                    break;
            }

            //holding strum and pushing dash button
            if (A.IsNewAction || leftBumper.IsNewAction)
                Dash(0);

            if (B.IsNewAction)
                input.Red = true;
            if (Y.IsNewAction)
                input.Yellow = true;
            if (X.IsNewAction)
                input.Blue = true;

            if (input.isSet())
            {
                currentAttack = attacks.getAttack(input);
                startAttack();
                input.Reset();

                //stop all movement if an attack is set
                this.actor.PhysicsObject.CharacterController.HorizontalMotionConstraint.MovementDirection = Vector2.Zero;

            }
        }
        private void updateGuitarWithStrum(float dt)
        {
            int dir = (int)strum.value;
            //if all the guitar face buttons are not pressed then move
            if (B.value == 0.0f && Y.value == 0.0f && X.value == 0.0f) /* A.value == 0.0f && leftBumper.value == 0.0f && )*/
            {
                SetFacingDirection(dir);

                if (dir != 0)
                    State = PlayerState.Running;
                else
                    State = PlayerState.Normal;

                switch (MoveDirection)
                {
                    case PlayerDirection.Right:
                        this.actor.PhysicsObject.CharacterController.HorizontalMotionConstraint.MovementDirection = dir * Vector2.UnitX;
                        break;
                    case PlayerDirection.Left:
                        this.actor.PhysicsObject.CharacterController.HorizontalMotionConstraint.MovementDirection = dir * -Vector2.UnitX;
                        break;
                    case PlayerDirection.Forward:
                        this.actor.PhysicsObject.CharacterController.HorizontalMotionConstraint.MovementDirection = dir * -Vector2.UnitY;
                        break;
                    case PlayerDirection.Backward:
                        this.actor.PhysicsObject.CharacterController.HorizontalMotionConstraint.MovementDirection = dir * Vector2.UnitY;
                        break;
                }
            }
            else
            {
                State = PlayerState.Normal;
                this.actor.PhysicsObject.CharacterController.HorizontalMotionConstraint.MovementDirection = Vector2.Zero;
            }

            //holding strum and pushing dash button
            if (strum.value != 0.0f)
            {
                if (A.IsNewAction || leftBumper.IsNewAction)
                    Dash(dir);
            }

            //all strumming actions
            if (strum.IsNewAction)
            {
                if (A.value != 0.0f || leftBumper.value != 0.0f)
                    Dash(dir);
                else
                {
                    if (B.value != 0.0f)
                        input.Red = true;
                    if (Y.value != 0.0f)
                        input.Yellow = true;
                    if (X.value != 0.0f)
                        input.Blue = true;

                    if (input.isSet())
                    {
                        currentAttack = attacks.getAttack(input);
                        startAttack();
                        input.Reset();
                    }
                }
            }
        }
        private void finishAttack()
        {
            //perform attack
            Stage.ActiveStage.GetQB<PlayerAttackSystemQB>().PerformAttack(Player.PhysicsObject.Position, facing, currentAttack, smash / MAX_SMASH);

            //set player state
            State = PlayerState.Normal;
            recoveryTimer = 0;
            currentAttack = null;
        }
        private void updateGamePad(float dt)
        {
            int dir = (int)leftAxisX.value;

            SetFacingDirection(dir);
            if (dir != 0)
                State = PlayerState.Running;
            else
                State = PlayerState.Normal;

            switch (MoveDirection)
            {
                case PlayerDirection.Right:
                    this.actor.PhysicsObject.CharacterController.HorizontalMotionConstraint.MovementDirection = dir * Vector2.UnitX;
                    break;
                case PlayerDirection.Left:
                    this.actor.PhysicsObject.CharacterController.HorizontalMotionConstraint.MovementDirection = dir * -Vector2.UnitX;
                    break;
                case PlayerDirection.Forward:
                    this.actor.PhysicsObject.CharacterController.HorizontalMotionConstraint.MovementDirection = dir * -Vector2.UnitY;
                    break;
                case PlayerDirection.Backward:
                    this.actor.PhysicsObject.CharacterController.HorizontalMotionConstraint.MovementDirection = dir * Vector2.UnitY;
                    break;
            }

            if (rightBumper.IsNewAction)
                Dash(1);
            else if (leftBumper.IsNewAction)
                Dash(-1);
            else
            {
                //get attack from input
                if (B.IsNewAction)
                    input.Blue = true;
                if (Y.IsNewAction)
                {
                    input.Yellow = true;
                    input.Red = true;
                    input.Blue = true;
                }
                if (X.IsNewAction)
                    input.Yellow = true;
                if (A.IsNewAction)
                    input.Red = true;

                if (input.isSet())
                {
                    this.actor.PhysicsObject.CharacterController.HorizontalMotionConstraint.MovementDirection = Vector2.Zero;
                    currentAttack = attacks.getAttack(input);
                    startAttack();
                    input.Reset();
                }
            }
        }
 public void stunIndefinitely()
 {
     recoveryTimer = float.PositiveInfinity;
     currentAttack = null;
     State = PlayerState.Stunned;
     Player.PhysicsObject.CharacterController.Body.LinearVelocity = Vector3.Zero;
     Player.PhysicsObject.CharacterController.HorizontalMotionConstraint.MovementDirection = Vector2.Zero;
 }
 public void stun(float stun)
 {
     if (State != PlayerState.Stunned)
     {
         recoveryTimer = stun;
         currentAttack = null;
         State = PlayerState.Stunned;
         Player.PhysicsObject.CharacterController.Body.LinearVelocity = Vector3.Zero;
         Player.PhysicsObject.CharacterController.HorizontalMotionConstraint.MovementDirection = Vector2.Zero;
     }
 }
        public void PerformAttack(Vector3 position, PlayerDirection facing, Move newMove, float increase)
        {
            bool enemyHit = false;
            bool shieldHit = false;
            string soundName = null;

            if (newMove.Sound_hit != String.Empty)
                soundName = newMove.Sound_hit;

            float damage = newMove.Damage + newMove.Damage * increase;
            float rockMeter = newMove.RockMeterIncrease;

            //bouding box
            const float DEPTH_CONST = 100;
            const float HEIGHT_CONST = 2;
            BoundingBox hitbox = new BoundingBox();

            float front = newMove.FrontArea + newMove.FrontArea * increase;
            float back = newMove.BackArea + newMove.BackArea * increase;

            hitbox.Min.Y = position.Y - HEIGHT_CONST - HEIGHT_CONST * increase;
            hitbox.Max.Y = position.Y + HEIGHT_CONST + HEIGHT_CONST * increase;

            Vector3 force = Vector3.Zero;

            switch (facing)
            {
                case PlayerDirection.Right:
                    hitbox.Min.X = position.X - back;
                    hitbox.Max.X = position.X + front;
                    hitbox.Min.Z = position.Z - DEPTH_CONST;
                    hitbox.Max.Z = position.Z + DEPTH_CONST;
                    force = Vector3.Right;
                    break;
                case PlayerDirection.Left:
                    hitbox.Min.X = position.X - front;
                    hitbox.Max.X = position.X + back;
                    hitbox.Min.Z = position.Z - DEPTH_CONST;
                    hitbox.Max.Z = position.Z + DEPTH_CONST;
                    force = Vector3.Right;
                    break;
                case PlayerDirection.Forward:
                    hitbox.Min.X = position.X - DEPTH_CONST;
                    hitbox.Max.X = position.X + DEPTH_CONST;
                    hitbox.Min.Z = position.Z - front;
                    hitbox.Max.Z = position.Z + back;
                    force = Vector3.Backward;
                    break;
                case PlayerDirection.Backward:
                    hitbox.Min.X = position.X - DEPTH_CONST;
                    hitbox.Max.X = position.X + DEPTH_CONST;
                    hitbox.Min.Z = position.Z - back;
                    hitbox.Max.Z = position.Z + front;
                    force = Vector3.Backward;
                    break;
            }

            // todo: move to a better place. maybe a function in player agent called "SmashEffects" or something like that. maybe a class called "PlayerAttackEffects" and a static function called "Smash" in there
            if (newMove.Name == "Smash")
            {
                Vector3 difference = hitbox.Max - hitbox.Min;
                float length = difference.Z;
                float height = difference.Y;
                float width = difference.X;
                Vector3 center = new Vector3(hitbox.Max.X - width / 2.0f, hitbox.Max.Y - height / 2.0f, hitbox.Max.Z - length / 2.0f);
                Stage.ActiveStage.GetQB<Engine.Decals.DecalQB>().CreateDecal(new Ray(center, Vector3.Down), 10.0f, "Decals/crack", 10.0f, 20.0f, Decals.DecalLayers.CracksLayer);

                Stage.ActiveStage.GetQB<Particles.ParticleQB>().AddParticleEmitter(null, mainCharacter.PhysicsObject.Position + new Vector3(0.0f, -3.0f, 0.0f), true, -1f, 50,
                                                            75, 1.0f, 1.5f, 4, 5, new Vector2(1.0f), new Vector2(2.0f), new Vector3(1.0f, 0.0f, 1.0f),
                                                            Vector3.Up, new Vector3(8.4f, 0.3f, 8.4f), "dust2");

                Stage.ActiveStage.GetQB<AudioQB>().PlaySound("WeakAOE_16", 1.0f, 0.0f, 0.0f);
                Stage.ActiveStage.GetQB<AudioQB>().PlaySound("asphaltsmash_16", 0.7f, 0.0f, 0.0f);
            }

            Actor actor;
            foreach (GameLib.Engine.AI.AI ai in Stage.ActiveStage.GetQB<GameLib.Engine.AI.AIQB>().aliveEnemies)
            {
                actor = ai.actor;
                if (hitbox.Intersects(actor.PhysicsObject.CollisionInformation.BoundingBox))
                {
                    enemyHit = true;
                    Vector3 actorPos = actor.PhysicsObject.Position;

                    HealthAgent actorHealth = actor.GetAgent<HealthAgent>();

                    float startingHealth = actorHealth.Health;
                    float remainingHealth = actorHealth.ModifyHealth(-damage, mainCharacter.PhysicsObject.Position, newMove.Disarming);

                    if (remainingHealth < startingHealth)
                    {
                        if (newMove.Force != Vector2.Zero && remainingHealth > 0)
                        {
                            force *= (actorPos - position);
                            force.Normalize();

                            force.X *= newMove.Force.X + newMove.Force.X * increase;
                            force.X *= newMove.Force.X + newMove.Force.X * increase;
                            float jumpVal = newMove.Force.Y + newMove.Force.Y * increase;

                            if (actor.PhysicsObject.physicsType == PhysicsObject.PhysicsType.CylinderCharacter)
                            {
                                actor.PhysicsObject.CylinderCharController.Body.LinearVelocity = Vector3.Zero;
                                if (jumpVal != 0)
                                {
                                    actor.PhysicsObject.CylinderCharController.Jump(jumpVal / actor.PhysicsObject.CylinderCharController.Body.Mass);
                                }
                                if (force != Vector3.Zero)
                                    actor.PhysicsObject.CylinderCharController.Body.ApplyLinearImpulse(ref force);
                            }
                        }

                        //we did damage so increase the multiplier
                        playerRockMeter.PerformedAttack(rockMeter);

                        //stun the enemy
                        if (newMove.StunTime != 0.0f)
                            ai.Stun(newMove.StunTime);

                        if (ai.bloodOnDamage)
                        {
                            Vector3 bloodDir = actorPos - mainCharacter.PhysicsObject.Position;
                            bloodDir.Normalize();
                            bloodDir *= 10;
                            Stage.ActiveStage.GetQB<Particles.ParticleQB>().AddParticleEmitter(null, actor.PhysicsObject.Position, true, -1, 5,
                                                            10, .25f, .5f, 0, 0, Vector2.One, Vector2.One * 2.0f,
                                                            Vector3.Zero, bloodDir, 2 * Vector3.One, "blood1");
                            Stage.ActiveStage.GetQB<Gameplay.BloodSplatterQB>().SplatBlood();
                            Stage.ActiveStage.GetQB<Decals.DecalQB>().CreateDecal(actorPos, new BoundingBox(new Vector3(-20.0f, -20.0f, -20.0f), new Vector3(20.0f, 20.0f, 20.0f)), "Decals/blood", 10.0f, 5.0f,                                                                                                         Decals.DecalLayers.BloodLayer);
                            //Stage.ActiveStage.GetQB<Decals.DecalQB>().CreateDecal(new Ray(actor.PhysicsObject.Position, Vector3.Down), 10.0f, "Decals/blood", 10.0f, 5.0f, Decals.DecalLayers.BloodLayer);
                        }

                        if (remainingHealth <= 0.0f) //killed the enemy
                        {
                            //playerRockMeter.IncreaseRockLevel(ai.rockLevelForKilling);
                            int increaseRockMeter = playerRockMeter.IncreaseScoreDueToKill(ai.pointsForKilling);
                            playerRockMeter.AddKill();

                            Vector3 screenPos = Stage.renderer.GraphicsDevice.Viewport.Project(actorPos,
                                CameraQB.ProjectionMatrix, CameraQB.ViewMatrix, Matrix.Identity);

                            Stage.ActiveStage.GetQB<ParticleQB>().AddFloatingText(new Vector2(screenPos.X, screenPos.Y + 10), -50 * Vector2.UnitY,
                                2.0f, increaseRockMeter.ToString(System.Globalization.CultureInfo.InvariantCulture));
                        }
                    }
                    else //you hit an enemy but dealt no damage
                    {
                        shieldHit = true;
                        soundName = newMove.Sound_shield;
                    }

                    if (!newMove.AOE)
                        break; //only hit one enemy
                }
            }

            //play sounds
            if (shieldHit)
                playRandomShieldHitSound(newMove.Disarming);
            else if (!enemyHit)
                playMissSound();
            else
                playRandomHitSound();
        }
 private void LoadMoveList(Move[] moves)
 {
     foreach (Move m in moves) {
         movelist.Add(m.Name, m);
     }
 }
        private void ExportMoves()
        {
            Move[] moves = new Move[movelist.Count];

            for(int i = 0; i < movelist.Count; i++){
                moves[i] = movelist.ElementAt(i).Value;
            }

            XmlWriterSettings settings = new XmlWriterSettings();
            settings.Indent = true;

            using (XmlWriter writer = XmlWriter.Create(String.Concat(directoryHome, "/HeroesOfRockContent/Movelist.xml"), settings)) {
                IntermediateSerializer.Serialize(writer, moves, null);
            }
        }