public IToolImpact Use(IDynamicEntity owner) { var godEntity = owner as GodEntity; if (godEntity == null) { throw new ArgumentException("Invalid owner entity, should be GodEntity"); } var godHandToolState = (GodHandToolState)godEntity.EntityState.ToolState; if (godEntity.EntityState.MouseButton == MouseButton.LeftButton) { if (godHandToolState.DesignationBlueprintId != 0) { return(ItemPlacement(godEntity, godHandToolState)); } return(Selection(owner, godEntity, godHandToolState)); } if (godEntity.EntityState.MouseButton == MouseButton.RightButton) { return(UnitMoveOrder(godEntity)); } return(new ToolImpact()); }
public StorageOperationResult Create(IDynamicEntity entity) { MongoCollection<BsonDocument> descriptors = GetCollection(); var insertData = DynamicEntityToBsonAdapter.ToBsonDocument(entity); descriptors.Insert(insertData); return new StorageOperationResult { AffectedRecords = 1 }; }
public void CopyTo(object[] array, int arrayIndex) { var target = new IDynamicEntity[DynEntities.Count]; DynEntities.CopyTo(target, arrayIndex); target.CopyTo(array, arrayIndex); }
/// <inheritdoc/> public bool Load(JProperty newProperty, bool reload = false) { Covenant.Requires <ArgumentNullException>(newProperty != null); var changed = !NeonHelper.JTokenEquals(property, newProperty); property = newProperty; if (newProperty.Value == null || newProperty.Value.Type == JTokenType.Null) { entityValue = null; } else if (newProperty.Value.Type == JTokenType.Object) { entityValue = DynamicEntity.Create <TEntity>(newProperty.Value as JObject, context); entityValue._Attach(parentEntity); } else { throw new InvalidCastException($"Unable to cast a [{newProperty.Type}] into a [{typeof(TEntity).FullName}]."); } if (reload && changed) { parentEntity._OnPropertyChanged(PropertyName); } return(changed); }
/// <summary> /// Executes put operation /// Removes one item from the inventory and puts it into /// the world /// </summary> /// <param name="owner">entity that runs the operation</param> /// <returns></returns> public override IToolImpact Put(IDynamicEntity owner, Item worldDroppedItem = null) { //Is the player already binded to a soulstone ? var charEntity = owner as CharacterEntity; if (charEntity.BindedSoulStone != null) { IToolImpact impact = new ToolImpact(); impact.Message = "You are already binded to a soulstone."; impact.Success = false; return(impact); } if (worldDroppedItem == null) { SoulStone clonedNewSoulstone = (SoulStone)this.Clone(); clonedNewSoulstone.DynamicEntityOwnerID = charEntity.DynamicId; worldDroppedItem = clonedNewSoulstone as Item; } var putResult = base.Put(owner, worldDroppedItem); if (putResult.Success && worldDroppedItem != null) { //The soulStone has been placed into the world ! //Bind this entity with the player. charEntity.BindedSoulStone = worldDroppedItem as SoulStone; DynamicEntityOwnerID = charEntity.DynamicId; } return(putResult); }
/// <summary> /// Npc will run away from the Dangerous entities /// </summary> public void RunAway() { if (Npc.DangerousEntities.Count == 0) { return; } // find the point maximally far from dangerous objects (run direction) _runAwayPoint = Npc.DangerousEntities.Select(e => { var escape = Npc.Character.Position - e.Position; escape.Normalize(); var value = 16 - Vector3D.Distance(e.Position, Npc.Character.Position); if (value <= 0) { return(Vector3D.Zero); } return(escape * value * 10); }).Aggregate((s, v) => s + v).ToCubePosition() + Npc.Character.Position.ToCubePosition(); _leader = null; Npc.Server.LandscapeManager.CalculateCustomPathAsync(Npc.DynamicEntity.Position.ToCubePosition(), n => Npc.DangerousEntities.All(e => Vector3I.Distance(n.Cursor.GlobalPosition, e.Position.ToCubePosition()) > 16), AStarNodeFunc3D.GetSuccessors, n => Vector3I.Distance(_runAwayPoint, n.Cursor.GlobalPosition), FollowPath); WaitingForPath = true; _runAway = true; }
/// <inheritdoc/> public HtmlString ContextAttributes(IDynamicEntity target, string noParameterOrder = Eav.Constants.RandomProtectionParameter, string field = null, string contentType = null, Guid?newGuid = null, string apps = null, int max = 100) { Log.Add("ctx attribs - enabled:{Enabled}"); if (!Enabled) { return(null); } Eav.Constants.ProtectAgainstMissingParameterNames(noParameterOrder, nameof(ContextAttributes), $"{nameof(field)},{nameof(contentType)},{nameof(newGuid)}"); if (field == null) { throw new Exception("need parameter 'field'"); } var serialized = JsonConvert.SerializeObject(new { apps, field, guid = newGuid.ToString(), max, parent = target.EntityId, parentGuid = target.EntityGuid, type = contentType ?? Settings.AttributeSetStaticNameContentBlockTypeName, }); return(new HtmlString(innerContentAttribute + "='" + serialized + "'")); }
public LookUpForTokenTemplate(string name, IDynamicEntity entity, int repeaterIndex = -1, int repeaterTotal = -1) { Name = name; _entity = entity; _repeaterIndex = repeaterIndex; _repeaterTotal = repeaterTotal; }
public override void SetPosition(EntityPosition pos, IItem item, IDynamicEntity owner) { base.SetPosition(pos, item, owner); var cubeEntity = (BlockItem)item; cubeEntity.BlockLocationRoot = BlockHelper.EntityToBlock(pos.Position); }
private string link; // The entity link string or NULL /// <summary> /// Constructor. /// </summary> /// <param name="propertyNameMap"> /// The dictionary mapping JSON property names to their entity equivalents. /// </param> /// <param name="context">The optional entity context.</param> public DynamicEntity(IDictionary <string, string> propertyNameMap, IDynamicEntityContext context = null) { Covenant.Requires <ArgumentNullException>(propertyNameMap != null); this.propertyNameMap = propertyNameMap; this.context = context; this.self = (IDynamicEntity)this; this.parent = null; }
public IToolImpact Use(IDynamicEntity owner) { IToolImpact checkImpact; if (!CanDoBlockAction(owner, out checkImpact)) { return(checkImpact); } var impact = new BlockToolImpact { SrcBlueprintId = BluePrintId }; var cursor = LandscapeManager.GetCursor(owner.EntityState.PickedBlockPosition); if (cursor == null) { impact.Dropped = true; return(impact); } cursor.OwnerDynamicId = owner.DynamicId; var selectedCube = cursor.Read(); var treeSystem = new TreeLSystem(); bool removed = false; foreach (var soul in EntityFactory.LandscapeManager.AroundChunks(owner.Position, 16).SelectMany(c => c.Entities.Enumerate <TreeSoul>())) { var treeBlueprint = EntityFactory.Config.TreeBluePrintsDico[soul.TreeTypeId]; if (selectedCube != treeBlueprint.TrunkBlock && selectedCube != treeBlueprint.FoliageBlock) { continue; } var blocks = treeSystem.Generate(soul.TreeRndSeed, BlockHelper.EntityToBlock(soul.Position), treeBlueprint); if (blocks.Any(b => b.WorldPosition == owner.EntityState.PickedBlockPosition)) { cursor.RemoveEntity(soul.GetLink()); removed = true; break; } } if (!removed) { impact.Message = "This is not an alive tree"; return(impact); } TakeFromPlayer(owner); return(impact); }
public DynamicType Import(ASYCUDA adoc, IDynamicEntity docSet) { try { a = adoc; var ads = docSet; da.xcuda_Item = new List <DynamicType>() { }; da.XMLId = a.id; da.ASYCUDA_Id = 0; da.xcuda_ASYCUDA_ExtendedProperties = new DynamicType("xcuda_ASYCUDA_ExtendedProperties", da.ASYCUDA_Id); da.xcuda_Suppliers_documents = new List <DynamicType>(); SaveGeneralInformation(); SaveDeclarant(); SaveTraders(); SaveProperty(); SaveIdentification(); SaveTransport(); SaveFinancial(); Save_Warehouse(); Save_Valuation(); SaveContainer(); Save_Items(); if (!((List <DynamicType>)da.xcuda_Item).Any()) { return(new DynamicType("xcuda_ASYCUDA", 0)); } Save_Suppliers_Documents(); da.xcuda_ASYCUDA_ExtendedProperties.ImportComplete = true; da.xcuda_ASYCUDA_ExtendedProperties.AsycudaDocumentSetId = docSet.Id; da.xcuda_ASYCUDA_ExtendedProperties.Total_CIF = Convert.ToSingle(a.Valuation.Total_CIF); foreach (var itm in da.xcuda_Item) { if (itm.ImportComplete != false) { continue; } da.xcuda_ASYCUDA_ExtendedProperties.ImportComplete = false; break; } return(da); } catch (Exception) { throw; } }
private const string WrapperSingleItem = WrapperMultiItems + " show-placeholder single-item"; // enables a placeholder when empty, and limits one entry internal static string RenderWithEditContext(DynamicEntity dynParent, IDynamicEntity subItem, string cbFieldName, Guid? newGuid = null, IInPageEditingSystem edit = null) { if (edit == null) edit = new InPageEditingHelper(dynParent.Block); var attribs = edit.ContextAttributes(dynParent, field: cbFieldName, newGuid: newGuid); var inner = subItem == null ? "": Render(dynParent.Block, subItem.Entity).ToString(); var cbClasses = edit.Enabled ? WrapperSingleItem : ""; return string.Format(WrapperTemplate, new object[] { cbClasses, attribs, inner}); }
public IToolImpact Use(IDynamicEntity owner) { IToolImpact impact; if (!CanDoBlockAction(owner, out impact)) { return(impact); } return(BlockImpact(owner)); }
/// <summary> /// Returns new entity position correspoding to the player /// </summary> /// <param name="owner">An entity wich trying to put the entity</param> /// <returns></returns> public virtual EntityPosition GetPosition(IDynamicEntity owner) { EntityPosition position; position.Valid = true; position.Position = new Vector3D(owner.EntityState.PickPoint); position.Rotation = Quaternion.Identity; position.Orientation = ItemOrientation.East; return(position); }
public override void SetPosition(EntityPosition pos, IItem item, IDynamicEntity owner) { base.SetPosition(pos, item, owner); var blockItem = item as OrientedBlockLinkedItem; if (blockItem != null) { blockItem.Orientation = pos.Orientation; } }
/// <inheritdoc/> public void _Attach(IDynamicEntity parent) { Covenant.Requires <ArgumentNullException>(this.parent != null); if (this.parent != null && !object.ReferenceEquals(this.parent, this.parent)) { throw new InvalidOperationException($"Cannot attach an [{nameof(IDynamicEntity)}] here when it is already attached elsewhere."); } this.parent = parent; }
/// <summary> /// Creates event args from entity state /// </summary> /// <param name="owner"></param> /// <returns></returns> public static EntityUseEventArgs FromState(IDynamicEntity owner) { var state = owner.EntityState.Clone(); var e = new EntityUseEventArgs { State = state, Entity = owner }; return(e); }
public override void BeforeDestruction(IDynamicEntity destructor) { var charEntity = destructor as CharacterEntity; if (charEntity.DynamicId == this.DynamicEntityOwnerID) { //Unbind the soulstone from player charEntity.BindedSoulStone = null; } base.BeforeDestruction(destructor); }
/// <summary> /// Constructor. /// </summary> /// <param name="parentEntity">The <see cref="IDynamicEntity"/> that owns this mapper.</param> /// <param name="jsonName">The JSON property name.</param> /// <param name="propertyName">The entity property name.</param> /// <param name="context">The <see cref="IDynamicEntityContext"/> or <c>null</c>.</param> public SimpleMapper(IDynamicEntity parentEntity, string jsonName, string propertyName, IDynamicEntityContext context) { Covenant.Requires <ArgumentNullException>(parentEntity != null); Covenant.Requires <ArgumentNullException>(!string.IsNullOrEmpty(jsonName)); Covenant.Requires <ArgumentNullException>(!string.IsNullOrEmpty(propertyName)); this.parentEntity = parentEntity; this.context = context; this.JsonName = jsonName; this.PropertyName = propertyName; this.property = null; }
public VisualWorldParameters(WorldParameters worldParameters, IDynamicEntity player, Vector2I visibleChunkInWorld, CubeTexturesManager cubeTextureManager) { CubeTextureManager = cubeTextureManager; VisibleChunkInWorld = visibleChunkInWorld; WorldParameters = worldParameters; //Find the chunk location int X = (MathHelper.Floor(player.Position.X / 16) * 16) - ((VisibleChunkInWorld.X / 2) * 16); int Z = (MathHelper.Floor(player.Position.Z / 16) * 16) - ((VisibleChunkInWorld.Y / 2) * 16); WorldChunkStartUpPosition = new Vector3I(X, 0, Z); }
protected bool CanDoEntityAction(IDynamicEntity owner, out IToolImpact impact) { if (!owner.EntityState.IsEntityPicked) { impact = new ToolImpact { Message = "Pick an entity" }; return(false); } return(CanDo(owner, out impact)); }
public IToolImpact Use(IDynamicEntity owner) { IToolImpact checkImpact; if (!CanDoEntityAction(owner, out checkImpact)) { return(checkImpact); } var impact = new EntityToolImpact(); if (owner.EntityState.PickedEntityLink.IsDynamic) { impact.Message = "Only static entities allowed to use"; return(impact); } var entity = owner.EntityState.PickedEntityLink.ResolveStatic(LandscapeManager); if (entity == null) { impact.Message = "There is no entity by this link"; return(impact); } //Trigger item activation (Make it play sound, open, ...) if (entity is IUsableEntity) { var usable = (IUsableEntity)entity; usable.Use(); impact.Success = true; impact.EntityId = entity.StaticId; return(impact); } var cursor = LandscapeManager.GetCursor(entity.Position); if (cursor == null) { impact.Dropped = true; return(impact); } if (!entity.IsPickable) { impact.Message = "You need a special tool to pick this item"; return(impact); } cursor.OwnerDynamicId = owner.DynamicId; return(TakeImpact(owner, entity, impact, cursor, this)); }
protected bool CanDoBlockOrEntityAction(IDynamicEntity owner, out IToolImpact impact) { impact = null; if (!owner.EntityState.IsBlockPicked && !owner.EntityState.IsEntityPicked) { impact = new ToolImpact { Message = "Pick an entity or a block" }; return(false); } return(CanDo(owner, out impact)); }
protected bool CanDo(IDynamicEntity owner, out IToolImpact impact) { impact = null; if (owner.IsReadOnly) { impact = new ToolImpact { Message = "You don't have the access to modify the world. Ask admins for access." }; return(false); } return(true); }
public override EntityPosition GetPosition(IDynamicEntity owner) { var pos = new EntityPosition(); // allow to put only on top of the entity if (owner.EntityState.PickPointNormal.Y != 1) { return(pos); } pos.Position = new Vector3D(owner.EntityState.PickPoint); pos.Valid = true; return(pos); }
/// <summary> /// Constructor. /// </summary> /// <param name="parentEntity">The <see cref="IDynamicEntity"/> that owns this list.</param> /// <param name="context">The <see cref="IDynamicEntityContext"/> or <c>null</c>.</param> /// <param name="jArray">The underlying <see cref="jArray"/>.</param> /// <param name="items">The initial items or <c>null</c> to initialize from <paramref name="jArray"/>.</param> public EntityListWrapper(IDynamicEntity parentEntity, IDynamicEntityContext context, JArray jArray, IEnumerable <TEntity> items) { Covenant.Requires <ArgumentNullException>(parentEntity != null); Covenant.Requires <ArgumentNullException>(jArray != null); this.parentEntity = parentEntity; this.context = context; this.jArray = jArray; this.itemChangedHandler = new EventHandler <EventArgs>(OnItemChanged); this.list = new ObservableCollection <TEntity>(); if (items != null) { Covenant.Assert(jArray.Count == 0); foreach (var item in items) { Add(item); } } else { foreach (var jToken in jArray) { if (jToken.Type == JTokenType.Object) { var item = DynamicEntity.Create <TEntity>((JObject)jToken, context); item.Changed += itemChangedHandler; // We need to bubble up nested change events list.Add(item); } else { list.Add(null); // Ignore anything that's not an object. } } } // We're going to listen to our own collection changed event to // bubble them up. list.CollectionChanged += (s, a) => { CollectionChanged?.Invoke(this, a); parentEntity._OnChanged(); }; }
/// <summary> /// Render one content block /// This is accessed through DynamicEntity.Render() /// At the moment it MUST stay internal, as it's not clear what API we want to surface /// </summary> /// <param name="dynParent">The parent-item containing the content-blocks and providing edit-context</param> /// <param name="dontRelyOnParameterOrder"></param> /// <param name="item">The content-block item to render. Optional, by default the same item is used as the context.</param> /// <param name="field">Optional: </param> /// <param name="newGuid">Internal: this is the guid given to the item when being created in this block. Important for the inner-content functionality to work. </param> /// <returns></returns> public static IHtmlString One(DynamicEntity dynParent, string dontRelyOnParameterOrder = Eav.Constants.RandomProtectionParameter, IDynamicEntity item = null, string field = null, Guid?newGuid = null) { Eav.Constants.ProtectAgainstMissingParameterNames(dontRelyOnParameterOrder, nameof(One), $"{nameof(item)},{nameof(field)},{nameof(newGuid)}"); if (item == null) { item = dynParent; } return(new HtmlString(field == null ? Simple.Render(dynParent.Block, item.Entity) // with edit-context : Simple.RenderWithEditContext(dynParent, item, field, newGuid) + "<b>data-list-context</b>")); // data-list-context (no edit-context) }
public override void SetPosition(EntityPosition pos, IItem item, IDynamicEntity owner) { base.SetPosition(pos, item, owner); var cubeEntity = (BlockLinkedItem)item; if (!owner.EntityState.IsBlockPicked) { cubeEntity.Linked = false; } else { cubeEntity.LinkedCube = owner.EntityState.PickedBlockPosition; cubeEntity.BlockLocationRoot = BlockHelper.EntityToBlock(pos.Position); cubeEntity.Linked = true; } }
/// <inheritdoc/> public bool Load(JProperty newProperty, bool reload = false) { Covenant.Requires <ArgumentNullException>(newProperty != null); var changed = !NeonHelper.JTokenEquals(property, newProperty); this.property = newProperty; this.entityValue = null; // Purge any cached entity info this.isDeletedFunc = null; if (reload && changed) { parentEntity._OnPropertyChanged(PropertyName); } return(changed); }
/// <summary> /// Constructor. /// </summary> /// <param name="parentEntity">The <see cref="IDynamicEntity"/> that owns this list.</param> /// <param name="context">The <see cref="IDynamicEntityContext"/> or <c>null</c>.</param> /// <param name="jArray">The underlying <see cref="jArray"/>.</param> /// <param name="items">The initial items or <c>null</c> to initialize from <paramref name="jArray"/>.</param> public LinkListWrapper(IDynamicEntity parentEntity, IDynamicEntityContext context, JArray jArray, IEnumerable <TEntity> items) { Covenant.Requires <ArgumentNullException>(parentEntity != null); Covenant.Requires <ArgumentNullException>(jArray != null); this.parentEntity = parentEntity; this.context = context; this.jArray = jArray; this.list = new ObservableCollection <LinkState>(); if (items != null) { Covenant.Assert(jArray.Count == 0); foreach (var item in items) { Add(item); } } else { foreach (var token in jArray) { list.Add(new LinkState() { Link = GetLink(token) }); } } // We're going to listen to our own collection changed event to // bubble them up. list.CollectionChanged += (s, a) => { if (!notifyDisabled) { CollectionChanged?.Invoke(this, a); parentEntity._OnChanged(); } }; }
public static BsonDocument ToBsonDocument(IDynamicEntity entity) { var fields = new BsonArray(); foreach (var f in entity.Fields) { var props = f.Properties != null && f.Properties.Any() ? new BsonArray(f.Properties.Select(p => new BsonDocument{ { "name", p.Key }, { "value", BsonValue.Create(p.Value) } } )) : null; var fDoc = new BsonDocument { { "name", f.Name }, { "datatype", f.DataType.FullName } }; if (f.DefaultValue != null) { fDoc["default_value"] = BsonValue.Create(f.DefaultValue); } if (props != null) { fDoc["properties"] = props; } fields.Add(fDoc); } var result = new BsonDocument { { "name", entity.Name }, { "fields", new BsonArray(fields) } }; return result; }
public StorageOperationResult Update(IDynamicEntity newEntity) { // TODO: move diff logic to some diff handler when it will be needed to capture history or sth MongoCollection<BsonDocument> descriptors = GetCollection(); var oldEntityDoc = descriptors.FindOne(MongoQueryBuilder.EQ("name", newEntity.Name)); if (oldEntityDoc == null) { return new StorageOperationResult { AffectedRecords = 0, Error = new Exception(String.Format("There's no dynamic with the name {0} present in the storage", newEntity.Name)) }; } descriptors.Update( MongoQueryBuilder.EQ("name", newEntity.Name), MongoUpdateBuilder.Set("fields", DynamicEntityToBsonAdapter.ToBsonDocument(newEntity)["fields"]) ); return new StorageOperationResult { AffectedRecords = 1 }; }