public BlockInformation GetNextBlock(MyDefinitionId blockId, HashSet <MyDefinitionId> alreadyKnownBlocks, bool forceNext = false) { if (blockId.TypeId.IsNull) { return((BlockInformation)null); } BlockInformation CurrentBI = GetbyBlockId(blockId); List <BlockInformation> blockList = new List <BlockInformation>(); typeList.TryGetValue(CurrentBI.Type, out blockList); /* Maybe make this a toggle in settings, This would go with Learning everything under the current value of this block */ bool Next = true; BlockInformation BI = new BlockInformation(); BlockInformation Lowest = new BlockInformation(); foreach (BlockInformation selectedBI in blockList) { if (Next && CurrentBI.Group == selectedBI.Group && !alreadyKnownBlocks.Contains(selectedBI.BlockId) || Next && forceNext && !alreadyKnownBlocks.Contains(selectedBI.BlockId)) { return(selectedBI); } if (selectedBI.BlockId.ToString() == CurrentBI.BlockId.ToString() && CurrentBI.Group == selectedBI.Group) { Next = true; } } return((BlockInformation)null); }
public int CurrentLearningCountByType(MyDefinitionId blockId, HashSet <MyDefinitionId> alreadyKnownBlocks) { if (blockId.TypeId.IsNull) { return(-1); } HashSet <MyDefinitionId> Blocks = new HashSet <MyDefinitionId>(); BlockInformation CurrentBI = this.GetbyBlockId(blockId); List <BlockInformation> blockList = new List <BlockInformation>(); typeList.TryGetValue(CurrentBI.Type, out blockList); int pos = 0; foreach (BlockInformation selectedBI in blockList) { if (selectedBI.Group == CurrentBI.Group && alreadyKnownBlocks.Contains(selectedBI.BlockId)) { pos++; /*if (CurrentBI.TechPos >= pos) * { * pos++; * }*/ } } return(pos); }
public BlockInformation GetbyBlockId(MyDefinitionId blockId) { BlockInformation BI = new BlockInformation(); ComponentsCosts.TryGetValue(blockId, out BI); return(BI); }
public int GetBlockPosition(MyDefinitionId blockId) { if (blockId.TypeId.IsNull) { return(-1); } List <MyDefinitionId> Blocks = new List <MyDefinitionId>(); BlockInformation CurrentBI = this.GetbyBlockId(blockId); return(CurrentBI.TechPos); /*List<BlockInformation> blockList = new List<BlockInformation>(); * typeList.TryGetValue(CurrentBI.Type, out blockList); * if (blockList.Count() > 0) * { * int pos = 0; * foreach (BlockInformation selectedBI in blockList) * { * if (CurrentBI.Group == selectedBI.Group) * { * MyCubeBlockDefinition cb = new MyCubeBlockDefinition(); * MyDefinitionManager.Static.TryGetDefinition<MyCubeBlockDefinition>(selectedBI.BlockId, out cb); * * if (!Blocks.Contains(cb.Id)) * { * pos++; Blocks.Add(cb.Id); * if (cb.BlockStages != null && cb.BlockStages.Length > 0) * { * //pos++; * var ids = new HashSet<MyDefinitionId>(cb.BlockStages, MyDefinitionId.Comparer); * ids.Add(cb.Id); * foreach (var id in ids) * { * if (!Blocks.Contains(id)) * { * if (!this.GetbyBlockId(id).SmallLargeBlockId.IsNull()) { Blocks.Add(this.GetbyBlockId(id).SmallLargeBlockId); }; * Blocks.Add(id); * } * } * } * } * //pos++; * } * /* Add Blocks of the same group and size * if (selectedBI.BlockId.ToString() == blockId.ToString() && CurrentBI.Group == selectedBI.Group) * { * //pos = Blocks.Count() - pos; * //pos++; * return pos; * } * * } * }*/ return(-1); }
public HashSet <MyDefinitionId> GetBlocksUnderBlockId(MyDefinitionId blockId) { if (blockId.TypeId.IsNull) { return((HashSet <MyDefinitionId>)null); } HashSet <MyDefinitionId> Blocks = new HashSet <MyDefinitionId>(); BlockInformation CurrentBI = this.GetbyBlockId(blockId); List <BlockInformation> blockList = new List <BlockInformation>(); typeList.TryGetValue(CurrentBI.Type, out blockList); if (blockList.Count() > 0) { foreach (BlockInformation selectedBI in blockList) { if (CurrentBI.TechPos > selectedBI.TechPos && CurrentBI.Group == selectedBI.Group) { Blocks.Add(selectedBI.BlockId); } } /* * foreach (BlockInformation selectedBI in blockList) * { * //MyLog.Default.WriteLine($"compare {selectedBI.blockId.ToString()} <> {blockId.ToString()}"); * if (selectedBI.BlockId.ToString() == blockId.ToString() && CurrentBI.Group == selectedBI.Group) * { * return Blocks; * } * /* Add Blocks of the same group and size * if (CurrentBI.CubeSize == selectedBI.CubeSize && CurrentBI.Group == selectedBI.Group) * { * Blocks.Add(selectedBI.BlockId); * } * }*/ } return(Blocks); //return (HashSet<MyDefinitionId>)null; }
void UnlockById(MyDefinitionId blockId, long playerID, bool force = false) { var ids = new HashSet <MyDefinitionId>(); ulong steamId; bool NextGenBlock = false; try { PlayerData playerData = players[playerID]; if (!force && playerData.LearnedBocks.Contains(blockId)) { if (settings.EnhancedProgression) { /* Get the Next Block Tech */ BlockInformation BI = progress.GetNextBlock(blockId, playerData.LearnedBocks); if (BI != null) { var cbtest = MyDefinitionManager.Static.GetCubeBlockDefinition(blockId); MyLog.Default.WriteLine($"{cbtest.DisplayNameText} is Generated? {cbtest.IsGeneratedBlock}"); blockId = BI.BlockId; NextGenBlock = true; } else { return; } } else { return; } } if (!settings.InstantLearn || NextGenBlock) { //double blockLuck = progress.getLuckValueByBlockId(blockId); double playerluck = playerData.Luck; //double settingsdifficulty = settings.LearnDifficulty; //1 = 20 //double RandomRoll = new Rnd(1,100).Next(); //double RandomRoll = 100; double goal = settings.LearnDifficulty; //double roll = RandomRoll*((playerluck*1.5)); //double goal = (100*(blockLuck)) * (settings.LearnDifficulty * 10); //MyLog.Default.WriteLine($"Roll {roll} RandomRoll {RandomRoll} playerLuck {playerluck} Goal {goal}"); if (goal > playerluck) { //MyLog.Default.WriteLine($"{playerID} Luck Failed: {roll}"); if (userIds.TryGetValue(playerID, out steamId)) { SendUnlockNotification(blockId, "White", $"Your Knowledge on { progress.GetbyBlockId(blockId).Type }s has increased. {playerluck} of {goal}", steamId); } playerData.Luck++; return; } playerData.Luck = 1; //MyLog.Default.WriteLine($"{playerID} Luck Roll Won: {roll}"); } ids.Add(blockId); var cb = MyDefinitionManager.Static.GetCubeBlockDefinition(blockId); if (!cb.Public) { return; } /* Start unlocking Blocks */ var dg = MyDefinitionManager.Static.TryGetDefinitionGroup(cb.BlockPairName); if (dg != null) { if (dg.Large != null) { ids.Add(dg.Large.Id); } if (dg.Small != null) { ids.Add(dg.Small.Id); } } if (!cb.GuiVisible || (cb.BlockStages != null && cb.BlockStages.Length > 0)) { foreach (var bid in ids.ToList()) { HashSet <MyDefinitionId> blocks; if (variantGroups.TryGetValue(bid, out blocks)) { if (blocks != null) { foreach (var block in blocks) { ids.Add(block); } } } } } if (false && settings.EnhancedProgression) { //Remove all blocks that the player already has ids.UnionWith(progress.GetBlocksUnderBlockId(blockId)); //ids = new HashSet<MyDefinitionId>(ids.Except(playerData.LearnedBocks).ToList()); } foreach (var id in ids) { playerData.LearnedBocks.Add(id); MyVisualScriptLogicProvider.PlayerResearchUnlock(playerID, id); } /* Send Message to Player */ try { if (!force && userIds.TryGetValue(playerID, out steamId)) { var lockedBlock = new SerializableDefinitionId(); if (settings.AlwaysLocked.TryGetValue(blockId, out lockedBlock)) { MyLog.Default.WriteLine($"Learning Denied: {lockedBlock.ToString()}"); SendUnlockNotification(blockId, "Red", $"{MyDefinitionManager.Static.GetCubeBlockDefinition(blockId).DisplayNameText} technology is out of your reach.", steamId); return; } else { if (progress.GetNextBlock(blockId, playerData.LearnedBocks) == null) { SendUnlockNotification(blockId, "Blue", $"You can now build {MyDefinitionManager.Static.GetCubeBlockDefinition(blockId).DisplayNameText}. You've mastered { progress.GetbyBlockId(blockId).Type }!", steamId); } else { SendUnlockNotification(blockId, "White", $"You can now build {MyDefinitionManager.Static.GetCubeBlockDefinition(blockId).DisplayNameText}.", steamId); //SendUnlockNotification(blockId, true, $"You can now build {MyDefinitionManager.Static.GetCubeBlockDefinition(blockId).DisplayNameText}. {progress.CurrentLearningCountByType(blockId, playerData.LearnedBocks)} out of {progress.GetBlockTechTreeCount(blockId)}", steamId); } } } } catch (Exception e) { MyLog.Default.WriteLine($"ERROR Sending Unlock notification: {e.Message}"); MyLog.Default.WriteLine($"ERROR Sending Unlock notification: {e.StackTrace}"); MyLog.Default.Flush(); } } catch (Exception e) { MyLog.Default.WriteLine($"ERROR: {e.Message}"); MyLog.Default.WriteLine($"ERROR: {e.StackTrace}"); MyLog.Default.Flush(); } }
public int GetBlockTechTreeCount(MyDefinitionId blockId) { if (blockId.TypeId.IsNull) { return(-1); } HashSet <MyDefinitionId> Blocks = new HashSet <MyDefinitionId>(); BlockInformation CurrentBI = this.GetbyBlockId(blockId); List <BlockInformation> blockList = new List <BlockInformation>(); typeList.TryGetValue(CurrentBI.Type, out blockList); //blockList.AsQueryable(); //blockList = (List<BlockInformation>)blockList.Where(s => s.Group == CurrentBI.Group); int pos = -1; if (blockList.Count() > 0) { foreach (BlockInformation selectedBI in blockList) { if (selectedBI.Group == CurrentBI.Group) { if (selectedBI.TechPos > pos) { pos = selectedBI.TechPos; } } } } return(pos);//blockList.Last().TechPos; /* * int pos = -1; * int posGrouped = 0; * if (blockList.Count() > 0) * { * * foreach (BlockInformation selectedBI in blockList) * { * /* Add Blocks of the same group and size * if (CurrentBI.Group == selectedBI.Group) * { * MyCubeBlockDefinition cb = new MyCubeBlockDefinition(); * MyDefinitionManager.Static.TryGetDefinition<MyCubeBlockDefinition>(selectedBI.BlockId, out cb); * * if (!Blocks.Contains(cb.Id)) * { * pos++; Blocks.Add(cb.Id); * if (cb.BlockStages != null && cb.BlockStages.Length > 0) * { * //pos++; * //pos++; * var ids = new HashSet<MyDefinitionId>(cb.BlockStages, MyDefinitionId.Comparer); * ids.Add(cb.Id); * //pos = pos - ids.Count(); * foreach (var id in ids) * { * if (!Blocks.Contains(id)) * { * MyLog.Default.WriteLine($"BlockStages: {(SerializableDefinitionId)id}"); * if (!this.GetbyBlockId(id).SmallLargeBlockId.IsNull()) { Blocks.Add(this.GetbyBlockId(id).SmallLargeBlockId); posGrouped++; }; * Blocks.Add(id); * posGrouped++; * } * } * } * } * //pos++; * //Blocks.Add(cb.Id); * * } * } * } * return pos; * * foreach (BlockInformation selectedBI in blockList) * { * /* Add Blocks of the same group and size * if (CurrentBI.CubeSize == selectedBI.CubeSize && CurrentBI.Group == selectedBI.Group) * { * MyCubeBlockDefinition cb = new MyCubeBlockDefinition(); * MyDefinitionManager.Static.TryGetDefinition<MyCubeBlockDefinition>(selectedBI.BlockId, out cb); * * if (!Blocks.Contains(cb.Id)) { pos++; Blocks.Contains(cb.Id); } * if (cb.BlockStages != null && cb.BlockStages.Length > 0) * { * pos++; * //pos++; * var ids = new HashSet<MyDefinitionId>(cb.BlockStages, MyDefinitionId.Comparer); * ids.Add(cb.Id); * //pos = pos - ids.Count(); * foreach (var id in ids) * { * MyLog.Default.WriteLine($"BlockStages: {(SerializableDefinitionId)id}"); * if(!Blocks.Contains(id)) * { * Blocks.Add(id); * } * } * } * //pos++; * //Blocks.Add(cb.Id); * * } * }*/ }