Exemple #1
0
 //Attack and deal damage if a player was hit
 public void Attack()
 {
     action = E_ACTION.ATTACK;
     //If there is no valid target in the attackbox then the attack is missed
     if (attackHitbox.target != null)
     {
         attackHitbox.target.transform.GetComponent <PlayerHealth>().DamagePlayer(attackDamage);
         if (attackHitbox.target.transform.GetComponent <PlayerHealth>().playerState == PlayerHealth.PlayerState.ALIVE)
         {
             //Set 0 to 1 and 1 to 0
             path = FlowFieldGenerator.GetInstance().AttemptTarget(path * -1 + 1);
         }
         //DEBUG
         //transform.Find("AttackEffect").GetComponent<ParticleSystem>().Play();
         Debug.Log("attacking " + attackHitbox.target.name);
     }
 }
Exemple #2
0
 private void set_actionString(E_ACTION value)
 {
     switch (value)
     {
         case E_ACTION.cp:
             actionString = (changedirection) ? "Im Vergleichsordner ändern" : "In der Quelle aktualisieren";
             break;
         case E_ACTION.cpn:
             actionString = (changedirection) ? "Im Vergleichsordner löschen" : "In die Quelle kopieren";
             break;
         case E_ACTION.del:
             actionString = (changedirection) ? "In den Vergleichsordner kopieren" : "In der Quelle löschen";
             break;
         case E_ACTION.mv:
             actionString = (changedirection) ? "Im Vergleichsordner verschieben" : "In der Quelle verschieben";
             break;
         case E_ACTION.none:
             actionString = "Keine Aktion";
             break;
     }
     NotifyPropertyChanged("ActionString");
 }
Exemple #3
0
        static void TestACTION(TestData t)
        {
            AesEncryption aes = new AesEncryption(base64Key: t.APISessionKey, APIAuthKey: t.APIAuthKey);

            //Console.WriteLine($"\nTest MakeEncr");
            //
            //// Test MakeEncr directly
            //ACTION query = new ACTION(type.QUERY, t.lastActionID + 1);
            //
            //encr encr1 = MakeEncr(query, aes/*, t.APIAuthKey*/, t.iv);
            //Debug.Assert(encr1.payload == t.expected_payload);
            //
            //string mac1 = hmac(encr1, aes);
            //Debug.Assert(mac1 == t.expected_mac);

            Console.WriteLine($"\nTest E_ACTION wrapper");
            // Test E_ACTION wrapper - should produce same "encr"
            E_ACTION e_ACTION = new E_ACTION(type.QUERY, t.lastActionID + 1, aes, t.iv);

            encr encr2 = e_ACTION.data;

            Debug.Assert(encr2.payload == t.expected_payload);

            //string mac2 = hmac(encr2, aes);
            string mac2 = e_ACTION.mac;

            Debug.Assert(mac2 == t.expected_mac);

            string json = JsonConvert.SerializeObject(e_ACTION);

            Console.WriteLine($"Frame: {json}\n");

            if (t.expected_frame != null)
            {
                Debug.Assert(t.expected_frame == json);
            }
        }
Exemple #4
0
    // Update is called once per frame
    void Update()
    {
        switch (state)
        {
        case E_STATE.NORMAL:
            //Disable fire effect here?
            break;

        case E_STATE.IGNITED:
            //Mabye display some fire effect here?
            health.DamageHealth(fireDamageOverTime * Time.deltaTime);
            fireTime -= Time.deltaTime;
            //Enemy is no longer on fire
            if (fireTime <= 0.0f)
            {
                state = E_STATE.NORMAL;
            }
            break;
        }

        //Delayed death, use the dead() method for anything needing to happen on kill
        if (!alive)
        {
            deadTimer -= Time.deltaTime;
            if (deadTimer <= 0.0f)
            {
                spawner.Despawn(gameObject);
            }

            renderer.material.SetFloat("Dissolve_Value", (deadTimer * -1.0f) + 1.0f);
            acceleration = Vector3.zero;
            velocity     = Vector3.zero;
            return;
        }

        //Sound
        groanTimer -= Time.deltaTime;
        if (groanTimer <= 0.0f)
        {
            //Randomize the pitch
            audio.pitch = originalPitch + (Random.Range(-1.0f, 1.0f) * pitchVariance);

            //Play a sound at random
            if (Random.value >= 0.5f)
            {
                audio.PlayOneShot(groan1);
            }
            else
            {
                audio.PlayOneShot(groan2);
            }

            //Countdown till next groan
            groanTimer = groanDelay + (Random.Range(-1.0f, 1.0f) * groanVariance);
        }

        //If we have no path get one
        if (path == -1)
        {
            attackLocked = false;
            if (p1HP.playerState == PlayerHealth.PlayerState.ALIVE)
            {
                path = 0;
            }
            else if (p2HP.playerState == PlayerHealth.PlayerState.ALIVE)
            {
                path = 1;
            }
            else
            {
                return;
            }
        }

        //Debug.Log(path);
        //Just incase
        if (path == 0 && p1HP.playerState != PlayerHealth.PlayerState.ALIVE)
        {
            path     = -1;
            engaging = false;
        }
        else if (path == 1 && p2HP.playerState != PlayerHealth.PlayerState.ALIVE)
        {
            path     = -1;
            engaging = false;
        }

        //Cycle through all behaviours or attack
        if (engaging) //Attack
        {
            if (target == null)
            {
                engaging    = false;
                attackTimer = 0.0f;
                attackRecov = 0.0f;
                return;
            }
            //Move directly towards our target
            acceleration = target.transform.position - transform.position;

            attackTimer -= Time.deltaTime;
            if (attackLocked)
            {
                anim.SetBool("IsAttacking", true);
                if (attackTimer <= 0.0f && attackRecov <= 0.0f)
                {
                    Attack();
                    //Allow movement and rotation again
                    attackLocked = false;
                    //Set the time for cooldown between attacks
                    attackRecov = attackRate;
                }
            }
            else
            {
                attackRecov -= Time.deltaTime;
            }
        }
        else //Behaviours
        {
            anim.SetBool("IsAttacking", false);
            //Deadlock prevention!
            attackLocked = false;

            acceleration = Vector3.zero;
            foreach (BaseBehaviour b in behaviours)
            {
                acceleration += b.Update() * b.weight;
            }
        }
        //No up velocity
        acceleration.y = 0.0f;
        //Normalize it and multiply it by our speed
        acceleration.Normalize();
        acceleration *= movementSpeed;

        //Prevent movement while attacking ------
        if (attackLocked)
        {
            acceleration = Vector3.zero;
            velocity     = Vector3.zero;
        }

        velocity += acceleration / mass;
        velocity *= drag;

        //rotate towards where we are going
        if (velocity != Vector3.zero)
        {
            anim.SetBool("IsMoving", true);
            transform.localRotation = Quaternion.LookRotation(velocity);
            //transform.rotation.SetFromToRotation(Vector3.zero, velocity);
            action = E_ACTION.MOVE;
        }
        else
        {
            anim.SetBool("IsMoving", false);
        }

        //Cap max velocity
        if (velocity.magnitude > movementSpeed)
        {
            velocity = Vector3.Normalize(velocity) * movementSpeed;
        }

        //Anchor the enemy to the floor (rigidbody raycast fix)
        transform.position = new Vector3(transform.position.x, 0.0f, transform.position.z);
    }