예제 #1
0
    /// <summary>
    /// Force pickup
    /// </summary>
    public void PickUp(Player player)
    {
        if(player && player.state != (int)EntityState.Dead && player.state != (int)EntityState.Invalid && gameObject.activeInHierarchy) {
            float val = value;

            switch(type) {
                case ItemType.Health:
                    if(player.stats.curHP < player.stats.maxHP) {
                        if(player.stats.curHP + val > player.stats.maxHP) {
                            player.stats.subTankEnergyCurrent += (player.stats.curHP + val) - player.stats.maxHP;
                        }

                        player.stats.curHP += val;
                    }
                    else {
                        float curTankAmt = player.stats.subTankEnergyCurrent;
                        player.stats.subTankEnergyCurrent += val;

                        if(curTankAmt < player.stats.subTankEnergyCurrent)
                            SoundPlayerGlobal.instance.Play(sfxId);
                    }
                    break;

                case ItemType.Energy:
                    Weapon wpn = null;
                    if(player.currentWeaponIndex == 0 || player.currentWeapon.isMaxEnergy) {
                        wpn = player.lowestEnergyWeapon;
                    }
                    else
                        wpn = player.currentWeapon;

                    if(wpn && !wpn.isMaxEnergy) {
                        if(wpn.currentEnergy + val > Weapon.weaponEnergyDefaultMax) {
                            player.stats.subTankWeaponCurrent += (wpn.currentEnergy + val) - Weapon.weaponEnergyDefaultMax;
                        }

                        wpn.currentEnergy += val;

                        if(wpn != player.currentWeapon)
                            SoundPlayerGlobal.instance.Play(sfxId);
                    }
                    else {
                        float curTankAmt = player.stats.subTankWeaponCurrent;
                        player.stats.subTankWeaponCurrent += val;

                        if(curTankAmt < player.stats.subTankWeaponCurrent)
                            SoundPlayerGlobal.instance.Play(sfxId);
                    }
                    break;

                case ItemType.Life:
                    PlayerStats.curLife++;
                    HUD.instance.RefreshLifeCount();
                    SoundPlayerGlobal.instance.Play(sfxId);
                    break;

                case ItemType.HealthUpgrade:
                    SlotInfo.AddHPMod(bit);
                    Player.instance.stats.RefreshHPMod();
                    SoundPlayerGlobal.instance.Play(sfxId);
                    break;

                case ItemType.EnergyTank:
                    if(bit == 0)
                        player.stats.AcquireSubTankEnergy1();
                    else
                        player.stats.AcquireSubTankEnergy2();

                    SoundPlayerGlobal.instance.Play(sfxId);
                    break;

                case ItemType.WeaponTank:
                    if(bit == 0)
                        player.stats.AcquireSubTankWeapon1();
                    else
                        player.stats.AcquireSubTankWeapon2();

                    SoundPlayerGlobal.instance.Play(sfxId);
                    break;

                case ItemType.Armor:
                    player.stats.AcquireArmor();
                    player.RefreshArmor();

                    SoundPlayerGlobal.instance.Play(sfxId);
                    break;

                case ItemType.Invul:
                    player.stats.invulGO.SetActive(true);
                    break;
            }

            if(savePickUp) {
                SceneState.instance.SetGlobalFlag(LevelController.levelPickupBitState, pickupBit, true, false);

                bool isHardcore = SlotInfo.gameMode == SlotInfo.GameMode.Hardcore;
                if(isHardcore) {
                    int dat = SceneState.instance.GetGlobalValue(LevelController.levelPickupBitState, 0);
                    SceneState.instance.SetValue(LevelController.levelPickupBitState, dat, true);
                }
            }

            if(!string.IsNullOrEmpty(sound)) {
                SoundPlayerGlobal.instance.Play(sound);
            }

            if(collider)
                collider.enabled = false;

            if(pickupCallback != null)
                pickupCallback(this);

            if(dialogTextRefs != null && dialogTextRefs.Length > 0) {
                mCurDialogTextInd = 0;
                UIModalCharacterDialog dlg = UIModalCharacterDialog.Open(true, UIModalCharacterDialog.defaultModalRef,
                                                                         dialogTextRefs[mCurDialogTextInd], HUD.gitgirlNameRef, HUD.gitgirlPortraitRef, null);
                dlg.actionCallback += OnDialogAction;

            }
            else {
                if(!string.IsNullOrEmpty(popTextRef))
                    HUD.instance.PopUpMessage(GameLocalize.GetText(popTextRef));

                Release();
            }
        }
    }