public DungeonScript FindScriptOrNull(DungeonLobby pLobby, DungeonLevel pLevel, int itemId = -1) { var key = Tuple.Create(pLobby, pLevel); List <DungeonScript> allowableScripts; if (!HasScript(pLobby, pLevel, itemId)) { //Doesn't have the exact script, let's see if it has one at all for the lobby or level if (!HasScript(pLobby, pLevel)) { //this is awkward... We should just not allow this to happen at all return(null); } //One for the lobby and level so let's just use that as a default allowableScripts = _scripts[key]; } else { allowableScripts = _scripts[key].Where(a => a.ItemPass.Contains(itemId)).ToList(); } if (allowableScripts.Count <= 0) { return(null); } //Random script! var index = RandomProvider.Get().Next(0, allowableScripts.Count - 1); return(allowableScripts[index]); }
//TODO: Account for freed regions. public bool StartDungeon(Creature pCreator, DungeonLobby pLobby, DungeonLevel pLevel, Item pItem) { var script = FindScriptOrNull(pLobby, pLevel, pItem.Info.Id); if (script == null) { return(false); } int nextAvailableRegion = _regionIndex; Log.Info("Next available Region: {0}", nextAvailableRegion); var newDungeon = new Dungeon(pCreator, _regionIndex, script, out nextAvailableRegion); if (newDungeon == null) { return(false); } _regionIndex = nextAvailableRegion; var addKey = Tuple.Create(pLobby, pLevel); if (!_activeDungeons.ContainsKey(addKey)) { _activeDungeons[addKey] = new List <Dungeon>(); } _activeDungeons[addKey].Add(newDungeon); Log.Info("Starting dungeon..."); newDungeon.Start(); return(true); }
public bool HasScript(DungeonLobby pLobby, DungeonLevel pLevel, int itemId = -1) { var key = Tuple.Create(pLobby, pLevel); if (!_scripts.ContainsKey(key)) { return(false); } if (itemId == -1 && _scripts[key].Count > 0) { return(true); } if (_scripts[key].Count(a => a.ItemPass.Contains(itemId)) > 0) //<<<Gross { return(true); } return(false); }
public void SetLobby(DungeonLobby pLobby) { Lobby = pLobby; }