public async Task EntityScript_should_work() { var entity = _world.CreateEntity(); entity.Set(new TestComponent { Dice1 = Dice.Parse("2d+5") }); var c = entity.Get <TestComponent>(); //sanity Assert.Equal(0, c.RollResult); var changeScript = new EntityScript(@" if(entity.Has<TestComponent>()) { var c = entity.Get<TestComponent>(); c.RollResult = c.Dice1.Roll(); } ", Assembly.GetExecutingAssembly()); await changeScript.RunAsyncOn(entity); Assert.NotEqual(0, c.RollResult); }
/// <returns>An enumeration of the (id, item) pairs. Returns null if no items are present</returns> protected virtual List <T> OnGetItems() { if (string.IsNullOrEmpty(m_winTabName)) { m_winTabName = Feng.Server.Utils.ServiceHelper.GetWindowTabNameFromAddress(WebOperationContext.Current.IncomingRequest.UriTemplateMatch.BaseUri.LocalPath); } var r = DataSearchViewService.InternalGetItems(m_winTabName, WebOperationContext.Current.IncomingRequest.UriTemplateMatch.QueryParameters); if (r == null) { return(null); } List <T> items = new List <T>(); foreach (Dictionary <string, object> i in r) { T item = Feng.Utils.ReflectionHelper.CreateInstanceFromType(typeof(T)) as T; foreach (KeyValuePair <string, object> kvp in i) { EntityScript.SetPropertyValue(item, kvp.Key, kvp.Value); } items.Add(item); } return(items); }
//public static void 自动凭证应付对账单生成费用(ArchiveOperationForm masterForm) //{ // IControlManager<业务费用> detailCm = (((IArchiveDetailFormWithDetailGrids)detailForm).DetailGrids[0] as IArchiveGrid).ControlManager // as IControlManager<业务费用>; // IList<费用> list = new List<费用>(); // foreach (业务费用 item in detailCm.DisplayManagerT.Entities) // { // list.Add(item.Clone() as 业务费用); // } // ArchiveOperationForm masterFormKj = TabbedMdiForm.ShowMenuFormInMdi("凭证_会计付款") as ArchiveOperationForm; // if (masterFormKj != null) // { // if (masterFormKj.DoAdd()) // { // IControlManager<凭证费用明细> detailCmKj = (((IArchiveDetailFormWithDetailGrids)detailForm).DetailGrids[0] as IArchiveGrid).ControlManager as IControlManager<凭证费用明细>; // IBaseDao masterDao = ((IArchiveGrid)masterFormKj.ActiveGrid).Bll as IBaseDao; // MemoryDao<凭证费用明细> memoryBll = (masterDao.GetSubDao(0) as IMasterDao).DetailMemoryDao as MemoryDao<凭证费用明细>; // MemoryDao<费用> memoryBll2 = (((masterDao.GetSubDao(0) as IMasterDao).DetailDao as IBaseDao).GetSubDao(0) as IMasterDao).DetailMemoryDao as MemoryDao<费用>; // (masterFormKj.DisplayManager.CurrentItem as 凭证).自动手工标志 = 自动手工标志.对账单; // process_pz.AddFees(masterFormKj.DisplayManager.CurrentItem as 凭证, list, detailCmKj, memoryBll, memoryBll2); // //frm_cw_fkpz_kj_detail detailFormTo = form.ArchiveDetailForm as frm_cw_fkpz_kj_detail; // detailCmKj.DisplayManager.DataControls["金额.数额"].SelectedDataValue = detailForm.ControlManager.DisplayManager.DataControls["凭证金额"].SelectedDataValue; // detailCmKj.DisplayManager.DataControls["金额.币制编号"].SelectedDataValue = detailForm.ControlManager.DisplayManager.DataControls["凭证币制编号"].SelectedDataValue; // } // } //} public static void 择应付对账单费用(ArchiveOperationForm masterForm) { if (masterForm.ControlManager.DisplayManager.DataControls["相关人编号"].SelectedDataValue == null) { MessageForm.ShowError("请先填写相关人编号!"); return; } masterForm.ControlManager.DisplayManager.DataControls["相关人编号"].ReadOnly = true; EntityScript.SetPropertyValue(masterForm.DisplayManager.CurrentItem, "相关人编号", masterForm.ControlManager.DisplayManager.DataControls["相关人编号"].SelectedDataValue); Dictionary <string, object> dict = new Dictionary <string, object>(); dict["相关人编号"] = masterForm.ControlManager.DisplayManager.DataControls["相关人编号"].SelectedDataValue; ArchiveCheckForm form = ProcessSelect.Execute((masterForm.ArchiveDetailForm as IDisplayManagerContainer).DisplayManager, "选择_应付对账单_费用", dict); if (form != null) { IControlManager detailCm = (((IArchiveDetailFormWithDetailGrids)masterForm.ArchiveDetailForm).DetailGrids[0] as IArchiveGrid).ControlManager; using (var rep = ServiceProvider.GetService <IRepositoryFactory>().GenerateRepository <业务费用>()) { foreach (object i in form.SelectedEntites) { 业务费用 item = i as 业务费用; item.对账单 = masterForm.DisplayManager.CurrentItem as 对账单; detailCm.AddNew(); detailCm.DisplayManager.Items[detailCm.DisplayManager.Position] = item; detailCm.EndEdit(); } } } }
/// <summary> /// Initializes all components /// </summary> public void Init(EntityScript e) { foreach (var c in RenderComps) { e.thisEntity.AddComponent(c); } }
// Use this for initialization void Start() { name = "Balloon"; anim = this.GetComponent <Animator>(); coll = this.GetComponent <BoxCollider2D>(); self = this.GetComponent <EntityScript>(); }
void SpawnEntities() { List <EntityScript> currentEnemies = new List <EntityScript> (); foreach (GameObject entity in playerList) { pcScript e = Instantiate(entity).GetComponent <pcScript> (); currentPlayers.Add(e); Debug.Log(e); // TODO Place them on the screen } foreach (GameObject entity in enemyList) { EntityScript e = Instantiate(entity).GetComponent <EntityScript> (); e.battleManager = this; e.InitializeCombat(currentPlayers); currentEnemies.Add(e); // TODO Place them on the screen } foreach (pcScript entity in currentPlayers) { entity.battleManager = this; entity.playerGUI = playerUI; entity.combatGUI = playerUI; entity.InitializeCombat(currentEnemies); // TODO Place them on the screen } activeEnemies = currentEnemies; turnManager.StartCombat(currentPlayers, currentEnemies); }
public static T ConvertTypeFromRealToWS <T>(object i) where T : class, new() { T item = Feng.Utils.ReflectionHelper.CreateInstanceFromType(typeof(T)) as T; foreach (var p in typeof(T).GetProperties()) { object value = EntityScript.GetPropertyValue(i, p.Name); if (value != null) { Type propertyType = value.GetType(); if (propertyType.IsValueType || propertyType == typeof(string) || propertyType.IsEnum) { } else if (propertyType.GetInterface("IEnumerable") != null) // Collections { continue; } else { value = value.ToString(); } } EntityScript.SetPropertyValue(item, p.Name, value); } return(item); }
private List <object> GenerateData(object entity, string gridName, List <SoaDataGridColumn> columns) { Dictionary <string, object> dict; using (GridDataConvert dp = new GridDataConvert()) { dict = dp.Process(entity, gridName); } List <object> ret = new List <object>(); foreach (SoaDataGridColumn col in columns) { if (dict.ContainsKey(col.Name)) { ret.Add(dict[col.Name]); } else { object o = null; try { o = EntityScript.GetPropertyValue(entity, col.Name); } catch (Exception) // 不一定有这个属性,例如大写金额 { } ret.Add(o); } } return(ret); }
internal static Tuple <string, object> GetDataControlValue(string s2, IDisplayManager dm) { string s1 = s2; // maybe there is '.' // '.', ':' is invalid in sql int idx = s1.IndexOf('_'); string dataControlName, propertyName; if (idx == -1) { dataControlName = s1; propertyName = null; } else { dataControlName = s1.Substring(0, idx); propertyName = s1.Substring(idx + 1); } if (dm.DataControls[dataControlName] == null) { throw new ArgumentException("there is no IDataControl with name " + dataControlName + "!"); } object o = dm.DataControls[dataControlName].SelectedDataValue; if (!string.IsNullOrEmpty(propertyName)) { propertyName = propertyName.Replace('_', '.'); o = EntityScript.GetPropertyValue(o, propertyName); } return(new Tuple <string, object>(dataControlName, o)); }
internal static Tuple <string, object> GetEntityValue(string s2, IDisplayManager dm) { string s1 = s2; // maybe there is '.' // '.', ':' is invalid in sql int idx = s1.IndexOf('_'); string dataControlName, propertyName; if (idx == -1) { dataControlName = s1; propertyName = null; } else { dataControlName = s1.Substring(0, idx); propertyName = s1.Substring(idx + 1); } object o = EntityScript.GetPropertyValue(dm.CurrentItem, dataControlName); if (!string.IsNullOrEmpty(propertyName)) { propertyName = propertyName.Replace('_', '.'); o = EntityScript.GetPropertyValue(o, propertyName); } return(new Tuple <string, object>(dataControlName, o)); }
public void UnloadEntity(Entity entity) { if (entity.obj == null) { Debug.Log("not loaded"); } else { Vector2 position = GetEntityPosition(entity); entity.x = position.x; entity.y = position.y; //Debug.LogFormat("1childentities {0}", entity.childEntities.Count); EntityScript entityScript = entity.obj.GetComponent <EntityScript>(); entityScript.selfEntity = null; entityScript.unInitialize(); //Debug.LogFormat("2childentities {0}", entity.childEntities.Count); if (entity.childEntities != null) { foreach (Entity childEntity in entity.childEntities) { UnloadEntity(childEntity); } } Debug.LogFormat("unloaded {0}", entity.objName); entity.obj.SetActive(false); entity.obj = null; } }
/// <summary> /// Creates and initializes a IEntityScriptingService from a list of expressions. /// </summary> /// <param name="expressions">Expressions to evaluated.</param> /// <param name="initialAttributes">The initial values to be use for dynamic properties /// if not already present on the entity.</param> /// <typeparam name="TEntity">The entity type associated with the list of expressions.</typeparam> /// <returns>The created service.</returns> public static IEntityScriptingService CreateService <TEntity>(this IList <EntityExpression> expressions, IDictionary <string, object> initialAttributes = null) where TEntity : IAttributedEntity { if (expressions == null) { throw new ArgumentNullException(nameof(expressions)); } var es = new EntityScript( Guid.NewGuid().ToString(), "default", typeof(TEntity).AssemblyQualifiedName, new ReadOnlyCollection <EntityExpression>(expressions)); es.ImportedAssemblies = new[] { typeof(Common.Extensions.ObjectExtensions).GetTypeInfo().Assembly.FullName }; es.ImportedNamespaces = new[] { typeof(Common.Extensions.ObjectExtensions).Namespace }; if (initialAttributes != null) { es.InitialAttributes = initialAttributes; } var loggerFactory = new LoggerFactory(); var evalSrv = new EntityScriptingService(loggerFactory); evalSrv.Load(new[] { es }); return(evalSrv); }
public void LoadEntity(Entity entity) { Vector2 position = new Vector2(entity.x, entity.y); if (entity.obj != null) { //Debug.LogFormat("duplicate instantiation of one entity: {0}", entity.objName); } else { entity.obj = objectPooler.GetObjectFromPool(objectPools[entity.objName]); if (entity.obj == null) { objectPooler.IncreaseObjectPoolSize(objectPools[entity.objName], objNames[entity.objName], objectPoolInitialSizes[entity.objName]); entity.obj = objectPooler.GetObjectFromPool(objectPools[entity.objName]); } entity.obj.transform.position = position; entity.obj.SetActive(true); } if (entity.childEntities != null) { foreach (Entity childEntity in entity.childEntities) { LoadEntity(childEntity); } } EntityScript entityScript = entity.obj.GetComponent <EntityScript>(); entity.step = entityScript.step; entityScript.selfEntity = entity; entityScript.initialize(); }
/// <summary> /// /// </summary> /// <param name="searchExpression"></param> /// <param name="searchOrders"></param> /// <param name="parentItem"></param> public override System.Collections.IEnumerable GetData(ISearchExpression searchExpression, IList <ISearchOrder> searchOrders, object parentItem) { IList <T> list; object masterItem = parentItem; if (masterItem != null) { if (masterItem.GetType() == typeof(T)) { list = new List <T>(); list.Add((T)masterItem); } else { using (var rep = new Repository(this.RepositoryCfgName)) { rep.BeginTransaction(); object id = EntityScript.GetPropertyValue(masterItem, TypedEntityMetadata.GenerateEntityInfo(rep.Session.SessionFactory, masterItem.GetType()).IdName); NHibernate.ICriteria criteria = rep.Session.CreateCriteria(typeof(T)) .Add(NHibernate.Criterion.Expression.IdEq(id)); OnCriteriaCreated(criteria); list = criteria.List <T>(); rep.CommitTransaction(); } } } else { list = new List <T>(); } return(list); }
private void InitializeEntityScript() { entityScript = GetComponent <EntityScript>(); entityScript.step = Step; entityScript.initialize = Initialize; entityScript.unInitialize = UnInitialize; entityScript.remove = Remove; }
private ExpressionEvaluator[] CreateExpressionEvaluators(EntityScript script) { return(script.Expressions.Select(exp => { var scriptRunner = CreateScriptRunner(script, exp.Expression); return new ExpressionEvaluator(exp, scriptRunner); }).ToArray()); }
public PowerupController(EntityScript ps) { this.parentScript = ps; return; parentScript.impactEffects.Add("health", new FSQI(new FloatStat("health", 10f), "baseValue", 1000, -2, 1)); parentScript.impactEffects.Add("ranged", new FSQI(new FloatStat("ranged", 10f), "POWAH", 9001f, 9001)); }
/// <summary> /// SaveRowValues /// </summary> /// <param name="row"></param> /// <param name="grid"></param> public static void SaveRowValues(Xceed.Grid.CellRow row, IArchiveGrid grid) { if (row is InsertionRow) { grid.ControlManager.AddNew(); row.Tag = grid.ControlManager.DisplayManager.CurrentItem; grid.AddThrowInsertRow = true; } else { grid.ControlManager.EditCurrent(); // when insert, dataRow endingedit event will occur also row.Tag = grid.ControlManager.DisplayManager.CurrentItem; } try { foreach (GridColumnInfo info in ADInfoBll.Instance.GetGridColumnInfos(grid.GridName)) { if (row.Cells[info.GridColumnName] != null && !string.IsNullOrEmpty(info.PropertyName)) { if (info.GridColumnType == GridColumnType.Normal) { if (row.Cells[info.GridColumnName].ReadOnly) { continue; } if (info.GridColumnType == GridColumnType.Normal) { EntityScript.SetPropertyValue(grid.ControlManager.DisplayManager.CurrentItem, info.Navigator, info.PropertyName, row.Cells[info.GridColumnName].Value); } else if (info.GridColumnType == GridColumnType.ExpressionColumn) { Script.ExecuteStatement(info.Navigator, new Dictionary <string, object> { { "entity", grid.ControlManager.DisplayManager.CurrentItem }, { "cm", grid.ControlManager } }); } } } } } catch (Exception ex) { ExceptionProcess.ProcessWithNotify(ex); throw; } grid.ControlManager.EndEdit(true); grid.AddThrowInsertRow = false; grid.ArchiveGridHelper.ClearError(row); }
private void OnEnable() { entityScript = GetComponent <EntityScript>(); entityScript.ComputeTargetVelocity += ComputeVelocity; spriteRenderer = GetComponent <SpriteRenderer>(); AllowAttackInput = true; AllowNewAttack = true; Attack1Input = false; }
private void OnCollisionStay2D(Collision2D collision) { EntityScript entity = collision.gameObject.GetComponent <EntityScript>(); if (entity != null) { entity.TakeDamage(1); } }
protected override void OnCollision(GameObject target) { EntityScript entity = target.GetComponent <EntityScript>(); if (entity != null) { this.controller.OnHit(entity); } }
// Used to create a cached delegate that can be used to execute a script // against a domain model and a set of dynamic attributes. private ScriptRunner <object> CreateScriptRunner(EntityScript script, string expression) { var scopeType = typeof(EntityScriptScope <>).MakeGenericType(script.EntityType); var options = GetScriptOptions(script); var scriptRunner = CSharpScript.Create <object>(expression, options, scopeType); return(scriptRunner.CreateDelegate()); }
public static void 批量生成费用付款(IRepository rep, int 费用实体类型, 普通票 票, IEnumerable 箱s, string 费用项编号, 收付标志?收付标志, IList <业务费用理论值> llzs, bool service) { if (!收付标志.HasValue || 收付标志.Value == Hd.Model.收付标志.付) { // 生成付款费用 付款合同 fkht = HdDataBuffer.Instance.Get付款合同(rep, 费用实体类型); if (fkht != null) { foreach (付款合同费用项 htfyx in fkht.合同费用项) { // 如果指定费用项,则只生成此费用项下的费用 if (!string.IsNullOrEmpty(费用项编号) && htfyx.费用项编号 != 费用项编号) { continue; } // 不是服务运行时(即界面上点按钮),付款合同费用项.是否生成实际费用 = false 不生产费用 if (!service && !htfyx.是否生成实际费用) { continue; } 批量生成费用(rep, 票, 箱s, Hd.Model.收付标志.付, htfyx, llzs, !string.IsNullOrEmpty(费用项编号)); } } if (费用实体类型 == 11) { bool?cybz = ConvertHelper.ToBoolean(EntityScript.GetPropertyValue(票, "承运标志")); if (cybz.HasValue && cybz.Value) { // 受托人合同 string str = ConvertHelper.ToString(EntityScript.GetPropertyValue(票, "承运人编号")); if (!string.IsNullOrEmpty(str)) { // 生成付款费用 受托人合同 strht = HdDataBuffer.Instance.Get受托人合同(rep, 费用实体类型, str); if (strht != null) { foreach (受托人合同费用项 htfyx in strht.合同费用项) { // 如果指定费用项,则只生成此费用项下的费用 if (!string.IsNullOrEmpty(费用项编号) && htfyx.费用项编号 != 费用项编号) { continue; } 批量生成费用(rep, 票, 箱s, Hd.Model.收付标志.付, htfyx, llzs, !string.IsNullOrEmpty(费用项编号)); } } } } } } }
// Use this for initialization void Start() { gravity = -15 * scale; grav = 2.4f * scale; name = "Rocket"; anim = this.GetComponent <Animator>(); coll = this.GetComponent <BoxCollider2D>(); self = this.GetComponent <EntityScript>(); }
public static void EndTurn(List <StatusLibrary.StatusEnum> enums, EntityScript target) { foreach (StatusLibrary.StatusEnum e in enums) { if (EnumToEffect(e) is EndofTurn) { EnumToEffect(e).Affect(target); Debug.Log(e + " " + target); } } }
// A script can specify the default values that should be used for an entity's // dynamic attributes. These are only set if the entity doesn't already have // the attribute from a prior evaluation or manually specified by the caller. private static void SetDefaultAttributeValues(EntityScript script, object entity) { if (!(entity is IAttributedEntity attributedEntity)) { return; } foreach (var attribute in script.InitialAttributes) { attributedEntity.Attributes.SetValue(attribute.Key, attribute.Value, overrideIfPresent: false); } }
public bool belongsTo(EntityScript es, string parameter) { object entityParam = getParameter(parameter); if (entityParam == null || es == null) { return(false); } // Same as in entity but entity script comparition also. return(entityParam == es || entityParam == es.Entity || entityParam == es.gameObject || entityParam == es.tag); }
/// <summary> /// Constructor. Created data-model from script entity. /// </summary> /// <param name="script">The script domain entity.</param> public EntityScriptMeta(EntityScript script) { ScriptId = script.ScriptId; EntityType = script.EntityType.AssemblyQualifiedName; Name = script.Name; Description = script.Description; Attributes = script.InitialAttributes; ImportedAssemblies = script.ImportedAssemblies; ImportedNamespaces = script.ImportedNamespaces; SetExpressions(script.Expressions); }
void OnParticleCollision(GameObject other) { EntityScript entity = other.GetComponent <EntityScript>(); if (entity != null) { particleHitCount += 1; if (particleHitCount >= 5) { entity.TakeDamage(1); particleHitCount = 0; } } }
// Start is called before the first frame update void Start() { //Startup agent agent = GetComponent <NavMeshAgent>(); agent.updateRotation = false; agent.updateUpAxis = false; //Startup rbody2d rbody2d = gameObject.GetComponent <Rigidbody2D>(); //Startup animation anim = gameObject.GetComponentInChildren <Animator>(); //Startup es eScript = gameObject.GetComponent <EntityScript>(); //Startup controller eScript.getController(null, new Vector2(0, 0)); }
public bool belongsTo(EntityScript es) { return belongsTo(es, OWNER_PARAM); }
public bool belongsTo(EntityScript es, string parameter) { object entityParam = getParameter(parameter); if (entityParam == null || es == null) return false; // Same as in entity but entity script comparition also. return entityParam == es || entityParam == es.Entity || entityParam == es.gameObject || entityParam == es.tag; }
public Entity() { scripts = new EntityScript[8]; scriptsCount = 0; }
public virtual void OnHit(EntityScript obj) { obj.ModifyHealth(this.damage); }