public void SetTargetState(BaseAspect aspect, Mobile target, TimeSpan duration) { Dictionary <Mobile, State> states; if (!States.TryGetValue(this, out states) || states == null) { States.AddOrReplace(this, val => val ?? (states = new Dictionary <Mobile, State>())); } states.AddOrReplace( target, state => { if (state == null) { state = new State(this, aspect, target, duration); } else { OnRemoved(state); state.Aspect = aspect; state.Target = target; state.Expire = DateTime.UtcNow + duration; } OnAdded(state); return(state); }); }