Beispiel #1
0
 private void Awake()
 {
     _unit = GetComponent <Unit>();
     _grenadeController  = GetComponent <GrenadeController>();
     _weaponController   = GetComponent <WeaponController>();
     _movementController = GetComponent <MovementController>();
 }
Beispiel #2
0
    private void DrawGrenade(int grenadeID)
    {
        meleeObject.SetActive(false);

        GrenadeController toInstantiate = GrenadeDatabase.GetGrenadeByID(grenadeID);
        GrenadeController grenInstance  = (GrenadeController)Instantiate(toInstantiate);

        grenInstance.transform.parent        = weaponsParent;
        grenInstance.transform.localPosition = toInstantiate.thirdPersonPosition;
        grenInstance.transform.localRotation = toInstantiate.thirdPersonRotation;
        grenInstance.PrepareForMultiplayer();
        GetComponent <AudioSource>().PlayOneShot(drawSound, 0.7f);

        pullPinSound               = toInstantiate.pullPinSound;
        throwSound                 = toInstantiate.throwSound;
        currentGHP                 = grenInstance.GetComponent <GrenadeHandler_Proxy>();
        currentGHP.whp             = this;
        currentGHP.grenadePrefab   = grenInstance.grenadePrefab;
        currentGHP.displayMesh     = grenInstance.displayMesh;
        currentGHP.throwStr        = grenInstance.throwStrength;
        currentGHP.tossStr         = grenInstance.tossStrength;
        currentGHP.ignoreColliders = ignoreGrenades;
        baseDelay       = grenInstance.baseDelay;
        detonationDelay = grenInstance.detonationDelay;
        Destroy(grenInstance);

        currentGC      = null;
        currentVisuals = null;
    }
Beispiel #3
0
 void Awake()
 {
     greCtrl       = GetComponentInChildren <GrenadeController>();
     playerCtrl    = GetComponent <PlayerController>();
     gunCtrl       = GetComponentInChildren <GunController>();
     respownPlayer = FindObjectOfType <RespownPlayer>();
 }
Beispiel #4
0
    public void RemoveGrenadeFromInventory(int index)
    {
        int sn = Mathf.Clamp(index, 0, 1);

        if (grenadeInventory[sn])
        {
            if (curGrenade == grenadeInventory[sn])
            {
                curGrenade = null;
            }

            Destroy(grenadeInventory[sn].gameObject);
            if (sn == 0)
            {
                gam.grenadeTypeOne = -1;
            }
            else if (sn == 1)
            {
                gam.grenadeTypeTwo = -1;
            }

            grenadeInventory[sn] = null;
            SwitchToAvailableGrenade();
        }
    }
    protected override void buy()
    {
        tempGun           = currPlayer.transform.GetComponent <GunController>().equippedGun;
        grenadeController = currPlayer.transform.GetComponent <GrenadeController>();

        if (currPlayer.money >= cost && (tempGun.ammoLeft < tempGun.maxAmmo || grenadeController.grenades < grenadeController.maxGrenades))//purchaseable
        {
            sound[0].Play();
            currPlayer.money -= cost;
            if (tempGun.ammoLeft + ammoAmount > tempGun.maxAmmo)
            {
                tempGun.ammoLeft = tempGun.maxAmmo;
            }
            else
            {
                tempGun.ammoLeft += ammoAmount;
            }

            if (grenadeController.grenades + grenadeAmount > grenadeController.maxGrenades)
            {
                grenadeController.grenades = grenadeController.maxGrenades;
            }
            else
            {
                grenadeController.grenades += grenadeAmount;
            }
        }
        else
        {
            if (!sound[1].isPlaying)
            {
                sound[1].Play();
            }
        }
    }
Beispiel #6
0
    private void Throw(int direction)
    {
        GameObject grenade = Instantiate(grenadePrefab, grenadeSpawn.position, grenadeSpawn.rotation);

        grenade.layer = LayerMask.NameToLayer("Damage" + skillManager.playerNumber);
        GrenadeController jorgeGrenade = grenade.GetComponent <GrenadeController>();

        jorgeGrenade.horizontal   = horizontalThrow * direction;
        jorgeGrenade.vertical     = verticalThrow;
        jorgeGrenade.enemy        = skillManager.enemy;
        jorgeGrenade.stunDuration = stunDuration;
    }
        public GrenadeControllerSwitchCommand(BattleUnit unit) : base(unit)
        {
            _defaultWeaponController = unit.WeaponController;
            _nullWeaponController    = unit.GetComponentInChildren <NullWeaponController>(true);
            _grenadeController       = unit.GetComponentInChildren <GrenadeController>(true);

            GameHelper.CheckForNull(_defaultWeaponController, nameof(GrenadeControllerSwitchCommand));
            GameHelper.CheckForNull(_nullWeaponController, nameof(GrenadeControllerSwitchCommand));
            GameHelper.CheckForNull(_grenadeController, nameof(GrenadeControllerSwitchCommand));

            _grenadeController.OnGrenadeLaunchedCallback = OnGrenadeLaunchedCallback;
        }
Beispiel #8
0
 public void OnSelect(bool multiplayer)
 {
     if (multiplayer)
     {
         if (Topan.Network.isConnected && wm.rootNetView != null)
         {
             wm.rootNetView.RPC(Topan.RPCMode.Others, "NetworkSelectGrenade", (byte)curGrenade.grenadeID);
         }
     }
     else
     {
         DeselectAll();
         curGrenade = availableGrenades[Mathf.Clamp(grenadeIndex, 0, availableGrenades.Count - 1)];
         curGrenade.gameObject.SetActive(true);
         curGrenade.OnSelect();
         dm.sao = curGrenade.GetComponent <SprintAnimOverride>();
     }
 }
    public IEnumerator BulletDestroy() //destroi a bala
    {
        if (!bulletDestroying)
        {
            bulletDestroying = true;

            GrenadeController grenadeC  = gameObject.GetComponent <GrenadeController>();
            float             limitTime = grenadeC.Explode(collisionMask); // tempo para explodir

            yield return(new WaitForSeconds(destroyDelay));                //esperar x segundos antes de destruir bala

            HashSet <GameObject> listOfDamages = grenadeC.GetListOfDamages();
            foreach (GameObject gameO in listOfDamages) ////pra cada objeto verificar se eh um target e dar dano
            {
                if (gameO != null && gameO.gameObject.layer == LayerMask.NameToLayer(target))
                {
                    GameObject gmO = DoLaser((gameO.transform.position - gameObject.transform.position), grenadeC.explosionRadius); //tentar acertar o alvo pela range
                    if (gmO != null && gmO.layer == gameO.layer)                                                                    //verifica se layers batem (enemy cm enemy) [qualquer coisa tirar]
                    {                                                                                                               //se foi possivel alcancar o alvo (sem barreiras)
                        if (gmO.gameObject.layer == LayerMask.NameToLayer(target))                                                  //dar dano e knock back se for um target (qualquer coisa alterar pro player tbm levar dano)
                        {
                            //Debug.Log("Alo: " + gameO);
                            DoDamage(gmO);                                                  //dar dano
                            DoKnockBack(gmO.transform.gameObject, knockBackForceExplosion); //dar knockback ao acertar
                        }
                        //DoDamage(gameO); //dar dano
                    }
                }
            }

            if (isFreezingBullet)                                                                               //se for congelante
            {
                limitTime = limitTime >= explosionSoundFreeze.length ? limitTime : explosionSoundFreeze.length; //se o maior tempo for o da animacao usar ele se n usar o do som de explosao
                audioSource.PlayOneShot(explosionSoundFreeze);                                                  //tocar som de explodir
            }
            else //se n
            {
                limitTime = limitTime >= explosionSoundBurn.length ? limitTime : explosionSoundBurn.length; //se o maior tempo for o da animacao usar ele se n usar o do som de explosao
                audioSource.PlayOneShot(explosionSoundBurn);                                                //tocar som de explodir
            }

            Destroy(gameObject, limitTime); //destroi bala quando colide //implementar bala perfuravel--> tirar destroy/arrumar //tempo pra destruir objeto
        }
    }
Beispiel #10
0
    public GrenadeController AddGrenadeToInventory(int targetID)
    {
        if (targetID < 0)
        {
            return(null);
        }

        GrenadeController instantiation = (GrenadeController)Instantiate(GrenadeDatabase.GetGrenadeByID(targetID));

        if (instantiation != null)
        {
            Transform tra = instantiation.transform;
            tra.parent        = transform;
            tra.localPosition = Vector3.zero;
            tra.localRotation = Quaternion.identity;
            instantiation.Initialize();
            instantiation.gameObject.SetActive(false);
        }

        return(instantiation);
    }
Beispiel #11
0
    public void Initialize()
    {
        if (nadeList != null)
        {
            GrenadeDatabase.savedGrenadeList = nadeList;
        }

        PlayerReference playerRef = GeneralVariables.playerRef;

        wm  = playerRef.wm;
        dm  = playerRef.dm;
        gam = playerRef.gam;

        grenadeInventory[0] = AddGrenadeToInventory(gam.grenadeTypeOne);
        grenadeInventory[1] = AddGrenadeToInventory(gam.grenadeTypeTwo);

        CheckGrenades();

        curGrenade = availableGrenades[0];
        curGrenade.OnSelect();
        canSwitch = true;
        gameObject.SetActive(false);
    }
Beispiel #12
0
    public IEnumerator SelectGrenade(GrenadeController grenade, bool immediate)
    {
        if (Topan.Network.isConnected && wm.rootNetView != null)
        {
            wm.rootNetView.RPC(Topan.RPCMode.Others, "NetworkSelectGrenade", (byte)grenade.grenadeID);
        }

        if (!immediate)
        {
            dm.Draw(wm.drawTime);
            canSwitch = false;
            yield return(new WaitForSeconds(wm.drawTime));

            wm.GetComponent <AudioSource>().PlayOneShot(wm.drawSound, 0.2f);
        }

        DeselectAll();
        curGrenade = grenade;
        curGrenade.gameObject.SetActive(true);
        curGrenade.OnSelect();
        dm.sao = curGrenade.GetComponent <SprintAnimOverride>();

        canSwitch = true;
    }
Beispiel #13
0
    public override void OnInspectorGUI()
    {
        GrenadeController gc = target as GrenadeController;

        GUI.color      = new Color(1f, 0.8f, 0.6f, 1f);
        gc.grenadeName = EditorGUILayout.TextField("Grenade Name:", gc.grenadeName);
        GUI.color      = new Color(0.8f, 0.8f, 0.8f, 1f);
        EditorGUIUtility.labelWidth = 140f;
        gc.grenadeIcon = (Texture2D)EditorGUILayout.ObjectField("  Icon Texture:", gc.grenadeIcon, typeof(Texture2D));
        EditorGUIUtility.LookLikeControls();
        GUI.color = Color.white;

        GUILayout.Space(10);

        gc.isDetonatable = EditorGUILayout.Toggle(" Is Detonatable:", gc.isDetonatable);

        if (gc.isDetonatable)
        {
            gc.baseDelay       = EditorGUILayout.FloatField(" Initial Delay:", Mathf.Clamp(gc.baseDelay, 0f, 5f));
            gc.detonationDelay = EditorGUILayout.FloatField(" Detonation Interval:", Mathf.Clamp(gc.detonationDelay, 0f, 5f));
        }

        GUILayout.Space(10);

        gc.throwPos      = (Transform)EditorGUILayout.ObjectField(" Throw Position:", gc.throwPos, typeof(Transform), true);
        gc.grenadePrefab = (Rigidbody)EditorGUILayout.ObjectField((gc.isDetonatable) ? " Explosive Prefab:" : " Grenade Prefab:", gc.grenadePrefab, typeof(Rigidbody), true);
        gc.displayMesh   = (MeshRenderer)EditorGUILayout.ObjectField(" Display Mesh:", gc.displayMesh, typeof(MeshRenderer), true);

        GUILayout.Space(10);

        EditorGUIUtility.labelWidth = 150f;
        gc.throwThreshold           = EditorGUILayout.FloatField(" Throw Threshold:", Mathf.Clamp(gc.throwThreshold, 0f, 5f));
        gc.cookingThreshold         = EditorGUILayout.FloatField(" Cooking Threshold:", Mathf.Clamp(gc.cookingThreshold, 0f, 10f));
        GUILayout.Space(5);
        gc.throwStrength = EditorGUILayout.FloatField(" Throw Strength:", Mathf.Clamp(gc.throwStrength, 0f, 1000f));

        if (!gc.isDetonatable)
        {
            gc.tossStrength = EditorGUILayout.FloatField(" Toss Strength:", Mathf.Clamp(gc.tossStrength, 0f, 1000f));
        }

        EditorGUIUtility.LookLikeControls();

        GUILayout.Space(10);

        EditorGUILayout.LabelField("Sounds", EditorStyles.boldLabel);
        EditorGUI.indentLevel += 1;

        gc.pullPinSound = (AudioClip)EditorGUILayout.ObjectField((gc.isDetonatable) ? "Detonation Sound:" : "Pull Pin Sound:", gc.pullPinSound, typeof(AudioClip), true);

        gc.throwSound          = (AudioClip)EditorGUILayout.ObjectField("Throw Sound:", gc.throwSound, typeof(AudioClip), true);
        EditorGUI.indentLevel -= 1;

        GUILayout.Space(6);

        EditorGUILayout.LabelField("Third Person Variables (MP)", EditorStyles.boldLabel);
        EditorGUI.indentLevel += 1;
        EditorGUILayout.LabelField("Local Position: " + DarkRef.PreciseStringVector3(gc.thirdPersonPosition));
        EditorGUILayout.LabelField("Local Rotation: " + DarkRef.PreciseStringVector3(gc.thirdPersonRotation.eulerAngles));

        GUILayout.Space(8f);

        if (gc.transform.parent != null && gc.transform.parent.name == "WeaponsParent" && GUILayout.Button("Preview Transform Info"))
        {
            gc.transform.localPosition = gc.thirdPersonPosition;
            gc.transform.localRotation = gc.thirdPersonRotation;
        }

        if (GUILayout.Button("Set Transform Info"))
        {
            GrenadeController prefab = GrenadeDatabase.GetGrenadeByID(gc.grenadeID);
            prefab.thirdPersonPosition = gc.transform.localPosition;
            prefab.thirdPersonRotation = gc.transform.localRotation;

            gc.thirdPersonPosition = gc.transform.localPosition;
            gc.thirdPersonRotation = gc.transform.localRotation;
        }

        EditorGUI.indentLevel -= 1;

        DarkRef.GUISeparator(8f);

        GUI.color = new Color(0.7f, 0.7f, 0.7f, 1f);
        EditorGUIUtility.labelWidth = 210f;
        EditorGUILayout.IntField("Grenade ID:", gc.grenadeID);
        EditorGUIUtility.LookLikeControls();

        if (GUI.changed)
        {
            EditorUtility.SetDirty(gc);
        }
    }
    void OnGUI()
    {
        if (settingsPrefab == null)
        {
            GUI.enabled = false;
        }

        if (GUILayout.Button("Initialize Assignment of Grenade IDs"))
        {
            GrenadeDatabase.Initialize();
        }
        if (GUILayout.Button("Clear Grenade IDs"))
        {
            GrenadeDatabase.customGrenadeList = new GrenadeController[0];
            GrenadeList temp = (GrenadeList)Instantiate(settingsPrefab);
            temp.savedGrenades = new GrenadeController[0];
            GrenadeDatabase.RefreshIDs();
            PrefabUtility.ReplacePrefab(temp.gameObject, settingsPrefab, ReplacePrefabOptions.Default);
            DestroyImmediate(temp.gameObject);
            GrenadeDatabase.Initialize();
        }
        if (GUILayout.Button("Auto-fill Grenade IDs"))
        {
            Object[] resourcesGC = Resources.LoadAll("Explosive Controllers", typeof(GrenadeController));
            GrenadeDatabase.customGrenadeList = new GrenadeController[resourcesGC.Length];

            for (int i = 0; i < resourcesGC.Length; i++)
            {
                GrenadeDatabase.customGrenadeList[i] = (GrenadeController)resourcesGC[i];
            }

            GrenadeList temp = (GrenadeList)Instantiate(settingsPrefab);
            temp.savedGrenades = GrenadeDatabase.customGrenadeList;

            GrenadeDatabase.RefreshIDs();
            PrefabUtility.ReplacePrefab(temp.gameObject, settingsPrefab, ReplacePrefabOptions.Default);
            DestroyImmediate(temp.gameObject);
            WeaponDatabase.Initialize();
        }

        GUI.enabled = true;

        GUILayout.Space(10);

        EditorGUIUtility.labelWidth = 120f;
        GUILayout.Box("Prefab Directory:   MAIN - Blackraze/Resources/Static Prefabs", GUILayout.MaxWidth(500), GUILayout.Height(20));

        if (settingsPrefab)
        {
            EditorGUILayout.ObjectField("Settings Prefab:", settingsPrefab, typeof(GrenadeList), false, GUILayout.MaxWidth(350));
        }
        else
        {
            GrenadeList savedGL = (GrenadeList)Resources.Load("Static Prefabs/Grenade List", typeof(GrenadeList));
            if (savedGL)
            {
                settingsPrefab = savedGL;
                GrenadeDatabase.customGrenadeList = savedGL.savedGrenades;
            }
            else
            {
                GUI.color = new Color(1f, 0.2f, 0f, 1f);
                if (GUILayout.Button("Generate Prefab", GUILayout.MaxWidth(120)))
                {
                    if (settingsPrefab == null)
                    {
                        GameObject go = new GameObject("Grenade List");
                        go.AddComponent <GrenadeList>();

                        settingsPrefab = PrefabUtility.CreatePrefab("Assets/MAIN - Blackraze/Resources/Static Prefabs/Grenade List.prefab", go, ReplacePrefabOptions.ConnectToPrefab).GetComponent <GrenadeList>();
                        DestroyImmediate(go);
                    }
                }
                GUI.color = Color.white;
            }
        }

        EditorGUIUtility.LookLikeControls();

        if (settingsPrefab == null)
        {
            GUI.color   = Color.gray;
            GUI.enabled = false;
        }
        else if (!settingsPrefab.GetComponent <GrenadeList>())
        {
            GUI.color   = Color.gray;
            GUI.enabled = false;
        }

        DarkRef.GUISeparator(10f);

        if (GUILayout.Button((inEditMode) ? "DONE" : "EDIT", GUILayout.MaxWidth(80)))
        {
            inEditMode = !inEditMode;

            if (!inEditMode)
            {
                GrenadeDatabase.RefreshIDs();
            }
        }

        EditorGUILayout.LabelField("Grenade ID List", EditorStyles.boldLabel);

        EditorGUILayout.BeginHorizontal();

        EditorGUI.indentLevel += 1;
        if (inEditMode)
        {
            int length = GrenadeDatabase.customGrenadeList.Length;
            GrenadeController[] tempStorage = GrenadeDatabase.customGrenadeList;
            EditorGUIUtility.labelWidth = 90f;
            length = EditorGUILayout.IntField("Length:", Mathf.Clamp(length, 0, 100), GUILayout.MaxWidth(150));
            EditorGUIUtility.LookLikeControls();
            if (length != GrenadeDatabase.customGrenadeList.Length)
            {
                GrenadeDatabase.customGrenadeList = new GrenadeController[length];
                for (int i = 0; i < tempStorage.Length; i++)
                {
                    if (i < GrenadeDatabase.customGrenadeList.Length)
                    {
                        GrenadeDatabase.customGrenadeList[i] = tempStorage[i];
                    }
                }
            }

            scrollPos              = EditorGUILayout.BeginScrollView(scrollPos, GUILayout.Width(Screen.width - 10), GUILayout.Height(Mathf.Clamp(Screen.height - 210, 1, Screen.height)));
            EditorGUI.indentLevel += 1;
            for (int i = 0; i < length; i++)
            {
                EditorGUIUtility.labelWidth          = 90f;
                GrenadeDatabase.customGrenadeList[i] = (GrenadeController)EditorGUILayout.ObjectField("Element #" + i.ToString(), GrenadeDatabase.customGrenadeList[i], typeof(GrenadeController), false, GUILayout.MaxWidth(330));
                EditorGUIUtility.LookLikeControls();
            }
            EditorGUI.indentLevel -= 1;
            EditorGUILayout.EndScrollView();

            if (GrenadeDatabase.customGrenadeList != settingsPrefab.savedGrenades)
            {
                settingsPrefab.savedGrenades = new GrenadeController[length];
                for (int i = 0; i < GrenadeDatabase.customGrenadeList.Length; i++)
                {
                    if (i < settingsPrefab.savedGrenades.Length)
                    {
                        settingsPrefab.savedGrenades[i] = GrenadeDatabase.customGrenadeList[i];
                    }
                }
            }
        }
        else
        {
            if (GrenadeDatabase.publicGrenadeControllers.Length <= 0)
            {
                EditorGUILayout.LabelField("[Press the 'EDIT' button above to get started]");
            }
            else
            {
                scrollPos = EditorGUILayout.BeginScrollView(scrollPos, GUILayout.Width(Screen.width - 10), GUILayout.Height(Mathf.Clamp(Screen.height - 210, 1, Screen.height)));
                for (int i = 0; i < GrenadeDatabase.publicGrenadeControllers.Length; i++)
                {
                    GrenadeController gc = GrenadeDatabase.publicGrenadeControllers[i];

                    if (gc != null)
                    {
                        if (gc.grenadeID <= -1)
                        {
                            EditorGUILayout.LabelField(i + " - (UNASSIGNED)");
                        }
                        else
                        {
                            EditorGUILayout.LabelField(i + " - " + gc.name);
                        }
                    }
                    else
                    {
                        EditorGUILayout.LabelField(i + " - (NULL)");
                    }
                }
                EditorGUILayout.EndScrollView();
            }
        }

        EditorGUILayout.EndHorizontal();

        EditorGUI.indentLevel -= 1;
    }