Пример #1
0
    public Toy InitToyObj(Island_Button island_b, string toy_name, bool fake)
    {
        if (island_b.my_toy != null && island_b.my_toy.gameObject.activeSelf)
        {
            throw new Exception("Adding toy " + toy_name + " to an island " + island_b.name + " that already has a toy\n");
        }

        GameObject parent = island_b.parent;
        Vector3    posv   = parent.transform.position;

        island_b.setBlocked(true);
        GameObject toy_obj = zoo.getObject("Toys/" + toy_name, false);

        toy_obj.tag   = "Player";
        toy_obj.layer = 10;

        Toy toy = toy_obj.GetComponent <Toy>();

        toy_obj.transform.SetParent(parent.transform);
        toy_obj.transform.position      = posv;
        toy_obj.transform.localScale    = Vector3.one;// = Vector3.one;
        toy_obj.transform.localRotation = Quaternion.identity;
        toy_obj.SetActive(true);
        StationaryZ z = toy_obj.GetComponent <StationaryZ>();

        if (z != null)
        {
            z.Init();
        }

        return(toy);
    }
Пример #2
0
 public void EnableMe(float timer, Island_Button island)
 {
     my_button = island;
     my_time   = timer;
     StartCoroutine("DisableMe");
     this.transform.SetParent(island.transform);
 }
Пример #3
0
    void Level2_Sensible()
    {
        Island_Button i    = islands[2];
        GameObject    zero = Peripheral.Instance.PlaceToyOnIsland("sensible_tower", i.gameObject);

        zero.name = "default0";
        i.my_toy.my_tower_stats = GameStatCollector.Instance.addTowerStats(i.my_toy);

        i = islands[3];

        GameObject one = Peripheral.Instance.PlaceToyOnIsland("sensible_tower", i.gameObject);

        one.name = "one";
        i.my_toy.my_tower_stats = GameStatCollector.Instance.addTowerStats(i.my_toy);

        i = islands[1];

        GameObject two = Peripheral.Instance.PlaceToyOnIsland("sensible_tower", i.gameObject);

        two.name = "two";
        i.my_toy.my_tower_stats = GameStatCollector.Instance.addTowerStats(i.my_toy);

        i = islands[4];

        GameObject three = Peripheral.Instance.PlaceToyOnIsland("sensible_tower", i.gameObject);

        three.name = "three";
        i.my_toy.my_tower_stats = GameStatCollector.Instance.addTowerStats(i.my_toy);

        i = islands[5];

        GameObject four = Peripheral.Instance.PlaceToyOnIsland("sensible_tower", i.gameObject);

        four.name = "four";
        i.my_toy.my_tower_stats = GameStatCollector.Instance.addTowerStats(i.my_toy);

        i = islands[6];

        GameObject five = Peripheral.Instance.PlaceToyOnIsland("sensible_tower", i.gameObject);

        five.name = "five";
        i.my_toy.my_tower_stats = GameStatCollector.Instance.addTowerStats(i.my_toy);

        i = islands[12];

        GameObject six = Peripheral.Instance.PlaceToyOnIsland("sensible_tower", i.gameObject);

        six.name = "six";
        i.my_toy.my_tower_stats = GameStatCollector.Instance.addTowerStats(i.my_toy);

        i = islands[8];

        GameObject seven = Peripheral.Instance.PlaceToyOnIsland("sensible_tower", i.gameObject);

        seven.name = "seven";
        i.my_toy.my_tower_stats = GameStatCollector.Instance.addTowerStats(i.my_toy);
    }
Пример #4
0
    public bool TowerBuild(MyPlayerEvent e)
    {
        if (e.event_complete)
        {
            return(true);
        }


        //unitStats stats = Central.Instance.getToy(tower.toy_id.rune_type, tower.toy_id.toy_type);
        unitStats stats    = Central.Instance.getToy(e.attribute_1);
        string    toy_name = stats.name;
        bool      force    = true;

        if (force || canBuildTower(stats, force))
        {
            Toy           f      = null;
            Island_Button island = Monitor.Instance.getIslandByID(e.attribute_2);
            if (island == null)
            {
                Debug.LogError("Could not locate island " + e.attribute_2 + " for tower " + e.attribute_1 + "\n");
                return(false);
            }

            GameObject o   = Peripheral.Instance.makeToy(toy_name, island, true, ref f, true);
            Toy        toy = o.GetComponent <Toy>();
            toy.my_tower_stats.name = e.metric_1.ToString();

            if (toy.toy_type == ToyType.Temporary)
            {
                ghosts.Add(toy);
            }
            else
            {
                toys.Add(toy);
            }

            if (toy.toy_type == ToyType.Hero)
            {
                loadHeroSkills(skills_and_inventory, toy.runetype);
            }

            e.event_complete = true;
            return(true);
        }
        else
        {
            Debug.LogError("Could not build tower " + e.attribute_2 + " for tower " + e.attribute_1 + "\n");
            return(false);
        }

        return(false);
    }
Пример #5
0
    void Awake()
    {
        Instance = this;

        if (islands_parent == null)
        {
            Debug.Log("Monitor cannot find Islands gameobject!!\n"); return;
        }
        //might want to store this in the prefab later on
        foreach (Transform i in islands_parent.transform)
        {
            Island_Button b = i.gameObject.GetComponentInChildren <Island_Button>();
            b.setID();
            b.Hidden = false;

            if (b != null)
            {
                try
                {
                    islands.Add(i.name, b);
                }catch (Exception e)
                {
                    Debug.LogError(e + ": " + i.name + "\n");
                }
            }
            if (b == castle_island)
            {
                continue;                    //castle or anything else that has a permanent sprite
            }
            if (b.transform.childCount > 0)
            {
                Transform      child  = b.transform.GetChild(0);
                SpriteRenderer sprite = child.gameObject.GetComponent <SpriteRenderer>();
                if (sprite != null)
                {
                    island_sprites.Add(sprite);
                }
            }
        }
        if (EagleEyes.Instance.global_rune_panel != null)
        {
            global_rune_panel = EagleEyes.Instance.global_rune_panel;
        }
        SpyGlass.onSelected            += onSelected;
        Island_Button.onSelected       += onSelected;
        Peripheral.onSelected          += onSelected;
        MyButton.onSelected            += onSelected;
        MyFastForwardButton.onSelected += onSelected;
        Enemy_Button.onSelected        += onSelected;
    }
Пример #6
0
    IEnumerator DisableMe()
    {
        while (my_time > 0)
        {
            yield return(new WaitForSeconds(interval));

            my_time -= interval;
        }
        my_button.setBlocked(false);
        my_button = null;

        Peripheral.Instance.zoo.returnObject(this.gameObject);

        yield return(null);
    }
Пример #7
0
    void InitSignal(Range_Indicator my_signal, Island_Button island, float _size, bool main)
    {
        if (main && my_signal == null)
        {
            my_signal = Zoo.Instance.getObject("GUI/range_sphere", true).GetComponent <Range_Indicator>();
            signal    = my_signal;
        }
        my_signal.gameObject.SetActive(true); //soft clear removes signal

        my_signal.gameObject.transform.SetParent(island.transform);
        my_signal.gameObject.transform.position = island.transform.position;
        SetSignalSize(my_signal, _size);


        my_signal.Set(true, island.island_type == IslandType.Temporary && island.my_toy != null);
    }
    public void UpdatePanel(Island_Button button)
    {
        if (button == null && selected_island == null)
        {
            return;
        }
        if (button != null && selected_island != null && button.gameObject.GetInstanceID() == selected_island.gameObject.GetInstanceID())
        {
            return;
        }

        if (button == null)
        {
            selected_island = null;
            selected_island_image.gameObject.SetActive(false);
            my_panel.gameObject.SetActive(false);
            return;
        }


        //if (selected_island != null && button.gameObject.GetInstanceID() != selected_island.gameObject.GetInstanceID()) ResetSelected();

        selected_island = button;

        bool temp_ok = false;

        temp_ok = (selected_island.island_type == IslandType.Permanent || (selected_island.island_type == IslandType.Temporary && Monitor.Instance.SetAllowedRange("sensible_city")));


        int ok_buttons = 0;

        EagleEyes.Instance.UpdateToyButtons("blah", ToyType.Normal, true);

        foreach (MyLabel label in my_panel.list)
        {
            if (!label.AmIActive())
            {
                label.SetHidden(true);
                continue;
            }


            unitStats stats = Central.Instance.getToy(label.runetype, label.toytype);
            if (stats != null)
            {
                if (stats.island_type != IslandType.Either && stats.island_type != selected_island.island_type)
                {
                    label.SetHidden(true);
                    label.ShowButtons(false);
                    continue;
                }
                if (stats.island_type == IslandType.Temporary)
                {
                    if (!temp_ok)
                    {
                        label.SetHidden(true);
                        label.ShowButtons(false);
                        continue;
                    }
                    string ok = selected_island.verify_toy_for_distance(label.content);
                    if (ok.Equals("TOOFAR"))
                    {
                        label.SetHidden(true);
                        label.ShowButtons(false);
                        continue;
                    }
                }

                //if (label.button.IsInteractable()){
                label.SetHidden(false);
                label.ShowButtons(true);
                ok_buttons++;

                /*
                 * }else{
                 * label.SetHidden(true);
                 * label.ShowButtons(false);
                 * }*/
            }
        }
        Vector3 set_to = button.transform.position;

        if (ok_buttons > 0)
        {
            my_panel.transform.position = set_to;
            my_panel.gameObject.SetActive(true);

            my_panel.radius = (ok_buttons <= 6) ? 1.2f :
                              (ok_buttons == 7) ? 1.35f :
                              (ok_buttons == 8) ? 1.5f : 1.6f;
            my_panel.spacing = 2f * Mathf.PI * my_panel.radius / ok_buttons;
            my_panel.UpdatePanel();
            // if (Monitor.Instance != null) Monitor.Instance.my_spyglass.PointSpyglass(button.transform.position,.20f);

            selected_island_image.gameObject.SetActive(true);
            selected_island_image.transform.position = set_to;
        }
        else
        {
            selected_island_image.gameObject.SetActive(false);
            Noisemaker.Instance.Play("island_too_far");
            ShowNoResourcesPopup(set_to);
        }
    }
Пример #9
0
    public void initStats(unitStats s, Vector3 scaleV, Island_Button i, string _name, Rune _rune)
    {
        tilesize = i.getPeripheral().tileSize;
        stats    = s;
        float dmg_base = 0;

        my_name                    = _name;
        my_tower_stats             = new tower_stats();
        my_tower_stats.island_name = string.Copy(i.ID);
        my_tower_stats.wave_time   = Moon.Instance.TIME;
        my_tower_stats.initSkillStats(runetype);
        if (building.tower_visual)
        {
            building.tower_visual.updateVisuals();
            building.tower_visual.setSprite(true);
        }

        Rune.onUpgrade += onUpgrade;

        float bonus = 0f;

        //  float bonus = StaticRune.GetDistanceBonus(my_name, this.transform.position, this);
        Debug.Log($"TOY Initializing {toy_type} {runetype}\n");
        if (_rune == null || toy_type != ToyType.Hero)
        {
            rune = new Rune();
            SetBonus(bonus);
            int max_lvl = LevelStore.getMaxLevel(Central.Instance.current_lvl, Peripheral.Instance.difficulty, runetype, toy_type);

            rune.initStats(runetype, max_lvl, toy_type);
            Debug.Log($"TOY Initializing {toy_type} {runetype} new rune lvl {max_lvl}\n");
        }
        else
        {
            SetBonus(bonus);
            rune = _rune;
            rune.UpdateStats();
            Debug.Log($"TOY Initializing {toy_type} {runetype} EXISTING rune lvl {rune.getMaxLevel()}\n");
        }
        Active  = true;
        island  = i;
        rune.ID = this.gameObject.GetInstanceID();
        center.localPosition = Vector3.Scale(center.localPosition, scaleV);
        //        my_toy.center.localPosition = Vector3.Scale(my_toy.center.localPosition, scaleV);
        transform.transform.localRotation = Quaternion.identity;

        building.initStats(this);
        //


        // if (rune.level > 0 && rune_buttons != null) rune_buttons.UpdateMe();

        if (parent_toy != null)
        {
            parent_toy.AddTargetToy(this);
        }


        if (toy_type == ToyType.Hero)
        {
            //rune.InitHero(Central.Instance.current_lvl);//for testing, gives hero some xp based on current level, if xp is 0
            // also sensible hero comes with airattack for free, done by an event in 02level_scene
            rune.setMaxLevel((int)Mathf.Max(Central.Instance.getToy(my_name).getMaxLvl(), rune.getMaxLevel()));
        }

        if (firearm != null)
        {
            firearm.initStats(this);
        }
        //if (rune_buttons != null) rune_buttons.UpdateMe(); // ghost towers don't get their own rune buttons
        TIME_AT_START = Time.time;
    }
Пример #10
0
    public void LoadBasicMidLevelShit(SaveState saver)
    {
        //	Debug.Log("Peripheral loaded snapshot, wave " + saver.current_wave + "\n");
        StopAllCoroutines();
        level_state = LState.WaveButton;
        ChangeTime(TimeScale.Normal);
        Wave_interval = 0f;
        TIME          = 0f;
        have_cities   = false;
        toy_parents   = new List <Toy>();
        Moon.Instance.WaveInProgress = false;
        foreach (unitStatsSaver a in saver.actor_stats)
        {
            Central.Instance.setUnitStats(a, a.toy_id.toy_type == ToyType.Hero);
        }

        Monitor.Instance.ResetIslands();

        xp_factor.Reset();
        damage_factor.Reset();
        dream_factor.Reset();

        difficulty = saver.difficulty;


        if (saver.type == SaveStateType.MidLevel)
        {
            FancyLoader.Instance.LoadWavesOnly(Central.Instance.level_list.levels[Central.Instance.current_lvl].name);

            Moon.Instance.SetWave(saver.current_wave, 0);
            Sun.Instance.Init(0);
            Moon.Instance.WaveInProgress = false;
            foreach (unitStatsSaver a in saver.actor_stats)
            {
                Central.Instance.setUnitStats(a, true);
            }

            TIME = next_wave_time;
            Debug.Log("Peripheral Loading snapshot\n");
            // Sun.Instance.SetTimePassively(saver.time_of_day);



            PlaceCastle();
            RuneSaver castle_toysaver = saver.getCastle();
            if (castle_toysaver != null)
            {
                castle.loadSnapshot(castle_toysaver);                         //this guy needs to be loaded first
            }
            else
            {
                Debug.LogError("Could not find castle toysaver!");
            }

            //castle.rune.DoSpecialThing(EffectType.Architect); //load gnomesss


            if (saver.health > 0)
            {
                SetHealth(saver.health, false);
            }
            dreams = saver.dreams;
            setToys(0);
            monster_count = 0;

            for (int i = 0; i < saver.islands.Count; i++)
            {
                var           island_saver = saver.islands[i];
                Island_Button island       = null;
                Monitor.Instance.islands.TryGetValue(island_saver.name, out island);

                if (island == null)
                {
                    Debug.Log("Could not find island " + island_saver.name + "\n"); continue;
                }
                if (island_saver.island_type != IslandType.Null)
                {
                    island.ChangeType(island_saver.island_type, false);
                }

                if (island_saver.toy_saver != null)
                {
                    if (island_saver.toy_saver.rune_saver.runetype == RuneType.Castle)
                    {
                        continue;
                    }
                    if (island_saver.toy_saver.toy_name.Equals(Get.NullToyName()))
                    {
                        continue;
                    }
                    Toy toy = null;


                    GameObject toy_object = makeToy(island_saver.toy_saver.toy_name, island, false, ref toy, false);
                    if (toy_object == null)
                    {
                        Debug.Log("FAILED TO LOAD TOY! NO FIREARM\n"); return;
                    }
                    toy.loadSnapshot(island_saver.toy_saver);
                    if (toy.firearm != null)
                    {
                        toy.firearm.CheckForUpgrades();
                    }

                    if (island_saver.toy_saver.rune_saver.runetype != RuneType.Modulator &&
                        (island_saver.toy_saver.type == ToyType.Normal))
                    {
                        incrementToys();
                    }
                }
                if (!(island_saver.block_timer > 0))
                {
                    continue;
                }
                island.MakeDeadIsland(island_saver.block_timer);
            }
            //skillmaster is initialized indirectly, when the toys are initialized, through Rune
            Central.Instance.level_list.special_skill_button_driver.Init();
            EagleEyes.Instance.UpdateToyButtons("blah", ToyType.Normal, false);
        }
        else
        {
            Debug.LogError("Loading midlevel shit on a non midlevel savegame!\n");
            Debug.Log("Peripheral loaded start level snapshot, current wave is " + 0 + "\n");
            Moon.Instance.SetWave(0, 0);

            Sun.Instance.Init(0);

            PlaceCastle();
        }// end loading snapshot specific stuff

        EagleEyes.Instance.UpdateToyButtons("blah", ToyType.Normal, false);
        level_active = true;
        ChangeTime(TimeScale.Normal);
        // not sure what this is for, what are we saving for castle???
        //if (saver.castle != null){  castle.loadSnapshot(saver.castle);		}
    }
Пример #11
0
    public GameObject makeToy(string toy_name, Island_Button island_b, bool check_cost, ref Toy _toy, bool force)
    {
        unitStats my_stats     = Central.Instance.getToy(toy_name);
        Cost      my_cost_type = my_stats.cost_type;

        if (!force && check_cost && my_cost_type.type != CostType.Dreams)
        {
            if (!HaveResource(my_stats.cost_type))
            {
                Debug.Log("Cannot afford toy " + toy_name + " of type " + my_cost_type + " for " + my_cost_type.Amount + " cost\n");
                return(null);
            }
        }



        _toy = InitToyObj(island_b, toy_name, false);
        GameObject toy_obj = _toy.gameObject;

        if (_toy.target_toys.Length > 0)
        {
            toy_parents.Add(_toy);
        }

        if (_toy.firearm != null)
        {
            firearms.Add(_toy.firearm);
        }

        island_b.my_toy = _toy;
        _toy.my_name    = toy_name;

        Rune rune = null;

        bool new_hero = false;

        if (_toy.toy_type == ToyType.Hero)
        {
            Rune have = Central.Instance.getHeroStats(_toy.runetype);
            if (have != null)
            {
                rune = have;
            }
            else
            {
                new_hero = true;
            }
        }

        if (_toy != null)
        {
            _toy.initStats(my_stats, Vector3.one, island_b, toy_name, rune);
        }


        if (_toy.building)
        {
            _toy.building.StartConstruction();
        }

        //   Debug.Log("NEW TOY cost toytype " + my_cost_type.toytype + "\n");


        _toy.name       = toy_name + "|" + all_toys;
        _toy.rune.order = all_toys;



        all_toys++;
        if (check_cost || my_cost_type.isHero())
        {
            if (my_cost_type.type == CostType.Dreams)
            {
                if (_toy.runetype != RuneType.Modulator)
                {
                    incrementToys();
                }
                addDreams(-my_cost_type.Amount, toy_obj.transform.position, false);
                Central.Instance.updateCost(toys);
                // if (Central.Instance.getToy(toy_name).cost_type.cost > dreams) { SelectToy(""); }
            }
            else if (my_cost_type.type == CostType.Wishes)
            {
                my_inventory.AddWish(WishType.Sensible, -my_cost_type.Amount, 1);
            }
            else if (my_cost_type.isHero())
            {
                SetHeroPoint(my_cost_type.getHeroRuneType(), 0, true);
                SelectToy(null, RuneType.Null);
            }
        }


        if (onPlacedToy != null)
        {
            onPlacedToy(_toy.my_name, _toy.runetype, _toy.toy_type);
        }


        if (new_hero)
        {
            Central.Instance.hero_toy_stats.Add(_toy.rune);
        }
        if (check_cost)
        {
            Noisemaker.Instance.Play("make_tower");
        }

        if (check_cost)
        {
            Tracker.Log(PlayerEvent.TowerBuilt, true,
                        customAttributes: new Dictionary <string, string>()
            {
                { "attribute_1", _toy.my_name }, { "attribute_2", island_b.ID }
            },
                        customMetrics: new Dictionary <string, double>()
            {
                { "metric_1", _toy.rune.order }
            });
        }


        return(toy_obj);
    }
Пример #12
0
    public GameObject makeToy(string name, GameObject parent, ref Toy firearm)
    {
        Island_Button island_b = parent.GetComponent <Island_Button>();

        return(makeToy(name, island_b, true, ref firearm, false));
    }