Пример #1
0
    public IEnumerator MeleeAttack()
    {
        yield return(new WaitForSeconds(attack.attackPlaceholderAnimFrames / 30));

        Debug.Log("meleeswing");
        newAttack = Instantiate(attack, gameObject.GetComponentInParent <Rigidbody> ().position + transform.forward * 1.5f + transform.up, this.gameObject.GetComponentInParent <Rigidbody>().rotation) as AttackClass;
        //Debug.Log(this.gameObject.GetComponent<FillerAttackScript>());

        //!!!!!Turn the attack into a trigger and add a dummy trigger to the player object !!!!
        newAttack.atkScript = this.gameObject.GetComponent <FillerAttackScript>();
        newAttack.GetComponent <Collider>().enabled = true;
        Debug.Log(attack.GetComponent <Collider>().enabled + "attacktemplateenabled");
        //newAttack.GetComponent<Collider>().enabled = false;//disables collider after attack so it doesn't act as a hazard
        Debug.Log("attackcolliderenabled? " + attack.GetComponent <Collider>().enabled);
        //Debug.Log(newAttack.atkScript);
        //Instantiate(attack, gameObject.GetComponentInParent<Rigidbody>().position + transform.forward, transform.rotation);
        yield return(new WaitForSeconds(attack.attackRecoveryFrames / 30));

        //newAttack.GetComponent<Collider>().enabled = true;
        if (newAttack != null)
        {
            Destroy(newAttack.gameObject);
        }

        canAttack = true;
        //gameObject.GetComponentInParent<ScriptEnemyMovement>().enabled = true;
        detect.enabled = true;
        enabled        = false;
    }
Пример #2
0
    private IEnumerator PlayAttackAnimations(AttackClass attack)
    {
        if (owner != null)
        {
            attackToChecking = attack;
            currentlyAttackedCharacters.Clear();
            owner.movementController.UnlockAnimations();
            owner.movementController.canMove = false;
            owner.canBlocking = false;
            owner.movementController.SetVelocity(Vector2.zero);
            SetFixedDirection(weaponAnimator, owner.movementController.animationController, owner.movementController.lastInputMove);
            owner.movementController.PlayAnimation(attack.weaponAndPlayerAnimationName, true);
            owner.movementController.SetVelocity(owner.movementController.lastInputMove * attack.attackMoveVelocity);
            owner.movementController.DecreseVelocity(attack.attackMoveVelocityDecrease);
            owner.movementController.animationController.speed = attack.attackSpeed;
            if (weaponAnimator)
            {
                weaponAnimator.speed = attack.attackSpeed;
                weaponAnimator.Play(attack.weaponAndPlayerAnimationName);
            }
            owner.attackStartTime = 0;
            yield return(new WaitForSeconds(attack.attackDuration));

            OnAnimationEnd();
        }
    }
Пример #3
0
 public void StartAttack(AttackClass attack)
 {
     CurrentAttack = attack;
     CurrentAttack.StartAttack();
     Attack1Input = false;
     Attack2Input = false;
 }
Пример #4
0
 public void Hit(AttackClass atk, string dir)
 {
     hitBy          = atk;
     hp            -= hitBy.damage;
     fTick          = 0.1f;
     velToSet       = new Vector2(hitBy.knockback.x * (dir == "r" ? 1.0f : -1.0f), hitBy.knockback.y);
     rb.constraints = RigidbodyConstraints2D.FreezeAll;
 }
Пример #5
0
    private IEnumerator AttacksLock(float time)
    {
        currentAttack.enabled = false;
        yield return(new WaitForSeconds(time));

        currentAttack         = FindAttackByName(firstAttackName);
        currentAttack.enabled = true;
    }
Пример #6
0
 // Use this for initialization
 void Start()
 {
     if (useWeaponAnimations)
     {
         weaponAnimator = GetComponent <Animator> ();
     }
     currentAttack         = FindAttackByName(firstAttackName);
     currentAttack.enabled = true;
 }
Пример #7
0
        Object ToHitType(String s)
        {
            if (s.Length > 2)
            {
                return(Failure);
            }

            AttackClass aclass = AttackClass.None;
            AttackPower apower = AttackPower.None;

            if (Char.ToUpper(s[0]) == 'N')
            {
                apower = AttackPower.Normal;
            }
            else if (Char.ToUpper(s[0]) == 'H')
            {
                apower = AttackPower.Hyper;
            }
            else if (Char.ToUpper(s[0]) == 'S')
            {
                apower = AttackPower.Special;
            }
            else if (Char.ToUpper(s[0]) == 'A')
            {
                apower = AttackPower.All;
            }
            else
            {
                return(Failure);
            }

            if (s.Length == 1)
            {
                aclass = AttackClass.All;
            }
            else
            {
                if (Char.ToUpper(s[1]) == 'T')
                {
                    aclass = AttackClass.Throw;
                }
                else if (Char.ToUpper(s[1]) == 'P')
                {
                    aclass = AttackClass.Projectile;
                }
                else if (Char.ToUpper(s[1]) == 'A')
                {
                    aclass = AttackClass.Normal;
                }
                else
                {
                    return(Failure);
                }
            }

            return(new Combat.HitType(aclass, apower));
        }
Пример #8
0
 void SwitchAttacks(int _attackNum)
 {
     if (_attackNum >= 0 && _attackNum < attacks.Length)
     {
         AttackClass _attack = attacks[_attackNum];
         if (_attack.available)
         {
             currentAttack = _attack;
         }
     }
 }
Пример #9
0
    private void Attack(AttackClass attack)
    {
        StopCoroutineSave(EnableNextAttackCoroutine);
        StopCoroutineSave(AttackAnimationCoroutine);
        attack.enabled = false;

        AttackAnimationCoroutine = StartCoroutine(PlayAttackAnimations(attack));

        AttackClass nextAttack = FindAttackByName(attack.nextAttackName);

        EnableNextAttackCoroutine = StartCoroutine(EnableNextAttackTask(nextAttack, attack.timeToNextAttackEnable, attack.timeToNextAttackTimeout));
    }
Пример #10
0
    private IEnumerator EnableNextAttackTask(AttackClass attack, float time_to_enable, float time_to_timeout)
    {
        yield return(new WaitForSeconds(time_to_enable));

        if (attack != null)
        {
            currentAttack         = attack;
            currentAttack.enabled = true;
        }
        yield return(new WaitForSeconds(time_to_timeout - time_to_enable));

        currentAttack.enabled = false;
        StartCoroutine(AttacksLock(currentAttack.delayBetweenCombos));
    }
Пример #11
0
 private void OnAnimationEnd()
 {
     if (owner != null)
     {
         owner.movementController.UnlockAnimations();
         owner.movementController.canMove = true;
         owner.movementController.animationController.speed = 1;
         if (weaponAnimator)
         {
             weaponAnimator.Play("Idle");
             weaponAnimator.speed = 1;
         }
         owner.canBlocking = true;
         attackToChecking  = null;
     }
 }
Пример #12
0
    public IEnumerator RangedAttack()
    {
        //original version saved
        //yield return new WaitForSeconds(aimTime);
        //Vector3 arrowShot = transform.TransformDirection(Vector3.forward);
        ////arrowShot = transform.InverseTransformPoint(arrowShot);
        //Debug.Log(GetComponentInParent<Rigidbody>().name);
        //Instantiate(attack, gameObject.GetComponentInParent<Rigidbody>().position + transform.forward, this.gameObject.GetComponentInParent<Rigidbody>().rotation);
        //attack.atkScript = gameObject.GetComponent<FillerAttackScript>();
        //yield return new WaitForSeconds(waitTime);
        //canAttack = true;
        ////Debug.Log("gameobject" + gameObject);
        ////Debug.Log("gameobjecttrans" + gameObject.GetComponentInParent<Transform>());
        ////Debug.Log("gameobjecttransscript" + gameObject.GetComponentInParent<Transform>().GetComponentInChildren<ScriptDetectionRadius>());
        ////gameObject.GetComponentInParent<Transform>().GetComponentInChildren<ScriptDetectionRadius>().enabled = false;
        ////gameObject.GetComponentInParent<ScriptEnemyMovement>().enabled = false;
        ////gameObject.GetComponentInParent<ScriptEnemyMovement>().enabled = true; //these two lines reset the enemymovement script so it doesn't have any odd values
        //Debug.Log("postattack scriptenemymovement isMoving" + gameObject.GetComponentInParent<ScriptEnemyMovement>().isMovementRunning);

        //detect.enabled = true;

        yield return(new WaitForSeconds(attack.attackPlaceholderAnimFrames / 30));

        Debug.Log("ArrowShot");
        newAttack = Instantiate(attack, gameObject.GetComponentInParent <Rigidbody>().position + transform.forward, this.gameObject.GetComponentInParent <Rigidbody>().rotation) as AttackClass;
        //Debug.Log(this.gameObject.GetComponent<FillerAttackScript>());

        newAttack.atkScript = this.gameObject.GetComponent <FillerAttackScript>();
        //Debug.Log(newAttack.atkScript);
        //Instantiate(attack, gameObject.GetComponentInParent<Rigidbody>().position + transform.forward, transform.rotation);
        yield return(new WaitForSeconds(attack.attackRecoveryFrames / 30));

        if (newAttack != null)
        {
            Destroy(newAttack.gameObject);
        }


        //Debug.Log("rangedenemy moving" + gameObject.GetComponentInParent<ScriptEnemyMovement>().isMovementRunning);
        canAttack      = true;
        detect.enabled = true;
        //if (navi != null)
        //{
        //    navi.enabled = true;
        //}
        enabled = false;
    }
Пример #13
0
    public void EnableAttack(string name)
    {
        AttackClass attack = FindAttackByName(name);

        if (attack != null)
        {
            currentlyAttackedCharacters.Clear();
            attackToChecking = attack;
            if (owner != null)
            {
                owner.attackStartTime = 0;
            }
        }
        else
        {
            Debug.LogError("Cannot find attack desc: " + name);
        }
    }
Пример #14
0
    private void Awake()
    {
        /* Create Moves */
        gMash01 = new AttackClass()
        {
            hitbox       = new Vector4(1.0f, 0.0f, 1.0f, 0.5f),
            moveDistance = new Vector2(0.25f, 0.0f),
            playerVel    = new Vector2(0.0f, 0.0f),
            knockback    = new Vector2(2.0f, 2.0f),
            moveName     = "GroundMash01",
            grounded     = true,
            damage       = 1.0f,
            startup      = 0.1f,
            atkTime      = 0.025f,
            recovery     = 0.25f,
            walkTime     = 0.2f,
            // Etc...
        };
        gwBladeGrab = new AttackClass()
        {
            hitbox       = new Vector4(1.0f, 0.0f, 1.0f, 1.0f),
            moveDistance = new Vector2(-0.1f, 0.0f),
            playerVel    = new Vector2(0.0f, 0.0f),
            knockback    = new Vector2(-0.5f, 3.0f),
            moveName     = "BladeGrab",
            grounded     = true,
            damage       = 1.0f,
            startup      = 0.1f,
            atkTime      = 0.075f,
            recovery     = 0.15f,
            walkTime     = 0.4f,
            // Etc...
        };
        gwGolfSwing = new AttackClass()
        {
            hitbox       = new Vector4(0.75f, -0.15f, 1.5f, 1.0f),
            moveDistance = new Vector2(0.2f, 0.0f),
            playerVel    = new Vector2(0.0f, 0.0f),
            knockback    = new Vector2(8.0f, 6.0f),
            moveName     = "GolfSwing",
            grounded     = true,
            damage       = 1.0f,
            startup      = 0.3f,
            atkTime      = 0.1f,
            recovery     = 0.15f,
            walkTime     = 0.2f,
            // Etc...
        };
        gMash02 = new AttackClass()
        {
            hitbox       = new Vector4(1.0f, 0.0f, 1.0f, 0.5f),
            moveDistance = new Vector2(0.25f, 0.0f),
            playerVel    = new Vector2(0.0f, 0.0f),
            knockback    = new Vector2(2.0f, 2.0f),
            moveName     = "GroundMash02",
            grounded     = true,
            damage       = 1.0f,
            startup      = 0.1f,
            atkTime      = 0.025f,
            recovery     = 0.25f,
            walkTime     = 0.1f,
            // Etc...
        };
        gMash03 = new AttackClass()
        {
            hitbox       = new Vector4(1.0f, 0.05f, 1.0f, 1.1f),
            moveDistance = new Vector2(0.35f, 0.0f),
            playerVel    = new Vector2(0.0f, 0.0f),
            knockback    = new Vector2(2.0f, 2.0f),
            moveName     = "GroundMash03F",
            grounded     = true,
            damage       = 2.0f,
            startup      = 0.1f,
            atkTime      = 0.1f,
            recovery     = 0.35f,
            walkTime     = 0.2f,
            // Etc...
        };
        gMash04F = new AttackClass()
        {
            hitbox       = new Vector4(1.15f, 0.05f, 1.3f, 1.1f),
            moveDistance = new Vector2(0.45f, 0.0f),
            playerVel    = new Vector2(0.0f, 0.0f),
            knockback    = new Vector2(4.5f, 4.5f),
            moveName     = "GroundMash03F",
            grounded     = true,
            damage       = 2.0f,
            startup      = 0.4f,
            atkTime      = 0.125f,
            recovery     = 0.45f,
            walkTime     = 0.3f,
            // Etc...
        };
        gMash01.nextNorm     = gMash02;
        gMash02.nextNorm     = gMash03;
        gMash03.nextNorm     = gMash04F;
        gMash01.nextWait     = gwBladeGrab;
        gwBladeGrab.nextNorm = gwGolfSwing;

        ghLauncher = new AttackClass()
        {
            hitbox       = new Vector4(1.0f, -1.0f, 1.0f, 2.0f),
            moveDistance = new Vector2(0.0f, 0.0f),
            playerVel    = new Vector2(0.0f, 20.0f),
            knockback    = new Vector2(0.5f, 21.0f),
            moveName     = "LaunchEnemyF",
            grounded     = true,
            damage       = 2.0f,
            startup      = 0.1f,
            atkTime      = 0.2f,
            recovery     = 0.15f,
            walkTime     = 0.1f,
        };

        aMash01 = new AttackClass()
        {
            hitbox       = new Vector4(1.5f, 0.0f, 1.5f, 1.0f),
            moveDistance = new Vector2(0.0f, 0.0f),
            playerVel    = new Vector2(0.0f, 7.5f),
            knockback    = new Vector2(0.0f, 6.0f),
            moveName     = "AirMash01",
            grounded     = false,
            damage       = 1.0f,
            startup      = 0.05f,
            atkTime      = 0.05f,
            recovery     = 0.25f,
            walkTime     = 0.1f,
            // Etc...
        };
        aMash02 = new AttackClass()
        {
            hitbox       = new Vector4(1.5f, 0.0f, 1.5f, 1.0f),
            moveDistance = new Vector2(0.0f, 0.0f),
            playerVel    = new Vector2(0.0f, 7.5f),
            knockback    = new Vector2(0.0f, 6.0f),
            moveName     = "AirMash02",
            grounded     = false,
            damage       = 1.0f,
            startup      = 0.05f,
            atkTime      = 0.05f,
            recovery     = 0.25f,
            walkTime     = 0.3f,
            // Etc...
        };
        aMash03F = new AttackClass()
        {
            hitbox       = new Vector4(1.5f, 0.0f, 1.5f, 1.0f),
            moveDistance = new Vector2(0.0f, 0.0f),
            playerVel    = new Vector2(0.0f, 5.0f),
            knockback    = new Vector2(10.0f, -10.0f),
            moveName     = "AirMash03F",
            grounded     = false,
            damage       = 2.0f,
            startup      = 0.1f,
            atkTime      = 0.05f,
            recovery     = 0.35f,
            walkTime     = 0.1f,
            // Etc...
        };
        aMash01.nextNorm = aMash02;
        aMash02.nextNorm = aMash03F;

        awLauncher01 = new AttackClass()
        {
            hitbox       = new Vector4(1.0f, -0.75f, 1.0f, 1.5f),
            moveDistance = new Vector2(0.0f, 0.0f),
            playerVel    = new Vector2(0.0f, 10.0f),
            knockback    = new Vector2(0.0f, 10.0f),
            moveName     = "AirLauncher01",
            grounded     = false,
            damage       = 2.0f,
            startup      = 0.05f,
            atkTime      = 0.3f,
            recovery     = 0.25f,
            walkTime     = 0.1f,
            // Etc...
        };
        awLauncher02F = new AttackClass()
        {
            hitbox       = new Vector4(1.5f, 0.5f, 1.5f, 2.1f),
            moveDistance = new Vector2(0.0f, 0.0f),
            playerVel    = new Vector2(0.0f, -25.0f),
            knockback    = new Vector2(1.0f, -10.0f),
            moveName     = "Launcher02F",
            grounded     = false,
            damage       = 2.0f,
            startup      = 0.1f,
            atkTime      = 0.2f,
            recovery     = 0.2f,
            walkTime     = 0.1f,
            // Etc...
        };
        aMash02.nextWait      = awLauncher01;
        awLauncher01.nextNorm = awLauncher02F;

        amDash = new AttackClass()
        {
            hitbox       = new Vector4(0.75f, -0.1f, 1.0f, 1.75f),
            moveDistance = new Vector2(0.0f, 0.0f),
            playerVel    = new Vector2(7.0f, 7.5f),
            knockback    = new Vector2(-10.0f, -10.0f),
            moveName     = "Lock & Key",
            grounded     = false,
            damage       = 1.0f,
            startup      = 0.1f,
            atkTime      = 0.15f,
            recovery     = 0.25f,
            walkTime     = 0.1f,
            // Etc...
        };
    }
Пример #15
0
 public HitType(AttackClass aclass, AttackPower apower)
 {
     m_class = aclass;
     m_power = apower;
 }
Пример #16
0
        public static ItemComponent CreateNewItem(MessageProvider messageProvider, GameState state,
            string name, string imageLocation, string description,
            string modelPath, Vector2i size, Vector3 offset, Quaternion rotation, Shape shape, ItemLocation location,
            AttackClass attackClasses, ItemUsage itemUsages, Protection protection, Material physicsMaterial,
            float mass, float healthDelta, float usageDeltaPerUsage, float attackStrength, float throwPower, float usage)
        {
            var entity = EntityFactory.Instance.CreateWith(name, messageProvider,
                systems: new[] { typeof(ItemSystem), typeof(ModelSystem), typeof(PhysicsSystem) });

            var item = entity.GetComponent<ItemComponent>();
            item.ImageLocation = imageLocation;
            item.Description = description;
            item.Size = size;
            item.Location = location;
            item.AttackClasses = attackClasses;
            item.ItemUsages = itemUsages;
            item.Protection = protection;
            item.HealthDelta = healthDelta;
            item.AttackStrength = attackStrength;
            item.ThrowPower = throwPower;
            item.Usage = usage;
            item.UsageDeltaPerUsage = usageDeltaPerUsage;
            item.Mass = mass;
            item.PhysicsMaterial = physicsMaterial;
            item.PositionOffset = offset;
            item.Rotation = rotation;
            item.ItemUsageHandler = new MazeItemUseHandler();

            var model = new ModelSceneObject(modelPath);
            model.Enabled = true;
            state.Scene.AddObject(model);
            entity.GetComponent<ModelComponent>().Model = model;

            var transform = entity.GetComponent<TransformComponent>();
            var physics = entity.GetComponent<PhysicsComponent> ();

            if (shape == null)
            {
                List<JVector> vertices = new List<JVector>();
                model.Model.Meshes[0].Vertices.ForEach(x => vertices.Add(x.ToJitterVector()));

                List<TriangleVertexIndices> indices = new List<TriangleVertexIndices>();

                for(int i = 0; i < model.Model.Meshes[0].Indices.Length; i+= 3)
                {
                    int i0 = model.Model.Meshes[0].Indices[i+0];
                    int i1 = model.Model.Meshes[0].Indices[i+1];
                    int i2 = model.Model.Meshes[0].Indices[i+2];

                    indices.Add(new TriangleVertexIndices(i0, i1, i2));
                }

                shape = new TriangleMeshShape(new Octree(vertices, indices));
            }

            var body = new RigidBody(shape);
            body.Position = transform.Position.ToJitterVector ();
            if (mass >= 0)
                body.Mass = mass;
            body.Material = physicsMaterial;
            body.AllowDeactivation = true;
            body.Tag = entity;

            state.PhysicsManager.World.AddBody(body);
            physics.RigidBody = body;
            physics.World = state.PhysicsManager.World;
            physics.PhysicsApplying = AffectedByPhysics.Orientation | AffectedByPhysics.Position;
            physics.RigidBody.IsStatic = false;
            physics.RigidBody.IsActive = false;
            physics.RigidBody.Position = transform.Position.ToJitterVector();
            model.Position = transform.Position;

            return item;
        }
Пример #17
0
    public void Update()
    {
        if (CurrentAttack != null)
        {
            CurrentAttack.Update(Time.deltaTime, this);
        }

        if (AllowAttackInput)
        {
            //buffer attack inputs
            if (Input.GetKeyDown(KeyCode.K))
            {
                Attack1Input = true;
                animator.SetBool("isAttacking", true);
            }
            else
            {
                animator.SetBool("isShooting", false);
                animator.SetBool("isAttacking", false);
            }
            if (Input.GetKeyDown(KeyCode.J))
            {
                Attack2Input = true;
                animator.SetBool("isShooting", true);
            }
            else
            {
                animator.SetBool("isAttacking", false);
                animator.SetBool("isShooting", false);
            }
        }

        if (AllowNewAttack)
        {
            //loop through all attacks and check if one is availible
            int         priority   = 0;
            AttackClass nextAttack = null;
            int         linkValue  = 0;
            if (CurrentAttack != null)
            {
                linkValue = CurrentAttack.MyLinkValue;
            }
            foreach (AttackClass attack in attacks)
            {
                if (attack.TakesInput(Attack1Input, Attack2Input, linkValue, priority))
                {
                    nextAttack = attack;
                    priority   = nextAttack.Priority;
                }
            }
            //if an attack is availible start it
            if (nextAttack != null)
            {
                StartAttack(nextAttack);
            }
        }

        if (damageTimer > 0)
        {
            damageTimer -= Time.deltaTime;
            if (damageTimer <= 0)
            {
                spriteRenderer.color = Color.white;
            }
        }

        spriteRenderer.flipX = facing == -1;
    }
Пример #18
0
 public void EndAttack()
 {
     CurrentAttack    = null;
     AllowAttackInput = true;
     AllowNewAttack   = true;
 }
Пример #19
0
 public void DisableAttack()
 {
     attackToChecking = null;
 }
Пример #20
0
		public HitType(AttackClass aclass, AttackPower apower)
		{
			m_class = aclass;
			m_power = apower;
		}