Beispiel #1
0
    public void PickUp(Item item)
    {
        bool remain = false;

        switch (item.type)
        {
        case "Ammo":
            PlayerWeaponManager wm = player.GetComponent <PlayerWeaponManager>();
            wm.ammo_count[wm.ammo_type.IndexOf(item.name)] += Mathf.RoundToInt(item.count);
            items.Remove(item);
            break;

        case "Health":
            PlayerStats ps = player.GetComponent <PlayerStats>();
            ps.health += item.count;
            items.Remove(item);
            break;

        case "Fuel":
            PlayerMove pm       = player.GetComponent <PlayerMove>();
            float      leftover = pm.AddFuel(item.count);
            if (leftover != 0)
            {
                item.count = leftover;
                remain     = true;
            }
            items.Remove(item);
            break;

        case "Module":
            PlayerModuleManager mm = player.GetComponent <PlayerModuleManager>();
            if (mm.InsertModule(item.module) == false)
            {
                remain = true;
            }
            items.Remove(item);
            break;

        case "Weapon":
            GameObject wp = Instantiate((item.obj), transform.position, Quaternion.identity);
            wp.GetComponent <WeaponStats>()._GM_ = GameObject.FindGameObjectWithTag("GM").GetComponent <GM>();
            wp.GetComponent <WeaponStats>().PickUp(player.GetComponent <PlayerPickUp>().weaponsFolder.transform);
            items.Remove(item);
            break;
        }
        if (remain)
        {
            items.Add(item);
        }

        RefreshSlots();
    }
Beispiel #2
0
    private void OnTriggerEnter2D(Collider2D collision)
    {
        if (collision.gameObject.CompareTag("Player"))
        {
            // retrieve action type
            IModuleItemType moduleType   = gameObject.GetComponent <IModuleItemType>();
            BaseModule      moduleAction = moduleType.getModuleAction();

            // retrieve the player's obtained module list and add the new module
            PlayerModuleManager playerModuleManager = collision.gameObject.GetComponent <PlayerModuleManager>();
            playerModuleManager.addModule(moduleAction);

            // display the text overlay for this module's function
            GameObject textOverlay = GameObject.FindGameObjectWithTag("TextOverlayObject");
            textOverlay.GetComponent <ModuleTextOverlay>().setText(moduleAction.onEnableText());

            // now delete this game object from the screen
            Destroy(this.gameObject);
        }
    }
Beispiel #3
0
    public void EnterCommand(string com)
    {
        string[] coms = com.Split('/');

        /*
         * for (int i = 0; i < coms.Length; i++)
         * {
         *  coms[i] = coms[i].ToLower();
         *  Debug.Log(coms[i]);
         * }
         */

        try
        {
            switch (coms[0])
            {
            case "player":
                switch (coms[1])
                {
                case "health":
                    if (coms[2] == "max")
                    {
                        GM.GetGM().player.GetComponent <PlayerStats>().health = GM.GetGM().player.GetComponent <PlayerStats>().maxHealth;
                    }
                    else
                    {
                        GM.GetGM().player.GetComponent <PlayerStats>().health = GM.GetFloat(coms[2], GM.GetGM().player.GetComponent <PlayerStats>().health);
                    }
                    GM.DisplayText("Command entered.", true);
                    break;

                case "maxhealth":
                    GM.GetGM().player.GetComponent <PlayerStats>().maxHealth = GM.GetFloat(coms[2], GM.GetGM().player.GetComponent <PlayerStats>().maxHealth);
                    GM.DisplayText("Command entered.", true);
                    break;

                case "fuel":
                    GM.GetGM().player.GetComponent <PlayerMove>().fuel = GM.GetFloat(coms[2], GM.GetGM().player.GetComponent <PlayerMove>().fuel);
                    GM.DisplayText("Command entered.", true);
                    break;

                case "maxfuel":
                    GM.GetGM().player.GetComponent <PlayerMove>().maxFuel = GM.GetFloat(coms[2], GM.GetGM().player.GetComponent <PlayerMove>().maxFuel);
                    GM.DisplayText("Command entered.", true);
                    break;

                case "god":
                    if (coms[2] == "enable")
                    {
                        GM.GetPlayer().GetComponent <PlayerStats>().god = true;
                    }
                    if (coms[2] == "disable")
                    {
                        GM.GetPlayer().GetComponent <PlayerStats>().god = false;
                    }
                    else
                    {
                        GM.DisplayText("Invalid command", true);
                    }
                    break;

                default:
                    GM.DisplayText("Unknown command", true);
                    break;
                }
                break;

            case "getitem":
                switch (coms[1])
                {
                case "module":
                    foreach (Module _GM_M in GM.GetGM().modulesList)
                    {
                        if (_GM_M.ID == coms[2] && _GM_M.level == GM.GetFloat(coms[3], 1))
                        {
                            PlayerModuleManager mm = GM.GetPlayer().GetComponent <PlayerModuleManager>();
                            if (mm.InsertModule(_GM_M) == false)
                            {
                                GM.DisplayText("Unable to add module", true);
                            }
                        }
                    }
                    break;

                case "weapon":
                    foreach (Item _GM_I in GM.GetGM().itemsList)
                    {
                        if (_GM_I.name == coms[2])
                        {
                            GameObject wp = Instantiate((_GM_I.obj), transform.position, Quaternion.identity);
                            wp.GetComponent <WeaponStats>()._GM_ = GameObject.FindGameObjectWithTag("GM").GetComponent <GM>();
                            wp.GetComponent <WeaponStats>().PickUp(GM.GetPlayer().GetComponent <PlayerPickUp>().weaponsFolder.transform);
                            GM.DisplayText("Picked up: " + _GM_I.name, false);
                            GM.DisplayText("Command entered.", true);
                        }
                    }
                    break;

                case "deployable":
                    foreach (Item _GM_I in GM.GetGM().itemsList)
                    {
                        if (_GM_I.name == coms[2])
                        {
                            Item a = _GM_I;
                            a.count = Mathf.RoundToInt(GM.GetFloat(coms[3], GM.GetGM().player.GetComponent <PlayerMove>().maxFuel));
                            DeployablesManager dm = GM.GetPlayer().GetComponent <DeployablesManager>();
                            dm.dplybles_count[dm.deployables.IndexOf(a.obj)] += (int)a.count;
                            GM.DisplayText("Picked up: " + a.name + " GRND x (" + a.count + ")", false);
                            GM.DisplayText("Command entered.", true);
                        }
                    }
                    break;

                case "ammo":
                    PlayerWeaponManager wm = GM.GetPlayer().GetComponent <PlayerWeaponManager>();
                    wm.ammo_count[wm.ammo_type.IndexOf(coms[2])] += Mathf.RoundToInt(GM.GetFloat(coms[3], 0));
                    GM.DisplayText("Picked up: " + coms[2] + " x (" + GM.GetFloat(coms[3], 0) + ")", false);
                    break;

                default:
                    GM.DisplayText("Unknown command", true);
                    break;
                }
                break;

            case "clock":
                if (coms[1] == "pause")
                {
                    GM.GetGM().gameObject.GetComponent <Clock>().paused = true;
                }
                else if (coms[1] == "resume")
                {
                    GM.GetGM().gameObject.GetComponent <Clock>().paused = false;
                }
                else if (coms[1] == "time")
                {
                    GM.GetGM().gameObject.GetComponent <Clock>().remainingTime = GM.GetFloat(coms[2], GM.GetGM().gameObject.GetComponent <Clock>().remainingTime);
                }
                else
                {
                    GM.DisplayText("Unknown command", true);
                }
                break;

            case "scores":
                if (coms[1] == "show")
                {
                    GM.GetUI().GetComponent <UI_Scores>().Show();
                }
                if (coms[1] == "hide")
                {
                    GM.GetUI().GetComponent <UI_Scores>().Hide();
                }
                if (coms[1] == "save")
                {
                    GM.GetGM().data.SaveData();
                }
                if (coms[1] == "clear")
                {
                    GM.GetGM().data.ResetData();
                }
                if (coms[1] == "pw")
                {
                    GM.DisplayText("QWERTY", true);
                }
                else
                {
                    GM.DisplayText("Unknown command", true);
                }
                break;

            default:
                GM.DisplayText("Unknown command", true);
                break;
            }
        }
        catch
        {
            GM.DisplayText("Invalid command.", true);
        }
    }
Beispiel #4
0

        
Beispiel #5
0
    public void PickUp(int index)
    {
        //Debug.Log("Picking Up: " + index);
        if (index >= items.Count)
        {
            return;
        }
        Item item   = items[index];
        bool remain = false;

        switch (item.type)
        {
        case "Ammo":
            PlayerWeaponManager wm = player.GetComponent <PlayerWeaponManager>();
            wm.ammo_count[wm.ammo_type.IndexOf(item.name)] += Mathf.RoundToInt(item.count);
            items.Remove(item);
            GM.DisplayText3("Picked up: " + item.name + " x (" + item.count + ")", false, 0);
            break;

        case "Health":
            PlayerStats ps = player.GetComponent <PlayerStats>();
            ps.health += item.count;
            items.Remove(item);
            GM.DisplayText3("Health += " + item.count, false, 0);
            break;

        case "Fuel":
            PlayerMove pm       = player.GetComponent <PlayerMove>();
            float      leftover = pm.AddFuel(item.count);
            if (leftover != 0)
            {
                if (leftover == item.count)
                {
                    GM.DisplayText3("Maximum fuel capacity reached", false, 0);
                }
                else
                {
                    item.count = leftover;
                    remain     = true;
                    GM.DisplayText3("Fuel += " + (item.count - leftover) + "mL", false, 0);
                }
            }
            else
            {
                GM.DisplayText3("Fuel += " + item.count + "mL", false, 0);
            }
            items.Remove(item);
            break;

        case "Module":
            PlayerModuleManager mm = player.GetComponent <PlayerModuleManager>();
            if (mm.InsertModule(item.module) == false)
            {
                remain = true;
            }
            //GM.DisplayText3("Module Added: " + item.module.ID + " [LV. " + item.module.level + "]", false, 0);
            //GM.DisplayText("Module Added: " + item.module.ID + " [LV. " + item.module.level + "]", false);
            items.Remove(item);
            break;

        case "Weapon":
            GameObject wp = Instantiate((item.obj), transform.position, Quaternion.identity);
            wp.GetComponent <WeaponStats>()._GM_ = GameObject.FindGameObjectWithTag("GM").GetComponent <GM>();
            wp.GetComponent <WeaponStats>().PickUp(player.GetComponent <PlayerPickUp>().weaponsFolder.transform);
            GM.DisplayText("Picked up: " + item.name, false);
            GM.DisplayText3("Picked up: " + item.name, false, 0);
            items.Remove(item);
            break;

        case "Deployable":
            DeployablesManager dm = player.GetComponent <DeployablesManager>();
            dm.dplybles_count[dm.deployables.IndexOf(item.obj)] += (int)item.count;
            GM.DisplayText3("Picked up: " + item.name + " GRND x (" + item.count + ")", false, 0);
            GM.DisplayText("Picked up: " + item.name + " GRND x (" + item.count + ")", false);
            items.Remove(item);
            break;
        }
        if (remain)
        {
            items.Add(item);
        }
        RefreshSlots();
    }