/* * Author: Needles * https://steamcommunity.com/profiles/76561198026257137/ */ ::Debug.Print("*** STATE"); ::State <- {}; ::State.SCOPE_KEY <- UniqueString(); enum STATE { NONE = 0, BURN = 1, MINICRIT = 2, AIRBORNE = 3, } ::State.StateManager <- class { stateMap = null; countMap = null; id = null; constructor() { self = _self; modMap = {}; stateMap = {}; id = 0; } function HasState(state) { if (!(state in countMap)) return false; return (countMap[state] > 0); } function AddStateMod(state) { stateMap[++id] <- state; // @TODO - Using integer as key... This will eventually overflow, but it won't be a problem. if (!(state in countMap)) countMap[state] <- 0; countMap[state] ++; return id; } function RemoveStateMod(id) { if (!(id in stateMap)) return; countMap[stateMap[id]]--; stateMap.rawdelete(id); } function ResetState() { countMap.clear(); stateMap.clear(); } } function State::ValidateStateManager(scope) { if (!(::State.SCOPE_KEY in scope)) scope[::State.SCOPE_KEY] <- ::State.StateManager(); return scope[::State.SCOPE_KEY]; } function State::HasState(entity, state) { entity.ValidateScriptScope(); local stateManager = ::State.ValidateStateManager(entity.GetScriptScope()); return (stateManager.HasState(state)); } function State::AddStateMod(entity, state) { entity.ValidateScriptScope(); local stateManager = ::State.ValidateStateManager(entity.GetScriptScope()); stateManager.AddStateMod(state); } function State::RemoveStateMod(entity, modId) { entity.ValidateScriptScope(); local stateManager = ::State.ValidateStateManager(entity.GetScriptScope()); stateManager.RemoveStateMod(modId); }