Beispiel #1
0
            private void OnDeserialized(StreamingContext context)
            {
                if (!(context.Context is ActionHandler handler))
                {
                    return;
                }
                var actions = _additionalData["actions"].ToObject <List <JToken> >();

                _actions = new DynamicRandomSelector <BaseAction>();
                Message  = "No action to randomize from";
                foreach (var action in actions)
                {
                    if (handler.GetAction((string)action["type"], action["action"], out var baseAction))
                    {
                        var weight = (float)(action["weight"] ?? 1.0F);
                        _actions.Add(baseAction, weight);
                    }
                }

                if (_actions.Count > 0)
                {
                    _actions.Build();
                }
            }