Beispiel #1
0
        public LevelTree(int nodeType, int id, int difficulty, int depth = -1, LevelParams levelParams = null, string name = null, string desc = null, string fixedRewardDescription = null)
        {
            levelData = null;

            Unlocked = false;

            LevelReward = new DropInfo();

            this.LevelNodeType = nodeType;
            this.Id            = id;
            this.Depth         = depth;
            this.Difficulty    = difficulty;
            this.LevelParams   = levelParams;
            this.Name          = name;
            this.Description   = desc;

            if (fixedRewardDescription != null)
            {
                hardcodedRewardDesc = fixedRewardDescription;
            }
            else
            {
                hardcodedRewardDesc = null;
            }
        }
Beispiel #2
0
        private void SpawnMonsters()
        {
            AbstractLevelData data = mapHolder.levelData;

            if (data != null)
            {
                data.SpawnMonsters();
            }
            else     // just for test
            {
                Debug.LogWarning("a map doesnt have abstractleveldata set! spawning default mobs");

                /*foreach (MapRoom room in rooms)
                 * {
                 *      MonsterSpawnInfo info = new MonsterSpawnInfo(MonsterId.Lymfocyte_melee, mapHolder.GetTileWorldPosition(room.tiles[25]));
                 *      info.SetRegion(room.region.GetParentOrSelf());
                 *
                 *      mapHolder.AddMonsterToMap(info);
                 * }*/
            }
        }
Beispiel #3
0
        private void HandleSkillControls()
        {
            if (Input.GetKeyDown(KeyCode.Tab))
            {
                ui.SwitchConsole();
            }

            if (Input.GetKeyDown(KeyCode.Return) || Input.GetKeyDown(KeyCode.KeypadEnter))
            {
                ui.OnEnter();
            }

            if (!ui.consoleActive)
            {
                if (Input.GetKeyDown(KeyCode.Q))
                {
                    data.StartMeleeTargeting(false);
                }

                if (data.ActiveConfirmationSkill == null && Input.GetMouseButtonDown(0) && !ui.MouseOverUI)
                {
                    data.StartMeleeTargeting(true);
                }

                if (Input.GetKeyDown(KeyCode.W))
                {
                    EquippableItem u = new HpUpgradeAdd(1);
                    u.Init();
                    u.SpawnGameObject(Utils.GenerateRandomPositionAround(data.GetBody().transform.position, 3));
                    //data.GetOwner().AddUpgrade(u);
                    //data.GetOwner().EquipUpgrade(u);
                }

                if (Input.GetKeyDown(KeyCode.I))
                {
                    ui.SwitchInventory();
                }

                if (Input.GetKeyDown(KeyCode.U))
                {
                    Player p = data.GetOwner() as Player;
                    p.UnlockSkill(temp++, true);

                    //ui.DamageMessage(data.GetBody(), 10, Color.cyan);

                    //ui.ScreenMessage("Ahoasdddddddddddddddddddsssssssssddddddddddddoj" + (temp++), 1);
                    //data.AddPhysicsPush(new Vector2(0, 100), ForceMode2D.Impulse);
                }

                if (Input.GetKeyDown(KeyCode.E))
                {
                    InventoryItem u = new DnaItem(Random.Range(10, 20));
                    u.Init();
                    u.SpawnGameObject(Utils.GenerateRandomPositionAround(data.GetBody().transform.position, 3));

                    InventoryItem p = new HpPotion(1);
                    p.Init();
                    p.SpawnGameObject(Utils.GenerateRandomPositionAround(data.GetBody().transform.position, 3));
                }

                if (Input.GetKeyDown(KeyCode.B))
                {
                    AbstractLevelData levelData = WorldHolder.instance.activeMap.levelData;

                    if (levelData.CanHaveBase())
                    {
                        levelData.CreateBase();
                    }
                }

                if (Input.GetKeyDown(KeyCode.L))
                {
                    ui.ShowLevelsView();
                }

                if (Input.GetKeyDown(KeyCode.M))
                {
                    ui.HideLevelsView();
                }

                if (Input.GetKeyDown(KeyCode.V))
                {
                    AbstractLevelData levelData = WorldHolder.instance.activeMap.levelData;

                    if (levelData.HasBase())
                    {
                        if (SiegeManager.IsSiegeActive() == false)
                        {
                            SiegeManager.StartSiege(WorldHolder.instance.activeMap);
                        }
                        else
                        {
                            SiegeManager.CancelSiege();
                        }
                    }
                }

                if (Input.GetKeyDown(KeyCode.R))
                {
                    InventoryItem u = UpgradeTable.Instance.GenerateUpgrade(ItemType.CLASSIC_UPGRADE, 1, 2, 1);
                    u.Init();
                    u.SpawnGameObject(Utils.GenerateRandomPositionAround(data.GetBody().transform.position, 3));
                }

                /*if (Input.GetKeyDown(KeyCode.R))
                 * {
                 *      AbstractUpgrade u = data.GetOwner().Inventory.GetUpgrade(typeof (TemplateUpgrade));
                 *      data.GetOwner().UnequipUpgrade(u);
                 *      data.GetOwner().RemoveUpgrade(u);
                 *
                 *      u = data.GetOwner().Inventory.GetUpgrade(typeof(TemplateUpgrade));
                 *      data.GetOwner().UnequipUpgrade(u);
                 *      data.GetOwner().RemoveUpgrade(u);
                 * }*/

                if (Input.GetKeyDown(KeyCode.Alpha1))
                {
                    data.LaunchSkill(1);
                }

                if (Input.GetKeyDown(KeyCode.Alpha2))
                {
                    data.LaunchSkill(2);
                }

                if (Input.GetKeyDown(KeyCode.Alpha3))
                {
                    data.LaunchSkill(3);
                }

                if (Input.GetKeyDown(KeyCode.Alpha4))
                {
                    data.LaunchSkill(4);
                }

                if (Input.GetKeyDown(KeyCode.Alpha5))
                {
                    data.LaunchSkill(5);
                }

                if (Input.GetKeyDown(KeyCode.Alpha6))
                {
                    data.LaunchSkill(6);
                }

                if (Input.GetKeyDown(KeyCode.Alpha7))
                {
                    data.LaunchSkill(7);
                }

                if (Input.GetKeyDown(KeyCode.Alpha8))
                {
                    data.LaunchSkill(8);
                }

                if (Input.GetKeyDown(KeyCode.Alpha9))
                {
                    data.LaunchSkill(9);
                }

                if (Input.GetKeyDown(KeyCode.Alpha0))
                {
                    data.LaunchSkill(10);
                }
            }
        }
Beispiel #4
0
        public void GenerateGenericEnemyGroup(MapRoom room, AbstractLevelData level, RoomType roomType, int difficulty, MapRegion regionData, int forcedId = -1)
        {
            Player player      = GameSystem.Instance.CurrentPlayer;
            int    playerLevel = 1;

            if (player != null)
            {
                playerLevel = player.Level;
            }

            RegionSize size = RegionSize.SMALL;

            if (regionData != null)
            {
                int sInt = regionData.GetFamilyRegions().Count;
                if (sInt == 2 || sInt == 3)
                {
                    size = RegionSize.MEDIUM;
                }
                else if (sInt >= 4)
                {
                    size = RegionSize.LARGE;
                }
            }

            int world = WorldHolder.instance.worldLevel;

            int selectedId = forcedId;

            if (forcedId < 0)
            {
                int soucet = 0;
                foreach (MobGroup group in mobGroups)
                {
                    if (group.minRegionSize != RegionSize.NULL && group.minRegionSize > size)
                    {
                        continue;
                    }

                    if (group.maxRegionSize != RegionSize.NULL && group.maxRegionSize < size)
                    {
                        continue;
                    }

                    if (roomType == group.roomType && group.minLevel <= playerLevel && group.maxLevel >= playerLevel &&
                        group.maxWorld >= world && group.minWorld <= world)
                    {
                        soucet += group.frequency;
                    }
                }

                int[] sum = new int[soucet];
                soucet = 0;

                foreach (MobGroup group in mobGroups)
                {
                    if (group.minRegionSize != RegionSize.NULL && group.minRegionSize > size)
                    {
                        continue;
                    }

                    if (group.maxRegionSize != RegionSize.NULL && group.maxRegionSize < size)
                    {
                        continue;
                    }

                    if (roomType == group.roomType && group.minLevel <= playerLevel && group.maxLevel >= playerLevel &&
                        group.maxWorld >= world && group.minWorld <= world)
                    {
                        for (int i = 0; i < group.frequency; i++)
                        {
                            sum[soucet + i] = group.id;
                        }

                        soucet += group.frequency;
                    }
                }

                if (sum.Length == 0)
                {
                    return;
                }

                int rnd = Random.Range(0, sum.Length);
                selectedId = sum[rnd];
            }

            if (selectedId < 0)
            {
                Debug.LogError("chyba - nenalezena spravna groupa ");
                return;
            }

            bool spawned = false;

            foreach (MobGroup group in mobGroups)
            {
                if (group.id == selectedId)
                //if ((roomType == group.roomType && group.minLevel <= playerLevel && group.maxLevel >= playerLevel && group.maxWorld >= world && group.minWorld <= world && forcedId < 0) || (forcedId > 0 && group.id == forcedId))
                {
                    List <MonsterSpawnInfo> infos = new List <MonsterSpawnInfo>();

                    int count = 0;

                    foreach (MobData mob in group.mobs)
                    {
                        Tile tile;

                        if (mob.minSize != RegionSize.NULL)
                        {
                            if (size < mob.minSize)
                            {
                                continue;
                            }
                        }

                        if (mob.location == MapRoom.DIRECTION_LARGEST_ROOM)
                        {
                            tile = room.GetLargestSubRoom(mob.exclude);
                        }
                        else
                        {
                            tile = room.GetSubRoom(mob.roomSize, mob.location, mob.exclude);
                        }

                        if (tile == null)
                        {
                            continue;
                        }

                        MonsterSpawnInfo monsterInfo;

                        if (mob.count > 1)
                        {
                            for (int i = 0; i < mob.count; i++)
                            {
                                monsterInfo = level.SpawnMonsterToRoom(room, mob.monsterTypeName, tile, true, mob.level, mob.chance);

                                if (monsterInfo != null)
                                {
                                    count++;
                                    monsterInfo.tempId = mob.mobId;

                                    if (mob.idParent > 0)
                                    {
                                        try
                                        {
                                            MonsterSpawnInfo parent = null;

                                            foreach (MonsterSpawnInfo inf in infos)
                                            {
                                                if (inf.tempId == mob.idParent)
                                                {
                                                    parent = inf;
                                                    break;
                                                }
                                            }

                                            monsterInfo.master = parent;
                                        }
                                        catch (Exception)
                                        {
                                            throw new Exception("pokousim se nastavit idparent na " + mob.idParent + " ale takovy mob neexistuje! kouka se jen na moby ktere byly nacteny drive. ID nacitaneho moba je " + mob.mobId);
                                        }
                                    }

                                    infos.Add(monsterInfo);
                                }
                            }
                        }
                        else
                        {
                            monsterInfo = level.SpawnMonsterToRoom(room, mob.monsterTypeName, tile, false, mob.level, mob.chance);

                            if (monsterInfo != null)
                            {
                                count++;
                                monsterInfo.tempId = mob.mobId;

                                if (mob.idParent > 0)
                                {
                                    try
                                    {
                                        MonsterSpawnInfo parent = null;

                                        foreach (MonsterSpawnInfo inf in infos)
                                        {
                                            if (inf.tempId == mob.idParent)
                                            {
                                                parent = inf;
                                                break;
                                            }
                                        }

                                        monsterInfo.master = parent;
                                    }
                                    catch (Exception)
                                    {
                                        throw new Exception("pokousim se nastavit idparent na " + mob.idParent + " ale takovy mob neexistuje! kouka se jen na moby ktere byly nacteny drive. ID nacitaneho moba je " + mob.mobId);
                                    }
                                }

                                infos.Add(monsterInfo);
                            }
                        }
                    }

                    if (group.extraGroups.Any())
                    {
                        int minStack = 10000;
                        int maxStack = 0;

                        foreach (ExtraGroupData extraGroup in group.extraGroups)
                        {
                            // spawn all -1 groups
                            if (extraGroup.stackId == -1)
                            {
                                if (Random.Range(0, 100) < extraGroup.chance)
                                {
                                    GenerateGenericEnemyGroup(room, level, RoomType.EXTRA_ROOM, difficulty, regionData, extraGroup.groupId);
                                }
                            }
                            else                             // optimize for next for loop
                            {
                                if (extraGroup.stackId > maxStack)
                                {
                                    maxStack = extraGroup.stackId;
                                }

                                if (extraGroup.stackId < minStack)
                                {
                                    minStack = extraGroup.stackId;
                                }
                            }
                        }

                        // are there any groups that have stackid set?
                        if (maxStack > 0)
                        {
                            // shuffle
                            System.Random rnd = new System.Random();
                            IOrderedEnumerable <ExtraGroupData> shuffled = group.extraGroups.OrderBy(item => rnd.Next());

                            for (int i = minStack; i <= maxStack; i++)
                            {
                                foreach (ExtraGroupData extraGroup in shuffled)
                                {
                                    if (extraGroup.stackId == i)
                                    {
                                        if (Random.Range(0, 100) < extraGroup.chance)
                                        {
                                            GenerateGenericEnemyGroup(room, level, RoomType.EXTRA_ROOM, difficulty, regionData, extraGroup.groupId);
                                            break;                                             // only one spawned group per stack
                                        }
                                    }
                                }
                            }
                        }
                    }

                    spawned = true;

                    Debug.Log("spawnuto " + count + " ze skup. " + selectedId);

                    break;
                }
            }

            if (!spawned)
            {
                Debug.LogError("nenalezena spawngroup do mistnosti typu " + roomType.ToString() + " " + room.region.x + "-" + room.region.y + " in world " + level.ToString());
            }

            if (forcedId > 0 && WorldHolder.instance.activeMap != null)
            {
                WorldHolder.instance.activeMap.ConfigureMonstersAfterSpawn();
            }
        }