Ejemplo n.º 1
0
    /// <summary>
    /// Generates a quest with the goal of clearing a specific chunk structure
    /// </summary>
    /// <param name="dungeonPos"></param>
    /// <param name="chunkStructure"></param>
    /// <returns></returns>
    private Quest GenerateDungeonQuest(Vec2i dungeonPos, ChunkStructure chunkStructure)
    {
        questCount++;
        //Get the dungeon this quest is based on
        Dungeon dun = chunkStructure.DungeonEntrance.GetDungeon();
        //If the dungeon doesn't have a key (generation should be set so it doesn't), we create one
        Key key = dun.GetKey();

        if (key == null)
        {
            key = new SimpleDungeonKey(GenRan.RandomInt(1, int.MaxValue));
            dun.SetKey(key);
        }

        //We build the quest in reverse, we first define the goal
        List <QuestTask> revTasks = new List <QuestTask>();

        //For a dungeon quest, this is always to kill the dungeon boss
        revTasks.Add(new QuestTask("Kill " + dun.Boss.Name, QuestTask.QuestTaskType.KILL_ENTITY, new object[] { dun.Boss }));

        //The second to last task is to get to the dungeon,
        revTasks.Add(new QuestTask("Get to dungeon", QuestTask.QuestTaskType.GO_TO_LOCATION, new object[] { chunkStructure.WorldMapLocation, dun.WorldEntrance }));

        //Before we get to the dungeon, we need to get the key.
        //The key can either be held by an entity, or it can be found in a
        //random chunk structure with no dungeon.


        return(GenerateDungeonKeyQuest_RandomStructure(dungeonPos, dun, revTasks));
    }
Ejemplo n.º 2
0
    public int AddChunkStructure(ChunkStructure cStruct)
    {
        int id = WorldChunkStructures.Count;

        WorldChunkStructures.Add(id, cStruct);
        cStruct.SetID(id);
        return(id);
    }
Ejemplo n.º 3
0
    public EntityGroup SpawnBanditPatrol(ChunkStructure camp, List <Entity> groupEntities)
    {
        EntityGroupBandits bandits = new EntityGroupBandits(camp, groupEntities);


        AddEntityGroup(bandits);

        return(bandits);
    }
Ejemplo n.º 4
0
    public EntityGroupBandits(ChunkStructure home, List <Entity> entities = null, EconomicInventory inventory = null) : base(home.ChunkPos, entities, inventory)
    {
        Vec2i deltaPosition = GenerationRandom.RNG.RandomVec2i(-64, 64);

        Vec2i tChunk = home.ChunkPos + deltaPosition;

        NearGroups = new List <EntityGroup>(20);

        Home = home;
        GenerateNewPath(tChunk);
    }
Ejemplo n.º 5
0
    private Dungeon GenerateCaveDungeon(DungeonEntrance entr)
    {
        ChunkStructure cStruc = entr.ChunkStructure;

        if (cStruc is BanditCamp)
        {
            BanditCaveDungeonBuilder bcdb = new BanditCaveDungeonBuilder(cStruc.Position, cStruc.Size);
            Dungeon dun = bcdb.Generate(entr, GenRan);
            entr.SetDungeon(dun);
            return(dun);
        }
        return(null);
    }
Ejemplo n.º 6
0
    /// <summary>
    /// Searches all chunk structures to find a valid chunkstructure within
    /// 'allowedDistance' regions of the centre point.
    /// </summary>
    /// <param name="centrePoint"></param>
    /// <param name="allowedDistance"></param>
    /// <returns></returns>
    private ChunkStructure GetRandomFreeStructure(Vec2i centrePoint, int allowedDistance)
    {
        //We first collect all regions close to the required region
        List <Vec2i> allowedRegions = new List <Vec2i>();

        for (int x = -allowedDistance; x <= allowedDistance; x++)
        {
            for (int z = -allowedDistance; z <= allowedDistance; z++)
            {
                allowedRegions.Add(centrePoint + new Vec2i(x, z));
            }
        }

        bool isValid = false;
        int  count   = 0;

        while (!isValid)
        {
            if (allowedRegions.Count == 0)
            {
                return(null);
            }
            //We choose a random region
            Vec2i chosenReg = GenRan.RandomFromList(allowedRegions);

            if (OrderedStructures.ContainsKey(chosenReg) && OrderedStructures[chosenReg].Count > 0)
            {
                ChunkStructure ranStruct = GenRan.RandomFromList(OrderedStructures[chosenReg]);
                //We require a structure with no dungeon
                if (!ranStruct.HasDungeonEntrance)
                {
                    //If this chunk structure is valid, we remove it from the list of chunk structures and return it;
                    OrderedStructures[chosenReg].Remove(ranStruct);
                    isValid = true;
                    return(ranStruct);
                }
            }
            else
            {
                allowedRegions.Remove(chosenReg);
            }

            count++;
            if (count > 100)
            {
                isValid = true;
            }
        }
        return(null);
    }
    public Dictionary <Vec2i, ChunkData> GenerateAllStructures()
    {
        GeneratedChunks        = new Dictionary <Vec2i, ChunkData>();
        GeneratedChunksAddLock = new Object();

        //Create array to hold data we send to the thread
        ChunkStructure[] toGen = new ChunkStructure[10];
        int genCount           = 0;

        //Create list to store all threads
        List <Thread> threads = new List <Thread>(20);

        //iterate all structure shells
        foreach (KeyValuePair <Vec2i, ChunkStructure> kvp in ChunkStructureShells)
        {
            //Add to array
            toGen[genCount] = kvp.Value;
            genCount++;
            if (genCount == 10)
            {
                //Start generation
                threads.Add(ThreadStructureGeneration(toGen));
                //Reset
                genCount = 0;
                toGen    = new ChunkStructure[10];
            }
        }

        if (toGen[0] != null)
        {
            threads.Add(ThreadStructureGeneration(toGen));
        }


        bool threadsComplete = false;

        while (!threadsComplete)
        {
            threadsComplete = true;
            foreach (Thread t in threads)
            {
                if (t.IsAlive)
                {
                    threadsComplete = false;
                }
            }
        }
        return(GeneratedChunks);
    }
Ejemplo n.º 8
0
 private string TeleportToChunkStructure(string[] args)
 {
     if (int.TryParse(args[1], out int structID))
     {
         ChunkStructure cstruct = GameManager.WorldManager.World.GetChunkStructure(structID);
         if (cstruct == null)
         {
             return("Chunk structure with ID " + structID + " not found");
         }
         GameManager.PlayerManager.Player.SetPosition(cstruct.Position * World.ChunkSize);
         return("Teleporting to chunk structure " + structID);
     }
     else
     {
         return("Argument must be ID of chunk structure, " + args[1] + " not recognised");
     }
 }
Ejemplo n.º 9
0
 public void SpawnChunkEntities(ChunkBase cb)
 {
     if (cb.ChunkStructure != null)
     {
         ChunkStructure cStruct  = cb.ChunkStructure;
         Vec2i          localPos = cb.Position - cStruct.Position;
         List <Entity>  toSpawn  = cStruct.StructureEntities[localPos.x, localPos.z];
         if (toSpawn == null)
         {
             return;
         }
         foreach (Entity e in toSpawn)
         {
             e.CombatManager.Reset();
             Manager.LoadEntity(e);
         }
     }
 }
Ejemplo n.º 10
0
    /// <summary>
    /// Places the dungeon key in a random structure.
    ///
    /// </summary>
    /// <param name="dungeonPos"></param>
    /// <param name="chunkStructure"></param>
    /// <param name="endTasks"></param>
    /// <returns></returns>
    private Quest GenerateDungeonKeyQuest_RandomStructure(Vec2i dungeonPos, Dungeon dungeon, List <QuestTask> endTasks)
    {
        //Find a random chunk structure
        ChunkStructure ranStruct = GetRandomFreeStructure(dungeonPos, 3);

        if (ranStruct == null)
        {
            throw new System.Exception("We need to fix this");
        }
        //We add the dungeon key to the loot chest of this structure
        ranStruct.FinalLootChest.GetInventory().AddItem(dungeon.GetKey());
        //Add the item finding task


        endTasks.Add(new QuestTask("Go to " + ranStruct.Name + " and collect the key", QuestTask.QuestTaskType.PICK_UP_ITEM,
                                   new object[] { dungeon.GetKey(), ranStruct.WorldMapLocation, (ranStruct.FinalLootChest as WorldObjectData).WorldPosition }));

        //Quest initiator will be a random entity
        //Therefore, we choose a random settlement
        Settlement set = GetRandomSettlement(dungeonPos, 5);
        //Then take a random npc from it.
        NPC            npc       = GameManager.EntityManager.GetEntityFromID(GenRan.RandomFromList(set.SettlementNPCIDs)) as NPC;
        QuestInitiator questInit = new QuestInitiator(QuestInitiator.InitiationType.TALK_TO_NPC, new object[] { npc, false });



        //We now reverse the tasks to get in correct order
        endTasks.Reverse();
        Quest quest = new Quest("Clear dungeon " + questCount, questInit, endTasks.ToArray(), QuestType.clear_dungeon);



        if (npc.Dialog == null)
        {
            NPCDialog dialog = new NPCDialog(npc, "Hello adventurer! How can I help you today?");

            NPCDialogNode exitNode = new NPCDialogNode("Don't worry, I'll be on my way", "");
            exitNode.IsExitNode = true;

            dialog.AddNode(exitNode);
            npc.SetDialog(dialog);
        }
        NPCDialogNode startQuestNode = new NPCDialogNode("Have you heard of any quests for an adventurer such as myself?", "I've heard of a dungeon that may be full of sweet shit." +
                                                         " It's probably locked though, last I heard the key was at " + ranStruct.Name);

        NPCDialogNode exitNode2 = new NPCDialogNode("Thanks! I'll be on my way", "");

        exitNode2.IsExitNode = true;
        startQuestNode.AddNode(exitNode2);
        npc.Dialog.AddNode(startQuestNode);

        startQuestNode.SetOnSelectFunction(() => {
            GameManager.QuestManager.StartQuest(quest);
        });
        startQuestNode.SetShouldDisplayFunction(() =>
        {
            if (GameManager.QuestManager.Unstarted.Contains(quest))
            {
                return(true);
            }
            return(false);
        });


        NPCDialogNode questRewardNode = new NPCDialogNode("I killed " + dungeon.Boss.Name, "I didn't think it was possible. Here, take this as a reward");

        questRewardNode.AddNode(exitNode2);
        questRewardNode.SetShouldDisplayFunction(() => {
            return(GameManager.QuestManager.Completed.Contains(quest));
        });
        questRewardNode.SetOnSelectFunction(() =>
        {
            Inventory playerInv = GameManager.PlayerManager.Player.Inventory;
            playerInv.AddItem(new SteelLongSword());
        });
        npc.Dialog.AddNode(questRewardNode);

        return(quest);
    }
 public ChunkStructureBuilder(ChunkStructure structure, GameGenerator gameGen = null) : base(structure.ChunkPos, structure.Size, null, null)
 {
     Structure = structure;
 }
Ejemplo n.º 12
0
 public BanditCampBuilder(ChunkStructure structure, GameGenerator gameGen = null) : base(structure, gameGen)
 {
     structure.SetName("Bandit camp");
     RaiseBase(2, Boundry);
 }
Ejemplo n.º 13
0
 public void AddChunkStructure(ChunkStructure cStruct)
 {
     ChunkStructure = cStruct;
 }
Ejemplo n.º 14
0
 public void SetChunkStructure(ChunkStructure entranceStructure)
 {
     ChunkStructure = entranceStructure;
 }