public static void SetDescription(this IThingGraph source, IThing thing, object name) { var thingGraph = source as SchemaThingGraph; if (thingGraph != null) { var desc = thingGraph.ThingToDisplay(thing); if (desc != null) { if (desc != thing) { source.DoChangeData(desc, name); } } else { var factory = Registry.Pooled <IThingFactory>(); new Schema(source, thing).SetTheLeaf(CommonSchema.DescriptionMarker, factory.CreateItem(source, name)); } } else { throw new ArgumentException("source must be a SchemaThingGraph"); } }
/// <summary> /// assigns the content's descriptions to the thing /// assign = set content.Description to the leaf with CommonSchema.DescriptionMarker /// set content.Source to the leaf with CommonSchema.SourceMarker /// if the leaf doesn't exist, it will be created /// </summary> /// <param name="thing"></param> /// <param name="content"></param> /// <param name="thingGraph"></param> public virtual void AssignContentDescription(IThing thing, Content <Stream> content, IThingGraph thingGraph) { var streamThing = thing as IStreamThing; if (streamThing == null) { return; } var schema = new CommonSchema(thingGraph, streamThing); if (content.Description != null) { if (schema.Description != null) { schema.Description.Data = content.Description; } else { schema.Description = Factory.CreateItem(content.Description);; } } if (content.Source != null) { var sourceThing = schema.GetTheLeaf(CommonSchema.SourceMarker); if (sourceThing == null) { sourceThing = Factory.CreateItem(content.Source); schema.SetTheLeaf(CommonSchema.SourceMarker, sourceThing); } else { sourceThing.Data = content.Source; } } }
public void ThingIdSerializerTest() { IThingGraph graph = new ThingGraph(); IThing thing = factory.CreateItem(); graph.Add(thing); graph.Add(factory.CreateItem()); ThingXmlIdSerializer serializer = new ThingXmlIdSerializer(); serializer.Graph = graph; serializer.Things = graph; foreach (IThing t in graph) { Assert.IsTrue(serializer.Things.Contains(t)); } Stream s = new MemoryStream(); serializer.Write(s); s.Position = 0; serializer = new ThingXmlIdSerializer(); serializer.Graph = graph; serializer.Read(s); foreach (IThing t in graph) { Assert.IsTrue(serializer.Things.Contains(t)); } }
/// <summary> /// Search for name /// if something is found, /// get the described thing for it /// </summary> /// <param name="thingGraph"></param> /// <param name="name"></param> /// <param name="exact"></param> /// <returns></returns> public static IEnumerable <IThing> Search(this IThingGraph thingGraph, object name, bool exact) { var schemaGraph = thingGraph as SchemaThingGraph; bool isSchemaGraph = schemaGraph != null; var schema = new CommonSchema(); foreach (var thing in thingGraph.GetByData(name, exact)) { IThing described = null; if (isSchemaGraph) { described = schemaGraph.DescribedThing(thing); } else { described = schema.GetTheRoot(thingGraph, thing, CommonSchema.DescriptionMarker); } if (described != null) { yield return(described); } else { yield return(thing); } } }
IThing AttackManager_OnDealDamage(IThing Target) { (Target as IDefender).Armor -= Dmg((IDefender)Target); (Target as IDefender).Barrier -= Dmg((IDefender)Target); Temp.State.Current.Chat.Message(new DrawerLine("Weakening poison reduce target arm and bar!", ConsoleColor.Green)); return(Target); }
public void ReadDescriptionTest() { IThing root = GetRoot(); if (root == null) { WriteDescriptionTest(); } root = GetRoot(); ReportDetail("Reading"); this.Tickers.Start(); var schemaGraph = this.Graph as SchemaThingGraph; var view = new SubGraph <IThing, ILink>(this.Graph, new Graph <IThing, ILink>()); var facade = new SubGraphWorker <IThing, ILink>(view); view.Add(root); var iCount = 0; for (var i = 0; i < ReadCount; i++) { foreach (var thing in facade.Expand(new IThing[] { root }, false)) { if (!(thing is ILink)) { var thingToDisplay = schemaGraph.ThingToDisplay(thing); iCount++; } } } ReportSummary(string.Format("Reads \t{0}\t({1} repeats)", iCount, ReadCount)); }
/// <summary>Executes the rule on the specified player <see cref="Thing"/>.</summary> /// <param name="playerThing">The player thing.</param> /// <param name="statName">Name of the attribute.</param> /// <param name="valueToAdd">The value to add.</param> public override void Execute(IThing playerThing, string statName, int valueToAdd) { value = valueToAdd; parentThing = (Thing)playerThing; FindStat(statName); IncreaseStatValue(); }
public static string ToPrettyString(this IThing thing) => thing.MapThing( s => $"{s.Title} ({s.Subsections.Length.ToString()})", ss => $"{ss.Title} ({ss.Clauses.Length.ToString()})", c => $"{c.Title} ({c.Subclauses.Length.ToString()})", sc => $"{sc.Title}" );
protected IThing GetRoot() { IThing root = null; if (rootId == 0) { IThing topic = Graph.GetById(TopicSchema.Topics.Id); if (topic == null) { return(null); } foreach (ILink link in Graph.Edges(topic)) { if (link.Marker.Id == testMarkerId) { return(link.Leaf); } } } else { root = Graph.GetById(rootId); } return(root); }
public virtual WebContent GetContentFromThing(IThingGraph graph, IThing thing) { var info = graph.ContentOf(thing); var uri = GetUri(thing); return(GetContentFromContent(info, uri)); }
public static IEnumerable <IThing> GetChildren(this IThing thing) => thing.MapThing( s => s.Subsections as IEnumerable <IThing>, ss => ss.Clauses as IEnumerable <IThing>, c => c.Subclauses as IEnumerable <IThing>, sc => EMPTY_THING );
public virtual void TestTitle() { this.ReportDetail("**** TestTitle"); IThingGraph graph = new ThingGraph(); IThing thing = Factory.CreateItem(); graph.Add(thing); IThing title = Factory.CreateItem("Title1"); var digidoc = new DigidocSchema(graph, thing); // test the new description: digidoc.Title = title; ValidateTitle(digidoc, graph, thing, title); ValidateTitle(digidoc, graph, thing, title); // add same description again: digidoc.Title = title; ValidateTitle(digidoc, graph, thing, title); // the first description will be an orphan: IThing orphan = title; // make a new description: title = Factory.CreateItem("Title2"); digidoc.Title = title; ValidateTitle(digidoc, graph, thing, title); // test if orphan is deleted: Assert.IsFalse(graph.Contains(orphan), "Orphan not deleted"); // take a new schema: digidoc = new DigidocSchema(graph, thing); ValidateTitle(digidoc, graph, thing, title); }
public IThing DisassembleAndReassemble(IThing thing) { var disassembledThing = Disassemble(thing); var reassembledThing = Reassemble(disassembledThing); return(reassembledThing); }
/// <summary> /// Initializes a new instance of the <see cref="ThingMovementGroundToSlot"/> class. /// </summary> /// <param name="creatureRequestingId"></param> /// <param name="thingMoving"></param> /// <param name="fromLocation"></param> /// <param name="fromStackPos"></param> /// <param name="toLocation"></param> /// <param name="count"></param> public ThingMovementGroundToSlot(uint creatureRequestingId, IThing thingMoving, Location fromLocation, byte fromStackPos, Location toLocation, byte count = 1) : base(creatureRequestingId, EvaluationTime.OnExecute) { if (count == 0 || count > 100) { throw new ArgumentException($"Invalid count {count}.", nameof(count)); } this.FromLocation = fromLocation; this.FromStackPos = fromStackPos; this.FromTile = Game.Instance.GetTileAt(this.FromLocation); this.ToLocation = toLocation; this.ToSlot = (byte)toLocation.Slot; this.Thing = thingMoving; this.Count = count; var droppingItem = this.Requestor?.Inventory?[this.ToSlot]; this.Conditions.Add(new SlotHasContainerAndContainerHasEnoughCapacityEventCondition(this.RequestorId, droppingItem)); this.Conditions.Add(new GrabberHasEnoughCarryStrengthEventCondition(this.RequestorId, this.Thing, droppingItem)); this.Conditions.Add(new ThingIsTakeableEventCondition(this.RequestorId, this.Thing)); this.Conditions.Add(new LocationsMatchEventCondition(this.Thing?.Location ?? default(Location), this.FromLocation)); this.Conditions.Add(new TileContainsThingEventCondition(this.Thing, this.FromLocation, this.Count)); this.ActionsOnPass.Add(new GenericEventAction(this.MoveFromGroudToSlot)); }
/// <summary> /// Initializes a new instance of the <see cref="ThingMovementContainerToContainer"/> class. /// </summary> /// <param name="requestorId"></param> /// <param name="thingMoving"></param> /// <param name="fromLocation"></param> /// <param name="toLocation"></param> /// <param name="count"></param> public ThingMovementContainerToContainer(uint requestorId, IThing thingMoving, Location fromLocation, Location toLocation, byte count = 1) : base(requestorId, EvaluationTime.OnExecute) { if (count == 0) { throw new ArgumentException("Invalid count zero.", nameof(count)); } if (this.Requestor == null) { throw new ArgumentException("Invalid requestor id.", nameof(requestorId)); } this.Thing = thingMoving; this.Count = count; this.FromLocation = fromLocation; this.FromContainer = (this.Requestor as IPlayer)?.GetContainer(this.FromLocation.Container); this.FromIndex = (byte)this.FromLocation.Z; this.ToLocation = toLocation; this.ToContainer = (this.Requestor as IPlayer)?.GetContainer(this.ToLocation.Container); this.ToIndex = (byte)this.ToLocation.Z; if (this.FromContainer?.HolderId != this.ToContainer?.HolderId && this.ToContainer?.HolderId == this.RequestorId) { this.Conditions.Add(new GrabberHasEnoughCarryStrengthEventCondition(this.RequestorId, this.Thing)); } this.Conditions.Add(new GrabberHasContainerOpenEventCondition(this.RequestorId, this.FromContainer)); this.Conditions.Add(new ContainerHasItemAndEnoughAmountEventCondition(this.Thing as IItem, this.FromContainer, this.FromIndex, this.Count)); this.Conditions.Add(new GrabberHasContainerOpenEventCondition(this.RequestorId, this.ToContainer)); this.ActionsOnPass.Add(new GenericEventAction(this.MoveBetweenContainers)); }
/// <summary> /// Checks if the thing has the given condition. /// </summary> /// <param name="thing">The thing to check the conditions on.</param> /// <param name="conditionType">The type of condition.</param> /// <returns>True if the thing has such condition, false otherwise.</returns> public static bool HasCondition(this IThing thing, ConditionType conditionType) { thing.ThrowIfNull(nameof(thing)); conditionType.ThrowIfNull(nameof(conditionType)); return(thing.TrackedEvents.ContainsKey(conditionType.ToString())); }
public static void MonsterOnMap(Location location, ushort monsterId) { var monster = MonsterFactory.Create(monsterId); if (monster != null) { IThing monsterAsThing = monster; var tile = Game.Instance.GetTileAt(location); if (tile == null) { Console.WriteLine($"Unable to place monster at {location}, no tile there."); return; } // place the monster. tile.AddThing(ref monsterAsThing); if (!Game.Instance.Creatures.TryAdd(monster.CreatureId, monster)) { Console.WriteLine($"WARNING: Failed to add {monster.Article} {monster.Name} to the global dictionary."); } Game.Instance.NotifySpectatingPlayers(conn => new CreatureAddedNotification(conn, monster, EffectT.BubbleBlue), monster.Location); } }
public bool Buy(ICitizen trader, TownInterfaces.ThingType type) { float percent = (float)trader.ProfLevels["trader"] / Config.MaxLevel; IThing thing = trader.Bag.GetWithPriceLower(Money, percent, type); if (thing != null) { float priceWithPercent = thing.Price * (1 + percent); Money -= priceWithPercent; trader.Money += priceWithPercent; try { Bag.Add(thing); } catch (OverloadedBagExeption ex) { Log.Add("citizens:Human " + Name + " haven't enougth place for new thing after buying"); } string typeName = thing.GetType().Name; Log.Add("other:Human " + Name + " bought " + typeName + " with price: " + priceWithPercent + " at " + trader.Name); return(true); } return(false); }
public static bool CountObjects(IThing thingAt, string comparer, ushort value) { if (thingAt?.Tile == null || string.IsNullOrWhiteSpace(comparer)) { return(false); } var count = thingAt.Tile.Ground == null ? 0 : 1; count += thingAt.Tile.DownItems.Count(); switch (comparer.Trim()) { case "=": case "==": return(count == value); case ">=": return(count >= value); case "<=": return(count <= value); case ">": return(count > value); case "<": return(count < value); } return(false); }
/// <summary> /// all links of sweeped /// are linked to sink /// </summary> /// <param name="thingGraph"></param> /// <param name="sweeped"></param> /// <param name="sink"></param> /// <returns></returns> public static IEnumerable <IThing> MergeThing(this IThingGraph thingGraph, IThing sweeped, IThing sink) { foreach (var link in thingGraph.Edges(sweeped).ToArray()) { if (link.Root == sweeped) { link.Root = sink; } if (link.Leaf == sweeped) { link.Leaf = sink; } if (link.Marker == sweeped) { link.Marker = sink; } if (link.Root == link.Leaf) { thingGraph.Remove(link); } else { thingGraph.Add(link); } yield return(link); } foreach (var link in thingGraph.WhereQ <ILink> (l => l.Marker != null && l.Marker.Id == sweeped.Id)) { link.Marker = sink; thingGraph.Add(link); yield return(link); } }
/* * ██╗ ██╗███████╗███████╗ * ██║ ██║██╔════╝██╔════╝ * ██║ ██║███████╗█████╗ * ██║ ██║╚════██║██╔══╝ * ╚██████╔╝███████║███████╗ * ╚═════╝ ╚══════╝╚══════╝ */ public override void Use(IPlayer sender, IThing other) { if (other is null) { IThing thing_inside = this.Inventory.FirstOrDefault(); if (thing_inside is Tofu tofu) { if (tofu.Frozen) { tofu.Frozen = false; sender.Reply("The tofu immediately unfreezes."); } else { sender.Reply("The microwave seems to only unfreeze things. The tofu still is room temperatured."); } } else { sender.Reply("The microwave turns on for 30 seconds. Nothing really happens. You wasted some energy. Somewhere in the rain forest a tree dies. Maybe 'put' something inside."); } } else { base.Use(sender, other); } }
public async Task TestA2Async() { IThing thing = GetInstance(true); string result = await thing.GetNumberAsTextAsync(Data.Number); Assert.AreEqual(Data.NumberAsText, result); }
public static bool EnsureChangeData(this IThingGraph thingGraph, IThing item, object data) { if (item == null) { return(false); } var result = false; var link = item as ILink; if (link != null) { var marker = data as IThing; if (marker != null && link.Marker != marker) { link.Marker = marker; result = true; } return(false); } else if (!object.Equals(item.Data, data)) { item.Data = data; result = true; } if (result) { thingGraph.Add(item); } return(result); }
public override void Execute(IThing playerThing, string attributeName, string statName) { parentThing = (Thing)playerThing; FindStat(statName); FindAttribute(attributeName); AddAttributeValueToStatValue(); }
void Update() { Player.Update(); if (Input.GetKeyDown(KeyCode.F)) { var thing = ThingsBehaviour.Instance.SearchNearly(PlayerGameObject); if (thing != null) { var gameObj = ThingsBehaviour.Instance.Things[thing]; var distance = Utils.Distance(gameObj, PlayerGameObject); var skillContext = new SkillContext(Player, distance, null); if (!_useThingSkill.ReadyToUse(skillContext)) { return; } _usableThing = thing; _useThingSkill.Thing = thing; Player.Use(_useThingSkill, skillContext); } } }
/// <summary> /// Initializes a new instance of the <see cref="ThingMovementSlotToContainer"/> class. /// </summary> /// <param name="requestorId"></param> /// <param name="thingMoving"></param> /// <param name="fromLocation"></param> /// <param name="toLocation"></param> /// <param name="count"></param> public ThingMovementSlotToContainer(uint requestorId, IThing thingMoving, Location fromLocation, Location toLocation, byte count = 1) : base(requestorId, EvaluationTime.OnExecute) { if (count == 0) { throw new ArgumentException("Invalid count zero.", nameof(count)); } if (this.Requestor == null) { throw new ArgumentException("Invalid requestor id.", nameof(requestorId)); } this.FromLocation = fromLocation; this.FromSlot = (byte)this.FromLocation.Slot; this.ToLocation = toLocation; this.ToContainer = (this.Requestor as IPlayer)?.GetContainer(this.ToLocation.Container); this.ToIndex = (byte)this.ToLocation.Z; this.Item = thingMoving as IItem; this.Count = count; this.Conditions.Add(new SlotContainsItemAndCountEventCondition(this.RequestorId, this.Item, this.FromSlot, this.Count)); this.Conditions.Add(new GrabberHasContainerOpenEventCondition(this.RequestorId, this.ToContainer)); this.Conditions.Add(new ContainerHasEnoughCapacityEventCondition(this.ToContainer)); this.ActionsOnPass.Add(new GenericEventAction(this.MoveSlotToContainer)); }
public TestItem(Int64 id, IThing thing, IVisual one, IVisual two) { this.id = id; this.thing = thing; this.one = one; this.two = two; }
public ThingMovementContainerToGround(uint creatureRequestingId, IThing thingMoving, Location fromLocation, Location toLocation, byte count = 1) : base(creatureRequestingId, EvaluationTime.OnExecute) { // intentionally left thing null check out. Handled by Perform(). var requestor = RequestorId == 0 ? null : Game.Instance.GetCreatureWithId(RequestorId); if (count == 0) { throw new ArgumentException("Invalid count zero."); } if (requestor == null) { throw new ArgumentNullException(nameof(requestor)); } Thing = thingMoving; Count = count; FromLocation = fromLocation; FromContainer = (requestor as IPlayer)?.GetContainer(FromLocation.Container); FromIndex = (byte)FromLocation.Z; ToLocation = toLocation; ToTile = Game.Instance.GetTileAt(ToLocation); Conditions.Add(new CanThrowBetweenEventCondition(RequestorId, requestor.Location, ToLocation)); Conditions.Add(new GrabberHasContainerOpenEventCondition(RequestorId, FromContainer)); Conditions.Add(new ContainerHasItemAndEnoughAmountEventCondition(Thing as IItem, FromContainer, FromIndex, Count)); Conditions.Add(new LocationNotObstructedEventCondition(RequestorId, Thing, ToLocation)); Conditions.Add(new LocationHasTileWithGroundEventCondition(ToLocation)); ActionsOnPass.Add(new GenericEventAction(MoveContainerToGround)); }
/* * ██████╗ ██╗ ██╗████████╗ * ██╔══██╗██║ ██║╚══██╔══╝ * ██████╔╝██║ ██║ ██║ * ██╔═══╝ ██║ ██║ ██║ * ██║ ╚██████╔╝ ██║ * ╚═╝ ╚═════╝ ╚═╝ */ public override bool DoesItemFit(IThing thing, out string error) { error = ""; if (!IsOpen) { error = $"The {this} is closed"; return(false); } IThing thing_inside = this.FirstOrDefault(); bool empty = thing_inside == null; if (empty) { if (thing is Tofu) { return(true); } else if (thing is Hamster) { return(true); } else { error = $"I don't really feel like putting {thing} into the microwave."; return(false); } } else { error = $"You can't put {thing} in the microwave. There is already {thing_inside} inside the microwave."; return(false); } }
public virtual void TestDescription(IThing described, IThing description, ILink descriptionLink) { Assert.IsTrue(Graph.Contains(described)); //Assert.IsTrue(Graph.Contains(description)); Assert.IsFalse(Graph.Contains(descriptionLink)); foreach (var link in Graph.Edges(described)) { Assert.IsFalse(link.Equals(descriptionLink)); } foreach (ILink link in Graph.Edges(description)) { Assert.IsFalse(link.Equals(descriptionLink)); } var schemaGraph = Graph as SchemaThingGraph; var thing = schemaGraph.ThingToDisplay(described); Assert.AreEqual(description, thing); thing = schemaGraph.DescribedThing(description); Assert.AreEqual(described, thing); foreach (var item in Graph.Walk().DeepWalk(described, 0)) { Assert.IsFalse(item.Node.Equals(descriptionLink)); Assert.IsFalse(item.Node.Equals(description)); } }
/// <summary> /// Executes the rule on the specified player <see cref="Thing"/>. /// </summary> /// <param name="playerThing">The player thing.</param> /// <param name="statName">Name of the attribute.</param> /// <param name="valueToAdd">The value to add.</param> public override void Execute(IThing playerThing, string statName, int valueToAdd) { value = valueToAdd; parentThing = (Thing)playerThing; FindStat(statName); IncreaseStatValue(); }
public GuyWithServiceAndThing(IService service, IThing thing) { _service = service; _thing = thing; }
public RelyOnThing(IThing thing) { }
protected void LoadThingField(XmlElement Node, IThing T) { XmlElement ThingRoot = Node.SelectSingleNode(String.Format("./child::thing[@type = '{0}']", T.GetType().Name)) as XmlElement; if (ThingRoot != null) T.Load(ThingRoot); else throw new ArgumentException(String.Format(I18N.GetText("InvalidThingField"), T.TypeName)); }
public bool IsSame(IThing t) { TPin p = t as TPin; return p != null && p.Module.IsSame(Module) && p.IsOutput == IsOutput && p.Index == Index; }
/// <summary> /// The query for delete /// </summary> /// <param name="thing">The thing to be deleted</param> /// <returns>SQL query</returns> public string BuildDelete(IThing thing) { return "DELETE FROM " + TableName + " where id = " + thing.Id; }
public bool IsSame(IThing t) { return t is TModule && (t as TModule).Mod == Mod; }
public bool IsSame(IThing t) { TCable c = t as TCable; return c != null && c.Src.IsSame(Src) && c.Dest.IsSame(Dest) && c.Index == Index; }
void SetSelected(IThing t) { if (t != Selected) { Selected = t; Invalidate(); Dirty = true; } }
void SetHovered(IThing t) { if (t != Hovered) { Hovered = t; Invalidate(); } }
protected override void OnPaint(PaintEventArgs pe) { // Call the OnPaint method of the base class. base.OnPaint(pe); if (MyGraph == null) return; var g = pe.Graphics; if (Dirty) { DoLayout(g); Dirty = false; Selected = Things.FirstOrDefault(t => t.IsSame(Selected)); Hovered = Things.FirstOrDefault(t => t.IsSame(Hovered)); } foreach (var thing in Things.OrderBy(t => t.Priority + (t == Selected ? 100 : 0))) thing.Paint(g, this, thing==Hovered, thing==Selected); if (DragCable != null) DragCable.Paint(g, this, true, true); }
public ThingUser(IThing thing) { Thing = thing; }
public void Add(IThing th) { if (weight + th.Weight > maxCapacity) { throw new OverloadedBagExeption(); } else { things.Add(th); weight += th.Weight; } }
private void DenyCommunicationRequest(IThing root, CancellableGameEvent e) { var communicationRequest = e as VerbalCommunicationEvent; if (communicationRequest != null && communicationRequest.ActiveThing == this.Parent) { e.Cancel("You are currently muted."); } }
/// <summary> /// Update a table, filtering using the thing /// </summary> /// <param name="collumns">The fields to be updated</param> /// <param name="item">The Thing</param> /// <returns>SQL query</returns> public string BuildUpdate(IDictionary<string, object> collumns, IThing item) { string update = "UPDATE `" + TableName + "` SET {0} where id = {1}"; IList<string> updates = new List<string>(); foreach (KeyValuePair<string, object> attr in collumns) { string columnName = "`" + attr.Key + "`"; string value = NormalizeInput(attr.Value); updates.Add(columnName + " = " + value); } return string.Format(update, string.Join(", ", updates), item.Id); }
/// <summary> /// Executes the specified player thing. /// </summary> /// <param name="playerThing">The player thing.</param> /// <param name="value1">The value1.</param> /// <param name="value2">The value2.</param> public virtual void Execute(IThing playerThing, string value1, int value2) { throw new NotImplementedException(); }
public ComplexThing(IThing thing) { Thing = thing; }
/// <summary>Executes the rule.</summary> /// <param name="playerThing">The player thing.</param> /// <param name="value1">The value1.</param> /// <param name="value2">The value2.</param> public override void Execute(IThing playerThing, string value1, int value2) { parentThing = (Thing)playerThing; }
public static void SetStructuredData(this DataPackage dataPackage, IThing thing) { dataPackage.SetData(thing.Type, thing.Stringify()); }