/// <summary> /// Intializes a new <see cref="ReplaceitemEntityCommand"/> /// </summary> /// <param name="selector">Selector selecting the entities to replace the item on</param> /// <param name="slot">The slot to put the item into</param> /// <param name="item">The item to put into the block</param> /// <param name="count">The amount of the item</param> public ReplaceitemEntityCommand(BaseSelector selector, IItemSlot slot, Item item, int count) { Selector = selector; Slot = slot; Item = item; Count = count; }
private string GetSelectorValue(Page page, BaseSelector selector) { string result = string.Empty; if (selector.Type == SelectorType.Enviroment) { if (SelectorUtils.Parse(selector) is EnviromentSelector enviromentSelector) { result = SelectorUtils.GetEnviromentValue(enviromentSelector.Field, page, 0)?.ToString(); } } else { result = page.Selectable.Select(SelectorUtils.Parse(selector)).GetValue(); } if (!string.IsNullOrEmpty(result) && TotalPageFormatters != null) { foreach (var formatter in TotalPageFormatters) { result = formatter.Formate(result)?.ToString(); } } if (string.IsNullOrWhiteSpace(result)) { throw new SpiderException("The result of total selector is null."); } else { return(result); } }
private void VisitBaseSelector(BaseSelector selector) { AggregateSelectorList aggregateSelectorList = selector as AggregateSelectorList; if (aggregateSelectorList != null) { this.VisitSelectorList(aggregateSelectorList); } else { ComplexSelector complexSelector = selector as ComplexSelector; if (complexSelector != null) { this.VisitComplexSelector(complexSelector); } else { SimpleSelector simpleSelector = selector as SimpleSelector; if (simpleSelector != null) { this.VisitSimpleSelector(simpleSelector.ToString()); } } } }
private string GetSelectorValue(Page page, BaseSelector selector) { string totalStr = string.Empty; if (selector.Type == SelectorType.Enviroment) { if (SelectorUtils.Parse(TotalPageSelector) is EnviromentSelector enviromentSelector) { totalStr = EntityExtractor.GetEnviromentValue(enviromentSelector.Field, page, 0); } } else { totalStr = page.Selectable.Select(SelectorUtils.Parse(TotalPageSelector)).GetValue(); } if (!string.IsNullOrEmpty(totalStr) && TotalPageFormatters != null) { foreach (var formatter in TotalPageFormatters) { totalStr = formatter.Formate(totalStr); } } if (string.IsNullOrEmpty(totalStr)) { throw new SpiderException("The result of total selector is null."); } else { return(totalStr); } }
public SkillIconItem(Transform Parent, BaseSkill Skill, RectTransform CancelObj, bool IsRect /*temp*/) { this.Skill = Skill; IconTransform = AssetManager.CreatePrefabSync(new AssetUri(IsRect ? "prefabs/skillicon.prefab" : "prefabs/newskillIcon.prefab")).transform; IconTransform.SetParent(Parent, false); UIHelper.GetComponent <Image>(IconTransform, "BG/Icon").sprite = AssetManager.CreateAssetSync <Sprite>(new AssetUri(Skill.Icon)); UIHelper.GetComponent <Image>(IconTransform, "BG/Mask").sprite = AssetManager.CreateAssetSync <Sprite>(new AssetUri(Skill.Icon)); Mask_ = IconTransform.Find("BG/Mask").GetComponent <Image>(); Mask_.fillAmount = 1; CDText_ = IconTransform.Find("CD").GetComponent <Text>(); CDText_.gameObject.SetActive(false); NameText_ = IconTransform.Find("Name").GetComponent <Text>(); NameText_.text = Skill.Name; Selector_ = SkillLibrary.Get(Skill.SkillID).Selector.Clone(); var Args = new SkillArgs(Skill) { CancelObj = CancelObj }; Selector_.BindCarrier(IconTransform, Args, (SArgs) => { Skill.Master.Skill.UseSkill(SArgs); }); }
void VisitBaseSelector(BaseSelector selector) { var selectorList = selector as AggregateSelectorList; if (selectorList != null) { VisitSelectorList(selectorList); return; } var complexSelector = selector as ComplexSelector; if (complexSelector != null) { VisitComplexSelector(complexSelector); return; } var simpleSelector = selector as SimpleSelector; if (simpleSelector != null) { VisitSimpleSelector(simpleSelector.ToString()); } }
/// <summary> /// Intializes a new <see cref="AdvancementSingleCommand"/> /// </summary> /// <param name="selector">Selector for selecting players to grant/revoke the advancement or advancement criterion for</param> /// <param name="grant">True if the advancement should be granted. False if it should be revoked</param> /// <param name="advancement">The advancement to grant/revoke</param> /// <param name="criterion">The advancement criterion to grant/revoke. Leave null to only grant/revoke the advancement</param> public AdvancementSingleCommand(BaseSelector selector, IAdvancement advancement, AdvancementObjects.ITrigger?criterion, bool grant = true) { Selector = selector; Grant = grant; Advancement = advancement; Criterion = criterion; }
public Column(PropertyInfo property, PropertyDefine propertyDefine) { Property = property; PropertyDefine = propertyDefine; if (DataType.FullName != DataTypeNames.String && propertyDefine.Length > 0) { throw new SpiderException("Only string property can set length."); } DefaultValue = Property.PropertyType.IsValueType ? Activator.CreateInstance(Property.PropertyType) : null; Option = propertyDefine.Option; Selector = new BaseSelector { Expression = propertyDefine.Expression, Type = propertyDefine.Type, Argument = propertyDefine.Argument }; NotNull = propertyDefine.NotNull; IgnoreStore = propertyDefine.IgnoreStore; Length = propertyDefine.Length; foreach (var formatter in property.GetCustomAttributes <Formatter.Formatter>(true)) { Formatters.Add(formatter); } }
public static void NotNullExpression(BaseSelector selector) { if (string.IsNullOrEmpty(selector.Expression)) { throw new SpiderException($"Expression of {selector} should not be null/empty."); } }
/// <summary> /// Executes if the <paramref name="mainSelector"/>'s score value is <paramref name="operation"/> than <paramref name="otherSelector"/>'s score value /// </summary> /// <param name="mainSelector">The first <see cref="BaseSelector"/></param> /// <param name="mainObject">The first <see cref="BaseSelector"/>'s <see cref="Objective"/></param> /// <param name="operation">The operation used to check the scores</param> /// <param name="otherSelector">The second <see cref="BaseSelector"/></param> /// <param name="otherObject">The second <see cref="BaseSelector"/>'s <see cref="Objective"/></param> /// <param name="want">false if it should execute when it's false</param> /// <returns>The function running the command</returns> public Function IfScore(BaseSelector mainSelector, Objective mainObject, ID.IfScoreOperation operation, BaseSelector otherSelector, Objective otherObject, bool want = true) { mainSelector.LimitSelector(); otherSelector.LimitSelector(); ForFunction.AddCommand(new ExecuteIfScoreRelative(mainSelector, mainObject, operation, otherSelector, otherObject, want)); return(ForFunction); }
/// <summary> /// Intializes a new <see cref="ExperienceModifyCommand"/> /// </summary> /// <param name="selector">Selector selecting the players whose experience to change</param> /// <param name="changeLevels">True if the players' levels should change. False if the players' points should change</param> /// <param name="modifier">The way to modify the players experience</param> /// <param name="value">The value to modify with</param> public ExperienceModifyCommand(BaseSelector selector, bool changeLevels, ID.AddSetModifier modifier, int value) { Selector = selector; ChangeLevels = changeLevels; Modifier = modifier; Value = value; }
private void OnClickObj(BaseSelector selector) { if (selector.gameObject == gameObject) { CurrentState++; } }
public Column(PropertyInfo property, PropertyDefine propertyDefine) { Property = property; PropertyDefine = propertyDefine; var type = Property.PropertyType; if (DataType.FullName != DataTypeNames.String && propertyDefine.Length > 0) { throw new SpiderException("Only string property can set length."); } Multi = typeof(IList).IsAssignableFrom(type); Option = propertyDefine.Option; Selector = new BaseSelector { Expression = propertyDefine.Expression, Type = propertyDefine.Type, Argument = propertyDefine.Argument }; NotNull = propertyDefine.NotNull; IgnoreStore = propertyDefine.IgnoreStore; Length = propertyDefine.Length; foreach (var formatter in property.GetCustomAttributes <Formatter.Formatter>(true)) { Formatters.Add(formatter); } }
private void OnClickObj(BaseSelector selector) { if (selector.gameObject == gameObject) { GetComponentInParent <ChatScene>().ChatDialogState++; } }
public static ISelector Parse(BaseSelector selector) { if (selector != null) { string expression = selector.Expression; switch (selector.Type) { case SelectorType.Css: { NotNullExpression(selector); return(Selectors.Css(expression)); } case SelectorType.Enviroment: { return(Selectors.Enviroment(expression)); } case SelectorType.JsonPath: { NotNullExpression(selector); return(Selectors.JsonPath(expression)); } case SelectorType.Regex: { NotNullExpression(selector); if (string.IsNullOrEmpty(selector.Argument)) { return(Selectors.Regex(expression)); } else { if (int.TryParse(selector.Argument, out var group)) { return(Selectors.Regex(expression, group)); } throw new SpiderException("Regex argument should be a number set to group: " + selector); } } case SelectorType.XPath: { NotNullExpression(selector); return(Selectors.XPath(expression)); } default: { throw new SpiderException($"Selector {selector} unsupoort."); } } } else { return(null); } }
/// <summary> /// Intializes a new <see cref="EffectGiveCommand"/> /// </summary> /// <param name="selector">Selector selecting entities to give the effect to</param> /// <param name="effect">The effect to give</param> /// <param name="seconds">The amount of seconds the entities will have the effect for</param> /// <param name="amplifier">The amplifier of the effect</param> /// <param name="hideParticles">If the effect shouldn't show particles</param> public EffectGiveCommand(BaseSelector selector, ID.Effect effect, int seconds, byte amplifier, bool hideParticles) { Selector = selector; Seconds = seconds; Amplifier = amplifier; Effect = effect; HideParticles = hideParticles; }
public void IncludeNewTarget(BaseSelector bs) { if (targets == null) { targets = new List <BaseSelector>(); } targets.Add(bs); }
/// <summary> /// Intializes a new <see cref="ExecuteIfScoreRelative"/> command /// </summary> /// <param name="selector1">Selector selecting the thing to get a score from</param> /// <param name="objective1">The <see cref="Objective"/> to get the score for <see cref="selector1"/> from</param> /// <param name="selector2">Selector selecting the thing to get a score from</param> /// <param name="objective2">The <see cref="Objective"/> to get the score for <see cref="selector2"/> from</param> /// <param name="operator">How the scores should be relative to each other</param> /// <param name="executeIf">True to use execute if and false to use execute unless the given thing is true</param> public ExecuteIfScoreRelative(BaseSelector selector1, Objective objective1, ID.IfScoreOperation @operator, BaseSelector selector2, Objective objective2, bool executeIf = true) : base(executeIf) { Selector1 = selector1; Objective1 = objective1; Selector2 = selector2; Objective2 = objective2; Operator = @operator; }
public static int GetSpecificity(this BaseSelector selector) { if (selector is SimpleSelector) { var simpleCode = selector.ToString().ToLowerInvariant(); if (simpleCode.StartsWith(":not(")) { simpleCode = simpleCode.Substring(5, simpleCode.Length - 6); return(GetSpecificity(new SimpleSelector(simpleCode))); } else if (simpleCode.StartsWith("#")) { // ID selector return(1 << 12); } else if (simpleCode.StartsWith("::") || simpleCode == ":after" || simpleCode == ":before" || simpleCode == ":first-letter" || simpleCode == ":first-line" || simpleCode == ":selection") { // pseudo-element return(1 << 4); } else if (simpleCode.StartsWith(".") || simpleCode.StartsWith(":") || simpleCode.StartsWith("[")) { // class, pseudo-class, attribute return(1 << 8); } else if (simpleCode.Equals("*")) { // all selector return(0); } else { // element selector return(1 << 4); } } else { var list = selector as IEnumerable <BaseSelector>; if (list != null) { return((from s in list select GetSpecificity(s)).Aggregate((p, c) => p + c)); } else { var complex = selector as IEnumerable <CombinatorSelector>; if (complex != null) { return((from s in complex select GetSpecificity(s.Selector)).Aggregate((p, c) => p + c)); } else { return(0); } } } }
public EntityDefine() { Type = typeof(T); var typeName = Type.GetTypeCrossPlatform().FullName; Name = typeName; TableInfo = Type.GetCustomAttribute <EntityTable>(); if (TableInfo != null) { if (TableInfo.Indexs != null) { TableInfo.Indexs = new HashSet <string>(TableInfo.Indexs.Select(i => i.Replace(" ", ""))).ToArray(); } if (TableInfo.Uniques != null) { TableInfo.Uniques = new HashSet <string>(TableInfo.Uniques.Select(i => i.Replace(" ", ""))).ToArray(); } } EntitySelector entitySelector = Type.GetCustomAttribute <EntitySelector>(); if (entitySelector != null) { Multi = true; Take = entitySelector.Take; Selector = new BaseSelector { Expression = entitySelector.Expression, Type = entitySelector.Type }; } else { Multi = false; } var targetUrlsSelectors = Type.GetCustomAttributes <TargetUrlsSelector>(); TargetUrlsSelectors = targetUrlsSelectors.ToList(); var sharedValueSelectorAttributes = Type.GetCustomAttributes <SharedValueSelector>(); if (sharedValueSelectorAttributes != null) { SharedValues = sharedValueSelectorAttributes.Select(e => new SharedValueSelector { Name = e.Name, Expression = e.Expression, Type = e.Type }).ToList(); } else { SharedValues = new List <SharedValueSelector>(); } GenerateEntityColumns(); ValidateEntityDefine(); }
public void TestImplicitScoreValue() { ScoreValue scoreValue = new ScoreValue(ID.Selector.s, new Objective("scores")); Objective objective = scoreValue; BaseSelector selector = scoreValue; Assert.AreEqual("scores", objective.Name, "Objective wasn't converted correctly"); Assert.AreEqual("@s", selector.GetSelectorString(), "Selector wasn't converted correctly"); }
/// <summary> /// Makes the selected entities join the specified <see cref="Team"/> /// </summary> /// <param name="selector">The <see cref="BaseSelector"/> to use</param> /// <param name="team">The team they should join. Leave null to make them leave their team</param> public void JoinTeam(BaseSelector selector, Team?team) { if (team != null) { ForFunction.AddCommand(new TeamJoinCommand(team, selector)); } else { ForFunction.AddCommand(new TeamLeaveCommand(selector)); } }
/// <summary> /// Gives an item to the selected players /// </summary> /// <param name="player">the <see cref="BaseSelector"/> to use</param> /// <param name="giveItem">The <see cref="Item"/> to give to the players</param> public void GiveItem(BaseSelector player, Item giveItem) { if (giveItem.Slot is null) { ForFunction.AddCommand(new GiveCommand(player, giveItem, giveItem.Count ?? 1)); } else { ForFunction.AddCommand(new ReplaceitemEntityCommand(player, new Slots.InventorySlot((int)giveItem.Slot), giveItem, giveItem.Count ?? 1)); } }
/// <summary> /// Gives the loot which the block at the given coords would drop of broken to the selected players /// </summary> /// <param name="player">the <see cref="BaseSelector"/> to use</param> /// <param name="breakBlock">the coords of the block</param> /// <param name="breakWith">the item used to break the block</param> public void GiveItem(BaseSelector player, Vector breakBlock, Item?breakWith) { if (breakWith is null) { ForFunction.AddCommand(new LootCommand(new LootTargets.GiveTarget(player), new LootSources.MineHandSource(breakBlock, true))); } else { ForFunction.AddCommand(new LootCommand(new LootTargets.GiveTarget(player), new LootSources.MineItemSource(breakBlock, breakWith))); } }
/// <summary> /// Puts the item from the loot table into the players hotbar /// </summary> /// <param name="player">the <see cref="BaseSelector"/> to use</param> /// <param name="breakBlock">the coords of the block</param> /// <param name="breakWith">the item used to break the block</param> /// <param name="slot">The hotbar slot to put the item in</param> public void GiveHotbar(BaseSelector player, Vector breakBlock, Item?breakWith, int slot) { if (breakWith is null) { ForFunction.AddCommand(new LootCommand(new LootTargets.EntityTarget(player, new Slots.HotbarSlot(slot)), new LootSources.MineHandSource(breakBlock, true))); } else { ForFunction.AddCommand(new LootCommand(new LootTargets.EntityTarget(player, new Slots.HotbarSlot(slot)), new LootSources.MineItemSource(breakBlock, breakWith))); } }
/// <summary> /// Forces a player to spectate an entity. The player has to be in spectator mode. Leave both params empty to make the executing player stop spectating /// </summary> /// <param name="spectate">The entity to spectate</param> /// <param name="spectator">The spectating player</param> public void Spectate(BaseSelector spectate, BaseSelector spectator) { if (spectate is null) { ForFunction.AddCommand(new SpectateStopCommand()); } else { spectate.LimitSelector(); spectator.LimitSelector(); ForFunction.AddCommand(new SpectateCommand(spectate, spectator)); } }
public static ISelector Parse(BaseSelector selector) { if (string.IsNullOrEmpty(selector?.Expression)) { return(null); } string expression = selector.Expression; switch (selector.Type) { case SelectorType.Css: { return(Selectors.Css(expression)); } case SelectorType.Enviroment: { return(Selectors.Enviroment(expression)); } case SelectorType.JsonPath: { return(Selectors.JsonPath(expression)); } case SelectorType.Regex: { if (string.IsNullOrEmpty(selector.Argument)) { return(Selectors.Regex(expression)); } else { int group; if (int.TryParse(selector.Argument, out group)) { return(Selectors.Regex(expression, group)); } throw new SpiderException("Regex argument should be a number set to group: " + selector); } } case SelectorType.XPath: { return(Selectors.XPath(expression)); } } throw new SpiderException("Not support selector: " + selector); }
public SkillDescriptor(uint SkillID, SkillType Type, string Name, string Icon, float CD, int Cost, float Radius, int Priority, FilterRule Rule, BaseExecutor Executor, BaseSelector Selector) { this.SkillID = SkillID; this.Type = Type; this.Name = Name; this.Icon = Icon; this.CD = CD; this.Cost = Cost; this.Radius = Radius; this.Rule = Rule; this.Priority = Priority; this.Executor = Executor; this.Selector = Selector; }
protected override void OnSelectObj(BaseSelector obj) { if (PhaseState != PhaseStates.Playing) { return; } if (obj is SelectableObj) { var selector = obj as SelectableObj; selectedId = selector.id; heartObj.transform.position = selector.transform.position; } }
public static int GetSpecificity(this BaseSelector selector) { switch (selector) { case SimpleSelector _: return(GetSimpleSpecificity(selector.ToString().ToLowerInvariant())); case IEnumerable <BaseSelector> list: return((from s in list select GetSpecificity(s)).Aggregate((p, c) => p + c)); case IEnumerable <CombinatorSelector> complex: return((from s in complex select GetSpecificity(s.Selector)).Aggregate((p, c) => p + c)); default: return(0); } }