/// <summary> Set the current pewter fatigue </summary> public void SetPewterFatigue(float value) { if (value < 0) { value = 0; } allomancyTree.SetFloat("pewterFatigue", value); Entity.WatchedAttributes.MarkPathDirty("allomancy"); }
ITreeAttribute chunkGenParams() { TreeAttribute tree = new TreeAttribute(); TreeAttribute subtree; tree["structureChanceModifier"] = subtree = new TreeAttribute(); subtree.SetFloat("gates", 10); tree["structureMaxCount"] = subtree = new TreeAttribute(); subtree.SetInt("gates", 1); return(tree); }
/// <summary> Initialize the helper </summary> public void Initialize() { if (allomancyTree == null) { // The entity doesn't have any allomantic properties registered, so we add them. Entity.WatchedAttributes.SetAttribute("allomancy", allomancyTree = new TreeAttribute()); allomancyTree.SetAttribute("powers", new TreeAttribute()); allomancyTree.SetAttribute("metals", new TreeAttribute()); allomancyTree.SetAttribute("status", new TreeAttribute()); allomancyTree.SetAttribute("toggle", new TreeAttribute()); allomancyTree.SetString("selectedMetal", "none"); allomancyTree.SetFloat("pewterFatigue", 0); // Make the entity a random misting. string chosenPower = MistModSystem.METALS[RNG.Next(0, MistModSystem.METALS.Length)]; AllomanticPowers.SetBool(chosenPower, true); Entity.WatchedAttributes.MarkPathDirty("allomancy"); return; } }
public override void OnHeldInteractStart(ItemSlot slot, EntityAgent byEntity, BlockSelection blockSel, EntitySelection entitySel, bool firstEvent, ref EnumHandHandling handling) { IPlayer byPlayer = null; if (byEntity is EntityPlayer) { byPlayer = byEntity.World.PlayerByUid(((EntityPlayer)byEntity).PlayerUID); } if (byPlayer == null) { return; } TreeAttribute tree = new TreeAttribute(); tree.SetFloat("totalChance", slot.Itemstack.Attributes.GetFloat("totalChance", 1)); tree.SetString("inventoryId", slot.Inventory.InventoryID); tree.SetInt("slotId", slot.Inventory.GetSlotId(slot)); api.Event.PushEvent("OpenStackRandomizerDialog", tree); }
public bool TryTriggerState(string statecode) { bool triggered = false; for (int stateid = 0; stateid < availableStates.Count; stateid++) { EmotionState newstate = availableStates[stateid]; if (newstate.Code != statecode || entity.World.Rand.NextDouble() > newstate.Chance) { continue; } if (newstate.whenHealthRelBelow < healthRel) { continue; } float activedur = 0; foreach (int activestateid in ActiveStatesById.Keys) { if (activestateid == stateid) { activedur = ActiveStatesById[stateid]; continue; } EmotionState activestate = availableStates[activestateid]; if (activestate.Slot == newstate.Slot) { // Active state has priority over this one if (activestate.Priority > newstate.Priority) { return(false); } else { // New state has priority ActiveStatesById.Remove(activestateid); entityAttrById.RemoveAttribute("" + activestateid); entityAttr.RemoveAttribute(newstate.Code); break; } } } float newDuration = 0; if (newstate.AccumType == EnumAccumType.Sum) { newDuration = activedur + newstate.Duration; } if (newstate.AccumType == EnumAccumType.Max) { newDuration = Math.Max(activedur, newstate.Duration); } if (newstate.AccumType == EnumAccumType.NoAccum) { newDuration = activedur > 0 ? activedur : newstate.Duration; } ActiveStatesById[stateid] = newDuration; entityAttrById.SetFloat("" + stateid, newDuration); entityAttr.SetFloat(newstate.Code, newDuration); triggered = true; } return(triggered); }
public bool TryTriggerState(string statecode, double chance) { bool triggered = false; for (int stateid = 0; stateid < availableStates.Count; stateid++) { EmotionState newstate = availableStates[stateid]; if (newstate.Code != statecode || chance > newstate.Chance) { continue; } if (newstate.whenHealthRelBelow < healthRel) { continue; } float activedur = 0; foreach (int activestateid in ActiveStatesById.Keys) { if (activestateid == stateid) { activedur = ActiveStatesById[stateid]; continue; } EmotionState activestate = availableStates[activestateid]; if (activestate.Slot == newstate.Slot) { // Active state has priority over this one if (activestate.Priority > newstate.Priority) { return(false); } else { // New state has priority ActiveStatesById.Remove(activestateid); entityAttrById.RemoveAttribute("" + activestateid); entityAttr.RemoveAttribute(newstate.Code); break; } } } float duration = newstate.Duration; if (newstate.BelowTempThreshold > -99 && entity.World.BlockAccessor.GetClimateAt(entity.Pos.AsBlockPos, EnumGetClimateMode.NowValues).Temperature < newstate.BelowTempDuration) { duration = newstate.BelowTempDuration; } float newDuration = 0; if (newstate.AccumType == EnumAccumType.Sum) { newDuration = activedur + duration; } if (newstate.AccumType == EnumAccumType.Max) { newDuration = Math.Max(activedur, duration); } if (newstate.AccumType == EnumAccumType.NoAccum) { newDuration = activedur > 0 ? activedur : duration; } ActiveStatesById[stateid] = newDuration; entityAttrById.SetFloat("" + stateid, newDuration); entityAttr.SetFloat(newstate.Code, newDuration); triggered = true; } return(triggered); }
public bool TryTriggerState(string statecode, double chance, long sourceEntityId) { bool triggered = false; for (int stateid = 0; stateid < availableStates.Length; stateid++) { EmotionState newstate = availableStates[stateid]; if (newstate.Code != statecode || chance > newstate.Chance) { continue; } if (newstate.whenHealthRelBelow < healthRel) { continue; } ActiveEmoState activeState = null; foreach (var val in ActiveStatesByCode) { if (val.Key == newstate.Code) { activeState = val.Value; continue; } int activestateid = val.Value.StateId; EmotionState activestate = availableStates[activestateid]; if (activestate.Slot == newstate.Slot) { // Active state has priority over this one if (activestate.Priority > newstate.Priority) { return(false); } else { // New state has priority ActiveStatesByCode.Remove(val.Key); entityAttr.RemoveAttribute(newstate.Code); break; } } } float duration = newstate.Duration; if (newstate.BelowTempThreshold > -99 && entity.World.BlockAccessor.GetClimateAt(entity.Pos.AsBlockPos, EnumGetClimateMode.NowValues).Temperature < newstate.BelowTempDuration) { duration = newstate.BelowTempDuration; } float newDuration = 0; if (newstate.AccumType == EnumAccumType.Sum) { newDuration = activeState?.Duration ?? 0 + duration; } if (newstate.AccumType == EnumAccumType.Max) { newDuration = Math.Max(activeState?.Duration ?? 0, duration); } if (newstate.AccumType == EnumAccumType.NoAccum) { newDuration = activeState?.Duration > 0 ? activeState?.Duration ?? 0 : duration; } if (activeState == null) { ActiveStatesByCode[newstate.Code] = new ActiveEmoState() { Duration = newDuration, SourceEntityId = sourceEntityId, StateId = stateid }; } else { activeState.SourceEntityId = sourceEntityId; } entityAttr.SetFloat(newstate.Code, newDuration); triggered = true; } return(triggered); }
public bool TryTriggerState(string statecode) { EmotionState newstate; if (!availableStates.TryGetValue(statecode, out newstate)) { return(false); } if (entity.World.Rand.NextDouble() > newstate.Chance) { return(false); } float activedur = 0; foreach (string activestatecode in activeStates.Keys) { if (activestatecode == statecode) { activedur = activeStates[activestatecode]; continue; } EmotionState activestate = availableStates[activestatecode]; if (activestate.Slot == newstate.Slot) { // Active state has priority over this one if (activestate.Priority > newstate.Priority) { return(false); } else { // New state has priority activeStates.Remove(activestatecode); entityAttr.RemoveAttribute(activestatecode); break; } } } float newDuration = 0; if (newstate.AccumType == EnumAccumType.Sum) { newDuration = activedur + newstate.Duration; } if (newstate.AccumType == EnumAccumType.Max) { newDuration = Math.Max(activedur, newstate.Duration); } if (newstate.AccumType == EnumAccumType.NoAccum) { newDuration = activedur > 0 ? activedur : newstate.Duration; } activeStates[statecode] = newDuration; entityAttr.SetFloat(statecode, newDuration); return(true); }