Esempio n. 1
0
        void DisplayCannotPerformWarning(Map.Ability ability, CannotPerformReason reason)
        {
            if (lastCannotPerformAbility == ability && lastCannotPerformReason == reason)
            {
                return;
            }
            lastCannotPerformAbility = ability;
            lastCannotPerformReason  = reason;
            if (!ability.DisplayCannotPerformReason(reason))
            {
                return;
            }
            string text = "";
            var    sm   = Program.Instance.SoundManager;

            switch (reason)
            {
            case CannotPerformReason.NotEnoughAmmo:
                text = Locale.Resource.HUDWarnNotEnoughAmmo;
                sm.GetSFX(Client.Sound.SFX.RifleEmpty1).Play(new Sound.PlayArgs());
                break;

            case CannotPerformReason.NotEnoughRage:
                text = Locale.Resource.HUDWarnNotEnoughRage;
                sm.GetSoundResourceGroup(sm.GetSFX(Client.Sound.SFX.IAmOutOfRage1)).Play(new Sound.PlayArgs());
                break;

            case CannotPerformReason.TooClose:
                text = Locale.Resource.HUDWarnTooClose;
                break;

            case CannotPerformReason.OnCooldown:
                text = Locale.Resource.HUDWarnOnCooldown;
                break;

            default:
                text = reason.ToString();
                break;
            }
            Game.Instance.Interface.AddChild(new Interface.WarningPopupText
            {
                Text = text
            });
        }
 void u_StartPerformAbility(Unit arg1, Ability arg2)
 {
     if (!Ability.IsAssignableFrom(arg2.GetType())) return;
     Script.TryStartPerform();
     nUsed++;
     if (NUses >= 0 && nUsed >= NUses)
         TryEndPerform(false);
 }
Esempio n. 3
0
 public virtual void OnStartPerformAbility(Ability ability)
 {
     if (StartPerformAbility != null)
         StartPerformAbility(this, ability);
 }
Esempio n. 4
0
 public void AddAbility(Ability a)
 {
     a.Performer = this;
     a.Mediator = this;
     abilities.Add(a);
 }
 void DisplayCannotPerformWarning(Map.Ability ability, CannotPerformReason reason)
 {
     if (lastCannotPerformAbility == ability && lastCannotPerformReason == reason) return;
     lastCannotPerformAbility = ability;
     lastCannotPerformReason = reason;
     if (!ability.DisplayCannotPerformReason(reason)) return;
     string text = "";
     var sm = Program.Instance.SoundManager;
     switch (reason)
     {
         case CannotPerformReason.NotEnoughAmmo:
             text = Locale.Resource.HUDWarnNotEnoughAmmo;
             sm.GetSFX(Client.Sound.SFX.RifleEmpty1).Play(new Sound.PlayArgs());
             break;
         case CannotPerformReason.NotEnoughRage:
             text = Locale.Resource.HUDWarnNotEnoughRage;
             sm.GetSoundResourceGroup(sm.GetSFX(Client.Sound.SFX.IAmOutOfRage1)).Play(new Sound.PlayArgs());
             break;
         case CannotPerformReason.TooClose:
             text = Locale.Resource.HUDWarnTooClose;
             break;
         case CannotPerformReason.OnCooldown:
             text = Locale.Resource.HUDWarnOnCooldown;
             break;
         default:
             text = reason.ToString();
             break;
     }
     Game.Instance.Interface.AddChild(new Interface.WarningPopupText
     {
         Text = text
     });
 }
        protected override void OnUpdate(Graphics.UpdateEventArgs e)
        {
            base.OnUpdate(e);
            if (!Activated) return;

            cannotPerformAcc += e.Dtime;
            if (cannotPerformAcc >= 1)
            {
                cannotPerformAcc = 0;
                lastCannotPerformAbility = null;
                lastCannotPerformReason = CannotPerformReason.None;
            }

            if (Game.Instance.State is Game.PausedState ||
                Game.Instance.Map.MainCharacter.State != Map.UnitState.Alive ||
                Game.Instance.FrameId <= 2 || !Program.Instance.Focused)
                return;

            if (Game.Instance.Input.State.SwitchToMeleeWeapon)
                Game.Instance.Map.MainCharacter.SelectedWeapon = 0;
            else if (Game.Instance.Input.State.SwitchToRangedWeapon)
                Game.Instance.Map.MainCharacter.SelectedWeapon = 1;

            RunDir.Y = RunDir.X = 0;
            //if((GetAsyncKeyState(65) >> 8) != 0)
            if (Game.Instance.Input.State.StrafeLeft)
                RunDir.X -= 1;
            //if ((GetAsyncKeyState(68) >> 8) != 0)
            if (Game.Instance.Input.State.StrafeRight)
                RunDir.X += 1;
            //if ((GetAsyncKeyState(87) >> 8) != 0)
            if (Game.Instance.Input.State.WalkForward)
                RunDir.Y += 1;
            //if ((GetAsyncKeyState(83) >> 8) != 0)
            if (Game.Instance.Input.State.WalkBackward)
                RunDir.Y -= 1;

            if (RunDir.Length() != 0)
            {
                Program.Instance.SignalEvent(new ProgramEvents.UserInput { InputType = ProgramEvents.UserInputType.WASD });
            }

            Game.Instance.Map.MainCharacter.Running = RunDir.Length() > 0;

            Vector3 mvp = Game.Instance.Input.State.MousePlanePosition;

            var dir3 = Vector3.Normalize(mvp - Game.Instance.Map.MainCharacter.Translation);
            var dir = Vector2.Normalize(Common.Math.ToVector2(dir3));
            if (dir.X == 0 && dir.Y == 0)
                dir.X = 1;
            float rot = (float)Common.Math.AngleFromVector3XY(Common.Math.ToVector3(dir));
            var worldDir = Vector3.Normalize(Game.Instance.Input.State.MouseGroundPosition -
                (Game.Instance.Map.MainCharacter.Translation + Vector3.UnitZ*Game.Instance.Map.MainCharacter.MainAttackFromHeight));
            float lean = (float)Math.Asin(worldDir.Z);
            if (Game.Instance.Map.MainCharacter.CanControlRotation)
            {
            #if DEBUG
                if (dir.X == 0 && dir.Y == 0)
                    throw new Exception("dir: " + dir + ", rot: " + rot);
                else
                    Game.Instance.Map.MainCharacter.LookatDir = rot;
            #else
                if(dir.X != 0 || dir.Y != 0)
                    Game.Instance.Map.MainCharacter.LookatDir = rot;
            #endif
                Game.Instance.Map.MainCharacter.TorsoLean = lean;
                if (!Game.Instance.Map.MainCharacter.Running)
                {
                    float startMoveLegsAngle = 0.7f;
                    if (Game.Instance.Map.MainCharacter.TorsoDiffDir > startMoveLegsAngle)
                        Game.Instance.Map.MainCharacter.Orientation = rot - startMoveLegsAngle < 0 ? rot - startMoveLegsAngle + 2f * (float)System.Math.PI : rot - startMoveLegsAngle;
                    else if (Game.Instance.Map.MainCharacter.TorsoDiffDir < -1)
                        Game.Instance.Map.MainCharacter.Orientation = rot + startMoveLegsAngle < 0 ? rot + startMoveLegsAngle + 2f * (float)System.Math.PI : rot + startMoveLegsAngle;
                }
            }

            bool spacePressed = Game.Instance.Input.State.Jump;
            if (spacePressed && !spaceWasPressed)
            {
                if (Game.Instance.Map.MainCharacter.State == Client.Game.Map.UnitState.Alive)
                {
                    Game.Instance.Map.MainCharacter.Jump();

                    Program.Instance.SignalEvent(new ProgramEvents.UserInput { InputType = ProgramEvents.UserInputType.Jump });
                }
            }
            spaceWasPressed = spacePressed;

            if (Game.Instance.Map.MainCharacter.CanControlMovement)
            {

                if (RunDir.Length() > 0)
                {
                    var runDir = Vector3.TransformNormal(Common.Math.ToVector3(RunDir),
                            Game.Instance.Scene.Camera.ViewProjection);
                    runDir.Z = 0;
                    runDir.Normalize();
                    runDir *= Game.Instance.Map.MainCharacter.RunSpeed;

                    Game.Instance.Map.MainCharacter.MotionUnit.RunVelocity = Common.Math.ToVector2(runDir);
                    float runAngle = (float)Common.Math.AngleFromVector3XY(runDir);
                    if (Common.Math.DiffAngle(rot, runAngle) > Math.PI / 2f)
                    {
                        runAngle = (float)Common.Math.AngleFromVector3XY(-runDir);
                        Game.Instance.Map.MainCharacter.RunningBackwards = true;
                    }
                    else
                        Game.Instance.Map.MainCharacter.RunningBackwards = false;

                    Game.Instance.Map.MainCharacter.MotionUnit.Rotation = Quaternion.RotationAxis(Vector3.UnitZ, runAngle < 0 ? runAngle + 2f * (float)System.Math.PI : runAngle);
                }
                else
                    Game.Instance.Map.MainCharacter.MotionUnit.RunVelocity = Vector2.Zero;
            }

            Fire fire = Fire.None;
            if (Game.Instance.Map.MainCharacter.CanPerformAbilities &&
                 !Game.Instance.Map.MainCharacter.IsPerformingAbility)
            {
                Vector3 mouseGroundPosition = Game.Instance.Input.State.MouseGroundPosition;

                //Map.Unit unit = null;
                //if (Game.Instance.SceneController.MouseOverEntity != null)
                //    unit = Game.Instance.SceneController.MouseOverEntity as Map.Unit;

                foreach (var v in Game.Instance.Map.MainCharacter.Abilities)
                {
                    //v.TargetEntity = unit;
                    v.TargetPosition = mouseGroundPosition;
                }

                Map.Ability ab = null;
                if (Game.Instance.Input.State.PrimaryFire)
                {
                    ab = Game.Instance.Map.MainCharacter.PrimaryAbility;
                    fire = Fire.Primary;

                    Program.Instance.SignalEvent(new ProgramEvents.UserInput { InputType = ProgramEvents.UserInputType.FirePrimary });
                }
                else if (Game.Instance.Input.State.SecondaryFire)
                {
                    ab = Game.Instance.Map.MainCharacter.SecondaryAbility;
                    fire = Fire.Secondary;
                }

                if (ab != null && !ab.IsPerforming)
                {
                    if (!ab.TryStartPerform())
                    {
                        if (ab.LastCannotPerformReason != CannotPerformReason.None &&
                            prevFire != fire)
                        {
                            DisplayCannotPerformWarning(ab, ab.LastCannotPerformReason);
                        }
                    }
                }

            }

            prevFire = fire;
        }
Esempio n. 7
0
        protected override void OnUpdate(Graphics.UpdateEventArgs e)
        {
            base.OnUpdate(e);
            if (!Activated)
            {
                return;
            }

            cannotPerformAcc += e.Dtime;
            if (cannotPerformAcc >= 1)
            {
                cannotPerformAcc         = 0;
                lastCannotPerformAbility = null;
                lastCannotPerformReason  = CannotPerformReason.None;
            }

            if (Game.Instance.State is Game.PausedState ||
                Game.Instance.Map.MainCharacter.State != Map.UnitState.Alive ||
                Game.Instance.FrameId <= 2 || !Program.Instance.Focused)
            {
                return;
            }

            if (Game.Instance.Input.State.SwitchToMeleeWeapon)
            {
                Game.Instance.Map.MainCharacter.SelectedWeapon = 0;
            }
            else if (Game.Instance.Input.State.SwitchToRangedWeapon)
            {
                Game.Instance.Map.MainCharacter.SelectedWeapon = 1;
            }

            RunDir.Y = RunDir.X = 0;
            //if((GetAsyncKeyState(65) >> 8) != 0)
            if (Game.Instance.Input.State.StrafeLeft)
            {
                RunDir.X -= 1;
            }
            //if ((GetAsyncKeyState(68) >> 8) != 0)
            if (Game.Instance.Input.State.StrafeRight)
            {
                RunDir.X += 1;
            }
            //if ((GetAsyncKeyState(87) >> 8) != 0)
            if (Game.Instance.Input.State.WalkForward)
            {
                RunDir.Y += 1;
            }
            //if ((GetAsyncKeyState(83) >> 8) != 0)
            if (Game.Instance.Input.State.WalkBackward)
            {
                RunDir.Y -= 1;
            }

            if (RunDir.Length() != 0)
            {
                Program.Instance.SignalEvent(new ProgramEvents.UserInput {
                    InputType = ProgramEvents.UserInputType.WASD
                });
            }


            Game.Instance.Map.MainCharacter.Running = RunDir.Length() > 0;


            Vector3 mvp = Game.Instance.Input.State.MousePlanePosition;

            var dir3 = Vector3.Normalize(mvp - Game.Instance.Map.MainCharacter.Translation);
            var dir  = Vector2.Normalize(Common.Math.ToVector2(dir3));

            if (dir.X == 0 && dir.Y == 0)
            {
                dir.X = 1;
            }
            float rot      = (float)Common.Math.AngleFromVector3XY(Common.Math.ToVector3(dir));
            var   worldDir = Vector3.Normalize(Game.Instance.Input.State.MouseGroundPosition -
                                               (Game.Instance.Map.MainCharacter.Translation + Vector3.UnitZ * Game.Instance.Map.MainCharacter.MainAttackFromHeight));
            float lean = (float)Math.Asin(worldDir.Z);

            if (Game.Instance.Map.MainCharacter.CanControlRotation)
            {
#if DEBUG
                if (dir.X == 0 && dir.Y == 0)
                {
                    throw new Exception("dir: " + dir + ", rot: " + rot);
                }
                else
                {
                    Game.Instance.Map.MainCharacter.LookatDir = rot;
                }
#else
                if (dir.X != 0 || dir.Y != 0)
                {
                    Game.Instance.Map.MainCharacter.LookatDir = rot;
                }
#endif
                Game.Instance.Map.MainCharacter.TorsoLean = lean;
                if (!Game.Instance.Map.MainCharacter.Running)
                {
                    float startMoveLegsAngle = 0.7f;
                    if (Game.Instance.Map.MainCharacter.TorsoDiffDir > startMoveLegsAngle)
                    {
                        Game.Instance.Map.MainCharacter.Orientation = rot - startMoveLegsAngle < 0 ? rot - startMoveLegsAngle + 2f * (float)System.Math.PI : rot - startMoveLegsAngle;
                    }
                    else if (Game.Instance.Map.MainCharacter.TorsoDiffDir < -1)
                    {
                        Game.Instance.Map.MainCharacter.Orientation = rot + startMoveLegsAngle < 0 ? rot + startMoveLegsAngle + 2f * (float)System.Math.PI : rot + startMoveLegsAngle;
                    }
                }
            }

            bool spacePressed = Game.Instance.Input.State.Jump;
            if (spacePressed && !spaceWasPressed)
            {
                if (Game.Instance.Map.MainCharacter.State == Client.Game.Map.UnitState.Alive)
                {
                    Game.Instance.Map.MainCharacter.Jump();

                    Program.Instance.SignalEvent(new ProgramEvents.UserInput {
                        InputType = ProgramEvents.UserInputType.Jump
                    });
                }
            }
            spaceWasPressed = spacePressed;

            if (Game.Instance.Map.MainCharacter.CanControlMovement)
            {
                if (RunDir.Length() > 0)
                {
                    var runDir = Vector3.TransformNormal(Common.Math.ToVector3(RunDir),
                                                         Game.Instance.Scene.Camera.ViewProjection);
                    runDir.Z = 0;
                    runDir.Normalize();
                    runDir *= Game.Instance.Map.MainCharacter.RunSpeed;

                    Game.Instance.Map.MainCharacter.MotionUnit.RunVelocity = Common.Math.ToVector2(runDir);
                    float runAngle = (float)Common.Math.AngleFromVector3XY(runDir);
                    if (Common.Math.DiffAngle(rot, runAngle) > Math.PI / 2f)
                    {
                        runAngle = (float)Common.Math.AngleFromVector3XY(-runDir);
                        Game.Instance.Map.MainCharacter.RunningBackwards = true;
                    }
                    else
                    {
                        Game.Instance.Map.MainCharacter.RunningBackwards = false;
                    }

                    Game.Instance.Map.MainCharacter.MotionUnit.Rotation = Quaternion.RotationAxis(Vector3.UnitZ, runAngle < 0 ? runAngle + 2f * (float)System.Math.PI : runAngle);
                }
                else
                {
                    Game.Instance.Map.MainCharacter.MotionUnit.RunVelocity = Vector2.Zero;
                }
            }

            Fire fire = Fire.None;
            if (Game.Instance.Map.MainCharacter.CanPerformAbilities &&
                !Game.Instance.Map.MainCharacter.IsPerformingAbility)
            {
                Vector3 mouseGroundPosition = Game.Instance.Input.State.MouseGroundPosition;

                //Map.Unit unit = null;
                //if (Game.Instance.SceneController.MouseOverEntity != null)
                //    unit = Game.Instance.SceneController.MouseOverEntity as Map.Unit;

                foreach (var v in Game.Instance.Map.MainCharacter.Abilities)
                {
                    //v.TargetEntity = unit;
                    v.TargetPosition = mouseGroundPosition;
                }

                Map.Ability ab = null;
                if (Game.Instance.Input.State.PrimaryFire)
                {
                    ab   = Game.Instance.Map.MainCharacter.PrimaryAbility;
                    fire = Fire.Primary;

                    Program.Instance.SignalEvent(new ProgramEvents.UserInput {
                        InputType = ProgramEvents.UserInputType.FirePrimary
                    });
                }
                else if (Game.Instance.Input.State.SecondaryFire)
                {
                    ab   = Game.Instance.Map.MainCharacter.SecondaryAbility;
                    fire = Fire.Secondary;
                }

                if (ab != null && !ab.IsPerforming)
                {
                    if (!ab.TryStartPerform())
                    {
                        if (ab.LastCannotPerformReason != CannotPerformReason.None &&
                            prevFire != fire)
                        {
                            DisplayCannotPerformWarning(ab, ab.LastCannotPerformReason);
                        }
                    }
                }
            }

            prevFire = fire;
        }