Ejemplo n.º 1
0
    /**
     * @param initHealth
     * @param initShield
     * @param initEnergy
     * @param rechargeType
     * @param weaponType
     * @param ammoType
     */
    public bool InitEnemy(int initLifes,
                          float initHealth,
                          float initShield,
                          float initEnergy,
                          CoreSystems.Energy.eRechargeTypes rechargeType,
                          WeaponSystems.eWeaponTypes weaponType,
                          Weapon.eAmmoTypes ammoType,
                          bool autoShoting)
    {
        bool ret = true;

        ret = nesCoreSys.Init(initLifes, initHealth, initShield, initEnergy, rechargeType) && ret;
        ret = nesWeapSys.Init(weaponType, ammoType, autoShoting) && ret;

        return(ret);
    }
    public void OnTriggerEnter(Collider other)
    {
        if (other.tag == "Boundary" || other.tag == "Shield")
        {
            // 1) ignore BOUNDARY --> boundary will destroy THIS after
            //	  OnTriggerExit of Destroy By Boundary script is called
            // 2) ignore SHIELD --> for unknown reason, shield is collieding
            //	  with the ship in the moment, when the shield is activated...
            return;
        }


        // player ship is hit by ENEMY BULLET
        if (other.tag == "Bullet")
        {
            // fail-safe
            float bullDamage = 20.0f;

            BulletController refBullCtrl = other.gameObject.GetComponent <BulletController>();
            if (refBullCtrl != null)
            {
                bullDamage = refBullCtrl.nesBulletSys.GetDamageCollision();
            }
            else
            {
                Debug.LogWarning("PLAYER >> Unable to obtain damage of bullet, which just hit the player...");
            }

            // destroy enemy's bullet
            Destroy(other.gameObject);

            // show explosion caused by hit
            //Instantiate (refExplosionPlayer, transform.position, transform.rotation);

            bool isAlive = HitShip(bullDamage);

            // show actualized gui texts
            RuntimeContext.GetInst().StorePlayerCore(nesCoreSys.nesLifes.GetLifes(),
                                                     nesCoreSys.nesHealth.GetHealth(),
                                                     nesCoreSys.nesShield.GetShield());

            // store flags for bonus generation into global context container
            RuntimeContext.GetInst().StorePlayerCoreMax(nesCoreSys.nesHealth.IsMaxHealth(),
                                                        nesCoreSys.nesShield.IsMaxShield());

            if (!isAlive)
            {
                PlayerDestruction();
            }
        }
        // player ship is hit by BONUS
        else if (other.tag == "Bonus")
        {
            BonusController refBonCtrl = other.gameObject.GetComponent <BonusController>();
            if (refBonCtrl != null)
            {
                if (refBonCtrl.bonusType == "Energy")
                {
                    // recharge energy & show actualized gui texts
                    RuntimeContext.GetInst().StorePlayerCoreEnergy(
                        nesCoreSys.nesEnergy.RechargeEnergy(refBonCtrl.bonusValue),
                        nesCoreSys.nesEnergy.actualRechargeType);
                }
                else if (refBonCtrl.bonusType == "Shield")
                {
                    // shield was initialized properlly
                    if (refShieldControll != null)
                    {
                        // activate shield's GameObject
                        refShieldControll.gameObject.SetActive(true);

                        // recharge shield & show actualized gui texts
                        RuntimeContext.GetInst().StorePlayerCoreShield(
                            nesCoreSys.nesShield.RechargeShield(refBonCtrl.bonusValue),
                            nesCoreSys.nesShield.IsMaxShield());
                    }
                    else
                    {
                        Debug.LogWarning("PLAYER >> Shield was not initialized properlly, no bonus added...");
                    }
                }
                else if (refBonCtrl.bonusType == "Health")
                {
                    // recharge health & show actualized gui texts
                    RuntimeContext.GetInst().StorePlayerCoreHealth(
                        nesCoreSys.nesHealth.RechargeHealth(refBonCtrl.bonusValue),
                        nesCoreSys.nesHealth.IsMaxHealth());
                }
                else
                {
                    Debug.Log("PLAYER >> Unknown bonus");
                }

                //Debug.Log ("PLAYER >> Bonus >> " + refBonCtrl.bonusType + " >> +" + refBonCtrl.bonusValue + " units");
            }

            // destroy bonus object
            Destroy(other.gameObject);
        }
        //
        else if (other.tag == "Weapon")
        {
            BonusController refBonCtrl = other.gameObject.GetComponent <BonusController>();
            if (refBonCtrl != null)
            {
                bool anyChange = false;

                if (refBonCtrl.bonusType == "AmmoType")
                {
                    bool ammoTypeOk = true;

                    switch (refBonCtrl.bonusMode)
                    {
                    case "Advanced":
                        // check, if `advanced` ammo type can be activated
                        if (nesWeapSys.actualAmmoType == Weapon.eAmmoTypes.Better)
                        {
                            if (!nesWeapSys.Init(nesWeapSys.actualWeaponType,
                                                 Weapon.eAmmoTypes.Advanced,
                                                 false))
                            {
                                ammoTypeOk = false;
                                break;
                            }

                            anyChange = true;
                        }
                        break;

                    case "Hardcore":
                        // check, if `hardcore` ammo type can be activated
                        if (nesWeapSys.actualAmmoType == Weapon.eAmmoTypes.Advanced)
                        {
                            if (!nesWeapSys.Init(nesWeapSys.actualWeaponType,
                                                 Weapon.eAmmoTypes.Hardcore,
                                                 false))
                            {
                                ammoTypeOk = false;
                                break;
                            }

                            anyChange = true;
                        }
                        break;

                    case "Armagedon":
                        // check, if `armagedon` ammo type can be activated
                        if (nesWeapSys.actualAmmoType == Weapon.eAmmoTypes.Hardcore)
                        {
                            if (!nesWeapSys.Init(nesWeapSys.actualWeaponType,
                                                 Weapon.eAmmoTypes.Armagedon,
                                                 false))
                            {
                                ammoTypeOk = false;
                                break;
                            }

                            anyChange = true;
                        }
                        break;

                    default:
                        Debug.LogWarning("PLAYER >> Unknown Ammo Type");
                        break;
                    }

                    if (!ammoTypeOk)
                    {
                        // initialization of new ammo type failed...
                        Debug.LogWarning("PLAYER >> Unable to initialize eAmmoTypes::" + refBonCtrl.bonusMode);
                    }
                }
                else if (refBonCtrl.bonusType == "Weapon")
                {
                    bool weaponSystemOk = true;

                    switch (refBonCtrl.bonusMode)
                    {
                    case "ForwardBetter":
                        // check, if `forward better` weapon type can be activated
                        if (nesWeapSys.actualWeaponType == WeaponSystems.eWeaponTypes.ForwardBasic)
                        {
                            if (!nesWeapSys.Init(WeaponSystems.eWeaponTypes.ForwardBetter,
                                                 Weapon.eAmmoTypes.Better,
                                                 false))
                            {
                                weaponSystemOk = false;
                                break;
                            }

                            anyChange = true;
                        }
                        break;

                    case "ForwardAdvanced":
                        // check, if `forward advanced` weapon type can be activated
                        if (nesWeapSys.actualWeaponType == WeaponSystems.eWeaponTypes.ForwardBetter)
                        {
                            if (!nesWeapSys.Init(WeaponSystems.eWeaponTypes.ForwardAdvanced,
                                                 Weapon.eAmmoTypes.Better,
                                                 false))
                            {
                                weaponSystemOk = false;
                                break;
                            }

                            anyChange = true;
                        }
                        break;

                    case "DirectionalBasic":
                        // check, if `directional basic` weapon type can be activated
                        if (nesWeapSys.actualWeaponType == WeaponSystems.eWeaponTypes.ForwardAdvanced)
                        {
                            if (!nesWeapSys.Init(WeaponSystems.eWeaponTypes.DirectionalBasic,
                                                 Weapon.eAmmoTypes.Better,
                                                 false))
                            {
                                weaponSystemOk = false;
                                break;
                            }

                            anyChange = true;
                        }
                        break;

                    default:
                        Debug.LogWarning("PLAYER >> Unknown Weapon System");
                        break;
                    }

                    if (!weaponSystemOk)
                    {
                        // initialization of new weapon type failed...
                        Debug.LogWarning("PLAYER >> Unable to initialize eWeaponTypes::" + refBonCtrl.bonusMode);
                    }
                }

                if (anyChange)
                {
                    if (!nesWeapSys.ActivateWeapons())
                    {
                        Debug.LogError("PLAYER >> FAILED to activate weapon systems (!!)");
                        anyChange = false;
                    }
                }

                if (anyChange)
                {
                    // store current state of ship systems for next-time loading and bonus generation system
                    RuntimeContext.GetInst().StorePlayerWeapon(nesWeapSys.actualWeaponType,
                                                               nesWeapSys.actualAmmoType);
                }
            }
            else
            {
                Debug.LogError("PLAYER >> FAILED to obtain reference to `BonusController`");
            }

            // destroy bonus object
            Destroy(other.gameObject);
        }
        // player ship is hit by ASTEROID or ENEMY SHIP
        else if (other.tag == "Asteroid" || other.tag == "Enemy")
        {
            bool isAlive = HitShip(GetCollisionDamageRate());

            // show actualized gui texts
            RuntimeContext.GetInst().StorePlayerCore(nesCoreSys.nesLifes.GetLifes(),
                                                     nesCoreSys.nesHealth.GetHealth(),
                                                     nesCoreSys.nesShield.GetShield());

            // store flags for bonus generation into global context container
            RuntimeContext.GetInst().StorePlayerCoreMax(nesCoreSys.nesHealth.IsMaxHealth(),
                                                        nesCoreSys.nesShield.IsMaxShield());

            if (!isAlive)
            {
                PlayerDestruction();
            }
        }
        else
        {
            Debug.Log("PLAYER >> Something just hit the ship (!!) >> " + other.name);
        }
    }