Пример #1
0
    // Update is called once per frame
    void Update()
    {

        //Sistema di Rotazione (non ce n'è bisogno per ora)
        if (Input.GetKey(KeyCode.A))
            transform.Rotate(Vector3.up, -1); //-1 sono i gradi di rotazione
        else
            if (Input.GetKey(KeyCode.D))
                transform.Rotate(Vector3.up, 1);


        // FINE SISTEMA DI ROTAZIONE


        //Usiamo i tasti per muoverci
        if (Input.GetKey(KeyCode.K)) //Tasto per debuggare
        {
            long tempo_now = UnixTimeNow();
            long t = tempo_now - tempo_attacco;
        }

        //tasto per spawnare npc
        if (Input.GetKey(KeyCode.U))
        {
            insertNpc();
        }

        if (Input.GetMouseButtonDown(1))
        {
            if (!isTargetting)
            {
                camera.transform.position = new Vector3(armacamera_p_x, armacamera_p_y, armacamera_p_z);
                camera.transform.rotation = new Quaternion(armacamera_o_x, armacamera_o_y, armacamera_o_z, 0);
                isTargetting = true;
                Debug.Log("Camera spostata sull'arma");
            }
        }
        if (Input.GetMouseButtonUp(1))
        {
            if (isTargetting)
            {
                camera.transform.position = new Vector3(camera_p_x, camera_p_y, camera_p_z);
                camera.transform.rotation = new Quaternion(camera_o_x, camera_o_y, camera_o_z, 0);
                isTargetting = false;
                Debug.Log("Camera spostata sul personaggio");
            }
        }
        

        //Fine sistema di movimento semplice
        /*
        if(Input.GetMouseButtonDown(0)){
            if(currentTarget!=null){
                currentTarget.stopParticle();
                currentTarget = null;
                TM.setTargetTrue(false);
            }
        }
        */
        if (Input.GetKeyDown(KeyCode.L))
        {
            save();
        }
        if (Input.GetKeyDown(KeyCode.M))
        {
            load("player");
        }

        //andare nel menù
        if (Input.GetKey(KeyCode.Escape))
        {
            DbManager.setInstance();
            query = "INSERT INTO player(id, name, level, exp, expToNextLvl, health, maxhealth, position_x, position_y, position_z, orientation_x, orientation_y, orientation_z, savetype) VALUES(2, 'player', " + level + ", " + exp + ", " + expToNextLevel + ", " + health + ", " + maxHealth + ", " + transform.position.x + ", " + transform.position.y + ", " + transform.position.z + ", " + transform.rotation.x + ", " + transform.rotation.y + ", " + transform.rotation.z + ", 1);";
            Application.LoadLevel("menu");
        }

        //Check morte del player
        if (health <= 0)
        {
            Debug.Log("Player morto.");
            //Respawna il player
            transform.position = spawnPos;
            //Resetta la vita
            health = maxHealth;
            wasDead = true;
            TM.SendMessage("playerText", health + "-" + maxHealth + "-" + " " + "-" + level + "-" + exp + "-" + expToNextLevel);
        }

        if (currentTarget != null)
        {
            if (Vector3.Distance(transform.position, currentTarget.transform.position) <= 2)
            {
                isAttacking = true;
                attackEnemy(currentTarget);
            }
            else
                isAttacking = false;
        }
        else
            isAttacking = false;

        if (currentTarget != null && !isAttacking)
        {
            TM.setTargetTrue(true);
            string targetInfo = currentTarget.getHealth() + "-" + currentTarget.getMaxHealth() + "-" + " " + "-" + currentTarget.getLevel() + "-";
            TM.SendMessage("targetText", targetInfo);
        }
        if (currentTarget != null)
        {
            if (currentTarget.isDead())
            {
                currentTarget = null;
                TM.setTargetTrue(false);
            }
        }

        if (currentTarget == null && !isAttacking)
        {

            /*
             * ********************************************
             * Health regeneration System
             * ********************************************/
            /*tempo_ora_regen_health = UnixTimeNow(); //registro quando sono uscito fuori dal combat
            
            if ((tempo_ora_regen_health - t) >= 5)
            {
                int max_health_player = getMaxHealthPlayer();
                if (health < max_health_player)
                    health = health + (max_health_player / 100) * 3; //+3% ogni 5 secondi (in questo caso +7.5)
                if (health >= max_health_player)
                    health = max_health_player;
                TM.SendMessage("playerText", health + "-" + maxHealth + "-" + " " + "-" + level + "-" + exp + "-" + expToNextLevel);
                t = UnixTimeNow();
                //Debug.Log("Doing Health regeneration");
                /*if (health == max_health_player)
                    Debug.Log("Health regeneration completed");
            }*/
        }


    }
Пример #2
0
 void attackEnemy(Infetto target)
 {
     if (attackTime - Time.deltaTime <= 0)
     {
         int dam = UnityEngine.Random.Range(10, 25);
         target.SendMessage("applyDamage", dam);
         string targetInfo = currentTarget.getHealth() + "-" + currentTarget.getMaxHealth() + "-" + dam + "-" + currentTarget.getLevel() + "-";
         TM.SendMessage("targetText", targetInfo);
         attackTime = 1.5F;
     }
     else
         attackTime -= Time.deltaTime;
 }