/// <summary> /// Set the type of a voxel without triggering all the bookkeeping mechanisms. /// Should only be used by ChunkGenerator as it can break geometry building. /// </summary> /// <param name="NewType"></param> public void RawSetType(MaybeNull <VoxelType> MaybeNewType) { if (MaybeNewType.HasValue(out VoxelType NewType)) { var previous = _cache_Chunk.Data.Types[_cache_Index]; // Change actual data _cache_Chunk.Data.Types[_cache_Index] = (byte)NewType.ID; // Changing the voxel type clears grass. _cache_Chunk.Data.Grass[_cache_Index] = 0; // Did we go from empty to filled or vice versa? Update filled counter. if (previous == 0 && NewType.ID != 0) { _cache_Chunk.Data.VoxelsPresentInSlice[_cache_Local_Y] += 1; } else if (previous != 0 && NewType.ID == 0) { _cache_Chunk.Data.VoxelsPresentInSlice[_cache_Local_Y] -= 1; } } else { throw new InvalidOperationException("Tried to set voxel to null type"); } }
protected void ChangeAct(MaybeNull<Act> NewAct) { if (CurrentAct.HasValue(out Act currentAct)) currentAct.OnCanceled(); CurrentAct = NewAct; }
public void ChangeTask(Task task) { Blackboard.Erase("NoPath"); if (CurrentTask.HasValue(out var previousTask)) { previousTask.OnUnAssign(this); } CurrentTask = task; if (CurrentTask.HasValue(out var newTask)) { ChangeAct(newTask.CreateScript(Creature)); if (Tasks.Contains(task)) { Tasks.Remove(task); } else { task.OnAssign(this); } } else { ChangeAct(null); } }
public void CancelTask(MaybeNull <Task> Task) { if (Task.HasValue(out var task)) { var localAssigneeList = new List <CreatureAI>(task.AssignedCreatures); foreach (var actor in localAssigneeList) { actor.RemoveTask(task); } Tasks.RemoveAll(t => Object.ReferenceEquals(t, task)); task.OnDequeued(World); task.OnCancelled(this, World); task.WasCancelled = true; } }
public IEnumerable <Status> CreateResource() { if (RawMaterials == null || RawMaterials.Count == 0) { Agent.SetTaskFailureReason("Failed to create resources."); yield return(Act.Status.Fail); yield break; } ActualCreatedResource = Library.CreateMetaResource(ItemType.Craft_MetaResourceFactory, Agent, new Resource(ItemType), Agent.Blackboard.GetData <List <Resource> >("stashed-materials")); if (ActualCreatedResource.HasValue(out var res)) { yield return(Status.Success); } else { Agent.SetTaskFailureReason("Failed to create meta resource."); yield return(Act.Status.Fail); } }
public ResourceSet GenerateTradeItems(WorldManager world) { var toReturn = new ResourceSet(); String[] blacklistTags = { "Money", "Corpse" }; foreach (var tags in TradeGoods) { int num = MathFunctions.RandInt(tags.Value, tags.Value + 4); if (tags.Key == "Craft") { for (int i = 0; i < num; i++) { MaybeNull <Resource> randResource = null; if (tags.Key == "Craft") { var craftTag = Datastructures.SelectRandom(Crafts); var availableCrafts = Library.EnumerateResourceTypesWithTag(craftTag); if (Library.CreateMetaResource("Trinket", null, new Resource("Trinket"), new List <Resource> { new Resource(Datastructures.SelectRandom(availableCrafts)) }).HasValue(out var trinket)) { if (MathFunctions.RandEvent(0.3f) && Encrustings.Count > 0) { randResource = Library.CreateMetaResource("GemTrinket", null, new Resource("Gem-set Trinket"), new List <Resource> { trinket, new Resource(Datastructures.SelectRandom(Library.EnumerateResourceTypesWithTag(Datastructures.SelectRandom(Encrustings)))) }); } else { randResource = trinket; } } } if (randResource.HasValue(out var res)) { toReturn.Add(res); } } } else { var resources = Library.EnumerateResourceTypesWithTag(tags.Key).Select(r => new Resource(r)); if (resources.Count() <= 0) { continue; } for (int i = 0; i < num; i++) { MaybeNull <Resource> randResource = Datastructures.SelectRandom(resources); if (!randResource.HasValue(out var res) || !res.ResourceType.HasValue(out var resType) || resType.Tags.Any(blacklistTags.Contains)) { continue; } if (randResource.HasValue(out res)) { toReturn.Add(res); } } } } return(toReturn); }
public Resource(ResourceType Type) { _TypeName = Type.TypeName; _cachedResourceType = Type; }
private void OnTypeSet(MaybeNull <VoxelType> MaybeNewType) { if (MaybeNewType.HasValue(out VoxelType NewType)) { // Changing a voxel is actually a relatively rare event, so we can afford to do a bit of // bookkeeping here. var previous = _cache_Chunk.Data.Types[_cache_Index]; var blockDestroyed = false; // Change actual data _cache_Chunk.Data.Types[_cache_Index] = (byte)NewType.ID; // Changing the voxel type clears grass. _cache_Chunk.Data.Grass[_cache_Index] = 0; // Did we go from empty to filled or vice versa? Update filled counter. if (previous == 0 && NewType.ID != 0) { _cache_Chunk.Data.VoxelsPresentInSlice[_cache_Local_Y] += 1; } else if (previous != 0 && NewType.ID == 0) { blockDestroyed = true; _cache_Chunk.Data.VoxelsPresentInSlice[_cache_Local_Y] -= 1; } var voxelAbove = VoxelHelpers.GetVoxelAbove(this); if (voxelAbove.IsValid) { InvalidateVoxel(voxelAbove); } InvalidateVoxel(this); // Propogate sunlight (or lack thereof) downwards. var sunlight = (NewType.ID == 0 || NewType.IsTransparent) ? this.Sunlight : false; var below = this; while (true) { below = VoxelHelpers.GetVoxelBelow(below); if (!below.IsValid) { break; } below.Sunlight = sunlight; if (!below.IsEmpty) { InvalidateVoxel(below); } if (!below.IsEmpty && !below.Type.IsTransparent) { break; } } if (blockDestroyed) { // Reveal! VoxelHelpers.RadiusReveal(_cache_Chunk.Manager, this, 10); // Clear player built flag! IsPlayerBuilt = false; } // Invoke new voxel listener. _cache_Chunk.Manager.NotifyChangedVoxel(new VoxelChangeEvent { Type = VoxelChangeEventType.VoxelTypeChanged, Voxel = this, OriginalVoxelType = previous, NewVoxelType = NewType.ID }); } else { throw new InvalidOperationException("Tried to set voxel to null voxel type"); } }
public bool ReferenceEquals(MaybeNull <T> Other) { return(Object.ReferenceEquals(_Value, Other._Value)); }